Advertisement
Dekowta

SB.h

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