Purge underscored header file barriers
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / frame-buffer-state-cache.h
1 #ifndef DALI_INTERNAL_CONTEXT_FRAME_BUFFER_STATE_CACHE_H
2 #define DALI_INTERNAL_CONTEXT_FRAME_BUFFER_STATE_CACHE_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
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/public-api/common/dali-vector.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 /**
32  * @brief Keeps track of color, depth and stencil buffer state within each frame buffer.
33  * Used to avoid redundant glClear calls.
34  *
35  */
36 class FrameBufferStateCache
37 {
38 public:
39
40
41   /**
42    * @brief Constructor
43    */
44   FrameBufferStateCache();
45
46   /**
47    * @brief  non-virtual destructor
48    */
49   ~FrameBufferStateCache();
50
51   /**
52    * @brief Get the bitmask to pass to glClear based on the mask requested
53    * and the current state of the frame buffer
54    * @param[in] mask glClear bit mask
55    * @param[in] forceClear whether to force the clear ( ignore cached state)
56    * @param[in] scissorTestEnabled whether scissor test is enabled
57    * @return new bitmask to pass to glClear
58    */
59   GLbitfield GetClearMask( GLbitfield mask, bool forceClear, bool scissorTestEnabled );
60
61   /**
62    * @brief Set the current bound frame buffer
63    * @param[in] frameBufferId frame buffer id
64    */
65   void SetCurrentFrameBuffer( GLuint frameBufferId );
66
67   /**
68    * @brief Called when frame buffers are deleted
69    * @param[in] count number of frame buffers
70    * @param[in] framebuffers array of frame buffer ids
71    */
72   void FrameBuffersDeleted( GLsizei count, const GLuint* const frameBuffers );
73
74   /**
75    * @brief Called when frame buffers are created
76    * @param[in] count number of frame buffers
77    * @param[in] framebuffers array of frame buffer ids
78    */
79   void FrameBuffersCreated( GLsizei count, const GLuint* const frameBuffers );
80
81   /**
82    * @brief Draw operation performed on the current frame buffer
83    * @param[in] colorBufferUsed whether the color buffer is being written to (glColorMask )
84    * @param[in] depthBufferUsed whether the depth buffer is being written to (glDepthMask )
85    * @param[in] stencilBufferUsed whether the stencil buffer is being written to (glStencilMask )
86    */
87   void DrawOperation( bool colorBufferUsed, bool depthBufferUsed, bool stencilBufferUsed );
88
89   /**
90    * Reset the cache
91    */
92   void Reset();
93
94 private:
95
96   /**
97    * Current status of the frame buffer
98    */
99   enum FrameBufferStatus
100   {
101     COLOR_BUFFER_CLEAN      = 1 << 0, ///< color buffer clean
102     DEPTH_BUFFER_CLEAN      = 1 << 1, ///< depth buffer clean
103     STENCIL_BUFFER_CLEAN    = 1 << 2, ///< stencil buffer clean
104   };
105
106   /**
107    * POD to store the status of frame buffer regarding color,depth and stencil buffers
108    */
109   struct FrameBufferState
110   {
111     /**
112      * Constructor
113      */
114     FrameBufferState( GLuint id, unsigned int state)
115     :mId( id ),
116     mState( state )
117     {
118     }
119     GLuint mId;           ///< Frame buffer id
120     unsigned int mState;  ///< State, bitmask of FrameBufferStatus flags
121   };
122
123   typedef Dali::Vector< FrameBufferState > FrameBufferStateVector;
124
125   /**
126    * @brief Set the clear state
127    * @param[in] pointer to frame buffer state object
128    * @param[in] mask clear mask
129    */
130   void SetClearState( FrameBufferState* state, GLbitfield mask );
131
132   /**
133    * @brief Helper
134    * @param[in] frameBufferId frame buffer id
135    * @return pointer to  frame buffer state object ( NULL if it doesn't exist)
136    */
137   FrameBufferState* GetFrameBufferState( GLuint frameBufferId );
138
139   /**
140    * @brief Helper to delete a frame buffer state object
141    * @param[in] frameBufferId frame buffer id
142    */
143   void DeleteFrameBuffer( GLuint frameBufferId );
144
145   /**
146    * @brief Get the default state of a frame buffer, before it's used
147    * @return initial state
148    */
149   unsigned int GetInitialFrameBufferState();
150
151   FrameBufferStateCache( const FrameBufferStateCache& );            ///< undefined copy constructor
152
153   FrameBufferStateCache& operator=( const FrameBufferStateCache& ); ///< undefined assignment operator
154
155 private: // data
156
157   FrameBufferStateVector    mFrameBufferStates;     ///< state of the frame buffers
158   GLuint                    mCurrentFrameBufferId;  ///< currently bound frame buffer
159 };
160
161 } // namespace Internal
162
163 } // namespace Dali
164
165 #endif // DALI_INTERNAL_CONTEXT_FRAME_BUFFER_STATE_CACHE_H