Qt 4.8
Functions
qgl_egl.cpp File Reference
#include <QtCore/qdebug.h>
#include <QtOpenGL/qgl.h>
#include <QtOpenGL/qglpixelbuffer.h>
#include "qgl_p.h"
#include "qgl_egl_p.h"
#include "qglpixelbuffer_p.h"
#include <QtGui/private/qpixmap_x11_p.h>

Go to the source code of this file.

Functions

void qt_eglproperties_set_glformat (QEglProperties &eglProperties, const QGLFormat &glFormat)
 
void qt_glformat_from_eglconfig (QGLFormat &format, const EGLConfig config)
 

Function Documentation

◆ qt_eglproperties_set_glformat()

void qt_eglproperties_set_glformat ( QEglProperties eglProperties,
const QGLFormat glFormat 
)

Definition at line 61 of file qgl_egl.cpp.

Referenced by QGLPixelBuffer::hasOpenGLPbuffers(), QGLPixelBufferPrivate::init(), and qt_egl_create_surface().

62 {
63  int redSize = glFormat.redBufferSize();
64  int greenSize = glFormat.greenBufferSize();
65  int blueSize = glFormat.blueBufferSize();
66  int alphaSize = glFormat.alphaBufferSize();
67  int depthSize = glFormat.depthBufferSize();
68  int stencilSize = glFormat.stencilBufferSize();
69  int sampleCount = glFormat.samples();
70 
71  bool prefer32Bit = false;
72 #ifdef Q_OS_SYMBIAN
73  // on Symbian we prefer 32-bit configs, unless we're using the low memory GPU
74  prefer32Bit = !QSymbianGraphicsSystemEx::hasBCM2727();
75 #endif
76 
77  if (prefer32Bit) {
78  if (glFormat.alpha() && alphaSize <= 0)
79  alphaSize = 8;
80  if (glFormat.depth() && depthSize <= 0)
81  depthSize = 24;
82  if (glFormat.stencil() && stencilSize <= 0)
83  stencilSize = 8;
84  if (glFormat.sampleBuffers() && sampleCount <= 0)
85  sampleCount = 1;
86 
87  redSize = redSize > 0 ? redSize : 8;
88  greenSize = greenSize > 0 ? greenSize : 8;
89  blueSize = blueSize > 0 ? blueSize : 8;
90  alphaSize = alphaSize > 0 ? alphaSize : 8;
91  depthSize = depthSize > 0 ? depthSize : 24;
92  stencilSize = stencilSize > 0 ? stencilSize : 8;
93  sampleCount = sampleCount >= 0 ? sampleCount : 4;
94  } else {
95  // QGLFormat uses a magic value of -1 to indicate "don't care", even when a buffer of that
96  // type has been requested. So we must check QGLFormat's booleans too if size is -1:
97  if (glFormat.alpha() && alphaSize <= 0)
98  alphaSize = 1;
99  if (glFormat.depth() && depthSize <= 0)
100  depthSize = 1;
101  if (glFormat.stencil() && stencilSize <= 0)
102  stencilSize = 1;
103  if (glFormat.sampleBuffers() && sampleCount <= 0)
104  sampleCount = 1;
105 
106  // We want to make sure 16-bit configs are chosen over 32-bit configs as they will provide
107  // the best performance. The EGL config selection algorithm is a bit stange in this regard:
108  // The selection criteria for EGL_BUFFER_SIZE is "AtLeast", so we can't use it to discard
109  // 32-bit configs completely from the selection. So it then comes to the sorting algorithm.
110  // The red/green/blue sizes have a sort priority of 3, so they are sorted by first. The sort
111  // order is special and described as "by larger _total_ number of color bits.". So EGL will
112  // put 32-bit configs in the list before the 16-bit configs. However, the spec also goes on
113  // to say "If the requested number of bits in attrib_list for a particular component is 0,
114  // then the number of bits for that component is not considered". This part of the spec also
115  // seems to imply that setting the red/green/blue bits to zero means none of the components
116  // are considered and EGL disregards the entire sorting rule. It then looks to the next
117  // highest priority rule, which is EGL_BUFFER_SIZE. Despite the selection criteria being
118  // "AtLeast" for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are
119  // put in the list before 32-bit configs. So, to make sure 16-bit is preffered over 32-bit,
120  // we must set the red/green/blue sizes to zero. This has an unfortunate consequence that
121  // if the application sets the red/green/blue size to 5/6/5 on the QGLFormat, they will
122  // probably get a 32-bit config, even when there's an RGB565 config available. Oh well.
123 
124  // Now normalize the values so -1 becomes 0
125  redSize = redSize > 0 ? redSize : 0;
126  greenSize = greenSize > 0 ? greenSize : 0;
127  blueSize = blueSize > 0 ? blueSize : 0;
128  alphaSize = alphaSize > 0 ? alphaSize : 0;
129  depthSize = depthSize > 0 ? depthSize : 0;
130  stencilSize = stencilSize > 0 ? stencilSize : 0;
131  sampleCount = sampleCount > 0 ? sampleCount : 0;
132  }
133 
134  eglProperties.setValue(EGL_RED_SIZE, redSize);
135  eglProperties.setValue(EGL_GREEN_SIZE, greenSize);
136  eglProperties.setValue(EGL_BLUE_SIZE, blueSize);
137  eglProperties.setValue(EGL_ALPHA_SIZE, alphaSize);
138  eglProperties.setValue(EGL_DEPTH_SIZE, depthSize);
139  eglProperties.setValue(EGL_STENCIL_SIZE, stencilSize);
140  eglProperties.setValue(EGL_SAMPLES, sampleCount);
141  eglProperties.setValue(EGL_SAMPLE_BUFFERS, sampleCount ? 1 : 0);
142 }
int greenBufferSize() const
Returns the green buffer size.
Definition: qgl.cpp:1070
void setValue(int name, int value)
int redBufferSize() const
Returns the red buffer size.
Definition: qgl.cpp:1035
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.
Definition: qgl.h:658
int alphaBufferSize() const
Returns the alpha buffer size.
Definition: qgl.cpp:1132
bool depth() const
Returns true if the depth buffer is enabled; otherwise returns false.
Definition: qgl.h:618
int depthBufferSize() const
Returns the depth buffer size.
Definition: qgl.cpp:1000
bool stencil() const
Returns true if the stencil buffer is enabled; otherwise returns false.
Definition: qgl.h:638
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
Definition: qgl.h:628
int blueBufferSize() const
Returns the blue buffer size.
Definition: qgl.cpp:1105
int stencilBufferSize() const
Returns the stencil buffer size.
Definition: qgl.cpp:1185
int samples() const
Returns the number of samples per pixel when multisampling is enabled.
Definition: qgl.cpp:824

◆ qt_glformat_from_eglconfig()

void qt_glformat_from_eglconfig ( QGLFormat format,
const EGLConfig  config 
)

Definition at line 145 of file qgl_egl.cpp.

Referenced by QGLPixelBufferPrivate::init(), QX11GLPixmapData::paintEngine(), qt_egl_create_surface(), and QX11GLSharedContexts::QX11GLSharedContexts().

146 {
147  EGLint redSize = 0;
148  EGLint greenSize = 0;
149  EGLint blueSize = 0;
150  EGLint alphaSize = 0;
151  EGLint depthSize = 0;
152  EGLint stencilSize = 0;
153  EGLint sampleCount = 0;
154  EGLint level = 0;
155 
156  EGLDisplay display = QEgl::display();
157  eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize);
158  eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize);
159  eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize);
160  eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize);
161  eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize);
162  eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize);
163  eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount);
164  eglGetConfigAttrib(display, config, EGL_LEVEL, &level);
165 
166  format.setRedBufferSize(redSize);
167  format.setGreenBufferSize(greenSize);
168  format.setBlueBufferSize(blueSize);
169  format.setAlphaBufferSize(alphaSize);
170  format.setDepthBufferSize(depthSize);
171  format.setStencilBufferSize(stencilSize);
172  format.setSamples(sampleCount);
173  format.setPlane(level);
174  format.setDirectRendering(true); // All EGL contexts are direct-rendered
175  format.setRgba(true); // EGL doesn't support colour index rendering
176  format.setStereo(false); // EGL doesn't support stereo buffers
177  format.setAccumBufferSize(0); // EGL doesn't support accululation buffers
178  format.setDoubleBuffer(true); // We don't support single buffered EGL contexts
179 
180  // Clear the EGL error state because some of the above may
181  // have errored out because the attribute is not applicable
182  // to the surface type. Such errors don't matter.
183  eglGetError();
184 }
void setSamples(int numSamples)
Set the preferred number of samples per pixel when multisampling is enabled to numSamples.
Definition: qgl.cpp:836
void setAccumBufferSize(int size)
Set the preferred accumulation buffer size, where size is the bit depth for each RGBA component...
Definition: qgl.cpp:1143
void setRedBufferSize(int size)
Set the preferred red buffer size to size.
Definition: qgl.cpp:1015
void setDirectRendering(bool enable)
If enable is true enables direct rendering; otherwise disables direct rendering.
Definition: qgl.cpp:787
void setAlphaBufferSize(int size)
Set the preferred alpha buffer size to size.
Definition: qgl.cpp:1116
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
void setDepthBufferSize(int size)
Set the minimum depth buffer size to size.
Definition: qgl.cpp:984
void setDoubleBuffer(bool enable)
If enable is true sets double buffering; otherwise sets single buffering.
Definition: qgl.cpp:566
void setGreenBufferSize(int size)
Set the preferred green buffer size to size.
Definition: qgl.cpp:1050
void setRgba(bool enable)
If enable is true sets RGBA mode.
Definition: qgl.cpp:633
void setStereo(bool enable)
If enable is true enables stereo buffering; otherwise disables stereo buffering.
Definition: qgl.cpp:754
void setBlueBufferSize(int size)
Set the preferred blue buffer size to size.
Definition: qgl.cpp:1085
void setPlane(int plane)
Sets the requested plane to plane.
Definition: qgl.cpp:942
void setStencilBufferSize(int size)
Set the preferred stencil buffer size to size.
Definition: qgl.cpp:1169