sculpto
buffer.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file buffer.h
3 * \brief Buffer interfaces definition module.
4 *
5 * \author Sabitov Kirill
6 * \date 26 June 2022
7 *********************************************************************/
8
9#pragma once
10
11#include "render_primitive.h"
12#include "../render_context.h"
14
15namespace scl
16{
18 enum class usage_type: u8
19 {
29 };
30
32 enum class buffer_type: u8
33 {
34 ARRAY,
37 };
38
40 class constant_buffer : public render_primitive
41 {
42 public:
44 virtual ~constant_buffer() = default;
45
46 /*!*
47 * Bind buffer to current render stage function.
48 *
49 * \param None.
50 * \return None.
51 */
52 virtual void Bind(u32 BindingPoint) const = 0;
53
54 /*!*
55 * Unbind buffer from current render stage function.
56 *
57 * \param None.
58 * \return None.
59 */
60 virtual void Unbind() const = 0;
61
62 /*!*
63 * Update buffer data function.
64 *
65 * \param Data - buffer data pointer.
66 * \param Size - buffer data size.
67 * \return None.
68 */
69 virtual void Update(void *Data, u32 Size) = 0;
70
71 /*!*
72 * Clear buffer from GPU memory function.
73 *
74 * \param None.
75 * \return None.
76 */
77 virtual void Free() = 0;
78
79 /*!*
80 * Create API specific empty constant buffer.
81 *
82 * \param BindingPoint - shader_props binding point of buffer.
83 * \param Size - buffer data size.
84 * \return constant buffer pointer.
85 */
87
88 /*!*
89 * Create API specific constant buffer filled with data.
90 *
91 * \param BindingPoint - shader_props binding point of buffer.
92 * \param Data - buffer data pointer.
93 * \param Size - buffer data size.
94 * \return constant buffer pointer.
95 */
96 static shared<constant_buffer> Create(const void *Data, u32 Size);
97 };
98
100 class vertex_buffer : public render_primitive
101 {
102 protected:
104
105 public:
108
109 public:
110 /*!*
111 * Vertex buffer default constructor.
112 *
113 * \param VertexLayout - layout of vertices in buffer.
114 */
116
118 virtual ~vertex_buffer() = default;
119
120 /*!*
121 * Bind buffer to current render stage function.
122 *
123 * \param None.
124 * \return None.
125 */
126 virtual void Bind() const = 0;
127
128 /*!*
129 * Unbind buffer from current render stage function.
130 *
131 * \param None.
132 * \return None.
133 */
134 virtual void Unbind() const = 0;
135
136 /*!*
137 * Update buffer data function.
138 *
139 * \param Vertices - verices array.
140 * \param Count - length of vertices array.
141 * \return None.
142 */
143 virtual void Update(const void *Vertices, u32 Count) = 0;
144
145 /*!*
146 * Clear buffer from GPU memory function.
147 *
148 * \param None.
149 * \return None.
150 */
151 virtual void Free() = 0;
152
153 /*!*
154 * Vertex biffer vertices count getter function.
155 *
156 * \param None.
157 * \return vertices count.
158 */
159 virtual u32 GetCount() const = 0;
160
161 /*!*
162 * Create API specific vertex buffer by vertices count.
163 *
164 * \param Count - vertices in buffer count.
165 * \param VertexLayout - layout of vertices in buffer.
166 * \return vertex buffer pointer.
167 */
169
170 /*!*
171 * Create API specific vertex buffer by vertices count and data.
172 *
173 * \param Vertices - vertices array.
174 * \param Count - vertices in buffer count.
175 * \param VertexLayout - layout of vertices in buffer.
176 * \return vertex buffer pointer.
177 */
178 static shared<vertex_buffer> Create(const void *Vertices, u32 Count, const vertex_layout &VertexLayout);
179 };
180
182 class index_buffer : public render_primitive
183 {
184 public:
186 virtual ~index_buffer() = default;
187
188 /*!*
189 * Bind buffer to current render stage function.
190 *
191 * \param None.
192 * \return None.
193 */
194 virtual void Bind() const = 0;
195
196 /*!*
197 * Unbind buffer from current render stage function.
198 *
199 * \param None.
200 * \return None.
201 */
202 virtual void Unbind() const = 0;
203
204 /*!*
205 * Clear buffer from GPU memory function.
206 *
207 * \param None.
208 * \return None.
209 */
210 virtual void Free() = 0;
211
212 /*!*
213 * Update buffer function function.
214 *
215 * \param Indices - array of indices.
216 * \param Count
217 */
218 virtual void Update(u32 *Indices, u32 Count) = 0;
219
220 /*!*
221 * Index biffer indices count getter function.
222 *
223 * \param None.
224 * \return indicies count.
225 */
226 virtual u32 GetCount() const = 0;
227
228 /*!*
229 * Create API specific index buffer by indices count and data.
230 *
231 * \param Indices - indices array.
232 * \param Count - indices in buffer count.
233 * \return vertex buffer pointer.
234 */
235 static shared<index_buffer> Create(u32 *Indices, u32 Count);
236 };
237}
static shared< constant_buffer > Create(u32 Size)
Definition: buffer.cpp:14
virtual void Update(void *Data, u32 Size)=0
virtual void Unbind() const =0
virtual void Free()=0
virtual ~constant_buffer()=default
virtual void Bind(u32 BindingPoint) const =0
virtual void Bind() const =0
virtual void Free()=0
virtual void Update(u32 *Indices, u32 Count)=0
virtual u32 GetCount() const =0
virtual void Unbind() const =0
virtual ~index_buffer()=default
static shared< index_buffer > Create(u32 *Indices, u32 Count)
Definition: buffer.cpp:65
virtual ~vertex_buffer()=default
virtual void Free()=0
static shared< vertex_buffer > Create(u32 Count, const vertex_layout &VertexLayout)
Definition: buffer.cpp:41
virtual void Update(const void *Vertices, u32 Count)=0
vertex_layout VertexLayout
Definition: buffer.h:103
virtual u32 GetCount() const =0
vertex_buffer(const vertex_layout &VertexLayout)
Definition: buffer.cpp:38
virtual void Bind() const =0
vertex_layout GetVertexLayout() const
Definition: buffer.h:107
virtual void Unbind() const =0
Definition: base.h:33
buffer_type
Definition: buffer.h:33
usage_type
Definition: buffer.h:19
std::shared_ptr< T > shared
Definition: smart_ptr.h:15
uint32_t u32
Definition: math_common.h:21
uint8_t u8
Definition: math_common.h:17
Render primitive abstract class definition module.
Vertex description and storage classes definition module.