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