BsGLFrameBufferObject.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsGLContext.h"
  4. #include "BsGLPixelBuffer.h"
  5. #include "BsPixelData.h"
  6. namespace BansheeEngine
  7. {
  8. /** GL surface descriptor. Points to a 2D surface that can be rendered to.
  9. */
  10. struct BS_RSGL_EXPORT GLSurfaceDesc
  11. {
  12. public:
  13. GLPixelBufferPtr buffer;
  14. UINT32 zoffset;
  15. UINT32 numSamples;
  16. GLSurfaceDesc() :buffer(0), zoffset(0), numSamples(0) {}
  17. };
  18. /** Frame Buffer Object abstraction.
  19. */
  20. class BS_RSGL_EXPORT GLFrameBufferObject
  21. {
  22. public:
  23. GLFrameBufferObject(UINT32 multisampleCount);
  24. ~GLFrameBufferObject();
  25. /** Bind a surface to a certain attachment point.
  26. attachment: 0..BS_MAX_MULTIPLE_RENDER_TARGETS-1
  27. */
  28. void bindSurface(UINT32 attachment, const GLSurfaceDesc &target);
  29. /** Unbind attachment
  30. */
  31. void unbindSurface(UINT32 attachment);
  32. /**
  33. * @brief Bind depth stencil buffer.
  34. */
  35. void bindDepthStencil(GLPixelBufferPtr depthStencilBuffer);
  36. /**
  37. * @brief Unbinds depth stencil buffer.
  38. */
  39. void unbindDepthStencil();
  40. /** Bind FrameBufferObject
  41. */
  42. void bind();
  43. /// Get the GL id for the FBO
  44. GLuint getGLFBOID() const { return mFB; }
  45. /// Accessors
  46. UINT32 getWidth();
  47. UINT32 getHeight();
  48. PixelFormat getFormat();
  49. const GLSurfaceDesc &getSurface(UINT32 attachment) { return mColor[attachment]; }
  50. private:
  51. GLsizei mNumSamples;
  52. GLuint mFB;
  53. GLPixelBufferPtr mDepthStencilBuffer;
  54. // Arbitrary number of texture surfaces
  55. GLSurfaceDesc mColor[BS_MAX_MULTIPLE_RENDER_TARGETS];
  56. /** Initialise object (find suitable depth and stencil format).
  57. Must be called every time the bindings change.
  58. It fails with an exception (ERR_INVALIDPARAMS) if:
  59. - Attachment point 0 has no binding
  60. - Not all bound surfaces have the same size
  61. - Not all bound surfaces have the same internal format
  62. */
  63. void initialize();
  64. };
  65. }