1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
#include "qglxconvenience.h"
#include <QtCore/QVector>
enum {
XFocusOut = FocusOut,
XFocusIn = FocusIn,
XKeyPress = KeyPress,
XKeyRelease = KeyRelease,
XNone = None,
XRevertToParent = RevertToParent,
XGrayScale = GrayScale,
XCursorShape = CursorShape
};
#undef FocusOut
#undef FocusIn
#undef KeyPress
#undef KeyRelease
#undef None
#undef RevertToParent
#undef GrayScale
#undef CursorShape
#ifdef FontChange
#undef FontChange
#endif
QVector<int> buildSpec(const QPlatformWindowFormat &format)
{
QVector<int> spec(48);
int i = 0;
spec[i++] = GLX_LEVEL;
spec[i++] = 0;
spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = GLX_WINDOW_BIT;
if (format.rgba()) {
spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_RGBA_BIT;
spec[i++] = GLX_RED_SIZE; spec[i++] = (format.redBufferSize() == -1) ? 1 : format.redBufferSize();
spec[i++] = GLX_GREEN_SIZE; spec[i++] = (format.greenBufferSize() == -1) ? 1 : format.greenBufferSize();
spec[i++] = GLX_BLUE_SIZE; spec[i++] = (format.blueBufferSize() == -1) ? 1 : format.blueBufferSize();
if (format.alpha()) {
spec[i++] = GLX_ALPHA_SIZE; spec[i++] = (format.alphaBufferSize() == -1) ? 1 : format.alphaBufferSize();
}
spec[i++] = GLX_ACCUM_RED_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
spec[i++] = GLX_ACCUM_GREEN_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
spec[i++] = GLX_ACCUM_BLUE_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
if (format.alpha()) {
spec[i++] = GLX_ACCUM_ALPHA_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
}
} else {
spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_COLOR_INDEX_BIT; //I'm really not sure if this works....
spec[i++] = GLX_BUFFER_SIZE; spec[i++] = 8;
}
spec[i++] = GLX_DOUBLEBUFFER; spec[i++] = format.doubleBuffer() ? True : False;
spec[i++] = GLX_STEREO; spec[i++] = format.stereo() ? True : False;
if (format.depth()) {
spec[i++] = GLX_DEPTH_SIZE; spec[i++] = (format.depthBufferSize() == -1) ? 1 : format.depthBufferSize();
}
if (format.stencil()) {
spec[i++] = GLX_STENCIL_SIZE; spec[i++] = (format.stencilBufferSize() == -1) ? 1 : format.stencilBufferSize();
}
if (format.sampleBuffers()) {
spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
spec[i++] = 1;
spec[i++] = GLX_SAMPLES_ARB;
spec[i++] = format.samples() == -1 ? 4 : format.samples();
}
spec[i++] = XNone;
return spec;
}
GLXFBConfig findConfig(Display *display, int screen , const QPlatformWindowFormat &format)
{
bool reduced = true;
GLXFBConfig chosenConfig = 0;
QPlatformWindowFormat reducedFormat = format;
while (!chosenConfig && reduced) {
QVector<int> spec = buildSpec(reducedFormat);
int confcount = 0;
GLXFBConfig *configs;
configs = glXChooseFBConfig(display, screen,spec.constData(),&confcount);
if (confcount)
{
for (int i = 0; i < confcount; i++) {
chosenConfig = configs[i];
// Make sure we try to get an ARGB visual if the format asked for an alpha:
if (reducedFormat.alpha()) {
int alphaSize;
glXGetFBConfigAttrib(display,configs[i],GLX_ALPHA_SIZE,&alphaSize);
if (alphaSize > 0)
break;
} else {
break; // Just choose the first in the list if there's no alpha requested
}
}
XFree(configs);
}
reducedFormat = reducePlatformWindowFormat(reducedFormat,&reduced);
}
if (!chosenConfig)
qWarning("Warning no context created");
return chosenConfig;
}
XVisualInfo *findVisualInfo(Display *display, int screen, const QPlatformWindowFormat &format)
{
GLXFBConfig config = findConfig(display,screen,format);
XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display,config);
return visualInfo;
}
QPlatformWindowFormat platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext ctx)
{
QPlatformWindowFormat format;
int redSize = 0;
int greenSize = 0;
int blueSize = 0;
int alphaSize = 0;
int depthSize = 0;
int stencilSize = 0;
int sampleBuffers = 0;
int sampleCount = 0;
int level = 0;
int rgba = 0;
int stereo = 0;
int accumSizeA = 0;
int accumSizeR = 0;
int accumSizeG = 0;
int accumSizeB = 0;
XVisualInfo *vi = glXGetVisualFromFBConfig(display,config);
glXGetConfig(display,vi,GLX_RGBA,&rgba);
XFree(vi);
glXGetFBConfigAttrib(display, config, GLX_RED_SIZE, &redSize);
glXGetFBConfigAttrib(display, config, GLX_GREEN_SIZE, &greenSize);
glXGetFBConfigAttrib(display, config, GLX_BLUE_SIZE, &blueSize);
glXGetFBConfigAttrib(display, config, GLX_ALPHA_SIZE, &alphaSize);
glXGetFBConfigAttrib(display, config, GLX_DEPTH_SIZE, &depthSize);
glXGetFBConfigAttrib(display, config, GLX_STENCIL_SIZE, &stencilSize);
glXGetFBConfigAttrib(display, config, GLX_SAMPLES, &sampleBuffers);
glXGetFBConfigAttrib(display, config, GLX_LEVEL, &level);
glXGetFBConfigAttrib(display, config, GLX_STEREO, &stereo);
glXGetFBConfigAttrib(display, config, GLX_ACCUM_ALPHA_SIZE, &accumSizeA);
glXGetFBConfigAttrib(display, config, GLX_ACCUM_RED_SIZE, &accumSizeR);
glXGetFBConfigAttrib(display, config, GLX_ACCUM_GREEN_SIZE, &accumSizeG);
glXGetFBConfigAttrib(display, config, GLX_ACCUM_BLUE_SIZE, &accumSizeB);
format.setRedBufferSize(redSize);
format.setGreenBufferSize(greenSize);
format.setBlueBufferSize(blueSize);
format.setAlphaBufferSize(alphaSize);
format.setDepthBufferSize(depthSize);
format.setStencilBufferSize(stencilSize);
format.setSampleBuffers(sampleBuffers);
if (format.sampleBuffers()) {
glXGetFBConfigAttrib(display, config, GLX_SAMPLES_ARB, &sampleCount);
format.setSamples(sampleCount);
}
format.setDirectRendering(glXIsDirect(display, ctx));
format.setRgba(rgba);
format.setStereo(stereo);
format.setAccumBufferSize(accumSizeB);
return format;
}
QPlatformWindowFormat reducePlatformWindowFormat(const QPlatformWindowFormat &format, bool *reduced)
{
QPlatformWindowFormat retFormat = format;
*reduced = true;
if (retFormat.sampleBuffers()) {
retFormat.setSampleBuffers(false);
} else if (retFormat.stereo()) {
retFormat.setStereo(false);
} else if (retFormat.accum()) {
retFormat.setAccum(false);
}else if (retFormat.stencil()) {
retFormat.setStencil(false);
}else if (retFormat.alpha()) {
retFormat.setAlpha(false);
}else if (retFormat.depth()) {
retFormat.setDepth(false);
}else if (retFormat.doubleBuffer()) {
retFormat.setDoubleBuffer(false);
}else{
*reduced = false;
}
return retFormat;
}
|