moderngl_window.meta
- class moderngl_window.meta.base.ResourceDescription(**kwargs: Any)[source]
Description of any resource. Resource descriptions are required to load a resource. This class can be extended to add more specific properties.
- property attrs: dict[str, Any]
All keywords arguments passed to the resource
- Type:
dict
- default_kind = ''
The default kind for this resource type
- Type:
str
- property kind: str
default resource kind.
The resource
kindis directly matched with thekindin loader classes.This property also supports assignment and is useful if the
kindis detected based in the the attribute values.description.kind = 'something'
- Type:
str
- property label: str | None
optional name for the resource
Assigning a label is not mandatory but can help when aliasing resources. Some prefer to preload all needed resources and fetch them later by the label. This can he a lot less chaotic in larger applications.
- Type:
str
- property loader_cls: type | None
The loader class for this resource.
This property is assigned to during the loading stage were a loader class is assigned based on the kind.
- Type:
type
- property path: str | None
The path to a resource when a single file is specified
- Type:
str
- property resolved_path: Path | None
The resolved path by a finder.
The absolute path to the resource can optionally be assigned by a loader class.
- Type:
pathlib.Path
- resource_type = ''
A unique identifier for the resource type
- Type:
str
- class moderngl_window.meta.data.DataDescription(path: str | None = None, kind: str | None = None, **kwargs: Any)[source]
Bases:
ResourceDescriptionDescribes data file to load.
This is a generic resource description type for loading resources that are not textures, programs and scenes. That loaded class is used depends on the
kindor the file extension.Currently used to load:
text files
json files
binary files
# Describe a text file. Text loader is used based on file extension DataDescription(path='data/text.txt') # Describe a json file. Json loader is used based on file extension DataDescription(path='data/data.json') # Describe a binary file. Specify a binary loader should be used. DataDescription(path='data/data.bin', kind='binary')
- default_kind: str = ''
The default kind for this resource type
- Type:
str
- resource_type = 'data'
A unique identifier for the resource type
- Type:
str
- class moderngl_window.meta.program.ProgramDescription(path: str | None = None, kind: str | None = None, reloadable: bool = False, vertex_shader: str | None = None, geometry_shader: str | None = None, fragment_shader: str | None = None, tess_control_shader: str | None = None, tess_evaluation_shader: str | None = None, compute_shader: str | None = None, defines: dict[str, Any] | None = None, varyings: list[str] | None = None, **kwargs: Any)[source]
Bases:
ResourceDescriptionDescribes a program to load
By default a program can be loaded in the following ways:
By supplying a path to s single glsl file containing all shaders
By supplying several paths to separate files containing each shader type. For example
vertex_shader,fragment_shader.. etc.
# Single glsl file containing all shaders ProgramDescription(path='programs/myprogram.glsl') # Multiple shader files ProgramDescription( vertex_shader='programs/myprogram_vs.glsl'. fragment_shader='programs/myprogram_fs.glsl'. geometry_shader='programs/myprogram_gs.glsl'. )
- property compute_shader: str | None
Relative path to compute shader
- Type:
str
- default_kind = ''
The default kind for this resource type
- Type:
str
- property defines: dict[str, Any]
Dictionary with define values to replace in the source
- Type:
dict
- property fragment_shader: str | None
Relative path to fragment shader
- Type:
str
- property geometry_shader: str | None
Relative path to geometry shader
- Type:
str
- property reloadable: bool | None
if this program is reloadable
- Type:
bool
- resource_type = 'programs'
A unique identifier for the resource type
- Type:
str
- property tess_control_shader: str | None
Relative path to tess control shader
- Type:
str
- property tess_evaluation_shader: str | None
Relative path to tessellation evaluation shader
- Type:
str
- property varyings: list[str]
List of varying names for transform shaders
- Type:
list
- property vertex_shader: str | None
Relative path to vertex shader
- Type:
str
- class moderngl_window.meta.scene.SceneDescription(path: str | None = None, kind: str | None = None, cache: bool = False, attr_names: type[~moderngl_window.geometry.attributes.AttributeNames] = <class 'moderngl_window.geometry.attributes.AttributeNames'>, **kwargs: ~typing.Any)[source]
Bases:
ResourceDescriptionDescribes a scene to load.
The correct loader is resolved by looking at the file extension. This can be overridden by specifying a
kindthat maps directly to a specific loader class.# Wavefront/obj file SceneDescription(path='scenes/cube.obj') # stl file SceneDescription(path='scenes/crater.stl') # GLTF 2 file SceneDescription(path='scenes/sponza.gltf')
The user can also override what buffer/attribute names should be used by specifying
attr_names.A
cacheoption is also available as some scene loaders supports converting the file into a different format on the fly to speed up loading.- property attr_names: AttributeNames
Attribute name config
- Type:
- property cache: bool
Use cache feature in scene loader
- Type:
bool
- default_kind = ''
The default kind for this resource type
- Type:
str
- resource_type = 'scenes'
A unique identifier for the resource type
- Type:
str
- class moderngl_window.meta.texture.TextureDescription(path: str | None = None, kind: str | None = None, flip: bool = True, flip_x: bool = False, flip_y: bool = True, mipmap: bool = False, mipmap_levels: tuple[int, int] | None = None, anisotropy: float = 1.0, image: Image | None = None, layers: int | None = None, pos_x: str | None = None, pos_y: str | None = None, pos_z: str | None = None, neg_x: str | None = None, neg_y: str | None = None, neg_z: str | None = None, **kwargs: Any)[source]
Bases:
ResourceDescriptionDescribes a texture to load.
Example:
# Loading a 2d texture TextureDescription(path='textures/wood.png') # Loading a 2d texture with mimpmaps with anisotropy TextureDescription(path='textures/wood.png', mipmap=True, anisotropy=16.0) # Loading texture array containing 10 layers TextureDescription(path='textures/tiles.png', layers=10, kind='array')
- property anisotropy: float | None
Number of samples for anisotropic filtering
- Type:
float
- default_kind = '2d'
The default kind for this resource type
- Type:
str
- property flip_x: bool | None
If the image should be flipped horizontally (left to right)
- Type:
bool
- property flip_y: bool | None
If the image should be flipped vertically (top to bottom)
- Type:
bool
- property image: Image | None
PIL image when loading embedded resources
- Type:
Image
- property layers: int | None
Number of layers in texture array
- Type:
int
- property mipmap: bool | None
If mipmaps should be generated
- Type:
bool
- property mipmap_levels: tuple[int, int] | None
base, max_level for mipmap generation
- Type:
tuple[int, int]
- property neg_x: str | None
Path to negative x in a cubemap texture
- Type:
str
- property neg_y: str | None
Path to negative y in a cubemap texture
- Type:
str
- property neg_z: str | None
Path to negative z in a cubemap texture
- Type:
str
- property pos_x: str | None
Path to positive x in a cubemap texture
- Type:
str
- property pos_y: str | None
Path to positive y in a cubemap texture
- Type:
str
- property pos_z: str | None
Path to positive z in a cubemap texture
- Type:
str
- resource_type = 'textures'
A unique identifier for the resource type
- Type:
str