summaryrefslogtreecommitdiff
path: root/src/render/immdraw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/immdraw.c')
-rw-r--r--src/render/immdraw.c58
1 files changed, 47 insertions, 11 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