diff --git a/src/DemoApp/main.cpp b/src/DemoApp/main.cpp index 2ee60666a573757aad2fd483c6777149bbfa9465..d9902a89a614d82e42411070b70cb16977126daf 100644 --- a/src/DemoApp/main.cpp +++ b/src/DemoApp/main.cpp @@ -80,7 +80,8 @@ void AddCustomAttributeToMeshes() { auto theMesh = ro->getMesh(); auto displayMesh = - dynamic_cast<Ra::Engine::Data::AttribArrayDisplayable*>( theMesh.get() ); + std::dynamic_pointer_cast<Ra::Engine::Data::AttribArrayDisplayable>( + theMesh ); LOG( logINFO ) << "\t\tMesh " << displayMesh->getName() << " is processed."; auto& coreMesh = displayMesh->getAttribArrayGeometry(); diff --git a/src/libRender/RadiumNBR/NodeBasedRenderer.cpp b/src/libRender/RadiumNBR/NodeBasedRenderer.cpp index e1cbe285f4331c0ad651a6146f89604a73b70cbc..184a3d9baf6b6077c94a2c099f252e5e2b0616ec 100644 --- a/src/libRender/RadiumNBR/NodeBasedRenderer.cpp +++ b/src/libRender/RadiumNBR/NodeBasedRenderer.cpp @@ -29,11 +29,11 @@ int NodeBasedRendererMagic = 0xFF0F00F0; static const GLenum buffers[] = {GL_COLOR_ATTACHMENT0}; -static RenderControlFunctor noOpController; +static NodeBasedRenderer::RenderControlFunctor noOpController; NodeBasedRenderer::NodeBasedRenderer() : Renderer(), m_controller{noOpController} {} -NodeBasedRenderer::NodeBasedRenderer( RenderControlFunctor& controller ) : +NodeBasedRenderer::NodeBasedRenderer( NodeBasedRenderer::RenderControlFunctor& controller ) : Renderer(), m_controller{controller} {} NodeBasedRenderer::~NodeBasedRenderer() = default; @@ -145,6 +145,8 @@ void NodeBasedRenderer::initializeInternal() { void NodeBasedRenderer::resizeInternal() { + m_controller.resize( m_width, m_height ); + m_sharedTextures["Depth (RadiumNBR)"]->resize( m_width, m_height ); m_sharedTextures["Linear RGB (RadiumNBR)"]->resize( m_width, m_height ); diff --git a/src/libRender/RadiumNBR/NodeBasedRenderer.hpp b/src/libRender/RadiumNBR/NodeBasedRenderer.hpp index ab3691b173197a4f98aedd0ea5f51508d888b21b..72c4b721974c0069428c859bff16f361dce3182f 100644 --- a/src/libRender/RadiumNBR/NodeBasedRenderer.hpp +++ b/src/libRender/RadiumNBR/NodeBasedRenderer.hpp @@ -11,42 +11,34 @@ class Framebuffer; 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 client applications extern int NodeBasedRendererMagic; -class NodeBasedRenderer; class UIPass; class DebugPass; -/** - * 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 - * This Renderer is fully configurable, either dynammically or programatically. - * It implements the Ra::Engine::Rendering/Renderer interface and can be configured by adding - * as many RadiumNBR::RenderPass as needed. + * This Renderer is fully configurable, either dynamically or programmatically. + * It implements the Ra::Engine::Rendering/Renderer interface. + * + * A NodeBasedRenderer is configured by using the RenderControlFunctor given at construction. + * A RenderControlFunctor offers the following services : + * - configure() : add to the renderer as many RadiumNBR::RenderPass as needed. This method is + * called once when initializing the renderer. This method could also initialize internal + * resources into the controller that could be used to control the rendering. + * - resize() : called each time the renderer output is resized. This will allow modify controller + * resources that depends on the size of the output (e.g. internal textures ...) + * - update() : Called once before each frame to update the internal state of the renderer. * - * It defines two textures that migh be shared between passes : - * - a depth buffer attachable texture - * - a Linear space RGBA color texture + * A NodeBasedRenderer defines two textures that might be shared between passes : + * - a depth buffer attachable texture, stored with the key "Depth (RadiumNBR)" into the shared + * textures collection + * - a Linear space RGBA color texture, stored with the key "Linear RGB (RadiumNBR)" into the + * shared textures collection * - * It allows to apply a linearRGB to sRGB color transformation before displaying the image. + * If requested on the base Ra::Engine::Rendering::Renderer, a NodeBasedRenderer apply a + * post-process step on the "Linear RGB (RadiumNBR)" that convert colors from linearRGB to sRGB + * color space before displaying the image. * * * @see rendering.md for description of the renderer @@ -55,11 +47,39 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende { public: - // + /** + * Rendering functor prototype + * @todo make this a concept + */ + struct RenderControlFunctor { + + RenderControlFunctor() = default; + virtual ~RenderControlFunctor() = default; + RenderControlFunctor( const RenderControlFunctor& ) = delete; + RenderControlFunctor( const RenderControlFunctor&& ) = delete; + RenderControlFunctor& operator=( RenderControlFunctor&& ) = delete; + RenderControlFunctor& operator=( const RenderControlFunctor& ) = delete; + + /// 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 ){}; + }; + + /// Construct a renderer that has to be configured explicitely NodeBasedRenderer(); + /// Construct a renderer configured and managed through the controller explicit NodeBasedRenderer( RenderControlFunctor& controller ); + /// The destructor is defaulted ~NodeBasedRenderer() override; [[nodiscard]] std::string getRendererName() const override { return "Configurable Renderer"; } @@ -102,8 +122,6 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende void debugInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override; void uiInternal( const Ra::Engine::Data::ViewingParameters& renderData ) override; - // TODO : merge these two function into initResources ? - /** 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. @@ -134,7 +152,7 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende /// internal FBO used for post-processing std::unique_ptr<globjects::Framebuffer> m_postprocessFbo; - /// vector of this renderer render passes, sorted by precedence (first pass is at index 0) + /// collection of render passes, sorted by precedence (first pass is at key 0) std::map<int, std::shared_ptr<RenderPass>> m_renderPasses; /// The default pass @@ -147,7 +165,7 @@ class NodeBasedRenderer_LIBRARY_API NodeBasedRenderer : public Ra::Engine::Rende std::unique_ptr<UIPass> m_uiPass; bool m_showUi{false}; - /// The pass to draw UI object + /// The pass to draw Debug object std::unique_ptr<DebugPass> m_debugPass; bool m_showDebug{false}; }; diff --git a/src/libRender/RadiumNBR/Renderer/Visualization.hpp b/src/libRender/RadiumNBR/Renderer/Visualization.hpp index ecf18ae23528bd35253169463c1ef67a072966b4..9df91aa533a773c29017b79d1eba8792774e12d5 100644 --- a/src/libRender/RadiumNBR/Renderer/Visualization.hpp +++ b/src/libRender/RadiumNBR/Renderer/Visualization.hpp @@ -8,7 +8,8 @@ class ClearPass; * This class parameterize the renderer just after the OpenGL system was initialized. * when a method of this controler is called, the OpenGL context of the drawing window is activated. */ -class NodeBasedRenderer_LIBRARY_API VisualizationController : public RadiumNBR::RenderControlFunctor +class NodeBasedRenderer_LIBRARY_API VisualizationController + : public RadiumNBR::NodeBasedRenderer::RenderControlFunctor { public: /*