Removing some uses of gl Context object
[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) 2021 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 // INTERNAL INCLUDES
21 #include <dali/devel-api/common/owner-container.h>
22 #include <dali/graphics-api/graphics-controller.h>
23 #include <dali/integration-api/gl-abstraction.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/public-api/common/dali-vector.h>
28 #include <dali/public-api/rendering/geometry.h>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 class Context;
35 class Program;
36 class GpuBuffer;
37
38 namespace Render
39 {
40 class VertexBuffer;
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 Geometry
48 {
49 public:
50   using Type = Dali::Geometry::Type;
51
52   Geometry();
53
54   /**
55    * Destructor
56    */
57   ~Geometry();
58
59   /**
60    * Adds a property buffer to the geometry
61    * @param[in] dataProvider The VertexBuffer data provider
62    */
63   void AddVertexBuffer(Render::VertexBuffer* vertexBuffer);
64
65   /**
66    * Set the data for the index buffer to be used by the geometry
67    * @param[in] indices A vector containing the indices
68    */
69   void SetIndexBuffer(Dali::Vector<uint16_t>& indices);
70
71   /**
72    * Removes a VertexBuffer from the geometry
73    * @param[in] vertexBuffer The property buffer to be removed
74    */
75   void RemoveVertexBuffer(const Render::VertexBuffer* vertexBuffer);
76
77   /**
78    * Get the vertex buffers
79    * @return the list of vertex buffers
80    */
81   const Vector<Render::VertexBuffer*>& GetVertexBuffers() const;
82
83   /**
84    * Called from RenderManager to notify the geometry that current rendering pass has finished.
85    */
86   void OnRenderFinished();
87
88   /**
89    * Check if the attributes for the geometry have changed
90    * @return True if vertex buffers have been added or removed since last frame, false otherwise
91    */
92   bool AttributesChanged() const
93   {
94     return mAttributesChanged;
95   }
96
97   /**
98    * Sets the geometry type
99    * @param[in] type The new geometry type
100    */
101   void SetType(Type type)
102   {
103     mGeometryType = type;
104   }
105
106   /**
107    * @return the topology of this geometry
108    */
109   Graphics::PrimitiveTopology GetTopology() const;
110
111   /**
112    * Upload the geometry if it has changed
113    */
114   void Upload(Graphics::Controller& graphicsController);
115
116   /**
117    * Set up the attributes and perform the Draw call corresponding to the geometry type.
118    *
119    * @param[in] context The GL context @todo remove
120    * @param[in] graphicsController The graphics controller
121    * @param[in] bufferIndex The current buffer index
122    * @param[in] attributeLocation The location for the attributes in the shader
123    * @param[in] elementBufferOffset The index of first element to draw if index buffer bound
124    * @param[in] elementBufferCount Number of elements to draw if index buffer bound, uses whole buffer when 0
125    * @return true if the draw command was issued, false otherwise
126    */
127   bool Draw(Graphics::Controller&    graphicsController,
128             Graphics::CommandBuffer& commandBuffer,
129             uint32_t                 elementBufferOffset,
130             uint32_t                 elementBufferCount);
131
132 private:
133   // VertexBuffers
134   Vector<Render::VertexBuffer*> mVertexBuffers;
135
136   Dali::Vector<uint16_t>  mIndices;
137   OwnerPointer<GpuBuffer> mIndexBuffer;
138   Type                    mGeometryType;
139
140   // Booleans
141   bool mIndicesChanged : 1;
142   bool mHasBeenUpdated : 1;
143   bool mAttributesChanged : 1;
144 };
145
146 } // namespace Render
147 } // namespace Internal
148 } // namespace Dali
149
150 #endif // DALI_INTERNAL_RENDER_GEOMETRY_H