From 94861808438c593e9e231504c5ee4089be01f01c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 21 Jun 2018 21:36:12 +0200 Subject: [PATCH] - simplify the interface. --- src/gl/renderer/gl_renderer.cpp | 2 +- src/gl/scene/gl_scene.cpp | 2 +- src/gl/shaders/gl_shader.cpp | 27 ++++++++++++++------------- src/gl/shaders/gl_shader.h | 7 ++++--- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 6bd2a6188..55009e2ce 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -471,7 +471,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) matrices.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f); matrices.mViewMatrix.loadIdentity(); matrices.CalcDependencies(); - GLRenderer->mShaderManager->ApplyMatrices(&matrices.mProjectionMatrix, &matrices.mViewMatrix, &matrices.mNormalViewMatrix, NORMAL_PASS); + GLRenderer->mShaderManager->ApplyMatrices(&matrices, NORMAL_PASS); glDisable(GL_DEPTH_TEST); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 75874aafe..10c67c809 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -75,7 +75,7 @@ EXTERN_CVAR (Bool, r_drawvoxels) void FDrawInfo::ApplyVPUniforms() { VPUniforms.CalcDependencies(); - GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms.mProjectionMatrix, &VPUniforms.mViewMatrix, &VPUniforms.mNormalViewMatrix, NORMAL_PASS); + GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms, NORMAL_PASS); } //----------------------------------------------------------------------------- diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 3641b8801..f50fb595a 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -34,6 +34,7 @@ #include "cmdlib.h" #include "hwrenderer/utility/hw_shaderpatcher.h" #include "hwrenderer/data/shaderuniforms.h" +#include "hwrenderer/scene/hw_viewpointuniforms.h" #include "gl_load/gl_interface.h" #include "gl/system/gl_debug.h" @@ -434,12 +435,12 @@ FShader *FShaderCollection::Compile (const char *ShaderName, const char *ShaderP // //========================================================================== -void FShader::ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm) +void FShader::ApplyMatrices(HWViewpointUniforms *u) { Bind(); - glUniformMatrix4fv(projectionmatrix_index, 1, false, proj->get()); - glUniformMatrix4fv(viewmatrix_index, 1, false, view->get()); - glUniformMatrix4fv(normalviewmatrix_index, 1, false, norm->get()); + glUniformMatrix4fv(projectionmatrix_index, 1, false, u->mProjectionMatrix.get()); + glUniformMatrix4fv(viewmatrix_index, 1, false, u->mViewMatrix.get()); + glUniformMatrix4fv(normalviewmatrix_index, 1, false, u->mNormalViewMatrix.get()); } //========================================================================== @@ -539,10 +540,10 @@ FShader *FShaderManager::Get(unsigned int eff, bool alphateston, EPassType passT return nullptr; } -void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm, EPassType passType) +void FShaderManager::ApplyMatrices(HWViewpointUniforms *u, EPassType passType) { if (passType < mPassShaders.Size()) - mPassShaders[passType]->ApplyMatrices(proj, view, norm); + mPassShaders[passType]->ApplyMatrices(u); if (mActiveShader) mActiveShader->Bind(); @@ -687,25 +688,25 @@ FShader *FShaderCollection::BindEffect(int effect) //========================================================================== EXTERN_CVAR(Int, gl_fuzztype) -void FShaderCollection::ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm) +void FShaderCollection::ApplyMatrices(HWViewpointUniforms *u) { for (int i = 0; i < SHADER_NoTexture; i++) { - mMaterialShaders[i]->ApplyMatrices(proj, view, norm); - mMaterialShadersNAT[i]->ApplyMatrices(proj, view, norm); + mMaterialShaders[i]->ApplyMatrices(u); + mMaterialShadersNAT[i]->ApplyMatrices(u); } - mMaterialShaders[SHADER_NoTexture]->ApplyMatrices(proj, view, norm); + mMaterialShaders[SHADER_NoTexture]->ApplyMatrices(u); if (gl_fuzztype != 0) { - mMaterialShaders[SHADER_NoTexture + gl_fuzztype]->ApplyMatrices(proj, view, norm); + mMaterialShaders[SHADER_NoTexture + gl_fuzztype]->ApplyMatrices(u); } for (unsigned i = FIRST_USER_SHADER; i < mMaterialShaders.Size(); i++) { - mMaterialShaders[i]->ApplyMatrices(proj, view, norm); + mMaterialShaders[i]->ApplyMatrices(u); } for (int i = 0; i < MAX_EFFECTS; i++) { - mEffectShaders[i]->ApplyMatrices(proj, view, norm); + mEffectShaders[i]->ApplyMatrices(u); } } diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index a3ca7eb7c..10503f527 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -38,6 +38,7 @@ enum }; class FShaderCollection; +struct HWViewpointUniforms; //========================================================================== // @@ -306,7 +307,7 @@ public: bool Bind(); unsigned int GetHandle() const { return hShader; } - void ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm); + void ApplyMatrices(HWViewpointUniforms *u); }; @@ -326,7 +327,7 @@ public: FShader *BindEffect(int effect, EPassType passType); FShader *Get(unsigned int eff, bool alphateston, EPassType passType); - void ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm, EPassType passType); + void ApplyMatrices(HWViewpointUniforms *u, EPassType passType); private: FShader *mActiveShader = nullptr; @@ -348,7 +349,7 @@ public: FShader *Compile(const char *ShaderName, const char *ShaderPath, const char *LightModePath, const char *shaderdefines, bool usediscard, EPassType passType); int Find(const char *mame); FShader *BindEffect(int effect); - void ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm); + void ApplyMatrices(HWViewpointUniforms *u); FShader *Get(unsigned int eff, bool alphateston) {