vertex_array_vector.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** 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
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28
29
30 #pragma once
31
32 #include "vertex_array_buffer.h"
33 #include "transfer_vector.h"
34
35 namespace clan
36 {
39
42 template<typename Type>
43 class VertexArrayVector : public VertexArrayBuffer
44 {
47 public:
49 VertexArrayVector()
50 {
51 }
52
54 explicit VertexArrayVector(const VertexArrayBuffer &buffer) : VertexArrayBuffer(buffer)
55 {
56 }
57
63 VertexArrayVector(GraphicContext &gc, int size, BufferUsage usage = usage_static_draw)
64 : VertexArrayBuffer(gc, size * sizeof(Type), usage)
65 {
66 }
67
74 VertexArrayVector(GraphicContext &gc, Type *data, int size, BufferUsage usage = usage_static_draw)
75 : VertexArrayBuffer(gc, data, size * sizeof(Type), usage)
76 {
77 }
78
79 VertexArrayVector(GraphicContext &gc, const std::vector<Type> &data, BufferUsage usage = usage_static_draw)
80 : VertexArrayBuffer(gc, data.empty() ? (Type*)0 : &data[0], data.size() * sizeof(Type), usage)
81 {
82 }
84
87 public:
89
92 public:
94 void upload_data(GraphicContext &gc, int offset, const Type *data, int size)
95 {
96 VertexArrayBuffer::upload_data(gc, offset * sizeof(Type), data, size * sizeof(Type));
97 }
98
100 void upload_data(GraphicContext &gc, int offset, const std::vector<Type> &data)
101 {
102 if (!data.empty())
103 VertexArrayBuffer::upload_data(gc, offset, &data[0], data.size() * sizeof(Type));
104 }
105
107 void copy_from(GraphicContext &gc, TransferVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
108 {
109 if (size != -1)
110 size = size * sizeof(Type);
111 VertexArrayBuffer::copy_from(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
112 }
113
115 void copy_to(GraphicContext &gc, TransferVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
116 {
117 if (size != -1)
118 size = size * sizeof(Type);
119 VertexArrayBuffer::copy_to(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
120 }
122
125 private:
127 };
128
129 }
130
clan
Definition: clanapp.h:35
clan::VertexArrayBuffer::upload_data
void upload_data(GraphicContext &gc, int offset, const void *data, int size)
Uploads data to vertex array buffer.
clan::VertexArrayVector::VertexArrayVector
VertexArrayVector()
Constructs a null instance.
Definition: vertex_array_vector.h:49
clan::VertexArrayBuffer
Vertex Array Buffer.
Definition: vertex_array_buffer.h:46
clan::VertexArrayBuffer::copy_from
void copy_from(GraphicContext &gc, TransferBuffer &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data from transfer buffer.
clan::VertexArrayVector::VertexArrayVector
VertexArrayVector(GraphicContext &gc, int size, BufferUsage usage=usage_static_draw)
Constructs a VertexArrayBuffer.
Definition: vertex_array_vector.h:63
clan::VertexArrayVector::upload_data
void upload_data(GraphicContext &gc, int offset, const Type *data, int size)
Uploads data to vertex array buffer.
Definition: vertex_array_vector.h:94
clan::VertexArrayVector::copy_to
void copy_to(GraphicContext &gc, TransferVector< Type > &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data to transfer buffer.
Definition: vertex_array_vector.h:115
clan::VertexArrayVector::VertexArrayVector
VertexArrayVector(const VertexArrayBuffer &buffer)
Constructs a VertexArrayBuffer using an existing VertexArrayBuffer.
Definition: vertex_array_vector.h:54
clan::usage_static_draw
Definition: buffer_usage.h:45
clan::BufferUsage
BufferUsage
Array Buffer usage enum.
Definition: buffer_usage.h:40
clan::GraphicContext
Interface to drawing graphics.
Definition: graphic_context.h:257
clan::TransferVector
Transfer Vector.
Definition: transfer_vector.h:42
clan::VertexArrayVector::VertexArrayVector
VertexArrayVector(GraphicContext &gc, Type *data, int size, BufferUsage usage=usage_static_draw)
Constructs a VertexArrayBuffer.
Definition: vertex_array_vector.h:74
clan::VertexArrayVector::upload_data
void upload_data(GraphicContext &gc, int offset, const std::vector< Type > &data)
Uploads data to vertex array buffer.
Definition: vertex_array_vector.h:100
clan::VertexArrayBuffer::copy_to
void copy_to(GraphicContext &gc, TransferBuffer &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data to transfer buffer.
clan::VertexArrayVector::copy_from
void copy_from(GraphicContext &gc, TransferVector< Type > &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data from transfer buffer.
Definition: vertex_array_vector.h:107
clan::VertexArrayVector::VertexArrayVector
VertexArrayVector(GraphicContext &gc, const std::vector< Type > &data, BufferUsage usage=usage_static_draw)
Definition: vertex_array_vector.h:79
clan::VertexArrayVector
Vertex Array Vector.
Definition: vertex_array_vector.h:43