From 12db295a8f3e720d215012db5050cba7014f3ba7 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 30 Nov 2024 20:26:04 +0000 Subject: [PATCH] library: fix DrawArrays handling bug --- src/library/gl.c | 116 +++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/src/library/gl.c b/src/library/gl.c index 64580f7..f7f597c 100644 --- a/src/library/gl.c +++ b/src/library/gl.c @@ -1654,65 +1654,63 @@ hunt strategy is as follows: */ void _bolt_gl_onDrawArrays(GLenum mode, GLint first, GLsizei count) { struct GLContext* c = _bolt_context(); - if (c->current_draw_framebuffer) { - GLint target_tex_id; - gl.GetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &target_tex_id); - struct GLTexture2D* target_tex = _bolt_context_get_texture(c, target_tex_id); - - if (c->bound_program->is_minimap && target_tex->width == GAME_MINIMAP_BIG_SIZE && target_tex->height == GAME_MINIMAP_BIG_SIZE) { - GLint ubo_binding, ubo_view_index; - gl.GetActiveUniformBlockiv(c->bound_program->id, c->bound_program->block_index_ViewTransforms, GL_UNIFORM_BLOCK_BINDING, &ubo_binding); - gl.GetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, (GLuint)ubo_binding, &ubo_view_index); - const float* camera_position = (float*)((uint8_t*)(_bolt_context_get_buffer(c, ubo_view_index)->data) + c->bound_program->offset_uCameraPosition); - target_tex->is_minimap_tex_big = 1; - target_tex->minimap_center_x = camera_position[0]; - target_tex->minimap_center_y = camera_position[2]; - } else if (mode == GL_TRIANGLE_STRIP && count == 4) { - if (c->bound_program->loc_sSceneHDRTex != -1) { - GLint source_tex_unit; - gl.GetUniformiv(c->bound_program->id, c->bound_program->loc_sSceneHDRTex, &source_tex_unit); - struct GLTexture2D* source_tex = c->texture_units[source_tex_unit]; - if (c->current_draw_framebuffer == 0 && c->game_view_sSceneHDRTex != source_tex->id) { - c->game_view_sSceneHDRTex = source_tex->id; - c->target_3d_tex = c->game_view_sSceneHDRTex; - c->game_view_x = 0; - c->game_view_y = 0; - c->game_view_w = source_tex->width; - c->game_view_h = source_tex->height; - c->recalculate_sSceneHDRTex = false; - c->does_blit_3d_target = false; - c->depth_of_field_enabled = false; - printf("new direct sSceneHDRTex %i\n", c->target_3d_tex); - } else if (c->recalculate_sSceneHDRTex && !c->depth_of_field_enabled && (c->game_view_part_framebuffer == c->current_draw_framebuffer || c->game_view_sSourceTex == target_tex_id)) { - c->game_view_sSceneHDRTex = source_tex->id; - c->target_3d_tex = c->game_view_sSceneHDRTex; - c->game_view_w = source_tex->width; - c->game_view_h = source_tex->height; - c->recalculate_sSceneHDRTex = false; - printf("new sSceneHDRTex %i\n", c->target_3d_tex); - } - } else if (c->bound_program->loc_sSourceTex != -1) { - GLint source_tex_unit; - gl.GetUniformiv(c->bound_program->id, c->bound_program->loc_sSourceTex, &source_tex_unit); - struct GLTexture2D* source_tex = c->texture_units[source_tex_unit]; - if (c->bound_program->loc_sBlurFarTex != -1) { - if (c->depth_of_field_enabled || c->game_view_sSceneHDRTex != target_tex->id) return; - c->depth_of_field_sSourceTex = source_tex->id; - c->depth_of_field_enabled = true; - printf("new depth-of-field sSourceTex %i...\n", c->depth_of_field_sSourceTex); - } else if (c->current_draw_framebuffer == 0 && c->game_view_sSourceTex != source_tex->id) { - c->game_view_sSceneHDRTex = -1; - c->game_view_sSourceTex = source_tex->id; - c->does_blit_3d_target = false; - c->depth_of_field_enabled = false; - c->game_view_x = 0; - c->game_view_y = 0; - c->recalculate_sSceneHDRTex = true; - printf("new direct sSourceTex %i...\n", c->game_view_sSourceTex); - } else if (c->recalculate_sSceneHDRTex && c->game_view_part_framebuffer == c->current_draw_framebuffer) { - c->game_view_sSourceTex = source_tex->id; - printf("new sSourceTex %i...\n", c->game_view_sSourceTex); - } + GLint target_tex_id; + gl.GetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &target_tex_id); + struct GLTexture2D* target_tex = _bolt_context_get_texture(c, target_tex_id); + + if (c->current_draw_framebuffer && c->bound_program->is_minimap && target_tex->width == GAME_MINIMAP_BIG_SIZE && target_tex->height == GAME_MINIMAP_BIG_SIZE) { + GLint ubo_binding, ubo_view_index; + gl.GetActiveUniformBlockiv(c->bound_program->id, c->bound_program->block_index_ViewTransforms, GL_UNIFORM_BLOCK_BINDING, &ubo_binding); + gl.GetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, (GLuint)ubo_binding, &ubo_view_index); + const float* camera_position = (float*)((uint8_t*)(_bolt_context_get_buffer(c, ubo_view_index)->data) + c->bound_program->offset_uCameraPosition); + target_tex->is_minimap_tex_big = 1; + target_tex->minimap_center_x = camera_position[0]; + target_tex->minimap_center_y = camera_position[2]; + } else if (mode == GL_TRIANGLE_STRIP && count == 4) { + if (c->bound_program->loc_sSceneHDRTex != -1) { + GLint source_tex_unit; + gl.GetUniformiv(c->bound_program->id, c->bound_program->loc_sSceneHDRTex, &source_tex_unit); + struct GLTexture2D* source_tex = c->texture_units[source_tex_unit]; + if (c->current_draw_framebuffer == 0 && c->game_view_sSceneHDRTex != source_tex->id) { + c->game_view_sSceneHDRTex = source_tex->id; + c->target_3d_tex = c->game_view_sSceneHDRTex; + c->game_view_x = 0; + c->game_view_y = 0; + c->game_view_w = source_tex->width; + c->game_view_h = source_tex->height; + c->recalculate_sSceneHDRTex = false; + c->does_blit_3d_target = false; + c->depth_of_field_enabled = false; + printf("new direct sSceneHDRTex %i\n", c->target_3d_tex); + } else if (c->recalculate_sSceneHDRTex && !c->depth_of_field_enabled && (c->game_view_part_framebuffer == c->current_draw_framebuffer || c->game_view_sSourceTex == target_tex_id)) { + c->game_view_sSceneHDRTex = source_tex->id; + c->target_3d_tex = c->game_view_sSceneHDRTex; + c->game_view_w = source_tex->width; + c->game_view_h = source_tex->height; + c->recalculate_sSceneHDRTex = false; + printf("new sSceneHDRTex %i\n", c->target_3d_tex); + } + } else if (c->bound_program->loc_sSourceTex != -1) { + GLint source_tex_unit; + gl.GetUniformiv(c->bound_program->id, c->bound_program->loc_sSourceTex, &source_tex_unit); + struct GLTexture2D* source_tex = c->texture_units[source_tex_unit]; + if (c->current_draw_framebuffer && c->bound_program->loc_sBlurFarTex != -1) { + if (c->depth_of_field_enabled || c->game_view_sSceneHDRTex != target_tex_id) return; + c->depth_of_field_sSourceTex = source_tex->id; + c->depth_of_field_enabled = true; + printf("new depth-of-field sSourceTex %i...\n", c->depth_of_field_sSourceTex); + } else if (c->current_draw_framebuffer == 0 && c->game_view_sSourceTex != source_tex->id) { + c->game_view_sSceneHDRTex = -1; + c->game_view_sSourceTex = source_tex->id; + c->does_blit_3d_target = false; + c->depth_of_field_enabled = false; + c->game_view_x = 0; + c->game_view_y = 0; + c->recalculate_sSceneHDRTex = true; + printf("new direct sSourceTex %i...\n", c->game_view_sSourceTex); + } else if (c->recalculate_sSceneHDRTex && c->game_view_part_framebuffer == c->current_draw_framebuffer) { + c->game_view_sSourceTex = source_tex->id; + printf("new sSourceTex %i...\n", c->game_view_sSourceTex); } } }