vulk.graphic package

Submodules

vulk.graphic.camera module

class vulk.graphic.camera.Camera[source]

Bases: abc.ABC

unproject(position, viewport_x, viewport_y, viewport_width, viewport_height)[source]

Unproject position to view matrix. Allow to get world coordinate from screen coordinate.

Parameters:

  • position: Vector3 screen position right-handed.
    z(0) = near plane, z(1) = far plane
update(update_frustum=True)[source]
class vulk.graphic.camera.OrthographicCamera(viewport_width, viewport_height)[source]

Bases: vulk.graphic.camera.Camera

to_orthographic(viewport_width, viewport_height)[source]
update(update_frustum=True)[source]
class vulk.graphic.camera.PerspectiveCamera(fov, viewport_width, viewport_height)[source]

Bases: vulk.graphic.camera.Camera

update(update_frustum=True)[source]

vulk.graphic.mesh module

This module contains mesh

class vulk.graphic.mesh.Mesh(context, max_vertices, max_indices, attributes)[source]

Bases: object

bind(cmd)[source]

Bind the buffers during command buffer registering

Parameters:

  • command: CommandBufferRegister
draw(cmd, offset=0, count=0)[source]

Draw the mesh during command buffer registration

Parameters:

  • cmd: CommandBufferRegister
  • offset: Start drawing at offset vertices
  • count: Draw count vertices

Note: `offset` and `count` target indices if mesh is indexed

set_indices(indices, offset=0)[source]

Set indices of mesh

Parameters:

  • indices: list of float
  • offset: Offset in mesh indices array

Note: Mesh must be indexed

set_vertex(index, vertex)[source]

Set one vertex of the mesh at position index

Parameters:

  • index: Vertex index
  • vertex: Vertex data (tuple format)

Exemple:

For a mesh with two attributes (2 components and 4 components):

` vertex = ([x, y], [r, g, b, a]) mesh.set_vertex(idx, vertex) `

**Note: Vertex data type depends on VertexAttributes of the mesh.
It must be a tuple containing an array for each attributes**
**Note: Once mesh vertices are updated, you need to upload the mesh
to take into account the changes.**
set_vertices(vertices, offset=0)[source]

Set vertices of the mesh. Report to set_vertex, it works the same but it waits for an array of vertex.

Parameters:

  • vertices: list of Vertex data (see set_vertex)
  • offset: Offset in the mesh vertices array
upload(context)[source]

Upload vertices and indices to graphic card

Parameters:

  • context: VulkContext
upload_indices(context)[source]

Upload indices to graphic card

Parameters:

  • context: VulkContext

Note: Mesh must be indexed

upload_vertices(context)[source]

Upload vertices to graphic card

Parameters:

  • context: VulkContext
class vulk.graphic.mesh.VertexAttribute(location, attribute_format)[source]

Bases: object

class vulk.graphic.mesh.VertexAttributes(attributes)[source]

Bases: object

size

vulk.graphic.texture module

This module allows to load texture and to sample from it

class vulk.graphic.texture.BinaryTexture(context, width, height, texture_format, raw_bitmap, mip_levels=1)[source]

Bases: vulk.graphic.texture.RawTexture

RawTexture with provided bitmap buffer.

Warning: You are responsible of the bitmap buffer

generate_mipmaps(context)[source]

Generate mipmap automatically

This method generates mipmap on processor and then upload it on GPU. This method is heavy, use it with care. You shouldn’t need to call it several times unless raw_bitmap is modified.

You must call upload to update the texture in Graphic Card.

Args:
context (VulkContext)
init_bitmap()[source]

Initialize bitmap array with raw_bitmap

upload_buffer(context, mip_level)[source]

Upload bitmap into Vulkan memory

Args:
context (VulkContext) mip_level (int): Level of mip
class vulk.graphic.texture.HighQualityTexture(context, path_file, anisotropy=0)[source]

Bases: vulk.graphic.texture.Texture

Texture with best quality

To get best quality, we generate automatically all mipmaps and set filter to trilinear or anisotropy filtering. It’s really just a helper class.

init_sampler(context)[source]
class vulk.graphic.texture.RawTexture(context, width, height, texture_format, mip_levels=1)[source]

Bases: object

A Raw texture is not initialized with an image file but can be filled manually

init_bitmap()[source]

Return the numpy array containing bitmap

init_sampler(context)[source]
init_texture(context, mip_levels)[source]
init_view(context)[source]
set_sampler(context, mag_filter=<Filter.NONE: 0>, min_filter=<Filter.NONE: 0>, mipmap_mode=<SamplerMipmapMode.NONE: 0>, address_mode_u=<SamplerAddressMode.NONE: 0>, address_mode_v=<SamplerAddressMode.NONE: 0>, address_mode_w=<SamplerAddressMode.NONE: 0>, anisotropy_enable=False, max_anisotropy=16)[source]

Set the texture sampler

By default, sampler is configured for the best performance. If you want better quality, you must enable manually bilinear, trilinear or anisotropic filtering.

Args:
context (VulkContext): Context mag_filter (Filter): Magnification filter to apply to lookups min_filter (Filter): Minification filter to apply to lookups mipmap_mode (SamplerMipmapMode): Mipmap filter to apply to lookups address_mode_u (SamplerAddressMode): address_mode_v (SamplerAddressMode): address_mode_w (SamplerAddressMode): anisotropy_enable (bool): Whether to enable anisotropy max_anisotropy (int): Anisotropy value clamp
set_view(context)[source]

Set texture view

Args:
context (VulkContext)
upload(context)[source]

Make texture accessible for shader

If this function is not called, the texture can’t be used. When all your buffers are uploaded, call this function

class vulk.graphic.texture.Texture(context, path_file, mip_levels=1)[source]

Bases: vulk.graphic.texture.BinaryTexture

BinaryTexture with file managing

static components_to_format(components)[source]

Convert number of channel components in image to Vulkan format

Parameters:

  • components: Number of components
class vulk.graphic.texture.TextureRegion(texture, u=0, v=0, u2=1, v2=1)[source]

Bases: object

Defines a rectangular area of a texture. The coordinate system used has its origin in the upper left corner with the x-axis pointing to the right and the y axis pointing downwards.

static from_pixels(texture, x, y, width, height)[source]

Create a TextureRegion with pixel coordinates

Args:
texture (Texture): Base texture of region x (int): X offset (left to right) y (int): Y offset (top to bottom) width (int): Region width height (int): Region height
Returns:
The new TextureRegion
set_region(u, u2, v, v2)[source]

Set coordinate relatively to texture size

Parameters:

  • u, u2: X coordinate relative to texture size
  • v, v2: Y coordinate relative to texture size
set_region_pixel(x, y, width, height)[source]

Set coordinate relatively to pixel size

Parameters:

  • x: X coordinate of the texture
  • y: Y coordinate of the texture
  • width: Width of the region
  • height: Height of the region
set_texture(texture)[source]

Set texture of TextureRegion

Parameters:

  • texture: RawTexture

vulk.graphic.uniform module

class vulk.graphic.uniform.UniformAttribute(shape_type, data_type)[source]

Bases: object

class vulk.graphic.uniform.UniformAttributes(attributes)[source]

Bases: object

size
class vulk.graphic.uniform.UniformBlock(context, attributes)[source]

Bases: object

set_uniform(index, uniform)[source]

Update uniform at index position

Parameters:

  • index: Position of uniform in UniformAttributes
  • uniform: Uniform data to pass (flattened)
upload(context)[source]
class vulk.graphic.uniform.UniformShapeType[source]

Bases: enum.IntEnum

An enumeration.

MATRIX4 = 16

vulk.graphic.util module

class vulk.graphic.util.Color(r=1, g=1, b=1, a=1)[source]

Bases: object

a
b
g
r

Module contents