Texture2D.h 2.7 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 "../Macro.h"
  22. #include "../Types.h"
  23. #include "Texture.h"
  24. RENDERER_BEGIN
  25. /**
  26. * @addtogroup gfx
  27. * @{
  28. */
  29. /**
  30. * The 2d texture class\n
  31. * JS API: gfx.Texture2D
  32. @code
  33. let texture = new gfx.Texture2D(cc.renderer.device, {
  34. images: [],
  35. width: 128,
  36. height: 128,
  37. wrapS: renderEngine.gfx.WRAP_REPEAT,
  38. wrapT: renderEngine.gfx.WRAP_REPEAT,
  39. format: renderEngine.gfx.TEXTURE_FMT_RGB8,
  40. mipmap: false,
  41. });
  42. @endcode
  43. */
  44. class Texture2D : public Texture
  45. {
  46. public:
  47. Texture2D();
  48. ~Texture2D();
  49. /*
  50. * Init the texture with device and options
  51. * @see Texture::Options
  52. */
  53. bool init(DeviceGraphics* device, Options& options);
  54. /**
  55. * Update the texture with new options
  56. * @see Texture::Options
  57. */
  58. void update(const Options& options);
  59. /**
  60. * Update a sub area of the texture with sub image option
  61. * @see Texture::SubImageOption
  62. */
  63. void updateSubImage(const SubImageOption& option);
  64. /**
  65. * Update the image of a given level mipmap specified in image option
  66. * @see Texture::ImageOption
  67. */
  68. void updateImage(const ImageOption& option);
  69. private:
  70. void setSubImage(const SubImageOption& options);
  71. void setImage(const ImageOption& options);
  72. void setMipmap(const std::vector<Image>& images, bool isFlipY, bool isPremultiplyAlpha);
  73. void setTexInfo();
  74. };
  75. // end of gfx group
  76. /// @}
  77. RENDERER_END