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