ffb248f9d679adcd1e0d33001f5e6e3192b97456
[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();
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();
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();
267   Renderer renderer = Renderer::New( geometry, material );
268
269   Actor actor = Actor::New();
270   // set a transparent actor color so that blending is enabled
271   actor.SetOpacity( 0.5f );
272   actor.AddRenderer(renderer);
273   actor.SetSize(400, 400);
274   Stage::GetCurrent().Add(actor);
275
276   material.SetBlendFunc(BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE);
277
278   // Test that Set was successful:
279   BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
280   BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
281   BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
282   BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
283   material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
284
285   DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb,    TEST_LOCATION );
286   DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorRgb,   TEST_LOCATION );
287   DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha,  TEST_LOCATION );
288   DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorAlpha, TEST_LOCATION );
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();
311   Renderer renderer = Renderer::New( geometry, material );
312
313   Actor actor = Actor::New();
314   actor.SetOpacity( 0.5f ); // enable blending
315   actor.AddRenderer(renderer);
316   actor.SetSize(400, 400);
317   Stage::GetCurrent().Add(actor);
318
319   material.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
320                          BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
321
322   // Test that Set was successful:
323   {
324     BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
325     BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
326     BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
327     BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
328     material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
329
330     DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR,            srcFactorRgb,    TEST_LOCATION );
331     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR,  destFactorRgb,   TEST_LOCATION );
332     DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA,            srcFactorAlpha,  TEST_LOCATION );
333     DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA,  destFactorAlpha, TEST_LOCATION );
334   }
335
336   application.SendNotification();
337   application.Render();
338
339   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
340   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR,           glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
341   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
342   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA,           glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
343   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
344
345   END_TEST;
346 }
347
348
349
350 int UtcDaliMaterialBlendingOptions03(void)
351 {
352   TestApplication application;
353
354   tet_infoline("Test GetBlendEquation() defaults ");
355
356   Geometry geometry = CreateQuadGeometry();
357   Material material = CreateMaterial();
358   Renderer renderer = Renderer::New( geometry, material );
359
360   Actor actor = Actor::New();
361   actor.AddRenderer(renderer);
362   actor.SetSize(400, 400);
363   Stage::GetCurrent().Add(actor);
364
365   // Test the defaults as documented in blending.h
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   END_TEST;
373 }
374
375
376 int UtcDaliMaterialBlendingOptions04(void)
377 {
378   TestApplication application;
379
380   tet_infoline("Test SetBlendEquation() ");
381
382   Geometry geometry = CreateQuadGeometry();
383   Material material = CreateMaterial();
384   Renderer renderer = Renderer::New( geometry, material );
385
386   Actor actor = Actor::New();
387   actor.SetOpacity( 0.1f );
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();
430   Renderer renderer = Renderer::New( geometry, material );
431
432   Actor actor = Actor::New();
433   actor.SetOpacity( 0.98f );
434   actor.AddRenderer(renderer);
435   actor.SetSize(400, 400);
436   Stage::GetCurrent().Add(actor);
437
438   material.SetBlendMode(BlendingMode::ON);
439
440   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
441   glAbstraction.EnableEnableDisableCallTrace(true);
442
443   application.SendNotification();
444   application.Render();
445
446   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
447   std::ostringstream blendStr;
448   blendStr << GL_BLEND;
449   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
450
451   END_TEST;
452 }
453
454
455 int UtcDaliMaterialSetBlendMode02(void)
456 {
457   TestApplication application;
458
459   tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
460
461   Geometry geometry = CreateQuadGeometry();
462   Material material = CreateMaterial();
463   Renderer renderer = Renderer::New( geometry, material );
464
465   Actor actor = Actor::New();
466   actor.SetOpacity( 0.15f );
467   actor.AddRenderer(renderer);
468   actor.SetSize(400, 400);
469   Stage::GetCurrent().Add(actor);
470
471   material.SetBlendMode(BlendingMode::OFF);
472
473   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
474   glAbstraction.EnableEnableDisableCallTrace(true);
475
476   application.SendNotification();
477   application.Render();
478
479   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
480   std::ostringstream blendStr;
481   blendStr << GL_BLEND;
482   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
483
484   END_TEST;
485 }
486
487 int UtcDaliMaterialSetBlendMode03(void)
488 {
489   TestApplication application;
490
491   tet_infoline("Test setting the blend mode to auto with a transparent material color renders with blending enabled");
492
493   Geometry geometry = CreateQuadGeometry();
494   Material material = CreateMaterial();
495   Renderer renderer = Renderer::New( geometry, material );
496
497   Actor actor = Actor::New();
498   actor.SetOpacity( 0.75f );
499   actor.AddRenderer(renderer);
500   actor.SetSize(400, 400);
501   Stage::GetCurrent().Add(actor);
502
503   material.SetBlendMode(BlendingMode::AUTO);
504
505   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
506   glAbstraction.EnableEnableDisableCallTrace(true);
507
508   application.SendNotification();
509   application.Render();
510
511   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
512   std::ostringstream blendStr;
513   blendStr << GL_BLEND;
514   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
515
516   END_TEST;
517 }
518
519 int UtcDaliMaterialSetBlendMode04(void)
520 {
521   TestApplication application;
522
523   tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
524
525   Geometry geometry = CreateQuadGeometry();
526   Material material = CreateMaterial();
527   Renderer renderer = Renderer::New( geometry, material );
528
529   Actor actor = Actor::New();
530   actor.AddRenderer(renderer);
531   actor.SetSize(400, 400);
532   Stage::GetCurrent().Add(actor);
533
534   material.SetBlendMode(BlendingMode::AUTO);
535
536   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
537   glAbstraction.EnableEnableDisableCallTrace(true);
538
539   application.SendNotification();
540   application.Render();
541
542   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
543   std::ostringstream blendStr;
544   blendStr << GL_BLEND;
545   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
546
547   END_TEST;
548 }
549
550 int UtcDaliMaterialSetBlendMode04b(void)
551 {
552   TestApplication application;
553
554   tet_infoline("Test setting the blend mode to auto with an opaque material color and a transparent actor color renders with blending enabled");
555
556   Geometry geometry = CreateQuadGeometry();
557   Material material = CreateMaterial();
558   Renderer renderer = Renderer::New( geometry, material );
559
560   Actor actor = Actor::New();
561   actor.AddRenderer(renderer);
562   actor.SetSize(400, 400);
563   actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
564   Stage::GetCurrent().Add(actor);
565
566   material.SetBlendMode(BlendingMode::AUTO);
567
568   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
569   glAbstraction.EnableEnableDisableCallTrace(true);
570
571   application.SendNotification();
572   application.Render();
573
574   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
575   std::ostringstream blendStr;
576   blendStr << GL_BLEND;
577   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
578
579   END_TEST;
580 }
581
582 int UtcDaliMaterialSetBlendMode04c(void)
583 {
584   TestApplication application;
585
586   tet_infoline("Test setting the blend mode to auto with an opaque material color and an opaque actor color renders with blending disabled");
587
588   Geometry geometry = CreateQuadGeometry();
589   Material material = CreateMaterial();
590   Renderer renderer = Renderer::New( geometry, material );
591
592   Actor actor = Actor::New();
593   actor.AddRenderer(renderer);
594   actor.SetSize(400, 400);
595   actor.SetColor( Color::MAGENTA );
596   Stage::GetCurrent().Add(actor);
597
598   material.SetBlendMode(BlendingMode::AUTO);
599
600   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
601   glAbstraction.EnableEnableDisableCallTrace(true);
602
603   application.SendNotification();
604   application.Render();
605
606   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
607   std::ostringstream blendStr;
608   blendStr << GL_BLEND;
609   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
610
611   END_TEST;
612 }
613
614 int UtcDaliMaterialSetBlendMode05(void)
615 {
616   TestApplication application;
617
618   tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
619
620   Geometry geometry = CreateQuadGeometry();
621   BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
622   Material material = CreateMaterial( image );
623   Renderer renderer = Renderer::New( geometry, material );
624
625   Actor actor = Actor::New();
626   actor.AddRenderer(renderer);
627   actor.SetSize(400, 400);
628   Stage::GetCurrent().Add(actor);
629
630   material.SetBlendMode(BlendingMode::AUTO);
631
632   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
633   glAbstraction.EnableEnableDisableCallTrace(true);
634
635   application.SendNotification();
636   application.Render();
637
638   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
639   std::ostringstream blendStr;
640   blendStr << GL_BLEND;
641   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
642
643   END_TEST;
644 }
645
646 int UtcDaliMaterialSetBlendMode06(void)
647 {
648   TestApplication application;
649   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");
650
651   Geometry geometry = CreateQuadGeometry();
652   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
653   Material material = Material::New(shader);
654
655   Renderer renderer = Renderer::New( geometry, material );
656
657   Actor actor = Actor::New();
658   actor.AddRenderer(renderer);
659   actor.SetSize(400, 400);
660   Stage::GetCurrent().Add(actor);
661
662   material.SetBlendMode(BlendingMode::AUTO);
663
664   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
665   glAbstraction.EnableEnableDisableCallTrace(true);
666
667   application.SendNotification();
668   application.Render();
669
670   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
671   std::ostringstream blendStr;
672   blendStr << GL_BLEND;
673   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
674
675   END_TEST;
676 }
677
678
679 //Todo: test the Shader::HINT_OUTPUT_IS_OPAQUE would disable the blending, the test cannot pass with current implementation
680 /*int UtcDaliMaterialSetBlendMode07(void)
681 {
682   TestApplication application;
683   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");
684   Geometry geometry = CreateQuadGeometry();
685   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
686   Material material = Material::New(shader);
687
688   Renderer renderer = Renderer::New( geometry, material );
689
690   Actor actor = Actor::New();
691   actor.AddRenderer(renderer);
692   actor.SetSize(400, 400);
693   Stage::GetCurrent().Add(actor);
694
695   material.SetBlendMode(BlendingMode::AUTO);
696
697   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
698   glAbstraction.EnableEnableDisableCallTrace(true);
699
700   application.SendNotification();
701   application.Render();
702
703   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
704   std::ostringstream blendStr;
705   blendStr << GL_BLEND;
706   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
707
708   END_TEST;
709 }*/
710
711 int UtcDaliMaterialSetBlendMode08(void)
712 {
713   TestApplication application;
714   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");
715
716   Geometry geometry = CreateQuadGeometry();
717   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
718   Material material = Material::New(shader);
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.EnableEnableDisableCallTrace(true);
732
733   application.SendNotification();
734   application.Render();
735
736   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
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::AUTO, TEST_LOCATION );
753
754   // ON
755   material.SetBlendMode(BlendingMode::ON);
756   DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::ON, TEST_LOCATION );
757
758   // OFF
759   material.SetBlendMode(BlendingMode::OFF);
760   DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION );
761
762   END_TEST;
763 }
764
765 int UtcDaliMaterialSetBlendColor(void)
766 {
767   TestApplication application;
768
769   tet_infoline("Test SetBlendColor(color)");
770
771   Geometry geometry = CreateQuadGeometry();
772   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
773   Material material = Material::New(shader);
774   BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
775   material.AddTexture( image, "sTexture" );
776   Renderer renderer = Renderer::New( geometry, material );
777
778   Actor actor = Actor::New();
779   actor.AddRenderer(renderer);
780   actor.SetSize(400, 400);
781   Stage::GetCurrent().Add(actor);
782
783   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
784
785   material.SetBlendColor( Color::TRANSPARENT );
786   application.SendNotification();
787   application.Render();
788   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
789
790   material.SetBlendColor( Color::MAGENTA );
791   application.SendNotification();
792   application.Render();
793   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
794
795   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
796   material.SetBlendColor( color );
797   application.SendNotification();
798   application.Render();
799   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
800
801   END_TEST;
802 }
803
804 int UtcDaliMaterialGetBlendColor(void)
805 {
806   TestApplication application;
807
808   tet_infoline("Test GetBlendColor()");
809
810   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
811   Material material = Material::New(shader);
812
813   DALI_TEST_EQUALS( material.GetBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
814
815   material.SetBlendColor( Color::MAGENTA );
816   application.SendNotification();
817   application.Render();
818   DALI_TEST_EQUALS( material.GetBlendColor(), Color::MAGENTA, TEST_LOCATION );
819
820   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
821   material.SetBlendColor( color );
822   application.SendNotification();
823   application.Render();
824   DALI_TEST_EQUALS( material.GetBlendColor(), color, TEST_LOCATION );
825
826   END_TEST;
827 }
828
829 int UtcDaliMaterialConstraint(void)
830 {
831   TestApplication application;
832
833   tet_infoline("Test that a custom material property can be constrained");
834
835   Shader shader = Shader::New( "VertexSource", "FragmentSource");
836   Material material = Material::New( shader );
837
838   Geometry geometry = CreateQuadGeometry();
839   Renderer renderer = Renderer::New( geometry, material );
840
841   Actor actor = Actor::New();
842   actor.AddRenderer(renderer);
843   actor.SetSize(400, 400);
844   Stage::GetCurrent().Add(actor);
845
846   Vector4 initialColor = Color::WHITE;
847   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
848
849   application.SendNotification();
850   application.Render(0);
851   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
852
853   // Apply constraint
854   Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
855   constraint.Apply();
856   application.SendNotification();
857   application.Render(0);
858
859   // Expect no blue component in either buffer - yellow
860   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
861   application.Render(0);
862   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
863
864   material.RemoveConstraints();
865   material.SetProperty(colorIndex, Color::WHITE );
866   application.SendNotification();
867   application.Render(0);
868   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
869
870   END_TEST;
871 }
872
873 int UtcDaliMaterialConstraint02(void)
874 {
875   TestApplication application;
876
877   tet_infoline("Test that a uniform map material property can be constrained");
878
879   Shader shader = Shader::New( "VertexSource", "FragmentSource");
880   Material material = Material::New( shader );
881
882   Geometry geometry = CreateQuadGeometry();
883   Renderer renderer = Renderer::New( geometry, material );
884
885   Actor actor = Actor::New();
886   actor.AddRenderer(renderer);
887   actor.SetSize(400, 400);
888   Stage::GetCurrent().Add(actor);
889   application.SendNotification();
890   application.Render(0);
891
892   Vector4 initialColor = Color::WHITE;
893   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
894
895   TestGlAbstraction& gl = application.GetGlAbstraction();
896
897   application.SendNotification();
898   application.Render(0);
899
900   Vector4 actualValue(Vector4::ZERO);
901   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
902   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
903
904   // Apply constraint
905   Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
906   constraint.Apply();
907   application.SendNotification();
908   application.Render(0);
909
910    // Expect no blue component in either buffer - yellow
911   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
912   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
913
914   application.Render(0);
915   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
916   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
917
918   material.RemoveConstraints();
919   material.SetProperty(colorIndex, Color::WHITE );
920   application.SendNotification();
921   application.Render(0);
922
923   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
924   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
925
926   END_TEST;
927 }
928
929 int UtcDaliMaterialAnimatedProperty01(void)
930 {
931   TestApplication application;
932
933   tet_infoline("Test that a non-uniform material property can be animated");
934
935   Shader shader = Shader::New( "VertexSource", "FragmentSource");
936   Material material = Material::New( shader );
937
938   Geometry geometry = CreateQuadGeometry();
939   Renderer renderer = Renderer::New( geometry, material );
940
941   Actor actor = Actor::New();
942   actor.AddRenderer(renderer);
943   actor.SetSize(400, 400);
944   Stage::GetCurrent().Add(actor);
945
946   Vector4 initialColor = Color::WHITE;
947   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
948
949   application.SendNotification();
950   application.Render(0);
951   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
952
953   Animation  animation = Animation::New(1.0f);
954   KeyFrames keyFrames = KeyFrames::New();
955   keyFrames.Add(0.0f, initialColor);
956   keyFrames.Add(1.0f, Color::TRANSPARENT);
957   animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
958   animation.Play();
959
960   application.SendNotification();
961   application.Render(500);
962
963   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
964
965   application.Render(500);
966
967   DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
968
969   END_TEST;
970 }
971
972 int UtcDaliMaterialAnimatedProperty02(void)
973 {
974   TestApplication application;
975
976   tet_infoline("Test that a uniform map material property can be animated");
977
978   Shader shader = Shader::New( "VertexSource", "FragmentSource");
979   Material material = Material::New( shader );
980
981   Geometry geometry = CreateQuadGeometry();
982   Renderer renderer = Renderer::New( geometry, material );
983
984   Actor actor = Actor::New();
985   actor.AddRenderer(renderer);
986   actor.SetSize(400, 400);
987   Stage::GetCurrent().Add(actor);
988   application.SendNotification();
989   application.Render(0);
990
991   Vector4 initialColor = Color::WHITE;
992   Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
993
994   TestGlAbstraction& gl = application.GetGlAbstraction();
995
996   application.SendNotification();
997   application.Render(0);
998
999   Vector4 actualValue(Vector4::ZERO);
1000   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1001   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1002
1003   Animation  animation = Animation::New(1.0f);
1004   KeyFrames keyFrames = KeyFrames::New();
1005   keyFrames.Add(0.0f, initialColor);
1006   keyFrames.Add(1.0f, Color::TRANSPARENT);
1007   animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
1008   animation.Play();
1009
1010   application.SendNotification();
1011   application.Render(500);
1012
1013   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1014   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1015
1016   application.Render(500);
1017   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1018   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1019
1020   END_TEST;
1021 }
1022
1023
1024 int UtcDaliMaterialSetTextureUniformName01(void)
1025 {
1026   TestApplication application;
1027
1028   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1029
1030   Material material = CreateMaterial();
1031   material.AddTexture( image, "sTexture" );
1032
1033   int textureIndex = material.GetTextureIndex( "sTexture" );
1034   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1035
1036   material.SetTextureUniformName( 0, "sEffectTexture" );
1037   textureIndex = material.GetTextureIndex( "sEffectTexture" );
1038   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1039
1040   Geometry geometry = CreateQuadGeometry();
1041   Renderer renderer = Renderer::New( geometry, material );
1042   Actor actor = Actor::New();
1043   actor.AddRenderer(renderer);
1044   actor.SetParentOrigin( ParentOrigin::CENTER );
1045   actor.SetSize(400, 400);
1046
1047   Stage::GetCurrent().Add( actor );
1048
1049   TestGlAbstraction& gl = application.GetGlAbstraction();
1050
1051   application.SendNotification();
1052   application.Render();
1053
1054   int textureUnit=-1;
1055   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
1056   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1057
1058   END_TEST;
1059 }
1060
1061 int UtcDaliMaterialSetTextureUniformName02(void)
1062 {
1063   TestApplication application;
1064
1065   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1066   Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1067
1068   Material material = CreateMaterial();
1069   material.AddTexture( image, "sTexture");
1070   material.SetTextureUniformName( 0, "sEffectTexture" );
1071   material.AddTexture( image2, "sTexture2");
1072
1073   int textureIndex = material.GetTextureIndex( "sEffectTexture" );
1074   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1075
1076   textureIndex = material.GetTextureIndex( "sTexture2" );
1077   DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
1078
1079   Geometry geometry = CreateQuadGeometry();
1080   Renderer renderer = Renderer::New( geometry, material );
1081   Actor actor = Actor::New();
1082   actor.AddRenderer(renderer);
1083   actor.SetParentOrigin( ParentOrigin::CENTER );
1084   actor.SetSize(400, 400);
1085
1086   Stage::GetCurrent().Add( actor );
1087
1088   TestGlAbstraction& gl = application.GetGlAbstraction();
1089
1090   application.SendNotification();
1091   application.Render();
1092
1093   int textureUnit=-1;
1094   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
1095   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1096
1097   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
1098   DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
1099
1100   END_TEST;
1101 }
1102
1103 int UtcDaliMaterialSetTextureAffectsTransparency(void)
1104 {
1105   TestApplication application;
1106
1107   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1108
1109   Material material = CreateMaterial();
1110   material.AddTexture( image, "sTexture" );
1111
1112   Geometry geometry = CreateQuadGeometry();
1113   Renderer renderer = Renderer::New( geometry, material );
1114   Actor actor = Actor::New();
1115   actor.AddRenderer(renderer);
1116   actor.SetParentOrigin( ParentOrigin::CENTER );
1117   actor.SetSize(400, 400);
1118   Stage::GetCurrent().Add( actor );
1119
1120   TestGlAbstraction& gl = application.GetGlAbstraction();
1121
1122   // Test SetAffectsTransparency( false )
1123   material.SetTextureAffectsTransparency( 0, false );
1124
1125   gl.EnableEnableDisableCallTrace(true);
1126   application.SendNotification();
1127   application.Render();
1128
1129   TraceCallStack& glEnableStack = gl.GetEnableDisableTrace();
1130   std::ostringstream blendStr;
1131   blendStr << GL_BLEND;
1132   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1133
1134   // Test SetAffectsTransparency( true )
1135   material.SetTextureAffectsTransparency( 0, true );
1136
1137   glEnableStack.Reset();
1138   gl.EnableEnableDisableCallTrace(true);
1139   application.SendNotification();
1140   application.Render();
1141
1142   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
1143
1144   END_TEST;
1145 }
1146
1147 int UtcDaliMaterialAddTexture01(void)
1148 {
1149   TestApplication application;
1150
1151   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1152
1153   Material material = CreateMaterial();
1154   material.AddTexture( image, "sTexture");
1155
1156   Geometry geometry = CreateQuadGeometry();
1157   Renderer renderer = Renderer::New( geometry, material );
1158   Actor actor = Actor::New();
1159   actor.AddRenderer(renderer);
1160   actor.SetParentOrigin( ParentOrigin::CENTER );
1161   actor.SetSize(400, 400);
1162
1163   Stage::GetCurrent().Add( actor );
1164
1165   TestGlAbstraction& gl = application.GetGlAbstraction();
1166
1167   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1168   texParameterTrace.Reset();
1169   texParameterTrace.Enable( true );
1170   application.SendNotification();
1171   application.Render();
1172
1173   int textureUnit=-1;
1174   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
1175   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1176
1177   texParameterTrace.Enable( false );
1178
1179   // Verify gl state
1180   // There are three calls to TexParameteri when the texture is first created
1181   // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
1182   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
1183
1184   END_TEST;
1185 }
1186
1187 int UtcDaliMaterialAddTexture02(void)
1188 {
1189   TestApplication application;
1190
1191   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1192
1193   Material material = CreateMaterial();
1194
1195   Sampler sampler = Sampler::New();
1196   sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1197   material.AddTexture( image, "sTexture", sampler );
1198
1199   Geometry geometry = CreateQuadGeometry();
1200   Renderer renderer = Renderer::New( geometry, material );
1201   Actor actor = Actor::New();
1202   actor.AddRenderer(renderer);
1203   actor.SetParentOrigin( ParentOrigin::CENTER );
1204   actor.SetSize(400, 400);
1205
1206   Stage::GetCurrent().Add( actor );
1207
1208   TestGlAbstraction& gl = application.GetGlAbstraction();
1209
1210   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1211   texParameterTrace.Reset();
1212   texParameterTrace.Enable( true );
1213   application.SendNotification();
1214   application.Render();
1215
1216   int textureUnit=-1;
1217   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
1218   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1219
1220   texParameterTrace.Enable( false );
1221
1222   // Verify gl state
1223   // There are three calls to TexParameteri when the texture is first created
1224   // Texture minification and magnification filters are now different than default so
1225   //there should have been two extra TexParameteri calls to set the new filter mode
1226   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
1227
1228   END_TEST;
1229 }
1230
1231 int UtcDaliMaterialRemoveTexture(void)
1232 {
1233   TestApplication application;
1234
1235   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1236
1237   Material material = CreateMaterial();
1238   material.RemoveTexture(0);
1239   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0, TEST_LOCATION );
1240
1241   material.RemoveTexture(1);
1242   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0, TEST_LOCATION );
1243
1244   Sampler sampler = Sampler::New();
1245   sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1246   material.AddTexture( image, "sTexture", sampler );
1247   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1, TEST_LOCATION );
1248
1249   material.RemoveTexture(1);
1250   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1, TEST_LOCATION );
1251
1252   material.RemoveTexture(0);
1253   DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0, TEST_LOCATION );
1254
1255   END_TEST;
1256 }
1257
1258 int UtcDaliMaterialSetSampler(void)
1259 {
1260   TestApplication application;
1261
1262   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1263
1264   Material material = CreateMaterial();
1265   material.AddTexture( image, "sTexture");
1266
1267   Geometry geometry = CreateQuadGeometry();
1268   Renderer renderer = Renderer::New( geometry, material );
1269   Actor actor = Actor::New();
1270   actor.AddRenderer(renderer);
1271   actor.SetParentOrigin( ParentOrigin::CENTER );
1272   actor.SetSize(400, 400);
1273
1274   Stage::GetCurrent().Add( actor );
1275
1276   TestGlAbstraction& gl = application.GetGlAbstraction();
1277
1278   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
1279   texParameterTrace.Reset();
1280   texParameterTrace.Enable( true );
1281   application.SendNotification();
1282   application.Render();
1283
1284   int textureUnit=-1;
1285   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
1286   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
1287
1288   texParameterTrace.Enable( false );
1289
1290   // Verify gl state
1291   // There are three calls to TexParameteri when the texture is first created
1292   // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
1293   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
1294
1295   texParameterTrace.Reset();
1296   texParameterTrace.Enable( true );
1297
1298   Sampler sampler = Sampler::New();
1299   sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1300   material.SetTextureSampler(0, sampler );
1301
1302
1303   application.SendNotification();
1304   application.Render();
1305
1306   texParameterTrace.Enable( false );
1307
1308   // Verify gl state
1309   //There should have been two calls to TexParameteri to set the new filtering mode
1310   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1311
1312
1313   END_TEST;
1314 }
1315
1316 int UtcDaliMaterialGetTextureIndex(void)
1317 {
1318   TestApplication application;
1319
1320   Image image0 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1321   Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1322   Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1323   Image image3 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1324
1325
1326   Material material = CreateMaterial();
1327   material.AddTexture( image0, "sTexture0");
1328   material.AddTexture( image1, "sTexture1");
1329   material.AddTexture( image2, "sTexture2");
1330   material.AddTexture( image3, "sTexture3");
1331
1332   int textureIndex = material.GetTextureIndex( "sTexture0" );
1333   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1334
1335   textureIndex = material.GetTextureIndex( "sTexture1" );
1336   DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
1337
1338   textureIndex = material.GetTextureIndex( "sTexture2" );
1339   DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION );
1340
1341   textureIndex = material.GetTextureIndex( "sTexture3" );
1342   DALI_TEST_EQUALS( textureIndex, 3, TEST_LOCATION );
1343
1344   material.RemoveTexture(1);
1345
1346   textureIndex = material.GetTextureIndex( "sTexture0" );
1347   DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
1348
1349   textureIndex = material.GetTextureIndex( "sTexture2" );
1350   DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
1351
1352   textureIndex = material.GetTextureIndex( "sTexture3" );
1353   DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION );
1354
1355   END_TEST;
1356 }