diff --git a/src/gl/dynlights/gl_lightbuffer.cpp b/src/gl/dynlights/gl_lightbuffer.cpp index 769adb0d7..041735d57 100644 --- a/src/gl/dynlights/gl_lightbuffer.cpp +++ b/src/gl/dynlights/gl_lightbuffer.cpp @@ -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. diff --git a/src/gl/shaders/gl_ambientshader.cpp b/src/gl/shaders/gl_ambientshader.cpp index e896d9208..a19e8bf0c 100644 --- a/src/gl/shaders/gl_ambientshader.cpp +++ b/src/gl/shaders/gl_ambientshader.cpp @@ -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(); diff --git a/src/gl/shaders/gl_ambientshader.h b/src/gl/shaders/gl_ambientshader.h index aae7dd3e8..aa0ada361 100644 --- a/src/gl/shaders/gl_ambientshader.h +++ b/src/gl/shaders/gl_ambientshader.h @@ -1,9 +1,7 @@ #ifndef __GL_AMBIENTSHADER_H #define __GL_AMBIENTSHADER_H -#include - -#include "gl_shaderprogram.h" +#include "hwrenderer/postprocessing/hw_shaderprogram.h" class FLinearDepthShader { @@ -42,7 +40,7 @@ public: ShaderUniforms Uniforms; private: - std::unique_ptr mShader; + std::unique_ptr mShader; bool mMultisample = false; }; @@ -101,7 +99,7 @@ private: FString GetDefines(int mode, bool multisample); - std::unique_ptr mShader; + std::unique_ptr mShader; Quality mCurrentQuality = Off; bool mMultisample = false; }; @@ -131,7 +129,7 @@ public: ShaderUniforms Uniforms[2]; private: - FShaderProgram mShader[2]; + std::unique_ptr mShader[2]; }; class FSSAOCombineShader @@ -163,7 +161,7 @@ public: ShaderUniforms Uniforms; private: - std::unique_ptr mShader; + std::unique_ptr mShader; bool mMultisample = false; }; diff --git a/src/gl/shaders/gl_bloomshader.cpp b/src/gl/shaders/gl_bloomshader.cpp index 5fef88364..1025e9afe 100644 --- a/src/gl/shaders/gl_bloomshader.cpp +++ b/src/gl/shaders/gl_bloomshader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_bloomshader.h b/src/gl/shaders/gl_bloomshader.h index 7be7bd487..742705ebf 100644 --- a/src/gl/shaders/gl_bloomshader.h +++ b/src/gl/shaders/gl_bloomshader.h @@ -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 Uniforms; private: - FShaderProgram mShader; + std::unique_ptr mShader; }; class FBloomCombineShader @@ -35,7 +35,7 @@ public: void Bind(IRenderQueue *q); private: - FShaderProgram mShader; + std::unique_ptr mShader; }; #endif \ No newline at end of file diff --git a/src/gl/shaders/gl_blurshader.cpp b/src/gl/shaders/gl_blurshader.cpp index 93212f0b0..df929df9d 100644 --- a/src/gl/shaders/gl_blurshader.cpp +++ b/src/gl/shaders/gl_blurshader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_blurshader.h b/src/gl/shaders/gl_blurshader.h index 2ae392ad7..711f19734 100644 --- a/src/gl/shaders/gl_blurshader.h +++ b/src/gl/shaders/gl_blurshader.h @@ -1,8 +1,7 @@ #pragma once -#include "gl_shaderprogram.h" -#include +#include "hwrenderer/postprocessing/hw_shaderprogram.h" class FGLRenderer; class PPFrameBuffer; @@ -36,5 +35,5 @@ public: ShaderUniforms Uniforms[2]; private: - FShaderProgram mShader[2]; + std::unique_ptr mShader[2]; }; diff --git a/src/gl/shaders/gl_colormapshader.cpp b/src/gl/shaders/gl_colormapshader.cpp index 30353f4e8..989cd1145 100644 --- a/src/gl/shaders/gl_colormapshader.cpp +++ b/src/gl/shaders/gl_colormapshader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_colormapshader.h b/src/gl/shaders/gl_colormapshader.h index 7b48947ce..74b534fc3 100644 --- a/src/gl/shaders/gl_colormapshader.h +++ b/src/gl/shaders/gl_colormapshader.h @@ -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 mShader; }; #endif \ No newline at end of file diff --git a/src/gl/shaders/gl_fxaashader.cpp b/src/gl/shaders/gl_fxaashader.cpp index ddded7150..8d5abe515 100644 --- a/src/gl/shaders/gl_fxaashader.cpp +++ b/src/gl/shaders/gl_fxaashader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_fxaashader.h b/src/gl/shaders/gl_fxaashader.h index 7ee3f2c07..591e8e072 100644 --- a/src/gl/shaders/gl_fxaashader.h +++ b/src/gl/shaders/gl_fxaashader.h @@ -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 mShader; }; @@ -64,7 +64,7 @@ public: ShaderUniforms Uniforms; private: - FShaderProgram mShaders[Count]; + std::unique_ptr mShaders[Count]; }; #endif // __GL_FXAASHADER_H__ diff --git a/src/gl/shaders/gl_lensshader.cpp b/src/gl/shaders/gl_lensshader.cpp index f4924e7f0..65e32484c 100644 --- a/src/gl/shaders/gl_lensshader.cpp +++ b/src/gl/shaders/gl_lensshader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_lensshader.h b/src/gl/shaders/gl_lensshader.h index 80bb8ef7a..895128e7a 100644 --- a/src/gl/shaders/gl_lensshader.h +++ b/src/gl/shaders/gl_lensshader.h @@ -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 Uniforms; private: - FShaderProgram mShader; + std::unique_ptr mShader; }; #endif \ No newline at end of file diff --git a/src/gl/shaders/gl_postprocessshader.cpp b/src/gl/shaders/gl_postprocessshader.cpp index 5f4c136ce..d47bd095d 100644 --- a/src/gl/shaders/gl_postprocessshader.cpp +++ b/src/gl/shaders/gl_postprocessshader.cpp @@ -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::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::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; diff --git a/src/gl/shaders/gl_present3dRowshader.cpp b/src/gl/shaders/gl_present3dRowshader.cpp index 963562541..2a0241097 100644 --- a/src/gl/shaders/gl_present3dRowshader.cpp +++ b/src/gl/shaders/gl_present3dRowshader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_presentshader.cpp b/src/gl/shaders/gl_presentshader.cpp index 929126cae..83c30934b 100644 --- a/src/gl/shaders/gl_presentshader.cpp +++ b/src/gl/shaders/gl_presentshader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_presentshader.h b/src/gl/shaders/gl_presentshader.h index fa2ae31dd..309d05546 100644 --- a/src/gl/shaders/gl_presentshader.h +++ b/src/gl/shaders/gl_presentshader.h @@ -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 mShader; }; class FPresentShader : public FPresentShaderBase diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 7a64f9c71..8bff7ee2a 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -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" diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 5f5881c68..021c6d288 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -382,11 +382,5 @@ public: } }; -enum -{ - LIGHTBUF_BINDINGPOINT = 1, - POSTPROCESS_BINDINGPOINT = 2 -}; - #endif diff --git a/src/gl/shaders/gl_shaderprogram.h b/src/gl/shaders/gl_shaderprogram.h index 9a9dc6579..09b73dea1 100644 --- a/src/gl/shaders/gl_shaderprogram.h +++ b/src/gl/shaders/gl_shaderprogram.h @@ -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; diff --git a/src/gl/shaders/gl_shadowmapshader.cpp b/src/gl/shaders/gl_shadowmapshader.cpp index 09e676454..17f4ea947 100644 --- a/src/gl/shaders/gl_shadowmapshader.cpp +++ b/src/gl/shaders/gl_shadowmapshader.cpp @@ -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); } diff --git a/src/gl/shaders/gl_shadowmapshader.h b/src/gl/shaders/gl_shadowmapshader.h index f657689de..34b8de4a9 100644 --- a/src/gl/shaders/gl_shadowmapshader.h +++ b/src/gl/shaders/gl_shadowmapshader.h @@ -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 Uniforms; private: - FShaderProgram mShader; + std::unique_ptr mShader; }; #endif \ No newline at end of file diff --git a/src/gl/shaders/gl_tonemapshader.cpp b/src/gl/shaders/gl_tonemapshader.cpp index 3dcc37d5d..c3f47e72b 100644 --- a/src/gl/shaders/gl_tonemapshader.cpp +++ b/src/gl/shaders/gl_tonemapshader.cpp @@ -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); } \ No newline at end of file diff --git a/src/gl/shaders/gl_tonemapshader.h b/src/gl/shaders/gl_tonemapshader.h index fe559665a..a7c5534c3 100644 --- a/src/gl/shaders/gl_tonemapshader.h +++ b/src/gl/shaders/gl_tonemapshader.h @@ -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 mShader[NumTonemapModes]; }; class FExposureExtractShader @@ -50,7 +50,7 @@ public: ShaderUniforms Uniforms; private: - FShaderProgram mShader; + std::unique_ptr mShader; }; class FExposureAverageShader @@ -59,7 +59,7 @@ public: void Bind(IRenderQueue *q); private: - FShaderProgram mShader; + std::unique_ptr mShader; }; class FExposureCombineShader @@ -89,7 +89,7 @@ public: ShaderUniforms Uniforms; private: - FShaderProgram mShader; + std::unique_ptr mShader; }; #endif \ No newline at end of file diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 20caf148e..ad8a25a45 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -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); diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 2ae1d2e96..8aff32906 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -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. diff --git a/src/hwrenderer/data/renderqueue.h b/src/hwrenderer/data/renderqueue.h index 69e67b990..43b8aab1d 100644 --- a/src/hwrenderer/data/renderqueue.h +++ b/src/hwrenderer/data/renderqueue.h @@ -19,15 +19,15 @@ typedef TFlags 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; }; diff --git a/src/hwrenderer/data/shaderuniforms.h b/src/hwrenderer/data/shaderuniforms.h index c8aa4aa22..ca29efb73 100644 --- a/src/hwrenderer/data/shaderuniforms.h +++ b/src/hwrenderer/data/shaderuniforms.h @@ -4,6 +4,12 @@ #include "hwrenderer/data/uniformbuffer.h" #include "v_video.h" +enum +{ + LIGHTBUF_BINDINGPOINT = 1, + POSTPROCESS_BINDINGPOINT = 2 +}; + enum class UniformType { Int, diff --git a/src/hwrenderer/postprocessing/hw_shaderprogram.h b/src/hwrenderer/postprocessing/hw_shaderprogram.h new file mode 100644 index 000000000..c1dca3dc7 --- /dev/null +++ b/src/hwrenderer/postprocessing/hw_shaderprogram.h @@ -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; +}; diff --git a/src/v_video.h b/src/v_video.h index df23f3b06..9e4df8013 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -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.