From ce3653f6e1d2ccba096e2e9f0f59b3ba1c1be715 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 13 Jul 2014 23:13:40 +0200 Subject: [PATCH] - remove all uses of builtin matrices. --- src/gl/data/gl_vertexbuffer.h | 4 +-- src/gl/renderer/gl_renderstate.cpp | 10 +++--- src/gl/scene/gl_flats.cpp | 4 +-- src/gl/shaders/gl_shader.cpp | 43 +++++++++++++++++++++++++ src/gl/shaders/gl_shader.h | 4 +++ wadsrc/static/shaders/glsl/shaderdefs.i | 4 +-- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/gl/data/gl_vertexbuffer.h b/src/gl/data/gl_vertexbuffer.h index d9e259db6..ff9d14278 100644 --- a/src/gl/data/gl_vertexbuffer.h +++ b/src/gl/data/gl_vertexbuffer.h @@ -80,7 +80,7 @@ public: #ifdef __GL_PCH_H // we need the system includes for this but we cannot include them ourselves without creating #define clashes. The affected files wouldn't try to draw anyway. void RenderArray(unsigned int primtype, unsigned int offset, unsigned int count) { - drawcalls.Clock(); + //drawcalls.Clock(); if (gl.flags & RFL_BUFFER_STORAGE) { glDrawArrays(primtype, offset, count); @@ -89,7 +89,7 @@ public: { ImmRenderBuffer(primtype, offset, count); } - drawcalls.Unclock(); + //drawcalls.Unclock(); } void RenderCurrent(FFlatVertex *newptr, unsigned int primtype, unsigned int *poffset = NULL, unsigned int *pcount = NULL) diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 95b0513b8..67a02440c 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -301,8 +301,10 @@ void FRenderState::Apply() void FRenderState::ApplyMatrices() { - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(mViewMatrix.get()); - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(mProjectionMatrix.get()); + drawcalls.Clock(); + if (GLRenderer->mShaderManager != NULL) + { + GLRenderer->mShaderManager->ApplyMatrices(&mProjectionMatrix, &mViewMatrix); + } + drawcalls.Unclock(); } diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 6b449ded3..fb5da4fd2 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -298,9 +298,9 @@ void GLFlat::DrawSubsectors(int pass, bool istrans) if (gl_drawinfo->ss_renderflags[sub-subsectors]&renderflags || istrans) { if (pass == GLPASS_ALL) lightsapplied = SetupSubsectorLights(lightsapplied, sub); - drawcalls.Clock(); + //drawcalls.Clock(); glDrawArrays(GL_TRIANGLE_FAN, index, sub->numlines); - drawcalls.Unclock(); + //drawcalls.Unclock(); flatvertices += sub->numlines; flatprimitives++; } diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 79746e5c2..1dbdada24 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -51,6 +51,7 @@ #include "gl/system/gl_interface.h" #include "gl/data/gl_data.h" +#include "gl/data/gl_matrix.h" #include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderstate.h" #include "gl/system/gl_cvars.h" @@ -206,6 +207,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * timer_index = glGetUniformLocation(hShader, "timer"); lights_index = glGetUniformLocation(hShader, "lights"); fakevb_index = glGetUniformLocation(hShader, "fakeVB"); + projectionmatrix_index = glGetUniformLocation(hShader, "ProjectionMatrix"); + viewmatrix_index = glGetUniformLocation(hShader, "ViewMatrix"); modelmatrix_index = glGetUniformLocation(hShader, "ModelMatrix"); texturematrix_index = glGetUniformLocation(hShader, "TextureMatrix"); @@ -277,6 +280,19 @@ FShader *FShaderManager::Compile (const char *ShaderName, const char *ShaderPath return shader; } +//========================================================================== +// +// +// +//========================================================================== + +void FShader::ApplyMatrices(VSMatrix *proj, VSMatrix *view) +{ + glProgramUniformMatrix4fv(hShader, projectionmatrix_index, 1, false, proj->get()); + glProgramUniformMatrix4fv(hShader, viewmatrix_index, 1, false, view->get()); +} + + //========================================================================== // // @@ -486,6 +502,33 @@ FShader *FShaderManager::BindEffect(int effect) } +//========================================================================== +// +// +// +//========================================================================== +EXTERN_CVAR(Int, gl_fuzztype) + +void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view) +{ + for (int i = 0; i <= 4; i++) + { + mTextureEffects[i]->ApplyMatrices(proj, view); + } + if (gl_fuzztype != 0) + { + mTextureEffects[4+gl_fuzztype]->ApplyMatrices(proj, view); + } + for (unsigned i = 12; i < mTextureEffects.Size(); i++) + { + mTextureEffects[i]->ApplyMatrices(proj, view); + } + for (int i = 0; i < MAX_EFFECTS; i++) + { + mEffectShaders[i]->ApplyMatrices(proj, view); + } +} + //========================================================================== // // diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index a87b1e576..663d09122 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -198,6 +198,8 @@ class FShader int timer_index; int lights_index; + int projectionmatrix_index; + int viewmatrix_index; int modelmatrix_index; int texturematrix_index; public: @@ -230,6 +232,7 @@ public: bool Bind(); unsigned int GetHandle() const { return hShader; } + void ApplyMatrices(VSMatrix *proj, VSMatrix *view); }; @@ -256,6 +259,7 @@ public: FShader *BindEffect(int effect); void SetActiveShader(FShader *sh); void SetWarpSpeed(unsigned int eff, float speed); + void ApplyMatrices(VSMatrix *proj, VSMatrix *view); FShader *GetActiveShader() const { return mActiveShader; diff --git a/wadsrc/static/shaders/glsl/shaderdefs.i b/wadsrc/static/shaders/glsl/shaderdefs.i index ebe751c96..867e9a709 100644 --- a/wadsrc/static/shaders/glsl/shaderdefs.i +++ b/wadsrc/static/shaders/glsl/shaderdefs.i @@ -36,8 +36,8 @@ uniform ivec4 uLightRange; // redefine the matrix names to what they actually represent. -#define ProjectionMatrix gl_ProjectionMatrix -#define ViewMatrix gl_ModelViewMatrix +uniform mat4 ProjectionMatrix; +uniform mat4 ViewMatrix; uniform mat4 ModelMatrix; uniform mat4 TextureMatrix;