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 {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief OpenGL variables that can be shared between shaders.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class OPENGLSHARED_EXPORT OpenGLSharedState {
|
|
|
|
public:
|
2013-12-22 14:04:33 +00:00
|
|
|
OpenGLSharedState();
|
2015-11-23 23:58:09 +00:00
|
|
|
~OpenGLSharedState();
|
2013-12-22 14:04:33 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Apply the stored variables to the bound program.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
void apply(OpenGLShaderProgram *program, int &texture_unit);
|
2013-12-22 14:04:33 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Get or create a variable in the state.
|
|
|
|
*/
|
|
|
|
OpenGLVariable *get(const std::string &name);
|
|
|
|
|
|
|
|
// Shortcuts
|
2015-11-09 21:30:46 +00:00
|
|
|
inline void set(const std::string &name, const Texture2D *texture, bool repeat = false, bool color = true) {
|
|
|
|
get(name)->set(texture, repeat, color);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, const Texture3D *texture, bool repeat = false, bool color = true) {
|
|
|
|
get(name)->set(texture, repeat, color);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, const Texture4D *texture, bool repeat = false, bool color = true) {
|
|
|
|
get(name)->set(texture, repeat, color);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, float value) {
|
|
|
|
get(name)->set(value);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, const Vector3 &vector) {
|
|
|
|
get(name)->set(vector);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, const QVector3D &vector) {
|
|
|
|
get(name)->set(vector);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, const Matrix4 &matrix) {
|
|
|
|
get(name)->set(matrix);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, const QMatrix4x4 &matrix) {
|
|
|
|
get(name)->set(matrix);
|
|
|
|
}
|
|
|
|
inline void set(const std::string &name, const Color &color) {
|
|
|
|
get(name)->set(color);
|
|
|
|
}
|
2013-12-22 14:04:33 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
|
|
|
std::map<std::string, OpenGLVariable *> variables;
|
|
|
|
};
|
2013-12-22 14:04:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OPENGLSHAREDSTATE_H
|