diff --git a/lib/renderer/include/private/renderer/context/concept_context.hpp b/lib/renderer/include/private/renderer/context/concept_context.hpp index d06227c99..a2876d7a5 100644 --- a/lib/renderer/include/private/renderer/context/concept_context.hpp +++ b/lib/renderer/include/private/renderer/context/concept_context.hpp @@ -9,6 +9,9 @@ namespace VTX::Renderer::Context { + using Key = std::string; + using Keys = std::vector; + /** * @brief Shared attributes for all render contexts. */ @@ -19,14 +22,11 @@ namespace VTX::Renderer::Context FilePath shaderPath; }; - using Key = std::string; - using Keys = std::vector; - /** * @brief The context is the graphic API implementation. */ template - concept Concept + concept ConceptContextImpl = std::is_base_of::value && requires( C p_context, @@ -55,7 +55,6 @@ namespace VTX::Renderer::Context std::any & p_textureData, const ComputePass & p_computePass, const bool p_bool - ) { { p_context.build( @@ -79,6 +78,192 @@ namespace VTX::Renderer::Context { p_context.compute( p_computePass ) } -> std::same_as; }; + /* + enum struct E_FUNCTION + { + BUILD, + RESIZE, + SET_OUTPUT, + SET_VALUE, + RESERVE_DATA, + SET, + SET_SUB, + GET, + FILL_INFOS, + MEASURE_TASK_DURATION, + COMPILE_SHADERS, + SNAPSHOT, + GET_TEXTURE_DATA, + COMPUTE + }; + */ + + /* + using FunctionBuild + = void ( * )( const RenderQueue &, const Links &, const Handle, const std::vector &, Instructions &, + InstructionsDurationRanges & ); using FunctionResize = void ( * )( const RenderQueue &, const size_t, const + size_t ); using FunctionSetOutput = void ( * )( const Handle ); using FunctionSetValue = void ( * )( const + std::any &, const Key &, const size_t ); using FunctionReserveData = void ( * )( const size_t, const Key &, const + std::any & ); using FunctionSet = void ( * )( const std::vector &, const Key & ); using + FunctionSetSub = void ( * )( const std::vector &, const Key &, const size_t, const bool, const size_t ); + using FunctionGet = void ( * )( std::vector &, const Key & ); + using FunctionFillInfos = void ( * )( StructInfos & ); + using FunctionMeasureTaskDuration = float ( * )( const Util::Chrono::Task & ); + using FunctionCompileShaders = void ( * )(); + using FunctionSnapshot + = void ( * )( std::vector &, const RenderQueue &, const Instructions &, const size_t, const size_t ); + using FunctionGetTextureData = void ( * )( std::any &, const size_t, const size_t, const Key &, const E_CHAN_OUT ); + using FunctionCompute = void ( * )( const ComputePass & ); + */ + + using FunctionBuild = std::function< + void( const RenderQueue &, const Links &, const Handle, const std::vector &, Instructions &, InstructionsDurationRanges & )>; + using FunctionResize = std::function; + using FunctionSetOutput = std::function; + using FunctionSetValue = std::function; + using FunctionReserveData = std::function; + using FunctionSet = std::function &, const Key & )>; + using FunctionSetSub + = std::function &, const Key &, const size_t, const bool, const size_t )>; + using FunctionGet = std::function &, const Key & )>; + using FunctionFillInfos = std::function; + using FunctionMeasureTaskDuration = std::function; + using FunctionCompileShaders = std::function; + using FunctionSnapshot = std::function< + void( std::vector &, const RenderQueue &, const Instructions &, const size_t, const size_t )>; + using FunctionGetTextureData + = std::function; + using FunctionCompute = std::function; + + class Context + { + public: + // Function pointer to the build function. + template + void set() + { + std::unique_ptr context = std::make_unique(); + //_impl = std::move( context ); + + //_build = + } + + /* + template + void run( Args... p_args ) + { + if constexpr ( F == E_FUNCTION::BUILD ) + { + _build( p_args... ); + } + else if constexpr ( F == E_FUNCTION::RESIZE ) + { + _resize( p_args... ); + } + else if constexpr ( F == E_FUNCTION::SET_OUTPUT ) + { + _setOutput( p_args... ); + } + else if constexpr ( F == E_FUNCTION::SET_VALUE ) + { + _setValue( p_args... ); + } + else if constexpr ( F == E_FUNCTION::RESERVE_DATA ) + { + _reserveData( p_args... ); + } + else if constexpr ( F == E_FUNCTION::SET ) + { + _set( p_args... ); + } + else if constexpr ( F == E_FUNCTION::SET_SUB ) + { + _setSub( p_args... ); + } + else if constexpr ( F == E_FUNCTION::GET ) + { + _get( p_args... ); + } + else if constexpr ( F == E_FUNCTION::FILL_INFOS ) + { + _fillInfos( p_args... ); + } + else if constexpr ( F == E_FUNCTION::MEASURE_TASK_DURATION ) + { + _measureTaskDuration( p_args... ); + } + else if constexpr ( F == E_FUNCTION::COMPILE_SHADERS ) + { + _compileShaders( p_args... ); + } + else if constexpr ( F == E_FUNCTION::SNAPSHOT ) + { + _snapshot( p_args... ); + } + else if constexpr ( F == E_FUNCTION::GET_TEXTURE_DATA ) + { + _getTextureData( p_args... ); + } + else if constexpr ( F == E_FUNCTION::COMPUTE ) + { + _compute( p_args... ); + } + else + { + static_assert( std::is_same_v, "Unknown function" ); + } + } + */ + + void build( + const RenderQueue & p_renderQueue, + const Links & p_links, + const Handle p_output, + const std::vector & p_globalData, + Instructions & p_instructions, + InstructionsDurationRanges & p_instructionsDurationRanges + ) + { + _build( p_renderQueue, p_links, p_output, p_globalData, p_instructions, p_instructionsDurationRanges ); + } + + void resize( const RenderQueue & p_renderQueue, const size_t p_width, const size_t p_height ) + { + _resize( p_renderQueue, p_width, p_height ); + } + + void setOutput( const Handle p_output ) { _setOutput( p_output ); } + + void setValue( const std::any & p_value, const Key & p_key, const size_t p_index ) + { + _setValue( p_value, p_key, p_index ); + } + + void reserveData( const size_t p_size, const Key & p_key, const std::any & p_value ) + { + _reserveData( p_size, p_key, p_value ); + } + + void set( const std::vector & p_data, const Key & p_key ) { _set( p_data, p_key ); } + + private: + std::unique_ptr _impl; + + FunctionBuild _build; + FunctionResize _resize; + FunctionSetOutput _setOutput; + FunctionSetValue _setValue; + FunctionReserveData _reserveData; + FunctionSet _set; + FunctionSetSub _setSub; + FunctionGet _get; + FunctionFillInfos _fillInfos; + FunctionMeasureTaskDuration _measureTaskDuration; + FunctionCompileShaders _compileShaders; + FunctionSnapshot _snapshot; + FunctionGetTextureData _getTextureData; + FunctionCompute _compute; + }; } // namespace VTX::Renderer::Context #endif diff --git a/lib/renderer/include/private/renderer/render_graph.hpp b/lib/renderer/include/private/renderer/render_graph.hpp index 3caf0e91c..cbd26713f 100644 --- a/lib/renderer/include/private/renderer/render_graph.hpp +++ b/lib/renderer/include/private/renderer/render_graph.hpp @@ -10,10 +10,7 @@ namespace VTX::Renderer { /** * @brief A graph with nodes (passes) and links. - * @tparam C The render context. - * @tparam S The scheduler that convert graph to render queue. */ - template class RenderGraph { public: @@ -113,7 +110,8 @@ namespace VTX::Renderer std::erase_if( _links, [ &p_link ]( const std::unique_ptr & p_e ) { return p_e.get() == p_link; } ); } - C * setup( + template + Context::Context * setup( void * const p_loader, const size_t p_width, const size_t p_height, @@ -135,7 +133,8 @@ namespace VTX::Renderer // Compute queue with scheduler. try { - _scheduler.schedule( _passes, _links, _output, _renderQueue ); + S scheduler; + scheduler.schedule( _passes, _links, _output, _renderQueue ); } catch ( const std::exception & p_e ) { @@ -193,9 +192,8 @@ namespace VTX::Renderer inline void addGlobalData( const BufferData & p_globalData ) { _globalData.emplace_back( p_globalData ); } private: - S _scheduler; - RenderQueue _renderQueue; - std::unique_ptr _context; + RenderQueue _renderQueue; + std::unique_ptr _context; const Output * _output; Passes _passes; diff --git a/lib/renderer/include/private/renderer/renderer.hpp b/lib/renderer/include/private/renderer/renderer.hpp index ff3810376..72d24a473 100644 --- a/lib/renderer/include/private/renderer/renderer.hpp +++ b/lib/renderer/include/private/renderer/renderer.hpp @@ -27,12 +27,6 @@ namespace VTX::Renderer class Renderer { public: - /** - * @brief The render graph with OpenGL45 API and the DFS scheduler. - */ - using RenderGraphOpenGL45 = RenderGraph; - using RenderGraphDefault = RenderGraph; - Renderer( const size_t p_width, const size_t p_height, @@ -263,12 +257,12 @@ namespace VTX::Renderer Util::Callback<> onReady; private: - Context::OpenGL45 * _context = nullptr; - void * _loader = nullptr; - bool _needUpdate = false; - size_t _framesRemaining = BUFFER_COUNT; - FilePath _shaderPath; - std::unique_ptr _renderGraph; + Context::Context * _context = nullptr; + void * _loader = nullptr; + bool _needUpdate = false; + size_t _framesRemaining = BUFFER_COUNT; + FilePath _shaderPath; + std::unique_ptr _renderGraph; // All instructions computed by the graph and his context. Instructions _instructions; // Used to log render times. diff --git a/lib/renderer/include/public/renderer/facade.hpp b/lib/renderer/include/public/renderer/facade.hpp index 5e1f0c855..87048d950 100644 --- a/lib/renderer/include/public/renderer/facade.hpp +++ b/lib/renderer/include/public/renderer/facade.hpp @@ -3,7 +3,6 @@ #include "renderer/descriptors.hpp" #include "renderer/struct_infos.hpp" -#include #include #include @@ -21,7 +20,7 @@ namespace VTX::Renderer } // namespace Proxy /** - * @brief The facade is the only way to access the renderer from another package. + * @brief The facade is the only way to access the renderer from another package (pimpl). */ class Facade { diff --git a/lib/renderer/src/renderer/renderer.cpp b/lib/renderer/src/renderer/renderer.cpp index 9d7e25407..e3f9693c7 100644 --- a/lib/renderer/src/renderer/renderer.cpp +++ b/lib/renderer/src/renderer/renderer.cpp @@ -12,7 +12,7 @@ namespace VTX::Renderer width( p_width ), height( p_height ), _shaderPath( p_shaderPath ), _loader( p_loader ) { // Graph. - _renderGraph = std::make_unique(); + _renderGraph = std::make_unique(); // Passes. _refreshGraph(); @@ -226,7 +226,7 @@ namespace VTX::Renderer Util::String::durationToStr( Util::CHRONO_CPU( [ & ]() { - _context = _renderGraph->setup( + _context = _renderGraph->setup( p_loader ? p_loader : _loader, width, height, @@ -375,6 +375,8 @@ namespace VTX::Renderer cacheSC.representations, "SpheresCylindersRepresentations", cacheSC.rangeSpheres.getFirst() ); _context->setSub( cacheR.representations, "RibbonsRepresentations", cacheR.range.getFirst() ); + cacheR.representations, "RibbonsRepresentations", cacheR.range.getFirst() + ); }; // Remove. @@ -385,6 +387,8 @@ namespace VTX::Renderer { Cache::SphereCylinder & cacheSC = _cacheSpheresCylinders[ &p_proxy ]; _context->setSub( *p_proxy.atomPositions, "SpheresCylindersPositions", cacheSC.rangeSpheres.getFirst() ); + *p_proxy.atomPositions, "SpheresCylindersPositions", cacheSC.rangeSpheres.getFirst() + ); }; // Colors. @@ -392,6 +396,8 @@ namespace VTX::Renderer { Cache::SphereCylinder & cacheSC = _cacheSpheresCylinders[ &p_proxy ]; _context->setSub( p_colors, "SpheresCylindersColors", cacheSC.rangeSpheres.getFirst() ); + p_colors, "SpheresCylindersColors", cacheSC.rangeSpheres.getFirst() + ); }; // Residue colors. @@ -452,6 +458,8 @@ namespace VTX::Renderer */ _context->setSub( cacheSC.flags, "SpheresCylindersFlags", cacheSC.rangeSpheres.getFirst() ); + cacheSC.flags, "SpheresCylindersFlags", cacheSC.rangeSpheres.getFirst() + ); // TODO: ribbons and SES. }; @@ -745,6 +753,8 @@ namespace VTX::Renderer p_proxy.onChange += [ this, &p_proxy ]( const size_t p_index ) { _context->setSub( { ( *p_proxy.colors )[ p_index ] }, "ColorLayout", p_index ); + { ( *p_proxy.colors )[ p_index ] }, "ColorLayout", p_index + ); setNeedUpdate( true ); }; }