Skip to content

Commit

Permalink
merge changes from acolombier, clear and set owned by parent flag, mo…
Browse files Browse the repository at this point in the history
…re clear transfer of waveformrendermarknode
  • Loading branch information
m0dB authored and m0dB committed Nov 1, 2024
1 parent b8f2268 commit 3c76b1b
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 185 deletions.
19 changes: 0 additions & 19 deletions src/rendergraph/common/rendergraph/nodeinterface.h

This file was deleted.

11 changes: 11 additions & 0 deletions src/rendergraph/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ target_link_libraries(rendergraph_gl PUBLIC
Qt6::Gui
Qt6::OpenGL
)
find_package(Microsoft.GSL CONFIG)
if(Microsoft.GSL_FOUND)
target_link_libraries(rendergraph_gl PRIVATE Microsoft.GSL::GSL)
else()
# check if the headers have been installed without cmake config (< 3.1.0)
check_include_file_cxx(gsl/gsl HAVE_GSL_GSL)
if(NOT HAVE_GSL_GSL)
unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag.
message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found")
endif()
endif()
target_compile_definitions(rendergraph_gl PRIVATE rendergraph=rendergraph_gl)

# USE_QSHADER_FOR_GL is set in rendergraph/CMakeLists.txt
Expand Down
2 changes: 2 additions & 0 deletions src/rendergraph/opengl/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Engine::Engine(std::unique_ptr<BaseNode> pRootNode)
}

Engine::~Engine() {
// Explicitly remove the root node (and tree from the engine before deallocating its vectors)
remove(m_pRootNode.get());
}

void Engine::add(BaseNode* pNode) {
Expand Down
33 changes: 31 additions & 2 deletions src/rendergraph/opengl/texture.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
#include "rendergraph/texture.h"

#include <qnamespace.h>
#include <qrgb.h>

#include "rendergraph/assert.h"
#include "rendergraph/context.h"

using namespace rendergraph;

namespace {
QImage premultiplyAlpha(const QImage& image) {
// Since the image is passed by const reference, implicit copy cannot be
// used, and this Qimage::bits will return a ref the QImage buffer, which
// may have a shorter lifecycle that the texture buffer. In order to
// workaround this, and because we cannot copy the image as we need to use
// the raw bitmap with an explicit image format, we make a manual copy of
// the buffer
QImage result(image.width(), image.height(), QImage::Format_RGBA8888);
if (image.format() == QImage::Format_RGBA8888_Premultiplied) {
VERIFY_OR_DEBUG_ASSERT(result.sizeInBytes() == image.sizeInBytes()) {
result.fill(QColor(Qt::transparent).rgba());
return result;
}
std::memcpy(result.bits(), image.bits(), result.sizeInBytes());
} else {
auto convertedImage = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
VERIFY_OR_DEBUG_ASSERT(result.sizeInBytes() == convertedImage.sizeInBytes()) {
result.fill(QColor(Qt::transparent).rgba());
return result;
}
std::memcpy(result.bits(), convertedImage.bits(), result.sizeInBytes());
}
return result;
/* TODO rendergraph ASK @acolombier to try if the following works as well
* (added the .copy())
if (image.format() == QImage::Format_RGBA8888_Premultiplied) {
return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888);
return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888).copy();
}
return QImage(
image.convertToFormat(QImage::Format_RGBA8888_Premultiplied)
.bits(),
image.width(),
image.height(),
QImage::Format_RGBA8888);
QImage::Format_RGBA8888).copy();
*/
}
} // namespace

Expand Down
11 changes: 11 additions & 0 deletions src/rendergraph/scenegraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ target_link_libraries(rendergraph_sg PUBLIC
Qt6::Qml
Qt6::Quick
)
find_package(Microsoft.GSL CONFIG)
if(Microsoft.GSL_FOUND)
target_link_libraries(rendergraph_sg PRIVATE Microsoft.GSL::GSL)
else()
# check if the headers have been installed without cmake config (< 3.1.0)
check_include_file_cxx(gsl/gsl HAVE_GSL_GSL)
if(NOT HAVE_GSL_GSL)
unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag.
message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found")
endif()
endif()
target_compile_definitions(rendergraph_sg PRIVATE rendergraph=rendergraph_sg)

target_include_directories(rendergraph_sg PUBLIC . ../common)
4 changes: 2 additions & 2 deletions src/rendergraph/scenegraph/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

using namespace rendergraph;

Context::Context(QQuickWindow* pWindow)
Context::Context(gsl::not_null<QQuickWindow*> pWindow)
: m_pWindow(pWindow) {
}

QQuickWindow* Context::window() const {
gsl::not_null<QQuickWindow*> Context::window() const {
return m_pWindow;
}
5 changes: 3 additions & 2 deletions src/rendergraph/scenegraph/rendergraph/context.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

#include <QQuickWindow>
#include <gsl/pointers>

namespace rendergraph {
class Context;
}

class rendergraph::Context {
public:
Context(QQuickWindow* pWindow);
QQuickWindow* window() const;
Context(gsl::not_null<QQuickWindow*> pWindow);
gsl::not_null<QQuickWindow*> window() const;

private:
QQuickWindow* m_pWindow;
Expand Down
26 changes: 26 additions & 0 deletions src/rendergraph/scenegraph/rendergraph/nodeinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "backend/basenode.h"
#include "rendergraph/assert.h"

namespace rendergraph {

template<class T_Node>
class NodeInterface : public T_Node {
public:
void appendChildNode(std::unique_ptr<BaseNode> pNode) {
BaseNode* pRawNode = pNode.release();
pRawNode->setFlag(QSNode::OwnedByParent, true);
T_Node::appendChildNode(pRawNode);
DEBUG_ASSERT(pNode->flags() & QSNode::OwnedByParent);
}
std::unique_ptr<BaseNode> detachChildNode(BaseNode* pNode) {
DEBUG_ASSERT(pNode->flags() & QSNode::OwnedByParent);
pNode->setFlag(QSNode::OwnedByParent, false);
T_Node::removeChildNode(pNode);
DEBUG_ASSERT(!pNode->flags() & QSNode::OwnedByParent);
return std::unique_ptr<BaseNode>(pNode);
}
};

} // namespace rendergraph
Loading

0 comments on commit 3c76b1b

Please sign in to comment.