Fix cameras and kdizd intro for true color mode

This commit is contained in:
Magnus Norddahl 2016-06-13 03:16:48 +02:00
parent 0f0859b0b2
commit cc10c2a970
5 changed files with 126 additions and 16 deletions

View file

@ -974,6 +974,8 @@ void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas,
R_RenderActorView (actor, dontmaplines); R_RenderActorView (actor, dontmaplines);
R_EndDrawerCommands();
RenderTarget = screen; RenderTarget = screen;
bRenderingToCanvas = false; bRenderingToCanvas = false;
R_ExecuteSetViewSize (); R_ExecuteSetViewSize ();
@ -981,8 +983,6 @@ void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas,
R_SetupBuffer (); R_SetupBuffer ();
screen->Unlock (); screen->Unlock ();
R_EndDrawerCommands();
viewactive = savedviewactive; viewactive = savedviewactive;
r_swtruecolor = savedoutputformat; r_swtruecolor = savedoutputformat;

View file

@ -87,11 +87,17 @@ void FSoftwareRenderer::PrecacheTexture(FTexture *tex, int cache)
if (cache & FTextureManager::HIT_Columnmode) if (cache & FTextureManager::HIT_Columnmode)
{ {
const FTexture::Span *spanp; const FTexture::Span *spanp;
tex->GetColumn(0, &spanp); /*if (r_swtruecolor)
tex->GetColumnBgra(0, &spanp);
else*/
tex->GetColumn(0, &spanp);
} }
else if (cache != 0) else if (cache != 0)
{ {
tex->GetPixels (); if (r_swtruecolor)
tex->GetPixels();
else
tex->GetPixels ();
} }
else else
{ {
@ -328,8 +334,8 @@ void FSoftwareRenderer::CopyStackedViewParameters()
void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov)
{ {
BYTE *Pixels = const_cast<BYTE*>(tex->GetPixels()); BYTE *Pixels = r_swtruecolor ? (BYTE*)tex->GetPixelsBgra() : (BYTE*)tex->GetPixels();
DSimpleCanvas *Canvas = tex->GetCanvas(); DSimpleCanvas *Canvas = r_swtruecolor ? tex->GetCanvasBgra() : tex->GetCanvas();
// curse Doom's overuse of global variables in the renderer. // 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. // 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.
@ -340,13 +346,28 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin
R_SetFOV ((double)fov); R_SetFOV ((double)fov);
R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate);
R_SetFOV (savedfov); R_SetFOV (savedfov);
if (Pixels == Canvas->GetBuffer())
if (Canvas->IsBgra())
{ {
FTexture::FlipSquareBlockRemap (Pixels, tex->GetWidth(), tex->GetHeight(), GPalette.Remap); if (Pixels == Canvas->GetBuffer())
{
FTexture::FlipSquareBlockBgra((uint32_t*)Pixels, tex->GetWidth(), tex->GetHeight());
}
else
{
FTexture::FlipNonSquareBlockBgra((uint32_t*)Pixels, (const uint32_t*)Canvas->GetBuffer(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch());
}
} }
else else
{ {
FTexture::FlipNonSquareBlockRemap (Pixels, Canvas->GetBuffer(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch(), GPalette.Remap); if (Pixels == Canvas->GetBuffer())
{
FTexture::FlipSquareBlockRemap(Pixels, tex->GetWidth(), tex->GetHeight(), GPalette.Remap);
}
else
{
FTexture::FlipNonSquareBlockRemap(Pixels, Canvas->GetBuffer(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch(), GPalette.Remap);
}
} }
tex->SetUpdated(); tex->SetUpdated();
fixedcolormap = savecolormap; fixedcolormap = savecolormap;

View file

@ -53,7 +53,6 @@ FCanvasTexture::FCanvasTexture (const char *name, int width, int height)
DummySpans[1].TopOffset = 0; DummySpans[1].TopOffset = 0;
DummySpans[1].Length = 0; DummySpans[1].Length = 0;
UseType = TEX_Wall; UseType = TEX_Wall;
Canvas = NULL;
bNeedsUpdate = true; bNeedsUpdate = true;
bDidUpdate = false; bDidUpdate = false;
bHasCanvas = true; bHasCanvas = true;
@ -101,6 +100,16 @@ const BYTE *FCanvasTexture::GetPixels ()
return Pixels; return Pixels;
} }
const uint32_t *FCanvasTexture::GetPixelsBgra()
{
bNeedsUpdate = true;
if (CanvasBgra == NULL)
{
MakeTextureBgra();
}
return PixelsBgra;
}
void FCanvasTexture::MakeTexture () void FCanvasTexture::MakeTexture ()
{ {
Canvas = new DSimpleCanvas (Width, Height, false); Canvas = new DSimpleCanvas (Width, Height, false);
@ -123,21 +132,57 @@ void FCanvasTexture::MakeTexture ()
memset (Pixels+Width*Height/2, 255, Width*Height/2); memset (Pixels+Width*Height/2, 255, Width*Height/2);
} }
void FCanvasTexture::MakeTextureBgra()
{
CanvasBgra = new DSimpleCanvas(Width, Height, true);
CanvasBgra->Lock();
GC::AddSoftRoot(CanvasBgra);
if (Width != Height || Width != CanvasBgra->GetPitch())
{
PixelsBgra = new uint32_t[Width*Height];
bPixelsAllocatedBgra = true;
}
else
{
PixelsBgra = (uint32_t*)CanvasBgra->GetBuffer();
bPixelsAllocatedBgra = false;
}
// Draw a special "unrendered" initial texture into the buffer.
memset(PixelsBgra, 0, Width*Height / 2 * 4);
memset(PixelsBgra + Width*Height / 2, 255, Width*Height / 2 * 4);
}
void FCanvasTexture::Unload () void FCanvasTexture::Unload ()
{ {
if (bPixelsAllocated) if (bPixelsAllocated)
{ {
if (Pixels != NULL) delete [] Pixels; if (Pixels != NULL) delete[] Pixels;
bPixelsAllocated = false; bPixelsAllocated = false;
Pixels = NULL; Pixels = NULL;
} }
if (bPixelsAllocatedBgra)
{
if (PixelsBgra != NULL) delete[] PixelsBgra;
bPixelsAllocatedBgra = false;
PixelsBgra = NULL;
}
if (Canvas != NULL) if (Canvas != NULL)
{ {
GC::DelSoftRoot(Canvas); GC::DelSoftRoot(Canvas);
Canvas->Destroy(); Canvas->Destroy();
Canvas = NULL; Canvas = NULL;
} }
if (CanvasBgra != NULL)
{
GC::DelSoftRoot(CanvasBgra);
CanvasBgra->Destroy();
CanvasBgra = NULL;
}
} }
bool FCanvasTexture::CheckModified () bool FCanvasTexture::CheckModified ()

View file

@ -410,6 +410,29 @@ void FTexture::FlipSquareBlock (BYTE *block, int x, int y)
} }
} }
void FTexture::FlipSquareBlockBgra(uint32_t *block, int x, int y)
{
int i, j;
if (x != y) return;
for (i = 0; i < x; ++i)
{
uint32_t *corner = block + x*i + i;
int count = x - i;
if (count & 1)
{
count--;
swapvalues<uint32_t>(corner[count], corner[count*x]);
}
for (j = 0; j < count; j += 2)
{
swapvalues<uint32_t>(corner[j], corner[j*x]);
swapvalues<uint32_t>(corner[j + 1], corner[(j + 1)*x]);
}
}
}
void FTexture::FlipSquareBlockRemap (BYTE *block, int x, int y, const BYTE *remap) void FTexture::FlipSquareBlockRemap (BYTE *block, int x, int y, const BYTE *remap)
{ {
int i, j; int i, j;
@ -453,6 +476,19 @@ void FTexture::FlipNonSquareBlock (BYTE *dst, const BYTE *src, int x, int y, int
} }
} }
void FTexture::FlipNonSquareBlockBgra(uint32_t *dst, const uint32_t *src, int x, int y, int srcpitch)
{
int i, j;
for (i = 0; i < x; ++i)
{
for (j = 0; j < y; ++j)
{
dst[i*y + j] = src[i + j*srcpitch];
}
}
}
void FTexture::FlipNonSquareBlockRemap (BYTE *dst, const BYTE *src, int x, int y, int srcpitch, const BYTE *remap) void FTexture::FlipNonSquareBlockRemap (BYTE *dst, const BYTE *src, int x, int y, int srcpitch, const BYTE *remap)
{ {
int i, j; int i, j;

View file

@ -274,8 +274,10 @@ private:
public: public:
static void FlipSquareBlock (BYTE *block, int x, int y); static void FlipSquareBlock (BYTE *block, int x, int y);
static void FlipSquareBlockBgra (uint32_t *block, int x, int y);
static void FlipSquareBlockRemap (BYTE *block, int x, int y, const BYTE *remap); static void FlipSquareBlockRemap (BYTE *block, int x, int y, const BYTE *remap);
static void FlipNonSquareBlock (BYTE *blockto, const BYTE *blockfrom, int x, int y, int srcpitch); static void FlipNonSquareBlock (BYTE *blockto, const BYTE *blockfrom, int x, int y, int srcpitch);
static void FlipNonSquareBlockBgra (uint32_t *blockto, const uint32_t *blockfrom, int x, int y, int srcpitch);
static void FlipNonSquareBlockRemap (BYTE *blockto, const BYTE *blockfrom, int x, int y, int srcpitch, const BYTE *remap); static void FlipNonSquareBlockRemap (BYTE *blockto, const BYTE *blockfrom, int x, int y, int srcpitch, const BYTE *remap);
friend class D3DTex; friend class D3DTex;
@ -518,21 +520,27 @@ public:
const BYTE *GetColumn (unsigned int column, const Span **spans_out); const BYTE *GetColumn (unsigned int column, const Span **spans_out);
const BYTE *GetPixels (); const BYTE *GetPixels ();
const uint32_t *GetPixelsBgra() override;
void Unload (); void Unload ();
bool CheckModified (); bool CheckModified ();
void NeedUpdate() { bNeedsUpdate=true; } void NeedUpdate() { bNeedsUpdate=true; }
void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; } void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; }
DSimpleCanvas *GetCanvas() { return Canvas; } DSimpleCanvas *GetCanvas() { return Canvas; }
DSimpleCanvas *GetCanvasBgra() { return CanvasBgra; }
void MakeTexture (); void MakeTexture ();
void MakeTextureBgra ();
protected: protected:
DSimpleCanvas *Canvas; DSimpleCanvas *Canvas = nullptr;
BYTE *Pixels; DSimpleCanvas *CanvasBgra = nullptr;
BYTE *Pixels = nullptr;
uint32_t *PixelsBgra = nullptr;
Span DummySpans[2]; Span DummySpans[2];
bool bNeedsUpdate; bool bNeedsUpdate = true;
bool bDidUpdate; bool bDidUpdate = false;
bool bPixelsAllocated; bool bPixelsAllocated = false;
bool bPixelsAllocatedBgra = false;
public: public:
bool bFirstUpdate; bool bFirstUpdate;