2013-12-21 22:48:54 +00:00
|
|
|
#ifndef OPENGLSHADERPROGRAM_H
|
|
|
|
#define OPENGLSHADERPROGRAM_H
|
|
|
|
|
|
|
|
#include "opengl_global.h"
|
|
|
|
|
2015-12-29 23:43:35 +00:00
|
|
|
#include <string>
|
|
|
|
|
2013-12-21 22:48:54 +00:00
|
|
|
class QOpenGLShaderProgram;
|
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace opengl {
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
class OPENGLSHARED_EXPORT OpenGLShaderProgram {
|
|
|
|
public:
|
2015-12-10 23:36:50 +00:00
|
|
|
OpenGLShaderProgram(const string &name, OpenGLRenderer *renderer);
|
2013-12-21 22:48:54 +00:00
|
|
|
~OpenGLShaderProgram();
|
|
|
|
|
2015-12-10 23:36:50 +00:00
|
|
|
void addVertexSource(const string &path);
|
|
|
|
void addFragmentSource(const string &path);
|
2013-12-21 22:48:54 +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-29 18:18:36 +00:00
|
|
|
|
2015-12-07 22:32:55 +00:00
|
|
|
/**
|
|
|
|
* Draw a VertexArray object.
|
|
|
|
*
|
|
|
|
* This will bind the program (compile it if needed), set the uniform variables, and
|
|
|
|
* ask the array object to bind its VAO and render itself.
|
|
|
|
*
|
|
|
|
* *state* is optional and may add ponctual variables to the global state.
|
|
|
|
*/
|
2015-12-13 18:06:27 +00:00
|
|
|
void draw(OpenGLVertexArray *vertices, OpenGLSharedState *state = NULL, int start = 0, int count = -1);
|
2013-12-24 10:44:39 +00:00
|
|
|
|
2015-12-23 22:40:19 +00:00
|
|
|
/**
|
|
|
|
* Check if the program is currently bound to OpenGL context.
|
|
|
|
*
|
|
|
|
* This does not really check the OpenGL context, just check we are between bind() and release() calls.
|
|
|
|
*/
|
|
|
|
inline bool isBound() const {
|
|
|
|
return bound;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the OpenGL ID for this program.
|
|
|
|
*/
|
|
|
|
unsigned int getId() const;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline QOpenGLShaderProgram *getProgram() const {
|
|
|
|
return program;
|
|
|
|
}
|
2015-12-07 22:32:55 +00:00
|
|
|
inline OpenGLFunctions *getFunctions() const {
|
|
|
|
return functions;
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
inline OpenGLRenderer *getRenderer() const {
|
|
|
|
return renderer;
|
|
|
|
}
|
2015-11-25 22:15:58 +00:00
|
|
|
inline OpenGLSharedState *getState() const {
|
|
|
|
return state;
|
|
|
|
}
|
2013-12-24 10:44:39 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
protected:
|
2013-12-22 14:04:33 +00:00
|
|
|
friend class OpenGLVariable;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-12-07 22:32:55 +00:00
|
|
|
bool bind(OpenGLSharedState *state = NULL);
|
|
|
|
void release();
|
2013-12-22 17:47:24 +00:00
|
|
|
void compile();
|
2013-12-21 22:48:54 +00:00
|
|
|
|
2013-12-22 17:47:24 +00:00
|
|
|
bool compiled;
|
2015-12-23 22:40:19 +00:00
|
|
|
bool bound;
|
2013-12-22 17:47:24 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
OpenGLRenderer *renderer;
|
2013-12-22 14:04:33 +00:00
|
|
|
|
2015-12-10 23:36:50 +00:00
|
|
|
string name;
|
2015-11-09 21:30:46 +00:00
|
|
|
QOpenGLShaderProgram *program;
|
|
|
|
OpenGLFunctions *functions;
|
2013-12-22 17:47:24 +00:00
|
|
|
|
2015-11-25 22:15:58 +00:00
|
|
|
OpenGLSharedState *state;
|
|
|
|
|
2015-12-10 23:36:50 +00:00
|
|
|
string source_vertex;
|
|
|
|
string source_fragment;
|
2013-12-21 22:48:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OPENGLSHADERPROGRAM_H
|