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