2013-12-22 14:04:33 +00:00
|
|
|
#ifndef OPENGLVARIABLE_H
|
|
|
|
#define OPENGLVARIABLE_H
|
|
|
|
|
|
|
|
#include "opengl_global.h"
|
|
|
|
|
2015-12-23 22:40:19 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2015-12-07 22:32:55 +00:00
|
|
|
class QImage;
|
2013-12-22 14:04:33 +00:00
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace opengl {
|
|
|
|
|
2016-01-03 18:21:23 +00:00
|
|
|
/**
|
|
|
|
* OpenGL variable that can be bound to a uniform for shaders.
|
2013-12-22 14:04:33 +00:00
|
|
|
*/
|
2015-12-23 22:40:19 +00:00
|
|
|
class OpenGLVariable final {
|
2015-11-09 21:30:46 +00:00
|
|
|
public:
|
2015-12-10 23:36:50 +00:00
|
|
|
OpenGLVariable(const string &name);
|
2015-12-07 22:32:55 +00:00
|
|
|
~OpenGLVariable();
|
2013-12-22 14:04:33 +00:00
|
|
|
|
2015-12-23 22:40:19 +00:00
|
|
|
/**
|
|
|
|
* Apply the variable to the bound shader program.
|
|
|
|
*
|
2016-01-06 18:55:49 +00:00
|
|
|
* 'texture_unit' will be used and updated accordingly.
|
2015-12-23 22:40:19 +00:00
|
|
|
*
|
|
|
|
* This must be called from the rendering thread, with the shader program bound.
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void destroy(OpenGLFunctions *functions);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
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);
|
2015-11-09 21:30:46 +00:00
|
|
|
void set(const Texture3D *texture, bool repeat = false, bool color = true);
|
|
|
|
void set(const Texture4D *texture, bool repeat = false, bool color = true);
|
2015-11-25 22:15:58 +00:00
|
|
|
void set(int value);
|
2013-12-22 14:04:33 +00:00
|
|
|
void set(float value);
|
2015-12-24 00:21:12 +00:00
|
|
|
void set(const FractalNoise &noise);
|
2013-12-22 14:04:33 +00:00
|
|
|
void set(const Vector3 &vector);
|
|
|
|
void set(const Matrix4 &matrix);
|
|
|
|
void set(const Color &color);
|
|
|
|
|
2015-12-23 22:40:19 +00:00
|
|
|
int getIntValue() const;
|
|
|
|
float getFloatValue() const;
|
2015-12-24 00:21:12 +00:00
|
|
|
float getFloatArrayValue(unsigned int index) const;
|
2015-12-13 18:56:00 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
protected:
|
2015-12-23 22:40:19 +00:00
|
|
|
void uploadTexture(OpenGLFunctions *renderer);
|
2013-12-22 17:05:11 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-12-23 22:40:19 +00:00
|
|
|
class pimpl;
|
|
|
|
unique_ptr<pimpl> impl;
|
2013-12-22 14:04:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OPENGLVARIABLE_H
|