1 #ifndef DALI_GRAPHICS_GLES_CONTEXT_FRAMEBUFFER_STATE_CACHE_H
2 #define DALI_GRAPHICS_GLES_CONTEXT_FRAMEBUFFER_STATE_CACHE_H
5 * Copyright (c) 2021 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>
25 namespace Dali::Graphics
30 * @brief Keeps track of color, depth and stencil buffer state within each frame buffer.
31 * Used to avoid redundant glClear calls.
34 class FrameBufferStateCache
40 FrameBufferStateCache();
43 * @brief non-virtual destructor
45 ~FrameBufferStateCache();
48 * @brief Get the bitmask to pass to glClear based on the mask requested
49 * and the current state of the frame buffer
50 * @param[in] mask glClear bit mask
51 * @param[in] forceClear whether to force the clear ( ignore cached state)
52 * @param[in] scissorTestEnabled whether scissor test is enabled
53 * @return new bitmask to pass to glClear
55 GLbitfield GetClearMask(GLbitfield mask, bool forceClear, bool scissorTestEnabled);
58 * @brief Set the current bound frame buffer
59 * @param[in] frameBufferId frame buffer id
61 void SetCurrentFrameBuffer(GLuint frameBufferId);
64 * @brief Called when frame buffers are deleted
65 * @param[in] count number of frame buffers
66 * @param[in] framebuffers array of frame buffer ids
68 void FrameBuffersDeleted(GLsizei count, const GLuint* const frameBuffers);
71 * @brief Called when frame buffers are created
72 * @param[in] count number of frame buffers
73 * @param[in] framebuffers array of frame buffer ids
75 void FrameBuffersCreated(GLsizei count, const GLuint* const frameBuffers);
78 * @brief Draw operation performed on the current frame buffer
79 * @param[in] colorBufferUsed whether the color buffer is being written to (glColorMask )
80 * @param[in] depthBufferUsed whether the depth buffer is being written to (glDepthMask )
81 * @param[in] stencilBufferUsed whether the stencil buffer is being written to (glStencilMask )
83 void DrawOperation(bool colorBufferUsed, bool depthBufferUsed, bool stencilBufferUsed);
92 * Current status of the frame buffer
94 enum FrameBufferStatus
96 COLOR_BUFFER_CLEAN = 1 << 0, ///< color buffer clean
97 DEPTH_BUFFER_CLEAN = 1 << 1, ///< depth buffer clean
98 STENCIL_BUFFER_CLEAN = 1 << 2, ///< stencil buffer clean
102 * POD to store the status of frame buffer regarding color,depth and stencil buffers
104 struct FrameBufferState
109 FrameBufferState(GLuint id)
114 GLuint mId; ///< Frame buffer id
115 unsigned int mState; ///< State, bitmask of FrameBufferStatus flags
118 using FrameBufferStateVector = Dali::Vector<FrameBufferState>;
121 * @brief Set the clear state
122 * @param[in] pointer to frame buffer state object
123 * @param[in] mask clear mask
125 void SetClearState(FrameBufferState* state, GLbitfield mask);
129 * @param[in] frameBufferId frame buffer id
130 * @return pointer to frame buffer state object ( NULL if it doesn't exist)
132 FrameBufferState* GetFrameBufferState(GLuint frameBufferId);
135 * @brief Helper to delete a frame buffer state object
136 * @param[in] frameBufferId frame buffer id
138 void DeleteFrameBuffer(GLuint frameBufferId);
140 FrameBufferStateCache(const FrameBufferStateCache&); ///< undefined copy constructor
142 FrameBufferStateCache& operator=(const FrameBufferStateCache&); ///< undefined assignment operator
145 FrameBufferStateVector mFrameBufferStates{}; ///< state of the frame buffers
146 GLuint mCurrentFrameBufferId{0}; ///< currently bound frame buffer
151 } // namespace Dali::Graphics
153 #endif // DALI_GRAPHICS_GLES_CONTEXT_FRAMEBUFFER_STATE_CACHE_H