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>;
33 class Pipeline : public PipelineResource
38 * @param[in] createInfo valid TextureCreateInfo structure
39 * @param[in] controller Reference to the Controller
41 Pipeline(const Graphics::PipelineCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
44 * @brief Destroys all the low-level resources used by the class
46 void DestroyResource() override;
49 * @brief Initializes low-level resources
51 * @return Tron success
53 bool InitializeResource() override;
56 * @brief Discards object
58 void DiscardResource() override;
61 * @brief returns GL program id
62 * @return GL program id
64 [[nodiscard]] uint32_t GetGLProgram() const;
67 * @brief Binds pipeline
69 * Binds Pipeline by binding GL program and flushing state.
71 * If previous pipeline specified, it will be used in order to
72 * avoid redundant state swiches.
74 * @param[in] prevPipeline previous pipeline
76 void Bind(GLES::Pipeline* prevPipeline);
79 * Executes state change function if condition met
81 template<typename FUNC, typename STATE>
82 void ExecuteStateChange(FUNC& func, const STATE* prevPipelineState, const STATE* thisPipelineState)
84 if(!prevPipelineState)
90 // binary test and execute when different
91 if(memcmp(prevPipelineState, thisPipelineState, sizeof(STATE)) != 0)
100 * @brief Helper function. Copies state if pointer is set
103 void CopyStateIfSet(const T* sourceState, T& copyState, T** destState)
105 *destState = nullptr;
108 copyState = *sourceState;
109 *destState = ©State;
114 * @brief Helper function. Copies const state if pointer is set
117 void CopyStateIfSet(const T* sourceState, T& copyState, const T** destState)
119 *destState = nullptr;
122 copyState = *sourceState;
123 *destState = ©State;
127 // Pipeline state is stored as a copy of create info
129 struct PipelineState;
130 std::unique_ptr<PipelineState> mPipelineState{};
132 uint32_t mGlProgram{0u};
135 } // namespace Dali::Graphics::GLES