From cab453ac3a230c1bb06488540f4706f6dad5b39a Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Thu, 11 May 2017 12:20:08 +0200 Subject: [PATCH 1/2] Graphics: Use proper resizing function for TEXFBOs Manually resizing the contained TEX objects skips updating the width/height TEXFBO properties, which GLMeta::blit relies on. --- src/graphics.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index d205697..8a6301a 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -92,11 +92,9 @@ struct PingPong { screenW = width; screenH = height; + for (int i = 0; i < 2; ++i) - { - TEX::bind(rt[i].tex); - TEX::allocEmpty(width, height); - } + TEXFBO::allocEmpty(rt[i], width, height); } void startRender() @@ -946,16 +944,13 @@ void Graphics::resizeScreen(int width, int height) p->screen.setResolution(width, height); - TEX::bind(p->frozenScene.tex); - TEX::allocEmpty(width, height); - TEX::bind(p->currentScene.tex); - TEX::allocEmpty(width, height); + TEXFBO::allocEmpty(p->frozenScene, width, height); + TEXFBO::allocEmpty(p->currentScene, width, height); FloatRect screenRect(0, 0, width, height); p->screenQuad.setTexPosRect(screenRect, screenRect); - TEX::bind(p->transBuffer.tex); - TEX::allocEmpty(width, height); + TEXFBO::allocEmpty(p->transBuffer, width, height); shState->eThread().requestWindowResize(width, height); } From bd694f9f99566de6de98be48d75bee826f5103bb Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Thu, 11 May 2017 12:37:15 +0200 Subject: [PATCH 2/2] Graphics: Remove superfluous TEXFBOs while reusing existing ones While the PingPong buffers were always texture-backed, currentScene and transBuffer used to be backed by renderbuffers, which might have been more optimized as render targets on older hardware; but since all buffers in Graphics got switched to being texture backed to allow blitting via rendering (when hardware blitting isn't available or broken, eg. on mobile platforms), their reason to exist vanished. For transBuffer, we can reuse the backbuffer of the PingPong structure, while currentScene might have been useless from the start. --- src/graphics.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index 8a6301a..6a12cb3 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -474,9 +474,7 @@ struct GraphicsPrivate bool frozen; TEXFBO frozenScene; - TEXFBO currentScene; Quad screenQuad; - TEXFBO transBuffer; /* Global list of all live Disposables * (disposed on reset) */ @@ -502,26 +500,15 @@ struct GraphicsPrivate TEXFBO::allocEmpty(frozenScene, scRes.x, scRes.y); TEXFBO::linkFBO(frozenScene); - TEXFBO::init(currentScene); - TEXFBO::allocEmpty(currentScene, scRes.x, scRes.y); - TEXFBO::linkFBO(currentScene); - FloatRect screenRect(0, 0, scRes.x, scRes.y); screenQuad.setTexPosRect(screenRect, screenRect); - TEXFBO::init(transBuffer); - TEXFBO::allocEmpty(transBuffer, scRes.x, scRes.y); - TEXFBO::linkFBO(transBuffer); - fpsLimiter.resetFrameAdjust(); } ~GraphicsPrivate() { TEXFBO::fini(frozenScene); - TEXFBO::fini(currentScene); - - TEXFBO::fini(transBuffer); } void updateScreenResoRatio(RGSSThreadData *rtData) @@ -721,8 +708,15 @@ void Graphics::transition(int duration, setBrightness(255); + /* The PP frontbuffer will hold the current scene after the + * composition step. Since the backbuffer is unused during + * the transition, we can reuse it as the target buffer for + * the final rendered image. */ + TEXFBO ¤tScene = p->screen.getPP().frontBuffer(); + TEXFBO &transBuffer = p->screen.getPP().backBuffer(); + /* Capture new scene */ - p->compositeToBuffer(p->currentScene); + p->screen.composite(); /* If no transition bitmap is provided, * we can use a simplified shader */ @@ -735,7 +729,7 @@ void Graphics::transition(int duration, shader.bind(); shader.applyViewportProj(); shader.setFrozenScene(p->frozenScene.tex); - shader.setCurrentScene(p->currentScene.tex); + shader.setCurrentScene(currentScene.tex); shader.setTransMap(transMap->getGLTypes().tex); shader.setVague(vague / 256.0f); shader.setTexSize(p->scRes); @@ -746,7 +740,7 @@ void Graphics::transition(int duration, shader.bind(); shader.applyViewportProj(); shader.setFrozenScene(p->frozenScene.tex); - shader.setCurrentScene(p->currentScene.tex); + shader.setCurrentScene(currentScene.tex); shader.setTexSize(p->scRes); } @@ -790,7 +784,7 @@ void Graphics::transition(int duration, /* Draw the composed frame to a buffer first * (we need this because we're skipping PingPong) */ - FBO::bind(p->transBuffer.fbo); + FBO::bind(transBuffer.fbo); FBO::clear(); p->screenQuad.draw(); @@ -801,7 +795,7 @@ void Graphics::transition(int duration, FBO::clear(); GLMeta::blitBeginScreen(Vec2i(p->winSize)); - GLMeta::blitSource(p->transBuffer); + GLMeta::blitSource(transBuffer); p->metaBlitBufferFlippedScaled(); GLMeta::blitEnd(); @@ -945,13 +939,10 @@ void Graphics::resizeScreen(int width, int height) p->screen.setResolution(width, height); TEXFBO::allocEmpty(p->frozenScene, width, height); - TEXFBO::allocEmpty(p->currentScene, width, height); FloatRect screenRect(0, 0, width, height); p->screenQuad.setTexPosRect(screenRect, screenRect); - TEXFBO::allocEmpty(p->transBuffer, width, height); - shState->eThread().requestWindowResize(width, height); }