2 * Copyright (c) 2014 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.
21 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
27 #include <mesh-builder.h>
29 #include <dali/internal/event/common/thread-local-storage.h>
30 #include <dali/internal/update/resources/resource-manager.h>
31 #include <dali/internal/update/manager/update-manager.h>
32 #include <dali/internal/event/resources/resource-client.h>
33 #include <dali/internal/event/resources/resource-ticket.h>
34 #include <dali/internal/event/resources/image-ticket.h>
35 #include <dali/internal/event/resources/resource-ticket-observer.h>
36 #include <dali/internal/event/images/image-impl.h>
37 #include <dali/internal/event/modeling/model-data-impl.h>
38 #include <dali/integration-api/resource-cache.h>
39 #include <dali/internal/event/modeling/material-impl.h>
40 #include <dali/internal/update/modeling/scene-graph-material.h>
41 #include <dali/internal/render/renderers/render-material.h>
42 #include <dali/internal/render/gl-resources/context.h>
43 #include <dali/internal/render/shaders/program.h>
47 Dali::Internal::MaterialProperties TEST_PROPS;
50 // Called only once before first test is run.
51 void utc_dali_material_startup(void)
53 TEST_PROPS.mOpacity = 0.4f;
54 TEST_PROPS.mShininess = 0.27f;
55 TEST_PROPS.mDiffuseColor = Color::MAGENTA;
56 TEST_PROPS.mAmbientColor = Color::GREEN;
57 TEST_PROPS.mSpecularColor = Color::BLUE;
58 TEST_PROPS.mEmissiveColor = Color::RED;
59 test_return_value = TET_UNDEF;
62 // Called only once after last test is run
63 void utc_dali_material_cleanup(void)
65 test_return_value = TET_PASS;
74 TestProgram( TestApplication& application )
77 Internal::Context* testContext = new Internal::Context( application.GetGlAbstraction() );
78 Integration::ShaderDataPtr shaderData = new Integration::ShaderData("123", "132");
79 shaderData->AllocateBuffer(10);
81 Integration::ResourceId resourceId = 100;
82 program = Internal::Program::New(resourceId, shaderData.Get(), *testContext, true);
83 programId = app.GetGlAbstraction().GetLastProgramCreated();
87 virtual ~TestProgram()
91 Internal::Program& GetProgram()
96 float GetUniformF(std::string uniform)
98 GLint uniformLoc = program->GetUniformLocation( program->RegisterUniform( uniform.c_str() ) );
100 if(app.GetGlAbstraction().GetUniformValue( programId, (GLuint) uniformLoc, value))
107 Vector4 GetUniformV(std::string uniform)
109 GLint uniformLoc = program->GetUniformLocation( program->RegisterUniform( uniform.c_str() ) );
111 if(app.GetGlAbstraction().GetUniformValue( programId, (GLuint) uniformLoc, value))
118 float GetOpacity() { return GetUniformF("uMaterial.mOpacity"); }
119 float GetShininess() { return GetUniformF("uMaterial.mShininess"); }
120 Vector4 GetAmbientColor() { return GetUniformV("uMaterial.mAmbient"); }
121 Vector4 GetDiffuseColor() { return GetUniformV("uMaterial.mDiffuse"); }
122 Vector4 GetSpecularColor() { return GetUniformV("uMaterial.mSpecular"); }
123 Vector4 GetEmissiveColor() { return GetUniformV("uMaterial.mEmissive"); }
125 TestApplication& app;
127 Internal::Program* program;
128 Integration::ShaderDataPtr shaderData;
132 class TestBoundTextures
135 TestBoundTextures(TestApplication& application)
138 std::vector<GLuint> ids;
139 ids.push_back( 8 ); // 8 = actor1
140 ids.push_back( 9 ); // 9 = actor2
141 ids.push_back( 10 ); // 10 = actor3
142 application.GetGlAbstraction().SetNextTextureIds( ids );
145 std::size_t GetNumBoundTextures()
147 const std::vector<GLuint>& boundTextures = app.GetGlAbstraction().GetBoundTextures();
148 return boundTextures.size();
151 bool CheckFirstTextureBound( GLuint activeTextureUnit )
154 const std::vector<GLuint>& boundTextures = app.GetGlAbstraction().GetBoundTextures( activeTextureUnit );
156 if ( boundTextures.size() == 1 )
158 if( boundTextures[0] == 8u )
166 bool CheckFirstTextureDeleted()
168 return ( app.GetGlAbstraction().CheckTextureDeleted( 8u ));
171 TestApplication& app;
175 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
177 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
178 ImageAttributes attr;
179 Integration::BitmapResourceType bitmapRequest(attr);
180 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
181 application.SendNotification(); // Flush update messages
182 application.Render(); // Process resource request
183 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
184 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
185 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
186 Integration::ResourcePointer resourcePtr(bitmap); // reference it
187 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
188 application.Render(); // Process LoadComplete
189 application.SendNotification(); // Process event messages
190 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
191 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
193 application.GetPlatform().ResetTrace();
198 Internal::ImagePtr LoadImage(TestApplication& application, const char* name)
200 Internal::ImagePtr image = Internal::Image::New(name);
201 application.SendNotification(); // Flush update messages
202 application.Render(); // Process resource request
203 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
204 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
205 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
206 Integration::ResourcePointer resourcePtr(bitmap); // reference it
208 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
209 application.Render(); // Process LoadComplete
210 application.SendNotification(); // Process event messages
211 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
213 application.GetPlatform().ResetTrace();
217 } // Anonymous Namespace
219 /********************************************************************************/
220 /********************************************************************************/
221 /********************************************************************************/
223 // Test new with no parameters sets up default object
224 int UtcDaliMaterialMethodNew01(void)
226 TestApplication application;
228 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
229 Internal::MaterialProperties props = sceneObject->GetProperties(); // copy.
230 DALI_TEST_CHECK(props.mOpacity == Dali::Material::DEFAULT_OPACITY);
231 DALI_TEST_CHECK(props.mShininess == Dali::Material::DEFAULT_SHININESS);
232 DALI_TEST_CHECK(props.mAmbientColor == Dali::Material::DEFAULT_AMBIENT_COLOR);
233 DALI_TEST_CHECK(props.mDiffuseColor == Dali::Material::DEFAULT_DIFFUSE_COLOR);
234 DALI_TEST_CHECK(props.mSpecularColor == Dali::Material::DEFAULT_SPECULAR_COLOR);
235 DALI_TEST_CHECK(props.mEmissiveColor == Dali::Material::DEFAULT_EMISSIVE_COLOR);
237 Internal::ResourceId textureId = sceneObject->GetDiffuseTextureId();
238 DALI_TEST_CHECK( !textureId );
239 textureId = sceneObject->GetOpacityTextureId();
240 DALI_TEST_CHECK( !textureId );
241 textureId = sceneObject->GetNormalMapId();
242 DALI_TEST_CHECK( !textureId );
244 DALI_TEST_CHECK(! sceneObject->HasDiffuseTexture());
245 DALI_TEST_CHECK(! sceneObject->HasOpacityTexture());
246 DALI_TEST_CHECK(! sceneObject->HasNormalMap());
250 // Test new with event object sets up parameters appropriately
251 int UtcDaliMaterialMethodNew02(void)
253 TestApplication application;
255 Internal::Material* material = Internal::Material::New("cloth");
256 DALI_TEST_CHECK(material->GetShininess() == Dali::Material::DEFAULT_SHININESS);
257 DALI_TEST_CHECK(material->GetAmbientColor() == Dali::Material::DEFAULT_AMBIENT_COLOR);
258 material->SetOpacity(0.4f);
259 material->SetDiffuseColor(Color::MAGENTA);
262 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(material);
263 Internal::MaterialProperties props = sceneObject->GetProperties(); // copy.
264 DALI_TEST_CHECK(props.mOpacity == 0.4f);
265 DALI_TEST_CHECK(props.mDiffuseColor == Color::MAGENTA);
266 DALI_TEST_CHECK(props.mShininess == Dali::Material::DEFAULT_SHININESS);
267 DALI_TEST_CHECK(props.mAmbientColor == Dali::Material::DEFAULT_AMBIENT_COLOR);
268 DALI_TEST_CHECK(props.mSpecularColor == Dali::Material::DEFAULT_SPECULAR_COLOR);
269 DALI_TEST_CHECK(props.mEmissiveColor == Dali::Material::DEFAULT_EMISSIVE_COLOR);
271 Internal::ResourceId textureId = sceneObject->GetDiffuseTextureId();
272 DALI_TEST_CHECK( !textureId );
273 textureId = sceneObject->GetOpacityTextureId();
274 DALI_TEST_CHECK( !textureId );
275 textureId = sceneObject->GetNormalMapId();
276 DALI_TEST_CHECK( !textureId );
278 DALI_TEST_CHECK(! sceneObject->HasDiffuseTexture());
279 DALI_TEST_CHECK(! sceneObject->HasOpacityTexture());
280 DALI_TEST_CHECK(! sceneObject->HasNormalMap());
283 const Internal::SceneGraph::Material* sceneObject2 = material->GetSceneObject();
284 DALI_TEST_CHECK( sceneObject2 != NULL );
285 Internal::MaterialProperties props2 = sceneObject2->GetProperties(); // copy.
286 DALI_TEST_CHECK(props2.mOpacity == 0.4f);
287 DALI_TEST_CHECK(props2.mDiffuseColor == Color::MAGENTA);
288 DALI_TEST_CHECK(props2.mShininess == Dali::Material::DEFAULT_SHININESS);
289 DALI_TEST_CHECK(props2.mAmbientColor == Dali::Material::DEFAULT_AMBIENT_COLOR);
290 DALI_TEST_CHECK(props2.mSpecularColor == Dali::Material::DEFAULT_SPECULAR_COLOR);
291 DALI_TEST_CHECK(props2.mEmissiveColor == Dali::Material::DEFAULT_EMISSIVE_COLOR);
293 DALI_TEST_CHECK(! sceneObject2->GetDiffuseTextureId());
294 DALI_TEST_CHECK(! sceneObject2->GetOpacityTextureId());
295 DALI_TEST_CHECK(! sceneObject2->GetNormalMapId());
297 DALI_TEST_CHECK(! sceneObject2->HasDiffuseTexture());
298 DALI_TEST_CHECK(! sceneObject2->HasOpacityTexture());
299 DALI_TEST_CHECK(! sceneObject2->HasNormalMap());
303 // Test setting ready texture off stage
304 int UtcDaliMaterialReadyTextureOffstage(void)
306 TestApplication application;
308 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "diffuse.png", 80, 80);
309 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
310 sceneObject->SetDiffuseTextureId(ticket->GetId());
312 DALI_TEST_EQUALS( sceneObject->GetDiffuseTextureId(), ticket->GetId(), TEST_LOCATION );
316 // Test setting unready texture offstage, becoming ready
317 int UtcDaliMaterialUnreadyTextureOffstage(void)
319 TestApplication application;
321 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
322 ImageAttributes attr;
323 Integration::BitmapResourceType bitmapRequest(attr);
324 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
325 application.SendNotification(); // Flush update messages
326 application.Render(); // Process resource request
328 // Ticket is valid, but no resource yet
329 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
330 Internal::ResourceId textureId = ticket->GetId();
331 sceneObject->SetDiffuseTextureId(textureId);
332 Internal::ResourceId textureId2 = sceneObject->GetDiffuseTextureId();
333 DALI_TEST_CHECK( textureId == textureId2 );
335 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
336 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
337 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
338 Integration::ResourcePointer resourcePtr(bitmap); // reference it
339 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
340 application.Render(); // Process LoadComplete
341 application.SendNotification(); // Process event messages
342 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
344 Internal::ResourceId textureId3 = sceneObject->GetDiffuseTextureId();
345 DALI_TEST_CHECK( textureId3 );
346 DALI_TEST_CHECK( textureId3 == textureId );
350 // Test staging creates render material
351 int UtcDaliMaterialStaging01(void)
353 TestApplication application;
354 TestBoundTextures boundTextures(application);
355 TestProgram testProgram(application);
357 // Create object and set some properties
358 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
359 DALI_TEST_CHECK( sceneObject != NULL );
360 sceneObject->SetProperties(TEST_PROPS);
363 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
364 AddMaterialMessage( updateManager, sceneObject );
365 application.SendNotification(); // Flush update Q
367 application.GetPlatform().IncrementGetTimeResult( 1 );
368 Integration::UpdateStatus status;
369 application.GetCore().Update( status );
371 // Check that a render object has been created
372 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
373 DALI_TEST_CHECK(renderMaterial != NULL);
374 // Not on render manager, and should have default props
376 Internal::SceneGraph::RenderMaterialUniforms materialUniforms;
377 renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
379 DALI_TEST_EQUALS( testProgram.GetOpacity(), 1.0f, TEST_LOCATION );
380 DALI_TEST_EQUALS( testProgram.GetShininess(), 0.5f, TEST_LOCATION );
381 DALI_TEST_EQUALS( testProgram.GetAmbientColor(), Vector4(0.2f, 0.2f, 0.2f, 1.0f), TEST_LOCATION);
382 DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), Vector4(0.8f, 0.8f, 0.8f, 1.0f), TEST_LOCATION);
383 DALI_TEST_EQUALS( testProgram.GetSpecularColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
384 DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
386 application.Render(); //Process render Q stores & processes mat
388 renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
389 renderMaterial->BindTextures( testProgram.GetProgram() );
390 DALI_TEST_CHECK( boundTextures.GetNumBoundTextures() == 0 );
392 DALI_TEST_EQUALS( testProgram.GetOpacity(), TEST_PROPS.mOpacity, TEST_LOCATION);
393 DALI_TEST_EQUALS( testProgram.GetShininess(), TEST_PROPS.mShininess, TEST_LOCATION );
394 DALI_TEST_EQUALS( testProgram.GetAmbientColor(), TEST_PROPS.mAmbientColor, TEST_LOCATION );
395 DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), TEST_PROPS.mDiffuseColor, TEST_LOCATION );
396 DALI_TEST_EQUALS( testProgram.GetSpecularColor(), TEST_PROPS.mSpecularColor, TEST_LOCATION );
397 DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), TEST_PROPS.mEmissiveColor, TEST_LOCATION );
401 // Test staging creates render material
402 int UtcDaliMaterialStaging02(void)
404 TestApplication application;
405 TestBoundTextures boundTextures(application);
406 TestProgram testProgram(application);
408 Internal::Material* material = Internal::Material::New("cloth");
409 material->SetOpacity(0.4f);
410 material->SetDiffuseColor(Color::MAGENTA);
412 // Create object and set some properties
413 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(material);
414 DALI_TEST_CHECK( sceneObject != NULL );
417 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
418 AddMaterialMessage( updateManager, sceneObject );
419 application.SendNotification(); // Flush update Q
421 application.GetPlatform().IncrementGetTimeResult( 1 );
422 Integration::UpdateStatus status;
423 application.GetCore().Update( status );
425 // Check that a render object has been created
426 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
427 DALI_TEST_CHECK(renderMaterial != NULL);
428 // Not on render manager, and should have default props
430 Internal::SceneGraph::RenderMaterialUniforms materialUniforms;
431 renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
433 DALI_TEST_EQUALS( testProgram.GetOpacity(), 1.0f, TEST_LOCATION );
434 DALI_TEST_EQUALS( testProgram.GetShininess(), 0.5f, TEST_LOCATION );
435 DALI_TEST_EQUALS( testProgram.GetAmbientColor(), Vector4(0.2f, 0.2f, 0.2f, 1.0f), TEST_LOCATION);
436 DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), Vector4(0.8f, 0.8f, 0.8f, 1.0f), TEST_LOCATION);
437 DALI_TEST_EQUALS( testProgram.GetSpecularColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
438 DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION);
440 application.Render(); //Process render Q stores & processes mat
442 renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
443 renderMaterial->BindTextures( testProgram.GetProgram() );
445 DALI_TEST_CHECK( boundTextures.GetNumBoundTextures() == 0 );
446 DALI_TEST_EQUALS( testProgram.GetOpacity(), 0.4f, TEST_LOCATION);
447 DALI_TEST_EQUALS( testProgram.GetShininess(), Dali::Material::DEFAULT_SHININESS, TEST_LOCATION );
448 DALI_TEST_EQUALS( testProgram.GetAmbientColor(), Dali::Material::DEFAULT_AMBIENT_COLOR, TEST_LOCATION );
449 DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), Color::MAGENTA, TEST_LOCATION );
450 DALI_TEST_EQUALS( testProgram.GetSpecularColor(), Dali::Material::DEFAULT_SPECULAR_COLOR, TEST_LOCATION );
451 DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), Dali::Material::DEFAULT_EMISSIVE_COLOR, TEST_LOCATION );
457 // Test setting properties on stage
458 int UtcDaliMaterialSetPropsWhilstStaged(void)
460 TestApplication application;
461 TestBoundTextures boundTextures(application);
462 TestProgram testProgram(application);
464 // Create object with default properties
465 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
466 DALI_TEST_CHECK( sceneObject != NULL );
469 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
470 AddMaterialMessage( updateManager, sceneObject );
471 application.SendNotification(); // Flush update Q
472 application.Render(); // Process update message Q then create & post to render Q
474 // Check that a render object has been created
475 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
476 DALI_TEST_CHECK(renderMaterial != NULL);
477 application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat
479 sceneObject->SetProperties(TEST_PROPS);
480 application.SendNotification(); // Flush update Q
481 application.Render(); // Update & Prepare material
482 application.Render(); // Process render Q
484 Internal::SceneGraph::RenderMaterialUniforms materialUniforms;
485 renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT );
486 renderMaterial->BindTextures( testProgram.GetProgram() );
488 DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION );
490 DALI_TEST_EQUALS( testProgram.GetOpacity(), TEST_PROPS.mOpacity, TEST_LOCATION);
491 DALI_TEST_EQUALS( testProgram.GetShininess(), TEST_PROPS.mShininess, TEST_LOCATION );
492 DALI_TEST_EQUALS( testProgram.GetAmbientColor(), TEST_PROPS.mAmbientColor, TEST_LOCATION );
493 DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), TEST_PROPS.mDiffuseColor, TEST_LOCATION );
494 DALI_TEST_EQUALS( testProgram.GetSpecularColor(), TEST_PROPS.mSpecularColor, TEST_LOCATION );
495 DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), TEST_PROPS.mEmissiveColor, TEST_LOCATION );
499 // Test setting ready texture on stage
500 int UtcDaliMaterialSetTextureWhilstStaged(void)
502 TestApplication application;
503 TestBoundTextures boundTextures(application);
504 TestProgram testProgram(application);
506 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "diffuse.png", 80, 80);
508 // Create object with default properties
509 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
510 DALI_TEST_CHECK( sceneObject != NULL );
513 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
514 AddMaterialMessage( updateManager, sceneObject );
515 application.SendNotification(); // Flush update Q
516 application.Render(); // Process update message Q then create & post to render Q
518 // Check that a render object has been created
519 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
520 DALI_TEST_CHECK(renderMaterial != NULL);
521 application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat
523 sceneObject->SetDiffuseTextureId(ticket->GetId());
524 application.SendNotification(); // Flush update Q
525 application.Render(); // Update & Prepare material
526 application.Render(); // Process render Q
528 renderMaterial->BindTextures( testProgram.GetProgram() );
529 DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) );
533 // Test setting unready texture on stage, becoming ready
534 int UtcDaliMaterialSetUnreadyTextureWhilstStaged(void)
536 TestApplication application;
537 TestBoundTextures boundTextures(application);
538 TestProgram testProgram(application);
540 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
541 ImageAttributes attr;
542 Integration::BitmapResourceType bitmapRequest(attr);
543 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
544 application.SendNotification(); // Flush update messages
545 application.Render(); // Process resource request
548 // Create object with default properties
549 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
550 DALI_TEST_CHECK( sceneObject != NULL );
553 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
554 AddMaterialMessage( updateManager, sceneObject );
555 application.SendNotification(); // Flush update Q
556 application.Render(); // Process update message Q then create & post to render Q
558 // Check that a render object has been created
559 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
560 DALI_TEST_CHECK(renderMaterial != NULL);
561 application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat
563 sceneObject->SetDiffuseTextureId(ticket->GetId());
564 application.SendNotification(); // Flush update Q
565 application.Render(); // Update & Prepare material
566 application.Render(); // Process render Q
568 renderMaterial->BindTextures( testProgram.GetProgram() );
570 DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION );
572 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
573 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
574 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
575 Integration::ResourcePointer resourcePtr(bitmap); // reference it
576 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
577 application.Render(); // Process LoadComplete
578 application.SendNotification(); // Process event messages
580 renderMaterial->BindTextures( testProgram.GetProgram() );
581 DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) );
585 // Test IsOpaque without texture, with unready texture, with ready texture
587 int UtcDaliMaterialIsOpaqueWithoutTexture(void)
589 TestApplication application;
591 // Create object with default properties
592 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
593 DALI_TEST_CHECK( sceneObject != NULL );
596 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
597 AddMaterialMessage( updateManager, sceneObject );
598 application.SendNotification(); // Flush update Q
599 application.Render(); // Process update message Q then create & post to render Q
601 // Check that a render object has been created
602 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
603 DALI_TEST_CHECK(renderMaterial != NULL);
604 application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat
606 DALI_TEST_CHECK( sceneObject->IsOpaque() );
610 int UtcDaliMaterialIsOpaqueWithTexture(void)
612 TestApplication application;
614 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "diffuse.png", 80, 80);
616 // Create object with default properties
617 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
618 DALI_TEST_CHECK( sceneObject != NULL );
621 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
622 AddMaterialMessage( updateManager, sceneObject );
623 application.SendNotification(); // Flush update Q
624 application.Render(); // Process update message Q then create & post to render Q
626 // Check that a render object has been created
627 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
628 DALI_TEST_CHECK(renderMaterial != NULL);
629 application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat
631 DALI_TEST_CHECK( sceneObject->IsOpaque() );
633 sceneObject->SetDiffuseTextureId(ticket->GetId());
634 application.SendNotification(); // Flush update Q
635 application.Render(); // Update & Prepare material
636 application.Render(); // Process render Q
638 DALI_TEST_CHECK( ! sceneObject->IsOpaque() );
643 int UtcDaliMaterialIsOpaqueWithProps(void)
645 TestApplication application;
647 // Create object with default properties
648 Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New();
649 DALI_TEST_CHECK( sceneObject != NULL );
652 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
653 AddMaterialMessage( updateManager, sceneObject );
654 application.SendNotification(); // Flush update Q
655 application.Render(); // Process update message Q then create & post to render Q
657 // Check that a render object has been created
658 Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial();
659 DALI_TEST_CHECK(renderMaterial != NULL);
660 application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat
662 DALI_TEST_CHECK( sceneObject->IsOpaque() );
664 sceneObject->SetProperties(TEST_PROPS);
665 application.SendNotification(); // Flush update Q
666 application.Render(); // Update & Prepare material
667 application.Render(); // Process render Q
669 DALI_TEST_CHECK( ! sceneObject->IsOpaque() );
673 int UtcDaliMaterialRender(void)
675 TestApplication application;
676 TestBoundTextures boundTextures(application);
681 MeshData::VertexContainer vertices;
682 MeshData::FaceIndices faces;
684 ConstructVertices(vertices, 60);
685 ConstructFaces(vertices, faces);
686 Dali::Material material = ConstructMaterial();
688 Internal::ImagePtr image = LoadImage(application, "texture.png");
689 Image imageHandle(image.Get());
690 material.SetDiffuseTexture(imageHandle);
691 meshData.SetData(vertices, faces, bones, material);
692 Mesh mesh = Mesh::New(meshData);
694 MeshActor actor = MeshActor::New(mesh);
695 std::string name = "AMeshActor";
697 actor.SetAffectedByLighting(false);
698 Stage::GetCurrent().Add(actor);
700 material.SetOpacity(TEST_PROPS.mOpacity);
701 material.SetShininess(TEST_PROPS.mShininess);
702 material.SetAmbientColor(TEST_PROPS.mAmbientColor);
703 material.SetDiffuseColor(TEST_PROPS.mDiffuseColor);
704 material.SetSpecularColor(TEST_PROPS.mSpecularColor);
705 material.SetEmissiveColor(TEST_PROPS.mEmissiveColor);
707 application.SendNotification();
708 application.Render();
709 application.SendNotification();
710 application.Render();
711 application.SendNotification();
712 application.Render();
713 application.SendNotification();
715 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mOpacity", TEST_PROPS.mOpacity ) );
716 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mShininess", TEST_PROPS.mShininess ) );
717 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mAmbient", TEST_PROPS.mAmbientColor ) );
718 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mDiffuse", TEST_PROPS.mDiffuseColor ) );
719 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mSpecular", TEST_PROPS.mSpecularColor ) );
720 DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mEmissive", TEST_PROPS.mEmissiveColor ) );
722 DALI_TEST_CHECK(boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ));
724 Stage::GetCurrent().Remove(actor);
725 application.SendNotification();
726 application.Render();
727 application.SendNotification();
728 application.Render();
730 application.SendNotification();
731 application.Render();
733 // texture should have been removed:
734 DALI_TEST_CHECK( boundTextures.CheckFirstTextureDeleted() );