storage_vector.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 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 <memory>
32 #include "storage_buffer.h"
33 
34 namespace clan
35 {
38 
41  template<typename Type>
43  {
44  public:
47  {
48  }
49 
56  : StorageBuffer(gc, size * sizeof(Type), sizeof(Type), usage)
57  {
58  }
59 
66  StorageVector(GraphicContext &gc, Type *data, int size, BufferUsage usage = usage_static_draw)
67  : StorageBuffer(gc, data, size * sizeof(Type), sizeof(Type), usage)
68  {
69  }
70 
71  StorageVector(GraphicContext &gc, const std::vector<Type> &data, BufferUsage usage = usage_static_draw)
72  : StorageBuffer(gc, data.empty() ? (Type*)0 : &data[0], data.size() * sizeof(Type), sizeof(Type), usage)
73  {
74  }
75 
79  void upload_data(GraphicContext &gc, const Type *data, int size)
80  {
81  StorageBuffer::upload_data(gc, data, size * sizeof(Type));
82  }
83 
85  void upload_data(GraphicContext &gc, const std::vector<Type> &data)
86  {
87  if (!data.empty())
88  StorageBuffer::upload_data(gc, &data[0], data.size() * sizeof(Type));
89  }
90 
92  void copy_from(GraphicContext &gc, TransferVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
93  {
94  if (size != -1)
95  size = size * sizeof(Type);
96  StorageBuffer::copy_from(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
97  }
98 
100  void copy_to(GraphicContext &gc, TransferVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
101  {
102  if (size != -1)
103  size = size * sizeof(Type);
104  StorageBuffer::copy_to(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
105  }
106  };
107 
109 }
StorageVector(GraphicContext &gc, Type *data, int size, BufferUsage usage=usage_static_draw)
Constructs a ElementArrayBuffer.
Definition: storage_vector.h:66
Definition: clanapp.h:35
void upload_data(GraphicContext &gc, const std::vector< Type > &data)
Uploads data to storage buffer.
Definition: storage_vector.h:85
void copy_from(GraphicContext &gc, TransferBuffer &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data from transfer buffer.
void copy_to(GraphicContext &gc, TransferBuffer &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data to transfer buffer.
Definition: buffer_usage.h:43
BufferUsage
Array Buffer usage enum.
Definition: buffer_usage.h:38
StorageVector(GraphicContext &gc, const std::vector< Type > &data, BufferUsage usage=usage_static_draw)
Definition: storage_vector.h:71
StorageVector(GraphicContext &gc, int size, BufferUsage usage=usage_static_draw)
Constructs a ElementArrayBuffer.
Definition: storage_vector.h:55
Interface to drawing graphics.
Definition: graphic_context.h:256
Transfer Vector.
Definition: transfer_vector.h:41
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: storage_vector.h:100
Storage Buffer.
Definition: storage_buffer.h:46
void upload_data(GraphicContext &gc, const void *data, int size)
Uploads data to storage buffer.
void upload_data(GraphicContext &gc, const Type *data, int size)
Uploads data to storage buffer.
Definition: storage_vector.h:79
StorageVector()
Constructs a null instance.
Definition: storage_vector.h:46
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: storage_vector.h:92
Storage Buffer Vector.
Definition: storage_vector.h:42