Skip to content

Commit

Permalink
fix resize
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhCode committed Nov 5, 2024
1 parent 42f5861 commit 561bce3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/gfx/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ Renderer::Renderer(const SizeHandler& sizes) {
});
}

void Renderer::Resize(const SizeHandler& sizes) {
void Renderer::Resize(const SizeHandler& _sizes) {
sizes = _sizes;

camera.Resize(sizes.size);

OtherFinalRenderTexture() =
RenderTexture(sizes.uiSize, sizes.dpiScale, TextureFormat::RGBA8UnormSrgb);
OtherFinalRenderTexture().UpdatePos(sizes.offset);
resized = true;
resize = true;

auto stencilTextureView =
utils::CreateRenderTexture(ctx.device, {sizes.uiFbSize, TextureFormat::Stencil8})
Expand Down Expand Up @@ -480,10 +482,12 @@ void Renderer::RenderWindows(
) {
// increment
frameIndex = (frameIndex + 1) % 2;
if (resized) {
if (resize) {
// resize other texture, since we're using the current one now
OtherFinalRenderTexture() = CurrFinalRenderTexture();
resized = false;
OtherFinalRenderTexture() =
RenderTexture(sizes.uiSize, sizes.dpiScale, TextureFormat::RGBA8UnormSrgb);
OtherFinalRenderTexture().UpdatePos(sizes.offset);
resize = false;
}

windowsRPD.cColorAttachments[0].view = CurrFinalRenderTexture().textureView;
Expand Down
4 changes: 3 additions & 1 deletion src/gfx/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ struct Renderer {

Ortho2D camera;

SizeHandler sizes;
bool resize = false;

int frameIndex = 1;
std::array<RenderTexture, 2> finalRenderTextures;
bool resized = false;
auto& CurrFinalRenderTexture() {
return finalRenderTextures[frameIndex];
}
Expand Down

0 comments on commit 561bce3

Please sign in to comment.