Texture3D¶
-
class
moderngl.Texture3D¶ A Texture is an OpenGL object that contains one or more images that all have the same image format. A texture can be used in two ways. It can be the source of a texture access from a Shader, or it can be used as a render target.
A Texture3D object cannot be instantiated directly, it requires a context. Use
Context.texture3d()to create one.
Create¶
-
Context.texture3d(size, components, data=None, alignment=1, dtype='f1') → Texture3D Create a
Texture3Dobject.Parameters: - size (tuple) – The width, height and depth of the texture.
- components (int) – The number of components 1, 2, 3 or 4.
- data (bytes) – Content of the texture.
Keyword Arguments: - alignment (int) – The byte alignment 1, 2, 4 or 8.
- dtype (str) – Data type.
Returns: Texture3Dobject
Methods¶
-
Texture3D.read(alignment=1) → bytes¶ Read the content of the texture into a buffer.
Keyword Arguments: alignment (int) – The byte alignment of the pixels. Returns: bytes
-
Texture3D.read_into(buffer, alignment=1, write_offset=0)¶ Read the content of the texture into a buffer.
Parameters: buffer (bytearray) – The buffer that will receive the pixels.
Keyword Arguments: - alignment (int) – The byte alignment of the pixels.
- write_offset (int) – The write offset.
-
Texture3D.write(data, viewport=None, alignment=1)¶ Update the content of the texture.
Parameters: - data (bytes) – The pixel data.
- viewport (tuple) – The viewport.
Keyword Arguments: alignment (int) – The byte alignment of the pixels.
-
Texture3D.build_mipmaps(base=0, max_level=1000)¶ Generate mipmaps.
This also changes the texture filter to
LINEAR_MIPMAP_LINEAR, LINEAR(Will be removed in6.x)Keyword Arguments: - base (int) – The base level
- max_level (int) – The maximum levels to generate
-
Texture3D.use(location=0)¶ Bind the texture.
Parameters: location (int) – The texture location. Same as the integer value that is used for sampler3D uniforms in the shaders. The value 0will bind the texture to theGL_TEXTURE0binding point.
Attributes¶
-
Texture3D.repeat_x¶ The x repeat flag for the texture (Default
True)Example:
# Enable texture repeat (GL_REPEAT) texture.repeat_x = True # Disable texture repeat (GL_CLAMP_TO_EDGE) texture.repeat_x = False
Type: bool
-
Texture3D.repeat_y¶ The y repeat flag for the texture (Default
True)Example:
# Enable texture repeat (GL_REPEAT) texture.repeat_y = True # Disable texture repeat (GL_CLAMP_TO_EDGE) texture.repeat_y = False
Type: bool
-
Texture3D.repeat_z¶ The z repeat flag for the texture (Default
True)Example:
# Enable texture repeat (GL_REPEAT) texture.repeat_z = True # Disable texture repeat (GL_CLAMP_TO_EDGE) texture.repeat_z = False
Type: bool
-
Texture3D.filter¶ The filter of the texture.
Type: tuple
-
Texture3D.swizzle¶ The swizzle mask of the texture (Default
'RGBA').The swizzle mask change/reorder the
vec4value returned by thetexture()function in a GLSL shaders. This is represented by a 4 character string were each character can be:'R' GL_RED 'G' GL_GREEN 'B' GL_BLUE 'A' GL_ALPHA '0' GL_ZERO '1' GL_ONE
Example:
# Alpha channel will always return 1.0 texture.swizzle = 'RGB1' # Only return the red component. The rest is masked to 0.0 texture.swizzle = 'R000' # Reverse the components texture.swizzle = 'ABGR'
Type: str
-
Texture3D.width¶ The width of the texture.
Type: int
-
Texture3D.height¶ The height of the texture.
Type: int
-
Texture3D.depth¶ The depth of the texture.
Type: int
-
Texture3D.size¶ The size of the texture.
Type: tuple
-
Texture3D.dtype¶ Data type.
Type: str
-
Texture3D.components¶ The number of components of the texture.
Type: int
-
Texture3D.glo¶ The internal OpenGL object. This values is provided for debug purposes only.
Type: int
-
Texture3D.extra¶ Any - Attribute for storing user defined objects