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-test-suite-utils.h>
22 #include <toolkit-test-application.h>
23 #include <string_view>
24 #include "dali-scene3d/public-api/loader/node-definition.h"
25 #include "dali-scene3d/public-api/loader/view-projection.h"
28 using namespace Dali::Scene3D::Loader;
35 ResourceBundle resources;
37 ViewProjection viewProjection;
38 Transforms transforms{MatrixStack{}, viewProjection};
40 NodeDefinition::CreateParams createParams{
47 int UtcDaliConstraintDefinitionsCompare(void)
49 ConstraintDefinition cd1{"orientation", 0};
50 ConstraintDefinition cd2{"position", 1};
52 DALI_TEST_CHECK(cd1 < cd2);
53 DALI_TEST_CHECK(!(cd2 < cd1));
54 DALI_TEST_CHECK(!(cd1 < cd1));
55 DALI_TEST_CHECK(!(cd2 < cd2));
57 DALI_TEST_CHECK(cd1 == cd1);
58 DALI_TEST_CHECK(cd2 == cd2);
60 ConstraintDefinition cd3{"position", 0};
61 ConstraintDefinition cd4{"scale", 1};
62 ConstraintDefinition cd5{"position", 1};
63 DALI_TEST_CHECK(cd2 != cd3);
64 DALI_TEST_CHECK(cd2 != cd4);
65 DALI_TEST_CHECK(cd2 == cd5);
66 DALI_TEST_CHECK(cd5 == cd2);
71 int UtcDaliBlendshapeShaderConfigurationRequestsCompare(void)
74 BlendshapeShaderConfigurationRequest bsscr1{"", 0, Shader(nullptr)};
76 BlendshapeShaderConfigurationRequest bsscr2{"", 0, Shader::New("void main(){ gl_Position = vec4(0.); }", "void main(){ gl_FragColor = vec4(1.); }")};
78 DALI_TEST_CHECK(bsscr1 < bsscr2);
79 DALI_TEST_CHECK(!(bsscr2 < bsscr1));
80 DALI_TEST_CHECK(!(bsscr1 < bsscr1));
81 DALI_TEST_CHECK(!(bsscr2 < bsscr2));
86 int UtcDaliNodeDefinitionExtrasCompare(void)
88 NodeDefinition::Extra e1{"alpha", Vector3::XAXIS * 2.f};
89 NodeDefinition::Extra e2{"beta", 8};
91 DALI_TEST_CHECK(e1 < e2);
92 DALI_TEST_CHECK(!(e1 < e1));
93 DALI_TEST_CHECK(!(e2 < e1));
94 DALI_TEST_CHECK(!(e2 < e2));
99 int UtcDaliNodeDefinitionProperties(void)
101 TestApplication testApp;
102 NodeDefinition nodeDef{
105 Vector3{-100.f, 100.f, -500.f},
106 Quaternion{Radian(Degree(45.f)), Vector3::ZAXIS},
107 Vector3{2.f, 4.f, 8.f},
108 Vector3{100.f, 50.f, 25.f},
112 Quaternion frobnicateFactor(0.f, 1.f, 2.f, 3.f);
113 frobnicateFactor.Normalize(); // because it will be (by DALi) once it's set as a property.
114 nodeDef.mExtras.push_back(NodeDefinition::Extra{"frobnicateFactor", frobnicateFactor});
117 auto actor = nodeDef.CreateModelNode(ctx.createParams);
118 DALI_TEST_EQUAL(nodeDef.mName, actor.GetProperty(Actor::Property::NAME).Get<std::string>());
119 DALI_TEST_EQUAL(nodeDef.mPosition, actor.GetProperty(Actor::Property::POSITION).Get<Vector3>());
120 DALI_TEST_EQUAL(nodeDef.mOrientation, actor.GetProperty(Actor::Property::ORIENTATION).Get<Quaternion>());
121 DALI_TEST_EQUAL(nodeDef.mScale, actor.GetProperty(Actor::Property::SCALE).Get<Vector3>());
122 DALI_TEST_EQUAL(nodeDef.mSize, actor.GetProperty(Actor::Property::SIZE).Get<Vector3>());
123 DALI_TEST_EQUAL(nodeDef.mIsVisible, actor.GetProperty(Actor::Property::VISIBLE).Get<bool>());
125 Property::Index propFrobnicateFactor = actor.GetPropertyIndex("frobnicateFactor");
126 DALI_TEST_CHECK(propFrobnicateFactor != Property::INVALID_INDEX);
128 auto frobnicateFactorValue = actor.GetProperty(propFrobnicateFactor);
129 DALI_TEST_EQUAL(Property::ROTATION, frobnicateFactorValue.GetType());
130 DALI_TEST_EQUAL(frobnicateFactorValue.Get<Quaternion>(), frobnicateFactor);
132 DALI_TEST_EQUAL(0, actor.GetChildCount());
133 DALI_TEST_EQUAL(0, actor.GetRendererCount());
138 int UtcDaliNodeDefinitionRenderableRegisterResources(void)
140 NodeDefinition nodeDef;
142 std::unique_ptr<NodeDefinition::Renderable> renderable = std::unique_ptr<NodeDefinition::Renderable>(new NodeDefinition::Renderable());
143 nodeDef.mRenderables.push_back(std::move(renderable));
144 nodeDef.mRenderables[0]->mShaderIdx = 0;
146 struct : IResourceReceiver
148 std::vector<Index> shaders;
149 uint32_t otherResources = 0;
151 void Register(ResourceType::Value type, Index id) override
155 case ResourceType::Shader:
156 shaders.push_back(id);
165 nodeDef.mRenderables[0]->RegisterResources(resourceReceiver);
166 DALI_TEST_EQUAL(1u, resourceReceiver.shaders.size());
167 DALI_TEST_EQUAL(0, resourceReceiver.shaders[0]);
168 DALI_TEST_EQUAL(0, resourceReceiver.otherResources);
173 int UtcDaliNodeDefinitionRenderableReflectResources(void)
175 NodeDefinition nodeDef;
177 std::unique_ptr<NodeDefinition::Renderable> renderable = std::unique_ptr<NodeDefinition::Renderable>(new NodeDefinition::Renderable());
178 nodeDef.mRenderables.push_back(std::move(renderable));
179 nodeDef.mRenderables[0]->mShaderIdx = 0;
181 struct : IResourceReflector
183 std::vector<Index*> shaders;
184 uint32_t otherResources = 0;
186 void Reflect(ResourceType::Value type, Index& id) override
190 case ResourceType::Shader:
191 shaders.push_back(&id);
200 nodeDef.mRenderables[0]->ReflectResources(resourceReflector);
201 DALI_TEST_EQUAL(1u, resourceReflector.shaders.size());
202 DALI_TEST_EQUAL(&nodeDef.mRenderables[0]->mShaderIdx, resourceReflector.shaders[0]);
203 DALI_TEST_EQUAL(0, resourceReflector.otherResources);
208 int UtcDaliNodeDefinitionRenderable(void)
210 TestApplication testApp;
211 NodeDefinition nodeDef;
213 std::unique_ptr<NodeDefinition::Renderable> renderable = std::unique_ptr<NodeDefinition::Renderable>(new NodeDefinition::Renderable());
214 nodeDef.mRenderables.push_back(std::move(renderable));
215 nodeDef.mRenderables[0]->mShaderIdx = 0;
218 const auto VSH = "void main() { gl_Position = vec4(0.); }";
219 const auto FSH = "void main() { gl_FragColor = vec4(1.); }";
220 auto shader = Shader::New(VSH, FSH);
221 ctx.resources.mShaders.push_back({ShaderDefinition{}, shader});
223 auto actor = nodeDef.CreateModelNode(ctx.createParams);
224 DALI_TEST_EQUAL(1, actor.GetRendererCount());
226 auto renderer = actor.GetRendererAt(0);
227 DALI_TEST_EQUAL(renderer.GetShader(), shader);