Skip to content

framebuffer

FreeBodyEngine.graphics.gl44.framebuffer #

GL_ATTACHMENT_FORMAT = {AttachmentFormat.R8: GL_R8, AttachmentFormat.RGBA8: GL_RGBA8, AttachmentFormat.RGBA16F: GL_RGBA16F, AttachmentFormat.RGBA32F: GL_RGBA32F, AttachmentFormat.RGB10_A2: GL_RGB10_A2, AttachmentFormat.R32F: GL_R32F, AttachmentFormat.RG32F: GL_RG32F, AttachmentFormat.DEPTH24: GL_DEPTH_COMPONENT24, AttachmentFormat.DEPTH32F: GL_DEPTH_COMPONENT32F, AttachmentFormat.STENCIL8: GL_STENCIL_INDEX8, AttachmentFormat.DEPTH24_STENCIL8: GL_DEPTH24_STENCIL8} module-attribute #

GL_ATTACHMENT_TYPE = {AttachmentFormat.R8: (GL_RED, GL_UNSIGNED_BYTE), AttachmentFormat.RGBA8: (GL_RGBA, GL_UNSIGNED_BYTE), AttachmentFormat.RGBA16F: (GL_RGBA, GL_FLOAT), AttachmentFormat.RGBA32F: (GL_RGBA, GL_FLOAT), AttachmentFormat.RGB10_A2: (GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), AttachmentFormat.R32F: (GL_RED, GL_FLOAT), AttachmentFormat.RG32F: (GL_RG, GL_FLOAT), AttachmentFormat.DEPTH24: (GL_DEPTH_COMPONENT, GL_UNSIGNED_INT), AttachmentFormat.DEPTH32F: (GL_DEPTH_COMPONENT, GL_FLOAT), AttachmentFormat.STENCIL8: (GL_STENCIL_INDEX, GL_UNSIGNED_BYTE), AttachmentFormat.DEPTH24_STENCIL8: (GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8)} module-attribute #

GL_CHANNEL_COUNT = {GL_RED: 1, GL_RG: 2, GL_RGB: 3, GL_RGBA: 4} module-attribute #

GL44Framebuffer(width, height, attachments, transparent=False) #

Bases: Framebuffer

The GL 4.4 implementation of Framebuffer: creates a real GL FBO with one 2D texture per color attachment and a shared renderbuffer for a depth/stencil/combined depth-stencil attachment (GL 4.4 has no functional need for a separate depth-only vs. combined path beyond which GL enum each is attached under).

Creates the FBO and, for each entry in attachments, its backing GPU resource: a texture for a COLOR attachment (assigned sequential GL_COLOR_ATTACHMENT0+n slots and registered as a draw buffer), or a renderbuffer for DEPTH/STENCIL/DEPTH_STENCIL. Raises RuntimeError if the resulting FBO isn't GL_FRAMEBUFFER_COMPLETE. transparent enables standard alpha blending for subsequent draws into this framebuffer.

depth_renderbuffer = glGenRenderbuffers(1) instance-attribute #

fbo = glGenFramebuffers(1) instance-attribute #

textures = {} instance-attribute #

bind() #

Binds this FBO as the current draw/read target and sets the GL viewport to its full size, so subsequent draw calls render into its attachments instead of the screen.

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

Clears the named color attachment to value via glClearBufferfv(GL_COLOR, draw_buffer_index, ...) - see GLFramebuffer.clear_color_attachment (gl33) for why this targets only one draw buffer rather than every bound one. This was missing entirely from GL44Framebuffer (PBRPipeline.draw() calls it unconditionally to keep gWorldPos.w a reliable sentinel), so PBRPipeline could never actually run on GL44Renderer before this.

draw(attachment, size=None) #

Draw a named attachment to the screen.

get_attachment_texture(attachment_name) #

Returns the raw GL texture name backing color attachment attachment_name (e.g. for wrapping via TextureManager.wrap_external_texture), logging an error instead of raising if it doesn't exist.

read(attachment_name) #

Synchronously reads back color attachment attachment_name (glReadPixels, always as GL_FLOAT) into a (height, width, channels) numpy array - a GPU/CPU sync point, so only meant for compute-emulation-style result readback, not per-frame use. Raises ValueError if attachment_name doesn't exist or isn't a color attachment.

resize(size) #

Recreates every attachment's backing texture/renderbuffer at the new size in place (same FBO, same attachment slots) - deletes each old GL object first rather than leaking it. Raises RuntimeError if the FBO isn't complete afterward, and leaves the GL viewport set to the new size.

set_draw_buffers(names) #

See Framebuffer.set_draw_buffers / GLFramebuffer.set_draw_buffers (gl33) - identical implementation. Assumes this FBO is already bound.

unbind() #

Rebinds the default framebuffer (id 0, the screen) - does not restore the previous viewport, so callers that resized it should reset that themselves.