src/internal.h
1#ifndef INTERNAL_H
2#define INTERNAL_H
3
4#include "alba.h"
5
6#include "hashmap.h"
7
8#define NO_TEXTURE {-1, -1}
9
10typedef struct RenderPassDataImpl
11{
12 // if set, the next frame will update the buffers
13 int dirty;
14 AlbaDynArray new_vertices;
15 WGPUBuffer vertices;
16 AlbaDynArray new_attributes;
17 WGPUBuffer attributes;
18 AlbaDynArray new_indices;
19 WGPUBuffer indices;
20 WGPUBuffer uniforms;
21 WGPUTexture texture;
22 WGPURenderPipeline pipeline;
23 WGPUBindGroup bind_group;
24} RenderPassData;
25
26typedef struct AlbaWindowImpl
27{
28 AlbaWindowOptions options;
29 GLFWwindow* glfw_window;
30 AlbaVector size;
31 AlbaVector scale;
32 WGPUInstance instance;
33 WGPUSurface surface;
34 WGPUAdapter adapter;
35 WGPUDevice device;
36 WGPUQueue queue;
37 WGPUShaderModule shaders;
38 RenderPassData drawing;
39 RenderPassData text;
40} AlbaWindow;
41
42// Atlas
43typedef struct
44{
45 uint32_t character;
46 FT_Long glyph_index;
47 FT_Glyph_Metrics metrics;
48 FT_Bitmap bitmap;
49 AlbaVector start;
50 AlbaVector end;
51} AlbaGlyph;
52
53typedef struct
54{
55 struct hashmap* glyphs;
56 int dirty;
57 AlbaDynArray glyph_sizes; // in w, h order
58 AlbaVector size;
59 uint8_t* image;
60} AlbaAtlas;
61
62AlbaAtlas atlas_new(uint32_t capacity);
63void atlas_reserve(AlbaAtlas* atlas, uint32_t capacity);
64void atlas_append(AlbaAtlas* atlas, FT_Face face, uint32_t character);
65void atlas_generate_image(AlbaAtlas* atlas);
66void atlas_release(const AlbaAtlas* atlas);
67
68// Helpers
69WGPUTexture create_texture(
70 const AlbaWindow* window,
71 WGPUTextureUsage usage,
72 AlbaVector size,
73 WGPUTextureFormat format, uint8_t samples,
74 const void* data
75);
76
77// Drawng
78void draw_triangles_indexed_render_pass(
79 RenderPassData* data,
80 uint32_t num_vertices,
81 const AlbaVector* vertices,
82 const AlbaAttribute* attributes,
83 uint32_t num_indices,
84 uint32_t* indices
85);
86
87#endif // INTERNAL_H