From 9a24771a7d6478c4140859652192a32342ee0eac Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Mar 2017 16:47:42 +0100 Subject: [PATCH] - refactored FDynamicColormap out of sector_t. This has increasingly become an obstacle with the hardware renderer, so now the values are being stored as plain data in the sector, with the software renderer getting the actual color tables when needed. While this is a bit slower than storing the pregenerated colormap, in realistic situations the added time is mostly negligible in the microseconds range. --- src/am_map.cpp | 23 ++--- src/doomtype.h | 12 +++ src/fragglescript/t_func.cpp | 4 +- src/fragglescript/t_load.cpp | 5 + src/fragglescript/t_script.h | 4 +- src/gl/compatibility/gl_20.cpp | 4 +- src/gl/renderer/gl_2ddrawer.cpp | 6 +- src/gl/renderer/gl_2ddrawer.h | 4 +- src/gl/renderer/gl_colormap.h | 53 ----------- src/gl/renderer/gl_lightdata.cpp | 10 +- src/gl/renderer/gl_lightdata.h | 9 -- src/gl/renderer/gl_renderer.h | 2 +- src/gl/scene/gl_drawinfo.cpp | 4 +- src/gl/scene/gl_fakeflat.cpp | 6 +- src/gl/scene/gl_flats.cpp | 16 ++-- src/gl/scene/gl_portal.cpp | 4 +- src/gl/scene/gl_renderhacks.cpp | 6 +- src/gl/scene/gl_scene.cpp | 2 +- src/gl/scene/gl_sprite.cpp | 96 ++++++++++---------- src/gl/scene/gl_walls.cpp | 14 +-- src/gl/scene/gl_weapon.cpp | 8 +- src/gl/system/gl_framebuffer.cpp | 2 +- src/gl/system/gl_framebuffer.h | 2 +- src/gl/system/gl_swframebuffer.cpp | 23 ++--- src/gl/system/gl_swframebuffer.h | 2 +- src/p_3dfloors.cpp | 41 ++++----- src/p_3dfloors.h | 7 +- src/p_acs.cpp | 4 +- src/p_saveg.cpp | 26 +++++- src/p_sectors.cpp | 31 +++++-- src/p_setup.cpp | 25 ++--- src/p_udmf.cpp | 23 ++--- src/polyrenderer/scene/poly_decal.cpp | 2 +- src/polyrenderer/scene/poly_particle.cpp | 2 +- src/polyrenderer/scene/poly_plane.cpp | 4 +- src/polyrenderer/scene/poly_playersprite.cpp | 2 +- src/polyrenderer/scene/poly_sprite.cpp | 2 +- src/polyrenderer/scene/poly_wall.cpp | 6 +- src/polyrenderer/scene/poly_wallsprite.cpp | 2 +- src/r_data/colormaps.h | 70 ++++++++++++++ src/r_defs.h | 32 ++++++- src/swrenderer/line/r_line.cpp | 10 +- src/swrenderer/line/r_renderdrawsegment.cpp | 16 ++-- src/swrenderer/line/r_walldraw.cpp | 2 +- src/swrenderer/r_swcanvas.cpp | 3 +- src/swrenderer/r_swcanvas.h | 2 +- src/swrenderer/scene/r_opaque_pass.cpp | 25 +++-- src/swrenderer/things/r_particle.cpp | 8 +- src/swrenderer/things/r_playersprite.cpp | 8 +- src/swrenderer/things/r_visiblesprite.cpp | 4 +- src/v_draw.cpp | 2 +- src/v_video.h | 3 +- src/version.h | 4 +- src/win32/fb_d3d9.cpp | 23 ++--- src/win32/win32swiface.h | 2 +- 55 files changed, 386 insertions(+), 326 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index fb89133a8..dcf988f10 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -1936,7 +1936,7 @@ sector_t * AM_FakeFlat(AActor *viewer, sector_t * sec, sector_t * dest) { if (in_area == -1) { - dest->ColorMap = s->ColorMap; + dest->Colormap = s->Colormap; if (!(s->MoreFlags & SECF_NOFAKELIGHT)) { dest->lightlevel = s->lightlevel; @@ -1956,7 +1956,7 @@ sector_t * AM_FakeFlat(AActor *viewer, sector_t * sec, sector_t * dest) if (in_area == -1) { - dest->ColorMap = s->ColorMap; + dest->Colormap = s->Colormap; dest->SetPlaneTexZ(sector_t::floor, sec->GetPlaneTexZ(sector_t::floor)); dest->floorplane = sec->floorplane; if (!(s->MoreFlags & SECF_NOFAKELIGHT)) @@ -1975,7 +1975,7 @@ sector_t * AM_FakeFlat(AActor *viewer, sector_t * sec, sector_t * dest) } else if (in_area == 1) { - dest->ColorMap = s->ColorMap; + dest->Colormap = s->Colormap; dest->SetPlaneTexZ(sector_t::floor, s->GetPlaneTexZ(sector_t::ceiling)); dest->floorplane = s->ceilingplane; if (!(s->MoreFlags & SECF_NOFAKELIGHT)) @@ -2016,7 +2016,7 @@ void AM_drawSubsectors() int floorlight; double scalex, scaley; double originx, originy; - FDynamicColormap *colormap; + FColormap colormap; PalEntry flatcolor; mpoint_t originpt; @@ -2058,7 +2058,7 @@ void AM_drawSubsectors() originpt.y = sec->GetYOffset(sector_t::floor); rotation = -sec->GetAngle(sector_t::floor); // Coloring for the polygon - colormap = sec->ColorMap; + colormap = sec->Colormap; FTextureID maptex = sec->GetTexture(sector_t::floor); flatcolor = sec->SpecialColors[sector_t::floor]; @@ -2150,14 +2150,11 @@ void AM_drawSubsectors() // to see it on the map), tint and desaturate it. if (!(subsectors[i].flags & SSECF_DRAWN)) { - colormap = GetSpecialLights( - MAKERGB( - (colormap->Color.r + 255) / 2, - (colormap->Color.g + 200) / 2, - (colormap->Color.b + 160) / 2), - colormap->Fade, - 255 - (255 - colormap->Desaturate) / 4); - floorlight = (floorlight + 200 * 15) / 16; + colormap.LightColor = PalEntry( + (colormap.LightColor.r + 255) / 2, + (colormap.LightColor.g + 200) / 2, + (colormap.LightColor.b + 160) / 2); + colormap.Desaturation = 255 - (255 - colormap.Desaturation) / 4; } // Draw the polygon. diff --git a/src/doomtype.h b/src/doomtype.h index 15717b65a..432fd3dd8 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -120,6 +120,18 @@ struct PalEntry PalEntry () {} PalEntry (uint32_t argb) { d = argb; } operator uint32_t () const { return d; } + void SetRGB(PalEntry other) + { + d = other.d & 0xffffff; + } + bool isBlack() const + { + return (d & 0xffffff) == 0; + } + bool isWhite() const + { + return (d & 0xffffff) == 0xffffff; + } PalEntry &operator= (uint32_t other) { d = other; return *this; } PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; } #ifdef __BIG_ENDIAN__ diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 580080d9d..ea9600afa 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -3885,7 +3885,9 @@ void FParser::SF_SetColor(void) while ((i = itr.Next()) >= 0) { if (!DFraggleThinker::ActiveThinker->setcolormaterial) - level.sectors[i].ColorMap = GetSpecialLights(color, level.sectors[i].ColorMap->Fade, 0); + { + level.sectors[i].SetColor(color.r, color.g, color.b, 0); + } else { // little hack for testing the D64 color stuff. diff --git a/src/fragglescript/t_load.cpp b/src/fragglescript/t_load.cpp index 16eab219e..99818a53d 100644 --- a/src/fragglescript/t_load.cpp +++ b/src/fragglescript/t_load.cpp @@ -327,6 +327,11 @@ bool FScriptLoader::ParseInfo(MapData * map) DFraggleThinker::ActiveThinker->nocheckposition = opt->nocheckposition; DFraggleThinker::ActiveThinker->setcolormaterial = opt->setcolormaterial; } + else + { + DFraggleThinker::ActiveThinker->nocheckposition = false; + DFraggleThinker::ActiveThinker->setcolormaterial = false; + } } diff --git a/src/fragglescript/t_script.h b/src/fragglescript/t_script.h index bf990b679..11977f9d2 100644 --- a/src/fragglescript/t_script.h +++ b/src/fragglescript/t_script.h @@ -694,8 +694,8 @@ public: TObjPtr LevelScript; TObjPtr RunningScripts; TArray > SpawnedThings; - bool nocheckposition; - bool setcolormaterial; + bool nocheckposition = false; + bool setcolormaterial = false; DFraggleThinker(); void OnDestroy() override; diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 78c2ac833..b1dbdee7d 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -485,7 +485,7 @@ static bool gl_CheckFog(FColormap *cm, int lightlevel) { frontfog = true; } - else if (level.fogdensity != 0 || (glset.lightmode & 4) || cm->fogdensity > 0) + else if (level.fogdensity != 0 || (glset.lightmode & 4) || cm->FogDensity > 0) { // case 3: level has fog density set frontfog = true; @@ -568,7 +568,7 @@ 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, Colormap.fogdensity); + float fogdensity = gl_GetFogDensity(lightlevel, Colormap.FadeColor, Colormap.FogDensity); float dist1 = Dist2(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, glseg.x1, glseg.y1); float dist2 = Dist2(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, glseg.x2, glseg.y2); diff --git a/src/gl/renderer/gl_2ddrawer.cpp b/src/gl/renderer/gl_2ddrawer.cpp index 5a89fd820..d95bb9eed 100644 --- a/src/gl/renderer/gl_2ddrawer.cpp +++ b/src/gl/renderer/gl_2ddrawer.cpp @@ -174,7 +174,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel) + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel) { FMaterial *gltexture = FMaterial::ValidateTexture(texture, false); @@ -435,9 +435,7 @@ void F2DDrawer::Draw() { DataSimplePoly *dsp = static_cast(dg); - FColormap cm; - cm = dsp->mColormap; - gl_SetColor(dsp->mLightLevel, 0, false, cm, 1.f); + gl_SetColor(dsp->mLightLevel, 0, false, dsp->mColormap, 1.f); gl_RenderState.SetMaterial(dsp->mTexture, CLAMP_NONE, 0, -1, false); gl_RenderState.SetObjectColor(dsp->mFlatColor|0xff000000); gl_RenderState.Apply(); diff --git a/src/gl/renderer/gl_2ddrawer.h b/src/gl/renderer/gl_2ddrawer.h index 80003b159..417f06ceb 100644 --- a/src/gl/renderer/gl_2ddrawer.h +++ b/src/gl/renderer/gl_2ddrawer.h @@ -44,7 +44,7 @@ class F2DDrawer : public FSimpleVertexBuffer { FMaterial *mTexture; int mLightLevel; - FDynamicColormap *mColormap; + FColormap mColormap; PalEntry mFlatColor; }; @@ -62,7 +62,7 @@ public: void AddPoly(FTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel); + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel); void AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t color); void AddPixel(int x1, int y1, int palcolor, uint32_t color); diff --git a/src/gl/renderer/gl_colormap.h b/src/gl/renderer/gl_colormap.h index cba2254f2..85988e0b8 100644 --- a/src/gl/renderer/gl_colormap.h +++ b/src/gl/renderer/gl_colormap.h @@ -23,58 +23,5 @@ enum EColorManipulation #define CM_MAXCOLORMAP int(CM_FIRSTSPECIALCOLORMAP + SpecialColormaps.Size()) - // for internal use -struct FColormap -{ - PalEntry LightColor; // a is saturation (0 full, 31=b/w, other=custom colormap) - PalEntry FadeColor; // a is fadedensity>>1 - int desaturation; - int blendfactor; - int fogdensity; - - void Clear() - { - LightColor=0xffffff; - FadeColor=0; - desaturation = 0; - blendfactor=0; - fogdensity = 0; - } - - void ClearColor() - { - LightColor.r=LightColor.g=LightColor.b=0xff; - blendfactor=0; - desaturation = 0; - } - - - FColormap & operator=(FDynamicColormap * from) - { - LightColor = from->Color; - desaturation = from->Desaturate; - FadeColor = from->Fade; - FadeColor.a = 0; - blendfactor = from->Color.a; - fogdensity = from->Fade.a*2; - return * this; - } - - void CopyLightColor(FDynamicColormap * from) - { - LightColor = from->Color; - desaturation = from->Desaturate; - blendfactor = from->Color.a; - } - - void CopyFrom3DLight(lightlist_t *light); - - 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; - } -}; - #endif diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 69c964ca0..b1960c91f 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -249,8 +249,8 @@ void gl_SetColor(int sectorlightlevel, int rellight, bool fullbright, const FCol else { int hwlightlevel = gl_CalcLightLevel(sectorlightlevel, rellight, weapon); - PalEntry pe = gl_CalcLightColor(hwlightlevel, cm.LightColor, cm.blendfactor); - gl_RenderState.SetColorAlpha(pe, alpha, cm.desaturation); + PalEntry pe = gl_CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor); + gl_RenderState.SetColorAlpha(pe, alpha, cm.Desaturation); gl_RenderState.SetSoftLightLevel(gl_ClampLight(sectorlightlevel + rellight)); } } @@ -339,7 +339,7 @@ bool gl_CheckFog(sector_t *frontsector, sector_t *backsector) // Check for fog boundaries. This needs a few more checks for the sectors - PalEntry fogcolor = frontsector->ColorMap->Fade; + PalEntry fogcolor = frontsector->Colormap.FadeColor; if ((fogcolor.d & 0xffffff) == 0) { @@ -361,7 +361,7 @@ bool gl_CheckFog(sector_t *frontsector, sector_t *backsector) if (frontsector->lightlevel >= 248) return false; } - fogcolor = backsector->ColorMap->Fade; + fogcolor = backsector->Colormap.FadeColor; if ((fogcolor.d & 0xffffff) == 0) { @@ -439,7 +439,7 @@ void gl_SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *c else if (cmap != NULL && !fullbright) { fogcolor = cmap->FadeColor; - fogdensity = gl_GetFogDensity(lightlevel, fogcolor, cmap->fogdensity); + fogdensity = gl_GetFogDensity(lightlevel, fogcolor, cmap->FogDensity); fogcolor.a=0; } else diff --git a/src/gl/renderer/gl_lightdata.h b/src/gl/renderer/gl_lightdata.h index 1b59dda6d..b052aa269 100644 --- a/src/gl/renderer/gl_lightdata.h +++ b/src/gl/renderer/gl_lightdata.h @@ -33,15 +33,6 @@ inline bool gl_isWhite(PalEntry color) return color.r + color.g + color.b == 3*0xff; } -inline void FColormap::CopyFrom3DLight(lightlist_t *light) -{ - LightColor = light->extra_colormap->Color; - desaturation = light->extra_colormap->Desaturate; - blendfactor = light->extra_colormap->Color.a; - if (light->caster && (light->caster->flags&FF_FADEWALLS) && (light->extra_colormap->Fade & 0xffffff) != 0) - FadeColor = light->extra_colormap->Fade; -} - #endif diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index e3a2c0372..92ce24278 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -188,7 +188,7 @@ public: void FillSimplePoly(FTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip); + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip); int PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, int first, int num); diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 88253c17c..241987ddf 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -1174,10 +1174,10 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo } else { - Colormap=sec->ColorMap; + Colormap = sec->Colormap; if (gltexture->tex->isFullbright()) { - Colormap.LightColor.r = Colormap.LightColor.g = Colormap.LightColor.b = 0xff; + Colormap.MakeWhite(); lightlevel=255; } else lightlevel=abs(ceiling? sec->GetCeilingLight() : sec->GetFloorLight()); diff --git a/src/gl/scene/gl_fakeflat.cpp b/src/gl/scene/gl_fakeflat.cpp index 304bbe4a8..6d0183f0e 100644 --- a/src/gl/scene/gl_fakeflat.cpp +++ b/src/gl/scene/gl_fakeflat.cpp @@ -245,7 +245,7 @@ sector_t * gl_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool bac { if (in_area==area_below) { - dest->ColorMap=s->ColorMap; + dest->CopyColors(s); if (!(s->MoreFlags & SECF_NOFAKELIGHT)) { dest->lightlevel = s->lightlevel; @@ -291,7 +291,7 @@ sector_t * gl_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool bac if (in_area==area_below) { - dest->ColorMap=s->ColorMap; + dest->CopyColors(s); dest->SetPlaneTexZ(sector_t::floor, sec->GetPlaneTexZ(sector_t::floor)); dest->SetPlaneTexZ(sector_t::ceiling, s->GetPlaneTexZ(sector_t::floor)); dest->floorplane=sec->floorplane; @@ -344,7 +344,7 @@ sector_t * gl_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool bac } else if (in_area == area_above) { - dest->ColorMap = s->ColorMap; + dest->CopyColors(s); dest->SetPlaneTexZ(sector_t::ceiling, sec->GetPlaneTexZ(sector_t::ceiling)); dest->SetPlaneTexZ(sector_t::floor, s->GetPlaneTexZ(sector_t::ceiling)); dest->ceilingplane = sec->ceilingplane; diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index c3b90608a..9674d4750 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -520,7 +520,7 @@ void GLFlat::Process(sector_t * model, int whichplane, bool fog) if (!gltexture) return; if (gltexture->tex->isFullbright()) { - Colormap.LightColor.r = Colormap.LightColor.g = Colormap.LightColor.b = 0xff; + Colormap.MakeWhite(); lightlevel=255; } } @@ -556,7 +556,7 @@ void GLFlat::SetFrom3DFloor(F3DFloor *rover, bool top, bool underside) if (rover->flags & FF_FOG) { - Colormap.LightColor = (light->extra_colormap)->Fade; + Colormap.LightColor = light->extra_colormap.FadeColor; FlatColor = 0xffffffff; } else @@ -619,7 +619,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) srf |= SSRF_RENDERFLOOR; lightlevel = gl_ClampLight(frontsector->GetFloorLight()); - Colormap = frontsector->ColorMap; + Colormap = frontsector->Colormap; FlatColor = frontsector->SpecialColors[sector_t::floor]; port = frontsector->ValidatePortal(sector_t::floor); if ((stack = (port != NULL))) @@ -679,7 +679,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) srf |= SSRF_RENDERCEILING; lightlevel = gl_ClampLight(frontsector->GetCeilingLight()); - Colormap = frontsector->ColorMap; + Colormap = frontsector->Colormap; FlatColor = frontsector->SpecialColors[sector_t::ceiling]; port = frontsector->ValidatePortal(sector_t::ceiling); if ((stack = (port != NULL))) @@ -765,7 +765,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) if (r_viewpoint.Pos.Z <= rover->top.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); - Colormap.FadeColor = frontsector->ColorMap->Fade; + Colormap.FadeColor = frontsector->Colormap.FadeColor; Process(rover->top.model, rover->top.isceiling, !!(rover->flags&FF_FOG)); } lastceilingheight = ff_top; @@ -779,7 +779,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) if (r_viewpoint.Pos.Z <= rover->bottom.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); - Colormap.FadeColor = frontsector->ColorMap->Fade; + Colormap.FadeColor = frontsector->Colormap.FadeColor; Process(rover->bottom.model, rover->bottom.isceiling, !!(rover->flags&FF_FOG)); } lastceilingheight = ff_bottom; @@ -805,7 +805,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) if (r_viewpoint.Pos.Z >= rover->bottom.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); - Colormap.FadeColor = frontsector->ColorMap->Fade; + Colormap.FadeColor = frontsector->Colormap.FadeColor; if (rover->flags&FF_FIX) { @@ -826,7 +826,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) if (r_viewpoint.Pos.Z >= rover->top.plane->ZatPoint(r_viewpoint.Pos)) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); - Colormap.FadeColor = frontsector->ColorMap->Fade; + Colormap.FadeColor = frontsector->Colormap.FadeColor; Process(rover->top.model, rover->top.isceiling, !!(rover->flags&FF_FOG)); } lastfloorheight = ff_top; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index b6a71ffac..f36016c3d 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -1238,7 +1238,7 @@ void GLEEHorizonPortal::DrawContents() GLHorizonInfo horz; horz.plane.GetFromSector(sector, sector_t::ceiling); horz.lightlevel = gl_ClampLight(sector->GetCeilingLight()); - horz.colormap = sector->ColorMap; + horz.colormap = sector->Colormap; if (portal->mType == PORTS_PLANE) { horz.plane.Texheight = r_viewpoint.Pos.Z + fabs(horz.plane.Texheight); @@ -1251,7 +1251,7 @@ void GLEEHorizonPortal::DrawContents() GLHorizonInfo horz; horz.plane.GetFromSector(sector, sector_t::floor); horz.lightlevel = gl_ClampLight(sector->GetFloorLight()); - horz.colormap = sector->ColorMap; + horz.colormap = sector->Colormap; if (portal->mType == PORTS_PLANE) { horz.plane.Texheight = r_viewpoint.Pos.Z - fabs(horz.plane.Texheight); diff --git a/src/gl/scene/gl_renderhacks.cpp b/src/gl/scene/gl_renderhacks.cpp index 4d2ec2e48..425adba5f 100644 --- a/src/gl/scene/gl_renderhacks.cpp +++ b/src/gl/scene/gl_renderhacks.cpp @@ -1047,7 +1047,8 @@ void FDrawInfo::CollectSectorStacksCeiling(subsector_t * sub, sector_t * anchor) if (me->GetTexture(sector_t::ceiling) != anchor->GetTexture(sector_t::ceiling) || me->ceilingplane != anchor->ceilingplane || me->GetCeilingLight() != anchor->GetCeilingLight() || - me->ColorMap != anchor->ColorMap || + me->Colormap != anchor->Colormap || + me->SpecialColors[sector_t::ceiling] != anchor->SpecialColors[sector_t::ceiling] || me->planes[sector_t::ceiling].xform != anchor->planes[sector_t::ceiling].xform) { // different visplane so it can't belong to this stack @@ -1090,7 +1091,8 @@ void FDrawInfo::CollectSectorStacksFloor(subsector_t * sub, sector_t * anchor) if (me->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) || me->floorplane != anchor->floorplane || me->GetFloorLight() != anchor->GetFloorLight() || - me->ColorMap != anchor->ColorMap || + me->Colormap != anchor->Colormap || + me->SpecialColors[sector_t::floor] != anchor->SpecialColors[sector_t::floor] || me->planes[sector_t::floor].xform != anchor->planes[sector_t::floor].xform) { // different visplane so it can't belong to this stack diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 8198511c7..c7b06d8b7 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -580,7 +580,7 @@ void GLSceneDrawer::DrawBlend(sector_t * viewsector) // 3d floor 'fog' is rendered as a blending value blendv = lightlist[i].blend; // If this is the same as the sector's it doesn't apply! - if (blendv == viewsector->ColorMap->Fade) blendv = 0; + if (blendv == viewsector->Colormap.FadeColor) blendv = 0; // a little hack to make this work for Legacy maps. if (blendv.a == 0 && blendv != 0) blendv.a = 128; break; diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 721ad4b6d..02b67a743 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -299,7 +299,7 @@ void GLSprite::Draw(int pass) if (!gl_isBlack(Colormap.FadeColor)) { float dist=Dist2(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, x,y); - int fogd = gl_GetFogDensity(lightlevel, Colormap.FadeColor, Colormap.fogdensity); + int fogd = gl_GetFogDensity(lightlevel, Colormap.FadeColor, Colormap.FogDensity); // this value was determined by trial and error and is scale dependent! float factor = 0.05f + exp(-fogd*dist / 62500.f); @@ -308,7 +308,7 @@ void GLSprite::Draw(int pass) } gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_sprite_threshold); - gl_RenderState.SetColor(0.2f,0.2f,0.2f,fuzzalpha, Colormap.desaturation); + gl_RenderState.SetColor(0.2f,0.2f,0.2f,fuzzalpha, Colormap.Desaturation); additivefog = true; lightlist = nullptr; // the fuzz effect does not use the sector's light level so splitting is not needed. } @@ -399,8 +399,7 @@ void GLSprite::Draw(int pass) int thisll = actor == nullptr? thislight : (uint8_t)gl_CheckSpriteGlow(actor->Sector, thislight, actor->InterpolatedPosition(r_viewpoint.TicFrac)); FColormap thiscm; - thiscm.FadeColor = Colormap.FadeColor; - thiscm.fogdensity = Colormap.fogdensity; + thiscm.CopyFog(Colormap); thiscm.CopyFrom3DLight(&(*lightlist)[i]); if (glset.nocoloredspritelighting) { @@ -526,7 +525,7 @@ void GLSprite::SplitSprite(sector_t * frontsector, bool translucent) { copySprite=*this; copySprite.lightlevel = gl_ClampLight(*lightlist[i].p_lightlevel); - copySprite.Colormap.CopyLightColor(lightlist[i].extra_colormap); + copySprite.Colormap.CopyLight(lightlist[i].extra_colormap); if (glset.nocoloredspritelighting) { @@ -535,9 +534,9 @@ void GLSprite::SplitSprite(sector_t * frontsector, bool translucent) if (!gl_isWhite(ThingColor)) { - copySprite.Colormap.LightColor.r=(copySprite.Colormap.LightColor.r*ThingColor.r)>>8; - copySprite.Colormap.LightColor.g=(copySprite.Colormap.LightColor.g*ThingColor.g)>>8; - copySprite.Colormap.LightColor.b=(copySprite.Colormap.LightColor.b*ThingColor.b)>>8; + copySprite.Colormap.LightColor.r = (copySprite.Colormap.LightColor.r*ThingColor.r) >> 8; + copySprite.Colormap.LightColor.g = (copySprite.Colormap.LightColor.g*ThingColor.g) >> 8; + copySprite.Colormap.LightColor.b = (copySprite.Colormap.LightColor.b*ThingColor.b) >> 8; } z1=copySprite.z2=lightbottom; @@ -666,7 +665,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) bool isPicnumOverride = thing->picnum.isValid(); // Don't waste time projecting sprites that are definitely not visible. - if ((thing->sprite == 0 && !isPicnumOverride) || !thing->IsVisibleToPlayer() || ((thing->renderflags & RF_MASKROTATION) && !thing->IsInsideVisibleAngles())) + if ((thing->sprite == 0 && !isPicnumOverride) || !thing->IsVisibleToPlayer() || ((thing->renderflags & RF_MASKROTATION) && !thing->IsInsideVisibleAngles())) { return; } @@ -853,9 +852,9 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) y1 = y + viewvecX*leftfac; y2 = y + viewvecX*rightfac; break; - + case RF_FLATSPRITE: - { + { x1 = x + leftfac; x2 = x + rightfac; y1 = y - topfac; @@ -873,27 +872,27 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) break; } } - else + else { x1 = x2 = x; y1 = y2 = y; z1 = z2 = z; - gltexture=NULL; + gltexture = NULL; } depth = FloatToFixed((x - r_viewpoint.Pos.X) * r_viewpoint.TanCos + (y - r_viewpoint.Pos.Y) * r_viewpoint.TanSin); // light calculation - bool enhancedvision=false; + bool enhancedvision = false; // 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) && (!gltexture || !gltexture->tex->gl_info.bDisableFullbright)); - lightlevel=fullbright? 255 : - gl_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? + lightlevel = fullbright ? 255 : + gl_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? rendersector->GetCeilingLight() : rendersector->GetFloorLight()); foglevel = (uint8_t)clamp(rendersector->lightlevel, 0, 255); @@ -904,16 +903,16 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) RenderStyle = thing->RenderStyle; // colormap stuff is a little more complicated here... - if (mDrawer->FixedColormap) + if (mDrawer->FixedColormap) { if ((gl_enhanced_nv_stealth > 0 && mDrawer->FixedColormap == CM_LITE) // Infrared powerup only || (gl_enhanced_nv_stealth == 2 && mDrawer->FixedColormap >= CM_TORCH)// Also torches || (gl_enhanced_nv_stealth == 3)) // Any fixed colormap - enhancedvision=true; + enhancedvision = true; Colormap.Clear(); - if (mDrawer->FixedColormap==CM_LITE) + if (mDrawer->FixedColormap == CM_LITE) { if (gl_enhanced_nightvision && (thing->IsKindOf(RUNTIME_CLASS(AInventory)) || thing->flags3&MF3_ISMONSTER || thing->flags&MF_MISSILE || thing->flags&MF_CORPSE)) @@ -922,24 +921,23 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) } } } - else + else { - Colormap=rendersector->ColorMap; + Colormap = rendersector->Colormap; if (fullbright) { if (rendersector == &level.sectors[rendersector->sectornum] || mDrawer->in_area != area_below) // under water areas keep their color for fullbright objects { // Only make the light white but keep everything else (fog, desaturation and Boom colormap.) - Colormap.LightColor.r= - Colormap.LightColor.g= - Colormap.LightColor.b=0xff; + Colormap.MakeWhite(); } else { - Colormap.LightColor.r = (3*Colormap.LightColor.r + 0xff)/4; - Colormap.LightColor.g = (3*Colormap.LightColor.g + 0xff)/4; - Colormap.LightColor.b = (3*Colormap.LightColor.b + 0xff)/4; + // Keep the color, but brighten things a bit so that a difference can be seen. + Colormap.LightColor.r = (3 * Colormap.LightColor.r + 0xff) / 4; + Colormap.LightColor.g = (3 * Colormap.LightColor.g + 0xff) / 4; + Colormap.LightColor.b = (3 * Colormap.LightColor.b + 0xff) / 4; } } else if (glset.nocoloredspritelighting) @@ -948,7 +946,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) } } - translation=thing->Translation; + translation = thing->Translation; OverrideShader = -1; trans = thing->Alpha; @@ -983,15 +981,15 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) trans = 1.f; } - if (trans >= 1.f-FLT_EPSILON && RenderStyle.BlendOp != STYLEOP_Shadow && ( - (RenderStyle.SrcAlpha == STYLEALPHA_One && RenderStyle.DestAlpha == STYLEALPHA_Zero) || - (RenderStyle.SrcAlpha == STYLEALPHA_Src && RenderStyle.DestAlpha == STYLEALPHA_InvSrc) - )) + if (trans >= 1.f - FLT_EPSILON && RenderStyle.BlendOp != STYLEOP_Shadow && ( + (RenderStyle.SrcAlpha == STYLEALPHA_One && RenderStyle.DestAlpha == STYLEALPHA_Zero) || + (RenderStyle.SrcAlpha == STYLEALPHA_Src && RenderStyle.DestAlpha == STYLEALPHA_InvSrc) + )) { // This is a non-translucent sprite (i.e. STYLE_Normal or equivalent) - trans=1.f; - - if (!gl_sprite_blend || modelframe || (thing->renderflags & (RF_FLATSPRITE|RF_WALLSPRITE)) || gl_billboard_faces_camera) + trans = 1.f; + + if (!gl_sprite_blend || modelframe || (thing->renderflags & (RF_FLATSPRITE | RF_WALLSPRITE)) || gl_billboard_faces_camera) { RenderStyle.SrcAlpha = STYLEALPHA_One; RenderStyle.DestAlpha = STYLEALPHA_Zero; @@ -1011,37 +1009,37 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) RenderStyle.DestAlpha = STYLEALPHA_InvSrc; } hw_styleflags = STYLEHW_NoAlphaTest; - } + } if (enhancedvision && gl_enhanced_nightvision) { if (RenderStyle.BlendOp == STYLEOP_Shadow) { // enhanced vision makes them more visible! - trans=0.5f; + trans = 0.5f; FRenderStyle rs = RenderStyle; RenderStyle = STYLE_Translucent; RenderStyle.Flags = rs.Flags; // Flags must be preserved, at this point it can only be STYLEF_InvertSource } - else if (thing->flags & MF_STEALTH) + else if (thing->flags & MF_STEALTH) { // enhanced vision overcomes stealth! if (trans < 0.5f) trans = 0.5f; } } - if (trans==0.0f) return; + if (trans == 0.0f) return; // end of light calculation - actor=thing; + actor = thing; index = GLRenderer->gl_spriteindex++; - particle=NULL; - - const bool drawWithXYBillboard = ( !(actor->renderflags & RF_FORCEYBILLBOARD) - && (actor->renderflags & RF_SPRITETYPEMASK) == RF_FACESPRITE - && players[consoleplayer].camera - && (gl_billboard_mode == 1 || actor->renderflags & RF_FORCEXYBILLBOARD ) ); + particle = NULL; + + const bool drawWithXYBillboard = (!(actor->renderflags & RF_FORCEYBILLBOARD) + && (actor->renderflags & RF_SPRITETYPEMASK) == RF_FACESPRITE + && players[consoleplayer].camera + && (gl_billboard_mode == 1 || actor->renderflags & RF_FORCEXYBILLBOARD)); // no light splitting when: @@ -1107,7 +1105,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s TArray & lightlist=sector->e->XFloor.lightlist; double lightbottom; - Colormap = sector->ColorMap; + Colormap = sector->Colormap; for(unsigned int i=0;iPos); @@ -1116,7 +1114,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s if (lightbottom < particle->Pos.Z) { lightlevel = gl_ClampLight(*lightlist[i].p_lightlevel); - Colormap.LightColor = (lightlist[i].extra_colormap)->Color; + Colormap.CopyLight(lightlist[i].extra_colormap); break; } } @@ -1128,7 +1126,7 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s else { lightlevel = 255; - Colormap = sector->ColorMap; + Colormap = sector->Colormap; Colormap.ClearColor(); } diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index 167437735..2ce769575 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -441,14 +441,14 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) { hi.plane.GetFromSector(fs, sector_t::ceiling); hi.lightlevel = gl_ClampLight(fs->GetCeilingLight()); - hi.colormap = fs->ColorMap; + hi.colormap = fs->Colormap; if (fs->e->XFloor.ffloors.Size()) { light = P_GetPlaneLight(fs, &fs->ceilingplane, true); if(!(fs->GetFlags(sector_t::ceiling)&PLANEF_ABSLIGHTING)) hi.lightlevel = gl_ClampLight(*light->p_lightlevel); - hi.colormap.LightColor = (light->extra_colormap)->Color; + hi.colormap.CopyLight(light->extra_colormap); } if (mDrawer->FixedColormap) hi.colormap.Clear(); @@ -469,14 +469,14 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) { hi.plane.GetFromSector(fs, sector_t::floor); hi.lightlevel = gl_ClampLight(fs->GetFloorLight()); - hi.colormap = fs->ColorMap; + hi.colormap = fs->Colormap; if (fs->e->XFloor.ffloors.Size()) { light = P_GetPlaneLight(fs, &fs->floorplane, false); if(!(fs->GetFlags(sector_t::floor)&PLANEF_ABSLIGHTING)) hi.lightlevel = gl_ClampLight(*light->p_lightlevel); - hi.colormap.LightColor = (light->extra_colormap)->Color; + hi.colormap.CopyLight(light->extra_colormap); } if (mDrawer->FixedColormap) hi.colormap.Clear(); @@ -1110,7 +1110,7 @@ void GLWall::BuildFFBlock(seg_t * seg, F3DFloor * rover, // this may not yet be done light = P_GetPlaneLight(rover->target, rover->top.plane, true); Colormap.Clear(); - Colormap.LightColor = (light->extra_colormap)->Fade; + Colormap.LightColor = light->extra_colormap.FadeColor; // the fog plane defines the light level, not the front sector lightlevel = gl_ClampLight(*light->p_lightlevel); gltexture = NULL; @@ -1510,7 +1510,7 @@ void GLWall::Process(seg_t *seg, sector_t * frontsector, sector_t * backsector) glseg.y1 = v1->fY(); glseg.x2 = v2->fX(); glseg.y2 = v2->fY(); - Colormap = frontsector->ColorMap; + Colormap = frontsector->Colormap; flags = 0; dynlightindex = -1; lightlist = NULL; @@ -1771,7 +1771,7 @@ void GLWall::ProcessLowerMiniseg(seg_t *seg, sector_t * frontsector, sector_t * alpha = 1.0f; RenderStyle = STYLE_Normal; - Colormap = frontsector->ColorMap; + Colormap = frontsector->Colormap; if (gl_GetWallGlow(frontsector, topglowcolor, bottomglowcolor)) flags |= GLWF_GLOW; topplane = frontsector->ceilingplane; diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 42f6e5a05..8cead55d6 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -277,7 +277,7 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) } else { - cm=fakesec->ColorMap; + cm=fakesec->Colormap; if (glset.nocoloredspritelighting) cm.ClearColor(); } @@ -396,9 +396,7 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) { if (fakesec == viewsector || in_area != area_below) { - cmc.LightColor.r= - cmc.LightColor.g= - cmc.LightColor.b=0xff; + cmc.MakeWhite(); } else { @@ -412,7 +410,7 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) // set the lighting parameters if (RenderStyle.BlendOp == STYLEOP_Shadow) { - gl_RenderState.SetColor(0.2f, 0.2f, 0.2f, 0.33f, cmc.desaturation); + gl_RenderState.SetColor(0.2f, 0.2f, 0.2f, 0.33f, cmc.Desaturation); } else { diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 4aedd176a..7a2d4f3f8 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -480,7 +480,7 @@ void OpenGLFrameBuffer::Clear(int left, int top, int right, int bottom, int palc void OpenGLFrameBuffer::FillSimplePoly(FTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip) { if (GLRenderer != nullptr && GLRenderer->m2DDrawer != nullptr && npoints >= 3) { diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index d243a1054..c83bb0e50 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -70,7 +70,7 @@ public: void FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip); + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip); FNativePalette *CreatePalette(FRemapTable *remap); diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index 1b7c6d43f..38f1b56c1 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -2946,7 +2946,7 @@ void OpenGLSWFrameBuffer::FlatFill(int left, int top, int right, int bottom, FTe void OpenGLSWFrameBuffer::FillSimplePoly(FTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip) { // Use an equation similar to player sprites to determine shade double fadelevel = clamp((swrenderer::LightVisibility::LightLevelToShade(lightlevel, true) / 65536. - 12) / NUMCOLORMAPS, 0.0, 1.0); @@ -2995,20 +2995,17 @@ void OpenGLSWFrameBuffer::FillSimplePoly(FTexture *texture, FVector2 *points, in { quad->Flags = BQF_WrapUV | BQF_GamePalette | BQF_DisableAlphaTest; quad->ShaderNum = BQS_PalTex; - if (colormap != nullptr) + if (colormap.Desaturation != 0) { - if (colormap->Desaturate != 0) - { - quad->Flags |= BQF_Desaturated; - } - quad->ShaderNum = BQS_InGameColormap; - quad->Desat = colormap->Desaturate; - color0 = ColorARGB(255, colormap->Color.r, colormap->Color.g, colormap->Color.b); - color1 = ColorARGB(uint32_t((1 - fadelevel) * 255), - uint32_t(colormap->Fade.r * fadelevel), - uint32_t(colormap->Fade.g * fadelevel), - uint32_t(colormap->Fade.b * fadelevel)); + quad->Flags |= BQF_Desaturated; } + quad->ShaderNum = BQS_InGameColormap; + quad->Desat = colormap.Desaturation; + color0 = ColorARGB(255, colormap.LightColor.r, colormap.LightColor.g, colormap.LightColor.b); + color1 = ColorARGB(uint32_t((1 - fadelevel) * 255), + uint32_t(colormap.FadeColor.r * fadelevel), + uint32_t(colormap.FadeColor.g * fadelevel), + uint32_t(colormap.FadeColor.b * fadelevel)); } else { diff --git a/src/gl/system/gl_swframebuffer.h b/src/gl/system/gl_swframebuffer.h index b5631074c..dc202a05c 100644 --- a/src/gl/system/gl_swframebuffer.h +++ b/src/gl/system/gl_swframebuffer.h @@ -60,7 +60,7 @@ public: void FlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin) override; void DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32_t realcolor) override; void DrawPixel(int x, int y, int palcolor, uint32_t rgbcolor) override; - void FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) override; + void FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip) override; bool WipeStartScreen(int type) override; void WipeEndScreen() override; bool WipeDo(int ticks) override; diff --git a/src/p_3dfloors.cpp b/src/p_3dfloors.cpp index 6c4527b31..509efa822 100644 --- a/src/p_3dfloors.cpp +++ b/src/p_3dfloors.cpp @@ -64,26 +64,26 @@ EXTERN_CVAR(Int, vid_renderer) // //========================================================================== -FDynamicColormap *F3DFloor::GetColormap() +FColormap F3DFloor::GetColormap() { // If there's no fog in either model or target sector this is easy and fast. - if ((target->ColorMap->Fade == 0 && model->ColorMap->Fade == 0) || (flags & (FF_FADEWALLS|FF_FOG))) + if ((target->Colormap.FadeColor.isBlack() && model->Colormap.FadeColor.isBlack()) || (flags & (FF_FADEWALLS|FF_FOG))) { - return model->ColorMap; + return model->Colormap; } else { // We must create a new colormap combining the properties we need - return GetSpecialLights(model->ColorMap->Color, target->ColorMap->Fade, model->ColorMap->Desaturate); + return{ model->Colormap.LightColor, target->Colormap.FadeColor, model->Colormap.Desaturation, model->Colormap.BlendFactor, target->Colormap.FogDensity }; } } PalEntry F3DFloor::GetBlend() { // The model sector's fog is used as blend unless FF_FADEWALLS is set. - if (!(flags & FF_FADEWALLS) && target->ColorMap->Fade != model->ColorMap->Fade) + if (!(flags & FF_FADEWALLS) && target->Colormap.FadeColor != model->Colormap.FadeColor) { - return model->ColorMap->Fade; + return model->Colormap.FadeColor; } else { @@ -91,22 +91,17 @@ PalEntry F3DFloor::GetBlend() } } -void F3DFloor::UpdateColormap(FDynamicColormap *&map) +void F3DFloor::UpdateColormap(FColormap &map) { - // If there's no fog in either model or target sector (or both have the same fog) this is easy and fast. - if ((target->ColorMap->Fade == 0 && model->ColorMap->Fade == 0) || (flags & FF_FADEWALLS) || - target->ColorMap->Fade == model->ColorMap->Fade) + // Note that this is a bit different from GetColormap. + if ((target->Colormap.FadeColor.isBlack() && model->Colormap.FadeColor.isBlack()) || (flags & FF_FADEWALLS) || + target->Colormap.FadeColor == model->Colormap.FadeColor) { - map = model->ColorMap; + map = model->Colormap; } else { - // since rebuilding the map is not a cheap operation let's only do it if something really changed. - if (map->Color != model->ColorMap->Color || map->Fade != target->ColorMap->Fade || - map->Desaturate != model->ColorMap->Desaturate) - { - map = GetSpecialLights(model->ColorMap->Color, target->ColorMap->Fade, model->ColorMap->Desaturate); - } + map = { model->Colormap.LightColor, target->Colormap.FadeColor, model->Colormap.Desaturation, model->Colormap.BlendFactor, target->Colormap.FogDensity }; } } @@ -251,10 +246,8 @@ static int P_Set3DFloor(line_t * line, int param, int param2, int alpha) VC_BLOOD, VC_SLUDGE, VC_HAZARD, VC_BOOMWATER }; flags |= FF_SWIMMABLE | FF_BOTHPLANES | FF_ALLSIDES | FF_FLOOD; - l->frontsector->ColorMap = - GetSpecialLights(l->frontsector->ColorMap->Color, - vavoomcolors[l->args[0]], - l->frontsector->ColorMap->Desaturate); + l->frontsector->Colormap.FadeColor = vavoomcolors[l->args[0]] & VC_COLORMASK; + l->frontsector->Colormap.FogDensity = 0; } alpha = (alpha * 255) / 100; break; @@ -587,7 +580,7 @@ void P_Recalculate3DFloors(sector_t * sector) lightlist[0].p_lightlevel = §or->lightlevel; lightlist[0].caster = NULL; lightlist[0].lightsource = NULL; - lightlist[0].extra_colormap = sector->ColorMap; + lightlist[0].extra_colormap = sector->Colormap; lightlist[0].blend = 0; lightlist[0].flags = 0; @@ -637,7 +630,7 @@ void P_Recalculate3DFloors(sector_t * sector) { resetlight.p_lightlevel = §or->lightlevel; resetlight.lightsource = NULL; - resetlight.extra_colormap = sector->ColorMap; + resetlight.extra_colormap = sector->Colormap; resetlight.blend = 0; } @@ -697,7 +690,7 @@ void P_RecalculateLights(sector_t *sector) } else { - ll->extra_colormap = sector->ColorMap; + ll->extra_colormap = sector->Colormap; ll->blend = 0; } } diff --git a/src/p_3dfloors.h b/src/p_3dfloors.h index cc3f71a17..f46aa913e 100644 --- a/src/p_3dfloors.h +++ b/src/p_3dfloors.h @@ -1,6 +1,7 @@ #ifndef __SECTORE_H #define __SECTORE_H +#include "r_data/colormaps.h" // 3D floor flags. Most are the same as in Legacy but I added some for EDGE's and Vavoom's features as well. typedef enum @@ -93,8 +94,8 @@ struct F3DFloor int lastlight; int alpha; - FDynamicColormap *GetColormap(); - void UpdateColormap(FDynamicColormap *&map); + FColormap GetColormap(); + void UpdateColormap(FColormap &map); PalEntry GetBlend(); }; @@ -104,7 +105,7 @@ struct lightlist_t { secplane_t plane; short * p_lightlevel; - FDynamicColormap * extra_colormap; + FColormap extra_colormap; PalEntry blend; int flags; F3DFloor* lightsource; diff --git a/src/p_acs.cpp b/src/p_acs.cpp index c2f40e825..36e0e46a7 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -6760,9 +6760,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) int d = clamp(args[1]/2, 0, 255); while ((s = it.Next()) >= 0) { - auto &sec = level.sectors[s]; - auto f = sec.ColorMap->Fade; - sec.ColorMap = GetSpecialLights(sec.ColorMap->Color, PalEntry(d, f.r, f.g, f.b), sec.ColorMap->Desaturate); + level.sectors[s].SetFogDensity(d); } break; } diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 623d9bcb3..d749be0cc 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -160,6 +160,30 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FLinkedSector &ls, FLi return arc; } +//============================================================================ +// +// Save a sector portal for savegames. +// +//============================================================================ + +FSerializer &Serialize(FSerializer &arc, const char *key, FColormap &port, FColormap *def) +{ + if (arc.canSkip() && def != nullptr && port == *def) + { + return arc; + } + + if (arc.BeginObject(key)) + { + arc("lightcolor", port.LightColor) + ("fadecolor", port.FadeColor) + ("desaturation", port.Desaturation) + ("fogdensity", port.FogDensity) + .EndObject(); + } + return arc; +} + //========================================================================== // // @@ -275,7 +299,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t ("midtexc_sectors", p.e->Midtex.Ceiling.AttachedSectors) ("linked_floor", p.e->Linked.Floor.Sectors) ("linked_ceiling", p.e->Linked.Ceiling.Sectors) - ("colormap", p.ColorMap, def->ColorMap) + ("colormap", p.Colormap, def->Colormap) .Array("specialcolors", p.SpecialColors, def->SpecialColors, 5, true) ("gravity", p.gravity, def->gravity) .Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0]) diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index faf15af5f..83abb6e58 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -804,8 +804,8 @@ DEFINE_ACTION_FUNCTION(_Sector, FindLowestCeilingPoint) void sector_t::SetColor(int r, int g, int b, int desat) { - PalEntry color = PalEntry (r,g,b); - ColorMap = GetSpecialLights (color, ColorMap->Fade, desat); + Colormap.LightColor = PalEntry(r, g, b); + Colormap.Desaturation = desat; P_RecalculateAttachedLights(this); } @@ -814,7 +814,8 @@ DEFINE_ACTION_FUNCTION(_Sector, SetColor) PARAM_SELF_STRUCT_PROLOGUE(sector_t); PARAM_COLOR(color); PARAM_INT(desat); - self->ColorMap = GetSpecialLights(color, self->ColorMap->Fade, desat); + self->Colormap.LightColor.SetRGB(color); + self->Colormap.Desaturation = desat; P_RecalculateAttachedLights(self); return 0; } @@ -826,8 +827,7 @@ DEFINE_ACTION_FUNCTION(_Sector, SetColor) void sector_t::SetFade(int r, int g, int b) { - PalEntry fade = PalEntry (r,g,b); - ColorMap = GetSpecialLights (ColorMap->Color, fade, ColorMap->Desaturate); + Colormap.FadeColor = PalEntry (r,g,b); P_RecalculateAttachedLights(this); } @@ -835,11 +835,28 @@ DEFINE_ACTION_FUNCTION(_Sector, SetFade) { PARAM_SELF_STRUCT_PROLOGUE(sector_t); PARAM_COLOR(fade); - self->ColorMap = GetSpecialLights(self->ColorMap->Color, fade, self->ColorMap->Desaturate); + self->Colormap.FadeColor.SetRGB(fade); P_RecalculateAttachedLights(self); return 0; } +//===================================================================================== +// +// +//===================================================================================== + +void sector_t::SetFogDensity(int dens) +{ + Colormap.FogDensity = dens; +} + +DEFINE_ACTION_FUNCTION(_Sector, SetFogDensity) +{ + PARAM_SELF_STRUCT_PROLOGUE(sector_t); + PARAM_INT(dens); + self->Colormap.FogDensity = dens; + return 0; +} //=========================================================================== // @@ -2396,7 +2413,7 @@ DEFINE_ACTION_FUNCTION(_Secplane, PointToDist) DEFINE_FIELD_X(Sector, sector_t, floorplane) DEFINE_FIELD_X(Sector, sector_t, ceilingplane) -DEFINE_FIELD_X(Sector, sector_t, ColorMap) +DEFINE_FIELD_X(Sector, sector_t, Colormap) DEFINE_FIELD_X(Sector, sector_t, SoundTarget) DEFINE_FIELD_X(Sector, sector_t, special) DEFINE_FIELD_X(Sector, sector_t, lightlevel) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index c464a1386..4793dd7ea 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1458,7 +1458,6 @@ void P_LoadSectors (MapData *map, FMissingTextureTracker &missingtex) mapsector_t *ms; sector_t* ss; int defSeqType; - FDynamicColormap *fogMap, *normMap; int lumplen = map->Size(ML_SECTORS); unsigned numsectors = lumplen / sizeof(mapsector_t); @@ -1471,8 +1470,6 @@ void P_LoadSectors (MapData *map, FMissingTextureTracker &missingtex) else defSeqType = -1; - fogMap = normMap = NULL; - msp = new char[lumplen]; map->Read(ML_SECTORS, msp); ms = (mapsector_t*)msp; @@ -1523,17 +1520,14 @@ void P_LoadSectors (MapData *map, FMissingTextureTracker &missingtex) // [RH] Sectors default to white light with the default fade. // If they are outside (have a sky ceiling), they use the outside fog. + ss->Colormap.LightColor = PalEntry(255, 255, 255); if (level.outsidefog != 0xff000000 && (ss->GetTexture(sector_t::ceiling) == skyflatnum || (ss->special&0xff) == Sector_Outside)) { - if (fogMap == NULL) - fogMap = GetSpecialLights (PalEntry (255,255,255), level.outsidefog, 0); - ss->ColorMap = fogMap; + ss->Colormap.FadeColor.SetRGB(level.outsidefog); } else { - if (normMap == NULL) - normMap = GetSpecialLights (PalEntry (255,255,255), level.fadeto, NormalLight.Desaturate); - ss->ColorMap = normMap; + ss->Colormap.FadeColor.SetRGB(level.fadeto); } // killough 8/28/98: initialize all sectors to normal friction @@ -2517,21 +2511,16 @@ void P_ProcessSideTextures(bool checktranmap, side_t *sd, sector_t *sec, intmaps if (colorgood | foggood) { - FDynamicColormap *colormap = NULL; - for (unsigned s = 0; s < level.sectors.Size(); s++) { if (tagManager.SectorHasTag(s, tag)) { - if (!colorgood) color = level.sectors[s].ColorMap->Color; - if (!foggood) fog = level.sectors[s].ColorMap->Fade; - if (colormap == NULL || - colormap->Color != color || - colormap->Fade != fog) + if (colorgood) { - colormap = GetSpecialLights (color, fog, 0); + level.sectors[s].Colormap.LightColor.SetRGB(color); + level.sectors[s].Colormap.BlendFactor = APART(color); } - level.sectors[s].ColorMap = colormap; + if (foggood) level.sectors[s].Colormap.FadeColor.SetRGB(fog); } } } diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 5aa2945ac..f4a756306 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -1526,11 +1526,11 @@ public: break; case NAME_Desaturation: - desaturation = int(255*CheckFloat(key)); + desaturation = int(255*CheckFloat(key) + FLT_EPSILON); // FLT_EPSILON to avoid rounding errors with numbers slightly below a full integer. continue; case NAME_fogdensity: - fogdensity = clamp(CheckInt(key), 0, 511); + fogdensity = CheckInt(key); break; case NAME_Silent: @@ -1770,22 +1770,19 @@ public: { // [RH] Sectors default to white light with the default fade. // If they are outside (have a sky ceiling), they use the outside fog. + sec->Colormap.LightColor = PalEntry(255, 255, 255); if (level.outsidefog != 0xff000000 && (sec->GetTexture(sector_t::ceiling) == skyflatnum || (sec->special & 0xff) == Sector_Outside)) { - if (fogMap == NULL) - fogMap = GetSpecialLights(PalEntry(255, 255, 255), level.outsidefog, 0); - sec->ColorMap = fogMap; + sec->Colormap.FadeColor.SetRGB(level.outsidefog); } else { - if (normMap == NULL) - normMap = GetSpecialLights (PalEntry (255,255,255), level.fadeto, NormalLight.Desaturate); - sec->ColorMap = normMap; + sec->Colormap.FadeColor.SetRGB(level.fadeto); } } else { - if (lightcolor == ~0u) lightcolor = PalEntry(255,255,255); + sec->Colormap.LightColor.SetRGB(lightcolor); if (fadecolor == ~0u) { if (level.outsidefog != 0xff000000 && (sec->GetTexture(sector_t::ceiling) == skyflatnum || (sec->special & 0xff) == Sector_Outside)) @@ -1793,11 +1790,9 @@ public: else fadecolor = level.fadeto; } - if (desaturation == -1) desaturation = NormalLight.Desaturate; - if (fogdensity != -1) fadecolor.a = fogdensity / 2; - else fadecolor.a = 0; - - sec->ColorMap = GetSpecialLights (lightcolor, fadecolor, desaturation); + sec->Colormap.FadeColor.SetRGB(fadecolor); + sec->Colormap.Desaturation = clamp(desaturation, 0, 255); + sec->Colormap.FogDensity = clamp(fogdensity, 0, 512) / 2; } } diff --git a/src/polyrenderer/scene/poly_decal.cpp b/src/polyrenderer/scene/poly_decal.cpp index d8043e2a6..a65926486 100644 --- a/src/polyrenderer/scene/poly_decal.cpp +++ b/src/polyrenderer/scene/poly_decal.cpp @@ -137,7 +137,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan PolyDrawArgs args; args.uniforms.flags = 0; - args.SetColormap(front->ColorMap); + args.SetColormap(GetColorTable(front->Colormap)); args.SetTexture(tex, decal->Translation, true); args.uniforms.globvis = (float)PolyRenderer::Instance()->Thread.Light->WallGlobVis(foggy); if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) diff --git a/src/polyrenderer/scene/poly_particle.cpp b/src/polyrenderer/scene/poly_particle.cpp index 966c93fcc..8889a561b 100644 --- a/src/polyrenderer/scene/poly_particle.cpp +++ b/src/polyrenderer/scene/poly_particle.cpp @@ -110,7 +110,7 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP args.ccw = true; args.stenciltestvalue = stencilValue; args.stencilwritevalue = stencilValue; - args.SetColormap(sub->sector->ColorMap); + args.SetColormap(GetColorTable(sub->sector->Colormap)); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.subsectorTest = true; args.writeStencil = false; diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index 1c6cd36fc..a897f7c69 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -148,7 +148,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c args.stenciltestvalue = stencilValue; args.stencilwritevalue = stencilValue + 1; args.SetTexture(tex); - args.SetColormap(sub->sector->ColorMap); + args.SetColormap(GetColorTable(sub->sector->Colormap)); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.blendmode = TriBlendMode::Copy; PolyTriangleDrawer::draw(args); @@ -345,7 +345,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan args.ccw = ccw; args.stenciltestvalue = stencilValue; args.stencilwritevalue = stencilValue + 1; - args.SetColormap(frontsector->ColorMap); + args.SetColormap(GetColorTable(frontsector->Colormap)); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); if (!isSky) diff --git a/src/polyrenderer/scene/poly_playersprite.cpp b/src/polyrenderer/scene/poly_playersprite.cpp index 74854e9a5..2b4e3cfb1 100644 --- a/src/polyrenderer/scene/poly_playersprite.cpp +++ b/src/polyrenderer/scene/poly_playersprite.cpp @@ -215,7 +215,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa bool noaccel = false; - FDynamicColormap *basecolormap = viewpoint.sector->ColorMap; + FDynamicColormap *basecolormap = GetColorTable(viewpoint.sector->Colormap); FDynamicColormap *colormap_to_use = basecolormap; int ColormapNum = 0; diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index e8f7ab179..0cdb6192e 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -162,7 +162,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla args.stenciltestvalue = stencilValue; args.stencilwritevalue = stencilValue; args.SetTexture(tex, thing->Translation); - args.SetColormap(sub->sector->ColorMap); + args.SetColormap(GetColorTable(sub->sector->Colormap)); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); TriBlendMode blendmode; diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index 3246d69ac..bda5f2aa8 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -73,7 +73,7 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const Vec4f &clipP wall.LineSeg = line; wall.Line = line->linedef; wall.Side = line->sidedef; - wall.Colormap = frontsector->ColorMap; + wall.Colormap = GetColorTable(frontsector->Colormap); wall.Masked = false; wall.SubsectorDepth = subsectorDepth; wall.StencilValue = stencilValue; @@ -175,7 +175,7 @@ void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, const Vec4f wall.LineSeg = line; wall.Line = fakeFloor->master; wall.Side = fakeFloor->master->sidedef[0]; - wall.Colormap = frontsector->ColorMap; + wall.Colormap = GetColorTable(frontsector->Colormap); wall.Masked = false; wall.SubsectorDepth = subsectorDepth; wall.StencilValue = stencilValue; @@ -262,7 +262,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane args.stencilwritevalue = StencilValue + 1; if (tex) args.SetTexture(tex); - args.SetColormap(Line->frontsector->ColorMap); + args.SetColormap(GetColorTable(Line->frontsector->Colormap)); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); //if (Side && Side->lighthead) diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index 56d694a6a..a5152e2bc 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -123,7 +123,7 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli args.stenciltestvalue = stencilValue; args.stencilwritevalue = stencilValue; args.SetTexture(tex); - args.SetColormap(sub->sector->ColorMap); + args.SetColormap(GetColorTable(sub->sector->Colormap)); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.subsectorTest = true; args.writeSubsector = false; diff --git a/src/r_data/colormaps.h b/src/r_data/colormaps.h index 942c0a961..5b5802e92 100644 --- a/src/r_data/colormaps.h +++ b/src/r_data/colormaps.h @@ -2,6 +2,7 @@ #define __RES_CMAP_H struct FSWColormap; +struct lightlist_t; void R_InitColormaps (); void R_DeinitColormaps (); @@ -12,6 +13,70 @@ uint32_t R_BlendForColormap (uint32_t map); // [RH] return calculated blend fo extern FSWColormap realcolormaps; // [RH] make the colormaps externally visible extern size_t numfakecmaps; +// for internal use +struct FColormap +{ + PalEntry LightColor; // a is saturation (0 full, 31=b/w, other=custom colormap) + PalEntry FadeColor; // a is fadedensity>>1 + uint8_t Desaturation; + uint8_t BlendFactor; // This is for handling Legacy-style colormaps which use a different formula to calculate how the color affects lighting. + uint16_t FogDensity; + + void Clear() + { + LightColor = 0xffffff; + FadeColor = 0; + Desaturation = 0; + BlendFactor = 0; + FogDensity = 0; + } + + void MakeWhite() + { + LightColor = 0xffffff; + } + + void ClearColor() + { + LightColor = 0xffffff; + BlendFactor = 0; + Desaturation = 0; + } + + void CopyLight(FColormap &from) + { + LightColor = from.LightColor; + Desaturation = from.Desaturation; + BlendFactor = from.BlendFactor; + } + + void CopyFog(FColormap &from) + { + FadeColor = from.FadeColor; + FogDensity = from.FogDensity; + } + + void CopyFrom3DLight(lightlist_t *light); + + 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; + } + + bool operator == (const FColormap &other) + { + return LightColor == other.LightColor && FadeColor == other.FadeColor && Desaturation == other.Desaturation && + BlendFactor == other.BlendFactor && FogDensity == other.FogDensity; + } + + bool operator != (const FColormap &other) + { + return !operator==(other); + } + +}; + struct FSWColormap { uint8_t *Maps = nullptr; @@ -32,6 +97,7 @@ struct FDynamicColormap : FSWColormap FDynamicColormap *Next; }; + // For hardware-accelerated weapon sprites in colored sectors struct FColormapStyle { @@ -83,5 +149,9 @@ extern bool NormalLightHasFixedLights; FDynamicColormap *GetSpecialLights (PalEntry lightcolor, PalEntry fadecolor, int desaturate); +inline FDynamicColormap *GetColorTable(const FColormap &cm) +{ + return GetSpecialLights(cm.LightColor, cm.FadeColor, cm.Desaturation); +} #endif diff --git a/src/r_defs.h b/src/r_defs.h index b9f6a4e36..011c1105a 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -639,6 +639,7 @@ public: void AdjustFloorClip () const; void SetColor(int r, int g, int b, int desat); void SetFade(int r, int g, int b); + void SetFogDensity(int dens); void ClosestPoint(const DVector2 &pos, DVector2 &out) const; int GetFloorLight () const; int GetCeilingLight () const; @@ -953,8 +954,27 @@ public: secplane_t floorplane, ceilingplane; // [RH] give floor and ceiling even more properties - FDynamicColormap *ColorMap; // [RH] Per-sector colormap - PalEntry SpecialColors[5]; + PalEntry SpecialColors[5]; + FColormap Colormap; + +private: + FDynamicColormap *_ColorMap; // [RH] Per-sector colormap + +public: + // just a helper for refactoring + FDynamicColormap *GetColorMap() + { + return _ColorMap; + } + + void CopyColors(sector_t *other) + { + memcpy(SpecialColors, other->SpecialColors, sizeof(SpecialColors)); + Colormap = other->Colormap; + + _ColorMap = other->_ColorMap; + } + TObjPtr SoundTarget; @@ -1472,5 +1492,13 @@ inline bool FBoundingBox::inRange(const line_t *ld) const } +inline void FColormap::CopyFrom3DLight(lightlist_t *light) +{ + CopyLight(light->extra_colormap); + if (light->caster && (light->caster->flags&FF_FADEWALLS) && light->extra_colormap.FadeColor != 0) + { + CopyFog(light->extra_colormap); + } +} #endif diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index 5eecfed2a..4e20e1547 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -214,7 +214,7 @@ namespace swrenderer if (mBackSector->GetVisFlags(sector_t::floor) != mFrontSector->GetVisFlags(sector_t::floor)) return false; if (mBackSector->GetVisFlags(sector_t::ceiling) != mFrontSector->GetVisFlags(sector_t::ceiling)) return false; - if (mBackSector->ColorMap != mFrontSector->ColorMap) return false; + if (mBackSector->Colormap != mFrontSector->Colormap) return false; if (mFrontSector->e && mFrontSector->e->XFloor.lightlist.Size()) return false; if (mBackSector->e && mBackSector->e->XFloor.lightlist.Size()) return false; @@ -603,7 +603,7 @@ namespace swrenderer if (mFrontSector->heightsec) return true; if (mBackSector->GetVisFlags(sector_t::floor) != mFrontSector->GetVisFlags(sector_t::floor)) return true; - if (mBackSector->ColorMap != mFrontSector->ColorMap) return true; + if (mBackSector->Colormap != mFrontSector->Colormap) return true; if (mFrontSector->e && mFrontSector->e->XFloor.lightlist.Size()) return true; if (mBackSector->e && mBackSector->e->XFloor.lightlist.Size()) return true; @@ -663,7 +663,7 @@ namespace swrenderer if (mBackSector->GetPlaneLight(sector_t::ceiling) != mFrontSector->GetPlaneLight(sector_t::ceiling)) return true; if (mBackSector->GetFlags(sector_t::ceiling) != mFrontSector->GetFlags(sector_t::ceiling)) return true; - if (mBackSector->ColorMap != mFrontSector->ColorMap) return true; + if (mBackSector->Colormap != mFrontSector->Colormap) return true; if (mFrontSector->e && mFrontSector->e->XFloor.lightlist.Size()) return true; if (mBackSector->e && mBackSector->e->XFloor.lightlist.Size()) return true; @@ -975,8 +975,8 @@ namespace swrenderer bool SWRenderLine::IsFogBoundary(sector_t *front, sector_t *back) const { - return r_fogboundary && CameraLight::Instance()->FixedColormap() == nullptr && front->ColorMap->Fade && - front->ColorMap->Fade != back->ColorMap->Fade && + return r_fogboundary && CameraLight::Instance()->FixedColormap() == nullptr && front->Colormap.FadeColor && + front->Colormap.FadeColor != back->Colormap.FadeColor && (front->GetTexture(sector_t::ceiling) != skyflatnum || back->GetTexture(sector_t::ceiling) != skyflatnum); } diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index f1dc2973e..5233bb94e 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -105,7 +105,7 @@ namespace swrenderer // killough 4/13/98: get correct lightlevel for 2s normal textures sec = Thread->OpaquePass->FakeFlat(frontsector, &tempsec, nullptr, nullptr, nullptr, 0, 0, 0, 0); - FDynamicColormap *basecolormap = sec->ColorMap; // [RH] Set basecolormap + FDynamicColormap *basecolormap = GetColorTable(sec->Colormap); // [RH] Set basecolormap int wallshade = ds->shade; rw_lightstep = ds->lightstep; @@ -125,7 +125,7 @@ namespace swrenderer if (clip3d->sclipTop <= frontsector->e->XFloor.lightlist[i].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[i]; - basecolormap = lit->extra_colormap; + basecolormap = GetColorTable(lit->extra_colormap); bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, viewport), foggy); break; @@ -691,7 +691,7 @@ namespace swrenderer } } // correct colors now - FDynamicColormap *basecolormap = frontsector->ColorMap; + FDynamicColormap *basecolormap = GetColorTable(frontsector->Colormap); wallshade = ds->shade; CameraLight *cameraLight = CameraLight::Instance(); if (cameraLight->FixedLightLevel() < 0) @@ -703,7 +703,7 @@ namespace swrenderer if (clip3d->sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; - basecolormap = lit->extra_colormap; + basecolormap = GetColorTable(lit->extra_colormap); bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; @@ -717,7 +717,7 @@ namespace swrenderer if (clip3d->sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; - basecolormap = lit->extra_colormap; + basecolormap = GetColorTable(lit->extra_colormap); bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; @@ -868,7 +868,7 @@ namespace swrenderer } } // correct colors now - FDynamicColormap *basecolormap = frontsector->ColorMap; + FDynamicColormap *basecolormap = GetColorTable(frontsector->Colormap); wallshade = ds->shade; CameraLight *cameraLight = CameraLight::Instance(); if (cameraLight->FixedLightLevel() < 0) @@ -880,7 +880,7 @@ namespace swrenderer if (clip3d->sclipTop <= backsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &backsector->e->XFloor.lightlist[j]; - basecolormap = lit->extra_colormap; + basecolormap = GetColorTable(lit->extra_colormap); bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; @@ -894,7 +894,7 @@ namespace swrenderer if (clip3d->sclipTop <= frontsector->e->XFloor.lightlist[j].plane.Zat0()) { lightlist_t *lit = &frontsector->e->XFloor.lightlist[j]; - basecolormap = lit->extra_colormap; + basecolormap = GetColorTable(lit->extra_colormap); bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); // [RH] set foggy flag wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(ds->foggy, *lit->p_lightlevel, lit->lightsource != nullptr) + LightVisibility::ActualExtraLight(ds->foggy, Thread->Viewport.get()), foggy); break; diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index 5248f3cdb..c1f4f293d 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -394,7 +394,7 @@ namespace swrenderer } lightlist_t *lit = &frontsector->e->XFloor.lightlist[i]; - basecolormap = lit->extra_colormap; + basecolormap = GetColorTable(lit->extra_colormap); wallshade = LightVisibility::LightLevelToShade(curline->sidedef->GetLightLevel(foggy, *lit->p_lightlevel, lit->lightsource != NULL) + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); } diff --git a/src/swrenderer/r_swcanvas.cpp b/src/swrenderer/r_swcanvas.cpp index c55c9a737..b70a6a965 100644 --- a/src/swrenderer/r_swcanvas.cpp +++ b/src/swrenderer/r_swcanvas.cpp @@ -205,7 +205,7 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms) void SWCanvas::FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, - FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) + const FColormap &fcolormap, PalEntry flatcolor, int lightlevel, int bottomclip) { // Use an equation similar to player sprites to determine shade fixed_t shade = LightVisibility::LightLevelToShade(lightlevel, true) - 12 * FRACUNIT; @@ -216,6 +216,7 @@ void SWCanvas::FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, fixed_t x; bool dorotate = rotation != 0.; double cosrot, sinrot; + auto colormap = GetColorTable(fcolormap); if (--npoints < 2) { // not a polygon or we're not locked diff --git a/src/swrenderer/r_swcanvas.h b/src/swrenderer/r_swcanvas.h index 01c9cbb7d..3d8135c2f 100644 --- a/src/swrenderer/r_swcanvas.h +++ b/src/swrenderer/r_swcanvas.h @@ -10,7 +10,7 @@ public: static void DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms); static void FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, - FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip); + const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip); static void DrawLine(DCanvas *canvas, int x0, int y0, int x1, int y1, int palColor, uint32_t realcolor); static void DrawPixel(DCanvas *canvas, int x, int y, int palColor, uint32_t realcolor); static void Clear(DCanvas *canvas, int left, int top, int right, int bottom, int palcolor, uint32_t color); diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index 0fefb42a1..17755bf11 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -118,7 +118,7 @@ namespace swrenderer { if (underwater) { - tempsec->ColorMap = s->ColorMap; + tempsec->Colormap = s->Colormap; if (!(s->MoreFlags & SECF_NOFAKELIGHT)) { tempsec->lightlevel = s->lightlevel; @@ -192,7 +192,7 @@ namespace swrenderer tempsec->ceilingplane = s->floorplane; tempsec->ceilingplane.FlipVert(); tempsec->ceilingplane.ChangeHeight(-1 / 65536.); - tempsec->ColorMap = s->ColorMap; + tempsec->Colormap = s->Colormap; } // killough 11/98: prevent sudden light changes from non-water sectors: @@ -241,8 +241,7 @@ namespace swrenderer tempsec->floorplane = s->ceilingplane; tempsec->floorplane.FlipVert(); tempsec->floorplane.ChangeHeight(+1 / 65536.); - tempsec->ColorMap = s->ColorMap; - tempsec->ColorMap = s->ColorMap; + tempsec->Colormap = s->Colormap; tempsec->SetTexture(sector_t::ceiling, diffTex ? sec->GetTexture(sector_t::ceiling) : s->GetTexture(sector_t::ceiling), false); tempsec->SetTexture(sector_t::floor, s->GetTexture(sector_t::ceiling), false); @@ -478,7 +477,7 @@ namespace swrenderer cll = ceilinglightlevel; // [RH] set foggy flag - bool foggy = level.fadeto || frontsector->ColorMap->Fade || (level.flags & LEVEL_HASFADETABLE); + bool foggy = level.fadeto || frontsector->Colormap.FadeColor || (level.flags & LEVEL_HASFADETABLE); // kg3D - fake lights CameraLight *cameraLight = CameraLight::Instance(); @@ -486,7 +485,7 @@ namespace swrenderer if (cameraLight->FixedLightLevel() < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(frontsector, &frontsector->ceilingplane, false); - basecolormap = light->extra_colormap; + basecolormap = GetColorTable(light->extra_colormap); // If this is the real ceiling, don't discard plane lighting R_FakeFlat() // accounted for. if (light->p_lightlevel != &frontsector->lightlevel) @@ -496,7 +495,7 @@ namespace swrenderer } else { - basecolormap = (r_fullbrightignoresectorcolor && cameraLight->FixedLightLevel() >= 0) ? &FullNormalLight : frontsector->ColorMap; + basecolormap = (r_fullbrightignoresectorcolor && cameraLight->FixedLightLevel() >= 0) ? &FullNormalLight : GetColorTable(frontsector->Colormap); } portal = frontsector->ValidatePortal(sector_t::ceiling); @@ -524,7 +523,7 @@ namespace swrenderer if (cameraLight->FixedLightLevel() < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(frontsector, &frontsector->floorplane, false); - basecolormap = light->extra_colormap; + basecolormap = GetColorTable(light->extra_colormap); // If this is the real floor, don't discard plane lighting R_FakeFlat() // accounted for. if (light->p_lightlevel != &frontsector->lightlevel) @@ -534,7 +533,7 @@ namespace swrenderer } else { - basecolormap = (r_fullbrightignoresectorcolor && cameraLight->FixedLightLevel() >= 0) ? &FullNormalLight : frontsector->ColorMap; + basecolormap = (r_fullbrightignoresectorcolor && cameraLight->FixedLightLevel() >= 0) ? &FullNormalLight : GetColorTable(frontsector->Colormap); } // killough 3/7/98: Add (x,y) offsets to flats, add deep water check @@ -609,7 +608,7 @@ namespace swrenderer if (cameraLight->FixedLightLevel() < 0 && sub->sector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(sub->sector, &frontsector->floorplane, false); - basecolormap = light->extra_colormap; + basecolormap = GetColorTable(light->extra_colormap); floorlightlevel = *light->p_lightlevel; } @@ -674,7 +673,7 @@ namespace swrenderer if (cameraLight->FixedLightLevel() < 0 && sub->sector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(sub->sector, &frontsector->ceilingplane, false); - basecolormap = light->extra_colormap; + basecolormap = GetColorTable(light->extra_colormap); ceilinglightlevel = *light->p_lightlevel; } tempsec.ceilingplane.ChangeHeight(1 / 65536.); @@ -703,7 +702,7 @@ namespace swrenderer ceilingplane = backupcp; } - basecolormap = frontsector->ColorMap; + basecolormap = GetColorTable(frontsector->Colormap); floorlightlevel = fll; ceilinglightlevel = cll; @@ -886,7 +885,7 @@ namespace swrenderer { int lightlevel = thing->Sector->GetTexture(sector_t::ceiling) == skyflatnum ? thing->Sector->GetCeilingLight() : thing->Sector->GetFloorLight(); thingShade = LightVisibility::LightLevelToShade(lightlevel + LightVisibility::ActualExtraLight(foggy, Thread->Viewport.get()), foggy); - thingColormap = thing->Sector->ColorMap; + thingColormap = GetColorTable(thing->Sector->Colormap); } if ((sprite.renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index b6520deb0..5924dee3b 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -148,7 +148,7 @@ namespace swrenderer botplane = &heightsec->ceilingplane; toppic = sector->GetTexture(sector_t::ceiling); botpic = heightsec->GetTexture(sector_t::ceiling); - map = heightsec->ColorMap; + map = GetColorTable(heightsec->Colormap); } else if (fakeside == WaterFakeSide::BelowFloor) { @@ -156,7 +156,7 @@ namespace swrenderer botplane = §or->floorplane; toppic = heightsec->GetTexture(sector_t::floor); botpic = sector->GetTexture(sector_t::floor); - map = heightsec->ColorMap; + map = GetColorTable(heightsec->Colormap); } else { @@ -164,7 +164,7 @@ namespace swrenderer botplane = &heightsec->floorplane; toppic = heightsec->GetTexture(sector_t::ceiling); botpic = heightsec->GetTexture(sector_t::floor); - map = sector->ColorMap; + map = GetColorTable(sector->Colormap); } } else @@ -173,7 +173,7 @@ namespace swrenderer botplane = §or->floorplane; toppic = sector->GetTexture(sector_t::ceiling); botpic = sector->GetTexture(sector_t::floor); - map = sector->ColorMap; + map = GetColorTable(sector->Colormap); } if (botpic != skyflatnum && particle->Pos.Z < botplane->ZatPoint(particle->Pos)) diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index daa4ef516..ea0b2af24 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -103,9 +103,9 @@ namespace swrenderer break; sec = rover->model; if (rover->flags & FF_FADEWALLS) - basecolormap = sec->ColorMap; + basecolormap = GetColorTable(sec->Colormap); else - basecolormap = Thread->Viewport->viewpoint.sector->e->XFloor.lightlist[i].extra_colormap; + basecolormap = GetColorTable(Thread->Viewport->viewpoint.sector->e->XFloor.lightlist[i].extra_colormap); } break; } @@ -113,7 +113,7 @@ namespace swrenderer if (!sec) { sec = Thread->Viewport->viewpoint.sector; - basecolormap = sec->ColorMap; + basecolormap = GetColorTable(sec->Colormap); } floorlight = ceilinglight = sec->lightlevel; } @@ -123,7 +123,7 @@ namespace swrenderer sec = Thread->OpaquePass->FakeFlat(Thread->Viewport->viewpoint.sector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0); // [RH] set basecolormap - basecolormap = sec->ColorMap; + basecolormap = GetColorTable(sec->Colormap); } // [RH] set foggy flag diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index dd844c5f7..d51a5bd79 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -113,11 +113,11 @@ namespace swrenderer sec = rover->model; if (rover->flags & FF_FADEWALLS) { - mybasecolormap = sec->ColorMap; + mybasecolormap = GetColorTable(sec->Colormap); } else { - mybasecolormap = spr->sector->e->XFloor.lightlist[i].extra_colormap; + mybasecolormap = GetColorTable(spr->sector->e->XFloor.lightlist[i].extra_colormap); } } break; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 3f3cae3a2..a040b80cf 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -955,7 +955,7 @@ void DCanvas::Dim(PalEntry color, float damount, int x1, int y1, int w, int h) void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, - FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) + const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip) { #ifndef NO_SWRENDER SWCanvas::FillSimplePoly(this, tex, points, npoints, originx, originy, scalex, scaley, rotation, colormap, flatcolor, lightlevel, bottomclip); diff --git a/src/v_video.h b/src/v_video.h index 891174d8e..444e80f04 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -52,6 +52,7 @@ void V_OutputResized (int width, int height); void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *cx1=NULL, int *cx2=NULL); class FTexture; +struct FColormap; // TagItem definitions for DrawTexture. As far as I know, tag lists // originated on the Amiga. @@ -232,7 +233,7 @@ public: // Fill a simple polygon with a texture virtual void FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, - struct FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip); + const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip); // Set an area to a specified color virtual void Clear (int left, int top, int right, int bottom, int palcolor, uint32_t color); diff --git a/src/version.h b/src/version.h index 8c697d9f4..0bcbbb83e 100644 --- a/src/version.h +++ b/src/version.h @@ -85,11 +85,11 @@ const char *GetVersionString(); #define SAVEGAME_EXT "zds" // MINSAVEVER is the minimum level snapshot version that can be loaded. -#define MINSAVEVER 4550 +#define MINSAVEVER 4551 // Use 4500 as the base git save version, since it's higher than the // SVN revision ever got. -#define SAVEVER 4550 +#define SAVEVER 4551 // This is so that derivates can use the same savegame versions without worrying about engine compatibility #define GAMESIG "GZDOOM" diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 3c3255515..df180587e 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -3125,7 +3125,7 @@ void D3DFB::FlatFill(int left, int top, int right, int bottom, FTexture *src, bo void D3DFB::FillSimplePoly(FTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip) { // Use an equation similar to player sprites to determine shade double fadelevel = clamp((swrenderer::LightVisibility::LightLevelToShade(lightlevel, true)/65536. - 12) / NUMCOLORMAPS, 0.0, 1.0); @@ -3174,20 +3174,17 @@ void D3DFB::FillSimplePoly(FTexture *texture, FVector2 *points, int npoints, { quad->Flags = BQF_WrapUV | BQF_GamePalette | BQF_DisableAlphaTest; quad->ShaderNum = BQS_PalTex; - if (colormap != NULL) + if (colormap.Desaturation != 0) { - if (colormap->Desaturate != 0) - { - quad->Flags |= BQF_Desaturated; - } - quad->ShaderNum = BQS_InGameColormap; - quad->Desat = colormap->Desaturate; - color0 = D3DCOLOR_ARGB(255, colormap->Color.r, colormap->Color.g, colormap->Color.b); - color1 = D3DCOLOR_ARGB(DWORD((1 - fadelevel) * 255), - DWORD(colormap->Fade.r * fadelevel), - DWORD(colormap->Fade.g * fadelevel), - DWORD(colormap->Fade.b * fadelevel)); + quad->Flags |= BQF_Desaturated; } + quad->ShaderNum = BQS_InGameColormap; + quad->Desat = colormap.Desaturation; + color0 = D3DCOLOR_ARGB(255, colormap.LightColor.r, colormap.LightColor.g, colormap.LightColor.b); + color1 = D3DCOLOR_ARGB(DWORD((1 - fadelevel) * 255), + DWORD(colormap.FadeColor.r * fadelevel), + DWORD(colormap.FadeColor.g * fadelevel), + DWORD(colormap.FadeColor.b * fadelevel)); } else { diff --git a/src/win32/win32swiface.h b/src/win32/win32swiface.h index 65cb4583d..ecd5a49df 100644 --- a/src/win32/win32swiface.h +++ b/src/win32/win32swiface.h @@ -139,7 +139,7 @@ public: void DrawPixel(int x, int y, int palcolor, uint32_t rgbcolor); void FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, - DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) override; + DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip) override; bool WipeStartScreen(int type); void WipeEndScreen(); bool WipeDo(int ticks);