BsGLFrameBufferObject.h 2.8 KB

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