ke.render

Graphics resources, renderer controls, and custom pipeline APIs.

API overview

Renderer

Facade for custom pipelines and renderable resource updates.

GraphicsDevice

Factory for backend graphics resources.

Texture

GPU texture created by a graphics device.

Buffer

GPU buffer created by a graphics device.

GraphicsPipeline

Opaque compiled graphics pipeline.

ShaderDesc

Shader stages and diagnostic name used to build a pipeline.

ShaderStage

One source stage in a pipeline shader description.

SceneHookPipelineDesc

Describe a custom graphics pipeline inserted into scene rendering.

SamplerDesc

Backend-neutral texture sampler settings.

ExternalBufferDesc

Describe transform storage owned outside the renderer.

class kangengine.render.GraphicsDevice[native]

Factory for backend graphics resources.

create_buffer(data: Any, usage: BufferUsage, label: str = '') Buffer

Create a GPU buffer initialized from a contiguous Python buffer.

create_texture(
path: str,
flip: bool = False,
sampler: SamplerDesc = ...,
) Texture

Load a texture from an image file.

class kangengine.render.Texture[native]

GPU texture created by a graphics device.

bind(slot: int = 0) None

Bind the texture to a backend texture unit.

get_height() int

Return the height in pixels.

get_width() int

Return the width in pixels.

property height

Return the height in pixels.

unbind() None

Unbind the texture from the active context.

property width

Return the width in pixels.

class kangengine.render.Buffer[native]

GPU buffer created by a graphics device.

set_data(data: Any, offset: int = 0) None

Upload a contiguous Python buffer at a byte offset.

property size

Return the allocation size in bytes.

property usage

Return the buffer usage flags.

class kangengine.render.GraphicsPipeline[native]

Opaque compiled graphics pipeline. Keep it alive while hooks use it.

class kangengine.render.Renderer[native]

Facade for custom pipelines and renderable resource updates.

add_render_hook(
phase: RenderHookPhase,
callback: Callable[[RenderHookContext], None],
) int

Register a command-recording callback and return its handle.

create_scene_hook_pipeline(desc: SceneHookPipelineDesc) GraphicsPipeline

Create a pipeline compatible with the scene render targets.

device() GraphicsDevice

Return the renderer-owned graphics device.

map_renderable_cuda_transform_buffers(
handles: Any,
count: int,
device_id: int,
stream_handle: int = 0,
) Any

Map transform buffers for direct CUDA writes.

point_lights() Any

Return the stored point lights.

remove_render_hook(handle: int) bool

Remove a previously registered render hook.

set_point_lights(lights: Any) None

Replace the renderer’s point-light list.

set_renderable_alpha_mode(
handle: int,
mode: AlphaMode,
cutoff: float = 0.5,
) None

Set alpha handling and mask cutoff.

set_renderable_casts_shadow(handle: int, enabled: bool = True) None

Set whether the renderable casts shadows.

set_renderable_colors(handle: int, colors: Any) None

Set per-instance colors.

set_renderable_double_sided(handle: int, enabled: bool = True) None

Set whether both triangle faces are rendered.

set_renderable_external_buffer(
handle: int,
descriptor: ExternalBufferDesc,
) None

Attach externally owned transform storage.

set_renderable_texture(
handle: int,
texture: Texture,
role: TextureRole,
) None

Attach a texture by semantic material role.

set_spot_lights(lights: Any) None

Replace the renderer’s spot-light list.

spot_lights() Any

Return the stored spot lights.

sync_scene_lights(scene: Any) None

Synchronize renderer lights from scene light prims.

unmap_renderable_cuda_transform_buffers(
handles: Any,
device_id: int,
stream_handle: int = 0,
) None

Unmap transform buffers after CUDA writes.

update_renderable_geometry(
handle: int,
positions: Any,
normals: Any | None = None,
) None

Update dynamic positions and optional normals.

update_renderable_skinning_matrices(handle: int, bone_matrices: Any) None

Update matrices for a skinned renderable.

update_renderable_transforms(
handle: int,
transforms: Any,
colors: Any | None = None,
) None

Replace instance transforms and optional colors.

class kangengine.render.ShaderDesc[native]

Shader stages and diagnostic name used to build a pipeline.

property name
property stages
class kangengine.render.ShaderStage[native]

One source stage in a pipeline shader description.

property entry_point
property source
property stage
class kangengine.render.SceneHookPipelineDesc[native]

Describe a custom graphics pipeline inserted into scene rendering.

property blend
property cull_mode
property depth_compare
property depth_test
property depth_write
property label
property shader
property topology
property use_scene_frame_bindings
property vertex_buffers
class kangengine.render.SamplerDesc[native]

Backend-neutral texture sampler settings.

__init__(
*,
wrap_u: kangengine.TextureWrap = TextureWrap.Repeat,
wrap_v: kangengine.TextureWrap = TextureWrap.Repeat,
min_filter: kangengine.TextureFilter = TextureFilter.LinearMipmapLinear,
mag_filter: kangengine.TextureFilter = TextureFilter.Linear,
)

Create texture sampler settings from keyword arguments.

property mag_filter

Texture magnification filter.

property min_filter

Texture minification filter.

property wrap_u

Texture coordinate wrapping mode on the U axis.

property wrap_v

Texture coordinate wrapping mode on the V axis.

class kangengine.render.ExternalBufferDesc[native]

Describe transform storage owned outside the renderer.

__init__(
*,
view: kangengine.GpuArrayView = GpuArrayView(),
format: kangengine.ExternalBufferFormat = ExternalBufferFormat.MAT4,
count: int = 0,
stride_bytes: int = 0,
sync_policy: kangengine.ExternalSyncPolicy = ExternalSyncPolicy.NONE,
)

Create an external buffer descriptor from keyword arguments.

property count

Element count; zero derives it from the view shape.

property format

Element layout used to decode the external buffer.

property stride_bytes

Element stride in bytes; zero derives it from the view.

property sync_policy

Synchronization policy for external producer updates.

property view

External array metadata and ownership view.

class kangengine.render.TextureRole[native]

Semantic texture slot used by built-in materials.

AMBIENT_OCCLUSION = <TextureRole.AMBIENT_OCCLUSION: 3>
BASE_COLOR = <TextureRole.BASE_COLOR: 0>
DIFFUSE = <TextureRole.BASE_COLOR: 0>
EMISSIVE = <TextureRole.EMISSIVE: 4>
METALLIC = <TextureRole.METALLIC: 5>
METALLIC_ROUGHNESS = <TextureRole.METALLIC_ROUGHNESS: 2>
NORMAL = <TextureRole.NORMAL: 1>
OCCLUSION_ROUGHNESS_METALLIC = <TextureRole.OCCLUSION_ROUGHNESS_METALLIC: 7>
ROUGHNESS = <TextureRole.ROUGHNESS: 6>
TextureRole.name -> str
property value
class kangengine.render.AlphaMode[native]

Fragment alpha policy.

BLEND = <AlphaMode.BLEND: 2>
MASK = <AlphaMode.MASK: 1>
OPAQUE = <AlphaMode.OPAQUE: 0>
AlphaMode.name -> str
property value
class kangengine.render.BufferUsage[native]

Bit flags describing GPU buffer use.

COPY_DST = <BufferUsage.COPY_DST: 16>
COPY_SRC = <BufferUsage.COPY_SRC: 8>
INDEX = <BufferUsage.INDEX: 2>
NONE = <BufferUsage.NONE: 0>
UNIFORM = <BufferUsage.UNIFORM: 4>
VERTEX = <BufferUsage.VERTEX: 1>
BufferUsage.name -> str
property value
class kangengine.render.ShaderType[native]

Programmable shader stage.

COMPUTE = <ShaderType.COMPUTE: 3>
FRAGMENT = <ShaderType.FRAGMENT: 1>
GEOMETRY = <ShaderType.GEOMETRY: 2>
VERTEX = <ShaderType.VERTEX: 0>
ShaderType.name -> str
property value
class kangengine.render.RenderHookPhase[native]

Point at which a scene command-recording callback runs.

AFTER_OPAQUE = <RenderHookPhase.AFTER_OPAQUE: 0>
AFTER_TRANSPARENT = <RenderHookPhase.AFTER_TRANSPARENT: 1>
RenderHookPhase.name -> str
property value
class kangengine.render.TextAlignment[native]

Horizontal text alignment.

CENTER = <TextAlignment.CENTER: 1>
LEFT = <TextAlignment.LEFT: 0>
RIGHT = <TextAlignment.RIGHT: 2>
TextAlignment.name -> str
property value
class kangengine.render.TextDepthMode[native]

Text depth-testing policy.

DEPTH_TESTED = <TextDepthMode.DEPTH_TESTED: 0>
OVERLAY = <TextDepthMode.OVERLAY: 1>
TextDepthMode.name -> str
property value
class kangengine.render.ScreenAnchor[native]

Anchor used for screen-space placement.

BOTTOM_CENTER = <ScreenAnchor.BOTTOM_CENTER: 7>
BOTTOM_LEFT = <ScreenAnchor.BOTTOM_LEFT: 6>
BOTTOM_RIGHT = <ScreenAnchor.BOTTOM_RIGHT: 8>
CENTER = <ScreenAnchor.CENTER: 4>
CENTER_LEFT = <ScreenAnchor.CENTER_LEFT: 3>
CENTER_RIGHT = <ScreenAnchor.CENTER_RIGHT: 5>
TOP_CENTER = <ScreenAnchor.TOP_CENTER: 1>
TOP_LEFT = <ScreenAnchor.TOP_LEFT: 0>
TOP_RIGHT = <ScreenAnchor.TOP_RIGHT: 2>
ScreenAnchor.name -> str
property value
class kangengine.Color[native]
property a
property b
property g
property r
class kangengine.ColorLibrary[native]
static get(type: kangengine.ColorType) Color