paysages3d/src/render/opengl/OpenGLSharedState.h

81 lines
2.2 KiB
C
Raw Normal View History

#ifndef OPENGLSHAREDSTATE_H
#define OPENGLSHAREDSTATE_H
#include "opengl_global.h"
#include <map>
#include "OpenGLVariable.h"
2015-12-07 22:32:55 +00:00
class QImage;
namespace paysages {
namespace opengl {
/**
* OpenGL variables that can be shared between shaders.
*/
class OPENGLSHARED_EXPORT OpenGLSharedState {
public:
OpenGLSharedState();
~OpenGLSharedState();
/**
* Apply the stored variables to the bound program.
*/
void apply(OpenGLShaderProgram *program, int &texture_unit);
/**
* Release any allocated resource in the opengl context.
*
* Must be called in the opengl rendering thread, and before the destructor is called.
*/
void destroy(OpenGLFunctions *functions);
/**
* Get or create a variable in the state.
*/
2015-12-10 23:36:50 +00:00
OpenGLVariable *get(const string &name);
// Shortcuts
inline void setInt(const string &name, int value) {
get(name)->set(value);
}
inline void set(const string &name, float value) {
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) {
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-12-10 23:36:50 +00:00
inline void set(const string &name, const Texture3D *texture, bool repeat = false, bool color = true) {
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) {
get(name)->set(texture, repeat, color);
}
2015-12-10 23:36:50 +00:00
inline void set(const string &name, const Vector3 &vector) {
get(name)->set(vector);
}
2015-12-10 23:36:50 +00:00
inline void set(const string &name, const QVector3D &vector) {
get(name)->set(vector);
}
2015-12-10 23:36:50 +00:00
inline void set(const string &name, const Matrix4 &matrix) {
get(name)->set(matrix);
}
2015-12-10 23:36:50 +00:00
inline void set(const string &name, const QMatrix4x4 &matrix) {
get(name)->set(matrix);
}
2015-12-10 23:36:50 +00:00
inline void set(const string &name, const Color &color) {
get(name)->set(color);
}
private:
2015-12-10 23:36:50 +00:00
map<string, OpenGLVariable *> variables;
};
}
}
#endif // OPENGLSHAREDSTATE_H