diff options
author | tsenyk <tsenyk@rudolf.europe.nokia.com> | 2010-05-05 12:27:01 (GMT) |
---|---|---|
committer | tsenyk <tsenyk@rudolf.europe.nokia.com> | 2010-05-05 12:27:01 (GMT) |
commit | e5cf17ca04005909dfeca938606041dfa3a1b2ad (patch) | |
tree | e3c1bedf2ae6ffa0e8abe39738882a332b37a010 | |
parent | 208e207925f9073fdca55f5824ce4d0051c86c6c (diff) | |
download | Qt-e5cf17ca04005909dfeca938606041dfa3a1b2ad.zip Qt-e5cf17ca04005909dfeca938606041dfa3a1b2ad.tar.gz Qt-e5cf17ca04005909dfeca938606041dfa3a1b2ad.tar.bz2 |
ifdef fix for egl on ws_lite
reviewed by: Jørgen
-rw-r--r-- | src/opengl/qgl.cpp | 3 | ||||
-rw-r--r-- | src/opengl/qgl_lite.cpp | 103 | ||||
-rw-r--r-- | src/opengl/qgl_p.h | 9 | ||||
-rw-r--r-- | src/opengl/qglpixelbuffer_p.h | 3 |
4 files changed, 112 insertions, 6 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 580f3d0..26eb1e7 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1588,7 +1588,8 @@ void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) #endif #if defined(Q_WS_LITE) platformContext = 0; -#elif !defined(QT_NO_EGL) +#endif +#if !defined(QT_NO_EGL) ownsEglContext = false; eglContext = 0; eglSurface = EGL_NO_SURFACE; diff --git a/src/opengl/qgl_lite.cpp b/src/opengl/qgl_lite.cpp index 0ffda5f..426683b 100644 --- a/src/opengl/qgl_lite.cpp +++ b/src/opengl/qgl_lite.cpp @@ -49,6 +49,109 @@ #include "qgl_p.h" #include "qglplatformintegration_lite.h" +#ifndef QT_NO_EGL +#include "qgl_egl_p.h" + +void qt_eglproperties_set_glformat(QEglProperties& eglProperties, const QGLFormat& glFormat) +{ + int redSize = glFormat.redBufferSize(); + int greenSize = glFormat.greenBufferSize(); + int blueSize = glFormat.blueBufferSize(); + int alphaSize = glFormat.alphaBufferSize(); + int depthSize = glFormat.depthBufferSize(); + int stencilSize = glFormat.stencilBufferSize(); + int sampleCount = glFormat.samples(); + + // QGLFormat uses a magic value of -1 to indicate "don't care", even when a buffer of that + // type has been requested. So we must check QGLFormat's booleans too if size is -1: + if (glFormat.alpha() && alphaSize <= 0) + alphaSize = 1; + if (glFormat.depth() && depthSize <= 0) + depthSize = 1; + if (glFormat.stencil() && stencilSize <= 0) + stencilSize = 1; + if (glFormat.sampleBuffers() && sampleCount <= 0) + sampleCount = 1; + + // We want to make sure 16-bit configs are chosen over 32-bit configs as they will provide + // the best performance. The EGL config selection algorithm is a bit stange in this regard: + // The selection criteria for EGL_BUFFER_SIZE is "AtLeast", so we can't use it to discard + // 32-bit configs completely from the selection. So it then comes to the sorting algorithm. + // The red/green/blue sizes have a sort priority of 3, so they are sorted by first. The sort + // order is special and described as "by larger _total_ number of color bits.". So EGL will + // put 32-bit configs in the list before the 16-bit configs. However, the spec also goes on + // to say "If the requested number of bits in attrib_list for a particular component is 0, + // then the number of bits for that component is not considered". This part of the spec also + // seems to imply that setting the red/green/blue bits to zero means none of the components + // are considered and EGL disregards the entire sorting rule. It then looks to the next + // highest priority rule, which is EGL_BUFFER_SIZE. Despite the selection criteria being + // "AtLeast" for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are + // put in the list before 32-bit configs. So, to make sure 16-bit is preffered over 32-bit, + // we must set the red/green/blue sizes to zero. This has an unfortunate consequence that + // if the application sets the red/green/blue size to 5/6/5 on the QGLFormat, they will + // probably get a 32-bit config, even when there's an RGB565 config avaliable. Oh well. + + // Now normalize the values so -1 becomes 0 + redSize = redSize > 0 ? redSize : 0; + greenSize = greenSize > 0 ? greenSize : 0; + blueSize = blueSize > 0 ? blueSize : 0; + alphaSize = alphaSize > 0 ? alphaSize : 0; + depthSize = depthSize > 0 ? depthSize : 0; + stencilSize = stencilSize > 0 ? stencilSize : 0; + sampleCount = sampleCount > 0 ? sampleCount : 0; + + eglProperties.setValue(EGL_RED_SIZE, redSize); + eglProperties.setValue(EGL_GREEN_SIZE, greenSize); + eglProperties.setValue(EGL_BLUE_SIZE, blueSize); + eglProperties.setValue(EGL_ALPHA_SIZE, alphaSize); + eglProperties.setValue(EGL_DEPTH_SIZE, depthSize); + eglProperties.setValue(EGL_STENCIL_SIZE, stencilSize); + eglProperties.setValue(EGL_SAMPLES, sampleCount); + eglProperties.setValue(EGL_SAMPLE_BUFFERS, sampleCount ? 1 : 0); +} + +// Updates "format" with the parameters of the selected configuration. +void qt_glformat_from_eglconfig(QGLFormat& format, const EGLConfig config) +{ + EGLint redSize = 0; + EGLint greenSize = 0; + EGLint blueSize = 0; + EGLint alphaSize = 0; + EGLint depthSize = 0; + EGLint stencilSize = 0; + EGLint sampleCount = 0; + EGLint level = 0; + + EGLDisplay display = QEgl::display(); + eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize); + eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize); + eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize); + eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize); + eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize); + eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize); + eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount); + eglGetConfigAttrib(display, config, EGL_LEVEL, &level); + + format.setRedBufferSize(redSize); + format.setGreenBufferSize(greenSize); + format.setBlueBufferSize(blueSize); + format.setAlphaBufferSize(alphaSize); + format.setDepthBufferSize(depthSize); + format.setStencilBufferSize(stencilSize); + format.setSamples(sampleCount); + format.setPlane(level + 1); // EGL calls level 0 "normal" whereas Qt calls 1 "normal" + format.setDirectRendering(true); // All EGL contexts are direct-rendered + format.setRgba(true); // EGL doesn't support colour index rendering + format.setStereo(false); // EGL doesn't support stereo buffers + format.setAccumBufferSize(0); // EGL doesn't support accululation buffers + + // Clear the EGL error state because some of the above may + // have errored out because the attribute is not applicable + // to the surface type. Such errors don't matter. + eglGetError(); +} +#endif + QT_BEGIN_NAMESPACE diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 34cbdfc..a2445b7 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -350,14 +350,17 @@ public: HBITMAP hbitmap; HDC hbitmap_hdc; #endif -#if defined(Q_WS_LITE) - QPlatformGLContext *platformContext; -#elif !defined(QT_NO_EGL) + +#if !defined(QT_NO_EGL) bool ownsEglContext; QEglContext *eglContext; EGLSurface eglSurface; void destroyEglSurfaceForDevice(); EGLSurface eglSurfaceForDevice() const; +#endif + +#if defined(Q_WS_LITE) + QPlatformGLContext *platformContext; #elif defined(Q_WS_X11) || defined(Q_WS_MAC) void* cx; #endif diff --git a/src/opengl/qglpixelbuffer_p.h b/src/opengl/qglpixelbuffer_p.h index de890c9..a7f4159 100644 --- a/src/opengl/qglpixelbuffer_p.h +++ b/src/opengl/qglpixelbuffer_p.h @@ -197,8 +197,7 @@ public: EGLSurface pbuf; QEglContext *ctx; int textureFormat; -#endif -#if defined(Q_WS_LITE) +#elif defined(Q_WS_LITE) // Stubs int pbuf; int ctx; |