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