VertexArray.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
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 CPP3DS_VERTEXARRAY_HPP
26 #define CPP3DS_VERTEXARRAY_HPP
27 
29 // Headers
31 #include <cpp3ds/Graphics/Vertex.hpp>
32 #include <cpp3ds/Graphics/PrimitiveType.hpp>
33 #include <cpp3ds/Graphics/Rect.hpp>
34 #include <cpp3ds/Graphics/Drawable.hpp>
35 #ifndef EMULATION
36 #include <cpp3ds/System/LinearAllocator.hpp>
37 #endif
38 #include <vector>
39 
40 
41 namespace cpp3ds
42 {
47 class VertexArray : public Drawable
48 {
49 public :
50 
57  VertexArray();
58 
66  explicit VertexArray(PrimitiveType type, unsigned int vertexCount = 0);
67 
74  unsigned int getVertexCount() const;
75 
90  Vertex& operator [](unsigned int index);
91 
106  const Vertex& operator [](unsigned int index) const;
107 
117  void clear();
118 
131  void resize(unsigned int vertexCount);
132 
139  void append(const Vertex& vertex);
140 
155  void setPrimitiveType(PrimitiveType type);
156 
164 
174  FloatRect getBounds() const;
175 
176 private :
177 
185  virtual void draw(RenderTarget& target, RenderStates states) const;
186 
187 private:
188 
190  // Member data
192  #ifdef EMULATION
193  std::vector<Vertex> m_vertices;
194  #else
195  std::vector<Vertex, LinearAllocator<Vertex>> m_vertices;
196  #endif
197  PrimitiveType m_primitiveType;
198 };
199 
200 }
201 
202 
203 #endif
204 
205 
void setPrimitiveType(PrimitiveType type)
Set the type of primitives to draw.
VertexArray()
Default constructor.
void append(const Vertex &vertex)
Add a vertex to the array.
Define a set of one or more 2D primitives.
Definition: VertexArray.hpp:47
PrimitiveType getPrimitiveType() const
Get the type of primitives drawn by the vertex array.
Define a point with color and texture coordinates.
Definition: Vertex.hpp:41
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:43
FloatRect getBounds() const
Compute the bounding rectangle of the vertex array.
Base class for all render targets (window, texture, ...)
void clear()
Clear the vertex array.
Define the states used for drawing to a RenderTarget.
PrimitiveType
Types of primitives that a cpp3ds::VertexArray can render.
void resize(unsigned int vertexCount)
Resize the vertex array.
Vertex & operator[](unsigned int index)
Get a read-write access to a vertex by its index.
unsigned int getVertexCount() const
Return the vertex count.