summaryrefslogtreecommitdiff
path: root/src/renderer/ral.c
diff options
context:
space:
mode:
authorJoshua Rowe <17525998+omnisci3nce@users.noreply.github.com>2024-05-20 10:50:11 +1000
committerGitHub <noreply@github.com>2024-05-20 10:50:11 +1000
commite904c22003c3a134201b222e6619e782fbe63947 (patch)
tree5295c8ce5f855ca4a0f1bebe50beee80bae66682 /src/renderer/ral.c
parent02e84ee4d18e705e3362be1e327fdb6f1397a032 (diff)
parent73d4145f46d2305f45761b8e456df692d1962dfb (diff)
Merge pull request #14 from omnisci3nce/realign
Realign
Diffstat (limited to 'src/renderer/ral.c')
-rw-r--r--src/renderer/ral.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/renderer/ral.c b/src/renderer/ral.c
new file mode 100644
index 0000000..7d868be
--- /dev/null
+++ b/src/renderer/ral.c
@@ -0,0 +1,42 @@
+#include "ral.h"
+
+size_t vertex_attrib_size(vertex_attrib_type attr) {
+ switch (attr) {
+ case ATTR_F32:
+ case ATTR_U32:
+ case ATTR_I32:
+ return 4;
+ case ATTR_F32x2:
+ case ATTR_U32x2:
+ case ATTR_I32x2:
+ return 8;
+ case ATTR_F32x3:
+ case ATTR_U32x3:
+ case ATTR_I32x3:
+ return 12;
+ case ATTR_F32x4:
+ case ATTR_U32x4:
+ case ATTR_I32x4:
+ return 16;
+ break;
+ }
+}
+
+void vertex_desc_add(vertex_description* builder, const char* name, vertex_attrib_type type) {
+ u32 i = builder->attributes_count;
+
+ size_t size = vertex_attrib_size(type);
+ builder->attributes[i] = type;
+ builder->stride += size;
+ builder->attr_names[i] = name;
+
+ builder->attributes_count++;
+}
+
+vertex_description static_3d_vertex_description() {
+ vertex_description builder = { .debug_label = "vertex" };
+ vertex_desc_add(&builder, "position", ATTR_F32x3);
+ vertex_desc_add(&builder, "normal", ATTR_F32x3);
+ vertex_desc_add(&builder, "texCoords", ATTR_F32x2);
+ return builder;
+}