From 193d26dcc137a6cac3e927dc96ba0ceba7fc5194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Mon, 24 Apr 2017 15:53:10 +0300 Subject: [PATCH] Renderer|DGL: Configure fog via DGL DGL fog parameters affect both `dgl.draw` and model shaders. --- doomsday/apps/api/api_gl.h | 19 ++- .../apps/client/include/gl/gl_deferredapi.h | 10 -- doomsday/apps/client/include/gl/gl_main.h | 1 + doomsday/apps/client/include/gl/sys_opengl.h | 6 - .../renderer.pack/shaders/dgl/dgl.dei | 2 + .../renderer.pack/shaders/dgl/dgl_draw.fsh | 38 ++++- doomsday/apps/client/src/gl/dgl_common.cpp | 133 +++++++++++++++--- doomsday/apps/client/src/gl/dgl_draw.cpp | 24 +++- .../apps/client/src/gl/gl_deferredapi.cpp | 32 ----- doomsday/apps/client/src/gl/gl_main.cpp | 29 ++-- doomsday/apps/client/src/gl/sys_opengl.cpp | 14 +- .../apps/client/src/render/modelrenderer.cpp | 24 +--- doomsday/apps/client/src/render/r_main.cpp | 4 +- doomsday/apps/client/src/render/rend_main.cpp | 45 +++--- 14 files changed, 227 insertions(+), 154 deletions(-) diff --git a/doomsday/apps/api/api_gl.h b/doomsday/apps/api/api_gl.h index 916f1d9317..5c8838938c 100644 --- a/doomsday/apps/api/api_gl.h +++ b/doomsday/apps/api/api_gl.h @@ -47,7 +47,11 @@ enum { DGL_CURRENT_COLOR_A, DGL_CURRENT_COLOR_RGBA, - DGL_MODULATE_TEXTURE_COLOR, + DGL_FOG_MODE, + DGL_FOG_START, + DGL_FOG_END, + DGL_FOG_DENSITY, + DGL_FOG_COLOR, // Matrices DGL_MODELVIEW = 0x4000, @@ -94,7 +98,9 @@ enum { DGL_CLAMP_TO_EDGE, DGL_REPEAT, DGL_LINE_WIDTH, - DGL_POINT_SIZE + DGL_POINT_SIZE, + DGL_EXP, + DGL_EXP2, }; // Types. @@ -328,9 +334,15 @@ DENG_API_TYPEDEF(GL) * be created dynamically. */ int (*Bind)(DGLuint texture); + void (*DeleteTextures)(int num, const DGLuint* names); + void (*Fogi)(DGLenum property, int value); + void (*Fogf)(DGLenum property, float value); + void (*Fogfv)(DGLenum property, float const *values); + void (*UseFog)(int yes); + void (*SetFilter)(dd_bool enable); void (*SetFilterColor)(float r, float g, float b, float a); void (*ConfigureBorderedProjection2)(dgl_borderedprojectionstate_t* bp, int flags, int width, int height, int availWidth, int availHeight, scalemode_t overrideMode, float stretchEpsilon); @@ -409,6 +421,9 @@ DENG_API_T(GL); #define DGL_NewTextureWithParams _api_GL.NewTextureWithParams #define DGL_Bind _api_GL.Bind #define DGL_DeleteTextures _api_GL.DeleteTextures +#define DGL_Fogi _api_GL.Fogi +#define DGL_Fogf _api_GL.Fogf +#define DGL_Fogfv _api_GL.Fogfv #define GL_UseFog _api_GL.UseFog #define GL_SetFilter _api_GL.SetFilter #define GL_SetFilterColor _api_GL.SetFilterColor diff --git a/doomsday/apps/client/include/gl/gl_deferredapi.h b/doomsday/apps/client/include/gl/gl_deferredapi.h index d8e7587e1a..4b8176481b 100644 --- a/doomsday/apps/client/include/gl/gl_deferredapi.h +++ b/doomsday/apps/client/include/gl/gl_deferredapi.h @@ -43,19 +43,9 @@ extern "C" { #endif -//#define glEnable(x) Deferred_glEnable(x) -//#define glDisable(x) Deferred_glDisable(x) -//#define glDeleteTextures(x, y) Deferred_glDeleteTextures(x, y) -//#define glFogi(x, y) Deferred_glFogi(x, y) -//#define glFogf(x, y) Deferred_glFogf(x, y) -//#define glFogfv(x, y) Deferred_glFogfv(x, y) - void Deferred_glEnable(GLenum e); void Deferred_glDisable(GLenum e); void Deferred_glDeleteTextures(GLsizei num, const GLuint* names); -void Deferred_glFogi(GLenum p, GLint v); -void Deferred_glFogf(GLenum p, GLfloat v); -void Deferred_glFogfv(GLenum p, const GLfloat* v); #ifdef __cplusplus } // extern "C" diff --git a/doomsday/apps/client/include/gl/gl_main.h b/doomsday/apps/client/include/gl/gl_main.h index ec32604efe..fac0256b6d 100644 --- a/doomsday/apps/client/include/gl/gl_main.h +++ b/doomsday/apps/client/include/gl/gl_main.h @@ -315,6 +315,7 @@ void DGL_CurrentColor(float *rgba); void DGL_ModulateTexture(int mode); void DGL_SetModulationColor(de::Vector4f const &modColor); de::Vector4f DGL_ModulationColor(); +void DGL_FogParams(de::GLUniform &fogRange, de::GLUniform &fogColor); // Console commands --------------------------------------------------------------------- diff --git a/doomsday/apps/client/include/gl/sys_opengl.h b/doomsday/apps/client/include/gl/sys_opengl.h index 2f4c9a8d94..7cbcfa067e 100644 --- a/doomsday/apps/client/include/gl/sys_opengl.h +++ b/doomsday/apps/client/include/gl/sys_opengl.h @@ -80,19 +80,13 @@ * High-level GL state information. */ typedef struct gl_state_s { - /// Global config: - //int multisampleFormat; - /// Current state: - dd_bool currentUseFog; float currentLineWidth; float currentPointSize; /// Feature (abstract) availability bits: /// Vendor and implementation agnostic. struct { - //uint blendSubtract : 1; - //uint genMipmap : 1; uint texCompression : 1; uint texFilterAniso : 1; } features; diff --git a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei index 3fad05a668..eda006e70c 100644 --- a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei +++ b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl.dei @@ -1,5 +1,7 @@ # Shader for the DGL drawing routines that emulate OpenGL 1.x behavior. shader dgl.draw { path.vertex = "dgl_draw.vsh" + + include.fragment <../include/fog.glsl> path.fragment = "dgl_draw.fsh" } diff --git a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh index 746c1b5f61..0a4f88543d 100644 --- a/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh +++ b/doomsday/apps/client/net.dengine.client.pack/renderer.pack/shaders/dgl/dgl_draw.fsh @@ -23,6 +23,7 @@ uniform int uTexEnabled; uniform int uTexMode; uniform vec4 uTexModeColor; +uniform float uAlphaLimit; uniform sampler2D uTex0; uniform sampler2D uTex1; @@ -54,11 +55,44 @@ void main() break; case 2: // Texture interpolation and modulation with primary color. - out_FragColor.rgb = mix(texColor[0].rgb, texColor[1].rgb, vColor.a) * vColor.rgb; + out_FragColor.rgb *= mix(texColor[0].rgb, texColor[1].rgb, uTexModeColor.a); break; case 3: // Texture interpolation. - out_FragColor.rgb = mix(texColor[0].rgb, texColor[1].rgb, vColor.a); + out_FragColor.rgb = mix(texColor[0].rgb, texColor[1].rgb, uTexModeColor.a); break; + case 4: + // Sector light, dynamic light, and texture. + out_FragColor.rgb += texColor[0].a * uTexModeColor.rgb; + out_FragColor *= texColor[1]; + break; + case 6: + // Simple dynlight addition (add to primary color). + out_FragColor.rgb += texColor[0].a * uTexModeColor.rgb; + break; + case 8: + // Texture and Detail. + out_FragColor *= texColor[0]; + out_FragColor.rgb *= texColor[1].rgb * 2.0; + break; + case 10: + // Sector light * texture + dynamic light. + out_FragColor *= texColor[0]; + out_FragColor.rgb += texColor[1].rgb * uTexModeColor.rgb; + break; + case 11: + // Normal modulation, alpha of 2nd stage. + // Tex0: texture + // Tex1: shiny texture + out_FragColor.rgb *= texColor[1].rgb; + out_FragColor.a *= texColor[0].a; + break; + } + + // Alpha test. + if (out_FragColor.a < uAlphaLimit) { + discard; } + + applyFog(); } diff --git a/doomsday/apps/client/src/gl/dgl_common.cpp b/doomsday/apps/client/src/gl/dgl_common.cpp index 5dc8b9af62..442efe6765 100644 --- a/doomsday/apps/client/src/gl/dgl_common.cpp +++ b/doomsday/apps/client/src/gl/dgl_common.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,11 @@ struct DGLState bool enableFog = false; int textureModulation = 0; Vector4f textureModulationColor; + DGLenum fogMode = DGL_LINEAR; + float fogStart = 0; + float fogEnd = 0; + float fogDensity = 0; + Vector4f fogColor; DGLState() { @@ -123,6 +129,30 @@ Vector4f DGL_ModulationColor() return dgl.textureModulationColor; } +void DGL_FogParams(GLUniform &fogRange, GLUniform &fogColor) +{ + if (dgl.enableFog) + { + fogColor = Vector4f(dgl.fogColor[0], + dgl.fogColor[1], + dgl.fogColor[2], + 1.f); + + // TODO: Implement EXP and EXP2 fog modes. This is LINEAR. + + Rangef const depthPlanes = GL_DepthClipRange(); + float const fogDepth = dgl.fogEnd - dgl.fogStart; + fogRange = Vector4f(dgl.fogStart, + fogDepth, + depthPlanes.start, + depthPlanes.end); + } + else + { + fogColor = Vector4f(); + } +} + #if 0 /** * Requires a texture environment mode that can add and multiply. @@ -222,6 +252,11 @@ void DGL_ModulateTexture(int mode) case 1: case 2: case 3: + case 4: + case 6: + case 8: + case 10: + case 11: break; } @@ -509,7 +544,11 @@ dd_bool DGL_GetIntegerv(int name, int *v) break; case DGL_FOG: - *v = GL_state.currentUseFog; + *v = (dgl.enableFog? 1 : 0); + break; + + case DGL_FOG_MODE: + *v = int(dgl.fogMode); break; case DGL_CURRENT_COLOR_R: @@ -611,13 +650,36 @@ dd_bool DGL_GetFloatv(int name, float *v) break; case DGL_CURRENT_COLOR_RGBA: - DGL_CurrentColor(color); + DGL_CurrentColor(v); + break; + + case DGL_FOG_START: + v[0] = dgl.fogStart; + break; + + case DGL_FOG_END: + v[0] = dgl.fogEnd; + break; + + case DGL_FOG_DENSITY: + v[0] = dgl.fogDensity; + break; + + case DGL_FOG_COLOR: for (int i = 0; i < 4; ++i) { - v[i] = color[i]; + v[i] = dgl.fogColor[i]; } break; + case DGL_LINE_WIDTH: + v[0] = GL_state.currentLineWidth; + break; + + case DGL_POINT_SIZE: + v[0] = GL_state.currentPointSize; + break; + default: return false; } @@ -628,17 +690,9 @@ dd_bool DGL_GetFloatv(int name, float *v) #undef DGL_GetFloat float DGL_GetFloat(int name) { - switch(name) - { - case DGL_LINE_WIDTH: - return GL_state.currentLineWidth; - - case DGL_POINT_SIZE: - return GL_state.currentPointSize; - - default: - return 0; - } + float value = 0.f; + DGL_GetFloatv(name, &value); + return value; } #undef DGL_SetFloat @@ -690,7 +744,6 @@ int DGL_Enable(int cap) switch(cap) { case DGL_TEXTURE_2D: - //Deferred_glEnable(GL_TEXTURE_2D); dgl.enableTexture[dgl.activeTexture] = true; break; @@ -705,9 +758,7 @@ int DGL_Enable(int cap) break; case DGL_FOG: - //Deferred_glEnable(GL_FOG); dgl.enableFog = true; - GL_state.currentUseFog = true; break; case DGL_SCISSOR_TEST: @@ -755,13 +806,10 @@ void DGL_Disable(int cap) break; case DGL_FOG: - //Deferred_glDisable(GL_FOG); dgl.enableFog = false; - GL_state.currentUseFog = false; break; case DGL_SCISSOR_TEST: - //glDisable(GL_SCISSOR_TEST); GLState::current().clearScissor().apply(); break; @@ -967,6 +1015,46 @@ void DGL_Ortho(float left, float top, float right, float bottom, float znear, fl dgl.multMatrix(Matrix4f::ortho(left, right, top, bottom, znear, zfar)); } +#undef DGL_Fogi +void DGL_Fogi(DGLenum property, int value) +{ + switch (property) + { + case DGL_FOG_MODE: + dgl.fogMode = DGLenum(value); + break; + } +} + +#undef DGL_Fogfv +void DGL_Fogfv(DGLenum property, float const *values) +{ + switch (property) + { + case DGL_FOG_START: + dgl.fogStart = values[0]; + break; + + case DGL_FOG_END: + dgl.fogEnd = values[0]; + break; + + case DGL_FOG_DENSITY: + dgl.fogDensity = values[0]; + break; + + case DGL_FOG_COLOR: + dgl.fogColor = Vector4f(values); + break; + } +} + +#undef DGL_Fogf +void DGL_Fogf(DGLenum property, float value) +{ + DGL_Fogfv(property, &value); +} + #undef DGL_DeleteTextures void DGL_DeleteTextures(int num, DGLuint const *names) { @@ -1111,6 +1199,9 @@ DENG_DECLARE_API(GL) = DGL_NewTextureWithParams, DGL_Bind, DGL_DeleteTextures, + DGL_Fogi, + DGL_Fogf, + DGL_Fogfv, GL_UseFog, GL_SetFilter, GL_SetFilterColor, @@ -1118,5 +1209,5 @@ DENG_DECLARE_API(GL) = GL_ConfigureBorderedProjection, GL_BeginBorderedProjection, GL_EndBorderedProjection, - GL_ResetViewEffects + GL_ResetViewEffects, }; diff --git a/doomsday/apps/client/src/gl/dgl_draw.cpp b/doomsday/apps/client/src/gl/dgl_draw.cpp index 6562915fdc..9d50009d06 100644 --- a/doomsday/apps/client/src/gl/dgl_draw.cpp +++ b/doomsday/apps/client/src/gl/dgl_draw.cpp @@ -65,12 +65,15 @@ struct DGLDrawState struct GLData { GLProgram shader; - GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 }; - GLUniform uTexMatrix0 { "uTexMatrix0", GLUniform::Mat4 }; - GLUniform uTexMatrix1 { "uTexMatrix1", GLUniform::Mat4 }; - GLUniform uTexEnabled { "uTexEnabled", GLUniform::Int }; - GLUniform uTexMode { "uTexMode", GLUniform::Int }; - GLUniform uTexModeColor { "uTexModeColor", GLUniform::Vec4 }; + GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 }; + GLUniform uTexMatrix0 { "uTexMatrix0", GLUniform::Mat4 }; + GLUniform uTexMatrix1 { "uTexMatrix1", GLUniform::Mat4 }; + GLUniform uTexEnabled { "uTexEnabled", GLUniform::Int }; + GLUniform uTexMode { "uTexMode", GLUniform::Int }; + GLUniform uTexModeColor { "uTexModeColor", GLUniform::Vec4 }; + GLUniform uAlphaLimit { "uAlphaLimit", GLUniform::Float }; + GLUniform uFogRange { "uFogRange", GLUniform::Vec4 }; + GLUniform uFogColor { "uFogColor", GLUniform::Vec4 }; GLuint vertexArray = 0; GLBuffer buffer; }; @@ -171,7 +174,10 @@ struct DGLDrawState << gl->uTexMatrix1 << gl->uTexEnabled << gl->uTexMode - << gl->uTexModeColor; + << gl->uTexModeColor + << gl->uAlphaLimit + << gl->uFogRange + << gl->uFogColor; auto &GL = LIBGUI_GL; @@ -259,6 +265,8 @@ struct DGLDrawState { glInit(); + GLState const &glState = GLState::current(); + // Update uniforms. gl->uMvpMatrix = DGL_Matrix(DGL_PROJECTION) * DGL_Matrix(DGL_MODELVIEW); gl->uTexMatrix0 = DGL_Matrix(DGL_TEXTURE0); @@ -267,6 +275,8 @@ struct DGLDrawState (DGL_GetInteger(DGL_TEXTURE1)? 0x2 : 0); gl->uTexMode = DGL_GetInteger(DGL_MODULATE_TEXTURE); gl->uTexModeColor = DGL_ModulationColor(); + gl->uAlphaLimit = (glState.alphaTest()? glState.alphaLimit() : 0.f); + DGL_FogParams(gl->uFogRange, gl->uFogColor); GLState::current().apply(); diff --git a/doomsday/apps/client/src/gl/gl_deferredapi.cpp b/doomsday/apps/client/src/gl/gl_deferredapi.cpp index 961ace0e9c..d652b2d000 100644 --- a/doomsday/apps/client/src/gl/gl_deferredapi.cpp +++ b/doomsday/apps/client/src/gl/gl_deferredapi.cpp @@ -47,24 +47,6 @@ static void GL_CALL deng_glDeleteTextures(GLsizei num, GLuint const *names) LIBGUI_GL.glDeleteTextures(num, names); } -static void GL_CALL deng_glFogi(GLenum p, GLint v) -{ - //LIBGUI_GL.glFogi(p, v); - qDebug() << "glFogi not implemented"; -} - -static void GL_CALL deng_glFogf(GLenum p, GLfloat v) -{ - //LIBGUI_GL.glFogf(p, v); - qDebug() << "glFogf not implemented"; -} - -static void GL_CALL deng_glFogfv(GLenum p, GLfloat const *v) -{ - //LIBGUI_GL.glFogfv(p, v); - qDebug() << "glFogfv not implemented"; -} - #define GL_CALL1(form, func, x) \ if(mustDefer()) GL_Defer_##form(func, x); else func(x); #define GL_CALL2(form, func, x, y) \ @@ -85,17 +67,3 @@ DENG_EXTERN_C void Deferred_glDeleteTextures(GLsizei num, GLuint const *names) GL_CALL2(uintArray, deng_glDeleteTextures, num, names); } -DENG_EXTERN_C void Deferred_glFogi(GLenum p, GLint v) -{ - GL_CALL2(i, deng_glFogi, p, v); -} - -DENG_EXTERN_C void Deferred_glFogf(GLenum p, GLfloat v) -{ - GL_CALL2(f, deng_glFogf, p, v); -} - -DENG_EXTERN_C void Deferred_glFogfv(GLenum p, GLfloat const *v) -{ - GL_CALL2(fv4, deng_glFogfv, p, v); -} diff --git a/doomsday/apps/client/src/gl/gl_main.cpp b/doomsday/apps/client/src/gl/gl_main.cpp index 7fdb66bc8c..d553c86a02 100644 --- a/doomsday/apps/client/src/gl/gl_main.cpp +++ b/doomsday/apps/client/src/gl/gl_main.cpp @@ -28,6 +28,7 @@ #include "de_base.h" #include "gl/gl_main.h" +#include "api_gl.h" #include #include @@ -366,16 +367,16 @@ void GL_Init2DState() // Default state for the white fog is off. fogParams.usingFog = false; DGL_Disable(DGL_FOG); - Deferred_glFogi(GL_FOG_MODE, (fogModeDefault == 0 ? GL_LINEAR : - fogModeDefault == 1 ? GL_EXP : GL_EXP2)); - Deferred_glFogf(GL_FOG_START, DEFAULT_FOG_START); - Deferred_glFogf(GL_FOG_END, DEFAULT_FOG_END); - Deferred_glFogf(GL_FOG_DENSITY, DEFAULT_FOG_DENSITY); + DGL_Fogi(DGL_FOG_MODE, (fogModeDefault == 0 ? DGL_LINEAR : + fogModeDefault == 1 ? DGL_EXP : DGL_EXP2)); + DGL_Fogf(DGL_FOG_START, DEFAULT_FOG_START); + DGL_Fogf(DGL_FOG_END, DEFAULT_FOG_END); + DGL_Fogf(DGL_FOG_DENSITY, DEFAULT_FOG_DENSITY); fogParams.fogColor[0] = DEFAULT_FOG_COLOR_RED; fogParams.fogColor[1] = DEFAULT_FOG_COLOR_GREEN; fogParams.fogColor[2] = DEFAULT_FOG_COLOR_BLUE; - fogParams.fogColor[3] = 1; - Deferred_glFogfv(GL_FOG_COLOR, fogParams.fogColor); + fogParams.fogColor[3] = 1.f; + DGL_Fogfv(DGL_FOG_COLOR, fogParams.fogColor); LIBGUI_ASSERT_GL_OK(); } @@ -1434,7 +1435,7 @@ D_CMD(Fog) } fogParams.fogColor[3] = 1; - Deferred_glFogfv(GL_FOG_COLOR, fogParams.fogColor); + DGL_Fogfv(DGL_FOG_COLOR, fogParams.fogColor); LOG_GL_VERBOSE("Fog color set"); return true; } @@ -1442,20 +1443,20 @@ D_CMD(Fog) { fogParams.fogStart = (GLfloat) strtod(argv[2], nullptr); - Deferred_glFogf(GL_FOG_START, fogParams.fogStart); + DGL_Fogf(DGL_FOG_START, fogParams.fogStart); LOG_GL_VERBOSE("Fog start distance set"); return true; } if(!stricmp(argv[1], "end") && argc == 3) { fogParams.fogEnd = (GLfloat) strtod(argv[2], nullptr); - Deferred_glFogf(GL_FOG_END, fogParams.fogEnd); + DGL_Fogf(DGL_FOG_END, fogParams.fogEnd); LOG_GL_VERBOSE("Fog end distance set"); return true; } if(!stricmp(argv[1], "density") && argc == 3) { - Deferred_glFogf(GL_FOG_DENSITY, (GLfloat) strtod(argv[2], nullptr)); + DGL_Fogf(DGL_FOG_DENSITY, (GLfloat) strtod(argv[2], nullptr)); LOG_GL_VERBOSE("Fog density set"); return true; } @@ -1463,19 +1464,19 @@ D_CMD(Fog) { if(!stricmp(argv[2], "linear")) { - Deferred_glFogi(GL_FOG_MODE, GL_LINEAR); + DGL_Fogi(DGL_FOG_MODE, GL_LINEAR); LOG_GL_VERBOSE("Fog mode set to linear"); return true; } if(!stricmp(argv[2], "exp")) { - Deferred_glFogi(GL_FOG_MODE, GL_EXP); + DGL_Fogi(DGL_FOG_MODE, GL_EXP); LOG_GL_VERBOSE("Fog mode set to exp"); return true; } if(!stricmp(argv[2], "exp2")) { - Deferred_glFogi(GL_FOG_MODE, GL_EXP2); + DGL_Fogi(DGL_FOG_MODE, GL_EXP2); LOG_GL_VERBOSE("Fog mode set to exp2"); return true; } diff --git a/doomsday/apps/client/src/gl/sys_opengl.cpp b/doomsday/apps/client/src/gl/sys_opengl.cpp index 9cf649b448..20d2bd2a12 100644 --- a/doomsday/apps/client/src/gl/sys_opengl.cpp +++ b/doomsday/apps/client/src/gl/sys_opengl.cpp @@ -141,18 +141,10 @@ dd_bool Sys_GLPreInit(void) if(novideo) return true; if(doneEarlyInit) return true; // Already been here?? - // Init assuming ideal configuration. - //GL_state.multisampleFormat = 0; // No valid default can be assumed at this time. - - //GL_state.features.blendSubtract = true; - //GL_state.features.genMipmap = true; - //GL_state.features.multisample = false; // We'll test for availability... GL_state.features.texCompression = false; GL_state.features.texFilterAniso = true; - GL_state.currentLineWidth = 1.5f; GL_state.currentPointSize = 1.5f; - GL_state.currentUseFog = false; doneEarlyInit = true; return true; @@ -289,9 +281,9 @@ void Sys_GLConfigureDefaultState(void) // Default state for the white fog is off. DGL_Disable(DGL_FOG); - Deferred_glFogi(GL_FOG_MODE, GL_LINEAR); - Deferred_glFogi(GL_FOG_END, 2100); // This should be tweaked a bit. - Deferred_glFogfv(GL_FOG_COLOR, fogcol); + DGL_Fogi(DGL_FOG_MODE, GL_LINEAR); + DGL_Fogi(DGL_FOG_END, 2100); // This should be tweaked a bit. + DGL_Fogfv(DGL_FOG_COLOR, fogcol); LIBGUI_ASSERT_GL_OK(); diff --git a/doomsday/apps/client/src/render/modelrenderer.cpp b/doomsday/apps/client/src/render/modelrenderer.cpp index 23811bbce7..c47cca107e 100644 --- a/doomsday/apps/client/src/render/modelrenderer.cpp +++ b/doomsday/apps/client/src/render/modelrenderer.cpp @@ -138,28 +138,6 @@ DENG2_PIMPL(ModelRenderer) lightCount++; } - void setupFog() - { - if (fogParams.usingFog) - { - uFogColor = Vector4f(fogParams.fogColor[0], - fogParams.fogColor[1], - fogParams.fogColor[2], - 1.f); - - Rangef const depthPlanes = GL_DepthClipRange(); - float const fogDepth = fogParams.fogEnd - fogParams.fogStart; - uFogRange = Vector4f(fogParams.fogStart, - fogDepth, - depthPlanes.start, - depthPlanes.end); - } - else - { - uFogColor = Vector4f(); - } - } - void setupPose(Vector3d const &modelWorldOrigin, Vector3f const &modelOffset, float yawAngle, @@ -231,7 +209,7 @@ DENG2_PIMPL(ModelRenderer) template // generic to accommodate psprites and vispsprites void draw(Params const &p) { - setupFog(); + DGL_FogParams(uFogRange, uFogColor); uTex = static_cast(p.model->textures->atlas()); p.model->draw(&p.animator->appearance(), p.animator); diff --git a/doomsday/apps/client/src/render/r_main.cpp b/doomsday/apps/client/src/render/r_main.cpp index 606bdfdecd..941489d8eb 100644 --- a/doomsday/apps/client/src/render/r_main.cpp +++ b/doomsday/apps/client/src/render/r_main.cpp @@ -172,7 +172,7 @@ void Rend_Draw2DPlayerSprites() if (fogParams.usingFog) { - LIBGUI_GL.glEnable(GL_FOG); + DGL_Enable(DGL_FOG); } // Draw HUD vissprites. @@ -200,7 +200,7 @@ void Rend_Draw2DPlayerSprites() if (fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } } diff --git a/doomsday/apps/client/src/render/rend_main.cpp b/doomsday/apps/client/src/render/rend_main.cpp index 55997b05a2..548b71a1a5 100644 --- a/doomsday/apps/client/src/render/rend_main.cpp +++ b/doomsday/apps/client/src/render/rend_main.cpp @@ -3939,7 +3939,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) // Fog is allowed during this pass. if(fogParams.usingFog) { - LIBGUI_GL.glEnable(GL_FOG); + DGL_Enable(DGL_FOG); } // All of the surfaces are opaque. GLState::current().setBlend(false).apply(); @@ -3969,7 +3969,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) // Fog is allowed during this pass. if(fogParams.usingFog) { - LIBGUI_GL.glEnable(GL_FOG); + DGL_Enable(DGL_FOG); } // All of the surfaces are opaque. GLState::current().setBlend(false).apply(); @@ -4027,7 +4027,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) if(fogParams.usingFog) { DGL_Enable(DGL_FOG); - Deferred_glFogfv(GL_FOG_COLOR, black); + DGL_Fogfv(DGL_FOG_COLOR, black); } GLState::current().setBlend(true).apply(); @@ -4064,7 +4064,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) // Fog is allowed. if(fogParams.usingFog) { - LIBGUI_GL.glEnable(GL_FOG); + DGL_Enable(DGL_FOG); } break; @@ -4078,7 +4078,6 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) // All of the surfaces are opaque. GLState::current().setBlend(true).apply(); - //glBlendFunc(GL_DST_COLOR, GL_ZERO); GLState::current().setBlendFunc(gl::DestColor, gl::Zero).apply(); break; @@ -4093,14 +4092,13 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) // All of the surfaces are opaque. GLState::current().setBlend(true).apply(); - //glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR); GLState::current().setBlendFunc(gl::DestColor, gl::SrcColor).apply(); // Use fog to fade the details, if fog is enabled. if(fogParams.usingFog) { DGL_Enable(DGL_FOG); dfloat const midGray[] = { .5f, .5f, .5f, fogParams.fogColor[3] }; // The alpha is probably meaningless? - Deferred_glFogfv(GL_FOG_COLOR, midGray); + DGL_Fogfv(DGL_FOG_COLOR, midGray); } break; @@ -4116,14 +4114,13 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) // All of the surfaces are opaque. GLState::current().setBlend(true).apply(); - //glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR); GLState::current().setBlendFunc(gl::DestColor, gl::SrcColor).apply(); // Use fog to fade the details, if fog is enabled. if(fogParams.usingFog) { DGL_Enable(DGL_FOG); dfloat const midGray[] = { .5f, .5f, .5f, fogParams.fogColor[3] }; // The alpha is probably meaningless? - Deferred_glFogfv(GL_FOG_COLOR, midGray); + DGL_Fogfv(DGL_FOG_COLOR, midGray); } break; @@ -4141,7 +4138,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) if(fogParams.usingFog) { DGL_Enable(DGL_FOG); - Deferred_glFogfv(GL_FOG_COLOR, fogParams.fogColor); + DGL_Fogfv(DGL_FOG_COLOR, fogParams.fogColor); } GLState::current().setBlend(true).apply(); GL_BlendMode(BM_NORMAL); @@ -4159,8 +4156,8 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) if(fogParams.usingFog) { // Fog makes the shininess diminish in the distance. - DGL_Enable(GL_FOG); - Deferred_glFogfv(GL_FOG_COLOR, black); + DGL_Enable(DGL_FOG); + DGL_Fogfv(DGL_FOG_COLOR, black); } GLState::current().setBlend(true).apply(); GL_BlendMode(BM_ADD); // Purely additive. @@ -4179,8 +4176,8 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap) if(fogParams.usingFog) { // Fog makes the shininess diminish in the distance. - DGL_Enable(GL_FOG); - Deferred_glFogfv(GL_FOG_COLOR, black); + DGL_Enable(DGL_FOG); + DGL_Fogfv(DGL_FOG_COLOR, black); } GLState::current().setBlend(true).apply(); GL_BlendMode(BM_ADD); // Purely additive. @@ -4211,7 +4208,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setDepthTest(false).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } GLState::current().setBlend(true).apply(); break; @@ -4224,7 +4221,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setDepthTest(false).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } GLState::current().setBlend(true).apply(); break; @@ -4254,7 +4251,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setDepthTest(false).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } GL_BlendMode(BM_NORMAL); break; @@ -4273,7 +4270,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setBlend(true).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } break; @@ -4290,7 +4287,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } break; @@ -4302,7 +4299,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } break; @@ -4310,7 +4307,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setDepthTest(false).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } break; @@ -4319,7 +4316,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setDepthTest(false).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } GL_BlendMode(BM_NORMAL); break; @@ -4331,7 +4328,7 @@ static void popGLStateForPass(DrawMode mode) GLState::current().setDepthTest(false).apply(); if(fogParams.usingFog) { - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); } GL_BlendMode(BM_NORMAL); break; @@ -4706,7 +4703,7 @@ static void drawAllLists(Map &map) if(fogParams.usingFog) { DGL_Enable(DGL_FOG); - Deferred_glFogfv(GL_FOG_COLOR, fogParams.fogColor); + DGL_Fogfv(DGL_FOG_COLOR, fogParams.fogColor); } // Draw masked walls, sprites and models.