BsGLFrameBufferObject.h 2.7 KB

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