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; -}