Asynchronous loading of Scene3D resources
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / common / environment-map-load-task.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-scene3d/internal/common/environment-map-load-task.h>
20
21 // INTERNAL INCLUDES
22 #include <dali-scene3d/public-api/loader/cube-map-loader.h>
23
24
25 namespace Dali
26 {
27 namespace Scene3D
28 {
29 namespace Internal
30 {
31
32 EnvironmentMapLoadTask::EnvironmentMapLoadTask(const std::string& environmentMapUrl, CallbackBase* callback)
33 : AsyncTask(callback),
34   mEnvironmentMapUrl(environmentMapUrl),
35   mIsReady(true),
36   mHasSucceeded(false)
37 {
38 }
39
40 EnvironmentMapLoadTask::~EnvironmentMapLoadTask()
41 {
42 }
43
44 void EnvironmentMapLoadTask::Process()
45 {
46   mHasSucceeded = Scene3D::Loader::LoadCubeMapData(mEnvironmentMapUrl, mEnvironmentMapPixelData);
47 }
48
49 bool EnvironmentMapLoadTask::IsReady()
50 {
51   return mIsReady;
52 }
53
54 bool EnvironmentMapLoadTask::HasSucceeded() const
55 {
56   return mHasSucceeded;
57 }
58
59 Dali::Scene3D::Loader::CubeData EnvironmentMapLoadTask::GetEnvironmentMap() const
60 {
61   Dali::Scene3D::Loader::CubeData environmentMapPixelData;
62   if(mIsReady && mHasSucceeded && !mEnvironmentMapPixelData.data.empty())
63   {
64     environmentMapPixelData = mEnvironmentMapPixelData;
65   }
66   return environmentMapPixelData;
67 }
68
69 } // namespace Internal
70
71 } // namespace Scene3D
72
73 } // namespace Dali