mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 12:11:25 +00:00
- changed voxel remapping to make a copy instead of destroying the original.
With live renderer switching both sets of data are needed.
This commit is contained in:
parent
2f96d3c61a
commit
942460ba55
9 changed files with 44 additions and 26 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<uint8_t> SlabDataRemapped;
|
||||
public:
|
||||
TArray<uint32_t> 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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -188,15 +188,6 @@ void FSoftwareRenderer::RenderView(player_t *player)
|
|||
FCanvasTextureInfo::UpdateAll();
|
||||
}
|
||||
|
||||
void FSoftwareRenderer::RemapVoxels()
|
||||
{
|
||||
for (unsigned i=0; i<Voxels.Size(); i++)
|
||||
{
|
||||
Voxels[i]->CreateBgraSlabData();
|
||||
Voxels[i]->Remap();
|
||||
}
|
||||
}
|
||||
|
||||
void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height)
|
||||
{
|
||||
DCanvas *pic = new DSimpleCanvas (width, height, false);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue