mirror of
https://github.com/jenshemprich/MacGLide.git
synced 2024-06-17 15:29:40 +00:00
Correctly restoring the client state, enhanced error handling
This commit is contained in:
parent
44b073af49
commit
20f46da51d
|
@ -832,6 +832,9 @@ void RenderUpdateState()
|
|||
{
|
||||
glReportErrors("RenderUpdateState");
|
||||
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1);
|
||||
VERIFY_TEXTURE_ENABLED_STATE();
|
||||
|
||||
// This filters out a few state changes in Carmageddon
|
||||
// (changing chromakey mode is expensive)
|
||||
if (OldGlideState.ChromaKeyMode != Glide.State.ChromaKeyMode)
|
||||
|
@ -870,14 +873,10 @@ void RenderUpdateState()
|
|||
|
||||
bool active_texture_unit_not_coloralpha1 = false;
|
||||
bool active_texture_unit_client_state_not_coloralpha1 = false;
|
||||
if (s_bUpdateFogModeState ||
|
||||
s_bUpdateFogColorState ||
|
||||
s_bUpdateColorInvertState ||
|
||||
s_bUpdateAlphaInvertState)
|
||||
// color or alpha inversion also triggers a fog mode state so we don't have to check explicitly
|
||||
if (s_bUpdateFogModeState || s_bUpdateFogColorState)
|
||||
{
|
||||
if (InternalConfig.FogMode == OpenGLideFogEmulation_EnvCombine)
|
||||
{
|
||||
if (s_bUpdateFogModeState || s_bUpdateFogColorState)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.FogTextureUnit);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
|
@ -887,12 +886,17 @@ void RenderUpdateState()
|
|||
}
|
||||
active_texture_unit_not_coloralpha1 = true;
|
||||
glReportError();
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.FogTextureUnit);
|
||||
// Fog color
|
||||
if (s_bUpdateFogColorState)
|
||||
{
|
||||
s_bUpdateFogColorState = false;
|
||||
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &OpenGL.FogColor[0]);
|
||||
glReportError();
|
||||
}
|
||||
|
||||
// Fog mode
|
||||
if (s_bUpdateFogModeState)
|
||||
{
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.FogTextureUnit);
|
||||
|
||||
s_bUpdateFogModeState = false;
|
||||
if (Glide.State.FogMode & (GR_FOG_WITH_ITERATED_ALPHA | GR_FOG_WITH_TABLE))
|
||||
{
|
||||
|
@ -963,17 +967,16 @@ void RenderUpdateState()
|
|||
OGLRender.UseEnvCombineFog = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Fog Color
|
||||
if (s_bUpdateFogColorState)
|
||||
{
|
||||
s_bUpdateFogColorState = false;
|
||||
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &OpenGL.FogColor[0]);
|
||||
glReportError();
|
||||
}
|
||||
}
|
||||
else if (InternalConfig.FogMode != OpenGLideFogEmulation_None)
|
||||
{
|
||||
if (s_bUpdateFogColorState)
|
||||
{
|
||||
s_bUpdateFogColorState = false;
|
||||
glFogfv(GL_FOG_COLOR, &OpenGL.FogColor[0]);
|
||||
glReportError();
|
||||
}
|
||||
|
||||
if (s_bUpdateFogModeState)
|
||||
{
|
||||
s_bUpdateFogModeState = false;
|
||||
|
@ -1003,19 +1006,13 @@ void RenderUpdateState()
|
|||
}
|
||||
glReportError();
|
||||
}
|
||||
|
||||
if (s_bUpdateFogColorState)
|
||||
{
|
||||
s_bUpdateFogColorState = false;
|
||||
glFogfv(GL_FOG_COLOR, &OpenGL.FogColor[0]);
|
||||
glReportError();
|
||||
}
|
||||
}
|
||||
|
||||
// Means fog texture unit is active
|
||||
if (active_texture_unit_not_coloralpha1 == false &&
|
||||
(s_bUpdateColorInvertState || s_bUpdateAlphaInvertState))
|
||||
if (s_bUpdateColorInvertState || s_bUpdateAlphaInvertState)
|
||||
{
|
||||
if (active_texture_unit_not_coloralpha1 == false)
|
||||
{
|
||||
active_texture_unit_not_coloralpha1 = true;
|
||||
glActiveTextureARB(OpenGL.FogTextureUnit);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
|
@ -1023,9 +1020,7 @@ void RenderUpdateState()
|
|||
active_texture_unit_client_state_not_coloralpha1 = true;
|
||||
}
|
||||
glReportError();
|
||||
active_texture_unit_not_coloralpha1 = true;
|
||||
}
|
||||
|
||||
if (s_bUpdateColorInvertState)
|
||||
{
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.FogTextureUnit);
|
||||
|
@ -1044,6 +1039,9 @@ void RenderUpdateState()
|
|||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, invert ? GL_ONE_MINUS_SRC_ALPHA : GL_SRC_ALPHA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VERIFY_TEXTURE_ENABLED_STATE();
|
||||
|
||||
// Coloralpha state changes
|
||||
if (s_bUpdateTextureState ||
|
||||
|
@ -1161,38 +1159,43 @@ void RenderUpdateState()
|
|||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, NULL);
|
||||
active_texture_unit_client_state_not_coloralpha1 = (unit_index != 0);
|
||||
}
|
||||
active_texture_unit_not_coloralpha1 = (unit_index != 0);
|
||||
glReportError();
|
||||
}
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, NULL);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glReportError();
|
||||
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
}
|
||||
#ifdef OPENGL_DEBUG
|
||||
else
|
||||
{
|
||||
#ifdef OPENGL_DEBUG
|
||||
GlideMsg("Unused texture unit GL_TEXTURE%d_ARB already disabled\n", unit_index);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save state changes if fog state hasn't been changed
|
||||
// and only coloralpha texture unit 0 is used
|
||||
// Any of the updates needs the active texture unit set, but not the client state
|
||||
// Save state changes if fog state hasn't been changed and only coloralpha texture unit 0 is used
|
||||
const bool set_active_texture_unit = active_texture_unit_not_coloralpha1 || unit_index != 0;
|
||||
if (set_active_texture_unit)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
glReportError();
|
||||
active_texture_unit_not_coloralpha1 = (unit_index != 0);
|
||||
// The client state is changed only if the texture unit must be enabled, otherwise the
|
||||
// active client texture unit is restored to color alpha unit 1 at the end
|
||||
}
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
// Don't check VERIFY_ACTIVE_TEXTURE_UNIT yet as it hasn't been set up completely yet
|
||||
|
||||
// Texture state
|
||||
if (s_bUpdateTextureState)
|
||||
|
@ -1227,9 +1230,21 @@ void RenderUpdateState()
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
|
||||
#ifdef OPENGL_DEBUG
|
||||
// At this point, the client state doesn't matter anymore, and we just need to check the active texture
|
||||
GLint y;
|
||||
const GLint x = OpenGL.ColorAlphaUnit1 + unit_index;
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &y);
|
||||
glReportError();
|
||||
const bool verified = x == y;
|
||||
if (!verified)
|
||||
{
|
||||
GlideMsg("Warning: %s() active texture unit is GL_TEXTURE%d_ARB, but should be GL_TEXTURE%d_ARB\n", __glide_functionname, y - GL_TEXTURE0_ARB, x - GL_TEXTURE0_ARB);
|
||||
}
|
||||
#ifdef OGL_STOP_ON_GL_ERROR
|
||||
assert(verified);
|
||||
#endif
|
||||
#endif
|
||||
// ColorCombineState
|
||||
if (s_bUpdateColorCombineState)
|
||||
{
|
||||
|
@ -1402,7 +1417,7 @@ void RenderUpdateState()
|
|||
const GrCombineLocal_t a_local = Glide.State.AlphaLocal;
|
||||
const GrCombineOther_t a_other = Glide.State.AlphaOther;
|
||||
const CombineArgument** combine_argument = &OpenGL.AlphaCombineArguments[0];
|
||||
// combine_argument[CFARG_Local] = 0; // This is set to 0 onn initialising OpenGL
|
||||
// combine_argument[CFARG_Local] = 0; // This is set to 0 on initialising OpenGL
|
||||
// combine_argument[CFARG_Other] = 0;
|
||||
combine_argument[CFARG_LocalAlpha] = &AlphaCombineLocals[a_local];
|
||||
combine_argument[CFARG_OtherAlpha] = Glide.State.TextureCombineAInvert ? &AlphaCombineOthersInverted[a_other] : &AlphaCombineOthers[a_other];
|
||||
|
@ -1565,16 +1580,16 @@ void RenderUpdateState()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restore state
|
||||
if (active_texture_unit_not_coloralpha1)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
}
|
||||
if (active_texture_unit_client_state_not_coloralpha1)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
}
|
||||
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1);
|
||||
VERIFY_TEXTURE_ENABLED_STATE();
|
||||
|
|
Loading…
Reference in New Issue
Block a user