Building 3D Scenes With QML Building 3D OpenGL Scenes with Qt 5 and - - PowerPoint PPT Presentation

building 3d scenes with qml
SMART_READER_LITE
LIVE PREVIEW

Building 3D Scenes With QML Building 3D OpenGL Scenes with Qt 5 and - - PowerPoint PPT Presentation

Building 3D Scenes With QML Building 3D OpenGL Scenes with Qt 5 and QML Krzysztof Krzewniak Integrated Computer Solutions (ICS) Talk overview Using the QQuickWidnow's OpenGL Context to render 3D objects Handling the camera Adding


slide-1
SLIDE 1

Building 3D Scenes With QML

Building 3D OpenGL Scenes with Qt 5 and QML Krzysztof Krzewniak Integrated Computer Solutions (ICS)

slide-2
SLIDE 2

Talk overview

  • Using the QQuickWidnow's OpenGL Context to

render 3D objects

  • Handling the camera
  • Adding scene content
  • Using framebuffer objects to write filters
  • Render the scene into a QQuickItem
slide-3
SLIDE 3

The target for today

slide-4
SLIDE 4

Hijacking the context

slide-5
SLIDE 5

Hijacking the context

Be nice when hijacking

  • Keep the rendering in the QSG thread
  • Leave the context as you found it
slide-6
SLIDE 6

Hijacking the context

Be nice when hijacking

  • Keep the rendering in the QSG thread
  • Leave the context as you found it

Or else ...

slide-7
SLIDE 7

Hijacking the context

  • Connect your rendering slot to QQuickWindow's

before/after rendering signals Use QQuickItem::itemChange look for QQuickItem::ItemSceneChange

  • Stop QQuickWindow from erasing your 3D scene

Use QQuickWindow::setClearBeforeRendering

(only if rendering your contents underneath QML)

slide-8
SLIDE 8

Hijacking the context

Code sample (Scene::itemChange)

slide-9
SLIDE 9

Camera

  • OpenGL Camera abstraction:

– 4X4 Model View Matrix – 4X4 Projection Matrix

  • Exposed as:

– Camera x, y, z position – Camera pitch, yaw, roll – Projection type (Orthogonal, Perspective) – Field of view and clipping planes

– Viewport width and height

slide-10
SLIDE 10

Camera

Code sample (core/Camera, Camera/main.qml) Demo (Camera)

slide-11
SLIDE 11

Populating the scene

What do we need to populate the scene?

slide-12
SLIDE 12

Populating the scene

What do we need to populate the scene?

  • A scene item abstraction
slide-13
SLIDE 13

Populating the scene

What do we need to populate the scene?

  • A scene item abstraction
  • A way to add items to the scene
slide-14
SLIDE 14

The Scene item abstraction

Scene item properties:

  • The item's x, y and z position
  • Scale
  • Material (keeping it simple):

– Shader paths and custom uniforms

Scene item API:

  • makeRenderPass
  • cleanup

Code sample (core/SceneObject)

slide-15
SLIDE 15

Adding items to the scene

Define a QQmlListProperty<SceneObject> property:

  • appendSceneObject
  • countSceneObjects
  • sceneObjectAt
  • clearSceneObjects

Code sample (core/Scene, SingleObject/main.qml) Demo (SingleObject)

slide-16
SLIDE 16

Scene filters

Increasing your scene's appeal by adding additional specialized render passes using QFrameBufferObjects What we need:

  • A render filter abstraction
  • A way to add render filters to the scene
  • Have the scene use render filters
slide-17
SLIDE 17

Render filter abstraction 1/2

Render filter public API:

  • hook – makes a filter intercept render calls
  • unhook – makes a filter stop intercepting render

calls

  • preRender – makes a filter do its custom work
  • render – makes a filter render out its results

Code sample (core/RenderFilter)

slide-18
SLIDE 18

Render filter abstraction 2/2

Render filter protected API:

  • createFrameBuffer - make a filter create its FBO
  • bindFrameBuffer – make a filter bind its FBO
  • makePreRender – make a filter do its magic
  • makeRender – make a filter render its results

Code sample (filters/LightFilter, Filters/main.qml) Demo (Filters)

slide-19
SLIDE 19

Render into a QQuickItem

With all of the above in place it is very easy to have

  • ur scene or its portion rendered into a QQuickItem.
  • Use a RenderFilter to redirect rendering into a FBO
  • Use a QQuickItem and QSGSimpleTextureNode to

render into QML Code sample (core/textureoutputfilter)

slide-20
SLIDE 20

Done

Code sample (LightDemo/main.qml) Demo (LightDemo)