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