1 #ifndef DALI_GRAPHICS_GLES_PIPELINE_H
2 #define DALI_GRAPHICS_GLES_PIPELINE_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/graphics-api/graphics-pipeline-create-info.h>
23 #include <dali/graphics-api/graphics-pipeline.h>
27 #include "gles-graphics-resource.h"
29 namespace Dali::Graphics::GLES
31 using PipelineResource = Resource<Graphics::Pipeline, Graphics::PipelineCreateInfo>;
34 * @brief PipelineWrapper is the object
35 * returned to the client-side
42 * @param[in] createInfo valid TextureCreateInfo structure
43 * @param[in] controller Reference to the Controller
45 PipelineImpl(const Graphics::PipelineCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
53 * @brief Destroys all the low-level resources used by the class
55 void DestroyResource();
58 * @brief Initializes low-level resources
60 * @return Tron success
62 bool InitializeResource();
65 * @brief Discards object
67 void DiscardResource();
70 * @brief returns GL program id
71 * @return GL program id
73 [[nodiscard]] uint32_t GetGLProgram() const;
76 * @brief Binds pipeline
78 * Binds Pipeline by binding GL program and flushing state.
80 * If previous pipeline specified, it will be used in order to
81 * avoid redundant state swiches.
83 * @param[in] prevPipeline previous pipeline
85 void Bind(GLES::PipelineImpl* prevPipeline);
88 * Executes state change function if condition met
90 template<typename FUNC, typename STATE>
91 void ExecuteStateChange(FUNC& func, const STATE* prevPipelineState, const STATE* thisPipelineState)
93 if(!prevPipelineState)
99 // binary test and execute when different
100 if(memcmp(prevPipelineState, thisPipelineState, sizeof(STATE)) != 0)
111 [[nodiscard]] uint32_t GetRefCount() const;
113 [[nodiscard]] const PipelineCreateInfo& GetCreateInfo() const;
115 [[nodiscard]] auto& GetController() const;
119 * @brief Helper function. Copies state if pointer is set
122 void CopyStateIfSet(const T* sourceState, T& copyState, T** destState)
124 *destState = nullptr;
127 copyState = *sourceState;
128 *destState = ©State;
133 * @brief Helper function. Copies const state if pointer is set
136 void CopyStateIfSet(const T* sourceState, T& copyState, const T** destState)
138 *destState = nullptr;
141 copyState = *sourceState;
142 *destState = ©State;
146 // Pipeline state is stored as a copy of create info
148 struct PipelineState;
149 std::unique_ptr<PipelineState> mPipelineState;
151 EglGraphicsController& mController;
152 PipelineCreateInfo mCreateInfo;
154 uint32_t mGlProgram{0u};
156 uint32_t mRefCount{0u};
160 * @brief Pipeline class wraps a unique pipeline object
163 class Pipeline : public Graphics::Pipeline
168 explicit Pipeline(GLES::PipelineImpl& pipeline)
169 : mPipeline(pipeline)
181 [[nodiscard]] auto& GetPipeline() const
186 [[nodiscard]] const PipelineCreateInfo& GetCreateInfo() const;
188 [[nodiscard]] EglGraphicsController& GetController() const;
191 GLES::PipelineImpl& mPipeline;
194 } // namespace Dali::Graphics::GLES