summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-11 22:06:55 +1000
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-11 22:06:55 +1000
commit677ab09b0dc3b6d9c872b732f8e31543fa2d11bb (patch)
treef8aa923eb9d97c561341579fa4e575e4804ad9f4 /examples
parent08d7e23fd5ed95953822a72ba11d4b6cd96b2846 (diff)
WIP: shader data
Diffstat (limited to 'examples')
-rw-r--r--examples/cube/ex_cube.c62
-rw-r--r--examples/triangle/ex_triangle.c2
2 files changed, 27 insertions, 37 deletions
diff --git a/examples/cube/ex_cube.c b/examples/cube/ex_cube.c
index 71b7917..699cf55 100644
--- a/examples/cube/ex_cube.c
+++ b/examples/cube/ex_cube.c
@@ -13,6 +13,14 @@
extern core g_core;
+const custom_vertex vertices[] = {
+ (custom_vertex){ .pos = vec2(-0.5, 0.5), .color = vec3(0.0, 0.0, 1.0) },
+ (custom_vertex){ .pos = vec2(0.5, 0.5), .color = vec3(0.0, 1.0, 0.0) },
+ (custom_vertex){ .pos = vec2(0.5, -0.5), .color = vec3(1.0, 0.0, 0.0) },
+ (custom_vertex){ .pos = vec2(-0.5, -0.5), .color = vec3(1.0, 1.0, 1.0) },
+};
+const u16 indices[] = { 0, 1, 2, 2, 3, 0 };
+
// Define the shader data
typedef struct mvp_uniforms {
mat4 model;
@@ -23,33 +31,15 @@ typedef struct mvp_uniforms {
shader_data_layout mvp_uniforms_layout(void* data) {
mvp_uniforms* d = (mvp_uniforms*)data;
bool has_data = data != NULL;
-
- shader_binding b1 = {
- .label = "model",
- .type = SHADER_BINDING_BYTES,
- .stores_data = has_data,
- .data = {.bytes = { .size = sizeof(mat4) }}
- };
- shader_binding b2 = {
- .label = "view",
- .type = SHADER_BINDING_BYTES,
- .stores_data = has_data,
- .data = {.bytes = { .size = sizeof(mat4) }}
- };
- shader_binding b3 = {
- .label = "projection",
- .type = SHADER_BINDING_BYTES,
- .stores_data = has_data,
- .data = {.bytes = { .size = sizeof(mat4) }}
- };
+
+ shader_binding b1 = { .label = "mvp_uniforms",
+ .type = SHADER_BINDING_BYTES,
+ .stores_data = has_data,
+ .data = { .bytes = { .size = sizeof(mvp_uniforms) } } };
if (has_data) {
- b1.data.bytes.data = &d->model;
- b2.data.bytes.data = &d->view;
- b3.data.bytes.data = &d->projection;
+ b1.data.bytes.data = d;
}
- return (shader_data_layout ){.name = "mvp_uniforms", .bindings = {
- b1, b2, b3
- }};
+ return (shader_data_layout){ .name = "global_ubo", .bindings = { b1 } };
}
int main() {
@@ -58,18 +48,7 @@ int main() {
DEBUG("render capacity %d", g_core.default_scene.renderables->capacity);
- shader_data_layout mvp_layout = mvp_uniforms_layout(NULL);
-
- mvp_uniforms mvp_data = {
- .model = mat4_ident(),
- .view = mat4_ident(),
- .projection = mat4_ident()
- };
-
- shader_data mvp_uniforms_data = {
- .data = &mvp_data,
- .shader_data_get_layout = &mvp_uniforms_layout
- };
+ shader_data mvp_uniforms_data = { .data = NULL, .shader_data_get_layout = &mvp_uniforms_layout };
gpu_renderpass_desc pass_description = {};
gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description);
@@ -84,6 +63,8 @@ int main() {
struct graphics_pipeline_desc pipeline_description = {
.debug_name = "Basic Pipeline",
+ .data_layouts = { mvp_uniforms_data },
+ .data_layouts_count = 1,
.vs = { .debug_name = "Triangle Vertex Shader",
.filepath = vert_path,
.code = vertex_shader.contents,
@@ -121,6 +102,13 @@ int main() {
encode_bind_pipeline(enc, PIPELINE_GRAPHICS, gfx_pipeline);
encode_set_default_settings(enc);
+ /* shader_data_layout mvp_layout = mvp_uniforms_layout(NULL); */
+
+ mvp_uniforms mvp_data = { .model = mat4_ident(),
+ .view = mat4_ident(),
+ .projection = mat4_ident() };
+ mvp_uniforms_data.data = &mvp_data;
+
// Record draw calls
encode_set_vertex_buffer(enc, triangle_vert_buf);
encode_set_index_buffer(enc, triangle_index_buf);
diff --git a/examples/triangle/ex_triangle.c b/examples/triangle/ex_triangle.c
index c6f0e54..5d8f0cf 100644
--- a/examples/triangle/ex_triangle.c
+++ b/examples/triangle/ex_triangle.c
@@ -11,6 +11,7 @@
#include "ral.h"
#include "ral_types.h"
#include "render.h"
+#include "render_types.h"
extern core g_core;
@@ -53,6 +54,7 @@ int main() {
};
gpu_pipeline* gfx_pipeline = gpu_graphics_pipeline_create(pipeline_description);
+ // Load triangle vertex and index data
buffer_handle triangle_vert_buf =
gpu_buffer_create(sizeof(vertices), CEL_BUFFER_VERTEX, CEL_BUFFER_FLAG_GPU, vertices);