Optimized final blit to the screen render target. (#65)

When bumping the table, instead of offseting the table pixels by CPU, just memcpy all the pixels to vScreenTex once, and then render two separate quads from that texture: one for the board and the other for the sidebar. Then change the coordinates of the board quad when bumping.
This commit is contained in:
MaikelChan 2021-10-24 06:13:51 +02:00 committed by GitHub
parent 5cd01807b2
commit 38cf08e298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
#include "pch.h" #include "pch.h"
#include "render.h" #include "render.h"
#include "fullscrn.h"
#include "GroupData.h" #include "GroupData.h"
#include "options.h" #include "options.h"
#include "pb.h" #include "pb.h"
@ -538,61 +539,7 @@ void render::BlitVScreen()
); );
assertm(static_cast<unsigned>(pitch) == vscreen->Width * sizeof(ColorRgba), "Padding on vScreen texture"); assertm(static_cast<unsigned>(pitch) == vscreen->Width * sizeof(ColorRgba), "Padding on vScreen texture");
if (offset_x == 0 && offset_y == 0)
{
// No offset - direct copy
std::memcpy(lockedPixels, vscreen->BmpBufPtr1, vscreen->Width * vscreen->Height * sizeof(ColorRgba)); std::memcpy(lockedPixels, vscreen->BmpBufPtr1, vscreen->Width * vscreen->Height * sizeof(ColorRgba));
}
else
{
// Copy offset table and fixed side bar
auto tableWidth = pb::MainTable->Width;
auto scoreWidth = vscreen->Width - pb::MainTable->Width;
auto tableStride = tableWidth * sizeof(ColorRgba);
auto scoreStride = scoreWidth * sizeof(ColorRgba);
auto srcScorePtr = &vscreen->BmpBufPtr1[tableWidth];
auto xSrc = 0, ySrc = 0, xDst = offset_x, yDst = offset_y, height = vscreen->Height;
// Negative dst == positive src offset
if (xDst < 0)
{
xSrc -= xDst;
xDst = 0;
}
if (yDst < 0)
{
ySrc -= yDst;
yDst = 0;
}
if (xSrc)
{
tableStride -= xSrc * sizeof(ColorRgba);
}
if (xDst)
{
tableStride -= xDst * sizeof(ColorRgba);
tableWidth -= xDst;
scoreWidth += xDst;
}
if (ySrc)
height -= ySrc;
auto srcBmpPtr = &vscreen->BmpBufPtr1[vscreen->Width * ySrc + xSrc];
auto dstPtr = &lockedPixels[vscreen->Width * yDst + xDst];
for (int y = height; y > 0; --y)
{
std::memcpy(dstPtr, srcBmpPtr, tableStride);
dstPtr += tableWidth;
std::memcpy(dstPtr, srcScorePtr, scoreStride);
dstPtr += scoreWidth;
srcBmpPtr += vscreen->Stride;
srcScorePtr += vscreen->Stride;
}
}
SDL_UnlockTexture(vScreenTex); SDL_UnlockTexture(vScreenTex);
} }
@ -600,5 +547,42 @@ void render::BlitVScreen()
void render::PresentVScreen() void render::PresentVScreen()
{ {
BlitVScreen(); BlitVScreen();
if (offset_x == 0 && offset_y == 0)
{
SDL_RenderCopy(winmain::Renderer, vScreenTex, nullptr, &DestinationRect); SDL_RenderCopy(winmain::Renderer, vScreenTex, nullptr, &DestinationRect);
} }
else
{
int32_t srcSeparationX = static_cast<int32_t>(vscreen->Width * 0.625f);
SDL_Rect srcBoardRect = SDL_Rect
{
0, 0,
srcSeparationX, vscreen->Height
};
SDL_Rect srcSidebarRect = SDL_Rect
{
srcSeparationX, 0,
vscreen->Width - srcSeparationX, vscreen->Height
};
int32_t dstSeparationX = static_cast<int32_t>(DestinationRect.w * 0.625f);
SDL_Rect dstBoardRect = SDL_Rect
{
DestinationRect.x + static_cast<int32_t>(offset_x * fullscrn::ScaleX), DestinationRect.y + static_cast<int32_t>(offset_y * fullscrn::ScaleY),
dstSeparationX, DestinationRect.h
};
SDL_Rect dstSidebarRect = SDL_Rect
{
DestinationRect.x + dstSeparationX, DestinationRect.y,
DestinationRect.w - dstSeparationX, DestinationRect.h
};
SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcBoardRect, &dstBoardRect);
SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcSidebarRect, &dstSidebarRect);
}
}