BsGLFrameBufferObject.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __OgreGLFBO_H__
  25. #define __OgreGLFBO_H__
  26. #include "BsGLPrerequisites.h"
  27. #include "BsGLContext.h"
  28. #include "BsGLPixelBuffer.h"
  29. #include "BsPixelData.h"
  30. namespace BansheeEngine
  31. {
  32. /** GL surface descriptor. Points to a 2D surface that can be rendered to.
  33. */
  34. struct BS_RSGL_EXPORT GLSurfaceDesc
  35. {
  36. public:
  37. GLPixelBufferPtr buffer;
  38. UINT32 zoffset;
  39. UINT32 numSamples;
  40. GLSurfaceDesc() :buffer(0), zoffset(0), numSamples(0) {}
  41. };
  42. /** Frame Buffer Object abstraction.
  43. */
  44. class BS_RSGL_EXPORT GLFrameBufferObject
  45. {
  46. public:
  47. GLFrameBufferObject(UINT32 multisampleCount);
  48. ~GLFrameBufferObject();
  49. /** Bind a surface to a certain attachment point.
  50. attachment: 0..BS_MAX_MULTIPLE_RENDER_TARGETS-1
  51. */
  52. void bindSurface(UINT32 attachment, const GLSurfaceDesc &target);
  53. /** Unbind attachment
  54. */
  55. void unbindSurface(UINT32 attachment);
  56. /**
  57. * @brief Bind depth stencil buffer.
  58. */
  59. void bindDepthStencil(GLPixelBufferPtr depthStencilBuffer);
  60. /**
  61. * @brief Unbinds depth stencil buffer.
  62. */
  63. void unbindDepthStencil();
  64. /** Bind FrameBufferObject
  65. */
  66. void bind();
  67. /// Get the GL id for the FBO
  68. GLuint getGLFBOID() const { return mFB; }
  69. /// Accessors
  70. UINT32 getWidth();
  71. UINT32 getHeight();
  72. PixelFormat getFormat();
  73. const GLSurfaceDesc &getSurface(UINT32 attachment) { return mColor[attachment]; }
  74. private:
  75. GLsizei mNumSamples;
  76. GLuint mFB;
  77. GLPixelBufferPtr mDepthStencilBuffer;
  78. // Arbitrary number of texture surfaces
  79. GLSurfaceDesc mColor[BS_MAX_MULTIPLE_RENDER_TARGETS];
  80. /** Initialise object (find suitable depth and stencil format).
  81. Must be called every time the bindings change.
  82. It fails with an exception (ERR_INVALIDPARAMS) if:
  83. - Attachment point 0 has no binding
  84. - Not all bound surfaces have the same size
  85. - Not all bound surfaces have the same internal format
  86. */
  87. void initialise();
  88. };
  89. }
  90. #endif