GLSLProgram.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(__INCLUDE_GLSLProgramh_INCLUDE__)
00022 #define __INCLUDE_GLSLProgramh_INCLUDE__
00023 
00024 #include <list>
00025 #include <string>
00026 #include <GLSL/GLSLShader.h>
00027 #include <GLEXT/GLTexture.h>
00028 #include <GLEXT/GLShadowFrameBuffer.h>
00029 #include <common/Vector.h>
00030 
00031 /// this class handles an OpenGL GLSL Program, that is a link unit of shaders.
00032 ///@note needs OpenGL 2.0
00033 class GLSLProgram
00034 {
00035 public:
00036         GLSLProgram();
00037         ~GLSLProgram();
00038 
00039         /// attach a shader
00040         void attach(GLSLShader &s);
00041 
00042         /// attach a shader
00043         void detach(GLSLShader &s);
00044 
00045         /// link program after all shaders are attached
00046         void link();
00047 
00048         /// use this program
00049         ///@note link program before using it!
00050         void use() const;
00051 
00052         /// use fixed function pipeline instead of particular program
00053         static void use_fixed();
00054 
00055         /// set up texture for a particular shader name
00056         void set_gl_texture(GLTexture& tex, const char *texName, unsigned texunit) const;
00057         void set_gl_texture(GLShadowFrameBuffer &tex, const char *texName, unsigned texunit) const;
00058         void set_gl_texture_unit(const char *texname, unsigned texunit) const;
00059 
00060         /// set uniform variable
00061         void set_uniform(const char *name, const Vector& value) const;
00062         void set_uniform(const char *name, const float value) const;
00063 
00064         /// get vertex attribute index
00065         unsigned get_vertex_attrib_index(const char *name) const;
00066 
00067  protected:
00068         unsigned int id_;
00069         bool linked_;
00070         std::list<GLSLShader*> attached_shaders_;
00071         static const GLSLProgram* used_program_;
00072 
00073  private:
00074         GLSLProgram(const GLSLProgram&);
00075         GLSLProgram& operator= (const GLSLProgram&);
00076 };
00077 
00078 #endif // __INCLUDE_GLSLProgramh_INCLUDE__

Generated on Mon Feb 16 15:14:45 2009 for Scorched3D by  doxygen 1.5.3