009fafe6918d2ab69426a66267fb6ce1b54af191
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer-property-buffer.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_RENDERER_PROPERTY_BUFFER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_RENDERER_PROPERTY_BUFFER_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/integration-api/gl-abstraction.h>
21 #include <dali/internal/common/buffer-index.h>
22 #include <dali/internal/common/owner-container.h>
23 #include <dali/internal/common/owner-pointer.h>
24 #include <dali/internal/render/data-providers/property-buffer-data-provider.h>
25 #include <dali/internal/render/gl-resources/gpu-buffer.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class Context;
32 class Program;
33
34 namespace Render
35 {
36 class NewRenderer;
37 }
38
39 namespace SceneGraph
40 {
41
42 /**
43  * This class encapsulates the GPU buffers. It is used to upload vertex data
44  * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
45  * bindings
46  */
47 class RenderPropertyBuffer
48 {
49 public:
50   typedef OwnerContainer< GpuBuffer* > GpuBuffers;
51
52   /**
53    * Constructor. Creates a render geometry object with no GPU buffers.
54    * @param[in] propertyBufferDataProvider The property-buffer  data provider (to fetch geometry from)
55    * @param[in] gpuBufferTarget Type of target for the gpu-buffer
56    * @param[in] gpuBufferUsage Type of target for the gpu-buffer
57    */
58   RenderPropertyBuffer( const PropertyBufferDataProvider& propertyBufferDataProvider,
59                         GpuBuffer::Target gpuBufferTarget,
60                         GpuBuffer::Usage gpuBufferUsage );
61
62   /**
63    * Destructor
64    */
65   ~RenderPropertyBuffer();
66
67   /**
68    * Perform the upload of the buffer only when requiered
69    * @param[in] context The GL context
70    * @param[in] bufferIndex The current buffer index
71    */
72   void Update( Context& context, BufferIndex bufferIndex );
73
74   /**
75    * Bind the geometry buffers
76    * @param[in] context The GL context
77    */
78   void BindBuffer( Context& context );
79
80   /**
81    * Enable the vertex attributes for each vertex buffer from the corresponding
82    * shader program.
83    * @param[in] context The GL context
84    * @param[in] bufferIndex The current buffer index
85    * @param[in] program The shader program to query for attribute locations
86    * @param[in] vAttributeLocation Vector containing attributes location for current program
87    * @param[in] locationBase Index in vAttributeLocation corresponding to the first attribute defined by this buffer
88    */
89   unsigned int EnableVertexAttributes( Context& context, BufferIndex bufferIndex, Vector<GLint>& vAttributeLocation, unsigned int locationBase);
90
91   /**
92    * Get the data provider for the buffer
93    */
94   const PropertyBufferDataProvider& GetDataProvider() const
95   {
96     return mDataProvider;
97   }
98
99 private: // implementation
100
101   /**
102    * Update attribute locations
103    * @param[in] context The GL context
104    * @param[in] bufferIndex The current buffer index
105    * @param[in] program The shader program to query for attribute locations
106    */
107   void UpdateAttributeLocations( Context& context, BufferIndex bufferIndex, Program& program );
108
109 private:
110   const PropertyBufferDataProvider& mDataProvider;  ///< Data provider used by this property buffer
111   Vector<GLint> mAttributesLocation;                ///< Location of the attributes for the property buffer in this renderer.
112
113   OwnerPointer<GpuBuffer> mGpuBuffer;               ///< Pointer to the GpuBuffer associated with this RenderPropertyBuffer
114   GpuBuffer::Target mGpuBufferTarget;               ///< The type of GPU buffer to create
115   GpuBuffer::Usage mGpuBufferUsage;                 ///< The type of usage the  GPU buffer will have
116 };
117
118 } // namespace SceneGraph
119 } // namespace Internal
120 } // namespace Dali
121
122 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_RENDERER_PROPERTY_BUFFER_H