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