Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

glshader.h

Go to the documentation of this file.
00001 // glshader.h
00002 //
00003 // Copyright (C) 2001-2004, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #ifndef _CELENGINE_GLSHADER_H_
00011 #define _CELENGINE_GLSHADER_H_
00012 
00013 #include <string>
00014 #include <vector>
00015 #include <iostream>
00016 #include <celmath/vecmath.h>
00017 
00018 class GLShaderLoader;
00019 
00020 enum GLShaderStatus
00021 {
00022     ShaderStatus_OK,
00023     ShaderStatus_CompileError,
00024     ShaderStatus_LinkError,
00025     ShaderStatus_OutOfMemory,
00026     ShaderStatus_EmptyProgram,
00027 };
00028 
00029 class GLShader
00030 {
00031  protected:
00032     GLShader(int _id);
00033     virtual ~GLShader();
00034 
00035  public:
00036     int getID() const;
00037 
00038  private:
00039     int id;
00040 
00041     GLShaderStatus compile(const std::vector<std::string>& source);
00042 
00043     friend class GLShaderLoader;
00044 };
00045 
00046 
00047 class GLVertexShader : public GLShader
00048 {
00049  private:
00050     GLVertexShader(int _id) : GLShader(_id) {};
00051 
00052  friend class GLShaderLoader;
00053 };
00054 
00055 
00056 class GLFragmentShader : public GLShader
00057 {
00058  private:
00059     GLFragmentShader(int _id) : GLShader(_id) {};
00060 
00061  friend class GLShaderLoader;
00062 };
00063 
00064 
00065 class GLProgram
00066 {
00067  private:
00068     GLProgram(int _id);
00069 
00070     void attach(const GLShader&);
00071 
00072  public:
00073     virtual ~GLProgram();
00074 
00075     GLShaderStatus link();
00076 
00077     void use() const;
00078     int getID() const { return id; }
00079 
00080  private:
00081     int id;
00082 
00083  friend class GLShaderLoader;
00084 };
00085 
00086 
00087 class FloatShaderParameter
00088 {
00089  public:
00090     FloatShaderParameter();
00091     FloatShaderParameter(int _obj, const char* name);
00092 
00093     FloatShaderParameter& operator=(float);
00094     
00095  private:
00096     int slot;
00097 };
00098 
00099 
00100 class Vec3ShaderParameter
00101 {
00102  public:
00103     Vec3ShaderParameter();
00104     Vec3ShaderParameter(int _obj, const char* name);
00105 
00106     Vec3ShaderParameter& operator=(const Vec3f&);
00107     Vec3ShaderParameter& operator=(const Point3f&);
00108 
00109  private:
00110     int slot;
00111 };
00112 
00113 
00114 class Vec4ShaderParameter
00115 {
00116  public:
00117     Vec4ShaderParameter();
00118     Vec4ShaderParameter(int _obj, const char* name);
00119 
00120     Vec4ShaderParameter& operator=(const Vec4f&);
00121 
00122  private:
00123     int slot;
00124 };
00125 
00126 
00127 
00128 class GLShaderLoader
00129 {
00130  public:
00131     static GLShaderStatus CreateVertexShader(const std::vector<std::string>&,
00132                                              GLVertexShader**);
00133     static GLShaderStatus CreateFragmentShader(const std::vector<std::string>&,
00134                                                GLFragmentShader**);
00135     static GLShaderStatus CreateVertexShader(const std::string&,
00136                                              GLVertexShader**);
00137     static GLShaderStatus CreateFragmentShader(const std::string&,
00138                                                GLFragmentShader**);
00139 
00140     static GLShaderStatus CreateProgram(const GLVertexShader& vs,
00141                                         const GLFragmentShader& fs,
00142                                         GLProgram**);
00143     static GLShaderStatus CreateProgram(const std::vector<std::string>& vs,
00144                                         const std::vector<std::string>& fs,
00145                                         GLProgram**);
00146     static GLShaderStatus CreateProgram(const std::string& vs,
00147                                         const std::string& fs,
00148                                         GLProgram**);
00149 };
00150 
00151 
00152 extern std::ostream* g_shaderLogFile;
00153 
00154 #endif // _CELENGINE_GLSHADER_H_

Generated on Sat Jan 14 22:30:27 2006 for Celestia by  doxygen 1.4.1