Skip to content

framebuffer

FreeBodyEngine.graphics.framebuffer #

AttachmentFormat #

Bases: Enum

GPU pixel formats available for a framebuffer attachment - color formats (paired with AttachmentType.COLOR) and depth/stencil formats (paired with the corresponding AttachmentType).

DEPTH24 = auto() class-attribute instance-attribute #

DEPTH24_STENCIL8 = auto() class-attribute instance-attribute #

DEPTH32F = auto() class-attribute instance-attribute #

R32F = auto() class-attribute instance-attribute #

R8 = auto() class-attribute instance-attribute #

RG32F = auto() class-attribute instance-attribute #

RGB10_A2 = auto() class-attribute instance-attribute #

RGBA16F = auto() class-attribute instance-attribute #

RGBA32F = auto() class-attribute instance-attribute #

RGBA8 = auto() class-attribute instance-attribute #

STENCIL8 = auto() class-attribute instance-attribute #

AttachmentType #

Bases: Enum

What a framebuffer attachment is used for - a sampled color output, or a depth/stencil buffer (or combined depth+stencil) that participates in depth testing but generally isn't sampled directly.

COLOR = auto() class-attribute instance-attribute #

DEPTH = auto() class-attribute instance-attribute #

DEPTH_STENCIL = auto() class-attribute instance-attribute #

STENCIL = auto() class-attribute instance-attribute #

Framebuffer(width, height, attachments) #

Backend-agnostic render target: a set of named attachments (color/ depth/stencil, in whatever formats requested) a Renderer can draw into instead of the screen - used for G-buffer passes, compute-shader emulation (see graphics/compute.py), and offscreen rendering generally.

Records the requested width/height/attachments - creating the actual GPU-side textures/renderbuffers for them is left to a concrete subclass.

attachments = attachments instance-attribute #

height = height instance-attribute #

width = width instance-attribute #

bind() #

Binds the framebuffer to allow for drawing.

clear_color_attachment(name, value=(0.0, 0.0, 0.0, 0.0)) #

Clears one color attachment to value, independent of whatever color the last Renderer.clear() call used - needed because a single glClearColor/glClear(GL_COLOR_BUFFER_BIT) clears every bound draw buffer to the same color, which is wrong for a G-buffer channel like world position/normal where "nothing was rasterized here" needs to be distinguishable from the scene's actual background color (e.g. via this channel's alpha, left at 0 only where a fragment shader never touched it).

draw(attachment, size=None) #

Draws the selected attachment to the currently bound framebuffer.

get_attachment_texture(attachment_name) #

Returns the backend-specific texture object backing the attachment_name color attachment.

read(attachment_name) #

Reads back one color attachment's pixels as a (height, width, channels) float32 array. A synchronous GPU->CPU stall - fine for compute-emulation result readback, not for anything per-frame.

resize(size) #

Changes the size of the framebuffer.

set_draw_buffers(names) #

Restricts subsequent draws to only the named color attachments, leaving every other attachment's storage untouched (this reconfigures which draw-buffer slots are active, it doesn't delete/resize anything). Needed by a pass that must write just one attachment of a multi-attachment framebuffer without touching the others still bound to it - e.g. PBRPipeline's lighting composite/forward- transparent passes writing only 'lit' on the same G-buffer FBO the opaque pass wrote every other channel of. bind() does not reset this - a later pass that needs the full attachment set back must call this again.

unbind() #

Unbinds the framebuffer.