summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/assets.c22
-rw-r--r--src/objects/pass.c4
-rw-r--r--src/objects/pass.h2
-rw-r--r--src/texture.c6
-rw-r--r--src/texture.h2
5 files changed, 20 insertions, 16 deletions
diff --git a/src/assets.c b/src/assets.c
index c11f09f..309aaa0 100644
--- a/src/assets.c
+++ b/src/assets.c
@@ -19,6 +19,16 @@ static mri_asset asset_void() {
};
}
+static mri_asset asset_from_slice(char *path, unsigned char* begin, unsigned char *end) {
+ return (mri_asset) {
+ .type = ASSET_SLICE,
+ .size = end - begin,
+ .pos = 0,
+ .data = begin,
+ .hash = djb2_hash((unsigned char *)path)
+ };
+}
+
static mri_asset asset_from_path(char *path) {
FILE *asset_file = fopen(path, "rb");
@@ -55,16 +65,6 @@ static mri_asset asset_from_path(char *path) {
return asset;
}
-static mri_asset asset_from_slice(char *path, unsigned char* begin, unsigned char *end) {
- return (mri_asset) {
- .type = ASSET_SLICE,
- .size = end - begin,
- .pos = 0,
- .data = begin,
- .hash = djb2_hash((unsigned char *)path)
- };
-}
-
static void mri_asset_manager_init() {
mvec_init(asset_manager.files);
}
@@ -144,7 +144,7 @@ mri_asset *mri_asset_manager_get(const char *part, mri_file_type_hint hint) {
}
if (ret == -1) {
- log_error("%s", "failed to alloc string");
+ log_error("%s", "failed to build string");
return NULL;
}
diff --git a/src/objects/pass.c b/src/objects/pass.c
index c2107aa..c90eb92 100644
--- a/src/objects/pass.c
+++ b/src/objects/pass.c
@@ -9,8 +9,8 @@ void mri_pass_parse(mri_pass *pass, json_t *root) {
json_t *textures = json_object_get(root, "textures");
json_array(texture, textures) {
if (json_is_string(texture)) {
- //mri_texture_load(&pass->textures[0], mri_asset_manager_get(json_string_value(texture), TEXTURE));
- //mri_texture_unload(&pass->textures[0]);
+ pass->textures[i] = mri_texture_load(mri_asset_manager_get(json_string_value(texture), TEXTURE));
+ mri_texture_unload(pass->textures[i]);
}
}
}
diff --git a/src/objects/pass.h b/src/objects/pass.h
index fca8bac..aa8e2fb 100644
--- a/src/objects/pass.h
+++ b/src/objects/pass.h
@@ -8,7 +8,7 @@
typedef struct {
// mri_shader *shader;
// mri_material *material;
- mri_texture textures[7];
+ mri_texture *textures[7];
// mvec(mri_uniform) uniforms;
// mvec(mri_combo) combos;
diff --git a/src/texture.c b/src/texture.c
index e649bb4..9f10dca 100644
--- a/src/texture.c
+++ b/src/texture.c
@@ -13,9 +13,11 @@ static unsigned char *load_image_rgba(unsigned char *data, int len) {
return stbi_load_from_memory(data, len, &w, &h, &channels, 4);
}
-void mri_texture_load(mri_texture *t, mri_asset *_asset) {
+mri_texture *mri_texture_load(mri_asset *_asset) {
// check if texture was previously loaded
+ mri_texture *t = (mri_texture *)malloc(sizeof(mri_texture));
+
mri_asset asset = *_asset;
mri_str type = read_string(asset, 9);
@@ -115,6 +117,8 @@ void mri_texture_load(mri_texture *t, mri_asset *_asset) {
seek(asset, byte_count);
}
+
+ return t;
}
void mri_texture_unload(mri_texture *texture) {
diff --git a/src/texture.h b/src/texture.h
index 4a1411d..a750ba6 100644
--- a/src/texture.h
+++ b/src/texture.h
@@ -47,7 +47,7 @@ typedef struct {
mri_texture_version version;
} mri_texture;
-void mri_texture_load(mri_texture *t, mri_asset *_asset);
+mri_texture *mri_texture_load(mri_asset *_asset);
void mri_texture_unload(mri_texture *texture);
#endif // _TEXTURE_H