Welcome to mirror list, hosted at ThFree Co, Russian Federation.

uniform_value.hpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 32b6ecdce6c9c38848bb0781aef4c6ac7d6e2365 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

#include "drape/pointers.hpp"
#include "drape/gpu_program.hpp"

#include "std/string.hpp"
#include "std/shared_array.hpp"
#include "std/cstring.hpp"

namespace dp
{

class UniformValue
{
public:
  enum Type
  {
    Int,
    Float,
    Matrix4x4
  };

  explicit UniformValue(string const & name, int32_t v);
  explicit UniformValue(string const & name, int32_t v1, int32_t v2);
  explicit UniformValue(string const & name, int32_t v1, int32_t v2, int32_t v3);
  explicit UniformValue(string const & name, int32_t v1, int32_t v2, int32_t v3, int32_t v4);

  explicit UniformValue(string const & name, float v);
  explicit UniformValue(string const & name, float v1, float v2);
  explicit UniformValue(string const & name, float v1, float v2, float v3);
  explicit UniformValue(string const & name, float v1, float v2, float v3, float v4);

  explicit UniformValue(string const & name, float const * matrixValue);

  string const & GetName() const;
  Type GetType() const;
  size_t GetComponentCount() const;

  void SetIntValue(int32_t v);
  void SetIntValue(int32_t v1, int32_t v2);
  void SetIntValue(int32_t v1, int32_t v2, int32_t v3);
  void SetIntValue(int32_t v1, int32_t v2, int32_t v3, int32_t v4);

  void SetFloatValue(float v);
  void SetFloatValue(float v1, float v2);
  void SetFloatValue(float v1, float v2, float v3);
  void SetFloatValue(float v1, float v2, float v3, float v4);

  void SetMatrix4x4Value(float const * matrixValue);

  void Apply(ref_ptr<GpuProgram> program) const;

  bool operator<(UniformValue const & other) const
  {
    if (m_name != other.m_name)
      return m_name < other.m_name;
    if (m_type != other.m_type)
      return m_type < other.m_type;
    if (m_componentCount != other.m_componentCount)
      return m_componentCount < other.m_componentCount;

    size_t s = ((m_type == Int) ? sizeof(int32_t) : sizeof(float)) * m_componentCount;
    return memcmp(m_values.get(), other.m_values.get(), s) < 0;
  }

private:
  void Allocate(size_t byteCount);

  template <typename T>
  T * CastMemory()
  {
    return reinterpret_cast<T *>(m_values.get());
  }

  template <typename T>
  const T * CastMemory() const
  {
    return reinterpret_cast<T *>(m_values.get());
  }

private:
  string m_name;
  Type m_type;
  size_t m_componentCount;

  shared_array<uint8_t> m_values;
};

} // namespace dp