Change enumeration values to uppercase for Mesh & Gradient Renderer
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / mesh / mesh-renderer.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_MESH_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_MESH_RENDERER_H__
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <fstream>
23 #include <string.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
27 #include <dali-toolkit/internal/controls/model3d-view/obj-loader.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * The renderer which renders a 3D object to the control's quad
40  *
41  * The following Property::Map keys are required to create a MeshRender
42  *
43  * | %Property Name  | Type        | Representing                            |
44  * |-----------------|-------------|-----------------------------------------|
45  * | objectUrl       | STRING      | A URL to the .obj file                  |
46  * | materialUrl     | STRING      | A URL to the .mtl file                  |
47  * | texturesPath    | STRING      | A URL of the path to the texture images |
48  * | shaderType      | STRING      | An enum of shader types                 |
49  */
50 class MeshRenderer: public ControlRenderer
51 {
52 public:
53
54   /**
55    * @brief Constructor.
56    *
57    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
58    */
59   MeshRenderer( RendererFactoryCache& factoryCache );
60
61   /**
62    * @brief A reference counted object may only be deleted by calling Unreference().
63    */
64   virtual ~MeshRenderer();
65
66 public:  // from ControlRenderer
67
68   /**
69    * @copydoc ControlRenderer::SetSize
70    */
71   virtual void SetSize( const Vector2& size );
72
73   /**
74    * @copydoc ControlRenderer::SetClipRect
75    */
76   virtual void SetClipRect( const Rect<int>& clipRect );
77
78   /**
79    * @copydoc ControlRenderer::SetOffset
80    */
81   virtual void SetOffset( const Vector2& offset );
82
83   /**
84    * @copydoc ControlRenderer::CreatePropertyMap
85    */
86   virtual void DoCreatePropertyMap( Property::Map& map ) const;
87
88 protected:
89
90   /**
91    * @copydoc ControlRenderer::DoInitialize
92    */
93   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
94
95   /**
96    * @copydoc ControlRenderer::DoSetOnStage
97    */
98   virtual void DoSetOnStage( Actor& actor );
99
100 public:
101
102   /**
103    * Declare whether a texture map should be used for the object, if it's present. Defaults to true.
104    * @param[in] useTexture boolean declaration.
105    */
106   void SetUseTexture( bool useTexture );
107
108   /**
109    * Declare whether a normal map should be used for the object, if it's present. Defaults to true.
110    * @param[in] useNormalMap boolean declaration.
111    */
112   void SetUseNormalMap( bool useNormalMap );
113
114 private:
115
116   //Corresponds to the shader that will be used by the mesh renderer.
117   enum ShaderType
118   {
119     TEXTURELESS,
120     DIFFUSE_TEXTURE,
121     ALL_TEXTURES
122   };
123
124   /**
125    * @brief Provide an empty geometry for the renderer to use.
126    * @details For use in error cases where the initialisation has failed for varying reasons.
127    */
128   void SupplyEmptyGeometry();
129
130   /**
131    * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
132    */
133   void InitializeRenderer();
134
135   /**
136    * @brief Create a shader for the object to use.
137    */
138   void CreateShader();
139
140   /**
141    * @brief Update shader related info, uniforms, etc. for the new shader.
142    */
143   void UpdateShaderUniforms();
144
145   /**
146    * @brief Use the object URL stored in the renderer to load and create the geometry of the object.
147    * @return Boolean of success of operation.
148    */
149   bool CreateGeometry();
150
151   /**
152    * @brief Use the object URL stored in the renderer to load the geometry of the object.
153    * @return Boolean of success of operation.
154    */
155   bool LoadGeometry();
156
157   /**
158    * @brief Use the material URL stored in the renderer to load the material of the object.
159    * @return Boolean of success of operation.
160    */
161   bool LoadMaterial();
162
163   /**
164    * @brief Use the image and texture URL components to load the different types of texture.
165    * @return Boolean of success of operation. Returns false if any texture fails to load from a url.
166    */
167   bool LoadTextures();
168
169 private:
170
171   // Undefined
172   MeshRenderer( const MeshRenderer& meshRenderer );
173
174   // Undefined
175   MeshRenderer& operator=( const MeshRenderer& meshRenderer );
176
177 private:
178
179   std::string mObjectUrl;
180   std::string mMaterialUrl;
181
182   std::string mDiffuseTextureUrl;
183   std::string mNormalTextureUrl;
184   std::string mGlossTextureUrl;
185   std::string mTexturesPath;
186
187   Shader mShader;
188   Geometry mGeometry;
189   TextureSet mTextureSet;
190
191   ObjLoader mObjLoader;
192   Vector3 mSceneCenter;
193   Vector3 mSceneSize;
194   ShaderType mShaderType;
195
196   bool mUseTexture;
197   bool mUseMipmapping;
198 };
199
200 } // namespace Internal
201
202 } // namespace Toolkit
203
204 } // namespace Dali
205
206 #endif /* __DALI_TOOLKIT_INTERNAL_MESH_RENDERER_H__ */