Loading...
Searching...
No Matches
VertexBuffer.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
31
35
37
38#include <cstddef>
39
40
41namespace sf
42{
43class RenderTarget;
44struct Vertex;
45
51{
52public:
63 enum class Usage
64 {
65 Stream,
66 Dynamic,
67 Static
68 };
69
76 VertexBuffer() = default;
77
87
96 explicit VertexBuffer(Usage usage);
97
109
117
122 ~VertexBuffer() override;
123
140 [[nodiscard]] bool create(std::size_t vertexCount);
141
148 [[nodiscard]] std::size_t getVertexCount() const;
149
168 [[nodiscard]] bool update(const Vertex* vertices);
169
201 [[nodiscard]] bool update(const Vertex* vertices, std::size_t vertexCount, unsigned int offset);
202
211 [[nodiscard]] bool update(const VertexBuffer& vertexBuffer);
212
222
229 void swap(VertexBuffer& right) noexcept;
230
241 [[nodiscard]] unsigned int getNativeHandle() const;
242
255
262 [[nodiscard]] PrimitiveType getPrimitiveType() const;
263
279 void setUsage(Usage usage);
280
287 [[nodiscard]] Usage getUsage() const;
288
310 static void bind(const VertexBuffer* vertexBuffer);
311
322 [[nodiscard]] static bool isAvailable();
323
324private:
332 void draw(RenderTarget& target, RenderStates states) const override;
333
335 // Member data
337 unsigned int m_buffer{};
338 std::size_t m_size{};
339 PrimitiveType m_primitiveType{PrimitiveType::Points};
340 Usage m_usage{Usage::Stream};
341};
342
350SFML_GRAPHICS_API void swap(VertexBuffer& left, VertexBuffer& right) noexcept;
351
352} // namespace sf
353
354
#define SFML_GRAPHICS_API
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
Base class for classes that require an OpenGL context.
Base class for all render targets (window, texture, ...)
Vertex buffer storage for one or more 2D primitives.
PrimitiveType getPrimitiveType() const
Get the type of primitives drawn by the vertex buffer.
static void bind(const VertexBuffer *vertexBuffer)
Bind a vertex buffer for rendering.
~VertexBuffer() override
Destructor.
VertexBuffer(const VertexBuffer &copy)
Copy constructor.
VertexBuffer(PrimitiveType type, Usage usage)
Construct a VertexBuffer with a specific PrimitiveType and usage specifier.
unsigned int getNativeHandle() const
Get the underlying OpenGL handle of the vertex buffer.
Usage
Usage specifiers.
VertexBuffer(PrimitiveType type)
Construct a VertexBuffer with a specific PrimitiveType
bool update(const VertexBuffer &vertexBuffer)
Copy the contents of another buffer into this buffer.
Usage getUsage() const
Get the usage specifier of this vertex buffer.
static bool isAvailable()
Tell whether or not the system supports vertex buffers.
std::size_t getVertexCount() const
Return the vertex count.
void setPrimitiveType(PrimitiveType type)
Set the type of primitives to draw.
VertexBuffer()=default
Default constructor.
bool create(std::size_t vertexCount)
Create the vertex buffer.
void setUsage(Usage usage)
Set the usage specifier of this vertex buffer.
bool update(const Vertex *vertices)
Update the whole buffer from an array of vertices.
bool update(const Vertex *vertices, std::size_t vertexCount, unsigned int offset)
Update a part of the buffer from an array of vertices.
VertexBuffer & operator=(const VertexBuffer &right)
Overload of assignment operator.
VertexBuffer(Usage usage)
Construct a VertexBuffer with a specific usage specifier.
void swap(VertexBuffer &right) noexcept
Swap the contents of this vertex buffer with those of another.
PrimitiveType
Types of primitives that a sf::VertexArray can render.
void swap(Texture &left, Texture &right) noexcept
Swap the contents of one texture with those of another.
Define the states used for drawing to a RenderTarget
Point with color and texture coordinates.
Definition Vertex.hpp:44