From 37cb5a1785c400d2df8d0381e48fcd554e0c7c9e Mon Sep 17 00:00:00 2001 From: korenkonder Date: Sat, 8 Jun 2024 20:34:16 +0300 Subject: [PATCH] `texture`: renamed some funcs --- src/CRE/rob/rob.cpp | 2 +- src/CRE/texture.cpp | 39 +++++++++++++++++++-------------------- src/CRE/texture.hpp | 2 +- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/CRE/rob/rob.cpp b/src/CRE/rob/rob.cpp index dbfd47a3..3d033bcb 100644 --- a/src/CRE/rob/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -14360,7 +14360,7 @@ static void sub_140526FD0(rob_chara_item_cos_data* item_cos_data, bool changed = false; if (item->data.col[j].flag & 0x01) { - tex = texture_copy(texture_manager_get_copy_id(0x30), tex); + tex = texture_create_copy_texture(texture_manager_get_copy_id(0x30), tex); texture_apply_color_tone(tex, tex, &item->data.col[j].col_tone); changed = true; } diff --git a/src/CRE/texture.cpp b/src/CRE/texture.cpp index 54c16d02..7e3d2eab 100644 --- a/src/CRE/texture.cpp +++ b/src/CRE/texture.cpp @@ -13,7 +13,7 @@ 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 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_load(GLenum target, GLenum internal_format, +static int32_t texture_load_pixels(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, GLenum internal_format, int32_t width, int32_t height, @@ -123,26 +123,28 @@ void texture_apply_color_tone(texture* chg_tex, texture_bind(org_tex->target, 0); } -texture* texture_copy(texture_id id, texture* org_tex) { +texture* texture_create_copy_texture(texture_id id, texture* org_tex) { if (org_tex->target != GL_TEXTURE_2D) return 0; - texture_bind(org_tex->target, org_tex->glid); + GLenum format = GL_ZERO; + GLenum type = GL_ZERO; + if (!(org_tex->flags & TEXTURE_BLOCK_COMPRESSION)) + texture_get_format_type_by_internal_format(org_tex->internal_format, &format, &type); + std::vector vec_data; + vec_data.reserve((size_t)org_tex->max_mipmap_level + 1); + + texture_bind(org_tex->target, org_tex->glid); for (int32_t i = 0; i <= org_tex->max_mipmap_level; i++) { void* data = force_malloc(org_tex->get_size_mip_level(i)); if (!data) break; - if (org_tex->flags & TEXTURE_BLOCK_COMPRESSION) { + if (org_tex->flags & TEXTURE_BLOCK_COMPRESSION) glGetCompressedTexImage(org_tex->target, i, data); - } - else { - GLenum format; - GLenum type; - texture_get_format_type_by_internal_format(org_tex->internal_format, &format, &type); + else glGetTexImage(org_tex->target, i, format, type, data); - } gl_state_get_error(); vec_data.push_back(data); } @@ -173,8 +175,8 @@ texture* texture_txp_load(txp* t, texture_id id) { if (!t || !t->mipmaps.size()) return 0; - int32_t count = t->array_size * t->mipmaps_count; - void** data_ptr = force_malloc(count); + std::vector data((size_t)t->array_size * t->mipmaps_count); + void** data_ptr = data.data(); 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(); @@ -184,13 +186,10 @@ texture* texture_txp_load(txp* t, texture_id id) { int32_t height = t->mipmaps[0].height; int32_t max_mipmap_level = t->mipmaps_count - 1; - texture* tex; if (t->has_cube_map) - tex = texture_load_tex_cube_map(id, internal_format, width, height, max_mipmap_level, data_ptr); + return texture_load_tex_cube_map(id, internal_format, width, height, max_mipmap_level, data_ptr); else - tex = texture_load_tex_2d(id, internal_format, width, height, max_mipmap_level, data_ptr, true); - free_def(data_ptr); - return tex; + return texture_load_tex_2d(id, internal_format, width, height, max_mipmap_level, data_ptr, true); } void texture_txp_store(texture* tex, txp* t) { @@ -632,7 +631,7 @@ static int32_t texture_get_size(GLenum internal_format, int32_t width, int32_t h } } -static int32_t texture_load(GLenum target, GLenum internal_format, +static int32_t texture_load_pixels(GLenum target, GLenum internal_format, int32_t width, int32_t height, int32_t level, void* data) { gl_state_get_all_gl_errors(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -733,7 +732,7 @@ static texture* texture_load_tex(texture_id id, GLenum target, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, }; - if (texture_load(target_cube_map_array[i], + if (texture_load_pixels(target_cube_map_array[i], working_internal_format, mip_width, mip_height, j, data) < 0) goto fail; size += texture_get_size(internal_format, mip_width, mip_height); @@ -748,7 +747,7 @@ static texture* texture_load_tex(texture_id id, GLenum target, else data = 0; - if (texture_load(target, + if (texture_load_pixels(target, working_internal_format, mip_width, mip_height, i, data) < 0) goto fail; size += texture_get_size(internal_format, mip_width, mip_height); diff --git a/src/CRE/texture.hpp b/src/CRE/texture.hpp index b35cb84b..f27b39bb 100644 --- a/src/CRE/texture.hpp +++ b/src/CRE/texture.hpp @@ -102,7 +102,7 @@ struct texture_param { extern texture* texture_alloc(texture_id id); extern void texture_apply_color_tone(texture* chg_tex, texture* org_tex, const color_tone* col_tone); -extern texture* texture_copy(texture_id id, texture* org_tex); +extern texture* texture_create_copy_texture(texture_id id, texture* org_tex); extern texture* texture_load_tex_2d(texture_id id, GLenum internal_format, int32_t width, int32_t height, int32_t max_mipmap_level, void** data_ptr, bool use_high_anisotropy); extern texture* texture_load_tex_cube_map(texture_id id, GLenum internal_format, int32_t width, int32_t height,