Skip to content

Fix blitting to default framebuffer #1992

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 2 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
5 changes: 3 additions & 2 deletions arcade/examples/gl/multisample_fbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
import math
import arcade

SAMPLES = 8

class MultisampleFramebuffer(arcade.Window):

def __init__(self, width, height):
super().__init__(width, height, "Multisampled Framebuffer")
super().__init__(width, height, "Multisampled Framebuffer", samples=SAMPLES)
self.time = 0

# Create a MSAA texture and framebuffer
self.texture = self.ctx.texture(self.get_framebuffer_size(), samples=8)
self.texture = self.ctx.texture(self.get_framebuffer_size(), samples=SAMPLES)
self.fbo = self.ctx.framebuffer(color_attachments=[self.texture])

def on_draw(self):
Expand Down
19 changes: 14 additions & 5 deletions arcade/gl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,18 +805,27 @@ def copy_framebuffer(
: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)
# Set source and dest framebuffer
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)

# TODO: We can support blitting multiple layers here
gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0 + src_attachment_index)
if dst.is_default:
gl.glDrawBuffer(gl.GL_BACK)
else:
gl.glDrawBuffer(gl.GL_COLOR_ATTACHMENT0)

# gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, src._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 if depth else 0,
gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT,
gl.GL_NEAREST,
)
gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0) # Reset read buffer
self.active_framebuffer.use(force=True)

# Reset states. We can also apply previous states here
gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0)

# --- Resource methods ---

Expand Down