Emscripten workarounds and llvm syntax fixes
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / scene-graph-mesh-renderer.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_MESH_RENDERER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_MESH_RENDERER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/internal/common/owner-pointer.h>
22 #include <dali/internal/render/renderers/render-material.h>
23 #include <dali/internal/render/renderers/scene-graph-renderer.h>
24 #include <dali/internal/update/modeling/bone-transforms.h>
25 #include <dali/internal/render/shaders/custom-uniform.h>
26 #include <dali/internal/event/effects/shader-declarations.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace SceneGraph
35 {
36
37 class RenderDataProvider;
38 struct BoneTransforms;
39 class LightController;
40 class RenderMaterial;
41 class Mesh;
42
43 /**
44  * An attachment for rendering a mesh with a material.
45  */
46 class MeshRenderer : public Renderer
47 {
48 public:
49
50   /**
51    * The information required to render a single mesh
52    */
53   struct MeshInfo
54   {
55     MeshInfo()
56     : mesh(NULL),
57       material(NULL),
58       boneTransforms()
59     {
60     }
61
62     Mesh*                 mesh;
63     RenderMaterial*       material;
64     BoneTransforms        boneTransforms; ///< Note, this is a std::vector. May be realloced in off-frame
65   };
66
67   /**
68    * Construct a new MeshRenderer.
69    * @param dataprovider to render
70    * @param lightController to get the light information
71    * @return The newly allocated MeshRenderer.
72    */
73   static MeshRenderer* New( RenderDataProvider& dataprovider, LightController& lightController );
74
75   /**
76    * Retrieve the mesh information for the next frame.
77    * This should only be accessed from the update-thread, using the current update buffer.
78    * @param[in] updateBufferIndex The current update buffer index.
79    */
80   MeshInfo& GetMeshInfo( BufferIndex updateBufferIndex )
81   {
82     return mMeshInfo[ updateBufferIndex ];
83   }
84
85   /**
86    * Called when the shader has changed; mCustomUniform should be reset.
87    */
88   void ResetCustomUniforms();
89
90   /**
91    * Set whether the renderer should be affected by scene lighting, or evenly lit
92    */
93   void SetAffectedByLighting( bool affectedByLighting );
94
95   /**
96    * Virtual destructor
97    */
98   virtual ~MeshRenderer();
99
100 private:
101
102   /**
103    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
104    */
105   virtual void GlCleanup();
106
107   /**
108    * @copydoc Dali::Internal::SceneGraph::Renderer::RequiresDepthTest()
109    */
110   virtual bool RequiresDepthTest() const;
111
112   /**
113    * @copydoc Dali::Internal::SceneGraph::Renderer::CheckResources()
114    */
115   virtual bool CheckResources();
116
117   /**
118    * @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
119    */
120   virtual void DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color );
121
122   /**
123    * Apply the view matrix to the bone transforms, and generate inverse transforms (for normal
124    * calculations)
125    * @param[inout] boneTransforms The bone transform matrices to update
126    * @param[in]    viewMatrix     The current view matrix
127    */
128   void ApplyViewToBoneTransforms( BoneTransforms& boneTransforms, const Matrix& viewMatrix );
129
130   /**
131    * Private constructor. See New()
132    */
133   MeshRenderer(RenderDataProvider& dataprovider);
134
135   // Undefined
136   MeshRenderer(const MeshRenderer&);
137
138   // Undefined
139   MeshRenderer& operator=(const MeshRenderer& rhs);
140
141 private:
142
143   MeshInfo         mMeshInfo[2];          ///< Double-buffered for update/render in separate threads.
144   LightController* mLightController;      ///< required to get the lights from the scene.
145   bool             mAffectedByLighting;   ///< Whether the scene lights should be used
146   GeometryType     mGeometryType;         ///< Records last geometry type
147   ShaderSubTypes   mShaderType;           ///< Records last shader type
148
149   static const unsigned int mNumberOfCustomUniforms = 13; // Number of uniforms needed for renderer
150   CustomUniform             mCustomUniform[SHADER_SUBTYPE_LAST][ mNumberOfCustomUniforms ];
151   RenderMaterialUniforms    mRenderMaterialUniforms; ///< Uniforms for render material
152
153 };
154
155 } // namespace SceneGraph
156
157 } // namespace Internal
158
159 } // namespace Dali
160
161 #endif // __DALI_INTERNAL_SCENE_GRAPH_MESH_RENDERER_H__