Fillwave  10.0.0
Uniform.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <flw/OpenGL.h>
25 
26 #include <flw/Math.h>
27 
28 #include <string>
29 #include <memory>
30 
31 namespace flw {
32 namespace flc {
33 
38 typedef union UniformData {
39  GLenum glEnum;
40  GLbitfield glBitfield;
41  GLuint glUint;
42  GLint glInt;
43  GLsizei glSizei;
44  GLboolean glBoolean;
45  GLbyte glByte;
46  GLshort glShort;
47  GLubyte glUbyte;
48  GLushort glUshort;
49  //GLulong glUlong;
50  GLfloat glFloat;
51  GLfloat glVec2[2];
52  GLfloat glVec3[3];
53  GLfloat glVec4[4];
54  GLfloat glMat2[4];
55  GLfloat glMat3[9];
56  GLfloat glMat4[16];
57 } UniformData;
58 
63 class Uniform final {
64 public:
65  Uniform(const std::string& name, GLuint type, GLsizei size, GLint location);
66 
67  bool isName(const std::string &name) const;
68 
69  GLuint getType() const;
70 
71  GLsizei getSize() const;
72 
73  GLint getLocation() const;
74 
75  void setName(std::string name);
76 
77  void setType(GLuint size);
78 
79  void setSize(GLsizei size);
80 
81  void setLocation(GLint location);
82 
83  void setData(UniformData data);
84 
85  /* Slow push with O(n) where n is uniform vector size */
86 
87  void push(GLint value);
88 
89  void push(GLint *value, GLint size);
90 
91  void push(GLfloat value);
92 
93  void push(GLfloat *value, GLint size);
94 
95  void push(glm::mat4 value);
96 
97  void push(glm::mat4 *value, GLuint size);
98 
99  void push(glm::mat3 value);
100 
101  void push(glm::mat2 value);
102 
103  void push(glm::vec2 value);
104 
105  void push(glm::vec3 value);
106 
107  void push(glm::vec3 *value, GLuint size);
108 
109  void push(glm::vec4 value);
110 
111  /* Fast push with O(1) */
112 
113  static void push(GLint location, GLint data);
114 
115  static void push(GLint location, GLuint data);
116 
117  static void push(GLint location, bool data);
118 
119  static void push(GLint location, GLint *data, GLint count);
120 
121  static void push(GLint location, GLfloat data);
122 
123  static void push(GLint location, GLfloat *data, GLint count);
124 
125  static void push(GLint location, glm::mat2 data);
126 
127  static void push(GLint location, glm::mat3 data);
128 
129  static void push(GLint location, glm::mat4 data);
130 
131  static void push(GLint location, glm::mat4 *data, GLuint size);
132 
133  static void push(GLint location, glm::vec2 data);
134 
135  static void push(GLint location, glm::vec3 data);
136 
137  static void push(GLint location, glm::vec4 data);
138 
139  void log() const;
140 
141 private:
142  std::string mName;
143  GLenum mType;
144  GLsizei mSize;
145  GLint mLocation;
146  UniformData mData;
147 };
148 
149 } /* flc */
150 } /* flw */
Definition: Aliases.h:30
Uniform.
Definition: Uniform.h:63
Uniform data structure.
Definition: Uniform.h:38