include/alba.h
1#ifndef ALBA_H
2#define ALBA_H
3
4#include "GLFW/glfw3.h"
5#include "webgpu.h"
6
7// Dynamic arrays
8typedef struct
9{
10 uint64_t length;
11 uint64_t capacity;
12 float* data;
13} FloatArray;
14
15void float_array_append(FloatArray* array, float value);
16void float_array_release(const FloatArray* array);
17void float_array_clear(FloatArray* array);
18
19typedef struct
20{
21 uint64_t length;
22 uint64_t capacity;
23 uint32_t* data;
24} Uint32Array;
25
26void uint32_array_append(Uint32Array* array, uint32_t value);
27void uint32_array_release(const Uint32Array* array);
28void uint32_array_clear(Uint32Array* array);
29
30// Misc
31typedef struct
32{
33 double r;
34 double g;
35 double b;
36 double a;
37} AlbaColor;
38
39// Window
40typedef struct
41{
42 char* title;
43 uint32_t initial_width;
44 uint32_t initial_height;
45 AlbaColor clear_color;
46} AlbaWindowOptions;
47
48typedef struct
49{
50 AlbaWindowOptions options;
51 GLFWwindow* glfw_window;
52 WGPUInstance instance;
53 WGPUSurface surface;
54 WGPUAdapter adapter;
55 WGPUDevice device;
56 WGPUQueue queue;
57 WGPUShaderModule shaders;
58 WGPURenderPipeline pipeline;
59 // Drawing
60 int dirty; // if set, the next frame will update the buffers
61 FloatArray new_vertices;
62 WGPUBuffer vertices;
63 FloatArray new_attributes;
64 WGPUBuffer attributes;
65 Uint32Array new_indices;
66 WGPUBuffer indices;
67} AlbaWindow;
68
69AlbaWindow* create_window(const AlbaWindowOptions* options);
70uint32_t window_should_close(const AlbaWindow* window);
71void window_render(AlbaWindow* window);
72void window_release(AlbaWindow* window);
73
74void draw_triangles(AlbaWindow* window, uint64_t num_vertices, float* vertices);
75
76#endif // ALBA_H