transfer_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 "transfer_buffer.h"
33
34 namespace clan
35 {
38
41 template<typename Type>
42 class TransferVector : public TransferBuffer
43 {
46 public:
48 TransferVector()
49 {
50 }
51
57 TransferVector(GraphicContext &gc, int size, BufferUsage usage = usage_dynamic_copy)
58 : TransferBuffer(gc, size * sizeof(Type), usage)
59 {
60 }
61
68 TransferVector(GraphicContext &gc, Type *data, int size, BufferUsage usage = usage_dynamic_copy)
69 : TransferBuffer(gc, data, size * sizeof(Type), usage)
70 {
71 }
72
73 TransferVector(GraphicContext &gc, const std::vector<Type> &data, BufferUsage usage = usage_dynamic_copy)
74 : TransferBuffer(gc, data.empty() ? (Type*)0 : &data[0], data.size() * sizeof(Type), usage)
75 {
76 }
77
79 explicit TransferVector(const TransferBuffer &transfer_buffer)
80 : TransferBuffer(transfer_buffer)
81 {
82 }
83
85
88 public:
90 Type *get_data() { return reinterpret_cast<Type*>(TransferBuffer::get_data()); }
91
92 Type &operator[](int index) { return get_data()[index]; }
93 Type &operator[](unsigned int index) { return get_data()[index]; }
95
98 public:
100 void upload_data(GraphicContext &gc, int offset, const Type *data, int size)
101 {
102 TransferBuffer::upload_data(gc, offset * sizeof(Type), data, size * sizeof(Type));
103 }
104
106 void upload_data(GraphicContext &gc, int offset, const std::vector<Type> &data)
107 {
108 if (!data.empty())
109 TransferBuffer::upload_data(gc, offset * sizeof(Type), &data[0], data.size() * sizeof(Type));
110 }
112
115 private:
117 };
118
119 }
120
clan::TransferVector::TransferVector
TransferVector()
Constructs a null instance.
Definition: transfer_vector.h:48
clan
Definition: clanapp.h:35
clan::TransferVector::operator[]
Type & operator[](int index)
Definition: transfer_vector.h:92
clan::TransferVector::get_data
Type * get_data()
Retrieves a pointer to the mapped buffer.
Definition: transfer_vector.h:90
clan::TransferBuffer::upload_data
void upload_data(GraphicContext &gc, int offset, const void *data, int size)
Uploads data to transfer buffer.
clan::TransferVector::upload_data
void upload_data(GraphicContext &gc, int offset, const Type *data, int size)
Uploads data to transfer buffer.
Definition: transfer_vector.h:100
clan::TransferVector::TransferVector
TransferVector(GraphicContext &gc, const std::vector< Type > &data, BufferUsage usage=usage_dynamic_copy)
Definition: transfer_vector.h:73
clan::TransferVector::TransferVector
TransferVector(GraphicContext &gc, Type *data, int size, BufferUsage usage=usage_dynamic_copy)
Constructs a TransferVector.
Definition: transfer_vector.h:68
clan::BufferUsage
BufferUsage
Array Buffer usage enum.
Definition: buffer_usage.h:40
clan::TransferBuffer::get_data
void * get_data()
Retrieves a pointer to the mapped buffer.
clan::GraphicContext
Interface to drawing graphics.
Definition: graphic_context.h:257
clan::TransferVector
Transfer Vector.
Definition: transfer_vector.h:42
clan::usage_dynamic_copy
Definition: buffer_usage.h:50
clan::TransferVector::TransferVector
TransferVector(GraphicContext &gc, int size, BufferUsage usage=usage_dynamic_copy)
Constructs a TransferVector.
Definition: transfer_vector.h:57
clan::TransferVector::operator[]
Type & operator[](unsigned int index)
Definition: transfer_vector.h:93
clan::TransferBuffer
Transfer Buffer.
Definition: transfer_buffer.h:45
clan::TransferVector::upload_data
void upload_data(GraphicContext &gc, int offset, const std::vector< Type > &data)
Uploads data to transfer buffer.
Definition: transfer_vector.h:106
clan::TransferVector::TransferVector
TransferVector(const TransferBuffer &transfer_buffer)
Constructs a TransferVector from an existing buffer.
Definition: transfer_vector.h:79