Loading...
Searching...
No Matches
VertexArray.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2026 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
37
38#include <vector>
39
40#include <cstddef>
41
42
43namespace sf
44{
45class RenderTarget;
46
52{
53public:
60 VertexArray() = default;
61
69 explicit VertexArray(PrimitiveType type, std::size_t vertexCount = 0);
70
77 [[nodiscard]] std::size_t getVertexCount() const;
78
93 [[nodiscard]] Vertex& operator[](std::size_t index);
94
109 [[nodiscard]] const Vertex& operator[](std::size_t index) const;
110
120 void clear();
121
134 void resize(std::size_t vertexCount);
135
142 void append(const Vertex& vertex);
143
158
165 [[nodiscard]] PrimitiveType getPrimitiveType() const;
166
176 [[nodiscard]] FloatRect getBounds() const;
177
186 [[nodiscard]] std::vector<Vertex>::iterator begin();
187
196 [[nodiscard]] std::vector<Vertex>::const_iterator begin() const;
197
210 [[nodiscard]] std::vector<Vertex>::iterator end();
211
224 [[nodiscard]] std::vector<Vertex>::const_iterator end() const;
225
226private:
234 void draw(RenderTarget& target, RenderStates states) const override;
235
237 // Member data
239 std::vector<Vertex> m_vertices;
240 PrimitiveType m_primitiveType{PrimitiveType::Points};
241};
242
243} // namespace sf
244
245
#define SFML_GRAPHICS_API
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
friend class RenderTarget
Definition Drawable.hpp:53
Base class for all render targets (window, texture, ...).
std::vector< Vertex >::iterator begin()
Return an iterator to the beginning of the array.
void resize(std::size_t vertexCount)
Resize the vertex array.
void clear()
Clear the vertex array.
VertexArray(PrimitiveType type, std::size_t vertexCount=0)
Construct the vertex array with a type and an initial number of vertices.
std::vector< Vertex >::iterator end()
Return an iterator to the end of the array.
void append(const Vertex &vertex)
Add a vertex to the array.
const Vertex & operator[](std::size_t index) const
Get a read-only access to a vertex by its index.
Vertex & operator[](std::size_t index)
Get a read-write access to a vertex by its index.
PrimitiveType getPrimitiveType() const
Get the type of primitives drawn by the vertex array.
void setPrimitiveType(PrimitiveType type)
Set the type of primitives to draw.
FloatRect getBounds() const
Compute the bounding rectangle of the vertex array.
std::size_t getVertexCount() const
Return the vertex count.
std::vector< Vertex >::const_iterator begin() const
Return an iterator to the beginning of the array.
VertexArray()=default
Default constructor.
std::vector< Vertex >::const_iterator end() const
Return an iterator to the end of the array.
PrimitiveType
Types of primitives that a sf::VertexArray can render.
@ Points
List of individual points.
Rect< float > FloatRect
Definition Rect.hpp:147
Define the states used for drawing to a RenderTarget.
Point with color and texture coordinates.
Definition Vertex.hpp:44