From ed05a2edd39c4919339bdcffd9e6af6a23a420a3 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 26 Jan 2017 10:22:54 +0100 Subject: [PATCH] Create CameraLight class --- src/gl/system/gl_swframebuffer.cpp | 2 +- src/polyrenderer/poly_renderer.cpp | 7 +++-- src/polyrenderer/scene/poly_decal.cpp | 4 ++- src/polyrenderer/scene/poly_particle.cpp | 3 +- src/polyrenderer/scene/poly_plane.cpp | 10 +++++-- src/polyrenderer/scene/poly_playersprite.cpp | 5 ++-- src/polyrenderer/scene/poly_sprite.cpp | 3 +- src/polyrenderer/scene/poly_wall.cpp | 3 +- src/polyrenderer/scene/poly_wallsprite.cpp | 3 +- src/swrenderer/drawers/r_draw.cpp | 7 +++-- src/swrenderer/line/r_line.cpp | 14 ++++++---- src/swrenderer/line/r_renderdrawsegment.cpp | 28 +++++++++++-------- src/swrenderer/line/r_walldraw.cpp | 10 ++++--- src/swrenderer/plane/r_flatplane.cpp | 9 +++--- src/swrenderer/plane/r_skyplane.cpp | 11 ++++---- src/swrenderer/plane/r_slopeplane.cpp | 9 +++--- src/swrenderer/r_swrenderer.cpp | 6 ++-- src/swrenderer/scene/r_light.cpp | 29 +++++++++++--------- src/swrenderer/scene/r_light.h | 14 +++++++--- src/swrenderer/scene/r_opaque_pass.cpp | 13 +++++---- src/swrenderer/scene/r_scene.cpp | 8 +++--- src/swrenderer/things/r_decal.cpp | 9 +++--- src/swrenderer/things/r_playersprite.cpp | 6 ++-- src/swrenderer/things/r_visiblesprite.cpp | 3 +- src/swrenderer/things/r_wallsprite.cpp | 9 +++--- src/v_draw.cpp | 2 +- src/win32/fb_d3d9.cpp | 2 +- 27 files changed, 133 insertions(+), 96 deletions(-) diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index 2250588d3..9ea7066f8 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -1409,7 +1409,7 @@ void OpenGLSWFrameBuffer::Draw3DPart(bool copy3d) uint32_t color0, color1; if (Accel2D) { - auto &map = swrenderer::realfixedcolormap; + auto &map = swrenderer::CameraLight::Instance()->realfixedcolormap; if (map == nullptr) { color0 = 0; diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index bf30e5ef8..be1fe0074 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -69,10 +69,11 @@ void PolyRenderer::RenderView(player_t *player) RenderActorView(player->mo, false); // Apply special colormap if the target cannot do it - if (realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) { R_BeginDrawerCommands(); - DrawerCommandQueue::QueueCommand(realfixedcolormap, screen); + DrawerCommandQueue::QueueCommand(cameraLight->realfixedcolormap, screen); R_EndDrawerCommands(); } @@ -119,7 +120,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) P_FindParticleSubsectors(); PO_LinkToSubsectors(); R_SetupFrame(actor); - swrenderer::R_SetupColormap(actor); + swrenderer::CameraLight::Instance()->SetCamera(actor); swrenderer::RenderViewport::Instance()->SetupFreelook(); ActorRenderFlags savedflags = camera->renderflags; diff --git a/src/polyrenderer/scene/poly_decal.cpp b/src/polyrenderer/scene/poly_decal.cpp index 559581972..78e43df9e 100644 --- a/src/polyrenderer/scene/poly_decal.cpp +++ b/src/polyrenderer/scene/poly_decal.cpp @@ -133,12 +133,14 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan bool fullbrightSprite = (decal->RenderFlags & RF_FULLBRIGHT) == RF_FULLBRIGHT; + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); + PolyDrawArgs args; args.uniforms.flags = 0; args.SetColormap(front->ColorMap); args.SetTexture(tex, decal->Translation, true); args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(); - if (fullbrightSprite || swrenderer::fixedlightlev >= 0 || swrenderer::fixedcolormap) + if (fullbrightSprite || cameraLight->fixedlightlev >= 0 || cameraLight->fixedcolormap) { args.uniforms.light = 256; args.uniforms.flags |= TriUniforms::fixed_light; diff --git a/src/polyrenderer/scene/poly_particle.cpp b/src/polyrenderer/scene/poly_particle.cpp index c49e2e531..bb21275f9 100644 --- a/src/polyrenderer/scene/poly_particle.cpp +++ b/src/polyrenderer/scene/poly_particle.cpp @@ -70,12 +70,13 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP // int color = (particle->color >> 24) & 0xff; // pal index, I think bool fullbrightSprite = particle->bright != 0; + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); PolyDrawArgs args; args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->ParticleGlobVis(); - if (fullbrightSprite || swrenderer::fixedlightlev >= 0 || swrenderer::fixedcolormap) + if (fullbrightSprite || cameraLight->fixedlightlev >= 0 || cameraLight->fixedcolormap) { args.uniforms.light = 256; args.uniforms.flags = TriUniforms::fixed_light; diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index eae3fced2..1fcbad9c9 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -96,8 +96,10 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c if (tex->UseType == FTexture::TEX_Null) return; + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); + int lightlevel = 255; - if (swrenderer::fixedlightlev < 0 && sub->sector->e->XFloor.lightlist.Size()) + if (cameraLight->fixedlightlev < 0 && sub->sector->e->XFloor.lightlist.Size()) { lightlist_t *light = P_GetPlaneLight(sub->sector, &sub->sector->ceilingplane, false); //basecolormap = light->extra_colormap; @@ -109,7 +111,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c PolyDrawArgs args; args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SlopePlaneGlobVis() * 48.0f; args.uniforms.light = (uint32_t)(lightlevel / 255.0f * 256.0f); - if (swrenderer::fixedlightlev >= 0 || swrenderer::fixedcolormap) + if (cameraLight->fixedlightlev >= 0 || cameraLight->fixedcolormap) args.uniforms.light = 256; args.uniforms.flags = 0; args.uniforms.subsectorDepth = subsectorDepth; @@ -300,10 +302,12 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan UVTransform transform(ceiling ? frontsector->planes[sector_t::ceiling].xform : frontsector->planes[sector_t::floor].xform, tex); + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); + PolyDrawArgs args; args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SlopePlaneGlobVis() * 48.0f; args.uniforms.light = (uint32_t)(frontsector->lightlevel / 255.0f * 256.0f); - if (swrenderer::fixedlightlev >= 0 || swrenderer::fixedcolormap) + if (cameraLight->fixedlightlev >= 0 || cameraLight->fixedcolormap) args.uniforms.light = 256; args.uniforms.flags = 0; args.uniforms.subsectorDepth = isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth; diff --git a/src/polyrenderer/scene/poly_playersprite.cpp b/src/polyrenderer/scene/poly_playersprite.cpp index 3333cf9a7..dd8fc4850 100644 --- a/src/polyrenderer/scene/poly_playersprite.cpp +++ b/src/polyrenderer/scene/poly_playersprite.cpp @@ -326,14 +326,15 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa } // If the main colormap has fixed lights, and this sprite is being drawn with that // colormap, disable acceleration so that the lights can remain fixed. - if (!noaccel && swrenderer::realfixedcolormap == nullptr && + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); + if (!noaccel && cameraLight->realfixedcolormap == nullptr && NormalLightHasFixedLights && mybasecolormap == &NormalLight && tex->UseBasePalette()) { noaccel = true; } // [SP] If emulating GZDoom fullbright, disable acceleration - if (r_fullbrightignoresectorcolor && swrenderer::fixedlightlev >= 0) + if (r_fullbrightignoresectorcolor && cameraLight->fixedlightlev >= 0) mybasecolormap = &FullNormalLight; if (r_fullbrightignoresectorcolor && !foggy && sprite->GetState()->GetFullbright()) mybasecolormap = &FullNormalLight; diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index ff84ce5e3..0b9b7a986 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -136,11 +136,12 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla } bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); PolyDrawArgs args; args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SpriteGlobVis(); args.uniforms.flags = 0; - if (fullbrightSprite || swrenderer::fixedlightlev >= 0 || swrenderer::fixedcolormap) + if (fullbrightSprite || cameraLight->fixedlightlev >= 0 || cameraLight->fixedcolormap) { args.uniforms.light = 256; args.uniforms.flags |= TriUniforms::fixed_light; diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index 64de4c675..18df84744 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -352,7 +352,8 @@ FTexture *RenderPolyWall::GetTexture() int RenderPolyWall::GetLightLevel() { - if (swrenderer::fixedlightlev >= 0 || swrenderer::fixedcolormap) + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); + if (cameraLight->fixedlightlev >= 0 || cameraLight->fixedcolormap) { return 255; } diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index 6025a274e..1d321fbc0 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -98,10 +98,11 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli } bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); + swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); PolyDrawArgs args; args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(); - if (fullbrightSprite || swrenderer::fixedlightlev >= 0 || swrenderer::fixedcolormap) + if (fullbrightSprite || cameraLight->fixedlightlev >= 0 || cameraLight->fixedcolormap) { args.uniforms.light = 256; args.uniforms.flags = TriUniforms::fixed_light; diff --git a/src/swrenderer/drawers/r_draw.cpp b/src/swrenderer/drawers/r_draw.cpp index cf3e4edbb..36b840745 100644 --- a/src/swrenderer/drawers/r_draw.cpp +++ b/src/swrenderer/drawers/r_draw.cpp @@ -456,11 +456,12 @@ namespace swrenderer return false; colfunc = &SWPixelFormatDrawers::DrawShadedColumn; drawer_needs_pal_input = true; - dc_color = fixedcolormap ? fixedcolormap->Maps[APART(color)] : basecolormap->Maps[APART(color)]; + CameraLight *cameraLight = CameraLight::Instance(); + dc_color = cameraLight->fixedcolormap ? cameraLight->fixedcolormap->Maps[APART(color)] : basecolormap->Maps[APART(color)]; basecolormap = &ShadeFakeColormap[16 - alpha]; - if (fixedlightlev >= 0 && fixedcolormap == NULL) + if (cameraLight->fixedlightlev >= 0 && cameraLight->fixedcolormap == NULL) { - R_SetColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); + R_SetColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); } else { diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index 84c1470f8..5f16f2b31 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -901,7 +901,8 @@ namespace swrenderer walltexcoords.Project(sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2, WallT); - if (fixedcolormap == NULL && fixedlightlev < 0) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedcolormap == nullptr && cameraLight->fixedlightlev < 0) { wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, frontsector->lightlevel) + R_ActualExtraLight(foggy)); double GlobVis = LightVisibility::Instance()->WallGlobVis(); @@ -918,7 +919,7 @@ namespace swrenderer bool SWRenderLine::IsFogBoundary(sector_t *front, sector_t *back) const { - return r_fogboundary && fixedcolormap == NULL && front->ColorMap->Fade && + return r_fogboundary && CameraLight::Instance()->fixedcolormap == nullptr && front->ColorMap->Fade && front->ColorMap->Fade != back->ColorMap->Fade && (front->GetTexture(sector_t::ceiling) != skyflatnum || back->GetTexture(sector_t::ceiling) != skyflatnum); } @@ -932,10 +933,11 @@ namespace swrenderer double yscale; fixed_t xoffset = rw_offset; - if (fixedlightlev >= 0) - R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); - else if (fixedcolormap != NULL) - R_SetColorMapLight(fixedcolormap, 0, 0); + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev >= 0) + R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); + else if (cameraLight->fixedcolormap != nullptr) + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); // clip wall to the floor and ceiling auto ceilingclip = RenderOpaquePass::Instance()->ceilingclip; diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index 07a781795..142162496 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -97,7 +97,8 @@ namespace swrenderer Clip3DFloors *clip3d = Clip3DFloors::Instance(); - if (fixedlightlev < 0) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev < 0) { if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) { @@ -139,10 +140,10 @@ namespace swrenderer spryscale = ds->iscale + ds->iscalestep * (x1 - ds->x1); rw_scalestep = ds->iscalestep; - if (fixedlightlev >= 0) - R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); - else if (fixedcolormap != nullptr) - R_SetColorMapLight(fixedcolormap, 0, 0); + if (cameraLight->fixedlightlev >= 0) + R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); + else if (cameraLight->fixedcolormap != nullptr) + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); // find positioning texheight = tex->GetScaledHeightDouble(); @@ -269,7 +270,7 @@ namespace swrenderer { for (int x = x1; x < x2; ++x) { - if (fixedcolormap == nullptr && fixedlightlev < 0) + if (cameraLight->fixedcolormap == nullptr && cameraLight->fixedlightlev < 0) { R_SetColorMapLight(basecolormap, rw_light, wallshade); } @@ -440,10 +441,11 @@ namespace swrenderer texturemid += rowoffset; } - if (fixedlightlev >= 0) - R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); - else if (fixedcolormap != nullptr) - R_SetColorMapLight(fixedcolormap, 0, 0); + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev >= 0) + R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); + else if (cameraLight->fixedcolormap != nullptr) + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); WallC.sz1 = ds->sz1; WallC.sz2 = ds->sz2; @@ -665,7 +667,8 @@ namespace swrenderer // correct colors now FDynamicColormap *basecolormap = frontsector->ColorMap; wallshade = ds->shade; - if (fixedlightlev < 0) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev < 0) { if ((ds->bFakeBoundary & 3) == 2) { @@ -839,7 +842,8 @@ namespace swrenderer // correct colors now FDynamicColormap *basecolormap = frontsector->ColorMap; wallshade = ds->shade; - if (fixedlightlev < 0) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev < 0) { if ((ds->bFakeBoundary & 3) == 2) { diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index 66c036a3f..75907c261 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -326,7 +326,8 @@ namespace swrenderer dc_wall_fracbits = r_swtruecolor ? FRACBITS : fracbits; - bool fixed = (fixedcolormap != NULL || fixedlightlev >= 0); + CameraLight *cameraLight = CameraLight::Instance(); + bool fixed = (cameraLight->fixedcolormap != NULL || cameraLight->fixedlightlev >= 0); if (fixed) { dc_wall_colormap[0] = dc_colormap; @@ -339,8 +340,8 @@ namespace swrenderer dc_wall_light[3] = 0; } - if (fixedcolormap) - R_SetColorMapLight(fixedcolormap, 0, 0); + if (cameraLight->fixedcolormap) + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); else R_SetColorMapLight(basecolormap, 0, 0); @@ -455,7 +456,8 @@ namespace swrenderer } else { - if (fixedcolormap != NULL || fixedlightlev >= 0 || !(frontsector->e && frontsector->e->XFloor.lightlist.Size())) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedcolormap != NULL || cameraLight->fixedlightlev >= 0 || !(frontsector->e && frontsector->e->XFloor.lightlist.Size())) { ProcessNormalWall(uwal, dwal, texturemid, swal, lwal); } diff --git a/src/swrenderer/plane/r_flatplane.cpp b/src/swrenderer/plane/r_flatplane.cpp index 08fad4ce3..dff82a5e4 100644 --- a/src/swrenderer/plane/r_flatplane.cpp +++ b/src/swrenderer/plane/r_flatplane.cpp @@ -108,14 +108,15 @@ namespace swrenderer basecolormap = colormap; GlobVis = LightVisibility::Instance()->FlatPlaneGlobVis() / planeheight; ds_light = 0; - if (fixedlightlev >= 0) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev >= 0) { - R_SetDSColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); + R_SetDSColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); plane_shade = false; } - else if (fixedcolormap) + else if (cameraLight->fixedcolormap) { - R_SetDSColorMapLight(fixedcolormap, 0, 0); + R_SetDSColorMapLight(cameraLight->fixedcolormap, 0, 0); plane_shade = false; } else diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index 451d894b6..d07c25b44 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -148,21 +148,22 @@ namespace swrenderer } bool fakefixed = false; - if (fixedcolormap) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedcolormap) { - R_SetColorMapLight(fixedcolormap, 0, 0); + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); } else { fakefixed = true; - fixedcolormap = &NormalLight; - R_SetColorMapLight(fixedcolormap, 0, 0); + cameraLight->fixedcolormap = &NormalLight; + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); } DrawSky(pl); if (fakefixed) - fixedcolormap = NULL; + cameraLight->fixedcolormap = nullptr; } void RenderSkyPlane::DrawSkyColumnStripe(int start_x, int y1, int y2, int columns, double scale, double texturemid, double yrepeat) diff --git a/src/swrenderer/plane/r_slopeplane.cpp b/src/swrenderer/plane/r_slopeplane.cpp index d697fecad..510697eeb 100644 --- a/src/swrenderer/plane/r_slopeplane.cpp +++ b/src/swrenderer/plane/r_slopeplane.cpp @@ -150,14 +150,15 @@ namespace swrenderer basecolormap = colormap; - if (fixedlightlev >= 0) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev >= 0) { - R_SetDSColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); + R_SetDSColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); plane_shade = false; } - else if (fixedcolormap) + else if (cameraLight->fixedcolormap) { - R_SetDSColorMapLight(fixedcolormap, 0, 0); + R_SetDSColorMapLight(cameraLight->fixedcolormap, 0, 0); plane_shade = false; } else diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index e8e1d2c12..a558e04c3 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -254,8 +254,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin // curse Doom's overuse of global variables in the renderer. // These get clobbered by rendering to a camera texture but they need to be preserved so the final rendering can be done with the correct palette. - FSWColormap *savecolormap = fixedcolormap; - FSpecialColormap *savecm = realfixedcolormap; + CameraLight savedCameraLight = *CameraLight::Instance(); DAngle savedfov = FieldOfView; R_SetFOV ((double)fov); @@ -315,8 +314,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin tex->SetUpdated(); - fixedcolormap = savecolormap; - realfixedcolormap = savecm; + *CameraLight::Instance() = savedCameraLight; } sector_t *FSoftwareRenderer::FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel) diff --git a/src/swrenderer/scene/r_light.cpp b/src/swrenderer/scene/r_light.cpp index a57daaea8..851fab750 100644 --- a/src/swrenderer/scene/r_light.cpp +++ b/src/swrenderer/scene/r_light.cpp @@ -38,21 +38,23 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) namespace swrenderer { - int fixedlightlev; - FSWColormap *fixedcolormap; - FSpecialColormap *realfixedcolormap; + CameraLight *CameraLight::Instance() + { + static CameraLight instance; + return &instance; + } - void R_SetupColormap(AActor *actor) + void CameraLight::SetCamera(AActor *actor) { player_t *player = actor->player; - if (camera && camera->player != 0) + if (camera && camera->player != nullptr) player = camera->player; - realfixedcolormap = NULL; - fixedcolormap = NULL; + realfixedcolormap = nullptr; + fixedcolormap = nullptr; fixedlightlev = -1; - if (player != NULL && camera == player->mo) + if (player != nullptr && camera == player->mo) { if (player->fixedcolormap >= 0 && player->fixedcolormap < (int)SpecialColormaps.Size()) { @@ -80,7 +82,7 @@ namespace swrenderer } } // [RH] Inverse light for shooting the Sigil - if (fixedcolormap == NULL && extralight == INT_MIN) + if (fixedcolormap == nullptr && extralight == INT_MIN) { fixedcolormap = &SpecialColormaps[INVERSECOLORMAP]; extralight = 0; @@ -184,15 +186,16 @@ namespace swrenderer basecolormap = GetSpecialLights(basecolormap->Color, basecolormap->Fade.InverseColor(), basecolormap->Desaturate); } - if (fixedcolormap) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedcolormap) { - BaseColormap = fixedcolormap; + BaseColormap = cameraLight->fixedcolormap; ColormapNum = 0; } - else if (fixedlightlev >= 0) + else if (cameraLight->fixedlightlev >= 0) { BaseColormap = (r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap; - ColormapNum = fixedlightlev >> COLORMAPSHIFT; + ColormapNum = cameraLight->fixedlightlev >> COLORMAPSHIFT; } else if (fullbright) { diff --git a/src/swrenderer/scene/r_light.h b/src/swrenderer/scene/r_light.h index 04a12c0ac..cebb34e9e 100644 --- a/src/swrenderer/scene/r_light.h +++ b/src/swrenderer/scene/r_light.h @@ -54,11 +54,17 @@ struct FSWColormap; namespace swrenderer { - extern int fixedlightlev; - extern FSWColormap *fixedcolormap; - extern FSpecialColormap *realfixedcolormap; + class CameraLight + { + public: + static CameraLight *Instance(); - void R_SetupColormap(AActor *actor); + int fixedlightlev = 0; + FSWColormap *fixedcolormap = nullptr; + FSpecialColormap *realfixedcolormap = nullptr; + + void SetCamera(AActor *actor); + }; class LightVisibility { diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index 2018fe38f..2391d0542 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -479,8 +479,9 @@ namespace swrenderer bool foggy = level.fadeto || frontsector->ColorMap->Fade || (level.flags & LEVEL_HASFADETABLE); // kg3D - fake lights + CameraLight *cameraLight = CameraLight::Instance(); FDynamicColormap *basecolormap; - if (fixedlightlev < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size()) + if (cameraLight->fixedlightlev < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(frontsector, &frontsector->ceilingplane, false); basecolormap = light->extra_colormap; @@ -493,7 +494,7 @@ namespace swrenderer } else { - basecolormap = (r_fullbrightignoresectorcolor && fixedlightlev >= 0) ? &FullNormalLight : frontsector->ColorMap; + basecolormap = (r_fullbrightignoresectorcolor && cameraLight->fixedlightlev >= 0) ? &FullNormalLight : frontsector->ColorMap; } portal = frontsector->ValidatePortal(sector_t::ceiling); @@ -518,7 +519,7 @@ namespace swrenderer if (ceilingplane) ceilingplane->AddLights(frontsector->lighthead); - if (fixedlightlev < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size()) + if (cameraLight->fixedlightlev < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(frontsector, &frontsector->floorplane, false); basecolormap = light->extra_colormap; @@ -531,7 +532,7 @@ namespace swrenderer } else { - basecolormap = (r_fullbrightignoresectorcolor && fixedlightlev >= 0) ? &FullNormalLight : frontsector->ColorMap; + basecolormap = (r_fullbrightignoresectorcolor && cameraLight->fixedlightlev >= 0) ? &FullNormalLight : frontsector->ColorMap; } // killough 3/7/98: Add (x,y) offsets to flats, add deep water check @@ -603,7 +604,7 @@ namespace swrenderer else position = sector_t::floor; frontsector = &tempsec; - if (fixedlightlev < 0 && sub->sector->e->XFloor.lightlist.Size()) + if (cameraLight->fixedlightlev < 0 && sub->sector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(sub->sector, &frontsector->floorplane, false); basecolormap = light->extra_colormap; @@ -668,7 +669,7 @@ namespace swrenderer frontsector = &tempsec; tempsec.ceilingplane.ChangeHeight(-1 / 65536.); - if (fixedlightlev < 0 && sub->sector->e->XFloor.lightlist.Size()) + if (cameraLight->fixedlightlev < 0 && sub->sector->e->XFloor.lightlist.Size()) { light = P_GetPlaneLight(sub->sector, &frontsector->ceilingplane, false); basecolormap = light->extra_colormap; diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index a85120eb3..1941bd4cb 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -103,9 +103,9 @@ namespace swrenderer RenderActorView(player->mo); // Apply special colormap if the target cannot do it - if (realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) + if (CameraLight::Instance()->realfixedcolormap && r_swtruecolor && !(r_shadercolormaps && screen->Accel2D)) { - DrawerCommandQueue::QueueCommand(realfixedcolormap, screen); + DrawerCommandQueue::QueueCommand(CameraLight::Instance()->realfixedcolormap, screen); } R_EndDrawerCommands(); @@ -125,7 +125,7 @@ namespace swrenderer clip3d->ResetClip(); // reset clips (floor/ceiling) R_SetupFrame(actor); - R_SetupColormap(actor); + CameraLight::Instance()->SetCamera(actor); RenderViewport::Instance()->SetupFreelook(); RenderPortal::Instance()->CopyStackedViewParameters(); @@ -193,7 +193,7 @@ namespace swrenderer // copy to the screen does not use a special colormap shader. if (!r_shadercolormaps && !r_swtruecolor) { - realfixedcolormap = NULL; + CameraLight::Instance()->realfixedcolormap = NULL; } } diff --git a/src/swrenderer/things/r_decal.cpp b/src/swrenderer/things/r_decal.cpp index 23f987c63..eb34f7c3a 100644 --- a/src/swrenderer/things/r_decal.cpp +++ b/src/swrenderer/things/r_decal.cpp @@ -253,10 +253,11 @@ namespace swrenderer } light = lightleft + (x1 - savecoord.sx1) * lightstep; - if (fixedlightlev >= 0) - R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); - else if (fixedcolormap != NULL) - R_SetColorMapLight(fixedcolormap, 0, 0); + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev >= 0) + R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); + else if (cameraLight->fixedcolormap != NULL) + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); else if (!foggy && (decal->RenderFlags & RF_FULLBRIGHT)) R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0); else diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index 649df8858..a1041808e 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -90,7 +90,8 @@ namespace swrenderer return; FDynamicColormap *basecolormap; - if (fixedlightlev < 0 && viewsector->e && viewsector->e->XFloor.lightlist.Size()) + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev < 0 && viewsector->e && viewsector->e->XFloor.lightlist.Size()) { for (i = viewsector->e->XFloor.lightlist.Size() - 1; i >= 0; i--) { @@ -480,7 +481,8 @@ namespace swrenderer } // If the main colormap has fixed lights, and this sprite is being drawn with that // colormap, disable acceleration so that the lights can remain fixed. - if (!noaccel && realfixedcolormap == nullptr && + CameraLight *cameraLight = CameraLight::Instance(); + if (!noaccel && cameraLight->realfixedcolormap == nullptr && NormalLightHasFixedLights && vis.Light.BaseColormap == &NormalLight && vis.pic->UseBasePalette()) { diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index f364a6cbd..b2c0b054a 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -86,7 +86,8 @@ namespace swrenderer if ((clip3d->fake3D & FAKE3D_CLIPTOP) && spr->gzb >= clip3d->sclipTop) return; // kg3D - correct colors now - if (!fixedcolormap && fixedlightlev < 0 && spr->sector->e && spr->sector->e->XFloor.lightlist.Size()) + CameraLight *cameraLight = CameraLight::Instance(); + if (!cameraLight->fixedcolormap && cameraLight->fixedlightlev < 0 && spr->sector->e && spr->sector->e->XFloor.lightlist.Size()) { if (!(clip3d->fake3D & FAKE3D_CLIPTOP)) { diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index e5b95c31d..f4587e6a1 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -184,10 +184,11 @@ namespace swrenderer float lightleft = float(GlobVis / spr->wallc.sz1); float lightstep = float((GlobVis / spr->wallc.sz2 - lightleft) / (spr->wallc.sx2 - spr->wallc.sx1)); float light = lightleft + (x1 - spr->wallc.sx1) * lightstep; - if (fixedlightlev >= 0) - R_SetColorMapLight(usecolormap, 0, FIXEDLIGHT2SHADE(fixedlightlev)); - else if (fixedcolormap != NULL) - R_SetColorMapLight(fixedcolormap, 0, 0); + CameraLight *cameraLight = CameraLight::Instance(); + if (cameraLight->fixedlightlev >= 0) + R_SetColorMapLight(usecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev)); + else if (cameraLight->fixedcolormap != NULL) + R_SetColorMapLight(cameraLight->fixedcolormap, 0, 0); else if (!spr->foggy && (spr->renderflags & RF_FULLBRIGHT)) R_SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0); else diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 296cc29b1..567799d47 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -197,7 +197,7 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) R_SetTranslationMap(identitymap); } - fixedcolormap = dc_fcolormap; + CameraLight::Instance()->fixedcolormap = dc_fcolormap; bool visible; FDynamicColormap *basecolormap = nullptr; if (r_swtruecolor) diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index d28ef2246..e04ab1dc1 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -1405,7 +1405,7 @@ void D3DFB::Draw3DPart(bool copy3d) D3DCOLOR color0, color1; if (Accel2D) { - auto &map = swrenderer::realfixedcolormap; + auto &map = swrenderer::CameraLight::Instance()->realfixedcolormap; if (map == NULL) { color0 = 0;