Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10036 was 9942, checked in by bensch, 18 years ago

HACK: Checking shader ability
@orxonoxers: make this faster

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