void QSGCanvasPrivate::renderSceneGraph(const QSize &size)
{
context->renderer()->setDeviceRect(QRect(QPoint(0, 0), size));
- context->renderer()->setViewportRect(QRect(QPoint(0, 0), size));
+ context->renderer()->setViewportRect(QRect(QPoint(0, 0), renderTarget ? renderTarget->size() : size));
context->renderer()->setProjectionMatrixToDeviceRect();
- context->renderNextFrame();
+ context->renderNextFrame(renderTarget);
#ifdef FRAME_TIMING
sceneGraphRenderTime = frameTimer.elapsed();
, vsyncAnimations(false)
, thread(0)
, animationDriver(0)
+ , renderTarget(0)
{
threadedRendering = !qmlNoThreadedRenderer();
}
}
+
+/*!
+ Sets the render target for this canvas to be \a fbo.
+
+ The specified fbo must be created in the context of the canvas
+ or one that shares with it.
+
+ \warning
+ This function can only be called from the thread doing
+ the rendering.
+ */
+
+void QSGCanvas::setRenderTarget(QGLFramebufferObject *fbo)
+{
+ Q_D(QSGCanvas);
+ if (d->context && d->context && QThread::currentThread() != d->context->thread()) {
+ qWarning("QSGCanvas::setRenderThread: Cannot set render target from outside the rendering thread");
+ return;
+ }
+
+ d->renderTarget = fbo;
+}
+
+
+
+/*!
+ Returns the render target for this canvas.
+
+ The default is to render to the surface of the canvas, in which
+ case the render target is 0.
+ */
+QGLFramebufferObject *QSGCanvas::renderTarget() const
+{
+ Q_D(const QSGCanvas);
+ return d->renderTarget;
+}
+
+
/*!
Grabs the contents of the framebuffer and returns it as an image.
#endif
renderer->swapBuffers();
+
#ifdef THREAD_DEBUG
printf(" RenderThread: swap complete...\n");
#endif
class QSGItem;
class QSGEngine;
class QSGCanvasPrivate;
+class QGLFramebufferObject;
+
class Q_DECLARATIVE_EXPORT QSGCanvas : public QGLWidget
{
Q_OBJECT
QImage grabFrameBuffer();
+ void setRenderTarget(QGLFramebufferObject *fbo);
+ QGLFramebufferObject *renderTarget() const;
+
Q_SIGNALS:
void sceneGraphInitialized();
#include <QtCore/qwaitcondition.h>
#include <private/qwidget_p.h>
#include <private/qgl_p.h>
+#include <QtOpenGL/qglframebufferobject.h>
QT_BEGIN_NAMESPACE
QAnimationDriver *animationDriver;
+ QGLFramebufferObject *renderTarget;
+
QHash<int, QSGItem *> itemForTouchPointId;
};
}
-void QSGContext::renderNextFrame()
+void QSGContext::renderNextFrame(QGLFramebufferObject *fbo)
{
Q_D(QSGContext);
emit d->engine.beforeRendering();
cleanupTextures();
- d->renderer->renderScene();
+
+ if (fbo) {
+ BindableFbo bindable(fbo);
+ d->renderer->renderScene(bindable);
+ } else {
+ d->renderer->renderScene();
+ }
emit d->engine.afterRendering();
class QSGEngine;
class QGLContext;
+class QGLFramebufferObject;
class Q_DECLARATIVE_EXPORT QSGContext : public QObject
{
QSGMaterialShader *prepareMaterial(QSGMaterial *material);
- virtual void renderNextFrame();
+ virtual void renderNextFrame(QGLFramebufferObject *fbo = 0);
virtual QSGRectangleNode *createRectangleNode();
virtual QSGImageNode *createImageNode();