| 1 | /*! |
|---|
| 2 | * @file shader_data.h |
|---|
| 3 | * @brief Definition of the Shader rendering class |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | #ifndef _SHADER_DATA_H |
|---|
| 7 | #define _SHADER_DATA_H |
|---|
| 8 | |
|---|
| 9 | #include "base_object.h" |
|---|
| 10 | |
|---|
| 11 | #include "glincl.h" |
|---|
| 12 | #include <vector> |
|---|
| 13 | #include "count_pointer.h" |
|---|
| 14 | |
|---|
| 15 | // FORWARD DECLARATION |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | //! The ShaderData is a Class-wrapper around the OpenGL Shader Language (GLSL). |
|---|
| 20 | class ShaderData : public BaseObject |
|---|
| 21 | { |
|---|
| 22 | ObjectListDeclaration(ShaderData); |
|---|
| 23 | //! The Type of Shader. |
|---|
| 24 | typedef enum { |
|---|
| 25 | None = 0, //!< No Type at all |
|---|
| 26 | Fragment = 1, //!< Fragment Shader. |
|---|
| 27 | Vertex = 2, //!< Vertex Shader. |
|---|
| 28 | Program = 4, //!< Compiled Shader Programm. |
|---|
| 29 | } Type; |
|---|
| 30 | |
|---|
| 31 | public: |
|---|
| 32 | typedef CountPointer<ShaderData> Pointer; |
|---|
| 33 | public: |
|---|
| 34 | ShaderData(); |
|---|
| 35 | virtual ~ShaderData(); |
|---|
| 36 | |
|---|
| 37 | bool load(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | GLhandleARB getProgram() const { return this->shaderProgram; } |
|---|
| 41 | GLhandleARB getVertexS() const { return this->vertexShader; } |
|---|
| 42 | GLhandleARB getFragmentS() const { return this->fragmentShader; } |
|---|
| 43 | |
|---|
| 44 | void activateShader(); |
|---|
| 45 | |
|---|
| 46 | void debug() const; |
|---|
| 47 | private: |
|---|
| 48 | void bindShader(const char* name, const float* value, size_t size); |
|---|
| 49 | void linkShaderProgram(); |
|---|
| 50 | bool readShader(const std::string& fileName, std::string& output); |
|---|
| 51 | bool loadShaderProgramm(ShaderData::Type type, const std::string& fileName); |
|---|
| 52 | void deleteProgram(ShaderData::Type type); |
|---|
| 53 | |
|---|
| 54 | static void printError(GLhandleARB program); |
|---|
| 55 | |
|---|
| 56 | private: |
|---|
| 57 | |
|---|
| 58 | std::string fragmentShaderFile; |
|---|
| 59 | std::string vertexShaderFile; |
|---|
| 60 | |
|---|
| 61 | GLhandleARB shaderProgram; |
|---|
| 62 | |
|---|
| 63 | GLhandleARB vertexShader; |
|---|
| 64 | GLhandleARB fragmentShader; |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| 67 | #endif /* _SHADER_DATA_H */ |
|---|