3 #include <Engine/RaEngine.hpp>
12 #include <Core/Utils/Color.hpp>
13 #include <Core/Utils/Timer.hpp>
14 #include <Engine/Data/DisplayableObject.hpp>
25 struct ViewingParameters;
27 class ShaderProgramManager;
38 class RenderObjectManager;
47 using RenderObjectPtr = std::shared_ptr<RenderObject>;
54 Core::Utils::TimePoint renderStart;
55 Core::Utils::TimePoint updateEnd;
56 Core::Utils::TimePoint feedRenderQueuesEnd;
57 Core::Utils::TimePoint mainRenderEnd;
58 Core::Utils::TimePoint postProcessEnd;
59 Core::Utils::TimePoint renderEnd;
86 Core::Vector2 m_screenCoords;
112 inline const std::vector<std::tuple<int, int, int>>& getIndices()
const;
115 inline void addIndex(
const std::tuple<int, int, int>& idx );
118 inline void reserve(
size_t s );
121 inline void removeDuplicatedIndices()
const;
126 inline void setRoIdx( Core::Utils::Index idx );
127 inline Core::Utils::Index getRoIdx()
const;
134 inline Scalar getDepth()
const;
135 inline void setDepth( Scalar depth );
141 Core::Utils::Index m_roIdx { Core::Utils::Index::Invalid() };
147 mutable std::vector<std::tuple<int, int, int>> m_indices;
166 inline const TimerData& getTimerData()
const;
177 inline void lockRendering();
182 inline void unlockRendering();
187 inline void toggleWireframe();
193 inline void enableWireframe(
bool enabled );
198 inline void toggleDrawDebug();
204 inline void enableDebugDraw(
bool enabled );
210 inline void enablePostProcess(
bool enabled );
237 void initialize( uint width, uint height );
248 void resize( uint width, uint height );
254 inline void addPickingRequest(
const PickingQuery& query );
262 inline const std::vector<PickingResult>& getPickingResults()
const;
270 inline const std::vector<PickingQuery>& getPickingQueries()
const;
272 inline void setMousePosition(
const Core::Vector2& pos );
274 inline void setBrushRadius( Scalar brushRadius );
277 bool hasLight()
const;
295 virtual void reloadShaders();
308 virtual void displayTexture(
const std::string& texName );
314 virtual std::vector<std::string> getAvailableTextures()
const;
334 int buildAllRenderTechniques()
const;
342 virtual std::unique_ptr<uchar[]> grabFrame(
size_t& w,
size_t& h )
const;
403 void saveExternalFBOInternal();
404 void restoreExternalFBOInternal();
414 void splitRQ(
const std::vector<RenderObjectPtr>& renderQueue,
415 std::array<std::vector<RenderObjectPtr>, 4>& renderQueuePicking );
417 const std::array<const Data::ShaderProgram*, 4>& pickingShaders,
418 const std::array<std::vector<RenderObjectPtr>, 4>& renderQueuePicking );
423 void drawScreenInternal();
426 void notifyRenderObjectsRenderingInternal();
442 RenderObjectManager* m_renderObjectManager {
nullptr };
457 bool m_renderQueuesUpToDate {
false };
459 std::vector<RenderObjectPtr> m_fancyRenderObjects;
460 std::vector<RenderObjectPtr> m_debugRenderObjects;
461 std::vector<RenderObjectPtr> m_xrayRenderObjects;
462 std::vector<RenderObjectPtr> m_uiRenderObjects;
465 std::unique_ptr<Data::Displayable> m_quadMesh;
467 bool m_drawDebug {
true };
468 bool m_wireframe {
false };
469 bool m_postProcessEnabled {
true };
483 std::mutex m_renderMutex;
486 Ra::Core::Vector2 m_mousePosition;
487 float m_brushRadius { 0 };
488 std::unique_ptr<globjects::Framebuffer> m_pickingFbo;
489 std::unique_ptr<Data::Texture> m_pickingTexture;
491 static const int NoPickingRenderMode = Data::Displayable::PickingRenderMode::NO_PICKING;
492 std::array<std::vector<RenderObjectPtr>, NoPickingRenderMode> m_fancyRenderObjectsPicking;
493 std::array<std::vector<RenderObjectPtr>, NoPickingRenderMode> m_debugRenderObjectsPicking;
494 std::array<std::vector<RenderObjectPtr>, NoPickingRenderMode> m_xrayRenderObjectsPicking;
495 std::array<std::vector<RenderObjectPtr>, NoPickingRenderMode> m_uiRenderObjectsPicking;
496 std::array<const Data::ShaderProgram*, NoPickingRenderMode> m_pickingShaders;
498 std::vector<PickingQuery> m_pickingQueries;
499 std::vector<PickingQuery> m_lastFramePickingQueries;
500 std::vector<PickingResult> m_pickingResults;
505 bool m_initialized {
false };
513 m_indices.push_back( idx );
517 m_indices.reserve( s );
521 std::sort( m_indices.begin(), m_indices.end() );
522 m_indices.erase( std::unique( m_indices.begin(), m_indices.end() ), m_indices.end() );
527 m_roIdx = Core::Utils::Index::Invalid();
531 inline void Renderer::PickingResult::setRoIdx( Core::Utils::Index idx ) {
535 inline Core::Utils::Index Renderer::PickingResult::getRoIdx()
const {
551 inline void Renderer::PickingResult::setDepth( Scalar depth ) {
564 m_renderMutex.lock();
568 m_renderMutex.unlock();
572 m_wireframe = !m_wireframe;
576 m_wireframe = enabled;
580 m_drawDebug = !m_drawDebug;
584 m_drawDebug = enabled;
588 m_postProcessEnabled = enabled;
592 m_pickingQueries.push_back( query );
596 return m_pickingResults;
600 return m_lastFramePickingQueries;
603 inline void Renderer::setMousePosition(
const Core::Vector2& pos ) {
604 m_mousePosition[0] = pos[0];
605 m_mousePosition[1] = m_height - pos[1];
608 inline void Renderer::setBrushRadius( Scalar brushRadius ) {
609 m_brushRadius = brushRadius;
613 m_backgroundColor = color;
617 return m_backgroundColor;
Result of a PickingQuery.
void addIndex(const std::tuple< int, int, int > &idx)
Add new ids to the result.
void clear()
Reset query to default.
void reserve(size_t s)
Reserve size of ids container.
const std::vector< std::tuple< int, int, int > > & getIndices() const
Read access to the collected ids.
void removeDuplicatedIndices() const
Remove duplicates in m_indices.
const TimerData & getTimerData() const
void addPickingRequest(const PickingQuery &query)
virtual std::string getRendererName() const =0
Get the name of the renderer, e.g to be displayed in the UI.
virtual void debugInternal(const Data::ViewingParameters &renderData)=0
Add the debug layer with useful informations.
void enableDebugDraw(bool enabled)
void enablePostProcess(bool enabled)
std::vector< Ra::Engine::Scene::LightManager * > m_lightmanagers
virtual void postProcessInternal(const Data::ViewingParameters &renderData)=0
Do all post processing stuff. If you override this method, be careful to fill.
Data::Texture * getDisplayTexture() const
virtual bool buildRenderTechnique(RenderObject *ro) const =0
std::unique_ptr< Data::Texture > m_fancyTexture
Final color texture : might be attached to the main framebuffer.
void setBackgroundColor(const Core::Utils::Color &color)
Update the background color (does not trigger a redraw)
Data::Texture * m_displayedTexture
The texture that will be displayed on screen. If no call to.
@ C_VERTEX
Picks all vertices of a mesh within a screen space circle.
@ C_TRIANGLE
Picks all triangles of a mesh within a screen space circle.
@ C_EDGE
Picks all edges of a mesh within a screen space circle.
@ TRIANGLE
Pick a triangle of a mesh.
@ EDGE
Pick an edge of a mesh.
@ VERTEX
Pick a vertex of a mesh.
virtual void initializeInternal()=0
initializeInternal Initialize the renderer dependant resources.
const std::vector< PickingResult > & getPickingResults() const
virtual void uiInternal(const Data::ViewingParameters &renderData)=0
Draw the UI data.
std::map< std::string, Data::Texture * > m_secondaryTextures
Textures exposed in the texture section box to be displayed.
std::unique_ptr< Data::Texture > m_depthTexture
Depth texture : might be attached to the main framebuffer.
virtual void updateStepInternal(const Data::ViewingParameters &renderData)=0
const std::vector< PickingQuery > & getPickingQueries() const
virtual void resizeInternal()=0
void enableWireframe(bool enabled)
virtual void renderInternal(const Data::ViewingParameters &renderData)=0
All the scene rendering magics basically happens here.
the set of viewing parameters extracted from the camera and given to the renderer