Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev-sge
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/app/src/app/vtx_app.cpp
  • Loading branch information
sguionni committed Sep 23, 2024
2 parents c034a5f + 4901361 commit 93429e1
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/bench/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion lib/app/src/app/vtx_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions lib/renderer/include/renderer/context/opengl_45.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ namespace VTX::Renderer::Context

void _createTexture( const IO & p_descIO, const Key p_key, std::vector<Key> & p_textures );

Vec2i _getTextureSize( const Attachment & ) const;

void _createUniforms(
GL::Buffer * const p_ubo,
const Uniforms & p_uniforms,
Expand Down
17 changes: 9 additions & 8 deletions lib/renderer/include/renderer/descriptors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
namespace VTX::Renderer
{
using Size = std::optional<std::variant<size_t, float>>;
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<size_t> width;
std::optional<size_t> 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
Expand Down
2 changes: 1 addition & 1 deletion lib/renderer/include/renderer/facade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions lib/renderer/include/renderer/passes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 9 additions & 5 deletions lib/renderer/include/renderer/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down Expand Up @@ -291,6 +294,7 @@ namespace VTX::Renderer
Vec3f cameraPosition;
uint padding;
Vec4f cameraClipInfos;
Vec2i resolution;
Vec2i mousePosition;
uint isPerspective;
};
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions lib/renderer/shaders/layout_uniforms_camera.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct Camera
mat4 matrixProjection;
vec3 cameraPosition;
vec4 cameraClipInfos; // _near * _far, _far, _far - _near, _near
ivec2 rendererSize;
ivec2 mousePosition;
uint isCameraPerspective;
};
Expand Down
40 changes: 35 additions & 5 deletions lib/renderer/src/renderer/context/opengl_45.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ namespace VTX::Renderer::Context
const IO & descIO = output.desc;
if ( std::holds_alternative<Attachment>( descIO ) )
{
// TODO: check if still needed.
Attachment attachment = std::get<Attachment>( descIO );

const Key keyTexture = _getKey( *descPassPtr, false, uint( channel ) );
const Key keyFbo = _getKey( *descPassPtr );
Expand All @@ -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
Expand Down Expand Up @@ -810,11 +817,13 @@ namespace VTX::Renderer::Context
_mapFormats[ attachment.format ]
);

Vec2i size = _getTextureSize( attachment );

_textures.emplace(
p_key,
std::make_unique<GL::Texture2D>(
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 ],
Expand All @@ -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<float>( p_Attachment.width.value() )
? size_t( std::get<float>( p_Attachment.width.value() ) * width )
: std::get<size_t>( p_Attachment.width.value() )
: width;

const size_t textureHeight = p_Attachment.height.has_value()
? std::holds_alternative<float>( p_Attachment.height.value() )
? size_t( std::get<float>( p_Attachment.height.value() ) * height )
: std::get<size_t>( p_Attachment.height.value() )
: height;

return Vec2i( textureWidth, textureHeight );
}

void OpenGL45::_createUniforms(
GL::Buffer * const p_ubo,
const Uniforms & p_uniforms,
Expand Down
5 changes: 4 additions & 1 deletion lib/renderer/src/renderer/facade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ); }

Expand Down
2 changes: 2 additions & 0 deletions lib/renderer/src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace VTX::Renderer
{ "Camera clip infos", // { _near * _far, _far, _far - _near, _near }
E_TYPE::VEC4F,
StructUniformValue<Vec4f> { VEC4F_ZERO } },
{ "Resolution", E_TYPE::VEC2I, StructUniformValue<Vec2i> { Vec2i { p_width, p_height } } },
{ "Mouse position", E_TYPE::VEC2I, StructUniformValue<Vec2i> { Vec2i { 0, 0 } } },
{ "Is perspective", E_TYPE::UINT, StructUniformValue<uint> { 1 } } },
15 }
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 93429e1

Please sign in to comment.