|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 "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 |
|
53 #include <private/qpaintengineex_opengl2_p.h> |
|
54 |
|
55 #include <qdesktopwidget.h> |
|
56 |
|
57 QT_BEGIN_NAMESPACE |
|
58 |
|
59 extern QGLWidget* qt_gl_share_widget(); |
|
60 |
|
61 /*! |
|
62 \class QGLFramebufferObjectPool |
|
63 \since 4.6 |
|
64 |
|
65 \brief The QGLFramebufferObject class provides a pool of framebuffer |
|
66 objects for offscreen rendering purposes. |
|
67 |
|
68 When requesting an FBO of a given size and format, an FBO of the same |
|
69 format and a size at least as big as the requested size will be returned. |
|
70 |
|
71 \internal |
|
72 */ |
|
73 |
|
74 static inline int areaDiff(const QSize &size, const QGLFramebufferObject *fbo) |
|
75 { |
|
76 return qAbs(size.width() * size.height() - fbo->width() * fbo->height()); |
|
77 } |
|
78 |
|
79 QGLFramebufferObject *QGLFramebufferObjectPool::acquire(const QSize &requestSize, const QGLFramebufferObjectFormat &requestFormat) |
|
80 { |
|
81 QGLFramebufferObject *chosen = 0; |
|
82 QGLFramebufferObject *candidate = 0; |
|
83 for (int i = 0; !chosen && i < m_fbos.size(); ++i) { |
|
84 QGLFramebufferObject *fbo = m_fbos.at(i); |
|
85 |
|
86 if (fbo->format() == requestFormat) { |
|
87 // choose the fbo with a matching format and the closest size |
|
88 if (!candidate || areaDiff(requestSize, candidate) > areaDiff(requestSize, fbo)) |
|
89 candidate = fbo; |
|
90 } |
|
91 |
|
92 if (candidate) { |
|
93 m_fbos.removeOne(candidate); |
|
94 |
|
95 const QSize fboSize = candidate->size(); |
|
96 QSize sz = fboSize; |
|
97 |
|
98 if (sz.width() < requestSize.width()) |
|
99 sz.setWidth(qMax(requestSize.width(), qRound(sz.width() * 1.5))); |
|
100 if (sz.height() < requestSize.height()) |
|
101 sz.setHeight(qMax(requestSize.height(), qRound(sz.height() * 1.5))); |
|
102 |
|
103 // wasting too much space? |
|
104 if (sz.width() * sz.height() > requestSize.width() * requestSize.height() * 4) |
|
105 sz = requestSize; |
|
106 |
|
107 if (sz != fboSize) { |
|
108 delete candidate; |
|
109 candidate = new QGLFramebufferObject(sz, requestFormat); |
|
110 } |
|
111 |
|
112 chosen = candidate; |
|
113 } |
|
114 } |
|
115 |
|
116 if (!chosen) { |
|
117 chosen = new QGLFramebufferObject(requestSize, requestFormat); |
|
118 } |
|
119 |
|
120 if (!chosen->isValid()) { |
|
121 delete chosen; |
|
122 chosen = 0; |
|
123 } |
|
124 |
|
125 return chosen; |
|
126 } |
|
127 |
|
128 void QGLFramebufferObjectPool::release(QGLFramebufferObject *fbo) |
|
129 { |
|
130 m_fbos << fbo; |
|
131 } |
|
132 |
|
133 |
|
134 QPaintEngine* QGLPixmapGLPaintDevice::paintEngine() const |
|
135 { |
|
136 return data->paintEngine(); |
|
137 } |
|
138 |
|
139 void QGLPixmapGLPaintDevice::beginPaint() |
|
140 { |
|
141 if (!data->isValid()) |
|
142 return; |
|
143 |
|
144 // QGLPaintDevice::beginPaint will store the current binding and replace |
|
145 // it with m_thisFBO: |
|
146 m_thisFBO = data->m_renderFbo->handle(); |
|
147 QGLPaintDevice::beginPaint(); |
|
148 |
|
149 Q_ASSERT(data->paintEngine()->type() == QPaintEngine::OpenGL2); |
|
150 |
|
151 // QPixmap::fill() is deferred until now, where we actually need to do the fill: |
|
152 if (data->needsFill()) { |
|
153 const QColor &c = data->fillColor(); |
|
154 float alpha = c.alphaF(); |
|
155 glDisable(GL_SCISSOR_TEST); |
|
156 glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); |
|
157 glClear(GL_COLOR_BUFFER_BIT); |
|
158 } |
|
159 else if (!data->isUninitialized()) { |
|
160 // If the pixmap (GL Texture) has valid content (it has been |
|
161 // uploaded from an image or rendered into before), we need to |
|
162 // copy it from the texture to the render FBO. |
|
163 |
|
164 glDisable(GL_DEPTH_TEST); |
|
165 glDisable(GL_SCISSOR_TEST); |
|
166 glDisable(GL_BLEND); |
|
167 |
|
168 #if !defined(QT_OPENGL_ES_2) |
|
169 glMatrixMode(GL_MODELVIEW); |
|
170 glLoadIdentity(); |
|
171 |
|
172 glMatrixMode(GL_PROJECTION); |
|
173 glLoadIdentity(); |
|
174 glOrtho(0, data->width(), data->height(), 0, -999999, 999999); |
|
175 #endif |
|
176 |
|
177 glViewport(0, 0, data->width(), data->height()); |
|
178 |
|
179 // Pass false to bind so it doesn't copy the FBO into the texture! |
|
180 context()->drawTexture(QRect(0, 0, data->width(), data->height()), data->bind(false)); |
|
181 } |
|
182 } |
|
183 |
|
184 void QGLPixmapGLPaintDevice::endPaint() |
|
185 { |
|
186 if (!data->isValid()) |
|
187 return; |
|
188 |
|
189 data->copyBackFromRenderFbo(false); |
|
190 |
|
191 // Base's endPaint will restore the previous FBO binding |
|
192 QGLPaintDevice::endPaint(); |
|
193 |
|
194 qgl_fbo_pool()->release(data->m_renderFbo); |
|
195 data->m_renderFbo = 0; |
|
196 } |
|
197 |
|
198 QGLContext* QGLPixmapGLPaintDevice::context() const |
|
199 { |
|
200 data->ensureCreated(); |
|
201 return data->m_ctx; |
|
202 } |
|
203 |
|
204 QSize QGLPixmapGLPaintDevice::size() const |
|
205 { |
|
206 return data->size(); |
|
207 } |
|
208 |
|
209 void QGLPixmapGLPaintDevice::setPixmapData(QGLPixmapData* d) |
|
210 { |
|
211 data = d; |
|
212 } |
|
213 |
|
214 static int qt_gl_pixmap_serial = 0; |
|
215 |
|
216 QGLPixmapData::QGLPixmapData(PixelType type) |
|
217 : QPixmapData(type, OpenGLClass) |
|
218 , m_renderFbo(0) |
|
219 , m_engine(0) |
|
220 , m_ctx(0) |
|
221 , m_dirty(false) |
|
222 , m_hasFillColor(false) |
|
223 , m_hasAlpha(false) |
|
224 { |
|
225 setSerialNumber(++qt_gl_pixmap_serial); |
|
226 m_glDevice.setPixmapData(this); |
|
227 } |
|
228 |
|
229 QGLPixmapData::~QGLPixmapData() |
|
230 { |
|
231 QGLWidget *shareWidget = qt_gl_share_widget(); |
|
232 if (!shareWidget) |
|
233 return; |
|
234 |
|
235 delete m_engine; |
|
236 |
|
237 if (m_texture.id) { |
|
238 QGLShareContextScope ctx(shareWidget->context()); |
|
239 glDeleteTextures(1, &m_texture.id); |
|
240 } |
|
241 } |
|
242 |
|
243 QPixmapData *QGLPixmapData::createCompatiblePixmapData() const |
|
244 { |
|
245 return new QGLPixmapData(pixelType()); |
|
246 } |
|
247 |
|
248 bool QGLPixmapData::isValid() const |
|
249 { |
|
250 return w > 0 && h > 0; |
|
251 } |
|
252 |
|
253 bool QGLPixmapData::isValidContext(const QGLContext *ctx) const |
|
254 { |
|
255 if (ctx == m_ctx) |
|
256 return true; |
|
257 |
|
258 const QGLContext *share_ctx = qt_gl_share_widget()->context(); |
|
259 return ctx == share_ctx || QGLContext::areSharing(ctx, share_ctx); |
|
260 } |
|
261 |
|
262 void QGLPixmapData::resize(int width, int height) |
|
263 { |
|
264 if (width == w && height == h) |
|
265 return; |
|
266 |
|
267 if (width <= 0 || height <= 0) { |
|
268 width = 0; |
|
269 height = 0; |
|
270 } |
|
271 |
|
272 w = width; |
|
273 h = height; |
|
274 is_null = (w <= 0 || h <= 0); |
|
275 d = pixelType() == QPixmapData::PixmapType ? 32 : 1; |
|
276 |
|
277 if (m_texture.id) { |
|
278 QGLShareContextScope ctx(qt_gl_share_widget()->context()); |
|
279 glDeleteTextures(1, &m_texture.id); |
|
280 m_texture.id = 0; |
|
281 } |
|
282 |
|
283 m_source = QImage(); |
|
284 m_dirty = isValid(); |
|
285 setSerialNumber(++qt_gl_pixmap_serial); |
|
286 } |
|
287 |
|
288 void QGLPixmapData::ensureCreated() const |
|
289 { |
|
290 if (!m_dirty) |
|
291 return; |
|
292 |
|
293 m_dirty = false; |
|
294 |
|
295 QGLShareContextScope ctx(qt_gl_share_widget()->context()); |
|
296 m_ctx = ctx; |
|
297 |
|
298 const GLenum format = qt_gl_preferredTextureFormat(); |
|
299 const GLenum target = GL_TEXTURE_2D; |
|
300 |
|
301 if (!m_texture.id) { |
|
302 glGenTextures(1, &m_texture.id); |
|
303 glBindTexture(target, m_texture.id); |
|
304 GLenum format = m_hasAlpha ? GL_RGBA : GL_RGB; |
|
305 glTexImage2D(target, 0, format, w, h, 0, |
|
306 GL_RGBA, GL_UNSIGNED_BYTE, 0); |
|
307 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
308 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
309 } |
|
310 |
|
311 if (!m_source.isNull()) { |
|
312 const QImage tx = ctx->d_func()->convertToGLFormat(m_source, true, format); |
|
313 |
|
314 glBindTexture(target, m_texture.id); |
|
315 glTexSubImage2D(target, 0, 0, 0, w, h, format, |
|
316 GL_UNSIGNED_BYTE, tx.bits()); |
|
317 |
|
318 if (useFramebufferObjects()) |
|
319 m_source = QImage(); |
|
320 } |
|
321 |
|
322 m_texture.options &= ~QGLContext::MemoryManagedBindOption; |
|
323 } |
|
324 |
|
325 void QGLPixmapData::fromImage(const QImage &image, |
|
326 Qt::ImageConversionFlags /*flags*/) |
|
327 { |
|
328 if (image.size() == QSize(w, h)) |
|
329 setSerialNumber(++qt_gl_pixmap_serial); |
|
330 resize(image.width(), image.height()); |
|
331 |
|
332 if (pixelType() == BitmapType) { |
|
333 m_source = image.convertToFormat(QImage::Format_MonoLSB); |
|
334 |
|
335 } else { |
|
336 QImage::Format format = QImage::Format_RGB32; |
|
337 if (qApp->desktop()->depth() == 16) |
|
338 format = QImage::Format_RGB16; |
|
339 |
|
340 if (image.hasAlphaChannel() && const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels()) |
|
341 format = QImage::Format_ARGB32_Premultiplied;; |
|
342 |
|
343 m_source = image.convertToFormat(format); |
|
344 } |
|
345 |
|
346 m_dirty = true; |
|
347 m_hasFillColor = false; |
|
348 |
|
349 m_hasAlpha = m_source.hasAlphaChannel(); |
|
350 w = image.width(); |
|
351 h = image.height(); |
|
352 is_null = (w <= 0 || h <= 0); |
|
353 d = m_source.depth(); |
|
354 |
|
355 if (m_texture.id) { |
|
356 QGLShareContextScope ctx(qt_gl_share_widget()->context()); |
|
357 glDeleteTextures(1, &m_texture.id); |
|
358 m_texture.id = 0; |
|
359 } |
|
360 } |
|
361 |
|
362 bool QGLPixmapData::scroll(int dx, int dy, const QRect &rect) |
|
363 { |
|
364 Q_UNUSED(dx); |
|
365 Q_UNUSED(dy); |
|
366 Q_UNUSED(rect); |
|
367 return false; |
|
368 } |
|
369 |
|
370 void QGLPixmapData::copy(const QPixmapData *data, const QRect &rect) |
|
371 { |
|
372 if (data->classId() != QPixmapData::OpenGLClass) { |
|
373 QPixmapData::copy(data, rect); |
|
374 return; |
|
375 } |
|
376 |
|
377 // can be optimized to do a framebuffer blit or similar ... |
|
378 QPixmapData::copy(data, rect); |
|
379 } |
|
380 |
|
381 void QGLPixmapData::fill(const QColor &color) |
|
382 { |
|
383 if (!isValid()) |
|
384 return; |
|
385 |
|
386 bool hasAlpha = color.alpha() != 255; |
|
387 if (hasAlpha && !m_hasAlpha) { |
|
388 if (m_texture.id) { |
|
389 glDeleteTextures(1, &m_texture.id); |
|
390 m_texture.id = 0; |
|
391 m_dirty = true; |
|
392 } |
|
393 m_hasAlpha = color.alpha() != 255; |
|
394 } |
|
395 |
|
396 if (useFramebufferObjects()) { |
|
397 m_source = QImage(); |
|
398 m_hasFillColor = true; |
|
399 m_fillColor = color; |
|
400 } else { |
|
401 |
|
402 if (m_source.isNull()) { |
|
403 m_fillColor = color; |
|
404 m_hasFillColor = true; |
|
405 |
|
406 } else if (m_source.depth() == 32) { |
|
407 m_source.fill(PREMUL(color.rgba())); |
|
408 |
|
409 } else if (m_source.depth() == 1) { |
|
410 if (color == Qt::color1) |
|
411 m_source.fill(1); |
|
412 else |
|
413 m_source.fill(0); |
|
414 } |
|
415 } |
|
416 } |
|
417 |
|
418 bool QGLPixmapData::hasAlphaChannel() const |
|
419 { |
|
420 return m_hasAlpha; |
|
421 } |
|
422 |
|
423 QImage QGLPixmapData::fillImage(const QColor &color) const |
|
424 { |
|
425 QImage img; |
|
426 if (pixelType() == BitmapType) { |
|
427 img = QImage(w, h, QImage::Format_MonoLSB); |
|
428 |
|
429 img.setNumColors(2); |
|
430 img.setColor(0, QColor(Qt::color0).rgba()); |
|
431 img.setColor(1, QColor(Qt::color1).rgba()); |
|
432 |
|
433 if (color == Qt::color1) |
|
434 img.fill(1); |
|
435 else |
|
436 img.fill(0); |
|
437 } else { |
|
438 img = QImage(w, h, |
|
439 m_hasAlpha |
|
440 ? QImage::Format_ARGB32_Premultiplied |
|
441 : QImage::Format_RGB32); |
|
442 img.fill(PREMUL(color.rgba())); |
|
443 } |
|
444 return img; |
|
445 } |
|
446 |
|
447 extern QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha); |
|
448 |
|
449 QImage QGLPixmapData::toImage() const |
|
450 { |
|
451 if (!isValid()) |
|
452 return QImage(); |
|
453 |
|
454 if (m_renderFbo) { |
|
455 copyBackFromRenderFbo(true); |
|
456 } else if (!m_source.isNull()) { |
|
457 return m_source; |
|
458 } else if (m_dirty || m_hasFillColor) { |
|
459 return fillImage(m_fillColor); |
|
460 } else { |
|
461 ensureCreated(); |
|
462 } |
|
463 |
|
464 QGLShareContextScope ctx(qt_gl_share_widget()->context()); |
|
465 glBindTexture(GL_TEXTURE_2D, m_texture.id); |
|
466 return qt_gl_read_texture(QSize(w, h), true, true); |
|
467 } |
|
468 |
|
469 struct TextureBuffer |
|
470 { |
|
471 QGLFramebufferObject *fbo; |
|
472 QGL2PaintEngineEx *engine; |
|
473 }; |
|
474 |
|
475 Q_GLOBAL_STATIC(QGLFramebufferObjectPool, _qgl_fbo_pool) |
|
476 QGLFramebufferObjectPool* qgl_fbo_pool() |
|
477 { |
|
478 return _qgl_fbo_pool(); |
|
479 } |
|
480 |
|
481 void QGLPixmapData::copyBackFromRenderFbo(bool keepCurrentFboBound) const |
|
482 { |
|
483 if (!isValid()) |
|
484 return; |
|
485 |
|
486 m_hasFillColor = false; |
|
487 |
|
488 const QGLContext *share_ctx = qt_gl_share_widget()->context(); |
|
489 QGLShareContextScope ctx(share_ctx); |
|
490 |
|
491 ensureCreated(); |
|
492 |
|
493 if (!ctx->d_ptr->fbo) |
|
494 glGenFramebuffers(1, &ctx->d_ptr->fbo); |
|
495 |
|
496 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, ctx->d_ptr->fbo); |
|
497 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, |
|
498 GL_TEXTURE_2D, m_texture.id, 0); |
|
499 |
|
500 const int x0 = 0; |
|
501 const int x1 = w; |
|
502 const int y0 = 0; |
|
503 const int y1 = h; |
|
504 |
|
505 if (!m_renderFbo->isBound()) |
|
506 glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, m_renderFbo->handle()); |
|
507 |
|
508 glDisable(GL_SCISSOR_TEST); |
|
509 |
|
510 glBlitFramebufferEXT(x0, y0, x1, y1, |
|
511 x0, y0, x1, y1, |
|
512 GL_COLOR_BUFFER_BIT, |
|
513 GL_NEAREST); |
|
514 |
|
515 if (keepCurrentFboBound) { |
|
516 glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo); |
|
517 } else { |
|
518 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, m_renderFbo->handle()); |
|
519 ctx->d_ptr->current_fbo = m_renderFbo->handle(); |
|
520 } |
|
521 } |
|
522 |
|
523 bool QGLPixmapData::useFramebufferObjects() |
|
524 { |
|
525 return QGLFramebufferObject::hasOpenGLFramebufferObjects() |
|
526 && QGLFramebufferObject::hasOpenGLFramebufferBlit() |
|
527 && qt_gl_preferGL2Engine(); |
|
528 } |
|
529 |
|
530 QPaintEngine* QGLPixmapData::paintEngine() const |
|
531 { |
|
532 if (!isValid()) |
|
533 return 0; |
|
534 |
|
535 if (m_renderFbo) |
|
536 return m_engine; |
|
537 |
|
538 if (useFramebufferObjects()) { |
|
539 extern QGLWidget* qt_gl_share_widget(); |
|
540 |
|
541 if (!QGLContext::currentContext()) |
|
542 qt_gl_share_widget()->makeCurrent(); |
|
543 QGLShareContextScope ctx(qt_gl_share_widget()->context()); |
|
544 |
|
545 QGLFramebufferObjectFormat format; |
|
546 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); |
|
547 format.setSamples(4); |
|
548 format.setInternalTextureFormat(GLenum(m_hasAlpha ? GL_RGBA : GL_RGB)); |
|
549 |
|
550 m_renderFbo = qgl_fbo_pool()->acquire(size(), format); |
|
551 |
|
552 if (m_renderFbo) { |
|
553 if (!m_engine) |
|
554 m_engine = new QGL2PaintEngineEx; |
|
555 return m_engine; |
|
556 } |
|
557 |
|
558 qWarning() << "Failed to create pixmap texture buffer of size " << size() << ", falling back to raster paint engine"; |
|
559 } |
|
560 |
|
561 m_dirty = true; |
|
562 if (m_source.size() != size()) |
|
563 m_source = QImage(size(), QImage::Format_ARGB32_Premultiplied); |
|
564 if (m_hasFillColor) { |
|
565 m_source.fill(PREMUL(m_fillColor.rgba())); |
|
566 m_hasFillColor = false; |
|
567 } |
|
568 return m_source.paintEngine(); |
|
569 } |
|
570 |
|
571 extern QRgb qt_gl_convertToGLFormat(QRgb src_pixel, GLenum texture_format); |
|
572 |
|
573 // If copyBack is true, bind will copy the contents of the render |
|
574 // FBO to the texture (which is not bound to the texture, as it's |
|
575 // a multisample FBO). |
|
576 GLuint QGLPixmapData::bind(bool copyBack) const |
|
577 { |
|
578 if (m_renderFbo && copyBack) { |
|
579 copyBackFromRenderFbo(true); |
|
580 } else { |
|
581 ensureCreated(); |
|
582 } |
|
583 |
|
584 GLuint id = m_texture.id; |
|
585 glBindTexture(GL_TEXTURE_2D, id); |
|
586 |
|
587 if (m_hasFillColor) { |
|
588 if (!useFramebufferObjects()) { |
|
589 m_source = QImage(w, h, QImage::Format_ARGB32_Premultiplied); |
|
590 m_source.fill(PREMUL(m_fillColor.rgba())); |
|
591 } |
|
592 |
|
593 m_hasFillColor = false; |
|
594 |
|
595 GLenum format = qt_gl_preferredTextureFormat(); |
|
596 QImage tx(w, h, QImage::Format_ARGB32_Premultiplied); |
|
597 tx.fill(qt_gl_convertToGLFormat(m_fillColor.rgba(), format)); |
|
598 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, GL_UNSIGNED_BYTE, tx.bits()); |
|
599 } |
|
600 |
|
601 return id; |
|
602 } |
|
603 |
|
604 QGLTexture* QGLPixmapData::texture() const |
|
605 { |
|
606 return &m_texture; |
|
607 } |
|
608 |
|
609 extern int qt_defaultDpiX(); |
|
610 extern int qt_defaultDpiY(); |
|
611 |
|
612 int QGLPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const |
|
613 { |
|
614 if (w == 0) |
|
615 return 0; |
|
616 |
|
617 switch (metric) { |
|
618 case QPaintDevice::PdmWidth: |
|
619 return w; |
|
620 case QPaintDevice::PdmHeight: |
|
621 return h; |
|
622 case QPaintDevice::PdmNumColors: |
|
623 return 0; |
|
624 case QPaintDevice::PdmDepth: |
|
625 return d; |
|
626 case QPaintDevice::PdmWidthMM: |
|
627 return qRound(w * 25.4 / qt_defaultDpiX()); |
|
628 case QPaintDevice::PdmHeightMM: |
|
629 return qRound(h * 25.4 / qt_defaultDpiY()); |
|
630 case QPaintDevice::PdmDpiX: |
|
631 case QPaintDevice::PdmPhysicalDpiX: |
|
632 return qt_defaultDpiX(); |
|
633 case QPaintDevice::PdmDpiY: |
|
634 case QPaintDevice::PdmPhysicalDpiY: |
|
635 return qt_defaultDpiY(); |
|
636 default: |
|
637 qWarning("QGLPixmapData::metric(): Invalid metric"); |
|
638 return 0; |
|
639 } |
|
640 } |
|
641 |
|
642 QGLPaintDevice *QGLPixmapData::glDevice() const |
|
643 { |
|
644 return &m_glDevice; |
|
645 } |
|
646 |
|
647 QT_END_NAMESPACE |