Merge "Remove scene graph property buffer" 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/internal/render/data-providers/render-data-provider.h>
26 #include <dali/integration-api/gl-abstraction.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 class RenderDataProvider;
44 class GeometryDataProvider;
45
46 /**
47  * This class encapsulates the GPU buffers. It is used to upload vertex data
48  * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
49  * bindings
50  */
51 class RenderGeometry
52 {
53 public:
54
55   /**
56    * Constructor. Creates a render geometry object with no GPU buffers.
57    */
58   RenderGeometry( const GeometryDataProvider& geometryDataProvider );
59
60   /**
61    * Destructor
62    */
63   ~RenderGeometry();
64
65   /**
66    * Called on Gl Context created
67    */
68   void GlContextCreated( Context& context );
69
70   /**
71    * Called on Gl Context destroyed.
72    */
73   void GlContextDestroyed();
74
75   /**
76    * Adds a property buffer to the geometry
77    * @param[in] dataProvider The PropertyBuffer data provider
78    * @param[in] isIndexBuffer True if the property buffer is intended to be used as an index buffer
79    */
80   void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer );
81
82   /**
83    * Removes a PropertyBuffer from the geometry
84    * @param[in] propertyBuffer The property buffer to be removed
85    */
86   void RemovePropertyBuffer(  const Render::PropertyBuffer* propertyBuffer );
87
88   /**
89    * Gets the attribute locations on the shader for the attributes defined in the geometry RenderBuffers
90    * @param[out] attributeLocation The vector where the attributes locations will be stored
91    * @param[in] program The program
92    * @param[in] bufferIndex The current buffer index
93    */
94   void GetAttributeLocationFromProgram( Vector<GLint>& attributeLocation, Program& program, BufferIndex bufferIndex ) const;
95
96   /**
97    * Called from RenderManager to notify the geometry that current rendering pass has finished.
98    */
99   void OnRenderFinished();
100
101   /**
102    * Chack if the attributes for the geometry have changed
103    * @return True if vertex buffers have been added or removed since last frame, false otherwise
104    */
105   bool AttributesChanged() const
106   {
107     return mAttributesChanged;
108   }
109
110   /**
111    * Upload the geometry if it has changed, set up the attributes and perform
112    * the Draw call corresponding to the geometry type
113    * @param[in] context The GL context
114    * @param[in] bufferIndex The current buffer index
115    * @param[in] attributeLocation The location for the attributes in the shader
116    */
117   void UploadAndDraw(Context& context,
118                      BufferIndex bufferIndex,
119                      Vector<GLint>& attributeLocation );
120
121 private:
122
123   const GeometryDataProvider& mGeometryDataProvider;  //Reference to update thread object
124
125   // PropertyBuffers
126   Render::PropertyBuffer* mIndexBuffer;
127   Vector<Render::PropertyBuffer*> mVertexBuffers;
128
129   // Booleans
130   bool mHasBeenUpdated : 1;
131   bool mAttributesChanged : 1;
132 };
133
134 } // namespace SceneGraph
135 } // namespace Internal
136 } // namespace Dali
137
138 #endif // DALI_INTERNAL_SCENE_GRAPH_SAMPLER_DATA_PROVIDER_H