CCGLProgramStateCache.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCGLPROGRAMSTATECACHE_H__
  22. #define __CCGLPROGRAMSTATECACHE_H__
  23. #include "base/ccTypes.h"
  24. #include "base/CCVector.h"
  25. #include "base/CCMap.h"
  26. #include "math/Vec2.h"
  27. #include "math/Vec3.h"
  28. #include "math/Vec4.h"
  29. /**
  30. * @addtogroup renderer
  31. * @{
  32. */
  33. NS_CC_BEGIN
  34. class GLProgram;
  35. class GLProgramState;
  36. /**
  37. Some GLprogram state could be shared. GLProgramStateCache is used to cache this, and will reuse the
  38. old GLProgramState, which will accelerate the creation of game objects such as sprites, particles etc.
  39. */
  40. class CC_DLL GLProgramStateCache
  41. {
  42. public:
  43. /**Get the GLProgramStateCache singleton instance.*/
  44. static GLProgramStateCache* getInstance();
  45. /**Destroy the GLProgramStateCache singleton.*/
  46. static void destroyInstance();
  47. /**Get the shared GLProgramState by the owner GLProgram.*/
  48. GLProgramState* getGLProgramState(GLProgram* program);
  49. /**Remove all the cached GLProgramState.*/
  50. void removeAllGLProgramState();
  51. /**Remove unused GLProgramState.*/
  52. void removeUnusedGLProgramState();
  53. protected:
  54. GLProgramStateCache();
  55. ~GLProgramStateCache();
  56. Map<GLProgram*, GLProgramState*> _glProgramStates;
  57. static GLProgramStateCache* s_instance;
  58. };
  59. NS_CC_END
  60. /**
  61. end of support group
  62. @}
  63. */
  64. #endif /* __CCGLPROGRAMSTATECACHE_H__ */