47 |
47 |
48 #include <qglframebufferobject.h> |
48 #include <qglframebufferobject.h> |
49 #include <qglpixelbuffer.h> |
49 #include <qglpixelbuffer.h> |
50 #include <qcolormap.h> |
50 #include <qcolormap.h> |
51 #include <qdesktopwidget.h> |
51 #include <qdesktopwidget.h> |
|
52 #include <private/qwidget_p.h> |
52 #include "qdebug.h" |
53 #include "qdebug.h" |
53 |
54 |
54 #ifdef Q_WS_X11 |
55 #ifdef Q_WS_X11 |
55 #include <private/qt_x11_p.h> |
56 #include <private/qt_x11_p.h> |
56 #include <qx11info_x11.h> |
57 #include <qx11info_x11.h> |
57 #include <private/qwidget_p.h> |
|
58 |
58 |
59 #ifndef QT_OPENGL_ES |
59 #ifndef QT_OPENGL_ES |
60 #include <GL/glx.h> |
60 #include <GL/glx.h> |
61 #include <X11/Xlib.h> |
61 #include <X11/Xlib.h> |
62 #endif |
62 #endif |
193 |
193 |
194 QGLWidget *shareWidget() { |
194 QGLWidget *shareWidget() { |
195 if (!initializing && !widget && !cleanedUp) { |
195 if (!initializing && !widget && !cleanedUp) { |
196 initializing = true; |
196 initializing = true; |
197 widget = new QGLWidget; |
197 widget = new QGLWidget; |
|
198 // We dont need this internal widget to appear in QApplication::topLevelWidgets() |
|
199 if (QWidgetPrivate::allWidgets) |
|
200 QWidgetPrivate::allWidgets->remove(widget); |
198 initializing = false; |
201 initializing = false; |
199 } |
202 } |
200 return widget; |
203 return widget; |
201 } |
204 } |
202 |
205 |
362 QGLContextPrivate *ctxpriv = ctx->d_func(); |
365 QGLContextPrivate *ctxpriv = ctx->d_func(); |
363 ctxpriv->eglSurface = ctxpriv->eglContext->createSurface(widget); |
366 ctxpriv->eglSurface = ctxpriv->eglContext->createSurface(widget); |
364 if (ctxpriv->eglSurface == EGL_NO_SURFACE) { |
367 if (ctxpriv->eglSurface == EGL_NO_SURFACE) { |
365 qWarning() << "hijackWindow() could not create EGL surface"; |
368 qWarning() << "hijackWindow() could not create EGL surface"; |
366 } |
369 } |
367 qDebug("QGLWindowSurface - using EGLConfig %d", ctxpriv->eglContext->config()); |
370 qDebug("QGLWindowSurface - using EGLConfig %d", reinterpret_cast<int>(ctxpriv->eglContext->config())); |
368 #endif |
371 #endif |
369 |
372 |
370 widgetPrivate->extraData()->glContext = ctx; |
373 widgetPrivate->extraData()->glContext = ctx; |
371 |
374 |
372 union { QGLContext **ctxPtr; void **voidPtr; }; |
375 union { QGLContext **ctxPtr; void **voidPtr; }; |
373 |
376 |
374 connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(deleted(QObject *))); |
377 connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(deleted(QObject*))); |
375 |
378 |
376 voidPtr = &widgetPrivate->extraData()->glContext; |
379 voidPtr = &widgetPrivate->extraData()->glContext; |
377 d_ptr->contexts << ctxPtr; |
380 d_ptr->contexts << ctxPtr; |
378 qDebug() << "hijackWindow() context created for" << widget << d_ptr->contexts.size(); |
381 qDebug() << "hijackWindow() context created for" << widget << d_ptr->contexts.size(); |
379 } |
382 } |
620 |
622 |
621 glViewport(0, 0, size.width(), size.height()); |
623 glViewport(0, 0, size.width(), size.height()); |
622 |
624 |
623 QGLShaderProgram *blitProgram = |
625 QGLShaderProgram *blitProgram = |
624 QGLEngineSharedShaders::shadersForContext(ctx)->blitProgram(); |
626 QGLEngineSharedShaders::shadersForContext(ctx)->blitProgram(); |
625 blitProgram->enable(); |
627 blitProgram->bind(); |
626 blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/); |
628 blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/); |
627 |
629 |
628 // The shader manager's blit program does not multiply the |
630 // The shader manager's blit program does not multiply the |
629 // vertices by the pmv matrix, so we need to do the effect |
631 // vertices by the pmv matrix, so we need to do the effect |
630 // of the orthographic projection here ourselves. |
632 // of the orthographic projection here ourselves. |
683 return; |
685 return; |
684 |
686 |
685 d_ptr->size = rect.size(); |
687 d_ptr->size = rect.size(); |
686 |
688 |
687 if (d_ptr->ctx) { |
689 if (d_ptr->ctx) { |
|
690 #ifndef QT_OPENGL_ES_2 |
688 if (d_ptr->destructive_swap_buffers) { |
691 if (d_ptr->destructive_swap_buffers) { |
689 glBindTexture(target, d_ptr->tex_id); |
692 glBindTexture(target, d_ptr->tex_id); |
690 glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
693 glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
691 glBindTexture(target, 0); |
694 glBindTexture(target, 0); |
692 } |
695 } |
|
696 #endif |
693 return; |
697 return; |
694 } |
698 } |
695 |
699 |
696 if (d_ptr->destructive_swap_buffers |
700 if (d_ptr->destructive_swap_buffers |
697 && (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject) |
701 && (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject) |
751 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
755 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
752 glBindTexture(target, 0); |
756 glBindTexture(target, 0); |
753 |
757 |
754 glMatrixMode(GL_PROJECTION); |
758 glMatrixMode(GL_PROJECTION); |
755 glLoadIdentity(); |
759 glLoadIdentity(); |
756 #ifndef QT_OPENGL_ES |
|
757 glOrtho(0, d_ptr->pb->width(), d_ptr->pb->height(), 0, -999999, 999999); |
760 glOrtho(0, d_ptr->pb->width(), d_ptr->pb->height(), 0, -999999, 999999); |
758 #else |
|
759 glOrthof(0, d_ptr->pb->width(), d_ptr->pb->height(), 0, -999999, 999999); |
|
760 #endif |
|
761 |
761 |
762 d_ptr->pb->d_ptr->qctx->d_func()->internal_context = true; |
762 d_ptr->pb->d_ptr->qctx->d_func()->internal_context = true; |
763 return; |
763 return; |
764 } else { |
764 } else { |
765 qDebug() << "QGLWindowSurface: Failed to create valid pixelbuffer, falling back"; |
765 qDebug() << "QGLWindowSurface: Failed to create valid pixelbuffer, falling back"; |
769 } |
769 } |
770 #endif // !defined(QT_OPENGL_ES_2) |
770 #endif // !defined(QT_OPENGL_ES_2) |
771 |
771 |
772 ctx->makeCurrent(); |
772 ctx->makeCurrent(); |
773 |
773 |
|
774 #ifndef QT_OPENGL_ES_2 |
774 if (d_ptr->destructive_swap_buffers) { |
775 if (d_ptr->destructive_swap_buffers) { |
775 glGenTextures(1, &d_ptr->tex_id); |
776 glGenTextures(1, &d_ptr->tex_id); |
776 glBindTexture(target, d_ptr->tex_id); |
777 glBindTexture(target, d_ptr->tex_id); |
777 glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
778 glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
778 |
779 |
779 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
780 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
780 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
781 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
781 glBindTexture(target, 0); |
782 glBindTexture(target, 0); |
782 } |
783 } |
|
784 #endif |
783 |
785 |
784 qDebug() << "QGLWindowSurface: Using plain widget as window surface" << this;; |
786 qDebug() << "QGLWindowSurface: Using plain widget as window surface" << this;; |
785 d_ptr->ctx = ctx; |
787 d_ptr->ctx = ctx; |
786 d_ptr->ctx->d_ptr->internal_context = true; |
788 d_ptr->ctx->d_ptr->internal_context = true; |
787 } |
789 } |