diff --git a/src/CRE/Glitter/file_reader.cpp b/src/CRE/Glitter/file_reader.cpp index af4b2999..f3b301d0 100644 --- a/src/CRE/Glitter/file_reader.cpp +++ b/src/CRE/Glitter/file_reader.cpp @@ -866,9 +866,9 @@ namespace Glitter { for (size_t l = 0; l < eff_group->resources_count; l++) { if (k->data.tex_hash == eff_group->resource_hashes[l]) - k->data.texture = eff_group->resources[l]->tex; + k->data.texture = eff_group->resources[l]->glid; if (k->data.mask_tex_hash == eff_group->resource_hashes[l]) - k->data.mask_texture = eff_group->resources[l]->tex; + k->data.mask_texture = eff_group->resources[l]->glid; } } } diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index 6fa90a7c..f5b66dca 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -6397,7 +6397,7 @@ static void auth_3d_object_disp(auth_3d_object* o, auth_3d* auth, render_context for (auth_3d_object_texture_transform& i : o->texture_transform) { if (tex_trans_count >= TEXTURE_TRANSFORM_COUNT || i.texture_id == -1 - || !texture_storage_get_texture(i.texture_id)) + || !texture_manager_get_texture(i.texture_id)) continue; tex_trans[tex_trans_count].id = i.texture_id; diff --git a/src/CRE/clear_color.cpp b/src/CRE/clear_color.cpp index d487ab0f..d00b2052 100644 --- a/src/CRE/clear_color.cpp +++ b/src/CRE/clear_color.cpp @@ -15,4 +15,3 @@ void clear_color_set_gl() { color = clear_color; glClearColor(color.x, color.y, color.z, color.w); } - diff --git a/src/CRE/effect.cpp b/src/CRE/effect.cpp index 1c80dedd..450d47e2 100644 --- a/src/CRE/effect.cpp +++ b/src/CRE/effect.cpp @@ -1261,7 +1261,7 @@ void leaf_particle_draw() { || !leaf_particle_enable || !stage_param_data_leaf_set) return; - texture* tex = texture_storage_get_texture(leaf_particle_tex_id); + texture* tex = texture_manager_get_texture(leaf_particle_tex_id); if (!tex) return; @@ -1286,7 +1286,7 @@ void leaf_particle_draw() { shader_data.g_lit_luce = rctx_ptr->obj_scene.g_light_chara_luce; leaf_particle_scene_ubo.WriteMemory(shader_data); - gl_state_active_bind_texture_2d(0, tex->tex); + gl_state_active_bind_texture_2d(0, tex->glid); shaders_ft.set(SHADER_FT_LEAF_PT); leaf_particle_scene_ubo.Bind(0); gl_state_bind_vertex_array(leaf_ptcl_vao); @@ -1298,7 +1298,7 @@ void rain_particle_draw() { if (!stage_param_data_rain_current || !rain_particle_enable || !stage_param_data_rain_set) return; - texture* tex = texture_storage_get_texture(rain_particle_tex_id); + texture* tex = texture_manager_get_texture(rain_particle_tex_id); if (!tex) return; @@ -1329,7 +1329,7 @@ void rain_particle_draw() { gl_state_set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_state_enable_depth_test(); gl_state_set_depth_mask(GL_FALSE); - gl_state_active_bind_texture_2d(0, tex->tex); + gl_state_active_bind_texture_2d(0, tex->glid); shaders_ft.set(SHADER_FT_RAIN); float_t tangent_sign = -rain->psize.x; @@ -1403,7 +1403,7 @@ void snow_particle_draw() { if (!stage_param_data_snow_current || !snow_particle_enable || !stage_param_data_snow_set) return; - texture* tex = texture_storage_get_texture(snow_particle_tex_id); + texture* tex = texture_manager_get_texture(snow_particle_tex_id); if (!tex) return; @@ -1446,7 +1446,7 @@ void snow_particle_draw() { snow_batch.start_vertex_location.x = 0; snow_particle_batch_ubo.WriteMemory(snow_batch); - gl_state_active_bind_texture_2d(0, tex->tex); + gl_state_active_bind_texture_2d(0, tex->glid); gl_state_active_bind_texture_2d(1, rctx_ptr->render.rend_texture[0].GetDepthTex()); gl_state_bind_vertex_array(rctx_ptr->common_vao); @@ -3296,14 +3296,14 @@ void EffectRipple::sub_1403584A0(RenderTexture* rt) { if (ripple_tex_id == -1) return; - texture* ripple_tex = texture_storage_get_texture(ripple_tex_id); + texture* ripple_tex = texture_manager_get_texture(ripple_tex_id); if (!ripple_tex) return; - field_BB8.SetColorDepthTextures(ripple_tex->tex); + field_BB8.SetColorDepthTextures(ripple_tex->glid); field_BB8.Bind(); - image_filter_scale(ripple_tex->tex, rt->GetColorTex(), 1.0f); + image_filter_scale(ripple_tex->glid, rt->GetColorTex(), 1.0f); gl_state_bind_framebuffer(0); } @@ -4090,9 +4090,9 @@ void water_particle::draw(mat4* mat) { gl_state_bind_vertex_array(rctx_ptr->common_vao); water_particle_scene_ubo.Bind(4); ssbo.Bind(0); - texture* tex = texture_storage_get_texture(splash_tex_id); + texture* tex = texture_manager_get_texture(splash_tex_id); if (tex) - gl_state_active_bind_texture_2d(0, tex->tex); + gl_state_active_bind_texture_2d(0, tex->glid); shaders_ft.draw_arrays(GL_TRIANGLES, 0, count * 6); gl_state_bind_vertex_array(0); @@ -5044,7 +5044,7 @@ void star_catalog_milky_way::draw(const mat4& vp, const mat4& mat, texture* tex, gl_state_enable_cull_face(); gl_state_disable_blend(); gl_state_set_depth_mask(GL_FALSE); - gl_state_active_bind_texture_2d(0, tex->tex); + gl_state_active_bind_texture_2d(0, tex->glid); gl_state_bind_sampler(0, sampler); gl_state_enable_primitive_restart(); gl_state_set_primitive_restart_index(restart_index); @@ -5095,8 +5095,8 @@ void star_catalog::draw() { if (!stage_param_data_ptr || !enable) return; - texture* star_tex = texture_storage_get_texture(this->star_tex); - texture* star_b_tex = texture_storage_get_texture(this->star_b_tex); + texture* star_tex = texture_manager_get_texture(this->star_tex); + texture* star_b_tex = texture_manager_get_texture(this->star_b_tex); if (!star_tex || !star_b_tex) return; @@ -5121,7 +5121,7 @@ void star_catalog::draw() { mat4 vp; mat4_mul(&rctx_ptr->view_mat, &proj, &vp); - texture* milky_way_tex = texture_storage_get_texture(milky_way_tex_id); + texture* milky_way_tex = texture_manager_get_texture(milky_way_tex_id); if (milky_way_tex) milky_way.draw(vp, model, milky_way_tex, scene_ubo); @@ -5160,11 +5160,11 @@ void star_catalog::draw() { batch_ubo.Bind(1); stars_ssbo.Bind(0); if (i) { - gl_state_active_bind_texture_2d(0, star_b_tex->tex); + gl_state_active_bind_texture_2d(0, star_b_tex->glid); shaders_ft.draw_arrays(GL_TRIANGLES, 0, star_b_count * 6); } else { - gl_state_active_bind_texture_2d(0, star_tex->tex); + gl_state_active_bind_texture_2d(0, star_tex->glid); shaders_ft.draw_arrays(GL_TRIANGLES, 0, star_count * 6); } } @@ -5587,9 +5587,9 @@ static void draw_fog_particle(EffectFogRing* data, mat4* mat) { shaders_ft.set(SHADER_FT_FOGPTCL); gl_state_enable_blend(); - texture* tex = texture_storage_get_texture(data->tex_id); + texture* tex = texture_manager_get_texture(data->tex_id); if (tex) - gl_state_active_bind_texture_2d(0, tex->tex); + gl_state_active_bind_texture_2d(0, tex->glid); gl_state_bind_vertex_array(rctx_ptr->common_vao); data->ssbo.Bind(0); shaders_ft.draw_arrays(GL_TRIANGLES, 0, data->num_vtx); diff --git a/src/CRE/mdl/draw_object.cpp b/src/CRE/mdl/draw_object.cpp index bcb09775..f4d5766a 100644 --- a/src/CRE/mdl/draw_object.cpp +++ b/src/CRE/mdl/draw_object.cpp @@ -459,9 +459,9 @@ namespace mdl { if (texture_id != -1) { for (int32_t j = 0; j < args->texture_pattern_count; j++) if (args->texture_pattern_array[j].src == ::texture_id(0, texture_id)) { - texture* tex = texture_storage_get_texture(args->texture_pattern_array[j].dst); + texture* tex = texture_manager_get_texture(args->texture_pattern_array[j].dst); if (tex) - tex_id = tex->tex; + tex_id = tex->glid; break; } @@ -469,7 +469,7 @@ namespace mdl { tex_id = (*textures)[texdata->texture_index]; if (tex_id == -1) - tex_id = 0; + tex_id = rctx->empty_texture_2d;; gl_state_active_bind_texture_2d(tex_index, tex_id); @@ -489,7 +489,7 @@ namespace mdl { else wrap_t = 0; - texture* tex = texture_storage_get_texture(::texture_id(0, texture_id)); + texture* tex = texture_manager_get_texture(::texture_id(0, texture_id)); gl_state_bind_sampler(tex_index, rctx->samplers[(wrap_t * 3 + wrap_s) * 2 + (!tex || tex->max_mipmap_level > 0 ? 1 : 0)]); } @@ -684,9 +684,9 @@ static void draw_object_material_set_default(render_context* rctx, const mdl::Ob uint32_t texture_id = texdata->tex_index; for (int32_t j = 0; j < args->texture_pattern_count; j++) if (args->texture_pattern_array[j].src == ::texture_id(0, texture_id)) { - texture* tex = texture_storage_get_texture(args->texture_pattern_array[j].dst); + texture* tex = texture_manager_get_texture(args->texture_pattern_array[j].dst); if (tex) - tex_id = tex->tex; + tex_id = tex->glid; break; } @@ -745,7 +745,7 @@ static void draw_object_material_set_default(render_context* rctx, const mdl::Ob else wrap_t = 0; - texture* tex = texture_storage_get_texture(::texture_id(0, texture_id)); + texture* tex = texture_manager_get_texture(::texture_id(0, texture_id)); gl_state_bind_sampler(tex_index, rctx->samplers[(wrap_t * 3 + wrap_s) * 2 + (!tex || tex->max_mipmap_level > 0 ? 1 : 0)]); } @@ -755,7 +755,7 @@ static void draw_object_material_set_default(render_context* rctx, const mdl::Ob if (tex_index == 1) uni_type = U_TEX_1_TYPE; - texture* tex = texture_storage_get_texture(texdata->tex_index); + texture* tex = texture_manager_get_texture(texdata->tex_index); if (!tex) uniform_value[uni_type] = 1; else if (tex->internal_format == GL_COMPRESSED_RED_RGTC1_EXT) @@ -917,9 +917,9 @@ static void draw_object_material_set_reflect(render_context* rctx, const mdl::Ob GLuint tex_id = -1; for (int32_t j = 0; j < args->texture_pattern_count; j++) if (args->texture_pattern_array[j].src == ::texture_id(0, texture_id)) { - texture* tex = texture_storage_get_texture(args->texture_pattern_array[j].dst); + texture* tex = texture_manager_get_texture(args->texture_pattern_array[j].dst); if (tex) - tex_id = tex->tex; + tex_id = tex->glid; break; } @@ -927,7 +927,7 @@ static void draw_object_material_set_reflect(render_context* rctx, const mdl::Ob tex_id = (*textures)[texdata->texture_index]; if (tex_id == -1) - tex_id = 0; + tex_id = rctx->empty_texture_2d;; gl_state_active_bind_texture_2d(i, tex_id); @@ -947,7 +947,7 @@ static void draw_object_material_set_reflect(render_context* rctx, const mdl::Ob else wrap_t = 0; - texture* tex = texture_storage_get_texture(::texture_id(0, texture_id)); + texture* tex = texture_manager_get_texture(::texture_id(0, texture_id)); gl_state_bind_sampler(i, rctx->samplers[(wrap_t * 3 + wrap_s) * 2 + (!tex || tex->max_mipmap_level > 0 ? 1 : 0)]); } diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 9ad57522..5e61e6d9 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -2409,7 +2409,7 @@ static bool ObjsetInfo_load_textures(ObjsetInfo* info, const void* data, bool bi texture** tex_data = info->tex_data; for (uint32_t i = 0; i < tex_num; i++) { info->tex_id_data.push_back(tex_id_data[i], i); - info->gentex.push_back(tex_data[i]->tex); + info->gentex.push_back(tex_data[i]->glid); } info->tex_id_data.sort(); return false; @@ -2438,7 +2438,7 @@ static bool ObjsetInfo_load_textures_modern(ObjsetInfo* info, texture** tex_data = info->tex_data; for (uint32_t i = 0; i < tex_num; i++) { info->tex_id_data.push_back(tex_id_data[i], i); - info->gentex.push_back(tex_data[i]->tex); + info->gentex.push_back(tex_data[i]->glid); } info->tex_id_data.sort(); return false; diff --git a/src/CRE/render.cpp b/src/CRE/render.cpp index d4675e5f..3945e695 100644 --- a/src/CRE/render.cpp +++ b/src/CRE/render.cpp @@ -118,7 +118,7 @@ namespace rndr { Render::~Render() { if (aet_back_tex) - texture_free(aet_back_tex); + texture_release(aet_back_tex); if (dof) { delete dof; @@ -165,7 +165,7 @@ namespace rndr { uniform_value[U_REDUCE] = 0; glViewport(0, 0, t->width, t->height); - gl_state_active_bind_texture_2d(0, taa_tex[2]->tex); + gl_state_active_bind_texture_2d(0, taa_tex[2]->glid); gl_state_bind_sampler(0, rctx->render_samplers[0]); shaders_ft.set(SHADER_FT_REDUCE); draw_quad(render_post_width[0], render_post_height[0], @@ -174,14 +174,14 @@ namespace rndr { } copy_to_frame_texture(rend_texture[0].GetColorTex(), - render_width[0], render_height[0], taa_tex[2]->tex); + render_width[0], render_height[0], taa_tex[2]->glid); frame_texture_reset_capture(); rctx->screen_buffer.Bind(); glViewport(0, 0, rctx->sprite_width, rctx->sprite_height); if (ssaa) { - gl_state_active_bind_texture_2d(0, taa_tex[2]->tex); + gl_state_active_bind_texture_2d(0, taa_tex[2]->glid); gl_state_bind_sampler(0, rctx->render_samplers[0]); uniform_value[U_ALPHA_MASK] = ss_alpha_mask ? 1 : 0; uniform_value[U_REDUCE] = 0; @@ -192,7 +192,7 @@ namespace rndr { uniform_value[U_ALPHA_MASK] = 0; } else { - gl_state_active_bind_texture_2d(0, taa_tex[2]->tex); + gl_state_active_bind_texture_2d(0, taa_tex[2]->glid); if (mag_filter == MAG_FILTER_NEAREST) gl_state_bind_sampler(0, rctx->render_samplers[1]); else @@ -596,7 +596,7 @@ namespace rndr { for (Render::FrameTextureData& i : frame_texture[slot].data) if (!i.texture) { - i.render_texture.SetColorDepthTextures(tex->tex); + i.render_texture.SetColorDepthTextures(tex->glid); i.texture = tex; i.type = type; return (int32_t)(&i - frame_texture[slot].data); @@ -645,7 +645,7 @@ namespace rndr { for (int32_t i = 0; i < 1; i++) if (transparency_tex[i]) { - texture_free(transparency_tex[i]); + texture_release(transparency_tex[i]); transparency_tex[i] = 0; texture_counter--; } @@ -665,7 +665,7 @@ namespace rndr { taa_buffer[i].Free(); if (taa_tex[i]) { - texture_free(taa_tex[i]); + texture_release(taa_tex[i]); taa_tex[i] = 0; texture_counter--; } @@ -674,7 +674,7 @@ namespace rndr { aet_back_texture.Free(); if (aet_back_tex) { - texture_free(aet_back_tex); + texture_release(aet_back_tex); aet_back_tex = 0; texture_counter--; } @@ -692,13 +692,13 @@ namespace rndr { for (int32_t i = 0; i < 5; i++) if (reduce_tex[i]) { - texture_free(reduce_tex[i]); + texture_release(reduce_tex[i]); reduce_tex[i] = 0; texture_counter--; } if (exposure_history) { - texture_free(exposure_history); + texture_release(exposure_history); exposure_history = 0; texture_counter--; } @@ -887,12 +887,12 @@ namespace rndr { for (int32_t i = 0; i < 3; i++) { taa_tex[i] = texture_load_tex_2d(texture_id(0x25, texture_counter++), GL_RGBA8, render_post_width[0], render_post_height[0], 0, 0, 0); - taa_buffer[i].SetColorDepthTextures(taa_tex[i]->tex, 0, rend_texture[0].GetDepthTex()); + taa_buffer[i].SetColorDepthTextures(taa_tex[i]->glid, 0, rend_texture[0].GetDepthTex()); } aet_back_tex = texture_load_tex_2d(texture_id(0x25, texture_counter++), GL_RGBA8, render_post_width[0], render_post_height[0], 0, 0, 0); - aet_back_texture.SetColorDepthTextures(aet_back_tex->tex, 0, rend_texture[0].GetDepthTex()); + aet_back_texture.SetColorDepthTextures(aet_back_tex->glid, 0, rend_texture[0].GetDepthTex()); mlaa_buffer.Init(render_post_width[0], render_post_height[0], 0, GL_RGBA8, GL_DEPTH_COMPONENT24); temp_buffer.Init(render_post_width[0], render_post_height[0], 0, GL_RGBA8, GL_ZERO); @@ -925,7 +925,7 @@ namespace rndr { transparency_tex[i] = texture_load_tex_2d(texture_id(0x25, texture_counter++), GL_RGBA16F, render_post_width[0], render_post_height[0], 0, 0, 0); - transparency = new renderer::Transparency(transparency_tex[0]->tex, + transparency = new renderer::Transparency(transparency_tex[0]->glid, rend_texture[0].GetDepthTex(), render_post_width[0], render_post_height[0]); } @@ -933,7 +933,7 @@ namespace rndr { for (int32_t i = 0; i < 5; i++) { reduce_tex[i] = texture_load_tex_2d(texture_id(0x25, texture_counter++), GL_RGBA16F, reduce_width[i], reduce_height[i], 0, 0, 0); - gl_state_bind_texture_2d(reduce_tex[i]->tex); + gl_state_bind_texture_2d(reduce_tex[i]->glid); const vec4 border_color = 0.0f; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); @@ -941,7 +941,7 @@ namespace rndr { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); } - reduce_texture[0].SetColorDepthTextures(reduce_tex[0]->tex); + reduce_texture[0].SetColorDepthTextures(reduce_tex[0]->glid); exposure_history = texture_load_tex_2d(texture_id(0x25, texture_counter++), GL_RGBA16F, 32, 2, 0, 0, 0); @@ -996,7 +996,7 @@ namespace rndr { return -1; movie_textures_data[index] = movie_texture; - movie_textures[index].SetColorDepthTextures(movie_texture->tex); + movie_textures[index].SetColorDepthTextures(movie_texture->glid); return index; } @@ -1026,7 +1026,7 @@ namespace rndr { return -1; render_textures_data[index] = render_texture; - render_textures[index].SetColorDepthTextures(render_texture->tex); + render_textures[index].SetColorDepthTextures(render_texture->glid); return index; } @@ -1106,17 +1106,17 @@ namespace rndr { for (int32_t i = 0; i < 3; i++) { texture_id id = taa_tex[i]->id; - texture_free(taa_tex[i]); + texture_release(taa_tex[i]); taa_tex[i] = texture_load_tex_2d(id, GL_RGBA8, render_post_width[0], render_post_height[0], 0, 0, 0); - taa_buffer[i].SetColorDepthTextures(taa_tex[i]->tex, 0, rend_texture[0].GetDepthTex()); + taa_buffer[i].SetColorDepthTextures(taa_tex[i]->glid, 0, rend_texture[0].GetDepthTex()); } texture_id aet_back_tex_id = aet_back_tex->id; - texture_free(aet_back_tex); + texture_release(aet_back_tex); aet_back_tex = texture_load_tex_2d(aet_back_tex_id, GL_RGBA8, render_post_width[0], render_post_height[0], 0, 0, 0); - aet_back_texture.SetColorDepthTextures(aet_back_tex->tex, 0, rend_texture[0].GetDepthTex()); + aet_back_texture.SetColorDepthTextures(aet_back_tex->glid, 0, rend_texture[0].GetDepthTex()); mlaa_buffer.Init(render_post_width[0], render_post_height[0], 0, GL_RGBA8, GL_DEPTH_COMPONENT24); temp_buffer.Init(render_post_width[0], render_post_height[0], 0, GL_RGBA8, GL_ZERO); @@ -1136,12 +1136,12 @@ namespace rndr { for (int32_t i = 0; i < 1; i++) { texture_id id = transparency_tex[i]->id; - texture_free(transparency_tex[i]); + texture_release(transparency_tex[i]); transparency_tex[i] = texture_load_tex_2d(id, GL_RGBA16F, render_post_width[0], render_post_height[0], 0, 0, 0); } - transparency->resize(transparency_tex[0]->tex, rend_texture[0].GetDepthTex(), + transparency->resize(transparency_tex[0]->glid, rend_texture[0].GetDepthTex(), render_post_width[0], render_post_height[0]); } @@ -1344,7 +1344,7 @@ namespace rndr { 0.0f, 0.0f, 1.0f, 1.1f, 1.1f, 1.1f, 0.0f); downsample_texture.Bind(); - gl_state_active_bind_texture_2d(0, reduce_tex[0]->tex); + gl_state_active_bind_texture_2d(0, reduce_tex[0]->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); for (int32_t i = 1; i < 5; i++) { float_t scale; @@ -1363,7 +1363,7 @@ namespace rndr { glViewport(0, 0, reduce_width[i], reduce_height[i]); draw_quad(reduce_width[i - 1], reduce_height[i - 1], 1.0f, 1.0f, 0.0f, 0.0f, scale, 1.0f, 1.0f, 1.0f, 1.0f); - gl_state_active_bind_texture_2d(0, reduce_tex[i]->tex); + gl_state_active_bind_texture_2d(0, reduce_tex[i]->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, reduce_width[i], reduce_height[i]); } @@ -1454,7 +1454,7 @@ namespace rndr { gl_state_begin_event("PostProcess::mlaa"); mlaa_buffer.Bind(); - gl_state_active_bind_texture_2d(0, taa_tex[2]->tex); + gl_state_active_bind_texture_2d(0, taa_tex[2]->glid); gl_state_bind_sampler(0, rctx->render_samplers[1]); uniform_value[U_MLAA] = 0; shaders_ft.set(SHADER_FT_MLAA); @@ -1476,7 +1476,7 @@ namespace rndr { RenderTexture& buf_texture = rctx->render_buffer; buf_texture.Bind(); - gl_state_active_bind_texture_2d(0, taa_tex[2]->tex); + gl_state_active_bind_texture_2d(0, taa_tex[2]->glid); gl_state_active_bind_texture_2d(1, temp_buffer.GetColorTex()); gl_state_bind_sampler(0, rctx->render_samplers[1]); gl_state_bind_sampler(1, rctx->render_samplers[1]); @@ -1526,12 +1526,12 @@ namespace rndr { gl_state_bind_sampler(6, rctx->render_samplers[2]); if (aet_back) { - gl_state_active_bind_texture_2d(6, aet_back_tex->tex); + gl_state_active_bind_texture_2d(6, aet_back_tex->glid); uniform_value[U_AET_BACK] = 1; } if (light_proj_tex) { - gl_state_active_bind_texture_2d(6, light_proj_tex->tex); + gl_state_active_bind_texture_2d(6, light_proj_tex->glid); uniform_value[U_LIGHT_PROJ] = 1; } @@ -1750,14 +1750,14 @@ namespace rndr { uniform_value[U_EXPOSURE] = 1; shaders_ft.set(SHADER_FT_EXPOSURE); rctx->exposure_measure_ubo.Bind(1); - gl_state_active_bind_texture_2d(0, reduce_tex[4]->tex); - gl_state_active_bind_texture_2d(1, reduce_tex[2]->tex); + gl_state_active_bind_texture_2d(0, reduce_tex[4]->glid); + gl_state_active_bind_texture_2d(1, reduce_tex[2]->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); gl_state_bind_sampler(1, rctx->render_samplers[2]); draw_quad(1, 1, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); - gl_state_active_bind_texture_2d(0, exposure_history->tex); + gl_state_active_bind_texture_2d(0, exposure_history->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); if (reset_exposure) glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 32, 1); @@ -1770,7 +1770,7 @@ namespace rndr { exposure_texture.Bind(); uniform_value[U_EXPOSURE] = 2; shaders_ft.set(SHADER_FT_EXPOSURE); - gl_state_active_bind_texture_2d(0, exposure_history->tex); + gl_state_active_bind_texture_2d(0, exposure_history->glid); gl_state_bind_sampler(0, rctx->render_samplers[0]); draw_quad(1, 1, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); @@ -1985,7 +1985,7 @@ namespace rndr { downsample_texture.Bind(); for (int32_t i = 1; i < 4; i++) { glViewport(0, 0, reduce_width[i], reduce_height[i]); - gl_state_active_bind_texture_2d(0, reduce_tex[i]->tex); + gl_state_active_bind_texture_2d(0, reduce_tex[i]->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); draw_quad(reduce_width[i], reduce_height[i], 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f); @@ -1994,7 +1994,7 @@ namespace rndr { for (int32_t i = 1; i < 4; i++) { glViewport(0, 0, reduce_width[i], reduce_height[i]); - gl_state_active_bind_texture_2d(0, reduce_tex[i]->tex); + gl_state_active_bind_texture_2d(0, reduce_tex[i]->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); draw_quad(reduce_width[i], reduce_height[i], 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); @@ -2005,7 +2005,7 @@ namespace rndr { shaders_ft.set(SHADER_FT_GAUSS); glViewport(0, 0, reduce_width[0], reduce_height[0]); - gl_state_active_bind_texture_2d(0, reduce_tex[0]->tex); + gl_state_active_bind_texture_2d(0, reduce_tex[0]->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); draw_quad(reduce_width[0], reduce_height[0], 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, @@ -2017,16 +2017,16 @@ namespace rndr { glViewport(0, 0, reduce_width[0], reduce_height[0]); reduce_texture[0].Bind(); gl_state_active_bind_texture_2d(0, downsample_texture.GetColorTex()); - gl_state_active_bind_texture_2d(1, reduce_tex[1]->tex); - gl_state_active_bind_texture_2d(2, reduce_tex[2]->tex); - gl_state_active_bind_texture_2d(3, reduce_tex[3]->tex); + gl_state_active_bind_texture_2d(1, reduce_tex[1]->glid); + gl_state_active_bind_texture_2d(2, reduce_tex[2]->glid); + gl_state_active_bind_texture_2d(3, reduce_tex[3]->glid); gl_state_bind_sampler(0, rctx->render_samplers[2]); gl_state_bind_sampler(1, rctx->render_samplers[2]); gl_state_bind_sampler(2, rctx->render_samplers[2]); gl_state_bind_sampler(3, rctx->render_samplers[2]); draw_quad(reduce_width[3], reduce_height[3], 1.0f, 1.0f, 0.0f, 0.0f, 0.25f, 0.15f, 0.25f, 0.25f, 0.25f); - reduce_tex_draw = reduce_tex[0]->tex; + reduce_tex_draw = reduce_tex[0]->glid; } void Render::update_tone_map_lut() { diff --git a/src/CRE/render_manager.cpp b/src/CRE/render_manager.cpp index 43e459ae..e1a7e9b9 100644 --- a/src/CRE/render_manager.cpp +++ b/src/CRE/render_manager.cpp @@ -789,7 +789,7 @@ namespace rndr { rctx->obj_scene_ubo.WriteMemory(rctx->obj_scene); if (effect_texture) - gl_state_active_bind_texture_2d(14, effect_texture->tex); + gl_state_active_bind_texture_2d(14, effect_texture->glid); else gl_state_active_bind_texture_2d(14, rctx->empty_texture_2d); @@ -1008,7 +1008,7 @@ namespace rndr { if (litproj && litproj->enable) { light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; if (set->lights[LIGHT_PROJECTION].get_type() == LIGHT_SPOT - && texture_storage_get_texture(litproj->texture_id)) + && texture_manager_get_texture(litproj->texture_id)) light_proj_tex = litproj->draw_texture.color_texture; } @@ -1088,7 +1088,7 @@ namespace rndr { shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4); if (effect_texture) - gl_state_active_bind_texture_2d(14, effect_texture->tex); + gl_state_active_bind_texture_2d(14, effect_texture->glid); else gl_state_active_bind_texture_2d(14, rctx->empty_texture_2d); gl_state_bind_sampler(14, rctx->render_samplers[0]); @@ -1403,7 +1403,7 @@ static bool draw_pass_shadow_litproj(light_proj* litproj) { if (!litproj) return false; - texture* tex = texture_storage_get_texture(litproj->texture_id); + texture* tex = texture_manager_get_texture(litproj->texture_id); if (!tex) return false; @@ -1421,7 +1421,7 @@ static bool draw_pass_shadow_litproj(light_proj* litproj) { render_context* rctx = rctx_ptr; rctx->draw_state->shader_index = SHADER_FT_LITPROJ; - gl_state_active_bind_texture_2d(17, tex->tex); + gl_state_active_bind_texture_2d(17, tex->glid); gl_state_bind_sampler(17, rctx->render_samplers[2]); gl_state_active_bind_texture_2d(18, litproj->shadow_texture[0].GetColorTex()); gl_state_bind_sampler(18, rctx->render_samplers[2]); diff --git a/src/CRE/render_texture.cpp b/src/CRE/render_texture.cpp index faeccc18..4fb1142a 100644 --- a/src/CRE/render_texture.cpp +++ b/src/CRE/render_texture.cpp @@ -39,12 +39,12 @@ int32_t RenderTexture::Bind(int32_t index) { void RenderTexture::Free() { if (depth_texture) { - texture_free(depth_texture); + texture_release(depth_texture); depth_texture = 0; } if (color_texture) { - texture_free(color_texture); + texture_release(color_texture); color_texture = 0; } diff --git a/src/CRE/render_texture.hpp b/src/CRE/render_texture.hpp index 1d79bf72..4df798ad 100644 --- a/src/CRE/render_texture.hpp +++ b/src/CRE/render_texture.hpp @@ -28,11 +28,11 @@ struct RenderTexture { int32_t max_level = 0, GLuint depth_texture = 0, bool stencil = false); inline GLuint GetColorTex() { - return color_texture->tex; + return color_texture->glid; }; inline GLuint GetDepthTex() { - return depth_texture->tex; + return depth_texture->glid; }; inline int32_t GetHeight() { diff --git a/src/CRE/rob/rob.cpp b/src/CRE/rob/rob.cpp index 30822930..5ee7e966 100644 --- a/src/CRE/rob/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -13608,20 +13608,6 @@ float_t rob_chara_item_cos_data::get_max_face_depth() { return max_face_depth; } -static int32_t item_cos_tex_chg_counter = 0; - -static texture_id item_cos_tex_chg_counter_get(texture_id id) { - if (id != texture_id(0x30, 0)) - return id; - - texture_id tex_id = texture_id(0x30, item_cos_tex_chg_counter); - if (item_cos_tex_chg_counter < 0xFFFFFFF) - item_cos_tex_chg_counter++; - else - item_cos_tex_chg_counter = 0; - return tex_id; -} - static void sub_140526FD0(rob_chara_item_cos_data* item_cos_data, int32_t item_no, const item_table_item* item) { if (!(item->attr & 0x0C)) @@ -13631,8 +13617,8 @@ static void sub_140526FD0(rob_chara_item_cos_data* item_cos_data, std::vector tex_chg_vec; for (const item_table_item_data_tex& i : item->data.tex) { item_cos_texture_change_tex chg_tex; - chg_tex.org = texture_storage_get_texture(i.org); - chg_tex.chg = texture_storage_get_texture(i.chg); + chg_tex.org = texture_manager_get_texture(i.org); + chg_tex.chg = texture_manager_get_texture(i.chg); chg_tex.changed = false; tex_chg_vec.push_back(chg_tex); } @@ -13654,7 +13640,7 @@ static void sub_140526FD0(rob_chara_item_cos_data* item_cos_data, size_t index = 0; for (int32_t& i : chg_tex_ids) { size_t j = &i - chg_tex_ids.data(); - texture* tex = texture_storage_get_texture(i); + texture* tex = texture_manager_get_texture(i); if (!tex) { index++; continue; @@ -13662,13 +13648,13 @@ 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(item_cos_tex_chg_counter_get(texture_id(0x30, 0)), tex); + tex = texture_copy(texture_manager_get_copy_id(0x30), tex); texture_apply_color_tone(tex, tex, &item->data.col[j].col_tone); changed = true; } item_cos_texture_change_tex chg_tex; - chg_tex.org = texture_storage_get_texture(item->data.col[j].tex_id); + chg_tex.org = texture_manager_get_texture(item->data.col[j].tex_id); chg_tex.chg = tex; chg_tex.changed = changed; tex_chg_vec.push_back(chg_tex); @@ -14199,7 +14185,7 @@ void rob_chara_item_cos_data::texture_change_clear() { for (auto i : texture_change) for (item_cos_texture_change_tex& j : i.second) if (j.changed) { - texture_free(j.chg); + texture_release(j.chg); j.chg = 0; } texture_change.clear(); diff --git a/src/CRE/sprite.cpp b/src/CRE/sprite.cpp index 2eedc141..99526ffb 100644 --- a/src/CRE/sprite.cpp +++ b/src/CRE/sprite.cpp @@ -861,7 +861,7 @@ namespace spr { rctx->sprite_scene_ubo.Bind(0); - gl_state_active_bind_texture_2d(7, tex->tex); + gl_state_active_bind_texture_2d(7, tex->glid); gl_state_bind_vertex_array(render_data.vao); for (sprite_draw_param& j : render_data.draw_param_buffer) { @@ -1615,7 +1615,7 @@ namespace spr { } break; case 1: - draw_param.texture[0] = tex_param[0].texture ? tex_param[0].texture->tex : 0; + draw_param.texture[0] = tex_param[0].texture ? tex_param[0].texture->glid : 0; draw_param.sampler = rctx->sprite_samplers[0]; if (args.num_vertex) { @@ -1758,8 +1758,8 @@ namespace spr { return; } - draw_param.texture[0] = tex_param[0].texture ? tex_param[0].texture->tex : 0; - draw_param.texture[1] = tex_param[1].texture ? tex_param[1].texture->tex : 0; + draw_param.texture[0] = tex_param[0].texture ? tex_param[0].texture->glid : 0; + draw_param.texture[1] = tex_param[1].texture ? tex_param[1].texture->glid : 0; draw_param.sampler = rctx->sprite_samplers[2]; sprite_draw_vertex spr_vtx[4] = {}; diff --git a/src/CRE/stage.cpp b/src/CRE/stage.cpp index ab0f5c61..74673223 100644 --- a/src/CRE/stage.cpp +++ b/src/CRE/stage.cpp @@ -567,11 +567,11 @@ static void stage_free(stage* s) { rndr::RenderManager* render_manager = rctx_ptr->render_manager; if (s->stage_data->render_texture != -1) rctx_ptr->render.render_texture_free( - texture_storage_get_texture(s->stage_data->render_texture), 0); + texture_manager_get_texture(s->stage_data->render_texture), 0); if (s->stage_data->movie_texture != -1) rctx_ptr->render.movie_texture_free( - texture_storage_get_texture(s->stage_data->movie_texture)); + texture_manager_get_texture(s->stage_data->movie_texture)); render_manager->set_shadow_true(); rctx_ptr->render.set_cam_blur(0); @@ -627,11 +627,11 @@ static void stage_load(stage* s) { if (s->stage_data->render_texture != -1) rctx_ptr->render.render_texture_set( - texture_storage_get_texture(s->stage_data->render_texture), 0); + texture_manager_get_texture(s->stage_data->render_texture), 0); if (s->stage_data->movie_texture != -1) rctx_ptr->render.movie_texture_set( - texture_storage_get_texture(s->stage_data->movie_texture)); + texture_manager_get_texture(s->stage_data->movie_texture)); s->state = 6; } } diff --git a/src/CRE/stage_modern.cpp b/src/CRE/stage_modern.cpp index 02b8fe25..08591866 100644 --- a/src/CRE/stage_modern.cpp +++ b/src/CRE/stage_modern.cpp @@ -565,11 +565,11 @@ static void stage_modern_free(stage_modern* s) { rndr::RenderManager* render_manager = rctx_ptr->render_manager; if (s->stage_data->render_texture != -1 && s->stage_data->render_texture != hash_murmurhash_empty) rctx_ptr->render.render_texture_free( - texture_storage_get_texture(s->stage_data->render_texture), 0); + texture_manager_get_texture(s->stage_data->render_texture), 0); if (s->stage_data->movie_texture != -1 && s->stage_data->movie_texture != hash_murmurhash_empty) rctx_ptr->render.movie_texture_free( - texture_storage_get_texture(s->stage_data->movie_texture)); + texture_manager_get_texture(s->stage_data->movie_texture)); render_manager->set_shadow_true(); rctx_ptr->render.set_cam_blur(0); @@ -620,11 +620,11 @@ static void stage_modern_load(stage_modern* s, void* data, object_database* obj_ if (s->stage_data->render_texture != -1 && s->stage_data->render_texture != hash_murmurhash_empty) rctx_ptr->render.render_texture_set( - texture_storage_get_texture(s->stage_data->render_texture), 0); + texture_manager_get_texture(s->stage_data->render_texture), 0); if (s->stage_data->movie_texture != -1 && s->stage_data->movie_texture != hash_murmurhash_empty) rctx_ptr->render.movie_texture_set( - texture_storage_get_texture(s->stage_data->movie_texture)); + texture_manager_get_texture(s->stage_data->movie_texture)); s->state = 6; } } diff --git a/src/CRE/texture.cpp b/src/CRE/texture.cpp index 0a454222..de1c508b 100644 --- a/src/CRE/texture.cpp +++ b/src/CRE/texture.cpp @@ -8,8 +8,6 @@ #include "../KKdLib/txp.hpp" #include "gl_state.hpp" #include "static_var.hpp" -#include -#include static void texture_bind(GLenum target, GLuint texture); static void texture_get_format_type_by_internal_format(GLenum internal_format, GLenum* format, GLenum* type); @@ -25,10 +23,10 @@ static texture* texture_load_tex(texture_id id, GLenum target, int32_t max_mipmap_level, void** data_ptr, bool use_high_anisotropy); static GLenum texture_txp_get_gl_internal_format(txp* t); -std::map texture_storage; +texture_manager* texture_manager_work_ptr; -texture::texture() : init_count(), flags(), width(), height(), -tex(), target(), internal_format(), max_mipmap_level(), size() { +texture::texture() : ref_count(), flags(), width(), height(), +glid(), target(), internal_format(), max_mipmap_level(), size_texmem() { } @@ -46,8 +44,26 @@ uint32_t texture::get_width_align_mip_level(uint8_t mip_level) { return max_def((uint32_t)width >> mip_level, 1u); } -texture* texture_init(texture_id id) { - return texture_storage_create_texture(id); +texture_manager::texture_manager() : entry_count(), alloc_count(), texmem_now_size(), +texmem_peak_size(), texmem_now_size_by_type(), texmem_peak_size_by_type(), copy_count() { + +} + +texture_manager::~texture_manager() { + +} + +texture* texture_alloc(texture_id id) { + auto elem = texture_manager_work_ptr->textures.find(id); + if (elem != texture_manager_work_ptr->textures.end()) { + elem->second.ref_count++; + return &elem->second; + } + + texture* tex = &texture_manager_work_ptr->textures.insert({ id, {} }).first->second; + tex->ref_count = 1; + tex->id = id; + return tex; } void texture_apply_color_tone(texture* chg_tex, @@ -68,25 +84,25 @@ void texture_apply_color_tone(texture* chg_tex, 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) { - texture_bind(org_tex->target, org_tex->tex); + 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) 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); - texture_bind(chg_tex->target, chg_tex->tex); + texture_bind(chg_tex->target, chg_tex->glid); uint32_t width = texture_get_width_mip_level(org_tex, i); uint32_t height = texture_get_width_mip_level(org_tex, i); glCompressedTexSubImage2D(chg_tex->target, i, 0, 0, width, height, chg_tex->internal_format, size, data); } else if (org_tex->internal_format == GL_RGB5) { - texture_bind(org_tex->target, org_tex->tex); + 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); - texture_bind(chg_tex->target, chg_tex->tex); + texture_bind(chg_tex->target, chg_tex->glid); uint32_t width = texture_get_width_mip_level(org_tex, i); uint32_t height = texture_get_width_mip_level(org_tex, i); glTexSubImage2D(chg_tex->target, i, 0, 0, width, height, @@ -102,7 +118,7 @@ texture* texture_copy(texture_id id, texture* org_tex) { if (org_tex->target != GL_TEXTURE_2D) return 0; - texture_bind(org_tex->target, org_tex->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)); @@ -243,7 +259,7 @@ void texture_txp_store(texture* tex, txp* t) { gl_state_get_error(); }; - texture_bind(tex->target, tex->tex); + texture_bind(tex->target, tex->glid); int32_t size = 0; if (t->has_cube_map) for (int32_t i = 0; i < 6; i++) @@ -263,8 +279,20 @@ void texture_txp_store(texture* tex, txp* t) { texture_bind(tex->target, 0); } -void texture_free(texture* tex) { - texture_storage_delete_texture(tex->id); +void texture_release(texture* tex) { + if (tex->ref_count > 1) { + tex->ref_count--; + return; + } + + if (tex->glid) { + glDeleteTextures(1, &tex->glid); + tex->glid = 0; + } + + texture_manager_work_ptr->texmem_now_size -= tex->size_texmem; + texture_manager_work_ptr->texmem_now_size_by_type[tex->id.id >> 4] -= tex->size_texmem; + texture_manager_work_ptr->textures.erase(tex->id); } void texture_array_free(texture** arr) { @@ -272,7 +300,7 @@ void texture_array_free(texture** arr) { return; for (texture** i = arr; *i; i++) - texture_free(*i); + texture_release(*i); free_def(arr); } @@ -366,55 +394,44 @@ bool texture_txp_set_load(txp_set* t, texture*** texs, texture_id* ids) { return true; } -inline void texture_storage_init() { - texture_storage = {}; +inline void texture_manager_init() { + texture_manager_work_ptr = new texture_manager; } -inline texture* texture_storage_create_texture(texture_id id) { - auto elem = texture_storage.find(id); - if (elem != texture_storage.end()) { - elem->second.init_count++; - return &elem->second; - } +inline texture_id texture_manager_get_copy_id(uint32_t id) { + if (!texture_manager_work_ptr || id != 0x30) + return texture_id(-1, -1); + + int32_t& copy_count = texture_manager_work_ptr->copy_count; + texture_id tex_id(0x30, copy_count); + if (copy_count < 0x0FFFFFFF) + copy_count++; + else + copy_count = 0; + return tex_id; - texture tex; - tex.init_count = 1; - tex.id = id; - return &texture_storage.insert({ id, tex }).first->second; } -inline texture* texture_storage_get_texture(uint32_t id) { - auto elem = texture_storage.find(texture_id(0x00, id)); - if (elem != texture_storage.end()) +inline texture* texture_manager_get_texture(uint32_t id) { + auto elem = texture_manager_work_ptr->textures.find(texture_id(0x00, id)); + if (elem != texture_manager_work_ptr->textures.end()) return &elem->second; return 0; } -inline texture* texture_storage_get_texture(texture_id id) { - auto elem = texture_storage.find(id); - if (elem != texture_storage.end()) +inline texture* texture_manager_get_texture(texture_id id) { + auto elem = texture_manager_work_ptr->textures.find(id); + if (elem != texture_manager_work_ptr->textures.end()) return &elem->second; return 0; } -inline void texture_storage_delete_texture(texture_id id) { - auto elem = texture_storage.find(id); - if (elem == texture_storage.end()) - return; +inline void texture_manager_free() { + for (auto& i : texture_manager_work_ptr->textures) + glDeleteTextures(1, &i.second.glid); - texture* tex = &elem->second; - if (tex->init_count > 1) { - tex->init_count--; - return; - } - - texture_storage.erase(elem); -} - -inline void texture_storage_free() { - for (auto& i : texture_storage) - glDeleteTextures(1, &i.second.tex); - texture_storage.clear(); + delete texture_manager_work_ptr; + texture_manager_work_ptr = 0; } inline static void texture_bind(GLenum target, GLuint texture) { @@ -640,12 +657,12 @@ static int32_t texture_load(GLenum target, GLenum internal_format, static texture* texture_load_tex(texture_id id, GLenum target, GLenum internal_format, int32_t width, int32_t height, int32_t max_mipmap_level, void** data_ptr, bool use_high_anisotropy) { - texture* tex = texture_init(id); - if (tex->init_count > 1) + texture* tex = texture_alloc(id); + if (tex->ref_count > 1) return tex; - glGenTextures(1, &tex->tex); - texture_bind(target, tex->tex); + glGenTextures(1, &tex->glid); + texture_bind(target, tex->glid); texture_set_params(target, max_mipmap_level, use_high_anisotropy); GLint swizzle[4]; @@ -733,7 +750,7 @@ static texture* texture_load_tex(texture_id id, GLenum target, tex->target = target; tex->width = (int16_t)width; tex->height = (int16_t)height; - tex->size = size; + tex->size_texmem = size; tex->internal_format = internal_format; tex->max_mipmap_level = max_mipmap_level; @@ -747,11 +764,21 @@ static texture* texture_load_tex(texture_id id, GLenum target, enum_or(tex->flags, TEXTURE_BLOCK_COMPRESSION); break; } + + texture_manager_work_ptr->texmem_now_size += tex->size_texmem; + texture_manager_work_ptr->texmem_peak_size = max_def( + texture_manager_work_ptr->texmem_peak_size, + texture_manager_work_ptr->texmem_now_size); + + texture_manager_work_ptr->texmem_now_size_by_type[id.id >> 4] += tex->size_texmem; + texture_manager_work_ptr->texmem_peak_size_by_type[id.id >> 4] = max_def( + texture_manager_work_ptr->texmem_peak_size_by_type[id.id >> 4], + texture_manager_work_ptr->texmem_now_size_by_type[id.id >> 4]); return tex; fail: texture_bind(target, 0); - texture_free(tex); + texture_release(tex); return 0; } diff --git a/src/CRE/texture.hpp b/src/CRE/texture.hpp index 38192ac3..8de801d4 100644 --- a/src/CRE/texture.hpp +++ b/src/CRE/texture.hpp @@ -9,6 +9,7 @@ #include "../KKdLib/image.hpp" #include "../KKdLib/txp.hpp" #include +#include enum texture_flags { TEXTURE_BLOCK_COMPRESSION = 0x01, @@ -55,16 +56,16 @@ inline bool operator !=(const texture_id& left, const texture_id& right) { } struct texture { - int32_t init_count; + int32_t ref_count; texture_id id; texture_flags flags; int16_t width; int16_t height; - GLuint tex; + GLuint glid; GLenum target; GLenum internal_format; int32_t max_mipmap_level; - int32_t size; + int32_t size_texmem; texture(); @@ -72,12 +73,26 @@ struct texture { uint32_t get_width_align_mip_level(uint8_t mip_level = 0); }; +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]; + int32_t copy_count; + + texture_manager(); + ~texture_manager(); +}; + struct texture_param { GLint width; GLint height; }; -extern texture* texture_init(texture_id id); +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); @@ -87,7 +102,7 @@ extern texture* texture_load_tex_cube_map(texture_id id, GLenum internal_format, int32_t max_mipmap_level, void** data_ptr); extern texture* texture_txp_load(txp* t, texture_id id); extern void texture_txp_store(texture* tex, txp* t); -extern void texture_free(texture* tex); +extern void texture_release(texture* tex); extern void texture_array_free(texture** arr); @@ -101,9 +116,8 @@ extern void texture_params_restore(texture_param* tex_0_param = 0, extern bool texture_txp_set_load(txp_set* t, texture*** texs, uint32_t* ids); extern bool texture_txp_set_load(txp_set* t, texture*** texs, texture_id* ids); -extern void texture_storage_init(); -extern texture* texture_storage_create_texture(texture_id id); -extern texture* texture_storage_get_texture(uint32_t id); -extern texture* texture_storage_get_texture(texture_id id); -extern void texture_storage_delete_texture(texture_id id); -extern void texture_storage_free(); +extern void texture_manager_init(); +extern texture_id texture_manager_get_copy_id(uint32_t id); +extern texture* texture_manager_get_texture(uint32_t id); +extern texture* texture_manager_get_texture(texture_id id); +extern void texture_manager_free(); diff --git a/src/ReDIVA/classes/data_view/texture.cpp b/src/ReDIVA/classes/data_view/texture.cpp index b83d30ce..e09e1d30 100644 --- a/src/ReDIVA/classes/data_view/texture.cpp +++ b/src/ReDIVA/classes/data_view/texture.cpp @@ -48,16 +48,16 @@ void data_view_texture_imgui(class_data* data) { return; } - extern std::map texture_storage; - for (auto& i : texture_storage) { + extern texture_manager* texture_manager_work_ptr; + for (auto& i : texture_manager_work_ptr->textures) { texture* tex = &i.second; if (tex->id.id) continue; ImGui::PushID(tex->id.index); char buf[0x1000]; - sprintf_s(buf, sizeof(buf), "ID: 0x%08X; Init Count: %3d; Width: %5d; Height: %5d; Mipmap Count: %2d", - tex->id.index, tex->init_count, tex->width, tex->height, tex->max_mipmap_level + 1); + sprintf_s(buf, sizeof(buf), "ID: 0x%08X; Ref Count: %3d; Width: %5d; Height: %5d; Mipmap Count: %2d", + tex->id.index, tex->ref_count, tex->width, tex->height, tex->max_mipmap_level + 1); ImGui::Selectable(buf); ImGui::PopID(); } diff --git a/src/ReDIVA/glitter_editor.cpp b/src/ReDIVA/glitter_editor.cpp index 45c6086e..0d59c696 100644 --- a/src/ReDIVA/glitter_editor.cpp +++ b/src/ReDIVA/glitter_editor.cpp @@ -2933,7 +2933,7 @@ static void glitter_editor_resources(GlitterEditor* glt_edt) { ImGui::BeginTooltip(); ImGui::Text("Tex Size: %dx%d", rtm->width, rtm->height); - ImGui::Image((void*)(size_t)r[i]->tex, size, + ImGui::Image((void*)(size_t)r[i]->glid, size, { 0, 0 }, { 1, 1 }, tint_col, border_col); ImGui::EndTooltip(); } @@ -4695,7 +4695,7 @@ static bool glitter_editor_property_particle_texture(GlitterEditor* glt_edt, ImGui::BeginTooltip(); ImGui::Text("Frame: %d\nUV Index %d", *tex_frame, *tex_index); ImGui::Text("Tex Size: %dx%d", rtm->width, rtm->height); - ImGui::Image((void*)(size_t)r[n - 1]->tex, size1, + ImGui::Image((void*)(size_t)r[n - 1]->glid, size1, { 0, 0 }, { 1, 1 }, tint_col, border_col); ImGui::Text("Preview Tex Size: %gx%g", particle->data.split_u > 1 @@ -4704,7 +4704,7 @@ static bool glitter_editor_property_particle_texture(GlitterEditor* glt_edt, particle->data.split_u > 1 ? (float_t)rtm->height / (float_t)particle->data.split_v : (float_t)rtm->height); - ImGui::Image((void*)(size_t)r[n - 1]->tex, size2, + ImGui::Image((void*)(size_t)r[n - 1]->glid, size2, uv_min, uv_max, tint_col, border_col); ImGui::EndTooltip(); } @@ -4728,7 +4728,7 @@ static bool glitter_editor_property_particle_texture(GlitterEditor* glt_edt, if (res) if (tex_idx) { - *tex = r[tex_idx - 1]->tex; + *tex = r[tex_idx - 1]->glid; *tex_hash = rh[tex_idx - 1]; } else { diff --git a/src/ReDIVA/pv_game/pv_game.cpp b/src/ReDIVA/pv_game/pv_game.cpp index 5a0fd9f3..d4aa5931 100644 --- a/src/ReDIVA/pv_game/pv_game.cpp +++ b/src/ReDIVA/pv_game/pv_game.cpp @@ -3478,7 +3478,7 @@ bool pv_game::load() { rndr::Render& rend = rctx_ptr->render; int32_t frame_texture_slot = 0; for (const pv_db_pv_frame_texture& i : data.pv->frame_texture) { - texture* tex = texture_storage_get_texture(aft_tex_db->get_texture_id(i.data.c_str())); + texture* tex = texture_manager_get_texture(aft_tex_db->get_texture_id(i.data.c_str())); if (tex) rend.frame_texture_load(frame_texture_slot, (rndr::Render::FrameTextureType)i.type, tex); frame_texture_slot++; @@ -4468,7 +4468,7 @@ bool pv_game::unload() { int32_t frame_texture_slot = 0; for (const pv_db_pv_frame_texture& i : data.pv->frame_texture) { if (i.data.size()) { - texture* tex = texture_storage_get_texture(aft_tex_db->get_texture_id(i.data.c_str())); + texture* tex = texture_manager_get_texture(aft_tex_db->get_texture_id(i.data.c_str())); if (tex) rend.frame_texture_unload(frame_texture_slot, tex); } diff --git a/src/ReDIVA/render.cpp b/src/ReDIVA/render.cpp index 4268f90e..96793eb8 100644 --- a/src/ReDIVA/render.cpp +++ b/src/ReDIVA/render.cpp @@ -551,7 +551,7 @@ static render_context* render_context_load() { render_shaders_load(); - texture_storage_init(); + texture_manager_init(); file_handler_storage_init(); @@ -1312,7 +1312,7 @@ static void render_context_dispose(render_context* rctx) { file_handler_storage_free(); - texture_storage_free(); + texture_manager_free(); render_shaders_free();