diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 42f0a1af..c21e4307 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -1192,13 +1192,13 @@ void object_material_msgpack_read(const char* path, const char* set_name, tex->mipmaps.reserve((tex->has_cube_map ? 6LL : 1LL) * tex->mipmaps_count); int32_t index = 0; do - for (uint32_t i = 0; i < tex->mipmaps_count; i++) { + for (int32_t i = 0; i < tex->mipmaps_count; i++) { txp_mipmap tex_mip; - tex_mip.width = max_def(d.width >> i, 1u); - tex_mip.height = max_def(d.height >> i, 1u); + tex_mip.width = max_def(d.width >> i, 1); + tex_mip.height = max_def(d.height >> i, 1); tex_mip.format = d.format; - uint32_t size = tex_mip.get_size(); + int32_t size = tex_mip.get_size(); tex_mip.size = size; tex_mip.data.resize(size); memcpy(tex_mip.data.data(), d.data[index], size); @@ -1263,13 +1263,13 @@ void object_material_msgpack_read(const char* path, const char* set_name, tex->mipmaps.reserve((tex->has_cube_map ? 6LL : 1LL) * tex->mipmaps_count); int32_t index = 0; do - for (uint32_t i = 0; i < tex->mipmaps_count; i++) { + for (int32_t i = 0; i < tex->mipmaps_count; i++) { txp_mipmap tex_mip; - tex_mip.width = max_def(d.width >> i, 1u); - tex_mip.height = max_def(d.height >> i, 1u); + tex_mip.width = max_def(d.width >> i, 1); + tex_mip.height = max_def(d.height >> i, 1); tex_mip.format = d.format; - uint32_t size = tex_mip.get_size(); + int32_t size = tex_mip.get_size(); tex_mip.size = size; tex_mip.data.resize(size); memcpy(tex_mip.data.data(), d.data[index], size); @@ -1577,8 +1577,8 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 txp& tex = txp_set->textures[i]; txp_format format = tex.mipmaps[0].format; - uint32_t width = tex.mipmaps[0].width; - uint32_t height = tex.mipmaps[0].height; + int32_t width = tex.mipmaps[0].width; + int32_t height = tex.mipmaps[0].height; dds d; d.format = format; @@ -1587,10 +1587,11 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 d.mipmaps_count = tex.mipmaps_count; d.has_cube_map = tex.has_cube_map; d.data.reserve((tex.has_cube_map ? 6LL : 1LL) * tex.mipmaps_count); - uint32_t index = 0; + int32_t index = 0; do - for (uint32_t j = 0; j < tex.mipmaps_count; j++) { - uint32_t size = txp::get_size(format, max_def(width >> j, 1u), max_def(height >> j, 1u)); + for (int32_t j = 0; j < tex.mipmaps_count; j++) { + int32_t size = txp::get_size(format, + max_def(width >> j, 1), max_def(height >> j, 1)); void* data = force_malloc(size); memcpy(data, tex.mipmaps[index].data.data(), size); d.data.push_back(data); diff --git a/src/CRE/texture.cpp b/src/CRE/texture.cpp index 70e0c8e7..ef2e627f 100644 --- a/src/CRE/texture.cpp +++ b/src/CRE/texture.cpp @@ -11,11 +11,8 @@ static void texture_bind(GLenum target, GLuint texture); static void texture_get_format_type_by_internal_format(GLenum internal_format, GLenum* format, GLenum* type); -static uint32_t texture_get_height_mip_level(texture* tex, int32_t mip_level); static GLuint texture_get_working_internal_format(GLuint internal_format); static int32_t texture_get_size(GLenum internal_format, int32_t width, int32_t height); -static int32_t texture_get_size_mip_level(texture* tex, int32_t mip_level); -static uint32_t texture_get_width_mip_level(texture* tex, int32_t mip_level); static int32_t texture_load(GLenum target, GLenum internal_format, int32_t width, int32_t height, int32_t level, void* data); static texture* texture_load_tex(texture_id id, GLenum target, @@ -30,14 +27,19 @@ glid(), target(), internal_format(), max_mipmap_level(), size_texmem() { } -uint32_t texture::get_height_align_mip_level(uint8_t mip_level) { +int32_t texture::get_height_align_mip_level(uint8_t mip_level) { if (flags & TEXTURE_BLOCK_COMPRESSION) return max_def((uint32_t)height >> mip_level, 4u); else return max_def((uint32_t)height >> mip_level, 1u); } -uint32_t texture::get_width_align_mip_level(uint8_t mip_level) { +int32_t texture::get_size_mip_level(uint8_t mip_level) { + return texture_get_size(internal_format, + get_width_mip_level(mip_level), get_height_mip_level(mip_level)); +} + +int32_t texture::get_width_align_mip_level(uint8_t mip_level) { if (flags & TEXTURE_BLOCK_COMPRESSION) return max_def((uint32_t)width >> mip_level, 4u); else @@ -83,7 +85,7 @@ void texture_apply_color_tone(texture* chg_tex, return; for (int32_t i = 0; i <= org_tex->max_mipmap_level; i++) { - int32_t size = texture_get_size_mip_level(org_tex, i); + int32_t size = org_tex->get_size_mip_level(i); void* data = force_malloc(size); if (!data) break; @@ -99,8 +101,8 @@ void texture_apply_color_tone(texture* chg_tex, dxt5_image_apply_color_tone(width_align, height_align, size, (dxt5_block*)data, col_tone); texture_bind(chg_tex->target, chg_tex->glid); - uint32_t width = texture_get_width_mip_level(org_tex, i); - uint32_t height = texture_get_height_mip_level(org_tex, i); + uint32_t width = org_tex->get_width_mip_level(i); + uint32_t height = org_tex->get_height_mip_level(i); glCompressedTexSubImage2D(chg_tex->target, i, 0, 0, width, height, chg_tex->internal_format, size, data); } @@ -110,8 +112,8 @@ void texture_apply_color_tone(texture* chg_tex, rgb565_image_apply_color_tone(width_align, height_align, size, (rgb565*)data, col_tone); texture_bind(chg_tex->target, chg_tex->glid); - uint32_t width = texture_get_width_mip_level(org_tex, i); - uint32_t height = texture_get_height_mip_level(org_tex, i); + uint32_t width = org_tex->get_width_mip_level(i); + uint32_t height = org_tex->get_height_mip_level(i); glTexSubImage2D(chg_tex->target, i, 0, 0, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); } @@ -128,7 +130,7 @@ texture* texture_copy(texture_id id, texture* org_tex) { texture_bind(org_tex->target, org_tex->glid); std::vector vec_data; for (int32_t i = 0; i <= org_tex->max_mipmap_level; i++) { - void* data = force_malloc(texture_get_size_mip_level(org_tex, i)); + void* data = force_malloc(org_tex->get_size_mip_level(i)); if (!data) break; @@ -173,8 +175,8 @@ texture* texture_txp_load(txp* t, texture_id id) { int32_t count = t->array_size * t->mipmaps_count; void** data_ptr = force_malloc(count); - for (uint32_t i = 0, k = 0; i < t->array_size; i++) - for (uint32_t j = 0; j < t->mipmaps_count; j++, k++) + for (int32_t i = 0, k = 0; i < t->array_size; i++) + for (int32_t j = 0; j < t->mipmaps_count; j++, k++) data_ptr[k] = t->mipmaps[k].data.data(); GLenum internal_format = texture_txp_get_gl_internal_format(t); @@ -249,10 +251,10 @@ void texture_txp_store(texture* tex, txp* t) { } auto get_tex_mipmap_data = [&](txp_mipmap& mipmap, GLenum target, int32_t mip_level) { - mipmap.width = texture_get_width_mip_level(tex, mip_level); - mipmap.height = texture_get_height_mip_level(tex, mip_level); + mipmap.width = tex->get_width_mip_level(mip_level); + mipmap.height = tex->get_height_mip_level(mip_level); mipmap.format = format; - mipmap.size = texture_get_size_mip_level(tex, mip_level); + mipmap.size = tex->get_size_mip_level(mip_level); mipmap.data.resize(mipmap.size); if (tex->flags & TEXTURE_BLOCK_COMPRESSION) @@ -570,10 +572,6 @@ static void texture_get_format_type_by_internal_format(GLenum internal_format, G *type = _type; } -inline static uint32_t texture_get_height_mip_level(texture* tex, int32_t mip_level) { - return max_def((uint32_t)tex->height >> mip_level, 1u); -} - inline static GLuint texture_get_working_internal_format(GLuint internal_format) { switch (internal_format) { case GL_ALPHA8: @@ -634,16 +632,6 @@ static int32_t texture_get_size(GLenum internal_format, int32_t width, int32_t h } } -inline static int32_t texture_get_size_mip_level(texture* tex, int32_t mip_level) { - return texture_get_size(tex->internal_format, - texture_get_width_mip_level(tex, mip_level), - texture_get_height_mip_level(tex, mip_level)); -} - -inline static uint32_t texture_get_width_mip_level(texture* tex, int32_t mip_level) { - return max_def((uint32_t)tex->width >> mip_level, 1u); -} - static int32_t texture_load(GLenum target, GLenum internal_format, int32_t width, int32_t height, int32_t level, void* data) { gl_state_get_all_gl_errors(); diff --git a/src/CRE/texture.hpp b/src/CRE/texture.hpp index 9fcc14d7..e89073b6 100644 --- a/src/CRE/texture.hpp +++ b/src/CRE/texture.hpp @@ -69,18 +69,26 @@ struct texture { texture(); - uint32_t get_height_align_mip_level(uint8_t mip_level = 0); - uint32_t get_width_align_mip_level(uint8_t mip_level = 0); + int32_t get_height_align_mip_level(uint8_t mip_level = 0); + int32_t get_size_mip_level(uint8_t mip_level = 0); + int32_t get_width_align_mip_level(uint8_t mip_level = 0); + + inline int32_t get_height_mip_level(uint8_t mip_level) { + return max_def(height >> mip_level, 1); + } + inline int32_t get_width_mip_level(uint8_t mip_level) { + return max_def(width >> mip_level, 1); + } }; struct texture_manager { std::map textures; int16_t entry_count; int16_t alloc_count; - int32_t texmem_now_size; - int32_t texmem_peak_size; - int32_t texmem_now_size_by_type[4]; - int32_t texmem_peak_size_by_type[4]; + uint32_t texmem_now_size; + uint32_t texmem_peak_size; + uint32_t texmem_now_size_by_type[4]; + uint32_t texmem_peak_size_by_type[4]; int32_t copy_count; texture_manager(); diff --git a/src/KKdLib/dds.cpp b/src/KKdLib/dds.cpp index 6cf84d37..5d5ad0a3 100644 --- a/src/KKdLib/dds.cpp +++ b/src/KKdLib/dds.cpp @@ -264,8 +264,8 @@ void dds::read(const wchar_t* path) { data.reserve(has_cube_map ? mipmaps_count * 6ULL : mipmaps_count); do - for (uint32_t i = 0; i < mipmaps_count; i++) { - uint32_t size = get_size(i); + for (int32_t i = 0; i < mipmaps_count; i++) { + int32_t size = get_size(i); void* data = force_malloc(size); s.read(data, size); if (reverse) @@ -300,7 +300,7 @@ void dds::write(const wchar_t* path) { dds_h.flags |= DDSD_MIPMAPCOUNT; dds_h.height = height; dds_h.width = width; - dds_h.pitchOrLinearSize = txp::get_size(format, width, height); + dds_h.pitchOrLinearSize = (uint32_t)txp::get_size(format, width, height); dds_h.mipMapCount = mipmaps_count; dds_h.caps |= DDS_SURFACE_FLAGS_TEXTURE; if (has_cube_map) @@ -364,10 +364,10 @@ void dds::write(const wchar_t* path) { s.write_uint32_t_reverse_endianness(DDS_MAGIC, true); s.write_data(dds_h); - uint32_t index = 0; + int32_t index = 0; do - for (uint32_t i = 0; i < mipmaps_count; i++) { - uint32_t size = get_size(i); + for (int32_t i = 0; i < mipmaps_count; i++) { + int32_t size = get_size(i); void* data = force_malloc(size); memcpy(data, this->data[index], size); dds_reverse_rgb(format, size, (uint8_t*)data); @@ -380,10 +380,10 @@ void dds::write(const wchar_t* path) { free_def(path_dds); } -uint32_t dds::get_size(uint32_t mip_level) { +int32_t dds::get_size(int32_t mip_level) { return txp::get_size(format, - max_def(width >> mip_level, 1u), - max_def(height >> mip_level, 1u)); + max_def(width >> mip_level, 1), + max_def(height >> mip_level, 1)); } static void dds_reverse_rgb(txp_format format, size_t size, uint8_t* data) { diff --git a/src/KKdLib/dds.hpp b/src/KKdLib/dds.hpp index a2c8c009..b0e5f6f1 100644 --- a/src/KKdLib/dds.hpp +++ b/src/KKdLib/dds.hpp @@ -10,9 +10,9 @@ struct dds { txp_format format; - uint32_t width; - uint32_t height; - uint32_t mipmaps_count; + int32_t width; + int32_t height; + int32_t mipmaps_count; bool has_cube_map; std::vector data; @@ -24,5 +24,5 @@ struct dds { void write(const char* path); void write(const wchar_t* path); - uint32_t get_size(uint32_t mip_level = 0); + int32_t get_size(int32_t mip_level = 0); }; diff --git a/src/KKdLib/txp.cpp b/src/KKdLib/txp.cpp index 945f6583..62154ce3 100644 --- a/src/KKdLib/txp.cpp +++ b/src/KKdLib/txp.cpp @@ -15,7 +15,7 @@ txp_mipmap::~txp_mipmap() { } -uint32_t txp_mipmap::get_size() { +int32_t txp_mipmap::get_size() { return txp::get_size(format, width, height); } @@ -27,8 +27,8 @@ txp::~txp() { } -uint32_t txp::get_size(txp_format format, uint32_t width, uint32_t height) { - uint32_t size = width * height; +int32_t txp::get_size(txp_format format, int32_t width, int32_t height) { + int32_t size = width * height; switch (format) { case TXP_A8: return size; @@ -302,7 +302,7 @@ bool txp_set::produce_enrs(enrs* enrs) { enrs->vec.push_back(ee); l += o = 12; - ee = { o, 1, tex->array_size * 4, tex->mipmaps_count }; + ee = { o, 1, (uint32_t)((size_t)tex->array_size * 4), (uint32_t)tex->mipmaps_count }; ee.append(0, tex->array_size, ENRS_DWORD); enrs->vec.push_back(ee); l += (size_t)(o = (uint32_t)((size_t)tex->array_size * tex->mipmaps_count * 4)); @@ -408,7 +408,7 @@ bool txp_set::unpack_file(const void* data, bool big_endian) { tex_mipmap->size = *(uint32_t*)(mipmap_d + 20); } - ssize_t size = tex_mipmap->get_size(); + int32_t size = tex_mipmap->get_size(); tex_mipmap->data.resize(max_def(size, tex_mipmap->size)); memcpy(tex_mipmap->data.data(), (void*)(mipmap_d + 24), tex_mipmap->size); size -= tex_mipmap->size; diff --git a/src/KKdLib/txp.hpp b/src/KKdLib/txp.hpp index a6532c71..38c7ef3a 100644 --- a/src/KKdLib/txp.hpp +++ b/src/KKdLib/txp.hpp @@ -27,28 +27,28 @@ enum txp_format { }; struct txp_mipmap { - uint32_t width; - uint32_t height; + int32_t width; + int32_t height; txp_format format; - uint32_t size; + int32_t size; std::vector data; txp_mipmap(); ~txp_mipmap(); - uint32_t get_size(); + int32_t get_size(); }; struct txp { bool has_cube_map; - uint32_t array_size; - uint32_t mipmaps_count; + int32_t array_size; + int32_t mipmaps_count; std::vector mipmaps; txp(); ~txp(); - static uint32_t get_size(txp_format format, uint32_t width, uint32_t height); + static int32_t get_size(txp_format format, int32_t width, int32_t height); }; struct txp_set { diff --git a/src/ReDIVA/glitter_editor.cpp b/src/ReDIVA/glitter_editor.cpp index ae5b7011..86797cfe 100644 --- a/src/ReDIVA/glitter_editor.cpp +++ b/src/ReDIVA/glitter_editor.cpp @@ -1870,7 +1870,7 @@ static bool glitter_editor_resource_import(GlitterEditor* glt_edt) { uint64_t hash_f2 = hash_utf16_murmurhash(f); txp* tex; - uint32_t index; + int32_t index; Glitter::EffectGroup* eg = glt_edt->effect_group; int32_t rc = eg->resources_count; @@ -1893,13 +1893,13 @@ static bool glitter_editor_resource_import(GlitterEditor* glt_edt) { tex->mipmaps.reserve((tex->has_cube_map ? 6LL : 1LL) * tex->mipmaps_count); index = 0; do - for (uint32_t i = 0; i < tex->mipmaps_count; i++) { + for (int32_t i = 0; i < tex->mipmaps_count; i++) { txp_mipmap tex_mip; - tex_mip.width = max_def(d.width >> i, 1u); - tex_mip.height = max_def(d.height >> i, 1u); + tex_mip.width = max_def(d.width >> i, 1); + tex_mip.height = max_def(d.height >> i, 1); tex_mip.format = d.format; - uint32_t size = tex_mip.get_size(); + int32_t size = tex_mip.get_size(); tex_mip.size = size; tex_mip.data.resize(size); memcpy(tex_mip.data.data(), d.data[index], size); @@ -1949,8 +1949,8 @@ static bool glitter_editor_resource_export(GlitterEditor* glt_edt) { txp& tex = eg->resources_tex.textures[sel_rsrc]; txp_format format = tex.mipmaps[0].format; - uint32_t width = tex.mipmaps[0].width; - uint32_t height = tex.mipmaps[0].height; + int32_t width = tex.mipmaps[0].width; + int32_t height = tex.mipmaps[0].height; dds d; d.format = format; @@ -1959,10 +1959,10 @@ static bool glitter_editor_resource_export(GlitterEditor* glt_edt) { d.mipmaps_count = tex.mipmaps_count; d.has_cube_map = tex.has_cube_map; d.data.reserve((tex.has_cube_map ? 6LL : 1LL) * tex.mipmaps_count); - uint32_t index = 0; + int32_t index = 0; do - for (uint32_t i = 0; i < tex.mipmaps_count; i++) { - uint32_t size = d.get_size(i); + for (int32_t i = 0; i < tex.mipmaps_count; i++) { + int32_t size = d.get_size(i); void* data = force_malloc(size); memcpy(data, tex.mipmaps[index].data.data(), size); d.data.push_back(data);