mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Make Camera.fbo the entity rendered to, with a separate fbo for emitted frames
This commit is contained in:
parent
66d12a1687
commit
d08a16a5fb
1 changed files with 9 additions and 11 deletions
|
@ -241,19 +241,18 @@ class Camera(object):
|
||||||
def init_context(self, ctx: moderngl.Context | None = None) -> None:
|
def init_context(self, ctx: moderngl.Context | None = None) -> None:
|
||||||
if ctx is None:
|
if ctx is None:
|
||||||
ctx = moderngl.create_standalone_context()
|
ctx = moderngl.create_standalone_context()
|
||||||
fbo = self.get_fbo(ctx, 0)
|
fbo = self.get_fbo(ctx, self.samples)
|
||||||
else:
|
else:
|
||||||
fbo = ctx.detect_framebuffer()
|
fbo = ctx.detect_framebuffer()
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.fbo = fbo
|
self.fbo = fbo
|
||||||
|
self.fbo.use()
|
||||||
self.set_ctx_blending()
|
self.set_ctx_blending()
|
||||||
|
|
||||||
self.ctx.enable(moderngl.PROGRAM_POINT_SIZE)
|
self.ctx.enable(moderngl.PROGRAM_POINT_SIZE)
|
||||||
|
|
||||||
# For multisample antialiasing
|
# This is the frame buffer we'll draw into when emitting frames
|
||||||
fbo_msaa = self.get_fbo(ctx, self.samples)
|
self.draw_fbo = self.get_fbo(ctx, 0)
|
||||||
fbo_msaa.use()
|
|
||||||
self.fbo_msaa = fbo_msaa
|
|
||||||
|
|
||||||
def set_ctx_blending(self, enable: bool = True) -> None:
|
def set_ctx_blending(self, enable: bool = True) -> None:
|
||||||
if enable:
|
if enable:
|
||||||
|
@ -298,7 +297,6 @@ class Camera(object):
|
||||||
|
|
||||||
def clear(self) -> None:
|
def clear(self) -> None:
|
||||||
self.fbo.clear(*self.background_rgba)
|
self.fbo.clear(*self.background_rgba)
|
||||||
self.fbo_msaa.clear(*self.background_rgba)
|
|
||||||
|
|
||||||
def reset_pixel_shape(self, new_width: int, new_height: int) -> None:
|
def reset_pixel_shape(self, new_width: int, new_height: int) -> None:
|
||||||
self.pixel_width = new_width
|
self.pixel_width = new_width
|
||||||
|
@ -306,13 +304,13 @@ class Camera(object):
|
||||||
self.refresh_perspective_uniforms()
|
self.refresh_perspective_uniforms()
|
||||||
|
|
||||||
def get_raw_fbo_data(self, dtype: str = 'f1') -> bytes:
|
def get_raw_fbo_data(self, dtype: str = 'f1') -> bytes:
|
||||||
# Copy blocks from the fbo_msaa to the drawn fbo using Blit
|
# Copy blocks from fbo into draw_fbo using Blit
|
||||||
pw, ph = (self.pixel_width, self.pixel_height)
|
pw, ph = (self.pixel_width, self.pixel_height)
|
||||||
gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, self.fbo_msaa.glo)
|
gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, self.fbo.glo)
|
||||||
gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, self.fbo.glo)
|
gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, self.draw_fbo.glo)
|
||||||
gl.glBlitFramebuffer(0, 0, pw, ph, 0, 0, pw, ph, gl.GL_COLOR_BUFFER_BIT, gl.GL_LINEAR)
|
gl.glBlitFramebuffer(0, 0, pw, ph, 0, 0, pw, ph, gl.GL_COLOR_BUFFER_BIT, gl.GL_LINEAR)
|
||||||
return self.fbo.read(
|
return self.draw_fbo.read(
|
||||||
viewport=self.fbo.viewport,
|
viewport=self.draw_fbo.viewport,
|
||||||
components=self.n_channels,
|
components=self.n_channels,
|
||||||
dtype=dtype,
|
dtype=dtype,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue