From 71d6774cc9e952409e04d45ec6827cfad9590805 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Thu, 27 Nov 2014 19:45:04 +0000 Subject: [PATCH] Shader & Program cleanup, Part 2: Stop calling render thread methods from update threads, cache uniform coordinate types - saves over 1000 messages in bubble effect start, 180 in dali-demo startup - fixed unmanaged test cases - fixed a regression in setting shader from script - removed non-functional geometry mapping enum Change-Id: Ida2e0ec0af1b5c9756691f2513183f2fb65fb124 --- automated-tests/src/dali-internal/CMakeLists.txt | 1 - .../dali-internal/utc-Dali-Internal-Material.cpp | 735 --------------------- .../src/dali-unmanaged/utc-Dali-ShaderEffect.cpp | 79 ++- .../dali-test-suite-utils/test-gl-abstraction.h | 24 + automated-tests/src/dali/utc-Dali-ShaderEffect.cpp | 24 +- dali/internal/event/common/proxy-object.cpp | 1 - dali/internal/event/common/proxy-object.h | 15 +- dali/internal/event/effects/shader-effect-impl.cpp | 25 +- dali/internal/event/effects/shader-effect-impl.h | 3 +- dali/internal/render/shaders/shader.cpp | 96 ++- dali/internal/render/shaders/shader.h | 78 +-- dali/internal/render/shaders/uniform-meta.h | 39 +- dali/public-api/actors/renderable-actor.h | 1 + dali/public-api/shader-effects/shader-effect.h | 7 +- 14 files changed, 222 insertions(+), 906 deletions(-) delete mode 100644 automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp diff --git a/automated-tests/src/dali-internal/CMakeLists.txt b/automated-tests/src/dali-internal/CMakeLists.txt index c41360e..db42ccc 100644 --- a/automated-tests/src/dali-internal/CMakeLists.txt +++ b/automated-tests/src/dali-internal/CMakeLists.txt @@ -10,7 +10,6 @@ SET(TC_SOURCES utc-Dali-Internal-Font.cpp utc-Dali-Internal-Handles.cpp utc-Dali-Internal-ImageFactory.cpp - utc-Dali-Internal-Material.cpp utc-Dali-Internal-Mesh.cpp utc-Dali-Internal-Text.cpp utc-Dali-Internal-ResourceClient.cpp diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp deleted file mode 100644 index f0446fd..0000000 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp +++ /dev/null @@ -1,735 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include - -#include - -using namespace Dali; - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -Dali::Internal::MaterialProperties TEST_PROPS; -} - -// Called only once before first test is run. -void utc_dali_material_startup(void) -{ - TEST_PROPS.mOpacity = 0.4f; - TEST_PROPS.mShininess = 0.27f; - TEST_PROPS.mDiffuseColor = Color::MAGENTA; - TEST_PROPS.mAmbientColor = Color::GREEN; - TEST_PROPS.mSpecularColor = Color::BLUE; - TEST_PROPS.mEmissiveColor = Color::RED; - test_return_value = TET_UNDEF; -} - -// Called only once after last test is run -void utc_dali_material_cleanup(void) -{ - test_return_value = TET_PASS; -} - -namespace -{ - -class TestProgram -{ -public: - TestProgram( TestApplication& application ) - : app(application) - { - Internal::Context* testContext = new Internal::Context( application.GetGlAbstraction() ); - testContext->GlContextCreated(); - - Integration::ShaderDataPtr shaderData = new Integration::ShaderData("123", "132"); - shaderData->AllocateBuffer(10); - - Integration::ResourceId resourceId = 100; - program = Internal::Program::New(resourceId, shaderData.Get(), *testContext, true); - program->Use(); // Ensure program lazy loading is forced to load program. - programId = app.GetGlAbstraction().GetLastProgramCreated(); - } - - virtual ~TestProgram() - { - } - - Internal::Program& GetProgram() - { - return *program; - } - - float GetUniformF(std::string uniform) - { - GLint uniformLoc = program->GetUniformLocation( program->RegisterUniform( uniform.c_str() ) ); - float value=0.0f; - if(app.GetGlAbstraction().GetUniformValue( programId, (GLuint) uniformLoc, value)) - { - return value; - } - return 0.0f; - } - - Vector4 GetUniformV(std::string uniform) - { - GLint uniformLoc = program->GetUniformLocation( program->RegisterUniform( uniform.c_str() ) ); - Vector4 value; - if(app.GetGlAbstraction().GetUniformValue( programId, (GLuint) uniformLoc, value)) - { - return value; - } - return Vector4(); - } - - float GetOpacity() { return GetUniformF("uMaterial.mOpacity"); } - float GetShininess() { return GetUniformF("uMaterial.mShininess"); } - Vector4 GetAmbientColor() { return GetUniformV("uMaterial.mAmbient"); } - Vector4 GetDiffuseColor() { return GetUniformV("uMaterial.mDiffuse"); } - Vector4 GetSpecularColor() { return GetUniformV("uMaterial.mSpecular"); } - Vector4 GetEmissiveColor() { return GetUniformV("uMaterial.mEmissive"); } - - TestApplication& app; - GLuint programId; - Internal::Program* program; - Integration::ShaderDataPtr shaderData; -}; - - -class TestBoundTextures -{ -public: - TestBoundTextures(TestApplication& application) - : app(application) - { - std::vector ids; - ids.push_back( 8 ); // 8 = actor1 - ids.push_back( 9 ); // 9 = actor2 - ids.push_back( 10 ); // 10 = actor3 - application.GetGlAbstraction().SetNextTextureIds( ids ); - } - - std::size_t GetNumBoundTextures() - { - const std::vector& boundTextures = app.GetGlAbstraction().GetBoundTextures(); - return boundTextures.size(); - } - - bool CheckFirstTextureBound( GLuint activeTextureUnit ) - { - bool bound=false; - const std::vector& boundTextures = app.GetGlAbstraction().GetBoundTextures( activeTextureUnit ); - - if ( boundTextures.size() == 1 ) - { - if( boundTextures[0] == 8u ) - { - bound = true; - } - } - return bound; - } - - bool CheckFirstTextureDeleted() - { - return ( app.GetGlAbstraction().CheckTextureDeleted( 8u )); - } - - TestApplication& app; -}; - - -Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h) -{ - Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); - ImageAttributes attr; - Integration::BitmapResourceType bitmapRequest(attr); - Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name ); - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h ); - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded ); - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - req=NULL; - application.GetPlatform().ResetTrace(); - - return ticket; -} - -Internal::ImagePtr LoadImage(TestApplication& application, const char* name) -{ - const Vector2 closestImageSize( 80, 80); - application.GetPlatform().SetClosestImageSize(closestImageSize); - Internal::ImagePtr image = Internal::Image::New(name, Dali::ImageAttributes::DEFAULT_ATTRIBUTES ); - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 ); - Integration::ResourcePointer resourcePtr(bitmap); // reference it - - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - req=NULL; - application.GetPlatform().ResetTrace(); - return image; -} - -} // Anonymous Namespace - -/********************************************************************************/ -/********************************************************************************/ -/********************************************************************************/ - -// Test new with no parameters sets up default object -int UtcDaliMaterialMethodNew01(void) -{ - TestApplication application; - - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - Internal::MaterialProperties props = sceneObject->GetProperties(); // copy. - DALI_TEST_CHECK(props.mOpacity == Dali::Material::DEFAULT_OPACITY); - DALI_TEST_CHECK(props.mShininess == Dali::Material::DEFAULT_SHININESS); - DALI_TEST_CHECK(props.mAmbientColor == Dali::Material::DEFAULT_AMBIENT_COLOR); - DALI_TEST_CHECK(props.mDiffuseColor == Dali::Material::DEFAULT_DIFFUSE_COLOR); - DALI_TEST_CHECK(props.mSpecularColor == Dali::Material::DEFAULT_SPECULAR_COLOR); - DALI_TEST_CHECK(props.mEmissiveColor == Dali::Material::DEFAULT_EMISSIVE_COLOR); - - Internal::ResourceId textureId = sceneObject->GetDiffuseTextureId(); - DALI_TEST_CHECK( !textureId ); - textureId = sceneObject->GetOpacityTextureId(); - DALI_TEST_CHECK( !textureId ); - textureId = sceneObject->GetNormalMapId(); - DALI_TEST_CHECK( !textureId ); - - DALI_TEST_CHECK(! sceneObject->HasDiffuseTexture()); - DALI_TEST_CHECK(! sceneObject->HasOpacityTexture()); - DALI_TEST_CHECK(! sceneObject->HasNormalMap()); - END_TEST; -} - -// Test new with event object sets up parameters appropriately -int UtcDaliMaterialMethodNew02(void) -{ - TestApplication application; - - Internal::Material* material = Internal::Material::New("cloth"); - DALI_TEST_CHECK(material->GetShininess() == Dali::Material::DEFAULT_SHININESS); - DALI_TEST_CHECK(material->GetAmbientColor() == Dali::Material::DEFAULT_AMBIENT_COLOR); - material->SetOpacity(0.4f); - material->SetDiffuseColor(Color::MAGENTA); - - // Create directly - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(material); - Internal::MaterialProperties props = sceneObject->GetProperties(); // copy. - DALI_TEST_CHECK(props.mOpacity == 0.4f); - DALI_TEST_CHECK(props.mDiffuseColor == Color::MAGENTA); - DALI_TEST_CHECK(props.mShininess == Dali::Material::DEFAULT_SHININESS); - DALI_TEST_CHECK(props.mAmbientColor == Dali::Material::DEFAULT_AMBIENT_COLOR); - DALI_TEST_CHECK(props.mSpecularColor == Dali::Material::DEFAULT_SPECULAR_COLOR); - DALI_TEST_CHECK(props.mEmissiveColor == Dali::Material::DEFAULT_EMISSIVE_COLOR); - - Internal::ResourceId textureId = sceneObject->GetDiffuseTextureId(); - DALI_TEST_CHECK( !textureId ); - textureId = sceneObject->GetOpacityTextureId(); - DALI_TEST_CHECK( !textureId ); - textureId = sceneObject->GetNormalMapId(); - DALI_TEST_CHECK( !textureId ); - - DALI_TEST_CHECK(! sceneObject->HasDiffuseTexture()); - DALI_TEST_CHECK(! sceneObject->HasOpacityTexture()); - DALI_TEST_CHECK(! sceneObject->HasNormalMap()); - - // Create indirectly - const Internal::SceneGraph::Material* sceneObject2 = material->GetSceneObject(); - DALI_TEST_CHECK( sceneObject2 != NULL ); - Internal::MaterialProperties props2 = sceneObject2->GetProperties(); // copy. - DALI_TEST_CHECK(props2.mOpacity == 0.4f); - DALI_TEST_CHECK(props2.mDiffuseColor == Color::MAGENTA); - DALI_TEST_CHECK(props2.mShininess == Dali::Material::DEFAULT_SHININESS); - DALI_TEST_CHECK(props2.mAmbientColor == Dali::Material::DEFAULT_AMBIENT_COLOR); - DALI_TEST_CHECK(props2.mSpecularColor == Dali::Material::DEFAULT_SPECULAR_COLOR); - DALI_TEST_CHECK(props2.mEmissiveColor == Dali::Material::DEFAULT_EMISSIVE_COLOR); - - DALI_TEST_CHECK(! sceneObject2->GetDiffuseTextureId()); - DALI_TEST_CHECK(! sceneObject2->GetOpacityTextureId()); - DALI_TEST_CHECK(! sceneObject2->GetNormalMapId()); - - DALI_TEST_CHECK(! sceneObject2->HasDiffuseTexture()); - DALI_TEST_CHECK(! sceneObject2->HasOpacityTexture()); - DALI_TEST_CHECK(! sceneObject2->HasNormalMap()); - END_TEST; -} - -// Test setting ready texture off stage -int UtcDaliMaterialReadyTextureOffstage(void) -{ - TestApplication application; - - Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "diffuse.png", 80, 80); - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - sceneObject->SetDiffuseTextureId(ticket->GetId()); - - DALI_TEST_EQUALS( sceneObject->GetDiffuseTextureId(), ticket->GetId(), TEST_LOCATION ); - END_TEST; -} - -// Test setting unready texture offstage, becoming ready -int UtcDaliMaterialUnreadyTextureOffstage(void) -{ - TestApplication application; - - Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); - ImageAttributes attr; - Integration::BitmapResourceType bitmapRequest(attr); - Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" ); - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - // Ticket is valid, but no resource yet - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - Internal::ResourceId textureId = ticket->GetId(); - sceneObject->SetDiffuseTextureId(textureId); - Internal::ResourceId textureId2 = sceneObject->GetDiffuseTextureId(); - DALI_TEST_CHECK( textureId == textureId2 ); - - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 ); - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded ); - - Internal::ResourceId textureId3 = sceneObject->GetDiffuseTextureId(); - DALI_TEST_CHECK( textureId3 ); - DALI_TEST_CHECK( textureId3 == textureId ); - END_TEST; -} - -// Test staging creates render material -int UtcDaliMaterialStaging01(void) -{ - TestApplication application; - TestBoundTextures boundTextures(application); - TestProgram testProgram(application); - - // Create object and set some properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - DALI_TEST_CHECK( sceneObject != NULL ); - sceneObject->SetProperties(TEST_PROPS); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.UpdateOnly(1); - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - // Not on render manager, and should have default props - - Internal::SceneGraph::RenderMaterialUniforms materialUniforms; - renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT ); - - DALI_TEST_EQUALS( testProgram.GetOpacity(), 1.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetShininess(), 0.5f, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetAmbientColor(), Vector4(0.2f, 0.2f, 0.2f, 1.0f), TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), Vector4(0.8f, 0.8f, 0.8f, 1.0f), TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetSpecularColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION); - - application.Render(); //Process render Q stores & processes mat - - renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT ); - renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ); - DALI_TEST_CHECK( boundTextures.GetNumBoundTextures() == 0 ); - - DALI_TEST_EQUALS( testProgram.GetOpacity(), TEST_PROPS.mOpacity, TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetShininess(), TEST_PROPS.mShininess, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetAmbientColor(), TEST_PROPS.mAmbientColor, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), TEST_PROPS.mDiffuseColor, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetSpecularColor(), TEST_PROPS.mSpecularColor, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), TEST_PROPS.mEmissiveColor, TEST_LOCATION ); - END_TEST; -} - -// Test staging creates render material -int UtcDaliMaterialStaging02(void) -{ - TestApplication application; - TestBoundTextures boundTextures(application); - TestProgram testProgram(application); - - Internal::Material* material = Internal::Material::New("cloth"); - material->SetOpacity(0.4f); - material->SetDiffuseColor(Color::MAGENTA); - - // Create object and set some properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(material); - DALI_TEST_CHECK( sceneObject != NULL ); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.UpdateOnly(1); - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - // Not on render manager, and should have default props - - Internal::SceneGraph::RenderMaterialUniforms materialUniforms; - renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT ); - - DALI_TEST_EQUALS( testProgram.GetOpacity(), 1.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetShininess(), 0.5f, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetAmbientColor(), Vector4(0.2f, 0.2f, 0.2f, 1.0f), TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), Vector4(0.8f, 0.8f, 0.8f, 1.0f), TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetSpecularColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), Vector4(0.0f, 0.0f, 0.0f, 1.0f), TEST_LOCATION); - - application.Render(); //Process render Q stores & processes mat - - renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT ); - renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ); - - DALI_TEST_CHECK( boundTextures.GetNumBoundTextures() == 0 ); - DALI_TEST_EQUALS( testProgram.GetOpacity(), 0.4f, TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetShininess(), Dali::Material::DEFAULT_SHININESS, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetAmbientColor(), Dali::Material::DEFAULT_AMBIENT_COLOR, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), Color::MAGENTA, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetSpecularColor(), Dali::Material::DEFAULT_SPECULAR_COLOR, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), Dali::Material::DEFAULT_EMISSIVE_COLOR, TEST_LOCATION ); - END_TEST; -} - - - -// Test setting properties on stage -int UtcDaliMaterialSetPropsWhilstStaged(void) -{ - TestApplication application; - TestBoundTextures boundTextures(application); - TestProgram testProgram(application); - - // Create object with default properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - DALI_TEST_CHECK( sceneObject != NULL ); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.Render(); // Process update message Q then create & post to render Q - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat - - sceneObject->SetProperties(TEST_PROPS); - application.SendNotification(); // Flush update Q - application.Render(); // Update & Prepare material - application.Render(); // Process render Q - - Internal::SceneGraph::RenderMaterialUniforms materialUniforms; - renderMaterial->SetUniforms( materialUniforms, testProgram.GetProgram(), Internal::SHADER_DEFAULT ); - renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ); - - DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION ); - - DALI_TEST_EQUALS( testProgram.GetOpacity(), TEST_PROPS.mOpacity, TEST_LOCATION); - DALI_TEST_EQUALS( testProgram.GetShininess(), TEST_PROPS.mShininess, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetAmbientColor(), TEST_PROPS.mAmbientColor, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetDiffuseColor(), TEST_PROPS.mDiffuseColor, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetSpecularColor(), TEST_PROPS.mSpecularColor, TEST_LOCATION ); - DALI_TEST_EQUALS( testProgram.GetEmissiveColor(), TEST_PROPS.mEmissiveColor, TEST_LOCATION ); - END_TEST; -} - -// Test setting ready texture on stage -int UtcDaliMaterialSetTextureWhilstStaged(void) -{ - TestApplication application; - TestBoundTextures boundTextures(application); - TestProgram testProgram(application); - - Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "diffuse.png", 80, 80); - - // Create object with default properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - DALI_TEST_CHECK( sceneObject != NULL ); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.Render(); // Process update message Q then create & post to render Q - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat - - sceneObject->SetDiffuseTextureId(ticket->GetId()); - application.SendNotification(); // Flush update Q - application.Render(); // Update & Prepare material - application.Render(); // Process render Q - - renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ); - DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) ); - END_TEST; -} - -// Test setting unready texture on stage, becoming ready -int UtcDaliMaterialSetUnreadyTextureWhilstStaged(void) -{ - TestApplication application; - TestBoundTextures boundTextures(application); - TestProgram testProgram(application); - - Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); - ImageAttributes attr; - Integration::BitmapResourceType bitmapRequest(attr); - Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" ); - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - - // Create object with default properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - DALI_TEST_CHECK( sceneObject != NULL ); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.Render(); // Process update message Q then create & post to render Q - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat - - sceneObject->SetDiffuseTextureId(ticket->GetId()); - application.SendNotification(); // Flush update Q - application.Render(); // Update & Prepare material - application.Render(); // Process render Q - - renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ); - - DALI_TEST_EQUALS( boundTextures.GetNumBoundTextures(), 0u, TEST_LOCATION ); - - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 ); - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - - renderMaterial->BindTextures( testProgram.GetProgram(), Internal::ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ); - DALI_TEST_CHECK( boundTextures.CheckFirstTextureBound( GL_TEXTURE0 ) ); - END_TEST; -} - -// Test IsOpaque without texture, with unready texture, with ready texture - -int UtcDaliMaterialIsOpaqueWithoutTexture(void) -{ - TestApplication application; - - // Create object with default properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - DALI_TEST_CHECK( sceneObject != NULL ); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.Render(); // Process update message Q then create & post to render Q - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat - - DALI_TEST_CHECK( sceneObject->IsOpaque() ); - END_TEST; -} - -int UtcDaliMaterialIsOpaqueWithTexture(void) -{ - TestApplication application; - - Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "diffuse.png", 80, 80); - - // Create object with default properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - DALI_TEST_CHECK( sceneObject != NULL ); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.Render(); // Process update message Q then create & post to render Q - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat - - DALI_TEST_CHECK( sceneObject->IsOpaque() ); - - sceneObject->SetDiffuseTextureId(ticket->GetId()); - application.SendNotification(); // Flush update Q - application.Render(); // Update & Prepare material - application.Render(); // Process render Q - - DALI_TEST_CHECK( ! sceneObject->IsOpaque() ); - END_TEST; -} - - -int UtcDaliMaterialIsOpaqueWithProps(void) -{ - TestApplication application; - - // Create object with default properties - Internal::SceneGraph::Material* sceneObject = Internal::SceneGraph::Material::New(); - DALI_TEST_CHECK( sceneObject != NULL ); - - // Stage the object - Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager(); - AddMaterialMessage( updateManager, sceneObject ); - application.SendNotification(); // Flush update Q - application.Render(); // Process update message Q then create & post to render Q - - // Check that a render object has been created - Internal::SceneGraph::RenderMaterial* renderMaterial = sceneObject->GetRenderMaterial(); - DALI_TEST_CHECK(renderMaterial != NULL); - application.Render(); // Update & Prepare renderMat, Process render Q stores & processes mat - - DALI_TEST_CHECK( sceneObject->IsOpaque() ); - - sceneObject->SetProperties(TEST_PROPS); - application.SendNotification(); // Flush update Q - application.Render(); // Update & Prepare material - application.Render(); // Process render Q - - DALI_TEST_CHECK( ! sceneObject->IsOpaque() ); - END_TEST; -} - -int UtcDaliMaterialRender(void) -{ - TestApplication application; - TestBoundTextures boundTextures(application); - - { - - MeshData meshData; - MeshData::VertexContainer vertices; - MeshData::FaceIndices faces; - BoneContainer bones; - ConstructVertices(vertices, 60); - ConstructFaces(vertices, faces); - Dali::Material material = ConstructMaterial(); - - Internal::ImagePtr image = LoadImage(application, "texture.png"); - Image imageHandle(image.Get()); - material.SetDiffuseTexture(imageHandle); - meshData.SetData(vertices, faces, bones, material); - Mesh mesh = Mesh::New(meshData); - - MeshActor actor = MeshActor::New(mesh); - std::string name = "AMeshActor"; - actor.SetName(name); - actor.SetAffectedByLighting(false); - Stage::GetCurrent().Add(actor); - - material.SetOpacity(TEST_PROPS.mOpacity); - material.SetShininess(TEST_PROPS.mShininess); - material.SetAmbientColor(TEST_PROPS.mAmbientColor); - material.SetDiffuseColor(TEST_PROPS.mDiffuseColor); - material.SetSpecularColor(TEST_PROPS.mSpecularColor); - material.SetEmissiveColor(TEST_PROPS.mEmissiveColor); - - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - application.SendNotification(); - - DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mOpacity", TEST_PROPS.mOpacity ) ); - DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mShininess", TEST_PROPS.mShininess ) ); - DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mAmbient", TEST_PROPS.mAmbientColor ) ); - DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mDiffuse", TEST_PROPS.mDiffuseColor ) ); - DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mSpecular", TEST_PROPS.mSpecularColor ) ); - DALI_TEST_CHECK(application.GetGlAbstraction().CheckUniformValue("uMaterial.mEmissive", TEST_PROPS.mEmissiveColor ) ); - - DALI_TEST_CHECK(boundTextures.CheckFirstTextureBound( GL_TEXTURE0 )); - - Stage::GetCurrent().Remove(actor); - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - } - application.SendNotification(); - application.Render(); - - // texture should have been removed: - DALI_TEST_CHECK( boundTextures.CheckFirstTextureDeleted() ); - END_TEST; -} diff --git a/automated-tests/src/dali-unmanaged/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali-unmanaged/utc-Dali-ShaderEffect.cpp index 24e9c47..1172c1f 100644 --- a/automated-tests/src/dali-unmanaged/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/src/dali-unmanaged/utc-Dali-ShaderEffect.cpp @@ -26,23 +26,25 @@ using namespace Dali; namespace { -static const char* VertexSource = -"void main()\n" -"{\n" -" gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" -" vTexCoord = aTexCoord;\n" -"}\n"; - -static const char* FragmentSource = -"void main()\n" -"{\n" -" gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n" -"}\n"; +static const char* VertexSource = "VertexSource: this can be whatever you want it to be, but don't make it exact the same as default shader\n"; + +static const char* FragmentSource = "FragmentSource: this can be whatever you want it to be, but don't make it exact the same as default shader\n"; const int GETSOURCE_BUFFER_SIZE = 0x10000; static const char* TestImageFilename = "icon_wrt.png"; +Integration::Bitmap* CreateBitmap( unsigned int imageHeight, unsigned int imageWidth, unsigned int initialColor ) +{ + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); + Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, imageWidth,imageHeight,imageWidth,imageHeight ); + unsigned int bytesPerPixel = GetBytesPerPixel( Pixel::RGBA8888 ); + + memset( pixbuffer, initialColor , imageHeight*imageWidth*bytesPerPixel); + + return bitmap; +} + } // Anonymous namespace @@ -53,12 +55,12 @@ int UtcDaliShaderEffectFromProperties01(void) std::string fragmentShaderPrefix = "#define TEST_FS 1\n#extension GL_OES_standard_derivatives : enable"; std::string vertexShaderPrefix = "#define TEST_VS 1"; + std::string vertexShader(VertexSource); + std::string fragmentShader(FragmentSource); // Call render to compile default shaders. application.SendNotification(); application.Render(); - application.Render(); - application.Render(); GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled(); @@ -71,11 +73,11 @@ int UtcDaliShaderEffectFromProperties01(void) Property::Value programMap = Property::Value(Property::MAP); - programMap.SetValue("vertex", std::string(VertexSource)); - programMap.SetValue("fragment", std::string(FragmentSource)); + programMap.SetValue("vertex", vertexShader); + programMap.SetValue("fragment", fragmentShader); - programMap.SetValue("vertex-prefix", std::string(fragmentShaderPrefix)); - programMap.SetValue("fragment-prefix", std::string(vertexShaderPrefix)); + programMap.SetValue("vertex-prefix", vertexShaderPrefix); + programMap.SetValue("fragment-prefix", fragmentShaderPrefix); programMap.SetValue("geometry-type", "GEOMETRY_TYPE_IMAGE"); @@ -83,11 +85,20 @@ int UtcDaliShaderEffectFromProperties01(void) Property::Value imageMap = Property::Value(Property::MAP); imageMap.SetValue("filename", Property::Value(TestImageFilename)); - effect.SetProperty(effect.GetPropertyIndex("image"), imageMap); - BitmapImage image(CreateBitmapImage()); + // do a update & render to get the image request + application.SendNotification(); + application.Render(); + + Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); + // create the image + Integration::Bitmap* bitmap = CreateBitmap( 10, 10, 0xFF ); + Integration::ResourcePointer resourcePtr(bitmap); + TestPlatformAbstraction& platform = application.GetPlatform(); + platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr); + BitmapImage image(CreateBitmapImage()); ImageActor actor = ImageActor::New( image ); actor.SetSize( 100.0f, 100.0f ); actor.SetName("TestImageFilenameActor"); @@ -97,30 +108,18 @@ int UtcDaliShaderEffectFromProperties01(void) application.SendNotification(); application.Render(); GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled(); - bool testResult = false; - - // we should have compiled 4 shaders. - DALI_TEST_CHECK(lastShaderCompiledAfter - lastShaderCompiledBefore == 4); - if (lastShaderCompiledAfter - lastShaderCompiledBefore == 4) - { - char testVertexSourceResult[GETSOURCE_BUFFER_SIZE]; - char testFragmentSourceResult[GETSOURCE_BUFFER_SIZE]; - // we are interested in the first two. - GLuint vertexShaderId = lastShaderCompiledBefore + 1; - GLuint fragmentShaderId = lastShaderCompiledBefore + 2; + // we should have compiled 2 shaders. + DALI_TEST_EQUALS(lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION ); - GLsizei lengthVertexResult; - GLsizei lengthFragmentResult; + std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 ); + DALI_TEST_EQUALS( vertexShaderPrefix, actualVertexShader.substr( 0, vertexShaderPrefix.length() ), TEST_LOCATION ); + DALI_TEST_EQUALS( vertexShader, actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION ); - application.GetGlAbstraction().GetShaderSource(vertexShaderId, GETSOURCE_BUFFER_SIZE, &lengthVertexResult, testVertexSourceResult); - application.GetGlAbstraction().GetShaderSource(fragmentShaderId, GETSOURCE_BUFFER_SIZE, &lengthFragmentResult, testFragmentSourceResult); + std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 ); + DALI_TEST_EQUALS( fragmentShaderPrefix, actualFragmentShader.substr( 0, fragmentShaderPrefix.length() ), TEST_LOCATION ); + DALI_TEST_EQUALS( fragmentShader, actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION ); - int vertexShaderHasPrefix = strncmp(testVertexSourceResult, "#define ", strlen("#define ")); - int fragmentShaderHasPrefix = strncmp(testFragmentSourceResult, "#define ", strlen("#define ")); - testResult = (vertexShaderHasPrefix == 0) && (fragmentShaderHasPrefix == 0); - } - DALI_TEST_CHECK(testResult); END_TEST; } diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index 20a5bcf..919405a 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -1547,6 +1547,30 @@ public: // TEST FUNCTIONS inline TraceCallStack& GetDrawTrace() { return mDrawTrace; } template + inline bool GetUniformValue( const char* name, T& value ) const + { + for( ProgramUniformMap::const_iterator program_it = mUniforms.begin(); + program_it != mUniforms.end(); + ++program_it ) + { + const UniformIDMap &uniformIDs = program_it->second; + + UniformIDMap::const_iterator uniform_it = uniformIDs.find( name ); + if( uniform_it != uniformIDs.end() ) + { + // found one matching uniform name, lets check the value... + GLuint programId = program_it->first; + GLint uniformId = uniform_it->second; + + const ProgramUniformValue &mProgramUniforms = GetProgramUniformsForType( value ); + return mProgramUniforms.GetUniformValue( programId, uniformId, value ); + } + } + return false; + } + + + template inline bool CheckUniformValue( const char* name, const T& value ) const { for( ProgramUniformMap::const_iterator program_it = mUniforms.begin(); diff --git a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp index 2b16b90..ba2a30e 100644 --- a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp @@ -483,13 +483,25 @@ int UtcDaliShaderEffectMethodSetUniformViewport(void) const Vector2& stageSize(Stage::GetCurrent().GetSize()); - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) ); + DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) ); + + DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2Dir", Vector2( -1.0f, 2.0f ) ) ); + + // change coordinate types + effect.SetUniform( "uVec2", Vector2( 0.1f, 0.2f ), ShaderEffect::COORDINATE_TYPE_DEFAULT ); + effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION ); + actor.SetPixelArea( ImageActor::PixelArea( 0, 0, 10, 10 ) ); + + application.SendNotification(); + application.Render(); + + Vector2 outValue; + application.GetGlAbstraction().GetUniformValue( "uVec2", outValue ); + DALI_TEST_EQUALS( outValue, Vector2( 0.1f, 0.2f ), TEST_LOCATION ); + + application.GetGlAbstraction().GetUniformValue( "uVec2Dir", outValue ); + DALI_TEST_EQUALS( outValue, Vector2( stageSize.x *.5f - 1.f, -stageSize.y * .5f + 2.f), TEST_LOCATION ); - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec2Dir", Vector2( -1.0f, 2.0f ) ) ); END_TEST; } diff --git a/dali/internal/event/common/proxy-object.cpp b/dali/internal/event/common/proxy-object.cpp index 3d7fd8a..f667b18 100644 --- a/dali/internal/event/common/proxy-object.cpp +++ b/dali/internal/event/common/proxy-object.cpp @@ -22,7 +22,6 @@ #include // INTERNAL INCLUDES -#include #include #include #include diff --git a/dali/internal/event/common/proxy-object.h b/dali/internal/event/common/proxy-object.h index 84c4ab8..28de752 100644 --- a/dali/internal/event/common/proxy-object.h +++ b/dali/internal/event/common/proxy-object.h @@ -22,11 +22,12 @@ #include // INTERNAL INCLUDES -#include -#include #include #include +#include +#include #include +#include #include #include #include @@ -281,7 +282,7 @@ public: // Constraints */ void RemoveConstraints( unsigned int tag ); -public: // Called by TypeInfo +public: /** * Called by TypeInfo to set the type-info that this proxy-object is created by. @@ -289,6 +290,14 @@ public: // Called by TypeInfo */ void SetTypeInfo( const TypeInfo* typeInfo ); + /** + * @return the index from which custom properties start + */ + unsigned int CustomPropertyStartIndex() + { + return PROPERTY_CUSTOM_START_INDEX; + } + protected: /** diff --git a/dali/internal/event/effects/shader-effect-impl.cpp b/dali/internal/event/effects/shader-effect-impl.cpp index 8dbb262..c162229 100644 --- a/dali/internal/event/effects/shader-effect-impl.cpp +++ b/dali/internal/event/effects/shader-effect-impl.cpp @@ -18,8 +18,6 @@ // CLASS HEADER #include -// EXTERNAL INCLUDES - // INTERNAL INCLUDES #include #include @@ -27,7 +25,6 @@ #include #include #include -#include "dali-shaders.h" #include #include #include @@ -36,8 +33,10 @@ #include #include #include +#include #include #include +#include "dali-shaders.h" using Dali::Internal::SceneGraph::UpdateManager; using Dali::Internal::SceneGraph::UniformMeta; @@ -300,7 +299,20 @@ void ShaderEffect::SetUniform( const std::string& name, Property::Value value, U SetProperty( index, value ); - SetCoordinateTypeMessage( mUpdateManager.GetEventToUpdate(), *mCustomMetadata[index], uniformCoordinateType ); + // RegisterProperty guarantees a positive value as index + DALI_ASSERT_DEBUG( static_cast(index) >= CustomPropertyStartIndex() ); + unsigned int metaIndex = index - CustomPropertyStartIndex(); + // check if there's space in cache + if( mCoordinateTypes.Count() < (metaIndex + 1) ) + { + mCoordinateTypes.Resize( metaIndex + 1 ); + } + // only send message if the value is different than current, initial value is COORDINATE_TYPE_DEFAULT (0) + if( uniformCoordinateType != mCoordinateTypes[ metaIndex ] ) + { + mCoordinateTypes[ metaIndex ] = uniformCoordinateType; + SetCoordinateTypeMessage( mUpdateManager.GetEventToUpdate(), *mSceneObject, metaIndex, uniformCoordinateType ); + } } void ShaderEffect::AttachExtension( Dali::ShaderEffect::Extension *extension ) @@ -538,7 +550,7 @@ void ShaderEffect::SetDefaultProperty( Property::Index index, const Property::Va DALI_ASSERT_ALWAYS(!"Geometry type unknown" ); } } - SetPrograms( geometryType, vertexPrefix, vertex, fragmentPrefix, fragment ); + SetPrograms( geometryType, vertexPrefix, fragmentPrefix, vertex, fragment ); break; } @@ -611,9 +623,6 @@ void ShaderEffect::InstallSceneObjectProperty( PropertyBase& newProperty, const UniformMeta* meta = UniformMeta::New( name, newProperty, Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT ); // mSceneObject is being used in a separate thread; queue a message to add the property InstallUniformMetaMessage( mUpdateManager.GetEventToUpdate(), *mSceneObject, *meta ); // Message takes ownership - - // Add entry to the metadata lookup - mCustomMetadata[index] = meta; } const SceneGraph::PropertyOwner* ShaderEffect::GetSceneObject() const diff --git a/dali/internal/event/effects/shader-effect-impl.h b/dali/internal/event/effects/shader-effect-impl.h index 828e3c1..d97af61 100644 --- a/dali/internal/event/effects/shader-effect-impl.h +++ b/dali/internal/event/effects/shader-effect-impl.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -233,11 +232,11 @@ private: // Data SceneGraph::UpdateManager& mUpdateManager;///< reference to the update manager SceneGraph::Shader* mSceneObject; ///< pointer to the scene shader, should not be changed on this thread Dali::Image mImage; ///< Client-side handle for the effect image - CustomUniformMetaLookup mCustomMetadata; ///< Used for accessing metadata for custom Shader properties IntrusivePtr mExtension; std::vector mTickets; ///< Collection of shader program tickets unsigned int mConnectionCount; ///< number of on-stage ImageActors using this shader effect Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry + Dali::Vector< UniformCoordinateType > mCoordinateTypes; ///< cached to avoid sending tons of unnecessary messages // Default properties typedef std::map DefaultPropertyLookup; diff --git a/dali/internal/render/shaders/shader.cpp b/dali/internal/render/shaders/shader.cpp index f026d2b..5d20a67 100644 --- a/dali/internal/render/shaders/shader.cpp +++ b/dali/internal/render/shaders/shader.cpp @@ -67,6 +67,9 @@ namespace Dali namespace Internal { +template <> struct ParameterType< Dali::ShaderEffect::GeometryHints> : public BasicType< Dali::ShaderEffect::GeometryHints > {}; +template <> struct ParameterType< Dali::ShaderEffect::UniformCoordinateType > : public BasicType< Dali::ShaderEffect::UniformCoordinateType > {}; + namespace SceneGraph { @@ -153,7 +156,6 @@ Integration::ResourceId Shader::GetEffectTextureResourceId() void Shader::ForwardUniformMeta( BufferIndex updateBufferIndex, UniformMeta* meta ) { // Defer setting uniform metadata until the next Render - // (Maintains thread safety on std::vector) typedef MessageValue1< Shader, UniformMeta* > DerivedType; @@ -164,6 +166,18 @@ void Shader::ForwardUniformMeta( BufferIndex updateBufferIndex, UniformMeta* met new (slot) DerivedType( this, &Shader::InstallUniformMetaInRender, meta ); } +void Shader::ForwardCoordinateType( BufferIndex updateBufferIndex, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type ) +{ + // Defer setting uniform coordinate type until the next Render + typedef MessageValue2< Shader, unsigned int, Dali::ShaderEffect::UniformCoordinateType > DerivedType; + + // Reserve some memory inside the render queue + unsigned int* slot = mRenderQueue->ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + + // Construct message in the render queue memory; note that delete should not be called on the return value + new (slot) DerivedType( this, &Shader::SetCoordinateTypeInRender, index, type ); +} + void Shader::ForwardGridDensity( BufferIndex updateBufferIndex, float density ) { typedef MessageValue1< Shader, float > DerivedType; @@ -219,6 +233,12 @@ void Shader::InstallUniformMetaInRender( UniformMeta* meta ) mUniformMetadata.PushBack( meta ); } +void Shader::SetCoordinateTypeInRender( unsigned int index, Dali::ShaderEffect::UniformCoordinateType type ) +{ + DALI_ASSERT_DEBUG( index < mUniformMetadata.Count() ); + mUniformMetadata[ index ]->SetCoordinateType( type ); +} + void Shader::SetProgram( GeometryType geometryType, ShaderSubTypes subType, Integration::ResourceId resourceId, @@ -384,21 +404,6 @@ void Shader::SetUniforms( Context& context, value.x *= -1.0f; break; } - case Dali::ShaderEffect::COORDINATE_TYPE_TEXTURE_POSITION : - { - if ( mTexture ) - { - UvRect textureArea; - mTexture->GetTextureCoordinates( textureArea ); - - //TODO: this only works for textures that are mapped as a axis aligned rectangle - float width = textureArea.u2 - textureArea.u0; - float height = textureArea.v2 - textureArea.v0; - value.x = textureArea.u0 + value.x * width; - value.y = textureArea.v0 + value.y * height; - } - break; - } case Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT : { // nothing to do in this case @@ -462,6 +467,65 @@ void Shader::SetUniforms( Context& context, DALI_PRINT_SHADER_UNIFORMS(debugStream); } + +// Messages + +void SetTextureIdMessage( EventToUpdate& eventToUpdate, const Shader& shader, Integration::ResourceId textureId ) +{ + typedef MessageDoubleBuffered1< Shader, Integration::ResourceId > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &shader, &Shader::ForwardTextureId, textureId ); +} + +void SetGridDensityMessage( EventToUpdate& eventToUpdate, const Shader& shader, float density ) +{ + typedef MessageDoubleBuffered1< Shader, float > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &shader, &Shader::ForwardGridDensity, density ); +} + +void SetHintsMessage( EventToUpdate& eventToUpdate, const Shader& shader, Dali::ShaderEffect::GeometryHints hint ) +{ + typedef MessageDoubleBuffered1< Shader, Dali::ShaderEffect::GeometryHints > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &shader, &Shader::ForwardHints, hint ); +} + +void InstallUniformMetaMessage( EventToUpdate& eventToUpdate, const Shader& shader, UniformMeta& meta ) +{ + typedef MessageDoubleBuffered1< Shader, UniformMeta* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &shader, &Shader::ForwardUniformMeta, &meta ); +} + +void SetCoordinateTypeMessage( EventToUpdate& eventToUpdate, const Shader& shader, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type ) +{ + typedef MessageDoubleBuffered2< Shader, unsigned int, Dali::ShaderEffect::UniformCoordinateType > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &shader, &Shader::ForwardCoordinateType, index, type ); +} + + } // namespace SceneGraph } // namespace Internal diff --git a/dali/internal/render/shaders/shader.h b/dali/internal/render/shaders/shader.h index 61156e0..4e19deb 100644 --- a/dali/internal/render/shaders/shader.h +++ b/dali/internal/render/shaders/shader.h @@ -194,6 +194,16 @@ public: void ForwardUniformMeta( BufferIndex updateBufferIndex, UniformMeta* meta ); /** + * Forwards coordinate type to render + * @sa InstallUniformMetaInRender + * @pre This method should only be called from the update thread. + * @param[in] updateBufferIndex The current update buffer index. + * @param[in] index of the metadata. + * @param[in] type the coordinate type. + */ + void ForwardCoordinateType( BufferIndex updateBufferIndex, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type ); + + /** * Forwards the grid density. * @pre This method is not thread-safe, and should only be called from the update thread. * @param[in] updateBufferIndex The current update buffer index. @@ -248,6 +258,13 @@ public: void InstallUniformMetaInRender( UniformMeta* meta ); /** + * Sets the uniform coordinate type + * @param index of the uniform + * @param type to set + */ + void SetCoordinateTypeInRender( unsigned int index, Dali::ShaderEffect::UniformCoordinateType type ); + + /** * Set the program for a geometry type and subtype * @param[in] geometryType The type of the object (geometry) that is to be rendered. * @param[in] subType The subtype, one of ShaderSubTypes. @@ -301,8 +318,6 @@ public: private: // Data - typedef OwnerContainer< UniformMeta* > UniformMetaContainer; - Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry float mGridDensity; ///< grid density Texture* mTexture; ///< Raw Pointer to Texture @@ -311,6 +326,7 @@ private: // Data std::vector mPrograms; ///< 2D array of Program*. Access by [Log::value][index]. An index of 0 selects the default program for that geometry type. + typedef OwnerContainer< UniformMeta* > UniformMetaContainer; UniformMetaContainer mUniformMetadata; ///< A container of owned UniformMeta values; one for each property in PropertyOwner::mDynamicProperties // These members are only safe to access during UpdateManager::Update() @@ -320,60 +336,12 @@ private: // Data TextureCache* mTextureCache; // Used for retrieving textures in the render thread }; -} // namespace SceneGraph - -template <> struct ParameterType : public BasicType< Dali::ShaderEffect::GeometryHints > -{ -}; - -namespace SceneGraph -{ - // Messages for Shader, to be processed in Update thread. - -inline void SetTextureIdMessage( EventToUpdate& eventToUpdate, const Shader& shader, Integration::ResourceId textureId ) -{ - typedef MessageDoubleBuffered1< Shader, Integration::ResourceId > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &shader, &Shader::ForwardTextureId, textureId ); -} - -inline void SetGridDensityMessage( EventToUpdate& eventToUpdate, const Shader& shader, float density ) -{ - typedef MessageDoubleBuffered1< Shader, float > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &shader, &Shader::ForwardGridDensity, density ); -} - -inline void SetHintsMessage( EventToUpdate& eventToUpdate, const Shader& shader, Dali::ShaderEffect::GeometryHints hint ) -{ - typedef MessageDoubleBuffered1< Shader, Dali::ShaderEffect::GeometryHints > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &shader, &Shader::ForwardHints, hint ); -} - -inline void InstallUniformMetaMessage( EventToUpdate& eventToUpdate, const Shader& shader, UniformMeta& meta ) -{ - typedef MessageDoubleBuffered1< Shader, UniformMeta* > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &shader, &Shader::ForwardUniformMeta, &meta ); -} +void SetTextureIdMessage( EventToUpdate& eventToUpdate, const Shader& shader, Integration::ResourceId textureId ); +void SetGridDensityMessage( EventToUpdate& eventToUpdate, const Shader& shader, float density ); +void SetHintsMessage( EventToUpdate& eventToUpdate, const Shader& shader, Dali::ShaderEffect::GeometryHints hint ); +void InstallUniformMetaMessage( EventToUpdate& eventToUpdate, const Shader& shader, UniformMeta& meta ); +void SetCoordinateTypeMessage( EventToUpdate& eventToUpdate, const Shader& shader, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type ); } // namespace SceneGraph diff --git a/dali/internal/render/shaders/uniform-meta.h b/dali/internal/render/shaders/uniform-meta.h index b2ab419..030ca9f 100644 --- a/dali/internal/render/shaders/uniform-meta.h +++ b/dali/internal/render/shaders/uniform-meta.h @@ -46,12 +46,10 @@ class UniformMeta { public: - typedef Dali::ShaderEffect::UniformCoordinateType CoordinateType; - /** * Create a UniformMeta. */ - static UniformMeta* New( const std::string& name, const PropertyBase& property, CoordinateType coordType ) + static UniformMeta* New( const std::string& name, const PropertyBase& property, Dali::ShaderEffect::UniformCoordinateType coordType ) { return new UniformMeta( name, property, coordType ); } @@ -72,7 +70,7 @@ public: * Set the coordinate type. * @param [in] coordType The new coordinate type. */ - void SetCoordinateType( CoordinateType coordType ) + void SetCoordinateType( Dali::ShaderEffect::UniformCoordinateType coordType ) { coordinateType = coordType; } @@ -82,7 +80,7 @@ private: /** * Constructor */ - UniformMeta( const std::string& uniformName, const PropertyBase& prop, CoordinateType coordType ) + UniformMeta( const std::string& uniformName, const PropertyBase& prop, Dali::ShaderEffect::UniformCoordinateType coordType ) : name( uniformName ), property( prop ), coordinateType( coordType ) @@ -96,43 +94,14 @@ private: public: std::string name; ///< name of uniform to set/animate - const PropertyBase& property; ///< reference to the corresponding property - unsigned int cacheIndeces[ Log::value ][ SHADER_SUBTYPE_LAST ]; ///< internal program cache index, per program + Dali::ShaderEffect::UniformCoordinateType coordinateType; ///< The coordinate type of the uniform - CoordinateType coordinateType; ///< The coordinate type of the uniform }; -// Messages for UniformMeta - -}; // namespace SceneGraph - -// value types used by messages -template <> struct ParameterType< SceneGraph::UniformMeta::CoordinateType > -: public BasicType< SceneGraph::UniformMeta::CoordinateType > {}; - -namespace SceneGraph -{ - -inline void SetCoordinateTypeMessage( EventToUpdate& eventToUpdate, const UniformMeta& meta, UniformMeta::CoordinateType type ) -{ - typedef MessageValue1< UniformMeta, UniformMeta::CoordinateType > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &meta, &UniformMeta::SetCoordinateType, type ); -} - } // namespace SceneGraph -/** - * Used for accessing uniform metadata by property index - */ -typedef std::map CustomUniformMetaLookup; - } // namespace Internal } // namespace Dali diff --git a/dali/public-api/actors/renderable-actor.h b/dali/public-api/actors/renderable-actor.h index b6acf3f..31236ac 100644 --- a/dali/public-api/actors/renderable-actor.h +++ b/dali/public-api/actors/renderable-actor.h @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include +#include #include #include diff --git a/dali/public-api/shader-effects/shader-effect.h b/dali/public-api/shader-effects/shader-effect.h index 1f404a8..13ce2c2 100644 --- a/dali/public-api/shader-effects/shader-effect.h +++ b/dali/public-api/shader-effects/shader-effect.h @@ -214,10 +214,9 @@ public: */ enum UniformCoordinateType { - COORDINATE_TYPE_DEFAULT, ///< Default, No transformation to be applied - COORDINATE_TYPE_VIEWPORT_POSITION, ///< The uniform is a position vector in viewport coordinates that needs to be converted to GL view space coordinates. - COORDINATE_TYPE_VIEWPORT_DIRECTION, ///< The uniform is a directional vector in viewport coordinates that needs to be converted to GL view space coordinates. - COORDINATE_TYPE_TEXTURE_POSITION ///< The uniform is a position in texture coordinates. + COORDINATE_TYPE_DEFAULT, ///< Default, No transformation to be applied + COORDINATE_TYPE_VIEWPORT_POSITION, ///< The uniform is a position vector in viewport coordinates that needs to be converted to GL view space coordinates. + COORDINATE_TYPE_VIEWPORT_DIRECTION ///< The uniform is a directional vector in viewport coordinates that needs to be converted to GL view space coordinates. }; /** -- 2.7.4