-
Notifications
You must be signed in to change notification settings - Fork 3
/
osgQuickNode.h
80 lines (56 loc) · 1.79 KB
/
osgQuickNode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef OSG_QUICK_NODE_H
#define OSG_QUICK_NODE_H
#include <QtQuick/QSGSimpleTextureNode>
#include <QtQuick/QSGTextureMaterial>
#include <QtQuick/QSGOpaqueTextureMaterial>
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGFlatColorMaterial>
// osg
#include <osgViewer/Viewer>
#include <osg/PositionAttitudeTransform>
class OsgQuickNode : public QSGGeometryNode
{
public:
OsgQuickNode();
~OsgQuickNode();
// neede to setup the osg viewer correcly
void setQuickWindow(QQuickWindow *window);
void setSize(const QSize &size);
QSize size() const { return m_size; }
void setAAEnabled(bool enable);
// called by qt when the "UsePreprocess" flag is set
void preprocess();
// return osg viewer, mainly for setting scene, camera manipulator, etc...
osgViewer::Viewer* getViewer(){ return _osgViewer.get();}
protected:
// internal utility for osg rendering/binding
void init();
void saveOsgState();
void restoreOsgState();
GLuint getGLtexId();
void updateFBO();
void renderOsgFrame();
// TEST scene
osg::Node* createScene();
// Quick geometry stuff
QSGTextureMaterial _qTexMaterial;
QSGOpaqueTextureMaterial _qOpaqueMaterial;
QSGGeometry _qGeometry;
QSGTexture *_qTexture;
// QtQuick container window
QQuickWindow *_quickWindow;
int _samples;
bool _AAEnabled;
QSize m_size;
bool _initialized;
bool _dirtyFBO;
// Pointer to QOpenGLContext to be used by OSG.
QOpenGLContext* _osgContext;
// Pointer to QOpenGLContext to be restored after OSG context
QOpenGLContext* _qtContext;
// osg stuff
osg::ref_ptr<osgViewer::Viewer> _osgViewer;
osg::ref_ptr<osg::PositionAttitudeTransform> _pat;
osg::ref_ptr<osg::Texture2D> _fboTex;
};
#endif // OSG_QUICK_NODE_H