CG-Project2
Loading...
Searching...
No Matches
BasicScene Class Reference

This class is used to manage a scene with meshes that will be rendered. It's implemented using Singleton. More...

#include <EcsScene.hpp>

Public Member Functions

void init (const Shared< ogl::Camera > &mainCamera)
 Initialize the current scene by setting the given world camera.
Shared< ogl::CameragetCamera () const
 Retrieves the world camera shared pointer.
void addEntity (Shared< ogl::ShaderProgram > &shader, const unsigned int &ett)
 Adds an entity to the scene that will be rendered using the corresponding shader program.
void removeEntity (Shared< ogl::ShaderProgram > &shader, const unsigned int &ett)
 Removes the given entity from the scene with the corresponding shader, to optimize entity search process.
void removeEntity (const unsigned int &ett)
 Removes the given entity from the scene without knowing the corresponding shader.
std::map< Shared< ogl::ShaderProgram >, std::vector< unsigned int > > getShaderEntityMap () const
 Returns the scene map with key ogl::ShaderProgram shared pointer and a vector of entity ids (Shared<ogl::Program, std::vector<unsigned int>).
 BasicScene (BasicScene &other)=delete
void operator= (const BasicScene &other)=delete

Static Public Member Functions

static Shared< BasicSceneinstance ()
 Retrieves the instance of the BasicScene. If it's not instanced, it will be instanced automatically.

Detailed Description

This class is used to manage a scene with meshes that will be rendered. It's implemented using Singleton.

Member Function Documentation

◆ addEntity()

void BasicScene::addEntity ( Shared< ogl::ShaderProgram > & shader,
const unsigned int & ett )

Adds an entity to the scene that will be rendered using the corresponding shader program.

This method will store in a map of (ogl::ShaderProgram, std::vector<unsigned int>) the shader and the entity id. This allow the systems::render::renderAllMesh() method to call ogl::ShaderProgram::use() and then render all the meshes that uses that program. This way minimizes the number of calls to enable a shader program at each frame.

Parameters
shadera ogl::ShaderProgram shared pointer
ettan unsigned int entity id

◆ getCamera()

Shared< ogl::Camera > BasicScene::getCamera ( ) const
inline

Retrieves the world camera shared pointer.

Returns
the world ogl::Camera shared pointer

◆ getShaderEntityMap()

std::map< Shared< ogl::ShaderProgram >, std::vector< unsigned int > > BasicScene::getShaderEntityMap ( ) const
inline

Returns the scene map with key ogl::ShaderProgram shared pointer and a vector of entity ids (Shared<ogl::Program, std::vector<unsigned int>).

Returns
a map containing all the entities for each shader program

◆ init()

void BasicScene::init ( const Shared< ogl::Camera > & mainCamera)
inline

Initialize the current scene by setting the given world camera.

The camera will be used to send view and projection data to shaders.

Parameters
mainCamerathe world camera pointer

◆ instance()

Shared< BasicScene > BasicScene::instance ( )
inlinestatic

Retrieves the instance of the BasicScene. If it's not instanced, it will be instanced automatically.

Returns
a Shared<BasicScene> object

◆ removeEntity() [1/2]

void BasicScene::removeEntity ( const unsigned int & ett)

Removes the given entity from the scene without knowing the corresponding shader.

It iterate through all keys and find the entity, if it's in the map it will be erased.

Parameters
ettentity id

◆ removeEntity() [2/2]

void BasicScene::removeEntity ( Shared< ogl::ShaderProgram > & shader,
const unsigned int & ett )

Removes the given entity from the scene with the corresponding shader, to optimize entity search process.

@params shader a ogl::ShaderProgram shared pointer @params ett entity id


The documentation for this class was generated from the following files: