element_array_vector.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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 "element_array_buffer.h"
32 
33 namespace uicore
34 {
36  template<typename Type>
38  {
39  public:
42  {
43  }
44 
46  : _buffer(ElementArrayBuffer::create(gc, size * sizeof(Type), usage))
47  {
48  }
49 
50  ElementArrayVector(const GraphicContextPtr &gc, Type *data, int size, BufferUsage usage = usage_static_draw)
51  : _buffer(ElementArrayBuffer::create(gc, data, size * sizeof(Type), usage))
52  {
53  }
54 
55  ElementArrayVector(const GraphicContextPtr &gc, const std::vector<Type> &data, BufferUsage usage = usage_static_draw)
56  : _buffer(ElementArrayBuffer::create(gc, data.empty() ? (Type*)0 : &data[0], data.size() * sizeof(Type), usage))
57  {
58  }
59 
61  const ElementArrayBufferPtr &buffer() const { return _buffer; }
62 
63  operator const ElementArrayBufferPtr &() const { return buffer(); }
64 
68  void upload_data(const GraphicContextPtr &gc, const Type *data, int size)
69  {
70  _buffer->upload_data(gc, data, size * sizeof(Type));
71  }
72 
74  void upload_data(const GraphicContextPtr &gc, const std::vector<Type> &data)
75  {
76  _buffer->upload_data(gc, data.data(), data.size() * sizeof(Type));
77  }
78 
80  void copy_from(const GraphicContextPtr &gc, StagingVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
81  {
82  if (size != -1)
83  size = size * sizeof(Type);
84  _buffer->copy_from(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
85  }
86 
88  void copy_to(const GraphicContextPtr &gc, StagingVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
89  {
90  if (size != -1)
91  size = size * sizeof(Type);
92  _buffer->copy_to(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
93  }
94 
95  private:
96  ElementArrayBufferPtr _buffer;
97  };
98 }
const ElementArrayBufferPtr & buffer() const
Returns the element array buffer used by the vector.
Definition: element_array_vector.h:61
Element Array Buffer.
Definition: element_array_buffer.h:41
Typed access to a element array buffer.
Definition: element_array_vector.h:37
BufferUsage
Array Buffer usage enum.
Definition: buffer_usage.h:35
Definition: buffer_usage.h:40
std::shared_ptr< ElementArrayBuffer > ElementArrayBufferPtr
Definition: d3d_target.h:43
void copy_to(const GraphicContextPtr &gc, StagingVector< Type > &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data to transfer buffer.
Definition: element_array_vector.h:88
ElementArrayVector(const GraphicContextPtr &gc, const std::vector< Type > &data, BufferUsage usage=usage_static_draw)
Definition: element_array_vector.h:55
ElementArrayVector(const GraphicContextPtr &gc, int size, BufferUsage usage=usage_static_draw)
Definition: element_array_vector.h:45
ElementArrayVector()
Constructs a element array vector.
Definition: element_array_vector.h:41
void copy_from(const GraphicContextPtr &gc, StagingVector< Type > &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data from transfer buffer.
Definition: element_array_vector.h:80
std::shared_ptr< GraphicContext > GraphicContextPtr
Definition: d3d_target.h:49
void upload_data(const GraphicContextPtr &gc, const Type *data, int size)
Uploads data to element array buffer.
Definition: element_array_vector.h:68
Typed access to a transfer buffer.
Definition: staging_vector.h:37
ElementArrayVector(const GraphicContextPtr &gc, Type *data, int size, BufferUsage usage=usage_static_draw)
Definition: element_array_vector.h:50
Definition: Application/application.h:35
void upload_data(const GraphicContextPtr &gc, const std::vector< Type > &data)
Uploads data to element array buffer.
Definition: element_array_vector.h:74