Fixed bug on SetTextureUniformName
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-devel / utc-Dali-Material.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20
21 using namespace Dali;
22
23 #include <mesh-builder.h>
24
25 namespace
26 {
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
28 {
29   current.b = 0.0f;
30 }
31 }
32
33
34 void material_test_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void material_test_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 int UtcDaliMaterialNew01(void)
45 {
46   TestApplication application;
47
48   Shader shader = Shader::New("vertexSrc", "fragmentSrc");
49   Material material = Material::New(shader);
50
51   DALI_TEST_CHECK( material );
52   END_TEST;
53 }
54
55 int UtcDaliMaterialNew02(void)
56 {
57   TestApplication application;
58   Material material;
59   DALI_TEST_CHECK( !material );
60   END_TEST;
61 }
62
63 int UtcDaliMaterialCopyConstructor(void)
64 {
65   TestApplication application;
66
67   Shader shader = Shader::New("vertexSrc", "fragmentSrc");
68   Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
69   Material material = Material::New(shader);
70   material.AddTexture( image, "sTexture" );
71
72   Material materialCopy(material);
73
74   DALI_TEST_CHECK( materialCopy );
75
76   END_TEST;
77 }
78
79 int UtcDaliMaterialAssignmentOperator(void)
80 {
81   TestApplication application;
82
83   Shader shader = Shader::New("vertexSrc", "fragmentSrc");
84   Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
85   Material material = Material::New(shader);
86
87   Material material2;
88   DALI_TEST_CHECK( !material2 );
89
90   material2 = material;
91   DALI_TEST_CHECK( material2 );
92
93   END_TEST;
94 }
95
96 int UtcDaliMaterialDownCast01(void)
97 {
98   TestApplication application;
99   Shader shader = Shader::New("vertexSrc", "fragmentSrc");
100   Material material = Material::New(shader);
101
102   BaseHandle handle(material);
103   Material material2 = Material::DownCast(handle);
104   DALI_TEST_CHECK( material2 );
105
106   END_TEST;
107 }
108
109 int UtcDaliMaterialDownCast02(void)
110 {
111   TestApplication application;
112
113   Handle handle = Handle::New(); // Create a custom object
114   Material material = Material::DownCast(handle);
115   DALI_TEST_CHECK( !material );
116   END_TEST;
117 }
118
119 int UtcDaliMaterialSetShader(void)
120 {
121   TestApplication application;
122
123   tet_infoline("Test SetShader(shader) ");
124
125   Shader shader1 = Shader::New( "vertexSrc1", "fragmentSrc1" );
126   shader1.RegisterProperty( "uFadeColor", Color::CYAN );
127
128   Shader shader2 = Shader::New( "vertexSrc1", "fragmentSrc1" );
129   shader2.RegisterProperty( "uFadeColor", Color::MAGENTA );
130
131   // shader1
132   Material material = Material::New(shader1);
133
134   Geometry geometry = CreateQuadGeometry();
135   Renderer renderer = Renderer::New( geometry, material );
136
137   Actor actor = Actor::New();
138   actor.AddRenderer(renderer);
139   actor.SetSize(400, 400);
140   Stage::GetCurrent().Add(actor);
141
142   TestGlAbstraction& gl = application.GetGlAbstraction();
143   application.SendNotification();
144   application.Render(0);
145   Vector4 actualValue(Vector4::ZERO);
146   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
147   DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
148
149   // shader2
150   material.SetShader( shader2 );
151
152   application.SendNotification();
153   application.Render(0);
154   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
155   DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
156
157   // shader1
158   material.SetShader( shader1 );
159
160   application.SendNotification();
161   application.Render(0);
162   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
163   DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
164
165   END_TEST;
166 }
167
168 int UtcDaliMaterialGetShader(void)
169 {
170   TestApplication application;
171
172   tet_infoline("Test GetShader() ");
173
174   Shader shader1 = Shader::New( "vertexSrc1", "fragmentSrc1" );
175   Shader shader2 = Shader::New( "vertexSrc1", "fragmentSrc1" );
176
177   // shader1
178   Material material = Material::New(shader1);
179   DALI_TEST_EQUALS( shader1, material.GetShader(), TEST_LOCATION );
180
181   // shader2
182   material.SetShader( shader2 );
183   DALI_TEST_EQUALS( shader2, material.GetShader(), TEST_LOCATION );
184
185   // shader1
186   material.SetShader( shader1 );
187   DALI_TEST_EQUALS( shader1, material.GetShader(), TEST_LOCATION );
188
189   END_TEST;
190 }
191
192 int UtcDaliMaterialGetNumberOfTextures(void)
193 {
194   TestApplication application;
195
196   tet_infoline("Test GetNumberOfTextures()");
197
198   Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
199   Material material = CreateMaterial(0.5f);
200
201   Geometry geometry = CreateQuadGeometry();
202   Renderer renderer = Renderer::New( geometry, material );
203   Actor actor = Actor::New();
204   actor.AddRenderer(renderer);
205   actor.SetParentOrigin( ParentOrigin::CENTER );
206   actor.SetSize(400, 400);
207   Stage::GetCurrent().Add( actor );
208
209   material.AddTexture( image, "sTexture0" );
210   material.AddTexture( image, "sTexture1" );
211   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 2u, TEST_LOCATION );
212
213   material.AddTexture( image, "sTexture2" );
214   material.AddTexture( image, "sTexture3" );
215   material.AddTexture( image, "sTexture4" );
216   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 5u, TEST_LOCATION );
217
218   material.RemoveTexture(3);
219   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 4u, TEST_LOCATION );
220
221   material.RemoveTexture(3);
222   material.RemoveTexture(0);
223   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 2u, TEST_LOCATION );
224
225   END_TEST;
226 }
227
228 int UtcDaliMaterialSetFaceCullingMode(void)
229 {
230   TestApplication application;
231
232   tet_infoline("Test SetFaceCullingMode(cullingMode)");
233   Geometry geometry = CreateQuadGeometry();
234   Material material = CreateMaterial(0.5f);
235   Renderer renderer = Renderer::New( geometry, material );
236
237   Actor actor = Actor::New();
238   actor.AddRenderer(renderer);
239   actor.SetSize(400, 400);
240   Stage::GetCurrent().Add(actor);
241
242   TestGlAbstraction& gl = application.GetGlAbstraction();
243   TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
244   cullFaceStack.Reset();
245   gl.EnableCullFaceCallTrace(true);
246
247   material.SetFaceCullingMode( Material::CULL_BACK_AND_FRONT);
248   application.SendNotification();
249   application.Render();
250
251   // Todo: test the glCullFace(GL_FRONT_AND_BACK) is actually been called, cannot pass this test with current implementation
252   DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION);
253   //string parameter("GL_FRONT_AND_BACK" );
254   //DALI_TEST_CHECK( cullFaceStack.TestMethodAndParams(0, "CullFace", parameter) );
255
256   END_TEST;
257 }
258
259 int UtcDaliMaterialBlendingOptions01(void)
260 {
261   TestApplication application;
262
263   tet_infoline("Test SetBlendFunc(src, dest) ");
264
265   Geometry geometry = CreateQuadGeometry();
266   Material material = CreateMaterial(0.5f);
267   Renderer renderer = Renderer::New( geometry, material );
268
269   Actor actor = Actor::New();
270   actor.AddRenderer(renderer);
271   actor.SetSize(400, 400);
272   Stage::GetCurrent().Add(actor);
273
274   material.SetBlendFunc(BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE);
275
276   // Test that Set was successful:
277   {
278     BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
279     BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
280     BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
281     BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
282     material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
283
284     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb,    TEST_LOCATION );
285     DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorRgb,   TEST_LOCATION );
286     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha,  TEST_LOCATION );
287     DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorAlpha, TEST_LOCATION );
288   }
289
290   application.SendNotification();
291   application.Render();
292
293   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
294
295   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
296   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
297   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
298   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
299
300   END_TEST;
301 }
302
303 int UtcDaliMaterialBlendingOptions02(void)
304 {
305   TestApplication application;
306
307   tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) ");
308
309   Geometry geometry = CreateQuadGeometry();
310   Material material = CreateMaterial(0.5f);
311   Renderer renderer = Renderer::New( geometry, material );
312
313   Actor actor = Actor::New();
314   actor.AddRenderer(renderer);
315   actor.SetSize(400, 400);
316   Stage::GetCurrent().Add(actor);
317
318   material.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
319                          BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
320
321   // Test that Set was successful:
322   {
323     BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
324     BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
325     BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
326     BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
327     material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
328
329     DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR,            srcFactorRgb,    TEST_LOCATION );
330     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR,  destFactorRgb,   TEST_LOCATION );
331     DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA,            srcFactorAlpha,  TEST_LOCATION );
332     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA,  destFactorAlpha, TEST_LOCATION );
333   }
334
335   application.SendNotification();
336   application.Render();
337
338   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
339   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR,           glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
340   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
341   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA,           glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
342   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
343
344   END_TEST;
345 }
346
347
348
349 int UtcDaliMaterialBlendingOptions03(void)
350 {
351   TestApplication application;
352
353   tet_infoline("Test GetBlendEquation() defaults ");
354
355   Geometry geometry = CreateQuadGeometry();
356   Material material = CreateMaterial(0.5f);
357   Renderer renderer = Renderer::New( geometry, material );
358
359   Actor actor = Actor::New();
360   actor.AddRenderer(renderer);
361   actor.SetSize(400, 400);
362   Stage::GetCurrent().Add(actor);
363
364   // Test the defaults as documented in blending.h
365   {
366     BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
367     BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
368     material.GetBlendEquation( equationRgb, equationAlpha );
369     DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
370     DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
371   }
372
373   END_TEST;
374 }
375
376
377 int UtcDaliMaterialBlendingOptions04(void)
378 {
379   TestApplication application;
380
381   tet_infoline("Test SetBlendEquation() ");
382
383   Geometry geometry = CreateQuadGeometry();
384   Material material = CreateMaterial(0.5f);
385   Renderer renderer = Renderer::New( geometry, material );
386
387   Actor actor = Actor::New();
388   actor.AddRenderer(renderer);
389   actor.SetSize(400, 400);
390   Stage::GetCurrent().Add(actor);
391
392   // Test the single blending equation setting
393   {
394     material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
395     BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
396     material.GetBlendEquation( equationRgba, equationRgba );
397     DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
398   }
399
400   material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
401
402   // Test that Set was successful
403   {
404     BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
405     BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
406     material.GetBlendEquation( equationRgb, equationAlpha );
407     DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
408     DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
409   }
410
411   // Render & check GL commands
412   application.SendNotification();
413   application.Render();
414
415   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
416   DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(),   TEST_LOCATION );
417   DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
418
419   END_TEST;
420 }
421
422 int UtcDaliMaterialSetBlendMode01(void)
423 {
424   TestApplication application;
425
426   tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
427
428   Geometry geometry = CreateQuadGeometry();
429   Material material = CreateMaterial(1.0f);
430   Renderer renderer = Renderer::New( geometry, material );
431
432   Actor actor = Actor::New();
433   actor.AddRenderer(renderer);
434   actor.SetSize(400, 400);
435   Stage::GetCurrent().Add(actor);
436
437   material.SetBlendMode(BlendingMode::ON);
438
439   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
440   glAbstraction.EnableCullFaceCallTrace(true);
441
442   application.SendNotification();
443   application.Render();
444
445   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
446   std::ostringstream blendStr;
447   blendStr << GL_BLEND;
448   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
449
450   END_TEST;
451 }
452
453
454 int UtcDaliMaterialSetBlendMode02(void)
455 {
456   TestApplication application;
457
458   tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
459
460   Geometry geometry = CreateQuadGeometry();
461   Material material = CreateMaterial(0.5f);
462   Renderer renderer = Renderer::New( geometry, material );
463
464   Actor actor = Actor::New();
465   actor.AddRenderer(renderer);
466   actor.SetSize(400, 400);
467   Stage::GetCurrent().Add(actor);
468
469   material.SetBlendMode(BlendingMode::OFF);
470
471   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
472   glAbstraction.EnableCullFaceCallTrace(true);
473
474   application.SendNotification();
475   application.Render();
476
477   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
478   std::ostringstream blendStr;
479   blendStr << GL_BLEND;
480   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
481
482   END_TEST;
483 }
484
485 int UtcDaliMaterialSetBlendMode03(void)
486 {
487   TestApplication application;
488
489   tet_infoline("Test setting the blend mode to auto with a transparent material color renders with blending enabled");
490
491   Geometry geometry = CreateQuadGeometry();
492   Material material = CreateMaterial(0.5f);
493   Renderer renderer = Renderer::New( geometry, material );
494
495   Actor actor = Actor::New();
496   actor.AddRenderer(renderer);
497   actor.SetSize(400, 400);
498   Stage::GetCurrent().Add(actor);
499
500   material.SetBlendMode(BlendingMode::AUTO);
501
502   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
503   glAbstraction.EnableCullFaceCallTrace(true);
504
505   application.SendNotification();
506   application.Render();
507
508   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
509   std::ostringstream blendStr;
510   blendStr << GL_BLEND;
511   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
512
513   END_TEST;
514 }
515
516 int UtcDaliMaterialSetBlendMode04(void)
517 {
518   TestApplication application;
519
520   tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
521
522   Geometry geometry = CreateQuadGeometry();
523   Material material = CreateMaterial(1.0f);
524   Renderer renderer = Renderer::New( geometry, material );
525
526   Actor actor = Actor::New();
527   actor.AddRenderer(renderer);
528   actor.SetSize(400, 400);
529   Stage::GetCurrent().Add(actor);
530
531   material.SetBlendMode(BlendingMode::AUTO);
532
533   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
534   glAbstraction.EnableCullFaceCallTrace(true);
535
536   application.SendNotification();
537   application.Render();
538
539   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
540   std::ostringstream blendStr;
541   blendStr << GL_BLEND;
542   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
543
544   END_TEST;
545 }
546
547 int UtcDaliMaterialSetBlendMode04b(void)
548 {
549   TestApplication application;
550
551   tet_infoline("Test setting the blend mode to auto with an opaque material color and a transparent actor color renders with blending enabled");
552
553   Geometry geometry = CreateQuadGeometry();
554   Material material = CreateMaterial(1.0f);
555   Renderer renderer = Renderer::New( geometry, material );
556
557   Actor actor = Actor::New();
558   actor.AddRenderer(renderer);
559   actor.SetSize(400, 400);
560   actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
561   Stage::GetCurrent().Add(actor);
562
563   material.SetBlendMode(BlendingMode::AUTO);
564
565   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
566   glAbstraction.EnableCullFaceCallTrace(true);
567
568   application.SendNotification();
569   application.Render();
570
571   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
572   std::ostringstream blendStr;
573   blendStr << GL_BLEND;
574   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
575
576   END_TEST;
577 }
578
579 int UtcDaliMaterialSetBlendMode04c(void)
580 {
581   TestApplication application;
582
583   tet_infoline("Test setting the blend mode to auto with an opaque material color and an opaque actor color renders with blending disabled");
584
585   Geometry geometry = CreateQuadGeometry();
586   Material material = CreateMaterial(1.0f);
587   Renderer renderer = Renderer::New( geometry, material );
588
589   Actor actor = Actor::New();
590   actor.AddRenderer(renderer);
591   actor.SetSize(400, 400);
592   actor.SetColor( Color::MAGENTA );
593   Stage::GetCurrent().Add(actor);
594
595   material.SetBlendMode(BlendingMode::AUTO);
596
597   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
598   glAbstraction.EnableCullFaceCallTrace(true);
599
600   application.SendNotification();
601   application.Render();
602
603   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
604   std::ostringstream blendStr;
605   blendStr << GL_BLEND;
606   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
607
608   END_TEST;
609 }
610
611 int UtcDaliMaterialSetBlendMode05(void)
612 {
613   TestApplication application;
614
615   tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
616
617   Geometry geometry = CreateQuadGeometry();
618   BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
619   Material material = CreateMaterial(1.0f, image);
620   Renderer renderer = Renderer::New( geometry, material );
621
622   Actor actor = Actor::New();
623   actor.AddRenderer(renderer);
624   actor.SetSize(400, 400);
625   Stage::GetCurrent().Add(actor);
626
627   material.SetBlendMode(BlendingMode::AUTO);
628
629   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
630   glAbstraction.EnableCullFaceCallTrace(true);
631
632   application.SendNotification();
633   application.Render();
634
635   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
636   std::ostringstream blendStr;
637   blendStr << GL_BLEND;
638   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
639
640   END_TEST;
641 }
642
643 int UtcDaliMaterialSetBlendMode06(void)
644 {
645   TestApplication application;
646   tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_TRANSPARENT renders with blending enabled");
647
648   Geometry geometry = CreateQuadGeometry();
649   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
650   Material material = Material::New(shader);
651   material.SetProperty(Material::Property::COLOR, Color::WHITE);
652
653   Renderer renderer = Renderer::New( geometry, material );
654
655   Actor actor = Actor::New();
656   actor.AddRenderer(renderer);
657   actor.SetSize(400, 400);
658   Stage::GetCurrent().Add(actor);
659
660   material.SetBlendMode(BlendingMode::AUTO);
661
662   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
663   glAbstraction.EnableCullFaceCallTrace(true);
664
665   application.SendNotification();
666   application.Render();
667
668   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
669   std::ostringstream blendStr;
670   blendStr << GL_BLEND;
671   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
672
673   END_TEST;
674 }
675
676
677 //Todo: test the Shader::HINT_OUTPUT_IS_OPAQUE would disable the blending, the test cannot pass with current implementation
678 /*int UtcDaliMaterialSetBlendMode07(void)
679 {
680   TestApplication application;
681   tet_infoline("Test setting the blend mode to auto with a transparent color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
682   Geometry geometry = CreateQuadGeometry();
683   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
684   Material material = Material::New(shader);
685   material.SetProperty(Material::Property::COLOR, Color::TRANSPARENT);
686
687   Renderer renderer = Renderer::New( geometry, material );
688
689   Actor actor = Actor::New();
690   actor.AddRenderer(renderer);
691   actor.SetSize(400, 400);
692   Stage::GetCurrent().Add(actor);
693
694   material.SetBlendMode(BlendingMode::AUTO);
695
696   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
697   glAbstraction.EnableCullFaceCallTrace(true);
698
699   application.SendNotification();
700   application.Render();
701
702   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
703   std::ostringstream blendStr;
704   blendStr << GL_BLEND;
705   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
706
707   END_TEST;
708 }*/
709
710 int UtcDaliMaterialSetBlendMode08(void)
711 {
712   TestApplication application;
713   tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
714
715   Geometry geometry = CreateQuadGeometry();
716   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
717   Material material = Material::New(shader);
718   material.SetProperty(Material::Property::COLOR, Color::WHITE);
719   BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
720   material.AddTexture( image, "sTexture" );
721   Renderer renderer = Renderer::New( geometry, material );
722
723   Actor actor = Actor::New();
724   actor.AddRenderer(renderer);
725   actor.SetSize(400, 400);
726   Stage::GetCurrent().Add(actor);
727
728   material.SetBlendMode(BlendingMode::AUTO);
729
730   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
731   glAbstraction.EnableCullFaceCallTrace(true);
732
733   application.SendNotification();
734   application.Render();
735
736   TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
737   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
738
739   END_TEST;
740 }
741
742 int UtcDaliMaterialGetBlendMode(void)
743 {
744   TestApplication application;
745
746   tet_infoline("Test GetBlendMode()");
747
748   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
749   Material material = Material::New(shader);
750
751   // default value
752   DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION );
753
754   // AUTO
755   material.SetBlendMode(BlendingMode::AUTO);
756   DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::AUTO, TEST_LOCATION );
757
758   // ON
759   material.SetBlendMode(BlendingMode::ON);
760   DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::ON, TEST_LOCATION );
761
762   // OFF
763   material.SetBlendMode(BlendingMode::OFF);
764   DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION );
765
766   END_TEST;
767 }
768
769 int UtcDaliMaterialSetBlendColor(void)
770 {
771   TestApplication application;
772
773   tet_infoline("Test SetBlendColor(color)");
774
775   Geometry geometry = CreateQuadGeometry();
776   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
777   Material material = Material::New(shader);
778   material.SetProperty(Material::Property::COLOR, Color::WHITE);
779   BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
780   material.AddTexture( image, "sTexture" );
781   Renderer renderer = Renderer::New( geometry, material );
782
783   Actor actor = Actor::New();
784   actor.AddRenderer(renderer);
785   actor.SetSize(400, 400);
786   Stage::GetCurrent().Add(actor);
787
788   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
789
790   application.SendNotification();
791   application.Render();
792   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
793
794   material.SetBlendColor( Color::MAGENTA );
795   application.SendNotification();
796   application.Render();
797   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
798
799   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
800   material.SetBlendColor( color );
801   application.SendNotification();
802   application.Render();
803   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
804
805   END_TEST;
806 }
807
808 int UtcDaliMaterialGetBlendColor(void)
809 {
810   TestApplication application;
811
812   tet_infoline("Test GetBlendColor()");
813
814   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
815   Material material = Material::New(shader);
816
817   DALI_TEST_EQUALS( material.GetBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
818
819   material.SetBlendColor( Color::MAGENTA );
820   application.SendNotification();
821   application.Render();
822   DALI_TEST_EQUALS( material.GetBlendColor(), Color::MAGENTA, TEST_LOCATION );
823
824   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
825   material.SetBlendColor( color );
826   application.SendNotification();
827   application.Render();
828   DALI_TEST_EQUALS( material.GetBlendColor(), color, TEST_LOCATION );
829
830   END_TEST;
831 }
832
833 int UtcDaliMaterialConstraint(void)
834 {
835   TestApplication application;
836
837   tet_infoline("Test that a custom material property can be constrained");
838
839   Shader shader = Shader::New( "VertexSource", "FragmentSource");
840   Material material = Material::New( shader );
841   material.SetProperty(Material::Property::COLOR, Color::WHITE);
842
843   Geometry geometry = CreateQuadGeometry();
844   Renderer renderer = Renderer::New( geometry, material );
845
846   Actor actor = Actor::New();
847   actor.AddRenderer(renderer);
848   actor.SetSize(400, 400);
849   Stage::GetCurrent().Add(actor);
850
851   Vector4 initialColor = Color::WHITE;
852   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
853
854   application.SendNotification();
855   application.Render(0);
856   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
857
858   // Apply constraint
859   Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
860   constraint.Apply();
861   application.SendNotification();
862   application.Render(0);
863
864   // Expect no blue component in either buffer - yellow
865   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
866   application.Render(0);
867   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
868
869   material.RemoveConstraints();
870   material.SetProperty(colorIndex, Color::WHITE );
871   application.SendNotification();
872   application.Render(0);
873   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
874
875   END_TEST;
876 }
877
878 int UtcDaliMaterialConstraint02(void)
879 {
880   TestApplication application;
881
882   tet_infoline("Test that a uniform map material property can be constrained");
883
884   Shader shader = Shader::New( "VertexSource", "FragmentSource");
885   Material material = Material::New( shader );
886   material.SetProperty(Material::Property::COLOR, Color::WHITE);
887
888   Geometry geometry = CreateQuadGeometry();
889   Renderer renderer = Renderer::New( geometry, material );
890
891   Actor actor = Actor::New();
892   actor.AddRenderer(renderer);
893   actor.SetSize(400, 400);
894   Stage::GetCurrent().Add(actor);
895   application.SendNotification();
896   application.Render(0);
897
898   Vector4 initialColor = Color::WHITE;
899   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
900
901   TestGlAbstraction& gl = application.GetGlAbstraction();
902
903   application.SendNotification();
904   application.Render(0);
905
906   Vector4 actualValue(Vector4::ZERO);
907   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
908   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
909
910   // Apply constraint
911   Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
912   constraint.Apply();
913   application.SendNotification();
914   application.Render(0);
915
916    // Expect no blue component in either buffer - yellow
917   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
918   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
919
920   application.Render(0);
921   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
922   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
923
924   material.RemoveConstraints();
925   material.SetProperty(colorIndex, Color::WHITE );
926   application.SendNotification();
927   application.Render(0);
928
929   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
930   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
931
932   END_TEST;
933 }
934
935 int UtcDaliMaterialAnimatedProperty01(void)
936 {
937   TestApplication application;
938
939   tet_infoline("Test that a non-uniform material property can be animated");
940
941   Shader shader = Shader::New( "VertexSource", "FragmentSource");
942   Material material = Material::New( shader );
943   material.SetProperty(Material::Property::COLOR, Color::WHITE);
944
945   Geometry geometry = CreateQuadGeometry();
946   Renderer renderer = Renderer::New( geometry, material );
947
948   Actor actor = Actor::New();
949   actor.AddRenderer(renderer);
950   actor.SetSize(400, 400);
951   Stage::GetCurrent().Add(actor);
952
953   Vector4 initialColor = Color::WHITE;
954   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
955
956   application.SendNotification();
957   application.Render(0);
958   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
959
960   Animation  animation = Animation::New(1.0f);
961   KeyFrames keyFrames = KeyFrames::New();
962   keyFrames.Add(0.0f, initialColor);
963   keyFrames.Add(1.0f, Color::TRANSPARENT);
964   animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
965   animation.Play();
966
967   application.SendNotification();
968   application.Render(500);
969
970   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
971
972   application.Render(500);
973
974   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
975
976   END_TEST;
977 }
978
979 int UtcDaliMaterialAnimatedProperty02(void)
980 {
981   TestApplication application;
982
983   tet_infoline("Test that a uniform map material property can be animated");
984
985   Shader shader = Shader::New( "VertexSource", "FragmentSource");
986   Material material = Material::New( shader );
987   material.SetProperty(Material::Property::COLOR, Color::WHITE);
988
989   Geometry geometry = CreateQuadGeometry();
990   Renderer renderer = Renderer::New( geometry, material );
991
992   Actor actor = Actor::New();
993   actor.AddRenderer(renderer);
994   actor.SetSize(400, 400);
995   Stage::GetCurrent().Add(actor);
996   application.SendNotification();
997   application.Render(0);
998
999   Vector4 initialColor = Color::WHITE;
1000   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
1001
1002   TestGlAbstraction& gl = application.GetGlAbstraction();
1003
1004   application.SendNotification();
1005   application.Render(0);
1006
1007   Vector4 actualValue(Vector4::ZERO);
1008   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1009   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1010
1011   Animation  animation = Animation::New(1.0f);
1012   KeyFrames keyFrames = KeyFrames::New();
1013   keyFrames.Add(0.0f, initialColor);
1014   keyFrames.Add(1.0f, Color::TRANSPARENT);
1015   animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
1016   animation.Play();
1017
1018   application.SendNotification();
1019   application.Render(500);
1020
1021   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1022   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1023
1024   application.Render(500);
1025   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1026   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1027
1028   END_TEST;
1029 }
1030
1031
1032 int UtcDaliMaterialSetTextureUniformName01(void)
1033 {
1034   TestApplication application;
1035
1036   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1037
1038   Material material = CreateMaterial(1.0f);
1039   material.AddTexture( image, "sTexture" );
1040
1041   int textureIndex = material.GetTextureIndex( "sTexture" );
1042   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1043
1044   material.SetTextureUniformName( 0, "sEffectTexture" );
1045   textureIndex = material.GetTextureIndex( "sEffectTexture" );
1046   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1047
1048   Geometry geometry = CreateQuadGeometry();
1049   Renderer renderer = Renderer::New( geometry, material );
1050   Actor actor = Actor::New();
1051   actor.AddRenderer(renderer);
1052   actor.SetParentOrigin( ParentOrigin::CENTER );
1053   actor.SetSize(400, 400);
1054
1055   Stage::GetCurrent().Add( actor );
1056
1057   TestGlAbstraction& gl = application.GetGlAbstraction();
1058
1059   application.SendNotification();
1060   application.Render();
1061
1062   int textureUnit=-1;
1063   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
1064   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1065
1066   END_TEST;
1067 }
1068
1069 int UtcDaliMaterialSetTextureUniformName02(void)
1070 {
1071   TestApplication application;
1072
1073   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1074   Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1075
1076   Material material = CreateMaterial(1.0f);
1077   material.AddTexture( image, "sTexture");
1078   material.SetTextureUniformName( 0, "sEffectTexture" );
1079   material.AddTexture( image2, "sTexture2");
1080
1081   int textureIndex = material.GetTextureIndex( "sEffectTexture" );
1082   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1083
1084   textureIndex = material.GetTextureIndex( "sTexture2" );
1085   DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
1086
1087   Geometry geometry = CreateQuadGeometry();
1088   Renderer renderer = Renderer::New( geometry, material );
1089   Actor actor = Actor::New();
1090   actor.AddRenderer(renderer);
1091   actor.SetParentOrigin( ParentOrigin::CENTER );
1092   actor.SetSize(400, 400);
1093
1094   Stage::GetCurrent().Add( actor );
1095
1096   TestGlAbstraction& gl = application.GetGlAbstraction();
1097
1098   application.SendNotification();
1099   application.Render();
1100
1101   int textureUnit=-1;
1102   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
1103   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1104
1105   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
1106   DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
1107
1108   END_TEST;
1109 }
1110
1111 int UtcDaliMaterialSetTextureAffectsTransparency(void)
1112 {
1113   TestApplication application;
1114
1115   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1116
1117   Material material = CreateMaterial(1.0f);
1118   material.AddTexture( image, "sTexture" );
1119
1120   Geometry geometry = CreateQuadGeometry();
1121   Renderer renderer = Renderer::New( geometry, material );
1122   Actor actor = Actor::New();
1123   actor.AddRenderer(renderer);
1124   actor.SetParentOrigin( ParentOrigin::CENTER );
1125   actor.SetSize(400, 400);
1126   Stage::GetCurrent().Add( actor );
1127
1128   TestGlAbstraction& gl = application.GetGlAbstraction();
1129
1130   // Test SetAffectsTransparency( false )
1131   material.SetTextureAffectsTransparency( 0, false );
1132
1133   gl.EnableCullFaceCallTrace(true);
1134   application.SendNotification();
1135   application.Render();
1136
1137   TraceCallStack& glEnableStack = gl.GetCullFaceTrace();
1138   std::ostringstream blendStr;
1139   blendStr << GL_BLEND;
1140   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1141
1142   // Test SetAffectsTransparency( true )
1143   material.SetTextureAffectsTransparency( 0, true );
1144
1145   glEnableStack.Reset();
1146   gl.EnableCullFaceCallTrace(true);
1147   application.SendNotification();
1148   application.Render();
1149
1150   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1151
1152   END_TEST;
1153 }
1154
1155 int UtcDaliMaterialAddTexture01(void)
1156 {
1157   TestApplication application;
1158
1159   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1160
1161   Material material = CreateMaterial(1.0f);
1162   material.AddTexture( image, "sTexture");
1163
1164   Geometry geometry = CreateQuadGeometry();
1165   Renderer renderer = Renderer::New( geometry, material );
1166   Actor actor = Actor::New();
1167   actor.AddRenderer(renderer);
1168   actor.SetParentOrigin( ParentOrigin::CENTER );
1169   actor.SetSize(400, 400);
1170
1171   Stage::GetCurrent().Add( actor );
1172
1173   TestGlAbstraction& gl = application.GetGlAbstraction();
1174
1175   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1176   texParameterTrace.Reset();
1177   texParameterTrace.Enable( true );
1178   application.SendNotification();
1179   application.Render();
1180
1181   int textureUnit=-1;
1182   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
1183   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1184
1185   texParameterTrace.Enable( false );
1186
1187   // Verify gl state
1188   // There are three calls to TexParameteri when the texture is first created
1189   // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
1190   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
1191
1192   END_TEST;
1193 }
1194
1195 int UtcDaliMaterialAddTexture02(void)
1196 {
1197   TestApplication application;
1198
1199   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1200
1201   Material material = CreateMaterial(1.0f);
1202
1203   Sampler sampler = Sampler::New();
1204   sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1205   material.AddTexture( image, "sTexture", sampler );
1206
1207   Geometry geometry = CreateQuadGeometry();
1208   Renderer renderer = Renderer::New( geometry, material );
1209   Actor actor = Actor::New();
1210   actor.AddRenderer(renderer);
1211   actor.SetParentOrigin( ParentOrigin::CENTER );
1212   actor.SetSize(400, 400);
1213
1214   Stage::GetCurrent().Add( actor );
1215
1216   TestGlAbstraction& gl = application.GetGlAbstraction();
1217
1218   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1219   texParameterTrace.Reset();
1220   texParameterTrace.Enable( true );
1221   application.SendNotification();
1222   application.Render();
1223
1224   int textureUnit=-1;
1225   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
1226   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1227
1228   texParameterTrace.Enable( false );
1229
1230   // Verify gl state
1231   // There are three calls to TexParameteri when the texture is first created
1232   // Texture minification and magnification filters are now different than default so
1233   //there should have been two extra TexParameteri calls to set the new filter mode
1234   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
1235
1236   END_TEST;
1237 }
1238
1239 int UtcDaliMaterialRemoveTexture(void)
1240 {
1241   TestApplication application;
1242
1243   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1244
1245   Material material = CreateMaterial(1.0f);
1246   material.RemoveTexture(0);
1247   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0, TEST_LOCATION );
1248
1249   material.RemoveTexture(1);
1250   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0, TEST_LOCATION );
1251
1252   Sampler sampler = Sampler::New();
1253   sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1254   material.AddTexture( image, "sTexture", sampler );
1255   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1, TEST_LOCATION );
1256
1257   material.RemoveTexture(1);
1258   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1, TEST_LOCATION );
1259
1260   material.RemoveTexture(0);
1261   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0, TEST_LOCATION );
1262
1263   END_TEST;
1264 }
1265
1266 int UtcDaliMaterialSetSampler(void)
1267 {
1268   TestApplication application;
1269
1270   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1271
1272   Material material = CreateMaterial(1.0f);
1273   material.AddTexture( image, "sTexture");
1274
1275   Geometry geometry = CreateQuadGeometry();
1276   Renderer renderer = Renderer::New( geometry, material );
1277   Actor actor = Actor::New();
1278   actor.AddRenderer(renderer);
1279   actor.SetParentOrigin( ParentOrigin::CENTER );
1280   actor.SetSize(400, 400);
1281
1282   Stage::GetCurrent().Add( actor );
1283
1284   TestGlAbstraction& gl = application.GetGlAbstraction();
1285
1286   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1287   texParameterTrace.Reset();
1288   texParameterTrace.Enable( true );
1289   application.SendNotification();
1290   application.Render();
1291
1292   int textureUnit=-1;
1293   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
1294   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1295
1296   texParameterTrace.Enable( false );
1297
1298   // Verify gl state
1299   // There are three calls to TexParameteri when the texture is first created
1300   // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
1301   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
1302
1303   texParameterTrace.Reset();
1304   texParameterTrace.Enable( true );
1305
1306   Sampler sampler = Sampler::New();
1307   sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1308   material.SetTextureSampler(0, sampler );
1309
1310
1311   application.SendNotification();
1312   application.Render();
1313
1314   texParameterTrace.Enable( false );
1315
1316   // Verify gl state
1317   //There should have been two calls to TexParameteri to set the new filtering mode
1318   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1319
1320
1321   END_TEST;
1322 }
1323
1324 int UtcDaliMaterialGetTextureIndex(void)
1325 {
1326   TestApplication application;
1327
1328   Image image0 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1329   Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1330   Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1331   Image image3 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1332
1333
1334   Material material = CreateMaterial(1.0f);
1335   material.AddTexture( image0, "sTexture0");
1336   material.AddTexture( image1, "sTexture1");
1337   material.AddTexture( image2, "sTexture2");
1338   material.AddTexture( image3, "sTexture3");
1339
1340   int textureIndex = material.GetTextureIndex( "sTexture0" );
1341   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1342
1343   textureIndex = material.GetTextureIndex( "sTexture1" );
1344   DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
1345
1346   textureIndex = material.GetTextureIndex( "sTexture2" );
1347   DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION );
1348
1349   textureIndex = material.GetTextureIndex( "sTexture3" );
1350   DALI_TEST_EQUALS( textureIndex, 3, TEST_LOCATION );
1351
1352   material.RemoveTexture(1);
1353
1354   textureIndex = material.GetTextureIndex( "sTexture0" );
1355   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1356
1357   textureIndex = material.GetTextureIndex( "sTexture2" );
1358   DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
1359
1360   textureIndex = material.GetTextureIndex( "sTexture3" );
1361   DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION );
1362
1363   END_TEST;
1364 }