Skip to main content

cvkg_render_gpu/
types.rs

1//! Core data types, internal structs, and rendering contexts.
2use crate::vertex::Vertex;
3use cvkg_core::Rect;
4
5/// SvgModel — A collection of tessellated triangles representing a vector icon.
6#[derive(Clone, Debug)]
7pub struct SvgModel {
8    pub vertices: Vec<Vertex>,
9    pub indices: Vec<u32>,
10    pub view_box: Rect,
11    pub animations: Vec<SvgAnimation>,
12}
13
14#[derive(Clone, Debug)]
15pub struct SvgAnimation {
16    pub target_id: String,
17    pub attribute_name: String,
18    pub from_val: f32,
19    pub to_val: f32,
20    pub duration: f32,
21    pub vertex_range: std::ops::Range<usize>,
22}
23
24/// Represents a single batched GPU draw call.
25/// Batches are broken whenever the active texture or primitive mode changes.
26#[derive(Debug, Clone)]
27pub(crate) struct DrawCall {
28    pub texture_id: Option<u32>,
29    pub scissor_rect: Option<Rect>,
30    pub index_start: u32,
31    pub index_count: u32,
32    /// Material routing tag — determines which pass this draw call is routed to
33    /// in the multi-pass Backdrop Capture pipeline.
34    pub material: cvkg_core::DrawMaterial,
35    pub target_id: Option<u64>,
36    pub instance_start: u32,
37}
38
39pub struct OffscreenEffectConfig {
40    pub target_id: u64,
41    pub effect: String,
42    pub blend_mode: u32,
43    pub effect_args: [f32; 16],
44}
45
46#[derive(Debug, Clone, Copy)]
47pub(crate) struct ShadowState {
48    pub radius: f32,
49    pub color: [f32; 4],
50    pub _offset: [f32; 2],
51}
52
53pub(crate) struct SurfaceContext {
54    pub(crate) surface: wgpu::Surface<'static>,
55    pub(crate) config: wgpu::SurfaceConfiguration,
56    pub(crate) scene_texture: wgpu::TextureView,
57    pub(crate) scene_msaa_texture: wgpu::TextureView,
58    pub(crate) scene_bind_group: wgpu::BindGroup,
59    pub(crate) scene_texture_bind_group: wgpu::BindGroup,
60    pub(crate) depth_texture_view: wgpu::TextureView,
61    pub(crate) blur_tex_a: crate::kvasir::resource::ResourceId,
62    pub(crate) blur_tex_b: crate::kvasir::resource::ResourceId,
63    pub(crate) bloom_tex_a: crate::kvasir::resource::ResourceId,
64    pub(crate) bloom_tex_b: crate::kvasir::resource::ResourceId,
65    pub(crate) blur_env_bind_group_a: wgpu::BindGroup,
66    pub(crate) blur_env_bind_group_b: wgpu::BindGroup,
67    pub(crate) bloom_env_bind_group_a: wgpu::BindGroup,
68    pub(crate) bloom_env_bind_group_b: wgpu::BindGroup,
69    pub(crate) scale_factor: f32,
70    pub(crate) sampler: wgpu::Sampler,
71}
72
73/// HeadlessContext — A rendering target for surface-less execution.
74pub struct HeadlessContext {
75    pub scene_texture: wgpu::TextureView,
76    pub scene_msaa_texture: wgpu::TextureView,
77    pub scene_bind_group: wgpu::BindGroup,
78    pub scene_texture_bind_group: wgpu::BindGroup,
79    pub depth_texture_view: wgpu::TextureView,
80    pub blur_tex_a: crate::kvasir::resource::ResourceId,
81    pub blur_tex_b: crate::kvasir::resource::ResourceId,
82    pub bloom_tex_a: crate::kvasir::resource::ResourceId,
83    pub bloom_tex_b: crate::kvasir::resource::ResourceId,
84    pub blur_env_bind_group_a: wgpu::BindGroup,
85    pub blur_env_bind_group_b: wgpu::BindGroup,
86    pub bloom_env_bind_group_a: wgpu::BindGroup,
87    pub bloom_env_bind_group_b: wgpu::BindGroup,
88    pub scale_factor: f32,
89    pub sampler: wgpu::Sampler,
90    pub width: u32,
91    pub height: u32,
92    pub output_texture: wgpu::Texture,
93    pub output_view: wgpu::TextureView,
94}
95
96pub(crate) const MAX_VERTICES: usize = 100_000;
97pub(crate) const MAX_INDICES: usize = 150_000;
98
99#[repr(C)]
100#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
101pub struct EffectUniforms {
102    pub time: f32,
103    pub pad0: f32,
104    pub size: [f32; 2],
105    pub args: [f32; 16],
106}
107
108/// Per-draw-call glass instance parameters.
109/// Passed as push constants (fast path, no buffer allocation) or via
110/// a dedicated bind group for per-element blur sampling.
111#[repr(C)]
112#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
113pub struct GlassInstanceUniforms {
114    /// Local tint override: [r, g, b, weight].
115    /// weight=0 = use theme tint only, weight=1 = use local tint only.
116    pub tint_override: [f32; 4],
117    /// Per-instance IOR override. 0.0 = use theme default (1.45).
118    pub ior_override: f32,
119    /// Blur strength multiplier. 1.0 = normal, 2.0 = double blur.
120    pub blur_multiplier: f32,
121    /// Frost intensity override. 0.0 = theme default.
122    pub frost_override: f32,
123    /// Scissor rect in physical pixels: [x, y, width, height].
124    /// Used for per-element backdrop blur sampling.
125    pub scissor_px: [f32; 4],
126    /// Portal index: which per-element blur texture to sample.
127    /// 0 = main scene blur (default), 1+ = portal region blur.
128    pub portal_index: f32,
129    pub _pad: f32,
130}
131
132impl Default for GlassInstanceUniforms {
133    fn default() -> Self {
134        Self {
135            tint_override: [0.0; 4],
136            ior_override: 0.0,
137            blur_multiplier: 1.0,
138            frost_override: 0.0,
139            scissor_px: [0.0; 4],
140            portal_index: 0.0,
141            _pad: 0.0,
142        }
143    }
144}