Make surface format plugable from the scene graph plugin
authorGunnar Sletta <gunnar.sletta@nokia.com>
Fri, 23 Sep 2011 14:24:06 +0000 (16:24 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 26 Sep 2011 08:46:29 +0000 (10:46 +0200)
Also enable depth, stencil and samples by default as our default
renderer requires both depth and stencil and our default rounded
rectangles require multisampling

The user should be able to override the default format, by getting
the QSGCanvas::format(), modify it and set it back, but this
is currently not supported in QWindow, so that will have to wait

Change-Id: I1869003705709987ab2e9a3cebbeeec4d45a2021
Reviewed-on: http://codereview.qt-project.org/5464
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
src/declarative/items/qsgcanvas.cpp
src/declarative/scenegraph/qsgcontext.cpp
src/declarative/scenegraph/qsgcontext_p.h

index 749099c..8e5d1ec 100644 (file)
@@ -459,6 +459,7 @@ void QSGCanvasPrivate::init(QSGCanvas *c)
     thread->moveContextToThread(context);
 
     q->setSurfaceType(QWindow::OpenGLSurface);
+    q->setFormat(context->defaultSurfaceFormat());
 }
 
 void QSGCanvasPrivate::transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform)
@@ -1831,7 +1832,7 @@ QImage QSGCanvas::grabFrameBuffer()
 void QSGCanvasRenderLoop::createGLContext()
 {
     gl = new QOpenGLContext();
-    gl->setFormat(renderer->format());
+    gl->setFormat(d->context->defaultSurfaceFormat());
     gl->create();
 }
 
index 7adbb32..9016b81 100644 (file)
@@ -380,6 +380,16 @@ QSGTexture *QSGContext::decodeImageToTexture(QIODevice *dev,
 
 
 
+QSurfaceFormat QSGContext::defaultSurfaceFormat() const
+{
+    QSurfaceFormat format;
+    format.setDepthBufferSize(24);
+    format.setStencilBufferSize(8);
+    format.setSamples(16);
+    return format;
+}
+
+
 /*!
     Factory function for texture objects.
 
index a05854e..6fdd4ae 100644 (file)
 #ifndef QSGCONTEXT_H
 #define QSGCONTEXT_H
 
-#include <QImage>
-#include <QObject>
-#include <qabstractanimation.h>
+#include <QtCore/QObject>
+#include <QtCore/qabstractanimation.h>
+
+#include <QtGui/QImage>
+#include <QtGui/QSurfaceFormat>
 
 #include "qsgnode.h"
 
@@ -105,6 +107,8 @@ public:
     virtual QSGTexture *createTexture(const QImage &image = QImage()) const;
     virtual QSize minimumFBOSize() const;
 
+    virtual QSurfaceFormat defaultSurfaceFormat() const;
+
     static QSGContext *createDefaultContext();
 
     void scheduleTextureForCleanup(QSGTexture *texture);