Skip to content

Commit

Permalink
Merge pull request #643 from lethal-guitar/more-fixes
Browse files Browse the repository at this point in the history
More fixes
  • Loading branch information
lethal-guitar authored Jan 24, 2021
2 parents 51cd406 + 4b55c38 commit 5511365
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
32 changes: 20 additions & 12 deletions src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1016,6 +1018,8 @@ struct Renderer::Impl {
const int width,
const int height
) {
submitBatch();

const auto textureHandle =
createGlTexture(GLsizei(width), GLsizei(height), nullptr);

Expand All @@ -1029,8 +1033,8 @@ struct Renderer::Impl {
textureHandle,
0);

mStateChanged = true;
glBindTexture(GL_TEXTURE_2D, mLastUsedTexture);
commitRenderTarget(mLastCommittedState);

mRenderTargetDict.insert({textureHandle, {{width, height}, fboHandle}});

Expand All @@ -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<std::uint8_t> pixelData;
pixelData.resize(image.width() * image.height() * 4);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/ui/duke_script_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ void DukeScriptRunner::interpretNextAction() {
*mpResourceBundle,
showImage.image);
imageTexture.render(0, 0);
mpRenderer->submitBatch();
},

[this](const Delay& delay) {
Expand Down Expand Up @@ -536,7 +535,6 @@ void DukeScriptRunner::drawSprite(

renderer::Texture spriteTexture(mpRenderer, image);
spriteTexture.render(topLeftPx + drawOffsetPx);
mpRenderer->submitBatch();
}


Expand Down
2 changes: 1 addition & 1 deletion src/ui/ingame_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/ui/menu_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ui/menu_navigation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/ui/movie_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5511365

Please sign in to comment.