1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
5 * Copyright (c) 2018 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/graphics-api/graphics-api-controller.h>
23 #include <dali/graphics-api/graphics-api-accessor.h>
24 #include <dali/graphics-api/graphics-api-shader.h>
26 #include <dali/integration-api/graphics/graphics.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/common/shader-data.h>
30 #include <dali/internal/event/common/event-thread-services.h>
31 #include <dali/internal/update/common/property-owner.h>
32 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
33 #include <dali/internal/update/rendering/shader-cache.h>
43 class ConnectionObserver;
44 class SceneController;
47 * Owner of Graphics Shader; also enables sharing of uniform properties.
48 * Owned by UpdateManager.
50 class Shader : public PropertyOwner, public UniformMap::Observer
56 * @param hints Shader hints
58 Shader( Dali::Shader::Hint::Value& hints );
66 * Initialize the shader object with the Graphics API when added to UpdateManager
68 * @param[in] graphics The Graphics API
69 * @param[in] shaderCache A cache
71 void Initialize( Integration::Graphics::Graphics& graphics, ShaderCache& shaderCache );
74 * Query whether a shader hint is set.
75 * @pre The shader has been initialized.
76 * @param[in] hint The hint to check.
77 * @return True if the given hint is set.
79 bool HintEnabled( Dali::Shader::Hint::Value hint ) const
85 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties
87 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex )
89 // no default properties
93 * Get the graphics shader object
94 * @return the graphics shader object
96 Graphics::API::Accessor<Graphics::API::Shader>& GetGfxObject();
100 * Set the shader data into the graphics API.
102 * @param[in] shaderData The shader source or binary.
103 * @param[in] modifiesGeometry Hint to say if the shader modifies geometry. (useful for culling)
105 void SetShaderProgram( Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
107 public: // Implementation of ConnectionChangePropagator
110 * @copydoc ConnectionChangePropagator::AddObserver
112 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
115 * @copydoc ConnectionChangePropagator::RemoveObserver
117 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
119 public: // UniformMap::Observer
121 * @copydoc UniformMap::Observer::UniformMappingsChanged
123 virtual void UniformMappingsChanged( const UniformMap& mappings );
127 Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
128 Graphics::API::Accessor<Graphics::API::Shader> mGraphicsShader; ///< The graphics object
129 ShaderCache* mShaderCache;
130 Dali::Shader::Hint::Value mHints; ///< Hints for the shader
131 ConnectionChangePropagator mConnectionObservers; ///< Watch for connection changes
135 inline void SetShaderProgramMessage( EventThreadServices& eventThreadServices,
137 Internal::ShaderDataPtr shaderData,
138 bool modifiesGeometry )
140 typedef MessageValue2< Shader, Internal::ShaderDataPtr, bool > LocalType;
142 // Reserve some memory inside the message queue
143 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
145 // Construct message in the message queue memory; note that delete should not be called on the return value
146 new (slot) LocalType( &shader, &Shader::SetShaderProgram, shaderData, modifiesGeometry );
151 } // namespace SceneGraph
153 } // namespace Internal
157 #endif // __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__