Skip to content

Lingering glreadbuffer #1921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions arcade/gl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,17 @@ def flush(self) -> None:

# Various utility methods

def copy_framebuffer(self, src: Framebuffer, dst: Framebuffer):
def copy_framebuffer(
self,
src: Framebuffer,
dst: Framebuffer,
src_attachment_index: int = 0,
depth: bool = True,
):
"""
Copies/blits a framebuffer to another one.
We can select one color attachment to copy plus
an optional depth attachment.

This operation has many restrictions to ensure it works across
different platforms and drivers:
Expand All @@ -791,15 +799,20 @@ def copy_framebuffer(self, src: Framebuffer, dst: Framebuffer):

:param src: The framebuffer to copy from
:param dst: The framebuffer we copy to
:param src_attachment_index: The color attachment to copy from
:param depth: Also copy depth attachment if present
"""
# TODO: Make make this more configurable (target)
gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, src._glo)
gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0 + src_attachment_index)
gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, dst._glo)
gl.glBlitFramebuffer(
0, 0, src.width, src.height, # Make source and dest size the same
0, 0, src.width, src.height,
gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT,
gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT if depth else 0,
gl.GL_NEAREST,
)
gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0) # Reset read buffer
self.active_framebuffer.use(force=True)

# --- Resource methods ---
Expand Down
1 change: 1 addition & 0 deletions arcade/gl/framebuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def read(
x, y, width, height = 0, 0, self._width, self._height
data = (gl.GLubyte * (components * component_size * width * height))(0)
gl.glReadPixels(x, y, width, height, base_format, pixel_type, data)
gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0) # Reset to default

return string_at(data, len(data))

Expand Down