#ifndef MLSPRITEBATCH_H
#define MLSPRITEBATCH_H
#include "MLSprite.h"
#include "MLShader.h"
#include "general.h"
#include <map>
using MLRenderer::MLSprite;
using MLRenderer::MLShader;
using namespace MLMath::MLVector2;
using namespace MLMath::MLVector3;
//
#define ML_MAX_SPRITES 2000
namespace MLRenderer
{
namespace MLBatchItem
{
//batch item
typedef struct batchInfo
{
Vector3f VPos[ML_MAX_SPRITES * 4];
Vector2f UV[ML_MAX_SPRITES * 4];
batchInfo() : pointcount(0), spriteCount(0){}
void addPoint(Vector3f Vpos, Vector2f uv)
{
VPos[pointcount] = Vpos;
UV[pointcount] = uv;
pointcount++;
}
int spriteCount;
int pointcount;
}batchInfo;
}
class MLSpriteBatch
{
public:
MLSpriteBatch(void);
//constructor for custom shader
MLSpriteBatch(MLShader* inShader);
virtual ~MLSpriteBatch(void);
//begin function to be called first
void Begin(/*Settings*/bool Alpha = true);
//draw a sprite object
void Draw(MLSprite* Sprite);
//custom draw function
void Draw(GLuint Texture, Vector2f Pos, Vector2f Size);
//end batch and render everything
void End();
//set a custom shader
void setShader(MLShader* inShader);
//release the pointers and the shader
void release();
void releaseShader();
private:
//render the batch
void Render();
//initlaise the batch
void Initalise();
private:
bool m_beginCall;
//buffer objects
GLuint m_VposBuffer;
GLuint m_UVBuffer;
GLuint m_BatchVAO;
GLint* indicies;
GLsizei* Vcount;
int totalSpriteCount;
MLShader* m_shader;
//stores all the batch items
typedef std::map<GLuint, MLBatchItem::batchInfo*> BatchMap;
BatchMap m_BatchItems;
};
}
#endif //MLSPRITEBATCH_H