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_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_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**
-
-
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.
-
flush
()[source]¶ Flush all draws to graphic card. Currently, flush register and submit command.
Parameters:
- context: VulkContext
-
-
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)
-
-
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)
-
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
-
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
-
-
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)
-
vulk.graphic.d2.scene module¶
This module contains scene related functions and classes
-
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
-
alpha
¶
-
color_abs
¶ Absolute color (not depending on parent color)
-
column_width
¶
-
row_width
¶
-
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.
-
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
-
class
vulk.graphic.d2.scene.
Composite
(actions)[source]¶ Bases:
vulk.graphic.d2.scene.Action
-
class
vulk.graphic.d2.scene.
Image
(parent, texture_region)[source]¶ Bases:
vulk.graphic.d2.scene.Widget
-
class
vulk.graphic.d2.scene.
Label
(parent, fontdata, text)[source]¶ Bases:
vulk.graphic.d2.scene.Widget
Widget used to write text
-
class
vulk.graphic.d2.scene.
Repeat
(action, count=0)[source]¶ Bases:
vulk.graphic.d2.scene.Action
-
class
vulk.graphic.d2.scene.
Scene
(context, width, height, renderers=None)[source]¶ Bases:
vulk.graphic.d2.scene.BaseWidget
Main 2D Scene
-
class
vulk.graphic.d2.scene.
TemporalAction
(duration, interpolation)[source]¶ Bases:
vulk.graphic.d2.scene.Action
-
class
vulk.graphic.d2.scene.
Widget
(parent)[source]¶ Bases:
vulk.graphic.d2.scene.BaseWidget
,abc.ABC