Merge "Legacy Size negotiation mapper" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scene3d-view / scene3d-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCENE3D_VIEW_H\r
2 #define DALI_TOOLKIT_INTERNAL_SCENE3D_VIEW_H\r
3 \r
4 /*\r
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  */\r
20 \r
21 // EXTERNAL INCLUDES\r
22 #include <cstring>\r
23 #include <dali/public-api/object/base-object.h>\r
24 #include <dali/public-api/rendering/shader.h>\r
25 #include <dali/devel-api/adaptor-framework/image-loading.h>\r
26 #include <dali/devel-api/adaptor-framework/file-loader.h>\r
27 \r
28 // INTERNAL INCLUDES\r
29 #include <dali-toolkit/public-api/controls/control-impl.h>\r
30 #include <dali-toolkit/devel-api/controls/scene3d-view/scene3d-view.h>\r
31 #include <dali-toolkit/internal/controls/scene3d-view/gltf-loader.h>\r
32 \r
33 namespace Dali\r
34 {\r
35 \r
36 namespace Toolkit\r
37 {\r
38 \r
39 class Scene3dView;\r
40 \r
41 namespace Internal\r
42 {\r
43 \r
44 namespace Gltf\r
45 {\r
46 \r
47 class Loader;\r
48 \r
49 }\r
50 \r
51 /**\r
52  * Scene3dView implementation class\r
53  */\r
54 class Scene3dView : public Control\r
55 {\r
56 public:\r
57 \r
58   enum CubeType\r
59   {\r
60     CROSS_HORIZONTAL = 0,                 // Cross horizontal style cube map\r
61     ARRAY_HORIZONTAL,                     // array horizontal style cube map\r
62     NONE\r
63   };\r
64 \r
65 \r
66   /**\r
67    * @copydoc Dali::Toolkit::Scene3dView::Scene3dView\r
68    */\r
69   Scene3dView();\r
70 \r
71   /**\r
72    * @copydoc Dali::Toolkit::Scene3dView::~Scene3dView\r
73    */\r
74   virtual ~Scene3dView();\r
75 \r
76   /**\r
77    * @copydoc Dali::Toolkit::Scene3dView::New( const std::string& filePath )\r
78    */\r
79   static Dali::Toolkit::Scene3dView New( const std::string& filePath );\r
80 \r
81   /**\r
82    * @copydoc Dali::Toolkit::Scene3dView::New( const std::string& filePath, const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor )\r
83    */\r
84   static Dali::Toolkit::Scene3dView New( const std::string& filePath, const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor );\r
85 \r
86   /**\r
87    * @copydoc Dali::Toolkit::Scene3dView::CreateScene()\r
88    */\r
89   bool CreateScene();\r
90 \r
91   /**\r
92    * @copydoc Dali::Toolkit::Scene3dView::GetAnimationCount()\r
93    */\r
94   uint32_t GetAnimationCount();\r
95 \r
96   /**\r
97    * @copydoc Dali::Toolkit::Scene3dView::PlayAnimation()\r
98    */\r
99   bool PlayAnimation( uint32_t index );\r
100 \r
101   /**\r
102    * @copydoc Dali::Toolkit::Scene3dView::PlayAnimations()\r
103    */\r
104   bool PlayAnimations();\r
105 \r
106   /**\r
107    * @copydoc Dali::Toolkit::Scene3dView::SetLight( Toolkit::Scene3dView::LightType type, Vector3 lightVector, Vector3 lightColor )\r
108    */\r
109   bool SetLight( Toolkit::Scene3dView::LightType type, Vector3 lightVector, Vector3 lightColor );\r
110 \r
111   /**\r
112    * @brief Set default CameraActor specified in the each scene format specification.\r
113    * Default input values are derived from glTF default camera format.\r
114    * with Dali::Camera::Type = Dali::Camera::LOOK_AT_TARGET,\r
115    * near clipping plane = 0.1,\r
116    * and camera position = Vector3( 0.0, 0.0, 0.0 ).\r
117    */\r
118   bool SetDefaultCamera( const Dali::Camera::Type type = Dali::Camera::LOOK_AT_TARGET, const float nearPlane = 0.1, const Vector3 cameraPosition = Vector3( 0.0, 0.0, 0.0 ) );\r
119 \r
120   /**\r
121    * @brief Add CameraActor loaded from scene format file.\r
122    */\r
123   void AddCamera( CameraActor cameraActor );\r
124 \r
125   /**\r
126    * @brief Add Animation loaded from scene format file.\r
127    */\r
128   void AddAnimation( Animation animation );\r
129 \r
130   /**\r
131    * @brief Add new Shader.\r
132    * Actors can share same Shader if they use same properties.\r
133    * If a property changes in a shader, then the property of all actors that use the shader change.\r
134    */\r
135   void AddShader( Shader shader );\r
136 \r
137   /**\r
138    * @brief Get Root Actor.\r
139    */\r
140   Actor GetRoot();\r
141 \r
142   /**\r
143    * @copydoc Dali::Toolkit::Scene3dView::GetDefaultCamera()\r
144    */\r
145   CameraActor GetDefaultCamera();\r
146 \r
147   /**\r
148    * @copydoc Dali::Toolkit::Scene3dView::GetCameraCount()\r
149    */\r
150   uint32_t GetCameraCount();\r
151 \r
152   /**\r
153    * @copydoc Dali::Toolkit::Scene3dView::GetCamera( uint32_t cameraIndex )\r
154    */\r
155   CameraActor GetCamera( uint32_t cameraIndex );\r
156 \r
157   /**\r
158    * @brief Get light type.\r
159    */\r
160   Toolkit::Scene3dView::LightType GetLightType();\r
161 \r
162   /**\r
163    * @brief Get light vector.\r
164    * Return light position when light type is LightType::POINT_LIGHT\r
165    * Return light direction when light type is LightType::DIRECTIONAL_LIGHT\r
166    */\r
167   Vector3 GetLightVector();\r
168 \r
169   /**\r
170    * @brief Get light color.\r
171    */\r
172   Vector3 GetLightColor();\r
173 \r
174   /**\r
175    * @brief Get Scaling factor of IBL.\r
176    */\r
177   Vector4 GetIBLScaleFactor();\r
178 \r
179   /**\r
180    * @brief Get BRDF Texture.\r
181    */\r
182   Texture GetBRDFTexture();\r
183 \r
184   /**\r
185    * @brief Get diffuse cube map texture.\r
186    */\r
187   Texture GetDiffuseTexture();\r
188 \r
189   /**\r
190    * @brief Get specular cube map texture.\r
191    */\r
192   Texture GetSpecularTexture();\r
193 \r
194 private:\r
195   /**\r
196    * @brief Get Cropped image buffer.\r
197    * For each direction, Offset + faceSize must be width or height or less then them.\r
198    */\r
199   uint8_t* GetCroppedBuffer( uint8_t* sourceBuffer, uint32_t bytesPerPixel, uint32_t width, uint32_t height, uint32_t xOffset, uint32_t yOffset, uint32_t xFaceSize, uint32_t yFaceSize );\r
200 \r
201   /**\r
202    * @brief Upload cube map texture.\r
203    */\r
204   void UploadTextureFace( Texture& texture, Devel::PixelBuffer pixelBuffer, uint32_t faceIndex );\r
205 \r
206   /**\r
207    * @brief Set diffuse and specular cube map textures.\r
208    */\r
209   void SetCubeMap( const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor = Vector4( 1.0, 1.0, 1.0, 1.0 ) );\r
210 \r
211   virtual void OnInitialize();\r
212 \r
213 \r
214   /**\r
215    * @brief Load 2D texture.\r
216    * @param[in] imageUrl Image URL of the texture.\r
217    * @param[in] generateMipmaps If generateMipmaps is true, then generate mipmap of this texture.\r
218    * @return Texture loaded from imageUrl.\r
219    */\r
220   Texture LoadTexture( const char *imageUrl, bool generateMipmaps );\r
221 \r
222 private:\r
223   Actor mRoot; // Root actor that contains scene graph\r
224   std::string mFilePath; // Full file path of scene file\r
225 \r
226   std::vector<Shader> mShaderArray; // Shader Array to change properties of scene such as lighting.\r
227 \r
228   std::vector<CameraActor> mCameraActorArray; // CameraActer array loaded from scene format file.\r
229   CameraActor mDefaultCamera; // Default CameraActor for the empty mCameraActorArray.\r
230 \r
231   std::vector<Animation> mAnimationArray; // Animation array loaded from scene format file.\r
232 \r
233   Toolkit::Scene3dView::LightType mLightType; // Light type\r
234   Vector3 mLightVector; // Light position when mLightType is LightType::POINT_LIGHT\r
235                         // Light direction when mLightType is LightType::DIRECTIONAL_LIGHT\r
236   Vector3 mLightColor; // Light color\r
237 \r
238   Vector4 mIBLScaleFactor; // IBL scaling factor for the IBL rendering\r
239   Texture mBRDFTexture; // BRDF texture for the PBR rendering\r
240   Texture mSpecularTexture; // Specular cube map texture\r
241   Texture mDiffuseTexture; // Diffuse cube map texture\r
242 \r
243 private:\r
244 \r
245   // Undefined copy constructor.\r
246   Scene3dView( const Scene3dView& );\r
247 \r
248   // Undefined assignment operator.\r
249   Scene3dView& operator=( const Scene3dView& );\r
250 };\r
251 \r
252 } // namespace Internal\r
253 \r
254   // Helpers for public-api forwarding methods\r
255 inline const Internal::Scene3dView& GetImpl( const Toolkit::Scene3dView& scene3dView )\r
256 {\r
257   DALI_ASSERT_ALWAYS( scene3dView && "Scene3dView handle is empty" );\r
258   const Dali::RefObject& handle = scene3dView.GetImplementation();\r
259 \r
260   return static_cast<const Toolkit::Internal::Scene3dView&>( handle );\r
261 }\r
262 \r
263 inline Internal::Scene3dView& GetImpl( Toolkit::Scene3dView& scene3dView )\r
264 {\r
265   DALI_ASSERT_ALWAYS( scene3dView && "Scene3dView handle is empty" );\r
266 \r
267   Dali::RefObject& handle = scene3dView.GetImplementation();\r
268 \r
269   return static_cast<Toolkit::Internal::Scene3dView&>( handle );\r
270 }\r
271 \r
272 }//namespace Toolkit\r
273 \r
274 }//namespace Dali\r
275 \r
276 #endif // DALI_TOOLKIT_INTERNAL_SCENE3D_VIEW_H\r