summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
author0scar <qgt268@alumni.ku.dk>2024-02-26 13:55:21 +0000
committer0scar <qgt268@alumni.ku.dk>2024-02-27 13:37:27 +0000
commit57a5158400a7e1ccccfd06af292e782d8eff2e4b (patch)
treee68264ce2c4b1ff2e7d9181749015554a1077180 /src/resources
parent2262a2d28fb4930ac21e1b40bfa51de090db6d90 (diff)
Add model asset type
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/CMakeLists.txt1
-rw-r--r--src/resources/include/engine/resources.h12
-rw-r--r--src/resources/include/engine/resources/model.h32
-rw-r--r--src/resources/src/model.c58
4 files changed, 103 insertions, 0 deletions
diff --git a/src/resources/CMakeLists.txt b/src/resources/CMakeLists.txt
index 6cb68d3..8fd9413 100644
--- a/src/resources/CMakeLists.txt
+++ b/src/resources/CMakeLists.txt
@@ -10,6 +10,7 @@ add_library(daw_resources
src/fonts.c
src/scripts.c
src/textures.c
+ src/model.c
)
target_include_directories(daw_resources PRIVATE ${DAW_INCLUDE_DIRS})
diff --git a/src/resources/include/engine/resources.h b/src/resources/include/engine/resources.h
index 707bbde..d967403 100644
--- a/src/resources/include/engine/resources.h
+++ b/src/resources/include/engine/resources.h
@@ -34,6 +34,7 @@ enum Asset {
Asset_shader,
Asset_shaderprog,
Asset_texture,
+ Asset_model,
};
typedef struct {
@@ -69,6 +70,11 @@ typedef struct {
i32 bpc;
} Asset_TextureSpec;
+typedef struct {
+ enum Asset type;
+ const char* path;
+} Asset_ModelSpec;
+
typedef union {
enum Asset type;
Asset_AudioSpec audio;
@@ -76,8 +82,11 @@ typedef union {
Asset_ShaderSpec shader;
Asset_ShaderProgramSpec shaderprog;
Asset_TextureSpec texture;
+ Asset_ModelSpec model;
} asset_t;
+#include <engine/resources/model.h>
+
// The resource spec
typedef struct {
/* Assorted asset specification, makes reloading them easier. */
@@ -93,6 +102,9 @@ typedef struct {
usize texture_len;
Texture* texture;
+
+ usize model_len;
+ Model* model;
} Resources;
#define TextureDefinition(_path, ...) unimplemented
diff --git a/src/resources/include/engine/resources/model.h b/src/resources/include/engine/resources/model.h
new file mode 100644
index 0000000..d22dc21
--- /dev/null
+++ b/src/resources/include/engine/resources/model.h
@@ -0,0 +1,32 @@
+#ifndef ENGINE_RESOURCES_MODEL_H
+#define ENGINE_RESOURCES_MODEL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <engine/core/types.h>
+#include <cglm/cglm.h>
+#include <glad/gl.h>
+
+typedef enum {
+ Model_error,
+ Model_obj,
+} ModelType;
+
+typedef struct {
+ ModelType format;
+
+ GLuint m_uiVAO;
+ GLuint m_uiVBO;
+ GLuint m_uiIBO;
+ unsigned m_uiNumIndices;
+} Model;
+
+#include <engine/resources.h>
+Model load_model(const Asset_ModelSpec *restrict ms);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/resources/src/model.c b/src/resources/src/model.c
new file mode 100644
index 0000000..893036a
--- /dev/null
+++ b/src/resources/src/model.c
@@ -0,0 +1,58 @@
+#include <engine/core/logging.h>
+#include <engine/resources/model.h>
+
+Model load_model(const Asset_ModelSpec *restrict ms) {
+ ModelType format = Model_error;
+
+ isize vertices_len = 0;
+ vec3 *vertices = malloc(sizeof(vec3) * 512);
+ usize *vertices_idx = malloc(sizeof(usize) * 512);
+
+ isize uvs_len = 0;
+ vec2 *uvs = malloc(sizeof(vec2) * 512);
+ usize *uvs_idx = malloc(sizeof(usize) * 512);
+
+ isize normals_len = 0;
+ vec3 *normals = malloc(sizeof(vec3) * 512);
+ usize *normals_idx = malloc(sizeof(usize) * 512);
+
+ // For now, just default to obj
+ format = Model_obj;
+
+ //FILE* f = fopen(ms->path, "r");
+ //if (f == NULL) {
+ // ERROR("Failed to load file " TERM_COLOR_YELLOW "%s" TERM_COLOR_RESET, ms->path);
+ // return (Model){.format = format};
+ //}
+
+ //// Start the import on the given file with some example postprocessing
+ //// Usually - if speed is not the most important aspect for you - you'll t
+ //// probably to request more postprocessing than we do in this example.
+ //const struct aiScene* scene = aiImportFile( pFile,
+ // aiProcess_CalcTangentSpace |
+ // aiProcess_Triangulate |
+ // aiProcess_JoinIdenticalVertices |
+ // aiProcess_SortByPType);
+
+ //// If the import failed, report it
+ //if( NULL == scene) {
+ // DoTheErrorLogging( aiGetErrorString());
+ // return false;
+ //}
+
+ //// Now we can access the file's contents
+ //DoTheSceneProcessing( scene);
+
+ //// We're done. Release all resources associated with this import
+ //aiReleaseImport( scene);
+ //return true;
+
+ {
+ Model m = {};
+ m.format = format;
+
+ // TODO add index array
+
+ return m;
+ }
+}