From 0a943719748a4b672628211313f7b7fd53885abf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 3 May 2016 23:28:42 +0200 Subject: [PATCH] - reinstated old code for rendering fog boundaries and mirrot surfaces without shaders. - added code for filling the render list for textured dynamic lights. This is not yet active because no code is present to handle this data. --- src/gl/compatibility/gl_20.cpp | 92 +++++++++++++++++++++++++++++++++- src/gl/scene/gl_wall.h | 3 ++ src/gl/scene/gl_walls.cpp | 5 ++ src/gl/scene/gl_walls_draw.cpp | 44 ++++++++++------ src/gl/system/gl_load.c | 2 + 5 files changed, 130 insertions(+), 16 deletions(-) diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index e059a35635..1dac5ac383 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -49,6 +49,7 @@ #include "gl/dynlights/gl_dynlight.h" #include "gl/utility/gl_geometric.h" #include "gl/renderer/gl_renderer.h" +#include "gl/renderer/gl_lightdata.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_cvars.h" #include "gl/renderer/gl_renderstate.h" @@ -452,7 +453,7 @@ bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, Vector & nearPt, bool gl_SetupLightTexture() { - if (GLRenderer->gllight == NULL) return false; + if (GLRenderer->gllight == nullptr) return false; FMaterial * pat = FMaterial::ValidateTexture(GLRenderer->gllight, false); pat->Bind(CLAMP_XY, 0); return true; @@ -464,6 +465,95 @@ bool gl_SetupLightTexture() // //========================================================================== +bool GLWall::PutWallCompat(int passflag) +{ + static int list_indices[2][2] = + { { GLLDL_WALLS_PLAIN, GLLDL_WALLS_FOG },{ GLLDL_WALLS_MASKED, GLLDL_WALLS_FOGMASKED } }; + + // are lights possible? + if (gl_fixedcolormap != CM_DEFAULT || !gl_lights || seg->sidedef == nullptr || type == RENDERWALL_M2SNF || !gltexture) return false; + + // multipassing these is problematic. + if ((flags&GLWF_SKYHACK && type == RENDERWALL_M2S)) return false; + + // Any lights affecting this wall? + if (!(seg->sidedef->Flags & WALLF_POLYOBJ)) + { + if (seg->sidedef->lighthead == nullptr) return false; + } + else if (sub) + { + if (sub->lighthead != nullptr) return false; + } + + bool foggy = (!gl_isBlack(Colormap.FadeColor) || level.flags&LEVEL_HASFADETABLE); + bool masked = passflag == 2 && gltexture->isMasked(); + + int list = list_indices[masked][foggy]; + if (list == GLLDL_WALLS_PLAIN) + { + if (gltexture->tex->gl_info.Brightmap && gl.glslversion >= 0.f) list = GLLDL_WALLS_BRIGHT; + //if (flags & GLWF_GLOW) list = GLLDL_WALLS_BRIGHT; + } + gl_drawinfo->dldrawlists[list].AddWall(this); + return true; + +} + +//========================================================================== +// +// Fog boundary without any shader support +// +//========================================================================== + +void GLWall::RenderFogBoundaryCompat() +{ + // without shaders some approximation is needed. This won't look as good + // as the shader version but it's an acceptable compromise. + float fogdensity = gl_GetFogDensity(lightlevel, Colormap.FadeColor); + + float dist1 = Dist2(ViewPos.X, ViewPos.Y, glseg.x1, glseg.y1); + float dist2 = Dist2(ViewPos.X, ViewPos.Y, glseg.x2, glseg.y2); + + // these values were determined by trial and error and are scale dependent! + float fogd1 = (0.95f - exp(-fogdensity*dist1 / 62500.f)) * 1.05f; + float fogd2 = (0.95f - exp(-fogdensity*dist2 / 62500.f)) * 1.05f; + + float fc[4] = { Colormap.FadeColor.r / 255.0f,Colormap.FadeColor.g / 255.0f,Colormap.FadeColor.b / 255.0f,fogd2 }; + + gl_RenderState.EnableTexture(false); + gl_RenderState.EnableFog(false); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0); + gl_RenderState.Apply(); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(-1.0f, -128.0f); + glDepthFunc(GL_LEQUAL); + glColor4f(fc[0], fc[1], fc[2], fogd1); + glBegin(GL_TRIANGLE_FAN); + glTexCoord2f(lolft.u, lolft.v); + glVertex3f(glseg.x1, zbottom[0], glseg.y1); + glTexCoord2f(uplft.u, uplft.v); + glVertex3f(glseg.x1, ztop[0], glseg.y1); + glColor4f(fc[0], fc[1], fc[2], fogd2); + glTexCoord2f(uprgt.u, uprgt.v); + glVertex3f(glseg.x2, ztop[1], glseg.y2); + glTexCoord2f(lorgt.u, lorgt.v); + glVertex3f(glseg.x2, zbottom[1], glseg.y2); + glEnd(); + glDepthFunc(GL_LESS); + glPolygonOffset(0.0f, 0.0f); + glDisable(GL_POLYGON_OFFSET_FILL); + gl_RenderState.EnableFog(true); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.5f); + gl_RenderState.EnableTexture(true); +} + +//========================================================================== +// +// +// +//========================================================================== + void FGLRenderer::RenderMultipassStuff() { return; diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index 0d8096e76b..fdf78ee6f4 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -171,10 +171,13 @@ public: private: void CheckGlowing(); + bool PutWallCompat(int passflag); void PutWall(bool translucent); void PutPortal(int ptype); void CheckTexturePosition(); + void RenderFogBoundaryCompat(); + void Put3DWall(lightlist_t * lightlist, bool translucent); void SplitWallComplex(sector_t * frontsector, bool translucent, float maplightbottomleft, float maplightbottomright); void SplitWall(sector_t * frontsector, bool translucent); diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index ae7cb70c86..906f7f3e12 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -139,6 +139,11 @@ void GLWall::PutWall(bool translucent) } else { + if (gl.lightmethod == LM_SOFTWARE && !translucent) + { + // This is not yet ready. + //if (PutWallCompat(passflag[type])) return; + } bool masked; diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 8fe9d948ec..9fe120ae28 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -228,16 +228,23 @@ void GLWall::RenderFogBoundary() { if (gl_fogmode && gl_fixedcolormap == 0) { - int rel = rellight + getExtraLight(); - gl_SetFog(lightlevel, rel, &Colormap, false); - gl_RenderState.SetEffect(EFF_FOGBOUNDARY); - gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.0f, -128.0f); - RenderWall(RWF_BLANK); - glPolygonOffset(0.0f, 0.0f); - glDisable(GL_POLYGON_OFFSET_FILL); - gl_RenderState.SetEffect(EFF_NONE); + if (gl.glslversion > 0.f) + { + int rel = rellight + getExtraLight(); + gl_SetFog(lightlevel, rel, &Colormap, false); + gl_RenderState.SetEffect(EFF_FOGBOUNDARY); + gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(-1.0f, -128.0f); + RenderWall(RWF_BLANK); + glPolygonOffset(0.0f, 0.0f); + glDisable(GL_POLYGON_OFFSET_FILL); + gl_RenderState.SetEffect(EFF_NONE); + } + else + { + RenderFogBoundaryCompat(); + } } } @@ -255,12 +262,19 @@ void GLWall::RenderMirrorSurface() Vector v(glseg.y2-glseg.y1, 0 ,-glseg.x2+glseg.x1); v.Normalize(); - // we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is. - lolft.u = lorgt.u = uplft.u = uprgt.u = v.X(); - lolft.v = lorgt.v = uplft.v = uprgt.v = v.Z(); + if (gl.glslversion >= 0.f) + { + // we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is. + lolft.u = lorgt.u = uplft.u = uprgt.u = v.X(); + lolft.v = lorgt.v = uplft.v = uprgt.v = v.Z(); - gl_RenderState.EnableTextureMatrix(true); - gl_RenderState.mTextureMatrix.computeNormalMatrix(gl_RenderState.mViewMatrix); + gl_RenderState.EnableTextureMatrix(true); + gl_RenderState.mTextureMatrix.computeNormalMatrix(gl_RenderState.mViewMatrix); + } + else + { + glNormal3fv(&v[0]); + } // Use sphere mapping for this gl_RenderState.SetEffect(EFF_SPHEREMAP); diff --git a/src/gl/system/gl_load.c b/src/gl/system/gl_load.c index 9b89f2880c..aed4e0ff8a 100644 --- a/src/gl/system/gl_load.c +++ b/src/gl/system/gl_load.c @@ -42,6 +42,8 @@ static void* SunGetProcAddress (const GLubyte* name) #if defined(_WIN32) #ifdef _MSC_VER +// disable inlining here because it creates an incredible amount of bloat in this file. +#pragma inline_depth(0) #pragma warning(disable: 4055) #pragma warning(disable: 4054) #pragma warning(disable: 4996)