Advertisement
Dekowta

SpriteBatch.h

Sep 13th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #ifndef MLSPRITEBATCH_H
  2. #define MLSPRITEBATCH_H
  3. #include "MLSprite.h"
  4. #include "MLShader.h"
  5. #include "general.h"
  6. #include <map>
  7.  
  8. using MLRenderer::MLSprite;
  9. using MLRenderer::MLShader;
  10. using namespace MLMath::MLVector2;
  11. using namespace MLMath::MLVector3;
  12.  
  13. //
  14. #define ML_MAX_SPRITES 2000
  15.  
  16. namespace MLRenderer
  17. {
  18.     namespace MLBatchItem
  19.     {
  20.         //batch item
  21.         typedef struct batchInfo
  22.         {
  23.             Vector3f VPos[ML_MAX_SPRITES * 4];
  24.             Vector2f UV[ML_MAX_SPRITES * 4];
  25.            
  26.             batchInfo() : pointcount(0), spriteCount(0){}
  27.  
  28.             void addPoint(Vector3f Vpos, Vector2f uv)
  29.             {
  30.                 VPos[pointcount] = Vpos;
  31.                 UV[pointcount] = uv;
  32.                 pointcount++;
  33.             }
  34.             int spriteCount;
  35.             int pointcount;        
  36.         }batchInfo;
  37.     }
  38.  
  39.     class MLSpriteBatch
  40.     {
  41.     public:
  42.         MLSpriteBatch(void);
  43.         //constructor for custom shader
  44.         MLSpriteBatch(MLShader* inShader);
  45.         virtual ~MLSpriteBatch(void);
  46.  
  47.         //begin function to be called first
  48.         void Begin(/*Settings*/bool Alpha = true);
  49.  
  50.         //draw a sprite object
  51.         void Draw(MLSprite* Sprite);
  52.         //custom draw function
  53.         void Draw(GLuint Texture, Vector2f Pos, Vector2f Size);
  54.         //end batch and render everything
  55.         void End();
  56.  
  57.         //set a custom shader
  58.         void setShader(MLShader* inShader);
  59.  
  60.         //release the pointers and the shader
  61.         void release();
  62.         void releaseShader();
  63.     private:
  64.         //render the batch
  65.         void Render();
  66.         //initlaise the batch
  67.         void Initalise();
  68.        
  69.     private:
  70.         bool m_beginCall;
  71.  
  72.         //buffer objects
  73.         GLuint m_VposBuffer;
  74.         GLuint m_UVBuffer;
  75.         GLuint m_BatchVAO;
  76.  
  77.         GLint* indicies;
  78.         GLsizei* Vcount;
  79.  
  80.         int totalSpriteCount;
  81.  
  82.         MLShader* m_shader;
  83.        
  84.         //stores all the batch items
  85.         typedef std::map<GLuint, MLBatchItem::batchInfo*> BatchMap;
  86.         BatchMap m_BatchItems;
  87.     };
  88. }
  89.  
  90.  
  91. #endif //MLSPRITEBATCH_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement