Qt 4.8
qpixmapdata_gl.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 #include "qpixmap.h"
43 #include "qglframebufferobject.h"
44 
45 #include <private/qpaintengine_raster_p.h>
46 
47 #include "qpixmapdata_gl_p.h"
48 
49 #include <private/qgl_p.h>
50 #include <private/qdrawhelper_p.h>
51 #include <private/qimage_p.h>
52 #include <private/qfont_p.h>
53 
54 #include <private/qpaintengineex_opengl2_p.h>
55 
56 #include <qdesktopwidget.h>
57 #include <qfile.h>
58 #include <qimagereader.h>
59 #include <qbuffer.h>
60 
62 
64 
81 static inline int areaDiff(const QSize &size, const QGLFramebufferObject *fbo)
82 {
83  return qAbs(size.width() * size.height() - fbo->width() * fbo->height());
84 }
85 
86 extern int qt_next_power_of_two(int v);
87 
88 static inline QSize maybeRoundToNextPowerOfTwo(const QSize &sz)
89 {
90 #ifdef QT_OPENGL_ES_2
92  if (rounded.width() * rounded.height() < 1.20 * sz.width() * sz.height())
93  return rounded;
94 #endif
95  return sz;
96 }
97 
98 
99 QGLFramebufferObject *QGLFramebufferObjectPool::acquire(const QSize &requestSize, const QGLFramebufferObjectFormat &requestFormat, bool strictSize)
100 {
101  QGLFramebufferObject *chosen = 0;
102  QGLFramebufferObject *candidate = 0;
103  for (int i = 0; !chosen && i < m_fbos.size(); ++i) {
104  QGLFramebufferObject *fbo = m_fbos.at(i);
105 
106  if (strictSize) {
107  if (fbo->size() == requestSize && fbo->format() == requestFormat) {
108  chosen = fbo;
109  break;
110  } else {
111  continue;
112  }
113  }
114 
115  if (fbo->format() == requestFormat) {
116  // choose the fbo with a matching format and the closest size
117  if (!candidate || areaDiff(requestSize, candidate) > areaDiff(requestSize, fbo))
118  candidate = fbo;
119  }
120 
121  if (candidate) {
122  m_fbos.removeOne(candidate);
123 
124  const QSize fboSize = candidate->size();
125  QSize sz = fboSize;
126 
127  if (sz.width() < requestSize.width())
128  sz.setWidth(qMax(requestSize.width(), qRound(sz.width() * 1.5)));
129  if (sz.height() < requestSize.height())
130  sz.setHeight(qMax(requestSize.height(), qRound(sz.height() * 1.5)));
131 
132  // wasting too much space?
133  if (sz.width() * sz.height() > requestSize.width() * requestSize.height() * 4)
134  sz = requestSize;
135 
136  if (sz != fboSize) {
137  delete candidate;
138  candidate = new QGLFramebufferObject(maybeRoundToNextPowerOfTwo(sz), requestFormat);
139  }
140 
141  chosen = candidate;
142  }
143  }
144 
145  if (!chosen) {
146  if (strictSize)
147  chosen = new QGLFramebufferObject(requestSize, requestFormat);
148  else
149  chosen = new QGLFramebufferObject(maybeRoundToNextPowerOfTwo(requestSize), requestFormat);
150  }
151 
152  if (!chosen->isValid()) {
153  delete chosen;
154  chosen = 0;
155  }
156 
157  return chosen;
158 }
159 
161 {
162  if (fbo)
163  m_fbos << fbo;
164 }
165 
166 
168 {
169  return data->paintEngine();
170 }
171 
173 {
174  if (!data->isValid())
175  return;
176 
177  // QGLPaintDevice::beginPaint will store the current binding and replace
178  // it with m_thisFBO:
179  m_thisFBO = data->m_renderFbo->handle();
181 
182  Q_ASSERT(data->paintEngine()->type() == QPaintEngine::OpenGL2);
183 
184  // QPixmap::fill() is deferred until now, where we actually need to do the fill:
185  if (data->needsFill()) {
186  const QColor &c = data->fillColor();
187  float alpha = c.alphaF();
188  glDisable(GL_SCISSOR_TEST);
189  glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha);
190  glClear(GL_COLOR_BUFFER_BIT);
191  }
192  else if (!data->isUninitialized()) {
193  // If the pixmap (GL Texture) has valid content (it has been
194  // uploaded from an image or rendered into before), we need to
195  // copy it from the texture to the render FBO.
196 
197  glDisable(GL_DEPTH_TEST);
198  glDisable(GL_SCISSOR_TEST);
199  glDisable(GL_BLEND);
200 
201 #if !defined(QT_OPENGL_ES_2)
202  glMatrixMode(GL_MODELVIEW);
203  glLoadIdentity();
204 
205  glMatrixMode(GL_PROJECTION);
206  glLoadIdentity();
207  glOrtho(0, data->width(), data->height(), 0, -999999, 999999);
208 #endif
209 
210  glViewport(0, 0, data->width(), data->height());
211 
212  // Pass false to bind so it doesn't copy the FBO into the texture!
213  context()->drawTexture(QRect(0, 0, data->width(), data->height()), data->bind(false));
214  }
215 }
216 
218 {
219  if (!data->isValid())
220  return;
221 
222  data->copyBackFromRenderFbo(false);
223 
224  // Base's endPaint will restore the previous FBO binding
226 
227  qgl_fbo_pool()->release(data->m_renderFbo);
228  data->m_renderFbo = 0;
229 }
230 
232 {
233  data->ensureCreated();
234  return data->m_ctx;
235 }
236 
238 {
239  return data->size();
240 }
241 
243 {
244  return data->m_hasAlpha;
245 }
246 
248 {
249  data = d;
250 }
251 
252 static int qt_gl_pixmap_serial = 0;
253 
255  : QPixmapData(type, OpenGLClass)
256  , m_renderFbo(0)
257  , m_engine(0)
258  , m_ctx(0)
259  , m_dirty(false)
260  , m_hasFillColor(false)
261  , m_hasAlpha(false)
262 {
265 }
266 
268 {
269  const QGLContext *shareContext = qt_gl_share_context();
270  if (!shareContext)
271  return;
272 
273  delete m_engine;
274 
275  if (m_texture.id) {
276  QGLShareContextScope ctx(shareContext);
277  glDeleteTextures(1, &m_texture.id);
278  }
279 }
280 
282 {
283  return new QGLPixmapData(pixelType());
284 }
285 
287 {
288  return w > 0 && h > 0;
289 }
290 
292 {
293  if (ctx == m_ctx)
294  return true;
295 
296  const QGLContext *share_ctx = qt_gl_share_context();
297  return ctx == share_ctx || QGLContext::areSharing(ctx, share_ctx);
298 }
299 
301 {
302  if (width == w && height == h)
303  return;
304 
305  if (width <= 0 || height <= 0) {
306  width = 0;
307  height = 0;
308  }
309 
310  w = width;
311  h = height;
312  is_null = (w <= 0 || h <= 0);
313  d = pixelType() == QPixmapData::PixmapType ? 32 : 1;
314 
315  if (m_texture.id) {
317  glDeleteTextures(1, &m_texture.id);
318  m_texture.id = 0;
319  }
320 
321  m_source = QImage();
322  m_dirty = isValid();
324 }
325 
327 {
328  if (!m_dirty)
329  return;
330 
331  m_dirty = false;
332 
334  m_ctx = ctx;
335 
336  const GLenum internal_format = m_hasAlpha ? GL_RGBA : GL_RGB;
337 #ifdef QT_OPENGL_ES_2
338  const GLenum external_format = internal_format;
339 #else
340  const GLenum external_format = qt_gl_preferredTextureFormat();
341 #endif
342  const GLenum target = GL_TEXTURE_2D;
343 
344  if (!m_texture.id) {
345  glGenTextures(1, &m_texture.id);
346  glBindTexture(target, m_texture.id);
347  glTexImage2D(target, 0, internal_format, w, h, 0, external_format, GL_UNSIGNED_BYTE, 0);
350  }
351 
352  if (!m_source.isNull()) {
353  if (external_format == GL_RGB) {
355 
356  glBindTexture(target, m_texture.id);
357  glTexSubImage2D(target, 0, 0, 0, w, h, external_format,
358  GL_UNSIGNED_BYTE, tx.bits());
359  } else {
360  const QImage tx = ctx->d_func()->convertToGLFormat(m_source, true, external_format);
361 
362  glBindTexture(target, m_texture.id);
363  glTexSubImage2D(target, 0, 0, 0, w, h, external_format,
364  GL_UNSIGNED_BYTE, tx.bits());
365  }
366 
367  if (useFramebufferObjects())
368  m_source = QImage();
369  }
370 
371  m_texture.options &= ~QGLContext::MemoryManagedBindOption;
372 }
373 
375  Qt::ImageConversionFlags flags)
376 {
377  QImage img = image;
378  createPixmapForImage(img, flags, false);
379 }
380 
382  Qt::ImageConversionFlags flags)
383 {
384  QImage image = imageReader->read();
385  if (image.isNull())
386  return;
387 
388  createPixmapForImage(image, flags, true);
389 }
390 
391 bool QGLPixmapData::fromFile(const QString &filename, const char *format,
392  Qt::ImageConversionFlags flags)
393 {
395  return QPixmapData::fromFile(filename, format, flags);
396  QFile file(filename);
397  if (file.open(QIODevice::ReadOnly)) {
398  QByteArray data = file.peek(64);
399  bool alpha;
401  (data.constData(), data.size(), format, &alpha)) {
402  resize(0, 0);
403  data = file.readAll();
404  file.close();
407  (data.constData(), data.size(), format);
408  if (!size.isEmpty()) {
409  w = size.width();
410  h = size.height();
411  is_null = false;
412  d = 32;
413  m_hasAlpha = alpha;
414  m_source = QImage();
415  m_dirty = isValid();
416  return true;
417  }
418  return false;
419  }
420  }
421 
422  QImage image = QImageReader(filename, format).read();
423  if (image.isNull())
424  return false;
425 
426  createPixmapForImage(image, flags, true);
427 
428  return !isNull();
429 }
430 
431 bool QGLPixmapData::fromData(const uchar *buffer, uint len, const char *format,
432  Qt::ImageConversionFlags flags)
433 {
434  bool alpha;
435  const char *buf = reinterpret_cast<const char *>(buffer);
436  if (m_texture.canBindCompressedTexture(buf, int(len), format, &alpha)) {
437  resize(0, 0);
439  QSize size = m_texture.bindCompressedTexture(buf, int(len), format);
440  if (!size.isEmpty()) {
441  w = size.width();
442  h = size.height();
443  is_null = false;
444  d = 32;
445  m_hasAlpha = alpha;
446  m_source = QImage();
447  m_dirty = isValid();
448  return true;
449  }
450  }
451 
452  QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len);
453  QBuffer b(&a);
455  QImage image = QImageReader(&b, format).read();
456  if (image.isNull())
457  return false;
458 
459  createPixmapForImage(image, flags, true);
460 
461  return !isNull();
462 }
463 
467 void QGLPixmapData::createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
468 {
469  if (image.size() == QSize(w, h))
471 
472  resize(image.width(), image.height());
473 
474  if (pixelType() == BitmapType) {
476 
477  } else {
479  if (qApp->desktop()->depth() == 16)
480  format = QImage::Format_RGB16;
481 
482  if (image.hasAlphaChannel()
483  && ((flags & Qt::NoOpaqueDetection)
484  || const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels()))
486 
487  if (inPlace && image.data_ptr()->convertInPlace(format, flags)) {
488  m_source = image;
489  } else {
490  m_source = image.convertToFormat(format);
491 
492  // convertToFormat won't detach the image if format stays the same.
493  if (image.format() == format)
494  m_source.detach();
495  }
496  }
497 
498  m_dirty = true;
499  m_hasFillColor = false;
500 
502  w = image.width();
503  h = image.height();
504  is_null = (w <= 0 || h <= 0);
505  d = m_source.depth();
506 
507  if (m_texture.id) {
509  glDeleteTextures(1, &m_texture.id);
510  m_texture.id = 0;
511  }
512 }
513 
514 bool QGLPixmapData::scroll(int dx, int dy, const QRect &rect)
515 {
516  Q_UNUSED(dx);
517  Q_UNUSED(dy);
518  Q_UNUSED(rect);
519  return false;
520 }
521 
522 void QGLPixmapData::copy(const QPixmapData *data, const QRect &rect)
523 {
524  if (data->classId() != QPixmapData::OpenGLClass || !static_cast<const QGLPixmapData *>(data)->useFramebufferObjects()) {
525  QPixmapData::copy(data, rect);
526  return;
527  }
528 
529  const QGLPixmapData *other = static_cast<const QGLPixmapData *>(data);
530  if (other->m_renderFbo) {
532 
533  resize(rect.width(), rect.height());
534  m_hasAlpha = other->m_hasAlpha;
535  ensureCreated();
536 
537  if (!ctx->d_ptr->fbo)
538  glGenFramebuffers(1, &ctx->d_ptr->fbo);
539 
543 
544  if (!other->m_renderFbo->isBound())
546 
547  glDisable(GL_SCISSOR_TEST);
549  static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine)->invalidateState();
550 
551  glBlitFramebufferEXT(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height(),
552  0, 0, w, h,
554  GL_NEAREST);
555 
557  } else {
558  QPixmapData::copy(data, rect);
559  }
560 }
561 
562 void QGLPixmapData::fill(const QColor &color)
563 {
564  if (!isValid())
565  return;
566 
567  bool hasAlpha = color.alpha() != 255;
568  if (hasAlpha && !m_hasAlpha) {
569  if (m_texture.id) {
570  glDeleteTextures(1, &m_texture.id);
571  m_texture.id = 0;
572  m_dirty = true;
573  }
574  m_hasAlpha = color.alpha() != 255;
575  }
576 
577  if (useFramebufferObjects()) {
578  m_source = QImage();
579  m_hasFillColor = true;
580  m_fillColor = color;
581  } else {
582 
583  if (m_source.isNull()) {
584  m_fillColor = color;
585  m_hasFillColor = true;
586 
587  } else if (m_source.depth() == 32) {
588  m_source.fill(PREMUL(color.rgba()));
589 
590  } else if (m_source.depth() == 1) {
591  if (color == Qt::color1)
592  m_source.fill(1);
593  else
594  m_source.fill(0);
595  }
596  }
597 }
598 
600 {
601  return m_hasAlpha;
602 }
603 
605 {
606  QImage img;
607  if (pixelType() == BitmapType) {
608  img = QImage(w, h, QImage::Format_MonoLSB);
609 
610  img.setColorCount(2);
611  img.setColor(0, QColor(Qt::color0).rgba());
612  img.setColor(1, QColor(Qt::color1).rgba());
613 
614  if (color == Qt::color1)
615  img.fill(1);
616  else
617  img.fill(0);
618  } else {
619  img = QImage(w, h,
620  m_hasAlpha
623  img.fill(PREMUL(color.rgba()));
624  }
625  return img;
626 }
627 
628 extern QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha);
629 
631 {
632  if (!isValid())
633  return QImage();
634 
635  if (m_renderFbo) {
636  copyBackFromRenderFbo(true);
637  } else if (!m_source.isNull()) {
638  QImageData *data = const_cast<QImage &>(m_source).data_ptr();
639  if (data->paintEngine && data->paintEngine->isActive()
640  && data->paintEngine->paintDevice() == &m_source)
641  {
642  return m_source.copy();
643  }
644  return m_source;
645  } else if (m_dirty || m_hasFillColor) {
646  return fillImage(m_fillColor);
647  } else {
648  ensureCreated();
649  }
650 
652  glBindTexture(GL_TEXTURE_2D, m_texture.id);
653  return qt_gl_read_texture(QSize(w, h), true, true);
654 }
655 
657 {
660 };
661 
664 {
665  return _qgl_fbo_pool();
666 }
667 
668 void QGLPixmapData::copyBackFromRenderFbo(bool keepCurrentFboBound) const
669 {
670  if (!isValid())
671  return;
672 
673  m_hasFillColor = false;
674 
675  const QGLContext *share_ctx = qt_gl_share_context();
676  QGLShareContextScope ctx(share_ctx);
677 
678  ensureCreated();
679 
680  if (!ctx->d_ptr->fbo)
681  glGenFramebuffers(1, &ctx->d_ptr->fbo);
682 
686 
687  const int x0 = 0;
688  const int x1 = w;
689  const int y0 = 0;
690  const int y1 = h;
691 
692  if (!m_renderFbo->isBound())
694 
695  glDisable(GL_SCISSOR_TEST);
696 
697  glBlitFramebufferEXT(x0, y0, x1, y1,
698  x0, y0, x1, y1,
700  GL_NEAREST);
701 
702  if (keepCurrentFboBound) {
704  } else {
706  ctx->d_ptr->current_fbo = m_renderFbo->handle();
707  }
708 }
709 
711 {
715  && (w * h > 32*32); // avoid overhead of FBOs for small pixmaps
716 }
717 
719 {
720  if (!isValid())
721  return 0;
722 
723  if (m_renderFbo)
724  return m_engine;
725 
726  if (useFramebufferObjects()) {
727  extern QGLWidget* qt_gl_share_widget();
728 
730  const_cast<QGLContext *>(qt_gl_share_context())->makeCurrent();
732 
735  format.setSamples(4);
737 
738  m_renderFbo = qgl_fbo_pool()->acquire(size(), format);
739 
740  if (m_renderFbo) {
741  if (!m_engine)
743  return m_engine;
744  }
745 
746  qWarning() << "Failed to create pixmap texture buffer of size " << size() << ", falling back to raster paint engine";
747  }
748 
749  m_dirty = true;
750  if (m_source.size() != size())
752  if (m_hasFillColor) {
754  m_hasFillColor = false;
755  }
756  return m_source.paintEngine();
757 }
758 
759 extern QRgb qt_gl_convertToGLFormat(QRgb src_pixel, GLenum texture_format);
760 
761 // If copyBack is true, bind will copy the contents of the render
762 // FBO to the texture (which is not bound to the texture, as it's
763 // a multisample FBO).
764 GLuint QGLPixmapData::bind(bool copyBack) const
765 {
766  if (m_renderFbo && copyBack) {
767  copyBackFromRenderFbo(true);
768  } else {
769  ensureCreated();
770  }
771 
772  GLuint id = m_texture.id;
773  glBindTexture(GL_TEXTURE_2D, id);
774 
775  if (m_hasFillColor) {
776  if (!useFramebufferObjects()) {
779  }
780 
781  m_hasFillColor = false;
782 
786  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, GL_UNSIGNED_BYTE, tx.bits());
787  }
788 
789  return id;
790 }
791 
793 {
794  return &m_texture;
795 }
796 
798 {
799  if (w == 0)
800  return 0;
801 
802  switch (metric) {
804  return w;
806  return h;
808  return 0;
810  return d;
812  return qRound(w * 25.4 / qt_defaultDpiX());
814  return qRound(h * 25.4 / qt_defaultDpiY());
817  return qt_defaultDpiX();
820  return qt_defaultDpiY();
821  default:
822  qWarning("QGLPixmapData::metric(): Invalid metric");
823  return 0;
824  }
825 }
826 
828 {
829  return &m_glDevice;
830 }
831 
QGLTexture m_texture
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
GLuint fbo
Definition: qgl_p.h:420
static bool hasOpenGLFramebufferObjects()
Returns true if the OpenGL GL_EXT_framebuffer_object extension is present on this system; otherwise r...
virtual bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
QGLContext * m_ctx
QSize size() const
Returns the size of the texture attached to this framebuffer object.
QGLPaintDevice * glDevice() const
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
QGLFramebufferObjectPool * qgl_fbo_pool()
Format
The following image formats are available in Qt.
Definition: qimage.h:91
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
bool canBindCompressedTexture(const char *buf, int len, const char *format, bool *hasAlpha)
Definition: qgl.cpp:6057
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
unsigned int QRgb
Definition: qrgb.h:53
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha)
Definition: qgl.cpp:1871
void setAttachment(QGLFramebufferObject::Attachment attachment)
Sets the attachment configuration of a framebuffer object to attachment.
#define GL_RGB
int type
Definition: qmetatype.cpp:239
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
#define GL_TEXTURE_MIN_FILTER
unsigned char c[8]
Definition: qnumeric_p.h:62
QPixmapData * createCompatiblePixmapData() const
QGLPixmapGLPaintDevice m_glDevice
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void fill(const QColor &color)
bool isValidContext(const QGLContext *ctx) const
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
#define GL_DEPTH_TEST
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
#define Q_OPENGL_EXPORT
Definition: qglobal.h:1455
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
Q_OPENGL_EXPORT QGLWidget * qt_gl_share_widget()
bool isValid() const
Returns true if the framebuffer object is valid.
int height() const
Definition: qpaintdevice.h:92
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
GLuint bind(bool copyBack=true) const
void setInternalTextureFormat(GLenum internalTextureFormat)
Sets the internal format of a framebuffer object&#39;s texture or multisample framebuffer object&#39;s color ...
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
QGLContext * context() const
The QGLFramebufferObject class provides a pool of framebuffer objects for offscreen rendering purpose...
QRgb qt_gl_convertToGLFormat(QRgb src_pixel, GLenum texture_format)
Definition: qgl.cpp:2281
QGL2PaintEngineEx * engine
int width() const
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
long ASN1_INTEGER_get ASN1_INTEGER * a
int metric(QPaintDevice::PaintDeviceMetric metric) const
int qt_next_power_of_two(int v)
Definition: qgl.cpp:1886
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define GL_FRAMEBUFFER_EXT
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
QPaintEngine * m_engine
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define glBindFramebuffer
void copyBackFromRenderFbo(bool keepCurrentFboBound) const
QGLContext::BindOptions options
Definition: qgl_p.h:611
#define GL_TEXTURE_2D
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
#define GL_COLOR_ATTACHMENT0_EXT
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define GL_SCISSOR_TEST
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
QGLFramebufferObject * acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize=false)
static bool areSharing(const QGLContext *context1, const QGLContext *context2)
Returns true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.
Definition: qgl.cpp:3319
#define glBlitFramebufferEXT
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
PixelType pixelType() const
unsigned char uchar
Definition: qglobal.h:994
QGLTexture * texture() const
bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
int width() const
Returns the width.
Definition: qsize.h:126
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int width() const
Definition: qpaintdevice.h:91
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
QImage toImage() const
void ensureCreated() const
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isValid() const
QGLPixmapData(PixelType type)
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
#define qApp
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
QList< QGLFramebufferObject * > m_fbos
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void setSamples(int samples)
Sets the number of samples per pixel for a multisample framebuffer object to samples.
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
QGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
void resize(int width, int height)
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
void release(QGLFramebufferObject *fbo)
QSize size() const
qint64 peek(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, without side effects (i.
Definition: qiodevice.cpp:1563
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
QPaintEngine * paintEngine
Definition: qimage_p.h:110
Q_CORE_EXPORT void qWarning(const char *,...)
#define glGenFramebuffers
#define GL_COLOR_BUFFER_BIT
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
ClassId classId() const
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
bool useFramebufferObjects() const
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
QImage mirrored(bool horizontally=false, bool vertically=true) const
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on ...
Definition: qimage.cpp:4922
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
#define GL_DRAW_FRAMEBUFFER_EXT
void fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags)
bool qt_gl_preferGL2Engine()
Definition: qgl.cpp:218
QPaintEngine * paintEngine() const
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
DataPtr & data_ptr()
Definition: qimage.h:346
#define GL_READ_FRAMEBUFFER_EXT
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
#define GL_BLEND
bool hasAlphaChannel() const
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
GLuint current_fbo
Definition: qgl_p.h:456
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
unsigned int GLenum
Definition: main.cpp:50
QGLFramebufferObject * fbo
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
virtual void beginPaint()
#define GL_UNSIGNED_BYTE
void * data_ptr(const QTransform &t)
Definition: qpainter_p.h:81
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
out-of-place conversion (inPlace == false) will always detach()
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void setPixmapData(QGLPixmapData *)
#define ctx
Definition: qgl.cpp:6094
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
virtual void copy(const QPixmapData *data, const QRect &rect)
int height() const
Returns the height.
Definition: qsize.h:129
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QGLFramebufferObject * m_renderFbo
virtual QImage * buffer()
#define GL_RGBA
bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
int height() const
QPaintEngine * paintEngine() const
Used by QPainter to retrieve a paint engine for the image.
Definition: qimage.cpp:5970
bool isNull() const
static QSize maybeRoundToNextPowerOfTwo(const QSize &sz)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QImage fillImage(const QColor &color) const
bool convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags)
Definition: qimage.cpp:6935
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
QPaintEngine * paintEngine() const
#define GL_TEXTURE_MAG_FILTER
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
#define glFramebufferTexture2D
void setSerialNumber(int serNo)
QPaintEngine * active_engine
Definition: qgl_p.h:458
static int areaDiff(const QSize &size, const QGLFramebufferObject *fbo)
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
The QGLFramebufferObjectFormat class specifies the format of an OpenGL framebuffer object...
GLenum qt_gl_preferredTextureFormat()
Definition: qgl_p.h:709
static bool hasOpenGLFramebufferBlit()
Returns true if the OpenGL GL_EXT_framebuffer_blit extension is present on this system; otherwise ret...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QSize bindCompressedTexture(const QString &fileName, const char *format=0)
Definition: qgl.cpp:5996
QImage read()
Reads an image from the device.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static int qt_gl_pixmap_serial
bool scroll(int dx, int dy, const QRect &rect)
void copy(const QPixmapData *data, const QRect &rect)
virtual void endPaint()
#define GL_NEAREST