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 | // FORWARD DECLARATION |
---|
15 | |
---|
16 | |
---|
17 | //! A class for ... |
---|
18 | class Shader : public BaseObject |
---|
19 | { |
---|
20 | public: |
---|
21 | typedef enum |
---|
22 | { |
---|
23 | None = 0, |
---|
24 | Fragment = 1, |
---|
25 | Vertex = 2, |
---|
26 | |
---|
27 | Program = 4, |
---|
28 | } Type; |
---|
29 | |
---|
30 | public: |
---|
31 | Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); |
---|
32 | virtual ~Shader(); |
---|
33 | static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile); |
---|
34 | static bool unload(Shader* shader); |
---|
35 | |
---|
36 | |
---|
37 | static bool checkShaderAbility(); |
---|
38 | void activateShader(); |
---|
39 | static void deactivateShader(); |
---|
40 | |
---|
41 | |
---|
42 | bool loadShaderProgramm(Shader::Type type, const std::string& fileName); |
---|
43 | void deleteProgram(Shader::Type type); |
---|
44 | |
---|
45 | void linkShaderProgram(); |
---|
46 | |
---|
47 | |
---|
48 | bool readShader(const std::string& fileName, std::string& output); |
---|
49 | |
---|
50 | |
---|
51 | inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; |
---|
52 | inline static Shader* getActiveShader() { return Shader::storedShader; }; |
---|
53 | inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; |
---|
54 | inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; |
---|
55 | |
---|
56 | |
---|
57 | GLhandleARB getProgram() const { return this->shaderProgram; } |
---|
58 | GLhandleARB getVertexS() const { return this->vertexShader; } |
---|
59 | GLhandleARB getFragmentS() const { return this->fragmentShader; } |
---|
60 | |
---|
61 | void debug() const; |
---|
62 | |
---|
63 | static void printError(GLhandleARB program); |
---|
64 | |
---|
65 | |
---|
66 | private: |
---|
67 | std::string fragmentShaderFile; |
---|
68 | std::string vertexShaderFile; |
---|
69 | |
---|
70 | GLhandleARB shaderProgram; |
---|
71 | |
---|
72 | GLhandleARB vertexShader; |
---|
73 | GLhandleARB fragmentShader; |
---|
74 | |
---|
75 | static Shader* storedShader; |
---|
76 | }; |
---|
77 | |
---|
78 | #endif /* _SHADER_H */ |
---|