diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index 4009647f7..dbb808d9f 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -848,18 +848,9 @@ struct Renderer::Impl { } if (state.mRenderTargetTexture != mLastCommittedState.mRenderTargetTexture) { - base::Extents framebufferSize; - if (state.mRenderTargetTexture != 0) { - const auto iData = mRenderTargetDict.find(state.mRenderTargetTexture); - assert(iData != mRenderTargetDict.end()); - - glBindFramebuffer(GL_FRAMEBUFFER, iData->second.mFbo); - framebufferSize = iData->second.mSize; - } else { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - framebufferSize = mWindowSize; - } + const auto framebufferSize = currentFramebufferSize(); + commitRenderTarget(state); glViewport(0, 0, framebufferSize.width, framebufferSize.height); commitClipRect(state, framebufferSize); commitVertexAttributeFormat(); @@ -903,6 +894,17 @@ struct Renderer::Impl { } + void commitRenderTarget(const State& state) { + if (state.mRenderTargetTexture != 0) { + const auto iData = mRenderTargetDict.find(state.mRenderTargetTexture); + assert(iData != mRenderTargetDict.end()); + glBindFramebuffer(GL_FRAMEBUFFER, iData->second.mFbo); + } else { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + } + + void commitClipRect( const State& state, const base::Extents& framebufferSize @@ -1016,6 +1018,8 @@ struct Renderer::Impl { const int width, const int height ) { + submitBatch(); + const auto textureHandle = createGlTexture(GLsizei(width), GLsizei(height), nullptr); @@ -1029,8 +1033,8 @@ struct Renderer::Impl { textureHandle, 0); - mStateChanged = true; glBindTexture(GL_TEXTURE_2D, mLastUsedTexture); + commitRenderTarget(mLastCommittedState); mRenderTargetDict.insert({textureHandle, {{width, height}, fboHandle}}); @@ -1039,6 +1043,8 @@ struct Renderer::Impl { TextureId createTexture(const data::Image& image) { + submitBatch(); + // OpenGL wants pixel data in bottom-up format, so transform it accordingly std::vector pixelData; pixelData.resize(image.width() * image.height() * 4); @@ -1068,6 +1074,8 @@ struct Renderer::Impl { void destroyTexture(TextureId texture) { + submitBatch(); + const auto iRenderTarget = mRenderTargetDict.find(texture); if (iRenderTarget != mRenderTargetDict.end()) { glDeleteFramebuffers(1, &iRenderTarget->second.mFbo); diff --git a/src/ui/duke_script_runner.cpp b/src/ui/duke_script_runner.cpp index 16a506ecd..270507b3e 100644 --- a/src/ui/duke_script_runner.cpp +++ b/src/ui/duke_script_runner.cpp @@ -381,7 +381,6 @@ void DukeScriptRunner::interpretNextAction() { *mpResourceBundle, showImage.image); imageTexture.render(0, 0); - mpRenderer->submitBatch(); }, [this](const Delay& delay) { @@ -536,7 +535,6 @@ void DukeScriptRunner::drawSprite( renderer::Texture spriteTexture(mpRenderer, image); spriteTexture.render(topLeftPx + drawOffsetPx); - mpRenderer->submitBatch(); } diff --git a/src/ui/ingame_menu.cpp b/src/ui/ingame_menu.cpp index b69b73697..a6d35c0ec 100644 --- a/src/ui/ingame_menu.cpp +++ b/src/ui/ingame_menu.cpp @@ -468,7 +468,7 @@ void IngameMenu::enterMenu(const MenuType type) { }; auto saveSlotSelectionEventHook = [this](const SDL_Event& event) { - if (isConfirmButton(event)) { + if (isMenuConfirmButton(event)) { const auto enteredViaGamepad = event.type == SDL_CONTROLLERBUTTONDOWN; diff --git a/src/ui/menu_navigation.cpp b/src/ui/menu_navigation.cpp index 2d449ff99..1c89c55be 100644 --- a/src/ui/menu_navigation.cpp +++ b/src/ui/menu_navigation.cpp @@ -47,6 +47,14 @@ bool isConfirmButton(const SDL_Event& event) { } +bool isMenuConfirmButton(const SDL_Event& event) { + return + isConfirmButton(event) || + (isNonRepeatKeyDown(event) && event.key.keysym.sym == SDLK_SPACE); + +} + + bool isCancelButton(const SDL_Event& event) { const auto escapePressed = isNonRepeatKeyDown(event) && event.key.keysym.sym == SDLK_ESCAPE; diff --git a/src/ui/menu_navigation.hpp b/src/ui/menu_navigation.hpp index 6998d5ac7..46bfaa277 100644 --- a/src/ui/menu_navigation.hpp +++ b/src/ui/menu_navigation.hpp @@ -29,6 +29,7 @@ namespace rigel::ui { bool isNonRepeatKeyDown(const SDL_Event& event); bool isButtonPress(const SDL_Event& event); bool isConfirmButton(const SDL_Event& event); +bool isMenuConfirmButton(const SDL_Event& event); bool isCancelButton(const SDL_Event& event); bool isQuitConfirmButton(const SDL_Event& event); diff --git a/src/ui/movie_player.cpp b/src/ui/movie_player.cpp index 36c7d8800..989ec2eb4 100644 --- a/src/ui/movie_player.cpp +++ b/src/ui/movie_player.cpp @@ -52,7 +52,6 @@ void MoviePlayer::playMovie( auto baseImage = renderer::Texture(mpRenderer, movie.mBaseImage); baseImage.render(0, 0); - mpRenderer->submitBatch(); } mAnimationFrames = utils::transformed(movie.mFrames,