[Tizen] Make possible to capture on the old driver devices.
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-frame-buffer.h
1 #ifndef DALI_INTERNAL_RENDER_FRAME_BUFFER_H
2 #define DALI_INTERNAL_RENDER_FRAME_BUFFER_H
3
4 /*
5  * Copyright (c) 2020 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/public-api/rendering/frame-buffer.h>
22 #include <dali/devel-api/rendering/frame-buffer-devel.h>
23 #include <dali/internal/render/gl-resources/context.h>
24 #include <dali/internal/render/renderers/render-sampler.h>
25 #include <dali/integration-api/gl-defines.h>
26
27 namespace Dali
28 {
29 using Mask = Dali::FrameBuffer::Attachment::Mask;
30
31 namespace Internal
32 {
33 namespace Render
34 {
35 class Texture;
36
37 class FrameBuffer
38 {
39 public:
40
41   /**
42    * Constructor
43    */
44   FrameBuffer( uint32_t width, uint32_t height, Mask attachments );
45
46   /**
47    * Destructor
48    */
49   virtual ~FrameBuffer();
50
51   /**
52    * Creates a FrameBuffer object in the GPU.
53    * @param[in] context The GL context
54    */
55   virtual void Initialize( Context& context );
56
57   /**
58    * Deletes the framebuffer object from the GPU
59    * @param[in] context The GL context
60    */
61   virtual void Destroy( Context& context );
62
63   /**
64    * Called by RenderManager to inform the framebuffer that the context has been destroyed
65    */
66   virtual void GlContextDestroyed();
67
68   /**
69    * @brief Bind the framebuffer
70    * @param[in] context The GL context
71    */
72   virtual void Bind( Context& context );
73
74   /**
75    * @brief Get the width of the FrameBuffer
76    * @return The width of the framebuffer
77    */
78   virtual uint32_t GetWidth() const;
79
80   /**
81    * @brief Get the height of the FrameBuffer
82    * @return The height of the framebuffer
83    */
84   virtual uint32_t GetHeight() const;
85
86   /**
87    * @brief Attaches a texture for the color rendering. This API is valid only for frame buffer with COLOR attachments.
88    * @param[in] context The GL context
89    * @param[in] texture The texture that will be used as output when rendering
90    * @param[in] mipmapLevel The mipmap of the texture to be attached
91    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
92    * @note A maximum of Dali::FrameBuffer::MAX_COLOR_ATTACHMENTS are supported.
93    */
94   void AttachColorTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
95
96   /**
97    * @brief Attaches a texture for the depth rendering. This API is valid only for frame buffer with DEPTH attachments.
98    * @param[in] context The GL context
99    * @param[in] texture The texture that will be used as output when rendering
100    * @param[in] mipmapLevel The mipmap of the texture to be attached
101    */
102   void AttachDepthTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel );
103
104   /**
105    * @brief Attaches a texture for the depth/stencil rendering. This API is valid only for frame buffer with DEPTH_STENCIL attachments.
106    * @param[in] context The GL context
107    * @param[in] texture The texture that will be used as output when rendering
108    * @param[in] mipmapLevel The mipmap of the texture to be attached
109    */
110   void AttachDepthStencilTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel );
111
112   /**
113    * @brief Get the number of textures bound to this frame buffer as color attachments.
114    * @return The number of color attachments.
115    */
116   uint8_t GetColorAttachmentCount() const { return mColorAttachmentCount; }
117
118   /**
119    * @brief Get the id (OpenGL handle) of the texture bound to this frame buffer as color attachment @a index.
120    * @return The texture id.
121    */
122   GLuint GetTextureId(uint8_t index) { return mTextureId[index]; };
123
124   /**
125    * @brief Read render result
126    */
127   void DrawRenderedBuffer(Context& context);
128
129   /**
130    * @brief Retrieve rendered buffer.
131    * @return Buffer pointer
132    */
133   GLubyte* GetRenderedBuffer();
134
135   /**
136    * @brief Request to Read rendered result.
137    */
138   void CaptureRenderingResult();
139
140 private:
141
142   /**
143    * @brief Undefined copy constructor. FrameBuffer cannot be copied
144    */
145   FrameBuffer( const FrameBuffer& rhs ) = delete;
146
147   /**
148    * @brief Undefined assignment operator. FrameBuffer cannot be copied
149    */
150   FrameBuffer& operator=( const FrameBuffer& rhs ) = delete;
151
152 private:
153
154   GLuint mId;
155   GLuint mTextureId[ Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS ];
156   GLuint mDepthBuffer;
157   GLuint mStencilBuffer;
158   uint32_t mWidth;
159   uint32_t mHeight;
160   uint8_t mColorAttachmentCount;
161   GLubyte* mRenderedBuffer;
162   bool     mCaptureRenderedResult;
163   bool     mCaptured;
164 };
165
166 } // namespace Render
167
168 } // namespace Internal
169
170 } // namespace Dali
171
172
173 #endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H