1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "GLAttribs.h"
21 
22 #include "Renderer/GL.h"
23 
24 #include <wx/glcanvas.h>
25 
26 namespace TrenchBroom {
27     namespace View {
buildAttribs()28         const GLAttribs& buildAttribs() {
29             static bool initialized = false;
30             static GLAttribs attribs;
31             if (initialized)
32                 return attribs;
33 
34             int testAttribs[] =
35             {
36                 // 32 bit depth buffer, 4 samples
37                 WX_GL_RGBA,
38                 WX_GL_DOUBLEBUFFER,
39                 WX_GL_DEPTH_SIZE,       32,
40                 WX_GL_SAMPLE_BUFFERS,   1,
41                 WX_GL_SAMPLES,          4,
42                 0,
43                 // 24 bit depth buffer, 4 samples
44                 WX_GL_RGBA,
45                 WX_GL_DOUBLEBUFFER,
46                 WX_GL_DEPTH_SIZE,       24,
47                 WX_GL_SAMPLE_BUFFERS,   1,
48                 WX_GL_SAMPLES,          4,
49                 0,
50                 // 32 bit depth buffer, 2 samples
51                 WX_GL_RGBA,
52                 WX_GL_DOUBLEBUFFER,
53                 WX_GL_DEPTH_SIZE,       32,
54                 WX_GL_SAMPLE_BUFFERS,   1,
55                 WX_GL_SAMPLES,          2,
56                 0,
57                 // 24 bit depth buffer, 2 samples
58                 WX_GL_RGBA,
59                 WX_GL_DOUBLEBUFFER,
60                 WX_GL_DEPTH_SIZE,       24,
61                 WX_GL_SAMPLE_BUFFERS,   1,
62                 WX_GL_SAMPLES,          2,
63                 0,
64                 // 16 bit depth buffer, 4 samples
65                 WX_GL_RGBA,
66                 WX_GL_DOUBLEBUFFER,
67                 WX_GL_DEPTH_SIZE,       16,
68                 WX_GL_SAMPLE_BUFFERS,   1,
69                 WX_GL_SAMPLES,          4,
70                 0,
71                 // 16 bit depth buffer, 2 samples
72                 WX_GL_RGBA,
73                 WX_GL_DOUBLEBUFFER,
74                 WX_GL_DEPTH_SIZE,       16,
75                 WX_GL_SAMPLE_BUFFERS,   1,
76                 WX_GL_SAMPLES,          2,
77                 0,
78                 // 32 bit depth buffer, no multisampling
79                 WX_GL_RGBA,
80                 WX_GL_DOUBLEBUFFER,
81                 WX_GL_DEPTH_SIZE,       32,
82                 0,
83                 // 24 bit depth buffer, no multisampling
84                 WX_GL_RGBA,
85                 WX_GL_DOUBLEBUFFER,
86                 WX_GL_DEPTH_SIZE,       24,
87                 0,
88                 // 16 bit depth buffer, no multisampling
89                 WX_GL_RGBA,
90                 WX_GL_DOUBLEBUFFER,
91                 WX_GL_DEPTH_SIZE,       16,
92                 0,
93                 0,
94             };
95 
96             size_t index = 0;
97             while (!initialized && testAttribs[index] != 0) {
98                 size_t count = 0;
99                 for (; testAttribs[index + count] != 0; ++count);
100                 if (wxGLCanvas::IsDisplaySupported(&testAttribs[index])) {
101                     for (size_t i = 0; i < count; ++i)
102                         attribs.push_back(testAttribs[index + i]);
103                     attribs.push_back(0);
104                     initialized = true;
105                 }
106                 index += count + 1;
107             }
108 
109             assert(initialized);
110             assert(!attribs.empty());
111             return attribs;
112         }
113     }
114 }
115