FrameBuffer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <vector>
  22. #include "../Macro.h"
  23. #include "../Types.h"
  24. #include "GraphicsHandle.h"
  25. RENDERER_BEGIN
  26. class DeviceGraphics;
  27. class RenderTarget;
  28. /**
  29. * @addtogroup gfx
  30. * @{
  31. */
  32. /**
  33. * The FrameBuffer class can store the render results of DeviceGraphics.
  34. * It contains color buffers, depth buffers and stencil buffers,
  35. * they are destinations for drawing, clearing and writing operations during the render process.
  36. */
  37. class FrameBuffer final : public GraphicsHandle
  38. {
  39. public:
  40. /**
  41. * Create a FrameBuffer object with device and size
  42. */
  43. RENDERER_DEFINE_CREATE_METHOD_3(FrameBuffer, init, DeviceGraphics*, uint16_t, uint16_t)
  44. FrameBuffer();
  45. /**
  46. * Inits the frame buffer with device and size
  47. */
  48. bool init(DeviceGraphics* device, uint16_t width, uint16_t height);
  49. /**
  50. * Destroys the GL buffers created by this frame buffer object
  51. */
  52. void destroy();
  53. /**
  54. * Sets the color buffers as drawing and clearing destinations
  55. */
  56. void setColorBuffers(const std::vector<RenderTarget*>& renderTargets);
  57. /**
  58. * Sets a color buffer at specific index
  59. */
  60. void setColorBuffer(RenderTarget* rt, int index);
  61. /**
  62. * Sets the depth buffer as depth writing destination
  63. */
  64. void setDepthBuffer(RenderTarget* rt);
  65. /**
  66. * Sets the stencil buffer as stencil writing destination
  67. */
  68. void setStencilBuffer(RenderTarget* rt);
  69. /**
  70. * Sets the depth and stencil buffer at the same time.
  71. * If you want to set both with the same RenderTarget, you should use this instead of setting them separatly.
  72. */
  73. void setDepthStencilBuffer(RenderTarget* rt);
  74. /**
  75. * Sets the width of frame buffer
  76. */
  77. inline int getWidth() const { return _width; }
  78. /**
  79. * Sets the width of frame buffer
  80. */
  81. inline int getHeight() const { return _height; }
  82. /**
  83. * Gets the color buffers
  84. */
  85. const std::vector<RenderTarget*>& getColorBuffers() const;
  86. /**
  87. * Gets the depth buffer
  88. */
  89. const RenderTarget* getDepthBuffer() const;
  90. /**
  91. * Gets the stencil buffer
  92. */
  93. const RenderTarget* getStencilBuffer() const;
  94. /**
  95. * Gets the depth and stencil buffer if they share the same one.
  96. */
  97. const RenderTarget* getDepthStencilBuffer() const;
  98. private:
  99. virtual ~FrameBuffer();
  100. DeviceGraphics* _device;
  101. std::vector<RenderTarget*> _colorBuffers;
  102. RenderTarget* _depthBuffer;
  103. RenderTarget* _stencilBuffer;
  104. RenderTarget* _depthStencilBuffer;
  105. uint16_t _width;
  106. uint16_t _height;
  107. };
  108. // end of gfx group
  109. /// @}
  110. RENDERER_END