33
98
HGLRC OglContext::sharingContext = NULL;
35
100
LRESULT CALLBACK WndProc(HWND hWnd,
43
108
OglContext::~OglContext()
48
113
bool OglContext::makeCurrent()
53
if (!wglMakeContextCurrentARB(hPBufferDC, hPBufferDC, hPBufferRC))
55
msSetError(MS_OGLERR, "Can't Activate The GL Rendering pbuffer.", "OglContext::makeCurrent()");
118
if (!wglMakeContextCurrentARB(hPBufferDC, hPBufferDC, hPBufferRC))
120
msSetError(MS_OGLERR, "Can't Activate The GL Rendering pbuffer.", "OglContext::makeCurrent()");
62
127
bool OglContext::initWindow()
64
int windowPixelFormat;
69
HMODULE hInstance = NULL;
71
WindowRect.left=(long)0;
72
WindowRect.right=(long)0;
73
WindowRect.top=(long)0;
74
WindowRect.bottom=(long)0;
75
hInstance = GetModuleHandle(NULL);
76
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
79
wc.lpfnWndProc = (WNDPROC) WndProc;
80
wc.hInstance = hInstance;
81
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
82
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
83
wc.hbrBackground = NULL;
84
wc.lpszMenuName = NULL;
85
wc.lpszClassName = _T("OpenGL");
87
if (!RegisterClass(&wc))
89
msSetError(MS_OGLERR, "Failed To Register The Window Class.", "OglContext::initWindow()");
92
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
93
dwStyle=WS_OVERLAPPEDWINDOW;
95
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
97
if (!(hWnd=CreateWindowEx( dwExStyle,
104
WindowRect.right-WindowRect.left,
105
WindowRect.bottom-WindowRect.top,
111
msSetError(MS_OGLERR, "Window Creation Error.", "OglContext::initWindow()");
115
static PIXELFORMATDESCRIPTOR pfd=
117
sizeof(PIXELFORMATDESCRIPTOR),
123
24, // Select Our Color Depth
124
0, 0, 0, 0, 0, 0, // Color Bits Ignored
126
0, // Shift Bit Ignored
127
0, // No Accumulation Buffer
128
0, 0, 0, 0, // Accumulation Bits Ignored
129
16, // 16Bit Z-Buffer (Depth Buffer)
130
0, // No Stencil Buffer
131
0, // No Auxiliary Buffer
132
PFD_MAIN_PLANE, // Main Drawing Layer
134
0, 0, 0 // Layer Masks Ignored
137
if (!(window=GetDC(hWnd)))
139
msSetError(MS_OGLERR, "Can't Create A GL Device Context.", "OglContext::initWindow()");
143
if (!(windowPixelFormat=ChoosePixelFormat(window,&pfd)))
145
msSetError(MS_OGLERR, "Can't Find A Suitable windowPixelFormat.", "OglContext::initWindow()");
149
if(!SetPixelFormat(window,windowPixelFormat,&pfd))
151
msSetError(MS_OGLERR, "Can't Set The windowPixelFormat.", "OglContext::initWindow()");
129
int windowPixelFormat;
134
HMODULE hInstance = NULL;
136
WindowRect.left=(long)0;
137
WindowRect.right=(long)0;
138
WindowRect.top=(long)0;
139
WindowRect.bottom=(long)0;
140
hInstance = GetModuleHandle(NULL);
141
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
144
wc.lpfnWndProc = (WNDPROC) WndProc;
145
wc.hInstance = hInstance;
146
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
147
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
148
wc.hbrBackground = NULL;
149
wc.lpszMenuName = NULL;
150
wc.lpszClassName = _T("OpenGL");
152
if (!RegisterClass(&wc))
154
msSetError(MS_OGLERR, "Failed To Register The Window Class.", "OglContext::initWindow()");
157
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
158
dwStyle=WS_OVERLAPPEDWINDOW;
160
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
162
if (!(hWnd=CreateWindowEx( dwExStyle,
169
WindowRect.right-WindowRect.left,
170
WindowRect.bottom-WindowRect.top,
176
msSetError(MS_OGLERR, "Window Creation Error.", "OglContext::initWindow()");
180
static PIXELFORMATDESCRIPTOR pfd=
182
sizeof(PIXELFORMATDESCRIPTOR),
188
24, // Select Our Color Depth
189
0, 0, 0, 0, 0, 0, // Color Bits Ignored
191
0, // Shift Bit Ignored
192
0, // No Accumulation Buffer
193
0, 0, 0, 0, // Accumulation Bits Ignored
194
16, // 16Bit Z-Buffer (Depth Buffer)
195
0, // No Stencil Buffer
196
0, // No Auxiliary Buffer
197
PFD_MAIN_PLANE, // Main Drawing Layer
199
0, 0, 0 // Layer Masks Ignored
202
if (!(window=GetDC(hWnd)))
204
msSetError(MS_OGLERR, "Can't Create A GL Device Context.. Last Error: %d", "OglContext::initWindow()", GetLastError());
208
if (!(windowPixelFormat=ChoosePixelFormat(window,&pfd)))
210
msSetError(MS_OGLERR, "Can't Find A Suitable windowPixelFormat. Last Error: %d", "OglContext::initWindow()", GetLastError());
214
if(!SetPixelFormat(window,windowPixelFormat,&pfd))
216
msSetError(MS_OGLERR, "Can't Set The windowPixelFormat. Last Error: %d", "OglContext::initWindow()", GetLastError());
157
222
bool OglContext::initSharingContext()
159
if (!(sharingContext=wglCreateContext(window)))
161
msSetError(MS_OGLERR, "Can't Create A GL Rendering Context.", "OglContext::createContext()");
165
if(!wglMakeCurrent(window,sharingContext))
167
msSetError(MS_OGLERR, "Can't Activate The GL Rendering Context.", "OglContext::createContext()");
171
wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB");
172
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
173
wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
174
wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribfvARB");
175
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
176
wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
177
wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
178
wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
179
wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
180
wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");
181
wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
182
wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
183
wglGetPixelFormatAttribivEXT = (PFNWGLGETPIXELFORMATATTRIBIVEXTPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
185
wglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
186
wglBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
187
wglBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
188
wglBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)wglGetProcAddress("glBufferSubDataARB");
189
wglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
190
wglGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)wglGetProcAddress("glGetBufferParameterivARB");
191
wglMapBufferARB = (PFNGLMAPBUFFERARBPROC)wglGetProcAddress("glMapBufferARB");
192
wglUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)wglGetProcAddress("glUnmapBufferARB");
194
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*) &MAX_ANISOTROPY);
195
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&MAX_TEXTURE_SIZE);
197
MIN_TEXTURE_SIZE = 8;
224
if (!(sharingContext=wglCreateContext(window)))
226
msSetError(MS_OGLERR, "Can't Create A GL Rendering Context.", "OglContext::createContext()");
230
if(!wglMakeCurrent(window,sharingContext))
232
msSetError(MS_OGLERR, "Can't Activate The GL Rendering Context.", "OglContext::createContext()");
236
if (!(wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB")))
238
msSetError(MS_OGLERR, "unable to retreive wglChoosePixelFormatARB method.", "OglContext::createContext()");
242
if (!(wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB")))
244
msSetError(MS_OGLERR, "unable to retreive wglCreatePbufferARB method.", "OglContext::createContext()");
248
if (!(wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB")))
250
msSetError(MS_OGLERR, "unable to retreive wglGetPbufferDCARB method.", "OglContext::createContext()");
254
if (!(wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB")))
256
msSetError(MS_OGLERR, "unable to retreive wglReleasePbufferDCARB method.", "OglContext::createContext()");
260
if (!(wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB")))
262
msSetError(MS_OGLERR, "unable to retreive wglMakeContextCurrentARB method.", "OglContext::createContext()");
266
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*) &MAX_ANISOTROPY);
267
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&MAX_TEXTURE_SIZE);
269
MIN_TEXTURE_SIZE = 8;
203
275
bool OglContext::createPBuffer(ms_uint32 width, ms_uint32 height)
205
HPBUFFERARB hPBuffer = NULL;
212
float fAttributes[] = {0,0};
213
int samples = MAX_MULTISAMPLE_SAMPLES;
215
while (!valid && samples >= 0)
219
WGL_SAMPLES_ARB,samples,
220
WGL_DRAW_TO_PBUFFER_ARB,GL_TRUE,
221
WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
222
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
223
WGL_COLOR_BITS_ARB,24,
224
WGL_ALPHA_BITS_ARB,8,
225
WGL_DEPTH_BITS_ARB,16,
226
WGL_STENCIL_BITS_ARB,0,
227
WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
228
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
232
valid = wglChoosePixelFormatARB(window,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
236
msSetError(MS_OGLERR, "P-buffer Error: Unable to find an acceptable pixel format.", "OglContext::createPBuffer()");
240
if (!(hPBuffer = wglCreatePbufferARB(window, pixelFormat, width, height, 0)))
242
msSetError(MS_OGLERR, "P-buffer Error: Unable to create P-buffer.", "OglContext::createPBuffer()");
245
if (!(hPBufferDC = wglGetPbufferDCARB(hPBuffer)))
247
msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC.", "OglContext::createPBuffer()");
250
if (!(hPBufferRC = wglCreateContext(hPBufferDC)))
252
msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC.", "OglContext::createPBuffer()");
256
if (wglShareLists(sharingContext,hPBufferRC) == FALSE)
258
msSetError(MS_OGLERR, "P-buffer Error: Unable to share display lists.", "OglContext::createPBuffer()");
277
HPBUFFERARB hPBuffer = NULL;
284
float fAttributes[] = {0,0};
285
int samples = MAX_MULTISAMPLE_SAMPLES;
287
while ((!valid || numFormats == 0) && samples >= 0)
291
WGL_SAMPLES_ARB,samples,
292
WGL_DRAW_TO_PBUFFER_ARB,GL_TRUE,
293
WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
294
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
295
WGL_COLOR_BITS_ARB,24,
296
WGL_ALPHA_BITS_ARB,8,
297
WGL_DEPTH_BITS_ARB,16,
298
WGL_STENCIL_BITS_ARB,0,
299
WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
300
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
304
valid = wglChoosePixelFormatARB(window,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
305
if (!valid || numFormats == 0) samples -= 2;
310
msSetError(MS_OGLERR, "P-buffer Error: Unable to find an acceptable pixel format.", "OglContext::createPBuffer()");
314
if (!(hPBuffer = wglCreatePbufferARB(window, pixelFormat, width, height, 0)))
316
msSetError(MS_OGLERR, "P-buffer Error: Unable to create P-buffer. glError: %d", "OglContext::createPBuffer()", glGetError());
319
if (!(hPBufferDC = wglGetPbufferDCARB(hPBuffer)))
321
msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC. glError: %d", "OglContext::createPBuffer()", glGetError());
324
if (!(hPBufferRC = wglCreateContext(hPBufferDC)))
326
msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC. glError: %d", "OglContext::createPBuffer()", glGetError());
330
if (wglShareLists(sharingContext,hPBufferRC) == FALSE)
332
msSetError(MS_OGLERR, "P-buffer Error: Unable to share display lists. glError: %d", "OglContext::createPBuffer()", glGetError());
339
PFNWGLCHOOSEPIXELFORMATARBPROC OglContext::wglChoosePixelFormatARB = NULL;
340
PFNWGLCREATEPBUFFERARBPROC OglContext::wglCreatePbufferARB = NULL;
341
PFNWGLGETPBUFFERDCARBPROC OglContext::wglGetPbufferDCARB = NULL;
342
PFNWGLRELEASEPBUFFERDCARBPROC OglContext::wglReleasePbufferDCARB = NULL;
343
PFNWGLMAKECONTEXTCURRENTARBPROC OglContext::wglMakeContextCurrentARB = NULL;
267
347
Display* OglContext::window = NULL;
271
351
OglContext::~OglContext()
277
357
bool OglContext::makeCurrent()
282
glXMakeCurrent(window, pbuffer, sharingContext);
362
if (!glXMakeCurrent(window, pbuffer, sharingContext))
364
msSetError(MS_OGLERR, "glXMakeCurrent failed. glError: %d", "OglContext::makeCurrent()", glGetError());
287
371
bool OglContext::initSharingContext()
289
int fb_attributes[] =
291
GLX_SAMPLES_ARB, MAX_MULTISAMPLE_SAMPLES,
292
GLX_RENDER_TYPE, GLX_RGBA_BIT,
293
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
300
GLX_SAMPLE_BUFFERS_ARB, 1,
305
while (num_configs == 0 && fb_attributes[1] >= 0)
307
configs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
308
fb_attributes[1] -= 2;
311
if (configs == NULL || num_configs == 0)
313
msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs.", "OglContext::init()");
317
sharingContext = glXCreateNewContext(window, *configs, GLX_RGBA_TYPE, NULL, 1);
318
if (sharingContext == NULL)
320
msSetError(MS_OGLERR, "glXCreateNewContext failed.", "OglContext::initSharingContext()");
373
int fb_attributes[] =
375
GLX_SAMPLES_ARB, MAX_MULTISAMPLE_SAMPLES,
376
GLX_RENDER_TYPE, GLX_RGBA_BIT,
377
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
384
GLX_SAMPLE_BUFFERS_ARB, 1,
389
while (num_configs == 0 && fb_attributes[1] >= 0)
391
configs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
392
fb_attributes[1] -= 2;
395
if (configs == NULL || num_configs == 0)
397
msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs. Likely your video card or drivers are not supported. glError: %d", "OglContext::init()", glGetError());
401
sharingContext = glXCreateNewContext(window, *configs, GLX_RGBA_TYPE, NULL, 1);
402
if (sharingContext == NULL)
404
msSetError(MS_OGLERR, "glXCreateNewContext failed. glError: %d", "OglContext::initSharingContext()", glGetError());
327
411
bool OglContext::createPBuffer(ms_uint32 width, ms_uint32 height)
329
int maxHeight, maxWidth;
331
glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_WIDTH, &maxWidth);
332
glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_HEIGHT, &maxHeight);
334
ms_uint32 uMaxHeight = maxHeight, uMaxWidth = maxWidth;
336
this->width = MS_MIN(width, uMaxWidth);
337
this->height = MS_MIN(height, uMaxHeight);
339
int iPbufferAttributes[] =
341
GLX_PBUFFER_WIDTH, this->width,
342
GLX_PBUFFER_HEIGHT, this->height,
343
GLX_LARGEST_PBUFFER, false,
347
pbuffer = glXCreatePbuffer(window, *configs, iPbufferAttributes);
350
msSetError(MS_OGLERR, "glXCreatePbuffer failed.", "OglContext::init()");
413
int maxHeight, maxWidth;
415
glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_WIDTH, &maxWidth);
416
glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_HEIGHT, &maxHeight);
418
ms_uint32 uMaxHeight = maxHeight, uMaxWidth = maxWidth;
420
this->width = MS_MIN(width, uMaxWidth);
421
this->height = MS_MIN(height, uMaxHeight);
423
int iPbufferAttributes[] =
425
GLX_PBUFFER_WIDTH, this->width,
426
GLX_PBUFFER_HEIGHT, this->height,
427
GLX_LARGEST_PBUFFER, false,
431
pbuffer = glXCreatePbuffer(window, *configs, iPbufferAttributes);
434
msSetError(MS_OGLERR, "glXCreatePbuffer failed. glError: %d", "OglContext::init()", glGetError());
357
441
bool OglContext::initWindow()
359
const char* const display_name = getenv("DISPLAY");
362
msSetError(MS_OGLERR, "DISPLAY environment variable not set", "OglContext::init()");
366
window = XOpenDisplay(display_name);
368
const int fb_attributes[] = {
369
GLX_RENDER_TYPE, GLX_RGBA_BIT,
370
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
377
GLX_SAMPLE_BUFFERS_ARB, 1,
382
GLXFBConfig* tempConfigs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
384
if (tempConfigs == NULL || num_configs == 0)
386
msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs.", "OglContext::initWindow()");
390
GLXContext tempContext = glXCreateNewContext(window, *tempConfigs, GLX_RGBA_TYPE, NULL, 1);
391
if (tempContext == NULL)
393
msSetError(MS_OGLERR, "glXCreateNewContext failed.", "OglContext::initWindow()");
397
int iPbufferAttributes[] = {0, 0};
399
GLXPbuffer tempBuffer = glXCreatePbuffer(window, *tempConfigs, iPbufferAttributes);
402
msSetError(MS_OGLERR, "glXCreatePbuffer failed.", "OglContext::initWindow()");
406
glXMakeCurrent(window, tempBuffer, tempContext);
408
glGetIntegerv(GL_MAX_SAMPLES_EXT, (GLint*)&MAX_MULTISAMPLE_SAMPLES);
409
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*) &MAX_ANISOTROPY);
410
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&MAX_TEXTURE_SIZE);
412
MIN_TEXTURE_SIZE = 8;
419
#if defined(_WIN32) && !defined(__CYGWIN__)
421
PFNWGLGETEXTENSIONSSTRINGARBPROC OglContext::wglGetExtensionsStringARB = NULL;
422
PFNWGLGETPIXELFORMATATTRIBIVARBPROC OglContext::wglGetPixelFormatAttribivARB = NULL;
423
PFNWGLGETPIXELFORMATATTRIBFVARBPROC OglContext::wglGetPixelFormatAttribfvARB = NULL;
424
PFNWGLCHOOSEPIXELFORMATARBPROC OglContext::wglChoosePixelFormatARB = NULL;
425
PFNWGLCREATEPBUFFERARBPROC OglContext::wglCreatePbufferARB = NULL;
426
PFNWGLGETPBUFFERDCARBPROC OglContext::wglGetPbufferDCARB = NULL;
427
PFNWGLRELEASEPBUFFERDCARBPROC OglContext::wglReleasePbufferDCARB = NULL;
428
PFNWGLDESTROYPBUFFERARBPROC OglContext::wglDestroyPbufferARB = NULL;
429
PFNWGLQUERYPBUFFERARBPROC OglContext::wglQueryPbufferARB = NULL;
430
PFNWGLBINDTEXIMAGEARBPROC OglContext::wglBindTexImageARB = NULL;
431
PFNWGLRELEASETEXIMAGEARBPROC OglContext::wglReleaseTexImageARB = NULL;
432
PFNWGLMAKECONTEXTCURRENTARBPROC OglContext::wglMakeContextCurrentARB = NULL;
433
PFNWGLGETPIXELFORMATATTRIBIVEXTPROC OglContext::wglGetPixelFormatAttribivEXT = NULL;
435
PFNGLGENBUFFERSARBPROC OglContext::wglGenBuffersARB = 0; // VBO Name Generation Procedure
436
PFNGLBINDBUFFERARBPROC OglContext::wglBindBufferARB = 0; // VBO Bind Procedure
437
PFNGLBUFFERDATAARBPROC OglContext::wglBufferDataARB = 0; // VBO Data Loading Procedure
438
PFNGLBUFFERSUBDATAARBPROC OglContext::wglBufferSubDataARB = 0; // VBO Sub Data Loading Procedure
439
PFNGLDELETEBUFFERSARBPROC OglContext::wglDeleteBuffersARB = 0; // VBO Deletion Procedure
440
PFNGLGETBUFFERPARAMETERIVARBPROC OglContext::wglGetBufferParameterivARB = 0; // return various parameters of VBO
441
PFNGLMAPBUFFERARBPROC OglContext::wglMapBufferARB = 0; // map VBO procedure
442
PFNGLUNMAPBUFFERARBPROC OglContext::wglUnmapBufferARB = 0; // unmap VBO procedure
447
HDC OglContext::hWINDOWDC = NULL;
448
HGLRC OglContext::hWINDOWRC = NULL;
449
int OglContext::windowPixelFormat = 0;
451
HPBUFFERARB OglContext::hPBuffer = NULL;
452
HDC OglContext::hPBufferDC = NULL;
453
HGLRC OglContext::hPBufferRC = NULL;
455
// P-Buffer for texture rendering.
456
HPBUFFERARB OglContext::hTexPBuffer = NULL;
457
HDC OglContext::hTexPBufferDC = NULL;
458
HGLRC OglContext::hTexPBufferRC = NULL;
460
bool OglContext::init()
466
HMODULE hInstance = NULL;
468
WindowRect.left=(long)0;
469
WindowRect.right=(long)0;
470
WindowRect.top=(long)0;
471
WindowRect.bottom=(long)0;
472
hInstance = GetModuleHandle(NULL);
473
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
476
wc.lpfnWndProc = (WNDPROC) WndProc;
477
wc.hInstance = hInstance;
478
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
479
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
480
wc.hbrBackground = NULL;
481
wc.lpszMenuName = NULL;
482
wc.lpszClassName = L"OpenGL";
484
if (!RegisterClass(&wc))
486
printError("Failed To Register The Window Class.");
489
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
490
dwStyle=WS_OVERLAPPEDWINDOW;
492
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
494
if (!(hWnd=CreateWindowEx( dwExStyle,
501
WindowRect.right-WindowRect.left,
502
WindowRect.bottom-WindowRect.top,
508
printError("Window Creation Error.");
512
static PIXELFORMATDESCRIPTOR pfd=
514
sizeof(PIXELFORMATDESCRIPTOR),
520
24, // Select Our Color Depth
521
0, 0, 0, 0, 0, 0, // Color Bits Ignored
523
0, // Shift Bit Ignored
524
0, // No Accumulation Buffer
525
0, 0, 0, 0, // Accumulation Bits Ignored
526
16, // 16Bit Z-Buffer (Depth Buffer)
527
0, // No Stencil Buffer
528
0, // No Auxiliary Buffer
529
PFD_MAIN_PLANE, // Main Drawing Layer
531
0, 0, 0 // Layer Masks Ignored
534
if (!(hWINDOWDC=GetDC(hWnd)))
536
printError("Can't Create A GL Device Context.");
540
if (!(windowPixelFormat=ChoosePixelFormat(hWINDOWDC,&pfd)))
542
printError("Can't Find A Suitable windowPixelFormat.");
546
if(!SetPixelFormat(hWINDOWDC,windowPixelFormat,&pfd))
548
printError("Can't Set The windowPixelFormat.");
552
if (!(hWINDOWRC=wglCreateContext(hWINDOWDC)))
554
printError("Can't Create A GL Rendering Context.");
558
if(!wglMakeCurrent(hWINDOWDC,hWINDOWRC))
560
printError("Can't Activate The GL Rendering Context.");
563
wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB");
564
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
565
wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
566
wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribfvARB");
567
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
568
wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
569
wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
570
wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
571
wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
572
wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");
573
wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
574
wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
575
wglGetPixelFormatAttribivEXT = (PFNWGLGETPIXELFORMATATTRIBIVEXTPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
577
wglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
578
wglBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
579
wglBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
580
wglBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)wglGetProcAddress("glBufferSubDataARB");
581
wglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
582
wglGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)wglGetProcAddress("glGetBufferParameterivARB");
583
wglMapBufferARB = (PFNGLMAPBUFFERARBPROC)wglGetProcAddress("glMapBufferARB");
584
wglUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)wglGetProcAddress("glUnmapBufferARB");
594
float fAttributes[] =
598
WGL_DRAW_TO_PBUFFER_ARB,GL_TRUE,
599
WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
600
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
601
WGL_COLOR_BITS_ARB,24,
602
WGL_ALPHA_BITS_ARB,8,
603
WGL_DEPTH_BITS_ARB,16,
604
WGL_STENCIL_BITS_ARB,0,
605
WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
606
WGL_SAMPLES_ARB,MUTLISAMPLE_SAMPLES,
607
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
611
valid = wglChoosePixelFormatARB(hWINDOWDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
614
printError("P-buffer Error: Unable to find an acceptable pixel format");
618
if (!(hPBuffer = wglCreatePbufferARB(hWINDOWDC, pixelFormat, MAX_WIDTH, MAX_HEIGHT, 0)))
620
printError("P-buffer Error: Unable to create P-buffer");
623
if (!(hPBufferDC = wglGetPbufferDCARB(hPBuffer)))
625
printError("P-buffer Error: Unable to get P-buffer DC");
628
if (!(hPBufferRC = wglCreateContext(hPBufferDC)))
630
printError("P-buffer Error: Unable to get P-buffer DC");
634
if (wglShareLists(hWINDOWRC,hPBufferRC) == FALSE)
636
printError("P-buffer Error: Unable to share display lists");
643
PFNWGLGETEXTENSIONSSTRINGARBPROC OglContext::wglGetExtensionsStringARB = NULL;
644
PFNWGLGETPIXELFORMATATTRIBIVARBPROC OglContext::wglGetPixelFormatAttribivARB = NULL;
645
PFNWGLGETPIXELFORMATATTRIBFVARBPROC OglContext::wglGetPixelFormatAttribfvARB = NULL;
646
PFNWGLCHOOSEPIXELFORMATARBPROC OglContext::wglChoosePixelFormatARB = NULL;
647
PFNWGLCREATEPBUFFERARBPROC OglContext::wglCreatePbufferARB = NULL;
648
PFNWGLGETPBUFFERDCARBPROC OglContext::wglGetPbufferDCARB = NULL;
649
PFNWGLRELEASEPBUFFERDCARBPROC OglContext::wglReleasePbufferDCARB = NULL;
650
PFNWGLDESTROYPBUFFERARBPROC OglContext::wglDestroyPbufferARB = NULL;
651
PFNWGLQUERYPBUFFERARBPROC OglContext::wglQueryPbufferARB = NULL;
652
PFNWGLBINDTEXIMAGEARBPROC OglContext::wglBindTexImageARB = NULL;
653
PFNWGLRELEASETEXIMAGEARBPROC OglContext::wglReleaseTexImageARB = NULL;
654
PFNWGLMAKECONTEXTCURRENTARBPROC OglContext::wglMakeContextCurrentARB = NULL;
655
PFNWGLGETPIXELFORMATATTRIBIVEXTPROC OglContext::wglGetPixelFormatAttribivEXT = NULL;
657
PFNGLGENBUFFERSARBPROC OglContext::wglGenBuffersARB = 0; // VBO Name Generation Procedure
658
PFNGLBINDBUFFERARBPROC OglContext::wglBindBufferARB = 0; // VBO Bind Procedure
659
PFNGLBUFFERDATAARBPROC OglRenderer::wglBufferDataARB = 0; // VBO Data Loading Procedure
660
PFNGLBUFFERSUBDATAARBPROC OglContext::wglBufferSubDataARB = 0; // VBO Sub Data Loading Procedure
661
PFNGLDELETEBUFFERSARBPROC OglContext::wglDeleteBuffersARB = 0; // VBO Deletion Procedure
662
PFNGLGETBUFFERPARAMETERIVARBPROC OglContext::wglGetBufferParameterivARB = 0; // return various parameters of VBO
663
PFNGLMAPBUFFERARBPROC OglContext::wglMapBufferARB = 0; // map VBO procedure
664
PFNGLUNMAPBUFFERARBPROC OglContext::wglUnmapBufferARB = 0; // unmap VBO procedure
666
LRESULT CALLBACK WndProc(HWND hWnd,
443
const char* const display_name = getenv("DISPLAY");
446
msSetError(MS_OGLERR, "DISPLAY environment variable not set", "OglContext::init()");
450
window = XOpenDisplay(display_name);
453
msSetError(MS_OGLERR, "XOpenDisplay() failed.", "OglContext::init()");
457
const int fb_attributes[] = {
458
GLX_RENDER_TYPE, GLX_RGBA_BIT,
459
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
466
GLX_SAMPLE_BUFFERS_ARB, 1,
471
GLXFBConfig* tempConfigs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
473
if (tempConfigs == NULL || num_configs == 0)
475
msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs. Likely your video card or drivers are not supported.", "OglContext::initWindow()");
479
GLXContext tempContext = glXCreateNewContext(window, *tempConfigs, GLX_RGBA_TYPE, NULL, 1);
480
if (tempContext == NULL)
482
msSetError(MS_OGLERR, "glXCreateNewContext failed.", "OglContext::initWindow()");
486
int iPbufferAttributes[] = {0, 0};
488
GLXPbuffer tempBuffer = glXCreatePbuffer(window, *tempConfigs, iPbufferAttributes);
491
msSetError(MS_OGLERR, "glXCreatePbuffer failed.", "OglContext::initWindow()");
495
if (!glXMakeCurrent(window, tempBuffer, tempContext))
497
msSetError(MS_OGLERR, "glXMakeCurrent failed.", "OglContext::initWindow()");
501
glGetIntegerv(GL_MAX_SAMPLES_EXT, (GLint*)&MAX_MULTISAMPLE_SAMPLES);
502
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*) &MAX_ANISOTROPY);
503
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&MAX_TEXTURE_SIZE);
505
MIN_TEXTURE_SIZE = 8;
677
512
#endif /* USE_OGL */