BsGLFrameBufferObject.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsGLPrerequisites.h"
  5. #include "BsGLContext.h"
  6. #include "BsGLPixelBuffer.h"
  7. #include "Image/BsPixelData.h"
  8. namespace bs { namespace ct
  9. {
  10. /** @addtogroup GL
  11. * @{
  12. */
  13. /** Describes OpenGL frame buffer surface. */
  14. struct GLSurfaceDesc
  15. {
  16. public:
  17. GLSurfaceDesc()
  18. :zoffset(0), numSamples(0), allLayers(false)
  19. { }
  20. SPtr<GLPixelBuffer> buffer;
  21. UINT32 zoffset;
  22. UINT32 numSamples;
  23. bool allLayers;
  24. };
  25. /**
  26. * Manages an OpenGL frame-buffer object. Frame buffer object is used as a rendering destination in the render system
  27. * pipeline, and it may consist out of one or multiple color surfaces and an optional depth/stencil surface.
  28. */
  29. class GLFrameBufferObject
  30. {
  31. public:
  32. GLFrameBufferObject();
  33. ~GLFrameBufferObject();
  34. /**
  35. * Binds a color surface to the specific attachment point. Call rebuild() to apply changes.
  36. *
  37. * @param[in] attachment Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS).
  38. * @param[in] target Description of the color surface to attach.
  39. *
  40. * @note
  41. * Multisample counts of all surfaces must match.
  42. * 0th attachment must be bound in order for the object to be usable, rest are optional.
  43. */
  44. void bindSurface(UINT32 attachment, const GLSurfaceDesc& target);
  45. /**
  46. * Unbinds the attachment at the specified attachment index. Call rebuild() to apply changes.
  47. *
  48. * @param[in] attachment Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS).
  49. */
  50. void unbindSurface(UINT32 attachment);
  51. /**
  52. * Binds a depth/stencil buffer. Call rebuild() to apply changes.
  53. *
  54. * @note
  55. * Multisample counts of depth/stencil and color surfaces must match.
  56. * Binding a depth/stencil buffer is optional.
  57. */
  58. void bindDepthStencil(SPtr<GLPixelBuffer> depthStencilBuffer, bool allLayers);
  59. /** Unbinds a depth stencil buffer. Call rebuild() to apply changes. */
  60. void unbindDepthStencil();
  61. /** Rebuilds internal frame buffer object. Should be called whenever surfaces changes or is bound/unbound. */
  62. void rebuild();
  63. /** Binds the frame buffer object to the OpenGL pipeline, making it used for any further rendering operations. */
  64. void bind();
  65. /** Checks is the color buffer at the specified index bound. */
  66. bool hasColorBuffer(UINT32 idx) const { return mColor[idx].buffer != nullptr; }
  67. /** Returns internal OpenGL frame buffer id. */
  68. GLuint getGLFBOID() const { return mFB; }
  69. private:
  70. GLuint mFB;
  71. GLSurfaceDesc mColor[BS_MAX_MULTIPLE_RENDER_TARGETS];
  72. SPtr<GLPixelBuffer> mDepthStencilBuffer;
  73. bool mDepthStencilAllLayers;
  74. };
  75. /** @} */
  76. }}