Advertisement
Tkap1

Untitled

Apr 10th, 2022
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. for(int i = 0; i < game->available_maps_count; i++)
  2. {
  3.     char* map_path = format_text("assets/%s", game->available_maps[i]);
  4.     s_map map = load_map(&game->client_rng, map_path, &arenas->frame_arena);
  5.  
  6.     rendering->map_thumbnail_fbo[i].width = (int)c_base_window_size.x;
  7.     rendering->map_thumbnail_fbo[i].height = (int)c_base_window_size.y;
  8.  
  9.     // This doesn't call gl funcs  
  10.     draw_map(&map, rendering, 0, false);
  11.  
  12.     gl(glGenFramebuffers(1, &rendering->map_thumbnail_fbo[i].fbo));
  13.     gl(glBindFramebuffer(GL_FRAMEBUFFER, rendering->map_thumbnail_fbo[i].fbo));
  14.  
  15.     gl(glGenTextures(1, &rendering->map_thumbnail_fbo[i].color[0]));
  16.     gl(glBindTexture(GL_TEXTURE_2D, rendering->map_thumbnail_fbo[i].color[0]));
  17.     gl(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rendering->map_thumbnail_fbo[i].width, rendering->map_thumbnail_fbo[i].height, 0, GL_RGBA, GL_FLOAT, NULL));
  18.     gl(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
  19.     gl(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
  20.     // gl(glBindTexture(GL_TEXTURE_2D, 0));
  21.  
  22.     gl(glGenTextures(1, &rendering->map_thumbnail_fbo[i].depth));
  23.     gl(glBindTexture(GL_TEXTURE_2D, rendering->map_thumbnail_fbo[i].depth));
  24.     gl(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, rendering->map_thumbnail_fbo[i].width, rendering->map_thumbnail_fbo[i].height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL));
  25.     // gl(glBindTexture(GL_TEXTURE_2D, 0));
  26.  
  27.     gl(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rendering->map_thumbnail_fbo[i].color[0], 0));
  28.     gl(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rendering->map_thumbnail_fbo[i].depth, 0));
  29.  
  30.     if(!(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE))
  31.     {
  32.         assert(false);
  33.     }
  34.  
  35.     gl(glViewport(0, 0, rendering->map_thumbnail_fbo[i].width, rendering->map_thumbnail_fbo[i].height));
  36.     gl(glEnable(GL_DEPTH_TEST));
  37.     gl(glClearColor(1, 0.0f, 1, 0.0f));
  38.     gl(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
  39.    
  40.     // This calls `glBufferSubdata` and `glDrawArraysInstanced`
  41.     solid_render_pass(0, rendering->view, rendering->projection, rendering->meshes, rendering->textures, rendering->shaders);
  42.  
  43.     rendering->textures[e_texture_map_thumbnail_000 + i].id = rendering->map_thumbnail_fbo[i].color[0];
  44.     rendering->textures[e_texture_map_thumbnail_000 + i].w = rendering->map_thumbnail_fbo[i].width;
  45.     rendering->textures[e_texture_map_thumbnail_000 + i].h = rendering->map_thumbnail_fbo[i].height;
  46.  
  47.     gl(glBindFramebuffer(GL_FRAMEBUFFER, 0));
  48.  
  49.     // @Hack(tkap): This prevents "delete_framebuffer" from deleting the texture. We want to keep the texture to draw it as a map thumbnail
  50.     rendering->map_thumbnail_fbo[i].color[0] = 0;
  51.  
  52.     delete_framebuffer(&rendering->map_thumbnail_fbo[i]);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement