Bladeren bron

begin_frame refactor

Josh Yelon 20 jaren geleden
bovenliggende
commit
cee838c08e

+ 8 - 4
panda/src/display/displayRegion.cxx

@@ -549,20 +549,24 @@ get_screenshot(PNMImage &image) {
   GraphicsStateGuardian *gsg = window->get_gsg();
   nassertr(gsg != (GraphicsStateGuardian *)NULL, false);
   
-  window->make_current();
+  if (!window->begin_frame(GraphicsOutput::FM_refresh)) {
+    return false;
+  }
 
   // Create a temporary texture to receive the framebuffer image.
   PT(Texture) tex = new Texture;
-
+  
   RenderBuffer buffer = gsg->get_render_buffer(get_screenshot_buffer_type());
   if (!gsg->framebuffer_copy_to_ram(tex, -1, this, buffer)) {
     return false;
   }
-
+  
+  window->end_frame(GraphicsOutput::FM_refresh);
+  
   if (!tex->store(image)) {
     return false;
   }
-
+  
   return true;
 }
 

+ 6 - 6
panda/src/display/graphicsEngine.cxx

@@ -790,7 +790,7 @@ cull_and_draw_together(const GraphicsEngine::Windows &wlist) {
   for (wi = wlist.begin(); wi != wlist.end(); ++wi) {
     GraphicsOutput *win = (*wi);
     if (win->is_active() && win->get_gsg()->is_active()) {
-      if (win->begin_frame()) {
+      if (win->begin_frame(GraphicsOutput::FM_render)) {
         win->clear();
       
         int num_display_regions = win->get_num_active_display_regions();
@@ -800,7 +800,7 @@ cull_and_draw_together(const GraphicsEngine::Windows &wlist) {
             cull_and_draw_together(win, dr);
           }
         }
-        win->end_frame();
+        win->end_frame(GraphicsOutput::FM_render);
 
         if (_auto_flip) {
           if (win->flip_ready()) {
@@ -864,7 +864,7 @@ cull_bin_draw(const GraphicsEngine::Windows &wlist) {
     GraphicsOutput *win = (*wi);
     if (win->is_active() && win->get_gsg()->is_active()) {
       // This should be done in the draw thread, not here.
-      if (win->begin_frame()) {
+      if (win->begin_frame(GraphicsOutput::FM_render)) {
         win->clear();
       
         int num_display_regions = win->get_num_active_display_regions();
@@ -874,7 +874,7 @@ cull_bin_draw(const GraphicsEngine::Windows &wlist) {
             cull_bin_draw(win, dr);
           }
         }
-        win->end_frame();
+        win->end_frame(GraphicsOutput::FM_render);
 
         if (_auto_flip) {
           if (win->flip_ready()) {
@@ -940,8 +940,8 @@ make_contexts(const GraphicsEngine::Windows &wlist) {
   Windows::const_iterator wi;
   for (wi = wlist.begin(); wi != wlist.end(); ++wi) {
     GraphicsOutput *win = (*wi);
-    if (win->needs_context()) {
-      win->make_context();
+    if (win->begin_frame(GraphicsOutput::FM_refresh)) {
+      win->end_frame(GraphicsOutput::FM_refresh);
     }
   }
 }

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

@@ -372,17 +372,6 @@ flip_ready() const {
   return _flip_ready;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::needs_context
-//       Access: Public
-//  Description: Returns true if make_context() still needs to be
-//               called, false otherwise.
-////////////////////////////////////////////////////////////////////
-INLINE bool GraphicsOutput::
-needs_context() const {
-  return _needs_context;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::operator <
 //       Access: Public

+ 2 - 72
panda/src/display/graphicsOutput.cxx

@@ -81,7 +81,6 @@ GraphicsOutput(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
   _has_size = false;
   _is_valid = false;
   _flip_ready = false;
-  _needs_context = true;
   _cube_map_index = -1;
   _cube_map_dr = NULL;
   _sort = 0;
@@ -961,7 +960,7 @@ reset_window(bool swapchain) {
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool GraphicsOutput::
-begin_frame() {
+begin_frame(FrameMode mode) {
   return false;
 }
 
@@ -973,7 +972,7 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void GraphicsOutput::
-end_frame() {
+end_frame(FrameMode mode) {
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -1090,37 +1089,6 @@ copy_to_textures() {
   _trigger_copy = false;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::begin_render_texture
-//       Access: Public, Virtual
-//  Description: If the GraphicsOutput supports direct render-to-texture,
-//               and if any setup needs to be done during begin_frame,
-//               then the setup code should go here.  Any textures that
-//               can not be rendered to directly should be reflagged
-//               as RTM_copy_texture.
-////////////////////////////////////////////////////////////////////
-void GraphicsOutput::
-begin_render_texture() {
-  for (int i=0; i<count_textures(); i++) {
-    if (get_rtm_mode(i) == RTM_bind_or_copy) {
-      _textures[i]._rtm_mode = RTM_copy_texture;
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::end_render_texture
-//       Access: Public, Virtual
-//  Description: If the GraphicsOutput supports direct render-to-texture,
-//               and if any setup needs to be done during end_frame,
-//               then the setup code should go here.  Any textures that
-//               could not be rendered to directly should be reflagged
-//               as RTM_copy_texture.
-////////////////////////////////////////////////////////////////////
-void GraphicsOutput::
-end_render_texture() {
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::change_scenes
 //       Access: Public
@@ -1188,33 +1156,6 @@ void GraphicsOutput::
 select_cube_map(int) {
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::make_context
-//       Access: Public, Virtual
-//  Description: If _needs_context is true, this will be called
-//               in the draw thread prior to rendering into the
-//               window.  It should attempt to create a graphics
-//               context, and return true if successful, false
-//               otherwise.  If it returns false the window will be
-//               considered failed.
-////////////////////////////////////////////////////////////////////
-bool GraphicsOutput::
-make_context() {
-  _needs_context = false;
-  return true;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::make_current
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               during begin_frame() to ensure the graphics context
-//               is ready for drawing.
-////////////////////////////////////////////////////////////////////
-void GraphicsOutput::
-make_current() {
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::release_gsg
 //       Access: Public
@@ -1230,17 +1171,6 @@ release_gsg() {
   _active = false;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GraphicsOutput::auto_resize
-//       Access: Public, Virtual
-//  Description: Certain graphics outputs can automatically resize
-//               themselves to automatically stay the same size as
-//               some other graphics output.
-////////////////////////////////////////////////////////////////////
-void GraphicsOutput::
-auto_resize() {
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::begin_flip
 //       Access: Public, Virtual

+ 18 - 12
panda/src/display/graphicsOutput.h

@@ -78,6 +78,13 @@ PUBLISHED:
     RTM_triggered_copy_ram,
   };
 
+  // There are many reasons to call begin_frame/end_frame.
+  enum FrameMode {
+    FM_render,   // We are rendering a frame.
+    FM_parasite, // We are rendering a frame of a parasite.
+    FM_refresh,  // We are just refreshing the display or exposing the window.
+  };
+
   virtual ~GraphicsOutput();
 
   INLINE GraphicsStateGuardian *get_gsg() const;
@@ -142,7 +149,6 @@ PUBLISHED:
 
 public:
   // These are not intended to be called directly by the user.
-  INLINE bool needs_context() const;
   INLINE bool flip_ready() const;
 
   INLINE bool operator < (const GraphicsOutput &other) const;
@@ -161,21 +167,22 @@ public:
   // thread other than the draw thread.  These methods are normally
   // called by the GraphicsEngine.
   void clear();
-  virtual bool begin_frame();
-  virtual void end_frame();
-
-  virtual void begin_render_texture();
-  virtual void end_render_texture();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
+
+  // These entry points have been removed. Use begin_frame/end_frame instead.
+  //  virtual void begin_render_texture();
+  //  virtual void end_render_texture();
+  //  INLINE bool needs_context() const;
+  //  bool _needs_context;
+  //  virtual bool make_context();
+  //  virtual void make_current();
+  //  virtual void auto_resize();
 
   void change_scenes(DisplayRegion *new_dr);
   virtual void select_cube_map(int cube_map_index);
 
-  // This method is called in the draw thread prior to issuing any
-  // drawing commands for the window.
-  virtual bool make_context();
-  virtual void make_current();
   virtual void release_gsg();
-  virtual void auto_resize();
   
   // These methods will be called within the app (main) thread.
   virtual void begin_flip();
@@ -208,7 +215,6 @@ protected:
   string _name;
   pvector<RenderTexture> _textures;
   bool _flip_ready;
-  bool _needs_context;
   int _cube_map_index;
   DisplayRegion *_cube_map_dr;
   PT(Geom) _texture_card;

+ 24 - 45
panda/src/display/parasiteBuffer.cxx

@@ -106,21 +106,23 @@ get_host() {
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool ParasiteBuffer::
-begin_frame() {
+begin_frame(FrameMode mode) {
   begin_frame_spam();
-  if (_gsg == (GraphicsStateGuardian *)NULL) {
+
+  if (!_host->begin_frame(FM_parasite)) {
     return false;
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
+
+  if (_track_host_size) {
+    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());
     }
   }
-  make_current();
-  begin_render_texture();
+
   clear_cube_map_selection();
-  return _gsg->begin_frame();
+  return true;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -131,46 +133,23 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void ParasiteBuffer::
-end_frame() {
+end_frame(FrameMode mode) {
   end_frame_spam();
+
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
-  _gsg->end_frame();
-  end_render_texture();
-  copy_to_textures();
-  trigger_flip();
-  if (_one_shot) {
-    prepare_for_deletion();
-  }
-  clear_cube_map_selection();
-}
 
-////////////////////////////////////////////////////////////////////
-//     Function: ParasiteBuffer::make_current
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               during begin_frame() to ensure the graphics context
-//               is ready for drawing.
-////////////////////////////////////////////////////////////////////
-void ParasiteBuffer::
-make_current() {
-  _host->make_current();
-}
+  if (mode == FM_refresh) {
+    return;
+  }
 
-////////////////////////////////////////////////////////////////////
-//     Function: ParasiteBuffer::auto_resize
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               to make sure this buffer is the right size.  If not,
-//               it will be resized.
-////////////////////////////////////////////////////////////////////
-void ParasiteBuffer::
-auto_resize() {
-  if (_track_host_size) {
-    _host->auto_resize();
-    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());
+  _host->end_frame(FM_parasite);
+  
+  if (mode == FM_render) {
+    copy_to_textures();
+    if (_one_shot) {
+      prepare_for_deletion();
     }
+    clear_cube_map_selection();
   }
 }
+

+ 2 - 4
panda/src/display/parasiteBuffer.h

@@ -63,11 +63,9 @@ PUBLISHED:
   virtual bool is_active() const;
 
 public:
-  virtual bool begin_frame();
-  virtual void end_frame();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
   virtual GraphicsOutput *get_host();
-  virtual void make_current();
-  virtual void auto_resize();
   
 private:
   PT(GraphicsOutput) _host;

+ 24 - 35
panda/src/dxgsg8/wdxGraphicsBuffer8.cxx

@@ -80,20 +80,18 @@ wdxGraphicsBuffer8::
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsBuffer8::
-begin_frame() {
+begin_frame(FrameMode mode) {
+
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
+
+  if (mode == FM_render) {
+    begin_render_texture();
+    clear_cube_map_selection();
   }
-  make_current();
-  begin_render_texture();
-  clear_cube_map_selection();
+  
   return _gsg->begin_frame();
 }
 
@@ -105,22 +103,30 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void wdxGraphicsBuffer8::
-end_frame() {
+end_frame(FrameMode mode) {
+
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
+
+  if (mode == FM_render) {
+    end_render_texture();
+    copy_to_textures();
+  }
+
   _gsg->end_frame();
-  end_render_texture();
-  copy_to_textures();
-  trigger_flip();
-  if (_one_shot) {
-    prepare_for_deletion();
+
+  if (mode == FM_render) {
+    trigger_flip();
+    if (_one_shot) {
+      prepare_for_deletion();
+    }
+    clear_cube_map_selection();
   }
-  clear_cube_map_selection();
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsStateGuardian::begin_render_texture
-//       Access: Public, Virtual
+//       Access: Public
 //  Description: If the GraphicsOutput supports direct render-to-texture,
 //               and if any setup needs to be done during begin_frame,
 //               then the setup code should go here.  Any textures that
@@ -208,7 +214,7 @@ begin_render_texture() {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::end_render_texture
-//       Access: Public, Virtual
+//       Access: Public
 //  Description: If the GraphicsOutput supports direct render-to-texture,
 //               and if any setup needs to be done during end_frame,
 //               then the setup code should go here.  Any textures that
@@ -319,23 +325,6 @@ select_cube_map(int cube_map_index) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer8::make_current
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               during begin_frame() to ensure the graphics context
-//               is ready for drawing.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer8::
-make_current() {
-  PStatTimer timer(_make_current_pcollector);
-
-  DXGraphicsStateGuardian8 *dxgsg;
-  DCAST_INTO_V(dxgsg, _gsg);
-
-  // do nothing here
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsBuffer8::release_gsg
 //       Access: Public, Virtual

+ 5 - 7
panda/src/dxgsg8/wdxGraphicsBuffer8.h

@@ -41,16 +41,12 @@ public:
                     int x_size, int y_size);
   virtual ~wdxGraphicsBuffer8();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
+  
   virtual void select_cube_map(int cube_map_index);
-
-  virtual void make_current();
   virtual void release_gsg();
 
-  virtual void begin_render_texture();
-  virtual void end_render_texture();
-
   virtual void process_events();
 
 protected:
@@ -58,6 +54,8 @@ protected:
   virtual bool open_buffer();
 
 private:
+  void begin_render_texture();
+  void end_render_texture();
   static void process_1_event();
 
   int _cube_map_index;

+ 47 - 43
panda/src/dxgsg8/wdxGraphicsWindow8.cxx

@@ -63,32 +63,6 @@ wdxGraphicsWindow8::
 ~wdxGraphicsWindow8() {
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsWindow8::make_current
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsWindow8::
-make_current() {
-  PStatTimer timer(_make_current_pcollector);
-
-  DXGraphicsStateGuardian8 *dxgsg;
-  DCAST_INTO_V(dxgsg, _gsg);
-  dxgsg->set_context(&_wcontext);
-
-  // Now that we have made the context current to a window, we can
-  // reset the GSG state if this is the first time it has been used.
-  // (We can't just call reset() when we construct the GSG, because
-  // reset() requires having a current context.)
-  if (dxgsg->reset_if_new()) {
-    // We should also fill in the buffer mask at this time, which adds
-    // support for depth buffer or stencil buffer if the window
-    // supports it.  This assumes that the gsg will not be shared by
-    // other windows with a different buffer mask.
-    dxgsg->_buffer_mask |= _buffer_mask;
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsWindow8::begin_frame
 //       Access: Public, Virtual
@@ -99,11 +73,12 @@ make_current() {
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsWindow8::
-begin_frame() {
+begin_frame(FrameMode mode) {
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
   }
+  
   if (_awaiting_restore) {
     // The fullscreen window was recently restored; we can't continue
     // until the GSG says we can.
@@ -112,18 +87,15 @@ begin_frame() {
       return false;
     }
     _awaiting_restore = false;
-
     init_resized_window();
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
-  }
+
   make_current();
-  begin_render_texture();
-  clear_cube_map_selection();
+
+  if (mode == FM_render) {
+    clear_cube_map_selection();
+  }
+  
   bool return_val = _gsg->begin_frame();
   _dxgsg->set_render_target();
   return return_val;
@@ -137,17 +109,49 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void wdxGraphicsWindow8::
-end_frame() {
+end_frame(FrameMode mode) {
+
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
+
+  if (mode == FM_render) {
+    copy_to_textures();
+  }
+
   _gsg->end_frame();
-  end_render_texture();
-  copy_to_textures();
-  trigger_flip();
-  if (_one_shot) {
-    prepare_for_deletion();
+
+  if (mode == FM_render) {
+    trigger_flip();
+    if (_one_shot) {
+      prepare_for_deletion();
+    }
+    clear_cube_map_selection();
+  }
+}
+////////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsWindow8::make_current
+//       Access: Private
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void wdxGraphicsWindow8::
+make_current() {
+  PStatTimer timer(_make_current_pcollector);
+
+  DXGraphicsStateGuardian8 *dxgsg;
+  DCAST_INTO_V(dxgsg, _gsg);
+  dxgsg->set_context(&_wcontext);
+
+  // Now that we have made the context current to a window, we can
+  // reset the GSG state if this is the first time it has been used.
+  // (We can't just call reset() when we construct the GSG, because
+  // reset() requires having a current context.)
+  if (dxgsg->reset_if_new()) {
+    // We should also fill in the buffer mask at this time, which adds
+    // support for depth buffer or stencil buffer if the window
+    // supports it.  This assumes that the gsg will not be shared by
+    // other windows with a different buffer mask.
+    dxgsg->_buffer_mask |= _buffer_mask;
   }
-  clear_cube_map_selection();
 }
 
 ////////////////////////////////////////////////////////////////////

+ 3 - 3
panda/src/dxgsg8/wdxGraphicsWindow8.h

@@ -38,9 +38,8 @@ public:
                      const string &name);
   virtual ~wdxGraphicsWindow8();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
-  virtual void make_current();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
   virtual void end_flip();
 
   virtual int verify_window_sizes(int numsizes, int *dimen);
@@ -73,6 +72,7 @@ private:
 
   bool reset_device_resize_window(UINT new_xsize, UINT new_ysize);
   void init_resized_window();
+  void make_current();
   static int D3DFMT_to_DepthBits(D3DFORMAT fmt);
   static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER8 *pDevID);
 

+ 24 - 37
panda/src/dxgsg9/wdxGraphicsBuffer9.cxx

@@ -77,21 +77,19 @@ wdxGraphicsBuffer9::
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsBuffer9::
-begin_frame() {
+begin_frame(FrameMode mode) {
   DBG_S dxgsg9_cat.debug ( ) << "wdxGraphicsBuffer9::begin_frame\n"; DBG_E
+
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
+
+  if (mode == FM_render) {
+    begin_render_texture();
+    clear_cube_map_selection();
   }
-  make_current();
-  begin_render_texture();
-  clear_cube_map_selection();
+  
   return _gsg->begin_frame();
 }
 
@@ -103,22 +101,30 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void wdxGraphicsBuffer9::
-end_frame() {
+end_frame(FrameMode mode) {
+
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
+
+  if (mode == FM_render) {
+    end_render_texture();
+    copy_to_textures();
+  }
+
   _gsg->end_frame();
-  end_render_texture();
-  copy_to_textures();
-  trigger_flip();
-  if (_one_shot) {
-    prepare_for_deletion();
+
+  if (mode == FM_render) {
+    trigger_flip();
+    if (_one_shot) {
+      prepare_for_deletion();
+    }
+    clear_cube_map_selection();
   }
-  clear_cube_map_selection();
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsStateGuardian::begin_render_texture
-//       Access: Public, Virtual
+//       Access: Public
 //  Description: If the GraphicsOutput supports direct render-to-texture,
 //               and if any setup needs to be done during begin_frame,
 //               then the setup code should go here.  Any textures that
@@ -221,7 +227,7 @@ begin_render_texture() {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsOutput::end_render_texture
-//       Access: Public, Virtual
+//       Access: Public
 //  Description: If the GraphicsOutput supports direct render-to-texture,
 //               and if any setup needs to be done during end_frame,
 //               then the setup code should go here.  Any textures that
@@ -355,25 +361,6 @@ select_cube_map(int cube_map_index) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: wdxGraphicsBuffer9::make_current
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               during begin_frame() to ensure the graphics context
-//               is ready for drawing.
-////////////////////////////////////////////////////////////////////
-void wdxGraphicsBuffer9::
-make_current() {
-  PStatTimer timer(_make_current_pcollector);
-
-  DXGraphicsStateGuardian9 *dxgsg;
-  DCAST_INTO_V(dxgsg, _gsg);
-
-  // do nothing here
-  DBG_S dxgsg9_cat.debug ( ) << "wdxGraphicsBuffer9::make_current\n"; DBG_E
-
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsBuffer9::release_gsg
 //       Access: Public, Virtual

+ 5 - 7
panda/src/dxgsg9/wdxGraphicsBuffer9.h

@@ -41,16 +41,12 @@ public:
                     int x_size, int y_size);
   virtual ~wdxGraphicsBuffer9();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
-  virtual void select_cube_map(int cube_map_index);
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
 
-  virtual void make_current();
+  virtual void select_cube_map(int cube_map_index);
   virtual void release_gsg();
 
-  virtual void begin_render_texture();
-  virtual void end_render_texture();
-
   virtual void process_events();
 
 protected:
@@ -58,6 +54,8 @@ protected:
   virtual bool open_buffer();
 
 private:
+  void begin_render_texture();
+  void end_render_texture();
   static void process_1_event();
 
   int _cube_map_index;

+ 22 - 17
panda/src/dxgsg9/wdxGraphicsWindow9.cxx

@@ -99,11 +99,12 @@ make_current() {
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool wdxGraphicsWindow9::
-begin_frame() {
+begin_frame(FrameMode mode) {
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
   }
+  
   if (_awaiting_restore) {
     // The fullscreen window was recently restored; we can't continue
     // until the GSG says we can.
@@ -112,18 +113,15 @@ begin_frame() {
       return false;
     }
     _awaiting_restore = false;
-
     init_resized_window();
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
-  }
+
   make_current();
-  begin_render_texture();
-  clear_cube_map_selection();
+
+  if (mode == FM_render) {
+    clear_cube_map_selection();
+  }
+  
   bool return_val = _gsg->begin_frame();
   _dxgsg->set_render_target();
   return return_val;
@@ -137,17 +135,24 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void wdxGraphicsWindow9::
-end_frame() {
+end_frame(FrameMode mode) {
+
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
+
+  if (mode == FM_render) {
+    copy_to_textures();
+  }
+
   _gsg->end_frame();
-  end_render_texture();
-  copy_to_textures();
-  trigger_flip();
-  if (_one_shot) {
-    prepare_for_deletion();
+
+  if (mode == FM_render) {
+    trigger_flip();
+    if (_one_shot) {
+      prepare_for_deletion();
+    }
+    clear_cube_map_selection();
   }
-  clear_cube_map_selection();
 }
 
 ////////////////////////////////////////////////////////////////////

+ 3 - 4
panda/src/dxgsg9/wdxGraphicsWindow9.h

@@ -38,10 +38,8 @@ public:
                      const string &name);
   virtual ~wdxGraphicsWindow9();
 
-  virtual void make_current();
-
-  virtual bool begin_frame();
-  virtual void end_frame();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
   virtual void end_flip();
 
   virtual int verify_window_sizes(int numsizes, int *dimen);
@@ -74,6 +72,7 @@ private:
 
   bool reset_device_resize_window(UINT new_xsize, UINT new_ysize);
   void init_resized_window();
+  void make_current();
   static int D3DFMT_to_DepthBits(D3DFORMAT fmt);
   static bool is_badvidmem_card(D3DADAPTER_IDENTIFIER9 *pDevID);
 

+ 5 - 5
panda/src/glstuff/glGraphicsBuffer_src.h

@@ -60,12 +60,12 @@ public:
   virtual ~CLP(GraphicsBuffer)();
 
   virtual void select_cube_map(int cube_map_index);
-  virtual void auto_resize();
-  virtual void make_current();
-  virtual void begin_render_texture();
-  virtual void end_render_texture();
-  
+
 private:
+  void make_current();
+  void begin_render_texture();
+  void end_render_texture();
+  
   // HPBUFFERARB _pbuffer;
   // HDC _pbuffer_dc;
 

+ 17 - 22
panda/src/glxdisplay/glxGraphicsBuffer.cxx

@@ -72,19 +72,25 @@ glxGraphicsBuffer::
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool glxGraphicsBuffer::
-begin_frame() {
+begin_frame(FrameMode mode) {
+  PStatTimer timer(_make_current_pcollector);
+
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
-  }
-  make_current();
-  begin_render_texture();
+
+  glxGraphicsStateGuardian *glxgsg;
+  DCAST_INTO_V(glxgsg, _gsg);
+  glXMakeCurrent(_display, _pbuffer, glxgsg->_context);
+
+  // Now that we have made the context current to a window, we can
+  // reset the GSG state if this is the first time it has been used.
+  // (We can't just call reset() when we construct the GSG, because
+  // reset() requires having a current context.)
+  glxgsg->reset_if_new();
+
+  // begin_render_texture();
   clear_cube_map_selection();
   return _gsg->begin_frame();
 }
@@ -97,11 +103,11 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void glxGraphicsBuffer::
-end_frame() {
+end_frame(FrameMode mode) {
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
   _gsg->end_frame();
-  end_render_texture();
+  // end_render_texture();
   copy_to_textures();
   trigger_flip();
   if (_one_shot) {
@@ -119,17 +125,6 @@ end_frame() {
 ////////////////////////////////////////////////////////////////////
 void glxGraphicsBuffer::
 make_current() { 
-  PStatTimer timer(_make_current_pcollector);
-
-  glxGraphicsStateGuardian *glxgsg;
-  DCAST_INTO_V(glxgsg, _gsg);
-  glXMakeCurrent(_display, _pbuffer, glxgsg->_context);
-
-  // Now that we have made the context current to a window, we can
-  // reset the GSG state if this is the first time it has been used.
-  // (We can't just call reset() when we construct the GSG, because
-  // reset() requires having a current context.)
-  glxgsg->reset_if_new();
 }
 
 ////////////////////////////////////////////////////////////////////

+ 2 - 3
panda/src/glxdisplay/glxGraphicsBuffer.h

@@ -41,9 +41,8 @@ public:
 
   virtual ~glxGraphicsBuffer();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
-  virtual void make_current();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
   virtual void release_gsg();
 
 protected:

+ 2 - 2
panda/src/glxdisplay/glxGraphicsWindow.cxx

@@ -170,7 +170,7 @@ release_gsg() {
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool glxGraphicsWindow::
-begin_frame() {
+begin_frame(FrameMode mode) {
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
@@ -200,7 +200,7 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void glxGraphicsWindow::
-end_frame() {
+end_frame(FrameMode mode) {
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
   _gsg->end_frame();

+ 2 - 5
panda/src/glxdisplay/glxGraphicsWindow.h

@@ -37,13 +37,10 @@ public:
   virtual ~glxGraphicsWindow();
 
   virtual bool move_pointer(int device, int x, int y);
-
-  virtual bool make_context();
-  virtual void make_current();
   virtual void release_gsg();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
   virtual void begin_flip();
 
   virtual void process_events();

+ 10 - 26
panda/src/mesadisplay/osMesaGraphicsBuffer.cxx

@@ -61,14 +61,15 @@ begin_frame() {
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
-  }
-  make_current();
-  begin_render_texture();
+
+  OSMesaGraphicsStateGuardian *mesagsg;
+  DCAST_INTO_V(mesagsg, _gsg);
+  OSMesaMakeCurrent(mesagsg->_context, _image.p(), _type,
+                    _x_size, _y_size);
+
+  mesagsg->reset_if_new();
+
+  // begin_render_texture();
   clear_cube_map_selection();
   return _gsg->begin_frame();
 }
@@ -85,7 +86,7 @@ end_frame() {
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
   _gsg->end_frame();
-  end_render_texture();
+  // end_render_texture();
   copy_to_textures();
   trigger_flip();
   if (_one_shot) {
@@ -94,23 +95,6 @@ end_frame() {
   clear_cube_map_selection();
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: OsMesaGraphicsBuffer::make_current
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               during begin_frame() to ensure the graphics context
-//               is ready for drawing.
-////////////////////////////////////////////////////////////////////
-void OsMesaGraphicsBuffer::
-make_current() {
-  OSMesaGraphicsStateGuardian *mesagsg;
-  DCAST_INTO_V(mesagsg, _gsg);
-  OSMesaMakeCurrent(mesagsg->_context, _image.p(), _type,
-                    _x_size, _y_size);
-
-  mesagsg->reset_if_new();
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: OsMesaGraphicsBuffer::close_buffer
 //       Access: Protected, Virtual

+ 2 - 3
panda/src/mesadisplay/osMesaGraphicsBuffer.h

@@ -38,9 +38,8 @@ public:
 
   virtual ~OsMesaGraphicsBuffer();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
-  virtual void make_current();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
 
 protected:
   virtual void close_buffer();

+ 22 - 34
panda/src/wgldisplay/wglGraphicsBuffer.cxx

@@ -65,7 +65,9 @@ wglGraphicsBuffer::
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsBuffer::
-begin_frame() {
+begin_frame(FrameMode mode) {
+  PStatTimer timer(_make_current_pcollector);
+
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
@@ -87,15 +89,12 @@ begin_frame() {
     }
   }
 
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
+  wglMakeCurrent(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc));
+  
+  if (mode == FM_render) {
+    begin_render_texture();
+    clear_cube_map_selection();
   }
-  make_current();
-  begin_render_texture();
-  clear_cube_map_selection();
   return _gsg->begin_frame();
 }
 
@@ -107,17 +106,24 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void wglGraphicsBuffer::
-end_frame() {
+end_frame(FrameMode mode) {
   end_frame_spam();
   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
+
+  if (mode == FM_render) {
+    end_render_texture();
+    copy_to_textures();
+  }
+  
   _gsg->end_frame();
-  end_render_texture();
-  copy_to_textures();
-  trigger_flip();
-  if (_one_shot) {
-    prepare_for_deletion();
+  
+  if (mode == FM_render) {
+    trigger_flip();
+    if (_one_shot) {
+      prepare_for_deletion();
+    }
+    clear_cube_map_selection();
   }
-  clear_cube_map_selection();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -219,23 +225,6 @@ select_cube_map(int cube_map_index) {
   wglgsg->_wglSetPbufferAttribARB(_pbuffer, iattrib_list);
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: wglGraphicsBuffer::make_current
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               during begin_frame() to ensure the graphics context
-//               is ready for drawing.
-////////////////////////////////////////////////////////////////////
-void wglGraphicsBuffer::
-make_current() {
-  PStatTimer timer(_make_current_pcollector);
-
-  wglGraphicsStateGuardian *wglgsg;
-  DCAST_INTO_V(wglgsg, _gsg);
-
-  wglMakeCurrent(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc));
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsBuffer::release_gsg
 //       Access: Public, Virtual
@@ -319,7 +308,6 @@ open_buffer() {
 
   wglMakeCurrent(twindow_dc, wglgsg->get_context(twindow_dc));
   wglgsg->reset_if_new();
-  _needs_context = false;
 
   // Now that we have fully made a window and used that window to
   // create a rendering context, we can attempt to create a pbuffer.

+ 3 - 4
panda/src/wgldisplay/wglGraphicsBuffer.h

@@ -46,11 +46,10 @@ public:
                     int x_size, int y_size);
   virtual ~wglGraphicsBuffer();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
-  virtual void select_cube_map(int cube_map_index);
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
 
-  virtual void make_current();
+  virtual void select_cube_map(int cube_map_index);
   virtual void release_gsg();
 
   virtual void begin_render_texture();

+ 34 - 61
panda/src/wgldisplay/wglGraphicsWindow.cxx

@@ -157,20 +157,26 @@ wglGraphicsWindow::
 //               should be skipped.
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsWindow::
-begin_frame() {
+begin_frame(FrameMode mode) {
+  PStatTimer timer(_make_current_pcollector);
+
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     return false;
   }
-  auto_resize();
-  if (needs_context()) {
-    if (!make_context()) {
-      return false;
-    }
+
+  wglGraphicsStateGuardian *wglgsg;
+  DCAST_INTO_R(wglgsg, _gsg, false);
+  
+  HGLRC context = wglgsg->get_context(_hdc);
+  nassertr(context, false);
+  wglMakeCurrent(_hdc, context);
+  wglgsg->reset_if_new();
+
+  if (mode == FM_render) {
+    clear_cube_map_selection();
   }
-  make_current();
-  begin_render_texture();
-  clear_cube_map_selection();
+  
   return _gsg->begin_frame();
 }
 
@@ -182,62 +188,25 @@ begin_frame() {
 //               should do whatever finalization is required.
 ////////////////////////////////////////////////////////////////////
 void wglGraphicsWindow::
-end_frame() {
-  end_frame_spam();
-  nassertv(_gsg != (GraphicsStateGuardian *)NULL);
-  _gsg->end_frame();
-  end_render_texture();
-  copy_to_textures();
-  trigger_flip();
-  if (_one_shot) {
-    prepare_for_deletion();
-  }
-  clear_cube_map_selection();
-}
+end_frame(FrameMode mode) {
 
-////////////////////////////////////////////////////////////////////
-//     Function: wglGraphicsWindow::make_context
-//       Access: Public, Virtual
-//  Description: If _needs_context is true, this will be called
-//               in the draw thread prior to rendering into the
-//               window.  It should attempt to create a graphics
-//               context, and return true if successful, false
-//               otherwise.  If it returns false the window will be
-//               considered failed.
-////////////////////////////////////////////////////////////////////
-bool wglGraphicsWindow::
-make_context() {
-  PStatTimer timer(_make_current_pcollector);
+  end_frame_spam();
 
-  wglGraphicsStateGuardian *wglgsg;
-  DCAST_INTO_R(wglgsg, _gsg, false);
+  nassertv(_gsg != (GraphicsStateGuardian *)NULL);
 
-  HGLRC context = wglgsg->get_context(_hdc);
-  if (context) {
-    wglMakeCurrent(_hdc, context);
-    wglgsg->reset_if_new();
-    _needs_context = false;
-    return true;
+  if (mode == FM_render) {
+    copy_to_textures();
   }
-  return false;
-}
 
-////////////////////////////////////////////////////////////////////
-//     Function: wglGraphicsWindow::make_current
-//       Access: Public, Virtual
-//  Description: This function will be called within the draw thread
-//               during begin_frame() to ensure the graphics context
-//               is ready for drawing.
-////////////////////////////////////////////////////////////////////
-void wglGraphicsWindow::
-make_current() {
-  PStatTimer timer(_make_current_pcollector);
+  _gsg->end_frame();
 
-  wglGraphicsStateGuardian *wglgsg;
-  DCAST_INTO_V(wglgsg, _gsg);
-  HGLRC context = wglgsg->get_context(_hdc);
-  nassertv(context);
-  wglMakeCurrent(_hdc, context);
+  if (mode == FM_render) {
+    trigger_flip();
+    if (_one_shot) {
+      prepare_for_deletion();
+    }
+    clear_cube_map_selection();
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -277,8 +246,12 @@ begin_flip() {
     // called.  Empirically, it appears that it is not necessary in
     // many cases, but it definitely is necessary at least in the case
     // of Mesa on Windows.
-    make_current();
-
+    wglGraphicsStateGuardian *wglgsg;
+    DCAST_INTO_V(wglgsg, _gsg);
+    HGLRC context = wglgsg->get_context(_hdc);
+    nassertv(context);
+    wglMakeCurrent(_hdc, context);
+    
     SwapBuffers(_hdc);
   }
 }

+ 3 - 4
panda/src/wgldisplay/wglGraphicsWindow.h

@@ -33,10 +33,9 @@ public:
                     const string &name);
   virtual ~wglGraphicsWindow();
 
-  virtual bool begin_frame();
-  virtual void end_frame();
-  virtual bool make_context();
-  virtual void make_current();
+  virtual bool begin_frame(FrameMode mode);
+  virtual void end_frame(FrameMode mode);
+
   virtual void release_gsg();
   virtual void begin_flip();