Framebuffer
FrameBuffer
- class arcade.gl.Framebuffer(ctx: Context, *, color_attachments=None, depth_attachment=None)[source]
Bases:
object
An offscreen render target also called a Framebuffer Object in OpenGL. This implementation is using texture attachments. When creating a Framebuffer we supply it with textures we want our scene rendered into. The advantage of using texture attachments is the ability we get to keep working on the contents of the framebuffer.
The best way to create framebuffer is through
arcade.gl.Context.framebuffer()
:# Create a 100 x 100 framebuffer with one attachment ctx.framebuffer(color_attachments=[ctx.texture((100, 100), components=4)]) # Create a 100 x 100 framebuffer with two attachments # Shaders can be configured writing to the different layers ctx.framebuffer( color_attachments=[ ctx.texture((100, 100), components=4), ctx.texture((100, 100), components=4), ] )
- Parameters
ctx (Context) – The context this framebuffer belongs to
color_attachments (List[arcade.gl.Texture]) – List of color attachments.
depth_attachment (arcade.gl.Texture) – A depth attachment (optional)
- activate()[source]
Context manager for binding the framebuffer.
Unlike the default context manager in this class this support nested framebuffer binding.
- clear(color=(0.0, 0.0, 0.0, 0.0), *, depth: float = 1.0, normalized: bool = False, viewport: Optional[Tuple[int, int, int, int]] = None)[source]
Clears the framebuffer:
# Clear framebuffer using the color red in normalized form fbo.clear(color=(1.0, 0.0, 0.0, 1.0), normalized=True) # Clear the framebuffer using arcade's colors (not normalized) fb.clear(color=arcade.color.WHITE)
If the background color is an
RGB
value instead ofRGBA`
we assume alpha value 255.
- property color_attachments: List[arcade.gl.texture.Texture]
A list of color attachments
- Type
list of
arcade.gl.Texture
- delete()[source]
Destroy the underlying OpenGL resource. Don’t use this unless you know exactly what you are doing.
- static delete_glo(ctx, framebuffer_id)[source]
Destroys the framebuffer object
- Parameters
ctx – OpenGL context
framebuffer_id – Framebuffer to destroy (glo)
- property depth_attachment: arcade.gl.texture.Texture
Depth attachment
- Type
- property depth_mask: bool
Get or set the depth mask (default:
True
). It determines if depth values should be written to the depth texture when depth testing is enabled.The depth mask value is persistent all will automatically be applies every time the framebuffer is bound.
- Type
- property glo: ctypes.c_uint
The OpenGL id/name of the framebuffer
- Type
GLuint
- is_default = False
Is this the default framebuffer? (window buffer)
- read(*, viewport=None, components=3, attachment=0, dtype='f1') bytearray [source]
Read framebuffer pixels
- resize()[source]
Detects size changes in attachments. This will reset the viewport to
0, 0, width, height
.
- property scissor: Optional[Tuple[int, int, int, int]]
Get or set the scissor box for this framebuffer.
By default the scissor box is disabled and has no effect and will have an initial value of
None
. The scissor box is enabled when setting a value and disabled when set toNone
# Set and eneable scissor box only drawing # in a 100 x 100 pixel lower left area ctx.scissor = 0, 0, 100, 100 # Disable scissoring ctx.scissor = None
- Type
tuple (x, y, width, height)
- use(*, force: bool = False)[source]
Bind the framebuffer making it the target of all redering commands
- Parameters
force (bool) – Force the framebuffer binding even if the system already believes it’s already bound.
- property viewport: Tuple[int, int, int, int]
Get or set the framebuffer’s viewport. The viewport parameter are
(x, y, width, height)
. It determines what part of the framebuffer should be redered to. By default the viewport is(0, 0, width, height)
.The viewport value is persistent all will automatically be applies every time the framebuffer is bound.
Example:
# 100, x 100 lower left with size 200 x 200px fb.viewport = 100, 100, 200, 200
DefaultFrameBuffer
- class arcade.gl.framebuffer.DefaultFrameBuffer(ctx: Context)[source]
Bases:
arcade.gl.framebuffer.Framebuffer
Represents the default framebuffer. This is the framebuffer of the window itself and need some special handling.
We are not allowed to destroy this framebuffer since it’s owned by pyglet. This framebuffer can also change size and pixel ratio at any point.
We’re doing some initial introspection to guess somewhat sane initial values. Since this is a dynamic framebuffer we cannot trust the internal values. We can only trust what the pyglet window itself reports related to window size and framebuffer size. This should be updated in the
on_resize
callback.- is_default = True
Is this the default framebuffer? (window buffer)
- property scissor: Optional[Tuple[int, int, int, int]]
Get or set the scissor box for this framebuffer.
By default the scissor box is disabled and has no effect and will have an initial value of
None
. The scissor box is enabled when setting a value and disabled when set toNone
# Set and eneable scissor box only drawing # in a 100 x 100 pixel lower left area ctx.scissor = 0, 0, 100, 100 # Disable scissoring ctx.scissor = None
- Type
tuple (x, y, width, height)
- property viewport: Tuple[int, int, int, int]
Get or set the framebuffer’s viewport. The viewport parameter are
(x, y, width, height)
. It determines what part of the framebuffer should be redered to. By default the viewport is(0, 0, width, height)
.The viewport value is persistent all will automatically be applies every time the framebuffer is bound.
Example:
# 100, x 100 lower left with size 200 x 200px fb.viewport = 100, 100, 200, 200