summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/backends/metal/backend_metal.m2
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c7
-rw-r--r--src/renderer/backends/opengl/backend_opengl.h4
-rw-r--r--src/renderer/backends/opengl/opengl_helpers.h1
-rw-r--r--src/renderer/ral_types.h1
-rw-r--r--src/renderer/render.c48
-rw-r--r--src/renderer/render.h19
-rw-r--r--src/renderer/render_types.h42
8 files changed, 69 insertions, 55 deletions
diff --git a/src/renderer/backends/metal/backend_metal.m b/src/renderer/backends/metal/backend_metal.m
index 0e9399e..4787755 100644
--- a/src/renderer/backends/metal/backend_metal.m
+++ b/src/renderer/backends/metal/backend_metal.m
@@ -1,5 +1,5 @@
#include <assert.h>
-#define CEL_REND_BACKEND_METAL
+// #define CEL_REND_BACKEND_METAL
#if defined(CEL_REND_BACKEND_METAL)
#include <stddef.h>
#include "ral_types.h"
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index ba9435e..de6b71a 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -44,7 +44,7 @@ bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) {
resource_pools_init(&context.pool_arena, context.resource_pools);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
@@ -132,7 +132,7 @@ gpu_cmd_encoder gpu_cmd_encoder_create() {
void gpu_cmd_encoder_destroy(gpu_cmd_encoder* encoder) {}
void gpu_cmd_encoder_begin(gpu_cmd_encoder encoder) {}
void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* renderpass) {
- rgba clear_colour = STONE_900;
+ rgba clear_colour = STONE_800;
glClearColor(clear_colour.r, clear_colour.g, clear_colour.b, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
@@ -181,7 +181,8 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d
glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, data->data);
} else if (binding.type == SHADER_BINDING_TEXTURE) {
gpu_texture* tex = TEXTURE_GET(binding.data.texture.handle);
- glActiveTexture(GL_TEXTURE0 + i);
+ glActiveTexture(GL_TEXTURE0);
+ // glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, tex->id);
}
}
diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h
index 348eb41..f3b4eb7 100644
--- a/src/renderer/backends/opengl/backend_opengl.h
+++ b/src/renderer/backends/opengl/backend_opengl.h
@@ -45,6 +45,10 @@ typedef struct gpu_texture {
void *pad
} gpu_texture;
+typedef struct opengl_support {
+
+} opengl_support;
+
u32 shader_create_separate(const char *vert_shader, const char *frag_shader);
void uniform_vec3f(u32 program_id, const char *uniform_name, vec3 *value);
diff --git a/src/renderer/backends/opengl/opengl_helpers.h b/src/renderer/backends/opengl/opengl_helpers.h
index a3c4014..41018cb 100644
--- a/src/renderer/backends/opengl/opengl_helpers.h
+++ b/src/renderer/backends/opengl/opengl_helpers.h
@@ -43,6 +43,7 @@ static opengl_vertex_attr format_from_vertex_attr(vertex_attrib_type attr) {
}
static u32 opengl_bindcreate_vao(gpu_buffer* buf, vertex_description desc) {
+ DEBUG("Vertex format name %s", desc.debug_label);
// 1. Bind the buffer
glBindBuffer(GL_ARRAY_BUFFER, buf->id.vbo);
// 2. Create new VAO
diff --git a/src/renderer/ral_types.h b/src/renderer/ral_types.h
index f1f7809..f1f261d 100644
--- a/src/renderer/ral_types.h
+++ b/src/renderer/ral_types.h
@@ -21,7 +21,6 @@ CORE_DEFINE_HANDLE(buffer_handle);
CORE_DEFINE_HANDLE(texture_handle);
CORE_DEFINE_HANDLE(sampler_handle);
CORE_DEFINE_HANDLE(shader_handle);
-CORE_DEFINE_HANDLE(model_handle);
CORE_DEFINE_HANDLE(pipeline_layout_handle);
CORE_DEFINE_HANDLE(pipeline_handle);
CORE_DEFINE_HANDLE(renderpass_handle);
diff --git a/src/renderer/render.c b/src/renderer/render.c
index 7833ac9..f9e8ccf 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -66,7 +66,7 @@ bool renderer_init(renderer* ren) {
// default_material_init();
// Create default rendering pipeline
- /* default_pipelines_init(ren); */
+ default_pipelines_init(ren);
return true;
}
@@ -86,36 +86,40 @@ void default_pipelines_init(renderer* ren) {
ren->default_renderpass = *renderpass;
printf("Load shaders\n");
- str8 vert_path = str8lit("build/linux/x86_64/debug/triangle.vert.spv");
- str8 frag_path = str8lit("build/linux/x86_64/debug/triangle.frag.spv");
- /* str8 vert_path =
- * str8lit("/home/void/code/celeritas-engine/celeritas-core/build/linux/x86_64/debug/triangle.vert.spv");
- */
- /* str8 frag_path =
- * str8lit("/home/void/code/celeritas-engine/celeritas-core/build/linux/x86_64/debug/triangle.frag.spv");
- */
+ str8 vert_path, frag_path;
+#ifdef CEL_REND_BACKEND_OPENGL
+ vert_path = str8lit("assets/shaders/cube.vert");
+ frag_path = str8lit("assets/shaders/cube.frag");
+#else
+ vert_path = str8lit("build/linux/x86_64/debug/cube.vert.spv");
+ frag_path = str8lit("build/linux/x86_64/debug/cube.frag.spv");
+#endif
str8_opt vertex_shader = str8_from_file(&scratch, vert_path);
str8_opt fragment_shader = str8_from_file(&scratch, frag_path);
if (!vertex_shader.has_value || !fragment_shader.has_value) {
ERROR_EXIT("Failed to load shaders from disk")
}
+ if (!vertex_shader.has_value || !fragment_shader.has_value) {
+ ERROR_EXIT("Failed to load shaders from disk")
+ }
- vertex_description vertex_input;
+ 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;
struct graphics_pipeline_desc pipeline_description = {
.debug_name = "Basic Pipeline",
.vertex_desc = vertex_input,
// .data_layouts
// .data_layouts_count
- .vs = { .debug_name = "Triangle Vertex Shader",
+ .vs = { .debug_name = "Basic Vertex Shader",
.filepath = vert_path,
.code = vertex_shader.contents,
.is_spirv = true },
- .fs = { .debug_name = "Triangle Fragment Shader",
+ .fs = { .debug_name = "Basic Fragment Shader",
.filepath = frag_path,
.code = fragment_shader.contents,
.is_spirv = true },
@@ -153,16 +157,20 @@ void render_frame_end(renderer* ren) {
}
void render_frame_draw(renderer* ren) {}
+bool mesh_has_indices(mesh* m) {
+ return m->geometry->has_indices;
+}
+
void draw_mesh(mesh* mesh, mat4* model) { // , 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) {
+ 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); */
- encode_draw_indexed(enc, mesh->index_count);
+ encode_draw_indexed(enc, mesh->geometry->indices->len);
}
void gfx_backend_draw_frame(renderer* ren, camera* camera, mat4 model, texture* tex) {}
@@ -182,15 +190,15 @@ mesh mesh_create(geometry_data* geometry, bool free_on_upload) {
geometry->vertices->data);
// 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);
+ 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);
+ 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;
- m.index_count = geometry->indices.len;
- m.vertices = geometry;
+ // m.has_indices = geometry->has_indices;
+ // m.index_count = geometry->indices.len;
+ m.geometry = geometry;
if (free_on_upload) {
geo_free_data(geometry);
}
diff --git a/src/renderer/render.h b/src/renderer/render.h
index c193ff9..b745e7a 100644
--- a/src/renderer/render.h
+++ b/src/renderer/render.h
@@ -13,6 +13,25 @@
#include "ral_types.h"
#include "render_types.h"
+/** @brief configuration passed to the renderer at init time */
+typedef struct renderer_config {
+ char window_name[256];
+ u32 scr_width, scr_height;
+ vec3 clear_colour; /** colour that the screen gets cleared to every frame */
+} renderer_config;
+
+typedef struct renderer {
+ struct GLFWwindow* window;
+ void* backend_context;
+ renderer_config config;
+ gpu_device device;
+ gpu_swapchain swapchain;
+ gpu_renderpass default_renderpass;
+ gpu_pipeline static_opaque_pipeline;
+ bool frame_aborted;
+ struct resource_pools* resource_pools;
+} renderer;
+
bool renderer_init(renderer* ren);
void renderer_shutdown(renderer* ren);
diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h
index 349f65a..2d9cf58 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -26,30 +26,11 @@
struct GLFWwindow;
-/** @brief configuration passed to the renderer at init time */
-typedef struct renderer_config {
- char window_name[256];
- u32 scr_width, scr_height;
- vec3 clear_colour; /** colour that the screen gets cleared to every frame */
-} renderer_config;
-
-typedef struct renderer {
- struct GLFWwindow* window;
- void* backend_context;
- renderer_config config;
- gpu_device device;
- gpu_swapchain swapchain;
- gpu_renderpass default_renderpass;
- gpu_pipeline static_opaque_pipeline;
- bool frame_aborted;
- struct resource_pools* resource_pools;
-} renderer;
-
typedef struct geometry_data {
vertex_format format;
vertex_darray* vertices; // TODO: make it not a pointer
bool has_indices;
- u32_darray indices;
+ u32_darray* indices;
vec3 colour; /** Optional: set vertex colours */
} geometry_data;
@@ -57,25 +38,31 @@ typedef struct geometry_data {
typedef struct mesh {
buffer_handle vertex_buffer;
buffer_handle index_buffer;
- u32 index_count;
- bool has_indices;
- geometry_data* vertices; // NULL means it has been freed
+ geometry_data* geometry; // NULL means it has been freed
bool is_uploaded;
bool is_latent;
} mesh;
+#ifndef TYPED_MESH_ARRAY
+KITC_DECL_TYPED_ARRAY(mesh)
+#define TYPED_MESH_ARRAY
+#endif
+
/* Hot reloading:
C side - reload_model():
- load model from disk using existing loader
- remove from transform graph so it isnt tried to be drawn
*/
+CORE_DEFINE_HANDLE(model_handle);
+
typedef struct model {
str8 name;
- mesh* meshes;
- u32 mesh_count;
+ mesh_darray* meshes;
} model;
+TYPED_POOL(model, model)
+
typedef struct texture {
} texture;
@@ -103,11 +90,6 @@ typedef blinn_phong_material material;
extern material DEFAULT_MATERIAL;
void default_material_init();
-#ifndef TYPED_MESH_ARRAY
-KITC_DECL_TYPED_ARRAY(mesh)
-#define TYPED_MESH_ARRAY
-#endif
-
#ifndef TYPED_MODEL_ARRAY
KITC_DECL_TYPED_ARRAY(model)
#define TYPED_MODEL_ARRAY