CORGI
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
corgi::component_library::RenderMeshComponent Class Reference

A Component that handles the rendering of each Entities mesh that is registered with this Component. More...

#include <rendermesh.h>

Inherits corgi::Component< RenderMeshData >.

Detailed Description

A Component that handles the rendering of each Entities mesh that is registered with this Component.

Public Member Functions

 RenderMeshComponent ()
 Default constructor for RenderMeshComponent.
 
virtual ~RenderMeshComponent ()
 Destructor for RenderMeshComponent.
 
virtual void Init ()
 Initialize the RenderMeshComponent with the AssetManager from the EntityManager.
 
virtual void AddFromRawData (EntityRef &entity, const void *raw_data)
 Deserialize a flat binary buffer to create and populate an Entity from raw data. More...
 
virtual RawDataUniquePtr ExportRawData (const EntityRef &entity) const
 Serializes a RenderMeshComponent's data for a given Entity. More...
 
virtual void InitEntity (EntityRef &)
 Initialize an Entity by also adding it to the TransformComponent.
 
virtual void UpdateAllEntities (WorldTime)
 Nothing happens per frame for these Entities.
 
void RenderPrep (const CameraInterface &camera)
 Prepares to do rendering. More...
 
void RenderPass (int pass_id, const CameraInterface &camera, fplbase::Renderer &renderer)
 Renders all Entities that are marked as being part of a given render pass to the current output buffer. More...
 
void RenderPass (int pass_id, const CameraInterface &camera, fplbase::Renderer &renderer, size_t shader_index)
 Renders all Entities that are marked as being part of a given render pass to the current output buffer. More...
 
void RenderAllEntities (fplbase::Renderer &renderer, const CameraInterface &camera)
 Goes through and renders every Entity that is visible from the camera, in pass order. More...
 
void SetVisibilityRecursively (const EntityRef &entity, bool visible)
 Recursively sets the visibility of the Entity and all of its children. More...
 
mathfu::vec3 light_position ()
 Get the light position uniform. More...
 
void set_light_position (const mathfu::vec3 &light_position)
 Set the light position uniform. More...
 
void SetCullDistance (float distance)
 Set the culling distance. More...
 
float culling_distance_squared () const
 Get the culling distance squared. More...
 
void set_culling_distance_squared (float culling_distance_squared)
 Set the square of the culling distance. More...
 
- Public Member Functions inherited from corgi::Component< RenderMeshData >
 Component ()
 Construct a Component without an EntityManager.
 
virtual ~Component ()
 Destructor for a Component.
 
virtual void AddEntityGenerically (EntityRef &entity)
 Provides an alternate way to add Entities if you do not care about the returned data structure, and if you do not feel like casting the BaseComponent into something more specific. More...
 
RenderMeshData * AddEntity (EntityRef &entity, AllocationLocation alloc_location)
 Adds an Entity to the list that this Component is tracking. More...
 
RenderMeshData * AddEntity (EntityRef &entity)
 Adds an Entity to the list that this Component is tracking. More...
 
virtual void RemoveEntity (EntityRef &entity)
 Removes an Entity from the list of Entities. More...
 
virtual EntityIterator RemoveEntity (EntityIterator iter)
 Removes an Entity from the list of Entities. More...
 
virtual EntityIterator begin ()
 Gets an iterator that will iterate over every Entity associated with the Component, starting from the beginning. More...
 
virtual EntityIterator end ()
 Gets an iterator that points to the end of the list of all entites in the Component. More...
 
virtual bool HasDataForEntity (const EntityRef &entity)
 Checks if this component contains any data associated with the supplied entity.
 
virtual void * GetComponentDataAsVoid (const EntityRef &entity)
 Gets the data for a given Entity as a void pointer. More...
 
virtual const void * GetComponentDataAsVoid (const EntityRef &entity) const
 Gets the data for a given Entity as a const void pointer. More...
 
RenderMeshData * GetComponentData (size_t data_index)
 Gets the Component data stored at a given index. More...
 
RenderMeshData * GetComponentData (const EntityRef &entity)
 Gets the data for a given Entity. More...
 
const RenderMeshData * GetComponentData (size_t data_index) const
 Gets the Component data stored at a given index. More...
 
const RenderMeshData * GetComponentData (const EntityRef &entity) const
 Gets the data for a given Entity. More...
 
virtual void ClearComponentData ()
 Clears all tracked Component data.
 
ComponentDataType * Data (const EntityRef &entity)
 A utility function for retrieving the Component data for an Entity from a specific Component. More...
 
ComponentDataType * Data (const EntityRef &entity) const
 A utility function for retrieving the Component data for an Entity from a specific Component. More...
 
bool IsRegisteredWithComponent (const EntityRef &entity)
 A utility function for checking if an entity is registered with a particular component. More...
 
ComponentDataType * GetComponent ()
 A utility function for retrieving a reference to a specific Component object, by type. More...
 
virtual void Cleanup ()
 Override this function with any code that executes when this Component is removed from the EntityManager. (i.e. Usually when the game/state is over and everything is shutting down.)
 
virtual void CleanupEntity (EntityRef &)
 Override this function with any code that needs to be executed when an Entity is removed from this Component.
 
virtual void SetEntityManager (EntityManager *entity_manager)
 Set the EntityManager for this Component. More...
 
virtual void SetComponentIdOnDataType (ComponentId id)
 Sets the Component ID on the data type. More...
 
- Public Member Functions inherited from corgi::ComponentInterface
virtual ~ComponentInterface ()
 A destructor for the Component interface.
 

Static Public Attributes

static const int kDefaultCullDist = 80
 The default distance to start culling.
 

Additional Inherited Members

- Public Types inherited from corgi::Component< RenderMeshData >
typedef VectorPool
< ComponentData >::Iterator 
EntityIterator
 An iterator to iterate through all of the Entities in the Component.
 
typedef RenderMeshData value_type
 The templated data type stored by this Component.
 
- Public Types inherited from corgi::ComponentInterface
typedef std::unique_ptr
< uint8_t, std::function< void(uint8_t *)> > 
RawDataUniquePtr
 A pointer type for exported raw data.
 
- Static Public Member Functions inherited from corgi::Component< RenderMeshData >
static ComponentId GetComponentId ()
 Get the ID for this Component. More...
 
- Protected Member Functions inherited from corgi::Component< RenderMeshData >
size_t GetComponentDataIndex (const EntityRef &entity) const
 Get the index of the Component data for a given Entity. More...
 
- Protected Attributes inherited from corgi::Component< RenderMeshData >
VectorPool< ComponentData > component_data_
 Storage for all of the data for the Component.
 
EntityManagerentity_manager_
 A pointer to the EntityManager for this Component. This is the main point of contact for Components that need to talk to other things.
 
std::unordered_map
< EntityIdType, ComponentIndex
component_index_lookup_
 A map, for translating unique entity IDs into vectorpool indexes.
 

Member Function Documentation

virtual void corgi::component_library::RenderMeshComponent::AddFromRawData ( EntityRef entity,
const void *  raw_data 
)
virtual

Deserialize a flat binary buffer to create and populate an Entity from raw data.

Parameters
[in,out]entityAn EntityRef reference that points to the Entity that is being added from the raw data.
[in]raw_dataA void pointer to the raw FlatBuffer data.

Implements corgi::ComponentInterface.

float corgi::component_library::RenderMeshComponent::culling_distance_squared ( ) const
inline

Get the culling distance squared.

Returns
Returns the square of the culling distance.
virtual RawDataUniquePtr corgi::component_library::RenderMeshComponent::ExportRawData ( const EntityRef entity) const
virtual

Serializes a RenderMeshComponent's data for a given Entity.

Parameters
[in]entityAn EntityRef reference that points to the Entity whose corresponding RenderMeshData will be serialized.
Returns
Returns a RawDataUniquePtr to the start of the raw data in a flat binary buffer.

Reimplemented from corgi::Component< RenderMeshData >.

mathfu::vec3 corgi::component_library::RenderMeshComponent::light_position ( )
inline

Get the light position uniform.

Note
This is a special uniform that is sent to all shaders without having to declare it explicitly in the shader.
Returns
Returns the light position uniform as a mathfu::vec3.
void corgi::component_library::RenderMeshComponent::RenderAllEntities ( fplbase::Renderer &  renderer,
const CameraInterface camera 
)

Goes through and renders every Entity that is visible from the camera, in pass order.

It Is equivalent to iterating through all of the passes and calling RenderPass() on each one.

Warning
You must have called RenderPrep() first, in order to pre-populate the lists of things visible from the camera!
Parameters
[out]rendererA reference to the fplbase::Renderer to capture the output of the render pass.
[in]cameraA CameraInterface reference to the camera used to render within the field of view.
void corgi::component_library::RenderMeshComponent::RenderPass ( int  pass_id,
const CameraInterface camera,
fplbase::Renderer &  renderer 
)

Renders all Entities that are marked as being part of a given render pass to the current output buffer.

Parameters
[in]pass_idAn int used to identify and index the desired render pass.
[in]cameraA CameraInterface reference to the camera used to render within the field of view.
[out]rendererA reference to the fplbase::Renderer to capture the output of the render pass.
void corgi::component_library::RenderMeshComponent::RenderPass ( int  pass_id,
const CameraInterface camera,
fplbase::Renderer &  renderer,
size_t  shader_index 
)

Renders all Entities that are marked as being part of a given render pass to the current output buffer.

Parameters
[in]pass_idAn int used to identify and index the desired render pass.
[in]cameraA CameraInterface reference to the camera used to render within the field of view.
[out]rendererA reference to the fplbase::Renderer to capture the output of the render pass.
[in]shader_indexThe shader index for the fplbase::Shader to use as the mesh shader for this render pass.
void corgi::component_library::RenderMeshComponent::RenderPrep ( const CameraInterface camera)

Prepares to do rendering.

Note
Must be called before any RenderPass() calls.

Pre-generates the draw lists, sorted by z-depth, and applies frustrum culling. (So that RenderPass can just iterate through the list and draw everything easily.)

Parameters
[in]cameraA CameraInterface reference to the camera used to render within the field of view.
void corgi::component_library::RenderMeshComponent::set_culling_distance_squared ( float  culling_distance_squared)
inline

Set the square of the culling distance.

Parameters
[in]culling_distance_squaredA float representing the square of the culling distance that should be set.
void corgi::component_library::RenderMeshComponent::set_light_position ( const mathfu::vec3 &  light_position)
inline

Set the light position uniform.

Note
This is a special uniform that is sent to all shaders without having to declare it explicitly in the shader.
Parameters
[in]light_positionA const mathfu::vec3 reference to the uniform to set for the light position.
void corgi::component_library::RenderMeshComponent::SetCullDistance ( float  distance)
inline

Set the culling distance.

Parameters
[in]distanceA float representing the new culling distance to set.
void corgi::component_library::RenderMeshComponent::SetVisibilityRecursively ( const EntityRef entity,
bool  visible 
)

Recursively sets the visibility of the Entity and all of its children.

Parameters
[in]entityAn EntityRef reference to the Entity that should have itself and its children's visibility set.
[in]visibleA bool determining if the Entities should be rendered.

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