Skip to content

Commit

Permalink
#219: Clean up GLSL program classes and interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 26, 2022
1 parent 8a6ee4d commit a22844c
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 92 deletions.
65 changes: 3 additions & 62 deletions include/iglprogram.h
@@ -1,9 +1,6 @@
#pragma once

#include "math/Vector3.h"
#include "math/Matrix4.h"
#include "render/Colour4.h"
#include "ishaderlayer.h"
class Matrix4;

/**
* Representation of a GL vertex/fragment program.
Expand All @@ -17,7 +14,7 @@ class GLProgram
virtual ~GLProgram() {}

/**
* Create this program using glGenProgramsARB and siblings. This needs the
* Create this program using glGenPrograms and siblings. This needs the
* OpenGL system to be initialised so cannot happen in the constructor.
*/
virtual void create() = 0;
Expand All @@ -35,63 +32,7 @@ class GLProgram
/**
* Unbind this program from OpenGL.
*/
virtual void disable() = 0;

/// Data structure containing rendering parameters
struct Params
{
#if 0
IShaderLayer::VertexColourMode vertexColourMode;

// Colour defined by the stage's rgba registers
Colour4 stageColour;
#endif
/// Light origin in world space
Vector3 lightOrigin;

/// Light colour
//Colour4 lightColour;

/// Transformation from world space into light space
Matrix4 world2Light;
#if 0
/// True if this is an ambient light, false for a directional light
bool isAmbientLight = false;
#endif
Params(/*IShaderLayer::VertexColourMode vertexColourMode_,
const Colour4& stageColour_,*/
const Vector3& lightOrigin_,
//const Colour4& lightColour_,
const Matrix4& world2Light_)
: /*vertexColourMode(vertexColourMode_),
stageColour(stageColour_),*/
lightOrigin(lightOrigin_),
//lightColour(lightColour_),
world2Light(world2Light_)
{}
};

/**
* \brief Apply render parameters used by this program to OpenGL.
*
* This method is invoked shortly before the renderable geometry is
* submitted for rendering; the GLProgram must apply to the GL state any
* parameters it uses.
*
* \param viewer
* Location of the viewer in object space.
*
* \param localToWorld
* Local to world transformation matrix.
*
* \param lightParms
* Params structure containing lighting information.
*
*/
virtual void applyRenderParams(const Vector3& viewer,
const Matrix4& localToWorld,
const Params& lightParms)
{ }
virtual void disable() = 0;
};

// Interface implemented by GLSL programs supporting alpha test
Expand Down
7 changes: 4 additions & 3 deletions radiantcore/rendersystem/backend/LightingModeRenderer.cpp
Expand Up @@ -7,6 +7,7 @@
#include "OpenGLShader.h"
#include "ObjectRenderer.h"
#include "OpenGLState.h"
#include "glprogram/GLSLCubeMapProgram.h"
#include "glprogram/GLSLDepthFillAlphaProgram.h"
#include "glprogram/InteractionProgram.h"

Expand Down Expand Up @@ -233,7 +234,7 @@ void LightingModeRenderer::drawShadowMaps(OpenGLState& current,std::size_t rende
glEnable(GL_CLIP_DISTANCE2);
glEnable(GL_CLIP_DISTANCE3);

glViewport(0, 0, _shadowMapFbo->getWidth(), _shadowMapFbo->getHeight());
glViewport(0, 0, static_cast<GLsizei>(_shadowMapFbo->getWidth()), static_cast<GLsizei>(_shadowMapFbo->getHeight()));
glClear(GL_DEPTH_BUFFER_BIT);

// Render shadow casting lights to the shadow map buffer, up to MaxShadowLightCount
Expand Down Expand Up @@ -340,9 +341,9 @@ void LightingModeRenderer::drawNonInteractionPasses(OpenGLState& current, Render
// Apply our state to the current state object
pass.evaluateStagesAndApplyState(current, globalFlagsMask, time, entity.get());

if (current.glProgram)
if (dynamic_cast<GLSLCubeMapProgram*>(current.glProgram))
{
OpenGLShaderPass::SetUpNonInteractionProgram(current, view.getViewer(), object->getObjectTransform());
static_cast<GLSLCubeMapProgram*>(current.glProgram)->setViewer(view.getViewer());
}

ObjectRenderer::SubmitObject(*object, _geometryStore);
Expand Down
8 changes: 0 additions & 8 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.cpp
Expand Up @@ -118,14 +118,6 @@ bool OpenGLShaderPass::stateIsActive()
(_glState.stage3 == NULL || _glState.stage3->isVisible()));
}

void OpenGLShaderPass::SetUpNonInteractionProgram(OpenGLState& current, const Vector3& viewer, const Matrix4& objTransform)
{
static GLProgram::Params parms({ 0, 0, 0 }, Matrix4::getIdentity());

assert(current.glProgram);
current.glProgram->applyRenderParams(viewer, objTransform, parms);
}

void OpenGLShaderPass::drawRenderables(OpenGLState& current)
{
if (_transformedRenderables.empty()) return;
Expand Down
4 changes: 0 additions & 4 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.h
@@ -1,13 +1,11 @@
#pragma once

#include "math/Vector3.h"
#include "math/Matrix4.h"
#include "OpenGLState.h"

#include <vector>

/* FORWARD DECLS */
class Matrix4;
class OpenGLRenderable;
class RendererLight;

Expand Down Expand Up @@ -140,8 +138,6 @@ class OpenGLShaderPass
// Evaluates the time- and entity-dependent expressions in the shader stages
void evaluateShaderStages(std::size_t time, const IRenderEntity* entity);

static void SetUpNonInteractionProgram(OpenGLState& current, const Vector3& viewer, const Matrix4& objTransform);

friend std::ostream& operator<<(std::ostream& st, const OpenGLShaderPass& self);
};

Expand Down
Expand Up @@ -71,7 +71,7 @@ void GLSLCubeMapProgram::disable()
debug::assertNoGlErrors();
}

void GLSLCubeMapProgram::applyRenderParams(const Vector3& viewer, const Matrix4&, const Params&)
void GLSLCubeMapProgram::setViewer(const Vector3& viewer)
{
// Pass the current viewer origin to the shader
glUniform3f(_locViewOrigin,
Expand Down
@@ -1,6 +1,5 @@
#pragma once

#include "GLProgramAttributes.h"
#include "GLSLProgramBase.h"

namespace render
Expand All @@ -23,8 +22,7 @@ class GLSLCubeMapProgram :
void enable() override;
void disable() override;

void applyRenderParams(const Vector3& viewer, const Matrix4& localToWorld,
const Params&) override;
void setViewer(const Vector3& viewer);
};

} // namespace render
Expand Down
@@ -1,6 +1,5 @@
#pragma once

#include "GLProgramAttributes.h"
#include "iglprogram.h"
#include "igl.h"

Expand All @@ -27,11 +26,6 @@ class GenericVFPProgram :
void destroy() override;
void enable() override;
void disable() override;

// Set render pass parameters
void applyRenderParams(const Vector3& viewer,
const Matrix4& localToWorld,
const Params& lightParams) override;
};

} // namespace render
Expand Up @@ -52,11 +52,6 @@ class InteractionProgram :
// The stage's vertex colour mode and colour as defined by the rgba registers
void setStageVertexColour(IShaderLayer::VertexColourMode vertexColourMode, const Colour4& stageColour);

void applyRenderParams(const Vector3& viewer,
const Matrix4& localToWorld,
const Params& lightParms) override
{ }

void setupLightParameters(OpenGLState& state, const RendererLight& light, std::size_t renderTime);

void setUpObjectLighting(const Vector3& worldLightOrigin,
Expand Down

0 comments on commit a22844c

Please sign in to comment.