Cleanup of the renderers and shader, reduces parameters passed to renderers and shade... 01/24101/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 1 Jul 2014 17:10:38 +0000 (18:10 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 8 Jul 2014 13:19:39 +0000 (14:19 +0100)
1. move Matrix and Color uniform setters to Renderer base class (reduces the number of parameter to derived renderers)

2. rename Shader::Apply to SetUniforms and move the call to base Renderer class from (removes parameters and code duplication)

4. perform culling first in base renderer Render method so we avoid any GL state changes if renderer is culled (previously we enabled blending etc)

5. remove MVP matrix from Shader as it has no use there anymore

6. rename GetGeometryTypes to ResolveGeometryTypes as its not just-a-getter. Remove duplicate calls to it from text and mesh renderers (removes code duplication)

7. removed implementation of dynamics debug renderer as it was a uncommented hack.

Change-Id: I1bcd57c205ff54cad7f6f3fd23561d568c1d9802
Signed-off-by: Adeel Kazmi <adeel.kazmi@samsung.com>
dali/internal/render/dynamics/scene-graph-dynamics-debug-renderer.cpp
dali/internal/render/renderers/scene-graph-image-renderer.cpp
dali/internal/render/renderers/scene-graph-image-renderer.h
dali/internal/render/renderers/scene-graph-mesh-renderer.cpp
dali/internal/render/renderers/scene-graph-mesh-renderer.h
dali/internal/render/renderers/scene-graph-renderer.cpp
dali/internal/render/renderers/scene-graph-renderer.h
dali/internal/render/renderers/scene-graph-text-renderer.cpp
dali/internal/render/renderers/scene-graph-text-renderer.h
dali/internal/render/shaders/shader.cpp
dali/internal/render/shaders/shader.h

index 0126e0c..6a86e7b 100644 (file)
@@ -81,23 +81,7 @@ void DynamicsDebugRenderer::UpdateBuffer( const Integration::DynamicsDebugVertex
 
 void DynamicsDebugRenderer::Render()
 {
-  if( mBuffer && mNumberOfPoints )
-  {
-    Integration::DynamicsDebugVertex* vertex = 0;
-
-    Program& program = mShader.Apply(*mContext, mBufferIndex, GEOMETRY_TYPE_IMAGE, Matrix::IDENTITY, Matrix::IDENTITY, mViewMatrix, mProjectionMatrix, Color::WHITE, SHADER_DEFAULT);
-    const GLint positionLoc = program.GetAttribLocation(Program::ATTRIB_POSITION);
-    const GLint colorLoc = program.GetAttribLocation(Program::ATTRIB_COLOR);
-    mBuffer->Bind();
-    mContext->VertexAttribPointer(positionLoc, 3, GL_FLOAT, false, sizeof(Integration::DynamicsDebugVertex), (void*)&vertex->position);
-    mContext->VertexAttribPointer(colorLoc, 4, GL_FLOAT, false, sizeof(Integration::DynamicsDebugVertex), (void*)&vertex->color);
-    mContext->EnableVertexAttributeArray(positionLoc);
-    mContext->EnableVertexAttributeArray(colorLoc);
-    mContext->DrawArrays( GL_LINES, 0, mNumberOfPoints );
-    mContext->DisableVertexAttributeArray(positionLoc);
-    mContext->DisableVertexAttributeArray(colorLoc);
-    mContext->BindArrayBuffer( 0 );
-  }
+  // @todo reimplement this properly in future
 }
 
 
index c4d5493..e046530 100644 (file)
@@ -219,27 +219,27 @@ bool ImageRenderer::CheckResources()
   return true;
 }
 
-void ImageRenderer::GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
+void ImageRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
 {
   outType = GEOMETRY_TYPE_IMAGE;
   outSubType = SHADER_DEFAULT;
 }
 
-
-void ImageRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color, bool cullTest )
+bool ImageRenderer::IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
 {
-  DALI_ASSERT_DEBUG( 0 != mTextureId && "ImageRenderer::DoRender. mTextureId == 0." );
-  DALI_ASSERT_DEBUG( NULL != mTexture && "ImageRenderer::DoRender. mTexture == NULL." );
-
   mContext->IncrementRendererCount();
-  if( cullTest )
+  if(IsOutsideClipSpaceImpl( modelMatrix, modelViewProjectionMatrix ) )
   {
-    if(IsOutsideClipSpace(modelMatrix) )
-    {
-      mContext->IncrementCulledCount();
-      return;
-    }
+    mContext->IncrementCulledCount();
+    return true;
   }
+  return false;
+}
+
+void ImageRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+{
+  DALI_ASSERT_DEBUG( 0 != mTextureId && "ImageRenderer::DoRender. mTextureId == 0." );
+  DALI_ASSERT_DEBUG( NULL != mTexture && "ImageRenderer::DoRender. mTexture == NULL." );
 
   if(! mIsMeshGenerated )
   {
@@ -254,11 +254,6 @@ void ImageRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMa
   // we call VertexAttribPointer otherwise you get weird output on the display
   mVertexBuffer->Bind();
 
-  ShaderSubTypes shaderType = SHADER_DEFAULT;
-
-  // Apply shader effect specific program and common uniforms
-  Program& program = mShader->Apply( *mContext, bufferIndex, GEOMETRY_TYPE_IMAGE, modelMatrix, viewMatrix, modelViewMatrix, projectionMatrix, color, shaderType );
-
   // Set sampler uniform
   GLint samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER );
   if( -1 != samplerLoc )
@@ -822,14 +817,14 @@ ImageRenderer::ImageRenderer( RenderDataProvider& dataprovider )
 }
 
 // Frustum culling using clip space and oriented bounding box checks
-bool ImageRenderer::IsOutsideClipSpace(const Matrix& modelMatrix)
+bool ImageRenderer::IsOutsideClipSpaceImpl(const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix)
 {
   // First, calculate if the center is inside clip space:
 
   // Downside is mvp matrix calc per renderer per frame
   // and up to 4 matrix * vector calls.
-  const Matrix& mvp = mShader->GetMVPMatrix();
-  Vector4 translation = mvp.GetTranslation();
+  const Matrix& mvp = modelViewProjectionMatrix;
+  const Vector4 translation = mvp.GetTranslation();
 
   // Upside is point test is very simple:
   if( -translation.w <= translation.x  &&  translation.x <= translation.w &&
index 3d59ef6..764bc4f 100644 (file)
@@ -114,14 +114,19 @@ public:
   virtual bool CheckResources();
 
   /**
-   * @copydoc Dali::Internal::SceneGraph::Renderer::GetGeometryTypes()
+   * @copydoc Dali::Internal::SceneGraph::Renderer::ResolveGeometryTypes()
    */
-  virtual void GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType );
+  virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType );
+
+  /**
+   * @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
+   */
+  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
 
   /**
    * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
    */
-  virtual void DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color, bool cullTest );
+  virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
 
 protected: // TextureObserver implementation
 
@@ -200,9 +205,11 @@ private:
   ImageRenderer& operator=(const ImageRenderer& rhs);
 
   /**
+   * @param modelMatrix
+   * @param modelViewProjectionMatrix
    * @return true if the renderer is outside clip space and doesn't need rendering
    */
-  bool IsOutsideClipSpace(const Matrix& modelMatrix);
+  bool IsOutsideClipSpaceImpl(const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix);
 
 private:
 
index 152c3dc..4959f50 100644 (file)
@@ -120,7 +120,7 @@ bool MeshRenderer::CheckResources()
   return true;
 }
 
-void MeshRenderer::GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
+void MeshRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
 {
   MeshInfo& meshInfo = mMeshInfo[bufferIndex];
   Mesh*           mesh     =   meshInfo.mesh;
@@ -164,9 +164,20 @@ void MeshRenderer::GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outT
       } // else default
     }
   }
+  if( outType != mGeometryType || outSubType != mShaderType )
+  {
+    mGeometryType = outType;
+    mShaderType = outSubType;
+    ResetCustomUniforms();
+  }
+}
+
+bool MeshRenderer::IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
+{
+  return false; // @todo add implementation
 }
 
-void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color, bool cullTest )
+void MeshRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
 {
   MeshInfo& meshInfo = mMeshInfo[bufferIndex];
   Mesh*           mesh              =    meshInfo.mesh;
@@ -186,19 +197,6 @@ void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
 
   GLsizei numBoneMatrices = (GLsizei)mesh->GetMeshData(Mesh::RENDER_THREAD).GetBoneCount();
 
-  GeometryType geometryType = GEOMETRY_TYPE_TEXTURED_MESH;
-  ShaderSubTypes shaderType = SHADER_DEFAULT;
-  GetGeometryTypes( bufferIndex, geometryType, shaderType );
-
-  if( geometryType != mGeometryType || shaderType != mShaderType )
-  {
-    mGeometryType = geometryType;
-    mShaderType = shaderType;
-    ResetCustomUniforms();
-  }
-
-  Program& program = mShader->Apply( *mContext, bufferIndex, geometryType, modelMatrix, viewMatrix, modelViewMatrix, projectionMatrix, color, mShaderType );
-
   GLint location       = Program::UNIFORM_UNKNOWN;
   GLint positionLoc    = program.GetAttribLocation(Program::ATTRIB_POSITION);
   GLint texCoordLoc    = Program::ATTRIB_UNKNOWN;
@@ -212,20 +210,20 @@ void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
 
   if( numBoneMatrices > 0 )
   {
-    location = mCustomUniform[ shaderType ][ 0 ].GetUniformLocation( program, "uBoneCount" );
+    location = mCustomUniform[ mShaderType ][ 0 ].GetUniformLocation( program, "uBoneCount" );
     if( Program::UNIFORM_UNKNOWN != location )
     {
       program.SetUniform1i(location, numBoneMatrices);
     }
 
-    location = mCustomUniform[ shaderType ][ 1 ].GetUniformLocation( program, "uBoneMatrices" );
+    location = mCustomUniform[ mShaderType ][ 1 ].GetUniformLocation( program, "uBoneMatrices" );
     if( Program::UNIFORM_UNKNOWN != location )
     {
       program.SetUniformMatrix4fv(location, numBoneMatrices, boneTransforms.viewTransforms[0].AsFloat());
     }
     if( mesh->GetMeshData(Mesh::RENDER_THREAD).HasNormals() )
     {
-      location = mCustomUniform[ shaderType ][ 2 ].GetUniformLocation( program, "uBoneMatricesIT" );
+      location = mCustomUniform[ mShaderType ][ 2 ].GetUniformLocation( program, "uBoneMatricesIT" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         program.SetUniformMatrix3fv( location, numBoneMatrices, boneTransforms.inverseTransforms[0].AsFloat() );
@@ -278,19 +276,19 @@ void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
     }
   }
 
-  material.SetUniforms( mRenderMaterialUniforms, program, shaderType );
+  material.SetUniforms( mRenderMaterialUniforms, program, mShaderType );
 
   if( mAffectedByLighting )
   {
     // Set light parameters
-    location = mCustomUniform[ shaderType ][ 3 ].GetUniformLocation( program, "uNumberOfLights" );
+    location = mCustomUniform[ mShaderType ][ 3 ].GetUniformLocation( program, "uNumberOfLights" );
     if( Program::UNIFORM_UNKNOWN != location )
     {
       program.SetUniform1i( location, mLightController->GetNumberOfLights() );
     }
 
     // Model View IT matrix required for vertex normal lighting calculation
-    location = mCustomUniform[ shaderType ][ 4 ].GetUniformLocation( program, "uModelViewIT" );
+    location = mCustomUniform[ mShaderType ][ 4 ].GetUniformLocation( program, "uModelViewIT" );
     if( Program::UNIFORM_UNKNOWN != location )
     {
       Matrix3 modelViewInverseTranspose = modelViewMatrix;
@@ -310,27 +308,27 @@ void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
 
       LightAttachment& light = dynamic_cast< LightAttachment& >( lightNode.GetAttachment() );
 
-      location = mCustomUniform[ shaderType ][ 5 ].GetUniformLocation( program, "uLight0.mType" );
+      location = mCustomUniform[ mShaderType ][ 5 ].GetUniformLocation( program, "uLight0.mType" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         program.SetUniform1i( location, (GLint)light.GetType() );
       }
 
-      location = mCustomUniform[ shaderType ][ 6 ].GetUniformLocation( program, "uLight0.mFallOff" );
+      location = mCustomUniform[ mShaderType ][ 6 ].GetUniformLocation( program, "uLight0.mFallOff" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         tempVector2 = light.GetFallOff();
         program.SetUniform2f( location, tempVector2.x, tempVector2.y );
       }
 
-      location = mCustomUniform[ shaderType ][ 7 ].GetUniformLocation( program, "uLight0.mSpotAngle" );
+      location = mCustomUniform[ mShaderType ][ 7 ].GetUniformLocation( program, "uLight0.mSpotAngle" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         tempVector2 = light.GetSpotAngle();
         program.SetUniform2f( location, tempVector2.x, tempVector2.y );
       }
 
-      location = mCustomUniform[ shaderType ][ 8 ].GetUniformLocation( program, "uLight0.mLightPos" );
+      location = mCustomUniform[ mShaderType ][ 8 ].GetUniformLocation( program, "uLight0.mLightPos" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         // light position in eyespace
@@ -338,7 +336,7 @@ void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
         program.SetUniform3f( location, tempVector3.x, tempVector3.y, tempVector3.z );
       }
 
-      location = mCustomUniform[ shaderType ][ 9 ].GetUniformLocation( program, "uLight0.mLightDir" );
+      location = mCustomUniform[ mShaderType ][ 9 ].GetUniformLocation( program, "uLight0.mLightDir" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         tempVector3 = light.GetDirection();
@@ -346,21 +344,21 @@ void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
         program.SetUniform3f( location, tempVector3.x, tempVector3.y, tempVector3.z );
       }
 
-      location = mCustomUniform[ shaderType ][ 10 ].GetUniformLocation( program, "uLight0.mAmbient" );
+      location = mCustomUniform[ mShaderType ][ 10 ].GetUniformLocation( program, "uLight0.mAmbient" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         tempVector3 = light.GetAmbientColor();
         program.SetUniform3f( location, tempVector3.r, tempVector3.g, tempVector3.b );
       }
 
-      location = mCustomUniform[ shaderType ][ 11 ].GetUniformLocation( program, "uLight0.mDiffuse" );
+      location = mCustomUniform[ mShaderType ][ 11 ].GetUniformLocation( program, "uLight0.mDiffuse" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         tempVector3 = light.GetDiffuseColor();
         program.SetUniform3f( location, tempVector3.r, tempVector3.g, tempVector3.b );
       }
 
-      location = mCustomUniform[ shaderType ][ 12 ].GetUniformLocation( program, "uLight0.mSpecular" );
+      location = mCustomUniform[ mShaderType ][ 12 ].GetUniformLocation( program, "uLight0.mSpecular" );
       if( Program::UNIFORM_UNKNOWN != location )
       {
         tempVector3 = light.GetSpecularColor();
@@ -373,16 +371,23 @@ void MeshRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
   switch( vertexGeometry )
   {
     case Dali::MeshData::TRIANGLES:
+    {
       mContext->DrawElements(GL_TRIANGLES, mesh->GetFaceIndexCount(Mesh::RENDER_THREAD), GL_UNSIGNED_SHORT, 0);
       DRAW_ELEMENT_RECORD(mesh->GetFaceIndexCount());
       break;
+    }
     case Dali::MeshData::LINES:
+    {
       mContext->DrawElements(GL_LINES, mesh->GetFaceIndexCount(Mesh::RENDER_THREAD), GL_UNSIGNED_SHORT, 0);
       DRAW_ELEMENT_RECORD(mesh->GetFaceIndexCount());
       break;
+    }
     case Dali::MeshData::POINTS:
+    {
       mContext->DrawArrays(GL_POINTS, 0, mesh->GetFaceIndexCount(Mesh::RENDER_THREAD) );
       DRAW_ARRAY_RECORD(mesh->GetFaceIndexCount());
+      break;
+    }
   }
 
   if( normalLoc != Program::ATTRIB_UNKNOWN )
index d7af8fb..d19559f 100644 (file)
@@ -121,14 +121,19 @@ private:
   virtual bool CheckResources();
 
   /**
-   * @copydoc Dali::Internal::SceneGraph::Renderer::GetGeometryTypes()
+   * @copydoc Dali::Internal::SceneGraph::Renderer::ResolveGeometryTypes()
    */
-  virtual void GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType );
+  virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType );
+
+  /**
+   * @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
+   */
+  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
 
   /**
    * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
    */
-  virtual void DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color, bool cullTest );
+  virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
 
   /**
    * Apply the view matrix to the bone transforms, and generate inverse transforms (for normal
index 9fcd0db..7f52d95 100644 (file)
@@ -34,20 +34,29 @@ namespace Internal
 
 namespace
 {
+static Matrix gModelViewProjectionMatrix( false ); ///< a shared matrix to calculate the MVP matrix, dont want to store it locally to reduce storage overhead
+static Matrix gNormalMatrix( false ); ///< a shared matrix to calculate normal matrix, dont want to store it locally to reduce storage overhead
+
 /**
  * Helper to set view and projection matrices once per program
+ * @param program to set the matrices to
+ * @param modelMatrix to set
+ * @param viewMatrix to set
+ * @param projectionMatrix to set
+ * @param modelViewMatrix to set
+ * @param modelViewProjectionMatrix to set
  */
-inline void SetMatrices( Program& program, const Matrix& projectionMatrix, const Matrix& viewMatrix )
+inline void SetMatrices( Program& program,
+                         const Matrix& modelMatrix,
+                         const Matrix& viewMatrix,
+                         const Matrix& projectionMatrix,
+                         const Matrix& modelViewMatrix,
+                         const Matrix& modelViewProjectionMatrix )
 {
-  // set projection matrix if program has not yet received it this frame or if it is dirty
-  GLint loc = program.GetUniformLocation( Program::UNIFORM_PROJECTION_MATRIX );
+  GLint loc = program.GetUniformLocation(Program::UNIFORM_MODEL_MATRIX);
   if( Program::UNIFORM_UNKNOWN != loc )
   {
-    if( program.GetProjectionMatrix() != &projectionMatrix )
-    {
-      program.SetProjectionMatrix( &projectionMatrix );
-      program.SetUniformMatrix4fv( loc, 1, projectionMatrix.AsFloat() );
-    }
+    program.SetUniformMatrix4fv( loc, 1, modelMatrix.AsFloat() );
   }
   loc = program.GetUniformLocation( Program::UNIFORM_VIEW_MATRIX );
   if( Program::UNIFORM_UNKNOWN != loc )
@@ -58,6 +67,36 @@ inline void SetMatrices( Program& program, const Matrix& projectionMatrix, const
       program.SetUniformMatrix4fv( loc, 1, viewMatrix.AsFloat() );
     }
   }
+  // set projection matrix if program has not yet received it this frame or if it is dirty
+  loc = program.GetUniformLocation( Program::UNIFORM_PROJECTION_MATRIX );
+  if( Program::UNIFORM_UNKNOWN != loc )
+  {
+    if( program.GetProjectionMatrix() != &projectionMatrix )
+    {
+      program.SetProjectionMatrix( &projectionMatrix );
+      program.SetUniformMatrix4fv( loc, 1, projectionMatrix.AsFloat() );
+    }
+  }
+  loc = program.GetUniformLocation(Program::UNIFORM_MODELVIEW_MATRIX);
+  if( Program::UNIFORM_UNKNOWN != loc )
+  {
+    program.SetUniformMatrix4fv( loc, 1, modelViewMatrix.AsFloat() );
+  }
+
+  loc = program.GetUniformLocation( Program::UNIFORM_MVP_MATRIX );
+  if( Program::UNIFORM_UNKNOWN != loc )
+  {
+    program.SetUniformMatrix4fv( loc, 1, modelViewProjectionMatrix.AsFloat() );
+  }
+
+  loc = program.GetUniformLocation( Program::UNIFORM_NORMAL_MATRIX );
+  if( Program::UNIFORM_UNKNOWN != loc )
+  {
+    gNormalMatrix = modelMatrix;
+    gNormalMatrix.Invert();
+    gNormalMatrix.Transpose();
+    program.SetUniformMatrix3fv( loc, 1, gNormalMatrix.AsFloat() );
+  }
 }
 }
 
@@ -117,6 +156,30 @@ void Renderer::Render( BufferIndex bufferIndex,
     return;
   }
 
+  // Calculate the MVP matrix first so we can do the culling test
+  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( *mContext, geometryType, subType, programIndex );
+
+  // Check culling (does not need the program to be in use)
+  bool areVerticesFixed = program.AreVerticesFixed();
+  if( cull && areVerticesFixed )
+  {
+    if( IsOutsideClipSpace( modelMatrix, gModelViewProjectionMatrix ) )
+    {
+      // don't do any further gl state changes as this renderer is not visible
+      return;
+    }
+  }
+  // Take the program into use so we can send uniforms to it
+  program.Use();
+
   // Enables/disables blending mode.
   mContext->SetBlend( mUseBlend );
 
@@ -144,32 +207,28 @@ void Renderer::Render( BufferIndex bufferIndex,
   mContext->BlendEquationSeparate( mBlendingOptions.GetBlendEquationRgb(),
                                    mBlendingOptions.GetBlendEquationAlpha() );
 
-  mShader->SetFrameTime( frametime );
-
-  const Matrix& modelMatrix = mDataProvider.GetModelMatrix( bufferIndex );
-  const Vector4& color = mDataProvider.GetRenderColor( bufferIndex );
-
-  // Calculate the MVP matrix first
-  Matrix& modelViewProjectionMatrix = mShader->GetMVPMatrix();
-  Matrix::Multiply( modelViewProjectionMatrix, modelViewMatrix, projectionMatrix );
-
-  // Call to over ridden method in the child class
-  // @todo, once MeshRenderer is fixed to render only one mesh, move mShader.Apply here
-  // and we can greatly reduce these parameters. Also then derived renderers can be passed the Program&
-
-  GeometryType geometryType=GEOMETRY_TYPE_IMAGE;
-  ShaderSubTypes subType=SHADER_DEFAULT;
-  GetGeometryTypes( bufferIndex, geometryType, subType );
-  Program& program = mShader->GetProgram( *mContext, geometryType, subType );
-  program.Use(); // apply the program so we can send uniforms to it
+  // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER
+  // set projection and view matrix if program has not yet received them yet this frame
+  SetMatrices( program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix, gModelViewProjectionMatrix );
 
-  bool areVerticesFixed = program.AreVerticesFixed();
+  // set color uniform
+  GLint loc = program.GetUniformLocation( Program::UNIFORM_COLOR );
+  if( Program::UNIFORM_UNKNOWN != loc )
+  {
+    const Vector4& color = mDataProvider.GetRenderColor( bufferIndex );
+    program.SetUniform4f( loc, color.r, color.g, color.b, color.a );
+  }
+  loc = program.GetUniformLocation(Program::UNIFORM_TIME_DELTA);
+  if( Program::UNIFORM_UNKNOWN != loc )
+  {
+    program.SetUniform1f( loc, frametime );
+  }
 
-  // set projection and view matrix if program has not yet received them yet this frame
-  SetMatrices( program, projectionMatrix, viewMatrix );
+  // set custom uniforms
+  mShader->SetUniforms( *mContext, program, bufferIndex, programIndex, subType );
 
-  // subclass rendering
-  DoRender( bufferIndex, modelViewMatrix, modelMatrix, viewMatrix, projectionMatrix, color, cull && areVerticesFixed );
+  // subclass rendering and actual draw call
+  DoRender( bufferIndex, program, modelViewMatrix, viewMatrix );
 }
 
 Renderer::Renderer( RenderDataProvider& dataprovider )
index 74b2955..16da342 100644 (file)
@@ -36,6 +36,7 @@ namespace Internal
 {
 class Context;
 class Texture;
+class Program;
 
 namespace SceneGraph
 {
@@ -103,14 +104,6 @@ public:
   virtual bool RequiresDepthTest() const = 0;
 
   /**
-   * Query the derived type for it's 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 GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType ) = 0;
-
-  /**
    * Called to render during RenderManager::Render().
    * @param[in] bufferIndex The index of the previous update buffer.
    * @param[in] modelViewMatrix The model-view matrix.
@@ -124,7 +117,7 @@ public:
                const Matrix& viewMatrix,
                const Matrix& projectionMatrix,
                float frametime,
-               bool cull);
+               bool cull );
 
 protected:
 
@@ -150,16 +143,29 @@ private:
   virtual bool CheckResources() = 0;
 
   /**
+   * 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's is culled.
+   * @param[in] modelMatrix The model matrix.
+   * @param[in] modelViewProjectionMatrix The MVP matrix.
+   * @return \e true if it is. Otherwise \e false.
+   */
+  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
+
+  /**
    * Called from Render; implemented in derived classes.
    * @param[in] bufferIndex The index of the previous update buffer.
+   * @param[in] program to use.
    * @param[in] modelViewMatrix The model-view matrix.
-   * @param[in] modelMatrix The model matrix.
    * @param[in] viewMatrix The view matrix.
-   * @param[in] projectionMatrix The projection matrix.
-   * @param[in] color to use
-   * @param[in] cullTest Whether to try and cull the renderer.
    */
-  virtual void DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color, bool cullTest ) = 0;
+  virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
 
 protected:
 
index 9a142ae..fecaa0d 100644 (file)
@@ -297,7 +297,7 @@ bool TextRenderer::CheckResources()
   return true;
 }
 
-void TextRenderer::GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
+void TextRenderer::ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType )
 {
   outType = GEOMETRY_TYPE_TEXT;
 
@@ -332,27 +332,19 @@ void TextRenderer::GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outT
   }
 }
 
-void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color, bool cullTest )
+bool TextRenderer::IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
 {
-  if ( ! ( mVertexBuffer && mIndexBuffer ) )
-  {
-    // This character has no geometry, must be a white space
-    return;
-  }
+  return false; // @todo add implementation
+}
 
+void TextRenderer::DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+{
   DALI_ASSERT_DEBUG( NULL != mTexture && "TextRenderer::DoRender. mTexture == NULL." );
 
   DALI_LOG_INFO( gTextFilter, Debug::General, "TextRenderer::DoRender(this: %p) textureId:%d\n", this, mTextureId );
 
-  GeometryType geometryType;
-  ShaderSubTypes shaderType;
-  GetGeometryTypes( bufferIndex, geometryType, shaderType );
-
-  // Apply shader effect specific program and common uniforms
-  Program& program = mShader->Apply( *mContext, bufferIndex, geometryType, modelMatrix, viewMatrix, modelViewMatrix, projectionMatrix, color, shaderType );
-
   // Set sampler uniform
-  GLint samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER );
+  const GLint samplerLoc = program.GetUniformLocation( Program::UNIFORM_SAMPLER );
   if( Program::UNIFORM_UNKNOWN != samplerLoc )
   {
     // set the uniform
@@ -365,7 +357,7 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
   float smoothWidth = SMOOTHING_ADJUSTMENT / mPixelSize;
   float smoothing = mSmoothing;
 
-  const int smoothingLoc = program.GetUniformLocation( Program::UNIFORM_SMOOTHING );
+  const GLint smoothingLoc = program.GetUniformLocation( Program::UNIFORM_SMOOTHING );
   if( Program::UNIFORM_UNKNOWN != smoothingLoc )
   {
     smoothWidth = min( min(mSmoothing, 1.0f - mSmoothing), smoothWidth );
@@ -382,8 +374,8 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
   {
     if( mTextParameters->IsOutlineEnabled() )
     {
-      const int outlineLoc = program.GetUniformLocation( Program::UNIFORM_OUTLINE );
-      const int outlineColorLoc = program.GetUniformLocation( Program::UNIFORM_OUTLINE_COLOR );
+      const GLint outlineLoc = program.GetUniformLocation( Program::UNIFORM_OUTLINE );
+      const GLint outlineColorLoc = program.GetUniformLocation( Program::UNIFORM_OUTLINE_COLOR );
 
       if( Program::UNIFORM_UNKNOWN != outlineLoc && Program::UNIFORM_UNKNOWN != outlineColorLoc )
       {
@@ -400,8 +392,8 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
 
     if( mTextParameters->IsGlowEnabled() )
     {
-      const int glowLoc = program.GetUniformLocation( Program::UNIFORM_GLOW );
-      const int glowColorLoc = program.GetUniformLocation( Program::UNIFORM_GLOW_COLOR );
+      const GLint glowLoc = program.GetUniformLocation( Program::UNIFORM_GLOW );
+      const GLint glowColorLoc = program.GetUniformLocation( Program::UNIFORM_GLOW_COLOR );
 
       if( Program::UNIFORM_UNKNOWN != glowLoc && Program::UNIFORM_UNKNOWN != glowColorLoc )
       {
@@ -414,9 +406,9 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
 
     if( mTextParameters->IsDropShadowEnabled() )
     {
-      const int shadowLoc = program.GetUniformLocation( Program::UNIFORM_SHADOW );
-      const int shadowColorLoc = program.GetUniformLocation( Program::UNIFORM_SHADOW_COLOR );
-      const int shadowSmoothingLoc = program.GetUniformLocation( Program::UNIFORM_SHADOW_SMOOTHING );
+      const GLint shadowLoc = program.GetUniformLocation( Program::UNIFORM_SHADOW );
+      const GLint shadowColorLoc = program.GetUniformLocation( Program::UNIFORM_SHADOW_COLOR );
+      const GLint shadowSmoothingLoc = program.GetUniformLocation( Program::UNIFORM_SHADOW_SMOOTHING );
 
       if( Program::UNIFORM_UNKNOWN != shadowLoc && Program::UNIFORM_UNKNOWN != shadowColorLoc && Program::UNIFORM_UNKNOWN != shadowSmoothingLoc )
       {
@@ -432,7 +424,7 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
   }
 
   // Set the text color uniform
-  const int textColorLoc = program.GetUniformLocation( Program::UNIFORM_TEXT_COLOR );
+  const GLint textColorLoc = program.GetUniformLocation( Program::UNIFORM_TEXT_COLOR );
   if( Program::UNIFORM_UNKNOWN != textColorLoc )
   {
     Vector4 textColor( (NULL != mTextColor) ? *mTextColor : TextStyle::DEFAULT_TEXT_COLOR );
@@ -440,31 +432,27 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
     program.SetUniform4f(textColorLoc, textColor.r, textColor.g, textColor.b, textColor.a);
   }
 
-  // All shaders except default shader require the uGradientLine.zw uniform to be set
-  // at the very least. (setting it to vec2(0.0, 0.0) will disable gradient)
-  if( shaderType != SHADER_DEFAULT )
+  if( mTextParameters )
   {
+    // All shaders except default shader require the uGradientLine.zw uniform to be set
+    // at the very least. (setting it to vec2(0.0, 0.0) will disable gradient)
     Vector2 projection( Vector2::ZERO );
     Vector2 startPoint( TextStyle::DEFAULT_GRADIENT_START_POINT );
-
-    if( mTextParameters )
+    startPoint = mTextParameters->GetGradientStartPoint();
+    projection = mTextParameters->GetGradientEndPoint() - startPoint;
+    if( mTextParameters->IsGradientEnabled() ) // same as: mGradientEndPoint != mGradientStartPoint
     {
-      startPoint = mTextParameters->GetGradientStartPoint();
-      projection = mTextParameters->GetGradientEndPoint() - startPoint;
-      if( mTextParameters->IsGradientEnabled() ) // same as: mGradientEndPoint != mGradientStartPoint
+      projection /= projection.LengthSquared();
+
+      // For valid gradients Gradient Color and Text Size information must be set.
+      const GLint gradientColorLoc = program.GetUniformLocation( Program::UNIFORM_GRADIENT_COLOR );
+      const GLint textSizeLoc = program.GetUniformLocation( Program::UNIFORM_INVERSE_TEXT_SIZE );
+
+      if( Program::UNIFORM_UNKNOWN != gradientColorLoc && Program::UNIFORM_UNKNOWN != textSizeLoc )
       {
-        projection /= projection.LengthSquared();
-
-        // For valid gradients Gradient Color and Text Size information must be set.
-        const int gradientColorLoc = program.GetUniformLocation( Program::UNIFORM_GRADIENT_COLOR );
-        const int textSizeLoc = program.GetUniformLocation( Program::UNIFORM_INVERSE_TEXT_SIZE );
-
-        if( Program::UNIFORM_UNKNOWN != gradientColorLoc && Program::UNIFORM_UNKNOWN != textSizeLoc )
-        {
-          const Vector4& color = mTextParameters->GetGradientColor();
-          program.SetUniform4f( gradientColorLoc, color.r, color.g, color.b, color.a );
-          program.SetUniform2f( textSizeLoc, mInvTextSize.width, mInvTextSize.height );
-        }
+        const Vector4& color = mTextParameters->GetGradientColor();
+        program.SetUniform4f( gradientColorLoc, color.r, color.g, color.b, color.a );
+        program.SetUniform2f( textSizeLoc, mInvTextSize.width, mInvTextSize.height );
       }
     }
 
@@ -472,7 +460,7 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
     // gradient information (gradientRequired), then we set
     // uGradientLine.zw = vec2(0.0, 0.0) to force vColor = uColor in the expression.
     // If we do have a gradient present, then we set up all information.
-    const int gradientLineLoc = program.GetUniformLocation( Program::UNIFORM_GRADIENT_LINE );
+    const GLint gradientLineLoc = program.GetUniformLocation( Program::UNIFORM_GRADIENT_LINE );
     if( Program::UNIFORM_UNKNOWN != gradientLineLoc )
     {
       program.SetUniform4f( gradientLineLoc,
@@ -483,8 +471,8 @@ void TextRenderer::DoRender( BufferIndex bufferIndex, const Matrix& modelViewMat
     }
   }
 
-  const int positionLoc = program.GetAttribLocation(Program::ATTRIB_POSITION);
-  const int texCoordLoc = program.GetAttribLocation(Program::ATTRIB_TEXCOORD);
+  const GLint positionLoc = program.GetAttribLocation(Program::ATTRIB_POSITION);
+  const GLint texCoordLoc = program.GetAttribLocation(Program::ATTRIB_TEXCOORD);
 
   mTexture->Bind(GL_TEXTURE_2D, GL_TEXTURE0);
 
index 66b6c4f..7310e9a 100644 (file)
@@ -127,14 +127,19 @@ public:
   virtual bool CheckResources();
 
   /**
-   * @copydoc Dali::Internal::SceneGraph::Renderer::GetGeometryTypes()
+   * @copydoc Dali::Internal::SceneGraph::Renderer::ResolveGeometryTypes()
    */
-  virtual void GetGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType );
+  virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType );
+
+  /**
+   * @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
+   */
+  virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
 
   /**
    * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
    */
-  virtual void DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color, bool cullTest );
+  virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
 
 protected: // TextureObserver implementation
   /**
index 4822dd1..a307294 100644 (file)
@@ -111,11 +111,9 @@ Shader::Shader( Dali::ShaderEffect::GeometryHints& hints )
   mTexture( NULL ),
   mRenderTextureId( 0 ),
   mUpdateTextureId( 0 ),
-  mModelViewProjection( false ), // Don't initialize.
   mRenderQueue(NULL),
   mPostProcessDispatcher(NULL),
-  mTextureCache(NULL),
-  mFrametime(0.f)
+  mTextureCache(NULL)
 {
   // Create enough size for all default types and sub-types
   mPrograms.resize(Log<GEOMETRY_TYPE_LAST>::value);
@@ -280,33 +278,30 @@ bool Shader::AreSubtypesRequired(GeometryType geometryType)
 
 Program& Shader::GetProgram( Context& context,
                              GeometryType type,
-                             const ShaderSubTypes subType )
+                             ShaderSubTypes subType,
+                             unsigned int& programIndex )
 {
   DALI_ASSERT_DEBUG(type < GEOMETRY_TYPE_LAST);
   DALI_DEBUG_OSTREAM(debugStream);
 
-  unsigned int programType = GetGeometryTypeIndex( type );
+  programIndex = GetGeometryTypeIndex( type );
 
-  DALI_ASSERT_DEBUG(!mPrograms[ programType ].mUseDefaultForAllSubtypes || subType == SHADER_DEFAULT);
-  DALI_ASSERT_DEBUG((unsigned int)subType < mPrograms[ programType ].Count());
-  DALI_ASSERT_DEBUG(NULL != mPrograms[ programType ][ subType ]);
+  DALI_ASSERT_DEBUG(!mPrograms[ programIndex ].mUseDefaultForAllSubtypes || subType == SHADER_DEFAULT);
+  DALI_ASSERT_DEBUG((unsigned int)subType < mPrograms[ programIndex ].Count());
+  DALI_ASSERT_DEBUG(NULL != mPrograms[ programIndex ][ subType ]);
 
-  Program& program = *(mPrograms[ programType ][ subType ]);
+  Program& program = *(mPrograms[ programIndex ][ subType ]);
   return program;
 }
 
 
-Program& Shader::Apply( Context& context,
-                        BufferIndex bufferIndex,
-                        GeometryType type,
-                        const Matrix& model,
-                        const Matrix& view,
-                        const Matrix& modelview,
-                        const Matrix& projection,
-                        const Vector4& color,
-                        const ShaderSubTypes subType /*= SHADER_DEFAULT*/ )
+void Shader::SetUniforms( Context& context,
+                          Program& program,
+                          BufferIndex bufferIndex,
+                          unsigned int programIndex,
+                          ShaderSubTypes subType )
 {
-  DALI_ASSERT_DEBUG(type < GEOMETRY_TYPE_LAST);
+  DALI_ASSERT_DEBUG( programIndex < Log<GEOMETRY_TYPE_LAST>::value );
   DALI_DEBUG_OSTREAM(debugStream);
 
   if( mRenderTextureId && ( mTexture == NULL ) )
@@ -316,25 +311,6 @@ Program& Shader::Apply( Context& context,
     DALI_ASSERT_DEBUG( mTexture != NULL );
   }
 
-  unsigned int programType = GetGeometryTypeIndex( type );
-
-  DALI_ASSERT_DEBUG(!mPrograms[ programType ].mUseDefaultForAllSubtypes || subType == SHADER_DEFAULT);
-  DALI_ASSERT_DEBUG((unsigned int)subType < mPrograms[ programType ].Count());
-  DALI_ASSERT_DEBUG(NULL != mPrograms[ programType ][ subType ]);
-
-  Program& program = *(mPrograms[ programType ][ subType ]);
-
-  // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER
-
-  // get color uniform
-  const GLint colorLoc = program.GetUniformLocation( Program::UNIFORM_COLOR );
-  if( Program::UNIFORM_UNKNOWN != colorLoc )
-  {
-    DALI_PRINT_UNIFORM( debugStream, bufferIndex, "uColor", color );
-    // set the uniform
-    program.SetUniform4f( colorLoc, color.r, color.g, color.b, color.a );
-  }
-
   GLint loc = Program::UNIFORM_UNKNOWN;
 
   if( mTexture )
@@ -351,45 +327,6 @@ Program& Shader::Apply( Context& context,
     }
   }
 
-  // Pass ModelView, projection, MVP, and normal matrices to the shader
-  loc = program.GetUniformLocation(Program::UNIFORM_MODELVIEW_MATRIX);
-  if( Program::UNIFORM_UNKNOWN != loc )
-  {
-    DALI_PRINT_UNIFORM( debugStream, bufferIndex, "uModelView", modelview );
-    program.SetUniformMatrix4fv( loc, 1, modelview.AsFloat() );
-  }
-
-  loc = program.GetUniformLocation( Program::UNIFORM_MVP_MATRIX );
-  if( Program::UNIFORM_UNKNOWN != loc )
-  {
-    DALI_PRINT_UNIFORM( debugStream, bufferIndex, "uMvpMatrix", mModelViewProjection );
-    program.SetUniformMatrix4fv( loc, 1, mModelViewProjection.AsFloat() );
-  }
-
-  loc = program.GetUniformLocation( Program::UNIFORM_NORMAL_MATRIX );
-  if( Program::UNIFORM_UNKNOWN != loc )
-  {
-    Matrix3 normalMatrix( modelview );
-    normalMatrix.Invert();
-    normalMatrix.Transpose();
-    DALI_PRINT_UNIFORM( debugStream, bufferIndex, "uNormalMatrix", normalMatrix );
-    program.SetUniformMatrix3fv( loc, 1, normalMatrix.AsFloat() );
-  }
-
-  loc = program.GetUniformLocation(Program::UNIFORM_TIME_DELTA);
-  if( Program::UNIFORM_UNKNOWN != loc )
-  {
-    DALI_PRINT_UNIFORM( debugStream, bufferIndex, "uTimeDelta", mFrametime );
-    program.SetUniform1f( loc, mFrametime );
-  }
-
-  loc = program.GetUniformLocation(Program::UNIFORM_MODEL_MATRIX);
-  if( Program::UNIFORM_UNKNOWN != loc )
-  {
-    DALI_PRINT_UNIFORM( debugStream, bufferIndex, "uModelMatrix", model );
-    program.SetUniformMatrix4fv( loc, 1, model.AsFloat() );
-  }
-
   // We should have one UniformMeta per uniform property
   for ( unsigned int i = 0u; i < mUniformMetadata.Count(); ++i )
   {
@@ -400,12 +337,12 @@ Program& Shader::Apply( Context& context,
     if ( metadata.name.length() > 0 )
     {
       // 0 means program has not got a cache index for this uniform
-      if( 0 == metadata.cacheIndeces[ programType ][ subType ] )
+      if( 0 == metadata.cacheIndeces[ programIndex ][ subType ] )
       {
         // register cacheindex for this program
-        metadata.cacheIndeces[ programType ][ subType ] = program.RegisterUniform( metadata.name );
+        metadata.cacheIndeces[ programIndex ][ subType ] = program.RegisterUniform( metadata.name );
       }
-      loc = program.GetUniformLocation( metadata.cacheIndeces[ programType ][ subType ] );
+      loc = program.GetUniformLocation( metadata.cacheIndeces[ programIndex ][ subType ] );
 
       // if we find uniform with location
       if ( Program::UNIFORM_UNKNOWN != loc )
@@ -535,16 +472,8 @@ Program& Shader::Apply( Context& context,
   }
 
   DALI_PRINT_SHADER_UNIFORMS(debugStream);
-
-  return program;
 }
 
-void Shader::SetFrameTime( float frametime )
-{
-  mFrametime = frametime;
-}
-
-
 } // namespace SceneGraph
 
 } // namespace Internal
index bdbb05f..ca8c639 100644 (file)
@@ -280,50 +280,32 @@ public:
 
   /**
    * Get the program associated with the given type and subtype
+   * @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,
-                       const ShaderSubTypes subType );
+                       ShaderSubTypes subType,
+                       unsigned int& programIndex );
 
   /**
-   * Applies the shader effect specific program and sets the common uniforms
+   * 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] model       model matrix of the object.
-   * @param[in] view        view matrix of the object.
-   * @param[in] modelview   matrix of the object.
-   * @param[in] projection  matrix for the camera.
-   * @param[in] color       to be used.
    * @param[in] subType     Identifier for geometry types with specialised default shaders
    */
-  Program& Apply( Context& context,
-                  BufferIndex bufferIndex,
-                  GeometryType type,
-                  const Matrix& model,
-                  const Matrix& view,
-                  const Matrix& modelview,
-                  const Matrix& projection,
-                  const Vector4& color,
-                  const ShaderSubTypes subType = SHADER_DEFAULT );
-
-  /**
-   * Applies the shader effect specific program and sets the common 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] frametime   time elapsed between the two last updates.
-   */
-  void SetFrameTime( float frametime );
-
-  /**
-   * @return The model view projection matrix
-   */
-  inline Matrix& GetMVPMatrix()
-  {
-    return mModelViewProjection;
-  }
+  void SetUniforms( Context& context,
+                    Program& program,
+                    BufferIndex bufferIndex,
+                    unsigned int programIndex,
+                    ShaderSubTypes subType = SHADER_DEFAULT );
 
 private: // Data
 
@@ -337,7 +319,6 @@ private: // Data
 
   std::vector<ProgramContainer>  mPrograms;         ///< 2D array of Program*. Access by [Log<GEOMETRY_TYPE_XXX>::value][index]. An index of 0 selects the default program for that geometry type.
 
-  Matrix                         mModelViewProjection; ///< Model view projection
   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()
@@ -346,7 +327,6 @@ private: // Data
   // These members are only safe to access in render thread
   PostProcessResourceDispatcher* mPostProcessDispatcher; ///< Used for saving shaders through the resource manager
   TextureCache*                  mTextureCache; // Used for retrieving textures in the render thread
-  float                          mFrametime;   ///< Used for setting the frametime delta shader uniform.
 };
 
 // Messages for Shader, to be processed in Update thread.