Remove uniform mappings.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Sampler.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 void sampler_test_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void sampler_test_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 int UtcDaliSamplerNew01(void)
36 {
37   TestApplication application;
38
39   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
40   Sampler sampler = Sampler::New(image, "sTexture");
41
42   DALI_TEST_EQUALS( (bool)sampler, true, TEST_LOCATION );
43   END_TEST;
44 }
45
46 int UtcDaliSamplerNew02(void)
47 {
48   TestApplication application;
49   Sampler sampler;
50   DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
51   END_TEST;
52 }
53
54 int UtcDaliSamplerDownCast01(void)
55 {
56   TestApplication application;
57   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
58   Sampler sampler = Sampler::New(image, "sTexture");
59
60   BaseHandle handle(sampler);
61   Sampler sampler2 = Sampler::DownCast(handle);
62   DALI_TEST_EQUALS( (bool)sampler2, true, TEST_LOCATION );
63   END_TEST;
64 }
65
66 int UtcDaliSamplerDownCast02(void)
67 {
68   TestApplication application;
69
70   BaseHandle handle;
71   Sampler sampler = Sampler::DownCast(handle);
72   DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
73   END_TEST;
74 }
75
76
77 int UtcDaliSamplerSetUniformName01(void)
78 {
79   TestApplication application;
80
81   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
82   Sampler sampler = Sampler::New(image, "sTexture");
83   sampler.SetUniformName( "sEffectTexture" );
84
85   Material material = CreateMaterial(1.0f);
86   material.AddSampler( sampler );
87
88   Geometry geometry = CreateQuadGeometry();
89   Renderer renderer = Renderer::New( geometry, material );
90   Actor actor = Actor::New();
91   actor.AddRenderer(renderer);
92   actor.SetParentOrigin( ParentOrigin::CENTER );
93   actor.SetSize(400, 400);
94
95   Stage::GetCurrent().Add( actor );
96
97   TestGlAbstraction& gl = application.GetGlAbstraction();
98
99   application.SendNotification();
100   application.Render();
101
102   int textureUnit=-1;
103   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
104   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
105
106   END_TEST;
107 }
108
109
110 int UtcDaliSamplerSetUniformName02(void)
111 {
112   TestApplication application;
113
114   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
115   Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
116   Sampler sampler1 = Sampler::New(image, "sTexture");
117   sampler1.SetUniformName( "sEffectTexture" );
118
119   Sampler sampler2 = Sampler::New(image2, "sTexture2");
120
121   Material material = CreateMaterial(1.0f);
122   material.AddSampler( sampler1 );
123   material.AddSampler( sampler2 );
124
125   Geometry geometry = CreateQuadGeometry();
126   Renderer renderer = Renderer::New( geometry, material );
127   Actor actor = Actor::New();
128   actor.AddRenderer(renderer);
129   actor.SetParentOrigin( ParentOrigin::CENTER );
130   actor.SetSize(400, 400);
131
132   Stage::GetCurrent().Add( actor );
133
134   TestGlAbstraction& gl = application.GetGlAbstraction();
135
136   application.SendNotification();
137   application.Render();
138
139   int textureUnit=-1;
140   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
141   DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
142
143   DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
144   DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
145
146   END_TEST;
147 }
148
149
150 int UtcDaliSamplerUniformMap01(void)
151 {
152   TestApplication application;
153
154   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
155   Sampler sampler = Sampler::New(image, "sTexture");
156   sampler.SetUniformName( "sEffectTexture" );
157
158   Material material = CreateMaterial(1.0f);
159   material.AddSampler( sampler );
160
161   Geometry geometry = CreateQuadGeometry();
162   Renderer renderer = Renderer::New( geometry, material );
163   Actor actor = Actor::New();
164   actor.AddRenderer(renderer);
165   actor.SetParentOrigin( ParentOrigin::CENTER );
166   actor.SetSize(400, 400);
167   Stage::GetCurrent().Add( actor );
168
169   float initialValue = 1.0f;
170   Property::Index widthClampIndex = sampler.RegisterProperty("uWidthClamp", initialValue );
171
172   TestGlAbstraction& gl = application.GetGlAbstraction();
173
174   application.SendNotification();
175   application.Render();
176
177   float actualValue=0.0f;
178   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uWidthClamp", actualValue ) );
179   DALI_TEST_EQUALS( actualValue, initialValue, TEST_LOCATION );
180
181   Animation  animation = Animation::New(1.0f);
182   KeyFrames keyFrames = KeyFrames::New();
183   keyFrames.Add(0.0f, 0.0f);
184   keyFrames.Add(1.0f, 640.0f);
185   animation.AnimateBetween( Property( sampler, widthClampIndex ), keyFrames );
186   animation.Play();
187
188   application.SendNotification();
189   application.Render( 500 );
190
191   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uWidthClamp", actualValue ) );
192   DALI_TEST_EQUALS( actualValue, 320.0f, TEST_LOCATION );
193
194   application.Render( 500 );
195   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uWidthClamp", actualValue ) );
196   DALI_TEST_EQUALS( actualValue, 640.0f, TEST_LOCATION );
197
198   END_TEST;
199 }