Documentation of SFML 2.6.2

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
Loading...
Searching...
No Matches
VertexBuffer.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 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#ifndef SFML_VERTEXBUFFER_HPP
26#define SFML_VERTEXBUFFER_HPP
27
29// Headers
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/PrimitiveType.hpp>
33#include <SFML/Graphics/Drawable.hpp>
34#include <SFML/Window/GlResource.hpp>
35
36
37namespace sf
38{
39class RenderTarget;
40class Vertex;
41
46class SFML_GRAPHICS_API VertexBuffer : public Drawable, private GlResource
47{
48public:
49
60 enum Usage
61 {
64 Static
65 };
66
74
84
93 explicit VertexBuffer(Usage usage);
94
106
114
120
137 bool create(std::size_t vertexCount);
138
145 std::size_t getVertexCount() const;
146
165 bool update(const Vertex* vertices);
166
198 bool update(const Vertex* vertices, std::size_t vertexCount, unsigned int offset);
199
208 bool update(const VertexBuffer& vertexBuffer);
209
218 VertexBuffer& operator =(const VertexBuffer& right);
219
226 void swap(VertexBuffer& right);
227
238 unsigned int getNativeHandle() const;
239
252
260
276 void setUsage(Usage usage);
277
285
307 static void bind(const VertexBuffer* vertexBuffer);
308
319 static bool isAvailable();
320
321private:
322
330 virtual void draw(RenderTarget& target, RenderStates states) const;
331
332private:
333
335 // Member data
337 unsigned int m_buffer;
338 std::size_t m_size;
339 PrimitiveType m_primitiveType;
340 Usage m_usage;
341};
342
343} // namespace sf
344
345
346#endif // SFML_VERTEXBUFFER_HPP
347
348
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:45
Base class for classes that require an OpenGL context.
Define the states used for drawing to a RenderTarget.
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(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.
void swap(VertexBuffer &right)
Swap the contents of this vertex buffer with those of another.
Usage
Usage specifiers.
@ Dynamic
Occasionally changing data.
@ Stream
Constantly changing data.
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.
bool create(std::size_t vertexCount)
Create the vertex buffer.
VertexBuffer()
Default constructor.
void setUsage(Usage usage)
Set the usage specifier of this vertex buffer.
~VertexBuffer()
Destructor.
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(Usage usage)
Construct a VertexBuffer with a specific usage specifier.
Define a point with color and texture coordinates.
Definition Vertex.hpp:43
PrimitiveType
Types of primitives that a sf::VertexArray can render.