Added support for Multiple Render Targets, to Dali::FrameBuffer.
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-texture-frame-buffer.h
1 #ifndef DALI_INTERNAL_RENDER_TEXTURE_FRAME_BUFFER_H
2 #define DALI_INTERNAL_RENDER_TEXTURE_FRAME_BUFFER_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/render/renderers/render-frame-buffer.h>
22
23 namespace Dali
24 {
25 using Mask = Dali::FrameBuffer::Attachment::Mask;
26
27 namespace Internal
28 {
29 namespace Render
30 {
31 class Texture;
32
33 class TextureFrameBuffer : public FrameBuffer
34 {
35 public:
36
37   /**
38    * Constructor
39    * @param[in] width The width of the FrameBuffer
40    * @param[in] height The height of the FrameBuffer
41    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
42    */
43   TextureFrameBuffer( uint32_t width, uint32_t height, Mask attachments );
44
45   /**
46    * Destructor
47    */
48   virtual ~TextureFrameBuffer();
49
50   /**
51    * @copydoc Dali::Internal::Renderer::FrameBuffer::Initialize()
52    */
53   void Initialize( Context& context ) override;
54
55   /**
56    * @copydoc Dali::Internal::Renderer::FrameBuffer::Destroy()
57    */
58   void Destroy( Context& context ) override;
59
60   /**
61    * @copydoc Dali::Internal::Renderer::FrameBuffer::GlContextDestroyed()
62    */
63   void GlContextDestroyed() override;
64
65   /**
66    * @copydoc Dali::Internal::Renderer::FrameBuffer::Bind()
67    */
68   void Bind( Context& context ) override;
69
70   /**
71    * @copydoc Dali::Internal::Renderer::FrameBuffer::GetWidth()
72    */
73   uint32_t GetWidth() const override;
74
75   /**
76    * @copydoc Dali::Internal::Renderer::FrameBuffer::GetHeight()
77    */
78   uint32_t GetHeight() const override;
79
80   /**
81    * @copydoc Dali::Internal::Renderer::FrameBuffer::IsSurfaceBacked()
82    */
83   bool IsSurfaceBacked() override { return false; };
84
85   /**
86    * @brief Attach a texture for color rendering. Valid only for Framebuffers with COLOR attachments.
87    * @param[in] context The GL context
88    * @param[in] texture The texture that will be used as output when rendering
89    * @param[in] mipmapLevel The mipmap of the texture to be attached
90    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
91    * @note A maximum of Dali::FrameBuffer::MAX_COLOR_ATTACHMENTS are supported.
92    */
93   void AttachColorTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
94
95   /**
96    * @brief Get the number of textures bound to this frame buffer as color attachments.
97    * @return The number of color attachments.
98    */
99   uint8_t GetColorAttachmentCount() const { return mColorAttachmentCount; }
100
101   /**
102    * @brief Get the id (OpenGL handle) of the texture bound to this frame buffer as color attachment @a index.
103    * @return The texture id.
104    */
105   GLuint GetTextureId(uint8_t index) { return mTextureId[index]; };
106
107 private:
108
109   GLuint mId;
110   GLuint mTextureId[Dali::FrameBuffer::MAX_COLOR_ATTACHMENTS];
111   GLuint mDepthBuffer;
112   GLuint mStencilBuffer;
113   uint32_t mWidth;
114   uint32_t mHeight;
115   uint8_t mColorAttachmentCount;
116 };
117
118
119 } // namespace Render
120
121 } // namespace Internal
122
123 } // namespace Dali
124
125
126 #endif // DALI_INTERNAL_RENDER_TEXTURE_FRAME_BUFFER_H