Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/shader.h @ 10118

Last change on this file since 10118 was 10118, checked in by patrick, 17 years ago

added the copy construtor and tried fixing the shader resource bug. no success

File size: 3.3 KB
Line 
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 "shader_data.h"
11
12// FORWARD DECLARATION
13
14
15
16//! The Shader is a Class-wrapper around the OpenGL Shader Language (GLSL).
17class Shader : public BaseObject
18{
19  ObjectListDeclaration(Shader);
20public:
21  class Uniform
22  {
23  public:
24          Uniform(const Shader& shader, const std::string& location) { if (Shader::isSupported()) this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
25          Uniform(GLhandleARB shaderProgram, const std::string& location) { if (Shader::isSupported()) this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; };
26
27    void set(float v0) const { if (Shader::isSupported()) glUniform1f(this->uniform, v0); }
28    void set(float v0, float v1) const { if (Shader::isSupported()) glUniform2f(this->uniform, v0, v1); }
29    void set(float v0, float v1, float v2) const { if (Shader::isSupported()) glUniform3f(this->uniform, v0, v1, v2); }
30    void set(float v0, float v1, float v2, float v3) const { if (Shader::isSupported()) glUniform4f(this->uniform, v0, v1, v2, v3); }
31
32    void set(int v0) const { if (Shader::isSupported()) glUniform1i(this->uniform, v0); }
33    void set(int v0, int v1) const { if (Shader::isSupported()) glUniform2i(this->uniform, v0, v1); }
34    void set(int v0, int v1, int v2) const { if (Shader::isSupported()) glUniform3i(this->uniform, v0, v1, v2); }
35    void set(int v0, int v1, int v2, int v3) const {if (Shader::isSupported())  glUniform4i(this->uniform, v0, v1, v2, v3); }
36
37    void setV(unsigned int count, float* vv) const;
38    void setV(unsigned int count, int* vv) const;
39
40  private:
41    GLint uniform;
42  };
43
44
45public:
46  Shader();
47  Shader(const Shader& shader);
48  Shader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = "");
49
50  Shader& operator=(const Shader& shader) { this->data = shader.data; return *this; };
51  const ShaderData::Pointer& dataPointer() const { return data; };
52  void acquireData(const ShaderData::Pointer& pointer) { this->data = pointer; };
53
54  bool load(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = "")
55    { return this->data->load(vertexShaderFile, fragmentShaderFile); }
56
57
58  Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(*this, location); }
59
60  GLhandleARB getProgram() const { return this->data->getProgram(); }
61  GLhandleARB getVertexS() const { return this->data->getVertexS(); }
62  GLhandleARB getFragmentS() const { return this->data->getFragmentS(); }
63
64  void activateShader() const;
65  static void deactivateShader();
66
67  void debug() const { this->data->debug(); };
68
69
70  static bool checkShaderAbility();
71  static bool isSupported() { return checkShaderAbility(); };
72
73  inline static bool isShaderActive() { return (Shader::storedShader != NULL) ? true : false; };
74  inline static const Shader* getActiveShader() { return Shader::storedShader; };
75
76  inline static void suspendShader() { const Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
77  inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
78
79private:
80  ShaderData::Pointer    data;
81
82  static const Shader*         storedShader;
83};
84
85#endif /* _SHADER_H */
Note: See TracBrowser for help on using the repository browser.