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

Cg.h

Go to the documentation of this file.
00001 
00024 #ifndef __GOV_CG_PROGRAMS
00025 #define __GOV_CG_PROGRAMS
00026 
00027 #include <string>
00028 #include <map>
00029 
00030 #include <Cg/cgGL.h>
00031 
00032 using namespace std;
00033 
00034 
00036 
00042 class CgObjects* Cg();
00043 
00045 
00046 char* fragmentProgramDir();
00048 
00049 char* vertexProgramDir();
00050 
00051 
00052 
00053 
00055 
00058 void releaseCg();
00059 
00061 
00066 class CgObjects
00067 {
00068  public:
00069   
00070   // Default constructor
00071   CgObjects();
00072   // Destructor
00073   virtual ~CgObjects();
00074     
00075   // Access to fragment profile
00076   CGprofile fragmentProfile();
00077   const CGprofile fragmentProfile() const;
00078       
00079   // Access to vertex profile
00080   CGprofile vertexProfile();
00081   const CGprofile vertexProfile() const;
00082   
00083   // Access to shader context
00084   CGcontext shaderContext();
00085   const CGcontext shaderContext() const;
00086 
00087 
00088  private:
00089   
00090   // Private error callback function
00091   static void cgErrorCallback(void);
00092   
00093   // Profile for fragment programs
00094   CGprofile _fragmentProfile;
00095   // Profile for vertex programs
00096   CGprofile _vertexProfile;
00097   // Context for shaders
00098   CGcontext _shaderContext;
00099 };
00100 
00101 
00103 
00107 class CgProgram
00108 {
00109  public:
00110 
00111   // Default constructor
00112   CgProgram();
00113   // Destructor
00114   virtual ~CgProgram();
00115     
00116   // Set the filename containing the shader source
00117   void setFilename( const string &fn );
00118   // Initialize program profile
00119   void initProfile( CGprofile p );
00120 
00121   // Setup, loads program from harddrive
00123   virtual void setup();
00124 
00125   // Enable the program
00126   virtual void enable();
00127   // Disable the program
00128   virtual void disable();
00129 
00130   // Read the handle of a parameter of the fragment program
00131   virtual CGparameter parameter( const string &var );
00132 
00133   // Set program parameter using parameter ID
00134   void setParameter( const CGparameter &p, int n, const float *v ) const;
00135   // Set program parameter using parameter name (as in Cg program)
00136   void setParameter( const string &pname, int n, const float *v );
00137 
00138 
00139  private:
00140 
00141   // Program code
00142   CGprogram _Program;
00143   // Profile the program uses
00144   CGprofile _Profile;
00145 
00146   // Parameters for the program
00147   map<string,CGparameter> _parameters;
00148   // Filename for the shader source code
00149   string _filename;
00150 };
00151 
00152 
00153 // A Cg Fragment program
00155 class CgFragmentProgram : public CgProgram
00156 {
00157  public:
00158   // Constructor using a file containing the shader source code
00159   CgFragmentProgram();
00160   // Destructor
00161   virtual ~CgFragmentProgram();
00162   
00163   // Setup, loads fragment program from harddrive
00165   virtual void setup();
00166 
00167   // Enable the fragment program and all associated textures
00168   virtual void enable();
00169   // Disable the program and all textures
00170   virtual void disable();
00171 
00172   // Bind a texture handle to a parameter of the fragment program
00173   virtual void bindTexture( const string &var, GLuint T );
00174   // Bind a texture handle to a parameter of the fragment program
00175   virtual void bindTexture( const CGparameter &p, GLuint T  );
00176   
00177 
00178  private:
00179 
00180   // Textures bound to parameters
00181   map<CGparameter,GLuint> _textures;
00182 };
00183 
00184 
00185 
00186 
00188 
00189 class CgVertexProgram : public CgProgram
00190 {
00191  public:
00192   // Constructor using a file containing the shader source code
00193   CgVertexProgram();
00194   // Destructor
00195   virtual ~CgVertexProgram();
00196 
00197   // Setup the program
00198   virtual void setup();
00199 
00200   // Set transformation matrix state
00207   void setStateMatrixParameter( const CGparameter &p,
00208                                 const CGGLenum matrix,
00209                                 const CGGLenum transform=CG_GL_MATRIX_IDENTITY ) const;
00210   
00211   // Set transformation matrix state
00218   void setStateMatrixParameter( const string &pname,
00219                                 const CGGLenum matrix,
00220                                 const CGGLenum transform=CG_GL_MATRIX_IDENTITY );
00221 };
00222 
00223 
00224 #endif

Generated on Thu Jan 20 02:47:12 2005 for Projective_Texture_Effect_Demo by doxygen 1.3.6