Removed texture_param and associated functions

This commit is contained in:
korenkonder
2024-06-09 14:07:49 +03:00
parent 13050298d4
commit e017c5887d
5 changed files with 44 additions and 117 deletions
+8 -13
View File
@@ -1413,15 +1413,12 @@ void EffectFogRing::draw() {
gl_state_get_error();
}
static void sub_1403B6F60(GLuint a1, GLuint a2, GLuint a3, EffectRipple::Params& params) {
if (!a1 || !a2 || !a3)
static void sub_1403B6F60(texture* a1, texture* a2, texture* a3, EffectRipple::Params& params) {
if (!a1 || !a1->glid || !a2 || !a2->glid || !a3 || !a3->glid)
return;
texture_param tex_params[2];
texture_params_get(0, 0, a1, &tex_params[0], a2, &tex_params[1]);
int32_t width = tex_params[1].width;
int32_t height = tex_params[1].height;
int32_t width = a2->width;
int32_t height = a2->height;
GLint v43[4];
glGetIntegervDLL(GL_VIEWPORT, v43);
@@ -1443,16 +1440,14 @@ static void sub_1403B6F60(GLuint a1, GLuint a2, GLuint a3, EffectRipple::Params&
shaders_ft.set(SHADER_FT_RIPPLE);
ripple_scene_ubo.Bind(0);
ripple_batch_ubo.Bind(1);
gl_state_active_bind_texture_2d(0, a2);
gl_state_active_bind_texture_2d(1, a3);
gl_state_active_bind_texture_2d(0, a2->glid);
gl_state_active_bind_texture_2d(1, a3->glid);
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
gl_state_active_bind_texture_2d(1, 0);
gl_state_active_bind_texture_2d(0, 0);
gl_state_bind_vertex_array(0);
glViewportDLL(v43[0], v43[1], v43[2], v43[3]);
texture_params_restore(&tex_params[0], &tex_params[1]);
}
static void sub_1403B6ED0(RenderTexture* a1, RenderTexture* a2, RenderTexture* a3, EffectRipple::Params& params) {
@@ -1462,7 +1457,7 @@ static void sub_1403B6ED0(RenderTexture* a1, RenderTexture* a2, RenderTexture* a
uniform->arr[U_RIPPLE] = 1;
else
uniform->arr[U_RIPPLE] = 0;
sub_1403B6F60(a1->GetColorTex(), a2->GetColorTex(), a3->GetColorTex(), params);
sub_1403B6F60(a1->color_texture, a2->color_texture, a3->color_texture, params);
gl_state_bind_framebuffer(0);
}
@@ -1541,7 +1536,7 @@ void EffectRipple::sub_1403584A0(RenderTexture* rt) {
field_BB8.SetColorDepthTextures(ripple_tex->glid);
field_BB8.Bind();
image_filter_scale(ripple_tex->glid, rt->GetColorTex(), 1.0f);
image_filter_scale(&field_BB8, rt->color_texture);
gl_state_bind_framebuffer(0);
}
+35 -45
View File
@@ -595,7 +595,7 @@ namespace rndr {
for (int32_t i = reflect_blur_num, j = 0; i > 0; i--, j++) {
blur_filter_apply(&refl_buf_tex, &refl_tex,
reflect_blur_filter, 1.0f, 1.0f, 0.0f);
glCopyTexSubImage2DDLL(GL_TEXTURE_2D, 0, 0, 0, 0, 0, refl_tex.GetWidth(), refl_tex.GetHeight());
image_filter_scale(&refl_tex, refl_buf_tex.color_texture);
}
}
else {
@@ -1077,13 +1077,14 @@ namespace rndr {
}
}
void image_filter_scale(GLuint dst, GLuint src, const vec4 scale) {
if (!dst || !src)
void image_filter_scale(RenderTexture* dst, texture* src, const vec4& scale) {
if (!dst || !dst->color_texture->glid || !dst->color_texture || !src || !src->glid)
return;
gl_state_begin_event("`anonymous-namespace'::Impl::apply_no_filter_sub");
texture_param tex_params[2];
texture_params_get(dst, &tex_params[0], src, &tex_params[1]);
glViewportDLL(0, 0, dst->color_texture->width, dst->color_texture->height);
dst->Bind();
filter_scene_shader_data filter_scene = {};
filter_scene.g_transform = { 1.0f, 1.0f, 0.0f, 0.0f };
@@ -1091,7 +1092,7 @@ void image_filter_scale(GLuint dst, GLuint src, const vec4 scale) {
rctx->filter_scene_ubo.WriteMemory(filter_scene);
imgfilter_batch_shader_data imgfilter_batch = {};
imgfilter_batch.g_color_scale = 1.0f;
imgfilter_batch.g_color_scale = scale;
imgfilter_batch.g_color_offset = 0.0f;
imgfilter_batch.g_texture_lod = 0.0f;
rctx->imgfilter_batch_ubo.WriteMemory(imgfilter_batch);
@@ -1100,11 +1101,10 @@ void image_filter_scale(GLuint dst, GLuint src, const vec4 scale) {
shaders_ft.set(SHADER_FT_IMGFILT);
rctx->filter_scene_ubo.Bind(0);
rctx->imgfilter_batch_ubo.Bind(1);
gl_state_active_bind_texture_2d(0, src);
gl_state_active_bind_texture_2d(0, src->glid);
gl_state_bind_sampler(0, rctx->render_samplers[0]);
gl_state_bind_vertex_array(rctx->common_vao);
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
texture_params_restore(&tex_params[0], &tex_params[1]);
gl_state_end_event();
}
@@ -1302,17 +1302,16 @@ static void draw_pass_shadow_end_make_shadowmap(Shadow* shad, int32_t index, int
RenderTexture* rend_tex = shad->curr_render_textures[1 + index];
RenderTexture& rend_buf_tex = rctx->shadow_buffer;
rend_tex->Bind();
image_filter_scale(rend_tex->GetColorTex(),
shad->curr_render_textures[0]->GetColorTex(), 1.0f);
image_filter_scale(rend_tex,
shad->curr_render_textures[0]->color_texture);
rend_buf_tex.Bind();
if (shad->blur_filter_enable[index]) {
for (int32_t i = shad->near_blur, j = 0; i > 0; i--, j++) {
blur_filter_apply(&rend_buf_tex, rend_tex,
shad->blur_filter, 1.0f, 1.0f, 0.0f);
glCopyTexSubImage2DDLL(GL_TEXTURE_2D, 0, 0, 0, 0, 0, rend_buf_tex.GetWidth(), rend_buf_tex.GetHeight());
image_filter_scale(rend_tex, rend_buf_tex.color_texture);
}
}
else {
@@ -1328,19 +1327,13 @@ static void draw_pass_shadow_end_make_shadowmap(Shadow* shad, int32_t index, int
static void draw_pass_shadow_filter(RenderTexture* a1, RenderTexture* a2,
RenderTexture* a3, float_t sigma, float_t far_texel_offset, bool enable_lit_proj) {
GLuint v7 = a1->GetColorTex();
GLuint v9 = a2->GetColorTex();
GLuint v11 = v7;
texture* v7 = a1->color_texture;
texture* v9 = a2->color_texture;
texture* v11 = v7;
if (a3)
v11 = a3->GetDepthTex();
v11 = a3->depth_texture;
if (!v7 || !v9 || !v11)
return;
texture_param tex_params[2];
texture_params_get(v7, &tex_params[0], v9, &tex_params[1]);
if (tex_params[0].width != tex_params[1].width
|| tex_params[0].height != tex_params[1].height)
if (!v7 || !v9 || !v11 || v7->width != v9->width || v7->height != v9->height)
return;
gl_state_begin_event("`anonymous-namespace'::Impl::apply_esm_filter");
@@ -1350,7 +1343,7 @@ static void draw_pass_shadow_filter(RenderTexture* a1, RenderTexture* a2,
rctx->filter_scene_ubo.WriteMemory(filter_scene);
esm_filter_batch_shader_data esm_filter_batch = {};
esm_filter_batch.g_params = { 1.0f / (float_t)tex_params[0].width, 0.0f, far_texel_offset, far_texel_offset };
esm_filter_batch.g_params = { 1.0f / (float_t)v7->width, 0.0f, far_texel_offset, far_texel_offset };
double_t v6 = 1.0 / (sqrt(M_PI * 2.0) * sigma);
double_t v8 = -1.0 / (2.0 * sigma * sigma);
for (int32_t i = 0; i < 8; i++)
@@ -1361,11 +1354,13 @@ static void draw_pass_shadow_filter(RenderTexture* a1, RenderTexture* a2,
rctx->filter_scene_ubo.Bind(0);
rctx->esm_filter_batch_ubo.Bind(1);
glViewportDLL(0, 0, v7->width, v7->height);
a2->Bind();
esm_filter_batch.g_params = { 1.0f / (float_t)tex_params[0].width, 0.0f, far_texel_offset, far_texel_offset };
esm_filter_batch.g_params = { 1.0f / (float_t)v7->width, 0.0f, far_texel_offset, far_texel_offset };
rctx->esm_filter_batch_ubo.WriteMemory(esm_filter_batch);
gl_state_active_bind_texture_2d(0, v11);
gl_state_active_bind_texture_2d(0, v11->glid);
if (a3) {
GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
@@ -1380,25 +1375,23 @@ static void draw_pass_shadow_filter(RenderTexture* a1, RenderTexture* a2,
a1->Bind();
esm_filter_batch.g_params = { 0.0f, 1.0f / (float_t)tex_params[0].height, far_texel_offset, far_texel_offset };
esm_filter_batch.g_params = { 0.0f, 1.0f / (float_t)v7->height, far_texel_offset, far_texel_offset };
rctx->esm_filter_batch_ubo.WriteMemory(esm_filter_batch);
gl_state_active_bind_texture_2d(0, v9);
gl_state_active_bind_texture_2d(0, v9->glid);
gl_state_bind_sampler(0, rctx->render_samplers[0]);
gl_state_bind_vertex_array(rctx->common_vao);
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
shader::unbind();
texture_params_restore(&tex_params[0], &tex_params[1], 0);
gl_state_end_event();
}
static void draw_pass_shadow_esm_filter(RenderTexture* dst, RenderTexture* buf, RenderTexture* src) {
GLuint dst_tex = dst->GetColorTex();
GLuint buf_tex = buf->GetColorTex();
GLuint src_tex = src->GetColorTex();
texture* dst_tex = dst->color_texture;
texture* buf_tex = buf->color_texture;
texture* src_tex = src->color_texture;
gl_state_begin_event("`anonymous-namespace'::Impl::apply_esm_min_filter");
if (!dst_tex || !buf_tex || !src_tex) {
if (!dst_tex || !dst_tex->glid || !buf_tex || !buf_tex->glid || !src_tex || !src_tex->glid) {
gl_state_end_event();
return;
}
@@ -1416,17 +1409,16 @@ static void draw_pass_shadow_esm_filter(RenderTexture* dst, RenderTexture* buf,
rctx->filter_scene_ubo.Bind(0);
rctx->esm_filter_batch_ubo.Bind(1);
texture_param tex_params[3];
texture_params_get(dst_tex, &tex_params[0], src_tex, &tex_params[1], buf_tex, &tex_params[2]);
glViewportDLL(0, 0, dst_tex->width, dst_tex->height);
buf->Bind();
esm_filter_batch.g_params = { 1.0f / (float_t)tex_params[1].width,
1.0f / (float_t)tex_params[1].height, 0.0f, 0.0f };
esm_filter_batch.g_params = { 1.0f / (float_t)src_tex->width,
1.0f / (float_t)src_tex->height, 0.0f, 0.0f };
rctx->esm_filter_batch_ubo.WriteMemory(esm_filter_batch);
uniform->arr[U_ESM_FILTER] = 0;
shaders_ft.set(SHADER_FT_ESMFILT);
gl_state_active_bind_texture_2d(0, src_tex);
gl_state_active_bind_texture_2d(0, src_tex->glid);
gl_state_bind_sampler(0, rctx->render_samplers[0]);
gl_state_bind_vertex_array(rctx->common_vao);
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -1434,18 +1426,16 @@ static void draw_pass_shadow_esm_filter(RenderTexture* dst, RenderTexture* buf,
gl_state_begin_event("erosion");
dst->Bind();
esm_filter_batch.g_params = { 0.75f / (float_t)tex_params[2].width,
0.75f / (float_t)tex_params[2].height, 0.0f, 0.0f };
esm_filter_batch.g_params = { 0.75f / (float_t)buf_tex->width,
0.75f / (float_t)buf_tex->height, 0.0f, 0.0f };
rctx->esm_filter_batch_ubo.WriteMemory(esm_filter_batch);
uniform->arr[U_ESM_FILTER] = 1;
shaders_ft.set(SHADER_FT_ESMFILT);
gl_state_active_bind_texture_2d(0, buf_tex);
gl_state_active_bind_texture_2d(0, buf_tex->glid);
gl_state_bind_sampler(0, rctx->render_samplers[0]);
gl_state_bind_vertex_array(rctx->common_vao);
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
texture_params_restore(&tex_params[0], &tex_params[1], &tex_params[2]);
gl_state_end_event();
gl_state_end_event();
}
+1 -1
View File
@@ -149,7 +149,7 @@ extern RenderTexture* litproj_shadow;
extern RenderTexture* litproj_texture;
extern rndr::RenderManager* render_manager;
extern void image_filter_scale(GLuint dst, GLuint src, const vec4 scale);
extern void image_filter_scale(RenderTexture* dst, texture* src, const vec4& scale = 1.0f);
extern void draw_pass_set_camera();
-46
View File
@@ -323,52 +323,6 @@ void texture_set_params(GLenum target, int32_t max_mipmap_level, bool use_high_a
glTexParameterfDLL(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
}
void texture_params_get(GLuint tex_0, texture_param* tex_0_param,
GLuint tex_1, texture_param* tex_1_param, GLuint tex_2, texture_param* tex_2_param) {
gl_state_disable_depth_test();
if (tex_0_param) {
tex_0_param->width = 0;
tex_0_param->height = 0;
if (tex_0) {
gl_state_bind_texture_2d(tex_0);
glGetTexLevelParameterivDLL(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tex_0_param->width);
glGetTexLevelParameterivDLL(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &tex_0_param->height);
}
}
if (tex_1_param) {
tex_1_param->width = 0;
tex_1_param->height = 0;
if (tex_1) {
gl_state_bind_texture_2d(tex_1);
glGetTexLevelParameterivDLL(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tex_1_param->width);
glGetTexLevelParameterivDLL(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &tex_1_param->height);
}
}
if (tex_2_param) {
tex_2_param->width = 0;
tex_2_param->height = 0;
if (tex_2) {
gl_state_bind_texture_2d(tex_2);
glGetTexLevelParameterivDLL(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tex_2_param->width);
glGetTexLevelParameterivDLL(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &tex_2_param->height);
}
}
gl_state_bind_texture_2d(0);
if (tex_0_param)
glViewportDLL(0, 0, tex_0_param->width, tex_0_param->height);
}
void texture_params_restore(texture_param* tex_0_param,
texture_param* tex_1_param, texture_param* tex_2_param) {
for (int32_t i = 0; i < 4; i++) {
gl_state_active_bind_texture_2d(i, 0);
gl_state_bind_sampler(i, 0);
}
}
bool texture_txp_set_load(txp_set* t, texture*** texs, uint32_t* ids) {
if (!t || !texs || !ids)
return false;
-12
View File
@@ -83,13 +83,6 @@ struct texture {
static_assert(sizeof(texture) == 0x24, "\"texture\" struct should have a size of 0x24");
struct texture_param {
GLint width;
GLint height;
};
static_assert(sizeof(texture_param) == 0x08, "\"texture_param\" struct should have a size of 0x08");
extern int32_t(FASTCALL* texture_info_get_id)(const char* name);
extern texture* texture_alloc(texture_id id);
@@ -109,11 +102,6 @@ extern void texture_array_free(texture** arr);
extern void texture_set_params(GLenum target, int32_t max_mipmap_level, bool use_high_anisotropy);
extern void texture_params_get(GLuint tex_0 = 0, texture_param* tex_0_param = 0,
GLuint tex_1 = 0, texture_param* tex_1_param = 0, GLuint tex_2 = 0, texture_param* tex_2_param = 0);
extern void texture_params_restore(texture_param* tex_0_param = 0,
texture_param* tex_1_param = 0, texture_param* tex_2_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);