Skip to content

Commit

Permalink
opengl: fix scissor state when switching between a canvas and the scr…
Browse files Browse the repository at this point in the history
…een while a scissor is active.

Fixes #2112.
  • Loading branch information
slime73 committed Nov 16, 2024
1 parent 383fec4 commit f8b1942
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/modules/graphics/opengl/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int pixelw, in
// Re-apply the scissor if it was active, since the rectangle passed to
// glScissor is affected by the viewport dimensions.
if (state.scissor)
setScissor(state.scissorRect);
setScissor(state.scissorRect, !iswindow);

// Make sure the correct sRGB setting is used when drawing to the textures.
if (GLAD_VERSION_1_0 || GLAD_EXT_sRGB_write_control)
Expand Down Expand Up @@ -1324,7 +1324,7 @@ int Graphics::getBackbufferMSAA() const
return internalBackbuffer.get() ? internalBackbuffer->getMSAA() : 0;
}

void Graphics::setScissor(const Rect &rect)
void Graphics::setScissor(const Rect &rect, bool rtActive)
{
flushBatchedDraws();

Expand All @@ -1342,12 +1342,17 @@ void Graphics::setScissor(const Rect &rect)
glrect.h = (int) (rect.h * dpiscale);

// OpenGL's reversed y-coordinate is compensated for in OpenGL::setScissor.
gl.setScissor(glrect, isRenderTargetActive());
gl.setScissor(glrect, rtActive);

state.scissor = true;
state.scissorRect = rect;
}

void Graphics::setScissor(const Rect &rect)
{
setScissor(rect, isRenderTargetActive());
}

void Graphics::setScissor()
{
if (states.back().scissor)
Expand Down
2 changes: 2 additions & 0 deletions src/modules/graphics/opengl/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class Graphics final : public love::graphics::Graphics

void setDebug(bool enable);

void setScissor(const Rect &rect, bool rtActive);

uint32 computePixelFormatUsage(PixelFormat format, bool readable);

std::unordered_map<RenderTargets, GLuint, CachedFBOHasher> framebufferObjects;
Expand Down

0 comments on commit f8b1942

Please sign in to comment.