From f4d9ad1123d912c63d300aa8965043330d6f8a66 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Mar 2018 21:33:44 +0100 Subject: [PATCH] - extended FTexture::GetPixels and FTexture::GetColumn by a RenderStyle parameter. Now it is no longer necessary to provide specially set up textures for rendering shaded decals, they can use any PNG texture now that contains a proper red channel. Handling of the alPh chunk has been removed as a result as it in no longer needed. --- src/gl/textures/gl_material.cpp | 5 +- src/gl/textures/gl_texture.cpp | 2 +- src/polyrenderer/drawers/poly_draw_args.cpp | 41 +++++---- src/polyrenderer/drawers/poly_draw_args.h | 10 +-- src/polyrenderer/poly_renderthread.cpp | 6 +- src/polyrenderer/poly_renderthread.h | 2 +- src/polyrenderer/scene/poly_model.cpp | 4 +- src/polyrenderer/scene/poly_plane.cpp | 4 +- src/polyrenderer/scene/poly_sky.cpp | 2 +- src/polyrenderer/scene/poly_wall.cpp | 2 +- src/polyrenderer/scene/poly_wallsprite.cpp | 2 +- src/r_data/renderstyle.h | 10 +++ src/swrenderer/line/r_renderdrawsegment.cpp | 5 +- src/swrenderer/line/r_walldraw.cpp | 4 +- src/swrenderer/plane/r_skyplane.cpp | 4 +- src/swrenderer/r_renderthread.cpp | 6 +- src/swrenderer/r_renderthread.h | 2 +- src/swrenderer/r_swcanvas.cpp | 2 +- src/swrenderer/r_swrenderer.cpp | 8 +- src/swrenderer/things/r_decal.cpp | 8 +- src/swrenderer/things/r_decal.h | 2 +- src/swrenderer/things/r_model.cpp | 4 +- src/swrenderer/things/r_playersprite.cpp | 4 +- src/swrenderer/things/r_sprite.cpp | 4 +- src/swrenderer/things/r_wallsprite.cpp | 8 +- src/swrenderer/things/r_wallsprite.h | 2 +- src/swrenderer/viewport/r_skydrawer.cpp | 4 +- src/swrenderer/viewport/r_spandrawer.cpp | 4 +- src/swrenderer/viewport/r_spritedrawer.cpp | 4 +- src/swrenderer/viewport/r_spritedrawer.h | 2 +- src/textures/backdroptexture.cpp | 4 +- src/textures/canvastexture.cpp | 12 +-- src/textures/multipatchtexture.cpp | 10 ++- src/textures/skyboxtexture.cpp | 8 +- src/textures/skyboxtexture.h | 4 +- src/textures/texture.cpp | 39 +++++---- src/textures/textures.h | 52 ++++++----- src/textures/warptexture.cpp | 97 ++++----------------- src/textures/worldtexture.cpp | 35 +++++--- src/v_font.cpp | 28 +++--- src/v_video.cpp | 12 +-- 41 files changed, 218 insertions(+), 250 deletions(-) diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 859706772a..98f0559d94 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -31,6 +31,7 @@ #include "r_utility.h" #include "templates.h" #include "sc_man.h" +#include "r_data/renderstyle.h" #include "colormatcher.h" #include "textures/warpbuffer.h" #include "textures/bitmap.h" @@ -297,7 +298,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla if (hwtex) { // Texture has become invalid - if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified()) + if ((!tex->bHasCanvas && (!tex->bWarped || gl.legacyMode)) && tex->CheckModified(DefaultRenderStyle())) { Clean(true); hwtex = CreateHwTexture(); @@ -323,7 +324,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla WarpBuffer((uint32_t*)warpbuffer, (const uint32_t*)buffer, w, h, wt->WidthOffsetMultiplier, wt->HeightOffsetMultiplier, screen->FrameTime, wt->Speed, tex->bWarped); delete[] buffer; buffer = warpbuffer; - wt->GenTime = screen->FrameTime; + wt->GenTime[0] = screen->FrameTime; } tex->ProcessData(buffer, w, h, false); } diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index 0680ccdd69..f228d21235 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -238,7 +238,7 @@ void FTexture::CreateDefaultBrightmap() ) { // May have one - let's check when we use this texture - const uint8_t *texbuf = GetPixels(); + const uint8_t *texbuf = GetPixels(DefaultRenderStyle()); const int white = ColorMatcher.Pick(255,255,255); int size = GetWidth() * GetHeight(); diff --git a/src/polyrenderer/drawers/poly_draw_args.cpp b/src/polyrenderer/drawers/poly_draw_args.cpp index 466a39f4ab..312cb3e32b 100644 --- a/src/polyrenderer/drawers/poly_draw_args.cpp +++ b/src/polyrenderer/drawers/poly_draw_args.cpp @@ -46,20 +46,21 @@ void PolyDrawArgs::SetTexture(const uint8_t *texels, int width, int height) mTranslation = nullptr; } -void PolyDrawArgs::SetTexture(FTexture *texture) +void PolyDrawArgs::SetTexture(FTexture *texture, FRenderStyle style) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); if (PolyRenderer::Instance()->RenderTarget->IsBgra()) mTexturePixels = (const uint8_t *)texture->GetPixelsBgra(); else - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); mTranslation = nullptr; } -void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal) +void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style) { - if (translationID != 0xffffffff && translationID != 0) + // Alphatexture overrides translations. + if (translationID != 0xffffffff && translationID != 0 && !(style.Flags & STYLEF_RedIsAlpha)) { FRemapTable *table = TranslationToTable(translationID); if (table != nullptr && !table->Inactive) @@ -71,20 +72,20 @@ void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); return; } } - if (forcePal) + if (style.Flags & STYLEF_RedIsAlpha) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); } else { - SetTexture(texture); + SetTexture(texture, style); } } @@ -164,8 +165,7 @@ void PolyDrawArgs::DrawElements(PolyRenderThread *thread, const TriVertex *verti void PolyDrawArgs::SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *tex, bool fullbright) { - bool forcePal = (renderstyle == LegacyRenderStyles[STYLE_Shaded] || renderstyle == LegacyRenderStyles[STYLE_AddShaded]); - SetTexture(tex, translationID, forcePal); + SetTexture(tex, translationID, renderstyle); if (renderstyle == LegacyRenderStyles[STYLE_Normal] || (r_drawfuzz == 0 && renderstyle == LegacyRenderStyles[STYLE_OptFuzzy])) { @@ -232,20 +232,20 @@ void RectDrawArgs::SetTexture(const uint8_t *texels, int width, int height) mTranslation = nullptr; } -void RectDrawArgs::SetTexture(FTexture *texture) +void RectDrawArgs::SetTexture(FTexture *texture, FRenderStyle style) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); if (PolyRenderer::Instance()->RenderTarget->IsBgra()) mTexturePixels = (const uint8_t *)texture->GetPixelsBgra(); else - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); mTranslation = nullptr; } -void RectDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal) +void RectDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style) { - if (translationID != 0xffffffff && translationID != 0) + if (translationID != 0xffffffff && translationID != 0 && !(style.Flags & STYLEF_RedIsAlpha)) { FRemapTable *table = TranslationToTable(translationID); if (table != nullptr && !table->Inactive) @@ -257,20 +257,20 @@ void RectDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); return; } } - if (forcePal) + if (style.Flags & STYLEF_RedIsAlpha) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); - mTexturePixels = texture->GetPixels(); + mTexturePixels = texture->GetPixels(style); } else { - SetTexture(texture); + SetTexture(texture, style); } } @@ -315,10 +315,9 @@ void RectDrawArgs::Draw(PolyRenderThread *thread, double x0, double x1, double y thread->DrawQueue->Push(*this); } -void RectDrawArgs::SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *tex, bool fullbright) +void RectDrawArgs::SetStyle(FRenderStyle renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *tex, bool fullbright) { - bool forcePal = (renderstyle == LegacyRenderStyles[STYLE_Shaded] || renderstyle == LegacyRenderStyles[STYLE_AddShaded]); - SetTexture(tex, translationID, forcePal); + SetTexture(tex, translationID, renderstyle); if (renderstyle == LegacyRenderStyles[STYLE_Normal] || (r_drawfuzz == 0 && renderstyle == LegacyRenderStyles[STYLE_OptFuzzy])) { diff --git a/src/polyrenderer/drawers/poly_draw_args.h b/src/polyrenderer/drawers/poly_draw_args.h index eb543bbbf5..05ad0862d9 100644 --- a/src/polyrenderer/drawers/poly_draw_args.h +++ b/src/polyrenderer/drawers/poly_draw_args.h @@ -67,8 +67,8 @@ class PolyDrawArgs public: void SetClipPlane(int index, const PolyClipPlane &plane) { mClipPlane[index] = plane; } void SetTexture(const uint8_t *texels, int width, int height); - void SetTexture(FTexture *texture); - void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false); + void SetTexture(FTexture *texture, FRenderStyle style); + void SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style); void SetLight(FSWColormap *basecolormap, uint32_t lightlevel, double globVis, bool fixed); void SetDepthTest(bool enable) { mDepthTest = enable; } void SetStencilTestValue(uint8_t stencilTestValue) { mStencilTestValue = stencilTestValue; } @@ -186,11 +186,11 @@ class RectDrawArgs { public: void SetTexture(const uint8_t *texels, int width, int height); - void SetTexture(FTexture *texture); - void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false); + void SetTexture(FTexture *texture, FRenderStyle style); + void SetTexture(FTexture *texture, uint32_t translationID, FRenderStyle style); void SetLight(FSWColormap *basecolormap, uint32_t lightlevel); void SetStyle(TriBlendMode blendmode, double srcalpha = 1.0, double destalpha = 1.0) { mBlendMode = blendmode; mSrcAlpha = (uint32_t)(srcalpha * 256.0 + 0.5); mDestAlpha = (uint32_t)(destalpha * 256.0 + 0.5); } - void SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *texture, bool fullbright); + void SetStyle(FRenderStyle renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *texture, bool fullbright); void SetColor(uint32_t bgra, uint8_t palindex); void Draw(PolyRenderThread *thread, double x0, double x1, double y0, double y1, double u0, double u1, double v0, double v1); diff --git a/src/polyrenderer/poly_renderthread.cpp b/src/polyrenderer/poly_renderthread.cpp index 9c3b331226..55d1c84696 100644 --- a/src/polyrenderer/poly_renderthread.cpp +++ b/src/polyrenderer/poly_renderthread.cpp @@ -74,7 +74,7 @@ void PolyRenderThread::FlushDrawQueue() } } -void PolyRenderThread::PrepareTexture(FTexture *texture) +void PolyRenderThread::PrepareTexture(FTexture *texture, FRenderStyle style) { if (texture == nullptr) return; @@ -91,9 +91,9 @@ void PolyRenderThread::PrepareTexture(FTexture *texture) std::unique_lock lock(loadmutex); - texture->GetPixels(); + texture->GetPixels(style); const FTexture::Span *spans; - texture->GetColumn(0, &spans); + texture->GetColumn(style, 0, &spans); if (PolyRenderer::Instance()->RenderTarget->IsBgra()) { texture->GetPixelsBgra(); diff --git a/src/polyrenderer/poly_renderthread.h b/src/polyrenderer/poly_renderthread.h index af10fd45c8..afed28b193 100644 --- a/src/polyrenderer/poly_renderthread.h +++ b/src/polyrenderer/poly_renderthread.h @@ -47,7 +47,7 @@ public: DrawerCommandQueuePtr DrawQueue; // Make sure texture can accessed safely - void PrepareTexture(FTexture *texture); + void PrepareTexture(FTexture *texture, FRenderStyle style); // Setup poly object in a threadsafe manner void PreparePolyObject(subsector_t *sub); diff --git a/src/polyrenderer/scene/poly_model.cpp b/src/polyrenderer/scene/poly_model.cpp index c952625c31..b2ce178cce 100644 --- a/src/polyrenderer/scene/poly_model.cpp +++ b/src/polyrenderer/scene/poly_model.cpp @@ -147,7 +147,7 @@ void PolyModelRenderer::DrawArrays(int start, int count) args.SetStencilTestValue(StencilValue); args.SetClipPlane(0, PolyClipPlane()); args.SetStyle(TriBlendMode::TextureOpaque); - args.SetTexture(SkinTexture); + args.SetTexture(SkinTexture, DefaultRenderStyle()); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); @@ -181,7 +181,7 @@ void PolyModelRenderer::DrawElements(int numIndices, size_t offset) args.SetStencilTestValue(StencilValue); args.SetClipPlane(0, PolyClipPlane()); args.SetStyle(TriBlendMode::TextureOpaque); - args.SetTexture(SkinTexture); + args.SetTexture(SkinTexture, DefaultRenderStyle()); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index f5485d0969..874fe26306 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -81,7 +81,7 @@ void RenderPolyPlane::RenderNormal(PolyRenderThread *thread, const TriMatrix &wo args.SetStencilTestValue(stencilValue); args.SetWriteStencil(true, stencilValue + 1); args.SetClipPlane(0, clipPlane); - args.SetTexture(tex); + args.SetTexture(tex, DefaultRenderStyle()); args.SetStyle(TriBlendMode::TextureOpaque); args.DrawArray(thread, vertices, fakeflat.Subsector->numlines, PolyDrawMode::TriangleFan); } @@ -572,7 +572,7 @@ void Render3DFloorPlane::Render(PolyRenderThread *thread, const TriMatrix &world args.SetFaceCullCCW(true); args.SetStencilTestValue(stencilValue); args.SetWriteStencil(true, stencilValue + 1); - args.SetTexture(tex); + args.SetTexture(tex, DefaultRenderStyle()); args.SetClipPlane(0, clipPlane); args.DrawArray(thread, vertices, sub->numlines, PolyDrawMode::TriangleFan); } diff --git a/src/polyrenderer/scene/poly_sky.cpp b/src/polyrenderer/scene/poly_sky.cpp index 06cb7a8ece..eafa4c94c0 100644 --- a/src/polyrenderer/scene/poly_sky.cpp +++ b/src/polyrenderer/scene/poly_sky.cpp @@ -91,7 +91,7 @@ void PolySkyDome::Render(PolyRenderThread *thread, const TriMatrix &worldToClip) RenderCapColorRow(thread, args, mCurrentSetup.frontskytex, 0, false); RenderCapColorRow(thread, args, mCurrentSetup.frontskytex, rc, true); - args.SetTexture(mCurrentSetup.frontskytex); + args.SetTexture(mCurrentSetup.frontskytex, DefaultRenderStyle()); uint32_t topcapcolor = mCurrentSetup.frontskytex->GetSkyCapColor(false); uint32_t bottomcapcolor = mCurrentSetup.frontskytex->GetSkyCapColor(true); diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index 20b9a1ade2..fb75f7bf45 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -327,7 +327,7 @@ void RenderPolyWall::Render(PolyRenderThread *thread, const TriMatrix &worldToCl args.SetStencilTestValue(StencilValue); args.SetWriteStencil(true, StencilValue + 1); if (Texture && !Polyportal) - args.SetTexture(Texture); + args.SetTexture(Texture, DefaultRenderStyle()); args.SetClipPlane(0, clipPlane); SetDynLights(thread, args); diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index 846524f9dd..7da68c5e54 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -105,7 +105,7 @@ void RenderPolyWallSprite::Render(PolyRenderThread *thread, const TriMatrix &wor args.SetTransform(&worldToClip); args.SetFaceCullCCW(true); args.SetStencilTestValue(stencilValue); - args.SetTexture(tex); + args.SetTexture(tex, thing->RenderStyle); args.SetClipPlane(0, clipPlane); args.SetDepthTest(true); args.SetWriteDepth(false); diff --git a/src/r_data/renderstyle.h b/src/r_data/renderstyle.h index 21c41278a5..afb82d3800 100644 --- a/src/r_data/renderstyle.h +++ b/src/r_data/renderstyle.h @@ -145,6 +145,16 @@ private: extern FRenderStyle LegacyRenderStyles[STYLE_Count]; +inline FRenderStyle DefaultRenderStyle() +{ + return LegacyRenderStyles[STYLE_Normal]; +} + +inline FRenderStyle BadRenderStyle() // This is just a marker to find places where work is still needed. +{ + return LegacyRenderStyles[STYLE_Normal]; +} + inline FRenderStyle &FRenderStyle::operator= (ERenderStyle legacy) { if (legacy < STYLE_None || legacy >= STYLE_Count) diff --git a/src/swrenderer/line/r_renderdrawsegment.cpp b/src/swrenderer/line/r_renderdrawsegment.cpp index 86f86c2cbe..f46fbc1331 100644 --- a/src/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/swrenderer/line/r_renderdrawsegment.cpp @@ -155,6 +155,7 @@ namespace swrenderer bool RenderDrawSegment::RenderWall(DrawSegment *ds, int x1, int x2, WallDrawerArgs &walldrawerargs, SpriteDrawerArgs &columndrawerargs, bool visible, FDynamicColormap *basecolormap, int wallshade) { + auto renderstyle = DefaultRenderStyle(); auto viewport = Thread->Viewport.get(); Clip3DFloors *clip3d = Thread->Clip3D.get(); @@ -314,7 +315,7 @@ namespace swrenderer // draw the columns one at a time if (visible) { - Thread->PrepareTexture(tex); + Thread->PrepareTexture(tex, renderstyle); for (int x = x1; x < x2; ++x) { if (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0) @@ -329,7 +330,7 @@ namespace swrenderer else sprtopscreen = viewport->CenterY - texturemid * spryscale; - columndrawerargs.DrawMaskedColumn(Thread, x, iscale, tex, maskedtexturecol[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip); + columndrawerargs.DrawMaskedColumn(Thread, x, iscale, tex, maskedtexturecol[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, renderstyle); rw_light += rw_lightstep; spryscale += rw_scalestep; diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index ac277a0aee..0b9c9131d9 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -97,7 +97,7 @@ namespace swrenderer col = width + (col % width); } - source = texture->GetColumn(col, nullptr); + source = texture->GetColumn(DefaultRenderStyle(), col, nullptr); source2 = nullptr; texturefracx = 0; } @@ -530,7 +530,7 @@ namespace swrenderer this->rw_pic = pic; this->mask = mask; - Thread->PrepareTexture(pic); + Thread->PrepareTexture(pic, DefaultRenderStyle()); // Get correct render style? Shaded won't get here. if (rw_pic->GetHeight() != 1 << rw_pic->HeightBits) { diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index ef7a6b898b..e95abbd463 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -172,8 +172,8 @@ namespace swrenderer drawerargs.SetLight(&NormalLight, 0, 0); } - Thread->PrepareTexture(frontskytex); - Thread->PrepareTexture(backskytex); + Thread->PrepareTexture(frontskytex, DefaultRenderStyle()); + Thread->PrepareTexture(backskytex, DefaultRenderStyle()); DrawSky(pl); } diff --git a/src/swrenderer/r_renderthread.cpp b/src/swrenderer/r_renderthread.cpp index bb2816a948..986879618a 100644 --- a/src/swrenderer/r_renderthread.cpp +++ b/src/swrenderer/r_renderthread.cpp @@ -89,7 +89,7 @@ namespace swrenderer return pal_drawers.get(); } - void RenderThread::PrepareTexture(FTexture *texture) + void RenderThread::PrepareTexture(FTexture *texture, FRenderStyle style) { if (texture == nullptr) return; @@ -106,9 +106,9 @@ namespace swrenderer std::unique_lock lock(loadmutex); - texture->GetPixels(); + texture->GetPixels(style); const FTexture::Span *spans; - texture->GetColumn(0, &spans); + texture->GetColumn(style, 0, &spans); if (Viewport->RenderTarget->IsBgra()) { texture->GetPixelsBgra(); diff --git a/src/swrenderer/r_renderthread.h b/src/swrenderer/r_renderthread.h index 3e559155bf..34beab6ae3 100644 --- a/src/swrenderer/r_renderthread.h +++ b/src/swrenderer/r_renderthread.h @@ -84,7 +84,7 @@ namespace swrenderer SWPixelFormatDrawers *Drawers(RenderViewport *viewport); // Make sure texture can accessed safely - void PrepareTexture(FTexture *texture); + void PrepareTexture(FTexture *texture, FRenderStyle style); // Setup poly object in a threadsafe manner void PreparePolyObject(subsector_t *sub); diff --git a/src/swrenderer/r_swcanvas.cpp b/src/swrenderer/r_swcanvas.cpp index 0330d4d6eb..5522d89dcd 100644 --- a/src/swrenderer/r_swcanvas.cpp +++ b/src/swrenderer/r_swcanvas.cpp @@ -196,7 +196,7 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms) while (x < x2_i) { - drawerargs.DrawMaskedColumn(&thread, x, iscale, img, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, !parms.masked); + drawerargs.DrawMaskedColumn(&thread, x, iscale, img, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, parms.style, !parms.masked); x++; frac += xiscale_i; } diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 3c18e62188..c31908a177 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -105,14 +105,14 @@ void FSoftwareRenderer::PrecacheTexture(FTexture *tex, int cache) if (isbgra) tex->GetColumnBgra(0, &spanp); else - tex->GetColumn(0, &spanp); + tex->GetColumn(DefaultRenderStyle(), 0, &spanp); } else if (cache != 0) { if (isbgra) tex->GetPixelsBgra(); else - tex->GetPixels (); + tex->GetPixels (DefaultRenderStyle()); } else { @@ -282,7 +282,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin cameraViewpoint = r_viewpoint; cameraViewwindow = r_viewwindow; - uint8_t *Pixels = renderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels(); + uint8_t *Pixels = renderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels(DefaultRenderStyle()); DSimpleCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas(); // curse Doom's overuse of global variables in the renderer. @@ -328,7 +328,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin // We need to make sure that both pixel buffers contain data: int width = tex->GetWidth(); int height = tex->GetHeight(); - uint8_t *palbuffer = (uint8_t *)tex->GetPixels(); + uint8_t *palbuffer = (uint8_t *)tex->GetPixels(DefaultRenderStyle()); uint32_t *bgrabuffer = (uint32_t*)tex->GetPixelsBgra(); for (int x = 0; x < width; x++) { diff --git a/src/swrenderer/things/r_decal.cpp b/src/swrenderer/things/r_decal.cpp index b1711d9e3b..8361a8061f 100644 --- a/src/swrenderer/things/r_decal.cpp +++ b/src/swrenderer/things/r_decal.cpp @@ -312,14 +312,14 @@ namespace swrenderer if (visible) { - thread->PrepareTexture(WallSpriteTile); + thread->PrepareTexture(WallSpriteTile, decal->RenderStyle); while (x < x2) { if (calclighting) { // calculate lighting drawerargs.SetLight(usecolormap, light, wallshade); } - DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip); + DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, decal->RenderStyle); light += lightstep; x++; } @@ -333,7 +333,7 @@ namespace swrenderer } while (needrepeat--); } - void RenderDecal::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip) + void RenderDecal::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style) { auto viewport = thread->Viewport.get(); @@ -345,6 +345,6 @@ namespace swrenderer else sprtopscreen = viewport->CenterY - texturemid * spryscale; - drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip); + drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, style); } } diff --git a/src/swrenderer/things/r_decal.h b/src/swrenderer/things/r_decal.h index 712e829003..e617b04a6a 100644 --- a/src/swrenderer/things/r_decal.h +++ b/src/swrenderer/things/r_decal.h @@ -16,6 +16,6 @@ namespace swrenderer private: static void Render(RenderThread *thread, side_t *wall, DBaseDecal *first, DrawSegment *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, const FWallCoords &wallC, bool foggy, FDynamicColormap *basecolormap, const short *walltop, const short *wallbottom, bool drawsegPass); - static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); + static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style); }; } diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index 4b68db2194..b6f5fe0c77 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -199,7 +199,7 @@ namespace swrenderer if (Thread->Viewport->RenderTarget->IsBgra()) args.SetTexture((const uint8_t *)SkinTexture->GetPixelsBgra(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); else - args.SetTexture(SkinTexture->GetPixels(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); + args.SetTexture(SkinTexture->GetPixels(DefaultRenderStyle()), SkinTexture->GetWidth(), SkinTexture->GetHeight()); args.SetDepthTest(true); args.SetWriteDepth(true); @@ -237,7 +237,7 @@ namespace swrenderer if (Thread->Viewport->RenderTarget->IsBgra()) args.SetTexture((const uint8_t *)SkinTexture->GetPixelsBgra(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); else - args.SetTexture(SkinTexture->GetPixels(), SkinTexture->GetWidth(), SkinTexture->GetHeight()); + args.SetTexture(SkinTexture->GetPixels(DefaultRenderStyle()), SkinTexture->GetWidth(), SkinTexture->GetHeight()); args.SetDepthTest(true); args.SetWriteDepth(true); diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index 41ec47239f..924c7a7d82 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -545,10 +545,10 @@ namespace swrenderer short *mceilingclip = zeroarray; fixed_t frac = startfrac; - thread->PrepareTexture(pic); + thread->PrepareTexture(pic, RenderStyle); for (int x = x1; x < x2; x++) { - drawerargs.DrawMaskedColumn(thread, x, iscale, pic, frac + xiscale / 2, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false); + drawerargs.DrawMaskedColumn(thread, x, iscale, pic, frac + xiscale / 2, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, RenderStyle, false); frac += xiscale; } diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index 74a76a79f8..be26ad7c2e 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -361,11 +361,11 @@ namespace swrenderer { RenderTranslucentPass *translucentPass = thread->TranslucentPass.get(); - thread->PrepareTexture(tex); + thread->PrepareTexture(tex, vis->RenderStyle); while (x < x2) { if (!translucentPass->ClipSpriteColumnWithPortals(x, vis)) - drawerargs.DrawMaskedColumn(thread, x, iscale, tex, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false); + drawerargs.DrawMaskedColumn(thread, x, iscale, tex, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, vis->RenderStyle, false); x++; frac += xiscale; } diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index be4c4195eb..f44d88e2a5 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -239,7 +239,7 @@ namespace swrenderer { RenderTranslucentPass *translucentPass = thread->TranslucentPass.get(); - thread->PrepareTexture(WallSpriteTile); + thread->PrepareTexture(WallSpriteTile, spr->RenderStyle); while (x < x2) { if (calclighting) @@ -247,14 +247,14 @@ namespace swrenderer drawerargs.SetLight(usecolormap, light, shade); } if (!translucentPass->ClipSpriteColumnWithPortals(x, spr)) - DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip); + DrawColumn(thread, drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip, spr->RenderStyle); light += lightstep; x++; } } } - void RenderWallSprite::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip) + void RenderWallSprite::DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style) { auto viewport = thread->Viewport.get(); @@ -266,6 +266,6 @@ namespace swrenderer else sprtopscreen = viewport->CenterY - texturemid * spryscale; - drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip); + drawerargs.DrawMaskedColumn(thread, x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, style); } } diff --git a/src/swrenderer/things/r_wallsprite.h b/src/swrenderer/things/r_wallsprite.h index c248c6c8c8..fa127ccf45 100644 --- a/src/swrenderer/things/r_wallsprite.h +++ b/src/swrenderer/things/r_wallsprite.h @@ -17,7 +17,7 @@ namespace swrenderer void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; private: - static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); + static void DrawColumn(RenderThread *thread, SpriteDrawerArgs &drawerargs, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style); FWallCoords wallc; uint32_t Translation = 0; diff --git a/src/swrenderer/viewport/r_skydrawer.cpp b/src/swrenderer/viewport/r_skydrawer.cpp index 16e2d2ab38..c134a46e2b 100644 --- a/src/swrenderer/viewport/r_skydrawer.cpp +++ b/src/swrenderer/viewport/r_skydrawer.cpp @@ -56,7 +56,7 @@ namespace swrenderer } else { - dc_source = texture->GetColumn(column, nullptr); + dc_source = texture->GetColumn(DefaultRenderStyle(), column, nullptr); dc_sourceheight = texture->GetHeight(); } } @@ -75,7 +75,7 @@ namespace swrenderer } else { - dc_source2 = texture->GetColumn(column, nullptr); + dc_source2 = texture->GetColumn(DefaultRenderStyle(), column, nullptr); dc_sourceheight2 = texture->GetHeight(); } } diff --git a/src/swrenderer/viewport/r_spandrawer.cpp b/src/swrenderer/viewport/r_spandrawer.cpp index ffc4dfc5ff..e5adf54094 100644 --- a/src/swrenderer/viewport/r_spandrawer.cpp +++ b/src/swrenderer/viewport/r_spandrawer.cpp @@ -32,7 +32,7 @@ namespace swrenderer void SpanDrawerArgs::SetTexture(RenderThread *thread, FTexture *tex) { - thread->PrepareTexture(tex); + thread->PrepareTexture(tex, DefaultRenderStyle()); ds_texwidth = tex->GetWidth(); ds_texheight = tex->GetHeight(); @@ -47,7 +47,7 @@ namespace swrenderer ds_ybits--; } - ds_source = thread->Viewport->RenderTarget->IsBgra() ? (const uint8_t*)tex->GetPixelsBgra() : tex->GetPixels(); + ds_source = thread->Viewport->RenderTarget->IsBgra() ? (const uint8_t*)tex->GetPixelsBgra() : tex->GetPixels(DefaultRenderStyle()); // Get correct render style? Shaded won't get here. ds_source_mipmapped = tex->Mipmapped() && tex->GetWidth() > 1 && tex->GetHeight() > 1; } diff --git a/src/swrenderer/viewport/r_spritedrawer.cpp b/src/swrenderer/viewport/r_spritedrawer.cpp index 0dbb387166..20abfca51e 100644 --- a/src/swrenderer/viewport/r_spritedrawer.cpp +++ b/src/swrenderer/viewport/r_spritedrawer.cpp @@ -43,7 +43,7 @@ namespace swrenderer colfunc = &SWPixelFormatDrawers::DrawColumn; } - void SpriteDrawerArgs::DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked) + void SpriteDrawerArgs::DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style, bool unmasked) { if (x < thread->X1 || x >= thread->X2) return; @@ -67,7 +67,7 @@ namespace swrenderer if (viewport->RenderTarget->IsBgra() && !drawer_needs_pal_input) column = (const uint8_t *)tex->GetColumnBgra(col >> FRACBITS, &span); else - column = tex->GetColumn(col >> FRACBITS, &span); + column = tex->GetColumn(style, col >> FRACBITS, &span); FTexture::Span unmaskedSpan[2]; if (unmasked) diff --git a/src/swrenderer/viewport/r_spritedrawer.h b/src/swrenderer/viewport/r_spritedrawer.h index e1df5e926e..f6a3aae79f 100644 --- a/src/swrenderer/viewport/r_spritedrawer.h +++ b/src/swrenderer/viewport/r_spritedrawer.h @@ -33,7 +33,7 @@ namespace swrenderer void SetSolidColor(int color) { dc_color = color; dc_color_bgra = GPalette.BaseColors[color]; } void SetDynamicLight(uint32_t color) { dynlightcolor = color; } - void DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *texture, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked = false); + void DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *texture, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, FRenderStyle style, bool unmasked = false); void FillColumn(RenderThread *thread); void DrawVoxelBlocks(RenderThread *thread, const VoxelBlock *blocks, int blockcount); diff --git a/src/textures/backdroptexture.cpp b/src/textures/backdroptexture.cpp index 05d3f2541a..9d9049fae1 100644 --- a/src/textures/backdroptexture.cpp +++ b/src/textures/backdroptexture.cpp @@ -77,7 +77,7 @@ class FBackdropTexture : public FWorldTexture public: FBackdropTexture(); - bool CheckModified() override; + bool CheckModified(FRenderStyle style) override; uint8_t *MakeTexture(FRenderStyle style) override; protected: @@ -204,7 +204,7 @@ FBackdropTexture::FBackdropTexture() // //============================================================================= -bool FBackdropTexture::CheckModified() +bool FBackdropTexture::CheckModified(FRenderStyle) { return LastRenderTic != gametic; } diff --git a/src/textures/canvastexture.cpp b/src/textures/canvastexture.cpp index bb6b3d6856..e13dd6d3d3 100644 --- a/src/textures/canvastexture.cpp +++ b/src/textures/canvastexture.cpp @@ -65,12 +65,12 @@ FCanvasTexture::~FCanvasTexture () Unload (); } -const uint8_t *FCanvasTexture::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FCanvasTexture::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) { bNeedsUpdate = true; if (Canvas == NULL) { - MakeTexture (); + MakeTexture (style); } if ((unsigned)column >= (unsigned)Width) { @@ -90,12 +90,12 @@ const uint8_t *FCanvasTexture::GetColumn(unsigned int column, const Span **spans return Pixels + column*Height; } -const uint8_t *FCanvasTexture::GetPixels () +const uint8_t *FCanvasTexture::GetPixels (FRenderStyle style) { bNeedsUpdate = true; if (Canvas == NULL) { - MakeTexture (); + MakeTexture (style); } return Pixels; } @@ -110,7 +110,7 @@ const uint32_t *FCanvasTexture::GetPixelsBgra() return PixelsBgra; } -void FCanvasTexture::MakeTexture () +void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style because making it work as alpha texture is impractical. { Canvas = new DSimpleCanvas (Width, Height, false); Canvas->Lock (); @@ -183,7 +183,7 @@ void FCanvasTexture::Unload () FTexture::Unload(); } -bool FCanvasTexture::CheckModified () +bool FCanvasTexture::CheckModified (FRenderStyle) { if (bDidUpdate) { diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index e2bf932e9f..8571f820be 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -195,11 +195,17 @@ protected: int NumParts; TexPart *Parts; TexInit *Inits; - bool bRedirect:1; - bool bTranslucentPatches:1; + bool bRedirect; + bool bTranslucentPatches; uint8_t *MakeTexture (FRenderStyle style); + // The getters must optionally redirect if it's a simple one-patch texture. + const uint8_t *GetPixels(FRenderStyle style) override { return bRedirect ? Parts->Texture->GetPixels(style) : FWorldTexture::GetPixels(style); } + const uint8_t *GetColumn(FRenderStyle style, unsigned int col, const Span **out) override + { return bRedirect ? Parts->Texture->GetColumn(style, col, out) : FWorldTexture::GetColumn(style, col, out); } + + private: void CheckForHacks (); void ParsePatch(FScanner &sc, TexPart & part, TexInit &init); diff --git a/src/textures/skyboxtexture.cpp b/src/textures/skyboxtexture.cpp index 7f19e7f855..5270af9374 100644 --- a/src/textures/skyboxtexture.cpp +++ b/src/textures/skyboxtexture.cpp @@ -59,9 +59,9 @@ FSkyBox::~FSkyBox() // //----------------------------------------------------------------------------- -const uint8_t *FSkyBox::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FSkyBox::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) { - if (faces[0]) return faces[0]->GetColumn(column, spans_out); + if (faces[0]) return faces[0]->GetColumn(style, column, spans_out); return NULL; } @@ -71,9 +71,9 @@ const uint8_t *FSkyBox::GetColumn(unsigned int column, const Span **spans_out) // //----------------------------------------------------------------------------- -const uint8_t *FSkyBox::GetPixels () +const uint8_t *FSkyBox::GetPixels (FRenderStyle style) { - if (faces[0]) return faces[0]->GetPixels(); + if (faces[0]) return faces[0]->GetPixels(style); return NULL; } diff --git a/src/textures/skyboxtexture.h b/src/textures/skyboxtexture.h index 74fc68bbef..a6048ce583 100644 --- a/src/textures/skyboxtexture.h +++ b/src/textures/skyboxtexture.h @@ -17,8 +17,8 @@ public: FSkyBox(); ~FSkyBox(); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf); bool UseBasePalette(); void Unload (); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index c81b691c42..2b6ec321c7 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -183,19 +183,20 @@ void FTexture::Unload() const uint32_t *FTexture::GetColumnBgra(unsigned int column, const Span **spans_out) { const uint32_t *pixels = GetPixelsBgra(); + if (pixels == nullptr) return nullptr; column %= Width; if (spans_out != nullptr) - GetColumn(column, spans_out); + GetColumn(DefaultRenderStyle(), column, spans_out); // This isn't the right way to create the spans. return pixels + column * Height; } const uint32_t *FTexture::GetPixelsBgra() { - if (PixelsBgra.empty() || CheckModified()) + if (PixelsBgra.empty() || CheckModified(DefaultRenderStyle())) { - if (!GetColumn(0, nullptr)) + if (!GetColumn(DefaultRenderStyle(), 0, nullptr)) return nullptr; FBitmap bitmap; @@ -206,7 +207,7 @@ const uint32_t *FTexture::GetPixelsBgra() return PixelsBgra.data(); } -bool FTexture::CheckModified () +bool FTexture::CheckModified (FRenderStyle) { return false; } @@ -282,6 +283,7 @@ FTexture::Span **FTexture::CreateSpans (const uint8_t *pixels) const newspan = true; for (y = numrows; y > 0; --y) { + if (*data_p++ == 0) { if (!newspan) @@ -552,7 +554,7 @@ void FTexture::GenerateBgraMipmapsFast() void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation, FRenderStyle style) { - const uint8_t *pixels = GetPixels(/*style*/); + const uint8_t *pixels = GetPixels(style); int srcwidth = Width; int srcheight = Height; int step_x = Height; @@ -720,7 +722,7 @@ FNativeTexture *FTexture::GetNative(bool wrapping) } else { - if (CheckModified()) + if (CheckModified(DefaultRenderStyle())) { Native->Update(); } @@ -740,12 +742,6 @@ void FTexture::KillNative() } } -// For this generic implementation, we just call GetPixels and copy that data -// to the buffer. Texture formats that can do better than paletted images -// should provide their own implementation that may preserve the original -// color data. Note that the buffer expects row-major data, since that's -// generally more convenient for any non-Doom image formats, and it doesn't -// need to be used by any of Doom's column drawing routines. void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat fmt) { const uint8_t *pix; @@ -758,7 +754,7 @@ void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat f { case TEX_Pal: case TEX_Gray: - pix = GetPixels(); + pix = GetPixels(DefaultRenderStyle()); stride = pitch - w; for (y = 0; y < h; ++y) { @@ -802,14 +798,14 @@ int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyI { PalEntry *palette = screen->GetPalette(); for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values - bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette, inf); + bmp->CopyPixelData(x, y, GetPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, palette, inf); for(int i=1;i<256;i++) palette[i].a = 0; return 0; } int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf) { - bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, remap, inf); + bmp->CopyPixelData(x, y, GetPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, remap, inf); return 0; } @@ -920,7 +916,7 @@ int FTexture::CheckRealHeight() for (int i = 0; i < GetWidth(); ++i) { - GetColumn(i, &span); + GetColumn(DefaultRenderStyle(), i, &span); while (span->Length != 0) { if (span->TopOffset < miny) @@ -960,8 +956,13 @@ void FDummyTexture::SetSize (int width, int height) CalcBitSize (); } -// This must never be called -uint8_t *FDummyTexture::MakeTexture (FRenderStyle) +// These only get called from the texture precacher which discards the result. +const uint8_t *FDummyTexture::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) +{ + return nullptr; +} + +const uint8_t *FDummyTexture::GetPixels(FRenderStyle style) { return nullptr; } @@ -990,7 +991,7 @@ CCMD (printspans) { const FTexture::Span *spans; Printf ("%4d:", x); - tex->GetColumn(x, &spans); + tex->GetColumn(DefaultRenderStyle(), x, &spans); while (spans->Length != 0) { Printf (" (%4d,%4d)", spans->TopOffset, spans->TopOffset+spans->Length-1); diff --git a/src/textures/textures.h b/src/textures/textures.h index 17cef6e1cb..3b517ddf1e 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -226,15 +226,15 @@ public: }; // Returns a single column of the texture - virtual const uint8_t *GetColumn(unsigned int column, const Span **spans_out) = 0;// delete; - //virtual const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) = 0; + virtual const uint8_t *GetColumn(unsigned int column, const Span **spans_out) = delete; + virtual const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) = 0; // Returns a single column of the texture, in BGRA8 format virtual const uint32_t *GetColumnBgra(unsigned int column, const Span **spans_out); // Returns the whole texture, stored in column-major order - virtual const uint8_t *GetPixels() = 0;// delete; - //virtual const uint8_t *GetPixels(FRenderStyle style) = 0; + virtual const uint8_t *GetPixels() = delete; + virtual const uint8_t *GetPixels(FRenderStyle style) = 0; // Returns the whole texture, stored in column-major order, in BGRA8 format virtual const uint32_t *GetPixelsBgra(); @@ -285,7 +285,7 @@ public: // Returns true if the next call to GetPixels() will return an image different from the // last call to GetPixels(). This should be considered valid only if a call to CheckModified() // is immediately followed by a call to GetPixels(). - virtual bool CheckModified (); + virtual bool CheckModified (FRenderStyle style); static void InitGrayMap(); @@ -592,52 +592,50 @@ protected: FWorldTexture(const char *name = nullptr, int lumpnum = -1); ~FWorldTexture(); - // These should not be overridden. If that is needed, a class should inherit from something else - const uint8_t *GetColumn(unsigned int column, const Span **spans_out) override final; - const uint8_t *GetPixels() override final; - void Unload() override final; // should be removed after refactoring. + + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) override; + const uint8_t *GetPixels(FRenderStyle style) override; + void Unload() override; virtual void MakeTexture() = delete; virtual uint8_t *MakeTexture(FRenderStyle style) = 0; + void FreeAllSpans(); }; // A texture that doesn't really exist -class FDummyTexture : public FWorldTexture +class FDummyTexture : public FTexture { public: FDummyTexture (); - uint8_t *MakeTexture(FRenderStyle); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) override; + const uint8_t *GetPixels(FRenderStyle style) override; void SetSize (int width, int height); }; // A texture that returns a wiggly version of another texture. -class FWarpTexture : public FTexture +class FWarpTexture : public FWorldTexture { public: FWarpTexture (FTexture *source, int warptype); ~FWarpTexture (); + void Unload() override; - virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL) override; const uint32_t *GetPixelsBgra() override; - void Unload (); - bool CheckModified (); + bool CheckModified (FRenderStyle) override; float GetSpeed() const { return Speed; } int GetSourceLump() { return SourcePic->GetSourceLump(); } void SetSpeed(float fac) { Speed = fac; } FTexture *GetRedirect(bool wantwarped); - uint64_t GenTime; - uint64_t GenTimeBgra; - float Speed; + uint64_t GenTime[2] = { 0, 0 }; + uint64_t GenTimeBgra = 0; + float Speed = 1.f; int WidthOffsetMultiplier, HeightOffsetMultiplier; // [mxd] protected: FTexture *SourcePic; - uint8_t *Pixels; - Span **Spans; - virtual void MakeTexture (uint64_t time); + uint8_t *MakeTexture (FRenderStyle style) override; int NextPo2 (int v); // [mxd] void SetupMultipliers (int width, int height); // [mxd] }; @@ -652,17 +650,17 @@ public: FCanvasTexture (const char *name, int width, int height); ~FCanvasTexture (); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); const uint32_t *GetPixelsBgra() override; void Unload (); - bool CheckModified (); + bool CheckModified (FRenderStyle) override; void NeedUpdate() { bNeedsUpdate=true; } void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; } DSimpleCanvas *GetCanvas() { return Canvas; } DSimpleCanvas *GetCanvasBgra() { return CanvasBgra; } bool Mipmapped() override { return false; } - void MakeTexture (); + void MakeTexture (FRenderStyle style); void MakeTextureBgra (); protected: diff --git a/src/textures/warptexture.cpp b/src/textures/warptexture.cpp index 41920849d0..d78bc52498 100644 --- a/src/textures/warptexture.cpp +++ b/src/textures/warptexture.cpp @@ -44,7 +44,7 @@ FWarpTexture::FWarpTexture (FTexture *source, int warptype) -: GenTime (0), GenTimeBgra(0), Speed (1.f), SourcePic (source), Pixels (0), Spans (0) + : SourcePic (source) { CopyInfo(source); if (warptype == 2) SetupMultipliers(256, 128); @@ -55,53 +55,25 @@ FWarpTexture::FWarpTexture (FTexture *source, int warptype) FWarpTexture::~FWarpTexture () { Unload (); - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } delete SourcePic; } void FWarpTexture::Unload () { - if (Pixels != NULL) - { - delete[] Pixels; - Pixels = NULL; - } - if (Spans != NULL) - { - FreeSpans (Spans); - Spans = NULL; - } SourcePic->Unload (); - FTexture::Unload(); + FWorldTexture::Unload(); + FreeAllSpans(); } -bool FWarpTexture::CheckModified () +bool FWarpTexture::CheckModified (FRenderStyle style) { - return screen->FrameTime != GenTime; -} - -const uint8_t *FWarpTexture::GetPixels () -{ - uint64_t time = screen->FrameTime; - - if (Pixels == NULL || time != GenTime) - { - MakeTexture (time); - } - return Pixels; + return screen->FrameTime != GenTime[!!(style.Flags & STYLEF_RedIsAlpha)]; } const uint32_t *FWarpTexture::GetPixelsBgra() { - uint64_t time = screen->FrameTime; - if (Pixels == NULL || time != GenTime) - MakeTexture(time); - - if (PixelsBgra.empty() || time != GenTimeBgra) + auto Pixels = GetPixels(DefaultRenderStyle()); + if (PixelsBgra.empty() || GenTime[0] != GenTimeBgra) { CreatePixelsBgraWithMipmaps(); for (int i = 0; i < Width * Height; i++) @@ -112,58 +84,21 @@ const uint32_t *FWarpTexture::GetPixelsBgra() PixelsBgra[i] = 0; } GenerateBgraMipmapsFast(); - GenTimeBgra = time; + GenTimeBgra = GenTime[0]; } return PixelsBgra.data(); } -const uint8_t *FWarpTexture::GetColumn(unsigned int column, const Span **spans_out) + +uint8_t *FWarpTexture::MakeTexture(FRenderStyle style) { - uint64_t time =screen->FrameTime; - - if (Pixels == NULL || time != GenTime) - { - MakeTexture (time); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - if (Spans == NULL) - { - Spans = CreateSpans (Pixels); - } - *spans_out = Spans[column]; - } - return Pixels + column*Height; -} - - -void FWarpTexture::MakeTexture(uint64_t time) -{ - const uint8_t *otherpix = SourcePic->GetPixels(); - - if (Pixels == NULL) - { - Pixels = new uint8_t[Width * Height]; - } - if (Spans != NULL) - { - FreeSpans(Spans); - Spans = NULL; - } - - GenTime = time; + uint64_t time = screen->FrameTime; + const uint8_t *otherpix = SourcePic->GetPixels(style); + auto Pixels = new uint8_t[Width * Height]; WarpBuffer(Pixels, otherpix, Width, Height, WidthOffsetMultiplier, HeightOffsetMultiplier, time, Speed, bWarped); + FreeAllSpans(); + GenTime[!!(style.Flags & STYLEF_RedIsAlpha)] = time; + return Pixels; } // [mxd] Non power of 2 textures need different offset multipliers, otherwise warp animation won't sync across texture diff --git a/src/textures/worldtexture.cpp b/src/textures/worldtexture.cpp index 8968902360..db50c7fb4b 100644 --- a/src/textures/worldtexture.cpp +++ b/src/textures/worldtexture.cpp @@ -56,6 +56,17 @@ FWorldTexture::FWorldTexture(const char *name, int lumpnum) FWorldTexture::~FWorldTexture() { Unload(); + FreeAllSpans(); +} + +//========================================================================== +// +// +// +//========================================================================== + +void FWorldTexture::FreeAllSpans() +{ for(int i = 0; i < 2; i++) { if (Spandata[i] != nullptr) @@ -91,9 +102,10 @@ void FWorldTexture::Unload () // //========================================================================== -const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FWorldTexture::GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out) { - GetPixels(); + int index = !!(style.Flags & STYLEF_RedIsAlpha); + GetPixels(style); if ((unsigned)column >= (unsigned)Width) { if (WidthMask + 1 == Width) @@ -107,13 +119,13 @@ const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_ } if (spans_out != nullptr) { - if (Spandata[0] == nullptr) + if (Spandata[index] == nullptr) { - Spandata[0] = CreateSpans (Pixeldata[0]); + Spandata[index] = CreateSpans (Pixeldata[index]); } - *spans_out = Spandata[0][column]; + *spans_out = Spandata[index][column]; } - return Pixeldata[0] + column*Height; + return Pixeldata[index] + column*Height; } //========================================================================== @@ -122,16 +134,17 @@ const uint8_t *FWorldTexture::GetColumn(unsigned int column, const Span **spans_ // //========================================================================== -const uint8_t *FWorldTexture::GetPixels () +const uint8_t *FWorldTexture::GetPixels (FRenderStyle style) { - if (CheckModified()) + if (CheckModified(style)) { Unload(); } - if (Pixeldata[0] == nullptr) + int index = !!(style.Flags & STYLEF_RedIsAlpha); + if (Pixeldata[index] == nullptr) { - Pixeldata[0] = MakeTexture (LegacyRenderStyles[STYLE_Normal]); + Pixeldata[index] = MakeTexture (style); } - return Pixeldata[0]; + return Pixeldata[index]; } diff --git a/src/v_font.cpp b/src/v_font.cpp index 1b36c22191..e38ecfbdee 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -177,8 +177,8 @@ class FFontChar1 : public FTexture { public: FFontChar1 (FTexture *sourcelump); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); ~FFontChar1 (); @@ -198,8 +198,8 @@ public: FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0); ~FFontChar2 (); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels (); + const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const Span **spans_out); + const uint8_t *GetPixels (FRenderStyle style); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); @@ -559,7 +559,7 @@ void RecordTextureColors (FTexture *pic, uint8_t *usedcolors) for (x = pic->GetWidth() - 1; x >= 0; x--) { const FTexture::Span *spans; - const uint8_t *column = pic->GetColumn(x, &spans); + const uint8_t *column = pic->GetColumn(DefaultRenderStyle(), x, &spans); // This shouldn't use the spans... while (spans->Length != 0) { @@ -1649,9 +1649,11 @@ FFontChar1::FFontChar1 (FTexture *sourcelump) // // FFontChar1 :: GetPixels // +// Render style is not relevant for fonts. This must not use it! +// //========================================================================== -const uint8_t *FFontChar1::GetPixels () +const uint8_t *FFontChar1::GetPixels (FRenderStyle) { if (Pixels == NULL) { @@ -1666,12 +1668,12 @@ const uint8_t *FFontChar1::GetPixels () // //========================================================================== -void FFontChar1::MakeTexture () +void FFontChar1::MakeTexture () { // Make the texture as normal, then remap it so that all the colors // are at the low end of the palette Pixels = new uint8_t[Width*Height]; - const uint8_t *pix = BaseTexture->GetPixels(); + const uint8_t *pix = BaseTexture->GetPixels(DefaultRenderStyle()); if (!SourceRemap) { @@ -1692,14 +1694,14 @@ void FFontChar1::MakeTexture () // //========================================================================== -const uint8_t *FFontChar1::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FFontChar1::GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) { if (Pixels == NULL) { MakeTexture (); } - BaseTexture->GetColumn(column, spans_out); + BaseTexture->GetColumn(DefaultRenderStyle(), column, spans_out); return Pixels + column*Height; } @@ -1797,9 +1799,11 @@ void FFontChar2::Unload () // // FFontChar2 :: GetPixels // +// Like for FontChar1, the render style has no relevance here as well. +// //========================================================================== -const uint8_t *FFontChar2::GetPixels () +const uint8_t *FFontChar2::GetPixels (FRenderStyle) { if (Pixels == NULL) { @@ -1814,7 +1818,7 @@ const uint8_t *FFontChar2::GetPixels () // //========================================================================== -const uint8_t *FFontChar2::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FFontChar2::GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) { if (Pixels == NULL) { diff --git a/src/v_video.cpp b/src/v_video.cpp index 77f83b285d..5e86b915bc 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -135,9 +135,9 @@ class FPaletteTester : public FTexture public: FPaletteTester (); - const uint8_t *GetColumn(unsigned int column, const Span **spans_out); - const uint8_t *GetPixels(); - bool CheckModified(); + const uint8_t *GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) override; + const uint8_t *GetPixels(FRenderStyle); + bool CheckModified(FRenderStyle); void SetTranslation(int num); protected: @@ -983,7 +983,7 @@ FPaletteTester::FPaletteTester() // //========================================================================== -bool FPaletteTester::CheckModified() +bool FPaletteTester::CheckModified(FRenderStyle) { return CurTranslation != WantTranslation; } @@ -1008,7 +1008,7 @@ void FPaletteTester::SetTranslation(int num) // //========================================================================== -const uint8_t *FPaletteTester::GetColumn(unsigned int column, const Span **spans_out) +const uint8_t *FPaletteTester::GetColumn(FRenderStyle, unsigned int column, const Span **spans_out) { if (CurTranslation != WantTranslation) { @@ -1028,7 +1028,7 @@ const uint8_t *FPaletteTester::GetColumn(unsigned int column, const Span **spans // //========================================================================== -const uint8_t *FPaletteTester::GetPixels () +const uint8_t *FPaletteTester::GetPixels (FRenderStyle) { if (CurTranslation != WantTranslation) {