diff --git a/src/CRE/rob/rob.cpp b/src/CRE/rob/rob.cpp index 3d033bcb..8afa13ea 100644 --- a/src/CRE/rob/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -14360,8 +14360,8 @@ static void sub_140526FD0(rob_chara_item_cos_data* item_cos_data, bool changed = false; if (item->data.col[j].flag & 0x01) { - tex = texture_create_copy_texture(texture_manager_get_copy_id(0x30), tex); - texture_apply_color_tone(tex, tex, &item->data.col[j].col_tone); + tex = texture_create_copy_texture_apply_color_tone( + texture_manager_get_copy_id(0x30), tex, &item->data.col[j].col_tone); changed = true; } diff --git a/src/CRE/texture.cpp b/src/CRE/texture.cpp index 9b12f493..910565f4 100644 --- a/src/CRE/texture.cpp +++ b/src/CRE/texture.cpp @@ -90,9 +90,10 @@ void texture_apply_color_tone(texture* chg_tex, if (!data) break; - int32_t width_align = org_tex->get_width_align_mip_level(i); - int32_t height_align = org_tex->get_height_align_mip_level(i); if (org_tex->flags & TEXTURE_BLOCK_COMPRESSION) { + int32_t width_align = org_tex->get_width_align_mip_level(i); + int32_t height_align = org_tex->get_height_align_mip_level(i); + texture_bind(org_tex->target, org_tex->glid); glGetCompressedTexImage(org_tex->target, i, data); if (org_tex->internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) @@ -107,6 +108,9 @@ void texture_apply_color_tone(texture* chg_tex, chg_tex->internal_format, size, data); } else if (org_tex->internal_format == GL_RGB5) { + int32_t width_align = org_tex->get_width_align_mip_level(i); + int32_t height_align = org_tex->get_height_align_mip_level(i); + texture_bind(org_tex->target, org_tex->glid); glGetTexImage(org_tex->target, i, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); rgb565_image_apply_color_tone(width_align, height_align, size, (rgb565*)data, col_tone); @@ -159,6 +163,59 @@ texture* texture_create_copy_texture(texture_id id, texture* org_tex) { return tex; } +texture* texture_create_copy_texture_apply_color_tone( + texture_id id, texture* org_tex, const color_tone* col_tone) { + if (!org_tex || !col_tone || org_tex->target != GL_TEXTURE_2D) + return 0; + + 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++) { + int32_t size = org_tex->get_size_mip_level(i); + void* data = force_malloc(org_tex->get_size_mip_level(i)); + if (!data) + break; + + if (org_tex->flags & TEXTURE_BLOCK_COMPRESSION) { + int32_t width_align = org_tex->get_width_align_mip_level(i); + int32_t height_align = org_tex->get_height_align_mip_level(i); + + glGetCompressedTexImage(org_tex->target, i, data); + if (org_tex->internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) + dxt1_image_apply_color_tone(width_align, height_align, size, (dxt1_block*)data, col_tone); + else + dxt5_image_apply_color_tone(width_align, height_align, size, (dxt5_block*)data, col_tone); + } + else if (org_tex->internal_format == GL_RGB5) { + int32_t width_align = org_tex->get_width_align_mip_level(i); + int32_t height_align = org_tex->get_height_align_mip_level(i); + + glGetTexImage(org_tex->target, i, format, type, data); + rgb565_image_apply_color_tone(width_align, height_align, size, (rgb565*)data, col_tone); + } + else + glGetTexImage(org_tex->target, i, format, type, data); + gl_state_get_error(); + vec_data.push_back(data); + } + texture_bind(org_tex->target, 0); + + texture* tex = texture_load_tex_2d(id, org_tex->internal_format, + org_tex->width, org_tex->height, org_tex->max_mipmap_level, vec_data.data(), true); + + for (void*& i : vec_data) + free_def(i); + + return tex; +} + 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) { return texture_load_tex(id, GL_TEXTURE_2D, internal_format, diff --git a/src/CRE/texture.hpp b/src/CRE/texture.hpp index 16ffdc60..7c607650 100644 --- a/src/CRE/texture.hpp +++ b/src/CRE/texture.hpp @@ -103,6 +103,8 @@ 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_create_copy_texture(texture_id id, texture* org_tex); +extern texture* texture_create_copy_texture_apply_color_tone( + texture_id id, texture* org_tex, const color_tone* col_tone); 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,