Qt 4.8
Functions
qglxconvenience.h File Reference
#include <QPlatformWindowFormat>
#include <X11/Xlib.h>
#include <GL/glx.h>

Go to the source code of this file.

Functions

QVector< int > qglx_buildSpec (const QPlatformWindowFormat &format, int drawableBit=GLX_WINDOW_BIT)
 
GLXFBConfig qglx_findConfig (Display *display, int screen, const QPlatformWindowFormat &format, int drawableBit=GLX_WINDOW_BIT)
 
XVisualInfo * qglx_findVisualInfo (Display *display, int screen, const QPlatformWindowFormat &format)
 
QPlatformWindowFormat qglx_platformWindowFromGLXFBConfig (Display *display, GLXFBConfig config, GLXContext context)
 
QPlatformWindowFormat qglx_reducePlatformWindowFormat (const QPlatformWindowFormat &format, bool *reduced)
 

Function Documentation

◆ qglx_buildSpec()

QVector<int> qglx_buildSpec ( const QPlatformWindowFormat format,
int  drawableBit = GLX_WINDOW_BIT 
)

Definition at line 73 of file qglxconvenience.cpp.

Referenced by qglx_findConfig().

74 {
75  QVector<int> spec(48);
76  int i = 0;
77 
78  spec[i++] = GLX_LEVEL;
79  spec[i++] = 0;
80  spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = drawableBit;
81 
82  if (format.rgba()) {
83  spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_RGBA_BIT;
84  spec[i++] = GLX_RED_SIZE; spec[i++] = (format.redBufferSize() == -1) ? 1 : format.redBufferSize();
85  spec[i++] = GLX_GREEN_SIZE; spec[i++] = (format.greenBufferSize() == -1) ? 1 : format.greenBufferSize();
86  spec[i++] = GLX_BLUE_SIZE; spec[i++] = (format.blueBufferSize() == -1) ? 1 : format.blueBufferSize();
87  if (format.alpha()) {
88  spec[i++] = GLX_ALPHA_SIZE; spec[i++] = (format.alphaBufferSize() == -1) ? 1 : format.alphaBufferSize();
89  }
90 
91  if (format.accum()) {
92  spec[i++] = GLX_ACCUM_RED_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
93  spec[i++] = GLX_ACCUM_GREEN_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
94  spec[i++] = GLX_ACCUM_BLUE_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
95 
96  if (format.alpha()) {
97  spec[i++] = GLX_ACCUM_ALPHA_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize();
98  }
99  }
100  } else {
101  spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_COLOR_INDEX_BIT; //I'm really not sure if this works....
102  spec[i++] = GLX_BUFFER_SIZE; spec[i++] = 8;
103  }
104 
105  spec[i++] = GLX_DOUBLEBUFFER; spec[i++] = format.doubleBuffer() ? True : False;
106  spec[i++] = GLX_STEREO; spec[i++] = format.stereo() ? True : False;
107 
108  if (format.depth()) {
109  spec[i++] = GLX_DEPTH_SIZE; spec[i++] = (format.depthBufferSize() == -1) ? 1 : format.depthBufferSize();
110  }
111 
112  if (format.stencil()) {
113  spec[i++] = GLX_STENCIL_SIZE; spec[i++] = (format.stencilBufferSize() == -1) ? 1 : format.stencilBufferSize();
114  }
115  if (format.sampleBuffers()) {
116  spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
117  spec[i++] = 1;
118  spec[i++] = GLX_SAMPLES_ARB;
119  spec[i++] = format.samples() == -1 ? 4 : format.samples();
120  }
121 
122  spec[i++] = XNone;
123  return spec;
124 }
int greenBufferSize() const
Returns the green buffer size.
bool rgba() const
Returns true if RGBA color mode is set.
#define GLX_RGBA_BIT
int samples() const
Returns the number of samples per pixel when multisampling is enabled.
int stencilBufferSize() const
Returns the stencil buffer size.
bool doubleBuffer() const
Returns true if double buffering is enabled; otherwise returns false.
bool stereo() const
Returns true if stereo buffering is enabled; otherwise returns false.
#define GLX_SAMPLE_BUFFERS_ARB
Definition: qgl_x11.cpp:96
#define GLX_DRAWABLE_TYPE
#define GLX_RENDER_TYPE
int depthBufferSize() const
Returns the depth buffer size.
int alphaBufferSize() const
Returns the alpha buffer size.
int accumBufferSize() const
Returns the accumulation buffer size.
bool depth() const
Returns true if the depth buffer is enabled; otherwise returns false.
bool accum() const
Returns true if the accumulation buffer is enabled; otherwise returns false.
#define GLX_SAMPLES_ARB
Definition: qgl_x11.cpp:97
bool stencil() const
Returns true if the stencil buffer is enabled; otherwise returns false.
int blueBufferSize() const
Returns the blue buffer size.
int redBufferSize() const
Returns the red buffer size.
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.

◆ qglx_findConfig()

GLXFBConfig qglx_findConfig ( Display display,
int  screen,
const QPlatformWindowFormat format,
int  drawableBit = GLX_WINDOW_BIT 
)

Definition at line 126 of file qglxconvenience.cpp.

Referenced by qglx_findVisualInfo(), and QGLXContext::QGLXContext().

127 {
128  bool reduced = true;
129  GLXFBConfig chosenConfig = 0;
130  QPlatformWindowFormat reducedFormat = format;
131  while (!chosenConfig && reduced) {
132  QVector<int> spec = qglx_buildSpec(reducedFormat, drawableBit);
133  int confcount = 0;
134  GLXFBConfig *configs;
135  configs = glXChooseFBConfig(display, screen,spec.constData(),&confcount);
136  if (confcount)
137  {
138  for (int i = 0; i < confcount; i++) {
139  chosenConfig = configs[i];
140  // Make sure we try to get an ARGB visual if the format asked for an alpha:
141  if (reducedFormat.alpha()) {
142  int alphaSize;
143  glXGetFBConfigAttrib(display,configs[i],GLX_ALPHA_SIZE,&alphaSize);
144  if (alphaSize > 0) {
145  XVisualInfo *visual = glXGetVisualFromFBConfig(display, chosenConfig);
146 #if !defined(QT_NO_XRENDER)
147  XRenderPictFormat *pictFormat = XRenderFindVisualFormat(display, visual->visual);
148  if (pictFormat->direct.alphaMask > 0)
149  break;
150 #else
151  if (visual->depth == 32)
152  break;
153 #endif
154  }
155  } else {
156  break; // Just choose the first in the list if there's no alpha requested
157  }
158  }
159 
160  XFree(configs);
161  }
162  reducedFormat = qglx_reducePlatformWindowFormat(reducedFormat,&reduced);
163  }
164 
165  if (!chosenConfig)
166  qWarning("Warning: no suitable glx confiuration found");
167 
168  return chosenConfig;
169 }
QVector< int > qglx_buildSpec(const QPlatformWindowFormat &format, int drawableBit)
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
#define glXGetFBConfigAttrib
#define glXChooseFBConfig
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QPlatformWindowFormat qglx_reducePlatformWindowFormat(const QPlatformWindowFormat &format, bool *reduced)
Q_CORE_EXPORT void qWarning(const char *,...)
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154

◆ qglx_findVisualInfo()

XVisualInfo* qglx_findVisualInfo ( Display display,
int  screen,
const QPlatformWindowFormat format 
)

Definition at line 171 of file qglxconvenience.cpp.

Referenced by QXcbWindow::QXcbWindow(), and QXlibWindow::QXlibWindow().

172 {
173  GLXFBConfig config = qglx_findConfig(display,screen,format);
174  XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display,config);
175  return visualInfo;
176 }
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
GLXFBConfig qglx_findConfig(Display *display, int screen, const QPlatformWindowFormat &format, int drawableBit)

◆ qglx_platformWindowFromGLXFBConfig()

QPlatformWindowFormat qglx_platformWindowFromGLXFBConfig ( Display display,
GLXFBConfig  config,
GLXContext  context 
)

Definition at line 178 of file qglxconvenience.cpp.

Referenced by QWaylandReadbackGlxContext::platformWindowFormat(), QWaylandXCompositeGLXContext::platformWindowFormat(), and QGLXContext::QGLXContext().

179 {
181  int redSize = 0;
182  int greenSize = 0;
183  int blueSize = 0;
184  int alphaSize = 0;
185  int depthSize = 0;
186  int stencilSize = 0;
187  int sampleBuffers = 0;
188  int sampleCount = 0;
189  int level = 0;
190  int rgba = 0;
191  int stereo = 0;
192  int accumSizeA = 0;
193  int accumSizeR = 0;
194  int accumSizeG = 0;
195  int accumSizeB = 0;
196 
197  XVisualInfo *vi = glXGetVisualFromFBConfig(display,config);
198  glXGetConfig(display,vi,GLX_RGBA,&rgba);
199  XFree(vi);
200  glXGetFBConfigAttrib(display, config, GLX_RED_SIZE, &redSize);
201  glXGetFBConfigAttrib(display, config, GLX_GREEN_SIZE, &greenSize);
202  glXGetFBConfigAttrib(display, config, GLX_BLUE_SIZE, &blueSize);
203  glXGetFBConfigAttrib(display, config, GLX_ALPHA_SIZE, &alphaSize);
204  glXGetFBConfigAttrib(display, config, GLX_DEPTH_SIZE, &depthSize);
205  glXGetFBConfigAttrib(display, config, GLX_STENCIL_SIZE, &stencilSize);
206  glXGetFBConfigAttrib(display, config, GLX_SAMPLES, &sampleBuffers);
207  glXGetFBConfigAttrib(display, config, GLX_LEVEL, &level);
208  glXGetFBConfigAttrib(display, config, GLX_STEREO, &stereo);
209  glXGetFBConfigAttrib(display, config, GLX_ACCUM_ALPHA_SIZE, &accumSizeA);
210  glXGetFBConfigAttrib(display, config, GLX_ACCUM_RED_SIZE, &accumSizeR);
211  glXGetFBConfigAttrib(display, config, GLX_ACCUM_GREEN_SIZE, &accumSizeG);
212  glXGetFBConfigAttrib(display, config, GLX_ACCUM_BLUE_SIZE, &accumSizeB);
213 
214  format.setRedBufferSize(redSize);
215  format.setGreenBufferSize(greenSize);
216  format.setBlueBufferSize(blueSize);
217  format.setAlphaBufferSize(alphaSize);
218  format.setDepthBufferSize(depthSize);
219  format.setStencilBufferSize(stencilSize);
220  format.setSampleBuffers(sampleBuffers);
221  if (format.sampleBuffers()) {
222  glXGetFBConfigAttrib(display, config, GLX_SAMPLES_ARB, &sampleCount);
223  format.setSamples(sampleCount);
224  }
225 
226  format.setDirectRendering(glXIsDirect(display, ctx));
227  format.setRgba(rgba);
228  format.setStereo(stereo);
229  format.setAccumBufferSize(accumSizeB);
230 
231  return format;
232 }
void setDepthBufferSize(int size)
Set the minimum depth buffer size to size.
void setStereo(bool enable)
If enable is true enables stereo buffering; otherwise disables stereo buffering.
void setDirectRendering(bool enable)
If enable is true enables direct rendering; otherwise disables direct rendering.
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
#define glXGetFBConfigAttrib
void setBlueBufferSize(int size)
Set the preferred blue buffer size to size.
void setStencilBufferSize(int size)
Set the preferred stencil buffer size to size.
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
void setAccumBufferSize(int size)
Set the preferred accumulation buffer size, where size is the bit depth for each RGBA component...
void setAlphaBufferSize(int size)
Set the preferred alpha buffer size to size.
void setSamples(int numSamples)
Set the preferred number of samples per pixel when multisampling is enabled to numSamples.
void setRgba(bool enable)
If enable is true sets RGBA mode.
#define GLX_SAMPLES_ARB
Definition: qgl_x11.cpp:97
#define ctx
Definition: qgl.cpp:6094
void setSampleBuffers(bool enable)
If enable is true, a GL context with multisample buffer support is picked; otherwise ignored...
void setRedBufferSize(int size)
Set the preferred red buffer size to size.
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.
void setGreenBufferSize(int size)
Set the preferred green buffer size to size.

◆ qglx_reducePlatformWindowFormat()

QPlatformWindowFormat qglx_reducePlatformWindowFormat ( const QPlatformWindowFormat format,
bool *  reduced 
)

Definition at line 234 of file qglxconvenience.cpp.

Referenced by qglx_findConfig().

235 {
236  QPlatformWindowFormat retFormat = format;
237  *reduced = true;
238 
239  if (retFormat.sampleBuffers()) {
240  retFormat.setSampleBuffers(false);
241  } else if (retFormat.stereo()) {
242  retFormat.setStereo(false);
243  } else if (retFormat.accum()) {
244  retFormat.setAccum(false);
245  }else if (retFormat.stencil()) {
246  retFormat.setStencil(false);
247  }else if (retFormat.alpha()) {
248  retFormat.setAlpha(false);
249  }else if (retFormat.depth()) {
250  retFormat.setDepth(false);
251  }else if (retFormat.doubleBuffer()) {
252  retFormat.setDoubleBuffer(false);
253  }else{
254  *reduced = false;
255  }
256  return retFormat;
257 }
void setStereo(bool enable)
If enable is true enables stereo buffering; otherwise disables stereo buffering.
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
bool doubleBuffer() const
Returns true if double buffering is enabled; otherwise returns false.
bool stereo() const
Returns true if stereo buffering is enabled; otherwise returns false.
bool depth() const
Returns true if the depth buffer is enabled; otherwise returns false.
void setDoubleBuffer(bool enable)
If enable is true sets double buffering; otherwise sets single buffering.
bool accum() const
Returns true if the accumulation buffer is enabled; otherwise returns false.
void setAlpha(bool enable)
If enable is true enables the alpha buffer; otherwise disables the alpha buffer.
void setSampleBuffers(bool enable)
If enable is true, a GL context with multisample buffer support is picked; otherwise ignored...
bool stencil() const
Returns true if the stencil buffer is enabled; otherwise returns false.
void setStencil(bool enable)
If enable is true enables the stencil buffer; otherwise disables the stencil buffer.
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.
void setAccum(bool enable)
If enable is true enables the accumulation buffer; otherwise disables the accumulation buffer...
void setDepth(bool enable)
If enable is true enables the depth buffer; otherwise disables the depth buffer.