Skip to content

Commit

Permalink
[Do Not Merge] Update adaption of the Qt metaltextureimport to displa…
Browse files Browse the repository at this point in the history
…y an ignition-rendering scene

- Ensure that the GUI uses the basic single threaded scene graph (as the render window must be initialised on the main thread)
- Use the Metal backend for the Qt application
- Add a scene node for the ignition scene
- Build the scene and camera from the simple_demo and wrap the render texture as a QSGTexture

Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring committed Oct 17, 2021
1 parent a876f53 commit 976253c
Show file tree
Hide file tree
Showing 3 changed files with 419 additions and 4 deletions.
5 changes: 4 additions & 1 deletion examples/metal_texture_import/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ int main(int _argc, char** _argv)
{
try
{
// use single-threaded scene graph rendering
qputenv("QSG_RENDER_LOOP", "basic");

qmlRegisterType<MetalTextureImport>("MetalTextureImport", 1, 0,
"MetalTextureImport");

Expand All @@ -21,7 +24,7 @@ int main(int _argc, char** _argv)
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:/Main.qml"));
view.resize(400, 400);
view.resize(800, 600);
view.show();

execReturn = app.exec();
Expand Down
37 changes: 36 additions & 1 deletion examples/metal_texture_import/MetalTextureImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@
#include <QSGTextureProvider>
#include <QSGSimpleTextureNode>

//#include <ignition/rendering.hh>

#include <memory>
//#include <string>

//--------------------------------------------------------------------------
class CustomTextureNodePrivate;
Expand All @@ -83,6 +86,37 @@ private slots:
std::unique_ptr<CustomTextureNodePrivate> dataPtr;
};

//--------------------------------------------------------------------------
class IgnitionSceneNodePrivate;

class IgnitionSceneNode : public QSGTextureProvider, public QSGSimpleTextureNode
{
Q_OBJECT

public:
virtual ~IgnitionSceneNode();
IgnitionSceneNode(QQuickItem *_item);

virtual QSGTexture *texture() const override;

void sync();

void InitialiseOnMainThread();

private slots:
void render();

private:
IgnitionSceneNode(const IgnitionSceneNode &_other) = delete;
IgnitionSceneNode& operator=(const IgnitionSceneNode &_other) = delete;

void WrapTexture();
void InitEngine();
void UpdateCamera();

std::unique_ptr<IgnitionSceneNodePrivate> dataPtr;
};

//--------------------------------------------------------------------------
class MetalTextureImport : public QQuickItem
{
Expand All @@ -103,7 +137,8 @@ private slots:
private:
virtual void releaseResources() override;

CustomTextureNode *m_node{nullptr};
// CustomTextureNode *m_node{nullptr};
IgnitionSceneNode *m_node{nullptr};
};

#endif // IGNITION_RENDERING_EXAMPLES_SIMPLE_DEMO_QML_METAL_METAL_TEXTURE_IMPORT_HH_
Loading

0 comments on commit 976253c

Please sign in to comment.