Skip to content

Commit

Permalink
also use rendergraph::Engine in scenegraph to initialize and resize n…
Browse files Browse the repository at this point in the history
…odes, add GeometryNode::markDirtyGeometry() and GeometryNode::markDirtyMaterial()
  • Loading branch information
m0dB authored and m0dB committed Sep 27, 2024
1 parent 3ea2349 commit 567bd06
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 67 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions src/rendergraph/common/engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "rendergraph/engine.h"

#include <cassert>

#include "rendergraph/node.h"

using namespace rendergraph;

Engine::Engine(std::unique_ptr<TreeNode> pNode)
: m_pTopNode(std::move(pNode)) {
addToEngine(m_pTopNode.get());
}

void Engine::resize(int w, int h) {
resize(m_pTopNode.get(), w, h);
}
File renamed without changes.
3 changes: 3 additions & 0 deletions src/rendergraph/common/rendergraph/geometrynode.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode,
Geometry& geometry() const;
Material& material() const;

void markDirtyGeometry();
void markDirtyMaterial();

private:
std::unique_ptr<Material> m_pMaterial;
std::unique_ptr<Geometry> m_pGeometry;
Expand Down
9 changes: 9 additions & 0 deletions src/rendergraph/common/rendergraph/treenode.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "backend/basenode.h"

namespace rendergraph {
class Engine; // fwd decl to avoid circular dependency
class TreeNode;
} // namespace rendergraph

Expand Down Expand Up @@ -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<TreeNode> m_pFirstChild;
Expand Down
1 change: 1 addition & 0 deletions src/rendergraph/examples/gl_example/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "examplenodes.h"
#include "rendergraph/context.h"
#include "rendergraph/engine.h"

Window::Window() {
}
Expand Down
10 changes: 8 additions & 2 deletions src/rendergraph/examples/sg_example/customitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "examplenodes.h"
#include "rendergraph/context.h"
#include "rendergraph/engine.h"
#include "rendergraph/node.h"

CustomItem::CustomItem(QQuickItem* parent)
Expand All @@ -31,8 +32,12 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) {
bgNode->setRect(boundingRect());

rendergraph::Context context(window());
m_node = std::make_unique<rendergraph::ExampleTopNode>(context);
bgNode->appendChildNode(m_node->backendNode());

auto pTopNode = std::make_unique<rendergraph::ExampleTopNode>(context);
bgNode->appendChildNode(pTopNode->backendNode());

m_pEngine = std::make_unique<rendergraph::Engine>(std::move(pTopNode));
m_pEngine->initialize();

node = bgNode;
} else {
Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/rendergraph/examples/sg_example/customitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace rendergraph {
class Node;
class Engine;
}

class CustomItem : public QQuickItem {
Expand All @@ -20,7 +21,7 @@ class CustomItem : public QQuickItem {
void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;

bool m_geometryChanged{};
std::unique_ptr<rendergraph::Node> m_node;
std::unique_ptr<rendergraph::Engine> m_pEngine;
};

#endif // CUSTOMITEM_H
13 changes: 7 additions & 6 deletions src/rendergraph/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -46,20 +49,18 @@ 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
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
Expand Down
12 changes: 0 additions & 12 deletions src/rendergraph/opengl/backend/basenode.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#pragma once

namespace rendergraph {
class Engine; // fwd decl to avoid circular dependency
}

namespace rendergraph {
class BaseNode;
}
Expand Down Expand Up @@ -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{};
};
66 changes: 27 additions & 39 deletions src/rendergraph/opengl/engine.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#include "rendergraph/engine.h"

#include <cassert>

#include "rendergraph/node.h"

using namespace rendergraph;

Engine::Engine(std::unique_ptr<TreeNode> 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() {
Expand All @@ -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() {
Expand All @@ -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) {
Expand All @@ -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();
}
}
8 changes: 8 additions & 0 deletions src/rendergraph/opengl/geometrynode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions src/rendergraph/opengl/treenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/rendergraph/scenegraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 567bd06

Please sign in to comment.