BsGLFrameBufferObject.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsGLPrerequisites.h"
  6. #include "BsGLContext.h"
  7. #include "BsGLPixelBuffer.h"
  8. #include "BsPixelData.h"
  9. namespace BansheeEngine
  10. {
  11. /**
  12. * @brief Describes OpenGL frame buffer surface.
  13. */
  14. struct BS_RSGL_EXPORT GLSurfaceDesc
  15. {
  16. public:
  17. GLSurfaceDesc()
  18. :zoffset(0), numSamples(0)
  19. { }
  20. GLPixelBufferPtr buffer;
  21. UINT32 zoffset;
  22. UINT32 numSamples;
  23. };
  24. /**
  25. * @brief Manages an OpenGL frame-buffer object. Frame buffer object
  26. * is used as a rendering destination in the render system pipeline,
  27. * and it may consist out of one or multiple color surfaces and an optional
  28. * depth/stencil surface.
  29. */
  30. class BS_RSGL_EXPORT GLFrameBufferObject
  31. {
  32. public:
  33. GLFrameBufferObject();
  34. ~GLFrameBufferObject();
  35. /**
  36. * @brief Binds a color surface to the specific attachment point.
  37. *
  38. * @param attachment Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS).
  39. * @param target Description of the color surface to attach.
  40. *
  41. * @note 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. * @brief Unbinds the attachment at the specified attachment index.
  47. *
  48. * @param attachment Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS).
  49. */
  50. void unbindSurface(UINT32 attachment);
  51. /**
  52. * @brief Binds a depth/stencil buffer.
  53. *
  54. * @note Multisample counts of depth/stencil and color surfaces must match.
  55. * Binding a depth/stencil buffer is optional.
  56. */
  57. void bindDepthStencil(GLPixelBufferPtr depthStencilBuffer);
  58. /**
  59. * @brief Unbinds a depth stencil buffer.
  60. */
  61. void unbindDepthStencil();
  62. /**
  63. * @brief Binds the frame buffer object to the OpenGL pipeline, making it used
  64. * for any further rendering operations.
  65. */
  66. void bind();
  67. /**
  68. * @brief Returns internal OpenGL frame buffer id.
  69. */
  70. GLuint getGLFBOID() const { return mFB; }
  71. private:
  72. /**
  73. * @brief Rebuilds internal frame buffer object. Should be called whenever surfaces change.
  74. */
  75. void rebuild();
  76. private:
  77. GLuint mFB;
  78. GLSurfaceDesc mColor[BS_MAX_MULTIPLE_RENDER_TARGETS];
  79. GLPixelBufferPtr mDepthStencilBuffer;
  80. };
  81. }