diff --git a/src/Mara/CMakeLists.txt b/src/Mara/CMakeLists.txt index 99e079be5497367da14c2c8ab8dcd949b19378ca..36203ed8eb6d8c4e57fbffcf3299a07130e995c1 100644 --- a/src/Mara/CMakeLists.txt +++ b/src/Mara/CMakeLists.txt @@ -38,7 +38,7 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -find_package(Radium REQUIRED Core Engine Gui PluginBase IO) +find_package(Radium REQUIRED COMPONENTS Gui) set(app_sources main.cpp diff --git a/src/libRender/CMakeLists.txt b/src/libRender/CMakeLists.txt index 52e8e96b0de7d7748e83f7ff3aafc7ccfc860282..09a397b07a3f1f677cc59a1f98b879a7849b3216 100644 --- a/src/libRender/CMakeLists.txt +++ b/src/libRender/CMakeLists.txt @@ -23,7 +23,7 @@ endif () # lib nbr configuration #----------------------------------------------------------------------------------- # Radium stuff -find_package(Radium REQUIRED Core Engine ) +find_package(Radium REQUIRED COMPONENTS Engine) message(STATUS "Found Radium version ${Radium_VERSION}" ) # std::uuid dependency diff --git a/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/SimpleNode.cpp b/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/SimpleNode.cpp index 3f95bd1da3149faa86a3683e4c256ce56aacb2a6..c5c3d79c312ec90893e7878b315411e43676096a 100644 --- a/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/SimpleNode.cpp +++ b/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/SimpleNode.cpp @@ -70,15 +70,15 @@ void SimpleNode::init() { texParams.texels = &blankAO; m_blankAO = new Ra::Engine::Data::Texture( texParams ); m_blankAO->initializeGL(); - /* - m_nodeState = new globjects::State(globjects::State::DeferredMode); - m_nodeState->enable( gl::GL_DEPTH_TEST ); - m_nodeState->depthMask( gl::GL_TRUE ); - m_nodeState->depthFunc( gl::GL_LEQUAL ); - m_nodeState->colorMask( gl::GL_TRUE, gl::GL_TRUE, gl::GL_TRUE, gl::GL_TRUE ); - m_nodeState->blendFunc( gl::GL_ONE, gl::GL_ONE ); - m_nodeState->disable( gl::GL_BLEND ); - */ + + m_nodeState = new globjects::State(globjects::State::DeferredMode); + m_nodeState->enable( gl::GL_DEPTH_TEST ); + m_nodeState->depthMask( gl::GL_TRUE ); + m_nodeState->depthFunc( gl::GL_LEQUAL ); + m_nodeState->colorMask( gl::GL_TRUE, gl::GL_TRUE, gl::GL_TRUE, gl::GL_TRUE ); + m_nodeState->blendFunc( gl::GL_ONE, gl::GL_ONE ); + m_nodeState->disable( gl::GL_BLEND ); + } void SimpleNode::update() {} @@ -112,14 +112,8 @@ void SimpleNode::execute() { const gl::GLenum buffers[] = { gl::GL_COLOR_ATTACHMENT0 }; gl::glDrawBuffers( 1, buffers ); - // auto currentState = globjects::State::currentState(); - // m_nodeState->apply(); - - gl::glEnable( gl::GL_DEPTH_TEST ); - gl::glDepthMask( gl::GL_TRUE ); - gl::glDepthFunc( gl::GL_LEQUAL ); - gl::glColorMask( gl::GL_TRUE, gl::GL_TRUE, gl::GL_TRUE, gl::GL_TRUE ); - gl::glDisable( gl::GL_BLEND ); + auto currentState = globjects::State::currentState(); + m_nodeState->apply(); float clearBlack[4] = { 0.04f, 0.04f, 0.04f, 0.0f }; float clearDepth = 1.0f; @@ -146,9 +140,7 @@ void SimpleNode::execute() { } } } - gl::glDisable( gl::GL_BLEND ); - gl::glDepthMask( gl::GL_TRUE ); - // currentState->apply(); + currentState->apply(); m_framebuffer->unbind(); } diff --git a/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/WireframeNode.cpp b/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/WireframeNode.cpp index 139ac80c89f2ee1960da5ed99657dbc32ef14ec8..648a121b281b5cd7c97f63c495c7d15bb2f0a190 100644 --- a/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/WireframeNode.cpp +++ b/src/libRender/RadiumNBR/NodeGraph/PremadeNodes/RenderPasses/WireframeNode.cpp @@ -74,7 +74,7 @@ void setupLineMesh( std::shared_ptr<Ra::Engine::Data::LineMesh>& disp, CoreGeome disp->updateGL(); // add observer auto handle = core.template getAttribHandle<typename CoreGeometry::Point>( - Ra::Engine::Data::Mesh::getAttribName( Ra::Engine::Data::Mesh::VERTEX_POSITION ) ); + Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_POSITION ) ); core.vertexAttribs().getAttrib( handle ).attach( VerticesUpdater( disp, core ) ); core.attach( IndicesUpdater( disp, core ) ); } diff --git a/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp b/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp index 889d34e494d022ee71186ab16094f678354891dd..d28669d22ccac65883361a8c1b6ef40a5d1581a7 100644 --- a/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp +++ b/src/libRender/RadiumNBR/NodeGraph/RenderGraph.cpp @@ -489,92 +489,38 @@ bool RenderGraph::compile() { if ( n->getOutputs().size() == 0 ) { infoNodes.emplace( n.get(), std::pair<int, std::vector<Node*>>( 0, {} ) ); - // Find nodes associated - for ( const auto& input : n->getInputs() ) - { - // Add all nodes that help to make this sink - if ( input->getLink() ) - { - Node* previous = input->getLink()->getNode(); - if ( previous ) - { - if ( infoNodes.find( previous ) != infoNodes.end() ) - { - // If the previous node is not already in the map, - // find if the current node is already a successor node - bool foundCurrent = false; - for ( const auto& successor : infoNodes[previous].second ) - { - if ( successor == n.get() ) { foundCurrent = true; } - } - if ( !foundCurrent ) - { - // If the current node is not a successor node, add it to the list - infoNodes[previous].second.push_back( n.get() ); - } - } - else - { - // Add node to info nodes - std::vector<Node*> successors; - successors.push_back( n.get() ); - infoNodes.emplace( - previous, std::pair<int, std::vector<Node*>>( 0, successors ) ); - } - backtrackGraph( previous, infoNodes ); - } - } - } + backtrackGraph(n.get(), infoNodes); } } - std::vector<std::shared_ptr<Node>> afterCullingNodes; - int idx = 0; - // Delete non-flagged nodes and pass resources to nodes - for ( auto const& n : m_nodes ) - { - if ( infoNodes.find( n.get() ) != infoNodes.end() ) + int maxLevel = 0; + for(auto& infNode : infoNodes) { + auto n = infNode.first; + for ( size_t i = 0; i < n->getInputs().size(); i++ ) { - for ( size_t i = 0; i < n->getInputs().size(); i++ ) + // If the node accepts render objects as input + // then it needs an index for the render techniques + if ( n->getInputs()[i]->getType() == + typeid( std::vector<NodeTypeRenderObject> ).hash_code() ) { - // If the node accepts render objects as input - // then it needs an index for the render techniques - if ( n->getInputs()[i]->getType() == - typeid( std::vector<NodeTypeRenderObject> ).hash_code() ) - { - n->setIndex( idx++ ); - break; - } + n->setIndex( idx++ ); + break; } - n->setResourcesDir( m_resourceDir ); - n->setShaderProgramManager( m_shaderMngr ); - afterCullingNodes.push_back( n ); } - } -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mRenderGraph\e[0m \"" << m_name - << "\": compilation: removed unused nodes, from " << m_nodes.size() << " to " - << afterCullingNodes.size() << " nodes (" << m_nodes.size() - afterCullingNodes.size() - << " removed)." << std::endl; -#endif - int maxLevel = 0; - for ( const auto& n : afterCullingNodes ) - { + n->setResourcesDir( m_resourceDir ); + n->setShaderProgramManager( m_shaderMngr ); + // Find all sources if ( n->getInputs().empty() ) { - // Use the info nodes map to find the successors - if ( infoNodes.find( n.get() ) != infoNodes.end() ) + for ( auto const successor : infNode.second.second ) { - for ( auto const& successor : infoNodes[n.get()].second ) - { - infoNodes[successor].first = - std::max( infoNodes[successor].first, infoNodes[n.get()].first + 1 ); - maxLevel = std::max( maxLevel, - std::max( infoNodes[successor].first, - goThroughGraph( successor, infoNodes ) ) ); - } + infoNodes[successor].first = + std::max( infoNodes[successor].first, infoNodes[n].first + 1 ); + maxLevel = std::max( maxLevel, + std::max( infoNodes[successor].first, + goThroughGraph( successor, infoNodes ) ) ); } } } @@ -582,34 +528,31 @@ bool RenderGraph::compile() { std::cout << "Max level " << maxLevel << std::endl; #endif m_nodesByLevel.clear(); - m_nodesByLevel.resize( afterCullingNodes.size() != 0 ? maxLevel + 1 : 0 ); + m_nodesByLevel.resize( infoNodes.size() != 0 ? maxLevel + 1 : 0 ); for ( auto it = infoNodes.begin(); it != infoNodes.end(); it++ ) { m_nodesByLevel[it->second.first].push_back( it->first ); } #ifdef GRAPH_CALL_TRACE std::cout << "\e[32m\e[1mRenderGraph\e[0m \"" << m_name << "\": compilation: reordered nodes." << std::endl; #endif - if ( m_nodesByLevel.size() != 0 ) + + // For each level + for ( auto& lvl : m_nodesByLevel ) { - // For each level - for ( size_t i = 0; i < m_nodesByLevel.size(); i++ ) + // For each node + for ( size_t j = 0; j < lvl.size(); j++ ) { - // For each node - for ( size_t j = 0; j < m_nodesByLevel[i].size(); j++ ) + // For each input + for ( size_t k = 0; k < lvl[j]->getInputs().size(); k++ ) { - // For each input - for ( size_t k = 0; k < m_nodesByLevel[i][j]->getInputs().size(); k++ ) + if ( lvl[j]->getInputs()[k]->isLinkMandatory() && + !lvl[j]->getInputs()[k]->isLinked() ) { - if ( m_nodesByLevel[i][j]->getInputs()[k]->isLinkMandatory() && - !m_nodesByLevel[i][j]->getInputs()[k]->isLinked() ) - { - m_ready = false; #ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mRenderGraph\e[0m \"" << m_name - << "\": compilation failed." << std::endl; + std::cout << "\e[32m\e[1mRenderGraph\e[0m \"" << m_name + << "\": compilation failed." << std::endl; #endif - return false; - } + return m_ready = false; } } } @@ -621,8 +564,7 @@ bool RenderGraph::compile() { std::cout << "\e[32m\e[1mRenderGraph\e[0m \"" << m_name << "\": end compilation." << std::endl << std::endl; #endif - m_ready = true; - return true; + return m_ready = true; } void RenderGraph::clearNodes() { @@ -652,19 +594,27 @@ void RenderGraph::backtrackGraph( Node* previous = input->getLink()->getNode(); if ( previous ) { - if ( infoNodes.find( previous ) != infoNodes.end() ) + auto previousInInfoNodes = infoNodes.find( previous ); + if ( previousInInfoNodes != infoNodes.end() ) { // If the previous node is not already in the map, // find if the current node is already a successor node + auto& previousSuccessors = previousInInfoNodes->second.second; + bool foundCurrent = std::any_of( previousSuccessors.begin(), + previousSuccessors.end(), + [current](auto c) { return c == current; } + ); + /* bool foundCurrent = false; for ( const auto& n : infoNodes[previous].second ) { if ( n == current ) { foundCurrent = true; } } + */ if ( !foundCurrent ) { // If the current node is not a successor node, add it to the list - infoNodes[previous].second.push_back( current ); + /*infoNodes[previous].second*/previousSuccessors.push_back( current ); } } else @@ -673,9 +623,10 @@ void RenderGraph::backtrackGraph( std::vector<Node*> successors; successors.push_back( current ); infoNodes.emplace( previous, - std::pair<int, std::vector<Node*>>( 0, successors ) ); + std::pair<int, std::vector<Node*>>( 0, std::move(successors) ) ); + backtrackGraph( previous, infoNodes ); } - backtrackGraph( previous, infoNodes ); + /*backtrackGraph( previous, infoNodes );*/ } } } diff --git a/src/libRender/RadiumNBR/Passes/WireframePass.cpp b/src/libRender/RadiumNBR/Passes/WireframePass.cpp index 08398996da62748dbc7411e9e71dfbc1502fd290..fc5c0b12e3960b5b45407ea8d668b6e051d269df 100644 --- a/src/libRender/RadiumNBR/Passes/WireframePass.cpp +++ b/src/libRender/RadiumNBR/Passes/WireframePass.cpp @@ -120,7 +120,7 @@ void setupLineMesh( std::shared_ptr<Ra::Engine::Data::LineMesh>& disp, CoreGeome disp->updateGL(); // add observer auto handle = core.template getAttribHandle<typename CoreGeometry::Point>( - Ra::Engine::Data::Mesh::getAttribName( Ra::Engine::Data::Mesh::VERTEX_POSITION ) ); + Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_POSITION ) ); core.vertexAttribs().getAttrib( handle ).attach( VerticesUpdater( disp, core ) ); core.attach( IndicesUpdater( disp, core ) ); }