Textures

Context.texture(size, components, data=None, samples=0, floats=False) → Texture

Create a Texture.

Parameters:
  • size (tuple) – The width and height of the texture.
  • components (int) – The number of components 1, 2, 3 or 4.
  • data (bytes) – Content of the texture.
Keyword Arguments:
 
  • samples (int) – The number of samples. Value 0 means no multisample format.
  • alignment (int) – The byte alignment 1, 2, 4 or 8.
  • floats (bool) – Use floating point precision.
Returns:

texture

Return type:

Texture

Context.depth_texture(size, data=None, samples=0) → Texture

Create a Texture.

Parameters:
  • size (tuple) – The width and height of the texture.
  • data (bytes) – Content of the texture.
Keyword Arguments:
 
  • samples (int) – The number of samples. Value 0 means no multisample format.
  • alignment (int) – The byte alignment 1, 2, 4 or 8.
Returns:

depth texture

Return type:

Texture

Context.texture3d(size, components, data=None, floats=False) → Texture3D

Create a Texture3D.

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.
  • floats (bool) – Use floating point precision.
Returns:

texture

Return type:

Texture3D

class Texture

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 Texture object cannot be instantiated directly, it requires a context. Use Context.texture() or Context.depth_texture() to create one.

read(alignment=1) → bytes

Read the content of the texture into a buffer.

Keyword Arguments:
 alignment (int) – The byte alignment of the pixels.
Returns:the pixels
Return type:bytes
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.
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.

build_mipmaps(base=0, max_level=1000)

Generate mipmaps.

use(location=0)

Bind the texture.

Parameters:location (int) – The texture location. Same as the integer value that is used for sampler2D uniforms in the shaders. The value 0 will bind the texture to the GL_TEXTURE0 binding point.
repeat_x

bool – The repeat_x of the texture.

repeat_y

bool – The repeat_y of the texture.

filter

TextureFilter – The filter of the texture.

swizzle

str – The swizzle of the texture.

width

int – The width of the texture.

height

int – The height of the texture.

size

tuple – The size of the texture.

components

int – The number of components of the texture.

samples

int – The number of samples of the texture.

floats

bool – Is the texture using floats?

depth

bool – Is the texture a depth texture?

class 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.

read(alignment=1) → bytes

Read the content of the texture into a buffer.

Keyword Arguments:
 alignment (int) – The byte alignment of the pixels.
Returns:the pixels
Return type:bytes
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.
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.

build_mipmaps(base=0, max_level=1000)

Generate mipmaps.

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 0 will bind the texture to the GL_TEXTURE0 binding point.
repeat_x

bool – The repeat_x of the texture.

repeat_y

bool – The repeat_y of the texture.

repeat_z

bool – The repeat_z of the texture.

filter

TextureFilter – The filter of the texture.

swizzle

str – The swizzle of the texture.

width

int – The width of the texture.

height

int – The height of the texture.

depth

int – The depth of the texture.

size

tuple – The size of the texture.

components

int – The number of components of the texture.

floats

bool – Is the texture using floats?