Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 1000
- namespace MLRenderer
- {
- namespace MLBatchItem
- {
- typedef struct Vertex
- {
- Vector3f VPos;
- Vector2f UV;
- float padding[3];
- }Vertex;
- //batch item
- typedef struct batchInfo
- {
- Vertex Verts[ML_MAX_SPRITES * 4];
- batchInfo() : pointcount(0), spriteCount(0){}
- void addPoint(Vector3f Vpos, Vector2f uv)
- {
- Verts[pointcount].VPos = Vpos;
- Verts[pointcount].UV = uv;
- pointcount++;
- }
- int spriteCount;
- int pointcount;
- }batchInfo;
- }
- class MLSpriteBatch
- {
- public:
- MLSpriteBatch(int bufferSize);
- //constructor for custom shader
- MLSpriteBatch(MLShader* inShader, int buffersize);
- 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;
- GLuint m_VertBuffer;
- const int m_spriteSize;
- const int m_BufferSize;
- int m_BufferOffset;
- int totalSpriteCount;
- MLShader* m_shader;
- //stores all the batch items
- typedef std::map<GLuint, MLBatchItem::batchInfo*> BatchMap;
- BatchMap m_BatchItems;
- };
- }
- #endif //MLSPRITEBATCH_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement