Browse Source

better implementation of set_one_shot()

David Rose 14 years ago
parent
commit
e91fb0d53e

+ 0 - 39
panda/src/display/graphicsOutput.I

@@ -299,45 +299,6 @@ is_valid() const {
   return _is_valid;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::set_one_shot
-//       Access: Published
-//  Description: Changes the current setting of the one-shot flag.
-//               When this is true, the GraphicsOutput will render one
-//               frame and then automatically set itself inactive.
-//               This is particularly useful for buffers that are
-//               created for the purposes of render-to-texture, for
-//               static textures that don't need to be continually
-//               re-rendered once they have been rendered the first
-//               time.
-//
-//               Setting the buffer inactive is not the same thing as
-//               destroying it.  You are still responsible for passing
-//               this buffer to GraphicsEngine::remove_window() when
-//               you no longer need the texture, in order to clean up
-//               fully.  (However, you should not call remove_window()
-//               on this buffer while the texture is still needed,
-//               because depending on the render-to-texture mechanism
-//               in use, this may invalidate the texture contents.)
-////////////////////////////////////////////////////////////////////
-INLINE void GraphicsOutput::
-set_one_shot(bool one_shot) {
-  _one_shot = one_shot;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::get_one_shot
-//       Access: Published
-//  Description: Returns the current setting of the one-shot flag.
-//               When this is true, the GraphicsOutput will
-//               automatically set itself inactive after the next
-//               frame.
-////////////////////////////////////////////////////////////////////
-INLINE bool GraphicsOutput::
-get_one_shot() const {
-  return _one_shot;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::get_inverted
 //       Access: Published

+ 54 - 1
panda/src/display/graphicsOutput.cxx

@@ -104,7 +104,6 @@ GraphicsOutput(GraphicsEngine *engine, GraphicsPipe *pipe,
   _child_sort = 0;
   _got_child_sort = false;
   _internal_sort_index = 0;
-  _one_shot = false;
   _inverted = window_inverted;
   _red_blue_stereo = false;
   _left_eye_color_mask = 0x0f;
@@ -447,9 +446,61 @@ is_active() const {
   }
 
   CDReader cdata(_cycler);
+  if (cdata->_one_shot_frame != -1) {
+    // If one_shot is in effect, then we are active only for the one
+    // indicated frame.
+    if (cdata->_one_shot_frame != ClockObject::get_global_clock()->get_frame_count()) {
+      return false;
+    }
+  }
   return cdata->_active;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsOutput::set_one_shot
+//       Access: Published
+//  Description: Changes the current setting of the one-shot flag.
+//               When this is true, the GraphicsOutput will render the
+//               current frame and then automatically set itself
+//               inactive.  This is particularly useful for buffers
+//               that are created for the purposes of
+//               render-to-texture, for static textures that don't
+//               need to be continually re-rendered once they have
+//               been rendered the first time.
+//
+//               Setting the buffer inactive is not the same thing as
+//               destroying it.  You are still responsible for passing
+//               this buffer to GraphicsEngine::remove_window() when
+//               you no longer need the texture, in order to clean up
+//               fully.  (However, you should not call remove_window()
+//               on this buffer while the texture is still needed,
+//               because depending on the render-to-texture mechanism
+//               in use, this may invalidate the texture contents.)
+////////////////////////////////////////////////////////////////////
+void GraphicsOutput::
+set_one_shot(bool one_shot) {
+  CDWriter cdata(_cycler, true);
+  if (one_shot) {
+    cdata->_one_shot_frame = ClockObject::get_global_clock()->get_frame_count();
+  } else {
+    cdata->_one_shot_frame = -1;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsOutput::get_one_shot
+//       Access: Published
+//  Description: Returns the current setting of the one-shot flag.
+//               When this is true, the GraphicsOutput will
+//               automatically set itself inactive after the next
+//               frame.
+////////////////////////////////////////////////////////////////////
+bool GraphicsOutput::
+get_one_shot() const {
+  CDReader cdata(_cycler);
+  return (cdata->_one_shot_frame == ClockObject::get_global_clock()->get_frame_count());
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::set_inverted
 //       Access: Published
@@ -1669,6 +1720,7 @@ CData() {
   // initially populated with inactive outputs.  Pipeline stage 0 is
   // set to active in the constructor.
   _active = false;
+  _one_shot_frame = -1;
   _active_display_regions_stale = false;
 }
 
@@ -1681,6 +1733,7 @@ GraphicsOutput::CData::
 CData(const GraphicsOutput::CData &copy) :
   _textures(copy._textures),
   _active(copy._active),
+  _one_shot_frame(copy._one_shot_frame),
   _active_display_regions(copy._active_display_regions),
   _active_display_regions_stale(copy._active_display_regions_stale)
 {

+ 3 - 3
panda/src/display/graphicsOutput.h

@@ -127,8 +127,8 @@ PUBLISHED:
   void set_active(bool active);
   virtual bool is_active() const;
 
-  INLINE void set_one_shot(bool one_shot);
-  INLINE bool get_one_shot() const;
+  void set_one_shot(bool one_shot);
+  bool get_one_shot() const;
 
   void set_inverted(bool inverted);
   INLINE bool get_inverted() const;
@@ -303,7 +303,6 @@ private:
   unsigned int _internal_sort_index;
 
 protected:
-  bool _one_shot;
   bool _inverted;
   bool _red_blue_stereo;
   unsigned int _left_eye_color_mask;
@@ -342,6 +341,7 @@ protected:
 
     RenderTextures _textures;
     bool _active;
+    int _one_shot_frame;
     ActiveDisplayRegions _active_display_regions;
     bool _active_display_regions_stale;
   };

+ 0 - 3
panda/src/display/parasiteBuffer.cxx

@@ -188,9 +188,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
   if (mode == FM_render) {
     promote_to_copy_texture();
     copy_to_textures();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/dxgsg8/wdxGraphicsBuffer8.cxx

@@ -150,9 +150,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
     restore_bitplanes();
   }

+ 0 - 3
panda/src/dxgsg8/wdxGraphicsWindow8.cxx

@@ -123,9 +123,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/dxgsg9/wdxGraphicsBuffer9.cxx

@@ -172,9 +172,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
     restore_bitplanes();
   }

+ 0 - 3
panda/src/dxgsg9/wdxGraphicsWindow9.cxx

@@ -141,9 +141,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/egldisplay/eglGraphicsBuffer.cxx

@@ -125,9 +125,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/egldisplay/eglGraphicsPixmap.cxx

@@ -130,9 +130,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/egldisplay/eglGraphicsWindow.cxx

@@ -207,9 +207,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -924,9 +924,6 @@ void CLP(GraphicsBuffer)::end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
   report_my_gl_errors();

+ 0 - 3
panda/src/glxdisplay/glxGraphicsBuffer.cxx

@@ -125,9 +125,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/glxdisplay/glxGraphicsPixmap.cxx

@@ -128,9 +128,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 4 - 0
panda/src/grutil/multitexReducer.cxx

@@ -276,7 +276,11 @@ flatten(GraphicsOutput *window) {
 
     GraphicsOutput *buffer = window->make_texture_buffer
       (multitex_name_strm.str(), x_size, y_size, NULL, false);
+
+    // TODO: this no longer automatically deletes the buffer.  We need
+    // to take care of this explicitly now.
     buffer->set_one_shot(true);
+
     Texture *tex = buffer->get_texture();
     tex->set_anisotropic_degree(aniso_degree);
     tex->set_minfilter(minfilter);

+ 0 - 3
panda/src/mesadisplay/osMesaGraphicsBuffer.cxx

@@ -102,9 +102,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/osxdisplay/osxGraphicsBuffer.cxx

@@ -125,9 +125,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/tinydisplay/tinyGraphicsBuffer.cxx

@@ -95,9 +95,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 1 - 4
panda/src/tinydisplay/tinyOsxGraphicsWindow.mm

@@ -673,10 +673,7 @@ void TinyOsxGraphicsWindow::end_frame(FrameMode mode, Thread *current_thread) {
     copy_to_textures();
 
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
-    clear_cube_map_selection();
+   clear_cube_map_selection();
   }
 }
 

+ 0 - 3
panda/src/tinydisplay/tinySDLGraphicsWindow.cxx

@@ -107,9 +107,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
   }
 }
 

+ 0 - 3
panda/src/tinydisplay/tinyWinGraphicsWindow.cxx

@@ -103,9 +103,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/tinydisplay/tinyXGraphicsWindow.cxx

@@ -135,9 +135,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/wgldisplay/wglGraphicsBuffer.cxx

@@ -130,9 +130,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
   
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/wgldisplay/wglGraphicsWindow.cxx

@@ -106,9 +106,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }

+ 0 - 3
panda/src/x11display/x11GraphicsWindow.cxx

@@ -226,9 +226,6 @@ end_frame(FrameMode mode, Thread *current_thread) {
 
   if (mode == FM_render) {
     trigger_flip();
-    if (_one_shot) {
-      prepare_for_deletion();
-    }
     clear_cube_map_selection();
   }
 }