summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c7
-rw-r--r--src/renderer/builtin_materials.h53
-rw-r--r--src/renderer/immediate.c50
-rw-r--r--src/renderer/immediate.h21
-rw-r--r--src/renderer/render_types.h6
5 files changed, 111 insertions, 26 deletions
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index d9859b2..18cd7ee 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -207,16 +207,11 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, ubo_buf->ubo_binding_point, ubo_buf->id.ubo);
- if (i == 2) {
- // pbr_params_light_uniforms* u = binding.data.bytes.data;
- // vec4* v = &u->viewPos;
- }
glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, binding.data.bytes.data);
} else if (binding.type == SHADER_BINDING_TEXTURE) {
gpu_texture* tex = TEXTURE_GET(binding.data.texture.handle);
- glActiveTexture(GL_TEXTURE0);
- // glActiveTexture(GL_TEXTURE0 + i);
+ glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, tex->id);
}
}
diff --git a/src/renderer/builtin_materials.h b/src/renderer/builtin_materials.h
index 7748599..1a04f32 100644
--- a/src/renderer/builtin_materials.h
+++ b/src/renderer/builtin_materials.h
@@ -102,3 +102,56 @@ static void* shader_layout_get_binding(shader_data_layout* layout, u32 nth_bindi
assert(nth_binding < layout->bindings_count);
return &layout->bindings[nth_binding].data;
}
+
+typedef struct pbr_textures {
+ texture_handle albedo_tex;
+ texture_handle metal_roughness_tex;
+ texture_handle ao_tex;
+ texture_handle normal_tex;
+} pbr_textures;
+
+typedef struct pbr_textured_bindgroup {
+ mvp_matrix_uniforms mvp_matrices;
+ pbr_params_light_uniforms lights;
+ pbr_textures textures;
+} pbr_textured_bindgroup;
+
+static shader_data_layout pbr_textured_shader_layout(void* data) {
+ pbr_textured_bindgroup* d = (pbr_textured_bindgroup*)data;
+ bool has_data = data != NULL;
+
+ shader_binding b1 = { .label = "MVP_Matrices",
+ .type = SHADER_BINDING_BYTES,
+ .stores_data = has_data,
+ .data = { .bytes = { .size = sizeof(mvp_matrix_uniforms) } } };
+
+ shader_binding b2 = { .label = "Scene_Lights",
+ .type = SHADER_BINDING_BYTES,
+ .stores_data = has_data,
+ .data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } };
+
+ shader_binding b3 = {.label = "Albedo",
+ .type = SHADER_BINDING_TEXTURE,
+ .stores_data = has_data };
+ shader_binding b4 = {.label = "Metallic Roughness",
+ .type = SHADER_BINDING_TEXTURE,
+ .stores_data = has_data };
+ shader_binding b5 = {.label = "Ambient Occlusion",
+ .type = SHADER_BINDING_TEXTURE,
+ .stores_data = has_data };
+ shader_binding b6 = {.label = "Normal Vectors",
+ .type = SHADER_BINDING_TEXTURE,
+ .stores_data = has_data };
+
+ if (has_data) {
+ b1.data.bytes.data = &d->mvp_matrices;
+ b2.data.bytes.data = &d->lights;
+ b3.data.texture.handle = d->textures.albedo_tex;
+ b4.data.texture.handle = d->textures.metal_roughness_tex;
+ b5.data.texture.handle = d->textures.ao_tex;
+ b6.data.texture.handle = d->textures.normal_tex;
+ }
+
+ return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3, b4, b5, b6 }, .bindings_count = 6
+ };
+} \ No newline at end of file
diff --git a/src/renderer/immediate.c b/src/renderer/immediate.c
index e76d102..b3431fa 100644
--- a/src/renderer/immediate.c
+++ b/src/renderer/immediate.c
@@ -1,18 +1,50 @@
#include "immediate.h"
+#include "glad/glad.h"
#include "maths.h"
#include "primitives.h"
#include "ral_types.h"
#include "render.h"
+#include "render_types.h"
-void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour) {
- // Create the vertices
- geometry_data geometry = geo_create_uvsphere(radius, 16, 16);
- geo_set_vertex_colours(&geometry, colour);
+typedef struct immdraw_system {
+ // primitive meshes (get reused for each draw call)
+ mesh plane;
+ mesh cube;
+ mesh sphere;
+ // command lists
+
+} immdraw_system;
- // Upload to GPU
- mat4 model = mat4_translation(pos);
+bool immdraw_system_init(immdraw_system* state) {
+ geometry_data plane_geometry = geo_create_plane(f32x2(1, 1));
+ state->plane = mesh_create(&plane_geometry, true);
- // Set pipeline
+ geometry_data cube_geometry = geo_create_cuboid(f32x3(1, 1, 1));
+ state->cube = mesh_create(&cube_geometry, true);
- // Draw
-} \ No newline at end of file
+ geometry_data sphere_geometry = geo_create_uvsphere(1.0, 48, 48);
+ state->sphere = mesh_create(&sphere_geometry, true);
+
+ return true;
+}
+
+void immdraw_plane(vec3 pos, quat rotation, f32 u_scale, f32 v_scale, vec4 colour) {
+
+}
+
+void immdraw_system_render(immdraw_system* state) {
+
+}
+
+// void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour) {
+// // Create the vertices
+// geometry_data geometry = geo_create_uvsphere(radius, 16, 16);
+// geo_set_vertex_colours(&geometry, colour);
+
+// // Upload to GPU
+// mat4 model = mat4_translation(pos);
+
+// // Set pipeline
+
+// // Draw
+// } \ No newline at end of file
diff --git a/src/renderer/immediate.h b/src/renderer/immediate.h
index b9d7c61..f4b1729 100644
--- a/src/renderer/immediate.h
+++ b/src/renderer/immediate.h
@@ -3,18 +3,17 @@
#include "geometry.h"
#include "maths_types.h"
+typedef struct immdraw_system immdraw_system;
+
+bool immdraw_system_init(immdraw_system* state);
+void immdraw_system_shutdown(immdraw_system* state);
+void immdraw_system_render(immdraw_system* state);
+
// 3. SIMA (simplified immediate mode api) / render.h
// - dont need to worry about uploading mesh data
// - very useful for debugging
-void imm_draw_cuboid(vec3 pos, quat rotation, f32x3 extents, vec4 colour);
-void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour);
-void imm_draw_camera_frustum();
-
-// static void imm_draw_model(
-// const char* model_filepath); // tracks internally whether the model is loaded
+void immdraw_plane(vec3 pos, quat rotation, f32 u_scale, f32 v_scale, vec4 colour);
+void immdraw_cuboid(vec3 pos, quat rotation, f32x3 extents, vec4 colour);
+void immdraw_sphere(vec3 pos, f32 radius, vec4 colour);
-// static void imm_draw_model(const char* model_filepath) {
-// check that model is loaded
-// if not loaded, load model and upload to gpu - LRU cache for models
-// else submit draw call
-// } \ No newline at end of file
+void immdraw_camera_frustum();
diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h
index 8588b87..b25fa14 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -35,11 +35,17 @@ typedef struct geometry_data {
rgba colour; /** Optional: set vertex colours */
} geometry_data;
+typedef struct u32_opt {
+ u32 value;
+ bool has_value;
+} u32_opt;
+
// 'Upload' a geometry_data (to GPU) -> get back a mesh
typedef struct mesh {
buffer_handle vertex_buffer;
buffer_handle index_buffer;
geometry_data* geometry; // NULL means it has been freed
+ u32_opt material_index;
bool is_uploaded;
bool is_latent;
} mesh;