Browse Source

Added RTM_triggered_copy_texture

Josh Yelon 20 years ago
parent
commit
2c09657017

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

@@ -241,6 +241,18 @@ get_sort() const {
   return _sort;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsOutput::trigger_copy
+//       Access: Published
+//  Description: When the GraphicsOutput is in triggered copy mode,
+//               this function triggers the copy (at the end of the
+//               next frame).
+////////////////////////////////////////////////////////////////////
+INLINE void GraphicsOutput::
+trigger_copy()  {
+  _trigger_copy = true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::make_display_region
 //       Access: Published

+ 30 - 13
panda/src/display/graphicsOutput.cxx

@@ -92,6 +92,7 @@ GraphicsOutput(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
   _inverted = window_inverted;
   _delete_flag = false;
   _texture_card = 0;
+  _trigger_copy = false;
 
   int mode = gsg->get_properties().get_frame_buffer_mode();
   if ((mode & FrameBufferProperties::FM_buffer) == FrameBufferProperties::FM_single_buffer) {
@@ -219,17 +220,13 @@ GraphicsOutput::
 //               render-to-a-texture mode.
 ////////////////////////////////////////////////////////////////////
 void GraphicsOutput::
-setup_render_texture(Texture *tex, bool allow_bind, bool to_ram) {
+setup_render_texture(Texture *tex, RenderTextureMode mode) {
+  if (mode == RTM_none) {
+    return;
+  }
   MutexHolder holder(_lock);
+  _rtm_mode = mode;
 
-  if (to_ram) {
-    _rtm_mode = RTM_copy_ram;
-  } else if (allow_bind) {
-    _rtm_mode = RTM_bind_or_copy;
-  } else {
-    _rtm_mode = RTM_copy_texture;
-  }
-  
   if (tex == (Texture *)NULL) {
     _texture = new Texture(get_name());
     _texture->set_wrap_u(Texture::WM_clamp);
@@ -250,6 +247,22 @@ setup_render_texture(Texture *tex, bool allow_bind, bool to_ram) {
   set_inverted(_gsg->get_copy_texture_inverted());
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsOutput::setup_render_texture
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+void GraphicsOutput::
+setup_render_texture(Texture *tex, bool allow_bind, bool to_ram) {
+  if (to_ram) {
+    setup_render_texture(tex, RTM_copy_ram);
+  } else if (allow_bind) {
+    setup_render_texture(tex, RTM_bind_or_copy);
+  } else {
+    setup_render_texture(tex, RTM_copy_texture);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::set_active
 //       Access: Published
@@ -912,7 +925,7 @@ begin_frame() {
 
   // Okay, we already have a GSG, so activate it.
   make_current();
-
+  
   if (_rtm_mode == RTM_bind_or_copy) {
     // Release the texture so we can render into the frame buffer.
     _gsg->framebuffer_release_texture(this, get_texture());
@@ -991,7 +1004,11 @@ end_frame() {
       }
     }
     
-    if (_rtm_mode == RTM_copy_texture) {
+    if ((_rtm_mode == RTM_copy_texture)||
+        (_rtm_mode == RTM_copy_ram)||
+        ((_rtm_mode == RTM_triggered_copy_texture)&&(_trigger_copy))||
+        ((_rtm_mode == RTM_triggered_copy_ram)&&(_trigger_copy))) {
+      _trigger_copy = false;
       if (display_cat.is_debug()) {
         display_cat.debug()
           << "Copying texture for " << get_name() << " at frame end.\n";
@@ -1000,7 +1017,7 @@ end_frame() {
       }
       RenderBuffer buffer = _gsg->get_render_buffer(get_draw_buffer_type());
       if (_cube_map_dr != (DisplayRegion *)NULL) {
-        if (_rtm_mode == RTM_copy_ram) {
+        if ((_rtm_mode == RTM_copy_ram)||(_rtm_mode == RTM_triggered_copy_ram)) {
           _gsg->framebuffer_copy_to_ram(get_texture(), _cube_map_index,
                                         _cube_map_dr, buffer);
         } else {
@@ -1008,7 +1025,7 @@ end_frame() {
                                             _cube_map_dr, buffer);
         }
       } else {
-        if (_rtm_mode == RTM_copy_ram) {
+        if ((_rtm_mode == RTM_copy_ram)||(_rtm_mode == RTM_triggered_copy_ram)) {
           _gsg->framebuffer_copy_to_ram(get_texture(), _cube_map_index,
                                         _default_display_region, buffer);
         } else {

+ 15 - 8
panda/src/display/graphicsOutput.h

@@ -69,6 +69,15 @@ private:
   void operator = (const GraphicsOutput &copy);
 
 PUBLISHED:
+  enum RenderTextureMode {
+    RTM_none,
+    RTM_bind_or_copy,
+    RTM_copy_texture,
+    RTM_copy_ram,
+    RTM_triggered_copy_texture,
+    RTM_triggered_copy_ram,
+  };
+
   virtual ~GraphicsOutput();
 
   INLINE GraphicsStateGuardian *get_gsg() const;
@@ -77,8 +86,9 @@ PUBLISHED:
 
   INLINE bool has_texture() const;  
   INLINE Texture *get_texture() const;  
+  void setup_render_texture(Texture *tex, RenderTextureMode mode);
   void setup_render_texture(Texture *tex, bool allow_bind, bool to_ram);
-
+  
   INLINE int get_x_size() const;
   INLINE int get_y_size() const;
   INLINE bool has_size() const;
@@ -99,6 +109,8 @@ PUBLISHED:
   void set_sort(int sort);
   INLINE int get_sort() const;
 
+  INLINE void trigger_copy();
+  
   INLINE DisplayRegion *make_display_region();
   INLINE DisplayRegion *make_display_region(float l, float r,
                                             float b, float t);
@@ -169,12 +181,6 @@ public:
   virtual void process_events();
   
 protected:
-  enum RenderTextureMode {
-    RTM_none,
-    RTM_bind_or_copy,
-    RTM_copy_texture,
-    RTM_copy_ram,
-  };
 
   PT(GraphicsStateGuardian) _gsg;
   PT(GraphicsPipe) _pipe;
@@ -186,7 +192,8 @@ protected:
   int _cube_map_index;
   DisplayRegion *_cube_map_dr;
   PT(Geom) _texture_card;
-
+  bool _trigger_copy;
+  
 private:
   DisplayRegion *add_display_region(DisplayRegion *display_region);