From b32aa60760a7108e2b135807995a7545e90a1bf2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 10 Dec 2018 02:43:37 +0100 Subject: [PATCH] Made SWPaletteTexture an ImageSource and let it be managed by the texture manager. This is a lot easier to manage because the palette is just static data that can easily mimic an image. --- src/swrenderer/r_swscene.cpp | 23 +++++++++++++---------- src/swrenderer/r_swscene.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/swrenderer/r_swscene.cpp b/src/swrenderer/r_swscene.cpp index 177efb711..88a5417b6 100644 --- a/src/swrenderer/r_swscene.cpp +++ b/src/swrenderer/r_swscene.cpp @@ -33,6 +33,7 @@ #include "d_player.h" #include "textures/bitmap.h" #include "swrenderer/scene/r_light.h" +#include "image.h" // [RH] Base blending values (for e.g. underwater) int BaseBlendR, BaseBlendG, BaseBlendB; @@ -41,27 +42,23 @@ void InitSoftwareSky(); -class FSWPaletteTexture : public FTexture +class FSWPaletteTexture : public FImageSource { public: FSWPaletteTexture() { Width = 256; Height = 1; - UseType = ETextureType::MiscPatch; } - FBitmap GetBgraBitmap(PalEntry *, int *trans) override + int CopyPixels(FBitmap *bmp, int conversion) override { - FBitmap bmp; - bmp.Create(256, 1); - PalEntry *pe = (PalEntry*)bmp.GetPixels(); + PalEntry *pe = (PalEntry*)bmp->GetPixels(); for (int i = 0; i < 256; i++) { pe[i] = GPalette.BaseColors[i].d | 0xff000000; } - if (trans) *trans = 0; - return bmp; + return 0; } }; @@ -74,7 +71,13 @@ public: SWSceneDrawer::SWSceneDrawer() { - PaletteTexture.reset(new FSWPaletteTexture); + auto texid = TexMan.CheckForTexture("@@palette@@", ETextureType::Any); + if (!texid.Exists()) + { + auto tex = new FImageTexture(new FSWPaletteTexture, "@@palette@@"); + texid = TexMan.AddTexture(tex); + } + PaletteTexture = TexMan.GetTexture(texid); } SWSceneDrawer::~SWSceneDrawer() @@ -98,7 +101,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); fbtex->GetSystemTexture(0)->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); auto mat = FMaterial::ValidateTexture(fbtex.get(), false); - mat->AddTextureLayer(PaletteTexture.get()); + mat->AddTextureLayer(PaletteTexture); Canvas.reset(); Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); diff --git a/src/swrenderer/r_swscene.h b/src/swrenderer/r_swscene.h index 47757a334..7dc12488d 100644 --- a/src/swrenderer/r_swscene.h +++ b/src/swrenderer/r_swscene.h @@ -12,7 +12,7 @@ class FWrapperTexture; class SWSceneDrawer { - std::unique_ptr PaletteTexture; + FTexture *PaletteTexture; std::unique_ptr FBTexture[2]; int FBTextureIndex = 0; bool FBIsTruecolor = false;