From b3b365c99e44ec65af82b5a15ef63b113ffe88f0 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 28 Feb 2008 23:16:13 +0000 Subject: [PATCH] Work on issues related to resizing buffers --- panda/src/display/graphicsBuffer.cxx | 18 +++++++++++++ panda/src/display/graphicsBuffer.h | 1 + panda/src/display/graphicsPipe.h | 9 ++++--- panda/src/display/parasiteBuffer.cxx | 18 +++++++++++++ panda/src/display/parasiteBuffer.h | 1 + panda/src/dxgsg8/wdxGraphicsBuffer8.cxx | 9 ++++++- panda/src/dxgsg8/wdxGraphicsPipe8.cxx | 27 ++++++++++++++++++++ panda/src/dxgsg9/wdxGraphicsBuffer9.cxx | 17 +++++++----- panda/src/dxgsg9/wdxGraphicsPipe9.cxx | 27 +++++++++++++++++++- panda/src/glstuff/glGraphicsBuffer_src.cxx | 1 + panda/src/glxdisplay/glxGraphicsPipe.cxx | 2 ++ panda/src/mesadisplay/osMesaGraphicsPipe.cxx | 1 + panda/src/osxdisplay/osxGraphicsPipe.cxx | 2 ++ panda/src/wgldisplay/wglGraphicsBuffer.cxx | 13 +++------- panda/src/wgldisplay/wglGraphicsPipe.cxx | 1 + 15 files changed, 125 insertions(+), 22 deletions(-) diff --git a/panda/src/display/graphicsBuffer.cxx b/panda/src/display/graphicsBuffer.cxx index 8a7b517bea..f4c927ca41 100644 --- a/panda/src/display/graphicsBuffer.cxx +++ b/panda/src/display/graphicsBuffer.cxx @@ -58,6 +58,24 @@ GraphicsBuffer:: ~GraphicsBuffer() { } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsBuffer::set_size +// Access: Public, Virtual +// Description: This is called by the GraphicsEngine to request that +// the buffer resize itself. Although calls to get the +// size will return the new value, much of the actual +// resizing work doesn't take place until the next +// begin_frame. Not all buffers are resizeable. +//////////////////////////////////////////////////////////////////// +void GraphicsBuffer:: +set_size(int x, int y) { + if ((_creation_flags & GraphicsPipe::BF_resizeable) == 0) { + nassert_raise("Cannot resize buffer unless it is created with BF_resizeable flag"); + return; + } + set_size_and_recalc(x, y); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsBuffer::request_open // Access: Public, Virtual diff --git a/panda/src/display/graphicsBuffer.h b/panda/src/display/graphicsBuffer.h index f843587d3d..12b00f6cb0 100644 --- a/panda/src/display/graphicsBuffer.h +++ b/panda/src/display/graphicsBuffer.h @@ -43,6 +43,7 @@ protected: PUBLISHED: virtual ~GraphicsBuffer(); + void set_size(int x, int y); public: virtual void request_open(); diff --git a/panda/src/display/graphicsPipe.h b/panda/src/display/graphicsPipe.h index 342729fb18..96d86da5a8 100644 --- a/panda/src/display/graphicsPipe.h +++ b/panda/src/display/graphicsPipe.h @@ -84,10 +84,11 @@ PUBLISHED: // Miscellaneous control flags. BF_can_bind_color = 0x0040, // Need capability: bind the color bitplane to a tex. BF_can_bind_every = 0x0080, // Need capability: bind all bitplanes to a tex. - BF_size_track_host = 0x0100, // Buffer should track the host size. - BF_rtt_cumulative = 0x0200, // Buffer supports cumulative render-to-texture. - BF_fb_props_optional = 0x0400, // FrameBufferProperties can be ignored. - BF_size_square = 0x0800, // x_size must equal y_size (e.g. for cube maps) + BF_resizeable = 0x0100, // Buffer should allow set_size. + BF_size_track_host = 0x0200, // Buffer should track the host size. + BF_rtt_cumulative = 0x0400, // Buffer supports cumulative render-to-texture. + BF_fb_props_optional = 0x0800, // FrameBufferProperties can be ignored. + BF_size_square = 0x1000, // x_size must equal y_size (e.g. for cube maps) }; INLINE bool is_valid() const; diff --git a/panda/src/display/parasiteBuffer.cxx b/panda/src/display/parasiteBuffer.cxx index cc829ffc29..32887cabcd 100644 --- a/panda/src/display/parasiteBuffer.cxx +++ b/panda/src/display/parasiteBuffer.cxx @@ -73,6 +73,24 @@ ParasiteBuffer:: _is_valid = false; } +//////////////////////////////////////////////////////////////////// +// Function: ParasiteBuffer::set_size +// Access: Public, Virtual +// Description: This is called by the GraphicsEngine to request that +// the buffer resize itself. Although calls to get the +// size will return the new value, much of the actual +// resizing work doesn't take place until the next +// begin_frame. Not all buffers are resizeable. +//////////////////////////////////////////////////////////////////// +void ParasiteBuffer:: +set_size(int x, int y) { + if ((_creation_flags & GraphicsPipe::BF_resizeable) == 0) { + nassert_raise("Cannot resize buffer unless it is created with BF_resizeable flag"); + return; + } + set_size_and_recalc(x, y); +} + //////////////////////////////////////////////////////////////////// // Function: ParasiteBuffer::is_active // Access: Published, Virtual diff --git a/panda/src/display/parasiteBuffer.h b/panda/src/display/parasiteBuffer.h index 0c9db334a4..29dd470fc7 100644 --- a/panda/src/display/parasiteBuffer.h +++ b/panda/src/display/parasiteBuffer.h @@ -61,6 +61,7 @@ PUBLISHED: virtual ~ParasiteBuffer(); virtual bool is_active() const; + void set_size(int x, int y); public: virtual bool begin_frame(FrameMode mode, Thread *current_thread); diff --git a/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx b/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx index 942768ff7b..6db6b82f98 100644 --- a/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx +++ b/panda/src/dxgsg8/wdxGraphicsBuffer8.cxx @@ -226,9 +226,16 @@ rebuild_bitplanes() { // Decide how big the bitplanes should be. + if ((_host != 0)&&(_creation_flags & GraphicsPipe::BF_size_track_host)) { + if ((_host->get_x_size() != _x_size)|| + (_host->get_y_size() != _y_size)) { + set_size_and_recalc(_host->get_x_size(), + _host->get_y_size()); + } + } int bitplane_x = _x_size; int bitplane_y = _y_size; - if (!_gsg->get_supports_tex_non_pow2()) { + if (Texture::get_textures_power_2() != ATS_none) { bitplane_x = Texture::up_to_power_2(bitplane_x); bitplane_y = Texture::up_to_power_2(bitplane_y); } diff --git a/panda/src/dxgsg8/wdxGraphicsPipe8.cxx b/panda/src/dxgsg8/wdxGraphicsPipe8.cxx index de38560968..1f5935d326 100644 --- a/panda/src/dxgsg8/wdxGraphicsPipe8.cxx +++ b/panda/src/dxgsg8/wdxGraphicsPipe8.cxx @@ -109,12 +109,22 @@ make_output(const string &name, if (retry == 0) { if (((flags&BF_require_parasite)!=0)|| ((flags&BF_refuse_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_rtt_cumulative)!=0)|| ((flags&BF_can_bind_color)!=0)|| ((flags&BF_can_bind_every)!=0)) { return NULL; } + // Early failure - if we are sure that this buffer WONT + // meet specs, we can bail out early. + if ((flags & BF_fb_props_optional) == 0) { + if ((fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_float() > 0)) { + return NULL; + } + } return new wdxGraphicsWindow8(this, name, fb_prop, win_prop, flags, gsg, host); } @@ -125,11 +135,28 @@ make_output(const string &name, if ((!support_render_texture)|| ((flags&BF_require_parasite)!=0)|| ((flags&BF_require_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_rtt_cumulative)!=0)|| ((flags&BF_can_bind_every)!=0)) { return NULL; } + // Early failure - if we are sure that this buffer WONT + // meet specs, we can bail out early. + if ((flags & BF_fb_props_optional) == 0) { + if ((fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_float() > 0)|| + (fb_prop.get_indexed_color() > 0)|| + (fb_prop.get_back_buffers() > 0)|| + (fb_prop.get_accum_bits() > 0)|| + (fb_prop.get_multisamples() > 0)) { + return NULL; + } + } + // Early success - if we are sure that this buffer WILL + // meet specs, we can precertify it. + // This looks rather overly optimistic -- ie, buggy. if ((gsg != 0)&& (gsg->is_valid())&& (!gsg->needs_reset())&& diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx index 13953a486f..6bdfad57de 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx @@ -247,13 +247,20 @@ rebuild_bitplanes() { // Decide how big the bitplanes should be. + if ((_host != 0)&&(_creation_flags & GraphicsPipe::BF_size_track_host)) { + if ((_host->get_x_size() != _x_size)|| + (_host->get_y_size() != _y_size)) { + set_size_and_recalc(_host->get_x_size(), + _host->get_y_size()); + } + } int bitplane_x = _x_size; int bitplane_y = _y_size; - if (!_gsg->get_supports_tex_non_pow2()) { + if (Texture::get_textures_power_2() != ATS_none) { bitplane_x = Texture::up_to_power_2(bitplane_x); bitplane_y = Texture::up_to_power_2(bitplane_y); } - + // Find the color and depth textures. Either may be present, // or neither. // @@ -297,8 +304,7 @@ rebuild_bitplanes() { _color_backing_store = NULL; } color_tex = get_texture(color_tex_index); - color_tex->set_x_size(bitplane_x); - color_tex->set_y_size(bitplane_y); + color_tex->set_size_padded(_x_size, _y_size); color_tex->set_format(Texture::F_rgba); color_ctx = DCAST(DXTextureContext9, @@ -370,8 +376,7 @@ rebuild_bitplanes() { depth_tex = get_texture(depth_tex_index); } - depth_tex->set_x_size(bitplane_x); - depth_tex->set_y_size(bitplane_y); + depth_tex->set_size_padded(_x_size, _y_size); depth_tex->set_format(Texture::F_depth_stencil); depth_ctx = DCAST(DXTextureContext9, diff --git a/panda/src/dxgsg9/wdxGraphicsPipe9.cxx b/panda/src/dxgsg9/wdxGraphicsPipe9.cxx index 36376bc5b9..bd9e834951 100755 --- a/panda/src/dxgsg9/wdxGraphicsPipe9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsPipe9.cxx @@ -109,12 +109,22 @@ make_output(const string &name, if (retry == 0) { if (((flags&BF_require_parasite)!=0)|| ((flags&BF_refuse_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_rtt_cumulative)!=0)|| ((flags&BF_can_bind_color)!=0)|| ((flags&BF_can_bind_every)!=0)) { return NULL; } + // Early failure - if we are sure that this buffer WONT + // meet specs, we can bail out early. + if ((flags & BF_fb_props_optional) == 0) { + if ((fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_float() > 0)) { + return NULL; + } + } return new wdxGraphicsWindow9(this, name, fb_prop, win_prop, flags, gsg, host); } @@ -125,11 +135,26 @@ make_output(const string &name, if ((!support_render_texture)|| ((flags&BF_require_parasite)!=0)|| ((flags&BF_require_window)!=0)|| - ((flags&BF_size_track_host)!=0)|| ((flags&BF_rtt_cumulative)!=0)|| ((flags&BF_can_bind_every)!=0)) { return NULL; } + // Early failure - if we are sure that this buffer WONT + // meet specs, we can bail out early. + if ((flags & BF_fb_props_optional) == 0) { + if ((fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_rgba() > 0)|| + (fb_prop.get_aux_float() > 0)|| + (fb_prop.get_indexed_color() > 0)|| + (fb_prop.get_back_buffers() > 0)|| + (fb_prop.get_accum_bits() > 0)|| + (fb_prop.get_multisamples() > 0)) { + return NULL; + } + } + // Early success - if we are sure that this buffer WILL + // meet specs, we can precertify it. + // This looks rather overly optimistic -- ie, buggy. if ((gsg != 0)&& (gsg->is_valid())&& (!gsg->needs_reset())&& diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index a7378f5426..c02f4b1e81 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx @@ -306,6 +306,7 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta if ((_tex[slot] == tex)&& (tex->get_x_size() == _rb_size_x)&& (tex->get_y_size() == _rb_size_y)) { + tex->set_pad_size(_rb_size_x - _x_size, _rb_size_y - _y_size); return; } diff --git a/panda/src/glxdisplay/glxGraphicsPipe.cxx b/panda/src/glxdisplay/glxGraphicsPipe.cxx index c7ace37df1..c67c7492cf 100644 --- a/panda/src/glxdisplay/glxGraphicsPipe.cxx +++ b/panda/src/glxdisplay/glxGraphicsPipe.cxx @@ -232,6 +232,7 @@ make_output(const string &name, if (retry == 0) { if (((flags&BF_require_parasite)!=0)|| ((flags&BF_refuse_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_rtt_cumulative)!=0)|| ((flags&BF_can_bind_color)!=0)|| @@ -283,6 +284,7 @@ make_output(const string &name, if ((!support_rtt)|| ((flags&BF_require_parasite)!=0)|| ((flags&BF_require_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_rtt_cumulative)!=0)|| ((flags&BF_can_bind_every)!=0)) { diff --git a/panda/src/mesadisplay/osMesaGraphicsPipe.cxx b/panda/src/mesadisplay/osMesaGraphicsPipe.cxx index 105e3b4c2b..1ee05d7882 100644 --- a/panda/src/mesadisplay/osMesaGraphicsPipe.cxx +++ b/panda/src/mesadisplay/osMesaGraphicsPipe.cxx @@ -95,6 +95,7 @@ make_output(const string &name, if ((!support_render_texture)|| ((flags&BF_require_parasite)!=0)|| ((flags&BF_require_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_can_bind_every)!=0)|| ((flags&BF_rtt_cumulative)!=0)) { diff --git a/panda/src/osxdisplay/osxGraphicsPipe.cxx b/panda/src/osxdisplay/osxGraphicsPipe.cxx index b362d1fbb0..4a3cb1f1e6 100644 --- a/panda/src/osxdisplay/osxGraphicsPipe.cxx +++ b/panda/src/osxdisplay/osxGraphicsPipe.cxx @@ -230,6 +230,7 @@ make_output(const string &name, if (retry == 0) { if (((flags&BF_require_parasite)!=0)|| ((flags&BF_refuse_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_can_bind_color)!=0)|| ((flags&BF_can_bind_every)!=0)) { @@ -261,6 +262,7 @@ make_output(const string &name, if ((!support_render_texture)|| ((flags&BF_require_parasite)!=0)|| ((flags&BF_require_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_can_bind_every)!=0)) { return NULL; diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.cxx b/panda/src/wgldisplay/wglGraphicsBuffer.cxx index 4cd189c401..70fadfe153 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.cxx +++ b/panda/src/wgldisplay/wglGraphicsBuffer.cxx @@ -162,14 +162,7 @@ bind_texture_to_pbuffer() { _pbuffer_bound->release(wglgsg->get_prepared_objects()); _pbuffer_bound = 0; } - int tex_x = _x_size; - int tex_y = _y_size; - if (!wglgsg->get_supports_tex_non_pow2()) { - tex_x = Texture::up_to_power_2(tex_x); - tex_y = Texture::up_to_power_2(tex_y); - } - tex->set_x_size(tex_x); - tex->set_y_size(tex_y); + tex->set_size_padded(_x_size, _y_size); if (tex->get_match_framebuffer_format()) { if (_fb_properties.get_alpha_bits()) { tex->set_format(Texture::F_rgba); @@ -421,7 +414,7 @@ rebuild_bitplanes() { // Determine what pbuffer attributes are needed // for currently-applicable textures. - if (_creation_flags & GraphicsPipe::BF_size_track_host) { + if ((_host != 0)&&(_creation_flags & GraphicsPipe::BF_size_track_host)) { if ((_host->get_x_size() != _x_size)|| (_host->get_y_size() != _y_size)) { set_size_and_recalc(_host->get_x_size(), @@ -430,7 +423,7 @@ rebuild_bitplanes() { } int desired_x = _x_size; int desired_y = _y_size; - if ((bindtexture != 0)&&(!wglgsg->get_supports_tex_non_pow2())) { + if ((bindtexture != 0)&&(Texture::get_textures_power_2() != ATS_none)) { desired_x = Texture::up_to_power_2(desired_x); desired_y = Texture::up_to_power_2(desired_y); } diff --git a/panda/src/wgldisplay/wglGraphicsPipe.cxx b/panda/src/wgldisplay/wglGraphicsPipe.cxx index 34853a6dab..7cc08c56cb 100644 --- a/panda/src/wgldisplay/wglGraphicsPipe.cxx +++ b/panda/src/wgldisplay/wglGraphicsPipe.cxx @@ -138,6 +138,7 @@ make_output(const string &name, if (retry == 0) { if (((flags&BF_require_parasite)!=0)|| ((flags&BF_refuse_window)!=0)|| + ((flags&BF_resizeable)!=0)|| ((flags&BF_size_track_host)!=0)|| ((flags&BF_rtt_cumulative)!=0)|| ((flags&BF_can_bind_color)!=0)||