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

DebugPass and UiPass are now operational

parent 445af391
No related branches found
No related tags found
No related merge requests found
...@@ -128,8 +128,11 @@ void NodeBasedRenderer::initializeInternal() { ...@@ -128,8 +128,11 @@ void NodeBasedRenderer::initializeInternal() {
// TODO, do we really need to setup an index for the two following passes // TODO, do we really need to setup an index for the two following passes
// build the Ui pass // build the Ui pass
// todo find a way to replace the "31" by another id // todo find a way to replace the "31" by another id
m_uiPass = std::make_unique<UIPass>( &m_uiRenderObjects, 31 ); m_uiPass = std::make_unique<UIPass>( &m_uiRenderObjects );
m_uiPass->setResourcesDir( resourcesPath ); m_uiPass->setResourcesDir( resourcesPath );
m_uiPass->setInputs( *( sharedTextures().find( "Depth (RadiumNBR)" ) ) );
m_uiPass->setOutput( m_fancyTexture.get() );
m_uiPass->initializePass( m_width, m_height, m_shaderProgramManager );
// configure the pass // configure the pass
m_uiPass->deactivate(); m_uiPass->deactivate();
......
...@@ -24,7 +24,7 @@ DebugPass::~DebugPass() = default; ...@@ -24,7 +24,7 @@ DebugPass::~DebugPass() = default;
bool DebugPass::buildRenderTechnique( const Ra::Engine::Rendering::RenderObject* ro, bool DebugPass::buildRenderTechnique( const Ra::Engine::Rendering::RenderObject* ro,
Ra::Engine::Rendering::RenderTechnique& rt ) const { Ra::Engine::Rendering::RenderTechnique& rt ) const {
// This method is never called for DebugObject. // This method is never called for DebugObjects.
// Rendering use the Default Radium pass // Rendering use the Default Radium pass
return true; return true;
} }
...@@ -42,17 +42,6 @@ bool DebugPass::update() { ...@@ -42,17 +42,6 @@ bool DebugPass::update() {
} }
void DebugPass::resize( size_t width, size_t height ) { void DebugPass::resize( size_t width, size_t height ) {
// Only resize the owned textures. Imported one are resized by their owner
for ( auto& t : m_localTextures )
{
t.second->resize( width, height );
}
for ( auto& t : m_sharedTextures )
{
t.second->resize( width, height );
}
m_fbo->bind(); m_fbo->bind();
m_fbo->attachTexture( GL_DEPTH_ATTACHMENT, m_importedTextures["Debug::Depth"]->texture() ); m_fbo->attachTexture( GL_DEPTH_ATTACHMENT, m_importedTextures["Debug::Depth"]->texture() );
// no need to resize the output texture, it belongs to the Ra::Engine::Rendering::Renderer and // no need to resize the output texture, it belongs to the Ra::Engine::Rendering::Renderer and
...@@ -69,13 +58,12 @@ void DebugPass::resize( size_t width, size_t height ) { ...@@ -69,13 +58,12 @@ void DebugPass::resize( size_t width, size_t height ) {
void DebugPass::execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const { void DebugPass::execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const {
m_fbo->bind(); m_fbo->bind();
glDrawBuffers( 1, buffers );
GL_ASSERT( glDisable( GL_BLEND ) ); GL_ASSERT( glDisable( GL_BLEND ) );
GL_ASSERT( glEnable( GL_DEPTH_TEST ) ); GL_ASSERT( glEnable( GL_DEPTH_TEST ) );
GL_ASSERT( glDepthMask( GL_FALSE ) ); GL_ASSERT( glDepthMask( GL_FALSE ) );
GL_ASSERT( glDepthFunc( GL_LESS ) ); GL_ASSERT( glDepthFunc( GL_LESS ) );
glDrawBuffers( 1, buffers );
for ( const auto& ro : *m_objectsToRender ) for ( const auto& ro : *m_objectsToRender )
{ {
ro->render( {}, viewParams ); ro->render( {}, viewParams );
......
...@@ -5,50 +5,116 @@ ...@@ -5,50 +5,116 @@
using namespace Ra::Core::Utils; // log using namespace Ra::Core::Utils; // log
//#endif //#endif
#include <Engine/Data/DisplayableObject.hpp>
#include <Engine/Data/Material.hpp> #include <Engine/Data/Material.hpp>
#include <Engine/Data/ShaderConfigFactory.hpp> #include <Engine/Data/ShaderConfigFactory.hpp>
#include <Engine/Data/ShaderProgramManager.hpp> #include <Engine/Data/ShaderProgramManager.hpp>
#include <Engine/Data/Texture.hpp> #include <Engine/Data/Texture.hpp>
#include <Engine/Data/ViewingParameters.hpp>
#include <Engine/Rendering/RenderObject.hpp> #include <Engine/Rendering/RenderObject.hpp>
#include <globjects/Framebuffer.h> #include <globjects/Framebuffer.h>
namespace RadiumNBR { namespace RadiumNBR {
using namespace gl; using namespace gl;
static const GLenum buffers[] = {GL_COLOR_ATTACHMENT0};
UIPass::UIPass( const std::vector<RenderObjectPtr>* objectsToRender, #define UI_PASS_ID 31
const Ra::Core::Utils::Index& idx ) : UIPass::UIPass( const std::vector<RenderObjectPtr>* objectsToRender) :
RenderPass( "User Interface pass", idx, objectsToRender ) {} RenderPass( "User Interface pass", UI_PASS_ID, objectsToRender ) {}
UIPass::~UIPass() = default; UIPass::~UIPass() = default;
bool UIPass::buildRenderTechnique( const Ra::Engine::Rendering::RenderObject* ro, bool UIPass::buildRenderTechnique( const Ra::Engine::Rendering::RenderObject* ro,
Ra::Engine::Rendering::RenderTechnique& rt ) const { Ra::Engine::Rendering::RenderTechnique& rt ) const {
return false; // This method is never called for UiObjects.
// Rendering use the Default Radium pass
return true;
} }
bool UIPass::initializePass( size_t width, bool UIPass::initializePass( size_t width,
size_t height, size_t height,
Ra::Engine::Data::ShaderProgramManager* shaderMngr ) { Ra::Engine::Data::ShaderProgramManager* shaderMngr ) {
return false; m_shaderMngr = shaderMngr;
m_fbo = std::make_unique<globjects::Framebuffer>();
return true;
} }
bool UIPass::update() { bool UIPass::update() {
return false; return false;
} }
void UIPass::resize( size_t width, size_t height ) {} void UIPass::resize( size_t width, size_t height ) {
m_fbo->bind();
m_fbo->attachTexture( GL_DEPTH_ATTACHMENT, m_importedTextures["Ui::Depth"]->texture() );
// no need to resize the output texture, it belongs to the Ra::Engine::Rendering::Renderer and
// is already resized
m_fbo->attachTexture( GL_COLOR_ATTACHMENT0, m_outputTexture->texture() );
#ifdef PASSES_LOG
if ( m_fbo->checkStatus() != GL_FRAMEBUFFER_COMPLETE )
{ LOG( logERROR ) << "FBO Error (EmissivityPass::resize): " << m_fbo->checkStatus(); }
#endif
// finished with fbo, undbind to bind default
globjects::Framebuffer::unbind();
}
void UIPass::execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const { void UIPass::execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const {
/*
LOG( Ra::Core::Utils::logINFO ) LOG( Ra::Core::Utils::logINFO )
<< " requested to render " << m_objectsToRender->size() << " UI objects"; << " requested to render " << m_objectsToRender->size() << " UI objects";
*/
m_fbo->bind();
glDrawBuffers( 1, buffers );
GL_ASSERT( glDepthMask( GL_TRUE ) );
GL_ASSERT( glEnable( GL_DEPTH_TEST ) );
GL_ASSERT( glDepthFunc( GL_LESS ) );
GL_ASSERT( glClear( GL_DEPTH_BUFFER_BIT ) );
for ( const auto& ro : *m_objectsToRender )
{
if ( ro->isVisible() )
{
auto shader = ro->getRenderTechnique()->getShader();
// bind data
shader->bind();
Ra::Core::Matrix4 M = ro->getTransformAsMatrix();
Ra::Core::Matrix4 MV = viewParams.viewMatrix * M;
Ra::Core::Vector3 V = MV.block<3, 1>( 0, 3 );
Scalar d = V.norm();
Ra::Core::Matrix4 S = Ra::Core::Matrix4::Identity();
S.coeffRef( 0, 0 ) = S.coeffRef( 1, 1 ) = S.coeffRef( 2, 2 ) = d;
M = M * S;
shader->setUniform( "transform.proj", viewParams.projMatrix );
shader->setUniform( "transform.view", viewParams.viewMatrix );
shader->setUniform( "transform.model", M );
auto shaderParameter = ro->getRenderTechnique()->getParametersProvider();
if ( shaderParameter != nullptr ) shaderParameter->getParameters().bind( shader );
// render
ro->getMesh()->render( shader );
}
}
// DebugRender::getInstance()->render( renderData.viewMatrix, renderData.projMatrix );
m_fbo->unbind();
} }
/// Add the output colorBuffer /// Add the output colorBuffer
void UIPass::setOutput( const SharedTextures& colorBuffer ) {} void UIPass::setOutput( const Ra::Engine::Data::Texture* colorBuffer ) {
m_outputTexture = colorBuffer;
}
/// These inputs must be computed before executing this pass /// These inputs must be computed before executing this pass
/// depth buffer ? // TODO verify we need this /// depth buffer ? // TODO verify we need this
void UIPass::setInputs( const SharedTextures& depthBuffer ) {} void UIPass::setInputs( const SharedTextures& depthBuffer ) {
addImportedTextures( {"Ui::Depth", depthBuffer.second} );
}
} // namespace RadiumNBR } // namespace RadiumNBR
...@@ -16,8 +16,7 @@ namespace RadiumNBR { ...@@ -16,8 +16,7 @@ namespace RadiumNBR {
class UIPass : public RenderPass class UIPass : public RenderPass
{ {
public: public:
UIPass( const std::vector<RenderObjectPtr>* objectsToRender, UIPass( const std::vector<RenderObjectPtr>* objectsToRender);
const Ra::Core::Utils::Index& idx );
~UIPass() override; ~UIPass() override;
bool buildRenderTechnique( const Ra::Engine::Rendering::RenderObject* ro, bool buildRenderTechnique( const Ra::Engine::Rendering::RenderObject* ro,
...@@ -30,7 +29,7 @@ class UIPass : public RenderPass ...@@ -30,7 +29,7 @@ class UIPass : public RenderPass
void execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const override; void execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const override;
/// Add the output colorBuffer /// Add the output colorBuffer
void setOutput( const SharedTextures& colorBuffer ); void setOutput( const Ra::Engine::Data::Texture* colorBuffer );
/// These inputs must be computed before executing this pass /// These inputs must be computed before executing this pass
/// depth buffer ? // TODO verify we need this /// depth buffer ? // TODO verify we need this
...@@ -44,6 +43,6 @@ class UIPass : public RenderPass ...@@ -44,6 +43,6 @@ class UIPass : public RenderPass
Ra::Engine::Data::ShaderProgramManager* m_shaderMngr{nullptr}; Ra::Engine::Data::ShaderProgramManager* m_shaderMngr{nullptr};
/// The color texture for output.Stored here for easy access. /// The color texture for output.Stored here for easy access.
SharedTextures m_outputTexture; const Ra::Engine::Data::Texture* m_outputTexture;
}; };
} // namespace RadiumNBR } // namespace RadiumNBR
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment