Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::Rectangle2D Class Reference

2D drawable component for rendering rectangle. More...

#include <rectangle_2d.hpp>

Inherits rendering_engine::Drawable2D.

Classes

struct  Properties
 

Public Member Functions

 Rectangle2D (RenderResourceContext renderContext, Scene &scene, Properties properties)
 Constructs the Rectangle2D with a render context. More...
 
void Initialize () override
 Initializes render resource pointers (material, mesh, etc.). Must be called after setting material and mesh names. More...
 
void Update (float deltaTime) override
 Updates logic (animation, movement, etc.) for this drawable. More...
 
void Draw (const Camera2D &camera) override
 Submits this quad to the renderer for drawing. More...
 
void SetColor (glm::vec4 color)
 Sets color. More...
 
 Rectangle2D (const Rectangle2D &rhs)=delete
 
Rectangle2Doperator= (const Rectangle2D &rhs)=delete
 
- Public Member Functions inherited from rendering_engine::Drawable2D
 Drawable2D (RenderResourceContext renderContext, Scene &scene)
 Constructs the Drawable2D with a resource context. More...
 
void Initialize () override
 Initializes render resources. More...
 
void Update (float deltaTime) override
 Updates model matrix (and any other logic). More...
 
virtual void Draw (const Camera2D &camera)=0
 Submits this quad to the renderer for drawing. More...
 
void SetPosition (const glm::vec2 &position)
 Sets the quad position in 2D space. More...
 
void SetRotation (float angleDegrees)
 Sets the quad rotation. More...
 
void SetScale (const glm::vec2 &scale)
 Sets the quad scale along each axis. More...
 
const glm::vec2 & GetPosition () const
 Gets the quad position. More...
 
float GetRotation () const
 Gets the quad rotation angle (degrees). More...
 
const glm::vec2 & GetScale () const
 Gets the quad scale. More...
 
SceneComponent2DGetTransform ()
 Access to the underlying SceneComponent2D (transform). More...
 
const SceneComponent2DGetTransform () const
 
void Destroy () override
 Requests destruction of this drawable. More...
 
- Public Member Functions inherited from rendering_engine::DrawableComponent
 DrawableComponent (RenderResourceContext renderContext, Scene &scene)
 Constructs the DrawableComponent with a resource context. More...
 
virtual ~DrawableComponent ()=default
 Virtual destructor. More...
 
virtual void Initialize ()
 Initializes render resource pointers (material, mesh, etc.). Must be called after setting material and mesh names. More...
 
virtual void Update (float deltaTime)=0
 Updates logic (animation, movement, etc.) for this drawable. More...
 
virtual void Shutdown ()
 Releases all render resources owned by this drawable. More...
 
virtual void Destroy ()
 Requests destruction of this drawable. More...
 
void UpdateOnTick (bool in)
 
 DrawableComponent (const DrawableComponent &)=delete
 
DrawableComponentoperator= (const DrawableComponent &)=delete
 

Protected Attributes

Properties mProperties
 
- Protected Attributes inherited from rendering_engine::Drawable2D
SceneComponent2D mSceneComponent
 
- Protected Attributes inherited from rendering_engine::DrawableComponent
RenderResourceContext mRenderContext
 
ScenemScene
 
std::vector< RenderBatchmRenderBatches
 
bool bUpdateOnTick
 

Additional Inherited Members

- Protected Member Functions inherited from rendering_engine::DrawableComponent
void AddRenderBatch (std::string meshName, std::string materialName)
 

Detailed Description

2D drawable component for rendering rectangle.

Note
Not copyable or assignable.
See also
Sprite2D, Quad2D, Drawable2D, DrawableComponent, SceneComponent2D, Camera2D

Definition at line 21 of file rectangle_2d.hpp.

Constructor & Destructor Documentation

◆ Rectangle2D() [1/2]

rendering_engine::Rectangle2D::Rectangle2D ( RenderResourceContext  renderContext,
Scene scene,
Properties  properties 
)

Constructs the Rectangle2D with a render context.

Parameters
renderContextResource context.

Definition at line 7 of file rectangle_2D.cpp.

8 :
9 Drawable2D(renderContext, scene),
10 mProperties(properties)
11{}
Drawable2D(RenderResourceContext renderContext, Scene &scene)
Constructs the Drawable2D with a resource context.
Definition: drawable_2d.cpp:7

◆ Rectangle2D() [2/2]

rendering_engine::Rectangle2D::Rectangle2D ( const Rectangle2D rhs)
delete

Member Function Documentation

◆ Draw()

void rendering_engine::Rectangle2D::Draw ( const Camera2D camera)
overridevirtual

Submits this quad to the renderer for drawing.

Implements rendering_engine::Drawable2D.

Definition at line 31 of file rectangle_2D.cpp.

32{
33 Transformations2D transformations;
34 transformations.model = GetTransform().GetWorldMatrix();
35 transformations.view = camera.GetWorldView();
36 transformations.proj = camera.GetProjectionMatrix();
37
38 for (auto& renderBatch : mRenderBatches)
39 {
40 renderBatch.renderResources->SubmitResources(transformations, renderBatch.materialParameters);
41 }
42}
SceneComponent2D & GetTransform()
Access to the underlying SceneComponent2D (transform).
Definition: drawable_2d.cpp:55
std::vector< RenderBatch > mRenderBatches
const glm::mat4 & GetWorldMatrix()
Returns the world transformation matrix.

◆ Initialize()

void rendering_engine::Rectangle2D::Initialize ( )
overridevirtual

Initializes render resource pointers (material, mesh, etc.). Must be called after setting material and mesh names.

Reimplemented from rendering_engine::Drawable2D.

Definition at line 13 of file rectangle_2D.cpp.

14{
15 const std::string meshName = "Quad2D";
16 const std::string materialName = "Rectangle2D";
17
18 AddRenderBatch(meshName, materialName);
19
21
24}
void Initialize() override
Initializes render resources.
Definition: drawable_2d.cpp:12
void SetScale(const glm::vec2 &scale)
Sets the quad scale along each axis.
Definition: drawable_2d.cpp:35
void AddRenderBatch(std::string meshName, std::string materialName)
void SetColor(glm::vec4 color)
Sets color.

◆ operator=()

Rectangle2D & rendering_engine::Rectangle2D::operator= ( const Rectangle2D rhs)
delete

◆ SetColor()

void rendering_engine::Rectangle2D::SetColor ( glm::vec4  color)

Sets color.

Parameters
colorRGBA [0.0f - 1.0f].

Definition at line 44 of file rectangle_2D.cpp.

45{
46 for (auto& renderBatch : mRenderBatches)
47 {
48 renderBatch.materialParameters.SetMaterialVec4("Color", color);
49 }
50}

◆ Update()

void rendering_engine::Rectangle2D::Update ( float  deltaTime)
overridevirtual

Updates logic (animation, movement, etc.) for this drawable.

Parameters
deltaTimeTime step (seconds).

Reimplemented from rendering_engine::Drawable2D.

Definition at line 26 of file rectangle_2D.cpp.

27{
28 Drawable2D::Update(deltaTime);
29}
void Update(float deltaTime) override
Updates model matrix (and any other logic).
Definition: drawable_2d.cpp:17

Member Data Documentation

◆ mProperties

Properties rendering_engine::Rectangle2D::mProperties
protected

Definition at line 63 of file rectangle_2d.hpp.


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