[Interest] Qt3D offscreen rendering

Harald Vistnes harald.vistnes at gmail.com
Tue Dec 15 16:18:47 CET 2015


I've been trying to adjust the code in scene3ditem.cpp. But I am having
some problems. The first parts of my code

    QSurfaceFormat format;

    format.setVersion(4, 3);

    format.setProfile(QSurfaceFormat::CoreProfile);

    format.setDepthBufferSize( 24 );

    format.setSamples( 4 );

    format.setStencilBufferSize(8);


    QOpenGLContext *context = new QOpenGLContext;

    context->setFormat(format);

    context->create();


    QOffscreenSurface *surface = new QOffscreenSurface;

    surface->setFormat(format);

    surface->create();


    context->makeCurrent(surface);


    Qt3DRender::QRenderAspect *renderAspect = new
Qt3DRender::QRenderAspect(Qt3DRender::QRenderAspect::Synchronous);


    Qt3DCore::QAspectEngine *engine = new Qt3DCore::QAspectEngine;

    engine->registerAspect(renderAspect);

    engine->initialize();


    QVariantMap data;

    data.insert(QStringLiteral("surface"),
QVariant::fromValue(static_cast<QSurface *>(surface)));

    data.insert(QStringLiteral("eventSource"), QVariant::fromValue(surface));

    engine->setData(data);


    renderAspect->renderInitialize(context);


crashes at the call to renderInitialize(). I've traced the crash to
Qt3DRender::Renderer::Renderer::initialize() (renderer.cpp line 324):
m_surface->format(). m_surface is NULL at that point because in
QRenderAspectPrivate::setSurface() hasPlatformSurface is false and so
m_renderer->setSurface() is never called on qrenderaspect.cpp line
212.


Is anything wrong in my code?


Thanks,


Harald



2015-12-14 21:57 GMT+01:00 Harald Vistnes <harald.vistnes at gmail.com>:

> Perfect.
>
> Thanks,
> Harald
> On Dec 14, 2015 9:17 PM, "Sean Harmer" <sh at theharmers.co.uk> wrote:
>
>> Hi,
>>
>> that's pretty much exactly what the implementation of Scene3D does:
>>
>> http://code.qt.io/cgit/qt/qt3d.git/tree/src/quick3d/imports/scene3d
>>
>> Cheers,
>>
>> Sean
>>
>> On 14/12/2015 20:06, Harald Vistnes wrote:
>>
>> Hi,
>>
>> I'm trying to do offscreen rendering with Qt3D, but I have not figured
>> out how to do it yet. I have two use cases for this. One is to render a
>> single image in a console application, the other is to have a desktop
>> application with a 3D window and a button to save the current view in a
>> user specified resolution.
>>
>> I'm guessing I should use a subclass of QOffscreenSurface instead of
>> QWindow as the surface, is that right? Or should I pass a custom render
>> target to the render target selector in the frame graph?
>>
>> But how can I make Qt3D render a single frame, and how can I get the
>> rendered image back? In QOpenGLFrameBufferObject there are toImage()
>> functions, but there are no such functions in Qt3DRender::QRenderTarget. Is
>> there a way to do this, or have this functionality not been implemented yet?
>>
>> Any hints on how to proceed would be welcome.
>>
>> Harald
>>
>>
>> _______________________________________________
>> Interest mailing listInterest at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151215/3543b1c1/attachment.html>


More information about the Interest mailing list