vulk.graphic.d2 package

Submodules

vulk.graphic.d2.batch module

BaseBatch module

BaseBatch is used by SpriteBatch and BlockBatch.

class vulk.graphic.d2.batch.BaseBatch(context, size=1000, shaderprogram=None, out_view=None)[source]

Bases: object

begin(context, semaphores=None)[source]

Begin drawing sprites

Parameters:

  • context: VulkContext
  • semaphore: list of Semaphore to wait on before
    starting all drawing operations

Note: `context` is borrowed until `end` call

end()[source]

End drawing of sprite

Parameters:

  • context: VulkContext

Returns:

Semaphore signaled when all drawing operations in SpriteBatch are finished

init_commandpool(context)[source]
init_framebuffer(context)[source]

Create the framebuffer with the final_image (from context)

Parameters:

  • context: VulkContext
init_indices(size)[source]

Initialize mesh’s indices. It’s done only at initialization for better performance.

Parameters:

  • size: Number of blocks to handle
init_pipeline(context)[source]

Initialize pipeline

Here we are to set the Vulkan pipeline.

Parameters:

  • context: VulkContext
init_pipelinelayout(context)[source]

Initialize pipeline layout

Parameters:

  • context: VulkContext
init_renderpass(context)[source]

Initialize BlockBatch renderpass

Parameters:

  • context: VulkContext
init_uniform(context)[source]

Initialize BlockBatch uniforms. It contains only the combined_matrix but you can extend it to add uniforms.

Parameters:

  • context: VulkContext
update_projection(matrix)[source]

Update the projection matrix with matrix

Parameters:

  • matrix: Matrix4
**Note: This function doesn’t keep a reference to the matrix,
it only copies data**
update_transform(matrix)[source]

Update the transfrom matrix with matrix

Parameters:

  • matrix: Matrix4
**Note: This function doesn’t keep a reference to the matrix,
it only copies data**
upload_matrices(context)[source]

Compute combined matrix from transform and projection matrix. Then upload combined matrix.

Parameters:

  • context: VulkContext
class vulk.graphic.d2.batch.BlockBatch(context, size=1000, shaderprogram=None, out_view=None)[source]

Bases: vulk.graphic.d2.batch.BaseBatch

BlockBatch allows to batch lot of block (small and stylized quad) into minimum of draw calls.

draw(properties)[source]

Draw a block with properties

Parameters:

  • properties: BlockProperty
flush()[source]

Flush all draws to graphic card. Currently, flush register and submit command.

Parameters:

  • context: VulkContext
get_default_shaderprogram(context)[source]

Generate a basic shader program if none given

Parameters:

  • context: VulkContext
init_descriptorlayout(context)[source]
init_descriptorpool(context)[source]
init_descriptorsets(context)[source]

Create the descriptor set (for mat4)

init_mesh(context, size)[source]

Initialize the Mesh handling blocks

Parameters:

  • context: VulkContext
  • size: Number of blocks to handle
class vulk.graphic.d2.batch.BlockProperty[source]

Bases: object

Allow to set properties for a draw call

class vulk.graphic.d2.batch.CharBatch(context, size=1000, shaderprogram=None, out_view=None)[source]

Bases: vulk.graphic.d2.batch.SpriteBatch

CharBatch allows to batch chars into minimum of draw calls.

draw_char(fontdata, char, x, y, r=1.0, g=1.0, b=1.0, a=1.0, scale_x=1.0, scale_y=1.0, rotation=0.0)[source]

Draw a char

Args:
fontdata (FontData): Data on font char (str): One character to draw size (float): Size x (int): X position y (int): Y position r (float): Red channel g (float): Green channel b (float): Blue channel a (float): Alpha channel scale_x (float): Scaling on x axis scale_y (float): Scaling on y axis rotation (float): Rotation in radian (clockwise)
get_default_shaderprogram(context)[source]

Generate a basic shader program if nono given

Parameters:

  • context: VulkContext
class vulk.graphic.d2.batch.SpriteBatch(context, size=1000, shaderprogram=None, out_view=None)[source]

Bases: vulk.graphic.d2.batch.BaseBatch

SpriteBatch allows to batch lot of sprites (small quad) into minimum of draw calls.

draw(texture, x, y, width=0, height=0, u=0, v=0, u2=1, v2=1, r=1, g=1, b=1, a=1, scale_x=1, scale_y=1, rotation=0)[source]

Draw texture at position x, y of size width, height

Parameters:

  • texture: RawTexture
  • x: X position
  • y: Y position
  • width: Width
  • heigth: Height
  • u: U texture coordinate
  • v: V texture coordinate
  • r: Red channel
  • g: Green channel
  • b: Blue channel
  • a: Alpha channel
  • scale_x: Scaling on x axis
  • scale_y: Scaling on y axis
  • rotation: Rotation in radian (clockwise)

Note: if width and height are set to 0, we take the image size

draw_region(region, x, y, width, height, r=1, g=1, b=1, a=1, scale_x=1, scale_y=1, rotation=0)[source]

Draw region at position x, y of size width, height

Parameters:

  • region: TextureRegion
  • x: X position
  • y: Y position
  • width: Width
  • heigth: Height
  • r: Red channel
  • g: Green channel
  • b: Blue channel
  • a: Alpha channel
  • scale_x: Scaling on x axis
  • scale_y: Scaling on y axis
  • rotation: Rotation in radian (clockwise)
end()[source]
flush()[source]

Flush all draws to graphic card

Currently, flush register and submit command.

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

Generate a basic shader program if nono given

Parameters:

  • context: VulkContext
get_descriptor(context, texture)[source]

Update descriptor set containing texture

Parameters:

  • context: VulkContext
  • texture: RawTexture to update
init_descriptorlayout(context)[source]

Initialize descriptor layout for one uniform and one texture

Parameters:

  • context: VulkContext
init_descriptorpool(context)[source]

Create the descriptor pool

Parameters:

  • context: VulkContext
init_dspool()[source]
init_mesh(context, size)[source]

Initialize the Mesh handling sprites

Parameters:

  • context: VulkContext
  • size: Number of sprites to handle
class vulk.graphic.d2.batch.SpriteBatchDescriptorPool(descriptorpool, descriptorlayout)[source]

Bases: object

Manage pool of descriptor sets dedicated to spritebatch textures. Theses sets contain uniform buffer and texture.

pull(context)[source]
reset()[source]

vulk.graphic.d2.font module

class vulk.graphic.d2.font.FontData(context, filepath)[source]

Bases: object

Load a BMFont Text file into a FontData

The FontData can be rendered with the CharBatch. See http://www.angelcode.com/products/bmfont/doc/file_format.html

get_kerning(previous_char, current_char)[source]

Get kerning between last and current char

Args:
previous_char (str): Previous character current_char (str): Current character
get_region(char)[source]

Get texture region of char in this FontData

Args:
char (str): One character to find
get_sizes(char)[source]

Get size of char in this FontData

Args:
char (str): One character to find
static load_bmfont(filepath)[source]

Convert the BMFont file into a dict

Args:
filename (str): BMFont file
class vulk.graphic.d2.font.TextRenderer(context, batch=None)[source]

Bases: object

TextRenderer performs computation to draw text

begin(context, semaphores=None)[source]

Start rendering

Args:
context (VulkContext): Context semaphores (list): Semaphore list
draw(fontdata, text, x, y, size, r=1.0, g=1.0, b=1.0, a=1.0, rotation=0.0)[source]

Render text on screen

Args:
fontdata (FontData): Font to render text (str): String to render x (int): X position (from left) y (int): Y position (from top) size (float): Pixel size of font r (float): Red channel g (float): Green channel b (float): Blue channel a (float): Alpha channel rotation (float): Rotation in radian (clockwise)
end()[source]

Stop rendering

Returns:
Semaphore signaled when all drawing operations are finished

vulk.graphic.d2.scene module

This module contains scene related functions and classes

class vulk.graphic.d2.scene.Action[source]

Bases: object

init(widget)[source]

Init action from widget

class vulk.graphic.d2.scene.BaseWidget(parent)[source]

Bases: object

Widget is the base of the scene

All widgets inherit from this class.

add_action(action)[source]

Add action to the widget

Actions are executed when you call update. Be careful, don’t use the same action across several widgets, create a new action each time. Actions are initialized for each widget, if you reuse the same action, it will be initialized two times and the first widget will loose the action

Args:
action (Action): Action to perform
add_child_to_grid(child, column, row)[source]

Called when the child ask a place in the parent grid

add_child_to_place(child, width, height, x, y)[source]
alpha
collect_children()[source]

Return all chidren recursively

color_abs

Absolute color (not depending on parent color)

column_width
grid(column=0, row=0)[source]
grid_position_to_xy(grid_position)[source]
place(width, height, x=0, y=0)[source]
register_child_grid(child, column, row)[source]
remove_action(action)[source]
reshape()[source]
reshape_all()[source]

Ascend all parent until root and ask to reshape all

reshape_grid()[source]
row_width
update(delta)[source]

Method allowing to perform actions

update_grid_size(column, row)[source]
x_rel
y_rel
class vulk.graphic.d2.scene.BatchedScene(context, width, height, renderers=None)[source]

Bases: vulk.graphic.d2.scene.Scene

Faster Scene but with limitations

If your scene doesnét contain overlapping elements, this scene will be faster.

collect_widgets_to_render()[source]

Return a mapping used to render widgets

Returns:
dict[renderer: list[widgets]]
render(context)[source]

Render Scene

Collect renderers and then display all widget by renderer. Renderers are in this order:

  • Block renderer
  • Sprite renderer
  • Text renderer
Args:
context (VulkContext)
Returns:
Semaphore or None if no semaphore
class vulk.graphic.d2.scene.Block(parent, border_colors=None, border_widths=None)[source]

Bases: vulk.graphic.d2.scene.Widget

Widget using the shader ‘block’ with allow lot of customization

get_renderer_name()[source]
render(renderer)[source]
Args:
renderer (BlockBatch)
class vulk.graphic.d2.scene.Composite(actions)[source]

Bases: vulk.graphic.d2.scene.Action

init(widget)[source]
class vulk.graphic.d2.scene.FadeIn(duration, interpolation=None)[source]

Bases: vulk.graphic.d2.scene.TemporalAction

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.FadeOut(duration, interpolation=None)[source]

Bases: vulk.graphic.d2.scene.TemporalAction

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.FadeTo(fade, duration, interpolation=None)[source]

Bases: vulk.graphic.d2.scene.TemporalAction

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.Image(parent, texture_region)[source]

Bases: vulk.graphic.d2.scene.Widget

get_renderer_name()[source]
render(renderer)[source]
Args:
renderer (SpriteBatch)
class vulk.graphic.d2.scene.Label(parent, fontdata, text)[source]

Bases: vulk.graphic.d2.scene.Widget

Widget used to write text

get_renderer_name()[source]
render(renderer)[source]
Args:
renderer (TextRenderer)
class vulk.graphic.d2.scene.MoveBy(x, y, duration, interpolation=None)[source]

Bases: vulk.graphic.d2.scene.TemporalAction

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.MoveTo(x, y, duration, interpolation=None)[source]

Bases: vulk.graphic.d2.scene.TemporalAction

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.Parallel(actions)[source]

Bases: vulk.graphic.d2.scene.Composite

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.Repeat(action, count=0)[source]

Bases: vulk.graphic.d2.scene.Action

init(widget)[source]
restart_action()[source]
update(delta)[source]
class vulk.graphic.d2.scene.RotateBy(rotation, duration, interpolation=None)[source]

Bases: vulk.graphic.d2.scene.TemporalAction

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.RotateTo(rotation, duration, interpolation=None)[source]

Bases: vulk.graphic.d2.scene.TemporalAction

init(widget)[source]
update(delta)[source]
class vulk.graphic.d2.scene.Scene(context, width, height, renderers=None)[source]

Bases: vulk.graphic.d2.scene.BaseWidget

Main 2D Scene

render(context)[source]

Render Scene

For each widget, get renderer and render it.

Args:
context (VulkContext)
Returns:
Semaphore or None if no semaphore
update(delta)[source]
class vulk.graphic.d2.scene.Sequence(actions)[source]

Bases: vulk.graphic.d2.scene.Composite

next_action()[source]
update(delta)[source]
class vulk.graphic.d2.scene.TemporalAction(duration, interpolation)[source]

Bases: vulk.graphic.d2.scene.Action

init(widget)[source]
percent()[source]
update(delta)[source]
class vulk.graphic.d2.scene.Widget(parent)[source]

Bases: vulk.graphic.d2.scene.BaseWidget, abc.ABC

render(renderer)[source]

Render widget

Args:
renderer (object): Renderer compatible with this widget

Module contents