- work on separating DFrameBuffer from DCanvas.

2D works in D3D backend, but 3D crashes because not all pointers have been rerouted yet.
This commit is contained in:
Christoph Oelckers 2018-03-27 13:50:31 +02:00
parent 377aa95e34
commit bb9283a9af
18 changed files with 84 additions and 149 deletions

View file

@ -174,10 +174,7 @@ OpenGLSWFrameBuffer::OpenGLSWFrameBuffer(void *hMonitor, int width, int height,
NeedGammaUpdate = false; NeedGammaUpdate = false;
NeedPalUpdate = false; NeedPalUpdate = false;
if (MemBuffer == nullptr) RenderBuffer = new DSimpleCanvas(Width, Height, bgra);
{
return;
}
memcpy(SourcePalette, GPalette.BaseColors, sizeof(PalEntry) * 256); memcpy(SourcePalette, GPalette.BaseColors, sizeof(PalEntry) * 256);
@ -780,7 +777,8 @@ void OpenGLSWFrameBuffer::Present()
void OpenGLSWFrameBuffer::SetInitialState() void OpenGLSWFrameBuffer::SetInitialState()
{ {
if (gl.es) UseMappedMemBuffer = false; //if (gl.es) re-enable later! First the basics must work.
UseMappedMemBuffer = false;
AlphaBlendEnabled = false; AlphaBlendEnabled = false;
AlphaBlendOp = GL_FUNC_ADD; AlphaBlendOp = GL_FUNC_ADD;
@ -1125,6 +1123,8 @@ bool OpenGLSWFrameBuffer::Lock(bool buffered)
} }
assert(!In2D); assert(!In2D);
Accel2D = vid_hw2d; Accel2D = vid_hw2d;
#if 0 // temporarily disabled. Must be fixed later
if (UseMappedMemBuffer) if (UseMappedMemBuffer)
{ {
if (!MappedMemBuffer) if (!MappedMemBuffer)
@ -1140,8 +1140,11 @@ bool OpenGLSWFrameBuffer::Lock(bool buffered)
Buffer = (uint8_t*)MappedMemBuffer; Buffer = (uint8_t*)MappedMemBuffer;
} }
else else
#endif
{ {
Buffer = MemBuffer; #if 0
//Buffer = MemBuffer;
#endif
} }
return false; return false;
} }
@ -1165,7 +1168,9 @@ void OpenGLSWFrameBuffer::Unlock()
} }
else if (--m_Lock == 0) else if (--m_Lock == 0)
{ {
#if 0
Buffer = nullptr; Buffer = nullptr;
#endif
if (MappedMemBuffer) if (MappedMemBuffer)
{ {
@ -1263,7 +1268,9 @@ void OpenGLSWFrameBuffer::Update()
//LOG1 ("cycles = %d\n", BlitCycles); //LOG1 ("cycles = %d\n", BlitCycles);
#endif #endif
#if 0
Buffer = nullptr; Buffer = nullptr;
#endif
UpdatePending = false; UpdatePending = false;
} }
@ -1286,7 +1293,7 @@ void OpenGLSWFrameBuffer::Flip()
int clientHeight = ViewportScaledHeight(GetClientWidth(), GetClientHeight()); int clientHeight = ViewportScaledHeight(GetClientWidth(), GetClientHeight());
if (clientWidth > 0 && clientHeight > 0 && (Width != clientWidth || Height != clientHeight)) if (clientWidth > 0 && clientHeight > 0 && (Width != clientWidth || Height != clientHeight))
{ {
Resize(clientWidth, clientHeight); RenderBuffer->Resize(clientWidth, clientHeight);
TrueHeight = Height; TrueHeight = Height;
PixelDoubling = 0; PixelDoubling = 0;
@ -1375,6 +1382,7 @@ void OpenGLSWFrameBuffer::Draw3DPart(bool copy3d)
int pixelsize = IsBgra() ? 4 : 1; int pixelsize = IsBgra() ? 4 : 1;
int size = Width * Height * pixelsize; int size = Width * Height * pixelsize;
auto MemBuffer = RenderBuffer->GetPixels();
uint8_t *dest = (uint8_t*)MapBuffer(GL_PIXEL_UNPACK_BUFFER, size); uint8_t *dest = (uint8_t*)MapBuffer(GL_PIXEL_UNPACK_BUFFER, size);
if (dest) if (dest)
{ {

View file

@ -24,6 +24,7 @@ class OpenGLSWFrameBuffer : public SDLGLFB
typedef SDLGLFB Super; //[C]commented, DECLARE_CLASS defines this in linux typedef SDLGLFB Super; //[C]commented, DECLARE_CLASS defines this in linux
#endif #endif
DSimpleCanvas *RenderBuffer;
public: public:

View file

@ -52,7 +52,7 @@ bool PolyTriangleDrawer::mirror;
void PolyTriangleDrawer::set_viewport(int x, int y, int width, int height, DCanvas *canvas) void PolyTriangleDrawer::set_viewport(int x, int y, int width, int height, DCanvas *canvas)
{ {
dest = (uint8_t*)canvas->GetBuffer(); dest = (uint8_t*)canvas->GetPixels();
dest_width = canvas->GetWidth(); dest_width = canvas->GetWidth();
dest_height = canvas->GetHeight(); dest_height = canvas->GetHeight();
dest_pitch = canvas->GetPitch(); dest_pitch = canvas->GetPitch();
@ -554,7 +554,7 @@ void DrawRectCommand::Execute(DrawerThread *thread)
thread_data.num_cores = thread->num_cores; thread_data.num_cores = thread->num_cores;
auto renderTarget = PolyRenderer::Instance()->RenderTarget; auto renderTarget = PolyRenderer::Instance()->RenderTarget;
const void *destOrg = renderTarget->GetBuffer(); const void *destOrg = renderTarget->GetPixels();
int destWidth = renderTarget->GetWidth(); int destWidth = renderTarget->GetWidth();
int destHeight = renderTarget->GetHeight(); int destHeight = renderTarget->GetHeight();
int destPitch = renderTarget->GetPitch(); int destPitch = renderTarget->GetPitch();

View file

@ -70,12 +70,14 @@ void PolyRenderer::RenderView(player_t *player)
RenderActorView(player->mo, false); RenderActorView(player->mo, false);
#if 0
// Apply special colormap if the target cannot do it // Apply special colormap if the target cannot do it
CameraLight *cameraLight = CameraLight::Instance(); CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->ShaderColormap() && RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D)) if (cameraLight->ShaderColormap() && RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D))
{ {
Threads.MainThread()->DrawQueue->Push<ApplySpecialColormapRGBACommand>(cameraLight->ShaderColormap(), screen); Threads.MainThread()->DrawQueue->Push<ApplySpecialColormapRGBACommand>(cameraLight->ShaderColormap(), screen);
} }
#endif
Threads.MainThread()->FlushDrawQueue(); Threads.MainThread()->FlushDrawQueue();
DrawerThreads::WaitForWorkers(); DrawerThreads::WaitForWorkers();

View file

@ -224,7 +224,7 @@ namespace swrenderer
auto rendertarget = args.Viewport()->RenderTarget; auto rendertarget = args.Viewport()->RenderTarget;
if (rendertarget->IsBgra()) if (rendertarget->IsBgra())
{ {
uint32_t *destorg = (uint32_t*)rendertarget->GetBuffer(); uint32_t *destorg = (uint32_t*)rendertarget->GetPixels();
uint32_t *dest = (uint32_t*)args.Dest(); uint32_t *dest = (uint32_t*)args.Dest();
int offset = (int)(ptrdiff_t)(dest - destorg); int offset = (int)(ptrdiff_t)(dest - destorg);
x = offset % rendertarget->GetPitch(); x = offset % rendertarget->GetPitch();
@ -232,7 +232,7 @@ namespace swrenderer
} }
else else
{ {
uint8_t *destorg = rendertarget->GetBuffer(); uint8_t *destorg = rendertarget->GetPixels();
uint8_t *dest = (uint8_t*)args.Dest(); uint8_t *dest = (uint8_t*)args.Dest();
int offset = (int)(ptrdiff_t)(dest - destorg); int offset = (int)(ptrdiff_t)(dest - destorg);
x = offset % rendertarget->GetPitch(); x = offset % rendertarget->GetPitch();
@ -246,7 +246,7 @@ namespace swrenderer
auto rendertarget = args.Viewport()->RenderTarget; auto rendertarget = args.Viewport()->RenderTarget;
if (rendertarget->IsBgra()) if (rendertarget->IsBgra())
{ {
uint32_t *destorg = (uint32_t*)rendertarget->GetBuffer(); uint32_t *destorg = (uint32_t*)rendertarget->GetPixels();
uint32_t *dest = (uint32_t*)args.Dest(); uint32_t *dest = (uint32_t*)args.Dest();
int offset = (int)(ptrdiff_t)(dest - destorg); int offset = (int)(ptrdiff_t)(dest - destorg);
x = offset % rendertarget->GetPitch(); x = offset % rendertarget->GetPitch();
@ -254,7 +254,7 @@ namespace swrenderer
} }
else else
{ {
uint8_t *destorg = rendertarget->GetBuffer(); uint8_t *destorg = rendertarget->GetPixels();
uint8_t *dest = (uint8_t*)args.Dest(); uint8_t *dest = (uint8_t*)args.Dest();
int offset = (int)(ptrdiff_t)(dest - destorg); int offset = (int)(ptrdiff_t)(dest - destorg);
x = offset % rendertarget->GetPitch(); x = offset % rendertarget->GetPitch();

View file

@ -3074,7 +3074,7 @@ namespace swrenderer
void DrawVoxelBlocksPalCommand::Execute(DrawerThread *thread) void DrawVoxelBlocksPalCommand::Execute(DrawerThread *thread)
{ {
int destpitch = args.Viewport()->RenderTarget->GetPitch(); int destpitch = args.Viewport()->RenderTarget->GetPitch();
uint8_t *destorig = args.Viewport()->RenderTarget->GetBuffer(); uint8_t *destorig = args.Viewport()->RenderTarget->GetPixels();
const uint8_t *colormap = args.Colormap(args.Viewport()); const uint8_t *colormap = args.Colormap(args.Viewport());
for (int i = 0; i < blockcount; i++) for (int i = 0; i < blockcount; i++)

View file

@ -719,6 +719,7 @@ namespace swrenderer
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#if 0
ApplySpecialColormapRGBACommand::ApplySpecialColormapRGBACommand(FSpecialColormap *colormap, DFrameBuffer *screen) ApplySpecialColormapRGBACommand::ApplySpecialColormapRGBACommand(FSpecialColormap *colormap, DFrameBuffer *screen)
{ {
buffer = screen->GetBuffer(); buffer = screen->GetBuffer();
@ -869,6 +870,7 @@ namespace swrenderer
count--; count--;
} }
} }
#endif
#endif #endif
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -938,7 +940,7 @@ namespace swrenderer
void DrawVoxelBlocksRGBACommand::Execute(DrawerThread *thread) void DrawVoxelBlocksRGBACommand::Execute(DrawerThread *thread)
{ {
int pitch = args.Viewport()->RenderTarget->GetPitch(); int pitch = args.Viewport()->RenderTarget->GetPitch();
uint8_t *destorig = args.Viewport()->RenderTarget->GetBuffer(); uint8_t *destorig = args.Viewport()->RenderTarget->GetPixels();
DrawSprite32Command drawer(args); DrawSprite32Command drawer(args);
drawer.args.dc_texturefracx = 0; drawer.args.dc_texturefracx = 0;

View file

@ -175,6 +175,7 @@ namespace swrenderer
FString DebugInfo() override; FString DebugInfo() override;
}; };
#if 0
class ApplySpecialColormapRGBACommand : public DrawerCommand class ApplySpecialColormapRGBACommand : public DrawerCommand
{ {
uint8_t *buffer; uint8_t *buffer;
@ -193,6 +194,7 @@ namespace swrenderer
void Execute(DrawerThread *thread) override; void Execute(DrawerThread *thread) override;
FString DebugInfo() override { return "ApplySpecialColormapRGBACommand"; } FString DebugInfo() override { return "ApplySpecialColormapRGBACommand"; }
}; };
#endif
template<typename CommandType, typename BlendMode> template<typename CommandType, typename BlendMode>
class DrawerBlendCommand : public CommandType class DrawerBlendCommand : public CommandType

View file

@ -225,7 +225,7 @@ void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int wi
r_viewwindow = mScene.MainThread()->Viewport->viewwindow; r_viewwindow = mScene.MainThread()->Viewport->viewwindow;
} }
screen->GetFlashedPalette (palette); screen->GetFlashedPalette (palette);
M_CreatePNG (file, pic->GetBuffer(), palette, SS_PAL, width, height, pic->GetPitch(), Gamma); M_CreatePNG (file, pic->GetPixels(), palette, SS_PAL, width, height, pic->GetPitch(), Gamma);
delete pic; delete pic;
} }
@ -300,24 +300,24 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin
if (Canvas->IsBgra()) if (Canvas->IsBgra())
{ {
if (Pixels == Canvas->GetBuffer()) if (Pixels == Canvas->GetPixels())
{ {
FTexture::FlipSquareBlockBgra((uint32_t*)Pixels, tex->GetWidth(), tex->GetHeight()); FTexture::FlipSquareBlockBgra((uint32_t*)Pixels, tex->GetWidth(), tex->GetHeight());
} }
else else
{ {
FTexture::FlipNonSquareBlockBgra((uint32_t*)Pixels, (const uint32_t*)Canvas->GetBuffer(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch()); FTexture::FlipNonSquareBlockBgra((uint32_t*)Pixels, (const uint32_t*)Canvas->GetPixels(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch());
} }
} }
else else
{ {
if (Pixels == Canvas->GetBuffer()) if (Pixels == Canvas->GetPixels())
{ {
FTexture::FlipSquareBlockRemap(Pixels, tex->GetWidth(), tex->GetHeight(), GPalette.Remap); FTexture::FlipSquareBlockRemap(Pixels, tex->GetWidth(), tex->GetHeight(), GPalette.Remap);
} }
else else
{ {
FTexture::FlipNonSquareBlockRemap(Pixels, Canvas->GetBuffer(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch(), GPalette.Remap); FTexture::FlipNonSquareBlockRemap(Pixels, Canvas->GetPixels(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch(), GPalette.Remap);
} }
} }

View file

@ -302,7 +302,7 @@ namespace swrenderer
if (viewport->RenderTarget->IsBgra()) if (viewport->RenderTarget->IsBgra())
{ {
uint32_t *dest = (uint32_t*)viewport->RenderTarget->GetBuffer() + x + Ytop * spacing; uint32_t *dest = (uint32_t*)viewport->RenderTarget->GetPixels() + x + Ytop * spacing;
uint32_t c = GPalette.BaseColors[color].d; uint32_t c = GPalette.BaseColors[color].d;
for (int y = Ytop; y <= Ybottom; y++) for (int y = Ytop; y <= Ybottom; y++)
@ -313,7 +313,7 @@ namespace swrenderer
} }
else else
{ {
uint8_t *dest = viewport->RenderTarget->GetBuffer() + x + Ytop * spacing; uint8_t *dest = viewport->RenderTarget->GetPixels() + x + Ytop * spacing;
for (int y = Ytop; y <= Ybottom; y++) for (int y = Ytop; y <= Ybottom; y++)
{ {

View file

@ -103,13 +103,13 @@ namespace swrenderer
{ {
if (!viewport->RenderTarget->IsBgra()) if (!viewport->RenderTarget->IsBgra())
{ {
memset(viewport->RenderTarget->GetBuffer(), clearcolor, viewport->RenderTarget->GetPitch() * viewport->RenderTarget->GetHeight()); memset(viewport->RenderTarget->GetPixels(), clearcolor, viewport->RenderTarget->GetPitch() * viewport->RenderTarget->GetHeight());
} }
else else
{ {
uint32_t bgracolor = GPalette.BaseColors[clearcolor].d; uint32_t bgracolor = GPalette.BaseColors[clearcolor].d;
int size = viewport->RenderTarget->GetPitch() * viewport->RenderTarget->GetHeight(); int size = viewport->RenderTarget->GetPitch() * viewport->RenderTarget->GetHeight();
uint32_t *dest = (uint32_t *)viewport->RenderTarget->GetBuffer(); uint32_t *dest = (uint32_t *)viewport->RenderTarget->GetPixels();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
dest[i] = bgracolor; dest[i] = bgracolor;
} }
@ -118,12 +118,14 @@ namespace swrenderer
RenderActorView(player->mo); RenderActorView(player->mo);
// Apply special colormap if the target cannot do it // Apply special colormap if the target cannot do it
#if 0
if (CameraLight::Instance()->ShaderColormap() && viewport->RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D)) if (CameraLight::Instance()->ShaderColormap() && viewport->RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D))
{ {
auto queue = std::make_shared<DrawerCommandQueue>(MainThread()->FrameMemory.get()); auto queue = std::make_shared<DrawerCommandQueue>(MainThread()->FrameMemory.get());
queue->Push<ApplySpecialColormapRGBACommand>(CameraLight::Instance()->ShaderColormap(), screen); queue->Push<ApplySpecialColormapRGBACommand>(CameraLight::Instance()->ShaderColormap(), screen);
DrawerThreads::Execute(queue); DrawerThreads::Execute(queue);
} }
#endif
DrawerWaitCycles.Clock(); DrawerWaitCycles.Clock();
DrawerThreads::WaitForWorkers(); DrawerThreads::WaitForWorkers();

View file

@ -162,7 +162,7 @@ namespace swrenderer
int pitch = RenderTarget->GetPitch(); int pitch = RenderTarget->GetPitch();
int pixelsize = RenderTarget->IsBgra() ? 4 : 1; int pixelsize = RenderTarget->IsBgra() ? 4 : 1;
return RenderTarget->GetBuffer() + (x + y * pitch) * pixelsize; return RenderTarget->GetPixels() + (x + y * pitch) * pixelsize;
} }
void RenderViewport::InitTextureMapping() void RenderViewport::InitTextureMapping()

View file

@ -121,7 +121,7 @@ void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style
} }
else else
{ {
Pixels = (uint8_t*)Canvas->GetBuffer(); Pixels = (uint8_t*)Canvas->GetPixels();
bPixelsAllocated = false; bPixelsAllocated = false;
} }
@ -141,7 +141,7 @@ void FCanvasTexture::MakeTextureBgra()
} }
else else
{ {
PixelsBgra = (uint32_t*)CanvasBgra->GetBuffer(); PixelsBgra = (uint32_t*)CanvasBgra->GetPixels();
bPixelsAllocatedBgra = false; bPixelsAllocatedBgra = false;
} }

View file

@ -199,8 +199,6 @@ int NewWidth, NewHeight, NewBits;
DCanvas::DCanvas (int _width, int _height, bool _bgra) DCanvas::DCanvas (int _width, int _height, bool _bgra)
{ {
// Init member vars // Init member vars
Buffer = NULL;
LockCount = 0;
Width = _width; Width = _width;
Height = _height; Height = _height;
Bgra = _bgra; Bgra = _bgra;
@ -527,7 +525,7 @@ void DFrameBuffer::CalcGamma (float gamma, uint8_t gammalookup[256])
DSimpleCanvas::DSimpleCanvas (int width, int height, bool bgra) DSimpleCanvas::DSimpleCanvas (int width, int height, bool bgra)
: DCanvas (width, height, bgra) : DCanvas (width, height, bgra)
{ {
MemBuffer = nullptr; PixelBuffer = nullptr;
Resize(width, height); Resize(width, height);
} }
@ -536,10 +534,10 @@ void DSimpleCanvas::Resize(int width, int height)
Width = width; Width = width;
Height = height; Height = height;
if (MemBuffer != NULL) if (PixelBuffer != NULL)
{ {
delete[] MemBuffer; delete[] PixelBuffer;
MemBuffer = NULL; PixelBuffer = NULL;
} }
// Making the pitch a power of 2 is very bad for performance // Making the pitch a power of 2 is very bad for performance
@ -578,8 +576,8 @@ void DSimpleCanvas::Resize(int width, int height)
} }
} }
int bytes_per_pixel = Bgra ? 4 : 1; int bytes_per_pixel = Bgra ? 4 : 1;
MemBuffer = new uint8_t[Pitch * height * bytes_per_pixel]; PixelBuffer = new uint8_t[Pitch * height * bytes_per_pixel];
memset (MemBuffer, 0, Pitch * height * bytes_per_pixel); memset (PixelBuffer, 0, Pitch * height * bytes_per_pixel);
} }
//========================================================================== //==========================================================================
@ -590,10 +588,10 @@ void DSimpleCanvas::Resize(int width, int height)
DSimpleCanvas::~DSimpleCanvas () DSimpleCanvas::~DSimpleCanvas ()
{ {
if (MemBuffer != NULL) if (PixelBuffer != NULL)
{ {
delete[] MemBuffer; delete[] PixelBuffer;
MemBuffer = NULL; PixelBuffer = NULL;
} }
} }
@ -607,7 +605,7 @@ DSimpleCanvas::~DSimpleCanvas ()
//========================================================================== //==========================================================================
DFrameBuffer::DFrameBuffer (int width, int height, bool bgra) DFrameBuffer::DFrameBuffer (int width, int height, bool bgra)
: DSimpleCanvas (ViewportScaledWidth(width, height), ViewportScaledHeight(width, height), bgra) : DCanvas (ViewportScaledWidth(width, height), ViewportScaledHeight(width, height), bgra)
{ {
LastMS = LastSec = FrameCount = LastCount = LastTic = 0; LastMS = LastSec = FrameCount = LastCount = LastTic = 0;
Accel2D = false; Accel2D = false;
@ -616,70 +614,6 @@ DFrameBuffer::DFrameBuffer (int width, int height, bool bgra)
VideoHeight = height; VideoHeight = height;
} }
//==========================================================================
//
// DFrameBuffer :: PostprocessBgra
//
// Copies data to destination buffer while performing gamma and flash.
// This is only needed if a target cannot do this with shaders.
//
//==========================================================================
void DFrameBuffer::CopyWithGammaBgra(void *output, int pitch, const uint8_t *gammared, const uint8_t *gammagreen, const uint8_t *gammablue, PalEntry flash, int flash_amount)
{
const uint8_t *gammatables[3] = { gammared, gammagreen, gammablue };
if (flash_amount > 0)
{
uint16_t inv_flash_amount = 256 - flash_amount;
uint16_t flash_red = flash.r * flash_amount;
uint16_t flash_green = flash.g * flash_amount;
uint16_t flash_blue = flash.b * flash_amount;
for (int y = 0; y < Height; y++)
{
uint8_t *dest = (uint8_t*)output + y * pitch;
uint8_t *src = MemBuffer + y * Pitch * 4;
for (int x = 0; x < Width; x++)
{
uint16_t fg_red = src[2];
uint16_t fg_green = src[1];
uint16_t fg_blue = src[0];
uint16_t red = (fg_red * inv_flash_amount + flash_red) >> 8;
uint16_t green = (fg_green * inv_flash_amount + flash_green) >> 8;
uint16_t blue = (fg_blue * inv_flash_amount + flash_blue) >> 8;
dest[0] = gammatables[2][blue];
dest[1] = gammatables[1][green];
dest[2] = gammatables[0][red];
dest[3] = 0xff;
dest += 4;
src += 4;
}
}
}
else
{
for (int y = 0; y < Height; y++)
{
uint8_t *dest = (uint8_t*)output + y * pitch;
uint8_t *src = MemBuffer + y * Pitch * 4;
for (int x = 0; x < Width; x++)
{
dest[0] = gammatables[2][src[0]];
dest[1] = gammatables[1][src[1]];
dest[2] = gammatables[0][src[2]];
dest[3] = 0xff;
dest += 4;
src += 4;
}
}
}
}
//========================================================================== //==========================================================================
// //
// DFrameBuffer :: DrawRateStuff // DFrameBuffer :: DrawRateStuff
@ -726,39 +660,16 @@ void DFrameBuffer::DrawRateStuff ()
// draws little dots on the bottom of the screen // draws little dots on the bottom of the screen
if (ticker) if (ticker)
{ {
int64_t i = I_GetTime(); int64_t t = I_GetTime();
int64_t tics = i - LastTic; int64_t tics = t - LastTic;
uint8_t *buffer = GetBuffer();
LastTic = i; LastTic = t;
if (tics > 20) tics = 20; if (tics > 20) tics = 20;
// Buffer can be NULL if we're doing hardware accelerated 2D
if (buffer != NULL)
{
if (IsBgra())
{
uint32_t *buffer32 = (uint32_t*)buffer;
buffer32 += (GetHeight() - 1) * GetPitch();
for (i = 0; i < tics * 2; i += 2) buffer32[i] = 0xffffffff;
for (; i < 20 * 2; i += 2) buffer32[i] = 0xff000000;
}
else
{
buffer += (GetHeight() - 1) * GetPitch();
for (i = 0; i < tics * 2; i += 2) buffer[i] = 0xff;
for (; i < 20 * 2; i += 2) buffer[i] = 0x00;
}
}
else
{
int i; int i;
for (i = 0; i < tics*2; i += 2) Clear(i, Height-1, i+1, Height, 255, 0); for (i = 0; i < tics*2; i += 2) Clear(i, Height-1, i+1, Height, 255, 0);
for ( ; i < 20*2; i += 2) Clear(i, Height-1, i+1, Height, 0, 0); for ( ; i < 20*2; i += 2) Clear(i, Height-1, i+1, Height, 0, 0);
} }
}
// draws the palette for debugging // draws the palette for debugging
if (vid_showpalette) if (vid_showpalette)

View file

@ -206,7 +206,8 @@ public:
virtual ~DCanvas (); virtual ~DCanvas ();
// Member variable access // Member variable access
inline uint8_t *GetBuffer () const { return Buffer; } //inline uint8_t *GetBuffer () const { return Buffer; }
inline uint8_t *GetPixels () const { return PixelBuffer; }
inline int GetWidth () const { return Width; } inline int GetWidth () const { return Width; }
inline int GetHeight () const { return Height; } inline int GetHeight () const { return Height; }
inline int GetPitch () const { return Pitch; } inline int GetPitch () const { return Pitch; }
@ -214,11 +215,10 @@ public:
protected: protected:
uint8_t *Buffer; uint8_t *PixelBuffer;
int Width; int Width;
int Height; int Height;
int Pitch; int Pitch;
int LockCount;
bool Bgra; bool Bgra;
int clipleft = 0, cliptop = 0, clipwidth = -1, clipheight = -1; int clipleft = 0, cliptop = 0, clipwidth = -1, clipheight = -1;
@ -236,11 +236,9 @@ class DSimpleCanvas : public DCanvas
public: public:
DSimpleCanvas (int width, int height, bool bgra); DSimpleCanvas (int width, int height, bool bgra);
~DSimpleCanvas (); ~DSimpleCanvas ();
protected:
void Resize(int width, int height); void Resize(int width, int height);
uint8_t *MemBuffer; private:
DSimpleCanvas() {} DSimpleCanvas() {}
}; };
@ -270,9 +268,10 @@ public:
// for actually implementing this. Built on top of SimpleCanvas, because it // for actually implementing this. Built on top of SimpleCanvas, because it
// needs a system memory buffer when buffered output is enabled. // needs a system memory buffer when buffered output is enabled.
class DFrameBuffer : public DSimpleCanvas class DFrameBuffer : public DCanvas
{ {
typedef DSimpleCanvas Super; typedef DSimpleCanvas Super;
protected: protected:
void DrawTextureV(FTexture *img, double x, double y, uint32_t tag, va_list tags) = delete; void DrawTextureV(FTexture *img, double x, double y, uint32_t tag, va_list tags) = delete;
virtual void DrawTextureParms(FTexture *img, DrawParms &parms); virtual void DrawTextureParms(FTexture *img, DrawParms &parms);
@ -281,6 +280,7 @@ protected:
bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext) const; bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext) const;
void DrawTextCommon(FFont *font, int normalcolor, double x, double y, const char *string, DrawParms &parms); void DrawTextCommon(FFont *font, int normalcolor, double x, double y, const char *string, DrawParms &parms);
int LockCount = 0;
public: public:
DFrameBuffer (int width, int height, bool bgra); DFrameBuffer (int width, int height, bool bgra);
@ -448,7 +448,6 @@ public:
protected: protected:
void DrawRateStuff (); void DrawRateStuff ();
void CopyFromBuff (uint8_t *src, int srcPitch, int width, int height, uint8_t *dest); void CopyFromBuff (uint8_t *src, int srcPitch, int width, int height, uint8_t *dest);
void CopyWithGammaBgra(void *output, int pitch, const uint8_t *gammared, const uint8_t *gammagreen, const uint8_t *gammablue, PalEntry flash, int flash_amount);
DFrameBuffer () {} DFrameBuffer () {}

View file

@ -261,10 +261,8 @@ D3DFB::D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen)
NeedGammaUpdate = false; NeedGammaUpdate = false;
NeedPalUpdate = false; NeedPalUpdate = false;
if (MemBuffer == NULL) RenderBuffer = new DSimpleCanvas(width, height, bgra);
{ Pitch = RenderBuffer->GetPitch(); // should be removed, but still needed as long as DFrameBuffer inherits from DCanvas
return;
}
memcpy(SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256); memcpy(SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256);
@ -930,7 +928,9 @@ bool D3DFB::Lock (bool buffered)
} }
assert (!In2D); assert (!In2D);
Accel2D = vid_hw2d; Accel2D = vid_hw2d;
#if 0
Buffer = MemBuffer; Buffer = MemBuffer;
#endif
return false; return false;
} }
@ -955,7 +955,9 @@ void D3DFB::Unlock ()
} }
else if (--LockCount == 0) else if (--LockCount == 0)
{ {
#if 0
Buffer = NULL; Buffer = NULL;
#endif
} }
} }
@ -1060,7 +1062,9 @@ void D3DFB::Update ()
BlitCycles.Unclock(); BlitCycles.Unclock();
//LOG1 ("cycles = %d\n", BlitCycles); //LOG1 ("cycles = %d\n", BlitCycles);
#if 0
Buffer = NULL; Buffer = NULL;
#endif
UpdatePending = false; UpdatePending = false;
} }
@ -1111,7 +1115,7 @@ void D3DFB::Flip()
GetClientRect(Window, &box); GetClientRect(Window, &box);
if (box.right > 0 && box.bottom > 0 && (Width != box.right || Height != box.bottom)) if (box.right > 0 && box.bottom > 0 && (Width != box.right || Height != box.bottom))
{ {
Resize(box.right, box.bottom); RenderBuffer->Resize(box.right, box.bottom);
TrueHeight = Height; TrueHeight = Height;
PixelDoubling = 0; PixelDoubling = 0;
@ -1208,6 +1212,7 @@ void D3DFB::Draw3DPart(bool copy3d)
{ {
if (IsBgra() && FBFormat == D3DFMT_A8R8G8B8) if (IsBgra() && FBFormat == D3DFMT_A8R8G8B8)
{ {
auto MemBuffer = RenderBuffer->GetPixels();
if (lockrect.Pitch == Pitch * sizeof(uint32_t) && Pitch == Width) if (lockrect.Pitch == Pitch * sizeof(uint32_t) && Pitch == Width)
{ {
memcpy(lockrect.pBits, MemBuffer, Width * Height * sizeof(uint32_t)); memcpy(lockrect.pBits, MemBuffer, Width * Height * sizeof(uint32_t));
@ -1228,17 +1233,17 @@ void D3DFB::Draw3DPart(bool copy3d)
{ {
if (lockrect.Pitch == Pitch && Pitch == Width) if (lockrect.Pitch == Pitch && Pitch == Width)
{ {
memcpy(lockrect.pBits, MemBuffer, Width * Height); memcpy(lockrect.pBits, RenderBuffer->GetPixels(), Width * Height);
} }
else else
{ {
uint8_t *dest = (uint8_t *)lockrect.pBits; uint8_t *dest = (uint8_t *)lockrect.pBits;
uint8_t *src = (uint8_t *)MemBuffer; uint8_t *src = RenderBuffer->GetPixels();
for (int y = 0; y < Height; y++) for (int y = 0; y < Height; y++)
{ {
memcpy(dest, src, Width); memcpy(dest, src, Width);
dest = reinterpret_cast<uint8_t*>(reinterpret_cast<uint8_t*>(dest) + lockrect.Pitch); dest = reinterpret_cast<uint8_t*>(reinterpret_cast<uint8_t*>(dest) + lockrect.Pitch);
src += Pitch; src += RenderBuffer->GetPitch();
} }
} }
} }

View file

@ -1169,7 +1169,7 @@ void Win32GLFrameBuffer::SetGammaTable(uint16_t *tbl)
bool Win32GLFrameBuffer::Lock(bool buffered) bool Win32GLFrameBuffer::Lock(bool buffered)
{ {
m_Lock++; m_Lock++;
Buffer = MemBuffer; //Buffer = MemBuffer;
return true; return true;
} }

View file

@ -20,6 +20,9 @@ extern HANDLE FPSLimitEvent;
class D3DFB : public BaseWinFB class D3DFB : public BaseWinFB
{ {
typedef BaseWinFB Super; typedef BaseWinFB Super;
DSimpleCanvas *RenderBuffer = nullptr;
public: public:
D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen); D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen);
~D3DFB (); ~D3DFB ();