Dali 3D User Interface Engine
utc-Dali-Sampler.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 <unistd.h>
20 #include <dali-test-suite-utils.h>
21 
22 using namespace Dali;
23 
24 #include <mesh-builder.h>
25 
27 {
29 }
30 
32 {
34 }
35 
37 {
38  TestApplication application;
39  Sampler sampler = Sampler::New();
40 
41  DALI_TEST_EQUALS( (bool)sampler, true, TEST_LOCATION );
42  END_TEST;
43 }
44 
46 {
47  TestApplication application;
48  Sampler sampler;
49  DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
50  END_TEST;
51 }
52 
54 {
55  TestApplication application;
56  tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
57 
58  // Initialize an object, ref count == 1
59  Sampler sampler = Sampler::New();
60 
62 
63  // Copy the object, ref count == 2
64  Sampler copy(sampler);
65  DALI_TEST_CHECK(copy);
66  if (copy)
67  {
68  DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
69  }
70 
71  END_TEST;
72 }
73 
74 
76 {
77  TestApplication application;
78  Sampler sampler = Sampler::New();
79 
80  BaseHandle handle(sampler);
81  Sampler sampler2 = Sampler::DownCast(handle);
82  DALI_TEST_EQUALS( (bool)sampler2, true, TEST_LOCATION );
83  END_TEST;
84 }
85 
87 {
88  TestApplication application;
89 
90  BaseHandle handle;
91  Sampler sampler = Sampler::DownCast(handle);
92  DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
93  END_TEST;
94 }
95 
97 {
98  TestApplication application;
99  Sampler sampler1 = Sampler::New();
100 
101  Sampler sampler2;
102 
103  DALI_TEST_CHECK(!(sampler1 == sampler2));
104 
105  sampler2 = sampler1;
106 
107  DALI_TEST_CHECK(sampler1 == sampler2);
108 
109  sampler2 = Sampler::New();
110 
111  DALI_TEST_CHECK(!(sampler1 == sampler2));
112 
113  END_TEST;
114 }
115 
116 
118 {
119  TestApplication application;
120 
121  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
122  Sampler sampler = Sampler::New();
123 
124  Material material = CreateMaterial();
125  material.AddTexture( image, "sTexture", sampler );
126 
127  Geometry geometry = CreateQuadGeometry();
128  Renderer renderer = Renderer::New( geometry, material );
129  Actor actor = Actor::New();
130  actor.AddRenderer(renderer);
132  actor.SetSize(400, 400);
133  Stage::GetCurrent().Add( actor );
134 
135 
136  TestGlAbstraction& gl = application.GetGlAbstraction();
137 
138  /**************************************************************/
139  // Default/Default
140  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
141  texParameterTrace.Reset();
142  texParameterTrace.Enable( true );
143 
145  application.SendNotification();
146  application.Render();
147 
148  texParameterTrace.Enable( false );
149 
150  // Verify gl state
151 
152  // There are three calls to TexParameteri when the texture is first created
153  // Texture mag filter is not called as the first time set it uses the system default
154  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
155 
156  std::stringstream out;
157  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
158  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
159 
160  /**************************************************************/
161  // Default/Default
162  texParameterTrace.Reset();
163  texParameterTrace.Enable( true );
164 
166 
167  // Flush the queue and render once
168  application.SendNotification();
169  application.Render();
170 
171  texParameterTrace.Enable( false );
172 
173  // Verify gl state
174 
175  // Should not make any calls when settings are the same
176  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
177 
178  /**************************************************************/
179  // Nearest/Nearest
180  texParameterTrace.Reset();
181  texParameterTrace.Enable( true );
182 
184 
185  // Flush the queue and render once
186  application.SendNotification();
187  application.Render();
188 
189  texParameterTrace.Enable( false );
190 
191  // Verify actor gl state
192  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
193 
194  out.str("");
195  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
196  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
197 
198  out.str("");
199  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
200  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
201 
202 
203  /**************************************************************/
204  // Nearest/Linear
205  texParameterTrace.Reset();
206  texParameterTrace.Enable( true );
207 
209 
210  // Flush the queue and render once
211  application.SendNotification();
212  application.Render();
213 
214  texParameterTrace.Enable( false );
215 
216  // Verify actor gl state
217  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
218 
219  out.str("");
220  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
221  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
222 
223  /**************************************************************/
224  // NONE/NONE
225  texParameterTrace.Reset();
226  texParameterTrace.Enable( true );
227 
229 
230  // Flush the queue and render once
231  application.SendNotification();
232  application.Render();
233 
234  texParameterTrace.Enable( false );
235 
236  // Verify actor gl state
237  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
238 
239  out.str("");
240  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR;
241  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
242 
243  END_TEST;
244 }
245 
247 {
248  TestApplication application;
249 
250  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
251  Material material = CreateMaterial();
252  Sampler sampler = Sampler::New();
253  material.AddTexture( image, "sTexture", sampler );
254 
255  Geometry geometry = CreateQuadGeometry();
256  Renderer renderer = Renderer::New( geometry, material );
257  Actor actor = Actor::New();
258  actor.AddRenderer(renderer);
260  actor.SetSize(400, 400);
261  Stage::GetCurrent().Add( actor );
262 
263  TestGlAbstraction& gl = application.GetGlAbstraction();
264 
265  //****************************************
266  // CLAMP_TO_EDGE / CLAMP_TO_EDGE
267  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
268  texParameterTrace.Reset();
269  texParameterTrace.Enable( true );
270 
271  application.SendNotification();
272  application.Render();
273 
274  texParameterTrace.Enable( false );
275 
276  // Verify gl state
277 
278  // There are three calls to TexParameteri when the texture is first created
279  // Texture mag filter is not called as the first time set it uses the system default
280  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
281 
282  std::stringstream out;
283  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_CLAMP_TO_EDGE;
284  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
285 
286  out.str("");
287  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_CLAMP_TO_EDGE;
288  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
289 
290  texParameterTrace.Reset();
291  texParameterTrace.Enable( true );
292 
294 
295  // Flush the queue and render once
296  application.SendNotification();
297  application.Render();
298 
299  texParameterTrace.Enable( false );
300 
301  // Verify gl state
302 
303  // Should not make any calls when settings are the same
304  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
305 
306  //Todo: Test the other wrap mode ( REPEAT, MIRRORED_REPEAT ) , currently not support!!
307 
308  END_TEST;
309 }
Dali Docs Home
Read more about Dali