From 721e41d2ec2cb6677f5b58133401e6bc47e42996 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Tue, 28 Nov 2023 20:27:21 +0300 Subject: [PATCH] Some RenderTexture refactoring --- src/CRE/post_process.cpp | 43 +++++++------- src/CRE/post_process/blur.cpp | 54 ++++++++---------- src/CRE/post_process/dof.cpp | 13 ++--- src/CRE/post_process/exposure.cpp | 2 +- src/CRE/post_process/tone_map.cpp | 14 ++--- src/CRE/render_context.cpp | 5 +- src/CRE/render_manager.cpp | 95 +++++++++++++++---------------- src/CRE/render_texture.cpp | 10 ++-- src/CRE/render_texture.hpp | 23 +++++++- src/CRE/task_effect.cpp | 16 +++--- 10 files changed, 146 insertions(+), 129 deletions(-) diff --git a/src/CRE/post_process.cpp b/src/CRE/post_process.cpp index 831d98d0..15bd4623 100644 --- a/src/CRE/post_process.cpp +++ b/src/CRE/post_process.cpp @@ -173,15 +173,14 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param draw_lens_ghost(&rend_texture); - get_frame_texture(rend_texture.color_texture->tex, POST_PROCESS_FRAME_TEXTURE_PRE_PP); + get_frame_texture(rend_texture.GetColorTex(), POST_PROCESS_FRAME_TEXTURE_PRE_PP); blur->get_blur(&rend_texture); exposure->get_exposure(cam, render_width, render_height, reset_exposure, - blur->tex[4].color_texture->tex, blur->tex[2].color_texture->tex); + blur->tex[4].GetColorTex(), blur->tex[2].GetColorTex()); tone_map->apply(&rend_texture, light_proj_tex, (texture*)(aet_back ? aet_back_tex : 0), - &rend_texture, &buf_texture,/* sss_contour_texture,*/ - blur->tex[0].color_texture->tex, - exposure->exposure.color_texture->tex, npr_param, this); + &rend_texture, &buf_texture, /* sss_contour_texture,*/ + blur->tex[0].GetColorTex(), exposure->exposure.GetColorTex(), npr_param, this); if (mlaa) apply_mlaa(samplers, ss_alpha_mask); @@ -198,20 +197,20 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param uniform_value[U_REDUCE] = 0; glViewport(0, 0, t->width, t->height); - gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex); + gl_state_active_bind_texture_2d(0, rend_texture.GetColorTex()); gl_state_bind_sampler(0, samplers[0]); shaders_ft.set(SHADER_FT_REDUCE); RenderTexture::DrawQuad(&shaders_ft, render_width, render_height); } - get_frame_texture(rend_texture.color_texture->tex, POST_PROCESS_FRAME_TEXTURE_POST_PP); + get_frame_texture(rend_texture.GetColorTex(), POST_PROCESS_FRAME_TEXTURE_POST_PP); frame_texture_reset_capture(); screen_texture.Bind(); glViewport(0, 0, sprite_width, sprite_height); if (ssaa) { - gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex); + gl_state_active_bind_texture_2d(0, rend_texture.GetColorTex()); gl_state_bind_sampler(0, samplers[0]); uniform_value[U_ALPHA_MASK] = ss_alpha_mask ? 1 : 0; uniform_value[U_REDUCE] = 0; @@ -220,7 +219,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param uniform_value[U_ALPHA_MASK] = 0; } else { - gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex); + gl_state_active_bind_texture_2d(0, rend_texture.GetColorTex()); if (mag_filter == POST_PROCESS_MAG_FILTER_NEAREST) gl_state_bind_sampler(0, samplers[1]); else @@ -258,14 +257,14 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param void post_process::apply_mlaa(GLuint* samplers, int32_t ss_alpha_mask) { gl_state_begin_event("PostProcess::mlaa"); mlaa_buffer.Bind(); - gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex); + gl_state_active_bind_texture_2d(0, rend_texture.GetColorTex()); gl_state_bind_sampler(0, samplers[1]); uniform_value[U_MLAA] = 0; shaders_ft.set(SHADER_FT_MLAA); RenderTexture::DrawQuad(&shaders_ft, render_width, render_height); temp_buffer.Bind(); - gl_state_active_bind_texture_2d(0, mlaa_buffer.color_texture->tex); + gl_state_active_bind_texture_2d(0, mlaa_buffer.GetColorTex()); gl_state_active_bind_texture_2d(1, mlaa_area_texture); gl_state_bind_sampler(0, samplers[0]); gl_state_bind_sampler(1, samplers[1]); @@ -275,8 +274,8 @@ void post_process::apply_mlaa(GLuint* samplers, int32_t ss_alpha_mask) { RenderTexture::DrawQuad(&shaders_ft, render_width, render_height); buf_texture.Bind(); - gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex); - gl_state_active_bind_texture_2d(1, temp_buffer.color_texture->tex); + gl_state_active_bind_texture_2d(0, rend_texture.GetColorTex()); + gl_state_active_bind_texture_2d(1, temp_buffer.GetColorTex()); gl_state_bind_sampler(0, samplers[1]); uniform_value[U_MLAA] = 2; uniform_value[U_ALPHA_MASK] = ss_alpha_mask ? 1 : 0; @@ -287,8 +286,8 @@ void post_process::apply_mlaa(GLuint* samplers, int32_t ss_alpha_mask) { gl_state_active_bind_texture_2d(1, 0); fbo::blit(buf_texture.fbos[0], rend_texture.fbos[0], - 0, 0, buf_texture.color_texture->width, buf_texture.color_texture->height, - 0, 0, rend_texture.color_texture->width, rend_texture.color_texture->height, GL_COLOR_BUFFER_BIT, GL_LINEAR); + 0, 0, buf_texture.GetWidth(), buf_texture.GetHeight(), + 0, 0, rend_texture.GetWidth(), rend_texture.GetHeight(), GL_COLOR_BUFFER_BIT, GL_LINEAR); gl_state_end_event(); } @@ -632,8 +631,8 @@ void post_process::draw_lens_ghost(RenderTexture* rt) { gl_state_bind_array_buffer(0); } - glViewport(0, 0, rt->color_texture->width, rt->color_texture->height); rt->Bind(); + rt->SetViewport(); gl_state_enable_blend(); gl_state_set_blend_func(GL_ONE, GL_ONE); @@ -658,24 +657,30 @@ void post_process::init_fbo(int32_t render_width, int32_t render_height, if (this->render_width != render_width || this->render_height != render_height) { blur->init_fbo(render_width, render_height); dof->init_fbo(render_width, render_height); + exposure->init_fbo(); tone_map->init_fbo(); + rend_texture.Init(render_width, render_height, 0, GL_RGBA16F, GL_DEPTH_COMPONENT32F); buf_texture.Init(render_width, render_height, 0, GL_RGBA16F, 0); + if (aet_back_tex) texture_free(aet_back_tex); aet_back_tex = texture_load_tex_2d(texture_id(0x25, texture_counter++), GL_RGBA8, render_width, render_height, 0, 0, false); - aet_back_texture.SetColorDepthTextures(aet_back_tex->tex, 0, rend_texture.depth_texture->tex); + aet_back_texture.SetColorDepthTextures(aet_back_tex->tex, 0, rend_texture.GetDepthTex()); transparency_texture.Init(render_width, render_height, 0, GL_RGBA16F, GL_DEPTH_COMPONENT32F); mlaa_buffer.Init(render_width, render_height, 0, GL_RGBA8, GL_DEPTH_COMPONENT32F); temp_buffer.Init(render_width, render_height, 0, GL_RGBA8, 0); sss_contour_texture = &mlaa_buffer; - gl_state_bind_texture_2d(rend_texture.depth_texture->tex); + + gl_state_bind_texture_2d(rend_texture.GetDepthTex()); GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); - gl_state_bind_texture_2d(mlaa_buffer.depth_texture->tex); + + gl_state_bind_texture_2d(mlaa_buffer.GetDepthTex()); glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); gl_state_bind_texture_2d(0); + this->render_width = render_width; this->render_height = render_height; } diff --git a/src/CRE/post_process/blur.cpp b/src/CRE/post_process/blur.cpp index 0e0cb1d5..c1b92bdd 100644 --- a/src/CRE/post_process/blur.cpp +++ b/src/CRE/post_process/blur.cpp @@ -62,9 +62,7 @@ void post_process_blur::get_blur(RenderTexture* rt) { for (; i < count_down; i++) { glViewport(0, 0, width_down[i], height_down[i]); tex_down[i].Bind(); - gl_state_active_bind_texture_2d(0, i - ? tex_down[i - 1].color_texture->tex - : rt->color_texture->tex); + gl_state_active_bind_texture_2d(0, (i ? tex_down[i - 1] : *rt).GetColorTex()); RenderTexture::DrawQuad(&shaders_ft, width_down[i], height_down[i]); } i--; @@ -75,18 +73,16 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 256, 144); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, count_down > 0 - ? tex_down[i].color_texture->tex - : rt->color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, width, height, 1.0f, 1.1f, 1.1f, 1.1f, 0.0f); + gl_state_active_bind_texture_2d(0, (count_down > 0 ? tex_down[i] : *rt).GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, width, height, 1.0f, 1.0f, 1.1f, 1.1f, 1.1f, 0.0f); uniform_value[U_GAUSS] = 1; shaders_ft.set(SHADER_FT_GAUSS); glViewport(0, 0, 256, 144); tex[5].Bind(); - gl_state_active_bind_texture_2d(0, tex[0].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 256, 144, 1.0f, + gl_state_active_bind_texture_2d(0, tex[0].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 256, 144, 1.0f, 1.0f, data.intensity.x * 0.5f, data.intensity.y * 0.5f, data.intensity.z * 0.5f, 1.0f); uniform_value[U_REDUCE] = 1; @@ -94,7 +90,7 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 128, 72); tex[1].Bind(); - gl_state_active_bind_texture_2d(0, tex[0].color_texture->tex); + gl_state_active_bind_texture_2d(0, tex[0].GetColorTex()); RenderTexture::DrawQuad(&shaders_ft, 256, 144); uniform_value[U_REDUCE] = 1; @@ -102,7 +98,7 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 64, 36); tex[2].Bind(); - gl_state_active_bind_texture_2d(0, tex[1].color_texture->tex); + gl_state_active_bind_texture_2d(0, tex[1].GetColorTex()); RenderTexture::DrawQuad(&shaders_ft, 128, 72); uniform_value[U_REDUCE] = 1; @@ -110,7 +106,7 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 32, 18); tex[3].Bind(); - gl_state_active_bind_texture_2d(0, tex[2].color_texture->tex); + gl_state_active_bind_texture_2d(0, tex[2].GetColorTex()); RenderTexture::DrawQuad(&shaders_ft, 64, 36); uniform_value[U_EXPOSURE] = 0; @@ -118,7 +114,7 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 8, 8); tex[4].Bind(); - gl_state_active_bind_texture_2d(0, tex[3].color_texture->tex); + gl_state_active_bind_texture_2d(0, tex[3].GetColorTex()); RenderTexture::DrawQuad(&shaders_ft, 32, 18); uniform_value[U_GAUSS] = 0; @@ -127,23 +123,23 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 128, 72); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, tex[1].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 128, 72, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f); + gl_state_active_bind_texture_2d(0, tex[1].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 128, 72, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f); fbo::blit(tex[0].fbos[0], tex[1].fbos[0], 0, 0, 128, 72, 0, 0, 128, 72, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 64, 36); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, tex[2].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 64, 36, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f); + gl_state_active_bind_texture_2d(0, tex[2].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 64, 36, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f); fbo::blit(tex[0].fbos[0], tex[2].fbos[0], 0, 0, 64, 36, 0, 0, 64, 36, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 32, 18); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, tex[3].color_texture->tex); + gl_state_active_bind_texture_2d(0, tex[3].GetColorTex()); RenderTexture::DrawQuad(&shaders_ft, 32, 18); fbo::blit(tex[0].fbos[0], tex[3].fbos[0], 0, 0, 32, 18, @@ -151,24 +147,24 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 128, 72); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, tex[1].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 128, 72, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); + gl_state_active_bind_texture_2d(0, tex[1].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 128, 72, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[1].fbos[0], 0, 0, 128, 72, 0, 0, 128, 72, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 64, 36); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, tex[2].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 64, 36, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); + gl_state_active_bind_texture_2d(0, tex[2].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 64, 36, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[2].fbos[0], 0, 0, 64, 36, 0, 0, 64, 36, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 32, 18); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, tex[3].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 32, 18, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); + gl_state_active_bind_texture_2d(0, tex[3].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 32, 18, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[3].fbos[0], 0, 0, 32, 18, 0, 0, 32, 18, GL_COLOR_BUFFER_BIT, GL_LINEAR); @@ -178,11 +174,11 @@ void post_process_blur::get_blur(RenderTexture* rt) { glViewport(0, 0, 256, 144); tex[0].Bind(); - gl_state_active_bind_texture_2d(0, tex[5].color_texture->tex); - gl_state_active_bind_texture_2d(1, tex[1].color_texture->tex); - gl_state_active_bind_texture_2d(2, tex[2].color_texture->tex); - gl_state_active_bind_texture_2d(3, tex[3].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 32, 18, 0.25f, 0.15f, 0.25f, 0.25f, 0.25f); + gl_state_active_bind_texture_2d(0, tex[5].GetColorTex()); + gl_state_active_bind_texture_2d(1, tex[1].GetColorTex()); + gl_state_active_bind_texture_2d(2, tex[2].GetColorTex()); + gl_state_active_bind_texture_2d(3, tex[3].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 32, 18, 0.25f, 0.25f, 0.15f, 0.25f, 0.25f, 0.25f); } void post_process_blur::init_fbo(int32_t width, int32_t height) { diff --git a/src/CRE/post_process/dof.cpp b/src/CRE/post_process/dof.cpp index d0ec23b7..d20c75a3 100644 --- a/src/CRE/post_process/dof.cpp +++ b/src/CRE/post_process/dof.cpp @@ -114,15 +114,13 @@ void post_process_dof::apply(RenderTexture* rt, RenderTexture* buf, camera* cam) } focus = max_def(focus, (float_t)cam->min_distance); - renderer::DOF3::apply_physical(this, rt, buf, - rt->color_texture->tex, rt->depth_texture->tex, + renderer::DOF3::apply_physical(this, rt, buf, rt->GetColorTex(), rt->GetDepthTex(), (float_t)cam->min_distance, (float_t)cam->max_distance, focus, dof_debug_data.focal_length, (float_t)cam->fov_rad, dof_debug_data.f_number); } else { float_t fuzzing_range = max_def(dof_debug_data.f2.fuzzing_range, 0.01f); - renderer::DOF3::apply_f2(this, rt, buf, - rt->color_texture->tex, rt->depth_texture->tex, + renderer::DOF3::apply_f2(this, rt, buf, rt->GetColorTex(), rt->GetDepthTex(), (float_t)cam->min_distance, (float_t)cam->max_distance, (float_t)cam->fov_rad, dof_debug_data.f2.focus, dof_debug_data.f2.focus_range, fuzzing_range, dof_debug_data.f2.ratio); @@ -132,8 +130,7 @@ void post_process_dof::apply(RenderTexture* rt, RenderTexture* buf, camera* cam) } else if (dof_pv_data.enable && dof_pv_data.f2.ratio > 0.0f) { float_t fuzzing_range = max_def(dof_pv_data.f2.fuzzing_range, 0.01f); - renderer::DOF3::apply_f2(this, rt, buf, - rt->color_texture->tex, rt->depth_texture->tex, + renderer::DOF3::apply_f2(this, rt, buf, rt->GetColorTex(), rt->GetDepthTex(), (float_t)cam->min_distance, (float_t)cam->max_distance, (float_t)cam->fov_rad, dof_pv_data.f2.focus, dof_pv_data.f2.focus_range, fuzzing_range, dof_pv_data.f2.ratio); @@ -418,8 +415,8 @@ namespace renderer { glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); fbo::blit(buf->fbos[0], rt->fbos[0], - 0, 0, buf->color_texture->width, buf->color_texture->height, - 0, 0, rt->color_texture->width, rt->color_texture->height, GL_COLOR_BUFFER_BIT, GL_LINEAR); + 0, 0, buf->GetWidth(), buf->GetHeight(), + 0, 0, rt->GetWidth(), rt->GetHeight(), GL_COLOR_BUFFER_BIT, GL_LINEAR); gl_state_end_event(); } diff --git a/src/CRE/post_process/exposure.cpp b/src/CRE/post_process/exposure.cpp index cd294de7..4579b02e 100644 --- a/src/CRE/post_process/exposure.cpp +++ b/src/CRE/post_process/exposure.cpp @@ -183,7 +183,7 @@ void post_process_exposure::get_exposure(camera* cam, int32_t render_width, exposure.Bind(); uniform_value[U_EXPOSURE] = 2; shaders_ft.set(SHADER_FT_EXPOSURE); - gl_state_active_bind_texture_2d(0, exposure_history.color_texture->tex); + gl_state_active_bind_texture_2d(0, exposure_history.GetColorTex()); RenderTexture::DrawQuad(&shaders_ft, 1, 1); } diff --git a/src/CRE/post_process/tone_map.cpp b/src/CRE/post_process/tone_map.cpp index e2ee28be..fcb55f99 100644 --- a/src/CRE/post_process/tone_map.cpp +++ b/src/CRE/post_process/tone_map.cpp @@ -87,7 +87,7 @@ void post_process_tone_map::apply(RenderTexture* in_tex, texture* light_proj_tex uniform_value[U_LIGHT_PROJ] = 0; //uniform_value[U25] = 0; - gl_state_active_bind_texture_2d(0, in_tex->color_texture->tex); + gl_state_active_bind_texture_2d(0, in_tex->GetColorTex()); gl_state_active_bind_texture_2d(1, in_tex_0); gl_state_active_bind_texture_2d(2, tone_map_tex); gl_state_active_bind_texture_2d(3, in_tex_1); @@ -164,29 +164,29 @@ void post_process_tone_map::apply(RenderTexture* in_tex, texture* light_proj_tex } if (npr_param == 1) { - /*gl_state_active_bind_texture_2d(16, contour_rt->color_texture->tex); + /*gl_state_active_bind_texture_2d(16, contour_rt->GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - gl_state_active_bind_texture_2d(17, contour_rt->depth_texture->tex); + gl_state_active_bind_texture_2d(17, contour_rt->GetDepthTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);*/ - gl_state_active_bind_texture_2d(14, rt->depth_texture->tex); + gl_state_active_bind_texture_2d(14, rt->GetDepthTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } tone_map_ubo.WriteMemory(shader_data); - glViewport(0, 0, rt->color_texture->width, rt->color_texture->height); buf_rt->Bind(); + buf_rt->SetViewport(); shaders_ft.set(SHADER_FT_TONEMAP); tone_map_ubo.Bind(1); RenderTexture::Draw(&shaders_ft); gl_state_active_bind_texture_2d(2, 0); fbo::blit(buf_rt->fbos[0], rt->fbos[0], - 0, 0, buf_rt->color_texture->width, buf_rt->color_texture->height, - 0, 0, rt->color_texture->width, rt->color_texture->height, GL_COLOR_BUFFER_BIT, GL_LINEAR); + 0, 0, buf_rt->GetWidth(), buf_rt->GetHeight(), + 0, 0, rt->GetWidth(), rt->GetHeight(), GL_COLOR_BUFFER_BIT, GL_LINEAR); gl_state_end_event(); } diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index 718188a9..2d172440 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -390,8 +390,7 @@ bool light_proj::set(render_context* rctx) { } else { draw_texture.Bind(); - glViewport(0, 0, draw_texture.color_texture->width, - draw_texture.color_texture->height); + draw_texture.SetViewport(); gl_state_enable_depth_test(); gl_state_set_depth_mask(GL_TRUE); glClearBufferfv(GL_COLOR, 0, (float_t*)&color_clear); @@ -4364,7 +4363,7 @@ int32_t Shadow::InitData() { return -1; for (int32_t i = 0; i < 4; i++) { - gl_state_bind_texture_2d(render_textures[i == 3 ? 7 : i].color_texture->tex); + gl_state_bind_texture_2d(render_textures[i == 3 ? 7 : i].GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); static const vec4 border_color = 1.0f; diff --git a/src/CRE/render_manager.cpp b/src/CRE/render_manager.cpp index 8773d5c5..57bfb25d 100644 --- a/src/CRE/render_manager.cpp +++ b/src/CRE/render_manager.cpp @@ -260,7 +260,7 @@ namespace rndr { //if (sss->npr_contour) { pp->rend_texture.Bind(); - glViewport(0, 0, pp->render_width, pp->render_height); + pp->rend_texture.SetViewport(); //} //else { // sss->textures[0].Bind(); @@ -300,7 +300,7 @@ namespace rndr { rctx->obj_scene_ubo.WriteMemory(rctx->obj_scene); pp->rend_texture.Bind(); - glViewport(0, 0, pp->render_width, pp->render_height); + pp->rend_texture.SetViewport(); glClear(GL_DEPTH_BUFFER_BIT); rctx->draw_state.shader_index = SHADER_FT_SSS_SKIN; gl_state_enable_depth_test(); @@ -333,7 +333,7 @@ namespace rndr { 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, pp->rend_texture.color_texture->tex); + gl_state_active_bind_texture_2d(0, pp->rend_texture.GetColorTex()); RenderTexture::DrawCustom(); } @@ -353,7 +353,7 @@ namespace rndr { || rctx->disp_manager.get_obj_count(mdl::OBJ_TYPE_REFLECT_CHARA_OPAQUE) || rctx->disp_manager.get_obj_count(mdl::OBJ_TYPE_REFLECT_CHARA_TRANSPARENT) || rctx->disp_manager.get_obj_count(mdl::OBJ_TYPE_REFLECT_CHARA_TRANSLUCENT)) { - glViewport(0, 0, refl_tex.color_texture->width, refl_tex.color_texture->height); + refl_tex.SetViewport(); draw_pass_set_camera(rctx); @@ -399,19 +399,19 @@ namespace rndr { for (int32_t i = reflect_blur_num, j = 0; i > 0; i--, j++) if (j % 2) { refl_tex.Bind(); - blur_filter_apply(rctx, refl_tex.color_texture->tex, - refl_buf_tex.color_texture->tex, reflect_blur_filter, 1.0f, 1.0f, 0.0f); + blur_filter_apply(rctx, refl_tex.GetColorTex(), + refl_buf_tex.GetColorTex(), reflect_blur_filter, 1.0f, 1.0f, 0.0f); } else { refl_buf_tex.Bind(); - blur_filter_apply(rctx, refl_buf_tex.color_texture->tex, - refl_tex.color_texture->tex, reflect_blur_filter, 1.0f, 1.0f, 0.0f); + blur_filter_apply(rctx, refl_buf_tex.GetColorTex(), + refl_tex.GetColorTex(), reflect_blur_filter, 1.0f, 1.0f, 0.0f); } if (reflect_blur_num % 2) fbo::blit(refl_buf_tex.fbos[0], refl_tex.fbos[0], - 0, 0, refl_buf_tex.color_texture->width, refl_buf_tex.color_texture->height, - 0, 0, refl_tex.color_texture->width, refl_tex.color_texture->height, + 0, 0, refl_buf_tex.GetWidth(), refl_buf_tex.GetHeight(), + 0, 0, refl_tex.GetWidth(), refl_tex.GetHeight(), GL_COLOR_BUFFER_BIT, GL_LINEAR); } else { @@ -575,7 +575,7 @@ namespace rndr { if (pass_sw[RND_PASSID_REFLECT] && reflect) { RenderTexture& refl_tex = get_render_texture(0); - gl_state_active_bind_texture_2d(15, refl_tex.color_texture->tex); + gl_state_active_bind_texture_2d(15, refl_tex.GetColorTex()); uniform_value[U_WATER_REFLECT] = 1; } else { @@ -590,7 +590,7 @@ namespace rndr { else gl_state_active_bind_texture_2d(14, rctx->empty_texture_2d); - gl_state_active_bind_texture_2d(16, sss_data.textures[1].color_texture->tex); + gl_state_active_bind_texture_2d(16, sss_data.textures[1].GetColorTex()); gl_state_active_texture(0); if (alpha_z_sort) { @@ -855,13 +855,13 @@ namespace rndr { rctx->contour_params_ubo.WriteMemory(contour_params_data); shaders_ft.set(SHADER_FT_CONTOUR_NPR); - gl_state_active_bind_texture_2d(16, contour_rt->color_texture->tex); + gl_state_active_bind_texture_2d(16, contour_rt->GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - gl_state_active_bind_texture_2d(17, contour_rt->depth_texture->tex); + gl_state_active_bind_texture_2d(17, contour_rt->GetDepthTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - gl_state_active_bind_texture_2d(14, rt->depth_texture->tex); + gl_state_active_bind_texture_2d(14, rt->GetDepthTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); rctx->quad_ubo.Bind(0); @@ -939,9 +939,9 @@ void draw_pass_set_camera(render_context* rctx) { static void draw_pass_shadow_begin_make_shadowmap(render_context* rctx, Shadow* shad, int32_t index, int32_t a3) { - texture* tex = shad->curr_render_textures[0]->color_texture; shad->curr_render_textures[0]->Bind(); - glViewport(0, 0, tex->width, tex->height); + shad->curr_render_textures[0]->SetViewport(); + texture* tex = shad->curr_render_textures[0]->color_texture; glScissor(0, 0, tex->width, tex->height); gl_state_enable_depth_test(); gl_state_enable_scissor_test(); @@ -999,25 +999,25 @@ static void draw_pass_shadow_end_make_shadowmap(render_context* rctx, RenderTexture* rend_buf_tex = shad->curr_render_textures[3]; rend_tex->Bind(); - image_filter_scale(rctx, rend_tex->color_texture->tex, - shad->curr_render_textures[0]->color_texture->tex, 1.0f); + image_filter_scale(rctx, rend_tex->GetColorTex(), + shad->curr_render_textures[0]->GetColorTex(), 1.0f); if (shad->blur_filter_enable[index]) { for (int32_t i = shad->near_blur, j = 0; i > 0; i--, j++) if (j % 2) { rend_tex->Bind(); - blur_filter_apply(rctx, rend_tex->color_texture->tex, - rend_buf_tex->color_texture->tex, shad->blur_filter, 1.0f, 1.0f, 0.0f); + blur_filter_apply(rctx, rend_tex->GetColorTex(), + rend_buf_tex->GetColorTex(), shad->blur_filter, 1.0f, 1.0f, 0.0f); } else { rend_buf_tex->Bind(); - blur_filter_apply(rctx, rend_buf_tex->color_texture->tex, - rend_tex->color_texture->tex, shad->blur_filter, 1.0f, 1.0f, 0.0f); + blur_filter_apply(rctx, rend_buf_tex->GetColorTex(), + rend_tex->GetColorTex(), shad->blur_filter, 1.0f, 1.0f, 0.0f); } if (shad->near_blur % 2) - image_filter_scale(rctx, rend_buf_tex->color_texture->tex, - rend_tex->color_texture->tex, 1.0f); + image_filter_scale(rctx, rend_buf_tex->GetColorTex(), + rend_tex->GetColorTex(), 1.0f); } else { rend_tex->Bind(); @@ -1026,18 +1026,18 @@ static void draw_pass_shadow_end_make_shadowmap(render_context* rctx, } gl_state_bind_framebuffer(0); - gl_state_bind_texture_2d(rend_tex->color_texture->tex); + gl_state_bind_texture_2d(rend_tex->GetColorTex()); glGenerateMipmap(GL_TEXTURE_2D); gl_state_bind_texture_2d(0); } static void draw_pass_shadow_filter(render_context* rctx, RenderTexture* a1, RenderTexture* a2, RenderTexture* a3, float_t sigma, float_t far_texel_offset, bool enable_lit_proj) { - GLuint v7 = a1->color_texture->tex; - GLuint v9 = a2->color_texture->tex; + GLuint v7 = a1->GetColorTex(); + GLuint v9 = a2->GetColorTex(); GLuint v11 = v7; if (a3) - v11 = a3->depth_texture->tex; + v11 = a3->GetDepthTex(); if (!v7 || !v9 || !v11) return; @@ -1094,9 +1094,9 @@ static void draw_pass_shadow_filter(render_context* rctx, RenderTexture* a1, Ren static void draw_pass_shadow_esm_filter(render_context* rctx, RenderTexture* dst, RenderTexture* buf, RenderTexture* src) { - GLuint dst_tex = dst->color_texture->tex; - GLuint buf_tex = buf->color_texture->tex; - GLuint src_tex = src->color_texture->tex; + GLuint dst_tex = dst->GetColorTex(); + GLuint buf_tex = buf->GetColorTex(); + GLuint src_tex = src->GetColorTex(); if (!dst_tex || !buf_tex || !src_tex) return; @@ -1147,9 +1147,7 @@ static bool draw_pass_shadow_litproj(render_context* rctx, light_proj* litproj) return false; litproj->draw_texture.Bind(); - - glViewport(0, 0, litproj->draw_texture.color_texture->width, - litproj->draw_texture.color_texture->height); + litproj->draw_texture.SetViewport(); gl_state_enable_depth_test(); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepthf(1.0f); @@ -1166,7 +1164,7 @@ static bool draw_pass_shadow_litproj(render_context* rctx, light_proj* litproj) glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - gl_state_active_bind_texture_2d(18, litproj->shadow_texture[0].color_texture->tex); + gl_state_active_bind_texture_2d(18, litproj->shadow_texture[0].GetColorTex()); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); @@ -1176,16 +1174,17 @@ static bool draw_pass_shadow_litproj(render_context* rctx, light_proj* litproj) static void draw_pass_sss_contour(render_context* rctx, post_process* pp) { pp->sss_contour_texture->Bind(); + pp->sss_contour_texture->SetViewport(); gl_state_enable_depth_test(); gl_state_set_depth_func(GL_ALWAYS); gl_state_set_depth_mask(GL_TRUE); glViewport(0, 0, pp->render_width, pp->render_height); - gl_state_active_bind_texture_2d(0, pp->rend_texture.color_texture->tex); + gl_state_active_bind_texture_2d(0, pp->rend_texture.GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - gl_state_active_bind_texture_2d(1, pp->rend_texture.depth_texture->tex); + gl_state_active_bind_texture_2d(1, pp->rend_texture.GetDepthTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -1319,15 +1318,15 @@ static void draw_pass_sss_filter(render_context* rctx, sss_data* sss) { post_process* pp = &rctx->post_process; uniform_value[U_REDUCE] = 0; shaders_ft.set(SHADER_FT_REDUCE); - gl_state_bind_texture_2d(pp->rend_texture.color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); + gl_state_bind_texture_2d(pp->rend_texture.GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); } sss->textures[2].Bind(); glViewport(0, 0, 320, 180); uniform_value[U_SSS_FILTER] = 0; shaders_ft.set(SHADER_FT_SSS_FILT); - gl_state_bind_texture_2d(sss->textures[0].color_texture->tex); - RenderTexture::DrawQuad(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); + gl_state_bind_texture_2d(sss->textures[0].GetColorTex()); + RenderTexture::DrawQuad(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); sss_filter_gaussian_coef_shader_data shader_data = {}; shader_data.g_param = { (float_t)(sss_count - 1), 0.0f, 1.0f, 1.0f }; @@ -1343,9 +1342,9 @@ static void draw_pass_sss_filter(render_context* rctx, sss_data* sss) { glViewport(0, 0, 320, 180); uniform_value[U_SSS_FILTER] = 3; shaders_ft.set(SHADER_FT_SSS_FILT); - gl_state_bind_texture_2d(sss->textures[2].color_texture->tex); + gl_state_bind_texture_2d(sss->textures[2].GetColorTex()); rctx->sss_filter_gaussian_coef_ubo.Bind(1); - RenderTexture::DrawQuad(&shaders_ft, 320, 180, 1.0f, 1.0f, 0.96f, 1.0f, 0.0f); + RenderTexture::DrawQuad(&shaders_ft, 320, 180, 1.0f, 1.0f, 1.0f, 0.96f, 1.0f, 0.0f); gl_state_bind_texture_2d(0); } @@ -1377,8 +1376,8 @@ static void draw_pass_3d_shadow_reset(render_context* rctx) { static void draw_pass_3d_shadow_set(Shadow* shad, render_context* rctx) { if (shad->self_shadow && shad->field_2EC > 0) { - gl_state_active_bind_texture_2d(19, shad->render_textures[3].color_texture->tex); - gl_state_active_bind_texture_2d(20, shad->render_textures[5].color_texture->tex); + gl_state_active_bind_texture_2d(19, shad->render_textures[3].GetColorTex()); + gl_state_active_bind_texture_2d(20, shad->render_textures[5].GetColorTex()); gl_state_active_texture(0); float_t esm_param = (shad->field_2D8 * shad->field_208 * 2.0f) * 1.442695f; rctx->obj_scene.g_esm_param = { esm_param, 0.0f, 0.0f, 0.0f }; @@ -1432,7 +1431,7 @@ static void draw_pass_3d_shadow_set(Shadow* shad, render_context* rctx) { continue; } - gl_state_active_bind_texture_2d(6 + j, shad->curr_render_textures[1 + i]->color_texture->tex); + gl_state_active_bind_texture_2d(6 + j, shad->curr_render_textures[1 + i]->GetColorTex()); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); j++; } @@ -1457,7 +1456,7 @@ static void draw_pass_3d_shadow_set(Shadow* shad, render_context* rctx) { rctx->draw_state.light = false; for (int32_t i = 0; i < 2; i++) - gl_state_active_bind_texture_2d(6 + i, shad->curr_render_textures[1 + i]->color_texture->tex); + gl_state_active_bind_texture_2d(6 + i, shad->curr_render_textures[1 + i]->GetColorTex()); gl_state_active_texture(0); rctx->obj_scene.g_shadow_ambient = 1.0f; diff --git a/src/CRE/render_texture.cpp b/src/CRE/render_texture.cpp index 3dc8cfc2..6008f4ff 100644 --- a/src/CRE/render_texture.cpp +++ b/src/CRE/render_texture.cpp @@ -84,8 +84,8 @@ int32_t RenderTexture::Init(int32_t width, int32_t height, return -1; render_texture_counter++; - color_texture = this->color_texture->tex; - gl_state_bind_texture_2d(this->color_texture->tex); + color_texture = GetColorTex(); + gl_state_bind_texture_2d(GetColorTex()); if (color_format == GL_RGBA32F) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -108,7 +108,7 @@ int32_t RenderTexture::Init(int32_t width, int32_t height, return -1; render_texture_counter++; - depth_texture = this->depth_texture->tex; + depth_texture = this->GetDepthTex(); stencil = depth_format == GL_DEPTH24_STENCIL8; } else { @@ -146,14 +146,14 @@ void RenderTexture::DrawCustom() { } void RenderTexture::DrawQuad(shader_set_data* set, int32_t width, int32_t height, - float_t scale, float_t param_x, float_t param_y, float_t param_z, float_t param_w) { + float_t scale_x, float_t scale_y, float_t param_x, float_t param_y, float_t param_z, float_t param_w) { extern render_context* rctx_ptr; float_t w = (float_t)max_def(width, 1); float_t h = (float_t)max_def(height, 1); quad_shader_data quad = {}; quad.g_texcoord_modifier = { 0.5f, 0.5f, 0.5f, 0.5f }; // x * 0.5 + 0.5 - quad.g_texel_size = { scale / w, scale / h, w, h }; + quad.g_texel_size = { scale_x / w, scale_y / h, w, h }; quad.g_color = { param_x, param_y, param_z, param_w }; quad.g_texture_lod = 0.0f; diff --git a/src/CRE/render_texture.hpp b/src/CRE/render_texture.hpp index 2a731c7b..542cd50f 100644 --- a/src/CRE/render_texture.hpp +++ b/src/CRE/render_texture.hpp @@ -30,8 +30,29 @@ struct RenderTexture { static void Draw(shader_set_data* set); static void DrawCustom(); - static void DrawQuad(shader_set_data* set, int32_t width, int32_t height, float_t scale = 1.0f, + static void DrawQuad(shader_set_data* set, + int32_t width, int32_t height, float_t scale_x = 1.0f, float_t scale_y = 1.0f, float_t param_x = 1.0f, float_t param_y = 1.0f, float_t param_z = 1.0f, float_t param_w = 1.0f); + + inline GLuint GetColorTex() { + return color_texture->tex; + }; + + inline GLuint GetDepthTex() { + return depth_texture->tex; + }; + + inline int32_t GetHeight() { + return color_texture->height; + }; + + inline int32_t GetWidth() { + return color_texture->width; + }; + + inline void SetViewport() { + glViewport(0, 0, GetWidth(), GetHeight()); + }; }; extern void render_texture_data_init(); diff --git a/src/CRE/task_effect.cpp b/src/CRE/task_effect.cpp index 30370ae0..73c72621 100644 --- a/src/CRE/task_effect.cpp +++ b/src/CRE/task_effect.cpp @@ -1943,15 +1943,15 @@ void ripple_emit::draw() { GLint v43[4]; glGetIntegerv(GL_VIEWPORT, v43); - int32_t width = rt[0]->color_texture->width; - int32_t height = rt[0]->color_texture->height; + int32_t width = rt[0]->GetWidth(); + int32_t height = rt[0]->GetHeight(); glViewport(1, 1, width - 2, height - 2); draw_pass_set_camera(rctx_ptr); glClear(GL_DEPTH_BUFFER_BIT); if (rctx->disp_manager.get_obj_count(mdl::OBJ_TYPE_USER)) { - gl_state_active_bind_texture_2d(7, rt[counter % 3]->color_texture->tex); + gl_state_active_bind_texture_2d(7, rt[counter % 3]->GetColorTex()); rctx->disp_manager.draw(mdl::OBJ_TYPE_USER, 0, true); gl_state_active_bind_texture_2d(7, 0); } @@ -2102,7 +2102,7 @@ void ripple_emit::sub_1403584A0(RenderTexture* rt) { field_BB8.SetColorDepthTextures(ripple_tex->tex); field_BB8.Bind(); - image_filter_scale(rctx_ptr, ripple_tex->tex, rt->color_texture->tex, 1.0f); + image_filter_scale(rctx_ptr, ripple_tex->tex, rt->GetColorTex(), 1.0f); gl_state_bind_framebuffer(0); } @@ -2945,7 +2945,7 @@ void snow_particle_draw() { snow_particle_batch_ubo.WriteMemory(snow_batch); gl_state_active_bind_texture_2d(0, tex->tex); - gl_state_active_bind_texture_2d(1, rctx_ptr->post_process.rend_texture.depth_texture->tex); + gl_state_active_bind_texture_2d(1, rctx_ptr->post_process.rend_texture.GetDepthTex()); gl_state_bind_vertex_array(snow_vao); uniform_value[U_SNOW_PARTICLE] = 0; @@ -4111,8 +4111,8 @@ static void draw_ripple_emit(render_context* rctx, struc_101* data) { RenderTexture& rt = rctx->render_manager.get_render_texture( ripple_emit_data->use_float_ripplemap ? 2 : 5); - int32_t width = rt.color_texture->width; - int32_t height = rt.color_texture->height; + int32_t width = rt.GetWidth(); + int32_t height = rt.GetHeight(); ripple_emit_scene_shader_data shader_data = {}; shader_data.g_size_in_projection = { @@ -5129,7 +5129,7 @@ static void sub_1403B6ED0(RenderTexture* a1, RenderTexture* a2, RenderTexture* a uniform_value[U_RIPPLE] = 1; else uniform_value[U_RIPPLE] = 0; - sub_1403B6F60(a1->color_texture->tex, a2->color_texture->tex, a3->color_texture->tex, params); + sub_1403B6F60(a1->GetColorTex(), a2->GetColorTex(), a3->GetColorTex(), params); gl_state_bind_framebuffer(0); }