Browse Source

Fixed a bug in copy_to_texture for depth buffers

Josh Yelon 18 years ago
parent
commit
0a4633cf81

+ 30 - 0
panda/src/display/drawableRegion.cxx

@@ -27,3 +27,33 @@
 DrawableRegion::
 ~DrawableRegion() {
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: DrawableRegion::get_renderbuffer_type
+//       Access: Static, Published
+//  Description: Returns the RenderBuffer::Type that corresponds
+//               to a RenderTexturePlane.
+////////////////////////////////////////////////////////////////////
+int DrawableRegion::
+get_renderbuffer_type(int rtp) {
+  switch(rtp) {
+  case RTP_stencil:        return RenderBuffer::T_stencil;
+  case RTP_depth:          return RenderBuffer::T_depth;
+  case RTP_color:          return RenderBuffer::T_color;
+  case RTP_aux_rgba_0:     return RenderBuffer::T_aux_rgba_0;
+  case RTP_aux_rgba_1:     return RenderBuffer::T_aux_rgba_1;
+  case RTP_aux_rgba_2:     return RenderBuffer::T_aux_rgba_2;
+  case RTP_aux_rgba_3:     return RenderBuffer::T_aux_rgba_3;
+  case RTP_aux_hrgba_0:    return RenderBuffer::T_aux_hrgba_0;
+  case RTP_aux_hrgba_1:    return RenderBuffer::T_aux_hrgba_1;
+  case RTP_aux_hrgba_2:    return RenderBuffer::T_aux_hrgba_2;
+  case RTP_aux_hrgba_3:    return RenderBuffer::T_aux_hrgba_3;
+  case RTP_aux_float_0:    return RenderBuffer::T_aux_float_0;
+  case RTP_aux_float_1:    return RenderBuffer::T_aux_float_1;
+  case RTP_aux_float_2:    return RenderBuffer::T_aux_float_2;
+  case RTP_aux_float_3:    return RenderBuffer::T_aux_float_3;
+  default:
+    display_cat.error() << "DrawableRegion::get_renderbuffer_type unexpected case!\n";
+    return 0;
+  };
+}

+ 2 - 0
panda/src/display/drawableRegion.h

@@ -95,6 +95,8 @@ PUBLISHED:
 
   INLINE bool is_any_clear_active() const;
 
+  static int get_renderbuffer_type(int plane);
+  
 public:
   INLINE int get_screenshot_buffer_type() const;
   INLINE int get_draw_buffer_type() const;

+ 7 - 2
panda/src/display/graphicsOutput.cxx

@@ -1007,8 +1007,13 @@ copy_to_textures() {
         display_cat.debug()
           << "cube_map_index = " << _cube_map_index << "\n";
       }
-      RenderBuffer buffer = _gsg->get_render_buffer(get_draw_buffer_type(),
-                                                    get_fb_properties());
+      int plane = get_texture_plane(i);
+      RenderBuffer buffer(_gsg, DrawableRegion::get_renderbuffer_type(plane));
+      if (plane == RTP_color) {
+        buffer = _gsg->get_render_buffer(get_draw_buffer_type(),
+                                         get_fb_properties());
+      }
+      
       if (_cube_map_dr != (DisplayRegion *)NULL) {
         if ((rtm_mode == RTM_copy_ram)||(rtm_mode == RTM_triggered_copy_ram)) {
           _gsg->framebuffer_copy_to_ram(texture, _cube_map_index,

+ 6 - 1
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -3426,7 +3426,7 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr,
                             const RenderBuffer &rb) {
   nassertv(tex != NULL && dr != NULL);
   set_read_buffer(rb._buffer_type);
-
+  
   int xo, yo, w, h;
   dr->get_region_pixels(xo, yo, w, h);
   tex->set_size_padded(w, h);
@@ -4800,6 +4800,11 @@ set_draw_buffer(int rbtype) {
 void CLP(GraphicsStateGuardian)::
 set_read_buffer(int rbtype) {
 
+  if (rbtype & (RenderBuffer::T_depth | RenderBuffer::T_stencil)) {
+    // Special case: don't have to call ReadBuffer for these.
+    return;
+  }
+
   if (_current_fbo) {
 
     GLuint buffer = GL_COLOR_ATTACHMENT0_EXT;