Skip to content

Commit

Permalink
- simplify the interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Jun 21, 2018
1 parent 1967165 commit 9486180
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/gl/renderer/gl_renderer.cpp
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/gl/scene/gl_scene.cpp
Expand Up @@ -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);
}

//-----------------------------------------------------------------------------
Expand Down
27 changes: 14 additions & 13 deletions src/gl/shaders/gl_shader.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}

//==========================================================================
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/gl/shaders/gl_shader.h
Expand Up @@ -38,6 +38,7 @@ enum
};

class FShaderCollection;
struct HWViewpointUniforms;

//==========================================================================
//
Expand Down Expand Up @@ -306,7 +307,7 @@ class FShader
bool Bind();
unsigned int GetHandle() const { return hShader; }

void ApplyMatrices(VSMatrix *proj, VSMatrix *view, VSMatrix *norm);
void ApplyMatrices(HWViewpointUniforms *u);

};

Expand All @@ -326,7 +327,7 @@ class FShaderManager

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;
Expand All @@ -348,7 +349,7 @@ class FShaderCollection
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)
{
Expand Down

0 comments on commit 9486180

Please sign in to comment.