1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#pragma once
#include "pointers.hpp"
#include "gpu_program.hpp"
#include "../std/string.hpp"
#include "../std/shared_ptr.hpp"
class UniformValue
{
public:
UniformValue(const string & name, int32_t v);
UniformValue(const string & name, int32_t v1, int32_t v2);
UniformValue(const string & name, int32_t v1, int32_t v2, int32_t v3);
UniformValue(const string & name, int32_t v1, int32_t v2, int32_t v3, int32_t v4);
UniformValue(const string & name, float v);
UniformValue(const string & name, float v1, float v2);
UniformValue(const string & name, float v1, float v2, float v3);
UniformValue(const string & name, float v1, float v2, float v3, float v4);
UniformValue(const string & name, float * matrixValue);
void Apply(WeakPointer<GpuProgram> program);
bool operator<(const UniformValue & other) const
{
size_t s = ((m_type == Int) ? sizeof(int32_t) : sizeof(float)) * m_componentCount;
return m_name < other.m_name
|| m_type < other.m_type
|| m_componentCount < other.m_componentCount
|| memcmp(m_values.get(), other.m_values.get(), s);
}
private:
void Allocate(size_t byteCount);
template <typename T>
T * CastMemory()
{
return reinterpret_cast<T *>(m_values.get());
}
private:
enum Type
{
Int,
Float,
Matrix4x4
};
string m_name;
Type m_type;
size_t m_componentCount;
shared_ptr<uint8_t> m_values;
};
|