From 73c66d30ae0df5c149b680c7a93c78fedcd02068 Mon Sep 17 00:00:00 2001 From: Jens Hemprich <31758696+jenshemprich@users.noreply.github.com> Date: Sun, 3 Sep 2006 19:51:39 +0000 Subject: [PATCH] Optimising calls to glAlphaTestFunc --- MacGLide/OpenGLide/GLRenderUpdateState.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/MacGLide/OpenGLide/GLRenderUpdateState.cpp b/MacGLide/OpenGLide/GLRenderUpdateState.cpp index 7f2e9f7..30c9b1d 100644 --- a/MacGLide/OpenGLide/GLRenderUpdateState.cpp +++ b/MacGLide/OpenGLide/GLRenderUpdateState.cpp @@ -419,7 +419,20 @@ inline void SetChromaKeyAndAlphaState_update() GlideMsg("Changing Chromakeymode state to enabled\n"); #endif // setup chroma keying - glAlphaFunc(GL_GEQUAL, 0.5); + const GLenum alphaTestFunction = GL_GEQUAL; + const GLfloat alphaTestReferenceValue = 0.5; +#ifdef OPTIMISE_OPENGL_STATE_CHANGES + // Update only when necessary + if (alphaTestFunction != OpenGL.AlphaTestFunction + || alphaTestReferenceValue != OpenGL.AlphaReferenceValue) + { + OpenGL.AlphaTestFunction = alphaTestFunction; + OpenGL.AlphaReferenceValue = alphaTestReferenceValue; +#endif + glAlphaFunc(alphaTestFunction, alphaTestReferenceValue); +#ifdef OPTIMISE_OPENGL_STATE_CHANGES + } +#endif glEnable(GL_ALPHA_TEST); if (InternalConfig.EXT_compiled_vertex_array) { @@ -440,9 +453,14 @@ inline void SetChromaKeyAndAlphaState_update() } else { - if ( Glide.State.AlphaTestFunction != GR_CMP_ALWAYS ) + if (Glide.State.AlphaTestFunction != GR_CMP_ALWAYS) { glEnable(GL_ALPHA_TEST); +#ifndef OPTIMISE_OPENGL_STATE_CHANGES + // Restore previous values + OpenGL.AlphaTestFunction = GL_NEVER + Glide.State.AlphaTestFunction; + OpenGL.AlphaReferenceValue = Glide.State.AlphaReferenceValue * D1OVER255; +#endif glAlphaFunc(OpenGL.AlphaTestFunction, OpenGL.AlphaReferenceValue); } else