1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
5 * Copyright (c) 2015 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/public-api/common/dali-vector.h>
23 #include <dali/public-api/shader-effects/shader-effect.h>
25 #include <dali/internal/common/shader-data.h>
27 #include <dali/internal/common/buffer-index.h>
28 #include <dali/internal/common/type-abstraction-enums.h>
30 #include <dali/internal/event/common/event-thread-services.h>
31 #include <dali/internal/event/effects/shader-declarations.h>
33 #include <dali/internal/update/common/property-owner.h>
34 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
36 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
37 #include <dali/internal/render/gl-resources/texture-declarations.h>
39 #include <dali/internal/render/common/render-manager.h>
56 class ConnectionObserver;
57 class SceneController;
60 * A base class for a collection of shader programs, to apply an effect to different geometry types.
61 * This class is also the default shader so its easier to override default behaviour
63 class Shader : public PropertyOwner, public UniformMap::Observer
69 * @param hints Geometry hints
71 Shader( Dali::ShaderEffect::GeometryHints& hints );
79 * Second stage initialization, called when added to the UpdateManager
80 * @param renderQueue Used to queue messages from update to render thread.
81 * @param textureCache Used to retrieve effect textures when rendering.
83 void Initialize( RenderQueue& renderQueue, TextureCache& textureCache );
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86 // The following methods are called during UpdateManager::Update()
87 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 * Query whether a shader geometry hint is set.
91 * @pre The shader has been initialized.
92 * @param[in] hint The geometry hint to check.
93 * @return True if the given geometry hint is set.
95 bool GeometryHintEnabled( Dali::ShaderEffect::GeometryHints hint ) const
97 return mGeometryHints & hint;
101 * Retrieve the set of geometry hints.
104 Dali::ShaderEffect::GeometryHints GetGeometryHints() const
106 return mGeometryHints;
110 * Set the geometry hints.
111 * @param[in] hints The hints.
113 void SetGeometryHints( Dali::ShaderEffect::GeometryHints hints )
115 mGeometryHints = hints;
119 * @return True if the fragment shader outputs only 1.0 on the alpha channel
121 * @note Shaders that can output any value on the alpha channel
122 * including 1.0 should return false for this.
124 bool IsOutputOpaque();
127 * @return True if the fragment shader can output any value but 1.0 on the alpha channel
129 * @note Shaders that can output any value on the alpha channel
130 * including 1.0 should return false for this
132 bool IsOutputTransparent();
135 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties
137 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex )
139 // no default properties
142 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
143 // The following methods are called in Render thread
144 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
147 * @brief Set the program for this shader.
148 * @param[in] shaderData The program's vertex/fragment source and optionally precompiled shader binary.
149 * @param[in] programCache Owner of the Programs.
150 * @param[in] modifiesGeometry True if the vertex shader changes the positions of vertexes such that
151 * they might exceed the bounding box of vertexes passing through the default transformation.
153 void SetProgram( Internal::ShaderDataPtr shaderData,
154 ProgramCache* programCache,
155 bool modifiesGeometry );
158 * Get the program built for this shader
159 * @return The program built from the shader sources.
161 Program* GetProgram();
163 public: // Implementation of ObjectOwnerContainer template methods
166 * Connect the object to the scene graph
168 * @param[in] sceneController The scene controller - used for sending messages to render thread
169 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
171 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
174 * Disconnect the object from the scene graph
175 * @param[in] sceneController The scene controller - used for sending messages to render thread
176 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
178 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
180 public: // Implementation of ConnectionChangePropagator
183 * @copydoc ConnectionChangePropagator::AddObserver
185 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
188 * @copydoc ConnectionChangePropagator::RemoveObserver
190 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
194 public: // UniformMap::Observer
196 * @copydoc UniformMap::Observer::UniformMappingsChanged
198 virtual void UniformMappingsChanged( const UniformMap& mappings );
202 Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry
203 float mGridDensity; ///< grid density
205 Texture* mTexture; ///< Raw Pointer to Texture
206 Integration::ResourceId mRenderTextureId; ///< Copy of the texture ID for the render thread
207 Integration::ResourceId mUpdateTextureId; ///< Copy of the texture ID for update thread
211 ConnectionChangePropagator mConnectionObservers;
213 // These members are only safe to access during UpdateManager::Update()
214 RenderQueue* mRenderQueue; ///< Used for queuing a message for the next Render
216 // These members are only safe to access in render thread
217 TextureCache* mTextureCache; // Used for retrieving textures in the render thread
220 } // namespace SceneGraph
222 } // namespace Internal
226 #endif // __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__