From c47c7421a36f4594f1637367607ba09666c44b35 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 May 2014 22:57:42 +0200 Subject: [PATCH] - route all glColor calls through render state. - add sector links to dynamic lights. --- src/gl/data/gl_data.h | 4 ++- src/gl/dynlights/a_dynlight.cpp | 46 ++++++++++++++++++++----- src/gl/dynlights/gl_dynlight.h | 4 ++- src/gl/dynlights/gl_dynlight1.cpp | 40 +++++++++++++++++++--- src/gl/renderer/gl_colormap.h | 24 ++++++------- src/gl/renderer/gl_lightdata.cpp | 50 +-------------------------- src/gl/renderer/gl_lightdata.h | 11 ------ src/gl/renderer/gl_renderer.cpp | 57 +++++++++++++------------------ src/gl/scene/gl_decal.cpp | 3 +- src/gl/scene/gl_drawinfo.cpp | 6 ++-- src/gl/scene/gl_flats.cpp | 7 ++-- src/gl/scene/gl_scene.cpp | 14 ++++---- src/gl/scene/gl_skydome.cpp | 6 ++-- src/gl/scene/gl_sprite.cpp | 30 +++++----------- src/gl/scene/gl_walls.cpp | 12 +++---- src/gl/scene/gl_walls_draw.cpp | 10 +++--- src/gl/scene/gl_weapon.cpp | 8 ++--- src/gl/shaders/gl_shader.cpp | 2 ++ src/r_defs.h | 1 + 19 files changed, 160 insertions(+), 175 deletions(-) diff --git a/src/gl/data/gl_data.h b/src/gl/data/gl_data.h index 6a71dd1ac..6a1589cde 100644 --- a/src/gl/data/gl_data.h +++ b/src/gl/data/gl_data.h @@ -33,7 +33,7 @@ EXTERN_CVAR(Int, gl_weaponlight); inline int getExtraLight() { - return extralight * gl_weaponlight; // ((glset.lightmode == 8)? 16:8); + return extralight * gl_weaponlight; } void gl_RecalcVertexHeights(vertex_t * v); @@ -58,4 +58,6 @@ extern TArray currentmapsection; void gl_InitPortals(); void gl_BuildPortalCoverage(FPortalCoverage *coverage, subsector_t *subsector, FPortal *portal); +extern long gl_frameMS; + #endif diff --git a/src/gl/dynlights/a_dynlight.cpp b/src/gl/dynlights/a_dynlight.cpp index bc12288cd..6ac50a785 100644 --- a/src/gl/dynlights/a_dynlight.cpp +++ b/src/gl/dynlights/a_dynlight.cpp @@ -526,6 +526,11 @@ void ADynamicLight::CollectWithinRadius(subsector_t *subSec, float radius) subSec->validcount = ::validcount; touching_subsectors = AddLightNode(&subSec->lighthead[additive], subSec, this, touching_subsectors); + if (subSec->sector->validcount != ::validcount) + { + touching_sector = AddLightNode(&subSec->sector->lighthead[additive], subSec->sector, this, touching_sector); + subSec->sector->validcount = ::validcount; + } for (unsigned int i = 0; i < subSec->numlines; i++) { @@ -537,8 +542,7 @@ void ADynamicLight::CollectWithinRadius(subsector_t *subSec, float radius) if (DMulScale32 (y-seg->v1->y, seg->v2->x-seg->v1->x, seg->v1->x-x, seg->v2->y-seg->v1->y) <=0) { seg->linedef->validcount=validcount; - touching_sides = AddLightNode(&seg->sidedef->lighthead[additive], - seg->sidedef, this, touching_sides); + touching_sides = AddLightNode(&seg->sidedef->lighthead[additive], seg->sidedef, this, touching_sides); } } @@ -581,15 +585,21 @@ void ADynamicLight::LinkLight() node->lightsource = NULL; node = node->nextTarget; } + node = touching_sector; + while (node) + { + node->lightsource = NULL; + node = node->nextTarget; + } if (radius>0) { // passing in radius*radius allows us to do a distance check without any calls to sqrtf - ::validcount++; subsector_t * subSec = R_PointInSubsector(x, y); if (subSec) { float fradius = FIXED2FLOAT(radius); + ::validcount++; CollectWithinRadius(subSec, fradius*fradius); } } @@ -618,6 +628,17 @@ void ADynamicLight::LinkLight() else node = node->nextTarget; } + + node = touching_sector; + while (node) + { + if (node->lightsource == NULL) + { + node = DeleteLightNode(node); + } + else + node = node->nextTarget; + } } @@ -670,8 +691,8 @@ size_t AActor::PropagateMark() CCMD(listlights) { - int walls, sectors; - int allwalls=0, allsectors=0; + int walls, sectors, subsecs; + int allwalls=0, allsectors=0, allsubsecs = 0; int i=0; ADynamicLight * dl; TThinkerIterator it; @@ -680,6 +701,7 @@ CCMD(listlights) { walls=0; sectors=0; + subsecs = 0; Printf("%s at (%f, %f, %f), color = 0x%02x%02x%02x, radius = %f ", dl->target? dl->target->GetClass()->TypeName.GetChars() : dl->GetClass()->TypeName.GetChars(), FIXED2FLOAT(dl->x), FIXED2FLOAT(dl->y), FIXED2FLOAT(dl->z), dl->args[LIGHT_RED], @@ -706,17 +728,25 @@ CCMD(listlights) node=dl->touching_subsectors; + while (node) + { + allsubsecs++; + subsecs++; + node = node->nextTarget; + } + + node = dl->touching_sector; + while (node) { allsectors++; sectors++; node = node->nextTarget; } - - Printf("- %d walls, %d subsectors\n", walls, sectors); + Printf("- %d walls, %d subsectors, %d sectors\n", walls, subsecs, sectors); } - Printf("%i dynamic lights, %d walls, %d subsectors\n\n\n", i, allwalls, allsectors); + Printf("%i dynamic lights, %d walls, %d subsectors, %d sectors\n\n\n", i, allwalls, allsubsecs, allsectors); } CCMD(listsublights) diff --git a/src/gl/dynlights/gl_dynlight.h b/src/gl/dynlights/gl_dynlight.h index dbf89324b..37cbc4f93 100644 --- a/src/gl/dynlights/gl_dynlight.h +++ b/src/gl/dynlights/gl_dynlight.h @@ -95,6 +95,7 @@ public: FState *targetState; FLightNode * touching_sides; FLightNode * touching_subsectors; + FLightNode * touching_sector; private: float DistToSeg(seg_t *seg); @@ -183,8 +184,9 @@ struct FDynLightData bool gl_GetLight(Plane & p, ADynamicLight * light, bool checkside, bool forceadditive, FDynLightData &data); -bool gl_SetupLight(Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right, float & scale, bool checkside=true, bool forceadditive=true); +bool gl_SetupLight(Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right, float & scale, int desaturation, bool checkside=true, bool forceadditive=true); bool gl_SetupLightTexture(); +void gl_UploadLights(FDynLightData &data); #endif diff --git a/src/gl/dynlights/gl_dynlight1.cpp b/src/gl/dynlights/gl_dynlight1.cpp index c1bb9dbbf..f13f24ab6 100644 --- a/src/gl/dynlights/gl_dynlight1.cpp +++ b/src/gl/dynlights/gl_dynlight1.cpp @@ -159,15 +159,13 @@ bool gl_GetLight(Plane & p, ADynamicLight * light, bool checkside, bool forceadd } - - //========================================================================== // // Sets up the parameters to render one dynamic light onto one plane // //========================================================================== bool gl_SetupLight(Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right, - float & scale, bool checkside, bool forceadditive) + float & scale, int desaturation, bool checkside, bool forceadditive) { Vector fn, pos; @@ -225,11 +223,45 @@ bool gl_SetupLight(Plane & p, ADynamicLight * light, Vector & nearPt, Vector & u { gl_RenderState.BlendEquation(GL_FUNC_ADD); } - glColor3f(r,g,b); + gl_RenderState.SetColor(r, g, b, 1.f, desaturation); return true; } +//========================================================================== +// +// +// +//========================================================================== + +#if 0 +void gl_UploadLights(FDynLightData &data) +{ + ParameterBufferElement *pptr; + int size0 = data.arrays[0].Size()/4; + int size1 = data.arrays[1].Size()/4; + int size2 = data.arrays[2].Size()/4; + + if (size0 + size1 + size2 > 0) + { + int sizetotal = size0 + size1 + size2 + 1; + int index = GLRenderer->mParmBuffer->Reserve(sizetotal, &pptr); + + float parmcnt[] = { index + 1, index + 1 + size0, index + 1 + size0 + size1, index + 1 + size0 + size1 + size2 }; + + memcpy(&pptr[0], parmcnt, 4 * sizeof(float)); + memcpy(&pptr[1], &data.arrays[0][0], 4 * size0*sizeof(float)); + memcpy(&pptr[1 + size0], &data.arrays[1][0], 4 * size1*sizeof(float)); + memcpy(&pptr[1 + size0 + size1], &data.arrays[2][0], 4 * size2*sizeof(float)); + gl_RenderState.SetDynLightIndex(index); + } + else + { + gl_RenderState.SetDynLightIndex(-1); + } +} +#endif + //========================================================================== // // diff --git a/src/gl/renderer/gl_colormap.h b/src/gl/renderer/gl_colormap.h index 59ccf9961..7d2bdb7ee 100644 --- a/src/gl/renderer/gl_colormap.h +++ b/src/gl/renderer/gl_colormap.h @@ -13,9 +13,6 @@ enum EColorManipulation CM_INVALID=-1, CM_DEFAULT=0, // untranslated - CM_DESAT0=CM_DEFAULT, - CM_DESAT1, // minimum desaturation - CM_DESAT31=CM_DESAT1+30, // maximum desaturation = grayscale CM_FIRSTSPECIALCOLORMAP, // first special fixed colormap // special internal values for texture creation @@ -34,14 +31,14 @@ struct FColormap { PalEntry LightColor; // a is saturation (0 full, 31=b/w, other=custom colormap) PalEntry FadeColor; // a is fadedensity>>1 - int colormap; + int desaturation; int blendfactor; void Clear() { LightColor=0xffffff; FadeColor=0; - colormap = CM_DEFAULT; + desaturation = 0; blendfactor=0; } @@ -49,19 +46,14 @@ struct FColormap { LightColor.r=LightColor.g=LightColor.b=0xff; blendfactor=0; + desaturation = 0; } - void GetFixedColormap() - { - Clear(); - colormap = gl_fixedcolormap >= (int)CM_LITE? (int)CM_DEFAULT : gl_fixedcolormap; - } - FColormap & operator=(FDynamicColormap * from) { LightColor = from->Color; - colormap = from->Desaturate>>3; + desaturation = from->Desaturate; FadeColor = from->Fade; blendfactor = from->Color.a; return * this; @@ -70,9 +62,15 @@ struct FColormap void CopyLightColor(FDynamicColormap * from) { LightColor = from->Color; - colormap = from->Desaturate>>3; + desaturation = from->Desaturate; blendfactor = from->Color.a; } + + void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark. + { + int v = (LightColor.r + LightColor.g + LightColor.b) / 3; + LightColor.r = LightColor.g = LightColor.b = (255 + v + v) / 3; + } }; diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 7d69ababd..c5bf4c1c8 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -72,22 +72,6 @@ CVAR(Bool, gl_brightfog, false, CVAR_ARCHIVE); -//========================================================================== -// -// -// -//========================================================================== - -bool gl_BrightmapsActive() -{ - return gl.hasGLSL(); -} - -bool gl_GlowActive() -{ - return gl.hasGLSL(); -} - //========================================================================== // // Sets up the fog tables @@ -337,7 +321,7 @@ void gl_SetColor(int light, int rellight, const FColormap * cm, float alpha, boo gl_GetLightColor(light, rellight, cm, &r, &g, &b, weapon); - gl_RenderState.SetColor(r, g, b, alpha); + gl_RenderState.SetColor(r, g, b, alpha, cm->desaturation); if (glset.lightmode == 8) { if (gl_fixedcolormap) @@ -518,15 +502,9 @@ bool gl_CheckFog(sector_t *frontsector, sector_t *backsector) void gl_SetShaderLight(float level, float olight) { -#if 1 //ndef _DEBUG const float MAXDIST = 256.f; const float THRESHOLD = 96.f; const float FACTOR = 0.75f; -#else - const float MAXDIST = 256.f; - const float THRESHOLD = 96.f; - const float FACTOR = 2.75f; -#endif if (level > 0) { @@ -606,9 +584,6 @@ void gl_SetFog(int lightlevel, int rellight, const FColormap *cmap, bool isaddit { fogcolor=0; } - // Handle desaturation - if (cmap->colormap != CM_DEFAULT) - gl_ModifyColor(fogcolor.r, fogcolor.g, fogcolor.b, cmap->colormap); gl_RenderState.EnableFog(true); gl_RenderState.SetFog(fogcolor, fogdensity); @@ -619,29 +594,6 @@ void gl_SetFog(int lightlevel, int rellight, const FColormap *cmap, bool isaddit } } -//========================================================================== -// -// Modifies a color according to a specified colormap -// -//========================================================================== - -void gl_ModifyColor(BYTE & red, BYTE & green, BYTE & blue, int cm) -{ - int gray = (red*77 + green*143 + blue*36)>>8; - if (cm >= CM_FIRSTSPECIALCOLORMAP && cm < CM_MAXCOLORMAP) - { - PalEntry pe = SpecialColormaps[cm - CM_FIRSTSPECIALCOLORMAP].GrayscaleToColor[gray]; - red = pe.r; - green = pe.g; - blue = pe.b; - } - else if (cm >= CM_DESAT1 && cm <= CM_DESAT31) - { - gl_Desaturate(gray, red, green, blue, red, green, blue, cm - CM_DESAT0); - } -} - - //========================================================================== // diff --git a/src/gl/renderer/gl_lightdata.h b/src/gl/renderer/gl_lightdata.h index 8eb70bbb9..b968bfe7a 100644 --- a/src/gl/renderer/gl_lightdata.h +++ b/src/gl/renderer/gl_lightdata.h @@ -5,9 +5,6 @@ #include "r_data/renderstyle.h" #include "gl/renderer/gl_colormap.h" -bool gl_BrightmapsActive(); -bool gl_GlowActive(); - inline int gl_ClampLight(int lightlevel) { return clamp(lightlevel, 0, 255); @@ -46,14 +43,6 @@ inline bool gl_isFullbright(PalEntry color, int lightlevel) return gl_fixedcolormap || (gl_isWhite(color) && lightlevel==255); } -__forceinline void gl_Desaturate(int gray, int ired, int igreen, int iblue, BYTE & red, BYTE & green, BYTE & blue, int fac) -{ - red = (ired*(31-fac) + gray*fac)/31; - green = (igreen*(31-fac) + gray*fac)/31; - blue = (iblue*(31-fac) + gray*fac)/31; -} - -void gl_ModifyColor(BYTE & red, BYTE & green, BYTE & blue, int cm); void gl_DeleteAllAttachedLights(); void gl_RecreateAllAttachedLights(); diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 3e88ebceb..b94995cc7 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -273,10 +273,10 @@ void FGLRenderer::ClearBorders() glLoadIdentity(); glOrtho(0.0, width * 1.0, 0.0, trueHeight, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); - glColor3f(0.f, 0.f, 0.f); + gl_RenderState.SetColor(0.f ,0.f ,0.f ,1.f); gl_RenderState.Set2DMode(true); gl_RenderState.EnableTexture(false); - gl_RenderState.Apply(true); + gl_RenderState.Apply(); glBegin(GL_QUADS); // upper quad @@ -311,36 +311,35 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) double y = parms.y - parms.top * yscale; double w = parms.destwidth; double h = parms.destheight; - float u1, v1, u2, v2, r, g, b; - float light = 1.f; + float u1, v1, u2, v2; + int light = 255; FMaterial * gltex = FMaterial::ValidateTexture(img); if (parms.colorOverlay && (parms.colorOverlay & 0xffffff) == 0) { // Right now there's only black. Should be implemented properly later - light = 1.f - APART(parms.colorOverlay)/255.f; + light = 255 - APART(parms.colorOverlay); parms.colorOverlay = 0; } if (!img->bHasCanvas) { - if (!parms.alphaChannel) + int translation = 0; + if (!parms.alphaChannel) { - int translation = 0; if (parms.remap != NULL && !parms.remap->Inactive) { GLTranslationPalette * pal = static_cast(parms.remap->GetNative()); if (pal) translation = -pal->GetIndex(); } - gltex->BindPatch(translation); } else { // This is an alpha texture gl_RenderState.SetTextureMode(TM_REDTOALPHA); - gltex->BindPatch(0); } + gltex->BindPatch(translation); u1 = gltex->GetUL(); v1 = gltex->GetVT(); @@ -373,17 +372,17 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) u2 = float(u2 - (parms.texwidth - parms.windowright) / parms.texwidth); } + PalEntry color; if (parms.style.Flags & STYLEF_ColorIsFixed) { - r = RPART(parms.fillcolor)/255.0f; - g = GPART(parms.fillcolor)/255.0f; - b = BPART(parms.fillcolor)/255.0f; + color = parms.fillcolor; } else { - r = g = b = light; + color = PalEntry(light, light, light); } - + color.a = Scale(parms.alpha, 255, FRACUNIT); + // scissor test doesn't use the current viewport for the coordinates, so use real screen coordinates int btm = (SCREENHEIGHT - screen->GetHeight()) / 2; btm = SCREENHEIGHT - btm; @@ -398,8 +397,7 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) gl_RenderState.SetTextureMode(TM_OPAQUE); } - glColor4f(r, g, b, FIXED2FLOAT(parms.alpha)); - + gl_RenderState.SetColor(color); gl_RenderState.EnableAlphaTest(false); gl_RenderState.Apply(); glBegin(GL_TRIANGLE_STRIP); @@ -418,8 +416,9 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms) gl_RenderState.SetTextureMode(TM_MASK); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.BlendEquation(GL_FUNC_ADD); + gl_RenderState.SetColor(PalEntry(parms.colorOverlay)); gl_RenderState.Apply(); - glColor4ub(RPART(parms.colorOverlay),GPART(parms.colorOverlay),BPART(parms.colorOverlay),APART(parms.colorOverlay)); + glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(u1, v1); glVertex2d(x, y); @@ -450,8 +449,8 @@ void FGLRenderer::DrawLine(int x1, int y1, int x2, int y2, int palcolor, uint32 { PalEntry p = color? (PalEntry)color : GPalette.BaseColors[palcolor]; gl_RenderState.EnableTexture(false); - gl_RenderState.Apply(true); - glColor3ub(p.r, p.g, p.b); + gl_RenderState.SetColorAlpha(p, 1.f); + gl_RenderState.Apply(); glBegin(GL_LINES); glVertex2i(x1, y1); glVertex2i(x2, y2); @@ -468,8 +467,8 @@ void FGLRenderer::DrawPixel(int x1, int y1, int palcolor, uint32 color) { PalEntry p = color? (PalEntry)color : GPalette.BaseColors[palcolor]; gl_RenderState.EnableTexture(false); - gl_RenderState.Apply(true); - glColor3ub(p.r, p.g, p.b); + gl_RenderState.SetColorAlpha(p, 1.f); + gl_RenderState.Apply(); glBegin(GL_POINTS); glVertex2i(x1, y1); glEnd(); @@ -484,19 +483,13 @@ void FGLRenderer::DrawPixel(int x1, int y1, int palcolor, uint32 color) void FGLRenderer::Dim(PalEntry color, float damount, int x1, int y1, int w, int h) { - float r, g, b; - gl_RenderState.EnableTexture(false); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.AlphaFunc(GL_GREATER,0); - gl_RenderState.Apply(true); - - r = color.r/255.0f; - g = color.g/255.0f; - b = color.b/255.0f; + gl_RenderState.SetColorAlpha(color, damount); + gl_RenderState.Apply(); glBegin(GL_TRIANGLE_FAN); - glColor4f(r, g, b, damount); glVertex2i(x1, y1); glVertex2i(x1, y1 + h); glVertex2i(x1 + w, y1 + h); @@ -536,9 +529,9 @@ void FGLRenderer::FlatFill (int left, int top, int right, int bottom, FTexture * fU2 = float(right-left) / src->GetWidth(); fV2 = float(bottom-top) / src->GetHeight(); } + gl_RenderState.ResetColor(); gl_RenderState.Apply(); glBegin(GL_TRIANGLE_STRIP); - glColor4f(1, 1, 1, 1); glTexCoord2f(fU1, fV1); glVertex2f(left, top); glTexCoord2f(fU1, fV2); glVertex2f(left, bottom); glTexCoord2f(fU2, fV1); glVertex2f(right, top); @@ -609,9 +602,7 @@ void FGLRenderer::FillSimplePoly(FTexture *texture, FVector2 *points, int npoint FColormap cm; cm = colormap; - lightlevel = gl_CalcLightLevel(lightlevel, 0, true); - PalEntry pe = gl_CalcLightColor(lightlevel, cm.LightColor, cm.blendfactor, true); - glColor3ub(pe.r, pe.g, pe.b); + gl_SetColor(lightlevel, 0, &cm, 1.f); gltexture->Bind(); diff --git a/src/gl/scene/gl_decal.cpp b/src/gl/scene/gl_decal.cpp index ed54e9e32..bc878ec0d 100644 --- a/src/gl/scene/gl_decal.cpp +++ b/src/gl/scene/gl_decal.cpp @@ -183,8 +183,7 @@ void GLWall::DrawDecal(DBaseDecal *decal) if (glset.nocoloredspritelighting) { - int v = (Colormap.LightColor.r * 77 + Colormap.LightColor.g*143 + Colormap.LightColor.b*35)/255; - p.LightColor = PalEntry(p.colormap, v, v, v); + p.Decolorize(); } diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 52177cbe2..4db9602dc 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -985,7 +985,7 @@ void FDrawInfo::SetupFloodStencil(wallseg * ws) glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); // increment stencil of valid pixels glColorMask(0,0,0,0); // don't write to the graphics buffer gl_RenderState.EnableTexture(false); - glColor3f(1,1,1); + gl_RenderState.ResetColor(); glEnable(GL_DEPTH_TEST); glDepthMask(true); @@ -1013,7 +1013,7 @@ void FDrawInfo::ClearFloodStencil(wallseg * ws) glStencilOp(GL_KEEP,GL_KEEP,GL_DECR); gl_RenderState.EnableTexture(false); glColorMask(0,0,0,0); // don't write to the graphics buffer - glColor3f(1,1,1); + gl_RenderState.ResetColor(); gl_RenderState.Apply(); glBegin(GL_TRIANGLE_FAN); @@ -1051,7 +1051,7 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo if (gl_fixedcolormap) { - Colormap.GetFixedColormap(); + Colormap.Clear(); lightlevel=255; } else diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 179c087d1..b5a5fc5c6 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -143,12 +143,13 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) } p.Set(plane.plane); - if (!gl_SetupLight(p, light, nearPt, up, right, scale, false, foggy)) + if (!gl_SetupLight(p, light, nearPt, up, right, scale, Colormap.desaturation, false, foggy)) { node=node->nextLight; continue; } draw_dlightf++; + gl_RenderState.Apply(); // Render the light glBegin(GL_TRIANGLE_FAN); @@ -501,7 +502,7 @@ inline void GLFlat::PutFlat(bool fog) if (gl_fixedcolormap) { - Colormap.GetFixedColormap(); + Colormap.Clear(); } if (renderstyle!=STYLE_Translucent || alpha < 1.f - FLT_EPSILON || fog) { @@ -533,7 +534,7 @@ inline void GLFlat::PutFlat(bool fog) else foggy = false; list = list_indices[light][masked][foggy]; - if (list == GLDL_LIGHT && gltexture->tex->gl_info.Brightmap && gl_BrightmapsActive()) list = GLDL_LIGHTBRIGHT; + if (list == GLDL_LIGHT && gltexture->tex->gl_info.Brightmap && gl.hasGLSL()) list = GLDL_LIGHTBRIGHT; gl_drawinfo->drawlists[list].AddFlat (this); } diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 0c4439bc6..4b47abb1f 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -474,7 +474,7 @@ void FGLRenderer::RenderScene(int recursion) } // third pass: modulated texture - glColor3f(1.0f, 1.0f, 1.0f); + gl_RenderState.ResetColor(); gl_RenderState.BlendFunc(GL_DST_COLOR, GL_ZERO); gl_RenderState.EnableFog(false); glDepthFunc(GL_LEQUAL); @@ -619,7 +619,7 @@ static void FillScreen() { gl_RenderState.EnableAlphaTest(false); gl_RenderState.EnableTexture(false); - gl_RenderState.Apply(true); + gl_RenderState.Apply(); glBegin(GL_TRIANGLE_STRIP); glVertex2f(0.0f, 0.0f); glVertex2f(0.0f, (float)SCREENHEIGHT); @@ -715,7 +715,7 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) if (extra_red || extra_green || extra_blue) { gl_RenderState.BlendFunc(GL_DST_COLOR, GL_ZERO); - glColor4f(extra_red, extra_green, extra_blue, 1.0f); + gl_RenderState.SetColor(extra_red, extra_green, extra_blue, 1.0f); FillScreen(); } } @@ -773,14 +773,14 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) if (inverse) { gl_RenderState.BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - glColor4f(1.f, 1.f, 1.f, 1.f); + gl_RenderState.ResetColor(); FillScreen(); } if (r < WHITE_THRESH || g < WHITE_THRESH || b < WHITE_THRESH) { gl_RenderState.BlendFunc(GL_DST_COLOR, GL_ZERO); - glColor4f(r, g, b, 1.0f); + gl_RenderState.SetColor(r, g, b, 1.0f); FillScreen(); } } @@ -806,7 +806,7 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) if (blend[3]>0.0f) { gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4fv(blend); + gl_RenderState.SetColor(blend[0], blend[1], blend[2], blend[3]); FillScreen(); } } @@ -850,7 +850,7 @@ void FGLRenderer::EndDrawScene(sector_t * viewsector) // Restore standard rendering state gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor3f(1.0f,1.0f,1.0f); + gl_RenderState.ResetColor(); gl_RenderState.EnableTexture(true); gl_RenderState.EnableAlphaTest(true); glDisable(GL_SCISSOR_TEST); diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index f56076ef6..5492a1649 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -109,7 +109,7 @@ static void SkyVertex(int r, int c) if (!foglayer) { - // this cannot use the renderstate because it's inside a primitive. + // this must not use the renderstate because it's inside a primitive. glColor4f(1.f, 1.f, 1.f, r==0? 0.0f : 1.0f); // And the texture coordinates. @@ -244,7 +244,7 @@ static void RenderDome(FTextureID texno, FMaterial * tex, float x_offset, float int texh = 0; bool texscale = false; - // 57 worls units roughly represent one sky texel for the glTranslate call. + // 57 world units roughly represent one sky texel for the glTranslate call. const float skyoffsetfactor = 57; if (tex) @@ -511,7 +511,7 @@ void GLSkyPortal::DrawContents() FadeColor = origin->fadecolor; } - gl_RenderState.SetColor(0xffffffff); + gl_RenderState.ResetColor(); gl_RenderState.EnableFog(false); gl_RenderState.EnableAlphaTest(false); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 9c8bba2f0..325fe9082 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -112,10 +112,6 @@ void GLSprite::Draw(int pass) { if (pass!=GLPASS_PLAIN && pass != GLPASS_ALL && pass!=GLPASS_TRANSLUCENT) return; - // Hack to enable bright sprites in faded maps - uint32 backupfade = Colormap.FadeColor.d; - if (gl_spritebrightfog && fullbright) - Colormap.FadeColor = 0; bool additivefog = false; @@ -126,16 +122,15 @@ void GLSprite::Draw(int pass) { // The translucent pass requires special setup for the various modes. - // Brightmaps will only be used when doing regular drawing ops and having no fog - if (!gl_spritebrightfog && (!gl_isBlack(Colormap.FadeColor) || level.flags&LEVEL_HASFADETABLE || - RenderStyle.BlendOp != STYLEOP_Add)) + // for special render styles brightmaps would not look good - especially for subtractive. + if (RenderStyle.BlendOp != STYLEOP_Add) { gl_RenderState.EnableBrightmap(false); } gl_SetRenderStyle(RenderStyle, false, // The rest of the needed checks are done inside gl_SetRenderStyle - trans > 1.f - FLT_EPSILON && gl_usecolorblending && gl_fixedcolormap < CM_FIRSTSPECIALCOLORMAP && actor && + trans > 1.f - FLT_EPSILON && gl_usecolorblending && gl_fixedcolormap == CM_DEFAULT && actor && fullbright && gltexture && !gltexture->GetTransparent()); if (hw_styleflags == STYLEHW_NoAlphaTest) @@ -169,7 +164,7 @@ void GLSprite::Draw(int pass) } gl_RenderState.AlphaFunc(GL_GEQUAL,minalpha*gl_mask_sprite_threshold); - gl_RenderState.SetColor(0.2f,0.2f,0.2f,fuzzalpha); + gl_RenderState.SetColor(0.2f,0.2f,0.2f,fuzzalpha, Colormap.desaturation); additivefog = true; } else if (RenderStyle.BlendOp == STYLEOP_Add && RenderStyle.DestAlpha == STYLEALPHA_One) @@ -339,12 +334,8 @@ void GLSprite::Draw(int pass) } } - // End of gl_sprite_brightfog hack: restore FadeColor to normalcy - if (backupfade != Colormap.FadeColor.d) - Colormap.FadeColor = backupfade; - - gl_RenderState.EnableTexture(true); gl_RenderState.SetObjectColor(0xffffffff); + gl_RenderState.EnableTexture(true); gl_RenderState.SetDynLight(0,0,0); } @@ -696,7 +687,7 @@ void GLSprite::Process(AActor* thing,sector_t * sector) // allow disabling of the fullbright flag by a brightmap definition // (e.g. to do the gun flashes of Doom's zombies correctly. fullbright = (thing->flags5 & MF5_BRIGHT) || - ((thing->renderflags & RF_FULLBRIGHT) && (!gl_BrightmapsActive() || !gltexture || !gltexture->tex->gl_info.bBrightmapDisablesFullbright)); + ((thing->renderflags & RF_FULLBRIGHT) && (!gl.hasGLSL() || !gltexture || !gltexture->tex->gl_info.bBrightmapDisablesFullbright)); lightlevel=fullbright? 255 : gl_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? @@ -717,7 +708,7 @@ void GLSprite::Process(AActor* thing,sector_t * sector) || (gl_enhanced_nv_stealth == 3)) // Any fixed colormap enhancedvision=true; - Colormap.GetFixedColormap(); + Colormap.Clear(); if (gl_fixedcolormap==CM_LITE) { @@ -750,10 +741,7 @@ void GLSprite::Process(AActor* thing,sector_t * sector) } else if (glset.nocoloredspritelighting) { - int v = (Colormap.LightColor.r /* * 77 */ + Colormap.LightColor.g /**143 */ + Colormap.LightColor.b /**35*/)/3;//255; - Colormap.LightColor.r= - Colormap.LightColor.g= - Colormap.LightColor.b=(255+v+v)/3; + Colormap.Decolorize(); } } @@ -894,7 +882,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s if (gl_fixedcolormap) { - Colormap.GetFixedColormap(); + Colormap.Clear(); } else if (!particle->bright) { diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index e8c23ad81..2d6b78fd5 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -71,7 +71,7 @@ void GLWall::CheckGlowing() { bottomglowcolor[3] = topglowcolor[3] = 0; - if (!gl_isFullbright(Colormap.LightColor, lightlevel) && gl_GlowActive()) + if (!gl_isFullbright(Colormap.LightColor, lightlevel) && gl.hasGLSL()) { FTexture *tex = TexMan[topflat]; if (tex != NULL && tex->isGlowing()) @@ -133,7 +133,7 @@ void GLWall::PutWall(bool translucent) // light planes don't get drawn with fullbright rendering if (!gltexture && passflag[type]!=4) return; - Colormap.GetFixedColormap(); + Colormap.Clear(); } CheckGlowing(); @@ -184,7 +184,7 @@ void GLWall::PutWall(bool translucent) list = list_indices[light][masked][!!(flags&GLWF_FOGGY)]; if (list == GLDL_LIGHT) { - if (gltexture->tex->gl_info.Brightmap && gl_BrightmapsActive()) list = GLDL_LIGHTBRIGHT; + if (gltexture->tex->gl_info.Brightmap && gl.hasGLSL()) list = GLDL_LIGHTBRIGHT; if (flags & GLWF_GLOW) list = GLDL_LIGHTBRIGHT; } gl_drawinfo->drawlists[list].AddWall(this); @@ -525,7 +525,7 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) hi.colormap.LightColor = (light->extra_colormap)->Color; } - if (gl_fixedcolormap) hi.colormap.GetFixedColormap(); + if (gl_fixedcolormap) hi.colormap.Clear(); horizon = &hi; PutWall(0); } @@ -554,8 +554,8 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) hi.colormap.LightColor = (light->extra_colormap)->Color; } - if (gl_fixedcolormap) hi.colormap.GetFixedColormap(); - horizon=&hi; + if (gl_fixedcolormap) hi.colormap.Clear(); + horizon = &hi; PutWall(0); } } diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 38adfeeab..937549195 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -81,7 +81,7 @@ bool GLWall::PrepareLight(texcoord * tcs, ADynamicLight * light) return false; } - if (!gl_SetupLight(p, light, nearPt, up, right, scale, true, !!(flags&GLWF_FOGGY))) + if (!gl_SetupLight(p, light, nearPt, up, right, scale, Colormap.desaturation, true, !!(flags&GLWF_FOGGY))) { return false; } @@ -267,7 +267,7 @@ void GLWall::RenderWall(int textured, float * color2, ADynamicLight * light) if (split && !(flags & GLWF_NOSPLITUPPER)) SplitUpperEdge(tcs); - // color for right side + // color for right side (do not set in render state!) if (color2) glColor4fv(color2); // upper right corner @@ -365,15 +365,13 @@ void GLWall::RenderFogBoundary() float fogd1=(0.95f-exp(-fogdensity*dist1/62500.f)) * 1.05f; float fogd2=(0.95f-exp(-fogdensity*dist2/62500.f)) * 1.05f; - gl_ModifyColor(Colormap.FadeColor.r, Colormap.FadeColor.g, Colormap.FadeColor.b, Colormap.colormap); 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_GREATER,0); glDepthFunc(GL_LEQUAL); - glColor4f(fc[0],fc[1],fc[2], fogd1); - gl_RenderState.SetColor(-1, 0, 0, 0); // we do not want the render state to control the color. + gl_RenderState.SetColor(fc[0], fc[1], fc[2], fogd1, Colormap.desaturation); if (glset.lightmode == 8) glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0); // Korshun. flags &= ~GLWF_GLOW; @@ -406,10 +404,10 @@ void GLWall::RenderMirrorSurface() gl_RenderState.SetEffect(EFF_SPHEREMAP); gl_SetColor(lightlevel, 0, &Colormap ,0.1f); + gl_SetFog(lightlevel, 0, &Colormap, true); gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE); gl_RenderState.AlphaFunc(GL_GREATER,0); glDepthFunc(GL_LEQUAL); - gl_SetFog(lightlevel, getExtraLight(), &Colormap, true); FMaterial * pat=FMaterial::ValidateTexture(GLRenderer->mirrortexture); pat->BindPatch(0); diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index d582b7165..57d05931f 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -203,7 +203,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) { bool disablefullbright = false; FTextureID lump = gl_GetSpriteFrame(psp->sprite, psp->frame, 0, 0, NULL); - if (lump.isValid() && gl_BrightmapsActive()) + if (lump.isValid() && gl.hasGLSL()) { FMaterial * tex=FMaterial::ValidateTexture(lump, false); if (tex) @@ -217,7 +217,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) if (gl_fixedcolormap) { lightlevel=255; - cm.GetFixedColormap(); + cm.Clear(); statebright[0] = statebright[1] = true; fakesec = viewsector; } @@ -294,7 +294,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) playermo->Inventory->AlterWeaponSprite(&vis); if (vis.colormap >= SpecialColormaps[0].Colormap && vis.colormap < SpecialColormaps[SpecialColormaps.Size()].Colormap && - cm.colormap == CM_DEFAULT) + gl_fixedcolormap == CM_DEFAULT) { // this only happens for Strife's inverted weapon sprite vis.RenderStyle.Flags |= STYLEF_InvertSource; @@ -379,7 +379,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) // set the lighting parameters if (vis.RenderStyle.BlendOp == STYLEOP_Shadow) { - gl_RenderState.SetColor(0.2f, 0.2f, 0.2f, 0.33f);// 0x55333333, cmc.desaturation); + gl_RenderState.SetColor(0.2f, 0.2f, 0.2f, 0.33f, cmc.desaturation); } else { diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 8f993b857..768d3ad53 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -393,6 +393,7 @@ FShader *FShaderContainer::Bind(int cm, bool glowing, float Speed, bool lights) glUniform3fv(sh->colormaprange_index, 1, m); } } + /* else { bool desat = cm>=CM_DESAT1 && cm<=CM_DESAT31; @@ -407,6 +408,7 @@ FShader *FShaderContainer::Bind(int cm, bool glowing, float Speed, bool lights) } } } + */ return sh; } diff --git a/src/r_defs.h b/src/r_defs.h index bb2401684..80f908e81 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -771,6 +771,7 @@ struct sector_t int subsectorcount; // list of subsectors subsector_t ** subsectors; FPortal * portals[2]; // floor and ceiling portals + FLightNode * lighthead[2]; enum {