• Main Page
  • Classes
  • Files
  • File List

T:/Eigene Dateien/Visual Studio 2008/Projects/VisLuFramework/src/Shader.hpp

00001 #ifndef SHADER_HPP
00002 #define SHADER_HPP
00003 
00004 #include <string>
00005 
00006 #include "common.h"
00007 #include "GlewContentManagement.h"
00008 
00009 using namespace std;
00017 class Shader
00018 {
00019 public:
00020 
00021         // Loads shaders from files and compiles them.
00022         // When path is "hello", the files "hello.frag" & "hello.vert"
00023         // will be loaded.
00024         Shader(const string &path);
00025         ~Shader();
00026 
00027         bool wasSuccessfullyLinked();
00028 
00029         // Bind the shader to the OGL state-machine
00030         void bind() const
00031         {
00032                 glUseProgram(_program);
00033         }
00034 
00035         // Unbind the shader
00036         void unbind() const
00037         {
00038                 glUseProgram(0);
00039         }
00040 
00041         // Query the location of a vertex attribute inside the shader.
00042         GLint get_attrib_location(const std::string &name) const
00043         {
00044                 return glGetAttribLocation(_program, name.c_str());
00045         }
00046 
00047         // Query the location of a uniform variable inside the shader.
00048         GLint get_uniform_location(const std::string &name) const
00049         {
00050                 return glGetUniformLocation(_program, name.c_str());
00051         }
00052 
00053         // Define the name of the variable inside the shader which represents the final color for each fragment.
00054         void bind_frag_data_location(const std::string &name)
00055         {
00056                 if(_program > 0)
00057                 {
00058                         glBindFragDataLocation(_program, 0, name.c_str() );
00059                         link();
00060                 }
00061         }
00062 
00063         // A little cast helper.
00064         // With this you can simply do "if (shader) {...}" to test if a
00065         // shader has been compiled successfully.
00066         operator bool ()
00067         {
00068                 return _success;
00069         }
00070 
00071 private:
00072 
00073         bool _success;
00074 
00075         GLuint _vertex_shader;
00076         GLuint _fragment_shader;
00077         GLuint _program;
00078 
00079         GLuint compile(GLenum type, const string &source);
00080         void link (void);
00081 
00082         void shader_log(GLuint shader);
00083         void program_log(GLuint program);
00084 };
00085 
00086 #endif

Generated on Tue Dec 14 2010 03:52:55 for VolVis by  doxygen 1.7.2