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.
72 lines
No EOL
1.2 KiB
C++
72 lines
No EOL
1.2 KiB
C++
|
|
#ifndef SPECTRE_BATCH_RENDERER2D_H
|
|
#define SPECTRE_BATCH_RENDERER2D_H
|
|
|
|
#include "Renderer2D.h"
|
|
#include <Spectre/Scene/Camera2D.h>
|
|
|
|
#include <Spectre/Graphics/RenderState.h>
|
|
#include <Spectre/Graphics/Vertex2D.h>
|
|
#include <Spectre/Math/Matrix4.h>
|
|
#include <vector>
|
|
|
|
class ShaderProgram;
|
|
|
|
class Texture;
|
|
|
|
class BatchRenderer2D : public Renderer2D
|
|
{
|
|
public :
|
|
|
|
BatchRenderer2D();
|
|
~BatchRenderer2D();
|
|
|
|
void setBatchSize(unsigned short value);
|
|
|
|
void begin();
|
|
|
|
void end();
|
|
|
|
void submit(const Renderable2D& renderable);
|
|
|
|
// Drawing
|
|
virtual void draw(const Renderable2D* renderable);
|
|
|
|
void render();
|
|
|
|
protected :
|
|
|
|
struct Batch
|
|
{
|
|
RenderType type;
|
|
const Texture* texture;
|
|
unsigned int count;
|
|
unsigned int offset;
|
|
};
|
|
|
|
typedef std::vector<Batch> BatchQueue;
|
|
|
|
void prepareQueue();
|
|
|
|
unsigned int addRenderable(Vertex2D* buffer, const Renderable2D* renderable);
|
|
|
|
void uploadBatch(const Batch& batch);
|
|
|
|
void drawBatch(Batch& batch);
|
|
|
|
protected :
|
|
|
|
std::vector<const Renderable2D*> m_queue;
|
|
|
|
unsigned int m_IBO;
|
|
unsigned int m_VBO;
|
|
|
|
RenderState m_state;
|
|
|
|
unsigned short m_size;
|
|
|
|
ShaderProgram m_textShader;
|
|
ShaderProgram m_spriteShader;
|
|
};
|
|
|
|
#endif /* SPECTRE_BATCH_RENDERER2D_H */ |