1 #ifndef DALI_INTERNAL_RENDER_SHADER_H
2 #define DALI_INTERNAL_RENDER_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 SceneController;
39 * A holder class for Program; also enables sharing of uniform properties
41 class Shader : public PropertyOwner, public UniformMap::Observer
46 * @param hints Shader hints
48 explicit Shader(Dali::Shader::Hint::Value& hints);
56 * Query whether a shader hint is set.
58 * @warning This method is called from Update Algorithms.
60 * @pre The shader has been initialized.
61 * @param[in] hint The hint to check.
62 * @return True if the given hint is set.
64 [[nodiscard]] bool HintEnabled(Dali::Shader::Hint::Value hint) const
70 * @brief Set the shader data for this shader.
71 * @param[in] shaderData The program's vertex/fragment source and optionally pre-compiled shader binary.
73 void SetShaderData(ShaderDataPtr shaderData);
76 * Get the shader data for this shader.
77 * @return The shader data.
79 [[nodiscard]] ShaderDataPtr GetShaderData() const;
83 * @copydoc ConnectionChangePropagator::AddObserver
85 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
88 * @copydoc ConnectionChangePropagator::RemoveObserver
90 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
92 public: // UniformMap::Observer
94 * @copydoc UniformMap::Observer::UniformMappingsChanged
96 void UniformMappingsChanged(const UniformMap& mappings) override;
99 Dali::Shader::Hint::Value mHints;
101 ShaderDataPtr mShaderData;
103 ConnectionChangePropagator mConnectionObservers;
106 inline void SetShaderDataMessage(EventThreadServices& eventThreadServices, const Shader& shader, ShaderDataPtr shaderData)
108 using LocalType = MessageValue1<Shader, ShaderDataPtr>;
110 // Reserve some memory inside the message queue
111 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
113 // Construct message in the message queue memory; note that delete should not be called on the return value
114 new(slot) LocalType(&shader, &Shader::SetShaderData, shaderData);
117 } // namespace SceneGraph
119 } // namespace Internal
123 #endif // DALI_INTERNAL_RENDER_SHADER_H