author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <private/qglpaintdevice_p.h> |
|
43 |
#include <private/qgl_p.h> |
|
44 |
#include <private/qglpixelbuffer_p.h> |
|
45 |
#include <private/qglframebufferobject_p.h> |
|
46 |
#include <private/qwindowsurface_gl_p.h> |
|
47 |
#ifdef Q_WS_X11 |
|
48 |
#include <private/qpixmapdata_x11gl_p.h> |
|
49 |
#endif |
|
50 |
||
51 |
#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) |
|
52 |
#include <private/qpixmapdata_gl_p.h> |
|
53 |
#endif |
|
54 |
||
55 |
#if defined(QT_OPENGL_ES_1_CL) |
|
56 |
#include "qgl_cl_p.h" |
|
57 |
#endif |
|
58 |
||
59 |
QT_BEGIN_NAMESPACE |
|
60 |
||
61 |
QGLPaintDevice::QGLPaintDevice() |
|
62 |
: m_thisFBO(0) |
|
63 |
{ |
|
64 |
} |
|
65 |
||
66 |
QGLPaintDevice::~QGLPaintDevice() |
|
67 |
{ |
|
68 |
} |
|
69 |
||
70 |
||
71 |
void QGLPaintDevice::beginPaint() |
|
72 |
{ |
|
73 |
// Make sure our context is the current one: |
|
74 |
QGLContext *ctx = context(); |
|
75 |
if (ctx != QGLContext::currentContext()) |
|
76 |
ctx->makeCurrent(); |
|
77 |
||
78 |
// Record the currently bound FBO so we can restore it again |
|
79 |
// in endPaint() and bind this device's FBO |
|
80 |
// |
|
81 |
// Note: m_thisFBO could be zero if the paint device is not |
|
82 |
// backed by an FBO (e.g. window back buffer). But there could |
|
83 |
// be a previous FBO bound to the context which we need to |
|
84 |
// explicitly unbind. Otherwise the painting will go into |
|
85 |
// the previous FBO instead of to the window. |
|
86 |
m_previousFBO = ctx->d_func()->current_fbo; |
|
87 |
||
88 |
if (m_previousFBO != m_thisFBO) { |
|
89 |
ctx->d_ptr->current_fbo = m_thisFBO; |
|
90 |
glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_thisFBO); |
|
91 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
// Set the default fbo for the context to m_thisFBO so that |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
// if some raw GL code between beginNativePainting() and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
// endNativePainting() calls QGLFramebufferObject::release(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
// painting will revert to the window surface's fbo. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
ctx->d_ptr->default_fbo = m_thisFBO; |
0 | 98 |
} |
99 |
||
100 |
void QGLPaintDevice::ensureActiveTarget() |
|
101 |
{ |
|
102 |
QGLContext* ctx = context(); |
|
103 |
if (ctx != QGLContext::currentContext()) |
|
104 |
ctx->makeCurrent(); |
|
105 |
||
106 |
if (ctx->d_ptr->current_fbo != m_thisFBO) { |
|
107 |
ctx->d_ptr->current_fbo = m_thisFBO; |
|
108 |
glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_thisFBO); |
|
109 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
ctx->d_ptr->default_fbo = m_thisFBO; |
0 | 112 |
} |
113 |
||
114 |
void QGLPaintDevice::endPaint() |
|
115 |
{ |
|
116 |
// Make sure the FBO bound at beginPaint is re-bound again here: |
|
117 |
QGLContext *ctx = context(); |
|
118 |
if (m_previousFBO != ctx->d_func()->current_fbo) { |
|
119 |
ctx->d_ptr->current_fbo = m_previousFBO; |
|
120 |
glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_previousFBO); |
|
121 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
ctx->d_ptr->default_fbo = 0; |
0 | 124 |
} |
125 |
||
126 |
QGLFormat QGLPaintDevice::format() const |
|
127 |
{ |
|
128 |
return context()->format(); |
|
129 |
} |
|
130 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
131 |
bool QGLPaintDevice::alphaRequested() const |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
132 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
133 |
return context()->d_func()->reqFormat.alpha(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
134 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
135 |
|
0 | 136 |
|
137 |
||
138 |
||
139 |
////////////////// QGLWidgetGLPaintDevice ////////////////// |
|
140 |
||
141 |
QGLWidgetGLPaintDevice::QGLWidgetGLPaintDevice() |
|
142 |
{ |
|
143 |
} |
|
144 |
||
145 |
QPaintEngine* QGLWidgetGLPaintDevice::paintEngine() const |
|
146 |
{ |
|
147 |
return glWidget->paintEngine(); |
|
148 |
} |
|
149 |
||
150 |
void QGLWidgetGLPaintDevice::setWidget(QGLWidget* w) |
|
151 |
{ |
|
152 |
glWidget = w; |
|
153 |
} |
|
154 |
||
155 |
void QGLWidgetGLPaintDevice::beginPaint() |
|
156 |
{ |
|
157 |
QGLPaintDevice::beginPaint(); |
|
158 |
if (!glWidget->d_func()->disable_clear_on_painter_begin && glWidget->autoFillBackground()) { |
|
159 |
if (glWidget->testAttribute(Qt::WA_TranslucentBackground)) |
|
160 |
glClearColor(0.0, 0.0, 0.0, 0.0); |
|
161 |
else { |
|
162 |
const QColor &c = glWidget->palette().brush(glWidget->backgroundRole()).color(); |
|
163 |
float alpha = c.alphaF(); |
|
164 |
glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); |
|
165 |
} |
|
166 |
glClear(GL_COLOR_BUFFER_BIT); |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
void QGLWidgetGLPaintDevice::endPaint() |
|
171 |
{ |
|
172 |
if (glWidget->autoBufferSwap()) |
|
173 |
glWidget->swapBuffers(); |
|
174 |
QGLPaintDevice::endPaint(); |
|
175 |
} |
|
176 |
||
177 |
||
178 |
QSize QGLWidgetGLPaintDevice::size() const |
|
179 |
{ |
|
180 |
return glWidget->size(); |
|
181 |
} |
|
182 |
||
183 |
QGLContext* QGLWidgetGLPaintDevice::context() const |
|
184 |
{ |
|
185 |
return const_cast<QGLContext*>(glWidget->context()); |
|
186 |
} |
|
187 |
||
188 |
// returns the QGLPaintDevice for the given QPaintDevice |
|
189 |
QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) |
|
190 |
{ |
|
191 |
QGLPaintDevice* glpd = 0; |
|
192 |
||
193 |
switch(pd->devType()) { |
|
194 |
case QInternal::Widget: |
|
195 |
// Should not be called on a non-gl widget: |
|
196 |
Q_ASSERT(qobject_cast<QGLWidget*>(static_cast<QWidget*>(pd))); |
|
197 |
glpd = &(static_cast<QGLWidget*>(pd)->d_func()->glDevice); |
|
198 |
break; |
|
199 |
case QInternal::Pbuffer: |
|
200 |
glpd = &(static_cast<QGLPixelBuffer*>(pd)->d_func()->glDevice); |
|
201 |
break; |
|
202 |
case QInternal::FramebufferObject: |
|
203 |
glpd = &(static_cast<QGLFramebufferObject*>(pd)->d_func()->glDevice); |
|
204 |
break; |
|
205 |
case QInternal::Pixmap: { |
|
206 |
#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) |
|
207 |
QPixmapData* pmd = static_cast<QPixmap*>(pd)->pixmapData(); |
|
208 |
if (pmd->classId() == QPixmapData::OpenGLClass) |
|
209 |
glpd = static_cast<QGLPixmapData*>(pmd)->glDevice(); |
|
210 |
#ifdef Q_WS_X11 |
|
211 |
else if (pmd->classId() == QPixmapData::X11Class) |
|
212 |
glpd = static_cast<QX11GLPixmapData*>(pmd); |
|
213 |
#endif |
|
214 |
else |
|
215 |
qWarning("Pixmap type not supported for GL rendering"); |
|
216 |
#else |
|
217 |
qWarning("Pixmap render targets not supported on OpenGL ES 1.x"); |
|
218 |
#endif |
|
219 |
break; |
|
220 |
} |
|
221 |
default: |
|
222 |
qWarning("QGLPaintDevice::getDevice() - Unknown device type %d", pd->devType()); |
|
223 |
break; |
|
224 |
} |
|
225 |
||
226 |
return glpd; |
|
227 |
} |
|
228 |
||
229 |
QT_END_NAMESPACE |