summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c10
-rw-r--r--src/renderer/backends/opengl/backend_opengl.h1
-rw-r--r--src/renderer/render.c56
-rw-r--r--src/renderer/render.h2
-rw-r--r--src/renderer/static_pipeline.h30
5 files changed, 76 insertions, 23 deletions
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index de6b71a..5a11f39 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -103,7 +103,6 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, binding_j, ubo_buf->id.ubo);
if (blockIndex != GL_INVALID_INDEX) {
- printf("Here\n");
glUniformBlockBinding(pipeline->shader_id, blockIndex, 0);
}
@@ -112,6 +111,8 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
}
}
+ pipeline->wireframe = description.wireframe;
+
return pipeline;
}
void gpu_pipeline_destroy(gpu_pipeline* pipeline) {}
@@ -164,6 +165,13 @@ void copy_buffer_to_image_oneshot(buffer_handle src, texture_handle dst) {}
// --- Render commands
void encode_bind_pipeline(gpu_cmd_encoder* encoder, pipeline_kind kind, gpu_pipeline* pipeline) {
encoder->pipeline = pipeline;
+
+ if (pipeline->wireframe) {
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ } else {
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ }
+
// In OpenGL binding a pipeline is more or less equivalent to just setting the shader
glUseProgram(pipeline->shader_id);
}
diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h
index f3b4eb7..ccdb446 100644
--- a/src/renderer/backends/opengl/backend_opengl.h
+++ b/src/renderer/backends/opengl/backend_opengl.h
@@ -20,6 +20,7 @@ typedef struct gpu_pipeline {
u32 shader_id;
vertex_description vertex_desc;
buffer_handle uniform_bindings[MAX_PIPELINE_UNIFORM_BUFFERS];
+ bool wireframe;
} gpu_pipeline;
typedef struct gpu_renderpass {
void *pad
diff --git a/src/renderer/render.c b/src/renderer/render.c
index f9e8ccf..3a373dc 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -11,6 +11,10 @@
#include "ral_types.h"
#include "render.h"
+//---NEW
+#include "static_pipeline.h"
+//---END
+
/** @brief Creates the pipelines built into Celeritas such as rendering static opaque geometry,
debug visualisations, immediate mode UI, etc */
void default_pipelines_init(renderer* ren);
@@ -56,15 +60,6 @@ bool renderer_init(renderer* ren) {
ren->resource_pools = arena_alloc(&pool_arena, sizeof(struct resource_pools));
resource_pools_init(&pool_arena, ren->resource_pools);
- // ren->blinn_phong =
- // shader_create_separate("assets/shaders/blinn_phong.vert",
- // "assets/shaders/blinn_phong.frag");
-
- // ren->skinned =
- // shader_create_separate("assets/shaders/skinned.vert", "assets/shaders/blinn_phong.frag");
-
- // default_material_init();
-
// Create default rendering pipeline
default_pipelines_init(ren);
@@ -103,18 +98,22 @@ void default_pipelines_init(renderer* ren) {
ERROR_EXIT("Failed to load shaders from disk")
}
- vertex_description vertex_input = {0};
+ // Vertex attributes
+ vertex_description vertex_input = { 0 };
vertex_input.debug_label = "Standard Static 3D Vertex Format";
vertex_desc_add(&vertex_input, "inPosition", ATTR_F32x3);
vertex_desc_add(&vertex_input, "inNormal", ATTR_F32x3);
vertex_desc_add(&vertex_input, "inTexCoords", ATTR_F32x2);
vertex_input.use_full_vertex_size = true;
+ // Shader data bindings
+ shader_data mvp_uniforms_data = { .data = NULL, .shader_data_get_layout = &mvp_uniforms_layout };
+
struct graphics_pipeline_desc pipeline_description = {
.debug_name = "Basic Pipeline",
.vertex_desc = vertex_input,
- // .data_layouts
- // .data_layouts_count
+ .data_layouts = { mvp_uniforms_data },
+ .data_layouts_count = 1,
.vs = { .debug_name = "Basic Vertex Shader",
.filepath = vert_path,
.code = vertex_shader.contents,
@@ -135,6 +134,7 @@ void render_frame_begin(renderer* ren) {
ren->frame_aborted = false;
if (!gpu_backend_begin_frame()) {
ren->frame_aborted = true;
+ WARN("Frame aborted");
return;
}
gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder();
@@ -148,7 +148,6 @@ void render_frame_end(renderer* ren) {
if (ren->frame_aborted) {
return;
}
- // gpu_temp_draw(3);
gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder();
gpu_cmd_encoder_end_render(enc);
gpu_cmd_buffer buf = gpu_cmd_encoder_finish(enc);
@@ -157,18 +156,33 @@ void render_frame_end(renderer* ren) {
}
void render_frame_draw(renderer* ren) {}
-bool mesh_has_indices(mesh* m) {
- return m->geometry->has_indices;
-}
+bool mesh_has_indices(mesh* m) { return m->geometry->has_indices; }
-void draw_mesh(mesh* mesh, mat4* model) { // , mat4* view, mat4* proj) {
+/**
+ *
+ * @param Camera used for getting the view projection matric to draw the mesh with.
+ * If NULL use the last used camera */
+void draw_mesh(mesh* mesh, mat4* model, camera* cam) { // , mat4* view, mat4* proj) {
gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder();
+
encode_set_vertex_buffer(enc, mesh->vertex_buffer);
if (mesh_has_indices(mesh)) {
encode_set_index_buffer(enc, mesh->index_buffer);
}
- // Assume this has already been done
- /* encode_bind_shader_data(enc, 0, &mvp_uniforms_data); */
+
+ mat4 view, proj;
+ if (cam) {
+ camera_view_projection(cam, // FIXME: proper swapchain dimensions
+ 1000, 1000, &view, &proj);
+
+ } else {
+ WARN("No camera set");
+ }
+ mvp_uniforms mvp_data = { .model = *model, .view = view, .projection = proj };
+ my_shader_bind_group shader_bind_data = { .mvp = mvp_data };
+ shader_data mvp_uniforms_data = { .data = &shader_bind_data,
+ .shader_data_get_layout = &mvp_uniforms_layout };
+ encode_bind_shader_data(enc, 0, &mvp_uniforms_data);
encode_draw_indexed(enc, mesh->geometry->indices->len);
}
@@ -192,8 +206,8 @@ mesh mesh_create(geometry_data* geometry, bool free_on_upload) {
// Create and upload index buffer
size_t index_bytes = geometry->indices->len * sizeof(u32);
INFO("Creating index buffer with size %d (len: %d)", index_bytes, geometry->indices->len);
- m.index_buffer =
- gpu_buffer_create(index_bytes, CEL_BUFFER_INDEX, CEL_BUFFER_FLAG_GPU, geometry->indices->data);
+ m.index_buffer = gpu_buffer_create(index_bytes, CEL_BUFFER_INDEX, CEL_BUFFER_FLAG_GPU,
+ geometry->indices->data);
m.is_uploaded = true;
// m.has_indices = geometry->has_indices;
diff --git a/src/renderer/render.h b/src/renderer/render.h
index b745e7a..12c0ce4 100644
--- a/src/renderer/render.h
+++ b/src/renderer/render.h
@@ -82,7 +82,7 @@ void shader_hot_reload(const char* filepath);
*/
mesh mesh_create(geometry_data* geometry, bool free_on_upload);
-void draw_mesh(mesh* mesh, mat4* model); //, mat4* view, mat4* proj); // TODO: material
+void draw_mesh(mesh* mesh, mat4* model, camera* cam);
model_handle model_load(const char* debug_name, const char* filepath);
diff --git a/src/renderer/static_pipeline.h b/src/renderer/static_pipeline.h
new file mode 100644
index 0000000..78f09f2
--- /dev/null
+++ b/src/renderer/static_pipeline.h
@@ -0,0 +1,30 @@
+#pragma once
+#include "maths_types.h"
+#include "defines.h"
+#include "ral.h"
+#include "ral_types.h"
+#include "render_types.h"
+
+typedef struct mvp_uniforms {
+ mat4 model;
+ mat4 view;
+ mat4 projection;
+} mvp_uniforms;
+typedef struct my_shader_bind_group {
+ mvp_uniforms mvp;
+} my_shader_bind_group;
+
+static shader_data_layout mvp_uniforms_layout(void* data) {
+ my_shader_bind_group* d = (my_shader_bind_group*)data;
+ bool has_data = data != NULL;
+
+ 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->mvp;
+ }
+ return (shader_data_layout){ .name = "global_ubo", .bindings = { b1}, .bindings_count = 1 };
+}