Dali 3D User Interface Engine
List of all members | Public Member Functions | Private Types | Private Attributes
Dali::Internal::SceneGraph::Shader Class Reference

A base class for a collection of shader programs, to apply an effect to different geometry types. More...

#include <scene-graph-shader.h>

Inheritance diagram for Dali::Internal::SceneGraph::Shader:
Inheritance graph
[legend]
Collaboration diagram for Dali::Internal::SceneGraph::Shader:
Collaboration graph
[legend]

Public Member Functions

 Shader (Dali::ShaderEffect::GeometryHints &hints)
 Constructor. More...
 
virtual ~Shader ()
 Virtual destructor. More...
 
void Initialize (RenderQueue &renderQueue, TextureCache &textureCache)
 Second stage initialization, called when added to the UpdateManager. More...
 
bool GeometryHintEnabled (Dali::ShaderEffect::GeometryHints hint) const
 Query whether a shader geometry hint is set. More...
 
Dali::ShaderEffect::GeometryHints GetGeometryHints () const
 Retrieve the set of geometry hints. More...
 
void SetGeometryHints (Dali::ShaderEffect::GeometryHints hints)
 Set the geometry hints. More...
 
bool IsOutputOpaque ()
 
bool IsOutputTransparent ()
 
virtual void ResetDefaultProperties (BufferIndex updateBufferIndex)
 Called after ResetToBaseValues; derived classes should reset any default properties. More...
 
void ForwardTextureId (BufferIndex updateBufferIndex, Integration::ResourceId textureId)
 Set the ID used to access textures. More...
 
Integration::ResourceId GetEffectTextureResourceId ()
 Gets the effect texture resource ID This is zero if there is effect texture. More...
 
void ForwardUniformMeta (BufferIndex updateBufferIndex, UniformMeta *meta)
 Forwards the meta data from the update thread to the render thread for actual installation. More...
 
void ForwardCoordinateType (BufferIndex updateBufferIndex, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type)
 Forwards coordinate type to render. More...
 
void ForwardGridDensity (BufferIndex updateBufferIndex, float density)
 Forwards the grid density. More...
 
void ForwardHints (BufferIndex updateBufferIndex, Dali::ShaderEffect::GeometryHints hint)
 Forwards hints. More...
 
void SetTextureId (Integration::ResourceId textureId)
 Set the ID used to access textures. More...
 
Integration::ResourceId GetTextureIdToRender ()
 Get the texture id, that will be used in the next call to Shader::Apply() More...
 
void SetGridDensity (float value)
 Sets grid density. More...
 
float GetGridDensity ()
 Get the grid density ID. More...
 
void InstallUniformMetaInRender (UniformMeta *meta)
 Installs metadata related to a newly installed uniform property. More...
 
void SetCoordinateTypeInRender (unsigned int index, Dali::ShaderEffect::UniformCoordinateType type)
 Sets the uniform coordinate type. More...
 
void SetProgram (Internal::ShaderDataPtr shaderData, ProgramCache *programCache, bool modifiesGeometry)
 Set the program for this shader. More...
 
ProgramGetProgram ()
 Get the program built for this shader. More...
 
void SetUniforms (Context &context, Program &program, BufferIndex bufferIndex)
 Sets the shader specific uniforms including custom uniforms. More...
 
- Public Member Functions inherited from Dali::Internal::SceneGraph::PropertyOwner
virtual ~PropertyOwner ()
 Virtual destructor; this is intended as a base class. More...
 
void AddObserver (Observer &observer)
 Add an observer. More...
 
void RemoveObserver (Observer &observer)
 Remove an observer. More...
 
bool IsObserved ()
 This method can be used to determine if there is an animation or constraint that is using this property owner. More...
 
void Destroy ()
 Called just before destruction to disconnect all observers and remove constraints. More...
 
void ConnectToSceneGraph ()
 Notify all observers that the object has been connected This occurs when the object is connected to the scene-graph during UpdateManager::Update(). More...
 
void DisconnectFromSceneGraph (BufferIndex updateBufferIndex)
 Notify all observers that the object has been disconnected and remove constraints. More...
 
void InstallCustomProperty (PropertyBase *property)
 Install a custom property. More...
 
OwnedPropertyContainerGetCustomProperties ()
 Retrieve the custom properties owned by the object. More...
 
const OwnedPropertyContainerGetCustomProperties () const
 Retrieve the custom properties owned by the object. More...
 
void ResetToBaseValues (BufferIndex updateBufferIndex)
 Reset animatable properties to the corresponding base values. More...
 
void ApplyConstraint (ConstraintBase *constraint)
 Apply a constraint. More...
 
void RemoveConstraint (ConstraintBase *constraint)
 Begin removal of constraints. More...
 
ConstraintOwnerContainerGetConstraints ()
 Retrieve the constraints that are currently applied. More...
 
virtual void AddUniformMapping (UniformPropertyMapping *map)
 Add a map to the mappings table. More...
 
virtual void RemoveUniformMapping (const std::string &uniformName)
 Remove a map from the mappings table. More...
 
const UniformMapGetUniformMap () const
 Get the mappings table. More...
 
void AddUniformMapObserver (UniformMap::Observer &observer)
  More...
 
void RemoveUniformMapObserver (UniformMap::Observer &observer)
  More...
 

Private Types

typedef OwnerContainer
< UniformMeta * > 
UniformMetaContainer
 

Private Attributes

Dali::ShaderEffect::GeometryHints mGeometryHints
 shader geometry hints for building the geometry More...
 
float mGridDensity
 grid density More...
 
TexturemTexture
 Raw Pointer to Texture. More...
 
Integration::ResourceId mRenderTextureId
 Copy of the texture ID for the render thread. More...
 
Integration::ResourceId mUpdateTextureId
 Copy of the texture ID for update thread. More...
 
ProgrammProgram
 
UniformMetaContainer mUniformMetadata
 A container of owned UniformMeta values; one for each property in PropertyOwner::mDynamicProperties. More...
 
RenderQueuemRenderQueue
 Used for queuing a message for the next Render. More...
 
TextureCachemTextureCache
 

Additional Inherited Members

- Static Public Member Functions inherited from Dali::Internal::SceneGraph::PropertyOwner
static PropertyOwnerNew ()
 Create a property owner. More...
 
- Protected Member Functions inherited from Dali::Internal::SceneGraph::PropertyOwner
 PropertyOwner ()
 Protected constructor. More...
 
- Protected Attributes inherited from Dali::Internal::SceneGraph::PropertyOwner
OwnedPropertyContainer mCustomProperties
 Properties provided with InstallCustomProperty() More...
 
UniformMap mUniformMaps
 Container of owned uniform maps. More...
 

Detailed Description

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

Definition at line 59 of file scene-graph-shader.h.

Member Typedef Documentation

Definition at line 276 of file scene-graph-shader.h.

Constructor & Destructor Documentation

Dali::Internal::SceneGraph::Shader::Shader ( Dali::ShaderEffect::GeometryHints hints)

Constructor.

Parameters
hintsGeometry hints

Definition at line 76 of file scene-graph-shader.cpp.

Dali::Internal::SceneGraph::Shader::~Shader ( )
virtual

Virtual destructor.

Definition at line 88 of file scene-graph-shader.cpp.

Member Function Documentation

void Dali::Internal::SceneGraph::Shader::ForwardCoordinateType ( BufferIndex  updateBufferIndex,
unsigned int  index,
Dali::ShaderEffect::UniformCoordinateType  type 
)

Forwards coordinate type to render.

See Also
InstallUniformMetaInRender
Precondition
This method should only be called from the update thread.
Parameters
[in]updateBufferIndexThe current update buffer index.
[in]indexof the metadata.
[in]typethe coordinate type.

Definition at line 133 of file scene-graph-shader.cpp.

References mRenderQueue, Dali::Internal::SceneGraph::RenderQueue::ReserveMessageSlot(), and SetCoordinateTypeInRender().

Referenced by Dali::Internal::SceneGraph::SetCoordinateTypeMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::ForwardGridDensity ( BufferIndex  updateBufferIndex,
float  density 
)

Forwards the grid density.

Precondition
This method is not thread-safe, and should only be called from the update thread.
Parameters
[in]updateBufferIndexThe current update buffer index.
[in]densityThe grid density.

Definition at line 145 of file scene-graph-shader.cpp.

References mRenderQueue, Dali::Internal::SceneGraph::RenderQueue::ReserveMessageSlot(), and SetGridDensity().

Referenced by Dali::Internal::SceneGraph::SetGridDensityMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::ForwardHints ( BufferIndex  updateBufferIndex,
Dali::ShaderEffect::GeometryHints  hint 
)

Forwards hints.

Precondition
This method is not thread-safe, and should only be called from the update thread.
Parameters
[in]updateBufferIndexThe current update buffer index.
[in]hintThe geometry hints.

Definition at line 156 of file scene-graph-shader.cpp.

References mRenderQueue, Dali::Internal::SceneGraph::RenderQueue::ReserveMessageSlot(), and SetGeometryHints().

Referenced by Dali::Internal::SceneGraph::SetHintsMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::ForwardTextureId ( BufferIndex  updateBufferIndex,
Integration::ResourceId  textureId 
)

Set the ID used to access textures.

Precondition
This method is not thread-safe, and should only be called from the update-thread.
Parameters
[in]updateBufferIndexThe current update buffer index.
[in]textureIdThe texture ID.

Definition at line 102 of file scene-graph-shader.cpp.

References mRenderQueue, mUpdateTextureId, Dali::Internal::SceneGraph::RenderQueue::ReserveMessageSlot(), and SetTextureId().

Referenced by Dali::Internal::SceneGraph::SetTextureIdMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::ForwardUniformMeta ( BufferIndex  updateBufferIndex,
UniformMeta meta 
)

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)

See Also
InstallUniformMetaInRender
Precondition
This method should only be called from the update thread.
Parameters
[in]updateBufferIndexThe current update buffer index.
[in]metaA pointer to a UniformMeta to be owned by the Shader.

Definition at line 120 of file scene-graph-shader.cpp.

References InstallUniformMetaInRender(), mRenderQueue, and Dali::Internal::SceneGraph::RenderQueue::ReserveMessageSlot().

Referenced by Dali::Internal::SceneGraph::InstallUniformMetaMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Dali::Internal::SceneGraph::Shader::GeometryHintEnabled ( Dali::ShaderEffect::GeometryHints  hint) const
inline

Query whether a shader geometry hint is set.

Precondition
The shader has been initialized.
Parameters
[in]hintThe geometry hint to check.
Returns
True if the given geometry hint is set.

Definition at line 91 of file scene-graph-shader.h.

References mGeometryHints.

Referenced by Dali::Internal::SceneGraph::AddRendererToRenderList(), and Dali::Internal::SceneGraph::Material::Prepare().

Here is the caller graph for this function:

Integration::ResourceId Dali::Internal::SceneGraph::Shader::GetEffectTextureResourceId ( )

Gets the effect texture resource ID This is zero if there is effect texture.

Returns
the resource Id

Definition at line 115 of file scene-graph-shader.cpp.

References mUpdateTextureId.

Dali::ShaderEffect::GeometryHints Dali::Internal::SceneGraph::Shader::GetGeometryHints ( ) const
inline

Retrieve the set of geometry hints.

Returns
The hints.

Definition at line 100 of file scene-graph-shader.h.

References mGeometryHints.

float Dali::Internal::SceneGraph::Shader::GetGridDensity ( )

Get the grid density ID.

Precondition
This method is not thread-safe, and should only be called from the render thread.
Returns
The grid density.

Definition at line 190 of file scene-graph-shader.cpp.

References mGridDensity.

Program * Dali::Internal::SceneGraph::Shader::GetProgram ( )

Get the program built for this shader.

Returns
The program built from the shader sources.

Definition at line 216 of file scene-graph-shader.cpp.

References mProgram.

Referenced by Dali::Internal::Render::Renderer::Render().

Here is the caller graph for this function:

Integration::ResourceId Dali::Internal::SceneGraph::Shader::GetTextureIdToRender ( )

Get the texture id, that will be used in the next call to Shader::Apply()

Returns
textureId The texture ID

Definition at line 180 of file scene-graph-shader.cpp.

References mRenderTextureId.

void Dali::Internal::SceneGraph::Shader::Initialize ( RenderQueue renderQueue,
TextureCache textureCache 
)

Second stage initialization, called when added to the UpdateManager.

Parameters
renderQueueUsed to queue messages from update to render thread.
textureCacheUsed to retrieve effect textures when rendering.

Definition at line 92 of file scene-graph-shader.cpp.

References mRenderQueue, and mTextureCache.

Referenced by Dali::Internal::SceneGraph::UpdateManager::AddShader().

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::InstallUniformMetaInRender ( UniformMeta meta)

Installs metadata related to a newly installed uniform property.

Precondition
This method is not thread-safe, and should only be called from the render-thread.
Parameters
[in]metaA pointer to a UniformMeta to be owned by the Shader.

Definition at line 195 of file scene-graph-shader.cpp.

References mUniformMetadata, and Dali::Vector< T, IsTrivialType >::PushBack().

Referenced by ForwardUniformMeta().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Dali::Internal::SceneGraph::Shader::IsOutputOpaque ( )
Returns
True if the fragment shader outputs only 1.0 on the alpha channel
Note
Shaders that can output any value on the alpha channel including 1.0 should return false for this.
bool Dali::Internal::SceneGraph::Shader::IsOutputTransparent ( )
Returns
True if the fragment shader can output any value but 1.0 on the alpha channel
Note
Shaders that can output any value on the alpha channel including 1.0 should return false for this
virtual void Dali::Internal::SceneGraph::Shader::ResetDefaultProperties ( BufferIndex  updateBufferIndex)
inlinevirtual

Called after ResetToBaseValues; derived classes should reset any default properties.

Parameters
[in]currentBufferIndexThe buffer to reset.

Reimplemented from Dali::Internal::SceneGraph::PropertyOwner.

Definition at line 133 of file scene-graph-shader.h.

void Dali::Internal::SceneGraph::Shader::SetCoordinateTypeInRender ( unsigned int  index,
Dali::ShaderEffect::UniformCoordinateType  type 
)

Sets the uniform coordinate type.

Parameters
indexof the uniform
typeto set

Definition at line 200 of file scene-graph-shader.cpp.

References Dali::VectorBase::Count(), DALI_ASSERT_DEBUG, and mUniformMetadata.

Referenced by ForwardCoordinateType().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::SetGeometryHints ( Dali::ShaderEffect::GeometryHints  hints)
inline

Set the geometry hints.

Parameters
[in]hintsThe hints.

Definition at line 109 of file scene-graph-shader.h.

References mGeometryHints.

Referenced by ForwardHints().

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::SetGridDensity ( float  value)

Sets grid density.

Precondition
This method is not thread-safe, and should only be called from the update thread.
Parameters
[in]valueThe grid density

Definition at line 185 of file scene-graph-shader.cpp.

References mGridDensity.

Referenced by ForwardGridDensity().

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::SetProgram ( Internal::ShaderDataPtr  shaderData,
ProgramCache programCache,
bool  modifiesGeometry 
)

Set the program for this shader.

Parameters
[in]shaderDataThe program's vertex/fragment source and optionally precompiled shader binary.
[in]programCacheOwner of the Programs.
[in]modifiesGeometryTrue if the vertex shader changes the positions of vertexes such that they might exceed the bounding box of vertexes passing through the default transformation.

Definition at line 206 of file scene-graph-shader.cpp.

References DALI_LOG_TRACE_METHOD_FMT, mProgram, and Dali::Internal::Program::New().

Referenced by Dali::Internal::SceneGraph::UpdateManager::SetShaderProgram().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::SetTextureId ( Integration::ResourceId  textureId)

Set the ID used to access textures.

Precondition
This method is not thread-safe, and should only be called from the render thread.
Parameters
[in]textureIdThe texture ID.

Definition at line 171 of file scene-graph-shader.cpp.

References mRenderTextureId, and mTexture.

Referenced by ForwardTextureId().

Here is the caller graph for this function:

void Dali::Internal::SceneGraph::Shader::SetUniforms ( Context context,
Program program,
BufferIndex  bufferIndex 
)

Sets the shader specific uniforms including custom uniforms.

Precondition
The shader has been initialized.
This method is not thread-safe, and should only be called from the render-thread.
Parameters
[in]contextThe context used to render.
[in]programto use.
[in]bufferIndexThe buffer to read shader properties from.
[in]typethe type of the object (geometry) that is being rendered.
[in]subTypeIdentifier for geometry types with specialised default shaders

Convert coordinates from viewport to GL view space

Viewport coordinate (0,0) +--—+ | | | | +--—+ (width,height)

GL view space coordinates (width/2,-height/2) +--—+ | | | | +--—+ (-width/2,height/2)

Definition at line 221 of file scene-graph-shader.cpp.

References Dali::Internal::Texture::ApplySampler(), Dali::Property::ARRAY, Dali::Matrix3::AsFloat(), Dali::Matrix::AsFloat(), Dali::Internal::SceneGraph::TextureCache::BindTexture(), Dali::Property::BOOLEAN, Dali::Internal::SceneGraph::UniformMeta::cacheIndex, Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT, Dali::ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION, Dali::ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION, Dali::Internal::SceneGraph::UniformMeta::coordinateType, Dali::VectorBase::Count(), DALI_ASSERT_DEBUG, DALI_LOG_ERROR, DALI_PRINT_CUSTOM_UNIFORM, DALI_PRINT_SHADER_UNIFORMS, DALI_PRINT_UNIFORM, Dali::FilterMode::DEFAULT, Dali::Property::FLOAT, Dali::Internal::SceneGraph::TextureCache::GetTexture(), Dali::Internal::Program::GetUniformLocation(), Dali::Internal::Context::GetViewport(), GL_TEXTURE_2D, Dali::Rect< T >::height, Dali::Property::INTEGER, Dali::Property::MAP, Dali::Property::MATRIX, Dali::Property::MATRIX3, mRenderTextureId, mTexture, mTextureCache, mUniformMetadata, Dali::Internal::SceneGraph::UniformMeta::name, Dali::Property::NONE, Dali::Internal::ImageSampler::PackBitfield(), Dali::Internal::SceneGraph::UniformMeta::property, Dali::Property::RECTANGLE, Dali::Internal::Program::RegisterUniform(), Dali::Property::ROTATION, Dali::Internal::Program::SetUniform1f(), Dali::Internal::Program::SetUniform1i(), Dali::Internal::Program::SetUniform2f(), Dali::Internal::Program::SetUniform3f(), Dali::Internal::Program::SetUniform4f(), Dali::Internal::Program::SetUniformMatrix3fv(), Dali::Internal::Program::SetUniformMatrix4fv(), Dali::Property::STRING, Dali::Internal::TEXTURE_UNIT_SHADER, Dali::Internal::Program::UNIFORM_EFFECT_SAMPLER, Dali::Internal::Program::UNIFORM_UNKNOWN, Dali::Property::VECTOR2, Dali::Property::VECTOR3, Dali::Property::VECTOR4, Dali::Rect< T >::width, Dali::Rect< T >::x, Dali::Vector4::y, and Dali::Vector3::y.

Here is the call graph for this function:

Member Data Documentation

Dali::ShaderEffect::GeometryHints Dali::Internal::SceneGraph::Shader::mGeometryHints
private

shader geometry hints for building the geometry

Definition at line 267 of file scene-graph-shader.h.

Referenced by GeometryHintEnabled(), GetGeometryHints(), and SetGeometryHints().

float Dali::Internal::SceneGraph::Shader::mGridDensity
private

grid density

Definition at line 268 of file scene-graph-shader.h.

Referenced by GetGridDensity(), and SetGridDensity().

Program* Dali::Internal::SceneGraph::Shader::mProgram
private

Definition at line 274 of file scene-graph-shader.h.

Referenced by GetProgram(), and SetProgram().

RenderQueue* Dali::Internal::SceneGraph::Shader::mRenderQueue
private

Used for queuing a message for the next Render.

Definition at line 280 of file scene-graph-shader.h.

Referenced by ForwardCoordinateType(), ForwardGridDensity(), ForwardHints(), ForwardTextureId(), ForwardUniformMeta(), and Initialize().

Integration::ResourceId Dali::Internal::SceneGraph::Shader::mRenderTextureId
private

Copy of the texture ID for the render thread.

Definition at line 271 of file scene-graph-shader.h.

Referenced by GetTextureIdToRender(), SetTextureId(), and SetUniforms().

Texture* Dali::Internal::SceneGraph::Shader::mTexture
private

Raw Pointer to Texture.

Definition at line 270 of file scene-graph-shader.h.

Referenced by SetTextureId(), and SetUniforms().

TextureCache* Dali::Internal::SceneGraph::Shader::mTextureCache
private

Definition at line 283 of file scene-graph-shader.h.

Referenced by Initialize(), and SetUniforms().

UniformMetaContainer Dali::Internal::SceneGraph::Shader::mUniformMetadata
private

A container of owned UniformMeta values; one for each property in PropertyOwner::mDynamicProperties.

Definition at line 277 of file scene-graph-shader.h.

Referenced by InstallUniformMetaInRender(), SetCoordinateTypeInRender(), and SetUniforms().

Integration::ResourceId Dali::Internal::SceneGraph::Shader::mUpdateTextureId
private

Copy of the texture ID for update thread.

Definition at line 272 of file scene-graph-shader.h.

Referenced by ForwardTextureId(), and GetEffectTextureResourceId().


The documentation for this class was generated from the following files:
Dali Docs Home
Read more about Dali