summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/animation.h2
-rw-r--r--src/maths/maths.h4
-rw-r--r--src/maths/maths_types.h5
-rw-r--r--src/new_render/render.c4
-rw-r--r--src/new_render/render_frame.c2
-rw-r--r--src/ral/backends/opengl/backend_opengl.c26
-rw-r--r--src/ral/backends/opengl/backend_opengl.h2
-rw-r--r--src/ral/backends/opengl/opengl_helpers.h11
-rw-r--r--src/ral/ral_types.h5
9 files changed, 46 insertions, 15 deletions
diff --git a/src/animation.h b/src/animation.h
index af2018d..66277e9 100644
--- a/src/animation.h
+++ b/src/animation.h
@@ -37,6 +37,8 @@ KITC_DECL_TYPED_ARRAY(Joint);
#define TYPED_JOINT_ARRAY
#endif
+typedef u32 JointIdx;
+
typedef struct Armature {
char* label;
Joint_darray* joints;
diff --git a/src/maths/maths.h b/src/maths/maths.h
index 3a8f34c..cd5b7b9 100644
--- a/src/maths/maths.h
+++ b/src/maths/maths.h
@@ -15,8 +15,8 @@
// --- Helpers
#define deg_to_rad(x) (x * 3.14 / 180.0)
-#define min(a, b) (a < b ? a : b)
-#define max(a, b) (a > b ? a : b)
+#define MIN(a, b) (a < b ? a : b)
+#define MAX(a, b) (a > b ? a : b)
// --- Vector Implementations
diff --git a/src/maths/maths_types.h b/src/maths/maths_types.h
index f256a9b..3fa3dac 100644
--- a/src/maths/maths_types.h
+++ b/src/maths/maths_types.h
@@ -14,11 +14,6 @@
#define HALF_PI 1.57079632679489661923
#define TAU (2.0 * PI)
-// --- Helpers
-#define deg_to_rad(x) (x * 3.14 / 180.0)
-#define min(a, b) (a < b ? a : b)
-#define max(a, b) (a > b ? a : b)
-
// --- Types
/** @brief 2D Vector */
diff --git a/src/new_render/render.c b/src/new_render/render.c
index dcaa5a5..b5311c8 100644
--- a/src/new_render/render.c
+++ b/src/new_render/render.c
@@ -156,13 +156,15 @@ 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);
+ char* data = stbi_load(path, &width, &height, &num_channels, 0);
if (data) {
DEBUG("loaded texture: %s", path);
} else {
WARN("failed to load texture");
}
+ // printf("width: %d height: %d num channels: %d\n", width, height, num_channels);
+
unsigned int channel_type;
GPU_TextureFormat format;
if (num_channels == 4) {
diff --git a/src/new_render/render_frame.c b/src/new_render/render_frame.c
index 9a95259..87c99e5 100644
--- a/src/new_render/render_frame.c
+++ b/src/new_render/render_frame.c
@@ -2,7 +2,7 @@
#include "render_frame.h"
#include <assert.h>
-#include "logos/threadpool.h"
+// #include "logos/threadpool.h"
#include "mem.h"
#include "render.h"
diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c
index cf3a4e5..4316e75 100644
--- a/src/ral/backends/opengl/backend_opengl.c
+++ b/src/ral/backends/opengl/backend_opengl.c
@@ -233,10 +233,23 @@ TextureHandle GPU_TextureCreate(TextureDesc desc, bool create_view, const void*
glGenTextures(1, &gl_texture_id);
texture->id = gl_texture_id;
- glBindTexture(GL_TEXTURE_2D, gl_texture_id);
+ GLenum gl_tex_type = opengl_tex_type(desc.tex_type);
+ texture->type = desc.tex_type;
+ printf("Creating texture of type %s\n", texture_type_names[desc.tex_type]);
+ glBindTexture(gl_tex_type, gl_texture_id);
- GLint internal_format = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_DEPTH_COMPONENT : GL_RGB;
- GLenum format = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_DEPTH_COMPONENT : GL_RGBA;
+ GLint internal_format;
+ if (desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT) {
+ internal_format = GL_DEPTH_COMPONENT;
+ } else if (desc.format == TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM) {
+ internal_format = GL_RGBA;
+ } else {
+ internal_format = GL_RGB;
+ }
+
+ GLint format = internal_format;
+ // FIXME: GLint format = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_DEPTH_COMPONENT :
+ // GL_RGBA;
GLenum data_type = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_FLOAT : GL_UNSIGNED_BYTE;
if (desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT) {
@@ -257,7 +270,9 @@ TextureHandle GPU_TextureCreate(TextureDesc desc, bool create_view, const void*
if (data) {
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, desc.extents.x, desc.extents.y, 0, format,
data_type, data);
- glGenerateMipmap(GL_TEXTURE_2D);
+ if (desc.tex_type == TEXTURE_TYPE_2D) {
+ glGenerateMipmap(GL_TEXTURE_2D);
+ }
} else {
WARN("No image data provided");
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, desc.extents.x, desc.extents.y, 0, format,
@@ -340,7 +355,8 @@ PUB void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderData
}
glUniform1i(tex_slot, i);
glActiveTexture(GL_TEXTURE0 + i);
- glBindTexture(GL_TEXTURE_CUBE_MAP, tex->id);
+ GLenum gl_tex_type = opengl_tex_type(tex->type);
+ glBindTexture(gl_tex_type, tex->id);
}
}
}
diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h
index fd50830..98ffe95 100644
--- a/src/ral/backends/opengl/backend_opengl.h
+++ b/src/ral/backends/opengl/backend_opengl.h
@@ -60,7 +60,7 @@ typedef struct GPU_Buffer {
typedef struct GPU_Texture {
u32 id;
- void *pad;
+ GPU_TextureType type;
} GPU_Texture;
typedef struct opengl_support {
diff --git a/src/ral/backends/opengl/opengl_helpers.h b/src/ral/backends/opengl/opengl_helpers.h
index f3059ac..f240050 100644
--- a/src/ral/backends/opengl/opengl_helpers.h
+++ b/src/ral/backends/opengl/opengl_helpers.h
@@ -127,4 +127,15 @@ static u32 shader_create_separate(const char* vert_shader, const char* frag_shad
return shader_prog;
}
+static GLenum opengl_tex_type(GPU_TextureType tex_type) {
+ switch (tex_type) {
+ case TEXTURE_TYPE_2D:
+ return GL_TEXTURE_2D;
+ case TEXTURE_TYPE_CUBE_MAP:
+ return GL_TEXTURE_CUBE_MAP;
+ default:
+ return GL_TEXTURE_2D;
+ }
+}
+
#endif
diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h
index a41cf28..d65b35c 100644
--- a/src/ral/ral_types.h
+++ b/src/ral/ral_types.h
@@ -54,6 +54,11 @@ typedef enum GPU_TextureType {
TEXTURE_TYPE_COUNT
} GPU_TextureType;
+static const char* texture_type_names[] = {
+ "RAL Texture 2D", "RAL Texture 3D", "RAL Texture 2D Array",
+ "RAL Texture Cubemap", "RAL Texture Count",
+};
+
typedef enum GPU_TextureFormat {
TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM,
TEXTURE_FORMAT_8_8_8_RGB_UNORM,