Changed passing of data providers to renderers
[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/internal/common/buffer-index.h>
21 #include <dali/internal/common/owner-container.h>
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/render/data-providers/render-data-provider.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 class Context;
30 class Program;
31 class GpuBuffer;
32
33 namespace SceneGraph
34 {
35 class RenderDataProvider;
36 class GeometryDataProvider;
37
38 /**
39  * This class encapsulates the GPU buffers. It is used to upload vertex data
40  * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
41  * bindings
42  */
43 class RenderGeometry
44 {
45 public:
46   typedef OwnerContainer< GpuBuffer* > GpuBuffers;
47
48   /**
49    * Constructor. Creates a render geometry object with no GPU buffers.
50    */
51   RenderGeometry( );
52
53   /**
54    * Destructor
55    */
56   ~RenderGeometry();
57
58   /**
59    * Called on Gl Context created
60    */
61   void GlContextCreated( Context& context );
62
63   /**
64    * Called on Gl Context destroyed.
65    */
66   void GlContextDestroyed();
67
68   /**
69    * Upload the geometry if it has changed, set up the attributes and perform
70    * the Draw call corresponding to the geometry type
71    * @param[in] context The GL context
72    * @param[in] program The shader program to query for attribute locations
73    * @param[in] bufferIndex The current buffer index
74    * @param[in] dataProviders The data providers (to fetch geometry from)
75    */
76   void UploadAndDraw(Context& context,
77                      Program& program,
78                      BufferIndex bufferIndex,
79                      const RenderDataProvider* dataProviders );
80
81   /**
82    * Tell the object that the geometry has been updated.
83    * It will be uploaded on the next UploadAndDraw call.
84    */
85   void GeometryUpdated();
86
87   /**
88    * Upload the vertex data if it needs uploading.
89    * @param[in] context The GL context
90    * @param[in] bufferIndex The current buffer index
91    * @param[in] geometryDataProvider The geometry data provider (to fetch geometry from)
92    */
93   void UploadVertexData( Context& context,
94                          BufferIndex bufferIndex,
95                          const RenderDataProvider* dataProviders );
96
97 private:
98   /**
99    * Perform the upload of the geometry
100    * @param[in] context The GL context
101    * @param[in] bufferIndex The current buffer index
102    * @param[in] dataProviders The data providers (to fetch geometry from)
103    */
104   void DoUpload( Context& context,
105                  BufferIndex bufferIndex,
106                  const RenderDataProvider* dataProviders );
107
108   /**
109    * Bind the geometry buffers
110    */
111   void BindBuffers();
112
113   /**
114    * Enable the vertex attributes for each vertex buffer from the corresponding
115    * shader program.
116    * @param[in] context The GL context
117    * @param[in] program The shader program to query for attribute locations
118    */
119   void EnableVertexAttributes( Context& context, Program& progam );
120
121   /**
122    * Disable the vertex attributes for each vertex buffer from the corresponding
123    * shader program.
124    * @param[in] context The GL context
125    * @param[in] program The shader program to query for attribute locations
126    */
127   void DisableVertexAttributes( Context& context, Program& program );
128
129   /**
130    * Perform the correct draw call corresponding to the geometry type
131    * @param[in] context The GL context
132    * @param[in] bufferIndex The current buffer index
133    * @param[in] dataProviders The data providers (to fetch geometry from)
134    */
135   void Draw( Context& context,
136              BufferIndex bufferIndex,
137              const RenderDataProvider* dataProviders );
138
139 private:
140   GpuBuffers mVertexBuffers;
141   OwnerPointer< GpuBuffer > mIndexBuffer;
142
143   bool mDataNeedsUploading;
144 };
145
146 } // namespace SceneGraph
147 } // namespace Internal
148 } // namespace Dali
149
150 #endif // DALI_INTERNAL_SCENE_GRAPH_SAMPLER_DATA_PROVIDER_H