2013-12-22 14:04:33 +00:00
|
|
|
#ifndef OPENGLSHAREDSTATE_H
|
|
|
|
#define OPENGLSHAREDSTATE_H
|
|
|
|
|
|
|
|
#include "opengl_global.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include "OpenGLVariable.h"
|
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace opengl {
|
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
/**
|
|
|
|
* OpenGL variables that can be shared between shaders.
|
2013-12-22 14:04:33 +00:00
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class OPENGLSHARED_EXPORT OpenGLSharedState {
|
|
|
|
public:
|
2013-12-22 14:04:33 +00:00
|
|
|
OpenGLSharedState();
|
2015-11-29 18:18:36 +00:00
|
|
|
~OpenGLSharedState();
|
2013-12-22 14:04:33 +00:00
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
/**
|
|
|
|
* Apply the stored variables to the bound program.
|
2013-12-22 14:04:33 +00:00
|
|
|
*/
|
2015-12-23 22:40:19 +00:00
|
|
|
void apply(OpenGLShaderProgram *program, unsigned int &texture_unit);
|
2013-12-22 14:04:33 +00:00
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
/**
|
|
|
|
* Release any allocated resource in the opengl context.
|
|
|
|
*
|
|
|
|
* Must be called in the opengl rendering thread, and before the destructor is called.
|
2013-12-22 14:04:33 +00:00
|
|
|
*/
|
2015-12-10 22:41:42 +00:00
|
|
|
void destroy(OpenGLFunctions *functions);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get or create a variable in the state.
|
2013-12-22 14:04:33 +00:00
|
|
|
*/
|
2015-12-10 23:36:50 +00:00
|
|
|
OpenGLVariable *get(const string &name);
|
2013-12-22 14:04:33 +00:00
|
|
|
|
|
|
|
// Shortcuts
|
2015-12-13 16:16:26 +00:00
|
|
|
inline void setInt(const string &name, int value) {
|
2015-11-25 22:15:58 +00:00
|
|
|
get(name)->set(value);
|
|
|
|
}
|
2015-12-13 16:16:26 +00:00
|
|
|
inline void set(const string &name, float value) {
|
2015-11-25 22:15:58 +00:00
|
|
|
get(name)->set(value);
|
|
|
|
}
|
2015-12-10 23:36:50 +00:00
|
|
|
inline void set(const string &name, const Texture2D *texture, bool repeat = false, bool color = true) {
|
2015-11-09 21:30:46 +00:00
|
|
|
get(name)->set(texture, repeat, color);
|
|
|
|
}
|
2015-12-10 23:36:50 +00:00
|
|
|
inline void set(const string &name, const QImage &texture, bool repeat = false, bool color = true) {
|
2015-12-07 22:32:55 +00:00
|
|
|
get(name)->set(texture, repeat, color);
|
2015-11-09 21:30:46 +00:00
|
|
|
}
|
2015-12-10 23:36:50 +00:00
|
|
|
inline void set(const string &name, const Texture3D *texture, bool repeat = false, bool color = true) {
|
2015-11-09 21:30:46 +00:00
|
|
|
get(name)->set(texture, repeat, color);
|
|
|
|
}
|
2015-12-10 23:36:50 +00:00
|
|
|
inline void set(const string &name, const Texture4D *texture, bool repeat = false, bool color = true) {
|
2015-11-09 21:30:46 +00:00
|
|
|
get(name)->set(texture, repeat, color);
|
|
|
|
}
|
2015-12-10 23:36:50 +00:00
|
|
|
inline void set(const string &name, const Vector3 &vector) {
|
2015-11-09 21:30:46 +00:00
|
|
|
get(name)->set(vector);
|
|
|
|
}
|
2015-12-10 23:36:50 +00:00
|
|
|
inline void set(const string &name, const Matrix4 &matrix) {
|
2015-11-09 21:30:46 +00:00
|
|
|
get(name)->set(matrix);
|
|
|
|
}
|
2015-12-10 23:36:50 +00:00
|
|
|
inline void set(const string &name, const Color &color) {
|
2015-11-09 21:30:46 +00:00
|
|
|
get(name)->set(color);
|
|
|
|
}
|
2015-12-24 00:21:12 +00:00
|
|
|
inline void set(const string &name, const FractalNoise &noise) {
|
|
|
|
get(name)->set(noise);
|
|
|
|
}
|
2013-12-22 14:04:33 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-12-10 23:36:50 +00:00
|
|
|
map<string, OpenGLVariable *> variables;
|
2015-11-09 21:30:46 +00:00
|
|
|
};
|
2013-12-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OPENGLSHAREDSTATE_H
|