#define __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
/*
- * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// INTERNAL INCLUDES
-#include <dali/public-api/common/dali-vector.h>
-#include <dali/public-api/shader-effects/shader-effect.h>
-
+#include <dali/devel-api/shader-effects/shader-effect.h>
#include <dali/internal/common/shader-data.h>
-
-#include <dali/internal/common/buffer-index.h>
-#include <dali/internal/common/type-abstraction-enums.h>
-
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/event/effects/shader-declarations.h>
-
#include <dali/internal/update/common/property-owner.h>
-
-#include <dali/internal/render/gl-resources/gl-resource-owner.h>
-#include <dali/internal/render/gl-resources/texture-declarations.h>
-#include <dali/internal/render/common/render-manager.h>
+#include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
namespace Dali
{
-
-namespace Integration
-{
-typedef unsigned int ResourceId;
-} // namespace Integration
-
namespace Internal
{
class Program;
+class ProgramCache;
namespace SceneGraph
{
-class RenderQueue;
-class UniformMeta;
-class TextureCache;
-
+class ConnectionObserver;
+class SceneController;
/**
- * A base class for a collection of shader programs, to apply an effect to different geometry types.
- * This class is also the default shader so its easier to override default behaviour
+ * A holder class for Program; also enables sharing of uniform properties
*/
-class Shader : public PropertyOwner
+class Shader : public PropertyOwner, public UniformMap::Observer
{
public:
/**
* Constructor
- * @param hints Geometry hints
+ * @param hints Shader hints
*/
- Shader( Dali::ShaderEffect::GeometryHints& hints );
+ Shader( Dali::Shader::Hint::Value& hints );
/**
* Virtual destructor
*/
virtual ~Shader();
- /**
- * Second stage initialization, called when added to the UpdateManager
- * @param renderQueue Used to queue messages from update to render thread.
- * @param textureCache Used to retrieve effect textures when rendering.
- */
- void Initialize( RenderQueue& renderQueue, TextureCache& textureCache );
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// The following methods are called during UpdateManager::Update()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
- * Query whether a shader geometry hint is set.
+ * Query whether a shader hint is set.
* @pre The shader has been initialized.
- * @param[in] hint The geometry hint to check.
- * @return True if the given geometry hint is set.
+ * @param[in] hint The hint to check.
+ * @return True if the given hint is set.
*/
- bool GeometryHintEnabled( Dali::ShaderEffect::GeometryHints hint ) const
+ bool HintEnabled( Dali::Shader::Hint::Value hint ) const
{
- return mGeometryHints & hint;
- }
-
- /**
- * Retrieve the set of geometry hints.
- * @return The hints.
- */
- Dali::ShaderEffect::GeometryHints GetGeometryHints() const
- {
- return mGeometryHints;
- }
-
- /**
- * Set the geometry hints.
- * @param[in] hints The hints.
- */
- void SetGeometryHints( Dali::ShaderEffect::GeometryHints hints )
- {
- mGeometryHints = hints;
+ return mHints & hint;
}
/**
// no default properties
}
- /**
- * Set the ID used to access textures
- * @pre This method is not thread-safe, and should only be called from the update-thread.
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] textureId The texture ID.
- */
- void ForwardTextureId( BufferIndex updateBufferIndex, Integration::ResourceId textureId );
-
- /**
- * Gets the effect texture resource ID
- * This is zero if there is effect texture
- * @return the resource Id
- */
- Integration::ResourceId GetEffectTextureResourceId();
-
- /**
- * Forwards the meta data from the update thread to the render thread for actual
- * installation. (Installation is to a std::vector, which is not thread safe)
- * @sa InstallUniformMetaInRender
- * @pre This method should only be called from the update thread.
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] meta A pointer to a UniformMeta to be owned by the Shader.
- */
- void ForwardUniformMeta( BufferIndex updateBufferIndex, UniformMeta* meta );
-
- /**
- * Forwards coordinate type to render
- * @sa InstallUniformMetaInRender
- * @pre This method should only be called from the update thread.
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] index of the metadata.
- * @param[in] type the coordinate type.
- */
- void ForwardCoordinateType( BufferIndex updateBufferIndex, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type );
-
- /**
- * Forwards the grid density.
- * @pre This method is not thread-safe, and should only be called from the update thread.
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] density The grid density.
- */
- void ForwardGridDensity( BufferIndex updateBufferIndex, float density );
-
- /**
- * Forwards hints.
- * @pre This method is not thread-safe, and should only be called from the update thread.
- * @param[in] updateBufferIndex The current update buffer index.
- * @param[in] hint The geometry hints.
- */
- void ForwardHints( BufferIndex updateBufferIndex, Dali::ShaderEffect::GeometryHints hint );
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// The following methods are called in Render thread
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
- * Set the ID used to access textures
- * @pre This method is not thread-safe, and should only be called from the render thread.
- * @param[in] textureId The texture ID.
+ * @brief Set the program for this shader.
+ * @param[in] shaderData The program's vertex/fragment source and optionally precompiled shader binary.
+ * @param[in] programCache Owner of the Programs.
+ * @param[in] modifiesGeometry True if the vertex shader changes the positions of vertexes such that
+ * they might exceed the bounding box of vertexes passing through the default transformation.
*/
- void SetTextureId( Integration::ResourceId textureId );
+ void SetProgram( Internal::ShaderDataPtr shaderData,
+ ProgramCache* programCache,
+ bool modifiesGeometry );
/**
- * Get the texture id, that will be used in the next call to Shader::Apply()
- * @return textureId The texture ID
+ * Get the program built for this shader
+ * @return The program built from the shader sources.
*/
- Integration::ResourceId GetTextureIdToRender();
+ Program* GetProgram();
- /**
- * Sets grid density
- * @pre This method is not thread-safe, and should only be called from the update thread.
- * @param[in] value The grid density
- */
- void SetGridDensity(float value);
+public: // Implementation of ObjectOwnerContainer template methods
/**
- * Get the grid density ID.
- * @pre This method is not thread-safe, and should only be called from the render thread.
- * @return The grid density.
+ * Connect the object to the scene graph
+ *
+ * @param[in] sceneController The scene controller - used for sending messages to render thread
+ * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
*/
- float GetGridDensity();
+ void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
/**
- * Installs metadata related to a newly installed uniform property.
- * @pre This method is not thread-safe, and should only be called from the render-thread.
- * @param[in] meta A pointer to a UniformMeta to be owned by the Shader.
+ * Disconnect the object from the scene graph
+ * @param[in] sceneController The scene controller - used for sending messages to render thread
+ * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
*/
- void InstallUniformMetaInRender( UniformMeta* meta );
+ void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
- /**
- * Sets the uniform coordinate type
- * @param index of the uniform
- * @param type to set
- */
- void SetCoordinateTypeInRender( unsigned int index, Dali::ShaderEffect::UniformCoordinateType type );
+public: // Implementation of ConnectionChangePropagator
/**
- * @brief Set the program for this shader.
- * @param[in] shaderData The program's vertex/fragment source and optionally precompiled shader binary.
- * @param[in] programCache Owner of the Programs.
- * @param[in] modifiesGeometry True if the vertex shader changes the positions of vertexes such that
- * they might exceed the bounding box of vertexes passing through the default transformation.
+ * @copydoc ConnectionChangePropagator::AddObserver
*/
- void SetProgram( Internal::ShaderDataPtr shaderData,
- ProgramCache* programCache,
- bool modifiesGeometry );
+ void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
/**
- * Get the program built for this shader
- * @return The program built from the shader sources.
+ * @copydoc ConnectionChangePropagator::RemoveObserver
*/
- Program* GetProgram();
+ void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
+public:
+
+public: // UniformMap::Observer
/**
- * Sets the shader specific uniforms including custom uniforms
- * @pre The shader has been initialized.
- * @pre This method is not thread-safe, and should only be called from the render-thread.
- * @param[in] context The context used to render.
- * @param[in] program to use.
- * @param[in] bufferIndex The buffer to read shader properties from.
- * @param[in] type the type of the object (geometry) that is being rendered.
- * @param[in] subType Identifier for geometry types with specialised default shaders
+ * @copydoc UniformMap::Observer::UniformMappingsChanged
*/
- void SetUniforms( Context& context,
- Program& program,
- BufferIndex bufferIndex );
+ virtual void UniformMappingsChanged( const UniformMap& mappings );
private: // Data
- Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry
- float mGridDensity; ///< grid density
-
- Texture* mTexture; ///< Raw Pointer to Texture
- Integration::ResourceId mRenderTextureId; ///< Copy of the texture ID for the render thread
- Integration::ResourceId mUpdateTextureId; ///< Copy of the texture ID for update thread
+ Dali::Shader::Hint::Value mHints;
Program* mProgram;
- typedef OwnerContainer< UniformMeta* > UniformMetaContainer;
- UniformMetaContainer mUniformMetadata; ///< A container of owned UniformMeta values; one for each property in PropertyOwner::mDynamicProperties
-
- // These members are only safe to access during UpdateManager::Update()
- RenderQueue* mRenderQueue; ///< Used for queuing a message for the next Render
-
- // These members are only safe to access in render thread
- TextureCache* mTextureCache; // Used for retrieving textures in the render thread
+ ConnectionChangePropagator mConnectionObservers;
};
-// Messages for Shader, to be processed in Update thread.
-void SetTextureIdMessage( EventThreadServices& eventThreadServices, const Shader& shader, Integration::ResourceId textureId );
-void SetGridDensityMessage( EventThreadServices& eventThreadServices, const Shader& shader, float density );
-void SetHintsMessage( EventThreadServices& eventThreadServices, const Shader& shader, Dali::ShaderEffect::GeometryHints hint );
-void InstallUniformMetaMessage( EventThreadServices& eventThreadServices, const Shader& shader, UniformMeta& meta );
-void SetCoordinateTypeMessage( EventThreadServices& eventThreadServices, const Shader& shader, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type );
-
} // namespace SceneGraph
} // namespace Internal