ccGLStateCache.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /****************************************************************************
  2. Copyright (c) 2011 Ricardo Quesada
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2011 Zynga Inc.
  5. Copyright (c) 2013-2016 Chukong Technologies Inc.
  6. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  7. http://www.cocos2d-x.org
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE.
  23. ****************************************************************************/
  24. #ifndef __CCGLSTATE_H__
  25. #define __CCGLSTATE_H__
  26. #include <cstdint>
  27. #include "platform/CCGL.h"
  28. #include "platform/CCPlatformMacros.h"
  29. NS_CC_BEGIN
  30. /**
  31. * @addtogroup renderer
  32. * @{
  33. */
  34. class GLProgram;
  35. class Texture2D;
  36. namespace GL {
  37. /** Vertex attrib flags. */
  38. enum {
  39. VERTEX_ATTRIB_FLAG_NONE = 0,
  40. VERTEX_ATTRIB_FLAG_POSITION = 1 << 0,
  41. VERTEX_ATTRIB_FLAG_COLOR = 1 << 1,
  42. VERTEX_ATTRIB_FLAG_TEX_COORD = 1 << 2,
  43. VERTEX_ATTRIB_FLAG_NORMAL = 1 << 3,
  44. VERTEX_ATTRIB_FLAG_BLEND_WEIGHT = 1 << 4,
  45. VERTEX_ATTRIB_FLAG_BLEND_INDEX = 1 << 5,
  46. VERTEX_ATTRIB_FLAG_POS_COLOR_TEX = (VERTEX_ATTRIB_FLAG_POSITION | VERTEX_ATTRIB_FLAG_COLOR | VERTEX_ATTRIB_FLAG_TEX_COORD),
  47. };
  48. /**
  49. * Invalidates the GL state cache.
  50. *
  51. * If CC_ENABLE_GL_STATE_CACHE it will reset the GL state cache.
  52. * @since v2.0.0
  53. */
  54. void CC_DLL invalidateStateCache(void);
  55. /**
  56. * Uses the GL program in case program is different than the current one.
  57. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly.
  58. * @since v2.0.0
  59. */
  60. void CC_DLL useProgram(GLuint program);
  61. /**
  62. * Deletes the GL program. If it is the one that is being used, it invalidates it.
  63. *
  64. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly.
  65. * @since v2.0.0
  66. */
  67. void CC_DLL deleteProgram(GLuint program);
  68. /**
  69. * Uses a blending function in case it not already used.
  70. *
  71. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly.
  72. * @since v2.0.0
  73. */
  74. void CC_DLL blendFunc(GLenum sfactor, GLenum dfactor);
  75. /**
  76. * Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation().
  77. *
  78. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD.
  79. * @since v2.0.0
  80. */
  81. void CC_DLL blendResetToCache(void);
  82. /**
  83. * Sets the projection matrix as dirty.
  84. * @since v2.0.0
  85. */
  86. void CC_DLL setProjectionMatrixDirty(void);
  87. /**
  88. * Will enable the vertex attribs that are passed as flags.
  89. * Possible flags:
  90. *
  91. * * VERTEX_ATTRIB_FLAG_POSITION
  92. * * VERTEX_ATTRIB_FLAG_COLOR
  93. * * VERTEX_ATTRIB_FLAG_TEX_COORDS
  94. *
  95. * These flags can be ORed. The flags that are not present, will be disabled.
  96. *
  97. * @since v2.0.0
  98. */
  99. void CC_DLL enableVertexAttribs(uint32_t flags);
  100. /**
  101. * If the texture is not already bound to texture unit 0, it binds it.
  102. *
  103. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
  104. * @since v2.0.0
  105. */
  106. void CC_DLL bindTexture2D(GLuint textureId);
  107. /**
  108. * If the texture is not already bound to texture unit 0, it binds it.
  109. *
  110. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
  111. *
  112. * @remark: It will bind alpha texture to support ETC1 alpha channel.
  113. * @since v3.13
  114. */
  115. void CC_DLL bindTexture2D(Texture2D* texture);
  116. /**
  117. * If the texture is not already bound to a given unit, it binds it.
  118. *
  119. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
  120. * @since v2.1.0
  121. */
  122. void CC_DLL bindTexture2DN(GLuint textureUnit, GLuint textureId);
  123. /** If the texture is not already bound to a given unit, it binds it.
  124. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
  125. * @since v3.6
  126. */
  127. void CC_DLL bindTextureN(GLuint textureUnit, GLuint textureId, GLuint textureType = GL_TEXTURE_2D);
  128. /**
  129. * It will delete a given texture. If the texture was bound, it will invalidate the cached.
  130. *
  131. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
  132. * @since v2.0.0
  133. */
  134. void CC_DLL deleteTexture(GLuint textureId);
  135. /**
  136. * It will delete a given texture. If the texture was bound, it will invalidate the cached for the given texture unit.
  137. *
  138. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
  139. * @since v2.1.0
  140. */
  141. CC_DEPRECATED_ATTRIBUTE void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId);
  142. /**
  143. * Select active texture unit.
  144. *
  145. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.
  146. * @since v3.0
  147. */
  148. void CC_DLL activeTexture(GLenum texture);
  149. /**
  150. * If the vertex array is not already bound, it binds it.
  151. *
  152. * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.
  153. * @since v2.0.0
  154. */
  155. void CC_DLL bindVAO(GLuint vaoId);
  156. // end of support group
  157. /// @}
  158. } // Namespace GL
  159. NS_CC_END
  160. #endif /* __CCGLSTATE_H__ */