Advertisement
Dekowta

SpriteBatchMod1.h

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