Beatmup
variables_bundle.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../utils/lockable_object.h"
21 #include "../color/matrix.h"
22 #include "program.h"
23 #include <map>
24 #include <vector>
25 #include <string>
26 
27 namespace Beatmup {
28  namespace GL {
29 
30  /*
31  Collection storing GLSL program parameters (scalars, matrices, vectors) to communicate them from user to GPU-managing thread.
32  */
34  private:
35 
37  public:
38  enum Type {
40  UNDEFINED
41  };
42 
43  private:
44  void* data;
45  unsigned short int width, height;
46  unsigned int count;
48 
49  public:
53 
54  void configure(Type type, unsigned short int width, unsigned short int height = 1, unsigned int count = 1);
55 
56  template<typename T> inline T* getData(int index = 0) const {
57  return (T*)data + width * height * index;
58  }
59 
60  int getCount() const { return count; }
61  int getWidth() const { return width; }
62  int getHeight() const { return height; }
63  Type getType() const { return type; }
64  };
65 
66  std::map<std::string, int> integers;
67  std::map<std::string, float> floats;
68  std::map<std::string, std::vector<float>> floatArrays;
69  std::map<std::string, MatrixParameter> params;
70 
71  protected:
72  void apply(Program& program);
73 
74  public:
75  /**
76  Removes all stored variables.
77  */
78  void clear();
79 
80  /**
81  Sets a scalar integer uniform value.
82  \param name The uniform variable name
83  \param value The variable value
84  */
85  void setInteger(std::string name, int value);
86 
87  void setInteger(std::string name, int x, int y);
88  void setInteger(std::string name, int x, int y, int z);
89  void setInteger(std::string name, int x, int y, int z, int w);
90 
91  /**
92  Sets a scalar float uniform value.
93  \param name The uniform variable name
94  \param value The variable value
95  */
96  void setFloat(std::string name, float value);
97 
98  void setFloat(std::string name, float x, float y);
99  void setFloat(std::string name, float x, float y, float z);
100  void setFloat(std::string name, float x, float y, float z, float w);
101 
102  /**
103  Sets a float 2*2 matrix variable value.
104  \param name The uniform variable name
105  \param matrix The variable value
106  */
107  void setFloatMatrix2(std::string name, const float matrix[4]);
108 
109  /**
110  Sets a float 3*3 matrix variable value.
111  \param name The uniform variable name
112  \param matrix The variable value
113  */
114  void setFloatMatrix3(std::string name, const float matrix[9]);
115 
116  /**
117  Sets a float 4*4 matrix variable value.
118  \param name The uniform variable name
119  \param matrix The variable value
120  */
121  void setFloatMatrix4(std::string name, const float matrix[16]);
122 
123  /**
124  Sets a float 4*4 matrix variable value from a Color::Matrix instance.
125  \param name The uniform variable name
126  \param matrix The color matrix to copy values from
127  */
128  void setFloatMatrix4(std::string name, const Color::Matrix& matrix);
129 
130  /**
131  Sets a float array variable value.
132  \param name The uniform variable name
133  \param values The values
134  */
135  void setFloatArray(std::string name, const std::vector<float>& values);
136 
137  /**
138  Retrieves a value of a scalar float uniform variable by its name.
139  \param name The variable name
140  \return the variable value, if defined previously, quiet NaN otherwise.
141  */
142  float getFloat(const std::string& name) const;
143  };
144  }
145 }
RGBA color mapping.
Definition: matrix.h:29
Regular OpenGL program.
Definition: program.h:229
void configure(Type type, unsigned short int width, unsigned short int height=1, unsigned int count=1)
MatrixParameter & operator=(MatrixParameter &&)
void setFloatMatrix4(std::string name, const float matrix[16])
Sets a float 4*4 matrix variable value.
float getFloat(const std::string &name) const
Retrieves a value of a scalar float uniform variable by its name.
void setInteger(std::string name, int value)
Sets a scalar integer uniform value.
void setFloat(std::string name, float value)
Sets a scalar float uniform value.
std::map< std::string, int > integers
std::map< std::string, MatrixParameter > params
void clear()
Removes all stored variables.
void setFloatMatrix3(std::string name, const float matrix[9])
Sets a float 3*3 matrix variable value.
void setFloatMatrix2(std::string name, const float matrix[4])
Sets a float 2*2 matrix variable value.
std::map< std::string, float > floats
void apply(Program &program)
void setFloatArray(std::string name, const std::vector< float > &values)
Sets a float array variable value.
std::map< std::string, std::vector< float > > floatArrays
return(jlong) new Beatmup jlong jstring name
jlong jstring jint jint jint z
jlong jint index
jobject jlong jint jint y
jlong jstring jint jint jint jint w
jobject jlong jint x