Advertisement
Dekowta

SpriteBatchMod2.h

Sep 18th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 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 5000
  15.  
  16. namespace MLRenderer
  17. {
  18.     namespace MLBatchItem
  19.     {
  20.  
  21.         typedef struct Vertex
  22.         {
  23.             Vector3f VPos;
  24.             Vector2f UV;
  25.             float padding[3];
  26.         }Vertex;
  27.         //batch item
  28.         typedef struct batchInfo
  29.         {
  30.             Vertex Verts[ML_MAX_SPRITES * 4];
  31.            
  32.             batchInfo() : pointcount(0), spriteCount(0){}
  33.  
  34.             void addPoint(Vector3f Vpos, Vector2f uv)
  35.             {
  36.                 Verts[pointcount].VPos = Vpos;
  37.                 Verts[pointcount].UV = uv;
  38.                 pointcount++;
  39.             }
  40.             int spriteCount;
  41.             int pointcount;        
  42.         }batchInfo;
  43.     }
  44.  
  45.     class MLSpriteBatch
  46.     {
  47.     public:
  48.         MLSpriteBatch(int bufferSize);
  49.         //constructor for custom shader
  50.         MLSpriteBatch(MLShader* inShader, int buffersize);
  51.         virtual ~MLSpriteBatch(void);
  52.  
  53.         //begin function to be called first
  54.         void Begin(/*Settings*/bool Alpha = true);
  55.  
  56.         //draw a sprite object
  57.         void Draw(MLSprite* Sprite);
  58.         //custom draw function
  59.         void Draw(GLuint Texture, Vector2f Pos, Vector2f Size);
  60.         //end batch and render everything
  61.         void End();
  62.  
  63.         //set a custom shader
  64.         void setShader(MLShader* inShader);
  65.  
  66.         //release the pointers and the shader
  67.         void release();
  68.         void releaseShader();
  69.     private:
  70.         //render the batch
  71.         void Render();
  72.         //initlaise the batch
  73.         void Initalise();
  74.        
  75.     private:
  76.         bool m_beginCall;
  77.  
  78.         //buffer objects
  79.         GLuint m_VposBuffer;
  80.         GLuint m_UVBuffer;
  81.         GLuint m_VertBuffer;
  82.         GLuint m_BatchVAO;
  83.  
  84.         const int m_spriteSize;
  85.         const int m_BufferSize;
  86.         int m_BufferOffset;
  87.  
  88.         int totalSpriteCount;
  89.  
  90.         MLShader* m_shader;
  91.        
  92.         //stores all the batch items
  93.         typedef std::map<GLuint, MLBatchItem::batchInfo*> BatchMap;
  94.         BatchMap m_BatchItems;
  95.     };
  96. }
  97.  
  98.  
  99. #endif //MLSPRITEBATCH_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement