summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/maths/primitives.c3
-rw-r--r--src/new_render/render.c12
-rw-r--r--src/new_render/skybox.c49
-rw-r--r--src/new_render/skybox.h2
-rw-r--r--src/ral/ral_common.h2
-rw-r--r--src/ral/ral_types.h5
6 files changed, 60 insertions, 13 deletions
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index 04977a6..233a7e0 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -117,6 +117,9 @@ Geometry Geo_CreateCuboid(f32x3 extents) {
for (u32 i = 0; i < vertices->len; i++) {
u32_darray_push(indices, i);
+ vertices->data[i].static_3d.position =
+ vec3_sub(vertices->data[i].static_3d.position,
+ vec3(0.5, 0.5, 0.5)); // make center of the cube is the origin of mesh space
}
Geometry geo = {
diff --git a/src/new_render/render.c b/src/new_render/render.c
index a757c97..58041dd 100644
--- a/src/new_render/render.c
+++ b/src/new_render/render.c
@@ -142,7 +142,7 @@ TextureData TextureDataLoad(const char* path, bool invert_y) {
stbi_set_flip_vertically_on_load(invert_y);
#pragma GCC diagnostic ignored "-Wpointer-sign"
- char* data = stbi_load(path, &width, &height, &num_channels, STBI_rgb_alpha);
+ char* data = stbi_load(path, &width, &height, &num_channels, STBI_rgb);
if (data) {
DEBUG("loaded texture: %s", path);
} else {
@@ -182,10 +182,12 @@ Mesh Mesh_Create(Geometry* geometry, bool free_on_upload) {
GPU_BufferCreate(vert_bytes, BUFFER_VERTEX, BUFFER_FLAG_GPU, 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);
- m.index_buffer =
- GPU_BufferCreate(index_bytes, BUFFER_INDEX, BUFFER_FLAG_GPU, geometry->indices->data);
+ if (geometry->has_indices) {
+ 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_BufferCreate(index_bytes, BUFFER_INDEX, BUFFER_FLAG_GPU, geometry->indices->data);
+ }
m.is_uploaded = true;
m.geometry = *geometry; // clone geometry data and store on Mesh struct
diff --git a/src/new_render/skybox.c b/src/new_render/skybox.c
index 267ec6d..8ac8356 100644
--- a/src/new_render/skybox.c
+++ b/src/new_render/skybox.c
@@ -12,12 +12,42 @@
#include "render_types.h"
#include "shader_layouts.h"
+float skyboxVertices[] = {
+ // positions
+ -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f,
+
+ -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f,
+ -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f,
+
+ 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f,
+
+ -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f,
+
+ -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f,
+
+ -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f
+};
+
Skybox Skybox_Create(const char** face_paths, int n) {
INFO("Creating a skybox");
assert(n == 6); // ! we're only supporting a full cubemap for now
// -- cube verts
- Geometry geom = Geo_CreateCuboid(f32x3(1.0, 1.0, 1.0));
+ Geometry geom = { .format = VERTEX_POS_ONLY, // doesnt matter
+ .has_indices = false,
+ .indices = NULL,
+ .vertices = Vertex_darray_new(36) };
+ for (u32 i = 0; i < (36 * 3); i += 3) {
+ Vertex_darray_push(
+ geom.vertices,
+ (Vertex){ .pos_only = { .position = vec3(skyboxVertices[i], skyboxVertices[i + 1],
+ skyboxVertices[i + 2]) } });
+ }
Mesh cube = Mesh_Create(&geom, false);
// -- cubemap texture
@@ -64,10 +94,14 @@ Skybox Skybox_Create(const char** face_paths, int n) {
ShaderData camera_data = { .data = NULL, .get_layout = &Binding_Camera_GetLayout };
ShaderData shader_data = { .data = NULL, .get_layout = &Skybox_GetLayout };
+ VertexDescription builder = { .debug_label = "pos only" };
+ VertexDesc_AddAttr(&builder, "inPosition", ATTR_F32x3);
+ builder.use_full_vertex_size = true;
+
GraphicsPipelineDesc pipeline_desc = {
.debug_name = "Skybox pipeline",
- .vertex_desc = static_3d_vertex_description(),
- .data_layouts = { camera_data, shader_data },
+ .vertex_desc = builder,
+ .data_layouts = { shader_data, camera_data },
.data_layouts_count = 2,
.vs = { .debug_name = "Skybox Vertex Shader",
.filepath = vert_path,
@@ -75,7 +109,7 @@ Skybox Skybox_Create(const char** face_paths, int n) {
.fs = { .debug_name = "Skybox Fragment Shader",
.filepath = frag_path,
.code = fragment_shader.contents },
- .wireframe = false,
+ .wireframe = true,
.depth_test = true,
};
@@ -86,6 +120,7 @@ Skybox Skybox_Create(const char** face_paths, int n) {
void Skybox_Draw(Skybox* skybox, Camera camera) {
GPU_CmdEncoder* enc = GPU_GetDefaultEncoder();
+ glDepthFunc(GL_LEQUAL);
GPU_CmdEncoder_BeginRender(enc, skybox->pipeline->renderpass);
GPU_EncodeBindPipeline(enc, skybox->pipeline);
GPU_EncodeSetDefaults(enc);
@@ -118,9 +153,9 @@ void Skybox_Draw(Skybox* skybox, Camera camera) {
GPU_EncodeSetVertexBuffer(enc, skybox->cube.vertex_buffer);
GPU_EncodeSetIndexBuffer(enc, skybox->cube.index_buffer);
- glDepthFunc(GL_LEQUAL);
- GPU_EncodeDrawIndexed(enc, skybox->cube.geometry.indices->len);
- glDepthFunc(GL_LESS);
+
+ GPU_EncodeDraw(enc, 36);
GPU_CmdEncoder_EndRender(enc);
+ glDepthFunc(GL_LESS);
}
diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h
index bf70976..71262fd 100644
--- a/src/new_render/skybox.h
+++ b/src/new_render/skybox.h
@@ -27,7 +27,7 @@ static ShaderDataLayout Skybox_GetLayout(void* data) {
bool has_data = data != NULL;
ShaderBinding b1 = {
- .label = "cubemap",
+ .label = "cubeMap",
.vis = VISIBILITY_FRAGMENT,
.kind = BINDING_TEXTURE,
};
diff --git a/src/ral/ral_common.h b/src/ral/ral_common.h
index 6a373ee..98f54ed 100644
--- a/src/ral/ral_common.h
+++ b/src/ral/ral_common.h
@@ -39,6 +39,8 @@ struct ResourcePools {
typedef struct ResourcePools ResourcePools;
void ResourcePools_Init(arena* a, struct ResourcePools* res_pools);
+PUB GPU_Renderpass* GPU_GetDefaultRenderpass(); // returns a renderpass that draws directly to default framebuffer with default depth
+
// --- Vertex formats
VertexDescription static_3d_vertex_description();
diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h
index 54dba56..bb15d2a 100644
--- a/src/ral/ral_types.h
+++ b/src/ral/ral_types.h
@@ -76,6 +76,7 @@ typedef enum VertexFormat {
VERTEX_SKINNED,
VERTEX_COLOURED_STATIC_3D,
VERTEX_RAW_POS_COLOUR,
+ VERTEX_POS_ONLY,
VERTEX_COUNT
} VertexFormat;
@@ -112,6 +113,10 @@ typedef union Vertex {
Vec2 position;
Vec3 colour;
} raw_pos_colour;
+
+ struct {
+ Vec3 position;
+ } pos_only;
} Vertex;
#ifndef TYPED_VERTEX_ARRAY