2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
21 #include "dali-scene3d/public-api/loader/node-definition.h"
22 #include "dali-scene3d/public-api/loader/view-projection.h"
23 #include <toolkit-test-application.h>
24 #include <dali-test-suite-utils.h>
25 #include <string_view>
28 using namespace Dali::Scene3D::Loader;
35 ResourceBundle resources;
37 ViewProjection viewProjection;
38 Transforms transforms { MatrixStack{}, viewProjection };
40 NodeDefinition::CreateParams createParams {
48 int UtcDaliConstraintDefinitionsCompare(void)
50 ConstraintDefinition cd1{ "orientation", 0 };
51 ConstraintDefinition cd2{ "position", 1 };
53 DALI_TEST_CHECK(cd1 < cd2);
54 DALI_TEST_CHECK(!(cd2 < cd1));
55 DALI_TEST_CHECK(!(cd1 < cd1));
56 DALI_TEST_CHECK(!(cd2 < cd2));
58 DALI_TEST_CHECK(cd1 == cd1);
59 DALI_TEST_CHECK(cd2 == cd2);
61 ConstraintDefinition cd3{ "position", 0 };
62 ConstraintDefinition cd4{ "scale", 1 };
63 ConstraintDefinition cd5{ "position", 1 };
64 DALI_TEST_CHECK(cd2 != cd3);
65 DALI_TEST_CHECK(cd2 != cd4);
66 DALI_TEST_CHECK(cd2 == cd5);
67 DALI_TEST_CHECK(cd5 == cd2);
72 int UtcDaliBlendshapeShaderConfigurationRequestsCompare(void)
75 BlendshapeShaderConfigurationRequest bsscr1{ "", 0, Shader(nullptr) };
77 BlendshapeShaderConfigurationRequest bsscr2{ "", 0, Shader::New(
78 "void main(){ gl_Position = vec4(0.); }",
79 "void main(){ gl_FragColor = vec4(1.); }"
82 DALI_TEST_CHECK(bsscr1 < bsscr2);
83 DALI_TEST_CHECK(!(bsscr2 < bsscr1));
84 DALI_TEST_CHECK(!(bsscr1 < bsscr1));
85 DALI_TEST_CHECK(!(bsscr2 < bsscr2));
90 int UtcDaliNodeDefinitionExtrasCompare(void)
92 NodeDefinition::Extra e1{ "alpha", Vector3::XAXIS * 2.f };
93 NodeDefinition::Extra e2{ "beta", 8 };
95 DALI_TEST_CHECK(e1 < e2);
96 DALI_TEST_CHECK(!(e1 < e1));
97 DALI_TEST_CHECK(!(e2 < e1));
98 DALI_TEST_CHECK(!(e2 < e2));
103 int UtcDaliNodeDefinitionProperties(void)
105 TestApplication testApp;
106 NodeDefinition nodeDef{
108 Vector3{ -100.f, 100.f, -500.f },
109 Quaternion{ Radian(Degree(45.f)), Vector3::ZAXIS },
110 Vector3{ 2.f, 4.f, 8.f },
111 Vector3{ 100.f, 50.f, 25.f },
115 Quaternion frobnicateFactor(0.f, 1.f, 2.f, 3.f);
116 frobnicateFactor.Normalize(); // because it will be (by DALi) once it's set as a property.
117 nodeDef.mExtras.push_back(NodeDefinition::Extra{ "frobnicateFactor", frobnicateFactor });
120 auto actor = nodeDef.CreateActor(ctx.createParams);
121 DALI_TEST_EQUAL(nodeDef.mName, actor.GetProperty(Actor::Property::NAME).Get<std::string>());
122 DALI_TEST_EQUAL(nodeDef.mPosition, actor.GetProperty(Actor::Property::POSITION).Get<Vector3>());
123 DALI_TEST_EQUAL(nodeDef.mOrientation, actor.GetProperty(Actor::Property::ORIENTATION).Get<Quaternion>());
124 DALI_TEST_EQUAL(nodeDef.mScale, actor.GetProperty(Actor::Property::SCALE).Get<Vector3>());
125 DALI_TEST_EQUAL(nodeDef.mSize, actor.GetProperty(Actor::Property::SIZE).Get<Vector3>());
126 DALI_TEST_EQUAL(nodeDef.mIsVisible, actor.GetProperty(Actor::Property::VISIBLE).Get<bool>());
128 Property::Index propFrobnicateFactor = actor.GetPropertyIndex("frobnicateFactor");
129 DALI_TEST_CHECK(propFrobnicateFactor != Property::INVALID_INDEX);
131 auto frobnicateFactorValue = actor.GetProperty(propFrobnicateFactor);
132 DALI_TEST_EQUAL(Property::ROTATION, frobnicateFactorValue.GetType());
133 DALI_TEST_EQUAL(frobnicateFactorValue.Get<Quaternion>(), frobnicateFactor);
135 DALI_TEST_EQUAL(0, actor.GetChildCount());
136 DALI_TEST_EQUAL(0, actor.GetRendererCount());
141 int UtcDaliNodeDefinitionRenderableRegisterResources(void)
143 NodeDefinition nodeDef;
145 auto renderable = new NodeDefinition::Renderable();
146 renderable->mShaderIdx = 0;
147 nodeDef.mRenderable.reset(renderable);
149 struct : IResourceReceiver
151 std::vector<Index> shaders;
152 uint32_t otherResources = 0;
154 void Register(ResourceType::Value type, Index id) override
158 case ResourceType::Shader:
159 shaders.push_back(id);
168 nodeDef.mRenderable->RegisterResources(resourceReceiver);
169 DALI_TEST_EQUAL(1u, resourceReceiver.shaders.size());
170 DALI_TEST_EQUAL(0, resourceReceiver.shaders[0]);
171 DALI_TEST_EQUAL(0, resourceReceiver.otherResources);
176 int UtcDaliNodeDefinitionRenderableReflectResources(void)
178 NodeDefinition nodeDef;
180 auto renderable = new NodeDefinition::Renderable();
181 renderable->mShaderIdx = 0;
182 nodeDef.mRenderable.reset(renderable);
184 struct : IResourceReflector
186 std::vector<Index*> shaders;
187 uint32_t otherResources = 0;
189 void Reflect(ResourceType::Value type, Index& id) override
193 case ResourceType::Shader:
194 shaders.push_back(&id);
203 nodeDef.mRenderable->ReflectResources(resourceReflector);
204 DALI_TEST_EQUAL(1u, resourceReflector.shaders.size());
205 DALI_TEST_EQUAL(&renderable->mShaderIdx, resourceReflector.shaders[0]);
206 DALI_TEST_EQUAL(0, resourceReflector.otherResources);
211 int UtcDaliNodeDefinitionRenderable(void)
213 TestApplication testApp;
214 NodeDefinition nodeDef;
216 auto renderable = new NodeDefinition::Renderable();
217 renderable->mShaderIdx = 0;
218 nodeDef.mRenderable.reset(renderable);
221 const auto VSH = "void main() { gl_Position = vec4(0.); }";
222 const auto FSH = "void main() { gl_FragColor = vec4(1.); }";
223 auto shader = Shader::New(VSH, FSH);
224 ctx.resources.mShaders.push_back({ ShaderDefinition{}, shader });
226 auto actor = nodeDef.CreateActor(ctx.createParams);
227 DALI_TEST_EQUAL(1, actor.GetRendererCount());
229 auto renderer = actor.GetRendererAt(0);
230 DALI_TEST_EQUAL(renderer.GetShader(), shader);