Double buffer source texture, optimize intermediate blitting.

This commit is contained in:
Christian Speckner 2020-01-25 19:51:46 +00:00
parent ec6348894a
commit 11f4846f21
2 changed files with 18 additions and 8 deletions

View File

@ -94,7 +94,7 @@ void QisBlitter::blit(SDL_Surface& surface)
recreateTexturesIfNecessary(); recreateTexturesIfNecessary();
SDL_Texture* texture = myIntermediateTexture; SDL_Texture* intermediateTexture = myIntermediateTexture;
if(myStaticData == nullptr) { if(myStaticData == nullptr) {
SDL_UpdateTexture(mySrcTexture, &mySrcRect, surface.pixels, surface.pitch); SDL_UpdateTexture(mySrcTexture, &mySrcRect, surface.pixels, surface.pitch);
@ -102,10 +102,14 @@ void QisBlitter::blit(SDL_Surface& surface)
blitToIntermediate(); blitToIntermediate();
myIntermediateTexture = mySecondaryIntermedateTexture; myIntermediateTexture = mySecondaryIntermedateTexture;
mySecondaryIntermedateTexture = texture; mySecondaryIntermedateTexture = intermediateTexture;
SDL_Texture* temporary = mySrcTexture;
mySrcTexture = mySecondarySrcTexture;
mySecondarySrcTexture = temporary;
} }
SDL_RenderCopy(myFB.renderer(), texture, &myIntermediateRect, &myDstRect); SDL_RenderCopy(myFB.renderer(), intermediateTexture, &myIntermediateRect, &myDstRect);
} }
@ -117,9 +121,11 @@ void QisBlitter::blitToIntermediate()
SDL_Rect r = mySrcRect; SDL_Rect r = mySrcRect;
r.x = r.y = 0; r.x = r.y = 0;
SDL_UpdateTexture(myIntermediateTexture, nullptr, myBlankBuffer.get(), 4 * myIntermediateRect.w);
SDL_SetRenderTarget(myFB.renderer(), myIntermediateTexture); SDL_SetRenderTarget(myFB.renderer(), myIntermediateTexture);
SDL_SetRenderDrawColor(myFB.renderer(), 0, 0, 0, 255);
SDL_RenderClear(myFB.renderer());
SDL_RenderCopy(myFB.renderer(), mySrcTexture, &r, &myIntermediateRect); SDL_RenderCopy(myFB.renderer(), mySrcTexture, &r, &myIntermediateRect);
SDL_SetRenderTarget(myFB.renderer(), nullptr); SDL_SetRenderTarget(myFB.renderer(), nullptr);
@ -151,8 +157,12 @@ void QisBlitter::recreateTexturesIfNecessary()
mySrcTexture = SDL_CreateTexture(myFB.renderer(), myFB.pixelFormat().format, mySrcTexture = SDL_CreateTexture(myFB.renderer(), myFB.pixelFormat().format,
texAccess, mySrcRect.w, mySrcRect.h); texAccess, mySrcRect.w, mySrcRect.h);
myBlankBuffer = make_unique<uInt32[]>(4 * myIntermediateRect.w * myIntermediateRect.h); if (myStaticData == nullptr) {
memset(myBlankBuffer.get(), 0, 4 * myIntermediateRect.w * myIntermediateRect.h); mySecondarySrcTexture = SDL_CreateTexture(myFB.renderer(), myFB.pixelFormat().format,
texAccess, mySrcRect.w, mySrcRect.h);
} else {
mySecondarySrcTexture = nullptr;
}
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");

View File

@ -46,6 +46,7 @@ class QisBlitter : public Blitter {
FrameBufferSDL2& myFB; FrameBufferSDL2& myFB;
SDL_Texture* mySrcTexture{nullptr}; SDL_Texture* mySrcTexture{nullptr};
SDL_Texture* mySecondarySrcTexture{nullptr};
SDL_Texture* myIntermediateTexture{nullptr}; SDL_Texture* myIntermediateTexture{nullptr};
SDL_Texture* mySecondaryIntermedateTexture{nullptr}; SDL_Texture* mySecondaryIntermedateTexture{nullptr};
@ -56,7 +57,6 @@ class QisBlitter : public Blitter {
bool myRecreateTextures{false}; bool myRecreateTextures{false};
SDL_Surface* myStaticData{nullptr}; SDL_Surface* myStaticData{nullptr};
unique_ptr<uInt32[]> myBlankBuffer;
private: private: