Skip to content

shader

FreeBodyEngine.graphics.gl44.shader #

GL_TYPE_NAMES = {GL_INT: 'int', GL_INT_VEC2: 'ivec2', GL_INT_VEC3: 'ivec3', GL_INT_VEC4: 'ivec4', GL_FLOAT: 'float', GL_FLOAT_VEC2: 'vec2', GL_FLOAT_VEC3: 'vec3', GL_FLOAT_VEC4: 'vec4', GL_FLOAT_MAT2: 'mat2', GL_FLOAT_MAT3: 'mat3', GL_FLOAT_MAT4: 'mat4', GL_BOOL: 'bool', GL_SAMPLER_2D: 'sampler2D', GL_SAMPLER_2D_ARRAY: 'sampler2DArray'} module-attribute #

GL44Shader(vertex_source, fragment_source, injector, geometry_source=None) #

Bases: Shader

The GL 4.4 implementation of Shader: compiles FBUSL source via GL44Generator into a real GL program, introspects its uniforms, and caches each uniform's last-set value so set_uniform() can skip a redundant glUniform* call when the value hasn't actually changed.

Compiles vertex_source/fragment_source(/geometry_source) into a linked GL program (via GL44Generator) and introspects its active uniforms into self.uniforms, seeding uniform_cache with None for each so the first set_uniform() call for any uniform always goes through.

uniform_cache = {} instance-attribute #

uniforms = {} instance-attribute #

check_val_type(val, gl_type, name) #

Validates that val is an acceptable Python value for a uniform of GL type gl_type - logging an engine error and returning False if not. Color/Vector/Vector3 are accepted directly for the vector GL types they map onto, alongside a plain tuple/list/ndarray of the right length.

get_uniform(name) #

Returns the introspected GL44Uniform record (location/size/type) for uniform name.

rebuild(injector=..., vertex_source=None, fragment_source=None, geometry_source=...) #

See GLShader.rebuild() (graphics/gl33/shader.py) for why vertex_source/fragment_source default to re-using self's existing ones rather than being required, and why geometry_source's default is the ... sentinel rather than None.

set_buffer(name, buffer) #

Binds buffer to the uniform block declared as name in this shader's source (self.data['buffers'], populated by generator-produced metadata) - warns instead of raising if name isn't a known buffer block.

set_uniform(name, val) #

Sets uniform name to val, after check_val_type() validates it. Skips the actual glUniform* call (and the cache update) if val equals the value already cached for this uniform, avoiding redundant driver calls when the same value is set every frame - as material properties typically are.

setup_uniforms() #

Populates self.uniforms from the program's active uniforms (glGetActiveUniform), normalizing the name PyOpenGL hands back (which can come as str, bytes, or a numpy array depending on driver/binding) to a plain, null-terminated string.

use() #

Activates this shader's program, updates the TIME builtin uniform if the shader declares one, and binds every currently-cached texture/texture-stack uniform (see _bind_textures).

GL44Uniform(location, size, type) dataclass #

A shader program's introspected uniform: its GL location, array size (>1 for a uniform array, e.g. a sampler2D[N]), and GL type enum.

location instance-attribute #

size instance-attribute #

type instance-attribute #

compile_shader(source, shader_type) #

Compiles source as a shader_type GL shader object, raising RuntimeError with the driver's compile log on failure.

create_shader_program(vertex_src, fragment_src, geometry_src=None) #

Compiles and links vertex_src/fragment_src (and geometry_src, if given) into a linked GL program, raising RuntimeError with the driver's log on a compile or link failure. The per-stage shader objects are deleted once linked - only the program is kept.

set_gl_uniform(loc, gl_type, val) #

The actual glUniform/glUniformMatrix dispatch, factored out of GL44Shader.set_uniform so GL44ComputeShader (graphics/gl44/compute.py) can reuse it instead of duplicating this same type-dispatch table. Assumes the target program is already current (glUseProgram).