SFML 3.0.1
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-2025 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
30#include <SFML/Graphics/Export.hpp>
31
32#include <SFML/Graphics/Drawable.hpp>
33#include <SFML/Graphics/PrimitiveType.hpp>
34#include <SFML/Graphics/RenderStates.hpp>
35
36#include <SFML/Window/GlResource.hpp>
37
38#include <cstddef>
39
40
41 namespace sf
42{
43 class RenderTarget;
44 struct Vertex;
45
50 class SFML_GRAPHICS_API VertexBuffer : public Drawable, private GlResource
51{
52 public:
63 enum class Usage
64 {
65 Stream,
66 Dynamic,
67 Static
68 };
69
76 VertexBuffer() = default;
77
86 explicit VertexBuffer(PrimitiveType type);
87
96 explicit VertexBuffer(Usage usage);
97
108 VertexBuffer(PrimitiveType type, Usage usage);
109
116 VertexBuffer(const VertexBuffer& copy);
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
221 VertexBuffer& operator=(const VertexBuffer& right);
222
229 void swap(VertexBuffer& right) noexcept;
230
241 [[nodiscard]] unsigned int getNativeHandle() const;
242
254 void setPrimitiveType(PrimitiveType type);
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
324 private:
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
350 SFML_GRAPHICS_API void swap(VertexBuffer& left, VertexBuffer& right) noexcept;
351
352} // namespace sf
353
354
Drawable.hpp
GlResource.hpp
Export.hpp
SFML_GRAPHICS_API
#define SFML_GRAPHICS_API
Definition Graphics/Export.hpp:42
PrimitiveType.hpp
RenderStates.hpp
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
sf::Drawable::RenderTarget
friend class RenderTarget
Definition Drawable.hpp:53
sf::GlResource::GlResource
GlResource()
Default constructor.
sf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition RenderTarget.hpp:63
sf::VertexBuffer
Vertex buffer storage for one or more 2D primitives.
Definition VertexBuffer.hpp:51
sf::VertexBuffer::getPrimitiveType
PrimitiveType getPrimitiveType() const
Get the type of primitives drawn by the vertex buffer.
sf::VertexBuffer::bind
static void bind(const VertexBuffer *vertexBuffer)
Bind a vertex buffer for rendering.
sf::VertexBuffer::~VertexBuffer
~VertexBuffer() override
Destructor.
sf::VertexBuffer::VertexBuffer
VertexBuffer(const VertexBuffer &copy)
Copy constructor.
sf::VertexBuffer::VertexBuffer
VertexBuffer(PrimitiveType type, Usage usage)
Construct a VertexBuffer with a specific PrimitiveType and usage specifier.
sf::VertexBuffer::getNativeHandle
unsigned int getNativeHandle() const
Get the underlying OpenGL handle of the vertex buffer.
sf::VertexBuffer::Usage
Usage
Usage specifiers.
Definition VertexBuffer.hpp:64
sf::VertexBuffer::Usage::Static
@ Static
Rarely changing data.
Definition VertexBuffer.hpp:67
sf::VertexBuffer::Usage::Dynamic
@ Dynamic
Occasionally changing data.
Definition VertexBuffer.hpp:66
sf::VertexBuffer::Usage::Stream
@ Stream
Constantly changing data.
Definition VertexBuffer.hpp:65
sf::VertexBuffer::VertexBuffer
VertexBuffer(PrimitiveType type)
Construct a VertexBuffer with a specific PrimitiveType
sf::VertexBuffer::update
bool update(const VertexBuffer &vertexBuffer)
Copy the contents of another buffer into this buffer.
sf::VertexBuffer::getUsage
Usage getUsage() const
Get the usage specifier of this vertex buffer.
sf::VertexBuffer::isAvailable
static bool isAvailable()
Tell whether or not the system supports vertex buffers.
sf::VertexBuffer::getVertexCount
std::size_t getVertexCount() const
Return the vertex count.
sf::VertexBuffer::setPrimitiveType
void setPrimitiveType(PrimitiveType type)
Set the type of primitives to draw.
sf::VertexBuffer::VertexBuffer
VertexBuffer()=default
Default constructor.
sf::VertexBuffer::create
bool create(std::size_t vertexCount)
Create the vertex buffer.
sf::VertexBuffer::setUsage
void setUsage(Usage usage)
Set the usage specifier of this vertex buffer.
sf::VertexBuffer::update
bool update(const Vertex *vertices)
Update the whole buffer from an array of vertices.
sf::VertexBuffer::update
bool update(const Vertex *vertices, std::size_t vertexCount, unsigned int offset)
Update a part of the buffer from an array of vertices.
sf::VertexBuffer::operator=
VertexBuffer & operator=(const VertexBuffer &right)
Overload of assignment operator.
sf::VertexBuffer::VertexBuffer
VertexBuffer(Usage usage)
Construct a VertexBuffer with a specific usage specifier.
sf::VertexBuffer::swap
void swap(VertexBuffer &right) noexcept
Swap the contents of this vertex buffer with those of another.
sf::PrimitiveType
PrimitiveType
Types of primitives that a sf::VertexArray can render.
Definition PrimitiveType.hpp:39
sf
Definition AudioResource.hpp:36
sf::swap
void swap(Texture &left, Texture &right) noexcept
Swap the contents of one texture with those of another.
sf::RenderStates
Define the states used for drawing to a RenderTarget
Definition RenderStates.hpp:48
sf::Vertex
Point with color and texture coordinates.
Definition Vertex.hpp:44