open_toontown_panda3d/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

153 lines
5.4 KiB
C++
Executable File

// Filename: wglGraphicsStateGuardian.cxx
// Created by: drose (27Jan03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "wglGraphicsStateGuardian.h"
#include "string_utils.h"
TypeHandle wglGraphicsStateGuardian::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: wglGraphicsStateGuardian::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
wglGraphicsStateGuardian::
wglGraphicsStateGuardian(const FrameBufferProperties &properties,
int pfnum) :
GLGraphicsStateGuardian(properties),
_pfnum(pfnum)
{
_made_context = false;
_context = (HGLRC)NULL;
_supports_pbuffer = false;
_supports_pixel_format = false;
}
////////////////////////////////////////////////////////////////////
// Function: wglGraphicsStateGuardian::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
wglGraphicsStateGuardian::
~wglGraphicsStateGuardian() {
if (_context != (HGLRC)NULL) {
wglDeleteContext(_context);
_context = (HGLRC)NULL;
}
}
////////////////////////////////////////////////////////////////////
// Function: wglGraphicsStateGuardian::reset
// Access: Public, Virtual
// Description: Resets all internal state as if the gsg were newly
// created.
////////////////////////////////////////////////////////////////////
void wglGraphicsStateGuardian::
reset() {
GLGraphicsStateGuardian::reset();
_supports_pbuffer = has_extension("WGL_ARB_pbuffer");
_supports_pixel_format = has_extension("WGL_ARB_pixel_format");
_wglCreatePbufferARB =
(wglCreatePbufferARB_proc)wglGetProcAddress("wglCreatePbufferARB");
_wglGetPbufferDCARB =
(wglGetPbufferDCARB_proc)wglGetProcAddress("wglGetPbufferDCARB");
_wglReleasePbufferDCARB =
(wglReleasePbufferDCARB_proc)wglGetProcAddress("wglReleasePbufferDCARB");
_wglDestroyPbufferARB =
(wglDestroyPbufferARB_proc)wglGetProcAddress("wglDestroyPbufferARB");
_wglQueryPbufferARB =
(wglQueryPbufferARB_proc)wglGetProcAddress("wglQueryPbufferARB");
if (_supports_pbuffer) {
if (_wglCreatePbufferARB == NULL ||
_wglGetPbufferDCARB == NULL ||
_wglReleasePbufferDCARB == NULL ||
_wglDestroyPbufferARB == NULL ||
_wglQueryPbufferARB == NULL) {
wgldisplay_cat.error()
<< "Driver claims to support WGL_ARB_pbuffer extension, but does not define all functions.\n";
_supports_pbuffer = false;
}
}
_wglGetPixelFormatAttribivARB =
(wglGetPixelFormatAttribivARB_proc)wglGetProcAddress("wglGetPixelFormatAttribivARB");
_wglGetPixelFormatAttribfvARB =
(wglGetPixelFormatAttribfvARB_proc)wglGetProcAddress("wglGetPixelFormatAttribfvARB");
_wglChoosePixelFormatARB =
(wglChoosePixelFormatARB_proc)wglGetProcAddress("wglChoosePixelFormatARB");
if (_supports_pixel_format) {
if (_wglGetPixelFormatAttribivARB == NULL ||
_wglGetPixelFormatAttribfvARB == NULL ||
_wglChoosePixelFormatARB == NULL) {
wgldisplay_cat.error()
<< "Driver claims to support WGL_ARB_pixel_format extension, but does not define all functions.\n";
_supports_pixel_format = false;
}
}
}
////////////////////////////////////////////////////////////////////
// Function: wglGraphicsStateGuardian::get_extra_extensions
// Access: Protected, Virtual
// Description: This may be redefined by a derived class (e.g. glx or
// wgl) to get whatever further extensions strings may
// be appropriate to that interface, in addition to the
// GL extension strings return by glGetString().
////////////////////////////////////////////////////////////////////
void wglGraphicsStateGuardian::
get_extra_extensions() {
// This is a little bit tricky, since the query function is itself
// an extension.
typedef const GLubyte *(*wglGetExtensionsStringEXT_proc)(void);
wglGetExtensionsStringEXT_proc wglGetExtensionsStringEXT =
(wglGetExtensionsStringEXT_proc)wglGetProcAddress("wglGetExtensionsStringEXT");
if (wglGetExtensionsStringEXT != NULL) {
save_extensions((const char *)wglGetExtensionsStringEXT());
}
}
////////////////////////////////////////////////////////////////////
// Function: wglGraphicsStateGuardian::make_context
// Access: Private
// Description: Creates a suitable context for rendering into the
// given window. This should only be called from the
// draw thread.
////////////////////////////////////////////////////////////////////
void wglGraphicsStateGuardian::
make_context(HDC hdc) {
// We should only call this once for a particular GSG.
nassertv(!_made_context);
_made_context = true;
// Attempt to create a context.
_context = wglCreateContext(hdc);
if (_context == NULL) {
wgldisplay_cat.error()
<< "Could not create GL context.\n";
return;
}
}