- use FShaderProgram through an abstract interface and remove all dependencies on the GL renderer from the shader definition source files.

This commit is contained in:
Christoph Oelckers 2018-06-13 22:08:55 +02:00
parent 8bf009bd89
commit 3401876476
30 changed files with 190 additions and 158 deletions

View file

@ -30,6 +30,7 @@
#include "gl/dynlights/gl_lightbuffer.h"
#include "hwrenderer/utility/hw_clock.h"
#include "hwrenderer/dynlights/hw_dynlightdata.h"
#include "hwrenderer/data/shaderuniforms.h"
static const int INITIAL_BUFFER_SIZE = 160000; // This means 80000 lights per frame and 160000*16 bytes == 2.56 MB.

View file

@ -20,10 +20,9 @@
//--------------------------------------------------------------------------
//
#include "gl_load/gl_system.h"
#include "v_video.h"
#include "hwrenderer/utility/hw_cvars.h"
#include "gl/shaders/gl_ambientshader.h"
#include "gl_ambientshader.h"
void FLinearDepthShader::Bind(IRenderQueue *q)
{
@ -36,9 +35,9 @@ void FLinearDepthShader::Bind(IRenderQueue *q)
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
if (multisample) prolog += "#define MULTISAMPLE\n";
mShader.reset(new FShaderProgram());
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/lineardepth.fp", prolog, 330);
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/lineardepth.fp", prolog, 330);
mShader->Link("shaders/glsl/lineardepth");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
@ -58,9 +57,9 @@ void FSSAOShader::Bind(IRenderQueue *q)
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
prolog += GetDefines(gl_ssao, multisample);
mShader.reset(new FShaderProgram());
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/ssao.fp", prolog, 330);
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/ssao.fp", prolog, 330);
mShader->Link("shaders/glsl/ssao");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
@ -105,13 +104,14 @@ void FDepthBlurShader::Bind(IRenderQueue *q, bool vertical)
else
prolog += "#define BLUR_HORIZONTAL\n";
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/depthblur.fp", prolog, 330);
shader.Link("shaders/glsl/depthblur");
shader.SetUniformBufferLocation(Uniforms[vertical].BindingPoint(), "Uniforms");
shader.reset(screen->CreateShaderProgram());
shader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader->Compile(IShaderProgram::Fragment, "shaders/glsl/depthblur.fp", prolog, 330);
shader->Link("shaders/glsl/depthblur");
shader->SetUniformBufferLocation(Uniforms[vertical].BindingPoint(), "Uniforms");
Uniforms[vertical].Init();
}
shader.Bind(q);
shader->Bind(q);
}
void FSSAOCombineShader::Bind(IRenderQueue *q)
@ -126,9 +126,9 @@ void FSSAOCombineShader::Bind(IRenderQueue *q)
if (multisample)
prolog += "#define MULTISAMPLE\n";
mShader.reset(new FShaderProgram());
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/ssaocombine.fp", prolog, 330);
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/ssaocombine.fp", prolog, 330);
mShader->Link("shaders/glsl/ssaocombine");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();

View file

@ -1,9 +1,7 @@
#ifndef __GL_AMBIENTSHADER_H
#define __GL_AMBIENTSHADER_H
#include <memory>
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FLinearDepthShader
{
@ -42,7 +40,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
std::unique_ptr<FShaderProgram> mShader;
std::unique_ptr<IShaderProgram> mShader;
bool mMultisample = false;
};
@ -101,7 +99,7 @@ private:
FString GetDefines(int mode, bool multisample);
std::unique_ptr<FShaderProgram> mShader;
std::unique_ptr<IShaderProgram> mShader;
Quality mCurrentQuality = Off;
bool mMultisample = false;
};
@ -131,7 +129,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms[2];
private:
FShaderProgram mShader[2];
std::unique_ptr<IShaderProgram> mShader[2];
};
class FSSAOCombineShader
@ -163,7 +161,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
std::unique_ptr<FShaderProgram> mShader;
std::unique_ptr<IShaderProgram> mShader;
bool mMultisample = false;
};

View file

@ -25,7 +25,6 @@
**
*/
#include "gl_load/gl_system.h"
#include "v_video.h"
#include "gl/shaders/gl_bloomshader.h"
@ -35,22 +34,24 @@ void FBloomExtractShader::Bind(IRenderQueue *q)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/bloomextract.fp", prolog, 330);
mShader.Link("shaders/glsl/bloomextract");
mShader.SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/bloomextract.fp", prolog, 330);
mShader->Link("shaders/glsl/bloomextract");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
mShader.Bind(q);
mShader->Bind(q);
}
void FBloomCombineShader::Bind(IRenderQueue *q)
{
if (!mShader)
{
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/bloomcombine.fp", "", 330);
mShader.Link("shaders/glsl/bloomcombine");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/bloomcombine.fp", "", 330);
mShader->Link("shaders/glsl/bloomcombine");
}
mShader.Bind(q);
mShader->Bind(q);
}

View file

@ -1,7 +1,7 @@
#ifndef __GL_BLOOMSHADER_H
#define __GL_BLOOMSHADER_H
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FBloomExtractShader
{
@ -26,7 +26,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
class FBloomCombineShader
@ -35,7 +35,7 @@ public:
void Bind(IRenderQueue *q);
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
#endif

View file

@ -25,12 +25,8 @@
**
*/
#include "gl_load/gl_system.h"
#include "v_video.h"
#include "gl/shaders/gl_blurshader.h"
#include "gl/data/gl_vertexbuffer.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderbuffers.h"
void FBlurShader::Bind(IRenderQueue *q, bool vertical)
{
@ -42,12 +38,13 @@ void FBlurShader::Bind(IRenderQueue *q, bool vertical)
else
prolog += "#define BLUR_HORIZONTAL\n";
mShader[vertical].Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader[vertical].Compile(FShaderProgram::Fragment, "shaders/glsl/blur.fp", prolog, 330);
mShader[vertical].Link("shaders/glsl/blur");
mShader[vertical].SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms");
mShader[vertical].reset(screen->CreateShaderProgram());
mShader[vertical]->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader[vertical]->Compile(IShaderProgram::Fragment, "shaders/glsl/blur.fp", prolog, 330);
mShader[vertical]->Link("shaders/glsl/blur");
mShader[vertical]->SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms");
Uniforms[vertical].Init();
}
mShader[vertical].Bind(q);
mShader[vertical]->Bind(q);
}

View file

@ -1,8 +1,7 @@
#pragma once
#include "gl_shaderprogram.h"
#include <memory>
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FGLRenderer;
class PPFrameBuffer;
@ -36,5 +35,5 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms[2];
private:
FShaderProgram mShader[2];
std::unique_ptr<IShaderProgram> mShader[2];
};

View file

@ -25,22 +25,21 @@
**
*/
#include "gl_load/gl_system.h"
#include "v_video.h"
#include "gl/shaders/gl_colormapshader.h"
void FColormapShader::Bind(IRenderQueue *q)
{
auto &shader = mShader;
if (!shader)
if (!mShader)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/colormap.fp", prolog, 330);
shader.Link("shaders/glsl/colormap");
shader.SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/colormap.fp", prolog, 330);
mShader->Link("shaders/glsl/colormap");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
shader.Bind(q);
mShader->Bind(q);
}

View file

@ -1,7 +1,7 @@
#ifndef __GL_COLORMAPSHADER_H
#define __GL_COLORMAPSHADER_H
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FColormapShader
{
@ -27,7 +27,7 @@ public:
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
#endif

View file

@ -24,7 +24,6 @@
// Fast approXimate Anti-Aliasing (FXAA) post-processing
//
#include "gl_load/gl_system.h"
#include "gl/shaders/gl_fxaashader.h"
EXTERN_CVAR(Int, gl_fxaa)
@ -33,17 +32,18 @@ void FFXAALumaShader::Bind(IRenderQueue *q)
{
if (!mShader)
{
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/fxaa.fp", "#define FXAA_LUMA_PASS\n", 330);
mShader.Link("shaders/glsl/fxaa");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/fxaa.fp", "#define FXAA_LUMA_PASS\n", 330);
mShader->Link("shaders/glsl/fxaa");
}
mShader.Bind(q);
mShader->Bind(q);
}
static int GetMaxVersion()
{
return gl.glslversion >= 4.f ? 400 : 330;
return screen->glslversion >= 4.f ? 400 : 330;
}
static FString GetDefines()
@ -76,19 +76,20 @@ static FString GetDefines()
void FFXAAShader::Bind(IRenderQueue *q)
{
assert(gl_fxaa > 0 && gl_fxaa < Count);
FShaderProgram &shader = mShaders[gl_fxaa];
auto &shader = mShaders[gl_fxaa];
if (!shader)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc()) + GetDefines();
const int maxVersion = GetMaxVersion();
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/fxaa.fp", prolog, maxVersion);
shader.Link("shaders/glsl/fxaa");
shader.SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
shader.reset(screen->CreateShaderProgram());
shader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", maxVersion);
shader->Compile(IShaderProgram::Fragment, "shaders/glsl/fxaa.fp", prolog, maxVersion);
shader->Link("shaders/glsl/fxaa");
shader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
shader.Bind(q);
shader->Bind(q);
}

View file

@ -27,7 +27,7 @@
#ifndef __GL_FXAASHADER_H__
#define __GL_FXAASHADER_H__
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_postprocess_cvars.h"
class FFXAALumaShader
@ -36,7 +36,7 @@ public:
void Bind(IRenderQueue *q);
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
@ -64,7 +64,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
FShaderProgram mShaders[Count];
std::unique_ptr<IShaderProgram> mShaders[Count];
};
#endif // __GL_FXAASHADER_H__

View file

@ -25,7 +25,6 @@
**
*/
#include "gl_load/gl_system.h"
#include "v_video.h"
#include "gl/shaders/gl_lensshader.h"
@ -35,11 +34,12 @@ void FLensShader::Bind(IRenderQueue *q)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/lensdistortion.fp", prolog, 330);
mShader.Link("shaders/glsl/lensdistortion");
mShader.SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/lensdistortion.fp", prolog, 330);
mShader->Link("shaders/glsl/lensdistortion");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
mShader.Bind(q);
mShader->Bind(q);
}

View file

@ -1,7 +1,7 @@
#ifndef __GL_LENSSHADER_H
#define __GL_LENSSHADER_H
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FLensShader
{
@ -33,7 +33,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
#endif

View file

@ -111,7 +111,7 @@ bool PostProcessShaderInstance::IsShaderSupported()
void PostProcessShaderInstance::CompileShader()
{
if (mProgram)
if (mProgram.Handle())
return;
// Get the custom shader
@ -164,10 +164,10 @@ void PostProcessShaderInstance::CompileShader()
prolog += uniformTextures;
prolog += pipelineInOut;
mProgram.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", Desc->ShaderVersion);
mProgram.Compile(FShaderProgram::Fragment, lumpName, code, prolog.GetChars(), Desc->ShaderVersion);
mProgram.Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", Desc->ShaderVersion);
mProgram.Compile(IShaderProgram::Fragment, lumpName, code, prolog.GetChars(), Desc->ShaderVersion);
mProgram.Link(Desc->ShaderLumpName.GetChars());
mInputTexture.Init(mProgram, "InputTexture");
mInputTexture.Init(mProgram.Handle(), "InputTexture");
}
void PostProcessShaderInstance::UpdateUniforms()
@ -176,7 +176,7 @@ void PostProcessShaderInstance::UpdateUniforms()
TMap<FString, PostProcessUniformValue>::Pair *pair;
while (it.NextPair(pair))
{
int location = glGetUniformLocation(mProgram, pair->Key.GetChars());
int location = glGetUniformLocation(mProgram.Handle(), pair->Key.GetChars());
if (location != -1)
{
switch (pair->Value.Type)
@ -207,7 +207,7 @@ void PostProcessShaderInstance::BindTextures()
TMap<FString, FString>::Pair *pair;
while (it.NextPair(pair))
{
int location = glGetUniformLocation(mProgram, pair->Key.GetChars());
int location = glGetUniformLocation(mProgram.Handle(), pair->Key.GetChars());
if (location == -1)
continue;

View file

@ -36,7 +36,7 @@ void FPresent3DCheckerShader::Bind(IRenderQueue *q)
{
Init("shaders/glsl/present_checker3d.fp", "shaders/glsl/presentChecker3d");
}
mShader.Bind(q);
mShader->Bind(q);
}
void FPresent3DColumnShader::Bind(IRenderQueue *q)
@ -45,7 +45,7 @@ void FPresent3DColumnShader::Bind(IRenderQueue *q)
{
Init("shaders/glsl/present_column3d.fp", "shaders/glsl/presentColumn3d");
}
mShader.Bind(q);
mShader->Bind(q);
}
void FPresent3DRowShader::Bind(IRenderQueue *q)
@ -54,5 +54,5 @@ void FPresent3DRowShader::Bind(IRenderQueue *q)
{
Init("shaders/glsl/present_row3d.fp", "shaders/glsl/presentRow3d");
}
mShader.Bind(q);
mShader->Bind(q);
}

View file

@ -25,7 +25,6 @@
**
*/
#include "gl_load/gl_system.h"
#include "v_video.h"
#include "gl/shaders/gl_presentshader.h"
@ -33,10 +32,11 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", prolog, 330);
mShader.Compile(FShaderProgram::Fragment, vtx_shader_name, prolog, 330);
mShader.Link(program_name);
mShader.SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", prolog, 330);
mShader->Compile(IShaderProgram::Fragment, vtx_shader_name, prolog, 330);
mShader->Link(program_name);
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
@ -46,5 +46,5 @@ void FPresentShader::Bind(IRenderQueue *q)
{
Init("shaders/glsl/present.fp", "shaders/glsl/present");
}
mShader.Bind(q);
mShader->Bind(q);
}

View file

@ -1,7 +1,7 @@
#ifndef __GL_PRESENTSHADER_H
#define __GL_PRESENTSHADER_H
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FPresentShaderBase
{
@ -38,7 +38,7 @@ public:
protected:
virtual void Init(const char * vtx_shader_name, const char * program_name);
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
class FPresentShader : public FPresentShaderBase

View file

@ -33,6 +33,7 @@
#include "doomerrors.h"
#include "cmdlib.h"
#include "hwrenderer/utility/hw_shaderpatcher.h"
#include "hwrenderer/data/shaderuniforms.h"
#include "gl_load/gl_interface.h"
#include "gl/system/gl_debug.h"

View file

@ -382,11 +382,5 @@ public:
}
};
enum
{
LIGHTBUF_BINDINGPOINT = 1,
POSTPROCESS_BINDINGPOINT = 2
};
#endif

View file

@ -3,32 +3,23 @@
#include "gl_load/gl_system.h"
#include "gl_shader.h"
#include "hwrenderer/data/shaderuniforms.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class IRenderQueue;
class FShaderProgram
class FShaderProgram : public IShaderProgram
{
public:
FShaderProgram();
~FShaderProgram();
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 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;
void Link(const char *name);
void SetUniformBufferLocation(int index, const char *name);
void Bind(IRenderQueue *q); // the parameter here is just a preparation for Vulkan
void Bind(IRenderQueue *q) override; // the parameter here is just a preparation for Vulkan
operator GLuint() const { return mProgram; }
explicit operator bool() const { return mProgram != 0; }
GLuint Handle() { return mProgram; }
//explicit operator bool() const { return mProgram != 0; }
private:
FShaderProgram(const FShaderProgram &) = delete;

View file

@ -20,7 +20,6 @@
//--------------------------------------------------------------------------
//
#include "gl_load/gl_system.h"
#include "files.h"
#include "gl/shaders/gl_shadowmapshader.h"
@ -30,11 +29,12 @@ void FShadowMapShader::Bind(IRenderQueue *q)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
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");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 430);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", prolog, 430);
mShader->Link("shaders/glsl/shadowmap");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
mShader.Bind(q);
mShader->Bind(q);
}

View file

@ -1,7 +1,7 @@
#ifndef __GL_SHADOWMAPSHADER_H
#define __GL_SHADOWMAPSHADER_H
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FShadowMapShader
{
@ -28,7 +28,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
#endif

View file

@ -25,7 +25,6 @@
**
*/
#include "gl_load/gl_system.h"
#include "v_video.h"
#include "hwrenderer/utility/hw_cvars.h"
#include "gl/shaders/gl_tonemapshader.h"
@ -37,11 +36,12 @@ void FTonemapShader::Bind(IRenderQueue *q)
{
auto prolog = GetDefines(gl_tonemap);
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/tonemap.fp", prolog, 330);
shader.Link("shaders/glsl/tonemap");
shader.reset(screen->CreateShaderProgram());
shader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader->Compile(IShaderProgram::Fragment, "shaders/glsl/tonemap.fp", prolog, 330);
shader->Link("shaders/glsl/tonemap");
}
shader.Bind(q);
shader->Bind(q);
}
bool FTonemapShader::IsPaletteMode()
@ -68,24 +68,26 @@ void FExposureExtractShader::Bind(IRenderQueue *q)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposureextract.fp", prolog, 330);
mShader.Link("shaders/glsl/exposureextract");
mShader.SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/exposureextract.fp", prolog, 330);
mShader->Link("shaders/glsl/exposureextract");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
mShader.Bind(q);
mShader->Bind(q);
}
void FExposureAverageShader::Bind(IRenderQueue *q)
{
if (!mShader)
{
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 400);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposureaverage.fp", "", 400);
mShader.Link("shaders/glsl/exposureaverage");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 400);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/exposureaverage.fp", "", 400);
mShader->Link("shaders/glsl/exposureaverage");
}
mShader.Bind(q);
mShader->Bind(q);
}
void FExposureCombineShader::Bind(IRenderQueue *q)
@ -94,11 +96,12 @@ void FExposureCombineShader::Bind(IRenderQueue *q)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposurecombine.fp", prolog, 330);
mShader.Link("shaders/glsl/exposurecombine");
mShader.SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
mShader.reset(screen->CreateShaderProgram());
mShader->Compile(IShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
mShader->Compile(IShaderProgram::Fragment, "shaders/glsl/exposurecombine.fp", prolog, 330);
mShader->Link("shaders/glsl/exposurecombine");
mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms");
Uniforms.Init();
}
mShader.Bind(q);
mShader->Bind(q);
}

View file

@ -1,7 +1,7 @@
#ifndef __GL_TONEMAPSHADER_H
#define __GL_TONEMAPSHADER_H
#include "gl_shaderprogram.h"
#include "hwrenderer/postprocessing/hw_shaderprogram.h"
class FTonemapShader
{
@ -24,7 +24,7 @@ private:
static const char *GetDefines(int mode);
FShaderProgram mShader[NumTonemapModes];
std::unique_ptr<IShaderProgram> mShader[NumTonemapModes];
};
class FExposureExtractShader
@ -50,7 +50,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
class FExposureAverageShader
@ -59,7 +59,7 @@ public:
void Bind(IRenderQueue *q);
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
class FExposureCombineShader
@ -89,7 +89,7 @@ public:
ShaderUniforms<UniformBlock, POSTPROCESS_BINDINGPOINT> Uniforms;
private:
FShaderProgram mShader;
std::unique_ptr<IShaderProgram> mShader;
};
#endif

View file

@ -41,6 +41,7 @@
#include "gl/data/gl_uniformbuffer.h"
#include "gl/models/gl_models.h"
#include "gl/stereo3d/gl_stereo3d.h"
#include "gl/shaders/gl_shaderprogram.h"
#include "gl_debug.h"
#include "r_videoscale.h"
@ -364,6 +365,12 @@ IUniformBuffer *OpenGLFrameBuffer::CreateUniformBuffer(size_t size, bool staticu
return new GLUniformBuffer(size, staticuse);
}
IShaderProgram *OpenGLFrameBuffer::CreateShaderProgram()
{
return new FShaderProgram;
}
void OpenGLFrameBuffer::UnbindTexUnit(int no)
{
FHardwareTexture::Unbind(no);

View file

@ -45,6 +45,7 @@ public:
void SetViewportRects(IntRect *bounds) override;
void BlurScene(float amount) override;
IUniformBuffer *CreateUniformBuffer(size_t size, bool staticuse = false) override;
IShaderProgram *CreateShaderProgram() override;
// Retrieves a buffer containing image data for a screenshot.

View file

@ -19,15 +19,15 @@ typedef TFlags<ColormaskBits, uint8_t> Colormask;
class IRenderQueue
{
Colormask mColorMask;
Colormask mColorMask;
Colormask GetColorMask() const
{
return mColorMask;
}
Colormask GetColorMask() const
{
return mColorMask;
}
void SetColorMask(Colormask mask) = 0;
virtual void SetColorMask(Colormask mask) = 0;
};

View file

@ -4,6 +4,12 @@
#include "hwrenderer/data/uniformbuffer.h"
#include "v_video.h"
enum
{
LIGHTBUF_BINDINGPOINT = 1,
POSTPROCESS_BINDINGPOINT = 2
};
enum class UniformType
{
Int,

View file

@ -0,0 +1,31 @@
#pragma once
#include "hwrenderer/data/shaderuniforms.h"
class IRenderQueue;
class IShaderProgram
{
public:
IShaderProgram() {}
virtual ~IShaderProgram() {}
enum ShaderType
{
Vertex,
Fragment,
NumShaderTypes
};
virtual void Compile(ShaderType type, const char *lumpName, const char *defines, int maxGlslVersion) = 0;
virtual void Compile(ShaderType type, const char *name, const FString &code, const char *defines, int maxGlslVersion) = 0;
virtual void Link(const char *name) = 0;
virtual void SetUniformBufferLocation(int index, const char *name) = 0;
virtual void Bind(IRenderQueue *q) = 0; // the parameter here is just a preparation for Vulkan
private:
IShaderProgram(const IShaderProgram &) = delete;
IShaderProgram &operator=(const IShaderProgram &) = delete;
};

View file

@ -45,6 +45,7 @@
#include "v_2ddrawer.h"
struct sector_t;
class IShaderProgram;
enum EHWCaps
{
@ -418,6 +419,7 @@ public:
// Interface to hardware rendering resources
virtual IUniformBuffer *CreateUniformBuffer(size_t size, bool staticuse = false) { return nullptr; }
virtual IShaderProgram *CreateShaderProgram() { return nullptr; }
// Begin 2D drawing operations.
// Returns true if hardware-accelerated 2D has been entered, false if not.