Skip to content

Commit

Permalink
library: fix DrawArrays handling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamcake committed Nov 30, 2024
1 parent baad1cb commit 12db295
Showing 1 changed file with 57 additions and 59 deletions.
116 changes: 57 additions & 59 deletions src/library/gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 12db295

Please sign in to comment.