paysages3d/src/render/opengl/OpenGLVariable.h

74 lines
1.8 KiB
C
Raw Normal View History

#ifndef OPENGLVARIABLE_H
#define OPENGLVARIABLE_H
#include "opengl_global.h"
#include <memory>
2015-12-07 22:32:55 +00:00
class QImage;
namespace paysages {
namespace opengl {
/*!
* \brief OpenGL variable that can be bound to a uniform for shaders.
*/
class OpenGLVariable final {
public:
typedef enum {
TYPE_NONE,
TYPE_TEXTURE_2D,
TYPE_TEXTURE_3D,
TYPE_TEXTURE_4D,
TYPE_INTEGER,
TYPE_FLOAT,
TYPE_VECTOR3,
TYPE_MATRIX4,
TYPE_COLOR
} OpenGLVariableType;
public:
2015-12-10 23:36:50 +00:00
OpenGLVariable(const string &name);
2015-12-07 22:32:55 +00:00
~OpenGLVariable();
/**
* Apply the variable to the bound shader program.
*
* *texture_unit* will be used and updated accordingly.
*
* This must be called from the rendering thread, with the shader program bound.
*/
void apply(OpenGLShaderProgram *program, unsigned 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);
void set(const Texture2D *texture, bool repeat = false, bool color = true);
2015-12-07 22:32:55 +00:00
void set(const QImage &texture, bool repeat = false, bool color = true);
void set(const Texture3D *texture, bool repeat = false, bool color = true);
void set(const Texture4D *texture, bool repeat = false, bool color = true);
void set(int value);
void set(float value);
void set(const Vector3 &vector);
void set(const Matrix4 &matrix);
void set(const Color &color);
int getIntValue() const;
float getFloatValue() const;
protected:
void uploadTexture(OpenGLFunctions *renderer);
2013-12-22 17:05:11 +00:00
private:
class pimpl;
unique_ptr<pimpl> impl;
};
}
}
#endif // OPENGLVARIABLE_H