25 #include <bias_config.h>
26 #include "glfRenderingContext_WGL.hh"
27 #include <Utils/GlutInitWrapper.hh>
28 #include <OpenGLFramework/Base/glfException.hh>
43 BIASASSERT(hDC_ == NULL);
44 BIASASSERT(hRC_ == NULL);
51 #ifndef BIAS_HAVE_GLEW
52 #error glfRenderingContext_WGL requires GLEW
55 #ifndef BIAS_HAVE_GLUT
56 #error glfRenderingContext_WGL requires GLUT
64 glutCreateWindow(
"Hidden window");
71 if (!WGLEW_ARB_pixel_format) {
72 GLF_THROW_EXCEPTION(
"WGL_ARB_pixel_format extension is unsupported");
76 HDC hCurrentDC = wglGetCurrentDC();
77 if (hCurrentDC == NULL) {
78 GLF_THROW_EXCEPTION(
"Failed to get OpenGL device context");
83 WGL_SUPPORT_OPENGL_ARB, TRUE,
84 GetWglRenderTargetAttribute(), TRUE,
87 const int MAX_PIXEL_FORMATS = 512;
88 int pixelFormats[MAX_PIXEL_FORMATS];
90 if (wglChoosePixelFormatARB(hCurrentDC, attribs, NULL,
91 MAX_PIXEL_FORMATS, pixelFormats,
92 &numFormats) == FALSE) {
93 GLF_THROW_EXCEPTION(
"Failed to choose pixel format");
95 if (numFormats == 0) {
96 GLF_THROW_EXCEPTION(
"No matching pixel format found");
98 if (numFormats > MAX_PIXEL_FORMATS) {
99 numFormats = MAX_PIXEL_FORMATS;
104 for (
int i = 0; i < (int)numFormats; i++) {
111 WGL_STENCIL_BITS_ARB,
112 WGL_DOUBLE_BUFFER_ARB
114 const int numAttribs =
sizeof(attribList)/
sizeof(
int);
115 int attribValues[numAttribs];
116 wglGetPixelFormatAttribivARB(hCurrentDC, pixelFormats[i], 0, numAttribs,
117 attribList, attribValues);
118 if (attribValues[0] == config.
redSize &&
120 attribValues[2] == config.
blueSize &&
125 pixelFormat_ = pixelFormats[i];
129 if (pixelFormat_ == -1) {
130 GLF_THROW_EXCEPTION(
"Requested rendering context configuration is unsupported");
134 hDC_ = CreateDeviceContext(config.
width, config.
height, pixelFormat_);
137 hRC_ = wglCreateContext(hDC_);
140 GLF_THROW_EXCEPTION(
"Failed to create WGL rendering context");
149 wglDeleteContext(hRC_);
153 DestroyDeviceContext();
159 BIASASSERT(hDC_ != NULL && hRC_ != NULL);
161 wglMakeCurrent(hDC_, hRC_);
167 BIASASSERT(hDC_ != NULL && hRC_ != NULL);
169 cerr <<
"Error: glfRenderingContext_WGL::DoneCurrent() is not implemented in BIAS for Windows." << endl;
174 BIASASSERT(hDC_ != NULL);
184 WGL_STENCIL_BITS_ARB,
185 WGL_DOUBLE_BUFFER_ARB
187 const int numAttribs =
sizeof(attribs)/
sizeof(
int);
188 int attribValues[numAttribs];
190 wglGetPixelFormatAttribivARB(hDC_, pixelFormat_, 0, numAttribs,
191 attribs, attribValues);
194 config.
redSize = attribValues[0];
~glfRenderingContext_WGL()
virtual void Init(const glfRenderingContextConfig &config)
Initializes the rendering context with the given configuration.
virtual void Destroy()
Uninitializes the rendering context.
virtual void DoneCurrent()
Removes the current state of this context.
static GlutInitWrapper * GetInstance()
virtual void MakeCurrent()
Makes this context the current target for OpenGL calls.
virtual void GetConfig(glfRenderingContextConfig &config)
Gets the currently used config of the rendering context.
glfRenderingContext_WGL()
Configuration for a rendering context.