1 | /*! |
---|
2 | * @file shader.h |
---|
3 | * @brief Definition of the Shader rendering class |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _SHADER_H |
---|
7 | #define _SHADER_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "glincl.h" |
---|
11 | #include <vector> |
---|
12 | |
---|
13 | |
---|
14 | typedef enum |
---|
15 | { |
---|
16 | SHADER_NONE = 0, |
---|
17 | SHADER_FRAGMENT = 1, |
---|
18 | SHADER_VERTEX = 0, |
---|
19 | |
---|
20 | } SHADER_TYPE; |
---|
21 | |
---|
22 | // FORWARD DECLARATION |
---|
23 | |
---|
24 | |
---|
25 | //! A class for ... |
---|
26 | class Shader : public BaseObject { |
---|
27 | |
---|
28 | public: |
---|
29 | Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); |
---|
30 | virtual ~Shader(); |
---|
31 | static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile); |
---|
32 | static bool unload(Shader* shader); |
---|
33 | |
---|
34 | bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName); |
---|
35 | void activateShader(); |
---|
36 | void bindShader(const char* name, const float* value, size_t size); |
---|
37 | static void deactivateShader(); |
---|
38 | void deleteProgram(SHADER_TYPE type); |
---|
39 | |
---|
40 | char* fileRead(const std::string& fileName); |
---|
41 | std::vector<char*>* fileReadArray(const std::string& fileName); |
---|
42 | |
---|
43 | static bool checkShaderAbility(); |
---|
44 | |
---|
45 | inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; |
---|
46 | inline static Shader* getActiveShader() { return Shader::storedShader; }; |
---|
47 | inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; |
---|
48 | inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; |
---|
49 | |
---|
50 | GLhandleARB getProgram() { return this->shaderProgram; } |
---|
51 | GLhandleARB getVertexS() { return this->vertexShader; } |
---|
52 | GLhandleARB getFragmentS() { return this->fragmentShader; } |
---|
53 | |
---|
54 | void printError(GLhandleARB program); |
---|
55 | void debug() const; |
---|
56 | |
---|
57 | private: |
---|
58 | |
---|
59 | private: |
---|
60 | std::string fragmentShaderFile; |
---|
61 | std::string vertexShaderFile; |
---|
62 | GLhandleARB shaderProgram; |
---|
63 | GLhandleARB vertexShader; |
---|
64 | GLhandleARB fragmentShader; |
---|
65 | |
---|
66 | static Shader* storedShader; |
---|
67 | }; |
---|
68 | |
---|
69 | #endif /* _SHADER_H */ |
---|