1 #ifndef __DALI_INTERNAL_CONTEXT_FRAME_BUFFER_STATE_CACHE_H__
2 #define __DALI_INTERNAL_CONTEXT_FRAME_BUFFER_STATE_CACHE_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/public-api/common/dali-vector.h>
32 * @brief Keeps track of color, depth and stencil buffer state within each frame buffer.
33 * Used to avoid redundant glClear calls.
36 class FrameBufferStateCache
44 FrameBufferStateCache();
47 * @brief non-virtual destructor
49 ~FrameBufferStateCache();
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
59 GLbitfield GetClearMask( GLbitfield mask, bool forceClear, bool scissorTestEnabled );
62 * @brief Set the current bound frame buffer
63 * @param[in] frameBufferId frame buffer id
65 void SetCurrentFrameBuffer( GLuint frameBufferId );
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
72 void FrameBuffersDeleted( GLsizei count, const GLuint* const frameBuffers );
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
79 void FrameBuffersCreated( GLsizei count, const GLuint* const frameBuffers );
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 )
87 void DrawOperation( bool colorBufferUsed, bool depthBufferUsed, bool stencilBufferUsed );
97 * Current status of the frame buffer
99 enum FrameBufferStatus
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
107 * POD to store the status of frame buffer regarding color,depth and stencil buffers
109 struct FrameBufferState
114 FrameBufferState( GLuint id, unsigned int state)
119 GLuint mId; ///< Frame buffer id
120 unsigned int mState; ///< State, bitmask of FrameBufferStatus flags
123 typedef Dali::Vector< FrameBufferState > FrameBufferStateVector;
126 * @brief Set the clear state
127 * @param[in] pointer to frame buffer state object
128 * @param[in] mask clear mask
130 void SetClearState( FrameBufferState* state, GLbitfield mask );
134 * @param[in] frameBufferId frame buffer id
135 * @return pointer to frame buffer state object ( NULL if it doesn't exist)
137 FrameBufferState* GetFrameBufferState( GLuint frameBufferId );
140 * @brief Helper to delete a frame buffer state object
141 * @param[in] frameBufferId frame buffer id
143 void DeleteFrameBuffer( GLuint frameBufferId );
146 * @brief Get the default state of a frame buffer, before it's used
147 * @return initial state
149 unsigned int GetInitialFrameBufferState();
151 FrameBufferStateCache( const FrameBufferStateCache& ); ///< undefined copy constructor
153 FrameBufferStateCache& operator=( const FrameBufferStateCache& ); ///< undefined assignment operator
157 FrameBufferStateVector mFrameBufferStates; ///< state of the frame buffers
158 GLuint mCurrentFrameBufferId; ///< currently bound frame buffer
161 } // namespace Internal
165 #endif // __DALI_INTERNAL_CONTEXT_FRAME_BUFFER_STATE_CACHE_H__