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>
42 {
43 public:
46 {
47 }
48
55 : TransferBuffer(gc, size * sizeof(Type), usage)
56 {
57 }
58
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}
Interface to drawing graphics.
Definition graphic_context.h:257
Transfer Buffer.
Definition transfer_buffer.h:45
void * get_data()
Retrieves a pointer to the mapped buffer.
void upload_data(GraphicContext &gc, int offset, const void *data, int size)
Uploads data to transfer buffer.
Transfer Vector.
Definition transfer_vector.h:42
void upload_data(GraphicContext &gc, int offset, const std::vector< Type > &data)
Uploads data to transfer buffer.
Definition transfer_vector.h:94
TransferVector(GraphicContext &gc, Type *data, int size, BufferUsage usage=BufferUsage::dynamic_copy)
Constructs a TransferVector.
Definition transfer_vector.h:65
void upload_data(GraphicContext &gc, int offset, const Type *data, int size)
Uploads data to transfer buffer.
Definition transfer_vector.h:88
Type & operator[](unsigned int index)
Definition transfer_vector.h:85
Type & operator[](int index)
Definition transfer_vector.h:84
TransferVector(GraphicContext &gc, int size, BufferUsage usage=BufferUsage::dynamic_copy)
Constructs a TransferVector.
Definition transfer_vector.h:54
TransferVector()
Constructs a null instance.
Definition transfer_vector.h:45
Type * get_data()
Retrieves a pointer to the mapped buffer.
Definition transfer_vector.h:82
TransferVector(GraphicContext &gc, const std::vector< Type > &data, BufferUsage usage=BufferUsage::dynamic_copy)
Definition transfer_vector.h:70
TransferVector(const TransferBuffer &transfer_buffer)
Constructs a TransferVector from an existing buffer.
Definition transfer_vector.h:76
BufferUsage
Array Buffer usage enum.
Definition buffer_usage.h:39
Definition clanapp.h:36