summaryrefslogtreecommitdiff
path: root/examples/triangle.c
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-17 19:18:38 +1100
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-17 19:18:38 +1100
commitc557763010a8976680f37609ca10e666ff849cd9 (patch)
treef2fa05b3e45c5fdc3565d654d485b2c46717324e /examples/triangle.c
parent3e1aea0243f54e0b68baa3b19ac19f3d965484e0 (diff)
metal triangle!
Diffstat (limited to 'examples/triangle.c')
-rw-r--r--examples/triangle.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/triangle.c b/examples/triangle.c
index ccbcea3..c304562 100644
--- a/examples/triangle.c
+++ b/examples/triangle.c
@@ -2,11 +2,57 @@
#include <celeritas.h>
+static vec4 vertices[] = {
+ {-0.5f, -0.5f, 0.0f, 1.0},
+ { 0.5f, -0.5f, 0.0f, 1.0},
+ { 0.0f, 0.5f, 0.0f, 1.0}
+};
+
+pipeline_handle draw_pipeline;
+buf_handle tri_vert_buffer;
+
+void draw() {
+ render_pass_desc d = {};
+ gpu_encoder* enc = ral_render_encoder(d);
+ ral_encode_bind_pipeline(enc, draw_pipeline);
+ ral_encode_set_vertex_buf(enc, tri_vert_buffer);
+ ral_encode_draw_tris(enc, 0, 3);
+ ral_encoder_finish_and_submit(enc);
+}
+
int main() {
core_bringup("Celeritas Example: Triangle", NULL);
+ // create rendering pipeline
+ gfx_pipeline_desc pipeline_desc = {
+ .label = "Triangle drawing pipeline",
+ .vertex_desc = NULL, // TODO
+ .vertex = {
+ .source = NULL,
+ .is_spirv = false,
+ .entry_point = "vertexShader",
+ .shader_stage = VISIBILITY_VERTEX,
+ },
+ .fragment = {
+ .source = NULL,
+ .is_spirv = false,
+ .entry_point = "fragmentShader",
+ .shader_stage = VISIBILITY_FRAGMENT,
+ },
+ };
+
+ draw_pipeline = ral_gfx_pipeline_create(pipeline_desc);
+
+ // create our buffer to hold vertices
+ printf("size of vertices %ld\n", sizeof(vec4) * 3);
+ tri_vert_buffer = ral_buffer_create(sizeof(vec4) * 3, &vertices);
+
while (!app_should_exit()) {
glfwPollEvents();
+
+ ral_frame_start();
+ ral_frame_draw(&draw);
+ ral_frame_end();
}
return 0;