From 00a9bf78069bd41f52ba4fed4c5a4c79c0cb1c8b Mon Sep 17 00:00:00 2001 From: matthew Date: Wed, 18 Jun 2025 19:05:56 +1000 Subject: [PATCH] more fixes, basic model loading/rendering complete --- src/assets.cpp | 140 +++-------------------------------------------- src/renderer.cpp | 9 ++- 2 files changed, 15 insertions(+), 134 deletions(-) diff --git a/src/assets.cpp b/src/assets.cpp index cd2f17f..f37402e 100644 --- a/src/assets.cpp +++ b/src/assets.cpp @@ -191,138 +191,6 @@ apAssetIndex(c8 *str) return 0; } -/* -static Asset apLoadTexture(TextureAsset asset_id) -{ - if (!ASSET_HEADER_LOADED) - { - apInit(); - } - - Assert(asset_id < i32(TEXTURE_ASSET_MAX), "LoadTextureAsset failure: asset_id is higher than TEXTURE_ASSET_MAX"); - - Asset asset = Texture_Asset_Lookup[asset_id]; - - if (asset.bytes == NULL) - { - AssetFile *asset_info = Texture_Assets + asset_id; - u8 *img = malloc(asset_info->len); - MemCpy(img, &ASSET_PACK[asset_info->data_offset], asset_info->len); - - asset.bytes = img; - asset.len = asset_info->len; - - Texture_Asset_Lookup[asset_id] = asset; - } - - return asset; -} - -static Asset apLoadShader(ShaderAsset asset_id) -{ - if (!ASSET_HEADER_LOADED) - { - apInit(); - } - - Assert(asset_id < SHADER_ASSET_MAX, "LoadShaderAsset failure: asset_id is higher than SHADER_ASSET_MAX"); - - Asset asset = Shader_Asset_Lookup[asset_id]; - if (asset.bytes == NULL) - { - AssetFile *asset_info = Shader_Assets + asset_id; - - asset.bytes = malloc(asset_info->len); - MemCpy(asset.bytes, &ASSET_PACK[asset_info->data_offset], asset_info->len); - asset.len = asset_info->len; - Shader_Asset_Lookup[asset_id] = asset; - } - - return asset; -} - -static Asset apLoadModel(ModelAsset asset_id) -{ - if (!ASSET_HEADER_LOADED) - { - apInit(); - } - - Assert(asset_id < MODEL_ASSET_MAX, "apLoadModel failure: asset_id is higher than MODEL_ASSET_MAX"); - - Asset asset = Model_Asset_Lookup[asset_id]; - if (asset.bytes == NULL) - { - AssetFile *asset_info = Model_Assets + asset_id; - - u8 *bytes = malloc(asset_info->len); - MemCpy(bytes, &ASSET_PACK[asset_info->data_offset], asset_info->len); - asset.model = apParseModel(bytes); - - free(bytes); - - Model_Asset_Lookup[asset_id] = asset; - } - - return asset; -} - -static TexMeta apGetTextureMeta(TextureAsset asset_id) -{ - AssetFile *asset_file = Texture_Assets + asset_id; - return asset_file->texture_meta; -} - -static ModelMeta apGetModelMeta(ModelAsset asset_id) -{ - //AssetFile *asset_file = Model_Assets + asset_id; - //return asset_file->model_meta; - - ModelMeta meta = {0}; - Asset asset = Model_Asset_Lookup[asset_id]; - if (asset.model != NULL) - { - meta.i_count = asset.model->index.count; - } - - return meta; -} - -static void apUnloadTexture(TextureAsset asset_id) -{ - Asset *asset = Texture_Asset_Lookup + asset_id; - if (asset->bytes != NULL) - { - free(asset->bytes); - asset->bytes = NULL; - asset->len = 0; - } -} - -static void apUnloadShader(ShaderAsset asset_id) -{ - Asset *asset = Shader_Asset_Lookup + asset_id; - if (asset->bytes != NULL) - { - free(asset->bytes); - asset->bytes = NULL; - asset->len = 0; - } -} - -static void apUnloadModel(ModelAsset asset_id) -{ - Asset *asset = Model_Asset_Lookup + asset_id; - if (asset->bytes != NULL) - { - free(asset->bytes); - asset->bytes = NULL; - asset->len = 0; - } -} - -*/ - // ::Assets::Loading::Functions::End:: @@ -415,11 +283,14 @@ apParseModel(u8 *data) for (u64 i = 0; i < m3d->numtexture; i += 1) { + Printfln("texture: %s", m3d->texture[i].name); + model->textures.data[i].bytes = m3d->texture[i].d; model->textures.data[i].w = m3d->texture[i].w; model->textures.data[i].h = m3d->texture[i].h; model->textures.data[i].ch = m3d->texture[i].f; + #ifdef BUILD_DEBUG Assert(i < model->textures.length, "Textures out of bounds access"); #endif @@ -427,6 +298,8 @@ apParseModel(u8 *data) for (u64 i = 0; i < m3d->nummaterial; i += 1) { + Printfln("material: %llu %s", i, m3d->material[i].name); + model->materials.data[i].tex.albedo = UINT32_MAX; model->materials.data[i].tex.ambient = UINT32_MAX; model->materials.data[i].tex.specular = UINT32_MAX; @@ -449,14 +322,17 @@ apParseModel(u8 *data) } break; case m3dp_map_Kd: { + Printfln("albedo: %llu", m3d->material[i].prop[j].value.textureid); model->materials.data[i].tex.albedo = m3d->material[i].prop[j].value.textureid; } break; case m3dp_map_Ka: { + Printfln("ambient: %llu", m3d->material[i].prop[j].value.textureid); model->materials.data[i].tex.ambient = m3d->material[i].prop[j].value.textureid; } break; case m3dp_map_Ks: { + Printfln("specular: %llu", m3d->material[i].prop[j].value.textureid); model->materials.data[i].tex.specular = m3d->material[i].prop[j].value.textureid; } break; default: diff --git a/src/renderer.cpp b/src/renderer.cpp index c82af8e..11bd5b9 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -110,6 +110,7 @@ InitModels(Renderer *renderer) mesh->type = PPT_NONE; if (a_mesh->mat_idx != UINT32_MAX) { + Printfln("mesh: %llu mat_idx: %llu", i, a_mesh->mat_idx); apMaterial *mat = a_model->materials.data + a_mesh->mat_idx; mesh->type |= mat->tex.albedo != UINT32_MAX ? PPT_ALBEDO_TEX : PPT_ALBEDO_VALUE; @@ -117,7 +118,9 @@ InitModels(Renderer *renderer) mesh->type |= mat->tex.specular != UINT32_MAX ? PPT_SPECULAR_TEX : PPT_SPECULAR_VALUE; mesh->values = mat->props; - mesh->textures = mat->tex; + mesh->textures.albedo = mat->tex.albedo != UINT32_MAX ? model->textures.data[mat->tex.albedo] : 0; + mesh->textures.ambient = mat->tex.ambient != UINT32_MAX ? model->textures.data[mat->tex.ambient] : 0; + mesh->textures.specular = mat->tex.specular != UINT32_MAX ? model->textures.data[mat->tex.specular] : 0; } } } @@ -400,8 +403,10 @@ RunCycle(Renderer *renderer) // ::Debug::Impl::Start:: -void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, GLchar const* message, void const* user_param) +void +DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, GLchar const* message, void const* user_param) { + return; if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) return; const char *source_str, *type_str, *severity_str;