Fixes an issue when element buffer count is 0 in render-geometry.
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-geometry.h
1 #ifndef DALI_INTERNAL_RENDER_GEOMETRY_H
2 #define DALI_INTERNAL_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/devel-api/common/owner-container.h>
22 #include <dali/devel-api/rendering/geometry.h>
23 #include <dali/internal/common/owner-pointer.h>
24 #include <dali/integration-api/gl-defines.h>
25 #include <dali/internal/common/buffer-index.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/integration-api/gl-abstraction.h>
28 #include <dali/devel-api/rendering/geometry.h>
29
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35 class Context;
36 class Program;
37 class GpuBuffer;
38
39 namespace Render
40 {
41 class PropertyBuffer;
42
43 /**
44  * This class encapsulates the GPU buffers. It is used to upload vertex data
45  * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
46  * bindings
47  */
48 class Geometry
49 {
50 public:
51   typedef Dali::Geometry::GeometryType GeometryType;
52
53   Geometry();
54
55   /**
56    * Destructor
57    */
58   ~Geometry();
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    * Adds a property buffer to the geometry
72    * @param[in] dataProvider The PropertyBuffer data provider
73    */
74   void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer );
75
76   /**
77    * Set the data for the index buffer to be used by the geometry
78    * @param[in] indices A vector containing the indices
79    */
80   void SetIndexBuffer( Dali::Vector<unsigned short>& indices );
81
82   /**
83    * Removes a PropertyBuffer from the geometry
84    * @param[in] propertyBuffer The property buffer to be removed
85    */
86   void RemovePropertyBuffer(  const Render::PropertyBuffer* propertyBuffer );
87
88   /**
89    * Gets the attribute locations on the shader for the attributes defined in the geometry RenderBuffers
90    * @param[out] attributeLocation The vector where the attributes locations will be stored
91    * @param[in] program The program
92    * @param[in] bufferIndex The current buffer index
93    */
94   void GetAttributeLocationFromProgram( Vector<GLint>& attributeLocation, Program& program, BufferIndex bufferIndex ) const;
95
96   /**
97    * Called from RenderManager to notify the geometry that current rendering pass has finished.
98    */
99   void OnRenderFinished();
100
101   /**
102    * Chack if the attributes for the geometry have changed
103    * @return True if vertex buffers have been added or removed since last frame, false otherwise
104    */
105   bool AttributesChanged() const
106   {
107     return mAttributesChanged;
108   }
109
110   /**
111    * Sets the geometry type
112    * @param[in] type The new geometry type
113    */
114   void SetGeometryType( GeometryType type )
115   {
116     mGeometryType = type;
117   }
118
119   /**
120    * Upload the geometry if it has changed, set up the attributes and perform
121    * the Draw call corresponding to the geometry type
122    * @param[in] context The GL context
123    * @param[in] bufferIndex The current buffer index
124    * @param[in] attributeLocation The location for the attributes in the shader
125    * @param[in] elementBufferOffset The index of first element to draw if index buffer bound
126    * @param[in] elementBufferCount Number of elements to draw if index buffer bound, uses whole buffer when 0
127    */
128   void UploadAndDraw(Context& context,
129                      BufferIndex bufferIndex,
130                      Vector<GLint>& attributeLocation,
131                      size_t elementBufferOffset,
132                      size_t elementBufferCount );
133
134 private:
135
136   // PropertyBuffers
137   Vector< Render::PropertyBuffer* > mVertexBuffers;
138
139   Dali::Vector< unsigned short> mIndices;
140   OwnerPointer< GpuBuffer > mIndexBuffer;
141   GeometryType mGeometryType;
142
143   // Booleans
144   bool mIndicesChanged : 1;
145   bool mHasBeenUpdated : 1;
146   bool mAttributesChanged : 1;
147
148 };
149
150 } // namespace Render
151 } // namespace Internal
152 } // namespace Dali
153
154 #endif // DALI_INTERNAL_RENDER_GEOMETRY_H