Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | /*! | - |
43 | \class QGLPixelBuffer | - |
44 | \inmodule QtOpenGL | - |
45 | \brief The QGLPixelBuffer class encapsulates an OpenGL pbuffer. | - |
46 | \since 4.1 | - |
47 | \obsolete | - |
48 | | - |
49 | \ingroup painting-3D | - |
50 | | - |
51 | Rendering into a pbuffer is normally done using full hardware | - |
52 | acceleration. This can be significantly faster than rendering | - |
53 | into a QPixmap. | - |
54 | | - |
55 | There are three approaches to using this class: | - |
56 | | - |
57 | \list 1 | - |
58 | \li \b{We can draw into the pbuffer and convert it to a QImage | - |
59 | using toImage().} This is normally much faster than calling | - |
60 | QGLWidget::renderPixmap(). | - |
61 | | - |
62 | \li \b{We can draw into the pbuffer and copy the contents into | - |
63 | an OpenGL texture using updateDynamicTexture().} This allows | - |
64 | us to create dynamic textures and works on all systems | - |
65 | with pbuffer support. | - |
66 | | - |
67 | \li \b{On systems that support it, we can bind the pbuffer to | - |
68 | an OpenGL texture.} The texture is then updated automatically | - |
69 | when the pbuffer contents change, eliminating the need for | - |
70 | additional copy operations. This is supported only on Windows | - |
71 | and Mac OS X systems that provide the \c render_texture | - |
72 | extension. Note that under Windows, a multi-sampled pbuffer | - |
73 | can't be used in conjunction with the \c render_texture | - |
74 | extension. If a multi-sampled pbuffer is requested under | - |
75 | Windows, the \c render_texture extension is turned off for that | - |
76 | pbuffer. | - |
77 | | - |
78 | | - |
79 | \endlist | - |
80 | | - |
81 | \note This class has been deprecated, use QOpenGLFramebufferObject | - |
82 | for offscreen rendering. | - |
83 | | - |
84 | \section1 Threading | - |
85 | | - |
86 | As of Qt 4.8, it's possible to render into a QGLPixelBuffer using | - |
87 | a QPainter in a separate thread. Note that OpenGL 2.0 or OpenGL ES | - |
88 | 2.0 is required for this to work. | - |
89 | | - |
90 | Pbuffers are provided by the OpenGL \c pbuffer extension; call | - |
91 | hasOpenGLPbuffer() to find out if the system provides pbuffers. | - |
92 | | - |
93 | \sa {opengl/pbuffers}{Pbuffers Example} | - |
94 | */ | - |
95 | | - |
96 | #include <private/qopenglextensions_p.h> | - |
97 | | - |
98 | #include <QtCore/qglobal.h> | - |
99 | #include <QtGui/qopenglframebufferobject.h> | - |
100 | | - |
101 | #include "gl2paintengineex/qpaintengineex_opengl2_p.h" | - |
102 | | - |
103 | #include <qglframebufferobject.h> | - |
104 | #include <qglpixelbuffer.h> | - |
105 | #include <private/qglpixelbuffer_p.h> | - |
106 | #include <private/qfont_p.h> | - |
107 | #include <qimage.h> | - |
108 | | - |
109 | QT_BEGIN_NAMESPACE | - |
110 | | - |
111 | extern QImage qt_gl_read_frame_buffer(const QSize&, bool, bool); | - |
112 | | - |
113 | | - |
114 | QGLContext* QGLPBufferGLPaintDevice::context() const | - |
115 | { | - |
116 | return pbuf->d_func()->qctx; never executed: return pbuf->d_func()->qctx; | 0 |
117 | } | - |
118 | | - |
119 | void QGLPBufferGLPaintDevice::beginPaint() | - |
120 | { | - |
121 | pbuf->makeCurrent(); never executed (the execution status of this line is deduced): pbuf->makeCurrent(); | - |
122 | QGLPaintDevice::beginPaint(); never executed (the execution status of this line is deduced): QGLPaintDevice::beginPaint(); | - |
123 | } | 0 |
124 | | - |
125 | void QGLPBufferGLPaintDevice::endPaint() | - |
126 | { | - |
127 | glFlush(); never executed (the execution status of this line is deduced): glFlush(); | - |
128 | QGLPaintDevice::endPaint(); never executed (the execution status of this line is deduced): QGLPaintDevice::endPaint(); | - |
129 | } | 0 |
130 | | - |
131 | void QGLPBufferGLPaintDevice::setFbo(GLuint fbo) | - |
132 | { | - |
133 | m_thisFBO = fbo; never executed (the execution status of this line is deduced): m_thisFBO = fbo; | - |
134 | } | 0 |
135 | | - |
136 | void QGLPBufferGLPaintDevice::setPBuffer(QGLPixelBuffer* pb) | - |
137 | { | - |
138 | pbuf = pb; never executed (the execution status of this line is deduced): pbuf = pb; | - |
139 | } | 0 |
140 | | - |
141 | void QGLPixelBufferPrivate::common_init(const QSize &size, const QGLFormat &format, QGLWidget *shareWidget) | - |
142 | { | - |
143 | Q_Q(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBuffer * const q = q_func(); | - |
144 | if(init(size, format, shareWidget)) { never evaluated: init(size, format, shareWidget) | 0 |
145 | req_size = size; never executed (the execution status of this line is deduced): req_size = size; | - |
146 | req_format = format; never executed (the execution status of this line is deduced): req_format = format; | - |
147 | req_shareWidget = shareWidget; never executed (the execution status of this line is deduced): req_shareWidget = shareWidget; | - |
148 | invalid = false; never executed (the execution status of this line is deduced): invalid = false; | - |
149 | glDevice.setPBuffer(q); never executed (the execution status of this line is deduced): glDevice.setPBuffer(q); | - |
150 | } | 0 |
151 | } | 0 |
152 | | - |
153 | /*! | - |
154 | Constructs an OpenGL pbuffer of the given \a size. If no \a | - |
155 | format is specified, the \l{QGLFormat::defaultFormat()}{default | - |
156 | format} is used. If the \a shareWidget parameter points to a | - |
157 | valid QGLWidget, the pbuffer will share its context with \a | - |
158 | shareWidget. | - |
159 | | - |
160 | If you intend to bind this pbuffer as a dynamic texture, the width | - |
161 | and height components of \c size must be powers of two (e.g., 512 | - |
162 | x 128). | - |
163 | | - |
164 | \sa size(), format() | - |
165 | */ | - |
166 | QGLPixelBuffer::QGLPixelBuffer(const QSize &size, const QGLFormat &format, QGLWidget *shareWidget) | - |
167 | : d_ptr(new QGLPixelBufferPrivate(this)) | - |
168 | { | - |
169 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
170 | d->common_init(size, format, shareWidget); never executed (the execution status of this line is deduced): d->common_init(size, format, shareWidget); | - |
171 | } | 0 |
172 | | - |
173 | | - |
174 | /*! \overload | - |
175 | | - |
176 | Constructs an OpenGL pbuffer with the \a width and \a height. If | - |
177 | no \a format is specified, the | - |
178 | \l{QGLFormat::defaultFormat()}{default format} is used. If the \a | - |
179 | shareWidget parameter points to a valid QGLWidget, the pbuffer | - |
180 | will share its context with \a shareWidget. | - |
181 | | - |
182 | If you intend to bind this pbuffer as a dynamic texture, the width | - |
183 | and height components of \c size must be powers of two (e.g., 512 | - |
184 | x 128). | - |
185 | | - |
186 | \sa size(), format() | - |
187 | */ | - |
188 | QGLPixelBuffer::QGLPixelBuffer(int width, int height, const QGLFormat &format, QGLWidget *shareWidget) | - |
189 | : d_ptr(new QGLPixelBufferPrivate(this)) | - |
190 | { | - |
191 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
192 | d->common_init(QSize(width, height), format, shareWidget); never executed (the execution status of this line is deduced): d->common_init(QSize(width, height), format, shareWidget); | - |
193 | } | 0 |
194 | | - |
195 | | - |
196 | /*! \fn QGLPixelBuffer::~QGLPixelBuffer() | - |
197 | | - |
198 | Destroys the pbuffer and frees any allocated resources. | - |
199 | */ | - |
200 | QGLPixelBuffer::~QGLPixelBuffer() | - |
201 | { | - |
202 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
203 | | - |
204 | // defined in qpaintengine_opengl.cpp | - |
205 | QGLContext *current = const_cast<QGLContext *>(QGLContext::currentContext()); never executed (the execution status of this line is deduced): QGLContext *current = const_cast<QGLContext *>(QGLContext::currentContext()); | - |
206 | if (current != d->qctx) never evaluated: current != d->qctx | 0 |
207 | makeCurrent(); never executed: makeCurrent(); | 0 |
208 | d->cleanup(); never executed (the execution status of this line is deduced): d->cleanup(); | - |
209 | if (current && current != d->qctx) never evaluated: current never evaluated: current != d->qctx | 0 |
210 | current->makeCurrent(); never executed: current->makeCurrent(); | 0 |
211 | } | 0 |
212 | | - |
213 | /*! \fn bool QGLPixelBuffer::makeCurrent() | - |
214 | | - |
215 | Makes this pbuffer the current OpenGL rendering context. Returns | - |
216 | true on success; otherwise returns false. | - |
217 | | - |
218 | \sa QGLContext::makeCurrent(), doneCurrent() | - |
219 | */ | - |
220 | | - |
221 | bool QGLPixelBuffer::makeCurrent() | - |
222 | { | - |
223 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
224 | if (d->invalid) never evaluated: d->invalid | 0 |
225 | return false; never executed: return false; | 0 |
226 | d->qctx->makeCurrent(); never executed (the execution status of this line is deduced): d->qctx->makeCurrent(); | - |
227 | if (!d->fbo) { | 0 |
228 | QOpenGLFramebufferObjectFormat format; never executed (the execution status of this line is deduced): QOpenGLFramebufferObjectFormat format; | - |
229 | if (d->req_format.stencil()) never evaluated: d->req_format.stencil() | 0 |
230 | format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); never executed: format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); | 0 |
231 | else if (d->req_format.depth()) never evaluated: d->req_format.depth() | 0 |
232 | format.setAttachment(QOpenGLFramebufferObject::Depth); never executed: format.setAttachment(QOpenGLFramebufferObject::Depth); | 0 |
233 | if (d->req_format.sampleBuffers()) never evaluated: d->req_format.sampleBuffers() | 0 |
234 | format.setSamples(d->req_format.samples()); never executed: format.setSamples(d->req_format.samples()); | 0 |
235 | d->fbo = new QOpenGLFramebufferObject(d->req_size, format); never executed (the execution status of this line is deduced): d->fbo = new QOpenGLFramebufferObject(d->req_size, format); | - |
236 | d->fbo->bind(); never executed (the execution status of this line is deduced): d->fbo->bind(); | - |
237 | d->glDevice.setFbo(d->fbo->handle()); never executed (the execution status of this line is deduced): d->glDevice.setFbo(d->fbo->handle()); | - |
238 | glViewport(0, 0, d->req_size.width(), d->req_size.height()); never executed (the execution status of this line is deduced): glViewport(0, 0, d->req_size.width(), d->req_size.height()); | - |
239 | } | 0 |
240 | return true; never executed: return true; | 0 |
241 | } | - |
242 | | - |
243 | /*! \fn bool QGLPixelBuffer::doneCurrent() | - |
244 | | - |
245 | Makes no context the current OpenGL context. Returns true on | - |
246 | success; otherwise returns false. | - |
247 | */ | - |
248 | | - |
249 | bool QGLPixelBuffer::doneCurrent() | - |
250 | { | - |
251 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
252 | if (d->invalid) never evaluated: d->invalid | 0 |
253 | return false; never executed: return false; | 0 |
254 | d->qctx->doneCurrent(); never executed (the execution status of this line is deduced): d->qctx->doneCurrent(); | - |
255 | return true; never executed: return true; | 0 |
256 | } | - |
257 | | - |
258 | /*! | - |
259 | Returns the context of this pixelbuffer. | - |
260 | */ | - |
261 | QGLContext *QGLPixelBuffer::context() const | - |
262 | { | - |
263 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
264 | return d->qctx; never executed: return d->qctx; | 0 |
265 | } | - |
266 | | - |
267 | /*! | - |
268 | \fn GLuint QGLPixelBuffer::generateDynamicTexture() const | - |
269 | | - |
270 | Generates and binds a 2D GL texture that is the same size as the | - |
271 | pbuffer, and returns the texture's ID. This can be used in | - |
272 | conjunction with bindToDynamicTexture() and | - |
273 | updateDynamicTexture(). | - |
274 | | - |
275 | \sa size() | - |
276 | */ | - |
277 | | - |
278 | /*! \fn bool QGLPixelBuffer::bindToDynamicTexture(GLuint texture_id) | - |
279 | | - |
280 | Binds the texture specified by \a texture_id to this pbuffer. | - |
281 | Returns true on success; otherwise returns false. | - |
282 | | - |
283 | The texture must be of the same size and format as the pbuffer. | - |
284 | | - |
285 | To unbind the texture, call releaseFromDynamicTexture(). While | - |
286 | the texture is bound, it is updated automatically when the | - |
287 | pbuffer contents change, eliminating the need for additional copy | - |
288 | operations. | - |
289 | | - |
290 | Example: | - |
291 | | - |
292 | \snippet code/src_opengl_qglpixelbuffer.cpp 0 | - |
293 | | - |
294 | \warning This function uses the \c {render_texture} extension, | - |
295 | which is currently not supported under X11. An alternative that | - |
296 | works on all systems (including X11) is to manually copy the | - |
297 | pbuffer contents to a texture using updateDynamicTexture(). | - |
298 | | - |
299 | \warning For the bindToDynamicTexture() call to succeed on the | - |
300 | Mac OS X, the pbuffer needs a shared context, i.e. the | - |
301 | QGLPixelBuffer must be created with a share widget. | - |
302 | | - |
303 | \sa generateDynamicTexture(), releaseFromDynamicTexture() | - |
304 | */ | - |
305 | | - |
306 | /*! \fn void QGLPixelBuffer::releaseFromDynamicTexture() | - |
307 | | - |
308 | Releases the pbuffer from any previously bound texture. | - |
309 | | - |
310 | \sa bindToDynamicTexture() | - |
311 | */ | - |
312 | | - |
313 | /*! \fn bool QGLPixelBuffer::hasOpenGLPbuffers() | - |
314 | | - |
315 | Returns true if the OpenGL \c pbuffer extension is present on | - |
316 | this system; otherwise returns false. | - |
317 | */ | - |
318 | | - |
319 | /*! | - |
320 | Copies the pbuffer contents into the texture specified with \a | - |
321 | texture_id. | - |
322 | | - |
323 | The texture must be of the same size and format as the pbuffer. | - |
324 | | - |
325 | Example: | - |
326 | | - |
327 | \snippet code/src_opengl_qglpixelbuffer.cpp 1 | - |
328 | | - |
329 | An alternative on Windows and Mac OS X systems that support the | - |
330 | \c render_texture extension is to use bindToDynamicTexture() to | - |
331 | get dynamic updates of the texture. | - |
332 | | - |
333 | \sa generateDynamicTexture(), bindToDynamicTexture() | - |
334 | */ | - |
335 | void QGLPixelBuffer::updateDynamicTexture(GLuint texture_id) const | - |
336 | { | - |
337 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
338 | if (d->invalid || !d->fbo) never evaluated: d->invalid never evaluated: !d->fbo | 0 |
339 | return; | 0 |
340 | | - |
341 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); never executed (the execution status of this line is deduced): QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - |
342 | if (!ctx) | 0 |
343 | return; | 0 |
344 | | - |
345 | #undef glBindFramebuffer | - |
346 | | - |
347 | #ifndef GL_READ_FRAMEBUFFER | - |
348 | #define GL_READ_FRAMEBUFFER 0x8CA8 | - |
349 | #endif | - |
350 | | - |
351 | #ifndef GL_DRAW_FRAMEBUFFER | - |
352 | #define GL_DRAW_FRAMEBUFFER 0x8CA9 | - |
353 | #endif | - |
354 | | - |
355 | QOpenGLExtensions extensions(ctx); never executed (the execution status of this line is deduced): QOpenGLExtensions extensions(ctx); | - |
356 | | - |
357 | if (d->blit_fbo) { never evaluated: d->blit_fbo | 0 |
358 | QOpenGLFramebufferObject::blitFramebuffer(d->blit_fbo, d->fbo); never executed (the execution status of this line is deduced): QOpenGLFramebufferObject::blitFramebuffer(d->blit_fbo, d->fbo); | - |
359 | extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, d->blit_fbo->handle()); never executed (the execution status of this line is deduced): extensions.glBindFramebuffer(0x8CA8, d->blit_fbo->handle()); | - |
360 | } | 0 |
361 | | - |
362 | glBindTexture(GL_TEXTURE_2D, texture_id); never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, texture_id); | - |
363 | #ifndef QT_OPENGL_ES | - |
364 | glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, d->req_size.width(), d->req_size.height(), 0); never executed (the execution status of this line is deduced): glCopyTexImage2D(0x0DE1, 0, 0x8058, 0, 0, d->req_size.width(), d->req_size.height(), 0); | - |
365 | #else | - |
366 | glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, d->req_size.width(), d->req_size.height(), 0); | - |
367 | #endif | - |
368 | | - |
369 | if (d->blit_fbo) never evaluated: d->blit_fbo | 0 |
370 | extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, ctx->d_func()->current_fbo); never executed: extensions.glBindFramebuffer(0x8CA8, ctx->d_func()->current_fbo); | 0 |
371 | } | 0 |
372 | | - |
373 | /*! | - |
374 | Returns the size of the pbuffer. | - |
375 | */ | - |
376 | QSize QGLPixelBuffer::size() const | - |
377 | { | - |
378 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
379 | return d->req_size; never executed: return d->req_size; | 0 |
380 | } | - |
381 | | - |
382 | /*! | - |
383 | Returns the contents of the pbuffer as a QImage. | - |
384 | */ | - |
385 | QImage QGLPixelBuffer::toImage() const | - |
386 | { | - |
387 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
388 | if (d->invalid) never evaluated: d->invalid | 0 |
389 | return QImage(); never executed: return QImage(); | 0 |
390 | | - |
391 | const_cast<QGLPixelBuffer *>(this)->makeCurrent(); never executed (the execution status of this line is deduced): const_cast<QGLPixelBuffer *>(this)->makeCurrent(); | - |
392 | if (d->fbo) | 0 |
393 | d->fbo->bind(); never executed: d->fbo->bind(); | 0 |
394 | return qt_gl_read_frame_buffer(d->req_size, d->format.alpha(), true); never executed: return qt_gl_read_frame_buffer(d->req_size, d->format.alpha(), true); | 0 |
395 | } | - |
396 | | - |
397 | /*! | - |
398 | Returns the native pbuffer handle. | - |
399 | */ | - |
400 | Qt::HANDLE QGLPixelBuffer::handle() const | - |
401 | { | - |
402 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
403 | if (d->invalid) never evaluated: d->invalid | 0 |
404 | return 0; never executed: return 0; | 0 |
405 | return (Qt::HANDLE) d->pbuf; never executed: return (Qt::HANDLE) d->pbuf; | 0 |
406 | } | - |
407 | | - |
408 | /*! | - |
409 | Returns true if this pbuffer is valid; otherwise returns false. | - |
410 | */ | - |
411 | bool QGLPixelBuffer::isValid() const | - |
412 | { | - |
413 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
414 | return !d->invalid; never executed: return !d->invalid; | 0 |
415 | } | - |
416 | | - |
417 | Q_GLOBAL_STATIC(QGLEngineThreadStorage<QGL2PaintEngineEx>, qt_buffer_2_engine) never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
418 | | - |
419 | /*! \reimp */ | - |
420 | QPaintEngine *QGLPixelBuffer::paintEngine() const | - |
421 | { | - |
422 | return qt_buffer_2_engine()->engine(); never executed: return qt_buffer_2_engine()->engine(); | 0 |
423 | } | - |
424 | | - |
425 | /*! \reimp */ | - |
426 | int QGLPixelBuffer::metric(PaintDeviceMetric metric) const | - |
427 | { | - |
428 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
429 | | - |
430 | float dpmx = qt_defaultDpiX()*100./2.54; never executed (the execution status of this line is deduced): float dpmx = qt_defaultDpiX()*100./2.54; | - |
431 | float dpmy = qt_defaultDpiY()*100./2.54; never executed (the execution status of this line is deduced): float dpmy = qt_defaultDpiY()*100./2.54; | - |
432 | int w = d->req_size.width(); never executed (the execution status of this line is deduced): int w = d->req_size.width(); | - |
433 | int h = d->req_size.height(); never executed (the execution status of this line is deduced): int h = d->req_size.height(); | - |
434 | switch (metric) { | - |
435 | case PdmWidth: | - |
436 | return w; never executed: return w; | 0 |
437 | | - |
438 | case PdmHeight: | - |
439 | return h; never executed: return h; | 0 |
440 | | - |
441 | case PdmWidthMM: | - |
442 | return qRound(w * 1000 / dpmx); never executed: return qRound(w * 1000 / dpmx); | 0 |
443 | | - |
444 | case PdmHeightMM: | - |
445 | return qRound(h * 1000 / dpmy); never executed: return qRound(h * 1000 / dpmy); | 0 |
446 | | - |
447 | case PdmNumColors: | - |
448 | return 0; never executed: return 0; | 0 |
449 | | - |
450 | case PdmDepth: | - |
451 | return 32;//d->depth; never executed: return 32; | 0 |
452 | | - |
453 | case PdmDpiX: | - |
454 | return qRound(dpmx * 0.0254); never executed: return qRound(dpmx * 0.0254); | 0 |
455 | | - |
456 | case PdmDpiY: | - |
457 | return qRound(dpmy * 0.0254); never executed: return qRound(dpmy * 0.0254); | 0 |
458 | | - |
459 | case PdmPhysicalDpiX: | - |
460 | return qRound(dpmx * 0.0254); never executed: return qRound(dpmx * 0.0254); | 0 |
461 | | - |
462 | case PdmPhysicalDpiY: | - |
463 | return qRound(dpmy * 0.0254); never executed: return qRound(dpmy * 0.0254); | 0 |
464 | | - |
465 | default: | - |
466 | qWarning("QGLPixelBuffer::metric(), Unhandled metric type: %d\n", metric); never executed (the execution status of this line is deduced): QMessageLogger("qglpixelbuffer.cpp", 466, __PRETTY_FUNCTION__).warning("QGLPixelBuffer::metric(), Unhandled metric type: %d\n", metric); | - |
467 | break; | 0 |
468 | } | - |
469 | return 0; never executed: return 0; | 0 |
470 | } | - |
471 | | - |
472 | /*! | - |
473 | Generates and binds a 2D GL texture to the current context, based | - |
474 | on \a image. The generated texture id is returned and can be used | - |
475 | in later glBindTexture() calls. | - |
476 | | - |
477 | The \a target parameter specifies the texture target. | - |
478 | | - |
479 | Equivalent to calling QGLContext::bindTexture(). | - |
480 | | - |
481 | \sa deleteTexture() | - |
482 | */ | - |
483 | GLuint QGLPixelBuffer::bindTexture(const QImage &image, GLenum target) | - |
484 | { | - |
485 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
486 | #ifndef QT_OPENGL_ES | - |
487 | return d->qctx->bindTexture(image, target, GLint(GL_RGBA8)); never executed: return d->qctx->bindTexture(image, target, GLint(0x8058)); | 0 |
488 | #else | - |
489 | return d->qctx->bindTexture(image, target, GL_RGBA); | - |
490 | #endif | - |
491 | } | - |
492 | | - |
493 | /*! \overload | - |
494 | | - |
495 | Generates and binds a 2D GL texture based on \a pixmap. | - |
496 | | - |
497 | Equivalent to calling QGLContext::bindTexture(). | - |
498 | | - |
499 | \sa deleteTexture() | - |
500 | */ | - |
501 | GLuint QGLPixelBuffer::bindTexture(const QPixmap &pixmap, GLenum target) | - |
502 | { | - |
503 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
504 | #ifndef QT_OPENGL_ES | - |
505 | return d->qctx->bindTexture(pixmap, target, GLint(GL_RGBA8)); never executed: return d->qctx->bindTexture(pixmap, target, GLint(0x8058)); | 0 |
506 | #else | - |
507 | return d->qctx->bindTexture(pixmap, target, GL_RGBA); | - |
508 | #endif | - |
509 | } | - |
510 | | - |
511 | /*! \overload | - |
512 | | - |
513 | Reads the DirectDrawSurface (DDS) compressed file \a fileName and | - |
514 | generates a 2D GL texture from it. | - |
515 | | - |
516 | Equivalent to calling QGLContext::bindTexture(). | - |
517 | | - |
518 | \sa deleteTexture() | - |
519 | */ | - |
520 | GLuint QGLPixelBuffer::bindTexture(const QString &fileName) | - |
521 | { | - |
522 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
523 | return d->qctx->bindTexture(fileName); never executed: return d->qctx->bindTexture(fileName); | 0 |
524 | } | - |
525 | | - |
526 | /*! | - |
527 | Removes the texture identified by \a texture_id from the texture cache. | - |
528 | | - |
529 | Equivalent to calling QGLContext::deleteTexture(). | - |
530 | */ | - |
531 | void QGLPixelBuffer::deleteTexture(GLuint texture_id) | - |
532 | { | - |
533 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
534 | d->qctx->deleteTexture(texture_id); never executed (the execution status of this line is deduced): d->qctx->deleteTexture(texture_id); | - |
535 | } | 0 |
536 | | - |
537 | /*! | - |
538 | \since 4.4 | - |
539 | | - |
540 | Draws the given texture, \a textureId, to the given target rectangle, | - |
541 | \a target, in OpenGL model space. The \a textureTarget should be a 2D | - |
542 | texture target. | - |
543 | | - |
544 | Equivalent to the corresponding QGLContext::drawTexture(). | - |
545 | */ | - |
546 | void QGLPixelBuffer::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) | - |
547 | { | - |
548 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
549 | d->qctx->drawTexture(target, textureId, textureTarget); never executed (the execution status of this line is deduced): d->qctx->drawTexture(target, textureId, textureTarget); | - |
550 | } | 0 |
551 | | - |
552 | /*! | - |
553 | \since 4.4 | - |
554 | | - |
555 | Draws the given texture, \a textureId, at the given \a point in OpenGL model | - |
556 | space. The textureTarget parameter should be a 2D texture target. | - |
557 | | - |
558 | Equivalent to the corresponding QGLContext::drawTexture(). | - |
559 | */ | - |
560 | void QGLPixelBuffer::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) | - |
561 | { | - |
562 | Q_D(QGLPixelBuffer); never executed (the execution status of this line is deduced): QGLPixelBufferPrivate * const d = d_func(); | - |
563 | d->qctx->drawTexture(point, textureId, textureTarget); never executed (the execution status of this line is deduced): d->qctx->drawTexture(point, textureId, textureTarget); | - |
564 | } | 0 |
565 | | - |
566 | /*! | - |
567 | Returns the format of the pbuffer. The format may be different | - |
568 | from the one that was requested. | - |
569 | */ | - |
570 | QGLFormat QGLPixelBuffer::format() const | - |
571 | { | - |
572 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
573 | return d->format; never executed: return d->format; | 0 |
574 | } | - |
575 | | - |
576 | /*! \fn int QGLPixelBuffer::devType() const | - |
577 | \internal | - |
578 | */ | - |
579 | | - |
580 | bool QGLPixelBufferPrivate::init(const QSize &, const QGLFormat &f, QGLWidget *shareWidget) | - |
581 | { | - |
582 | widget = new QGLWidget(f, 0, shareWidget); never executed (the execution status of this line is deduced): widget = new QGLWidget(f, 0, shareWidget); | - |
583 | widget->resize(1, 1); never executed (the execution status of this line is deduced): widget->resize(1, 1); | - |
584 | qctx = const_cast<QGLContext *>(widget->context()); never executed (the execution status of this line is deduced): qctx = const_cast<QGLContext *>(widget->context()); | - |
585 | return widget->isValid(); never executed: return widget->isValid(); | 0 |
586 | } | - |
587 | | - |
588 | bool QGLPixelBufferPrivate::cleanup() | - |
589 | { | - |
590 | delete fbo; never executed (the execution status of this line is deduced): delete fbo; | - |
591 | fbo = 0; never executed (the execution status of this line is deduced): fbo = 0; | - |
592 | delete blit_fbo; never executed (the execution status of this line is deduced): delete blit_fbo; | - |
593 | blit_fbo = 0; never executed (the execution status of this line is deduced): blit_fbo = 0; | - |
594 | delete widget; never executed (the execution status of this line is deduced): delete widget; | - |
595 | widget = 0; never executed (the execution status of this line is deduced): widget = 0; | - |
596 | return true; never executed: return true; | 0 |
597 | } | - |
598 | | - |
599 | bool QGLPixelBuffer::bindToDynamicTexture(GLuint texture_id) | - |
600 | { | - |
601 | Q_UNUSED(texture_id); never executed (the execution status of this line is deduced): (void)texture_id;; | - |
602 | return false; never executed: return false; | 0 |
603 | } | - |
604 | | - |
605 | void QGLPixelBuffer::releaseFromDynamicTexture() | - |
606 | { | - |
607 | } | - |
608 | | - |
609 | GLuint QGLPixelBuffer::generateDynamicTexture() const | - |
610 | { | - |
611 | Q_D(const QGLPixelBuffer); never executed (the execution status of this line is deduced): const QGLPixelBufferPrivate * const d = d_func(); | - |
612 | if (!d->fbo) | 0 |
613 | return 0; never executed: return 0; | 0 |
614 | | - |
615 | if (d->fbo->format().samples() > 0 never evaluated: d->fbo->format().samples() > 0 | 0 |
616 | && QOpenGLExtensions(QOpenGLContext::currentContext()) never evaluated: QOpenGLExtensions(QOpenGLContext::currentContext()) .hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit) | 0 |
617 | .hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit)) never evaluated: QOpenGLExtensions(QOpenGLContext::currentContext()) .hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit) | 0 |
618 | { | - |
619 | if (!d->blit_fbo) never evaluated: !d->blit_fbo | 0 |
620 | const_cast<QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size); never executed: const_cast<QOpenGLFramebufferObject *&>(d->blit_fbo) = new QOpenGLFramebufferObject(d->req_size); | 0 |
621 | } else { | 0 |
622 | return d->fbo->texture(); never executed: return d->fbo->texture(); | 0 |
623 | } | - |
624 | | - |
625 | GLuint texture; never executed (the execution status of this line is deduced): GLuint texture; | - |
626 | | - |
627 | glGenTextures(1, &texture); never executed (the execution status of this line is deduced): glGenTextures(1, &texture); | - |
628 | glBindTexture(GL_TEXTURE_2D, texture); never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, texture); | - |
629 | | - |
630 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2801, 0x2600); | - |
631 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2800, 0x2600); | - |
632 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2802, 0x812F); | - |
633 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2803, 0x812F); | - |
634 | | - |
635 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, d->req_size.width(), d->req_size.height(), 0, never executed (the execution status of this line is deduced): glTexImage2D(0x0DE1, 0, 0x1908, d->req_size.width(), d->req_size.height(), 0, | - |
636 | GL_RGBA, GL_UNSIGNED_BYTE, 0); never executed (the execution status of this line is deduced): 0x1908, 0x1401, 0); | - |
637 | | - |
638 | return texture; never executed: return texture; | 0 |
639 | } | - |
640 | | - |
641 | bool QGLPixelBuffer::hasOpenGLPbuffers() | - |
642 | { | - |
643 | return QGLFramebufferObject::hasOpenGLFramebufferObjects(); never executed: return QGLFramebufferObject::hasOpenGLFramebufferObjects(); | 0 |
644 | } | - |
645 | | - |
646 | QT_END_NAMESPACE | - |
647 | | - |
| | |