uniform_vector.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 <memory>
33 #include "../api_display.h"
34 #include "uniform_buffer.h"
35 
36 namespace clan
37 {
40 
43 template<typename Type>
44 class CL_API_DISPLAY UniformVector : public UniformBuffer
45 {
48 public:
51  {
52  }
53 
60  : UniformBuffer(gc, size * sizeof(Type), usage)
61  {
62  }
63 
70  UniformVector(GraphicContext &gc, Type *data, int size, BufferUsage usage = usage_static_draw)
71  : UniformBuffer(gc, data, size * sizeof(Type), usage)
72  {
73  }
74 
75  UniformVector(GraphicContext &gc, const std::vector<Type> &data, BufferUsage usage = usage_static_draw)
76  : UniformBuffer(gc, data.empty() ? (Type*)0 : &data[0], data.size() * sizeof(Type), usage)
77  {
78  }
80 
83 public:
85 
88 public:
92  void upload_data(GraphicContext &gc, const Type *data, int size)
93  {
94  UniformBuffer::upload_data(gc, data, size * sizeof(Type));
95  }
96 
98  void upload_data(GraphicContext &gc, const std::vector<Type> &data)
99  {
100  if (!data.empty())
101  UniformBuffer::upload_data(gc, &data[0], data.size() * sizeof(Type));
102  }
103 
105  void copy_from(GraphicContext &gc, TransferVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
106  {
107  if (size != -1)
108  size = size * sizeof(Type);
109  UniformBuffer::copy_from(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
110  }
111 
113  void copy_to(GraphicContext &gc, TransferVector<Type> &buffer, int dest_pos = 0, int src_pos = 0, int size = -1)
114  {
115  if (size != -1)
116  size = size * sizeof(Type);
117  UniformBuffer::copy_to(gc, buffer, dest_pos * sizeof(Type), src_pos * sizeof(Type), size);
118  }
120 
123 private:
125 };
126 
127 }
128 
void copy_to(GraphicContext &gc, TransferBuffer &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data to transfer buffer.
void upload_data(GraphicContext &gc, const std::vector< Type > &data)
Uploads data to uniforms buffer.
Definition: uniform_vector.h:98
UniformVector(GraphicContext &gc, int size, BufferUsage usage=usage_static_draw)
Constructs a ElementArrayBuffer.
Definition: uniform_vector.h:59
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: uniform_vector.h:113
UniformVector(GraphicContext &gc, const std::vector< Type > &data, BufferUsage usage=usage_static_draw)
Definition: uniform_vector.h:75
void upload_data(GraphicContext &gc, const Type *data, int size)
Uploads data to uniforms buffer.
Definition: uniform_vector.h:92
Definition: buffer_usage.h:46
BufferUsage
Array Buffer usage enum.
Definition: buffer_usage.h:41
void upload_data(GraphicContext &gc, const void *data, int size)
Uploads data to uniforms buffer.
Uniform Buffer.
Definition: uniform_buffer.h:48
Interface to drawing graphics.
Definition: graphic_context.h:257
Transfer Vector.
Definition: transfer_vector.h:42
UniformVector(GraphicContext &gc, Type *data, int size, BufferUsage usage=usage_static_draw)
Constructs a ElementArrayBuffer.
Definition: uniform_vector.h:70
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: uniform_vector.h:105
Uniform Buffer Vector.
Definition: uniform_vector.h:44
void copy_from(GraphicContext &gc, TransferBuffer &buffer, int dest_pos=0, int src_pos=0, int size=-1)
Copies data from transfer buffer.
UniformVector()
Constructs a null instance.
Definition: uniform_vector.h:50