1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package gpu
import glsl "core:math/linalg/glsl"
import bk "backend"
// Math type aliases
Vec2 :: glsl.vec2
Vec3 :: glsl.vec3
Vec4 :: glsl.vec4
Mat4 :: glsl.mat4x4
Quat :: quaternion128
// Color as 4 normalized floats (GPU-native, no conversion needed)
Color :: [4]f32
// Rectangle for 2D operations
Rectangle :: struct {
x, y, width, height: f32,
}
// 2D camera with offset, target, rotation, and zoom
Camera2D :: struct {
offset: Vec2,
target: Vec2,
rotation: f32,
zoom: f32,
}
// 3D camera with position, target, up vector, and projection params
Camera3D :: struct {
position: Vec3,
target: Vec3,
up: Vec3,
fovy: f32,
near: f32,
far: f32,
}
Camera_Mode :: enum {
FREE,
ORBITAL,
FIRST_PERSON,
THIRD_PERSON,
}
// Easing functions for smooth camera transitions and animations
Ease_Type :: enum {
LINEAR,
SINE_IN,
SINE_OUT,
SINE_IN_OUT,
QUAD_IN,
QUAD_OUT,
QUAD_IN_OUT,
CUBIC_IN,
CUBIC_OUT,
CUBIC_IN_OUT,
EXPO_IN,
EXPO_OUT,
EXPO_IN_OUT,
}
// Camera path keyframes for scripted camera movement (cutscenes)
Camera_Keyframe_2D :: struct {
camera: Camera2D,
time: f32, // absolute seconds from path start
easing: Ease_Type, // easing TO this keyframe from previous
}
Camera_Keyframe_3D :: struct {
camera: Camera3D,
time: f32,
easing: Ease_Type,
}
Camera_Path_2D :: struct {
keyframes: []Camera_Keyframe_2D, // user-owned slice
duration: f32, // last keyframe time
}
Camera_Path_3D :: struct {
keyframes: []Camera_Keyframe_3D,
duration: f32,
}
// GPU vertex layout
Vertex :: struct {
position: Vec3,
normal: Vec3,
tex_coord: Vec2,
color: Color,
}
// Opaque resource handles -- IDs are indices into internal pools
Texture :: struct {
id: u32,
width: i32,
height: i32,
}
Mesh :: struct {
id: u32,
vertex_count: i32,
index_count: i32,
}
Material :: struct {
shader: Shader,
diffuse: Texture,
normal_map: Texture,
color: Color,
double_sided: bool,
metallic: f32,
roughness: f32,
reflectance: f32,
emissive: Color,
}
// Light types for the lighting system
Light_Type :: enum u32 {
DIRECTIONAL = 0,
POINT = 1,
}
// Light source for 3D PBR and 2D screen-space lighting
Light :: struct {
type: Light_Type,
enabled: bool,
position: Vec3, // world position (point) or direction (directional)
color: Color, // RGB color
intensity: f32, // brightness multiplier
radius: f32, // point light range (attenuation cutoff)
casts_shadow: bool, // directional lights only
}
Model :: struct {
id: u32,
meshes: []Mesh,
materials: []Material,
transform: Mat4,
}
Shader :: struct {
id: u32,
}
Compute_Shader :: struct {
id: u32,
}
Storage_Buffer :: struct {
id: u32,
size: int,
}
// Helper to create Color from u8 RGBA values
color_from_rgba :: proc(r, g, b, a: u8) -> Color {
return Color{f32(r) / 255.0, f32(g) / 255.0, f32(b) / 255.0, f32(a) / 255.0}
}
// Default camera constructors
default_camera_2d :: proc() -> Camera2D {
return Camera2D{
offset = {0, 0},
target = {0, 0},
rotation = 0,
zoom = 1,
}
}
default_camera_3d :: proc() -> Camera3D {
return Camera3D{
position = {0, 2, 5},
target = {0, 0, 0},
up = {0, 1, 0},
fovy = 60,
near = 0.1,
far = 100,
}
}
// Backend types re-exported for external pipeline creation
Backend :: bk.Backend
Capability :: bk.Capability
Capability_Flags :: bk.Capability_Flags
Capabilities :: bk.Capabilities
Frame_Context :: bk.Frame_Context
Pipeline_Handle :: bk.Pipeline_Handle
Buffer_Handle :: bk.Buffer_Handle
Texture_Handle :: bk.Texture_Handle
Shader_Handle :: bk.Shader_Handle
Shader_Format :: bk.Shader_Format
Shader_Module_Desc :: bk.Shader_Module_Desc
REQUIRED_SHADER_FORMAT :: bk.REQUIRED_SHADER_FORMAT
Descriptor_Handle :: bk.Descriptor_Handle
Render_Pass_Handle :: bk.Render_Pass_Handle
Surface_Kind :: bk.Surface_Kind
Surface_Desc :: bk.Surface_Desc
X11_Surface_Handle :: bk.X11_Surface_Handle
Wayland_Surface_Handle :: bk.Wayland_Surface_Handle
Win32_Surface_Handle :: bk.Win32_Surface_Handle
Shader_Stage :: bk.Shader_Stage
Shader_Stage_Flag :: bk.Shader_Stage_Flag
Shader_Stage_Flags :: bk.Shader_Stage_Flags
Pipeline_Desc :: bk.Pipeline_Desc
Blend_Mode :: bk.Blend_Mode
Vertex_Binding :: bk.Vertex_Binding
Vertex_Attribute :: bk.Vertex_Attribute
Vertex_Format :: bk.Vertex_Format
Vertex_Input_Rate :: bk.Vertex_Input_Rate
Vertex_Attrib :: bk.Vertex_Attrib
Vertex_Layout_Entry :: bk.Vertex_Layout_Entry
Vertex_Layout :: bk.Vertex_Layout
MAX_VERTEX_ATTRIBS :: bk.MAX_VERTEX_ATTRIBS
// Layout variant enum and helpers
Layout_Variant :: bk.Layout_Variant
MAX_LAYOUT_VARIANTS :: bk.MAX_LAYOUT_VARIANTS
layout_to_variant :: bk.layout_to_variant
variant_to_layout :: bk.variant_to_layout
// Predefined vertex layouts
LAYOUT_POS_NORM :: bk.LAYOUT_POS_NORM
LAYOUT_POS_NORM_UV :: bk.LAYOUT_POS_NORM_UV
LAYOUT_POS_NORM_UV_COLOR :: bk.LAYOUT_POS_NORM_UV_COLOR
LAYOUT_POS_NORM_UV_TANGENT :: bk.LAYOUT_POS_NORM_UV_TANGENT
LAYOUT_POS_NORM_UV_COLOR_TANGENT :: bk.LAYOUT_POS_NORM_UV_COLOR_TANGENT
// Vertex layout helpers
vertex_format_size :: bk.vertex_format_size
vertex_attrib_default_format :: bk.vertex_attrib_default_format
vertex_layout_build :: bk.vertex_layout_build
vertex_layout_has :: bk.vertex_layout_has
vertex_layout_to_pipeline_attrs :: bk.vertex_layout_to_pipeline_attrs
Topology :: bk.Topology
Cull_Mode :: bk.Cull_Mode
Front_Face :: bk.Front_Face
NULL_PIPELINE :: bk.NULL_PIPELINE