diff --git a/CMakeLists.txt b/CMakeLists.txt index e98e01b6547..95cf8e2cfd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3811,6 +3811,7 @@ endif() add_subdirectory(src/rendergraph/opengl) add_subdirectory(res/shaders/rendergraph) target_link_libraries(mixxx-lib PUBLIC rendergraph_gl) +target_compile_definitions(mixxx-lib PRIVATE rendergraph=rendergraph_gl) # WavPack audio file support find_package(wavpack) diff --git a/src/rendergraph/common/engine.cpp b/src/rendergraph/common/engine.cpp new file mode 100644 index 00000000000..6d0798bc408 --- /dev/null +++ b/src/rendergraph/common/engine.cpp @@ -0,0 +1,16 @@ +#include "rendergraph/engine.h" + +#include + +#include "rendergraph/node.h" + +using namespace rendergraph; + +Engine::Engine(std::unique_ptr pNode) + : m_pTopNode(std::move(pNode)) { + addToEngine(m_pTopNode.get()); +} + +void Engine::resize(int w, int h) { + resize(m_pTopNode.get(), w, h); +} diff --git a/src/rendergraph/opengl/rendergraph/engine.h b/src/rendergraph/common/rendergraph/engine.h similarity index 100% rename from src/rendergraph/opengl/rendergraph/engine.h rename to src/rendergraph/common/rendergraph/engine.h diff --git a/src/rendergraph/common/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h index 44384b370bf..951c6e9b96c 100644 --- a/src/rendergraph/common/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -29,6 +29,9 @@ class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode, Geometry& geometry() const; Material& material() const; + void markDirtyGeometry(); + void markDirtyMaterial(); + private: std::unique_ptr m_pMaterial; std::unique_ptr m_pGeometry; diff --git a/src/rendergraph/common/rendergraph/treenode.h b/src/rendergraph/common/rendergraph/treenode.h index 2cd943ce838..4d925cbf80a 100644 --- a/src/rendergraph/common/rendergraph/treenode.h +++ b/src/rendergraph/common/rendergraph/treenode.h @@ -5,6 +5,7 @@ #include "backend/basenode.h" namespace rendergraph { +class Engine; // fwd decl to avoid circular dependency class TreeNode; } // namespace rendergraph @@ -55,11 +56,19 @@ class rendergraph::TreeNode { virtual void resize(int, int) { } + void setEngine(Engine* pEngine) { + m_pEngine = pEngine; + } + Engine* engine() const { + return m_pEngine; + } + private: void onAppendChildNode(TreeNode* pChild); void onRemoveAllChildNodes(); void onRemoveChildNode(TreeNode* pChild); + Engine* m_pEngine{}; rendergraph::BaseNode* m_pBackendNode; TreeNode* m_pParent{}; std::unique_ptr m_pFirstChild; diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index a5e5085d257..dc0818edd4b 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -2,6 +2,7 @@ #include "examplenodes.h" #include "rendergraph/context.h" +#include "rendergraph/engine.h" Window::Window() { } diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index 8651791c0a0..59b278cea4f 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -8,6 +8,7 @@ #include "examplenodes.h" #include "rendergraph/context.h" +#include "rendergraph/engine.h" #include "rendergraph/node.h" CustomItem::CustomItem(QQuickItem* parent) @@ -31,8 +32,12 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { bgNode->setRect(boundingRect()); rendergraph::Context context(window()); - m_node = std::make_unique(context); - bgNode->appendChildNode(m_node->backendNode()); + + auto pTopNode = std::make_unique(context); + bgNode->appendChildNode(pTopNode->backendNode()); + + m_pEngine = std::make_unique(std::move(pTopNode)); + m_pEngine->initialize(); node = bgNode; } else { @@ -41,6 +46,7 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { if (m_geometryChanged) { bgNode->setRect(boundingRect()); + m_pEngine->resize(boundingRect().width(), boundingRect().height()); m_geometryChanged = false; } diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index 304fb5c8f5e..7abd81a0524 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -5,6 +5,7 @@ namespace rendergraph { class Node; +class Engine; } class CustomItem : public QQuickItem { @@ -20,7 +21,7 @@ class CustomItem : public QQuickItem { void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; bool m_geometryChanged{}; - std::unique_ptr m_node; + std::unique_ptr m_pEngine; }; #endif // CUSTOMITEM_H diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 0e185a71e68..015eea487dd 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,10 +1,10 @@ add_library(rendergraph_gl -../common/treenode.cpp +../common/engine.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h -../common/rendergraph/treenode.h +../common/rendergraph/engine.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -25,13 +25,16 @@ add_library(rendergraph_gl ../common/rendergraph/node.h ../common/rendergraph/opacitynode.h ../common/rendergraph/texture.h +../common/rendergraph/treenode.h ../common/rendergraph/types.h ../common/rendergraph/uniform.h ../common/rendergraph/uniformscache.cpp ../common/rendergraph/uniformscache.h ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h +../common/treenode.cpp ../common/types.cpp +attributeset.cpp backend/baseattributeset.cpp backend/baseattributeset.h backend/basegeometry.cpp @@ -46,10 +49,8 @@ backend/basenode.h backend/baseopacitynode.h backend/baseopenglnode.cpp backend/baseopenglnode.h -backend/shadercache.h backend/basetexture.h -attributeset.cpp -treenode.cpp +backend/shadercache.h engine.cpp geometry.cpp geometrynode.cpp @@ -57,9 +58,9 @@ material.cpp materialshader.cpp openglnode.cpp rendergraph/context.h -rendergraph/engine.h rendergraph/openglnode.h texture.cpp +treenode.cpp ) target_link_libraries(rendergraph_gl PUBLIC diff --git a/src/rendergraph/opengl/backend/basenode.h b/src/rendergraph/opengl/backend/basenode.h index d224e4cc8b3..23c897c8316 100644 --- a/src/rendergraph/opengl/backend/basenode.h +++ b/src/rendergraph/opengl/backend/basenode.h @@ -1,9 +1,5 @@ #pragma once -namespace rendergraph { -class Engine; // fwd decl to avoid circular dependency -} - namespace rendergraph { class BaseNode; } @@ -31,14 +27,6 @@ class rendergraph::BaseNode { virtual void resizeBackend(int, int) { } - void setEngine(Engine* pEngine) { - m_pEngine = pEngine; - } - Engine* engine() const { - return m_pEngine; - } - private: bool m_usePreprocess{}; - Engine* m_pEngine{}; }; diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index 700b3b8994c..6b8875dff81 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -1,22 +1,23 @@ #include "rendergraph/engine.h" - #include -#include "rendergraph/node.h" - using namespace rendergraph; -Engine::Engine(std::unique_ptr pNode) - : m_pTopNode(std::move(pNode)) { - addToEngine(m_pTopNode.get()); -} +void Engine::addToEngine(TreeNode* pNode) { + assert(pNode->engine() == nullptr); -void Engine::initialize() { - for (auto pNode : m_pInitializeNodes) { - pNode->backendNode()->initializeBackend(); - pNode->initialize(); + pNode->setEngine(this); + m_pInitializeNodes.push_back(pNode); + if (pNode->backendNode()->usePreprocess()) { + m_pPreprocessNodes.push_back(pNode); + } + pNode = pNode->firstChild(); + while (pNode) { + if (pNode->engine() != this) { + addToEngine(pNode); + } + pNode = pNode->nextSibling(); } - m_pInitializeNodes.clear(); } void Engine::render() { @@ -28,8 +29,15 @@ void Engine::render() { } } -void Engine::resize(int w, int h) { - resize(m_pTopNode.get(), w, h); +void Engine::render(TreeNode* pNode) { + pNode->backendNode()->renderBackend(); + pNode = pNode->firstChild(); + while (pNode) { + if (!pNode->backendNode()->isSubtreeBlocked()) { + render(pNode); + } + pNode = pNode->nextSibling(); + } } void Engine::preprocess() { @@ -40,15 +48,12 @@ void Engine::preprocess() { } } -void Engine::render(TreeNode* pNode) { - pNode->backendNode()->renderBackend(); - pNode = pNode->firstChild(); - while (pNode) { - if (!pNode->backendNode()->isSubtreeBlocked()) { - render(pNode); - } - pNode = pNode->nextSibling(); +void Engine::initialize() { + for (auto pNode : m_pInitializeNodes) { + pNode->backendNode()->initializeBackend(); + pNode->initialize(); } + m_pInitializeNodes.clear(); } void Engine::resize(TreeNode* pNode, int w, int h) { @@ -60,20 +65,3 @@ void Engine::resize(TreeNode* pNode, int w, int h) { pNode = pNode->nextSibling(); } } - -void Engine::addToEngine(TreeNode* pNode) { - assert(pNode->backendNode()->engine() == nullptr); - - pNode->backendNode()->setEngine(this); - m_pInitializeNodes.push_back(pNode); - if (pNode->backendNode()->usePreprocess()) { - m_pPreprocessNodes.push_back(pNode); - } - pNode = pNode->firstChild(); - while (pNode) { - if (pNode->backendNode()->engine() != this) { - addToEngine(pNode); - } - pNode = pNode->nextSibling(); - } -} diff --git a/src/rendergraph/opengl/geometrynode.cpp b/src/rendergraph/opengl/geometrynode.cpp index ad5c4448dce..1af643cb8e2 100644 --- a/src/rendergraph/opengl/geometrynode.cpp +++ b/src/rendergraph/opengl/geometrynode.cpp @@ -21,3 +21,11 @@ Geometry& GeometryNode::geometry() const { Material& GeometryNode::material() const { return *m_pMaterial; } + +void GeometryNode::markDirtyGeometry() { + // not (yet) needed for opengl +} + +void GeometryNode::markDirtyMaterial() { + // not (yet) needed for opengl +} diff --git a/src/rendergraph/opengl/treenode.cpp b/src/rendergraph/opengl/treenode.cpp index 949e6e10a2b..0b9436a3e5f 100644 --- a/src/rendergraph/opengl/treenode.cpp +++ b/src/rendergraph/opengl/treenode.cpp @@ -9,9 +9,9 @@ void TreeNode::setUsePreprocess(bool value) { } void TreeNode::onAppendChildNode(TreeNode* pChild) { - if (backendNode()->engine() != nullptr && - backendNode()->engine() != pChild->backendNode()->engine()) { - backendNode()->engine()->addToEngine(pChild); + if (engine() != nullptr && + engine() != pChild->engine()) { + engine()->addToEngine(pChild); } } diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 9d38df1b7fe..1e26c6ef58c 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,10 +1,10 @@ add_library(rendergraph_sg -../common/treenode.cpp +../common/engine.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h -../common/rendergraph/treenode.h +../common/rendergraph/engine.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -25,13 +25,16 @@ add_library(rendergraph_sg ../common/rendergraph/node.h ../common/rendergraph/opacitynode.h ../common/rendergraph/texture.h +../common/rendergraph/treenode.h ../common/rendergraph/types.h ../common/rendergraph/uniform.h ../common/rendergraph/uniformscache.cpp ../common/rendergraph/uniformscache.h ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h +../common/treenode.cpp ../common/types.cpp +attributeset.cpp backend/baseattributeset.cpp backend/baseattributeset.h backend/basegeometry.h @@ -43,15 +46,15 @@ backend/basematerialtype.h backend/basenode.h backend/baseopacitynode.h backend/basetexture.h -attributeset.cpp -treenode.cpp context.cpp +engine.cpp geometry.cpp geometrynode.cpp material.cpp materialshader.cpp rendergraph/context.h texture.cpp +treenode.cpp ) target_link_libraries(rendergraph_sg PUBLIC diff --git a/src/rendergraph/scenegraph/engine.cpp b/src/rendergraph/scenegraph/engine.cpp new file mode 100644 index 00000000000..9354e76e2d1 --- /dev/null +++ b/src/rendergraph/scenegraph/engine.cpp @@ -0,0 +1,43 @@ +#include "rendergraph/engine.h" + +#include + +using namespace rendergraph; + +void Engine::addToEngine(TreeNode* pNode) { + assert(pNode->engine() == nullptr); + + pNode->setEngine(this); + m_pInitializeNodes.push_back(pNode); + pNode = pNode->firstChild(); + while (pNode) { + if (pNode->engine() != this) { + addToEngine(pNode); + } + pNode = pNode->nextSibling(); + } +} + +void Engine::render() { + assert(false && "should not be called for scenegraph, rendering is handled by Qt"); +} + +void Engine::preprocess() { + assert(false && "should not be called for scenegraph, preprocess is handled by Qt"); +} + +void Engine::initialize() { + for (auto pNode : m_pInitializeNodes) { + pNode->initialize(); + } + m_pInitializeNodes.clear(); +} + +void Engine::resize(TreeNode* pNode, int w, int h) { + pNode->resize(w, h); + pNode = pNode->firstChild(); + while (pNode) { + resize(pNode, w, h); + pNode = pNode->nextSibling(); + } +} diff --git a/src/rendergraph/scenegraph/geometrynode.cpp b/src/rendergraph/scenegraph/geometrynode.cpp index bd9f26570e8..59455ed9e8f 100644 --- a/src/rendergraph/scenegraph/geometrynode.cpp +++ b/src/rendergraph/scenegraph/geometrynode.cpp @@ -23,3 +23,11 @@ Geometry& GeometryNode::geometry() const { Material& GeometryNode::material() const { return *m_pMaterial; } + +void GeometryNode::markDirtyMaterial() { + markDirty(QSGNode::DirtyMaterial); +} + +void GeometryNode::markDirtyGeometry() { + markDirty(QSGNode::DirtyGeometry); +}