moderngl_window.loaders
- class moderngl_window.loaders.base.BaseLoader(meta: ResourceDescription)[source]
Bases:
objectBase loader class for all resources
- property ctx: Context
ModernGL context
- Type:
moderngl.Context
- file_extensions: list[list[str]] = []
A list defining the file extensions accepted by this loader.
Example:
# Loader will match .xyz and .xyz.gz files. file_extensions = [ ['.xyz'], ['.xyz', '.gz'], ]
- find_data(path: str | Path | None) Path | None[source]
Find resource using data finders.
This is mainly a shortcut method to simplify the task.
- Parameters:
path – Path to resource
- find_program(path: str | Path | None) Path | None[source]
Find resource using program finders.
This is mainly a shortcut method to simplify the task.
- Parameters:
path – Path to resource
- find_scene(path: str | Path | None) Path | None[source]
Find resource using scene finders.
This is mainly a shortcut method to simplify the task.
- Parameters:
path – Path to resource
- find_texture(path: str | Path | None) Path | None[source]
Find resource using texture finders.
This is mainly a shortcut method to simplify the task.
- Parameters:
path – Path to resource
- kind = 'unknown'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() Any[source]
Loads a resource.
When creating a loader this is the only method that needs to be implemented.
- Returns:
The loaded resource
- classmethod supports_file(meta: ResourceDescription) bool[source]
Check if the loader has a supported file extension.
What extensions are supported can be defined in the
file_extensionsclass attribute.
Text
- class moderngl_window.loaders.data.text.Loader(meta: ResourceDescription)[source]
Bases:
BaseLoader- file_extensions: list[list[str]] = [['.txt']]
A list defining the file extensions accepted by this loader.
Example:
# Loader will match .xyz and .xyz.gz files. file_extensions = [ ['.xyz'], ['.xyz', '.gz'], ]
- kind = 'text'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
JSON
- class moderngl_window.loaders.data.json.Loader(meta: ResourceDescription)[source]
Bases:
BaseLoader- file_extensions: list[list[str]] = [['.json']]
A list defining the file extensions accepted by this loader.
Example:
# Loader will match .xyz and .xyz.gz files. file_extensions = [ ['.xyz'], ['.xyz', '.gz'], ]
- kind = 'json'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
Binary
- class moderngl_window.loaders.data.binary.Loader(meta: ResourceDescription)[source]
Bases:
BaseLoader- kind = 'binary'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
Program (Separate)
- class moderngl_window.loaders.program.separate.Loader(meta: ResourceDescription)[source]
Bases:
BaseLoader- kind = 'separate'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() Program | ComputeShader | ReloadableProgram[source]
Loads a shader program were each shader is a separate file.
This detected and dictated by the
kindin theProgramDescription.- Returns:
The Program instance
- Return type:
moderngl.Program
- meta: ProgramDescription
Program (Single)
- class moderngl_window.loaders.program.single.Loader(meta: ResourceDescription)[source]
Bases:
BaseLoader- kind = 'single'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() Program[source]
Loads a shader program from a single glsl file.
Each shader type is separated by preprocessors
VERTEX_SHADER
FRAGMENT_SHADER
GEOMETRY_SHADER
TESS_CONTROL_SHADER
TESS_EVALUATION_SHADER
Example:
#version 330 #if defined VERTEX_SHADER in vec3 in_position; in vec2 in_texcoord_0; out vec2 uv0; void main() { gl_Position = vec4(in_position, 1); uv0 = in_texcoord_0; } #elif defined FRAGMENT_SHADER out vec4 fragColor; uniform sampler2D texture0; in vec2 uv0; void main() { fragColor = texture(texture0, uv0); } #endif
- Returns:
The Program instance
- Return type:
moderngl.Program
- meta: ProgramDescription
GLTF2
- class moderngl_window.loaders.scene.gltf2.Loader(meta: SceneDescription)[source]
Bases:
BaseLoaderLoader for GLTF 2.0 files
- file_extensions: list[list[str]] = [['.gltf'], ['.glb']]
A list defining the file extensions accepted by this loader.
Example:
# Loader will match .xyz and .xyz.gz files. file_extensions = [ ['.xyz'], ['.xyz', '.gz'], ]
- kind = 'gltf'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() Scene[source]
Load a GLTF 2 scene including referenced textures.
- Returns:
The scene instance
- Return type:
- meta: SceneDescription
- supported_extensions: list[str] = ['KHR_draco_mesh_compression', 'KHR_materials_unlit']
Supported GLTF extensions https://github.com/KhronosGroup/glTF/tree/master/extensions
Wavefront / OBJ
- class moderngl_window.loaders.scene.wavefront.Loader(meta: SceneDescription)[source]
Bases:
BaseLoaderLoad wavefront/obj files
- file_extensions: list[list[str]] = [['.obj'], ['.obj', '.gz'], ['.bin']]
A list defining the file extensions accepted by this loader.
Example:
# Loader will match .xyz and .xyz.gz files. file_extensions = [ ['.xyz'], ['.xyz', '.gz'], ]
- kind = 'wavefront'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() Scene[source]
Loads a wavefront/obj file including materials and textures
- Returns:
The Scene instance
- Return type:
- meta: SceneDescription
STL
- class moderngl_window.loaders.scene.stl.Loader(meta: ResourceDescription)[source]
Bases:
BaseLoader- file_extensions: list[list[str]] = [['.stl'], ['.stl', '.gz']]
A list defining the file extensions accepted by this loader.
Example:
# Loader will match .xyz and .xyz.gz files. file_extensions = [ ['.xyz'], ['.xyz', '.gz'], ]
- kind = 'stl'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
TextureArray
- class moderngl_window.loaders.texture.array.Loader(meta: ResourceDescription)[source]
Bases:
PillowLoader- kind = 'array'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() TextureArray[source]
Load a texture array as described by the supplied
TextureDescription`- Returns:
The TextureArray instance
- Return type:
moderngl.TextureArray
- meta: TextureDescription
TextureCube
- class moderngl_window.loaders.texture.cube.Loader(meta: ResourceDescription)[source]
Bases:
PillowLoader- kind = 'cube'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() TextureCube[source]
Load a texture cube as described by the supplied
TextureDescription`- Returns:
The TextureArray instance
- Return type:
moderngl.TextureCube
- meta: TextureDescription
Icon
- class moderngl_window.loaders.texture.icon.IconLoader(meta: ResourceDescription)[source]
Bases:
BaseLoader- find_icon() Path[source]
Find resource using texture finders.
This is mainly a shortcut method to simplify the task.
- Parameters:
path – Path to resource
- kind = 'icon'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- meta: TextureDescription
Texture2D
- class moderngl_window.loaders.texture.t2d.Loader(meta: ResourceDescription)[source]
Bases:
PillowLoader- kind = '2d'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
Pillow
- class moderngl_window.loaders.texture.pillow.PillowLoader(meta: ResourceDescription)[source]
Bases:
BaseLoaderBase loader using PIL/Pillow
- image: Image
- kind = '__unknown__'
The kind of resource this loaded supports. This can be used when file extensions is not enough to decide what loader should be selected.
- load() Texture | TextureArray | TextureCube | Texture3D[source]
Loads a resource.
When creating a loader this is the only method that needs to be implemented.
- Returns:
The loaded resource
- meta: TextureDescription