pyglet.image.buffer

OpenGL Framebuffer abstractions.

This module provides classes for working with Framebuffers & Renderbuffers and their attachments. Attachements can be pyglet Texture objects, which allows easily accessing their data, saving to disk, etc. Renderbuffers can be used if you don’t need to access their data at a later time. For example:

# Create two objects to use as attachments for our Framebuffer.
color_buffer = pyglet.image.Texture.create(width, height, min_filter=GL_NEAREST, mag_filter=GL_NEAREST)
depth_buffer = pyglet.image.buffer.Renderbuffer(width, height, GL_DEPTH_COMPONENT)

# Create a framebuffer object, and attach the two buffers:
framebuffer = pyglet.image.Framebuffer()
framebuffer.attach_texture(color_buffer, attachment=GL_COLOR_ATTACHMENT0)
framebuffer.attach_renderbuffer(depth_buffer, attachment=GL_DEPTH_ATTACHMENT)

# Bind the Framebuffer, which sets it as the active render target:
framebuffer.bind()

See the OpenGL documentation for more information on valid attachment types and targets.

class Framebuffer

OpenGL Framebuffer Object.

New in version 2.0.

__init__(target: int = 36160) None

Create a Framebuffer Instance.

attach_renderbuffer(
renderbuffer: Renderbuffer,
target: int = 36160,
attachment: int = 36064,
) None

Attach a Renderbuffer to the Framebuffer.

Parameters:
  • renderbuffer (Renderbuffer) – Specifies the Renderbuffer to attach to the framebuffer attachment point named by attachment.

  • target (int) – Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent to GL_DRAW_FRAMEBUFFER.

  • attachment (int) – Specifies the attachment point of the framebuffer. attachment must be GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or GL_DEPTH_STENCIL_ATTACHMENT.

Return type:

None

attach_texture(
texture: Texture,
target: int = 36160,
attachment: int = 36064,
) None

Attach a Texture to the Framebuffer.

Parameters:
  • texture (Texture) – Specifies the texture object to attach to the framebuffer attachment point named by attachment.

  • target (int) – Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent to GL_DRAW_FRAMEBUFFER.

  • attachment (int) – Specifies the attachment point of the framebuffer. attachment must be GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or GL_DEPTH_STENCIL_ATTACHMENT.

Return type:

None

attach_texture_layer(
texture: Texture,
layer: int,
level: int,
target: int = 36160,
attachment: int = 36064,
) None

Attach a Texture layer to the Framebuffer.

Parameters:
  • texture (Texture) – Specifies the texture object to attach to the framebuffer attachment point named by attachment.

  • layer (int) – Specifies the layer of texture to attach.

  • level (int) – Specifies the mipmap level of texture to attach.

  • target (int) – Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent to GL_DRAW_FRAMEBUFFER.

  • attachment (int) – Specifies the attachment point of the framebuffer. attachment must be GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or GL_DEPTH_STENCIL_ATTACHMENT.

Return type:

None

bind() None

Bind the Framebuffer.

This ctivates it as the current drawing target.

Return type:

None

clear() None

Clear the attachments.

Return type:

None

delete() None

Explicitly delete the Framebuffer.

Return type:

None

static get_status() str

Get the current Framebuffer status, as a string.

If Framebuffer.is_complete is False, this method can be used for more information. It will return a string with the OpenGL reported status.

Return type:

str

unbind() None

Unbind the Framebuffer.

Unbind should be called to prevent further rendering to the framebuffer, or if you wish to access data from its Texture atachments.

Return type:

None

property height: int

The height of the tallest attachment.

property id: int

The Framebuffer id.

property is_complete: bool

True if the framebuffer is ‘complete’, else False.

property width: int

The width of the widest attachment.

class Renderbuffer

OpenGL Renderbuffer Object.

__init__(
width: int,
height: int,
internal_format: int,
samples: int = 1,
) None

Create a RenderBuffer instance.

bind() None
Return type:

None

delete() None
Return type:

None

static unbind() None
Return type:

None

property height: int
property id: int
property width: int
get_max_color_attachments() int

Get the maximum allow Framebuffer Color attachements.

Return type:

int