Skip to content
Permalink
Browse files

- remove IShaderProgram and make the old classes an implementation de…

…tail of the OpenGL backend. In the long run they should be removed completely as their weird design is mostly an artifact of once having supported OpenGL 2
  • Loading branch information...
dpjudas committed Mar 12, 2019
1 parent 903f8b6 commit e5e9924c5e14138081f0f4d9d5df414e2e36ea66
@@ -1073,9 +1073,6 @@ set (PCH_SOURCES
rendering/hwrenderer/postprocessing/hw_postprocess.cpp
rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp
rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp
rendering/hwrenderer/postprocessing/hw_shadowmapshader.cpp
rendering/hwrenderer/postprocessing/hw_presentshader.cpp
rendering/hwrenderer/postprocessing/hw_present3dRowshader.cpp
rendering/hwrenderer/textures/hw_material.cpp
rendering/hwrenderer/textures/hw_precache.cpp
rendering/hwrenderer/utility/hw_clock.cpp
@@ -38,7 +38,7 @@
#include "gl/renderer/gl_renderbuffers.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_postprocessstate.h"
#include "hwrenderer/postprocessing/hw_presentshader.h"
#include "gl/shaders/gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_postprocess.h"
#include "hwrenderer/postprocessing/hw_postprocess_cvars.h"
#include "hwrenderer/utility/hw_vrmodes.h"
@@ -220,7 +220,7 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}

mPresentShader->Bind(NOQUEUE);
mPresentShader->Bind();
if (!applyGamma || framebuffer->IsHWGammaActive())
{
mPresentShader->Uniforms->InvGamma = 1.0f;
@@ -861,8 +861,8 @@ void FGLRenderBuffers::CompileEffectShaders()
prolog = UniformBlockDecl::Create("Uniforms", desc.Uniforms, POSTPROCESS_BINDINGPOINT);
prolog += desc.Defines;

glshader->Compile(IShaderProgram::Vertex, desc.VertexShader, "", desc.Version);
glshader->Compile(IShaderProgram::Fragment, desc.FragmentShader, prolog, desc.Version);
glshader->Compile(FShaderProgram::Vertex, desc.VertexShader, "", desc.Version);
glshader->Compile(FShaderProgram::Fragment, desc.FragmentShader, prolog, desc.Version);
glshader->Link(pair->Key.GetChars());
if (!desc.Uniforms.empty())
glshader->SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms");
@@ -987,7 +987,7 @@ void FGLRenderBuffers::RenderEffect(const FString &name)
}

// Set shader
shader->Bind(NOQUEUE);
shader->Bind();

// Draw the screen quad
GLRenderer->RenderScreenQuad();
@@ -47,10 +47,8 @@
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderstate.h"
#include "gl/renderer/gl_renderbuffers.h"
#include "gl/shaders/gl_shaderprogram.h"
#include "hwrenderer/utility/hw_vrmodes.h"
#include "hwrenderer/postprocessing/hw_presentshader.h"
#include "hwrenderer/postprocessing/hw_present3dRowshader.h"
#include "hwrenderer/postprocessing/hw_shadowmapshader.h"
#include "hwrenderer/data/flatvertices.h"
#include "hwrenderer/scene/hw_skydome.h"
#include "hwrenderer/scene/hw_fakeflat.h"
@@ -198,7 +196,7 @@ void FGLRenderer::UpdateShadowMap()

mBuffers->BindShadowMapFB();

mShadowMapShader->Bind(NOQUEUE);
mShadowMapShader->Bind();
mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality;
mShadowMapShader->Uniforms.Set();

@@ -24,25 +24,23 @@ class HWPortal;
class FLightBuffer;
class DPSprite;
class FGLRenderBuffers;
class FPresentShader;
class FPresent3DCheckerShader;
class FPresent3DColumnShader;
class FPresent3DRowShader;
class FGL2DDrawer;
class FHardwareTexture;
class FShadowMapShader;
class SWSceneDrawer;
class GLViewpointBuffer;
struct FRenderViewpoint;
class FPresentShaderBase;

namespace OpenGLRenderer
{
class FSamplerManager;
class FCustomPostProcessShaders;
class OpenGLFrameBuffer;

#define NOQUEUE nullptr // just some token to be used as a placeholder
class FPresentShaderBase;
class FPresentShader;
class FPresent3DCheckerShader;
class FPresent3DColumnShader;
class FPresent3DRowShader;
class FShadowMapShader;

class FGLRenderer
{
@@ -32,8 +32,7 @@
#include "gl/system/gl_framebuffer.h"
#include "gl/renderer/gl_postprocessstate.h"
#include "gl/system/gl_framebuffer.h"
#include "hwrenderer/postprocessing/hw_presentshader.h"
#include "hwrenderer/postprocessing/hw_present3dRowshader.h"
#include "gl/shaders/gl_shaderprogram.h"
#include "menu/menu.h"

EXTERN_CVAR(Int, vr_mode)
@@ -151,7 +150,7 @@ void FGLRenderer::prepareInterleavedPresent(FPresentShaderBase& shader)
const IntRect& box = screen->mOutputLetterbox;
glViewport(box.left, box.top, box.width, box.height);

shader.Bind(NOQUEUE);
shader.Bind();

if (framebuffer->IsHWGammaActive())
{
@@ -59,7 +59,7 @@ void FCustomPostProcessShaders::Run(FString target)
{
if (shader->Desc->Target == target)
{
shader->Run(NOQUEUE);
shader->Run();
}
}
}
@@ -72,7 +72,7 @@ PostProcessShaderInstance::~PostProcessShaderInstance()
glDeleteTextures(1, (GLuint*)&it.second);
}

void PostProcessShaderInstance::Run(IRenderQueue *q)
void PostProcessShaderInstance::Run()
{
if (!IsShaderSupported())
return;
@@ -92,7 +92,7 @@ void PostProcessShaderInstance::Run(IRenderQueue *q)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

mProgram.Bind(q);
mProgram.Bind();

UpdateUniforms();
BindTextures();
@@ -168,8 +168,8 @@ void PostProcessShaderInstance::CompileShader()
prolog += uniformTextures;
prolog += pipelineInOut;

mProgram.Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", Desc->ShaderVersion);
mProgram.Compile(IShaderProgram::Fragment, lumpName, code, prolog.GetChars(), Desc->ShaderVersion);
mProgram.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", Desc->ShaderVersion);
mProgram.Compile(FShaderProgram::Fragment, lumpName, code, prolog.GetChars(), Desc->ShaderVersion);
mProgram.Link(Desc->ShaderLumpName.GetChars());
mInputTexture.Init(mProgram.Handle(), "InputTexture");
}
@@ -15,7 +15,7 @@ class PostProcessShaderInstance
PostProcessShaderInstance(PostProcessShader *desc) : Desc(desc) { }
~PostProcessShaderInstance();

void Run(IRenderQueue *q);
void Run();

PostProcessShader *Desc;

@@ -221,7 +221,7 @@ void FShaderProgram::SetUniformBufferLocation(int index, const char *name)
//
//==========================================================================

void FShaderProgram::Bind(IRenderQueue *)
void FShaderProgram::Bind()
{
glUseProgram(mProgram);
}
@@ -295,4 +295,74 @@ FString FShaderProgram::PatchShader(ShaderType type, const FString &code, const
return patchedCode;
}

/////////////////////////////////////////////////////////////////////////////

void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program_name)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", PresentUniforms::Desc());

mShader.reset(new FShaderProgram());
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", prolog, 330);
mShader->Compile(FShaderProgram::Fragment, vtx_shader_name, prolog, 330);
mShader->Link(program_name);
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}

void FPresentShader::Bind()
{
if (!mShader)
{
Init("shaders/glsl/present.fp", "shaders/glsl/present");
}
mShader->Bind();
}

/////////////////////////////////////////////////////////////////////////////

void FPresent3DCheckerShader::Bind()
{
if (!mShader)
{
Init("shaders/glsl/present_checker3d.fp", "shaders/glsl/presentChecker3d");
}
mShader->Bind();
}

void FPresent3DColumnShader::Bind()
{
if (!mShader)
{
Init("shaders/glsl/present_column3d.fp", "shaders/glsl/presentColumn3d");
}
mShader->Bind();
}

void FPresent3DRowShader::Bind()
{
if (!mShader)
{
Init("shaders/glsl/present_row3d.fp", "shaders/glsl/presentRow3d");
}
mShader->Bind();
}

/////////////////////////////////////////////////////////////////////////////

void FShadowMapShader::Bind()
{
if (!mShader)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", ShadowMapUniforms::Desc());

mShader.reset(new FShaderProgram());
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 430);
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", prolog, 430);
mShader->Link("shaders/glsl/shadowmap");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
mShader->Bind();
}

}
@@ -3,23 +3,30 @@

#include "gl_load/gl_system.h"
#include "gl_shader.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_postprocess.h"

namespace OpenGLRenderer
{

class FShaderProgram : public IShaderProgram
class FShaderProgram
{
public:
FShaderProgram();
~FShaderProgram();

void Compile(ShaderType type, const char *lumpName, const char *defines, int maxGlslVersion) override;
void Compile(ShaderType type, const char *name, const FString &code, const char *defines, int maxGlslVersion) override;
enum ShaderType
{
Vertex,
Fragment,
NumShaderTypes
};

void Compile(ShaderType type, const char *lumpName, const char *defines, int maxGlslVersion);
void Compile(ShaderType type, const char *name, const FString &code, const char *defines, int maxGlslVersion);
void Link(const char *name);
void SetUniformBufferLocation(int index, const char *name);

void Bind(IRenderQueue *q) override; // the parameter here is just a preparation for Vulkan
void Bind();

GLuint Handle() { return mProgram; }
//explicit operator bool() const { return mProgram != 0; }
@@ -44,4 +51,53 @@ class FShaderProgram : public IShaderProgram
TArray<std::pair<FString, int>> samplerstobind;
};

class FPresentShaderBase
{
public:
virtual ~FPresentShaderBase() {}
virtual void Bind() = 0;

ShaderUniforms<PresentUniforms, POSTPROCESS_BINDINGPOINT> Uniforms;

protected:
virtual void Init(const char * vtx_shader_name, const char * program_name);
std::unique_ptr<FShaderProgram> mShader;
};

class FPresentShader : public FPresentShaderBase
{
public:
void Bind() override;

};

class FPresent3DCheckerShader : public FPresentShaderBase
{
public:
void Bind() override;
};

class FPresent3DColumnShader : public FPresentShaderBase
{
public:
void Bind() override;
};

class FPresent3DRowShader : public FPresentShaderBase
{
public:
void Bind() override;
};

class FShadowMapShader
{
public:
void Bind();

ShaderUniforms<ShadowMapUniforms, POSTPROCESS_BINDINGPOINT> Uniforms;

private:
std::unique_ptr<FShaderProgram> mShader;
};

}
@@ -325,11 +325,6 @@ FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
return new FGLModelRenderer(nullptr, gl_RenderState, mli);
}

IShaderProgram *OpenGLFrameBuffer::CreateShaderProgram()
{
return new FShaderProgram;
}

IVertexBuffer *OpenGLFrameBuffer::CreateVertexBuffer()
{
return new GLVertexBuffer;
@@ -37,7 +37,6 @@ class OpenGLFrameBuffer : public SystemGLFrameBuffer
void BeginFrame() override;
void SetViewportRects(IntRect *bounds) override;
void BlurScene(float amount) override;
IShaderProgram *CreateShaderProgram() override;
IVertexBuffer *CreateVertexBuffer() override;
IIndexBuffer *CreateIndexBuffer() override;
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override;
Oops, something went wrong.

0 comments on commit e5e9924

Please sign in to comment.
You can’t perform that action at this time.