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