From a936629cec470e3c4bdf6bfcf9481c6bae39e5ec Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 10 Jul 2014 10:33:07 +0200 Subject: [PATCH] - use default fragment shader for burn and stencil shader, with the time consuming parts disabled by a #define, to avoid code duplication. --- src/gl/shaders/gl_shader.cpp | 25 +++++++++++++++++++++++-- wadsrc/static/shaders/glsl/burn.vp | 7 ------- wadsrc/static/shaders/glsl/main.vp | 21 +++++++++++++++------ wadsrc/static/shaders/glsl/stencil.vp | 14 -------------- 4 files changed, 38 insertions(+), 29 deletions(-) delete mode 100644 wadsrc/static/shaders/glsl/burn.vp delete mode 100644 wadsrc/static/shaders/glsl/stencil.vp diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index bd96c1ce2..013e56709 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -212,6 +212,27 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * int texture_index = glGetUniformLocation(hShader, "texture2"); if (texture_index > 0) glUniform1i(texture_index, 1); + + GLint binaryLength; + void* binary; + FILE* outfile; + GLenum binaryFormat; + // + // Retrieve the binary from the program object + // + glGetProgramiv(hShader, GL_PROGRAM_BINARY_LENGTH, &binaryLength); + binary = (void*)malloc(binaryLength); + glGetProgramBinary(hShader, binaryLength, NULL, &binaryFormat, binary); + + // + // Cache the program binary for future runs + // + outfile = fopen(name, "wb"); + fwrite(binary, binaryLength, 1, outfile); + fclose(outfile); + free(binary); + + glUseProgram(0); return !!linked; } @@ -316,8 +337,8 @@ static const FEffectShader effectshaders[]= { { "fogboundary", "shaders/glsl/main.vp", "shaders/glsl/fogboundary.fp", NULL, "" }, { "spheremap", "shaders/glsl/main.vp", "shaders/glsl/main.fp", "shaders/glsl/func_normal.fp", "#define SPHEREMAP\n" }, - { "burn", "shaders/glsl/burn.vp", "shaders/glsl/burn.fp", NULL, "" }, - { "stencil", "shaders/glsl/stencil.vp", "shaders/glsl/stencil.fp", NULL, "" }, + { "burn", "shaders/glsl/main.vp", "shaders/glsl/burn.fp", NULL, "#define SIMPLE\n" }, + { "stencil", "shaders/glsl/main.vp", "shaders/glsl/stencil.fp", NULL, "#define SIMPLE\n" }, }; diff --git a/wadsrc/static/shaders/glsl/burn.vp b/wadsrc/static/shaders/glsl/burn.vp deleted file mode 100644 index 6a8d2b37b..000000000 --- a/wadsrc/static/shaders/glsl/burn.vp +++ /dev/null @@ -1,7 +0,0 @@ - -void main() -{ - gl_FrontColor = gl_Color; - gl_TexCoord[0] = gl_MultiTexCoord0; - gl_Position = ProjectionMatrix * gl_Vertex; -} diff --git a/wadsrc/static/shaders/glsl/main.vp b/wadsrc/static/shaders/glsl/main.vp index 81b0601c5..f0bbdd413 100644 --- a/wadsrc/static/shaders/glsl/main.vp +++ b/wadsrc/static/shaders/glsl/main.vp @@ -1,7 +1,9 @@ +#ifndef SIMPLE // we do not need these for simple shaders in vec4 aVertex2; out vec4 pixelpos; out vec2 glowdist; +#endif #ifdef UNIFORM_VB uniform float fakeVB[100]; @@ -30,16 +32,23 @@ void main() #define tc gl_MultiTexCoord0 #endif - vec4 worldcoord = ModelMatrix * mix(vert, aVertex2, uInterpolationFactor); + #ifndef SIMPLE + vec4 worldcoord = ModelMatrix * mix(vert, aVertex2, uInterpolationFactor); + #else + vec4 worldcoord = ModelMatrix * vert; + #endif + vec4 eyeCoordPos = ViewMatrix * worldcoord; gl_FrontColor = gl_Color; - - pixelpos.xyz = worldcoord.xyz; - pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w; - glowdist.x = -((uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z) - worldcoord.y; - glowdist.y = worldcoord.y + ((uGlowBottomPlane.w + uGlowBottomPlane.x * worldcoord.x + uGlowBottomPlane.y * worldcoord.z) * uGlowBottomPlane.z); + #ifndef SIMPLE + pixelpos.xyz = worldcoord.xyz; + pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w; + + glowdist.x = -((uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z) - worldcoord.y; + glowdist.y = worldcoord.y + ((uGlowBottomPlane.w + uGlowBottomPlane.x * worldcoord.x + uGlowBottomPlane.y * worldcoord.z) * uGlowBottomPlane.z); + #endif #ifdef SPHEREMAP vec3 u = normalize(eyeCoordPos.xyz); diff --git a/wadsrc/static/shaders/glsl/stencil.vp b/wadsrc/static/shaders/glsl/stencil.vp deleted file mode 100644 index f5ac9fdd1..000000000 --- a/wadsrc/static/shaders/glsl/stencil.vp +++ /dev/null @@ -1,14 +0,0 @@ - -out vec4 pixelpos; - -void main() -{ - // perform exactly the same relevant steps as in the main shader to ensure matching results (that also means including the model matrix here!) - vec4 worldcoord = ModelMatrix * gl_Vertex; - vec4 eyeCoordPos = ViewMatrix * worldcoord; - - pixelpos.xyz = worldcoord.xyz; - pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w; - - gl_Position = ProjectionMatrix * eyeCoordPos; -}