Adapt new findings about Texture

This commit is contained in:
korenkonder
2024-04-13 18:06:05 +03:00
parent c5659c6cb3
commit e178aa896c
12 changed files with 181 additions and 117 deletions
+2 -2
View File
@@ -522,9 +522,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;
}
}
}
+1 -1
View File
@@ -1214,7 +1214,7 @@ HOOK(void, FASTCALL, auth_3d_object_disp, 0x00000001401D0970, auth_3d_object* o,
for (auth_3d_object_texture_transform& i : o->texture_transform) {
if (tex_trans_count >= TEXTURE_TRANSFORM_COUNT || i.texture_id == -1
|| !texture_handler_get_texture(i.texture_id))
|| !texture_manager_get_texture(i.texture_id))
continue;
tex_trans[tex_trans_count].id = i.texture_id;
+19 -19
View File
@@ -532,7 +532,7 @@ void leaf_particle_draw() {
|| !leaf_particle_enable || !stage_param_data_leaf_set)
return;
texture* tex = texture_handler_get_texture(stage_param_data_leaf_current->tex_id);
texture* tex = texture_manager_get_texture(stage_param_data_leaf_current->tex_id);
if (!tex)
return;
@@ -557,7 +557,7 @@ void leaf_particle_draw() {
shader_data.g_lit_luce = rctx->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);
@@ -569,7 +569,7 @@ void rain_particle_draw() {
if (!stage_param_data_rain_current || !rain_particle_enable || !stage_param_data_rain_set)
return;
texture* tex = texture_handler_get_texture(stage_param_data_rain_current->tex_id);
texture* tex = texture_manager_get_texture(stage_param_data_rain_current->tex_id);
if (!tex)
return;
@@ -600,7 +600,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;
@@ -674,7 +674,7 @@ void snow_particle_draw() {
if (!stage_param_data_snow_current || !snow_particle_enable || !stage_param_data_snow_set)
return;
texture* tex = texture_handler_get_texture(stage_param_data_snow_current->tex_id);
texture* tex = texture_manager_get_texture(stage_param_data_snow_current->tex_id);
if (!tex)
return;
@@ -717,7 +717,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, render_get()->rend_texture[0].GetDepthTex());
gl_state_bind_vertex_array(rctx->common_vao);
@@ -1534,14 +1534,14 @@ void EffectRipple::sub_1403584A0(RenderTexture* rt) {
if (ripple_tex_id == -1)
return;
texture* ripple_tex = texture_handler_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);
}
@@ -1726,7 +1726,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, star_sampler);
gl_state_enable_primitive_restart();
gl_state_set_primitive_restart_index(restart_index);
@@ -1752,8 +1752,8 @@ void star_catalog::draw() {
if (!stage_param_data_ptr || !enable)
return;
texture* star_tex = texture_handler_get_texture(this->star_tex);
texture* star_b_tex = texture_handler_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;
@@ -1778,7 +1778,7 @@ void star_catalog::draw() {
mat4 vp;
mat4_mul(&rctx->view_mat, &proj, &vp);
texture* milky_way_tex = texture_handler_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, stars_scene_ubo);
@@ -1817,11 +1817,11 @@ void star_catalog::draw() {
stars_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);
}
}
@@ -1965,9 +1965,9 @@ void water_particle::draw(mat4* mat) {
gl_state_bind_vertex_array(rctx->common_vao);
water_particle_scene_ubo.Bind(4);
ssbo.Bind(0);
texture* tex = texture_handler_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);
@@ -1987,9 +1987,9 @@ static void draw_fog_particle(EffectFogRing* data, mat4* mat) {
shaders_ft.set(SHADER_FT_FOGPTCL);
gl_state_enable_blend();
texture* tex = texture_handler_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->common_vao);
ssbo.Bind(0);
shaders_ft.draw_arrays(GL_TRIANGLES, 0, data->num_vtx);
+12 -12
View File
@@ -439,9 +439,9 @@ namespace mdl {
texture_id &= 0xFFFFF;
for (int32_t j = 0; j < args->texture_pattern_count; j++)
if (args->texture_pattern_array[j].src == tex_index) {
texture* tex = texture_handler_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;
}
@@ -449,7 +449,7 @@ namespace mdl {
tex_id = (*textures)[texdata->tex_index >> 20];
if (tex_id == -1)
tex_id = 0;
tex_id = rctx->empty_texture_2d;;
gl_state_active_bind_texture_2d(tex_index, tex_id);
@@ -469,7 +469,7 @@ namespace mdl {
else
wrap_t = 0;
texture* tex = texture_handler_get_texture(texture_id);
texture* tex = texture_manager_get_texture(texture_id);
gl_state_bind_sampler(tex_index, rctx->samplers[(wrap_t * 3 + wrap_s) * 2
+ (!tex || tex->max_mipmap_level > 0 ? 1 : 0)]);
}
@@ -664,9 +664,9 @@ static void draw_object_material_set_default(const mdl::ObjSubMeshArgs* args, bo
uint32_t texture_id = texdata->tex_index & 0xFFFFF;
for (int32_t j = 0; j < args->texture_pattern_count; j++)
if (args->texture_pattern_array[j].src == texture_id) {
texture* tex = texture_handler_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;
}
@@ -725,7 +725,7 @@ static void draw_object_material_set_default(const mdl::ObjSubMeshArgs* args, bo
else
wrap_t = 0;
texture* tex = texture_handler_get_texture(texture_id);
texture* tex = texture_manager_get_texture(texture_id);
gl_state_bind_sampler(tex_index, rctx->samplers[(wrap_t * 3 + wrap_s) * 2
+ (!tex || tex->max_mipmap_level > 0 ? 1 : 0)]);
}
@@ -735,7 +735,7 @@ static void draw_object_material_set_default(const mdl::ObjSubMeshArgs* args, bo
if (tex_index == 1)
uni_type = U_TEX_1_TYPE;
texture* tex = texture_handler_get_texture(texture_id);
texture* tex = texture_manager_get_texture(texture_id);
if (!tex)
uniform->arr[uni_type] = 1;
else if (tex->internal_format == GL_COMPRESSED_RED_RGTC1_EXT)
@@ -897,9 +897,9 @@ static void draw_object_material_set_reflect(const mdl::ObjSubMeshArgs* args) {
GLuint tex_id = -1;
for (int32_t j = 0; j < args->texture_pattern_count; j++)
if (args->texture_pattern_array[j].src == texture_id) {
texture* tex = texture_handler_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;
}
@@ -907,7 +907,7 @@ static void draw_object_material_set_reflect(const mdl::ObjSubMeshArgs* args) {
tex_id = (*textures)[texdata->tex_index >> 20];
if (tex_id == -1)
tex_id = 0;
tex_id = rctx->empty_texture_2d;;
gl_state_active_bind_texture_2d(i, tex_id);
@@ -927,7 +927,7 @@ static void draw_object_material_set_reflect(const mdl::ObjSubMeshArgs* args) {
else
wrap_t = 0;
texture* tex = texture_handler_get_texture(texture_id);
texture* tex = texture_manager_get_texture(texture_id);
gl_state_bind_sampler(i, rctx->samplers[(wrap_t * 3 + wrap_s) * 2
+ (!tex || tex->max_mipmap_level > 0 ? 1 : 0)]);
}
+44 -44
View File
@@ -68,7 +68,7 @@ namespace rndr {
uniform->arr[U_REDUCE] = 0;
glViewportDLL(0, 0, t->width, t->height);
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture_selector]->tex);
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture_selector]->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],
@@ -77,7 +77,7 @@ namespace rndr {
}
copy_to_frame_texture(rend_texture[0].GetColorTex(),
render_width[0], render_height[0], taa_tex[taa_texture_selector]->tex);
render_width[0], render_height[0], taa_tex[taa_texture_selector]->glid);
if (taa) {
if (taa_blend >= 0.0f)
@@ -99,11 +99,11 @@ namespace rndr {
taa_texture = 2;
taa_buffer[2].Bind();
glViewportDLL(0, 0, render_width[0], render_height[0]);
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture_selector]->tex);
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture_selector]->glid);
gl_state_bind_sampler(0, sampler);
if (depth) {
gl_state_active_bind_texture_2d(2, rend_texture[0].depth_texture->tex);
gl_state_active_bind_texture_2d(2, rend_texture[0].depth_texture->glid);
gl_state_bind_sampler(2, sampler);
mat4 mat;
@@ -123,7 +123,7 @@ namespace rndr {
int32_t taa_texture_selector = this->taa_texture_selector + 1;
if (taa_texture_selector > taa)
taa_texture_selector = 0;
gl_state_active_bind_texture_2d(1, taa_tex[taa_texture_selector]->tex);
gl_state_active_bind_texture_2d(1, taa_tex[taa_texture_selector]->glid);
gl_state_bind_sampler(1, sampler);
uniform->arr[U_REDUCE] = 5;
}
@@ -145,7 +145,7 @@ namespace rndr {
rctx->screen_buffer.Bind();
glViewportDLL(0, 0, rctx->screen_width, rctx->screen_height);
if (ssaa) {
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture]->tex);
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture]->glid);
gl_state_bind_sampler(0, rctx->render_samplers[0]);
uniform->arr[U_ALPHA_MASK] = ss_alpha_mask ? 1 : 0;
uniform->arr[U_REDUCE] = 0;
@@ -156,7 +156,7 @@ namespace rndr {
uniform->arr[U_ALPHA_MASK] = 0;
}
else {
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture]->tex);
gl_state_active_bind_texture_2d(0, taa_tex[taa_texture]->glid);
if (mag_filter == MAG_FILTER_NEAREST)
gl_state_bind_sampler(0, rctx->render_samplers[1]);
else
@@ -344,7 +344,7 @@ namespace rndr {
if (movie_texture) {
movie_textures[0].Bind();
glViewportDLL(0, 0, movie_textures_data[0]->width, movie_textures_data[0]->height);
gl_state_active_bind_texture_2d(0, movie_texture->tex);
gl_state_active_bind_texture_2d(0, movie_texture->glid);
uniform->arr[U_REDUCE] = 0;
shaders_ft.set(SHADER_FT_REDUCE);
draw_quad(movie_texture->width, movie_texture->height,
@@ -595,7 +595,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--;
}
@@ -615,7 +615,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--;
}
@@ -624,7 +624,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--;
}
@@ -642,13 +642,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--;
}
@@ -730,12 +730,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);
@@ -768,7 +768,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]);
}
@@ -776,7 +776,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;
glTexParameterfvDLL(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color);
@@ -784,7 +784,7 @@ namespace rndr {
glTexParameteriDLL(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);
@@ -839,7 +839,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;
}
@@ -869,7 +869,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;
}
@@ -921,17 +921,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);
@@ -951,12 +951,12 @@ namespace rndr {
for (int32_t i = 0; i < 1; i++) {
texture_id id = taa_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]);
}
@@ -988,7 +988,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;
@@ -1007,7 +1007,7 @@ namespace rndr {
glViewportDLL(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]);
glCopyTexSubImage2DDLL(GL_TEXTURE_2D, 0, 0, 0, 0, 0, reduce_width[i], reduce_height[i]);
}
@@ -1139,7 +1139,7 @@ namespace rndr {
if (mlaa) {
gl_state_begin_event("PostProcess::mlaa");
mlaa_buffer.Bind();
gl_state_active_bind_texture_2d(0, taa_tex[source]->tex);
gl_state_active_bind_texture_2d(0, taa_tex[source]->glid);
gl_state_bind_sampler(0, rctx->render_samplers[1]);
uniform->arr[U_MLAA] = 0;
shaders_ft.set(SHADER_FT_MLAA);
@@ -1160,7 +1160,7 @@ namespace rndr {
0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
taa_buffer[destination].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]);
@@ -1177,7 +1177,7 @@ namespace rndr {
}
else {
taa_buffer[destination].Bind();
gl_state_active_bind_texture_2d(0, taa_tex[source]->tex);
gl_state_active_bind_texture_2d(0, taa_tex[source]->glid);
gl_state_bind_sampler(0, rctx->render_samplers[1]);
uniform->arr[U_REDUCE] = 0;
shaders_ft.set(SHADER_FT_REDUCE);
@@ -1218,14 +1218,14 @@ 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->arr[U_AET_BACK] = 1;
}
static texture* (FASTCALL * litproj_texture_get)() = (texture * (FASTCALL*)())0x0000000140350600;
texture* light_proj_tex = litproj_texture_get();
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->arr[U_LIGHT_PROJ] = 1;
}
@@ -1446,14 +1446,14 @@ namespace rndr {
uniform->arr[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)
glCopyTexSubImage2DDLL(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 32, 1);
@@ -1466,7 +1466,7 @@ namespace rndr {
exposure_texture.Bind();
uniform->arr[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);
@@ -1690,7 +1690,7 @@ namespace rndr {
downsample_texture.Bind();
for (int32_t i = 1; i < 4; i++) {
glViewportDLL(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);
@@ -1699,7 +1699,7 @@ namespace rndr {
for (int32_t i = 1; i < 4; i++) {
glViewportDLL(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);
@@ -1710,7 +1710,7 @@ namespace rndr {
shaders_ft.set(SHADER_FT_GAUSS);
glViewportDLL(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,
@@ -1722,16 +1722,16 @@ namespace rndr {
glViewportDLL(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() {
+4 -4
View File
@@ -762,7 +762,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);
@@ -1049,7 +1049,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]);
@@ -1438,7 +1438,7 @@ static bool draw_pass_shadow_litproj() {
if (!stage_param_data_litproj_current)
return false;
texture* tex = texture_handler_get_texture(stage_param_data_litproj_current->tex_id);
texture* tex = texture_manager_get_texture(stage_param_data_litproj_current->tex_id);
if (!tex)
return false;
@@ -1455,7 +1455,7 @@ static bool draw_pass_shadow_litproj() {
}
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[0].GetColorTex());
gl_state_bind_sampler(18, rctx->render_samplers[2]);
+2 -2
View File
@@ -26,12 +26,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;
}
+2 -2
View File
@@ -26,11 +26,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() {
+3 -3
View File
@@ -45,7 +45,7 @@ HOOK(bool, FASTCALL, sub_1401898E0, 0x00000001401898E0, __int64 a1, texture* tex
void* field_10;
};
if (!tex || !tex->width || !tex->height || !tex->tex)
if (!tex || !tex->width || !tex->height || !tex->glid)
return false;
static struc_21* (FASTCALL* sub_140188010)(struc_21*, int32_t width, int32_t height, int32_t pix_fmt)
@@ -62,7 +62,7 @@ HOOK(bool, FASTCALL, sub_1401898E0, 0x00000001401898E0, __int64 a1, texture* tex
struc_21 v9 = {};
sub_140188010(&v9, tex->width, tex->height, 1);
gl_state_bind_texture_2d(tex->tex);
gl_state_bind_texture_2d(tex->glid);
glGetTexImageDLL(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, sub_140188410(&v9));
gl_state_bind_texture_2d(0);
@@ -75,7 +75,7 @@ HOOK(bool, FASTCALL, sub_1401898E0, 0x00000001401898E0, __int64 a1, texture* tex
}
HOOK(void, FASTCALL, ScreenShotImpl__get_data, 0x0000000140557F50, ScreenShotImpl* impl) {
gl_state_active_bind_texture_2d(0, impl->tex->tex);
gl_state_active_bind_texture_2d(0, impl->tex->glid);
glCopyTexSubImage2DDLL(GL_TEXTURE_2D, 0, 0, 0, 0, 0, impl->width, impl->height);
float_t ratio = (float_t)(impl->curr_height * impl->curr_width) / (float_t)(impl->width * impl->height);
+4 -4
View File
@@ -356,7 +356,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) {
@@ -918,7 +918,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) {
@@ -1053,8 +1053,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] = {};
+83 -18
View File
@@ -10,15 +10,36 @@
#include "types.hpp"
#include <Helpers.h>
texture* (FASTCALL* texture_init)(texture_id id)
= (texture * (FASTCALL*)(texture_id id))0x000000014069A390;
void(FASTCALL* texture_free)(texture* tex)
= (void(FASTCALL*)(texture * tex))0x000000014069DA70;
struct texture_handler {
texture tex;
int32_t field_2C;
int32_t field_30;
int32_t field_34;
};
static_assert(sizeof(texture_handler) == 0x30, "\"texture_handler\" struct should have a size of 0x30");
struct texture_manager {
prj::map<texture_id, texture_handler> textures;
int16_t entry_count;
int16_t alloc_count;
__declspec(align(8)) 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;
bool field_44;
};
static_assert(sizeof(texture_manager) == 0x48, "\"texture_manager\" struct should have a size of 0x48");
int32_t(FASTCALL* texture_info_get_id)(const char* name)
= (int32_t(FASTCALL*)(const char* name))0x000000014069CBD0;
texture* (FASTCALL* texture_handler_get_texture)(uint32_t id)
texture* (FASTCALL* texture_manager_get_texture)(uint32_t id)
= (texture * (FASTCALL*)(uint32_t id))0x000000014069CD70;
texture_manager*& texture_manager_work_ptr = *(texture_manager**)0x000000014CC96988;
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);
@@ -47,6 +68,19 @@ uint32_t texture::get_width_align_mip_level(uint8_t mip_level) {
return max_def((uint32_t)width >> mip_level, 1u);
}
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.tex.ref_count++;
return &elem->second.tex;
}
texture* tex = &texture_manager_work_ptr->textures.insert({ id, {} }).first->second.tex;
tex->ref_count = 1;
tex->id = id;
return tex;
}
void texture_apply_color_tone(texture* chg_tex, texture* org_tex, color_tone* col_tone) {
for (int32_t i = 0; i <= org_tex->max_mipmap_level; i++) {
int32_t size = texture_get_size_mip_level(org_tex, i);
@@ -57,25 +91,25 @@ void texture_apply_color_tone(texture* chg_tex, texture* org_tex, color_tone* co
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);
glGetTexImageDLL(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);
glTexSubImage2DDLL(chg_tex->target, i, 0, 0, width, height,
@@ -91,7 +125,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<void*> 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));
@@ -232,7 +266,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++)
@@ -252,12 +286,28 @@ void texture_txp_store(texture* tex, txp* t) {
texture_bind(tex->target, 0);
}
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) {
if (!arr)
return;
for (texture** i = arr; *i; i++)
texture_free(*i);
texture_release(*i);
free_def(arr);
}
@@ -370,10 +420,15 @@ HOOK(texture*, FASTCALL, texture_load_tex_2d, 0x000000014069B8E0,
width, height, max_mipmap_level, data_ptr, use_high_anisotropy);
}
HOOK(void, FASTCALL, texture_release, 0x000000014069DA70, texture* tex) {
texture_release(tex);
}
void texture_patch() {
INSTALL_HOOK(texture_apply_color_tone);
INSTALL_HOOK(texture_load_tex_cube_map);
INSTALL_HOOK(texture_load_tex_2d);
INSTALL_HOOK(texture_release);
}
inline static void texture_bind(GLenum target, GLuint texture) {
@@ -598,12 +653,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];
@@ -691,7 +746,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;
@@ -705,11 +760,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;
}
+5 -6
View File
@@ -56,16 +56,16 @@ inline bool operator !=(const texture_id& left, const texture_id& right) {
static_assert(sizeof(texture_id) == 0x04, "\"texture_id\" struct should have a size of 0x04");
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;
uint32_t get_height_align_mip_level(uint8_t mip_level = 0);
uint32_t get_width_align_mip_level(uint8_t mip_level = 0);
@@ -80,10 +80,8 @@ struct texture_param {
static_assert(sizeof(texture_param) == 0x08, "\"texture_param\" struct should have a size of 0x08");
extern texture* (FASTCALL* texture_init)(texture_id id);
extern void(FASTCALL* texture_free)(texture* tex);
extern int32_t(FASTCALL* texture_info_get_id)(const char* name);
extern texture* (FASTCALL* texture_handler_get_texture)(uint32_t id);
extern texture* (FASTCALL* texture_manager_get_texture)(uint32_t id);
extern void texture_apply_color_tone(texture* chg_tex,
texture* org_tex, const color_tone* col_tone);
@@ -94,6 +92,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_release(texture* tex);
extern void texture_array_free(texture** arr);