diff --git a/app/bench/src/main.cpp b/app/bench/src/main.cpp index 4d2ca0ffe..cc5db95f6 100644 --- a/app/bench/src/main.cpp +++ b/app/bench/src/main.cpp @@ -155,14 +155,14 @@ int main( int, char ** ) // Main loop. while ( isRunning ) { - float time = float( ui.getTime() ) * 1e-3f; + float time = float( ui.getTime() ); float deltaTime = ui.getDeltaTime(); // Update scene. scene.update( deltaTime ); // Renderer. - renderer.render( time ); + renderer.render( deltaTime, time ); // UI. ui.draw( &camera, &scene, &renderer ); diff --git a/lib/app/src/app/vtx_app.cpp b/lib/app/src/app/vtx_app.cpp index 43a156fd8..f3be875cc 100644 --- a/lib/app/src/app/vtx_app.cpp +++ b/lib/app/src/app/vtx_app.cpp @@ -150,7 +150,8 @@ namespace VTX::App frameInfo.set( Internal::Monitoring::RENDER_DURATION_KEY, - Util::CHRONO_CPU( [ p_elapsedTime ]() { RENDERER_SYSTEM().facade().render( p_elapsedTime ); } ) + Util::CHRONO_CPU( [ p_deltaTime, p_elapsedTime ]() + { RENDERER_SYSTEM().facade().render( p_deltaTime, p_elapsedTime ); } ) ); frameInfo.set( diff --git a/lib/renderer/include/renderer/context/opengl_45.hpp b/lib/renderer/include/renderer/context/opengl_45.hpp index c08d53e94..db2f38ecb 100644 --- a/lib/renderer/include/renderer/context/opengl_45.hpp +++ b/lib/renderer/include/renderer/context/opengl_45.hpp @@ -284,6 +284,8 @@ namespace VTX::Renderer::Context void _createTexture( const IO & p_descIO, const Key p_key, std::vector & p_textures ); + Vec2i _getTextureSize( const Attachment & ) const; + void _createUniforms( GL::Buffer * const p_ubo, const Uniforms & p_uniforms, diff --git a/lib/renderer/include/renderer/descriptors.hpp b/lib/renderer/include/renderer/descriptors.hpp index b6b509301..0810de065 100644 --- a/lib/renderer/include/renderer/descriptors.hpp +++ b/lib/renderer/include/renderer/descriptors.hpp @@ -17,16 +17,17 @@ */ namespace VTX::Renderer { + using Size = std::optional>; struct Attachment { - E_FORMAT format = E_FORMAT::RGBA16F; - E_WRAPPING wrappingS = E_WRAPPING::CLAMP_TO_EDGE; - E_WRAPPING wrappingT = E_WRAPPING::CLAMP_TO_EDGE; - E_FILTERING filteringMin = E_FILTERING::NEAREST; - E_FILTERING filteringMag = E_FILTERING::NEAREST; - std::optional width; - std::optional height; - void * data = nullptr; + E_FORMAT format = E_FORMAT::RGBA16F; + E_WRAPPING wrappingS = E_WRAPPING::CLAMP_TO_EDGE; + E_WRAPPING wrappingT = E_WRAPPING::CLAMP_TO_EDGE; + E_FILTERING filteringMin = E_FILTERING::NEAREST; + E_FILTERING filteringMag = E_FILTERING::NEAREST; + Size width = std::nullopt; + Size height = std::nullopt; + void * data = nullptr; }; struct Data diff --git a/lib/renderer/include/renderer/facade.hpp b/lib/renderer/include/renderer/facade.hpp index 4faef671a..43aa5b4d5 100644 --- a/lib/renderer/include/renderer/facade.hpp +++ b/lib/renderer/include/renderer/facade.hpp @@ -24,7 +24,7 @@ namespace VTX::Renderer ~Facade(); void resize( const size_t p_width, const size_t p_height, const uint p_output = 0 ); void build( const uint p_output = 0, void * p_loader = nullptr ); - void render( const float p_time ); + void render( const float p_deltaTime, const float p_elapsedTime ); void setOutput( const uint p_output ); void addProxyMolecule( Proxy::Molecule & p_proxy ); void removeProxyMolecule( Proxy::Molecule & p_proxy ); diff --git a/lib/renderer/include/renderer/passes.hpp b/lib/renderer/include/renderer/passes.hpp index 06fe18714..45936acfe 100644 --- a/lib/renderer/include/renderer/passes.hpp +++ b/lib/renderer/include/renderer/passes.hpp @@ -158,8 +158,8 @@ namespace VTX::Renderer E_WRAPPING::REPEAT, E_FILTERING::NEAREST, E_FILTERING::NEAREST, - 1, - 1, + size_t( 1 ), + size_t( 1 ), (void *)( blurDefaultTexture.data() ) } } } }, Outputs { { E_CHAN_OUT::COLOR_0, { "", imageRGBA16F } } }, Programs { diff --git a/lib/renderer/include/renderer/renderer.hpp b/lib/renderer/include/renderer/renderer.hpp index d902b587c..32db529e6 100644 --- a/lib/renderer/include/renderer/renderer.hpp +++ b/lib/renderer/include/renderer/renderer.hpp @@ -65,6 +65,9 @@ namespace VTX::Renderer width = p_width; height = p_height; + Vec2i size = { p_width, p_height }; + setValue( size, "Resolution" ); + _context->resize( _renderGraph->getRenderQueue(), p_width, p_height ); setNeedUpdate( true ); @@ -86,17 +89,17 @@ namespace VTX::Renderer * @brief The render loop. * @param p_time is the current running time. */ - inline void render( const float p_time ) + inline void render( const float p_deltaTime, const float p_elapsedTime ) { if ( _needUpdate || forceUpdate || _framesRemaining > 0 ) { if ( logDurations ) { - _renderLog( p_time ); + _renderLog( p_deltaTime, p_elapsedTime ); } else { - _render( p_time ); + _render( p_deltaTime, p_elapsedTime ); } if ( not forceUpdate ) @@ -291,6 +294,7 @@ namespace VTX::Renderer Vec3f cameraPosition; uint padding; Vec4f cameraClipInfos; + Vec2i resolution; Vec2i mousePosition; uint isPerspective; }; @@ -319,7 +323,7 @@ namespace VTX::Renderer * @brief The main render loop that call each generated instruction. * @param p_time the current time. */ - inline void _render( const float p_time ) const + inline void _render( const float p_deltaTime, const float p_elapsedTime ) const { for ( const Instruction & instruction : _instructions ) { @@ -331,7 +335,7 @@ namespace VTX::Renderer * @brief The main render loop that call instructions with time logging. * @param p_time the current time. */ - inline void _renderLog( const float p_time ) + inline void _renderLog( const float p_deltaTime, const float p_elapsedTime ) { for ( InstructionsDurationRange & instructionDurationRange : _instructionsDurationRanges ) { diff --git a/lib/renderer/shaders/layout_uniforms_camera.glsl b/lib/renderer/shaders/layout_uniforms_camera.glsl index 80eb34532..c1c9697aa 100644 --- a/lib/renderer/shaders/layout_uniforms_camera.glsl +++ b/lib/renderer/shaders/layout_uniforms_camera.glsl @@ -4,6 +4,7 @@ struct Camera mat4 matrixProjection; vec3 cameraPosition; vec4 cameraClipInfos; // _near * _far, _far, _far - _near, _near + ivec2 rendererSize; ivec2 mousePosition; uint isCameraPerspective; }; diff --git a/lib/renderer/src/renderer/context/opengl_45.cpp b/lib/renderer/src/renderer/context/opengl_45.cpp index e7195a1f1..2fa5e0920 100644 --- a/lib/renderer/src/renderer/context/opengl_45.cpp +++ b/lib/renderer/src/renderer/context/opengl_45.cpp @@ -476,7 +476,7 @@ namespace VTX::Renderer::Context const IO & descIO = output.desc; if ( std::holds_alternative( descIO ) ) { - // TODO: check if still needed. + Attachment attachment = std::get( descIO ); const Key keyTexture = _getKey( *descPassPtr, false, uint( channel ) ); const Key keyFbo = _getKey( *descPassPtr ); @@ -488,9 +488,16 @@ namespace VTX::Renderer::Context assert( _framebuffers.contains( keyFbo ) ); auto & fbo = _framebuffers[ keyFbo ]; - texture->resize( width, height ); + const Vec2i size = _getTextureSize( attachment ); + texture->resize( size.x, size.y ); fbo->attachTexture( *texture, _mapAttachments[ channel ] ); - VTX_TRACE( "Texture resized: {} ({})", output.name, Util::Enum::enumName( channel ) ); + VTX_TRACE( + "Texture resized: {} ({}) = {}x{}", + output.name, + Util::Enum::enumName( channel ), + size.x, + size.y + ); } } else @@ -810,11 +817,13 @@ namespace VTX::Renderer::Context _mapFormats[ attachment.format ] ); + Vec2i size = _getTextureSize( attachment ); + _textures.emplace( p_key, std::make_unique( - attachment.width.has_value() ? attachment.width.value() : width, - attachment.height.has_value() ? attachment.height.value() : height, + size.x, + size.y, _mapFormats[ attachment.format ], _mapWrappings[ attachment.wrappingS ], _mapWrappings[ attachment.wrappingT ], @@ -834,6 +843,27 @@ namespace VTX::Renderer::Context } } + Vec2i OpenGL45::_getTextureSize( const Attachment & p_Attachment ) const + { + // Texture size can be: + // - fixed size. + // - relative size to the renderer size. + // - same as the renderer size. + const size_t textureWidth = p_Attachment.width.has_value() + ? std::holds_alternative( p_Attachment.width.value() ) + ? size_t( std::get( p_Attachment.width.value() ) * width ) + : std::get( p_Attachment.width.value() ) + : width; + + const size_t textureHeight = p_Attachment.height.has_value() + ? std::holds_alternative( p_Attachment.height.value() ) + ? size_t( std::get( p_Attachment.height.value() ) * height ) + : std::get( p_Attachment.height.value() ) + : height; + + return Vec2i( textureWidth, textureHeight ); + } + void OpenGL45::_createUniforms( GL::Buffer * const p_ubo, const Uniforms & p_uniforms, diff --git a/lib/renderer/src/renderer/facade.cpp b/lib/renderer/src/renderer/facade.cpp index 836f10ae9..5a436d984 100644 --- a/lib/renderer/src/renderer/facade.cpp +++ b/lib/renderer/src/renderer/facade.cpp @@ -17,7 +17,10 @@ namespace VTX::Renderer void Facade::build( const uint p_output, void * p_loader ) { _renderer->build( p_output, p_loader ); } - void Facade::render( const float p_time ) { _renderer->render( p_time ); } + void Facade::render( const float p_deltaTime, const float p_elapsedTime ) + { + _renderer->render( p_deltaTime, p_elapsedTime ); + } void Facade::setOutput( const uint p_output ) { _renderer->setOutput( p_output ); } diff --git a/lib/renderer/src/renderer/renderer.cpp b/lib/renderer/src/renderer/renderer.cpp index 6918703f7..57c69fa92 100644 --- a/lib/renderer/src/renderer/renderer.cpp +++ b/lib/renderer/src/renderer/renderer.cpp @@ -69,6 +69,7 @@ namespace VTX::Renderer { "Camera clip infos", // { _near * _far, _far, _far - _near, _near } E_TYPE::VEC4F, StructUniformValue { VEC4F_ZERO } }, + { "Resolution", E_TYPE::VEC2I, StructUniformValue { Vec2i { p_width, p_height } } }, { "Mouse position", E_TYPE::VEC2I, StructUniformValue { Vec2i { 0, 0 } } }, { "Is perspective", E_TYPE::UINT, StructUniformValue { 1 } } }, 15 } @@ -381,6 +382,7 @@ namespace VTX::Renderer p_proxy.cameraFar - p_proxy.cameraNear, p_proxy.cameraNear ), + Vec2i( width, height ), p_proxy.mousePosition, p_proxy.isPerspective } }, "Camera"