Avoid setting all the programs in all the shaders, NULL means use default 36/29936/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 5 Nov 2014 18:45:27 +0000 (18:45 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 6 Nov 2014 17:34:29 +0000 (09:34 -0800)
[Problem]
[Cause]
[Solution]

Change-Id: I714fc8237dff03f86d544afbdd493731c843cdd2

21 files changed:
dali/internal/event/effects/shader-effect-impl.cpp
dali/internal/event/effects/shader-factory.cpp
dali/internal/event/effects/shader-factory.h
dali/internal/render/common/render-algorithms.cpp
dali/internal/render/common/render-algorithms.h
dali/internal/render/common/render-manager.cpp
dali/internal/render/common/render-manager.h
dali/internal/render/gl-resources/context.cpp
dali/internal/render/renderers/scene-graph-image-renderer.cpp
dali/internal/render/renderers/scene-graph-renderer.cpp
dali/internal/render/renderers/scene-graph-renderer.h
dali/internal/render/shaders/program.cpp
dali/internal/render/shaders/shader.cpp
dali/internal/render/shaders/shader.h
dali/internal/update/controllers/scene-controller-impl.cpp
dali/internal/update/controllers/scene-controller-impl.h
dali/internal/update/controllers/scene-controller.h
dali/internal/update/manager/update-manager.cpp
dali/internal/update/manager/update-manager.h
dali/internal/update/node-attachments/scene-graph-image-attachment.cpp
dali/internal/update/node-attachments/scene-graph-renderable-attachment.cpp

index 3669778..5f67fe7 100644 (file)
@@ -91,9 +91,7 @@ WrapperStrings customShaderWrappers [] =
 
 BaseHandle Create()
 {
-  Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New( );
-
-  ShaderFactory::LoadTextSubtypeShaders(internal);
+  Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New();
 
   return Dali::ShaderEffect(internal.Get());
 }
@@ -167,7 +165,6 @@ ShaderEffectPtr ShaderEffect::NewWithPrefix( const string& vertexShaderPrefix,
                                              Dali::ShaderEffect::GeometryHints hints )
 {
   ShaderEffectPtr shaderEffect( New(hints) );
-  ShaderFactory::LoadTextSubtypeShaders(shaderEffect);
 
   shaderEffect->SetPrograms( geometryTypes, vertexShaderPrefix, vertexShader, fragmentShaderPrefix, fragmentShader );
   return shaderEffect;
@@ -185,8 +182,6 @@ ShaderEffectPtr ShaderEffect::New( const string& imageVertexShader,
 {
   ShaderEffectPtr shaderEffect( New(hints) );
 
-  ShaderFactory::LoadTextSubtypeShaders(shaderEffect);
-
   shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_IMAGE, SHADER_SUBTYPE_ALL, "", "", imageVertexShader, imageFragmentShader );
   shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_TEXT, SHADER_DEFAULT, "", "", textVertexShader, textFragmentShader );
   shaderEffect->SetWrappedProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_SUBTYPE_ALL, "", "", texturedMeshVertexShader, texturedMeshFragmentShader );
@@ -604,38 +599,22 @@ void ShaderEffect::SetPrograms( GeometryType  geometryTypes,
   {
     SetWrappedProgram( GEOMETRY_TYPE_IMAGE, SHADER_SUBTYPE_ALL, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
   }
-  else
-  {
-    SetWrappedProgram( GEOMETRY_TYPE_IMAGE, SHADER_SUBTYPE_ALL, emptyStr, emptyStr, emptyStr, emptyStr );
-  }
 
   if( geometryTypes & GEOMETRY_TYPE_TEXT )
   {
     // Only change the default program, leaving the other sub-types as-is.
     SetWrappedProgram( GEOMETRY_TYPE_TEXT, SHADER_DEFAULT, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
   }
-  else
-  {
-    SetWrappedProgram( GEOMETRY_TYPE_TEXT, SHADER_DEFAULT, emptyStr, emptyStr, emptyStr, emptyStr );
-  }
 
   if( geometryTypes & GEOMETRY_TYPE_TEXTURED_MESH )
   {
     SetWrappedProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_SUBTYPE_ALL, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
   }
-  else
-  {
-    SetWrappedProgram( GEOMETRY_TYPE_TEXTURED_MESH, SHADER_SUBTYPE_ALL, emptyStr, emptyStr, emptyStr, emptyStr );
-  }
 
   if( geometryTypes & GEOMETRY_TYPE_MESH )
   {
     SetWrappedProgram( GEOMETRY_TYPE_MESH, SHADER_SUBTYPE_ALL, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
   }
-  else
-  {
-    SetWrappedProgram( GEOMETRY_TYPE_MESH, SHADER_SUBTYPE_ALL, emptyStr, emptyStr, emptyStr, emptyStr );
-  }
 }
 
 void ShaderEffect::SetWrappedProgram( GeometryType geometryType, ShaderSubTypes subType,
index 9fc93db..0a34ca9 100644 (file)
@@ -117,7 +117,15 @@ void ShaderFactory::LoadDefaultShaders()
 
   mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_DEFAULT, DistanceFieldFontVertex, DistanceFieldFontFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
 
-  LoadTextSubtypeShaders(mDefaultShader); // TODO: Remove when applications no longer need these shaders
+  mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT, SHADER_DEF_USE_GRADIENT, SHADER_DEF_USE_GRADIENT, DistanceFieldFontVertex, DistanceFieldFontFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+
+  mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_GLOW, DistanceFieldFontGlowVertex, DistanceFieldFontGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+
+  mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_SHADOW, DistanceFieldFontShadowVertex, DistanceFieldFontShadowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+
+  mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE, DistanceFieldFontOutlineVertex, DistanceFieldFontOutlineFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
+
+  mDefaultShader->SetProgram( GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE_GLOW, DistanceFieldFontOutlineGlowVertex, DistanceFieldFontOutlineGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
 
   // Untextured meshes
   mDefaultShader->SetProgram( GEOMETRY_TYPE_MESH, SHADER_DEFAULT,
@@ -193,24 +201,6 @@ void ShaderFactory::LoadDefaultShaders()
                               ShaderEffect::MODIFIES_GEOMETRY );
 }
 
-void ShaderFactory::LoadTextSubtypeShaders(ShaderEffectPtr shaderEffect)
-{
-  shaderEffect->SetProgram(GEOMETRY_TYPE_TEXT, SHADER_GRADIENT,
-                           SHADER_DEF_USE_GRADIENT,
-                           SHADER_DEF_USE_GRADIENT,
-                           DistanceFieldFontVertex, DistanceFieldFontFragment,
-                           ShaderEffect::DOESNT_MODIFY_GEOMETRY );
-
-  shaderEffect->SetProgram(GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_GLOW, DistanceFieldFontGlowVertex, DistanceFieldFontGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
-
-  shaderEffect->SetProgram(GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_SHADOW, DistanceFieldFontShadowVertex, DistanceFieldFontShadowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
-
-  shaderEffect->SetProgram(GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE, DistanceFieldFontOutlineVertex, DistanceFieldFontOutlineFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
-
-  shaderEffect->SetProgram(GEOMETRY_TYPE_TEXT, SHADER_GRADIENT_OUTLINE_GLOW, DistanceFieldFontOutlineGlowVertex, DistanceFieldFontOutlineGlowFragment, ShaderEffect::DOESNT_MODIFY_GEOMETRY );
-}
-
-
 } // namespace Internal
 
 } // namespace Dali
index 2314c48..861d394 100644 (file)
@@ -68,13 +68,6 @@ public:
    */
   void LoadDefaultShaders();
 
-  /**
-   * Called during ShaderEffect::New() to load shaders for text sub-types
-   * (Default shader can be overridden)
-   * @param[in] shaderEffect The shader effect for which to load the sub-type shaders
-   */
-  static void LoadTextSubtypeShaders(ShaderEffectPtr shaderEffect);
-
 private:
 
   // Undefined
index 0821279..a04d234 100644 (file)
@@ -43,6 +43,7 @@ namespace Render
  * Process a render-list.
  * @param[in] renderList The render-list to process.
  * @param[in] context The GL context.
+ * @param[in] defaultShader The default shader to use.
  * @param[in] buffer The current render buffer index (previous update buffer)
  * @param[in] frameTime The elapsed time between the last two updates.
  * @param[in] viewMatrix The view matrix from the appropriate camera.
@@ -51,6 +52,7 @@ namespace Render
  */
 inline void ProcessRenderList( const RenderList& renderList,
                                Context& context,
+                               SceneGraph::Shader& defaultShader,
                                BufferIndex bufferIndex,
                                float frameTime,
                                const Matrix& viewMatrix,
@@ -116,12 +118,13 @@ inline void ProcessRenderList( const RenderList& renderList,
     SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( item.GetRenderer() );
     const Matrix& modelViewMatrix = item.GetModelViewMatrix();
 
-    renderer->Render( bufferIndex, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode );
+    renderer->Render( bufferIndex, defaultShader, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode );
   }
 }
 
 void ProcessRenderInstruction( const RenderInstruction& instruction,
                                Context& context,
+                               SceneGraph::Shader& defaultShader,
                                BufferIndex bufferIndex,
                                float frameTime )
 {
@@ -144,7 +147,7 @@ void ProcessRenderInstruction( const RenderInstruction& instruction,
       if(  renderList &&
           !renderList->IsEmpty() )
       {
-        ProcessRenderList( *renderList, context, bufferIndex, frameTime, *viewMatrix, *projectionMatrix, instruction.mCullMode );
+        ProcessRenderList( *renderList, context, defaultShader, bufferIndex, frameTime, *viewMatrix, *projectionMatrix, instruction.mCullMode );
       }
     }
   }
index da09a90..7cf9ecc 100644 (file)
@@ -32,6 +32,7 @@ class Context;
 namespace SceneGraph
 {
 class RenderInstruction;
+class Shader;
 }
 
 namespace Render
@@ -41,11 +42,13 @@ namespace Render
  * Process a render-instruction.
  * @param[in] instruction The render-instruction to process.
  * @param[in] context The GL context.
+ * @param[in] defaultShader The default shader.
  * @param[in] buffer The current render buffer index (previous update buffer)
  * @param[in] frameTime The elapsed time between the last two updates.
  */
 void ProcessRenderInstruction( const SceneGraph::RenderInstruction& instruction,
                                Context& context,
+                               SceneGraph::Shader& defaultShader,
                                BufferIndex bufferIndex,
                                float frameTime );
 
index 318899a..236505c 100644 (file)
@@ -101,7 +101,8 @@ struct RenderManager::Impl
     rendererContainer(),
     materials(),
     renderersAdded( false ),
-    firstRenderCompleted( false )
+    firstRenderCompleted( false ),
+    defaultShader( NULL )
   {
   }
 
@@ -166,6 +167,7 @@ struct RenderManager::Impl
   RenderTrackerContainer              mRenderTrackers;     ///< List of render trackers
 
   bool                                firstRenderCompleted; ///< False until the first render is done
+  Shader*                             defaultShader;        ///< Default shader to use
 };
 
 RenderManager* RenderManager::New( Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQ )
@@ -319,6 +321,11 @@ void RenderManager::RemoveRenderTracker( RenderTracker* renderTracker )
   mImpl->RemoveRenderTracker(renderTracker);
 }
 
+void RenderManager::SetDefaultShader( Shader* shader )
+{
+  mImpl->defaultShader = shader;
+}
+
 bool RenderManager::Render( Integration::RenderStatus& status )
 {
   DALI_PRINT_RENDER_START( mImpl->renderBufferIndex );
@@ -374,26 +381,29 @@ bool RenderManager::Render( Integration::RenderStatus& status )
     // @todo move programs out of context onto a program controller and let that handle this
     mImpl->context.ResetProgramMatrices();
 
-    size_t count = mImpl->instructions.Count( mImpl->renderBufferIndex );
-    for ( size_t i = 0; i < count; ++i )
+    // if we don't have default shader, no point doing the render calls
+    if( mImpl->defaultShader )
     {
-      RenderInstruction& instruction = mImpl->instructions.At( mImpl->renderBufferIndex, i );
+      size_t count = mImpl->instructions.Count( mImpl->renderBufferIndex );
+      for ( size_t i = 0; i < count; ++i )
+      {
+        RenderInstruction& instruction = mImpl->instructions.At( mImpl->renderBufferIndex, i );
 
-      DoRender( instruction, mImpl->lastFrameTime );
+        DoRender( instruction, *mImpl->defaultShader, mImpl->lastFrameTime );
 
-      const RenderListContainer::SizeType countRenderList = instruction.RenderListCount();
-      if ( countRenderList > 0 )
-      {
-        status.SetHasRendered( true );
+        const RenderListContainer::SizeType countRenderList = instruction.RenderListCount();
+        if ( countRenderList > 0 )
+        {
+          status.SetHasRendered( true );
+        }
       }
-    }
-
-    GLenum attachments[] = { GL_DEPTH, GL_STENCIL };
-    mImpl->context.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
+      GLenum attachments[] = { GL_DEPTH, GL_STENCIL };
+      mImpl->context.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
 
-    mImpl->UpdateTrackers();
+      mImpl->UpdateTrackers();
 
-    mImpl->firstRenderCompleted = true;
+      mImpl->firstRenderCompleted = true;
+    }
   }
 
   PERF_MONITOR_END(PerformanceMonitor::DRAW_NODES);
@@ -419,7 +429,7 @@ bool RenderManager::Render( Integration::RenderStatus& status )
   return updateRequired;
 }
 
-void RenderManager::DoRender( RenderInstruction& instruction, float elapsedTime )
+void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime )
 {
   Rect<int> viewportRect;
   Vector4   clearColor;
@@ -498,6 +508,7 @@ void RenderManager::DoRender( RenderInstruction& instruction, float elapsedTime
 
   Render::ProcessRenderInstruction( instruction,
                                     mImpl->context,
+                                    defaultShader,
                                     mImpl->renderBufferIndex,
                                     elapsedTime );
 
index 4c7e357..22575c8 100644 (file)
@@ -50,6 +50,7 @@ class TextureCache;
 class RenderInstruction;
 class RenderInstructionContainer;
 class RenderTracker;
+class Shader;
 
 /**
  * RenderManager is responsible for rendering the result of the previous "update", which
@@ -178,6 +179,12 @@ public:
    */
   void RemoveRenderTracker( RenderTracker* renderTracker );
 
+  /**
+   * Set the default shader that is to be used in absence of custom shader
+   * @param[in] shader that is the default one
+   */
+  void SetDefaultShader( Shader* shader );
+
   // This method should be called from Core::Render()
 
   /**
@@ -192,8 +199,10 @@ private:
   /**
    * Helper to process a single RenderInstruction.
    * @param[in] instruction A description of the rendering operation.
+   * @param[in] defaultShader default shader to use.
+   * @param[in] elapsedTime from previous render.
    */
-  void DoRender( RenderInstruction& instruction, float elapsedTime );
+  void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
 
 private:
 
index cd2ff55..963eb15 100644 (file)
@@ -137,7 +137,7 @@ void Context::GlContextCreated()
 void Context::GlContextDestroyed()
 {
   DALI_LOG_INFO(gContextLogFilter, Debug::Verbose, "Context::GlContextDestroyed()\n");
-
+  SetCurrentProgram( NULL );
   // Inform programs they are no longer valid
   const ProgramContainer::iterator endp = mProgramCache.end();
   for ( ProgramContainer::iterator itp = mProgramCache.begin(); itp != endp; ++itp )
index 5d193fe..679127e 100644 (file)
@@ -33,8 +33,6 @@
 #include <dali/internal/render/shaders/shader.h>
 #include <dali/internal/update/controllers/scene-controller.h>
 
-using namespace std;
-
 namespace
 {
 #if defined(DEBUG_ENABLED)
index 573aec9..6bf81c0 100644 (file)
@@ -37,9 +37,8 @@ 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 Matrix3 gNormalMatrix; ///< a shared matrix to calculate normal matrix, dont want to store it locally to reduce storage overhead
+static Matrix gModelViewProjectionMatrix( false ); ///< a shared matrix to calculate the MVP matrix, dont want to store it in object to reduce storage overhead
+static Matrix3 gNormalMatrix; ///< a shared matrix to calculate normal matrix, dont want to store it in object to reduce storage overhead
 
 /**
  * Helper to set view and projection matrices once per program
@@ -150,6 +149,7 @@ void Renderer::SetSampler( unsigned int samplerBitfield )
 }
 
 void Renderer::Render( BufferIndex bufferIndex,
+                       Shader& defaultShader,
                        const Matrix& modelViewMatrix,
                        const Matrix& viewMatrix,
                        const Matrix& projectionMatrix,
@@ -157,7 +157,12 @@ void Renderer::Render( BufferIndex bufferIndex,
                        bool cull )
 {
   DALI_ASSERT_DEBUG( mContext && "Renderer::Render. Renderer not initialised!! (mContext == NULL)." );
-  DALI_ASSERT_DEBUG( mShader && "Renderer::Render. Shader not set!!" );
+
+  // if mShader is NULL it means we're set to default
+  if( !mShader )
+  {
+    mShader = &defaultShader;
+  }
 
   if( !CheckResources() )
   {
@@ -175,10 +180,16 @@ void Renderer::Render( BufferIndex bufferIndex,
   ShaderSubTypes subType=SHADER_DEFAULT;
   ResolveGeometryTypes( bufferIndex, geometryType, subType );
   unsigned int programIndex = 0;
-  Program& program = mShader->GetProgram( *mContext, geometryType, subType, programIndex );
+  Program* program = mShader->GetProgram( *mContext, geometryType, subType, programIndex );
+  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( *mContext, geometryType, subType, programIndex );
+    DALI_ASSERT_ALWAYS( program && "Default shader is missing a geometry type!!" );
+  }
 
   // Check culling (does not need the program to be in use)
-  if( cull && ! program.ModifiesGeometry() )
+  if( cull && ! program->ModifiesGeometry() )
   {
     if( IsOutsideClipSpace( modelMatrix, gModelViewProjectionMatrix ) )
     {
@@ -188,7 +199,7 @@ void Renderer::Render( BufferIndex bufferIndex,
   }
 
   // Take the program into use so we can send uniforms to it
-  program.Use();
+  program->Use();
 
   // Enables/disables blending mode.
   mContext->SetBlend( mUseBlend );
@@ -219,26 +230,26 @@ void Renderer::Render( BufferIndex bufferIndex,
 
   // 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 );
+  SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix, gModelViewProjectionMatrix );
 
   // set color uniform
-  GLint loc = program.GetUniformLocation( Program::UNIFORM_COLOR );
+  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 );
+    program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
   }
-  loc = program.GetUniformLocation(Program::UNIFORM_TIME_DELTA);
+  loc = program->GetUniformLocation(Program::UNIFORM_TIME_DELTA);
   if( Program::UNIFORM_UNKNOWN != loc )
   {
-    program.SetUniform1f( loc, frametime );
+    program->SetUniform1f( loc, frametime );
   }
 
   // set custom uniforms
-  mShader->SetUniforms( *mContext, program, bufferIndex, programIndex, subType );
+  mShader->SetUniforms( *mContext, *program, bufferIndex, programIndex, subType );
 
   // subclass rendering and actual draw call
-  DoRender( bufferIndex, program, modelViewMatrix, viewMatrix );
+  DoRender( bufferIndex, *program, modelViewMatrix, viewMatrix );
 }
 
 Renderer::Renderer( RenderDataProvider& dataprovider )
index c44e0d3..26c392e 100644 (file)
@@ -112,6 +112,7 @@ public:
   /**
    * Called to render during RenderManager::Render().
    * @param[in] bufferIndex The index of the previous update buffer.
+   * @param[in] defaultShader in case there is no custom shader
    * @param[in] modelViewMatrix The model-view matrix.
    * @param[in] viewMatrix The view matrix.
    * @param[in] projectionMatrix The projection matrix.
@@ -119,6 +120,7 @@ public:
    * @param[in] cull Whether to frustum cull this renderer
    */
   void Render( BufferIndex bufferIndex,
+               Shader& defaultShader,
                const Matrix& modelViewMatrix,
                const Matrix& viewMatrix,
                const Matrix& projectionMatrix,
index c6b605c..d442c3e 100644 (file)
@@ -417,11 +417,9 @@ void Program::GlContextCreated()
 void Program::GlContextDestroyed()
 {
   mLinked = false;
-
   mVertexShaderId = 0;
   mFragmentShaderId = 0;
   mProgramId = 0;
-  mContext.SetCurrentProgram( NULL );
 
   ResetAttribsUniformCache();
 }
index 2cd7859..fe9623f 100644 (file)
@@ -79,7 +79,7 @@ namespace // unnamed namespace
 {
 
 // Convert Geometry type bitmask to an array index
-unsigned int GetGeometryTypeIndex(GeometryType type)
+inline unsigned int GetGeometryTypeIndex(GeometryType type)
 {
   unsigned int index = Log<GEOMETRY_TYPE_IMAGE>::value;
   if ( type & GEOMETRY_TYPE_IMAGE )
@@ -245,16 +245,17 @@ void Shader::SetProgram( GeometryType geometryType,
     theSubType = SHADER_DEFAULT;
   }
 
+  const unsigned int geometryIndex = GetGeometryTypeIndex( geometryType );
   if(geometryType != GEOMETRY_TYPE_TEXT && subType == SHADER_SUBTYPE_ALL)
   {
-    mPrograms[GetGeometryTypeIndex(geometryType)].Resize(1);
-    mPrograms[GetGeometryTypeIndex(geometryType)][theSubType] = program;
-    mPrograms[GetGeometryTypeIndex(geometryType)].mUseDefaultForAllSubtypes = true;
+    mPrograms[geometryIndex].Resize(1);
+    mPrograms[geometryIndex][theSubType] = program;
+    mPrograms[geometryIndex].mUseDefaultForAllSubtypes = true;
   }
   else
   {
-    mPrograms[GetGeometryTypeIndex(geometryType)][theSubType] = program;
-    mPrograms[GetGeometryTypeIndex(geometryType)].mUseDefaultForAllSubtypes = false;
+    mPrograms[geometryIndex][theSubType] = program;
+    mPrograms[geometryIndex].mUseDefaultForAllSubtypes = false;
   }
 
   if( !precompiledBinary )
@@ -277,7 +278,7 @@ bool Shader::AreSubtypesRequired(GeometryType geometryType)
   return ! mPrograms[ programType ].mUseDefaultForAllSubtypes;
 }
 
-Program& Shader::GetProgram( Context& context,
+Program* Shader::GetProgram( Context& context,
                              GeometryType type,
                              ShaderSubTypes subType,
                              unsigned int& programIndex )
@@ -287,12 +288,9 @@ Program& Shader::GetProgram( Context& context,
 
   programIndex = GetGeometryTypeIndex( type );
 
-  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[ programIndex ][ subType ]);
-  return program;
+  return mPrograms[ programIndex ][ subType ];
 }
 
 
index b11f401..379b4af 100644 (file)
@@ -100,7 +100,7 @@ public:
      */
     void Resize(size_t length)
     {
-      mSubPrograms.Resize(length);
+      mSubPrograms.Resize( length, NULL );
     }
 
     /**
@@ -286,7 +286,7 @@ public:
    * @param[out] programIndex returns the program index to be passed onto SetUniforms.
    * @return the program to use.
    */
-  Program& GetProgram( Context& context,
+  Program* GetProgram( Context& context,
                        GeometryType type,
                        ShaderSubTypes subType,
                        unsigned int& programIndex );
index 3bc444a..986b7e6 100644 (file)
@@ -34,14 +34,12 @@ SceneControllerImpl::SceneControllerImpl( RenderMessageDispatcher& renderMessage
                                           RenderQueue& renderQueue,
                                           DiscardQueue& discardQueue,
                                           TextureCache& textureCache,
-                                          CompleteStatusManager& completeStatusManager,
-                                          Shader*& defaultShader )
+                                          CompleteStatusManager& completeStatusManager )
 : mRenderMessageDispatcher( renderMessageDispatcher ),
   mRenderQueue( renderQueue ),
   mDiscardQueue( discardQueue ),
   mTextureCache( textureCache ),
-  mCompleteStatusManager( completeStatusManager ),
-  mDefaultShader( defaultShader )
+  mCompleteStatusManager( completeStatusManager )
 {
   mLightController  = new LightControllerImpl;
 }
index 9a62482..055f502 100644 (file)
@@ -52,8 +52,7 @@ public:
                        RenderQueue& renderQueue,
                        DiscardQueue& discardQueue,
                        TextureCache& textureCache,
-                       CompleteStatusManager& completeStatusManager,
-                       Shader*& defaultShader );
+                       CompleteStatusManager& completeStatusManager );
 
   /**
    * Destructor
@@ -92,11 +91,6 @@ public:  // from SceneController
    */
   virtual CompleteStatusManager& GetCompleteStatusManager() { return mCompleteStatusManager;  }
 
-  /**
-   * @copydoc SceneController::GetDefaultShader()
-   */
-  virtual Shader* GetDefaultShader() { return mDefaultShader; }
-
 private:
 
   // Undefined copy constructor.
@@ -113,7 +107,6 @@ private:
   DiscardQueue&            mDiscardQueue;          ///< discard queue
   TextureCache&            mTextureCache;          ///< texture cache
   CompleteStatusManager&   mCompleteStatusManager; ///< Complete Status manager
-  Shader*&                 mDefaultShader;         ///< default shader, reference to a pointer as it will be setup later
 
 };
 
index 72a4468..39c05bc 100644 (file)
@@ -34,7 +34,6 @@ class RenderMessageDispatcher;
 class RenderQueue;
 class DiscardQueue;
 class TextureCache;
-class Shader;
 
 /**
  * Abstract interface for the scene controller
@@ -96,12 +95,6 @@ public:
    */
   virtual CompleteStatusManager& GetCompleteStatusManager() = 0;
 
-  /**
-   * Return the default shader
-   * @return pointer to the default shader
-   */
-  virtual Shader* GetDefaultShader() = 0;
-
 private:
 
   // Undefined copy constructor.
index 199d97c..6806a55 100644 (file)
@@ -178,7 +178,6 @@ struct UpdateManager::Impl
     systemLevelTaskList ( completeStatusManager ),
     root( NULL ),
     systemLevelRoot( NULL ),
-    defaultShader( NULL ),
     messageQueue( renderController, sceneGraphBuffers ),
     dynamicsChanged( false ),
     keepRenderingSeconds( 0.0f ),
@@ -190,7 +189,7 @@ struct UpdateManager::Impl
     renderSortingHelper(),
     renderTaskWaiting( false )
   {
-    sceneController = new SceneControllerImpl( renderMessageDispatcher, renderQueue, discardQueue, textureCache, completeStatusManager, defaultShader );
+    sceneController = new SceneControllerImpl( renderMessageDispatcher, renderQueue, discardQueue, textureCache, completeStatusManager );
   }
 
   ~Impl()
@@ -268,7 +267,6 @@ struct UpdateManager::Impl
   AnimationContainer                  animations;                    ///< A container of owned animations
   PropertyNotificationContainer       propertyNotifications;         ///< A container of owner property notifications.
 
-  Shader*                             defaultShader;                 ///< The default shader; owned by ShaderContainer
   ShaderContainer                     shaders;                       ///< A container of owned shaders
   AnimatableMeshContainer             animatableMeshes;              ///< A container of owned animatable meshes
   MaterialContainer                   materials;                     ///< A container of owned materials
@@ -532,19 +530,21 @@ void UpdateManager::PropertyNotificationSetNotify( PropertyNotification* propert
   propertyNotification->SetNotifyMode( notifyMode );
 }
 
-Shader* UpdateManager::GetDefaultShader()
-{
-  return mImpl->defaultShader;
-}
-
 void UpdateManager::AddShader( Shader* shader )
 {
   DALI_ASSERT_DEBUG( NULL != shader );
 
-  // Note: The first shader added becomes the default shader
-  if( NULL == mImpl->defaultShader )
+  if( mImpl->shaders.Count() == 0 )
   {
-    mImpl->defaultShader = shader;
+    // the first added shader becomes our default shader
+    // Construct message in the render queue memory; note that delete should not be called on the return value
+    typedef MessageValue1< RenderManager, Shader* > 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( &mImpl->renderManager, &RenderManager::SetDefaultShader, shader );
   }
 
   mImpl->shaders.PushBack( shader );
index 410396b..582505c 100644 (file)
@@ -267,12 +267,6 @@ public:
   // Shaders
 
   /**
-   * Retrieve the default shader.
-   * @return The default shader.
-   */
-  Shader* GetDefaultShader();
-
-  /**
    * Add a newly created shader.
    * @param[in] shader The shader to add.
    * @post The shader is owned by the UpdateManager.
index cf8e95f..7d84eb3 100644 (file)
@@ -190,11 +190,13 @@ void ImageAttachment::SetBorder( BufferIndex updateBufferIndex, const Vector4& b
 
 void ImageAttachment::ShaderChanged( BufferIndex updateBufferIndex )
 {
-  DALI_ASSERT_DEBUG( mShader != NULL );
   DALI_ASSERT_DEBUG( mSceneController );
 
-  int hints = mShader->GetGeometryHints();
-
+  int hints = 0; // default shader hints are 0
+  if( mShader )
+  {
+    hints = mShader->GetGeometryHints();
+  }
   if ( hints != mPreviousRefreshHints )
   {
     mPreviousRefreshHints = hints;
index f903fbf..7008134 100644 (file)
@@ -217,7 +217,7 @@ void RenderableAttachment::ApplyShader( BufferIndex updateBufferIndex, Shader* s
 void RenderableAttachment::RemoveShader( BufferIndex updateBufferIndex )
 {
   // return to default shader
-  mShader = mSceneController->GetDefaultShader();
+  mShader = NULL;
 
   // send the message to renderer
   SendShaderChangeMessage( updateBufferIndex );
@@ -327,8 +327,6 @@ RenderableAttachment::~RenderableAttachment()
 void RenderableAttachment::ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex )
 {
   mSceneController = &sceneController;
-  // get the default shader
-  mShader = mSceneController->GetDefaultShader();
 
   // Chain to derived attachments
   ConnectToSceneGraph2( updateBufferIndex );