1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <qdebug.h>
|
---|
43 | #include "qglpixelbuffer.h"
|
---|
44 | #include "qglpixelbuffer_p.h"
|
---|
45 | #include "qgl_egl_p.h"
|
---|
46 |
|
---|
47 | #include <qimage.h>
|
---|
48 | #include <private/qgl_p.h>
|
---|
49 |
|
---|
50 | #ifdef QT_OPENGL_ES_1_CL
|
---|
51 | #include "qgl_cl_p.h"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | QT_BEGIN_NAMESPACE
|
---|
55 |
|
---|
56 | #ifdef EGL_BIND_TO_TEXTURE_RGBA
|
---|
57 | #define QGL_RENDER_TEXTURE 1
|
---|
58 | #else
|
---|
59 | #define QGL_RENDER_TEXTURE 0
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | bool QGLPixelBufferPrivate::init(const QSize &size, const QGLFormat &f, QGLWidget *shareWidget)
|
---|
63 | {
|
---|
64 | // Create the EGL context.
|
---|
65 | ctx = new QEglContext();
|
---|
66 | ctx->setApi(QEgl::OpenGL);
|
---|
67 |
|
---|
68 | // Open the EGL display.
|
---|
69 | if (!ctx->openDisplay(0)) {
|
---|
70 | delete ctx;
|
---|
71 | ctx = 0;
|
---|
72 | return false;
|
---|
73 | }
|
---|
74 |
|
---|
75 | // Find the shared context.
|
---|
76 | QEglContext *shareContext = 0;
|
---|
77 | if (shareWidget && shareWidget->d_func()->glcx)
|
---|
78 | shareContext = shareWidget->d_func()->glcx->d_func()->eglContext;
|
---|
79 |
|
---|
80 | // Choose an appropriate configuration. We use the best format
|
---|
81 | // we can find, even if it is greater than the requested format.
|
---|
82 | // We try for a pbuffer that is capable of texture rendering if possible.
|
---|
83 | textureFormat = EGL_NONE;
|
---|
84 | if (shareContext) {
|
---|
85 | // Use the same configuration as the widget we are sharing with.
|
---|
86 | ctx->setConfig(shareContext->config());
|
---|
87 | #if QGL_RENDER_TEXTURE
|
---|
88 | EGLint value = EGL_FALSE;
|
---|
89 | if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGBA, &value) && value)
|
---|
90 | textureFormat = EGL_TEXTURE_RGBA;
|
---|
91 | else if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGB, &value) && value)
|
---|
92 | textureFormat = EGL_TEXTURE_RGB;
|
---|
93 | #endif
|
---|
94 | } else {
|
---|
95 | QEglProperties configProps;
|
---|
96 | qt_egl_set_format(configProps, QInternal::Pbuffer, f);
|
---|
97 | configProps.setRenderableType(ctx->api());
|
---|
98 | bool ok = false;
|
---|
99 | #if QGL_RENDER_TEXTURE
|
---|
100 | textureFormat = EGL_TEXTURE_RGBA;
|
---|
101 | configProps.setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE);
|
---|
102 | ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat);
|
---|
103 | if (!ok) {
|
---|
104 | // Try again with RGB texture rendering.
|
---|
105 | textureFormat = EGL_TEXTURE_RGB;
|
---|
106 | configProps.removeValue(EGL_BIND_TO_TEXTURE_RGBA);
|
---|
107 | configProps.setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE);
|
---|
108 | ok = ctx->chooseConfig(configProps, QEgl::BestPixelFormat);
|
---|
109 | if (!ok) {
|
---|
110 | // One last try for a pbuffer with no texture rendering.
|
---|
111 | configProps.removeValue(EGL_BIND_TO_TEXTURE_RGB);
|
---|
112 | textureFormat = EGL_NONE;
|
---|
113 | }
|
---|
114 | }
|
---|
115 | #endif
|
---|
116 | if (!ok) {
|
---|
117 | if (!ctx->chooseConfig(configProps, QEgl::BestPixelFormat)) {
|
---|
118 | delete ctx;
|
---|
119 | ctx = 0;
|
---|
120 | return false;
|
---|
121 | }
|
---|
|
---|