Browse Source

glgsg: Save a buffer bind call by changing order of blitting MS FBOs

rdb 3 years ago
parent
commit
4bdac5afac
1 changed files with 18 additions and 25 deletions
  1. 18 25
      panda/src/glstuff/glGraphicsBuffer_src.cxx

+ 18 - 25
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -2005,27 +2005,7 @@ resolve_multisamples() {
     }
     }
   }
   }
 
 
-#ifndef OPENGLES
-  if (_have_any_color) {
-    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
-    glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
-  } else {
-    glDrawBuffer(GL_NONE);
-    glReadBuffer(GL_NONE);
-  }
-#endif
-
-  if (do_depth_blit) {
-    glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
-                              GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
-                              GL_NEAREST);
-  }
-  else if (_have_any_color) {
-    glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
-                              GL_COLOR_BUFFER_BIT,
-                              GL_NEAREST);
-  }
-  // Now handle the other color buffers.
+  // First handle the auxiliary buffers.
 #ifndef OPENGLES
 #ifndef OPENGLES
   int next = GL_COLOR_ATTACHMENT1_EXT;
   int next = GL_COLOR_ATTACHMENT1_EXT;
   if (_fb_properties.is_stereo()) {
   if (_fb_properties.is_stereo()) {
@@ -2057,11 +2037,9 @@ resolve_multisamples() {
     next += 1;
     next += 1;
   }
   }
 #endif
 #endif
-  report_my_gl_errors();
-
-  // Bind the regular FBO as read buffer for the sake of copy_to_textures.
-  glgsg->_glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fbo);
 
 
+  // Now blit the normal color target, plus any depth/stencil.
+  // We do this last because we want to leave attachment 0 bound at the end.
 #ifndef OPENGLES
 #ifndef OPENGLES
   if (_have_any_color) {
   if (_have_any_color) {
     glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
     glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
@@ -2071,5 +2049,20 @@ resolve_multisamples() {
     glReadBuffer(GL_NONE);
     glReadBuffer(GL_NONE);
   }
   }
 #endif
 #endif
+
+  if (do_depth_blit) {
+    glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
+                              GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
+                              GL_NEAREST);
+  }
+  else if (_have_any_color) {
+    glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
+                              GL_COLOR_BUFFER_BIT,
+                              GL_NEAREST);
+  }
+
+  // Bind the regular FBO as read buffer for the sake of copy_to_textures.
+  glgsg->_glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fbo);
+
   report_my_gl_errors();
   report_my_gl_errors();
 }
 }