- simplify the interface.

This commit is contained in:
Christoph Oelckers 2018-06-21 21:36:12 +02:00
parent 1967165633
commit 9486180843
4 changed files with 20 additions and 18 deletions

View file

@ -471,7 +471,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
matrices.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f); matrices.mProjectionMatrix.ortho(0, screen->GetWidth(), screen->GetHeight(), 0, -1.0f, 1.0f);
matrices.mViewMatrix.loadIdentity(); matrices.mViewMatrix.loadIdentity();
matrices.CalcDependencies(); matrices.CalcDependencies();
GLRenderer->mShaderManager->ApplyMatrices(&matrices.mProjectionMatrix, &matrices.mViewMatrix, &matrices.mNormalViewMatrix, NORMAL_PASS); GLRenderer->mShaderManager->ApplyMatrices(&matrices, NORMAL_PASS);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);

View file

@ -75,7 +75,7 @@ EXTERN_CVAR (Bool, r_drawvoxels)
void FDrawInfo::ApplyVPUniforms() void FDrawInfo::ApplyVPUniforms()
{ {
VPUniforms.CalcDependencies(); VPUniforms.CalcDependencies();
GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms.mProjectionMatrix, &VPUniforms.mViewMatrix, &VPUniforms.mNormalViewMatrix, NORMAL_PASS); GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms, NORMAL_PASS);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -34,6 +34,7 @@
#include "cmdlib.h" #include "cmdlib.h"
#include "hwrenderer/utility/hw_shaderpatcher.h" #include "hwrenderer/utility/hw_shaderpatcher.h"
#include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/data/shaderuniforms.h"
#include "hwrenderer/scene/hw_viewpointuniforms.h"
#include "gl_load/gl_interface.h" #include "gl_load/gl_interface.h"
#include "gl/system/gl_debug.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(); Bind();
glUniformMatrix4fv(projectionmatrix_index, 1, false, proj->get()); glUniformMatrix4fv(projectionmatrix_index, 1, false, u->mProjectionMatrix.get());
glUniformMatrix4fv(viewmatrix_index, 1, false, view->get()); glUniformMatrix4fv(viewmatrix_index, 1, false, u->mViewMatrix.get());
glUniformMatrix4fv(normalviewmatrix_index, 1, false, norm->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; return nullptr;
} }
void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm, EPassType passType) void FShaderManager::ApplyMatrices(HWViewpointUniforms *u, EPassType passType)
{ {
if (passType < mPassShaders.Size()) if (passType < mPassShaders.Size())
mPassShaders[passType]->ApplyMatrices(proj, view, norm); mPassShaders[passType]->ApplyMatrices(u);
if (mActiveShader) if (mActiveShader)
mActiveShader->Bind(); mActiveShader->Bind();
@ -687,25 +688,25 @@ FShader *FShaderCollection::BindEffect(int effect)
//========================================================================== //==========================================================================
EXTERN_CVAR(Int, gl_fuzztype) 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++) for (int i = 0; i < SHADER_NoTexture; i++)
{ {
mMaterialShaders[i]->ApplyMatrices(proj, view, norm); mMaterialShaders[i]->ApplyMatrices(u);
mMaterialShadersNAT[i]->ApplyMatrices(proj, view, norm); mMaterialShadersNAT[i]->ApplyMatrices(u);
} }
mMaterialShaders[SHADER_NoTexture]->ApplyMatrices(proj, view, norm); mMaterialShaders[SHADER_NoTexture]->ApplyMatrices(u);
if (gl_fuzztype != 0) 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++) 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++) for (int i = 0; i < MAX_EFFECTS; i++)
{ {
mEffectShaders[i]->ApplyMatrices(proj, view, norm); mEffectShaders[i]->ApplyMatrices(u);
} }
} }

View file

@ -38,6 +38,7 @@ enum
}; };
class FShaderCollection; class FShaderCollection;
struct HWViewpointUniforms;
//========================================================================== //==========================================================================
// //
@ -306,7 +307,7 @@ public:
bool Bind(); bool Bind();
unsigned int GetHandle() const { return hShader; } 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 *BindEffect(int effect, EPassType passType);
FShader *Get(unsigned int eff, bool alphateston, 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: private:
FShader *mActiveShader = nullptr; 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); FShader *Compile(const char *ShaderName, const char *ShaderPath, const char *LightModePath, const char *shaderdefines, bool usediscard, EPassType passType);
int Find(const char *mame); int Find(const char *mame);
FShader *BindEffect(int effect); FShader *BindEffect(int effect);
void ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm); void ApplyMatrices(HWViewpointUniforms *u);
FShader *Get(unsigned int eff, bool alphateston) FShader *Get(unsigned int eff, bool alphateston)
{ {