Source code for picogl.backend.render.resources

"""Frame-scoped GPU resource descriptors."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Optional


@dataclass
[docs] class Texture: """GPU texture node in a render graph."""
[docs] name: str
[docs] width: int
[docs] height: int
[docs] format: int
[docs] handle: Optional[int] = None
@dataclass
[docs] class RenderTarget: """Color/depth render target."""
[docs] name: str
[docs] color: Texture
[docs] depth: Optional[Texture] = None
[docs] class FrameResources: """Allocator for per-frame transient GPU resources.""" def __init__(self):
[docs] self.textures: dict[str, Texture] = {}
[docs] self.render_targets: dict[str, RenderTarget] = {}
[docs] def create_texture(self, name: str, width: int, height: int, fmt: int) -> Texture: tex = Texture(name, width, height, fmt) self.textures[name] = tex return tex
[docs] def create_render_target( self, name: str, color: Texture, depth: Optional[Texture] = None, ) -> RenderTarget: target = RenderTarget(name, color, depth) self.render_targets[name] = target return target