summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/immdraw.c58
-rw-r--r--src/render/immdraw.h6
-rw-r--r--src/render/pbr.c2
-rw-r--r--src/render/shadows.c4
-rw-r--r--src/render/skybox.c2
5 files changed, 57 insertions, 15 deletions
diff --git a/src/render/immdraw.c b/src/render/immdraw.c
index 142087a..a097f90 100644
--- a/src/render/immdraw.c
+++ b/src/render/immdraw.c
@@ -3,28 +3,29 @@
#include "file.h"
#include "log.h"
#include "maths.h"
+#include "maths_types.h"
#include "primitives.h"
#include "ral_common.h"
#include "ral_impl.h"
#include "ral_types.h"
#include "render.h"
+#include "render_types.h"
#include "shader_layouts.h"
-// Forward declares
-void Immdraw_Primitive(Transform tf, f32 size, Vec4 colour, bool wireframe, Mesh mesh);
-
void Immdraw_Init(Immdraw_Storage* storage) {
INFO("Immediate drawing initialisation");
// Meshes
Geometry sphere_geo = Geo_CreateUVsphere(1.0, 16, 16);
- storage->sphere = Mesh_Create(&sphere_geo, false);
+ storage->sphere = Mesh_Create(&sphere_geo, true);
Geometry cube_geo = Geo_CreateCuboid(f32x3(1.0, 1.0, 1.0));
- storage->cube = Mesh_Create(&cube_geo, false);
+ storage->cube = Mesh_Create(&cube_geo, true);
Geometry plane_geo = Geo_CreatePlane(f32x2(1.0, 1.0));
- storage->plane = Mesh_Create(&plane_geo, false);
+ storage->plane = Mesh_Create(&plane_geo, true);
+
+ storage->bbox = GenBboxMesh();
// Pipeline / material
VertexDescription vertex_desc = {
@@ -64,20 +65,27 @@ void Immdraw_Shutdown(Immdraw_Storage* storage) {
void Immdraw_Sphere(Transform tf, Vec4 colour, bool wireframe) {
TRACE("Draw sphere");
Immdraw_Storage* imm = Render_GetImmdrawStorage();
- Immdraw_Primitive(tf, 1.0, colour, wireframe, imm->sphere);
+ Immdraw_Primitive(tf, CEL_TRI, 1.0, colour, wireframe, imm->sphere);
}
void Immdraw_Cuboid(Transform tf, Vec4 colour, bool wireframe) {
TRACE("Draw cube");
Immdraw_Storage* imm = Render_GetImmdrawStorage();
- Immdraw_Primitive(tf, 1.0, colour, wireframe, imm->cube);
+ Immdraw_Primitive(tf, CEL_TRI, 1.0, colour, wireframe, imm->cube);
}
void Immdraw_Plane(Transform tf, Vec4 colour, bool wireframe) {
TRACE("Draw plane");
Immdraw_Storage* imm = Render_GetImmdrawStorage();
- Immdraw_Primitive(tf, 1.0, colour, wireframe, imm->plane);
+ Immdraw_Primitive(tf, CEL_TRI, 1.0, colour, wireframe, imm->plane);
+}
+
+PUB void Immdraw_Bbox(Transform tf, Vec4 colour, bool wireframe) {
+ TRACE("Draw bbox");
+ Immdraw_Storage* imm = Render_GetImmdrawStorage();
+ Immdraw_Primitive(tf, CEL_LINE, 1.0, colour, wireframe, imm->bbox);
}
-void Immdraw_Primitive(Transform tf, f32 size, Vec4 colour, bool wireframe, Mesh mesh) {
+void Immdraw_Primitive(Transform tf, PrimitiveTopology topology, f32 size, Vec4 colour,
+ bool wireframe, Mesh mesh) {
Immdraw_Storage* imm = Render_GetImmdrawStorage();
GPU_CmdEncoder* enc = GPU_GetDefaultEncoder();
@@ -115,8 +123,36 @@ void Immdraw_Primitive(Transform tf, f32 size, Vec4 colour, bool wireframe, Mesh
// draw call
GPU_EncodeSetVertexBuffer(enc, mesh.vertex_buffer);
GPU_EncodeSetIndexBuffer(enc, mesh.index_buffer);
- GPU_EncodeDrawIndexed(enc, mesh.geometry.index_count);
+ GPU_EncodeDrawIndexed(enc, topology, mesh.geometry.index_count);
// end renderpass
GPU_CmdEncoder_EndRender(enc);
}
+
+Mesh GenBboxMesh() {
+ Vertex_darray* vertices = Vertex_darray_new(8);
+ u32_darray* indices = u32_darray_new(24);
+
+ // normals & uvs dont matter
+ VERT_3D(vertices, FRONT_BOT_LEFT, VEC3_NEG_Z, vec2(0, 0));
+ VERT_3D(vertices, FRONT_BOT_RIGHT, VEC3_NEG_Z, vec2(0, 0));
+ VERT_3D(vertices, BACK_BOT_LEFT, VEC3_NEG_Z, vec2(0, 0));
+ VERT_3D(vertices, BACK_BOT_RIGHT, VEC3_NEG_Z, vec2(0, 0));
+ VERT_3D(vertices, FRONT_TOP_LEFT, VEC3_NEG_Z, vec2(0, 0));
+ VERT_3D(vertices, FRONT_TOP_RIGHT, VEC3_NEG_Z, vec2(0, 0));
+ VERT_3D(vertices, BACK_TOP_LEFT, VEC3_NEG_Z, vec2(0, 0));
+ VERT_3D(vertices, BACK_TOP_RIGHT, VEC3_NEG_Z, vec2(0, 0));
+
+ u32 line_indices[24] = { 0, 1, 2, 3, 0, 2, 1, 3, 4, 5, 6, 7, 4, 6, 5, 7, 0, 4, 1, 5, 2, 6, 3, 7 };
+ for (u32 i = 0; i < 24; i++) {
+ u32_darray_push(indices, line_indices[i]);
+ }
+
+ Geometry geo = { .format = VERTEX_STATIC_3D,
+ .has_indices = true,
+ .index_count = indices->len,
+ .vertices = vertices,
+ .indices = indices };
+
+ return Mesh_Create(&geo, true);
+} \ No newline at end of file
diff --git a/src/render/immdraw.h b/src/render/immdraw.h
index 6b456d5..aa1847b 100644
--- a/src/render/immdraw.h
+++ b/src/render/immdraw.h
@@ -13,6 +13,7 @@ typedef struct Immdraw_Storage {
Mesh plane;
Mesh cube;
Mesh sphere;
+ Mesh bbox;
GPU_Pipeline* colour_pipeline; /** @brief Pipeline for drawing geometry that has vertex colours */
} Immdraw_Storage;
@@ -30,11 +31,16 @@ PUB void Immdraw_Shutdown(Immdraw_Storage* storage);
PUB void Immdraw_Plane(Transform tf, Vec4 colour, bool wireframe);
PUB void Immdraw_Cuboid(Transform tf, Vec4 colour, bool wireframe);
PUB void Immdraw_Sphere(Transform tf, Vec4 colour, bool wireframe);
+PUB void Immdraw_Bbox(Transform tf, Vec4 colour, bool wireframe);
PUB void Immdraw_TransformGizmo(Transform tf, f32 size);
// --- Internal
+void Immdraw_Primitive(Transform tf, PrimitiveTopology topology, f32 size, Vec4 colour, bool wireframe, Mesh mesh);
+
+Mesh GenBboxMesh();
+
static ShaderDataLayout ImmediateUniforms_GetLayout(void* data) {
ImmediateUniforms* d = (ImmediateUniforms*)data;
bool has_data = data != NULL;
diff --git a/src/render/pbr.c b/src/render/pbr.c
index 1a7b4de..fbdacac 100644
--- a/src/render/pbr.c
+++ b/src/render/pbr.c
@@ -120,7 +120,7 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te
GPU_EncodeSetVertexBuffer(enc, mesh->vertex_buffer);
GPU_EncodeSetIndexBuffer(enc, mesh->index_buffer);
// draw
- GPU_EncodeDrawIndexed(enc, mesh->geometry.index_count);
+ GPU_EncodeDrawIndexedTris(enc, mesh->geometry.index_count);
}
GPU_CmdEncoder_EndRender(enc);
diff --git a/src/render/shadows.c b/src/render/shadows.c
index 18a5f7a..499ec02 100644
--- a/src/render/shadows.c
+++ b/src/render/shadows.c
@@ -167,7 +167,7 @@ void Shadow_DrawDebugQuad() {
GPU_EncodeBindShaderData(enc, 0, quad_data);
GPU_EncodeSetVertexBuffer(enc, shadow_storage->quad.vertex_buffer);
GPU_EncodeSetIndexBuffer(enc, shadow_storage->quad.index_buffer);
- GPU_EncodeDrawIndexed(enc, shadow_storage->quad.geometry.indices->len);
+ GPU_EncodeDrawIndexedTris(enc, shadow_storage->quad.geometry.indices->len);
GPU_CmdEncoder_EndRender(enc);
}
@@ -201,7 +201,7 @@ void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform
GPU_EncodeBindShaderData(&shadow_encoder, 0, shader_data);
GPU_EncodeSetVertexBuffer(&shadow_encoder, mesh->vertex_buffer);
GPU_EncodeSetIndexBuffer(&shadow_encoder, mesh->index_buffer);
- GPU_EncodeDrawIndexed(&shadow_encoder, mesh->geometry.indices->len);
+ GPU_EncodeDrawIndexedTris(&shadow_encoder, mesh->geometry.indices->len);
}
}
diff --git a/src/render/skybox.c b/src/render/skybox.c
index b228c82..b4e1e42 100644
--- a/src/render/skybox.c
+++ b/src/render/skybox.c
@@ -154,7 +154,7 @@ void Skybox_Draw(Skybox* skybox, Camera camera) {
GPU_EncodeSetVertexBuffer(enc, skybox->cube.vertex_buffer);
GPU_EncodeSetIndexBuffer(enc, skybox->cube.index_buffer);
- GPU_EncodeDraw(enc, 36);
+ GPU_EncodeDrawTris(enc, 36);
GPU_CmdEncoder_EndRender(enc);
glDepthFunc(GL_LESS);