From 664bc3435294655655b658a7cd14f993b38c32a2 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Mon, 27 Nov 2023 22:24:28 +0300 Subject: [PATCH] Adapt new findings --- src/CRE/draw_object.cpp | 12 +-- src/CRE/render_context.cpp | 153 +++++++++++++++++++------------------ src/CRE/render_context.hpp | 18 ++--- src/CRE/render_manager.cpp | 15 ++-- src/CRE/sprite.cpp | 6 +- 5 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/CRE/draw_object.cpp b/src/CRE/draw_object.cpp index 16b0ec22..f3252760 100644 --- a/src/CRE/draw_object.cpp +++ b/src/CRE/draw_object.cpp @@ -485,8 +485,8 @@ namespace mdl { wrap_t = 0; texture* tex = texture_storage_get_texture(::texture_id(0, texture_id)); - gl_state_bind_sampler(tex_index, rctx->render_manager.samplers[(wrap_t * 3 - + wrap_s) * 2 + (tex->max_mipmap_level > 0 ? 1 : 0)]); + gl_state_bind_sampler(tex_index, rctx->samplers[(wrap_t * 3 + wrap_s) * 2 + + (tex->max_mipmap_level > 0 ? 1 : 0)]); } } @@ -746,8 +746,8 @@ static void draw_object_material_set_default(render_context* rctx, const mdl::Ob wrap_t = 0; texture* tex = texture_storage_get_texture(::texture_id(0, texture_id)); - gl_state_bind_sampler(tex_index, rctx->render_manager.samplers[(wrap_t * 3 - + wrap_s) * 2 + (tex->max_mipmap_level > 0 ? 1 : 0)]); + gl_state_bind_sampler(tex_index, rctx->samplers[(wrap_t * 3 + wrap_s) * 2 + + (tex->max_mipmap_level > 0 ? 1 : 0)]); } if (material->material.shader.index == SHADER_FT_SKY) { @@ -948,8 +948,8 @@ static void draw_object_material_set_reflect(render_context* rctx, const mdl::Ob wrap_t = 0; texture* tex = texture_storage_get_texture(::texture_id(0, texture_id)); - gl_state_bind_sampler(i, rctx->render_manager.samplers[(wrap_t * 3 - + wrap_s) * 2 + (tex->max_mipmap_level > 0 ? 1 : 0)]); + gl_state_bind_sampler(i, rctx->samplers[(wrap_t * 3 + wrap_s) * 2 + + (tex->max_mipmap_level > 0 ? 1 : 0)]); } vec4 ambient; diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index 7ac57d13..718188a9 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -113,10 +113,10 @@ sss_data::~sss_data() { } draw_state::draw_state() : wireframe(), wireframe_overlay(), light(), self_shadow(), -field_45(), use_global_material(), fog_height(), ex_data_mat(), field_68() { +shader_debug_flag(), use_global_material(), fog_height(), ex_data_mat(), field_68() { shader = true; shader_index = -1; - field_50 = -1; + show = -1; bump_depth = 1.0f; intensity = 1.0f; reflectivity = 1.0f; @@ -458,7 +458,7 @@ namespace mdl { culling(), show_alpha_center(), show_mat_center(), texture_pattern_count(), texture_pattern_array(), wet_param(), texture_transform_count(), texture_transform_array(), material_list_count(), material_list_array() { - field_230 = -1; + put_index = -1; object_culling = true; object_sort = true; chara_color = true; @@ -3379,10 +3379,10 @@ namespace mdl { namespace rndr { RenderManager::RenderManager() : pass_sw(), reflect_blur_num(), reflect_blur_filter(), sync_gpu(), - cpu_time(), gpu_time(), time(), draw_pass_3d(), show_ref_map(), reflect_type(), clear(), tex_index(), - multisample_framebuffer(), multisample_renderbuffer(), multisample(), show_vector_flags(), - show_vector_length(), show_vector_z_offset(), field_2F8(), effect_texture(), npr_param(), - field_31C(), field_31D(), field_31E(), field_31F(), field_320(), npr(), samplers(), sprite_samplers() { + cpu_time(), gpu_time(), time(), draw_pass_3d(), show_ref_map(), reflect_type(), clear(), + tex_index(), multisample_framebuffer(), multisample_renderbuffer(), multisample(), + show_vector_flags(), show_vector_length(), show_vector_z_offset(), field_2F8(), effect_texture(), + npr_param(), field_31C(), field_31D(), field_31E(), field_31F(), field_320(), npr() { for (bool& i : pass_sw) i = true; @@ -3416,76 +3416,9 @@ namespace rndr { } gl_state_bind_framebuffer(0); - static const vec4 border_color = 0.0f; - - glGenSamplers(18, samplers); - for (int32_t i = 0; i < 18; i++) { - GLuint sampler = samplers[i]; - - glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); - glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, - i % 2 ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); - glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); - - GLuint wrap_s; - switch (i / 2 % 3) { - case 0: - wrap_s = GL_CLAMP_TO_EDGE; - break; - case 1: - wrap_s = GL_REPEAT; - break; - case 2: - wrap_s = GL_MIRRORED_REPEAT; - break; - } - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, wrap_s); - - GLenum wrap_t; - switch (i / 6 % 3) { - case 0: - wrap_t = GL_CLAMP_TO_EDGE; - break; - case 1: - wrap_t = GL_REPEAT; - break; - case 2: - wrap_t = GL_MIRRORED_REPEAT; - break; - } - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, wrap_t); - } - - GLuint sampler; - glGenSamplers(3, sprite_samplers); - sampler = sprite_samplers[0]; - glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); - - sampler = sprite_samplers[1]; - glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT); - glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); - - sampler = sprite_samplers[2]; - glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); - glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); } RenderManager::~RenderManager() { - glDeleteSamplers(3, sprite_samplers); - glDeleteSamplers(18, samplers); - if (multisample_framebuffer) { glDeleteFramebuffers(1, &multisample_framebuffer); multisample_framebuffer = 0; @@ -3717,8 +3650,8 @@ void obj_batch_shader_data::set_transforms(const mat4& model, const mat4& view, g_transforms[3] = temp.row3; } -render_context::render_context() : litproj(), chara_reflect(), chara_refract(), view_mat(), -matrix_buffer(), box_vao(), box_vbo(), empty_texture_2d(), empty_texture_cube_map() { +render_context::render_context() : litproj(), chara_reflect(), chara_refract(), view_mat(), matrix_buffer(), +box_vao(), box_vbo(), empty_texture_2d(), empty_texture_cube_map(), samplers(), sprite_samplers() { camera = new ::camera; static const float_t box_texcoords[] = { @@ -3819,9 +3752,77 @@ matrix_buffer(), box_vao(), box_vbo(), empty_texture_2d(), empty_texture_cube_ma glCompressedTexImage2D(target_cube_map_array[side], 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 0, 8, empty_texture_data); gl_state_bind_texture_cube_map(0); + + static const vec4 border_color = 0.0f; + + glGenSamplers(18, samplers); + for (int32_t i = 0; i < 18; i++) { + GLuint sampler = samplers[i]; + + glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); + glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, + i % 2 ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); + glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); + + GLuint wrap_s; + switch (i / 2 % 3) { + case 0: + wrap_s = GL_CLAMP_TO_EDGE; + break; + case 1: + wrap_s = GL_REPEAT; + break; + case 2: + wrap_s = GL_MIRRORED_REPEAT; + break; + } + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, wrap_s); + + GLenum wrap_t; + switch (i / 6 % 3) { + case 0: + wrap_t = GL_CLAMP_TO_EDGE; + break; + case 1: + wrap_t = GL_REPEAT; + break; + case 2: + wrap_t = GL_MIRRORED_REPEAT; + break; + } + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, wrap_t); + } + + GLuint sampler; + glGenSamplers(3, sprite_samplers); + sampler = sprite_samplers[0]; + glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); + + sampler = sprite_samplers[1]; + glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT); + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT); + glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); + + sampler = sprite_samplers[2]; + glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); + glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); } render_context::~render_context() { + glDeleteSamplers(3, sprite_samplers); + glDeleteSamplers(18, samplers); + glDeleteTextures(1, &empty_texture_cube_map); glDeleteTextures(1, &empty_texture_2d); diff --git a/src/CRE/render_context.hpp b/src/CRE/render_context.hpp index 611455c2..6d7f877b 100644 --- a/src/CRE/render_context.hpp +++ b/src/CRE/render_context.hpp @@ -205,13 +205,13 @@ struct draw_state { bool wireframe_overlay; bool light; bool self_shadow; - bool field_45; + bool shader_debug_flag; bool use_global_material; bool fog_height; bool ex_data_mat; bool shader; int32_t shader_index; - int32_t field_50; + int32_t show; float_t bump_depth; float_t intensity; float_t reflectivity; @@ -541,16 +541,15 @@ namespace mdl { int32_t field_C; std::vector obj[mdl::OBJ_TYPE_MAX]; mdl::CullingCheck culling; - mat4 culling_mat; - int32_t field_230; + int32_t put_index; bool show_alpha_center; bool show_mat_center; bool object_culling; bool object_sort; bool chara_color; - int32_t buff_size; - int32_t buff_max; int32_t buff_offset; + int32_t buff_max; + int32_t buff_size; void* buff; morph_struct morph; int32_t texture_pattern_count; @@ -673,8 +672,6 @@ namespace rndr { bool field_320; bool npr; sss_data sss_data; - GLuint samplers[18]; - GLuint sprite_samplers[3]; RenderManager(); ~RenderManager(); @@ -913,8 +910,6 @@ struct render_context { GL::UniformBuffer imgfilter_batch_ubo; GL::UniformBuffer glass_eye_batch_ubo; GL::UniformBuffer quad_ubo; - GL::UniformBuffer ripple_ubo; - GL::UniformBuffer ripple_emit_ubo; GL::UniformBuffer sprite_scene_ubo; GL::UniformBuffer sss_filter_gaussian_coef_ubo; GL::UniformBuffer transparency_batch_ubo; @@ -929,6 +924,9 @@ struct render_context { GLuint empty_texture_2d; GLuint empty_texture_cube_map; + GLuint samplers[18]; + GLuint sprite_samplers[3]; + render_context(); ~render_context(); diff --git a/src/CRE/render_manager.cpp b/src/CRE/render_manager.cpp index 28ebafc5..772c96cb 100644 --- a/src/CRE/render_manager.cpp +++ b/src/CRE/render_manager.cpp @@ -19,8 +19,6 @@ #include "task_effect.hpp" #include "texture.hpp" -static void blur_filter_apply(render_context* rctx, GLuint tex_0, GLuint tex_1, - blur_filter_mode filter, const vec2 res_scale, const vec4 scale, const vec4 offset); static void draw_pass_shadow_begin_make_shadowmap(render_context* rctx, Shadow* shad, int32_t index, int32_t a3); static void draw_pass_shadow_end_make_shadowmap(render_context* rctx, @@ -43,8 +41,8 @@ static int32_t draw_pass_3d_translucent_count_layers(render_context* rctx, mdl::ObjType transparent, mdl::ObjType translucent); static void draw_pass_3d_translucent_has_objects(render_context* rctx, bool* arr, mdl::ObjType type); -extern bool draw_grid_3d; -extern void draw_pass_3d_grid(render_context* rctx); +static void blur_filter_apply(render_context* rctx, GLuint tex_0, GLuint tex_1, + blur_filter_mode filter, const vec2 res_scale, const vec4 scale, const vec4 offset); extern light_param_data_storage* light_param_data_storage_data; @@ -495,14 +493,14 @@ namespace rndr { pp->set_render_texture(); if (sprite_manager_get_reqlist_count(2)) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClearDepth(1.0f); + glClearDepthf(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl_state_bind_framebuffer(0); } else { vec4 clear_color = get_clear_color(); glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); - glClearDepth(1.0f); + glClearDepthf(1.0f); if (clear) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); else @@ -616,8 +614,11 @@ namespace rndr { Glitter::glt_particle_manager->DispScenes(Glitter::DISP_OPAQUE); - if (draw_grid_3d) + extern bool draw_grid_3d; + if (draw_grid_3d) { + extern void draw_pass_3d_grid(render_context * rctx); draw_pass_3d_grid(rctx); + } gl_state_enable_depth_test(); gl_state_set_depth_mask(GL_TRUE); diff --git a/src/CRE/sprite.cpp b/src/CRE/sprite.cpp index b004956a..521e36a5 100644 --- a/src/CRE/sprite.cpp +++ b/src/CRE/sprite.cpp @@ -1665,11 +1665,11 @@ namespace spr { break; case 1: draw_param.texture[0] = tex_param[0].texture->tex; - draw_param.sampler = rctx->render_manager.sprite_samplers[0]; + draw_param.sampler = rctx->sprite_samplers[0]; if (args.num_vertex) { if (args.kind == SPR_KIND_TRIANGLE) - draw_param.sampler = rctx->render_manager.sprite_samplers[1]; + draw_param.sampler = rctx->sprite_samplers[1]; if (args.kind == SPR_KIND_TRIANGLE) { draw_param.mode = GL_TRIANGLE_STRIP; @@ -1809,7 +1809,7 @@ namespace spr { draw_param.texture[0] = tex_param[0].texture->tex; draw_param.texture[1] = tex_param[1].texture->tex; - draw_param.sampler = rctx->render_manager.sprite_samplers[2]; + draw_param.sampler = rctx->sprite_samplers[2]; sprite_draw_vertex spr_vtx[4] = {}; spr_vtx[0].pos = vtx[0];