Dali 3D User Interface Engine
utc-Dali-ShaderEffects.cpp
Go to the documentation of this file.
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 <iostream>
19 #include <stdlib.h>
22 
47 
48 using namespace Dali;
49 
51 {
52  ToolkitTestApplication application;
53 
55  DALI_TEST_CHECK( !effect.Empty() );
56 
57  Property::Value* customShaderValue = effect.Find( "shader" );
58  DALI_TEST_CHECK( customShaderValue );
59 
60  Property::Map customShader;
61  DALI_TEST_CHECK( customShaderValue->Get( customShader ) );
62 
63  Property::Value* vertexShaderValue = customShader.Find( "vertexShader" );
64  DALI_TEST_CHECK( !vertexShaderValue );
65 
66  Property::Value* fragmentShaderValue = customShader.Find( "fragmentShader" );
67  DALI_TEST_CHECK( fragmentShaderValue );
68 
69  std::string fragmentShader;
70  DALI_TEST_CHECK( fragmentShaderValue->Get( fragmentShader ) );
71  DALI_TEST_CHECK( !fragmentShader.empty() );
72 
73  Property::Value* gridXValue = customShader.Find( "subdivideGridX" );
74  DALI_TEST_CHECK( !gridXValue );
75 
76  Property::Value* gridYValue = customShader.Find( "subdivideGridY" );
77  DALI_TEST_CHECK( !gridYValue );
78 
79  Property::Value* hintsValue = customShader.Find( "hints" );
80  DALI_TEST_CHECK( !hintsValue );
81 
82  END_TEST;
83 }
84 
86 {
87  ToolkitTestApplication application;
88 
90  DALI_TEST_CHECK( effect );
91 
92  END_TEST;
93 }
94 
96 {
97  ToolkitTestApplication application;
98 
100  DALI_TEST_CHECK( effect );
101 
102  END_TEST;
103 }
104 
106 {
107  ToolkitTestApplication application;
108 
109  Vector4 color(1.0f,1.0f,1.0f,1.0f);
110 
112  DALI_TEST_CHECK( effect );
113 
114  Property::Value value = effect.GetProperty( effect.GetPropertyIndex("uAssignedColor"));
115  DALI_TEST_EQUALS( value.Get<Vector4>(), color, TEST_LOCATION );
116 
117  END_TEST;
118 }
119 
121 {
122  ToolkitTestApplication application;
123 
125  DALI_TEST_CHECK( effect );
126 
127  END_TEST;
128 }
129 
131 {
132  ToolkitTestApplication application;
133 
135  DALI_TEST_CHECK( effect );
136 
137  END_TEST;
138 }
139 
141 {
142  ToolkitTestApplication application;
143 
145  DALI_TEST_CHECK( effect );
146 
147  END_TEST;
148 }
149 
150 int UtcDaliCreateDissolveEffect( bool highPrecision )
151 {
152  ToolkitTestApplication application;
153 
154  Property::Map effect = Toolkit::CreateDissolveEffect( highPrecision );
155  DALI_TEST_CHECK( !effect.Empty() );
156 
157  Property::Value* customShaderValue = effect.Find( "shader" );
158  DALI_TEST_CHECK( customShaderValue );
159 
160  Property::Map customShader;
161  DALI_TEST_CHECK( customShaderValue->Get( customShader ) );
162 
163  Property::Value* vertexShaderValue = customShader.Find( "vertexShader" );
164  DALI_TEST_CHECK( vertexShaderValue );
165 
166  std::string vertexShader;
167  DALI_TEST_CHECK( vertexShaderValue->Get( vertexShader ) );
168  DALI_TEST_CHECK( !vertexShader.empty() );
169 
170  Property::Value* fragmentShaderValue = customShader.Find( "fragmentShader" );
171  DALI_TEST_CHECK( fragmentShaderValue );
172 
173  std::string fragmentShader;
174  DALI_TEST_CHECK( fragmentShaderValue->Get( fragmentShader ) );
175  DALI_TEST_CHECK( !fragmentShader.empty() );
176 
177  Property::Value* gridXValue = customShader.Find( "subdivideGridX" );
178  DALI_TEST_CHECK( gridXValue );
179 
180  int gridX = 0;
181  DALI_TEST_CHECK( gridXValue->Get( gridX ) );
182  DALI_TEST_CHECK( gridX > 1 );
183 
184  Property::Value* gridYValue = customShader.Find( "subdivideGridY" );
185  DALI_TEST_CHECK( gridYValue );
186 
187  int gridY = 0;
188  DALI_TEST_CHECK( gridYValue->Get( gridY ) );
189  DALI_TEST_CHECK( gridY > 1 );
190 
191  Property::Value* hintsValue = customShader.Find( "hints" );
192  DALI_TEST_CHECK( hintsValue );
193 
194  std::string hints;
195  DALI_TEST_CHECK( hintsValue->Get( hints ) );
196  DALI_TEST_CHECK( hints == "outputIsTransparent" );
197 
198  Actor actor = Actor::New();
200  DALI_TEST_CHECK( actor.GetPropertyIndex( "uPercentage" ) != Property::INVALID_INDEX );
201 
202  END_TEST;
203 }
204 
206 {
207  return UtcDaliCreateDissolveEffect(true);
208 }
209 
211 {
212  return UtcDaliCreateDissolveEffect(false);
213 }
214 
216 {
217  ToolkitTestApplication application;
218 
220  DALI_TEST_CHECK( effect );
221 
222  END_TEST;
223 }
224 
226 {
227  ToolkitTestApplication application;
228 
230  DALI_TEST_CHECK( !effect.Empty() );
231 
232  Property::Value* customShaderValue = effect.Find( "shader" );
233  DALI_TEST_CHECK( customShaderValue );
234 
235  Property::Map customShader;
236  DALI_TEST_CHECK( customShaderValue->Get( customShader ) );
237 
238  Property::Value* vertexShaderValue = customShader.Find( "vertexShader" );
239  DALI_TEST_CHECK( !vertexShaderValue );
240 
241  Property::Value* fragmentShaderValue = customShader.Find( "fragmentShader" );
242  DALI_TEST_CHECK( fragmentShaderValue );
243 
244  std::string fragmentShader;
245  DALI_TEST_CHECK( fragmentShaderValue->Get( fragmentShader ) );
246  DALI_TEST_CHECK( !fragmentShader.empty() );
247 
248  Property::Value* gridXValue = customShader.Find( "subdivideGridX" );
249  DALI_TEST_CHECK( !gridXValue );
250 
251  Property::Value* hintsValue = customShader.Find( "hints" );
252  DALI_TEST_CHECK( hintsValue );
253 
254  std::string hints;
255  DALI_TEST_CHECK( hintsValue->Get( hints ) );
256  DALI_TEST_CHECK( hints == "outputIsTransparent" );
257 
258  END_TEST;
259 }
260 
262 {
263  ToolkitTestApplication application;
264 
266  DALI_TEST_CHECK( !effect.Empty() );
267 
268  Property::Value* customShaderValue = effect.Find( "shader" );
269  DALI_TEST_CHECK( customShaderValue );
270 
271  Property::Map customShader;
272  DALI_TEST_CHECK( customShaderValue->Get( customShader ) );
273 
274  Property::Value* vertexShaderValue = customShader.Find( "vertexShader" );
275  DALI_TEST_CHECK( vertexShaderValue );
276 
277  std::string vertexShader;
278  DALI_TEST_CHECK( vertexShaderValue->Get( vertexShader ) );
279  DALI_TEST_CHECK( !vertexShader.empty() );
280 
281  Property::Value* fragmentShaderValue = customShader.Find( "fragmentShader" );
282  DALI_TEST_CHECK( !fragmentShaderValue );
283 
284  Property::Value* gridXValue = customShader.Find( "subdivideGridX" );
285  DALI_TEST_CHECK( !gridXValue );
286 
287  Property::Value* gridYValue = customShader.Find( "subdivideGridY" );
288  DALI_TEST_CHECK( !gridYValue );
289 
290  Property::Value* hintsValue = customShader.Find( "hints" );
291  DALI_TEST_CHECK( !hintsValue );
292 
293  END_TEST;
294 }
295 
297 {
298  ToolkitTestApplication application;
299 
301  DALI_TEST_CHECK( effect );
302 
303  END_TEST;
304 }
305 
307 {
308  ToolkitTestApplication application;
309 
310  BufferImage image = CreateBufferImage();
311  ShaderEffect effect = Toolkit::CreateMaskEffect(image);
312  DALI_TEST_CHECK( effect );
313 
314  END_TEST;
315 }
316 
318 {
319  ToolkitTestApplication application;
320 
321  BufferImage image = CreateBufferImage();
323  DALI_TEST_CHECK( effect );
324 
325  END_TEST;
326 }
327 
329 {
330  ToolkitTestApplication application;
331 
333  DALI_TEST_CHECK( !effect.Empty() );
334 
335  Property::Value* customShaderValue = effect.Find( "shader" );
336  DALI_TEST_CHECK( customShaderValue );
337 
338  Property::Map customShader;
339  DALI_TEST_CHECK( customShaderValue->Get( customShader ) );
340 
341  Property::Value* vertexShaderValue = customShader.Find( "vertexShader" );
342  DALI_TEST_CHECK( vertexShaderValue );
343 
344  std::string vertexShader;
345  DALI_TEST_CHECK( vertexShaderValue->Get( vertexShader ) );
346  DALI_TEST_CHECK( !vertexShader.empty() );
347 
348  Property::Value* fragmentShaderValue = customShader.Find( "fragmentShader" );
349  DALI_TEST_CHECK( fragmentShaderValue );
350 
351  std::string fragmentShader;
352  DALI_TEST_CHECK( fragmentShaderValue->Get( fragmentShader ) );
353  DALI_TEST_CHECK( !fragmentShader.empty() );
354 
355  Property::Value* gridXValue = customShader.Find( "subdivideGridX" );
356  DALI_TEST_CHECK( gridXValue );
357 
358  int gridX = 0;
359  DALI_TEST_CHECK( gridXValue->Get( gridX ) );
360  DALI_TEST_CHECK( gridX > 1 );
361 
362  Property::Value* gridYValue = customShader.Find( "subdivideGridY" );
363  DALI_TEST_CHECK( gridYValue );
364 
365  int gridY = 0;
366  DALI_TEST_CHECK( gridYValue->Get( gridY ) );
367  DALI_TEST_CHECK( gridY > 1 );
368 
369  Property::Value* hintsValue = customShader.Find( "hints" );
370  DALI_TEST_CHECK( hintsValue );
371 
372  std::string hints;
373  DALI_TEST_CHECK( hintsValue->Get( hints ) );
374  DALI_TEST_CHECK( hints == "outputIsTransparent" );
375 
376  unsigned int sampleCount( 4 );
377  Actor actor = Actor::New();
378  Toolkit::SetMotionBlurProperties( actor, sampleCount );
379  DALI_TEST_CHECK( actor.GetPropertyIndex( "uBlurTexCoordScale" ) != Property::INVALID_INDEX );
380  DALI_TEST_CHECK( actor.GetPropertyIndex( "uGeometryStretchFactor" ) != Property::INVALID_INDEX );
381  DALI_TEST_CHECK( actor.GetPropertyIndex( "uSpeedScalingFactor" ) != Property::INVALID_INDEX );
382  DALI_TEST_CHECK( actor.GetPropertyIndex( "uObjectFadeStart" ) != Property::INVALID_INDEX );
383  DALI_TEST_CHECK( actor.GetPropertyIndex( "uObjectFadeEnd" ) != Property::INVALID_INDEX );
384  DALI_TEST_CHECK( actor.GetPropertyIndex( "uAlphaScale" ) != Property::INVALID_INDEX );
385  DALI_TEST_CHECK( actor.GetPropertyIndex( "uNumSamples" ) != Property::INVALID_INDEX );
386  DALI_TEST_CHECK( actor.GetPropertyIndex( "uModelLastFrame" ) != Property::INVALID_INDEX );
387 
388  END_TEST;
389 }
390 
392 {
393  ToolkitTestApplication application;
394 
396  DALI_TEST_CHECK( !effect.Empty() );
397 
398  Property::Value* customShaderValue = effect.Find( "shader" );
399  DALI_TEST_CHECK( customShaderValue );
400 
401  Property::Map customShader;
402  DALI_TEST_CHECK( customShaderValue->Get( customShader ) );
403 
404  Property::Value* vertexShaderValue = customShader.Find( "vertexShader" );
405  DALI_TEST_CHECK( vertexShaderValue );
406 
407  std::string vertexShader;
408  DALI_TEST_CHECK( vertexShaderValue->Get( vertexShader ) );
409  DALI_TEST_CHECK( !vertexShader.empty() );
410 
411  Property::Value* fragmentShaderValue = customShader.Find( "fragmentShader" );
412  DALI_TEST_CHECK( fragmentShaderValue );
413 
414  std::string fragmentShader;
415  DALI_TEST_CHECK( fragmentShaderValue->Get( fragmentShader ) );
416  DALI_TEST_CHECK( !fragmentShader.empty() );
417 
418  Property::Value* gridXValue = customShader.Find( "subdivideGridX" );
419  DALI_TEST_CHECK( gridXValue );
420 
421  int gridX = 0;
422  DALI_TEST_CHECK( gridXValue->Get( gridX ) );
423  DALI_TEST_CHECK( gridX > 1 );
424 
425  Property::Value* gridYValue = customShader.Find( "subdivideGridY" );
426  DALI_TEST_CHECK( gridYValue );
427 
428  int gridY = 0;
429  DALI_TEST_CHECK( gridYValue->Get( gridY ) );
430  DALI_TEST_CHECK( gridY > 1 );
431 
432  Property::Value* hintsValue = customShader.Find( "hints" );
433  DALI_TEST_CHECK( hintsValue );
434 
435  std::string hints;
436  DALI_TEST_CHECK( hintsValue->Get( hints ) );
437  DALI_TEST_CHECK( hints == "outputIsTransparent" );
438 
439  Actor actor = Actor::New();
441  DALI_TEST_CHECK( actor.GetPropertyIndex( "uGeometryStretchFactor" ) != Property::INVALID_INDEX );
442  DALI_TEST_CHECK( actor.GetPropertyIndex( "uSpeedScalingFactor" ) != Property::INVALID_INDEX );
443  DALI_TEST_CHECK( actor.GetPropertyIndex( "uObjectFadeStart" ) != Property::INVALID_INDEX );
444  DALI_TEST_CHECK( actor.GetPropertyIndex( "uObjectFadeEnd" ) != Property::INVALID_INDEX );
445  DALI_TEST_CHECK( actor.GetPropertyIndex( "uAlphaScale" ) != Property::INVALID_INDEX );
446  DALI_TEST_CHECK( actor.GetPropertyIndex( "uModelLastFrame" ) != Property::INVALID_INDEX );
447 
448  END_TEST;
449 }
450 
452 {
453  ToolkitTestApplication application;
454 
455  BufferImage image = CreateBufferImage();
457  DALI_TEST_CHECK( effect );
458 
459  END_TEST;
460 }
461 
463 {
464  ToolkitTestApplication application;
465 
467  DALI_TEST_CHECK( effect );
468 
469  END_TEST;
470 }
471 
473 {
474  ToolkitTestApplication application;
475 
477  DALI_TEST_CHECK( effect );
478 
479  END_TEST;
480 }
481 
483 {
484  ToolkitTestApplication application;
485 
487  DALI_TEST_CHECK( effect );
488 
489  END_TEST;
490 }
491 
493 {
494  ToolkitTestApplication application;
495 
497  DALI_TEST_CHECK( effect );
498 
499  END_TEST;
500 }
501 
503 {
504  ToolkitTestApplication application;
505 
507  DALI_TEST_CHECK( effect );
508 
509  END_TEST;
510 }
511 
513 {
514  ToolkitTestApplication application;
515 
517  DALI_TEST_CHECK( effect );
518 
519  END_TEST;
520 }
521 
523 {
524  ToolkitTestApplication application;
525 
527  DALI_TEST_CHECK( effect );
528 
529  END_TEST;
530 }
531 
533 {
534  ToolkitTestApplication application;
535 
537  DALI_TEST_CHECK( effect );
538 
539  END_TEST;
540 }
541 
543 {
544  ToolkitTestApplication application;
545 
547  DALI_TEST_CHECK( effect );
548 
549  END_TEST;
550 }
551 
553 {
554  ToolkitTestApplication application;
555 
557  DALI_TEST_CHECK( effect );
558 
559  END_TEST;
560 }
561 
563 {
564  ToolkitTestApplication application;
565 
567  DALI_TEST_CHECK( effect );
568 
569  END_TEST;
570 }
571 
573 {
574  ToolkitTestApplication application;
575 
577  DALI_TEST_CHECK( effect );
578 
579  END_TEST;
580 }
Dali Docs Home
Read more about Dali