Browse Source

Make current optimizations

Josh Yelon 19 years ago
parent
commit
a39a229c76

+ 12 - 6
panda/src/wgldisplay/wglGraphicsBuffer.cxx

@@ -69,7 +69,6 @@ wglGraphicsBuffer::
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsBuffer::
 bool wglGraphicsBuffer::
 begin_frame(FrameMode mode) {
 begin_frame(FrameMode mode) {
-  PStatTimer timer(_make_current_pcollector);
 
 
   begin_frame_spam();
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
   if (_gsg == (GraphicsStateGuardian *)NULL) {
@@ -91,8 +90,11 @@ begin_frame(FrameMode mode) {
       }
       }
     }
     }
   }
   }
-  
-  wglMakeCurrent(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc));
+
+  wglGraphicsPipe *wglpipe;
+  DCAST_INTO_R(wglpipe, _pipe, false);
+  wglpipe->wgl_make_current(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc),
+                            &_make_current_pcollector);
   
   
   if (mode == FM_render) {
   if (mode == FM_render) {
     begin_render_texture();
     begin_render_texture();
@@ -307,7 +309,10 @@ open_buffer() {
     return false;
     return false;
   }
   }
 
 
-  wglMakeCurrent(twindow_dc, wglgsg->get_context(twindow_dc));
+  wglGraphicsPipe *wglpipe;
+  DCAST_INTO_R(wglpipe, _pipe, false);
+  wglpipe->wgl_make_current(twindow_dc, wglgsg->get_context(twindow_dc),
+                            &_make_current_pcollector);
   wglgsg->reset_if_new();
   wglgsg->reset_if_new();
 
 
   // Now that we have fully made a window and used that window to
   // Now that we have fully made a window and used that window to
@@ -315,13 +320,14 @@ open_buffer() {
   // This might fail if the pbuffer extensions are not supported.
   // This might fail if the pbuffer extensions are not supported.
 
 
   if (!make_pbuffer(twindow_dc)) {
   if (!make_pbuffer(twindow_dc)) {
-    wglMakeCurrent(0, 0);
+    wglpipe->wgl_make_current(0, 0, &_make_current_pcollector);
     return false;
     return false;
   }
   }
 
 
   _pbuffer_dc = wglgsg->_wglGetPbufferDCARB(_pbuffer);
   _pbuffer_dc = wglgsg->_wglGetPbufferDCARB(_pbuffer);
   
   
-  wglMakeCurrent(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc));
+  wglpipe->wgl_make_current(_pbuffer_dc, wglgsg->get_context(_pbuffer_dc),
+                            &_make_current_pcollector);
   wglgsg->report_my_gl_errors();
   wglgsg->report_my_gl_errors();
   
   
   _is_valid = true;
   _is_valid = true;

+ 9 - 4
panda/src/wgldisplay/wglGraphicsPipe.cxx

@@ -49,13 +49,13 @@ wglGraphicsPipe::
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: wglGraphicsPipe::wgl_make_current
+//     Function: wglGraphicsWindow::wgl_make_current
 //       Access: Private, Static
 //       Access: Private, Static
 //  Description: a thin wrapper around wglMakeCurrent to avoid
 //  Description: a thin wrapper around wglMakeCurrent to avoid
-//               unnecessary switches.
+//               unnecessary OS-call overhead.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void wglGraphicsPipe::
 void wglGraphicsPipe::
-wgl_make_current(HDC hdc, HGLRC hglrc) {
+wgl_make_current(HDC hdc, HGLRC hglrc, PStatCollector *collector) {
   if ((_current_valid) &&
   if ((_current_valid) &&
       (_current_hdc == hdc) &&
       (_current_hdc == hdc) &&
       (_current_hglrc == hglrc)) {
       (_current_hglrc == hglrc)) {
@@ -64,7 +64,12 @@ wgl_make_current(HDC hdc, HGLRC hglrc) {
   _current_valid = true;
   _current_valid = true;
   _current_hdc = hdc;
   _current_hdc = hdc;
   _current_hglrc = hglrc;
   _current_hglrc = hglrc;
-  wglMakeCurrent(hdc, hglrc);
+  if (collector) {
+    PStatTimer timer(*collector);
+    wglMakeCurrent(hdc, hglrc);
+  } else {
+    wglMakeCurrent(hdc, hglrc);
+  }    
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 2
panda/src/wgldisplay/wglGraphicsPipe.h

@@ -73,13 +73,12 @@ private:
                                       const wglGraphicsStateGuardian *wglgsg, 
                                       const wglGraphicsStateGuardian *wglgsg, 
                                       HDC window_dc, int pfnum);
                                       HDC window_dc, int pfnum);
   static string format_pfd_flags(DWORD pfd_flags);
   static string format_pfd_flags(DWORD pfd_flags);
+  static void wgl_make_current(HDC hdc, HGLRC hglrc, PStatCollector *collector);
 
 
   static bool  _current_valid;
   static bool  _current_valid;
   static HDC   _current_hdc;
   static HDC   _current_hdc;
   static HGLRC _current_hglrc;
   static HGLRC _current_hglrc;
 
 
-  static void wgl_make_current(HDC hdc, HGLRC hglrc);
-
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {
     return _type_handle;
     return _type_handle;

+ 2 - 1
panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

@@ -128,7 +128,8 @@ choose_pixel_format(const FrameBufferProperties &properties) {
 
 
     HDC twindow_dc = temp_gsg->get_twindow_dc();
     HDC twindow_dc = temp_gsg->get_twindow_dc();
     if (twindow_dc != 0) {
     if (twindow_dc != 0) {
-      wglMakeCurrent(twindow_dc, temp_gsg->get_context(twindow_dc));
+      pipe->wgl_make_current(twindow_dc, temp_gsg->get_context(twindow_dc),
+                             NULL);
       temp_gsg->reset_if_new();
       temp_gsg->reset_if_new();
       
       
       if (temp_gsg->_supports_pixel_format) {
       if (temp_gsg->_supports_pixel_format) {

+ 10 - 5
panda/src/wgldisplay/wglGraphicsWindow.cxx

@@ -162,7 +162,6 @@ wglGraphicsWindow::
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsWindow::
 bool wglGraphicsWindow::
 begin_frame(FrameMode mode) {
 begin_frame(FrameMode mode) {
-  PStatTimer timer(_make_current_pcollector);
 
 
   begin_frame_spam();
   begin_frame_spam();
   if (_gsg == (GraphicsStateGuardian *)NULL) {
   if (_gsg == (GraphicsStateGuardian *)NULL) {
@@ -174,7 +173,10 @@ begin_frame(FrameMode mode) {
   
   
   HGLRC context = wglgsg->get_context(_hdc);
   HGLRC context = wglgsg->get_context(_hdc);
   nassertr(context, false);
   nassertr(context, false);
-  wglMakeCurrent(_hdc, context);
+  
+  wglGraphicsPipe *wglpipe;
+  DCAST_INTO_R(wglpipe, _pipe, false);
+  wglpipe->wgl_make_current(_hdc, context, &_make_current_pcollector);
   wglgsg->reset_if_new();
   wglgsg->reset_if_new();
 
 
   if (mode == FM_render) {
   if (mode == FM_render) {
@@ -240,8 +242,9 @@ begin_flip() {
     DCAST_INTO_V(wglgsg, _gsg);
     DCAST_INTO_V(wglgsg, _gsg);
     HGLRC context = wglgsg->get_context(_hdc);
     HGLRC context = wglgsg->get_context(_hdc);
     nassertv(context);
     nassertv(context);
-    wglMakeCurrent(_hdc, context);
-    
+    wglGraphicsPipe *wglpipe;
+    DCAST_INTO_V(wglpipe, _pipe);
+    wglpipe->wgl_make_current(_hdc, context, &_make_current_pcollector);
     SwapBuffers(_hdc);
     SwapBuffers(_hdc);
   }
   }
 }
 }
@@ -255,7 +258,9 @@ begin_flip() {
 void wglGraphicsWindow::
 void wglGraphicsWindow::
 close_window() {
 close_window() {
   if (_gsg != (GraphicsStateGuardian *)NULL) {
   if (_gsg != (GraphicsStateGuardian *)NULL) {
-    wglMakeCurrent(_hdc, NULL);
+    wglGraphicsPipe *wglpipe;
+    DCAST_INTO_V(wglpipe, _pipe);
+    wglpipe->wgl_make_current(_hdc, NULL, &_make_current_pcollector);
     _gsg.clear();
     _gsg.clear();
     _active = false;
     _active = false;
   }
   }