1 #ifndef DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H
2 #define DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_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.
23 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
24 #include <string_view>
34 * ImageVisualShaderFeature contains feature lists what image visual shader need to know.
36 namespace ImageVisualShaderFeature
38 namespace TextureAtlas
41 * @brief Whether use texture with atlas, or not
45 DISABLED = 0, ///< Image visual doesn't use ATLAS
46 ENABLED ///< Image visual uses ATLAS
48 } // namespace TextureAtlas
50 namespace DefaultTextureWrapMode
53 * @brief Whether apply to texture wraping in default, or not
57 APPLY = 0, ///< Image visual applies to wraping texture in default
58 DO_NOT_APPLY ///< Image visual doesn't apply to wraping texture in default
60 } // namespace DefaultTextureWrapMode
62 namespace RoundedCorner
65 * @brief Whether use rounded corner, or not
69 DISABLED = 0, ///< Image visual doesn't use rounded corner
70 ENABLED ///< Image visual uses rounded corner
72 } // namespace RoundedCorner
77 * @brief Whether use borderline, or not
81 DISABLED = 0, ///< Image visual doesn't use borderline
82 ENABLED ///< Image visual uses borderline
84 } // namespace Borderline
86 namespace ChangeFragmentShader
89 * @brief Whether native image change the default fragment shader, or not
93 DONT_CHANGE = 0, ///< Native image doesn't change default fragment shader.
94 NEED_CHANGE, ///< Native image changes default fragment shader. We need another shader cache.
95 UNDECIDED, ///< Undecided.
97 } // namespace ChangeFragmentShader
99 namespace AlphaMaskingOnRendering
102 * @brief Whether use runtime alpha masking in shader, or not
106 DISABLED = 0, ///< Image visual doesn't use runtime alpha masking
107 ENABLED ///< Image visual uses runtime alpha masking
109 } // namespace AlphaMaskingOnRendering
112 * @brief Collection of current image visual feature. Only use for ImageVisualShaderFactory::GetShader()
114 struct FeatureBuilder
117 : mTextureAtlas(TextureAtlas::DISABLED),
118 mDefaultTextureWrapMode(DefaultTextureWrapMode::APPLY),
119 mRoundedCorner(RoundedCorner::DISABLED),
120 mBorderline(Borderline::DISABLED),
121 mAlphaMaskingOnRendering(AlphaMaskingOnRendering::DISABLED),
126 FeatureBuilder& EnableTextureAtlas(bool enableTextureAtlas);
127 FeatureBuilder& ApplyDefaultTextureWrapMode(bool applyDefaultTextureWrapMode);
128 FeatureBuilder& EnableRoundedCorner(bool enableRoundedCorner);
129 FeatureBuilder& EnableBorderline(bool enableBorderline);
130 FeatureBuilder& SetTextureForFragmentShaderCheck(const Dali::Texture& texture);
131 FeatureBuilder& EnableAlphaMaskingOnRendering(bool enableAlphaMaskingOnRendering);
133 TextureAtlas::Type mTextureAtlas : 2; ///< Whether use texture with atlas, or not. default as TextureAtlas::DISABLED
134 DefaultTextureWrapMode::Type mDefaultTextureWrapMode : 2; ///< Whether apply to texture wraping in default, or not. default as DefaultTextureWrapMode::APPLY
135 RoundedCorner::Type mRoundedCorner : 2; ///< Whether use rounded corner, or not. default as RoundedCorner::DISABLED
136 Borderline::Type mBorderline : 2; ///< Whether use borderline, or not. default as Borderline::DISABLED
137 AlphaMaskingOnRendering::Type mAlphaMaskingOnRendering : 2; ///< Whether use runtime alpha masking, or not. default as AlphaMaskingOnRendering::DISABLED
138 Dali::Texture mTexture; ///< Texture to check whether we need to change fragment shader or not
141 } // namespace ImageVisualShaderFeature
144 * ImageVisualShaderFactory is an object that provides and shares shaders between image visuals
146 class ImageVisualShaderFactory
153 ImageVisualShaderFactory();
158 ~ImageVisualShaderFactory();
161 * @brief Get the standard image rendering shader.
162 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
163 * @param[in] featureBuilder Collection of current image shader's features
164 * @return The standard image rendering shader with features.
166 Shader GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeature::FeatureBuilder& featureBuilder);
169 * @brief Request the default vertex shader source.
170 * @return The default vertex shader source.
172 std::string_view GetVertexShaderSource();
175 * @brief Request the default fragment shader source.
176 * @return The default fragment shader source.
178 std::string_view GetFragmentShaderSource();
182 * Undefined copy constructor.
184 ImageVisualShaderFactory(const ImageVisualShaderFactory&);
187 * Undefined assignment operator.
189 ImageVisualShaderFactory& operator=(const ImageVisualShaderFactory& rhs);
194 * @brief Cached information whether native image should change fragment shader.
195 * Default it is ChangeFragmentShader::UNDECIDED.
196 * If we have any chance to check native image source apply fragment shader,
197 * this vaule will be changed one of these : ChangeFragmentShader::DONT_CHANGE or ChangeFragmentShader::NEED_CHANGE
199 * After result cached, this value will not be changed.
201 * If value is DONT_CHANGE, ImageVisualShaderFactory::GetShader never call ApplyNativeFragmentShader.
202 * Else, ImageVisualShaderFactory::GetShader will call ApplyNativeFragmentShader if native image source texture come.
204 ImageVisualShaderFeature::ChangeFragmentShader::Type mFragmentShaderNeedChange : 3;
207 } // namespace Internal
209 } // namespace Toolkit
213 #endif // DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H