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
100 * @brief Collection of current image visual feature. Only use for ImageVisualShaderFactory::GetShader()
102 struct FeatureBuilder
105 : mTextureAtlas(TextureAtlas::DISABLED),
106 mDefaultTextureWrapMode(DefaultTextureWrapMode::APPLY),
107 mRoundedCorner(RoundedCorner::DISABLED),
108 mBorderline(Borderline::DISABLED),
113 FeatureBuilder& EnableTextureAtlas(bool enableTextureAtlas);
114 FeatureBuilder& ApplyDefaultTextureWrapMode(bool applyDefaultTextureWrapMode);
115 FeatureBuilder& EnableRoundedCorner(bool enableRoundedCorner);
116 FeatureBuilder& EnableBorderline(bool enableBorderline);
117 FeatureBuilder& SetTextureForFragmentShaderCheck(const Dali::Texture& texture);
119 TextureAtlas::Type mTextureAtlas : 2; ///< Whether use texture with atlas, or not. default as TextureAtlas::DISABLED
120 DefaultTextureWrapMode::Type mDefaultTextureWrapMode : 2; ///< Whether apply to texture wraping in default, or not. default as DefaultTextureWrapMode::APPLY
121 RoundedCorner::Type mRoundedCorner : 2; ///< Whether use rounded corner, or not. default as RoundedCorner::DISABLED
122 Borderline::Type mBorderline : 2; ///< Whether use borderline, or not. default as Borderline::DISABLED
123 Dali::Texture mTexture; ///< Texture to check whether we need to change fragment shader or not
126 } // namespace ImageVisualShaderFactoryFeature
129 * ImageVisualShaderFactory is an object that provides and shares shaders between image visuals
131 class ImageVisualShaderFactory
138 ImageVisualShaderFactory();
143 ~ImageVisualShaderFactory();
146 * @brief Get the standard image rendering shader.
147 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
148 * @param[in] featureBuilder Collection of current image shader's features
149 * @return The standard image rendering shader with features.
151 Shader GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeature::FeatureBuilder& featureBuilder);
154 * @brief Request the default vertex shader source.
155 * @return The default vertex shader source.
157 std::string_view GetVertexShaderSource();
160 * @brief Request the default fragment shader source.
161 * @return The default fragment shader source.
163 std::string_view GetFragmentShaderSource();
167 * Undefined copy constructor.
169 ImageVisualShaderFactory(const ImageVisualShaderFactory&);
172 * Undefined assignment operator.
174 ImageVisualShaderFactory& operator=(const ImageVisualShaderFactory& rhs);
179 * @brief Cached information whether native image should change fragment shader.
180 * Default it is ChangeFragmentShader::UNDECIDED.
181 * If we have any chance to check native image source apply fragment shader,
182 * this vaule will be changed one of these : ChangeFragmentShader::DONT_CHANGE or ChangeFragmentShader::NEED_CHANGE
184 * After result cached, this value will not be changed.
186 * If value is DONT_CHANGE, ImageVisualShaderFactory::GetShader never call ApplyNativeFragmentShader.
187 * Else, ImageVisualShaderFactory::GetShader will call ApplyNativeFragmentShader if native image source texture come.
189 ImageVisualShaderFeature::ChangeFragmentShader::Type mFragmentShaderNeedChange : 3;
192 } // namespace Internal
194 } // namespace Toolkit
198 #endif // DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H