Renderer2D: reverse the relationship between Renderer2D and Renderable.
Pass Renderer2D to Renderable and have each subclass of Renderable decide what the Renderer should do (like drawText(), drawRect() etc). This makes the Renderable more flexible. right now, each renderable has a texture, vertices and indices. but what if some renderables does not use textures? or more than one? What if some renderables are just a group of other renderables? (Scene Graph's). If we instead just make Renderables implement render(Renderer2D& r) interface. we can make each renderable pass the data it holds to the renderer without a hard defined interface.
This commit is contained in:
parent
b2dbee33fb
commit
84ffd0189e
8 changed files with 32 additions and 2 deletions
|
|
@ -104,7 +104,12 @@ void BatchRenderer2D::end()
|
|||
|
||||
void BatchRenderer2D::submit(const Renderable2D& renderable)
|
||||
{
|
||||
m_queue.push_back(&renderable);
|
||||
renderable.render(*this);
|
||||
}
|
||||
|
||||
void BatchRenderer2D::draw(const Renderable2D* renderable)
|
||||
{
|
||||
m_queue.push_back(renderable);
|
||||
}
|
||||
|
||||
void BatchRenderer2D::render()
|
||||
|
|
@ -126,7 +131,7 @@ void BatchRenderer2D::render()
|
|||
// Setup position.
|
||||
glEnableVertexAttribArray(VertexAttribPosition);
|
||||
glVertexAttribPointer(VertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*) 0);
|
||||
|
||||
|
||||
|
||||
// Setup color
|
||||
glEnableVertexAttribArray(VertexAttribColor0);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
#include <Spectre/Graphics/Renderer2D.h>
|
||||
#include <Spectre/Graphics/Texture.h>
|
||||
#include <Spectre/Graphics/Sprite.h>
|
||||
|
||||
|
|
@ -108,4 +109,9 @@ const std::vector<unsigned short>& Sprite::getIndices() const
|
|||
|
||||
void Sprite::updateGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
void Sprite::render(Renderer2D& renderer) const
|
||||
{
|
||||
renderer.draw(this);
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include <Spectre/Math/Vector4.h>
|
||||
#include <Spectre/Graphics/Renderer2D.h>
|
||||
#include <Spectre/Graphics/Text.h>
|
||||
|
||||
Text::Text() :
|
||||
|
|
@ -167,4 +168,9 @@ void Text::updateGeometry() const
|
|||
int x = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Text::render(Renderer2D& renderer) const
|
||||
{
|
||||
renderer.draw(this);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue