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

shadermanager.h

Go to the documentation of this file.
00001 // shadermanager.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_SHADERMANAGER_H_
00011 #define _CELENGINE_SHADERMANAGER_H_
00012 
00013 #include <map>
00014 #include <iostream>
00015 #include <celengine/glshader.h>
00016 
00017 class ShaderProperties
00018 {
00019  public:
00020     ShaderProperties();
00021     bool usesShadows() const;
00022     bool usesFragmentLighting() const;
00023     unsigned int getShadowCountForLight(unsigned int) const;
00024     void setShadowCountForLight(unsigned int, unsigned int);
00025     bool hasShadowsForLight(unsigned int) const;
00026 
00027  enum
00028  {
00029      DiffuseTexture         = 0x01,
00030      SpecularTexture        = 0x02,
00031      NormalTexture          = 0x04,
00032      NightTexture           = 0x08,
00033      SpecularInDiffuseAlpha = 0x10,
00034      RingShadowTexture      = 0x20,
00035  };
00036 
00037  enum
00038  {
00039      DiffuseModel     = 0,
00040      SpecularModel    = 1,
00041      RingIllumModel   = 2,
00042  };
00043 
00044  public:
00045     unsigned short nLights;
00046     unsigned short texUsage;
00047     unsigned short lightModel;
00048 
00049     // Two bits per light, up to eight lights + three shadows per light
00050     unsigned short shadowCounts;
00051 };
00052 
00053 
00054 static const unsigned int MaxShaderLights = 4;
00055 static const unsigned int MaxShaderShadows = 3;
00056 struct CelestiaGLProgramLight
00057 {
00058     Vec3ShaderParameter direction;
00059     Vec3ShaderParameter diffuse;
00060     Vec3ShaderParameter specular;
00061     Vec3ShaderParameter halfVector;
00062 };
00063 
00064 struct CelestiaGLProgramShadow
00065 {
00066     Vec4ShaderParameter texGenS;
00067     Vec4ShaderParameter texGenT;
00068     FloatShaderParameter scale;
00069     FloatShaderParameter bias;
00070 };
00071 
00072 class CelestiaGLProgram
00073 {
00074  public:
00075     CelestiaGLProgram(GLProgram& _program, const ShaderProperties&);
00076     ~CelestiaGLProgram();
00077 
00078     void use() const { program->use(); }
00079     
00080  public:
00081     CelestiaGLProgramLight lights[MaxShaderLights];
00082     Vec3ShaderParameter fragLightColor[MaxShaderLights];
00083     Vec3ShaderParameter fragLightSpecColor[MaxShaderLights];
00084     Vec3ShaderParameter eyePosition;
00085     FloatShaderParameter shininess;
00086     Vec3ShaderParameter ambientColor;
00087 
00088     FloatShaderParameter ringWidth;
00089     FloatShaderParameter ringRadius;
00090 
00091     FloatShaderParameter textureOffset;
00092 
00093     CelestiaGLProgramShadow shadows[MaxShaderLights][MaxShaderShadows];
00094     
00095  private:
00096     void initParameters(const ShaderProperties&);
00097     void initSamplers(const ShaderProperties&);
00098 
00099     FloatShaderParameter floatParam(const std::string&);
00100     Vec3ShaderParameter vec3Param(const std::string&);
00101     Vec4ShaderParameter vec4Param(const std::string&);
00102 
00103     GLProgram* program;
00104 };
00105 
00106 
00107 class ShaderManager
00108 {
00109  public:
00110     ShaderManager();
00111     ~ShaderManager();
00112 
00113     CelestiaGLProgram* getShader(const ShaderProperties&);
00114 
00115  private:
00116     CelestiaGLProgram* buildProgram(const ShaderProperties&);
00117     GLVertexShader* buildVertexShader(const ShaderProperties&);
00118     GLFragmentShader* buildFragmentShader(const ShaderProperties&);
00119     GLVertexShader* buildRingsVertexShader(const ShaderProperties&);
00120     GLFragmentShader* buildRingsFragmentShader(const ShaderProperties&);
00121 
00122     std::map<ShaderProperties, CelestiaGLProgram*> shaders;
00123 };
00124 
00125 extern ShaderManager& GetShaderManager();
00126 
00127 #endif // _CELENGINE_SHADERMANAGER_H_

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