Skip to content

buffer

FreeBodyEngine.graphics.gl33.buffer #

TextureBuffer(data, gl_internal_format=None) #

Bases: Buffer

A GL_TEXTURE_BUFFER-backed storage buffer - the SSBO-equivalent "readable buffer" usable under a plain 3.3 core context (texture buffer objects are core since GL 3.1; real SSBOs need GL 4.3). Read-only from GLSL (sampled via texelFetch); written from Python via set_data(). Used for both compute-kernel buffer blocks and raytracing scene data.

Creates the backing GL_TEXTURE_BUFFER (tbo) and its sampling texture (tex), then uploads data via set_data(). gl_internal_format overrides the format set_data() would otherwise infer from data's shape/dtype (see _infer_format).

data = None instance-attribute #

internal_format = gl_internal_format instance-attribute #

tbo = glGenBuffers(1) instance-attribute #

tex = glGenTextures(1) instance-attribute #

bind(texture_unit) #

Activates texture_unit and binds this buffer's sampling texture to it, ready for texelFetch() in GLSL.

destroy() #

Deletes this object's GL texture and buffer.

get_data() #

Returns the data last passed to set_data(), already coerced to the buffer's actual dtype/format.

get_max_size() staticmethod #

Returns the GPU's max texture buffer size in bytes (GL_MAX_TEXTURE_BUFFER_SIZE).

set_data(data) #

Uploads data into the buffer object and (re)binds it as a buffer texture. The GL internal format is inferred from data's shape/ dtype only if gl_internal_format wasn't fixed at construction - once set (either way), every later call reuses that same format regardless of what a new data array's own shape might imply.

unbind() #

Unbinds GL_TEXTURE_BUFFER from whichever unit is currently active.

UBOBuffer(data) #

Bases: Buffer

The OpenGL 3.3 implementation of the buffer class.

Allocates a GL_UNIFORM_BUFFER sized for data and uploads it immediately.

buffer_size = data.nbytes instance-attribute #

data = data instance-attribute #

ubo = glGenBuffers(1) instance-attribute #

bind(point) #

Binds this UBO to uniform binding point point - remembered so unbind() can release the same point later.

destroy() #

Deletes this UBO's underlying GL buffer.

get_data() #

Returns the data last passed to set_data() (or the constructor) - NOT updated by update() below, which writes to the GPU buffer directly without touching this bookkeeping.

get_max_size() staticmethod #

Returns the GPU's max uniform block size in bytes (GL_MAX_UNIFORM_BLOCK_SIZE).

set_data(new_data) #

Replaces this UBO's contents with new_data, reallocating the GPU buffer first if its byte size changed.

unbind() #

Unbinds this UBO from whatever binding point bind() last used.

update(data, offset=0) #

Uploads data into this UBO starting at byte offset, without updating self.data/self.buffer_size the way set_data() does - for partial updates where get_data()'s bookkeeping isn't expected to reflect every byte of the live GPU buffer.