QtOpenGLSpriteBatch.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation.
  3. *
  4. * CAUTION: This class is in early, experimental state.
  5. *
  6. */
  7. #ifndef __QTOPENGLSPRITEBATCH__
  8. #define __QTOPENGLSPRITEBATCH__
  9. #include <QObject>
  10. #include <QMatrix4x4>
  11. #include "SpriteBatch.h"
  12. #include <QtOpenGL/QGLBuffer>
  13. #include <QtOpenGL/QGLWidget>
  14. #include <QtOpenGL/qglshaderprogram.h>
  15. #define COSINE_TABLE_SIZE 1024
  16. #define COSINE_TABLE_AND 1023
  17. #define BATCH_SIZE 16 // NOTE, THIS CANNOT BE CHANGED UNLESS CORRESPONDING VALUES FROM THE SHADER'S ARE CHANGED ACCORDINGLY
  18. class QtOpenGLSpriteBatch : public QObject, public SpriteBatch
  19. {
  20. Q_OBJECT
  21. public:
  22. QtOpenGLSpriteBatch(int targetWidth, int targetHeight, QObject *parent=0);
  23. virtual ~QtOpenGLSpriteBatch();
  24. void draw ( SpriteDrawInfo *sdi, int spriteCount=1 );
  25. void begin( BlendMode blendMode, TransformMode dTransform = ePIXELSPACE, float *customProjectionMatrix = 0);
  26. void end();
  27. void flushSprites(bool useTable = true);
  28. protected:
  29. float cosineTable[COSINE_TABLE_SIZE];
  30. //float inputMatrixTemp[ BATCH_SIZE * 16 ];
  31. QMatrix4x4 inputMatrixtemp[ BATCH_SIZE ];
  32. QMatrix4x4 projectionMatrix;
  33. SpriteDrawInfo batchCollection[ BATCH_SIZE ];
  34. int batchCounter;
  35. // Currently active texture
  36. GLuint currentTexture;
  37. int currentTextureWidth;
  38. int currentTextureHeight;
  39. void setActiveProgram( int programIndex );
  40. int currentProgram;
  41. bool allWhite;
  42. // Objects for GLES2 rendering
  43. TransformMode currentDestinationTransform;
  44. int currentViewportWidth;
  45. int currentViewportHeight;
  46. QGLShaderProgram program[2];
  47. QGLBuffer *qtvbo;
  48. // Some locations to the program
  49. GLuint inputMatrixLocation[2];
  50. GLuint projmLocation[2];
  51. GLuint samplerLocation[2];
  52. };
  53. #endif