BufferImage img = BufferImage::New( 1,1 );
ImageActor actor = ImageActor::New( img );
- ShaderEffect effect = ShaderEffect::New( " ", " ", GEOMETRY_TYPE_IMAGE, ShaderEffect::HINT_GRID );
+ ShaderEffect effect = ShaderEffect::New( " ", " ", ShaderEffect::HINT_GRID );
actor.SetShaderEffect( effect );
const float INVALID_SIZE = float(1u<<31);
programMap.SetValue("vertex-prefix", vertexShaderPrefix);
programMap.SetValue("fragment-prefix", fragmentShaderPrefix);
- programMap.SetValue("geometry-type", "GEOMETRY_TYPE_IMAGE");
-
effect.SetProperty(effect.GetPropertyIndex("program"), programMap);
Property::Value imageMap = Property::Value(Property::MAP);
int UtcDaliShaderEffectFromProperties02(void)
{
- try
- {
- TestApplication application;
- tet_infoline("UtcDaliShaderEffectFromProperties02()");
+ TestApplication application;
+ tet_infoline("UtcDaliShaderEffectFromProperties02()");
// Call render to compile default shaders.
application.SendNotification();
programMap.SetValue("vertex", std::string(VertexSource));
programMap.SetValue("fragment", std::string(FragmentSource));
- // programMap.SetValue("geometry-type", "GEOMETRY_TYPE_IMAGE");
- // dont set by value
- programMap.SetValue("geometry-type", GeometryType( GEOMETRY_TYPE_IMAGE ));
-
- effect.SetProperty(effect.GetPropertyIndex("program"), programMap);
+ effect.SetProperty(effect.GetPropertyIndex("program"), programMap);
- tet_result( TET_FAIL );
- }
- catch(Dali::DaliException& e)
- {
- DALI_TEST_PRINT_ASSERT( e );
- }
END_TEST;
}
template <> struct ParameterType< CullFaceMode > : public BasicType< CullFaceMode > {};
template <> struct ParameterType< BlendingMode::Type > : public BasicType< BlendingMode::Type > {};
-template <> struct ParameterType< GeometryType > : public BasicType< GeometryType > {};
-template <> struct ParameterType< ShaderSubTypes > : public BasicType< ShaderSubTypes > {};
} //namespace Internal
namespace Internal
{
-/**
- * Shader sub types.
- */
-enum ShaderSubTypes
-{
- SHADER_DEFAULT = 0, ///< Use default shader for geometry type
- SHADER_SUBTYPE_LAST,
-
- SHADER_SUBTYPE_ALL = 0xFF,
-};
-
class ShaderEffect;
typedef IntrusivePtr<ShaderEffect> ShaderEffectPtr;
const char* fragmentShaderPostfix;
};
-WrapperStrings customShaderWrappers [] =
+WrapperStrings customImageShaderWrappers =
{
- {
- CustomImagePrefixVertex, CustomImagePrefixFragment,
- CustomImagePostfixVertex, CustomImagePostfixFragment
- },
- {
- CustomUntexturedMeshPrefixVertex, CustomUntexturedMeshPrefixFragment,
- CustomUntexturedMeshPostfixVertex, CustomUntexturedMeshPostfixFragment
- },
- {
- CustomTexturedMeshPrefixVertex, CustomTexturedMeshPrefixFragment,
- CustomTexturedMeshPostfixVertex, CustomTexturedMeshPostfixFragment
- }
+ CustomImagePrefixVertex, CustomImagePrefixFragment,
+ CustomImagePostfixVertex, CustomImagePostfixFragment
};
/**
* Helper to wrap the program with our default pre and postfix if needed and then send it to update/render thread
* @param[in] effect of the shader
- * @param[in] actualGeometryType of the shader
- * @param[in] expectedGeometryType of the shader
* @param[in] vertexPrefix from application
* @param[in] fragmentPrefix from application
* @param[in] vertexBody from application
* @param[in] modifiesGeometry based on flags and vertex shader
*/
void WrapAndSetProgram( Internal::ShaderEffect& effect,
- GeometryType actualGeometryType, GeometryType expectedGeometryType,
const std::string& vertexPrefix, const std::string& fragmentPrefix,
const std::string& vertexBody, const std::string& fragmentBody,
bool modifiesGeometry )
{
- // if geometry type matches and there is some real data in the strings
- if( ( actualGeometryType & expectedGeometryType )&&
- ( ( vertexPrefix.length() > 0 )||
- ( fragmentPrefix.length() > 0 )||
- ( vertexBody.length() > 0 )||
- ( fragmentBody.length() > 0 ) ) )
+ // if there is some real data in the strings
+ if( ( vertexPrefix.length() > 0 ) ||
+ ( fragmentPrefix.length() > 0 ) ||
+ ( vertexBody.length() > 0 ) ||
+ ( fragmentBody.length() > 0 ) )
{
std::string vertexSource = vertexPrefix;
std::string fragmentSource = fragmentPrefix;
- // create complete shader program strings for the given geometry type
- unsigned int index = 0;
- switch( expectedGeometryType )
- {
- case GEOMETRY_TYPE_IMAGE:
- {
- index = 0;
- break;
- }
- case GEOMETRY_TYPE_UNTEXTURED_MESH:
- {
- index = 1;
- break;
- }
- case GEOMETRY_TYPE_TEXTURED_MESH:
- {
- index = 2;
- break;
- }
- case GEOMETRY_TYPE_LAST:
- {
- DALI_ASSERT_DEBUG(0 && "Wrong geometry type");
- break;
- }
- }
+ // Create complete shader program strings:
+
+ vertexSource += customImageShaderWrappers.vertexShaderPrefix;
- vertexSource += customShaderWrappers[index].vertexShaderPrefix;
// Append the custom vertex shader code if supplied, otherwise append the default
if ( vertexBody.length() > 0 )
{
}
else
{
- vertexSource.append( customShaderWrappers[index].vertexShaderPostfix );
+ vertexSource.append( customImageShaderWrappers.vertexShaderPostfix );
}
- fragmentSource += customShaderWrappers[index].fragmentShaderPrefix;
+ fragmentSource += customImageShaderWrappers.fragmentShaderPrefix;
+
// Append the custom fragment shader code if supplied, otherwise append the default
if ( fragmentBody.length() > 0 )
{
}
else
{
- fragmentSource.append( customShaderWrappers[index].fragmentShaderPostfix );
+ fragmentSource.append( customImageShaderWrappers.fragmentShaderPostfix );
}
- effect.SendProgramMessage( expectedGeometryType, vertexSource, fragmentSource, modifiesGeometry );
+ effect.SendProgramMessage( vertexSource, fragmentSource, modifiesGeometry );
}
}
}
}
-void ShaderEffect::SetPrograms( GeometryType geometryType, const string& vertexSource, const string& fragmentSource )
+void ShaderEffect::SetPrograms( const string& vertexSource, const string& fragmentSource )
{
- SetPrograms( geometryType, "", "", vertexSource, fragmentSource );
+ SetPrograms( "", "", vertexSource, fragmentSource );
}
-void ShaderEffect::SetPrograms( GeometryType geometryType,
- const std::string& vertexPrefix, const std::string& fragmentPrefix,
+void ShaderEffect::SetPrograms( const std::string& vertexPrefix, const std::string& fragmentPrefix,
const std::string& vertexSource, const std::string& fragmentSource )
{
bool modifiesGeometry = true;
// check if the vertex shader is empty (means it cannot modify geometry)
- if( (vertexPrefix.length() == 0 )&&( vertexSource.length() == 0 ) )
+ if( (vertexPrefix.length() == 0) && (vertexSource.length() == 0) )
{
modifiesGeometry = false;
}
// check the hint second
- if( (mGeometryHints & Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY ) != 0 )
+ if( ( mGeometryHints & Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY ) != 0 )
{
modifiesGeometry = false;
}
- WrapAndSetProgram( *this, geometryType, GEOMETRY_TYPE_IMAGE, vertexPrefix, fragmentPrefix, vertexSource, fragmentSource, modifiesGeometry );
- WrapAndSetProgram( *this, geometryType, GEOMETRY_TYPE_TEXTURED_MESH, vertexPrefix, fragmentPrefix, vertexSource, fragmentSource, modifiesGeometry );
- WrapAndSetProgram( *this, geometryType, GEOMETRY_TYPE_UNTEXTURED_MESH, vertexPrefix, fragmentPrefix, vertexSource, fragmentSource, modifiesGeometry );
+ WrapAndSetProgram( *this, vertexPrefix, fragmentPrefix, vertexSource, fragmentSource, modifiesGeometry );
}
-void ShaderEffect::SendProgramMessage( GeometryType geometryType,
- const string& vertexSource, const string& fragmentSource,
+void ShaderEffect::SendProgramMessage( const string& vertexSource, const string& fragmentSource,
bool modifiesGeometry )
{
ThreadLocalStorage& tls = ThreadLocalStorage::Get();
ResourceTicketPtr ticket( shaderFactory.Load(vertexSource, fragmentSource, shaderHash) );
- DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "ShaderEffect: SetProgram(geometryType %d ticket.id:%d)\n", geometryType, ticket->GetId() );
+ DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "ShaderEffect: SetProgram(ticket.id:%d)\n", ticket->GetId() );
// Add shader program to scene-object using a message to the UpdateManager
- SetShaderProgramMessage( mEventThreadServices.GetUpdateManager(), *mSceneObject, geometryType, ticket->GetId(), shaderHash, modifiesGeometry );
+ SetShaderProgramMessage( mEventThreadServices.GetUpdateManager(), *mSceneObject, ticket->GetId(), shaderHash, modifiesGeometry );
mTickets.push_back(ticket); // add ticket to collection to keep it alive.
}
std::string vertex = GetShader("vertex", propertyValue);
std::string fragment = GetShader("fragment", propertyValue);
- GeometryType geometryType = GEOMETRY_TYPE_IMAGE;
-
- if( propertyValue.HasKey("geometry-type") )
- {
- Property::Value geometryValue = propertyValue.GetValue("geometry-type");
- DALI_ASSERT_ALWAYS(geometryValue.GetType() == Property::STRING && "Geometry type is not a string" );
-
- std::string s = geometryValue.Get<std::string>();
- if(s == "GEOMETRY_TYPE_IMAGE")
- {
- geometryType = GEOMETRY_TYPE_IMAGE;
- }
- else if( s == "GEOMETRY_TYPE_UNTEXTURED_MESH")
- {
- geometryType = GEOMETRY_TYPE_UNTEXTURED_MESH;
- }
- else if( s == "GEOMETRY_TYPE_TEXTURED_MESH")
- {
- geometryType = GEOMETRY_TYPE_TEXTURED_MESH;
- }
- else
- {
- DALI_ASSERT_ALWAYS(!"Geometry type unknown" );
- }
- }
- SetPrograms( geometryType, vertexPrefix, fragmentPrefix, vertex, fragment );
+ SetPrograms( vertexPrefix, fragmentPrefix, vertex, fragment );
break;
}
* @param[in] vertexSource The source code for the vertex shader
* @param[in] fragmentSource The source code for the fragment shader
*/
- void SetPrograms( GeometryType geometryType, const std::string& vertexSource, const std::string& fragmentSource );
+ void SetPrograms( const std::string& vertexSource, const std::string& fragmentSource );
/**
- * Add a GeometryType specific default program to this ShaderEffect.
+ * Add a default program to this ShaderEffect.
* This overload allows the optional prefixing for both the vertex and fragment shader.
* A useful prefix may be shader \#defines for conditional compilation.
- * @param[in] geometryType The GeometryType rendered by the shader program
* @param[in] vertexPrefix The prefix source code for the vertex shader
* @param[in] fragmentPrefix The prefix source code for the fragment shader
* @param[in] vertexSource The source code for the vertex shader
* @param[in] fragmentSource The source code for the fragment shader
*/
- void SetPrograms( GeometryType geometryType,
- const std::string& vertexPrefix, const std::string& fragmentPrefix,
+ void SetPrograms( const std::string& vertexPrefix, const std::string& fragmentPrefix,
const std::string& vertexSource, const std::string& fragmentSource );
/**
* Send shader program to scene-graph object.
- * @param[in] geometryType The GeometryType rendered by the shader program
* @param[in] vertexSource The source code for the vertex shader
* @param[in] fragmentSource The source code for the fragment shader
* @param[in] modifiesGeometry True if the shader modifies geometry
*/
- void SendProgramMessage( GeometryType geometryType,
- const std::string& vertexSource, const std::string& fragmentSource,
+ void SendProgramMessage( const std::string& vertexSource, const std::string& fragmentSource,
bool modifiesGeometry );
/**
{
mDefaultShader = ShaderEffect::New();
- mDefaultShader->SendProgramMessage( GEOMETRY_TYPE_IMAGE, ImageVertex, ImageFragment, false );
+ mDefaultShader->SendProgramMessage( ImageVertex, ImageFragment, false );
}
} // namespace Internal
mTicket = ResourceTicketPtr( shaderFactory.Load(vertexSource, fragmentSource, shaderHash) );
// Add shader program to scene-object using a message to the UpdateManager
- SetShaderProgramMessage( updateManager, *mSceneObject, GEOMETRY_TYPE_IMAGE, mTicket->GetId(), shaderHash, false );
+ SetShaderProgramMessage( updateManager, *mSceneObject, mTicket->GetId(), shaderHash, false );
}
Shader::~Shader()
return true;
}
-void NewRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
-{
- // @todo MESH_REWORK Remove after merge
-
- // Do nothing
-}
-
bool NewRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
{
// @todo MESH_REWORK Add clipping
return false;
}
-void NewRenderer::DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType )
+void NewRenderer::DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex )
{
// Do nothing, we're going to set up the uniforms with our own code instead
}
virtual bool CheckResources();
/**
- * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
- */
- virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
- GeometryType& outType,
- ShaderSubTypes& outSubType );
-
- /**
* @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
*/
virtual bool IsOutsideClipSpace( Context& context,
/**
* @copydoc SceneGraph::Renderer::DoSetUniforms()
*/
- virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
+ virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex );
/**
* @copydoc SceneGraph::Renderer::DoSetCullFaceMode
return true;
}
-void ImageRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
-{
- outType = GEOMETRY_TYPE_IMAGE;
- outSubType = SHADER_DEFAULT;
-}
-
bool ImageRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
{
context.IncrementRendererCount();
virtual bool CheckResources();
/**
- * @copydoc Dali::Internal::SceneGraph::Renderer::ResolveGeometryTypes()
- */
- virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType );
-
- /**
* @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
*/
virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
const Matrix& modelMatrix = mDataProvider.GetModelMatrix( bufferIndex );
Matrix::Multiply( gModelViewProjectionMatrix, modelViewMatrix, projectionMatrix );
- // Get the program to use
- GeometryType geometryType=GEOMETRY_TYPE_IMAGE;
- ShaderSubTypes subType=SHADER_DEFAULT;
- ResolveGeometryTypes( bufferIndex, geometryType, subType );
- unsigned int programIndex = 0;
- Program* program = mShader->GetProgram( context, geometryType, subType, programIndex );
+ // Get the program to use:
+ Program* program = mShader->GetProgram();
if( !program )
{
// if program is NULL it means this is a custom shader with non matching geometry type so we need to use default shaders program
- program = defaultShader.GetProgram( context, geometryType, subType, programIndex );
- DALI_ASSERT_ALWAYS( program && "Default shader is missing a geometry type!!" );
+ program = defaultShader.GetProgram();
+ DALI_ASSERT_DEBUG( program && "Default shader should always have a program available." );
+ if( !program )
+ {
+ DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*) &*mShader );
+ return;
+ }
+
}
// Check culling (does not need the program to be in use)
}
//@todo MESH_REWORK Remove after removing ImageRenderer
- DoSetUniforms(context, bufferIndex, mShader, program, programIndex, subType );
+ DoSetUniforms(context, bufferIndex, mShader, program );
// subclass rendering and actual draw call
DoRender( context, textureCache, bufferIndex, *program, modelViewMatrix, viewMatrix );
}
// can be overridden by deriving class
-void Renderer::DoSetUniforms(Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType )
+void Renderer::DoSetUniforms(Context& context, BufferIndex bufferIndex, Shader* shader, Program* program )
{
- shader->SetUniforms( context, *program, bufferIndex, programIndex, subType );
+ shader->SetUniforms( context, *program, bufferIndex );
}
// can be overridden by deriving class
virtual bool CheckResources() = 0;
/**
- * @deprecated - Not needed in final MESH_REWORK
- * @todo MESH_REWORK Remove this API
- *
- * Resolve the derived renderers geometry type and subtype
- * @param[in] bufferIndex The index of the previous update buffer.
- * @param[out] outType The geometry type
- * @param[out] outSubType The geometry subtype
- */
- virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType ) = 0;
-
- /**
* Checks if renderer is culled.
* @param[in] modelMatrix The model matrix.
* @param[in] modelViewProjectionMatrix The MVP matrix.
* Called from Render prior to DoRender().
* @todo MESH_REWORK Remove after merge
*/
- virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
+ virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program );
/**
* Called from Render prior to DoRender(). Default method to set CullFaceMode
+++ /dev/null
-<VertexShader>
-
-uniform mediump mat4 uProjection;
-uniform mediump mat4 uModelView;
-uniform mediump mat4 uMvpMatrix;
-
-uniform bool uTextureMapped;
-uniform mediump vec4 uCustomTextureCoords;
-attribute highp vec2 aTexCoord;
-varying mediump vec2 vTexCoord;
-
-uniform mat3 uModelViewIT;
-attribute mediump vec3 aNormal;
-varying mediump vec3 vNormal;
-
-attribute mediump vec3 aPosition;
-varying mediump vec4 vVertex;
-
-#define MAX_BONES_PER_MESH 12
-
-#ifdef USE_BONES
-uniform int uBoneCount;
-uniform mediump mat4 uBoneMatrices[MAX_BONES_PER_MESH];
-uniform mediump mat3 uBoneMatricesIT[MAX_BONES_PER_MESH];
-attribute mediump vec4 aBoneWeights;
-attribute mediump vec4 aBoneIndices;
-#endif
-
-void main()
-{
- mediump vec4 vertexPosition = vec4(aPosition, 1.0);
-
-#ifdef USE_BONES
- if(uBoneCount > 0)
- {
- mediump vec4 boneWeights = aBoneWeights;
- mediump ivec4 boneIndices = ivec4(aBoneIndices);
- mediump vec3 vertexNormal;
-
- // re-calculate the final weight
- boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
-
- mediump vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
- bonePos += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
- bonePos += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
- bonePos += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
-
- vertexNormal = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
- vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
- vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
- vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
- vertexNormal = normalize(vertexNormal);
-
- vertexPosition = uProjection * bonePos;
- vVertex = bonePos;
- vNormal = vertexNormal;
- }
- else
- {
-#endif
- vertexPosition = uMvpMatrix * vec4(aPosition, 1.0);
- vVertex = uModelView * vec4(aPosition, 1.0);
- vNormal = uModelViewIT * aNormal;
-#ifdef USE_BONES
- }
-#endif
- gl_Position = vertexPosition;
-
- mediump vec2 start = uCustomTextureCoords.xy;
- mediump vec2 scale = uCustomTextureCoords.zw;
- vTexCoord = vec2(start.x + aTexCoord.x * scale.x, start.y + aTexCoord.y * scale.y);
-}
-
-</VertexShader>
-
-<FragmentShader>
-
-struct Material
-{
- mediump float mOpacity;
- mediump float mShininess;
- lowp vec4 mAmbient;
- lowp vec4 mDiffuse;
- lowp vec4 mSpecular;
- lowp vec4 mEmissive;
-};
-
-uniform sampler2D sTexture;
-uniform sampler2D sOpacityTexture;
-uniform sampler2D sNormalMapTexture;
-uniform sampler2D sEffect;
-varying mediump vec2 vTexCoord;
-
-uniform Material uMaterial;
-
-uniform lowp vec4 uColor;
-varying highp vec4 vVertex;
-varying highp vec3 vNormal;
-
-void main()
-{
- // sample the texture for the initial color
- mediump vec4 fragColor = texture2D(sTexture, vTexCoord);
-
- // apply material properties
- fragColor.rgb *= (uMaterial.mAmbient + uMaterial.mDiffuse).rgb;
-
- // apply material alpha/opacity to alpha channel
- fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
-
- // and finally, apply Actor color
- fragColor *= uColor;
-
- gl_FragColor = fragColor;
-}
-
-</FragmentShader>
+++ /dev/null
-<VertexShader>
-uniform mediump mat4 uProjection;
-uniform mediump mat4 uModelView;
-uniform mediump mat4 uMvpMatrix;
-
-uniform bool uTextureMapped;
-uniform mediump vec4 uCustomTextureCoords;
-attribute mediump vec2 aTexCoord;
-varying mediump vec2 vTexCoord;
-
-uniform mat3 uModelViewIT;
-attribute mediump vec3 aNormal;
-varying mediump vec3 vNormal;
-
-attribute mediump vec3 aPosition;
-varying mediump vec4 vVertex;
-#define USE_NORMALS
-#define MAX_BONES_PER_MESH 12
-
-#ifdef USE_BONES
-uniform int uBoneCount;
-uniform mediump mat4 uBoneMatrices[MAX_BONES_PER_MESH];
-uniform mediump mat3 uBoneMatricesIT[MAX_BONES_PER_MESH];
-attribute mediump vec4 aBoneWeights;
-attribute mediump vec4 aBoneIndices;
-#endif
-
-#ifdef USE_COLOR
-attribute lowp vec3 aColor;
-varying mediump vec3 vColor;
-#endif
-
-void main()
-{
- mediump vec4 vertexPosition = vec4(aPosition, 1.0);
-
-#ifdef USE_BONES
- if(uBoneCount > 0)
- {
- mediump vec4 boneWeights = aBoneWeights;
- mediump ivec4 boneIndices = ivec4(aBoneIndices);
- mediump vec3 vertexNormal;
-
- // re-calculate the final weight
- boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
-
- mediump vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
- bonePos += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
- bonePos += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
- bonePos += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
-
- vertexNormal = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
- vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
- vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
- vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
- vertexNormal = normalize(vertexNormal);
-
- vertexPosition = uProjection * bonePos;
- vVertex = bonePos;
- vNormal = vertexNormal;
- }
- else
- {
-#endif
- vertexPosition = uMvpMatrix * vec4(aPosition, 1.0);
- vVertex = uModelView * vec4(aPosition, 1.0);
- vNormal = uModelViewIT * aNormal;
-#ifdef USE_BONES
- }
-#endif
- gl_Position = vertexPosition;
-
-#ifdef USE_COLOR
- vColor = aColor;
-#endif
-}
-
-</VertexShader>
-
-<FragmentShader>
-
-struct Material
-{
- mediump float mOpacity;
- mediump float mShininess;
- lowp vec4 mAmbient;
- lowp vec4 mDiffuse;
- lowp vec4 mSpecular;
- lowp vec4 mEmissive;
-};
-
-uniform sampler2D sTexture;
-uniform sampler2D sOpacityTexture;
-uniform sampler2D sNormalMapTexture;
-uniform sampler2D sEffect;
-varying mediump vec2 vTexCoord;
-
-uniform Material uMaterial;
-
-uniform lowp vec4 uColor;
-varying highp vec4 vVertex;
-varying highp vec3 vNormal;
-
-#ifdef USE_COLOR
-varying mediump vec3 vColor;
-#endif
-
-void main()
-{
-#ifdef USE_COLOR
-
- // set initial color to vertex color
- mediump vec4 fragColor = vec4(vColor, 1.0);
-
-#else
-
- // set initial color to material color
- mediump vec4 fragColor = uMaterial.mAmbient + uMaterial.mDiffuse;
-
-#endif
-
- // apply material alpha/opacity to alpha channel
- fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
-
- // and finally, apply Actor color
- fragColor *= uColor;
-
- gl_FragColor = fragColor;
-}
-
-</FragmentShader>
namespace SceneGraph
{
-namespace // unnamed namespace
-{
-
-// Convert Geometry type bitmask to an array index
-inline unsigned int GetGeometryTypeIndex(GeometryType type)
-{
- unsigned int index = Log<GEOMETRY_TYPE_IMAGE>::value;
- if ( type & GEOMETRY_TYPE_IMAGE )
- {
- index = Log<GEOMETRY_TYPE_IMAGE>::value;
- }
- else if ( type & GEOMETRY_TYPE_UNTEXTURED_MESH )
- {
- index = Log<GEOMETRY_TYPE_UNTEXTURED_MESH>::value;
- }
- else if ( type & GEOMETRY_TYPE_TEXTURED_MESH )
- {
- index = Log<GEOMETRY_TYPE_TEXTURED_MESH>::value;
- }
- return index;
-}
-
-} // unnamed namespace
-
-
Shader::Shader( Dali::ShaderEffect::GeometryHints& hints )
: mGeometryHints( hints ),
mGridDensity( Dali::ShaderEffect::DEFAULT_GRID_DENSITY ),
mUniformMetadata[ index ]->SetCoordinateType( type );
}
-void Shader::SetProgram( GeometryType geometryType,
- Integration::ResourceId resourceId,
+void Shader::SetProgram( Integration::ResourceId resourceId,
Integration::ShaderDataPtr shaderData,
ProgramCache* programCache,
bool modifiesGeometry )
DALI_LOG_TRACE_METHOD_FMT(Debug::Filter::gShader, "%d\n", resourceId);
mProgram = Program::New( *programCache, shaderData, modifiesGeometry );
- // Implement: mProgram = programCache->GetProgram( shaderData, modifiesGeometry );
// The program cache owns the Program object so we don't need to worry here.
}
-bool Shader::AreSubtypesRequired(GeometryType geometryType)
-{
- DALI_ASSERT_DEBUG(geometryType < GEOMETRY_TYPE_LAST);
- return false;
-}
-
-Program* Shader::GetProgram( Context& context,
- GeometryType type,
- ShaderSubTypes subType,
- unsigned int& programIndex )
-{
- DALI_ASSERT_DEBUG(type < GEOMETRY_TYPE_LAST);
- DALI_DEBUG_OSTREAM(debugStream);
-
- return mProgram;
-}
-
Program* Shader::GetProgram()
{
return mProgram;
}
-
void Shader::SetUniforms( Context& context,
Program& program,
- BufferIndex bufferIndex,
- unsigned int programIndex,
- ShaderSubTypes subType )
+ BufferIndex bufferIndex )
{
- DALI_ASSERT_DEBUG( programIndex < Log<GEOMETRY_TYPE_LAST>::value );
- DALI_DEBUG_OSTREAM(debugStream);
-
if( mRenderTextureId && ( mTexture == NULL ) )
{
mTexture = mTextureCache->GetTexture( mRenderTextureId );
if ( metadata.name.length() > 0 )
{
// 0 means program has not got a cache index for this uniform
- if( 0 == metadata.cacheIndeces[ programIndex ][ subType ] )
+ if( 0 == metadata.cacheIndex )
{
// register cacheindex for this program
- metadata.cacheIndeces[ programIndex ][ subType ] = program.RegisterUniform( metadata.name );
+ metadata.cacheIndex = program.RegisterUniform( metadata.name );
}
- loc = program.GetUniformLocation( metadata.cacheIndeces[ programIndex ][ subType ] );
+ loc = program.GetUniformLocation( metadata.cacheIndex );
// if we find uniform with location
if ( Program::UNIFORM_UNKNOWN != loc )
/**
* @brief Set the program for a geometry type.
- * @param[in] geometryType The type of the object (geometry) that is to be rendered.
* @param[in] resourceId The resource ID for the program.
* @param[in] shaderData The program's vertex/fragment source and optionally compiled bytecode
* @param[in] programCache Owner of the Programs
- * @param[in] modifiesGeometry True if the vertex shader changes geometry
+ * @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 SetProgram( /** @deprecated This is currently ignored and will soon disappear. */
- GeometryType geometryType,
- Integration::ResourceId resourceId,
+ void SetProgram( Integration::ResourceId resourceId,
Integration::ShaderDataPtr shaderData,
ProgramCache* programCache,
bool modifiesGeometry );
/**
- * Determine if subtypes are required for the given geometry type
- * @deprecated
- * @param[in] geometryType The type of the object (geometry) that is to be rendered.
- * @return TRUE if subtypes are required, FALSE if there is only one subtype available
- */
- bool AreSubtypesRequired(GeometryType geometryType);
-
- /**
- * Get the program associated with the given type and subtype
- * @deprecated
- * @param[in] context the context used to render.
- * @param[in] type the type of the object (geometry) that is being rendered.
- * @param[in] subType Identifier for geometry types with specialised default shaders
- * @param[out] programIndex returns the program index to be passed onto SetUniforms.
- * @return the program to use.
- */
- Program* GetProgram( Context& context,
- GeometryType type,
- ShaderSubTypes subType,
- unsigned int& programIndex );
-
- /**
* Get the program built for this shader
- * @deprecated
- * @return the program to use.
+ * @return The program built from the shader sources.
*/
Program* GetProgram();
*/
void SetUniforms( Context& context,
Program& program,
- BufferIndex bufferIndex,
- unsigned int programIndex,
- ShaderSubTypes subType = SHADER_DEFAULT );
+ BufferIndex bufferIndex );
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
UniformMeta( const UniformMeta& meta )
: name( meta.name ),
property( meta.property ),
+ cacheIndex( meta.cacheIndex ),
coordinateType( meta.coordinateType )
{
- memcpy( cacheIndeces, meta.cacheIndeces, sizeof(cacheIndeces) );
}
/**
UniformMeta( const std::string& uniformName, const PropertyBase& prop, Dali::ShaderEffect::UniformCoordinateType coordType )
: name( uniformName ),
property( prop ),
+ cacheIndex( 0 ),
coordinateType( coordType )
{
- memset( cacheIndeces, 0, sizeof(cacheIndeces) );
}
// Undefined
std::string name; ///< name of uniform to set/animate
const PropertyBase& property; ///< reference to the corresponding property
- unsigned int cacheIndeces[ Log<GEOMETRY_TYPE_LAST>::value ][ SHADER_SUBTYPE_LAST ]; ///< internal program cache index, per program
+ unsigned int cacheIndex; ///< internal program cache index
Dali::ShaderEffect::UniformCoordinateType coordinateType; ///< The coordinate type of the uniform
+
};
} // namespace SceneGraph
DALI_ASSERT_DEBUG(false);
}
-void UpdateManager::SetShaderProgram( Shader* shader, GeometryType geometryType, ResourceId resourceId, size_t shaderHash, bool modifiesGeometry )
+void UpdateManager::SetShaderProgram( Shader* shader,
+ ResourceId resourceId, size_t shaderHash, bool modifiesGeometry )
{
- DALI_LOG_TRACE_METHOD_FMT(Debug::Filter::gShader, " - (geometryType:%d id:%d hash:%d)\n", geometryType, resourceId, shaderHash);
+ DALI_LOG_TRACE_METHOD_FMT(Debug::Filter::gShader, " - (id:%d hash:%d)\n", resourceId, shaderHash);
DALI_ASSERT_ALWAYS( NULL != shader && "shader is uninitialized" );
shaderData->SetHashValue( shaderHash );
shaderData->SetResourceId( resourceId );
- typedef MessageValue5< Shader, GeometryType, Integration::ResourceId, Integration::ShaderDataPtr, ProgramCache*, bool> DerivedType;
+ typedef MessageValue4< Shader, Integration::ResourceId, Integration::ShaderDataPtr, ProgramCache*, bool> DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( shader, &Shader::SetProgram, geometryType, resourceId, shaderData, mImpl->renderManager.GetProgramCache(), modifiesGeometry );
+ new (slot) DerivedType( shader, &Shader::SetProgram, resourceId, shaderData, mImpl->renderManager.GetProgramCache(), modifiesGeometry );
}
}
void RemoveShader(Shader* shader);
/**
- * Set the shader program for a specified GeometryType to a Shader object
+ * Set the shader program for a Shader object
* @param[in] shader The shader to modify
- * @param[in] geometryType The GeometryType to map to the program
* @param[in] resourceId A ResourceManager ticket ID for the program data (source and compiled binary)
* @param[in] shaderHash hash key created with vertex and fragment shader code
* @param[in] modifiesGeometry True if the vertex shader modifies geometry
*/
- void SetShaderProgram( Shader* shader, GeometryType geometryType, Integration::ResourceId resourceId, size_t shaderHash, bool modifiesGeometry );
+ void SetShaderProgram( Shader* shader, Integration::ResourceId resourceId, size_t shaderHash, bool modifiesGeometry );
/**
* Add a newly created gesture.
inline void SetShaderProgramMessage( UpdateManager& manager,
Shader& shader,
- GeometryType geometryType,
Integration::ResourceId resourceId,
size_t shaderHash,
bool modifiesGeometry )
{
- typedef MessageValue5< UpdateManager, Shader*, GeometryType, Integration::ResourceId, size_t, bool > LocalType;
+ typedef MessageValue4< UpdateManager, Shader*, Integration::ResourceId, size_t, bool > LocalType;
// Reserve some memory inside the message queue
unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
// Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, geometryType, resourceId, shaderHash, modifiesGeometry );
+ new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, resourceId, shaderHash, modifiesGeometry );
}
inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
return *this;
}
-ShaderEffect ShaderEffect::New( const std::string& vertexShader, const std::string& fragmentShader, GeometryType type, GeometryHints hints)
+ShaderEffect ShaderEffect::New( const std::string& vertexShader, const std::string& fragmentShader, GeometryHints hints)
{
// @todo MESH_REWORK - Assert only image geometry type is passed.
Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New( hints );
- internal->SetPrograms( type, vertexShader, fragmentShader );
+ internal->SetPrograms( vertexShader, fragmentShader );
return ShaderEffect( internal.Get() );
}
const std::string& vertexShader,
const std::string& fragmentShaderPrefix,
const std::string& fragmentShader,
- GeometryType type,
GeometryHints hints)
{
// @todo MESH_REWORK - Assert only image geometry type is passed.
Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New( hints );
- internal->SetPrograms( type, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
+ internal->SetPrograms( vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
return ShaderEffect( internal.Get() );
}
}
/**
- * @brief GeometryType determines how geometry is shaped.
- */
-enum GeometryType
-{
- GEOMETRY_TYPE_IMAGE = 0x01, ///< image, with flat color or texture
- GEOMETRY_TYPE_UNTEXTURED_MESH = 0x02, ///< Complex meshes, with flat color
- GEOMETRY_TYPE_TEXTURED_MESH = 0x04, ///< Complex meshes, with texture
- GEOMETRY_TYPE_LAST = 0x08
- // @todo MESH_REWORK - Remove these geometry types.
-};
-
-/**
- * @brief Shader effects provide a visual effect for actors.
+ * @brief Shader effects provide a visual effect for image actors.
*
* @deprecated Use classes Dali::Shader, Dali::Material, and Dali::Sampler to implement
* any new programmable shading effects.
*
* @param vertexShader code for the effect. If you pass in an empty string, the default version will be used
* @param fragmentShader code for the effect. If you pass in an empty string, the default version will be used
- * @param type GeometryType to define the shape of the geometry. Only GEOMETRY_TYPE_IMAGE is accepted for this
- * parameter. Any other value will lead to an error.
* @param hints GeometryHints to define the geometry of the rendered object
* @return A handle to a shader effect
*/
static ShaderEffect New( const std::string& vertexShader,
const std::string& fragmentShader,
- GeometryType type = GeometryType(GEOMETRY_TYPE_IMAGE),
GeometryHints hints = GeometryHints(HINT_NONE) );
/**
* @param vertexShader code for the effect. If you pass in an empty string, the default version will be used
* @param fragmentShaderPrefix code for the effect. It will be inserted before the default uniforms (ideal for \#defines)
* @param fragmentShader code for the effect. If you pass in an empty string, the default version will be used
- * @param type GeometryType to define the shape of the geometry. Only GEOMETRY_TYPE_IMAGE is accepted for this
- * parameter. Any other value will lead to an error.
* @param hints GeometryHints to define the geometry of the rendered object
* @return A handle to a shader effect
*/
const std::string& vertexShader,
const std::string& fragmentShaderPrefix,
const std::string& fragmentShader,
- GeometryType type = GeometryType(GEOMETRY_TYPE_IMAGE),
GeometryHints hints = GeometryHints(HINT_NONE) );
/**