texture
FreeBodyEngine.graphics.texture
#
MAX_TEXTURE_STACK_SIZE = 64
module-attribute
#
Texture(manager, id, uv_rect)
#
The texture object holds no real data, it just acts as a reference to the real texture in the manager.
Stores the manager-owned id this Texture refers to, and the
uv_rect selecting this texture's region within whatever atlas/
standalone image that id resolves to.
TextureManager()
#
Backend-agnostic owner of every texture resource (standalone images,
atlas sub-images, MSDF font atlases, texture-array stacks). Concrete
Texture/TextureStack objects only hold an opaque id back into here, so
all real GPU-texture bookkeeping - creation, slot binding, hot reload,
deletion - lives in one place, keyed off the backend-agnostic ids
gen_id() generates.
Sets up the empty id -> GL-object tracking dicts a concrete backend fills in as textures/atlases/stacks are created.
atlas_textures = {}
instance-attribute
#
current_texture = None
instance-attribute
#
dev_mode = get_flag(DEVMODE, False)
instance-attribute
#
standalone_textures = {}
instance-attribute
#
texture_stacks = {}
instance-attribute
#
set_texture_filter(id, nearest)
#
Switches a texture between nearest-neighbor sampling (crisp pixel
art) and the default linear/mipmap filtering. Called every time a
material using this texture is bound, since the same Texture may be
shared by materials with different filter settings.
TextureStack(manager, id, uv_rects)
#
A fixed set of same-sized image layers uploaded as one texture-array resource (see TextureManager._create_texture_stack/ _create_standalone_texture_stack), sampled by layer index from a shader. Unlike a plain Texture, one UV rect is kept per layer rather than a single rect for the whole thing.
Stores the manager-owned id this stack refers to and its
per-layer UV rects, reshaped to (layers, 4).
slice_texture_cell(texture, pos, grid)
#
Narrows a whole-image Texture down to one [col, row] cell of a
cols x rows grid. (0, 0) is the top-left cell.
Standalone/atlas textures are uploaded flipped on both axes (see
GLTextureManager._create_standalone_texture), so a cell's rect has to be
mirrored into that flipped space the same way whole-image atlas rects
are (see the identical 1.0 - x - w correction in
GLTextureManager._create_atlas_texture) - otherwise every cell would
sample a rotated, unrelated region of the sheet.