소스 검색

Work on issues related to resizing buffers

Josh Yelon 18 년 전
부모
커밋
b3b365c99e

+ 18 - 0
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

+ 1 - 0
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();

+ 5 - 4
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;

+ 18 - 0
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

+ 1 - 0
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);

+ 8 - 1
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);
   }

+ 27 - 0
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())&&

+ 11 - 6
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,

+ 26 - 1
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())&&

+ 1 - 0
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;
     }
     

+ 2 - 0
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)) {

+ 1 - 0
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)) {

+ 2 - 0
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;

+ 3 - 10
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);
   }

+ 1 - 0
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)||