Skip to content

Commit

Permalink
#5909: Replace gl_ModelViewProjectionMatrix with a custom uniform set…
Browse files Browse the repository at this point in the history
… by the code. This allows us to update the GLSL version to 140.
  • Loading branch information
codereader committed Mar 13, 2022
1 parent b7d604f commit 95021ea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions install/gl/zfill_vp.glsl
@@ -1,8 +1,9 @@
#version 120
#version 140

in vec4 attr_Position; // bound to attribute 0 in source, in object space
in vec4 attr_TexCoord; // bound to attribute 8 in source

uniform mat4 u_ModelViewProjection; // combined modelview and projection matrix
uniform mat4 u_ObjectTransform; // object transform (object2world)

// The two top-rows of the diffuse stage texture transformation matrix
Expand All @@ -15,7 +16,7 @@ void main()
{
// Apply the supplied object transform to the incoming vertex
// transform vertex position into homogenous clip-space
gl_Position = gl_ModelViewProjectionMatrix * u_ObjectTransform * attr_Position;
gl_Position = u_ModelViewProjection * u_ObjectTransform * attr_Position;

// Apply the stage texture transform to the incoming tex coord, component wise
var_TexDiffuse.x = dot(u_DiffuseTextureMatrix[0], attr_TexCoord);
Expand Down
3 changes: 3 additions & 0 deletions radiantcore/rendersystem/backend/LightInteractions.cpp
Expand Up @@ -81,6 +81,9 @@ void LightInteractions::fillDepthBuffer(OpenGLState& state, RenderStateFlags glo

auto depthFillProgram = depthFillPass->getDepthFillProgram();

// Set the modelview and projection matrix
depthFillProgram.setModelViewProjection(view.GetViewProjection());

// Set the stage texture transformation matrix to the GLSL uniform
// Since the texture matrix just needs 6 active components, we use two vec3
if (depthFillPass->state().stage0)
Expand Down
Expand Up @@ -33,6 +33,7 @@ void GLSLDepthFillAlphaProgram::create()

_locAlphaTest = glGetUniformLocation(_programObj, "u_AlphaTest");
_locObjectTransform = glGetUniformLocation(_programObj, "u_ObjectTransform");
_locModelViewProjection = glGetUniformLocation(_programObj, "u_ModelViewProjection");
_locDiffuseTextureMatrix = glGetUniformLocation(_programObj, "u_DiffuseTextureMatrix");

glUseProgram(_programObj);
Expand Down Expand Up @@ -75,6 +76,11 @@ void GLSLDepthFillAlphaProgram::applyAlphaTest(float alphaTest)
debug::assertNoGlErrors();
}

void GLSLDepthFillAlphaProgram::setModelViewProjection(const Matrix4& modelViewProjection)
{
loadMatrixUniform(_locModelViewProjection, modelViewProjection);
}

void GLSLDepthFillAlphaProgram::setObjectTransform(const Matrix4& transform)
{
loadMatrixUniform(_locObjectTransform, transform);
Expand Down
Expand Up @@ -11,13 +11,15 @@ class GLSLDepthFillAlphaProgram :
private:
GLint _locAlphaTest;
GLint _locObjectTransform;
GLint _locModelViewProjection;
GLint _locDiffuseTextureMatrix;

public:
void create() override;
void enable() override;
void disable() override;

void setModelViewProjection(const Matrix4& modelViewProjection);
void setObjectTransform(const Matrix4& transform);
void setDiffuseTextureTransform(const Matrix4& transform);

Expand Down

0 comments on commit 95021ea

Please sign in to comment.