CCGLUtils.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /****************************************************************************
  2. Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #pragma once
  21. #include <stdint.h>
  22. #include "base/ccMacros.h"
  23. #include "platform/CCGL.h"
  24. NS_CC_BEGIN
  25. struct BoundTextureInfo
  26. {
  27. GLenum target = GL_TEXTURE_2D;
  28. GLuint texture = 0;
  29. };
  30. void ccInvalidateStateCache();
  31. void ccActiveTexture(GLenum texture);
  32. void ccBindTexture(GLenum target, GLuint texture);
  33. BoundTextureInfo* getBoundTextureInfo(uint32_t textureUnit);
  34. void ccBindFramebuffer(GLenum target,GLuint buffer);
  35. void ccActiveOffScreenFramebuffer(GLuint offscreenFbo);
  36. void ccBindBuffer(GLenum target, GLuint buffer);
  37. void ccDeleteBuffers(GLsizei, const GLuint * buffers);
  38. GLint ccGetBoundVertexBuffer();
  39. GLint ccGetBoundIndexBuffer();
  40. void ccBindVertexArray(GLuint VAO);
  41. GLint ccGetBoundVertexArray();
  42. void ccViewport(GLint x, GLint y, GLsizei width, GLsizei height);
  43. void ccScissor(GLint x, GLint y, GLsizei width, GLsizei height);
  44. struct VertexAttributePointerInfo
  45. {
  46. VertexAttributePointerInfo(GLuint VBO, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer)
  47. : VBO(VBO)
  48. , index(index)
  49. , size(size)
  50. , type(type)
  51. , normalized(normalized)
  52. , stride(stride)
  53. , pointer(pointer)
  54. {}
  55. VertexAttributePointerInfo() {}
  56. GLuint index = 0;
  57. // The VBO this attribute bind to.
  58. GLuint VBO = 0;
  59. GLint size = 0;
  60. GLenum type = GL_UNSIGNED_BYTE;
  61. GLboolean normalized = false;
  62. GLsizei stride = 0;
  63. const GLvoid* pointer = nullptr;
  64. };
  65. void ccEnableVertexAttribArray(GLuint index);
  66. void ccDisableVertexAttribArray(GLuint index);
  67. void ccVertexAttribPointer(GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*);
  68. const VertexAttributePointerInfo* getVertexAttribPointerInfo(GLuint index);
  69. // Converts pixel if unpackFlipY or premultiplyAlpha is true.
  70. void ccFlipYOrPremultiptyAlphaIfNeeded(GLenum format, GLsizei width, GLsizei height, uint32_t pixelBytes, GLvoid* pixels);
  71. bool ccIsUnpackFlipY();
  72. bool ccIsPremultiplyAlpha();
  73. void ccPixelStorei(GLenum pname, GLint param);
  74. GLint ccGetBufferDataSize();
  75. NS_CC_END