From ce522f80a0b217b59f4634784d24c429ad64ad4d Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sat, 25 Jan 2020 19:51:46 +0000 Subject: [PATCH] Double buffer source texture, optimize intermediate blitting. --- src/common/sdl_blitter/QisBlitter.cxx | 24 +++++++++++++++++------- src/common/sdl_blitter/QisBlitter.hxx | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/common/sdl_blitter/QisBlitter.cxx b/src/common/sdl_blitter/QisBlitter.cxx index 506d1600d..95d958565 100644 --- a/src/common/sdl_blitter/QisBlitter.cxx +++ b/src/common/sdl_blitter/QisBlitter.cxx @@ -94,7 +94,7 @@ void QisBlitter::blit(SDL_Surface& surface) recreateTexturesIfNecessary(); - SDL_Texture* texture = myIntermediateTexture; + SDL_Texture* intermediateTexture = myIntermediateTexture; if(myStaticData == nullptr) { SDL_UpdateTexture(mySrcTexture, &mySrcRect, surface.pixels, surface.pitch); @@ -102,10 +102,14 @@ void QisBlitter::blit(SDL_Surface& surface) blitToIntermediate(); 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; r.x = r.y = 0; - SDL_UpdateTexture(myIntermediateTexture, nullptr, myBlankBuffer.get(), 4 * myIntermediateRect.w); - 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_SetRenderTarget(myFB.renderer(), nullptr); @@ -151,8 +157,12 @@ void QisBlitter::recreateTexturesIfNecessary() mySrcTexture = SDL_CreateTexture(myFB.renderer(), myFB.pixelFormat().format, texAccess, mySrcRect.w, mySrcRect.h); - myBlankBuffer = make_unique(4 * myIntermediateRect.w * myIntermediateRect.h); - memset(myBlankBuffer.get(), 0, 4 * myIntermediateRect.w * myIntermediateRect.h); + if (myStaticData == nullptr) { + mySecondarySrcTexture = SDL_CreateTexture(myFB.renderer(), myFB.pixelFormat().format, + texAccess, mySrcRect.w, mySrcRect.h); + } else { + mySecondarySrcTexture = nullptr; + } SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); diff --git a/src/common/sdl_blitter/QisBlitter.hxx b/src/common/sdl_blitter/QisBlitter.hxx index 5b2479a29..77ab2b51d 100644 --- a/src/common/sdl_blitter/QisBlitter.hxx +++ b/src/common/sdl_blitter/QisBlitter.hxx @@ -46,6 +46,7 @@ class QisBlitter : public Blitter { FrameBufferSDL2& myFB; SDL_Texture* mySrcTexture{nullptr}; + SDL_Texture* mySecondarySrcTexture{nullptr}; SDL_Texture* myIntermediateTexture{nullptr}; SDL_Texture* mySecondaryIntermedateTexture{nullptr}; @@ -56,7 +57,6 @@ class QisBlitter : public Blitter { bool myRecreateTextures{false}; SDL_Surface* myStaticData{nullptr}; - unique_ptr myBlankBuffer; private: