From a39a229c76803979b851accd88ef293cbea4c060 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 13 Apr 2006 18:24:46 +0000 Subject: [PATCH] Make current optimizations --- panda/src/wgldisplay/wglGraphicsBuffer.cxx | 18 ++++++++++++------ panda/src/wgldisplay/wglGraphicsPipe.cxx | 13 +++++++++---- panda/src/wgldisplay/wglGraphicsPipe.h | 3 +-- .../wgldisplay/wglGraphicsStateGuardian.cxx | 3 ++- panda/src/wgldisplay/wglGraphicsWindow.cxx | 15 ++++++++++----- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.cxx b/panda/src/wgldisplay/wglGraphicsBuffer.cxx index 92dc7d055a..62667b305a 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.cxx +++ b/panda/src/wgldisplay/wglGraphicsBuffer.cxx @@ -69,7 +69,6 @@ wglGraphicsBuffer:: //////////////////////////////////////////////////////////////////// bool wglGraphicsBuffer:: begin_frame(FrameMode mode) { - PStatTimer timer(_make_current_pcollector); begin_frame_spam(); 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) { begin_render_texture(); @@ -307,7 +309,10 @@ open_buffer() { 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(); // 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. if (!make_pbuffer(twindow_dc)) { - wglMakeCurrent(0, 0); + wglpipe->wgl_make_current(0, 0, &_make_current_pcollector); return false; } _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(); _is_valid = true; diff --git a/panda/src/wgldisplay/wglGraphicsPipe.cxx b/panda/src/wgldisplay/wglGraphicsPipe.cxx index 22e0f7c69b..78941c3d45 100644 --- a/panda/src/wgldisplay/wglGraphicsPipe.cxx +++ b/panda/src/wgldisplay/wglGraphicsPipe.cxx @@ -49,13 +49,13 @@ wglGraphicsPipe:: } //////////////////////////////////////////////////////////////////// -// Function: wglGraphicsPipe::wgl_make_current +// Function: wglGraphicsWindow::wgl_make_current // Access: Private, Static // Description: a thin wrapper around wglMakeCurrent to avoid -// unnecessary switches. +// unnecessary OS-call overhead. //////////////////////////////////////////////////////////////////// void wglGraphicsPipe:: -wgl_make_current(HDC hdc, HGLRC hglrc) { +wgl_make_current(HDC hdc, HGLRC hglrc, PStatCollector *collector) { if ((_current_valid) && (_current_hdc == hdc) && (_current_hglrc == hglrc)) { @@ -64,7 +64,12 @@ wgl_make_current(HDC hdc, HGLRC hglrc) { _current_valid = true; _current_hdc = hdc; _current_hglrc = hglrc; - wglMakeCurrent(hdc, hglrc); + if (collector) { + PStatTimer timer(*collector); + wglMakeCurrent(hdc, hglrc); + } else { + wglMakeCurrent(hdc, hglrc); + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/wgldisplay/wglGraphicsPipe.h b/panda/src/wgldisplay/wglGraphicsPipe.h index 472334e4a4..f997d2306a 100644 --- a/panda/src/wgldisplay/wglGraphicsPipe.h +++ b/panda/src/wgldisplay/wglGraphicsPipe.h @@ -73,13 +73,12 @@ private: const wglGraphicsStateGuardian *wglgsg, HDC window_dc, int pfnum); static string format_pfd_flags(DWORD pfd_flags); + static void wgl_make_current(HDC hdc, HGLRC hglrc, PStatCollector *collector); static bool _current_valid; static HDC _current_hdc; static HGLRC _current_hglrc; - static void wgl_make_current(HDC hdc, HGLRC hglrc); - public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx b/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx index 78a0138f5d..2314ec405d 100755 --- a/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx +++ b/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx @@ -128,7 +128,8 @@ choose_pixel_format(const FrameBufferProperties &properties) { HDC twindow_dc = temp_gsg->get_twindow_dc(); 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(); if (temp_gsg->_supports_pixel_format) { diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index ad616a87a4..2e8584e033 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -162,7 +162,6 @@ wglGraphicsWindow:: //////////////////////////////////////////////////////////////////// bool wglGraphicsWindow:: begin_frame(FrameMode mode) { - PStatTimer timer(_make_current_pcollector); begin_frame_spam(); if (_gsg == (GraphicsStateGuardian *)NULL) { @@ -174,7 +173,10 @@ begin_frame(FrameMode mode) { HGLRC context = wglgsg->get_context(_hdc); 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(); if (mode == FM_render) { @@ -240,8 +242,9 @@ begin_flip() { DCAST_INTO_V(wglgsg, _gsg); HGLRC context = wglgsg->get_context(_hdc); nassertv(context); - wglMakeCurrent(_hdc, context); - + wglGraphicsPipe *wglpipe; + DCAST_INTO_V(wglpipe, _pipe); + wglpipe->wgl_make_current(_hdc, context, &_make_current_pcollector); SwapBuffers(_hdc); } } @@ -255,7 +258,9 @@ begin_flip() { void wglGraphicsWindow:: close_window() { 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(); _active = false; }