PropertyBuffer Attributes.
[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                          BufferIndex bufferIndex,
97                          const RenderDataProvider* dataProviders );
98
99 private:
100   /**
101    * Perform the upload of the geometry
102    * @param[in] context The GL context
103    * @param[in] bufferIndex The current buffer index
104    * @param[in] dataProviders The data providers (to fetch geometry from)
105    */
106   void DoUpload( Context& context,
107                  BufferIndex bufferIndex,
108                  const RenderDataProvider* dataProviders );
109
110   /**
111    * Bind the geometry buffers
112    * @param[in] context The GL context
113    * @param[in] bufferIndex The current buffer index
114    * @param[in] program The shader program to query for attribute locations
115    */
116   void BindBuffers( Context& context,
117                     BufferIndex bufferIndex,
118                     Program& program );
119
120   /**
121    * Enable the vertex attributes for each vertex buffer from the corresponding
122    * shader program.
123    * @param[in] context The GL context
124    * @param[in] bufferIndex The current buffer index
125    * @param[in] program The shader program to query for attribute locations
126    */
127   void EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& progam );
128
129   /**
130    * Disable the vertex attributes for each vertex buffer from the corresponding
131    * shader program.
132    * @param[in] context The GL context
133    * @param[in] bufferIndex The current buffer index
134    * @param[in] program The shader program to query for attribute locations
135    */
136   void DisableVertexAttributes( Context& context, BufferIndex bufferIndex, Program& program );
137
138   /**
139    * Perform the correct draw call corresponding to the geometry type
140    * @param[in] context The GL context
141    * @param[in] bufferIndex The current buffer index
142    * @param[in] dataProviders The data providers (to fetch geometry from)
143    */
144   void Draw( Context& context,
145              BufferIndex bufferIndex,
146              const RenderDataProvider* dataProviders );
147
148 private:
149   // PropertyBuffers
150   OwnerPointer< RenderPropertyBuffer > mIndexBuffer;
151   OwnerContainer< RenderPropertyBuffer* > mVertexBuffers;
152
153   // Booleans
154   bool mDataNeedsUploading;
155   bool mShaderChanged;
156 };
157
158 } // namespace SceneGraph
159 } // namespace Internal
160 } // namespace Dali
161
162 #endif // DALI_INTERNAL_SCENE_GRAPH_SAMPLER_DATA_PROVIDER_H