BsGLFrameBufferObject.h 2.3 KB

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