1 #ifndef DALI_GRAPHICS_GLES_SHADER_H
2 #define DALI_GRAPHICS_GLES_SHADER_H
5 * Copyright (c) 2024 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-shader-create-info.h>
23 #include <dali/graphics-api/graphics-shader.h>
26 #include "gles-graphics-resource.h"
28 namespace Dali::Graphics::GLES
35 * @param[in] createInfo Valid createInfo structure
36 * @param[in] controller Reference to the controller
38 ShaderImpl(const Graphics::ShaderCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
46 * @brief Increases ref count
47 * @return ref count after increment
52 * @brief Decreases refcount
53 * @return ref count after decrement
58 * @brief returns current ref count
59 * @return current ref count
61 [[nodiscard]] uint32_t GetRefCount() const;
64 * Whilst unreferenced, increase the flush count and return it
66 * @return The new flush count
68 [[nodiscard]] uint32_t IncreaseFlushCount();
71 * Get the flush count whilst unreferenced
73 * @return the flush count
75 [[nodiscard]] uint32_t GetFlushCount() const;
78 * @brief Compiles shader
80 * @return True on success
82 [[nodiscard]] bool Compile() const;
85 * @brief Destroys GL shader
90 * @brief Returns GL resource
91 * @return Valid GL shader resource
93 uint32_t GetGLShader() const;
96 * @brief Returns create info structure
97 * @return Returns valid create info structure
99 [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
102 * @brief Returns reference to the graphics controller
103 * @return Valid reference to the graphics controller
105 [[nodiscard]] EglGraphicsController& GetController() const;
108 * Strips legacy prefix fromt he GLSL source code if necessary
109 * @param info valid ShaderCreateInfo strucutre
110 * @param[out] startIndex Start index of the source code
111 * @param[out] glslVersion Detected GLSL version of legacy shader
112 * @param[out] finalDataSize Size of trimmed data
114 static void StripLegacyCodeIfNeeded(const ShaderCreateInfo& info, size_t& startIndex, uint32_t& glslVersion, size_t& finalDataSize);
117 * @brief Sets preprocess code
118 * @param[in] data Valid pointer to the new source code
119 * @param[in] size Size of the source code
121 void SetPreprocessedCode(void* data, uint32_t size);
124 * @brief Returns GLSL version
125 * @return Returns valid GLSL version or 0 if undefined
127 [[nodiscard]] uint32_t GetGLSLVersion() const;
132 std::unique_ptr<Impl> mImpl{nullptr};
135 class Shader : public Graphics::Shader
141 * @param[in] impl Pointer to valid implementation
143 explicit Shader(ShaderImpl* impl)
154 [[nodiscard]] ShaderImpl* GetImplementation() const
159 [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
161 bool operator==(const GLES::Shader& shader) const
163 return (shader.mShader == mShader);
166 bool operator==(const GLES::ShaderImpl* shaderImpl) const
168 return (shaderImpl == mShader);
171 bool operator!=(const GLES::Shader& shader) const
173 return (shader.mShader != mShader);
177 * @brief Called when UniquePtr<> on client-side dies.
179 void DiscardResource();
182 * @brief Destroying GL resources
184 * This function is kept for compatibility with Resource<> class
185 * so can the object can be use with templated functions.
187 void DestroyResource()
189 // nothing to do here
192 [[nodiscard]] uint32_t GetGLSLVersion() const;
195 ShaderImpl* mShader{nullptr};
198 } // namespace Dali::Graphics::GLES