Merge "Path registration with type registry" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-geometry.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_GEOMETRY_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_GEOMETRY_H
3
4 /*
5  * Copyright (c) 2015 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 #include <dali/public-api/common/dali-vector.h>
21 #include <dali/devel-api/common/owner-container.h>
22 #include <dali/integration-api/gl-defines.h>
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/common/owner-pointer.h>
25 #include <dali/integration-api/gl-abstraction.h>
26 #include <dali/internal/update/rendering/scene-graph-geometry.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 class Context;
33 class Program;
34 class GpuBuffer;
35
36 namespace Render
37 {
38 class PropertyBuffer;
39 }
40
41 namespace SceneGraph
42 {
43
44 /**
45  * This class encapsulates the GPU buffers. It is used to upload vertex data
46  * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
47  * bindings
48  */
49 class RenderGeometry
50 {
51 public:
52
53   typedef SceneGraph::Geometry::GeometryType GeometryType;
54   /**
55    * Constructor. Creates a render geometry object with no GPU buffers.
56    * @param[in] center The center of the geometry
57    * @param[in] geometryType The geometry type
58    * @param[in] requiresDepthTest True if geometry requires depth testing, false otherwise
59    */
60   RenderGeometry( GeometryType geometryType, bool requiresDepthTest );
61   /**
62    * Destructor
63    */
64   ~RenderGeometry();
65
66   /**
67    * Called on Gl Context created
68    */
69   void GlContextCreated( Context& context );
70
71   /**
72    * Called on Gl Context destroyed.
73    */
74   void GlContextDestroyed();
75
76   /**
77    * Adds a property buffer to the geometry
78    * @param[in] dataProvider The PropertyBuffer data provider
79    * @param[in] isIndexBuffer True if the property buffer is intended to be used as an index buffer
80    */
81   void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer );
82
83   /**
84    * Removes a PropertyBuffer from the geometry
85    * @param[in] propertyBuffer The property buffer to be removed
86    */
87   void RemovePropertyBuffer(  const Render::PropertyBuffer* propertyBuffer );
88
89   /**
90    * Gets the attribute locations on the shader for the attributes defined in the geometry RenderBuffers
91    * @param[out] attributeLocation The vector where the attributes locations will be stored
92    * @param[in] program The program
93    * @param[in] bufferIndex The current buffer index
94    */
95   void GetAttributeLocationFromProgram( Vector<GLint>& attributeLocation, Program& program, BufferIndex bufferIndex ) const;
96
97   /**
98    * Called from RenderManager to notify the geometry that current rendering pass has finished.
99    */
100   void OnRenderFinished();
101
102   /**
103    * Chack if the attributes for the geometry have changed
104    * @return True if vertex buffers have been added or removed since last frame, false otherwise
105    */
106   bool AttributesChanged() const
107   {
108     return mAttributesChanged;
109   }
110
111   /**
112    * Sets the geometry type
113    * @param[in] type The new geometry type
114    */
115   void SetGeometryType( GeometryType type )
116   {
117     mGeometryType = type;
118   }
119
120   /**
121    * Sets if the geometry requires depth testing
122    * @param[in] requiresDepthTest True if depth testing is required, false otherwise
123    */
124   void SetRequiresDepthTest( bool requiresDepthTest )
125   {
126     mRequiresDepthTest = requiresDepthTest;
127   }
128
129   /**
130    * Check if geometry requires depth testing
131    * @return True if depth testing is required, false otherwise
132    */
133   bool RequiresDepthTest() const
134   {
135     return mRequiresDepthTest;
136   }
137
138   /**
139    * Upload the geometry if it has changed, set up the attributes and perform
140    * the Draw call corresponding to the geometry type
141    * @param[in] context The GL context
142    * @param[in] bufferIndex The current buffer index
143    * @param[in] attributeLocation The location for the attributes in the shader
144    */
145   void UploadAndDraw(Context& context,
146                      BufferIndex bufferIndex,
147                      Vector<GLint>& attributeLocation );
148
149 private:
150
151   // PropertyBuffers
152   Render::PropertyBuffer* mIndexBuffer;
153   Vector<Render::PropertyBuffer*> mVertexBuffers;
154
155   GeometryType  mGeometryType;
156
157   // Booleans
158   bool mRequiresDepthTest : 1;
159   bool mHasBeenUpdated : 1;
160   bool mAttributesChanged : 1;
161
162 };
163
164 } // namespace SceneGraph
165 } // namespace Internal
166 } // namespace Dali
167
168 #endif // DALI_INTERNAL_SCENE_GRAPH_SAMPLER_DATA_PROVIDER_H