summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-13 17:25:13 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-13 17:25:13 +1000
commit13949ca02bcf9fcdfcc48ea7949f617553a260b6 (patch)
tree28361375cc637c8442db3c79d274eaca0f4fbf00
parent87a8749049d74cc8aa3f0cacf0b896640dc53763 (diff)
allow UV tiling for plane geometry
-rw-r--r--src/maths/primitives.c21
-rw-r--r--src/maths/primitives.h2
-rw-r--r--src/render/immdraw.c2
-rw-r--r--src/render/render.c2
-rw-r--r--src/render/shadows.c2
-rw-r--r--src/systems/grid.c2
6 files changed, 17 insertions, 14 deletions
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index 1e1e673..13fa81b 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -20,7 +20,8 @@ Vec3 plane_vertex_positions[] = {
(Vec3){ 0.5, 0, 0.5 },
};
-Geometry Geo_CreatePlane(f32x2 extents) {
+Geometry Geo_CreatePlane(f32x2 extents, u32 tiling_u, u32 tiling_v) {
+ CASSERT(tiling_u >= 1 && tiling_v >= 1);
Vertex_darray* vertices = Vertex_darray_new(4);
u32_darray* indices = u32_darray_new(vertices->len);
@@ -30,15 +31,15 @@ Geometry Geo_CreatePlane(f32x2 extents) {
vert_pos[i].x *= extents.x;
vert_pos[i].z *= extents.y;
}
- VERT_3D(vertices, vert_pos[0], VEC3_Y, vec2(0, 0)); // back left
- VERT_3D(vertices, vert_pos[1], VEC3_Y, vec2(1, 0)); // back right
- VERT_3D(vertices, vert_pos[2], VEC3_Y, vec2(0, 1)); // front left
- VERT_3D(vertices, vert_pos[3], VEC3_Y, vec2(1, 1)); // front right
-
- push_triangle(indices, 0, 1, 2);
- push_triangle(indices, 2, 1, 3);
- // push_triangle(indices, 2, 1, 0);
- // push_triangle(indices, 3, 2, 1);
+ VERT_3D(vertices, vert_pos[0], VEC3_Y, vec2(0, 0)); // back left
+ VERT_3D(vertices, vert_pos[1], VEC3_Y, vec2(1 * tiling_u, 0 * tiling_v)); // back right
+ VERT_3D(vertices, vert_pos[2], VEC3_Y, vec2(0, 1 * tiling_v)); // front left
+ VERT_3D(vertices, vert_pos[3], VEC3_Y, vec2(1 * tiling_u, 1 * tiling_v)); // front right
+
+ // push_triangle(indices, 0, 1, 2);
+ // push_triangle(indices, 2, 1, 3);
+ push_triangle(indices, 2, 1, 0);
+ push_triangle(indices, 1,2,3);
for (int i = 0; i < 4; i++) {
printf("Vertex %d: (%f, %f, %f)\n", i, vert_pos[i].x, vert_pos[i].y, vert_pos[i].z);
diff --git a/src/maths/primitives.h b/src/maths/primitives.h
index f7b390d..bcf71c8 100644
--- a/src/maths/primitives.h
+++ b/src/maths/primitives.h
@@ -6,7 +6,7 @@
#include "maths_types.h"
#include "render_types.h"
-Geometry Geo_CreatePlane(f32x2 extents);
+Geometry Geo_CreatePlane(f32x2 extents, u32 tiling_u, u32 tiling_v);
Geometry Geo_CreateCuboid(f32x3 extents);
Geometry Geo_CreateCylinder(f32 radius, f32 height, u32 resolution);
Geometry Geo_CreateUVsphere(f32 radius, u32 north_south_lines, u32 east_west_lines);
diff --git a/src/render/immdraw.c b/src/render/immdraw.c
index a097f90..c2589c3 100644
--- a/src/render/immdraw.c
+++ b/src/render/immdraw.c
@@ -22,7 +22,7 @@ void Immdraw_Init(Immdraw_Storage* storage) {
Geometry cube_geo = Geo_CreateCuboid(f32x3(1.0, 1.0, 1.0));
storage->cube = Mesh_Create(&cube_geo, true);
- Geometry plane_geo = Geo_CreatePlane(f32x2(1.0, 1.0));
+ Geometry plane_geo = Geo_CreatePlane(f32x2(1.0, 1.0), 1, 1);
storage->plane = Mesh_Create(&plane_geo, true);
storage->bbox = GenBboxMesh();
diff --git a/src/render/render.c b/src/render/render.c
index 26007b7..4e7a60c 100644
--- a/src/render/render.c
+++ b/src/render/render.c
@@ -155,6 +155,8 @@ void Renderer_Shutdown(Renderer* ren) {
DEBUG("Freed PBR storage");
free(ren->terrain);
DEBUG("Freed Terrain storage");
+ free(ren->immediate);
+ DEBUG("Freed Immdraw storage");
arena_free_storage(&ren->frame_arena);
DEBUG("Freed frame allocator buffer");
}
diff --git a/src/render/shadows.c b/src/render/shadows.c
index 499ec02..3d348ea 100644
--- a/src/render/shadows.c
+++ b/src/render/shadows.c
@@ -127,7 +127,7 @@ void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_hei
storage->debugquad_pipeline =
GPU_GraphicsPipeline_Create(debugquad_pipeline_desc, storage->debugquad_pass);
- Geometry quad_geo = Geo_CreatePlane(f32x2(1, 1));
+ Geometry quad_geo = Geo_CreatePlane(f32x2(1, 1), 1,1 );
// HACK: Swap vertices to make it face us
Vertex top0 = quad_geo.vertices->data[0];
quad_geo.vertices->data[0] = quad_geo.vertices->data[2];
diff --git a/src/systems/grid.c b/src/systems/grid.c
index 6e62a21..e907865 100644
--- a/src/systems/grid.c
+++ b/src/systems/grid.c
@@ -13,7 +13,7 @@
void Grid_Init(Grid_Storage* storage) {
INFO("Infinite Grid initialisation");
- Geometry plane_geo = Geo_CreatePlane(f32x2(1.0, 1.0));
+ Geometry plane_geo = Geo_CreatePlane(f32x2(1.0, 1.0), 1, 1);
Mesh plane_mesh = Mesh_Create(&plane_geo, true);
storage->plane_vertices = plane_mesh.vertex_buffer;