From 0a4633cf81b4f117bfd1d8de5d7b62571200e4d0 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Mon, 3 Mar 2008 22:45:06 +0000 Subject: [PATCH] Fixed a bug in copy_to_texture for depth buffers --- panda/src/display/drawableRegion.cxx | 30 +++++++++++++++++++ panda/src/display/drawableRegion.h | 2 ++ panda/src/display/graphicsOutput.cxx | 9 ++++-- .../glstuff/glGraphicsStateGuardian_src.cxx | 7 ++++- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/panda/src/display/drawableRegion.cxx b/panda/src/display/drawableRegion.cxx index 605109eb7e..032387b6d2 100644 --- a/panda/src/display/drawableRegion.cxx +++ b/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; + }; +} diff --git a/panda/src/display/drawableRegion.h b/panda/src/display/drawableRegion.h index 342295c819..1c33c18763 100644 --- a/panda/src/display/drawableRegion.h +++ b/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; diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 632b62ad65..0c0d3f7602 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/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, diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 2821d443a5..2f841a64e4 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/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;