Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9940 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.0 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:
24    Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
25    Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; };
[5261]26
[8037]27    void set(float v0) const { glUniform1f(this->uniform, v0); }
28    void set(float v0, float v1) const { glUniform2f(this->uniform, v0, v1); }
29    void set(float v0, float v1, float v2) const { glUniform3f(this->uniform, v0, v1, v2); }
30    void set(float v0, float v1, float v2, float v3) const { glUniform4f(this->uniform, v0, v1, v2, v3); }
[5261]31
[8037]32    void set(int v0) const { glUniform1i(this->uniform, v0); }
33    void set(int v0, int v1) const { glUniform2i(this->uniform, v0, v1); }
34    void set(int v0, int v1, int v2) const { glUniform3i(this->uniform, v0, v1, v2); }
35    void set(int v0, int v1, int v2, int v3) const { 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();
[5317]70
[9869]71  inline static bool isShaderActive() { return (Shader::storedShader != NULL) ? true : false; };
72  inline static const Shader* getActiveShader() { return Shader::storedShader; };
[5317]73
[9869]74  inline static void suspendShader() { const Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
75  inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
[8037]76
77private:
[9869]78  ShaderData::Pointer    data;
[8037]79
[9869]80  static const Shader*         storedShader;
[1853]81};
82
[5261]83#endif /* _SHADER_H */
Note: See TracBrowser for help on using the repository browser.