| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsGLPrerequisites.h" |
| 6 | #include "BsGLContext.h" |
| 7 | #include "BsGLPixelBuffer.h" |
| 8 | #include "Image/BsPixelData.h" |
| 9 | |
| 10 | namespace bs { namespace ct |
| 11 | { |
| 12 | /** @addtogroup GL |
| 13 | * @{ |
| 14 | */ |
| 15 | |
| 16 | /** Describes OpenGL frame buffer surface. */ |
| 17 | struct GLSurfaceDesc |
| 18 | { |
| 19 | public: |
| 20 | GLSurfaceDesc() = default; |
| 21 | |
| 22 | SPtr<GLPixelBuffer> buffer; |
| 23 | UINT32 zoffset = 0; |
| 24 | UINT32 numSamples = 0; |
| 25 | bool allLayers = false; |
| 26 | }; |
| 27 | |
| 28 | /** |
| 29 | * Manages an OpenGL frame-buffer object. Frame buffer object is used as a rendering destination in the render system |
| 30 | * pipeline, and it may consist out of one or multiple color surfaces and an optional depth/stencil surface. |
| 31 | */ |
| 32 | class GLFrameBufferObject |
| 33 | { |
| 34 | public: |
| 35 | GLFrameBufferObject(); |
| 36 | ~GLFrameBufferObject(); |
| 37 | |
| 38 | /** |
| 39 | * Binds a color surface to the specific attachment point. Call rebuild() to apply changes. |
| 40 | * |
| 41 | * @param[in] attachment Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS). |
| 42 | * @param[in] target Description of the color surface to attach. |
| 43 | * |
| 44 | * @note |
| 45 | * Multisample counts of all surfaces must match. |
| 46 | * 0th attachment must be bound in order for the object to be usable, rest are optional. |
| 47 | */ |
| 48 | void bindSurface(UINT32 attachment, const GLSurfaceDesc& target); |
| 49 | |
| 50 | /** |
| 51 | * Unbinds the attachment at the specified attachment index. Call rebuild() to apply changes. |
| 52 | * |
| 53 | * @param[in] attachment Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS). |
| 54 | */ |
| 55 | void unbindSurface(UINT32 attachment); |
| 56 | |
| 57 | /** |
| 58 | * Binds a depth/stencil buffer. Call rebuild() to apply changes. |
| 59 | * |
| 60 | * @note |
| 61 | * Multisample counts of depth/stencil and color surfaces must match. |
| 62 | * Binding a depth/stencil buffer is optional. |
| 63 | */ |
| 64 | void bindDepthStencil(SPtr<GLPixelBuffer> depthStencilBuffer, bool allLayers); |
| 65 | |
| 66 | /** Unbinds a depth stencil buffer. Call rebuild() to apply changes. */ |
| 67 | void unbindDepthStencil(); |
| 68 | |
| 69 | /** Rebuilds internal frame buffer object. Should be called whenever surfaces changes or is bound/unbound. */ |
| 70 | void rebuild(); |
| 71 | |
| 72 | /** Binds the frame buffer object to the OpenGL pipeline, making it used for any further rendering operations. */ |
| 73 | void bind(); |
| 74 | |
| 75 | /** Checks is the color buffer at the specified index bound. */ |
| 76 | bool hasColorBuffer(UINT32 idx) const { return mColor[idx].buffer != nullptr; } |
| 77 | |
| 78 | /** Returns internal OpenGL frame buffer id. */ |
| 79 | GLuint getGLFBOID() const { return mFB; } |
| 80 | |
| 81 | private: |
| 82 | GLuint mFB; |
| 83 | |
| 84 | GLSurfaceDesc mColor[BS_MAX_MULTIPLE_RENDER_TARGETS]; |
| 85 | SPtr<GLPixelBuffer> mDepthStencilBuffer; |
| 86 | bool mDepthStencilAllLayers = false; |
| 87 | }; |
| 88 | |
| 89 | /** @} */ |
| 90 | }} |
| 91 | |