1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SHADER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SHADER_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/internal/common/shader-data.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
36 class ConnectionObserver;
37 class SceneController;
40 * A holder class for Program; also enables sharing of uniform properties
42 class Shader : public PropertyOwner, public UniformMap::Observer
47 * @param hints Shader hints
49 Shader(Dali::Shader::Hint::Value& hints);
56 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57 // The following methods are called during Update
58 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 * Query whether a shader hint is set.
62 * @pre The shader has been initialized.
63 * @param[in] hint The hint to check.
64 * @return True if the given hint is set.
66 bool HintEnabled(Dali::Shader::Hint::Value hint) const
72 * @return True if the fragment shader outputs only 1.0 on the alpha channel
74 * @note Shaders that can output any value on the alpha channel
75 * including 1.0 should return false for this.
77 bool IsOutputOpaque();
80 * @return True if the fragment shader can output any value but 1.0 on the alpha channel
82 * @note Shaders that can output any value on the alpha channel
83 * including 1.0 should return false for this
85 bool IsOutputTransparent();
88 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties
90 virtual void ResetDefaultProperties(BufferIndex updateBufferIndex)
92 // no default properties
95 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
96 // The following methods are called during Render
97 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100 * @brief Set the shader data for this shader.
101 * @param[in] shaderData The program's vertex/fragment source and optionally pre-compiled shader binary.
103 void SetShaderData(ShaderDataPtr shaderData);
106 * Get the shader data for this shader.
107 * @return The shader data.
109 ShaderDataPtr GetShaderData() const;
111 public: // Implementation of ConnectionChangePropagator
113 * @copydoc ConnectionChangePropagator::AddObserver
115 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
118 * @copydoc ConnectionChangePropagator::RemoveObserver
120 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
122 public: // UniformMap::Observer
124 * @copydoc UniformMap::Observer::UniformMappingsChanged
126 void UniformMappingsChanged(const UniformMap& mappings) override;
129 Dali::Shader::Hint::Value mHints;
131 ShaderDataPtr mShaderData;
133 ConnectionChangePropagator mConnectionObservers;
136 inline void SetShaderDataMessage(EventThreadServices& eventThreadServices, const Shader& shader, ShaderDataPtr shaderData)
138 using LocalType = MessageValue1<Shader, ShaderDataPtr>;
140 // Reserve some memory inside the message queue
141 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
143 // Construct message in the message queue memory; note that delete should not be called on the return value
144 new(slot) LocalType(&shader, &Shader::SetShaderData, shaderData);
147 } // namespace SceneGraph
149 } // namespace Internal
153 #endif // DALI_INTERNAL_SCENE_GRAPH_SHADER_H