Skip to content

Commit

Permalink
Re-add and fix up fallback for 1.4 ≤ OpenGL < 2.0.
Browse files Browse the repository at this point in the history
Patch by some linear combination of safety0ff, cybersphinx and Cyp.
  • Loading branch information
Cyp committed Nov 26, 2011
1 parent f5a4cec commit 2f816f5
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 10 deletions.
37 changes: 32 additions & 5 deletions lib/ivis_opengl/piedraw.cpp
Expand Up @@ -138,6 +138,7 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI
{
iIMDPoly *pPolys;
bool light = true;
bool shaders = pie_GetShaderAvailability();

pie_SetAlphaTest(true);

Expand Down Expand Up @@ -171,7 +172,14 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI
{
pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
light = false;
pie_ActivateShader(SHADER_BUTTON, teamcolour, shape->tcmaskpage, shape->normalpage);
if (shaders)
{
pie_ActivateShader(SHADER_BUTTON, shape, teamcolour, colour);
}
else
{
pie_ActivateFallback(SHADER_BUTTON, shape, teamcolour, colour);
}
}
pie_SetRendMode(REND_OPAQUE);
}
Expand All @@ -189,7 +197,14 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI
glMaterialfv(GL_FRONT, GL_SPECULAR, shape->material[LIGHT_SPECULAR]);
glMaterialf(GL_FRONT, GL_SHININESS, shape->shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, shape->material[LIGHT_EMISSIVE]);
pie_ActivateShader(SHADER_COMPONENT, teamcolour, shape->tcmaskpage, shape->normalpage);
if (shaders)
{
pie_ActivateShader(SHADER_COMPONENT, shape, teamcolour, colour);
}
else
{
pie_ActivateFallback(SHADER_COMPONENT, shape, teamcolour, colour);
}
}

if (pieFlag & pie_HEIGHT_SCALED) // construct
Expand All @@ -201,7 +216,7 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI
glTranslatef(1.0f, (-shape->max.y * (pie_RAISE_SCALE - pieFlagData)) * (1.0f / pie_RAISE_SCALE), 1.0f);
}

glColor4ubv(colour.vector); // Only need to set once for entire model
glColor4ubv(colour.vector); // Only need to set once for entire model
pie_SetTexturePage(shape->texpage);

frame %= MAX(1, shape->numFrames);
Expand Down Expand Up @@ -232,15 +247,27 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI
glNormal3fv((GLfloat*)&pPolys->normal);
for (n = 0; n < pPolys->npnts; n++)
{
glTexCoord2fv((GLfloat*)&pPolys->texCoord[frameidx * pPolys->npnts + n]);
GLfloat* texCoord = (GLfloat*)&pPolys->texCoord[frameidx * pPolys->npnts + n];
glTexCoord2fv(texCoord);
if (!shaders)
{
glMultiTexCoord2fv(GL_TEXTURE1, texCoord);
}
glVertex3fv((GLfloat*)&vertexCoords[n]);
}
}
glEnd();

if (light || (pieFlag & pie_BUTTON))
{
pie_DeactivateShader();
if (shaders)
{
pie_DeactivateShader();
}
else
{
pie_DeactivateFallback();
}
}
pie_SetShaderEcmEffect(false);

Expand Down
89 changes: 87 additions & 2 deletions lib/ivis_opengl/piestate.cpp
Expand Up @@ -36,7 +36,7 @@
* Global Variables
*/

// Variables for the coloured mouse cursor
static bool shadersAvailable;
static GLuint shaderProgram[SHADER_MAX];
static GLfloat shaderStretch = 0;
static GLint locTeam, locStretch, locTCMask, locFog, locNormalMap, locEcm, locTime;
Expand Down Expand Up @@ -129,6 +129,16 @@ PIELIGHT pie_GetFogColour(void)
return rendStates.fogColour;
}

bool pie_GetShaderAvailability(void)
{
return shadersAvailable;
}

void pie_SetShaderAvailability(bool availability)
{
shadersAvailable = availability;
}

// Read shader into text buffer
static char *readShaderBuf(const char *name)
{
Expand Down Expand Up @@ -330,8 +340,80 @@ void pie_SetShaderStretchDepth(float stretch)
shaderStretch = stretch;
}

void pie_ActivateShader(SHADER_MODE shaderMode, PIELIGHT teamcolour, int maskpage, int normalpage)
void pie_ActivateFallback(SHADER_MODE, iIMDShape* shape, PIELIGHT teamcolour, PIELIGHT colour)
{
if (shape->tcmaskpage == iV_TEX_INVALID)
{
return;
}

//Set the environment colour with tcmask
GLfloat tc_env_colour[4];
pal_PIELIGHTtoRGBA4f(&tc_env_colour[0], teamcolour);

// TU0
glActiveTexture(GL_TEXTURE0);
pie_SetTexturePage(shape->texpage);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, tc_env_colour);

// TU0 RGB
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

// TU0 Alpha
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

// TU1
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[shape->tcmaskpage].id);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

// TU1 RGB
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);

// TU1 Alpha
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

glEnable(GL_BLEND);
glBlendFunc(GL_CONSTANT_COLOR, GL_ZERO);
glBlendColor(colour.byte.r / 255.0, colour.byte.g / 255.0,
colour.byte.b / 255.0, colour.byte.a / 255.0);

glActiveTexture(GL_TEXTURE0);
}

void pie_DeactivateFallback()
{
glDisable(GL_BLEND);
rendStates.rendMode = REND_OPAQUE;

glActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}

void pie_ActivateShader(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamcolour, PIELIGHT colour)
{
int maskpage = shape->tcmaskpage;
int normalpage = shape->normalpage;
GLfloat colour4f[4];

if (shaderMode != currentShaderMode)
Expand All @@ -358,6 +440,9 @@ void pie_ActivateShader(SHADER_MODE shaderMode, PIELIGHT teamcolour, int maskpag
currentShaderMode = shaderMode;
}

glColor4ubv(colour.vector);
pie_SetTexturePage(shape->texpage);

pal_PIELIGHTtoRGBA4f(&colour4f[0], teamcolour);
glUniform4fv(locTeam, 1, &colour4f[0]);
glUniform1f(locStretch, shaderStretch);
Expand Down
6 changes: 5 additions & 1 deletion lib/ivis_opengl/piestate.h
Expand Up @@ -83,10 +83,14 @@ extern void pie_SetAlphaTest(bool keyingOn);
extern void pie_SetRendMode(REND_MODE rendMode);

// Shaders control center
extern bool pie_GetShaderAvailability(void);
extern void pie_SetShaderAvailability(bool);
bool pie_LoadShaders(void);
// Actual shaders (we do not want to export these calls)
void pie_DeactivateShader(void);
void pie_ActivateShader(SHADER_MODE shaderMode, PIELIGHT teamcolour, int maskpage, int normalpage);
void pie_DeactivateFallback(void);
void pie_ActivateShader(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamcolour, PIELIGHT colour);
void pie_ActivateFallback(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamcolour, PIELIGHT colour);
void pie_SetShaderStretchDepth(float stretch);
void pie_SetShaderTime(uint32_t shaderTime);
void pie_SetShaderEcmEffect(bool value);
Expand Down
10 changes: 8 additions & 2 deletions lib/ivis_opengl/screen.cpp
Expand Up @@ -123,9 +123,11 @@ bool screenInitialise()
screenWidth = MAX(screenWidth, 640);
screenHeight = MAX(screenHeight, 480);

/* Dump information about OpenGL 2.0+ implementation to the console and the dump file */
pie_SetShaderAvailability(GLEW_VERSION_2_0); // Simple check / close enough

if (GLEW_VERSION_2_0)
{
/* Dump information about OpenGL 2.0+ implementation to the console and the dump file */
GLint glMaxTIUs, glMaxTCs, glMaxTIUAs, glmaxSamples, glmaxSamplesbuf;

debug(LOG_3D, " * OpenGL GLSL Version : %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
Expand All @@ -145,9 +147,13 @@ bool screenInitialise()

pie_LoadShaders();
}
else if (GLEW_VERSION_1_4)
{
debug(LOG_POPUP, _("OpenGL 2.0 is not supported by your system. Some things may look wrong. Please upgrade your graphics driver/hardware, if possible."));
}
else
{
debug(LOG_FATAL, "OpenGL 2.0 is not supported by your system. The game require this. Please upgrade your graphics drivers, if possible.");
debug(LOG_FATAL, _("OpenGL 1.4 is not supported by your system. The game requires this. Please upgrade your graphics drivers/hardware, if possible."));
exit(1);
}

Expand Down

0 comments on commit 2f816f5

Please sign in to comment.