[4838] | 1 | /*! |
---|
[5261] | 2 | * @file shader.h |
---|
| 3 | * @brief Definition of the Shader rendering class |
---|
[3245] | 4 | */ |
---|
[1853] | 5 | |
---|
[5261] | 6 | #ifndef _SHADER_H |
---|
| 7 | #define _SHADER_H |
---|
[1853] | 8 | |
---|
[3543] | 9 | #include "base_object.h" |
---|
[5261] | 10 | #include "glincl.h" |
---|
[7164] | 11 | #include <vector> |
---|
[1853] | 12 | |
---|
[5261] | 13 | |
---|
[4838] | 14 | // FORWARD DECLARATION |
---|
[3543] | 15 | |
---|
| 16 | |
---|
[3955] | 17 | //! A class for ... |
---|
[7818] | 18 | class Shader : public BaseObject |
---|
| 19 | { |
---|
| 20 | public: |
---|
| 21 | typedef enum |
---|
| 22 | { |
---|
| 23 | None = 0, |
---|
| 24 | Fragment = 1, |
---|
| 25 | Vertex = 2, |
---|
[1853] | 26 | |
---|
[7818] | 27 | Program = 4, |
---|
| 28 | } Type; |
---|
| 29 | |
---|
[5323] | 30 | public: |
---|
[7221] | 31 | Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); |
---|
[5261] | 32 | virtual ~Shader(); |
---|
[7221] | 33 | static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile); |
---|
[5323] | 34 | static bool unload(Shader* shader); |
---|
[1853] | 35 | |
---|
[7818] | 36 | |
---|
| 37 | static bool checkShaderAbility(); |
---|
[5266] | 38 | void activateShader(); |
---|
| 39 | static void deactivateShader(); |
---|
[3245] | 40 | |
---|
[7818] | 41 | |
---|
| 42 | bool loadShaderProgramm(Shader::Type type, const std::string& fileName); |
---|
| 43 | void deleteProgram(Shader::Type type); |
---|
| 44 | |
---|
| 45 | void linkShaderProgram(); |
---|
| 46 | |
---|
| 47 | |
---|
[7822] | 48 | bool readShader(const std::string& fileName, std::string& output); |
---|
[5266] | 49 | |
---|
[5317] | 50 | |
---|
[7195] | 51 | inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; |
---|
[5323] | 52 | inline static Shader* getActiveShader() { return Shader::storedShader; }; |
---|
[5318] | 53 | inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; |
---|
[5317] | 54 | inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; |
---|
| 55 | |
---|
| 56 | |
---|
[7818] | 57 | GLhandleARB getProgram() const { return this->shaderProgram; } |
---|
| 58 | GLhandleARB getVertexS() const { return this->vertexShader; } |
---|
| 59 | GLhandleARB getFragmentS() const { return this->fragmentShader; } |
---|
| 60 | |
---|
[5262] | 61 | void debug() const; |
---|
| 62 | |
---|
[7818] | 63 | static void printError(GLhandleARB program); |
---|
[5262] | 64 | |
---|
[7818] | 65 | |
---|
[3245] | 66 | private: |
---|
[7221] | 67 | std::string fragmentShaderFile; |
---|
| 68 | std::string vertexShaderFile; |
---|
[7818] | 69 | |
---|
[5319] | 70 | GLhandleARB shaderProgram; |
---|
[7818] | 71 | |
---|
[5319] | 72 | GLhandleARB vertexShader; |
---|
| 73 | GLhandleARB fragmentShader; |
---|
[5317] | 74 | |
---|
| 75 | static Shader* storedShader; |
---|
[1853] | 76 | }; |
---|
| 77 | |
---|
[5261] | 78 | #endif /* _SHADER_H */ |
---|