- merged DCanvas and DSimpleCanvas and use a TArray to hold its memory.
This commit is contained in:
parent
927d333063
commit
024870ba11
8 changed files with 68 additions and 121 deletions
|
|
@ -82,87 +82,6 @@ void DFrameBuffer::CalcGamma (float gamma, uint8_t gammalookup[256])
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DSimpleCanvas Constructor
|
||||
//
|
||||
// A simple canvas just holds a buffer in main memory.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
DSimpleCanvas::DSimpleCanvas (int width, int height, bool bgra)
|
||||
: DCanvas (width, height, bgra)
|
||||
{
|
||||
PixelBuffer = nullptr;
|
||||
Resize(width, height);
|
||||
}
|
||||
|
||||
void DSimpleCanvas::Resize(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
||||
if (PixelBuffer != NULL)
|
||||
{
|
||||
delete[] PixelBuffer;
|
||||
PixelBuffer = NULL;
|
||||
}
|
||||
|
||||
// Making the pitch a power of 2 is very bad for performance
|
||||
// Try to maximize the number of cache lines that can be filled
|
||||
// for each column drawing operation by making the pitch slightly
|
||||
// longer than the width. The values used here are all based on
|
||||
// empirical evidence.
|
||||
|
||||
if (width <= 640)
|
||||
{
|
||||
// For low resolutions, just keep the pitch the same as the width.
|
||||
// Some speedup can be seen using the technique below, but the speedup
|
||||
// is so marginal that I don't consider it worthwhile.
|
||||
Pitch = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we couldn't figure out the CPU's L1 cache line size, assume
|
||||
// it's 32 bytes wide.
|
||||
if (CPU.DataL1LineSize == 0)
|
||||
{
|
||||
CPU.DataL1LineSize = 32;
|
||||
}
|
||||
// The Athlon and P3 have very different caches, apparently.
|
||||
// I am going to generalize the Athlon's performance to all AMD
|
||||
// processors and the P3's to all non-AMD processors. I don't know
|
||||
// how smart that is, but I don't have a vast plethora of
|
||||
// processors to test with.
|
||||
if (CPU.bIsAMD)
|
||||
{
|
||||
Pitch = width + CPU.DataL1LineSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
Pitch = width + MAX(0, CPU.DataL1LineSize - 8);
|
||||
}
|
||||
}
|
||||
int bytes_per_pixel = Bgra ? 4 : 1;
|
||||
PixelBuffer = new uint8_t[Pitch * height * bytes_per_pixel];
|
||||
memset (PixelBuffer, 0, Pitch * height * bytes_per_pixel);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DSimpleCanvas Destructor
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
DSimpleCanvas::~DSimpleCanvas ()
|
||||
{
|
||||
if (PixelBuffer != NULL)
|
||||
{
|
||||
delete[] PixelBuffer;
|
||||
PixelBuffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DFrameBuffer Constructor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue