Skip to content

texture

FreeBodyEngine.graphics.gl33.texture #

GLTextureManager(*args, **kwargs) #

Bases: TextureManager

The GL 3.3 implementation of TextureManager: owns the real GL texture objects behind every standalone/atlas/font-atlas/stack id, and does the actual glActiveTexture/glBindTexture slot bookkeeping (texture_slots/ slot_textures/next_texture_slot) that maps an engine-side id to a live GPU texture unit for the current draw.

Initializes the (empty) slot-tracking dicts and queries the driver's actual texture-unit limit (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS) into max_texture_slots, so _allocate_slot can refuse to overrun real hardware capacity instead of silently binding past it.

max_texture_slots = glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS) instance-attribute #

next_texture_slot = 0 instance-attribute #

slot_textures = {} instance-attribute #

texture_slots = {} instance-attribute #

begin_draw() #

Resets texture-unit allocation for a fresh draw: every previously-bound slot is forgotten and next_texture_slot restarts at 0. Called once per GLShader.draw_mesh() (see that method), so each mesh's material rebinds its textures from unit 0 rather than accumulating allocations across the whole frame - texture-buffer bindings a compute kernel manages itself (see GLComputeShader's own _next_unit) are deliberately independent of this and are never reset by it.

bind_texture(id) #

Resolves id to its underlying GL_TEXTURE_2D and allocates (or reuses) a texture unit for it via _allocate_slot, warning and returning None instead if id doesn't resolve to a real texture.

bind_texture_stack(id) #

Like bind_texture(), but for a GL_TEXTURE_2D_ARRAY-backed TextureStack id - allocates (or reuses) a texture unit for the whole array, not per-layer.

gen_id() #

Generates a fresh unique engine-side texture id (a uuid4) to key one of standalone_textures/atlas_textures/texture_stacks.

get_atlas_id_from_path(file_path) #

Reverse-looks-up the engine-side id already registered for the atlas at file_path, or None if that atlas hasn't been uploaded yet - used by _create_atlas_texture to dedupe repeated sub-images from the same atlas file onto one GL texture.

reload_standalone_texture(id, data) #

Re-decodes data into the same GL texture this standalone Texture id already wraps (glTexImage2D on the existing tex_id, no glGenTextures) - every Material/Sprite holding a reference to the Texture object sees the new image with no extra wiring, since neither the engine-side id nor the underlying GL texture name changes. Used by dev-mode hot reload (core/files/hot_reload.py); not meaningful for an atlas-backed or font-atlas Texture, only one created by _create_standalone_texture().

set_texture_filter(id, nearest) #

Looks up id's underlying GL texture and applies nearest- or linear-filtered sampling to both minification and magnification (see the inline comment below for why minification specifically uses the _MIPMAP_NEAREST variant rather than plain GL_NEAREST).

wrap_external_texture(gl_texture_id) #

Registers a GL_TEXTURE_2D that wasn't created by this manager (e.g. a compute-dispatch FBO's color attachment) under a generated id, so it can flow through the same Texture/slot-binding machinery as any other texture - used by GLComputeShader.get_output_texture().