Skip to content

Commit

Permalink
#5909: Move tons of GL state management code from shader pass to Open…
Browse files Browse the repository at this point in the history
…GLState awaiting further refactoring.
  • Loading branch information
codereader committed Mar 13, 2022
1 parent 9333b5b commit 009ac16
Show file tree
Hide file tree
Showing 5 changed files with 422 additions and 7 deletions.
4 changes: 4 additions & 0 deletions radiantcore/rendersystem/backend/DepthFillPass.cpp
Expand Up @@ -34,6 +34,7 @@ DepthFillPass::DepthFillPass(OpenGLShader& owner, OpenGLRenderSystem& renderSyst
assert(dynamic_cast<GLSLDepthFillAlphaProgram*>(_glState.glProgram));
}

#if 0
void DepthFillPass::activateShaderProgram(OpenGLState& current)
{
// We need a program, it is set up in the constructor
Expand All @@ -42,12 +43,15 @@ void DepthFillPass::activateShaderProgram(OpenGLState& current)
// Let the base class enable the program
OpenGLShaderPass::activateShaderProgram(current);

#if 0 // TODO: Migrate to LightInteractions::depthFill
auto zFillAlphaProgram = static_cast<GLSLDepthFillAlphaProgram*>(current.glProgram);

zFillAlphaProgram->applyAlphaTest(_glState.alphaThreshold);

setTextureState(current.texture0, _glState.texture0, GL_TEXTURE0, GL_TEXTURE_2D);
setupTextureMatrix(GL_TEXTURE0, _glState.stage0);
#endif
}
#endif

}
2 changes: 2 additions & 0 deletions radiantcore/rendersystem/backend/DepthFillPass.h
Expand Up @@ -23,8 +23,10 @@ class DepthFillPass :
return *static_cast<GLSLDepthFillAlphaProgram*>(_glState.glProgram);
}

#if 0
protected:
virtual void activateShaderProgram(OpenGLState& current) override;
#endif
};

}
21 changes: 18 additions & 3 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.cpp
Expand Up @@ -49,6 +49,7 @@ void OpenGLShaderPass::setTextureState(GLint& current,
namespace
{

#if 0
// Utility function to toggle an OpenGL state flag
inline void setState(unsigned int state,
unsigned int delta,
Expand All @@ -66,7 +67,7 @@ inline void setState(unsigned int state,
debug::assertNoGlErrors();
}
}

#endif
inline void evaluateStage(const IShaderLayer::Ptr& stage, std::size_t time, const IRenderEntity* entity)
{
if (!stage) return;
Expand All @@ -85,6 +86,7 @@ inline void evaluateStage(const IShaderLayer::Ptr& stage, std::size_t time, cons

// GL state enabling/disabling helpers

#if 0
void OpenGLShaderPass::setTexture0()
{
if (GLEW_VERSION_1_3)
Expand Down Expand Up @@ -112,7 +114,6 @@ void OpenGLShaderPass::disableTexture2D()

debug::assertNoGlErrors();
}

// Enable cubemap texturing and texcoord array
void OpenGLShaderPass::enableTextureCubeMap()
{
Expand All @@ -132,6 +133,8 @@ void OpenGLShaderPass::disableTextureCubeMap()
debug::assertNoGlErrors();
}

#endif
#if 0
void OpenGLShaderPass::enableRenderBlend()
{
glEnable(GL_BLEND);
Expand All @@ -147,7 +150,9 @@ void OpenGLShaderPass::disableRenderBlend()
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
debug::assertNoGlErrors();
}
#endif

#if 0
void OpenGLShaderPass::setupTextureMatrix(GLenum textureUnit, const IShaderLayer::Ptr& stage)
{
// Set the texture matrix for the given unit
Expand All @@ -164,7 +169,8 @@ void OpenGLShaderPass::setupTextureMatrix(GLenum textureUnit, const IShaderLayer
glLoadIdentity();
}
}

#endif
#if 0
// Apply all textures to texture units
void OpenGLShaderPass::applyAllTextures(OpenGLState& current,
unsigned requiredState)
Expand Down Expand Up @@ -214,6 +220,7 @@ void OpenGLShaderPass::applyAllTextures(OpenGLState& current,
glMatrixMode(GL_MODELVIEW);
}
}
#endif

void OpenGLShaderPass::evaluateShaderStages(std::size_t time, const IRenderEntity* entity)
{
Expand Down Expand Up @@ -249,6 +256,11 @@ void OpenGLShaderPass::applyState(OpenGLState& current, unsigned int globalState
globalStateMask |= RENDER_FILL | RENDER_DEPTHWRITE;
}

// Calculate the difference between this state and the current one
// and apply the changes required to match our required flags.
_glState.applyTo(current, globalStateMask);

#if 0
// Apply the global state mask to our own desired render flags to determine
// the final set of flags that must bet set
const unsigned requiredState = _glState.getRenderFlags() & globalStateMask;
Expand Down Expand Up @@ -482,8 +494,10 @@ void OpenGLShaderPass::applyState(OpenGLState& current, unsigned int globalState
current.setRenderFlags(requiredState);

debug::assertNoGlErrors();
#endif
}

#if 0
void OpenGLShaderPass::activateShaderProgram(OpenGLState& current)
{
if (current.glProgram == _glState.glProgram)
Expand Down Expand Up @@ -511,6 +525,7 @@ void OpenGLShaderPass::deactivateShaderProgram(OpenGLState& current)

current.glProgram = nullptr;
}
#endif

void OpenGLShaderPass::addRenderable(const OpenGLRenderable& renderable,
const Matrix4& modelview)
Expand Down
12 changes: 8 additions & 4 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.h
Expand Up @@ -57,30 +57,34 @@ class OpenGLShaderPass

protected:

#if 0
void setupTextureMatrix(GLenum textureUnit, const IShaderLayer::Ptr& stage);

#endif
// Render all of the given TransformedRenderables
void drawRenderables(OpenGLState& current);

/* Helper functions to enable/disable particular GL states */

#if 0
void setTexture0();

void enableTexture2D();
void disableTexture2D();

#endif
#if 0
void enableTextureCubeMap();
void disableTextureCubeMap();

void enableRenderBlend();
void disableRenderBlend();

// Apply all OpenGLState textures to texture units
void applyAllTextures(OpenGLState& current, unsigned requiredState);
#endif

#if 0
virtual void activateShaderProgram(OpenGLState& current);
virtual void deactivateShaderProgram(OpenGLState& current);

#endif
public:

OpenGLShaderPass(OpenGLShader& owner) :
Expand Down

0 comments on commit 009ac16

Please sign in to comment.