diff --git a/include/Spectre/Graphics/BatchRenderer2D.h b/include/Spectre/Graphics/BatchRenderer2D.h index 637a23f..ad49098 100644 --- a/include/Spectre/Graphics/BatchRenderer2D.h +++ b/include/Spectre/Graphics/BatchRenderer2D.h @@ -29,6 +29,9 @@ public : void submit(const Renderable2D& renderable); + // Drawing + virtual void draw(const Renderable2D* renderable); + void render(); protected : diff --git a/include/Spectre/Graphics/Renderable.h b/include/Spectre/Graphics/Renderable.h index 386c9e2..31425d7 100644 --- a/include/Spectre/Graphics/Renderable.h +++ b/include/Spectre/Graphics/Renderable.h @@ -8,6 +8,7 @@ #include #include +class Renderer2D; class ShaderProgram; class Texture; @@ -31,6 +32,8 @@ public : virtual const Texture* getTexture() const { return NULL; }; virtual const RenderType getRenderType() const = 0; + + virtual void render(Renderer2D& renderer) const = 0; }; #endif /* SPECTRE_GRAPHCIS_RENDERABLE_H */ diff --git a/include/Spectre/Graphics/Renderer2D.h b/include/Spectre/Graphics/Renderer2D.h index 2d1db4a..9690005 100644 --- a/include/Spectre/Graphics/Renderer2D.h +++ b/include/Spectre/Graphics/Renderer2D.h @@ -18,6 +18,9 @@ public : virtual void submit(const Renderable2D& renderable) = 0; + // Drawing. + virtual void draw(const Renderable2D* renderable) = 0; + virtual void render() = 0; protected : diff --git a/include/Spectre/Graphics/Sprite.h b/include/Spectre/Graphics/Sprite.h index f4c25dc..a786ec1 100644 --- a/include/Spectre/Graphics/Sprite.h +++ b/include/Spectre/Graphics/Sprite.h @@ -33,6 +33,8 @@ public : virtual const RenderType getRenderType() const { return RenderType_Scene; }; + virtual void render(Renderer2D& renderer) const; + protected : void updateGeometry(); diff --git a/include/Spectre/Graphics/Text.h b/include/Spectre/Graphics/Text.h index b02202f..bed3226 100644 --- a/include/Spectre/Graphics/Text.h +++ b/include/Spectre/Graphics/Text.h @@ -60,6 +60,8 @@ public : virtual const Texture* getTexture() const; + void render(Renderer2D& renderer) const; + private : void updateGeometry() const; diff --git a/source/Graphics/BatchRenderer2D.cpp b/source/Graphics/BatchRenderer2D.cpp index 7cf81f6..9c81a29 100644 --- a/source/Graphics/BatchRenderer2D.cpp +++ b/source/Graphics/BatchRenderer2D.cpp @@ -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); diff --git a/source/Graphics/Sprite.cpp b/source/Graphics/Sprite.cpp index 8ee6851..905dc49 100644 --- a/source/Graphics/Sprite.cpp +++ b/source/Graphics/Sprite.cpp @@ -1,4 +1,5 @@ +#include #include #include @@ -108,4 +109,9 @@ const std::vector& Sprite::getIndices() const void Sprite::updateGeometry() { +} + +void Sprite::render(Renderer2D& renderer) const +{ + renderer.draw(this); } \ No newline at end of file diff --git a/source/Graphics/Text.cpp b/source/Graphics/Text.cpp index e1ab6cd..7160c8e 100644 --- a/source/Graphics/Text.cpp +++ b/source/Graphics/Text.cpp @@ -1,5 +1,6 @@ #include +#include #include Text::Text() : @@ -167,4 +168,9 @@ void Text::updateGeometry() const int x = 0; +} + +void Text::render(Renderer2D& renderer) const +{ + renderer.draw(this); } \ No newline at end of file