Make current optimizations

This commit is contained in:
Josh Yelon 2006-04-13 18:24:46 +00:00
parent 8cff8009a9
commit a39a229c76
5 changed files with 34 additions and 18 deletions

View File

@ -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;

View File

@ -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);
}
}
////////////////////////////////////////////////////////////////////

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}