Skip to content
Snippets Groups Projects
Commit 08fbcc61 authored by Mathias Paulin's avatar Mathias Paulin :speech_balloon:
Browse files

some small refactoring ... to be continued.

parent 26159586
Branches
No related tags found
No related merge requests found
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
* This class parameterize the renderer just after the OpenGL system was initialized. * This class parameterize the renderer just after the OpenGL system was initialized.
* In the functor, The OpenGL context of the drawing window is activated. * In the functor, The OpenGL context of the drawing window is activated.
*/ */
class RendererBuilder { class RendererController : public RadiumNBR::RenderControlFunctor {
public: public:
void operator ()(RadiumNBR::NodeBasedRenderer *renderer, int w, int h) {
void configure(RadiumNBR::NodeBasedRenderer *renderer, int w, int h) override {
LOG( Ra::Core::Utils::logINFO ) << "Customizing the renderer " << renderer->getRendererName(); LOG( Ra::Core::Utils::logINFO ) << "Customizing the renderer " << renderer->getRendererName();
//! [Caching some helpers and data from the Engine and the renderer] //! [Caching some helpers and data from the Engine and the renderer]
...@@ -101,6 +102,7 @@ class DemoWindowFactory : public Ra::Gui::BaseApplication::WindowFactory ...@@ -101,6 +102,7 @@ class DemoWindowFactory : public Ra::Gui::BaseApplication::WindowFactory
std::shared_ptr<RadiumNBR::NodeBasedRenderer> renderer; std::shared_ptr<RadiumNBR::NodeBasedRenderer> renderer;
}; };
int main( int argc, char* argv[] ) { int main( int argc, char* argv[] ) {
if ( argc < 2 ) if ( argc < 2 )
{ {
...@@ -108,7 +110,8 @@ int main( int argc, char* argv[] ) { ...@@ -108,7 +110,8 @@ int main( int argc, char* argv[] ) {
return 1; return 1;
} }
//! [Instatiating the renderer giving a customization functor] //! [Instatiating the renderer giving a customization functor]
auto renderer = std::make_shared<RadiumNBR::NodeBasedRenderer>(RendererBuilder{} ); RendererController renderControl;
auto renderer = std::make_shared<RadiumNBR::NodeBasedRenderer>( renderControl );
//! [Instatiating the renderer giving a customization functor] //! [Instatiating the renderer giving a customization functor]
//! [Instatiating the application] //! [Instatiating the application]
......
...@@ -244,49 +244,36 @@ void FullFeatureRenderer::updateStepInternal( const ViewingParameters& renderDat ...@@ -244,49 +244,36 @@ void FullFeatureRenderer::updateStepInternal( const ViewingParameters& renderDat
// Split objects into opaque and transparent // Split objects into opaque and transparent
m_transparentRenderObjects.clear(); m_transparentRenderObjects.clear();
m_volumetricRenderObjects.clear(); m_volumetricRenderObjects.clear();
allRenderObjects()->clear();
for ( auto it = m_fancyRenderObjects.begin(); it != m_fancyRenderObjects.end(); ) auto objectsToRender = allRenderObjects();
{ for( auto it = objectsToRender->begin(); it != objectsToRender->end(); ) {
allRenderObjects()->push_back( *it );
if ( ( *it )->isTransparent() ) if ( ( *it )->isTransparent() )
{ {
m_transparentRenderObjects.push_back( *it ); m_transparentRenderObjects.push_back( *it );
it = m_fancyRenderObjects.erase( it ); it = objectsToRender->erase( it );
//++it;
} }
else else
{ {
auto material = ( *it )->getMaterial(); auto material = ( *it )->getMaterial();
if ( material && if ( material &&
material->getMaterialAspect() == Material::MaterialAspect::MAT_DENSITY ) material->getMaterialAspect() == Material::MaterialAspect::MAT_DENSITY )
{ {
m_volumetricRenderObjects.push_back( *it ); m_volumetricRenderObjects.push_back( *it );
it = m_fancyRenderObjects.erase( it ); it = objectsToRender->erase( it );
} }
else else
{ ++it; } { ++it; }
} }
} }
// Update passes
// Note that this could be expensive. Find a way to add attributes to renderObjects so
// that one ca factorizes some evaluations.
for ( auto& rp : renderPasses() )
{
if ( rp.second->isActive() ) { rp.second->update(); }
}
}
void FullFeatureRenderer::renderInternal( const ViewingParameters& renderData ) {
m_clearPass->setBackground( getBackgroundColor() ); m_clearPass->setBackground( getBackgroundColor() );
if ( m_hasEnvMap ) if ( m_hasEnvMap )
{ {
// for ( auto &lm : m_lightmanagers ) { lm->removeSystemLights(); } // for ( auto &lm : m_lightmanagers ) { lm->removeSystemLights(); }
} }
NodeBasedRenderer::renderInternal( renderData ); NodeBasedRenderer::updateStepInternal( renderData );
} }
void FullFeatureRenderer::setEnvMap( const std::string& files ) { void FullFeatureRenderer::setEnvMap( const std::string& files ) {
if ( files.empty() ) if ( files.empty() )
{ {
......
...@@ -55,7 +55,6 @@ class NodeBasedRenderer_LIBRARY_API FullFeatureRenderer final : public NodeBased ...@@ -55,7 +55,6 @@ class NodeBasedRenderer_LIBRARY_API FullFeatureRenderer final : public NodeBased
protected: protected:
void initializeInternal() override; void initializeInternal() override;
void updateStepInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override; void updateStepInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override;
void renderInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override;
private: private:
void initPasses(); void initPasses();
......
...@@ -26,11 +26,13 @@ int NodeBasedRendererMagic = 0xFF0F00F0; ...@@ -26,11 +26,13 @@ int NodeBasedRendererMagic = 0xFF0F00F0;
static const GLenum buffers[] = { GL_COLOR_ATTACHMENT0 }; static const GLenum buffers[] = { GL_COLOR_ATTACHMENT0 };
NodeBasedRenderer::NodeBasedRenderer() : Renderer() {} static RenderControlFunctor noOpController;
NodeBasedRenderer::NodeBasedRenderer( std::function<void(NodeBasedRenderer *, int, int)> configurator ) : NodeBasedRenderer::NodeBasedRenderer() : Renderer(), m_controller{noOpController} {}
NodeBasedRenderer::NodeBasedRenderer( RenderControlFunctor & controller ) :
Renderer(), Renderer(),
m_configurator{std::move(configurator)} {} m_controller{controller} {}
NodeBasedRenderer::~NodeBasedRenderer() = default; NodeBasedRenderer::~NodeBasedRenderer() = default;
...@@ -45,7 +47,7 @@ bool NodeBasedRenderer::buildRenderTechnique( RenderObject* ro ) const { ...@@ -45,7 +47,7 @@ bool NodeBasedRenderer::buildRenderTechnique( RenderObject* ro ) const {
return true; return true;
} }
void NodeBasedRenderer::initShaders() { void NodeBasedRenderer::initResources() {
// uses several resources from the Radium engine // uses several resources from the Radium engine
auto resourcesRootDir{ RadiumEngine::getInstance()->getResourcesDir() + "Shaders/" }; auto resourcesRootDir{ RadiumEngine::getInstance()->getResourcesDir() + "Shaders/" };
...@@ -54,15 +56,11 @@ void NodeBasedRenderer::initShaders() { ...@@ -54,15 +56,11 @@ void NodeBasedRenderer::initShaders() {
resourcesRootDir + "2DShaders/Basic2D.vert.glsl", resourcesRootDir + "2DShaders/Basic2D.vert.glsl",
resourcesRootDir + "2DShaders/Hdr2Ldr.frag.glsl" } ); resourcesRootDir + "2DShaders/Hdr2Ldr.frag.glsl" } );
}
void NodeBasedRenderer::initBuffers() {
m_postprocessFbo = std::make_unique<globjects::Framebuffer>(); m_postprocessFbo = std::make_unique<globjects::Framebuffer>();
// NodeBased renderer : only initializes textures that are shared between all the passes or // NodeBased renderer : only initializes textures that are shared between all the passes or
// that are used internally on the renderer. // that are used internally on the renderer.
// Each pass will manage its own textures and export them if they can be shared. // Each pass will manage its own textures and export them if they can be shared.
TextureParameters texparams; TextureParameters texparams;
texparams.width = m_width; texparams.width = m_width;
texparams.height = m_height; texparams.height = m_height;
...@@ -106,12 +104,11 @@ void NodeBasedRenderer::initializeInternal() { ...@@ -106,12 +104,11 @@ void NodeBasedRenderer::initializeInternal() {
m_lightmanagers.push_back( lmngr ); m_lightmanagers.push_back( lmngr );
// Initialize renderer resources // Initialize renderer resources
initShaders(); initResources();
initBuffers();
for ( const auto& t : m_sharedTextures ) for ( const auto& t : m_sharedTextures )
{ m_secondaryTextures.insert( { t.first, t.second.get() } ); } { m_secondaryTextures.insert( { t.first, t.second.get() } ); }
if ( m_configurator ) { m_configurator( this, m_width, m_height ); } m_controller.configure( this, m_width, m_height );
} }
void NodeBasedRenderer::resizeInternal() { void NodeBasedRenderer::resizeInternal() {
...@@ -269,13 +266,9 @@ void NodeBasedRenderer::postProcessInternal( const ViewingParameters& /* renderD ...@@ -269,13 +266,9 @@ void NodeBasedRenderer::postProcessInternal( const ViewingParameters& /* renderD
m_postprocessFbo->unbind(); m_postprocessFbo->unbind();
} }
// Todo : verify if the ro partition is the good one and that the passes use the right part.
void NodeBasedRenderer::updateStepInternal( const ViewingParameters& renderData ) { void NodeBasedRenderer::updateStepInternal( const ViewingParameters& renderData ) {
m_allRenderObjects.clear();
for ( auto it = m_fancyRenderObjects.begin(); it != m_fancyRenderObjects.end(); ++it) m_controller.update( renderData );
{
m_allRenderObjects.push_back( *it );
}
// Update passes // Update passes
// Note that this could be expensive. Find a way to add attributes to renderObjects so // Note that this could be expensive. Find a way to add attributes to renderObjects so
......
...@@ -14,6 +14,29 @@ namespace RadiumNBR { ...@@ -14,6 +14,29 @@ namespace RadiumNBR {
/// Todo, put this somewhere else. This is needed to locate resources by cclient applications /// Todo, put this somewhere else. This is needed to locate resources by cclient applications
extern int NodeBasedRendererMagic; extern int NodeBasedRendererMagic;
class NodeBasedRenderer;
/**
* Rendering functor prototype
* @todo make this a concept
*/
struct RenderControlFunctor {
virtual ~RenderControlFunctor() = default;
/// Configuration function.
/// Called once at the configuration of the renderer
virtual void configure(NodeBasedRenderer *renderer, int w, int h) {};
/// Resize function
/// Called each time the renderer is resized
virtual void resize(int w, int h) {};
/// Update function
/// Called once before each frame to update the internal state of the renderer
virtual void update(const Ra::Engine::Data::ViewingParameters& renderData) {};
};
/** Node based for the Radium Engine /** Node based for the Radium Engine
* This Renderer is fully configurable, either dynammically or programatically. * This Renderer is fully configurable, either dynammically or programatically.
* It implements the Ra::Engine::Rendering/Renderer interface and can be configured by adding * It implements the Ra::Engine::Rendering/Renderer interface and can be configured by adding
...@@ -32,8 +55,12 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende ...@@ -32,8 +55,12 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende
{ {
public: public:
//
NodeBasedRenderer(); NodeBasedRenderer();
NodeBasedRenderer( std::function<void(NodeBasedRenderer *, int, int)> configurator ); // TODO : instead of an std::function, restrict to a ref to a functor (class with () operator
// Such a functor could then be used also during the update step.
explicit NodeBasedRenderer( RenderControlFunctor& controller );
~NodeBasedRenderer() override; ~NodeBasedRenderer() override;
...@@ -64,8 +91,13 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende ...@@ -64,8 +91,13 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende
void debugInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override; void debugInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override;
void uiInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override; void uiInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override;
virtual void initShaders(); // TODO : merge these two function into initResources ?
virtual void initBuffers();
/** Initialize internal resources for the renderer.
* The base function creates the depth and final color texture to be shared by the rendering
* passes that need them.
*/
virtual void initResources();
public: public:
inline std::map<std::string, std::shared_ptr<Ra::Engine::Data::Texture>> &sharedTextures() { inline std::map<std::string, std::shared_ptr<Ra::Engine::Data::Texture>> &sharedTextures() {
...@@ -85,7 +117,8 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende ...@@ -85,7 +117,8 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende
} }
inline std::vector<RenderObjectPtr> *allRenderObjects() { inline std::vector<RenderObjectPtr> *allRenderObjects() {
return &m_allRenderObjects; //return &m_allRenderObjects;
return &m_fancyRenderObjects;
} }
inline int defaultPass() const { inline int defaultPass() const {
...@@ -103,13 +136,13 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende ...@@ -103,13 +136,13 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende
std::map< int, std::shared_ptr<RenderPass> > m_renderPasses; std::map< int, std::shared_ptr<RenderPass> > m_renderPasses;
/// Backup of all objects so that global passses can execute /// Backup of all objects so that global passses can execute
std::vector<RenderObjectPtr> m_allRenderObjects; //std::vector<RenderObjectPtr> m_allRenderObjects;
/// The default pass /// The default pass
int m_defaultPass{-1}; int m_defaultPass{-1};
/// The configurator functor to use /// The configurator functor to use
std::function<void(NodeBasedRenderer *, int, int)> m_configurator; RenderControlFunctor& m_controller;
}; };
} }
...@@ -50,7 +50,7 @@ void main() { ...@@ -50,7 +50,7 @@ void main() {
} }
} }
ssdo = 1 - ssdo/nbSamples; ssdo = 1 - ssdo/nbSamples;
ssdo *= ssdo; //ssdo *= ssdo;
ssdo = smoothstep(0, 1, ssdo); ssdo = smoothstep(0, 1, ssdo);
} }
out_ssao = vec4(vec3(ssdo), 1); out_ssao = vec4(vec3(ssdo), 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment