~ubuntu-branches/ubuntu/saucy/mapserver/saucy-security

« back to all changes in this revision

Viewing changes to mapoglcontext.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-12-23 14:02:06 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111223140206-n3h9t2hsa8hyslmu
Tags: 6.0.1-2
Added missed stuff for libmapscript-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * mapoglcontext.cpp
3
 
 *
4
 
 *  Created on: 11/01/2009
5
 
 *      Author: toby
6
 
 */
 
1
/******************************************************************************
 
2
 * $id: mapoglcontext.cpp 7725 2011-04-09 15:56:58Z toby $
 
3
 *
 
4
 * Project:  MapServer
 
5
 * Purpose:  Various template processing functions.
 
6
 * Author:   Steve Lime and the MapServer team.
 
7
 *
 
8
 ******************************************************************************
 
9
 * Copyright (c) 1996-2008 Regents of the University of Minnesota.
 
10
 *
 
11
 * Permission is hereby granted, free of charge, to any person obtaining a
 
12
 * copy of this software and associated documentation files (the "Software"),
 
13
 * to deal in the Software without restriction, including without limitation
 
14
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
 * and/or sell copies of the Software, and to permit persons to whom the
 
16
 * Software is furnished to do so, subject to the following conditions:
 
17
 *
 
18
 * The above copyright notice and this permission notice shall be included in 
 
19
 * all copies of this Software or works derived from this Software.
 
20
 *
 
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
22
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
24
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
27
 * DEALINGS IN THE SOFTWARE.
 
28
 ****************************************************************************/
7
29
 
8
30
#ifdef USE_OGL
9
31
 
11
33
#include "maperror.h"
12
34
#include "mapoglcontext.h"
13
35
 
 
36
MS_CVSID("$Id: mapoglcontext.cpp 11512 2011-04-09 08:46:51Z toby $")
 
37
 
14
38
#define _T(x) __TEXT(x)
15
39
 
16
40
ms_uint32 OglContext::MAX_MULTISAMPLE_SAMPLES = 16;
20
44
OglContext* OglContext::current = NULL;
21
45
 
22
46
OglContext::OglContext(ms_uint32 width, ms_uint32 height)
23
 
{
24
 
        if (!window) initWindow();
25
 
        if (!sharingContext) initSharingContext();
26
 
        createPBuffer(width, height);
27
 
        makeCurrent();
 
47
    : valid(false)
 
48
{
 
49
    if (!window && !initWindow()) return;
 
50
    if (!sharingContext && !initSharingContext()) return;
 
51
 
 
52
    if (!(this->width = getTextureSize(GL_TEXTURE_WIDTH, width))) return;
 
53
    if (!(this->height = getTextureSize(GL_TEXTURE_HEIGHT, height))) return;
 
54
 
 
55
    if (!createPBuffer(this->width, this->height)) return;
 
56
    if (!makeCurrent()) return;    
 
57
    valid = true;
 
58
}
 
59
 
 
60
ms_uint32 OglContext::getTextureSize(GLuint dimension, ms_uint32 value)
 
61
{
 
62
    glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA,  value, value, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
 
63
    GLint check = 0;
 
64
    glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, dimension, &check);
 
65
 
 
66
    if (glGetError() != GL_NO_ERROR)
 
67
    {
 
68
        msSetError(MS_OGLERR, "glGetTexLevelParameteriv failed. glError: %d", "OglContext::getTextureSize()", glGetError());
 
69
    }
 
70
 
 
71
    if (check == 0)
 
72
    {
 
73
        return MS_MAX(MS_MIN(NextPowerOf2(value), OglContext::MAX_TEXTURE_SIZE), OglContext::MIN_TEXTURE_SIZE);
 
74
    }
 
75
    else
 
76
    {
 
77
        msSetError(MS_OGLERR, "Unable to create opengl texture of map size", "OglContext::getTextureSize()");
 
78
        return value;
 
79
    }
 
80
}
 
81
 
 
82
GLuint OglContext::NextPowerOf2(GLuint in)
 
83
{
 
84
    in -= 1;
 
85
 
 
86
    in |= in >> 16;
 
87
    in |= in >> 8;
 
88
    in |= in >> 4;
 
89
    in |= in >> 2;
 
90
    in |= in >> 1;
 
91
 
 
92
    return in + 1;
28
93
}
29
94
 
30
95
#if defined(_WIN32) && !defined(__CYGWIN__)
33
98
HGLRC OglContext::sharingContext = NULL;
34
99
 
35
100
LRESULT CALLBACK WndProc(HWND hWnd,
36
 
                UINT message,
37
 
                WPARAM wParam,
38
 
                LPARAM lParam)
 
101
        UINT message,
 
102
        WPARAM wParam,
 
103
        LPARAM lParam)
39
104
{
40
 
        return(1L);
 
105
    return(1L);
41
106
}
42
107
 
43
108
OglContext::~OglContext()
44
109
{
45
 
        //TODO
 
110
    //TODO
46
111
}
47
112
 
48
113
bool OglContext::makeCurrent()
49
114
{
50
 
        if (current != this)
51
 
        {
52
 
                current = this;
53
 
                if (!wglMakeContextCurrentARB(hPBufferDC, hPBufferDC, hPBufferRC))
54
 
                {
55
 
                        msSetError(MS_OGLERR, "Can't Activate The GL Rendering pbuffer.", "OglContext::makeCurrent()");
56
 
                        return FALSE;
57
 
                }
58
 
        }
59
 
        return true;
 
115
    if (current != this)
 
116
    {
 
117
        current = this;
 
118
        if (!wglMakeContextCurrentARB(hPBufferDC, hPBufferDC, hPBufferRC))
 
119
        {
 
120
            msSetError(MS_OGLERR, "Can't Activate The GL Rendering pbuffer.", "OglContext::makeCurrent()");
 
121
            return FALSE;
 
122
        }
 
123
    }
 
124
    return true;
60
125
}
61
126
 
62
127
bool OglContext::initWindow()
63
128
{
64
 
        int windowPixelFormat;
65
 
        WNDCLASS wc;
66
 
        DWORD dwExStyle;
67
 
        DWORD dwStyle;
68
 
        RECT WindowRect;
69
 
        HMODULE hInstance = NULL;
70
 
        HWND hWnd = 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;
77
 
        wc.cbClsExtra = 0;
78
 
        wc.cbWndExtra = 0;
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");
86
 
 
87
 
        if (!RegisterClass(&wc))
88
 
        {
89
 
                msSetError(MS_OGLERR, "Failed To Register The Window Class.", "OglContext::initWindow()");
90
 
                return FALSE;
91
 
        }
92
 
        dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
93
 
        dwStyle=WS_OVERLAPPEDWINDOW;
94
 
 
95
 
        AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
96
 
 
97
 
        if (!(hWnd=CreateWindowEx( dwExStyle,
98
 
                                                        _T("OpenGL"),
99
 
                                                        _T("temp"),
100
 
                                                        dwStyle |
101
 
                                                        WS_CLIPSIBLINGS |
102
 
                                                        WS_CLIPCHILDREN,
103
 
                                                        0, 0,
104
 
                                                        WindowRect.right-WindowRect.left,
105
 
                                                        WindowRect.bottom-WindowRect.top,
106
 
                                                        NULL,
107
 
                                                        NULL,
108
 
                                                        hInstance,
109
 
                                                        NULL)))
110
 
        {
111
 
                msSetError(MS_OGLERR, "Window Creation Error.", "OglContext::initWindow()");
112
 
                return FALSE;
113
 
        }
114
 
 
115
 
        static PIXELFORMATDESCRIPTOR pfd=
116
 
        {
117
 
                sizeof(PIXELFORMATDESCRIPTOR),
118
 
                1,
119
 
                PFD_DRAW_TO_WINDOW |
120
 
                PFD_SUPPORT_OPENGL |
121
 
                PFD_DOUBLEBUFFER,
122
 
                PFD_TYPE_RGBA,
123
 
                24, // Select Our Color Depth
124
 
                0, 0, 0, 0, 0, 0, // Color Bits Ignored
125
 
                8, // Alpha Buffer
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
133
 
                0, // Reserved
134
 
                0, 0, 0 // Layer Masks Ignored
135
 
        };
136
 
 
137
 
        if (!(window=GetDC(hWnd)))
138
 
        {
139
 
                msSetError(MS_OGLERR, "Can't Create A GL Device Context.", "OglContext::initWindow()");
140
 
                return FALSE;
141
 
        }
142
 
 
143
 
        if (!(windowPixelFormat=ChoosePixelFormat(window,&pfd)))
144
 
        {
145
 
                msSetError(MS_OGLERR, "Can't Find A Suitable windowPixelFormat.", "OglContext::initWindow()");
146
 
                return FALSE;
147
 
        }
148
 
 
149
 
        if(!SetPixelFormat(window,windowPixelFormat,&pfd))
150
 
        {
151
 
                msSetError(MS_OGLERR, "Can't Set The windowPixelFormat.", "OglContext::initWindow()");
152
 
                return FALSE;
153
 
        }
154
 
        return TRUE;
 
129
    int windowPixelFormat;
 
130
    WNDCLASS wc;
 
131
    DWORD dwExStyle;
 
132
    DWORD dwStyle;
 
133
    RECT WindowRect;
 
134
    HMODULE hInstance = NULL;
 
135
    HWND hWnd = 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;
 
142
    wc.cbClsExtra = 0;
 
143
    wc.cbWndExtra = 0;
 
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");
 
151
 
 
152
    if (!RegisterClass(&wc))
 
153
    {
 
154
        msSetError(MS_OGLERR, "Failed To Register The Window Class.", "OglContext::initWindow()");
 
155
        return FALSE;
 
156
    }
 
157
    dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
 
158
    dwStyle=WS_OVERLAPPEDWINDOW;
 
159
 
 
160
    AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
 
161
 
 
162
    if (!(hWnd=CreateWindowEx( dwExStyle,
 
163
                            _T("OpenGL"),
 
164
                            _T("temp"),
 
165
                            dwStyle |
 
166
                            WS_CLIPSIBLINGS |
 
167
                            WS_CLIPCHILDREN,
 
168
                            0, 0,
 
169
                            WindowRect.right-WindowRect.left,
 
170
                            WindowRect.bottom-WindowRect.top,
 
171
                            NULL,
 
172
                            NULL,
 
173
                            hInstance,
 
174
                            NULL)))
 
175
    {
 
176
        msSetError(MS_OGLERR, "Window Creation Error.", "OglContext::initWindow()");
 
177
        return FALSE;
 
178
    }
 
179
 
 
180
    static PIXELFORMATDESCRIPTOR pfd=
 
181
    {
 
182
        sizeof(PIXELFORMATDESCRIPTOR),
 
183
        1,
 
184
        PFD_DRAW_TO_WINDOW |
 
185
        PFD_SUPPORT_OPENGL |
 
186
        PFD_DOUBLEBUFFER,
 
187
        PFD_TYPE_RGBA,
 
188
        24, // Select Our Color Depth
 
189
        0, 0, 0, 0, 0, 0, // Color Bits Ignored
 
190
        8, // Alpha Buffer
 
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
 
198
        0, // Reserved
 
199
        0, 0, 0 // Layer Masks Ignored
 
200
    };
 
201
 
 
202
    if (!(window=GetDC(hWnd)))
 
203
    {
 
204
        msSetError(MS_OGLERR, "Can't Create A GL Device Context.. Last Error: %d", "OglContext::initWindow()", GetLastError());
 
205
        return FALSE;
 
206
    }
 
207
 
 
208
    if (!(windowPixelFormat=ChoosePixelFormat(window,&pfd)))
 
209
    {
 
210
        msSetError(MS_OGLERR, "Can't Find A Suitable windowPixelFormat. Last Error: %d", "OglContext::initWindow()", GetLastError());
 
211
        return FALSE;
 
212
    }
 
213
 
 
214
    if(!SetPixelFormat(window,windowPixelFormat,&pfd))
 
215
    {
 
216
        msSetError(MS_OGLERR, "Can't Set The windowPixelFormat. Last Error: %d", "OglContext::initWindow()", GetLastError());
 
217
        return FALSE;
 
218
    }
 
219
    return TRUE;
155
220
}
156
221
 
157
222
bool OglContext::initSharingContext()
158
223
{
159
 
        if (!(sharingContext=wglCreateContext(window)))
160
 
        {
161
 
                msSetError(MS_OGLERR, "Can't Create A GL Rendering Context.", "OglContext::createContext()");
162
 
                return FALSE;
163
 
        }
164
 
 
165
 
        if(!wglMakeCurrent(window,sharingContext))
166
 
        {
167
 
                msSetError(MS_OGLERR, "Can't Activate The GL Rendering Context.", "OglContext::createContext()");
168
 
                return FALSE;
169
 
        }
170
 
 
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");
184
 
 
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");
193
 
 
194
 
        glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*) &MAX_ANISOTROPY);
195
 
        glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&MAX_TEXTURE_SIZE);
196
 
 
197
 
        MIN_TEXTURE_SIZE = 8;
198
 
 
199
 
 
200
 
        return TRUE;
 
224
    if (!(sharingContext=wglCreateContext(window)))
 
225
    {
 
226
        msSetError(MS_OGLERR, "Can't Create A GL Rendering Context.", "OglContext::createContext()");
 
227
        return FALSE;
 
228
    }
 
229
 
 
230
    if(!wglMakeCurrent(window,sharingContext))
 
231
    {
 
232
        msSetError(MS_OGLERR, "Can't Activate The GL Rendering Context.", "OglContext::createContext()");
 
233
        return FALSE;
 
234
    }
 
235
 
 
236
    if (!(wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB")))
 
237
    {
 
238
        msSetError(MS_OGLERR, "unable to retreive wglChoosePixelFormatARB method.", "OglContext::createContext()");
 
239
        return FALSE;
 
240
    }
 
241
    
 
242
    if (!(wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB")))
 
243
    {
 
244
        msSetError(MS_OGLERR, "unable to retreive wglCreatePbufferARB method.", "OglContext::createContext()");
 
245
        return FALSE;
 
246
    }
 
247
    
 
248
    if (!(wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB")))
 
249
    {
 
250
        msSetError(MS_OGLERR, "unable to retreive wglGetPbufferDCARB method.", "OglContext::createContext()");
 
251
        return FALSE;
 
252
    }
 
253
    
 
254
    if (!(wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB")))
 
255
    {
 
256
        msSetError(MS_OGLERR, "unable to retreive wglReleasePbufferDCARB method.", "OglContext::createContext()");
 
257
        return FALSE;
 
258
    }
 
259
    
 
260
    if (!(wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB")))
 
261
    {
 
262
        msSetError(MS_OGLERR, "unable to retreive wglMakeContextCurrentARB method.", "OglContext::createContext()");
 
263
        return FALSE;
 
264
    }
 
265
 
 
266
    glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*) &MAX_ANISOTROPY);
 
267
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&MAX_TEXTURE_SIZE);
 
268
 
 
269
    MIN_TEXTURE_SIZE = 8;
 
270
 
 
271
 
 
272
    return TRUE;
201
273
}
202
274
 
203
275
bool OglContext::createPBuffer(ms_uint32 width, ms_uint32 height)
204
276
{
205
 
        HPBUFFERARB hPBuffer = NULL;
206
 
        hPBufferDC = NULL;
207
 
        hPBufferRC = NULL;
208
 
 
209
 
        int pixelFormat;
210
 
        int valid = false;
211
 
        UINT numFormats;
212
 
        float fAttributes[] = {0,0};
213
 
        int samples = MAX_MULTISAMPLE_SAMPLES;
214
 
 
215
 
        while (!valid && samples >= 0)
216
 
        {
217
 
                int iAttributes[] =
218
 
                {
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,
229
 
                        0,0
230
 
                };
231
 
 
232
 
                valid = wglChoosePixelFormatARB(window,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
233
 
        }
234
 
        if(numFormats == 0)
235
 
        {
236
 
                msSetError(MS_OGLERR, "P-buffer Error: Unable to find an acceptable pixel format.", "OglContext::createPBuffer()");
237
 
                return FALSE;
238
 
        }
239
 
 
240
 
        if (!(hPBuffer = wglCreatePbufferARB(window, pixelFormat, width, height, 0)))
241
 
        {
242
 
                msSetError(MS_OGLERR, "P-buffer Error: Unable to create P-buffer.", "OglContext::createPBuffer()");
243
 
                return FALSE;
244
 
        }
245
 
        if (!(hPBufferDC = wglGetPbufferDCARB(hPBuffer)))
246
 
        {
247
 
                msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC.", "OglContext::createPBuffer()");
248
 
                return FALSE;
249
 
        }
250
 
        if (!(hPBufferRC = wglCreateContext(hPBufferDC)))
251
 
        {
252
 
                msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC.", "OglContext::createPBuffer()");
253
 
                return FALSE;
254
 
        }
255
 
 
256
 
        if (wglShareLists(sharingContext,hPBufferRC) == FALSE)
257
 
        {
258
 
                msSetError(MS_OGLERR, "P-buffer Error: Unable to share display lists.", "OglContext::createPBuffer()");
259
 
                return FALSE;
260
 
        }
261
 
 
262
 
        return TRUE;
 
277
    HPBUFFERARB hPBuffer = NULL;
 
278
    hPBufferDC = NULL;
 
279
    hPBufferRC = NULL;
 
280
 
 
281
    int pixelFormat;
 
282
    int valid = false;
 
283
    UINT numFormats = 0;
 
284
    float fAttributes[] = {0,0};
 
285
    int samples = MAX_MULTISAMPLE_SAMPLES;
 
286
 
 
287
    while ((!valid || numFormats == 0) && samples >= 0)
 
288
    {
 
289
        int iAttributes[] =
 
290
        {
 
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,            
 
301
            0,0
 
302
        };
 
303
 
 
304
        valid = wglChoosePixelFormatARB(window,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
 
305
        if (!valid || numFormats == 0) samples -= 2;
 
306
    }    
 
307
 
 
308
    if(numFormats == 0)
 
309
    {
 
310
        msSetError(MS_OGLERR, "P-buffer Error: Unable to find an acceptable pixel format.", "OglContext::createPBuffer()");
 
311
        return FALSE;
 
312
    }
 
313
 
 
314
    if (!(hPBuffer = wglCreatePbufferARB(window, pixelFormat, width, height, 0)))
 
315
    {
 
316
        msSetError(MS_OGLERR, "P-buffer Error: Unable to create P-buffer. glError: %d", "OglContext::createPBuffer()", glGetError());
 
317
        return FALSE;
 
318
    }
 
319
    if (!(hPBufferDC = wglGetPbufferDCARB(hPBuffer)))
 
320
    {
 
321
        msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC. glError: %d", "OglContext::createPBuffer()", glGetError());
 
322
        return FALSE;
 
323
    }
 
324
    if (!(hPBufferRC = wglCreateContext(hPBufferDC)))
 
325
    {
 
326
        msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC. glError: %d", "OglContext::createPBuffer()", glGetError());
 
327
        return FALSE;
 
328
    }
 
329
 
 
330
    if (wglShareLists(sharingContext,hPBufferRC) == FALSE)
 
331
    {
 
332
        msSetError(MS_OGLERR, "P-buffer Error: Unable to share display lists. glError: %d", "OglContext::createPBuffer()", glGetError());
 
333
        return FALSE;
 
334
    }
 
335
 
 
336
    return TRUE;
263
337
}
264
338
 
 
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;
 
344
 
265
345
#else /* UNIX */
266
346
 
267
347
Display* OglContext::window = NULL;
270
350
 
271
351
OglContext::~OglContext()
272
352
{
273
 
        //TODO
 
353
    //TODO
274
354
}
275
355
 
276
356
 
277
357
bool OglContext::makeCurrent()
278
358
{
279
 
        if (current != this)
280
 
        {
281
 
                current = this;
282
 
                glXMakeCurrent(window, pbuffer, sharingContext);
283
 
        }
284
 
        return true;
 
359
    if (current != this)
 
360
    {
 
361
        current = this;
 
362
        if (!glXMakeCurrent(window, pbuffer, sharingContext))
 
363
        {
 
364
            msSetError(MS_OGLERR, "glXMakeCurrent failed. glError: %d", "OglContext::makeCurrent()", glGetError());
 
365
            return false;
 
366
        }
 
367
    }
 
368
    return true;
285
369
}
286
370
 
287
371
bool OglContext::initSharingContext()
288
372
{
289
 
        int fb_attributes[] =
290
 
        {
291
 
                GLX_SAMPLES_ARB, MAX_MULTISAMPLE_SAMPLES,
292
 
                GLX_RENDER_TYPE, GLX_RGBA_BIT,
293
 
                GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
294
 
                GLX_RED_SIZE, 8,
295
 
                GLX_GREEN_SIZE, 8,
296
 
                GLX_BLUE_SIZE, 8,
297
 
                GLX_ALPHA_SIZE, 8,
298
 
                GLX_DEPTH_SIZE, 16,
299
 
                GLX_DOUBLEBUFFER, 0,
300
 
                GLX_SAMPLE_BUFFERS_ARB, 1,
301
 
                0
302
 
        };
303
 
 
304
 
        int num_configs = 0;
305
 
        while (num_configs == 0 && fb_attributes[1] >= 0)
306
 
        {
307
 
                configs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
308
 
                fb_attributes[1] -= 2;
309
 
        }
310
 
 
311
 
        if (configs == NULL || num_configs == 0)
312
 
        {
313
 
                msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs.", "OglContext::init()");
314
 
                return false;
315
 
        }
316
 
 
317
 
        sharingContext = glXCreateNewContext(window, *configs, GLX_RGBA_TYPE, NULL, 1);
318
 
        if (sharingContext == NULL)
319
 
        {
320
 
                msSetError(MS_OGLERR, "glXCreateNewContext failed.", "OglContext::initSharingContext()");
321
 
                return false;
322
 
        }
323
 
 
324
 
        return true;
 
373
    int fb_attributes[] =
 
374
    {
 
375
        GLX_SAMPLES_ARB, MAX_MULTISAMPLE_SAMPLES,
 
376
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
 
377
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
 
378
        GLX_RED_SIZE, 8,
 
379
        GLX_GREEN_SIZE, 8,
 
380
        GLX_BLUE_SIZE, 8,
 
381
        GLX_ALPHA_SIZE, 8,
 
382
        GLX_DEPTH_SIZE, 16,
 
383
        GLX_DOUBLEBUFFER, 0,
 
384
        GLX_SAMPLE_BUFFERS_ARB, 1,
 
385
        0
 
386
    };
 
387
 
 
388
    int num_configs = 0;
 
389
    while (num_configs == 0 && fb_attributes[1] >= 0)
 
390
    {
 
391
        configs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
 
392
        fb_attributes[1] -= 2;
 
393
    }
 
394
 
 
395
    if (configs == NULL || num_configs == 0)
 
396
    {
 
397
        msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs. Likely your video card or drivers are not supported. glError: %d", "OglContext::init()", glGetError());
 
398
        return false;
 
399
    }
 
400
 
 
401
    sharingContext = glXCreateNewContext(window, *configs, GLX_RGBA_TYPE, NULL, 1);
 
402
    if (sharingContext == NULL)
 
403
    {
 
404
        msSetError(MS_OGLERR, "glXCreateNewContext failed. glError: %d", "OglContext::initSharingContext()", glGetError());
 
405
        return false;
 
406
    }
 
407
 
 
408
    return true;
325
409
}
326
410
 
327
411
bool OglContext::createPBuffer(ms_uint32 width, ms_uint32 height)
328
412
{
329
 
        int maxHeight, maxWidth;
330
 
 
331
 
        glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_WIDTH, &maxWidth);
332
 
        glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_HEIGHT, &maxHeight);
333
 
 
334
 
        ms_uint32 uMaxHeight = maxHeight, uMaxWidth = maxWidth;
335
 
 
336
 
        this->width = MS_MIN(width, uMaxWidth);
337
 
        this->height = MS_MIN(height, uMaxHeight);
338
 
 
339
 
        int iPbufferAttributes[] =
340
 
        {
341
 
                        GLX_PBUFFER_WIDTH, this->width,
342
 
                        GLX_PBUFFER_HEIGHT, this->height,
343
 
                        GLX_LARGEST_PBUFFER, false,
344
 
                        0, 0
345
 
        };
346
 
 
347
 
        pbuffer = glXCreatePbuffer(window, *configs, iPbufferAttributes);
348
 
        if (pbuffer == 0)
349
 
        {
350
 
                msSetError(MS_OGLERR, "glXCreatePbuffer failed.", "OglContext::init()");
351
 
                return false;
352
 
        }
353
 
 
354
 
        return true;
 
413
    int maxHeight, maxWidth;
 
414
 
 
415
    glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_WIDTH, &maxWidth);
 
416
    glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_HEIGHT, &maxHeight);
 
417
 
 
418
    ms_uint32 uMaxHeight = maxHeight, uMaxWidth = maxWidth;
 
419
 
 
420
    this->width = MS_MIN(width, uMaxWidth);
 
421
    this->height = MS_MIN(height, uMaxHeight);
 
422
 
 
423
    int iPbufferAttributes[] =
 
424
    {
 
425
            GLX_PBUFFER_WIDTH, this->width,
 
426
            GLX_PBUFFER_HEIGHT, this->height,
 
427
            GLX_LARGEST_PBUFFER, false,
 
428
            0, 0
 
429
    };
 
430
 
 
431
    pbuffer = glXCreatePbuffer(window, *configs, iPbufferAttributes);
 
432
    if (pbuffer == 0)
 
433
    {
 
434
        msSetError(MS_OGLERR, "glXCreatePbuffer failed. glError: %d", "OglContext::init()", glGetError());
 
435
        return false;
 
436
    }
 
437
 
 
438
    return true;
355
439
}
356
440
 
357
441
bool OglContext::initWindow()
358
442
{
359
 
        const char* const display_name = getenv("DISPLAY");
360
 
        if (!display_name)
361
 
        {
362
 
                msSetError(MS_OGLERR, "DISPLAY environment variable not set", "OglContext::init()");
363
 
                return false;
364
 
        }
365
 
 
366
 
        window = XOpenDisplay(display_name);
367
 
 
368
 
        const int fb_attributes[] = {
369
 
                        GLX_RENDER_TYPE, GLX_RGBA_BIT,
370
 
                        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
371
 
                        GLX_RED_SIZE, 8,
372
 
                        GLX_GREEN_SIZE, 8,
373
 
                        GLX_BLUE_SIZE, 8,
374
 
                        GLX_ALPHA_SIZE, 8,
375
 
                        GLX_DEPTH_SIZE, 16,
376
 
                        GLX_DOUBLEBUFFER, 0,
377
 
                        GLX_SAMPLE_BUFFERS_ARB, 1,
378
 
                        0
379
 
                };
380
 
 
381
 
        int num_configs = 0;
382
 
        GLXFBConfig* tempConfigs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
383
 
 
384
 
        if (tempConfigs == NULL || num_configs == 0)
385
 
        {
386
 
                msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs.", "OglContext::initWindow()");
387
 
                return false;
388
 
        }
389
 
 
390
 
        GLXContext tempContext = glXCreateNewContext(window, *tempConfigs, GLX_RGBA_TYPE, NULL, 1);
391
 
        if (tempContext == NULL)
392
 
        {
393
 
                msSetError(MS_OGLERR, "glXCreateNewContext failed.", "OglContext::initWindow()");
394
 
                return false;
395
 
        }
396
 
 
397
 
        int iPbufferAttributes[] =      {0, 0};
398
 
 
399
 
        GLXPbuffer tempBuffer = glXCreatePbuffer(window, *tempConfigs, iPbufferAttributes);
400
 
        if (tempBuffer == 0)
401
 
        {
402
 
                msSetError(MS_OGLERR, "glXCreatePbuffer failed.", "OglContext::initWindow()");
403
 
                return false;
404
 
        }
405
 
 
406
 
        glXMakeCurrent(window, tempBuffer, tempContext);
407
 
 
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);
411
 
 
412
 
        MIN_TEXTURE_SIZE = 8;
413
 
 
414
 
        return true;
415
 
}
416
 
 
417
 
#endif /* WIN32 */
418
 
 
419
 
#if defined(_WIN32) && !defined(__CYGWIN__)
420
 
 
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;
434
 
 
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
443
 
 
444
 
#endif
445
 
 
446
 
/*
447
 
HDC OglContext::hWINDOWDC = NULL;
448
 
HGLRC OglContext::hWINDOWRC = NULL;
449
 
int OglContext::windowPixelFormat = 0;
450
 
 
451
 
HPBUFFERARB OglContext::hPBuffer = NULL;
452
 
HDC OglContext::hPBufferDC = NULL;
453
 
HGLRC OglContext::hPBufferRC = NULL;
454
 
 
455
 
// P-Buffer for texture rendering.
456
 
HPBUFFERARB OglContext::hTexPBuffer = NULL;
457
 
HDC OglContext::hTexPBufferDC = NULL;
458
 
HGLRC OglContext::hTexPBufferRC = NULL;
459
 
 
460
 
bool OglContext::init()
461
 
{
462
 
        WNDCLASS wc;
463
 
        DWORD dwExStyle;
464
 
        DWORD dwStyle;
465
 
        RECT WindowRect;
466
 
        HMODULE hInstance = NULL;
467
 
        HWND hWnd = 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;
474
 
        wc.cbClsExtra = 0;
475
 
        wc.cbWndExtra = 0;
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";
483
 
 
484
 
        if (!RegisterClass(&wc))
485
 
        {
486
 
                printError("Failed To Register The Window Class.");
487
 
                return FALSE;
488
 
        }
489
 
        dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
490
 
        dwStyle=WS_OVERLAPPEDWINDOW;
491
 
 
492
 
        AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
493
 
 
494
 
        if (!(hWnd=CreateWindowEx( dwExStyle,
495
 
                                                        L"OpenGL",
496
 
                                                        L"temp",
497
 
                                                        dwStyle |
498
 
                                                        WS_CLIPSIBLINGS |
499
 
                                                        WS_CLIPCHILDREN,
500
 
                                                        0, 0,
501
 
                                                        WindowRect.right-WindowRect.left,
502
 
                                                        WindowRect.bottom-WindowRect.top,
503
 
                                                        NULL,
504
 
                                                        NULL,
505
 
                                                        hInstance,
506
 
                                                        NULL)))
507
 
        {
508
 
                printError("Window Creation Error.");
509
 
                return FALSE;
510
 
        }
511
 
 
512
 
        static PIXELFORMATDESCRIPTOR pfd=
513
 
        {
514
 
                sizeof(PIXELFORMATDESCRIPTOR),
515
 
                1,
516
 
                PFD_DRAW_TO_WINDOW |
517
 
                PFD_SUPPORT_OPENGL |
518
 
                PFD_DOUBLEBUFFER,
519
 
                PFD_TYPE_RGBA,
520
 
                24, // Select Our Color Depth
521
 
                0, 0, 0, 0, 0, 0, // Color Bits Ignored
522
 
                8, // Alpha Buffer
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
530
 
                0, // Reserved
531
 
                0, 0, 0 // Layer Masks Ignored
532
 
        };
533
 
 
534
 
        if (!(hWINDOWDC=GetDC(hWnd)))
535
 
        {
536
 
                printError("Can't Create A GL Device Context.");
537
 
                return FALSE;
538
 
        }
539
 
 
540
 
        if (!(windowPixelFormat=ChoosePixelFormat(hWINDOWDC,&pfd)))
541
 
        {
542
 
                printError("Can't Find A Suitable windowPixelFormat.");
543
 
                return FALSE;
544
 
        }
545
 
 
546
 
        if(!SetPixelFormat(hWINDOWDC,windowPixelFormat,&pfd))
547
 
        {
548
 
                printError("Can't Set The windowPixelFormat.");
549
 
                return FALSE;
550
 
        }
551
 
 
552
 
        if (!(hWINDOWRC=wglCreateContext(hWINDOWDC)))
553
 
        {
554
 
                printError("Can't Create A GL Rendering Context.");
555
 
                return FALSE;
556
 
        }
557
 
 
558
 
        if(!wglMakeCurrent(hWINDOWDC,hWINDOWRC))
559
 
        {
560
 
                printError("Can't Activate The GL Rendering Context.");
561
 
                return FALSE;
562
 
        }
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");
576
 
 
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");
585
 
 
586
 
        loadShapes();
587
 
 
588
 
        hPBufferRC = NULL;
589
 
        hPBufferDC = NULL;
590
 
        hPBuffer = NULL;
591
 
        int pixelFormat;
592
 
        int valid;
593
 
        UINT numFormats;
594
 
        float fAttributes[] =
595
 
        {       0,0};
596
 
        int iAttributes[] =
597
 
        {
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,
608
 
                0,0
609
 
        };
610
 
 
611
 
        valid = wglChoosePixelFormatARB(hWINDOWDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
612
 
        if(numFormats == 0)
613
 
        {
614
 
                printError("P-buffer Error: Unable to find an acceptable pixel format");
615
 
                return FALSE;
616
 
        }
617
 
 
618
 
        if (!(hPBuffer = wglCreatePbufferARB(hWINDOWDC, pixelFormat, MAX_WIDTH, MAX_HEIGHT, 0)))
619
 
        {
620
 
                printError("P-buffer Error: Unable to create P-buffer");
621
 
                return FALSE;
622
 
        }
623
 
        if (!(hPBufferDC = wglGetPbufferDCARB(hPBuffer)))
624
 
        {
625
 
                printError("P-buffer Error: Unable to get P-buffer DC");
626
 
                return FALSE;
627
 
        }
628
 
        if (!(hPBufferRC = wglCreateContext(hPBufferDC)))
629
 
        {
630
 
                printError("P-buffer Error: Unable to get P-buffer DC");
631
 
                return FALSE;
632
 
        }
633
 
 
634
 
        if (wglShareLists(hWINDOWRC,hPBufferRC) == FALSE)
635
 
        {
636
 
                printError("P-buffer Error: Unable to share display lists");
637
 
                return FALSE;
638
 
        }
639
 
 
640
 
        initialised = true;
641
 
}
642
 
 
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;
656
 
 
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
665
 
 
666
 
LRESULT CALLBACK WndProc(HWND hWnd,
667
 
                UINT message,
668
 
                WPARAM wParam,
669
 
                LPARAM lParam)
670
 
{
671
 
        return(1L);
672
 
}
673
 
 
674
 
#endif
675
 
*/
 
443
    const char* const display_name = getenv("DISPLAY");
 
444
    if (!display_name)
 
445
    {
 
446
        msSetError(MS_OGLERR, "DISPLAY environment variable not set", "OglContext::init()");
 
447
        return false;
 
448
    }
 
449
 
 
450
    window = XOpenDisplay(display_name);
 
451
    if (!window)
 
452
    {
 
453
        msSetError(MS_OGLERR, "XOpenDisplay() failed.", "OglContext::init()");
 
454
        return false;
 
455
    }
 
456
 
 
457
    const int fb_attributes[] = {
 
458
            GLX_RENDER_TYPE, GLX_RGBA_BIT,
 
459
            GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
 
460
            GLX_RED_SIZE, 8,
 
461
            GLX_GREEN_SIZE, 8,
 
462
            GLX_BLUE_SIZE, 8,
 
463
            GLX_ALPHA_SIZE, 8,
 
464
            GLX_DEPTH_SIZE, 16,
 
465
            GLX_DOUBLEBUFFER, 0,
 
466
            GLX_SAMPLE_BUFFERS_ARB, 1,
 
467
            0
 
468
        };
 
469
 
 
470
    int num_configs = 0;
 
471
    GLXFBConfig* tempConfigs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);
 
472
 
 
473
    if (tempConfigs == NULL || num_configs == 0)
 
474
    {
 
475
        msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs. Likely your video card or drivers are not supported.", "OglContext::initWindow()");
 
476
        return false;
 
477
    }
 
478
 
 
479
    GLXContext tempContext = glXCreateNewContext(window, *tempConfigs, GLX_RGBA_TYPE, NULL, 1);
 
480
    if (tempContext == NULL)
 
481
    {
 
482
        msSetError(MS_OGLERR, "glXCreateNewContext failed.", "OglContext::initWindow()");
 
483
        return false;
 
484
    }
 
485
 
 
486
    int iPbufferAttributes[] =    {0, 0};
 
487
 
 
488
    GLXPbuffer tempBuffer = glXCreatePbuffer(window, *tempConfigs, iPbufferAttributes);
 
489
    if (tempBuffer == 0)
 
490
    {
 
491
        msSetError(MS_OGLERR, "glXCreatePbuffer failed.", "OglContext::initWindow()");
 
492
        return false;
 
493
    }
 
494
 
 
495
    if (!glXMakeCurrent(window, tempBuffer, tempContext))
 
496
    {
 
497
        msSetError(MS_OGLERR, "glXMakeCurrent failed.", "OglContext::initWindow()");
 
498
        return false;
 
499
    }
 
500
 
 
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);
 
504
 
 
505
    MIN_TEXTURE_SIZE = 8;
 
506
 
 
507
    return true;
 
508
}
 
509
 
 
510
#endif /* UNIX */
676
511
 
677
512
#endif /* USE_OGL */