transfer_vector.h Source File - ClanLib SDK
Description: transfer_vector.h Source File

transfer_vector.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
30
31#include "transfer_buffer.h"
32
33namespace clan
34{
37
40 template<typename Type>
41 class TransferVector : public TransferBuffer
42 {
43 public:
45 TransferVector()
46 {
47 }
48
54 TransferVector(GraphicContext &gc, int size, BufferUsage usage = BufferUsage::dynamic_copy)
55 : TransferBuffer(gc, size * sizeof(Type), usage)
56 {
57 }
58
65 TransferVector(GraphicContext &gc, Type *data, int size, BufferUsage usage = BufferUsage::dynamic_copy)
66 : TransferBuffer(gc, data, size * sizeof(Type), usage)
67 {
68 }
69
70 TransferVector(GraphicContext &gc, const std::vector<Type> &data, BufferUsage usage = BufferUsage::dynamic_copy)
71 : TransferBuffer(gc, data.empty() ? (Type*)0 : &data[0], data.size() * sizeof(Type), usage)
72 {
73 }
74
76 explicit TransferVector(const TransferBuffer &transfer_buffer)
77 : TransferBuffer(transfer_buffer)
78 {
79 }
80
82 Type *get_data() { return reinterpret_cast<Type*>(TransferBuffer::get_data()); }
83
84 Type &operator[](int index) { return get_data()[index]; }
85 Type &operator[](unsigned int index) { return get_data()[index]; }
86
88 void upload_data(GraphicContext &gc, int offset, const Type *data, int size)
89 {
90 TransferBuffer::upload_data(gc, offset * sizeof(Type), data, size * sizeof(Type));
91 }
92
94 void upload_data(GraphicContext &gc, int offset, const std::vector<Type> &data)
95 {
96 if (!data.empty())
97 TransferBuffer::upload_data(gc, offset * sizeof(Type), &data[0], data.size() * sizeof(Type));
98 }
99 };
100
102}
clan::GraphicContext
Interface to drawing graphics.
Definition graphic_context.h:257
clan::TransferBuffer
Transfer Buffer.
Definition transfer_buffer.h:45
clan::TransferBuffer::get_data
void * get_data()
Retrieves a pointer to the mapped buffer.
clan::TransferBuffer::upload_data
void upload_data(GraphicContext &gc, int offset, const void *data, int size)
Uploads data to transfer buffer.
clan::TransferVector
Transfer Vector.
Definition transfer_vector.h:42
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:94
clan::TransferVector::TransferVector
TransferVector(GraphicContext &gc, Type *data, int size, BufferUsage usage=BufferUsage::dynamic_copy)
Constructs a TransferVector.
Definition transfer_vector.h:65
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:88
clan::TransferVector::operator[]
Type & operator[](unsigned int index)
Definition transfer_vector.h:85
clan::TransferVector::operator[]
Type & operator[](int index)
Definition transfer_vector.h:84
clan::TransferVector::TransferVector
TransferVector(GraphicContext &gc, int size, BufferUsage usage=BufferUsage::dynamic_copy)
Constructs a TransferVector.
Definition transfer_vector.h:54
clan::TransferVector::TransferVector
TransferVector()
Constructs a null instance.
Definition transfer_vector.h:45
clan::TransferVector::get_data
Type * get_data()
Retrieves a pointer to the mapped buffer.
Definition transfer_vector.h:82
clan::TransferVector::TransferVector
TransferVector(GraphicContext &gc, const std::vector< Type > &data, BufferUsage usage=BufferUsage::dynamic_copy)
Definition transfer_vector.h:70
clan::TransferVector::TransferVector
TransferVector(const TransferBuffer &transfer_buffer)
Constructs a TransferVector from an existing buffer.
Definition transfer_vector.h:76
clan::BufferUsage
BufferUsage
Array Buffer usage enum.
Definition buffer_usage.h:39
clan::BufferUsage::dynamic_copy
@ dynamic_copy
clan
Definition clanapp.h:36