diff --git a/src/d_main.cpp b/src/d_main.cpp index 3568a1930..9af1039fe 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2729,7 +2729,6 @@ void D_DoomMain (void) // These calls from inside V_Init2 are still necessary C_NewModeAdjust(); M_InitVideoModesMenu(); - Renderer->RemapVoxels(); D_StartTitle (); // start up intro loop setmodeneeded = false; // This may be set to true here, but isn't needed for a restart } diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index fe58c398f..6b9e26d2e 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -306,7 +306,7 @@ void FVoxelModel::Initialize() FVoxelMipLevel *mip = &mVoxel->Mips[0]; for (int x = 0; x < mip->SizeX; x++) { - uint8_t *slabxoffs = &mip->SlabData[mip->OffsetX[x]]; + uint8_t *slabxoffs = &mip->GetSlabData(false)[mip->OffsetX[x]]; short *xyoffs = &mip->OffsetXY[x * (mip->SizeY + 1)]; for (int y = 0; y < mip->SizeY; y++) { diff --git a/src/r_data/voxels.cpp b/src/r_data/voxels.cpp index e9a9b89fc..2bef1a0b4 100644 --- a/src/r_data/voxels.cpp +++ b/src/r_data/voxels.cpp @@ -386,6 +386,18 @@ FVoxelMipLevel::~FVoxelMipLevel() } } +//========================================================================== +// +// FVoxelMipLevel :: GetSlabData +// +//========================================================================== + +uint8_t *FVoxelMipLevel::GetSlabData(bool wantremapped) const +{ + if (wantremapped && SlabDataRemapped.Size() > 0) return &SlabDataRemapped[0]; + return SlabData; +} + //========================================================================== // // FVoxel Constructor @@ -410,6 +422,8 @@ FVoxel::~FVoxel() void FVoxel::CreateBgraSlabData() { + if (Bgramade) return; + Bgramade = true; for (int i = 0; i < NumMips; ++i) { int size = Mips[i].OffsetX[Mips[i].SizeX]; @@ -464,14 +478,20 @@ void FVoxel::CreateBgraSlabData() void FVoxel::Remap() { + if (Remapped) return; + Remapped = true; if (Palette != NULL) { uint8_t *remap = GetVoxelRemap(Palette); for (int i = 0; i < NumMips; ++i) { - RemapVoxelSlabs((kvxslab_t *)Mips[i].SlabData, Mips[i].OffsetX[Mips[i].SizeX], remap); + int size = Mips[i].OffsetX[Mips[i].SizeX]; + if (size <= 0) continue; + + Mips[i].SlabDataRemapped.Resize(size); + memcpy(&Mips[i].SlabDataRemapped [0], Mips[i].SlabData, size); + RemapVoxelSlabs((kvxslab_t *)&Mips[i].SlabDataRemapped[0], Mips[i].OffsetX[Mips[i].SizeX], remap); } - RemovePalette(); } } diff --git a/src/r_data/voxels.h b/src/r_data/voxels.h index 57ae41a1f..eac1b39ee 100644 --- a/src/r_data/voxels.h +++ b/src/r_data/voxels.h @@ -23,6 +23,8 @@ struct kvxslab_bgra_t uint32_t col[1/*zleng*/];// color data from top to bottom }; +struct FVoxel; + struct FVoxelMipLevel { FVoxelMipLevel(); @@ -34,17 +36,27 @@ struct FVoxelMipLevel DVector3 Pivot; int *OffsetX; short *OffsetXY; - uint8_t *SlabData; +private: + uint8_t *SlabData; + TArray SlabDataRemapped; +public: TArray SlabDataBgra; + + uint8_t *GetSlabData(bool wantpaletted) const; + + friend FVoxel *R_LoadKVX(int lumpnum); + friend struct FVoxel; }; struct FVoxel { int LumpNum; int NumMips; - int VoxelIndex; // Needed by GZDoom + int VoxelIndex; uint8_t *Palette; FVoxelMipLevel Mips[MAXVOXMIPS]; + bool Remapped = false; + bool Bgramade = false; FVoxel(); ~FVoxel(); diff --git a/src/r_renderer.h b/src/r_renderer.h index d8426d221..7e70a1bbf 100644 --- a/src/r_renderer.h +++ b/src/r_renderer.h @@ -31,9 +31,6 @@ struct FRenderer // render 3D view virtual void RenderView(player_t *player) = 0; - // Remap voxel palette - virtual void RemapVoxels() {} - // renders view to a savegame picture virtual void WriteSavePic (player_t *player, FileWriter *file, int width, int height) = 0; diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 5a400e4ca..1d640c9d8 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -188,15 +188,6 @@ void FSoftwareRenderer::RenderView(player_t *player) FCanvasTextureInfo::UpdateAll(); } -void FSoftwareRenderer::RemapVoxels() -{ - for (unsigned i=0; iCreateBgraSlabData(); - Voxels[i]->Remap(); - } -} - void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { DCanvas *pic = new DSimpleCanvas (width, height, false); diff --git a/src/swrenderer/r_swrenderer.h b/src/swrenderer/r_swrenderer.h index 32bcdcc39..7f01b2d2c 100644 --- a/src/swrenderer/r_swrenderer.h +++ b/src/swrenderer/r_swrenderer.h @@ -15,9 +15,6 @@ struct FSoftwareRenderer : public FRenderer // render 3D view void RenderView(player_t *player) override; - // Remap voxel palette - void RemapVoxels() override; - // renders view to a savegame picture void WriteSavePic (player_t *player, FileWriter *file, int width, int height) override; diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index a3c12a865..f10840c09 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -338,7 +338,7 @@ namespace swrenderer } if (k >= voxobj->NumMips) k = voxobj->NumMips - 1; - mip = &voxobj->Mips[k]; if (mip->SlabData == NULL) return; + mip = &voxobj->Mips[k]; if (mip->GetSlabData(false) == NULL) return; minslabz >>= k; maxslabz >>= k; @@ -391,6 +391,8 @@ namespace swrenderer yoff = (abs(gxinc) + abs(gyinc)) >> 1; bool useSlabDataBgra = !drawerargs.DrawerNeedsPalInput() && viewport->RenderTarget->IsBgra(); + if (!useSlabDataBgra) voxobj->Remap(); + else voxobj->CreateBgraSlabData(); int coverageX1 = this->x2; int coverageX2 = this->x1; @@ -462,7 +464,8 @@ namespace swrenderer for (x = xs; x != xe; x += xi) { - uint8_t *slabxoffs = &mip->SlabData[mip->OffsetX[x]]; + auto SlabData = mip->GetSlabData(true); + uint8_t *slabxoffs = &SlabData[mip->OffsetX[x]]; short *xyoffs = &mip->OffsetXY[x * (mip->SizeY + 1)]; nx = FixedMul(ggxstart + ggxinc[x], viewport->viewingrangerecip) + x1; @@ -588,7 +591,7 @@ namespace swrenderer // // We can find the same slab column by calculating the offset from the start of SlabData // and use that to offset into the BGRA version of the same data. - columnColors = (const uint8_t *)(&mip->SlabDataBgra[0] + (ptrdiff_t)(col - mip->SlabData)); + columnColors = (const uint8_t *)(&mip->SlabDataBgra[0] + (ptrdiff_t)(col - SlabData)); } // Find top and bottom pixels that match and draw them as one strip @@ -687,7 +690,7 @@ namespace swrenderer kvxslab_t *RenderVoxel::GetSlabStart(const FVoxelMipLevel &mip, int x, int y) { - return (kvxslab_t *)&mip.SlabData[mip.OffsetX[x] + (int)mip.OffsetXY[x * (mip.SizeY + 1) + y]]; + return (kvxslab_t *)&mip.GetSlabData(true)[mip.OffsetX[x] + (int)mip.OffsetXY[x * (mip.SizeY + 1) + y]]; } kvxslab_t *RenderVoxel::GetSlabEnd(const FVoxelMipLevel &mip, int x, int y) diff --git a/src/v_video.cpp b/src/v_video.cpp index 9247807d0..465bcd18d 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1249,7 +1249,6 @@ void V_Init2() Printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT); screen->SetGamma (gamma); - Renderer->RemapVoxels(); FBaseCVar::ResetColors (); C_NewModeAdjust(); M_InitVideoModesMenu();