Lazy load programs 87/27087/2
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 4 Sep 2014 09:07:46 +0000 (10:07 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 4 Sep 2014 14:24:48 +0000 (15:24 +0100)
[Problem] startup is slow
[Cause] unnecessary loading of shaders that may not be used
[Solution] lazy load

Change-Id: I7ad9d8182aa2e1e650decb04cebf6f7752b99afc

automated-tests/src/dali/utc-Dali-ShaderEffect.cpp
dali/internal/render/shaders/program.cpp

index e57f493..1fa2684 100644 (file)
@@ -281,6 +281,8 @@ int UtcDaliShaderEffectMethodDelete01(void)
    application.SendNotification();
    application.Render();
 
+   GLuint beforeShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
+
    // create a new shader effect
    // the vertex and fragment shader will be cached in the ShaderFactory
    ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
@@ -297,16 +299,8 @@ int UtcDaliShaderEffectMethodDelete01(void)
    application.Render();
 
    GLuint lastShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
-
-   // get the vertex shader (compiled before fragment shader).
-   // this last shaders compiled is for text.
-   GLuint vertexShaderId = lastShaderCompiled - 1;
-
-   // compare the vertex shader sent to be compiled, with the shader string that ended up being compiled
-   // this is to confirm the string hasn't been deleted / corrupted.
-   std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( vertexShaderId );
-   DALI_TEST_EQUALS( VertexSource,
-                     actualVertexShader.substr( actualVertexShader.length() - strlen( VertexSource ) ), TEST_LOCATION );
+   // no shaders were compiled as they are now compiled on demand and this shader was not used
+   DALI_TEST_EQUALS( beforeShaderCompiled, lastShaderCompiled, TEST_LOCATION );
 
    END_TEST;
 }
index c25fdb0..0deb6f6 100644 (file)
@@ -128,7 +128,7 @@ Program* Program::New( const Integration::ResourceId& resourceId, Integration::S
     // program not found so create it
     program = new Program( shaderData, context, modifiesGeometry );
 
-    program->Load();
+    // we want to lazy load programs so dont do a Load yet, it gets done in Use
 
     // tell context to cache it
     context.CacheProgram( shaderHash, program );