2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
34 void texture_set_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void texture_set_test_cleanup(void)
41 test_return_value = TET_PASS;
44 int UtcDaliTextureSetNew01(void)
46 TestApplication application;
48 TextureSet textureSet = TextureSet::New();
50 DALI_TEST_CHECK( textureSet );
54 int UtcDaliTextureSetNew02(void)
56 TestApplication application;
57 TextureSet textureSet;
58 DALI_TEST_CHECK( !textureSet );
62 int UtcDaliTextureSetCopyConstructor(void)
64 TestApplication application;
66 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
67 TextureSet textureSet = TextureSet::New();
68 textureSet.SetImage( 0u, image );
70 TextureSet textureSetCopy(textureSet);
72 DALI_TEST_CHECK( textureSetCopy );
77 int UtcDaliTextureSetAssignmentOperator(void)
79 TestApplication application;
80 TextureSet textureSet = TextureSet::New();
82 TextureSet textureSet2;
83 DALI_TEST_CHECK( !textureSet2 );
85 textureSet2 = textureSet;
86 DALI_TEST_CHECK( textureSet2 );
91 int UtcDaliTextureSetDownCast01(void)
93 TestApplication application;
94 TextureSet textureSet = TextureSet::New();
96 BaseHandle handle(textureSet);
97 TextureSet textureSet2 = TextureSet::DownCast(handle);
98 DALI_TEST_CHECK( textureSet2 );
103 int UtcDaliTextureSetDownCast02(void)
105 TestApplication application;
107 Handle handle = Handle::New(); // Create a custom object
108 TextureSet textureSet = TextureSet::DownCast(handle);
109 DALI_TEST_CHECK( !textureSet );
113 int UtcDaliTextureSetSetImage01(void)
115 TestApplication application;
117 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
119 Shader shader = CreateShader();
120 TextureSet textureSet = CreateTextureSet();
121 textureSet.SetImage( 0u, image );
123 Geometry geometry = CreateQuadGeometry();
124 Renderer renderer = Renderer::New( geometry, shader );
125 renderer.SetTextures( textureSet );
127 Actor actor = Actor::New();
128 actor.AddRenderer(renderer);
129 actor.SetParentOrigin( ParentOrigin::CENTER );
130 actor.SetSize(400, 400);
132 Stage::GetCurrent().Add( actor );
134 TestGlAbstraction& gl = application.GetGlAbstraction();
136 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
137 texParameterTrace.Reset();
138 texParameterTrace.Enable( true );
139 application.SendNotification();
140 application.Render();
143 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
144 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
146 texParameterTrace.Enable( false );
149 // There are three calls to TexParameteri when the texture is first created
150 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
151 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
156 int UtcDaliTextureSetSetImage02(void)
158 TestApplication application;
160 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
162 Shader shader = CreateShader();
163 TextureSet textureSet = CreateTextureSet();
165 Sampler sampler = Sampler::New();
166 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
167 textureSet.SetImage( 0u, image );
168 textureSet.SetSampler( 0u, sampler );
170 Geometry geometry = CreateQuadGeometry();
171 Renderer renderer = Renderer::New( geometry, shader );
172 renderer.SetTextures( textureSet );
174 Actor actor = Actor::New();
175 actor.AddRenderer(renderer);
176 actor.SetParentOrigin( ParentOrigin::CENTER );
177 actor.SetSize(400, 400);
179 Stage::GetCurrent().Add( actor );
181 TestGlAbstraction& gl = application.GetGlAbstraction();
183 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
184 texParameterTrace.Reset();
185 texParameterTrace.Enable( true );
186 application.SendNotification();
187 application.Render();
190 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
191 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
193 texParameterTrace.Enable( false );
196 // There are three calls to TexParameteri when the texture is first created
197 // Texture minification and magnification filters are now different than default so
198 //there should have been two extra TexParameteri calls to set the new filter mode
199 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
204 int UtcDaliTextureSetSetSampler(void)
206 TestApplication application;
208 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
210 Shader shader = CreateShader();
211 TextureSet textureSet = CreateTextureSet( image );
213 Geometry geometry = CreateQuadGeometry();
214 Renderer renderer = Renderer::New( geometry, shader );
215 renderer.SetTextures( textureSet );
217 Actor actor = Actor::New();
218 actor.AddRenderer(renderer);
219 actor.SetParentOrigin( ParentOrigin::CENTER );
220 actor.SetSize(400, 400);
222 Stage::GetCurrent().Add( actor );
224 TestGlAbstraction& gl = application.GetGlAbstraction();
226 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
227 texParameterTrace.Reset();
228 texParameterTrace.Enable( true );
229 application.SendNotification();
230 application.Render();
233 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
234 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
236 texParameterTrace.Enable( false );
239 // There are three calls to TexParameteri when the texture is first created
240 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
241 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
243 texParameterTrace.Reset();
244 texParameterTrace.Enable( true );
246 Sampler sampler = Sampler::New();
247 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
248 textureSet.SetSampler( 0u, sampler );
251 application.SendNotification();
252 application.Render();
254 texParameterTrace.Enable( false );
257 //There should have been two calls to TexParameteri to set the new filtering mode
258 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
264 int UtcDaliTextureSetGetImage(void)
266 TestApplication application;
268 TextureSet textureSet = CreateTextureSet();
269 DALI_TEST_EQUALS( textureSet.GetImage(0), Image(), TEST_LOCATION );
270 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
271 DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
273 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
274 textureSet.SetImage( 0u, image );
276 DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
277 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
278 DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
280 textureSet.SetImage( 2u, image );
281 DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
282 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
283 DALI_TEST_EQUALS( textureSet.GetImage(2), image, TEST_LOCATION );
285 textureSet.SetImage( 2u, Image() );
286 DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
287 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
288 DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
293 int UtcDaliTextureSetGetSampler(void)
295 TestApplication application;
297 TextureSet textureSet = CreateTextureSet();
298 DALI_TEST_EQUALS( textureSet.GetSampler(0), Sampler(), TEST_LOCATION );
299 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
300 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
302 Sampler sampler = Sampler::New();
303 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
304 textureSet.SetSampler( 0u, sampler );
306 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
307 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
308 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
310 textureSet.SetSampler( 2u, sampler );
311 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
312 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
313 DALI_TEST_EQUALS( textureSet.GetSampler(2), sampler, TEST_LOCATION );
315 textureSet.SetSampler( 2u, Sampler() );
316 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
317 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
318 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
323 int UtcDaliTextureSetGetTextureCount(void)
325 TestApplication application;
327 TextureSet textureSet = CreateTextureSet();
328 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
330 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
331 textureSet.SetImage( 0u, image );
332 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
334 textureSet.SetImage( 1u, image );
335 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
337 textureSet.SetSampler( 2u, Sampler::New() );
338 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );