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

ShaderManager Class Reference

#include <shadermanager.h>

List of all members.

Public Member Functions

CelestiaGLProgramgetShader (const ShaderProperties &)
 ShaderManager ()
 ~ShaderManager ()

Private Member Functions

GLFragmentShaderbuildFragmentShader (const ShaderProperties &)
CelestiaGLProgrambuildProgram (const ShaderProperties &)
GLFragmentShaderbuildRingsFragmentShader (const ShaderProperties &)
GLVertexShaderbuildRingsVertexShader (const ShaderProperties &)
GLVertexShaderbuildVertexShader (const ShaderProperties &)

Private Attributes

std::map< ShaderProperties,
CelestiaGLProgram * > 
shaders


Constructor & Destructor Documentation

ShaderManager::ShaderManager  ) 
 

Definition at line 123 of file shadermanager.cpp.

References g_shaderLogFile.

00124 {
00125     if (g_shaderLogFile == NULL)
00126 #ifdef _WIN32
00127         g_shaderLogFile = new ofstream("shaders.log");
00128 #else
00129         g_shaderLogFile = new ofstream("/tmp/celestia-shaders.log");
00130 #endif
00131 }

ShaderManager::~ShaderManager  ) 
 

Definition at line 134 of file shadermanager.cpp.

00135 {
00136 }


Member Function Documentation

GLFragmentShader * ShaderManager::buildFragmentShader const ShaderProperties  )  [private]
 

Definition at line 745 of file shadermanager.cpp.

References GLShaderLoader::CreateFragmentShader(), DumpShaderSource(), FragLightProperty(), g_shaderLogFile, IndexedParameter(), LightDir(), SeparateSpecular(), ShaderStatus_OK, and ShadowsForLightSource().

Referenced by buildProgram().

00746 {
00747     string source;
00748 
00749     if (props.usesFragmentLighting() || props.usesShadows())
00750     {
00751         source += "uniform vec3 ambientColor;\n";
00752         source += "vec4 diff = vec4(ambientColor, 1.0);\n";
00753         for (unsigned int i = 0; i < props.nLights; i++)
00754         {
00755             source += "uniform vec3 " + FragLightProperty(i, "color") + ";\n";
00756             if (props.lightModel == ShaderProperties::SpecularModel)
00757             {
00758                 source += "uniform vec3 " +
00759                     FragLightProperty(i, "specColor") + ";\n";
00760             }
00761         }
00762     }
00763     else
00764     {
00765         source += "varying vec4 diff;\n";
00766     }
00767 
00768     if (props.usesShadows() && !props.usesFragmentLighting())
00769     {
00770         source += "varying vec4 diffFactors;\n";
00771     }
00772 
00773     if (props.lightModel == ShaderProperties::SpecularModel)
00774     {
00775         if (props.usesShadows())
00776         {
00777             source += "varying vec4 specFactors;\n";
00778             source += "vec4 spec;\n";
00779         }
00780         else
00781         {
00782             source += "varying vec4 spec;\n";
00783         }
00784     }
00785 
00786     if (props.texUsage & ShaderProperties::DiffuseTexture)
00787     {
00788         source += "varying vec2 diffTexCoord;\n";
00789         source += "uniform sampler2D diffTex;\n";
00790     }
00791 
00792     if (props.texUsage & ShaderProperties::NormalTexture)
00793     {
00794         source += "varying vec2 normTexCoord;\n";
00795         for (unsigned int i = 0; i < props.nLights; i++)
00796             source += "varying vec3 " + LightDir(i) + ";\n";
00797         source += "uniform sampler2D normTex;\n";
00798     }
00799 
00800     if (props.texUsage & ShaderProperties::SpecularTexture)
00801     {
00802         source += "varying vec2 specTexCoord;\n";
00803         source += "uniform sampler2D specTex;\n";
00804     }
00805 
00806     if (props.texUsage & ShaderProperties::NightTexture)
00807     {
00808         source += "varying vec2 nightTexCoord;\n";
00809         source += "uniform sampler2D nightTex;\n";
00810         source += "varying float totalLight;\n";
00811     }
00812 
00813     if (props.texUsage & ShaderProperties::RingShadowTexture)
00814     {
00815         source += "uniform sampler2D ringTex;\n";
00816         source += "varying vec4 ringShadowTexCoord;\n";
00817     }
00818 
00819     if (props.shadowCounts != 0)
00820     {
00821         for (unsigned int i = 0; i < props.nLights; i++)
00822         {
00823             for (unsigned int j = 0; j < props.getShadowCountForLight(i); j++)
00824             {
00825                 source += "varying vec2 " +
00826                     IndexedParameter("shadowTexCoord", i, j) + ";\n";
00827                 source += "uniform float " +
00828                     IndexedParameter("shadowScale", i, j) + ";\n";
00829                 source += "uniform float " +
00830                     IndexedParameter("shadowBias", i, j) + ";\n";
00831             }
00832         }
00833     }
00834 
00835     source += "\nvoid main(void)\n{\n";
00836     source += "vec4 color;\n";
00837 
00838     if (props.usesShadows())
00839     {
00840         // Temporaries required for shadows
00841         source += "float shadow;\n";
00842         if (props.shadowCounts != 0)
00843         {
00844             source += "vec2 shadowCenter;\n";
00845             source += "float shadowR;\n";
00846         }
00847     }
00848 
00849     if (props.texUsage & ShaderProperties::NormalTexture)
00850     {
00851         source += "vec3 n = texture2D(normTex, normTexCoord.st).xyz * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);\n";
00852         source += "float l;\n";
00853         for (unsigned i = 0; i < props.nLights; i++)
00854         {
00855             // Bump mapping with self shadowing
00856             source += "l = max(0.0, dot(" + LightDir(i) + ", n)) * clamp(" + LightDir(i) + ".z * 8.0, 0.0, 1.0);\n";
00857 
00858             string illum;
00859             if (props.hasShadowsForLight(i))
00860                 illum = string("l * shadow");
00861             else
00862                 illum = string("l");
00863 
00864             if (props.hasShadowsForLight(i))
00865                 source += ShadowsForLightSource(props, i);
00866 
00867             source += "diff.rgb += " + illum + " * " +
00868                 FragLightProperty(i, "color") + ";\n";
00869 
00870             if (props.lightModel == ShaderProperties::SpecularModel &&
00871                 props.usesShadows())
00872             {
00873                 source += "spec.rgb += " + illum + " * " + SeparateSpecular(i) +
00874                     " * " + FragLightProperty(i, "specColor") +
00875                     ";\n";
00876             }
00877         }
00878     }
00879     else if (props.usesShadows())
00880     {
00881         // Sum the contributions from each light source
00882         for (unsigned i = 0; i < props.nLights; i++)
00883         {
00884             source += ShadowsForLightSource(props, i);
00885             source += "diff.rgb += shadow * " +
00886                 FragLightProperty(i, "color") + ";\n";
00887             if (props.lightModel == ShaderProperties::SpecularModel)
00888             {
00889                 source += "spec.rgb += shadow * " + SeparateSpecular(i) +
00890                     " * " +
00891                     FragLightProperty(i, "specColor") + ";\n";
00892             }
00893         }
00894     }
00895 
00896     if (props.texUsage & ShaderProperties::DiffuseTexture)
00897         source += "color = texture2D(diffTex, diffTexCoord.st);\n";
00898     else
00899         source += "color = vec4(1.0, 1.0, 1.0, 1.0);\n";
00900 
00901     if (props.lightModel == ShaderProperties::SpecularModel)
00902     {
00903         if (props.texUsage & ShaderProperties::SpecularInDiffuseAlpha)
00904             source += "gl_FragColor = color * diff + float(color.a) * spec;\n";
00905         else if (props.texUsage & ShaderProperties::SpecularTexture)
00906             source += "gl_FragColor = color * diff + texture2D(specTex, specTexCoord.st) * spec;\n";
00907         else
00908             source += "gl_FragColor = color * diff + spec;\n";
00909     }
00910     else
00911     {
00912         source += "gl_FragColor = color * diff;\n";
00913     }
00914 
00915     if (props.texUsage & ShaderProperties::NightTexture)
00916     {
00917         source += "gl_FragColor += texture2D(nightTex, nightTexCoord.st) * totalLight;\n";
00918     }
00919 
00920     source += "}\n";
00921 
00922     if (g_shaderLogFile != NULL)
00923     {
00924         *g_shaderLogFile << "Fragment shader source:\n";
00925         DumpShaderSource(*g_shaderLogFile, source);
00926         *g_shaderLogFile << '\n';
00927     }
00928     
00929     GLFragmentShader* fs = NULL;
00930     GLShaderStatus status = GLShaderLoader::CreateFragmentShader(source, &fs);
00931     if (status != ShaderStatus_OK)
00932         return NULL;
00933     else
00934         return fs;
00935 }

CelestiaGLProgram * ShaderManager::buildProgram const ShaderProperties  )  [private]
 

Definition at line 1101 of file shadermanager.cpp.

References buildFragmentShader(), buildRingsFragmentShader(), buildRingsVertexShader(), buildVertexShader(), GLShaderLoader::CreateProgram(), errorFragmentShaderSource, errorVertexShaderSource, g_shaderLogFile, GLProgram::getID(), glx::glBindAttribLocationARB, GLProgram::link(), ShaderStatus_CompileError, and ShaderStatus_OK.

Referenced by getShader().

01102 {
01103     GLProgram* prog = NULL;
01104     GLShaderStatus status;
01105 
01106     GLVertexShader* vs = NULL;
01107     GLFragmentShader* fs = NULL;
01108 
01109     if (props.lightModel == ShaderProperties::RingIllumModel)
01110     {
01111         vs = buildRingsVertexShader(props);
01112         fs = buildRingsFragmentShader(props);
01113     }
01114     else
01115     {
01116         vs = buildVertexShader(props);
01117         fs = buildFragmentShader(props);
01118     }
01119 
01120     if (vs != NULL && fs != NULL)
01121     {
01122         status = GLShaderLoader::CreateProgram(*vs, *fs, &prog);
01123         if (status == ShaderStatus_OK)
01124         {
01125             if (props.texUsage & ShaderProperties::NormalTexture)
01126             {
01127                 // Tangents always in attribute 6 (should be a constant
01128                 // someplace)
01129                 glx::glBindAttribLocationARB(prog->getID(), 6, "tangent");
01130             }
01131             status = prog->link();
01132         }
01133     }
01134     else
01135     {
01136         status = ShaderStatus_CompileError;
01137         if (vs != NULL)
01138             delete vs;
01139         if (fs != NULL)
01140             delete fs;
01141     }
01142 
01143     if (status != ShaderStatus_OK)
01144     {
01145         // If the shader creation failed for some reason, substitute the
01146         // error shader.
01147         status = GLShaderLoader::CreateProgram(errorVertexShaderSource,
01148                                                errorFragmentShaderSource,
01149                                                &prog);
01150         if (status != ShaderStatus_OK)
01151         {
01152             if (g_shaderLogFile != NULL)
01153                 *g_shaderLogFile << "Failed to create error shader!\n";
01154         }
01155         else
01156         {
01157             status = prog->link();
01158         }
01159     }
01160 
01161     if (prog == NULL)
01162         return NULL;
01163     else
01164         return new CelestiaGLProgram(*prog, props);
01165 }

GLFragmentShader * ShaderManager::buildRingsFragmentShader const ShaderProperties  )  [private]
 

Definition at line 1015 of file shadermanager.cpp.

References GLShaderLoader::CreateFragmentShader(), DumpShaderSource(), FragLightProperty(), g_shaderLogFile, IndexedParameter(), SeparateDiffuse(), ShaderStatus_OK, and Shadow().

Referenced by buildProgram().

01016 {
01017     string source;
01018 
01019     source += "uniform vec3 ambientColor;\n";
01020     source += "vec4 diff = vec4(ambientColor, 1.0);\n";
01021     for (unsigned int i = 0; i < props.nLights; i++)
01022         source += "uniform vec3 " + FragLightProperty(i, "color") + ";\n";
01023 
01024     source += "varying vec4 diffFactors;\n";
01025 
01026     if (props.texUsage & ShaderProperties::DiffuseTexture)
01027     {
01028         source += "varying vec2 diffTexCoord;\n";
01029         source += "uniform sampler2D diffTex;\n";
01030     }
01031 
01032     if (props.shadowCounts != 0)
01033     {
01034         for (unsigned int i = 0; i < props.nLights; i++)
01035         {
01036             source += "varying vec3 " +
01037                 IndexedParameter("shadowTexCoord", i, 0) + ";\n";
01038             source += "uniform float " +
01039                 IndexedParameter("shadowScale", i, 0) + ";\n";
01040             source += "uniform float " +
01041                 IndexedParameter("shadowBias", i, 0) + ";\n";
01042         }
01043     }
01044 
01045     source += "\nvoid main(void)\n{\n";
01046     source += "vec4 color;\n";
01047 
01048     if (props.usesShadows())
01049     {
01050         // Temporaries required for shadows
01051         source += "float shadow;\n";
01052         source += "vec2 shadowCenter;\n";
01053         source += "float shadowR;\n";
01054     }
01055 
01056     // Sum the contributions from each light source
01057     for (unsigned i = 0; i < props.nLights; i++)
01058     {
01059         if (props.usesShadows())
01060         {
01061             source += "shadow = 1.0;\n";
01062             source += Shadow(i, 0);
01063             source += "shadow = min(1.0, shadow + step(0.0, " +
01064                 IndexedParameter("shadowTexCoord", i, 0) + ".z));\n";
01065             source += "diff.rgb += (shadow * " + SeparateDiffuse(i) + ") * " +
01066                 FragLightProperty(i, "color") + ";\n";
01067         }
01068         else
01069         {
01070             source += "diff.rgb += " + SeparateDiffuse(i) + " * " +
01071                 FragLightProperty(i, "color") + ";\n";
01072         }
01073     }
01074 
01075     if (props.texUsage & ShaderProperties::DiffuseTexture)
01076         source += "color = texture2D(diffTex, diffTexCoord.st);\n";
01077     else
01078         source += "color = vec4(1.0, 1.0, 1.0, 1.0);\n";
01079 
01080     source += "gl_FragColor = color * diff;\n";
01081 
01082     source += "}\n";
01083 
01084     if (g_shaderLogFile != NULL)
01085     {
01086         *g_shaderLogFile << "Fragment shader source:\n";
01087         DumpShaderSource(*g_shaderLogFile, source);
01088         *g_shaderLogFile << '\n';
01089     }
01090     
01091     GLFragmentShader* fs = NULL;
01092     GLShaderStatus status = GLShaderLoader::CreateFragmentShader(source, &fs);
01093     if (status != ShaderStatus_OK)
01094         return NULL;
01095     else
01096         return fs;
01097 }

GLVertexShader * ShaderManager::buildRingsVertexShader const ShaderProperties  )  [private]
 

Definition at line 939 of file shadermanager.cpp.

References GLShaderLoader::CreateVertexShader(), DeclareLights(), DumpShaderSource(), g_shaderLogFile, IndexedParameter(), LightProperty(), SeparateDiffuse(), ShaderStatus_OK, and TexCoord2D().

Referenced by buildProgram().

00940 {
00941     string source;
00942 
00943     source += DeclareLights(props);
00944     source += "uniform vec3 eyePosition;\n";
00945 
00946     source += "varying vec4 diffFactors;\n";
00947 
00948     if (props.texUsage & ShaderProperties::DiffuseTexture)
00949         source += "varying vec2 diffTexCoord;\n";
00950 
00951     if (props.shadowCounts != 0)
00952     {
00953         for (unsigned int i = 0; i < props.nLights; i++)
00954         {
00955             source += "uniform vec4 " +
00956                 IndexedParameter("shadowTexGenS", i, 0) + ";\n";
00957             source += "uniform vec4 " +
00958                 IndexedParameter("shadowTexGenT", i, 0) + ";\n";
00959             source += "varying vec3 " +
00960                 IndexedParameter("shadowTexCoord", i, 0) + ";\n";
00961         }
00962     }
00963 
00964     source += "\nvoid main(void)\n{\n";
00965     source += "float nDotVP;\n";
00966 
00967     // Get the normalized direction from the eye to the vertex
00968     source += "vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz);\n";
00969 
00970     for (unsigned int i = 0; i < props.nLights; i++)
00971     {
00972         source += SeparateDiffuse(i) + " = (dot(" +
00973             LightProperty(i, "direction") + ", eyeDir) + 1.0) * 0.5;\n";
00974     }
00975 
00976     if (props.texUsage & ShaderProperties::DiffuseTexture)
00977         source += "diffTexCoord = " + TexCoord2D(0) + ";\n";
00978 
00979     if (props.shadowCounts != 0)
00980     {
00981         for (unsigned int i = 0; i < props.nLights; i++)
00982         {
00983             source += IndexedParameter("shadowTexCoord", i, 0) +
00984                 ".x = dot(gl_Vertex, " +
00985                 IndexedParameter("shadowTexGenS", i, 0) + ");\n";
00986             source += IndexedParameter("shadowTexCoord", i, 0) +
00987                 ".y = dot(gl_Vertex, " +
00988                 IndexedParameter("shadowTexGenT", i, 0) + ");\n";
00989             source += IndexedParameter("shadowTexCoord", i, 0) +
00990                 ".z = dot(gl_Vertex.xyz, " +
00991                 LightProperty(i, "direction") + ");\n";
00992         }
00993     }
00994 
00995     source += "gl_Position = ftransform();\n";
00996     source += "}\n";
00997 
00998     if (g_shaderLogFile != NULL)
00999     {
01000         *g_shaderLogFile << "Vertex shader source:\n";
01001         DumpShaderSource(*g_shaderLogFile, source);
01002         *g_shaderLogFile << '\n';
01003     }
01004 
01005     GLVertexShader* vs = NULL;
01006     GLShaderStatus status = GLShaderLoader::CreateVertexShader(source, &vs);
01007     if (status != ShaderStatus_OK)
01008         return NULL;
01009     else
01010         return vs;
01011 }

GLVertexShader * ShaderManager::buildVertexShader const ShaderProperties  )  [private]
 

Definition at line 551 of file shadermanager.cpp.

References GLShaderLoader::CreateVertexShader(), DeclareLights(), DirectionalLight(), DumpShaderSource(), g_shaderLogFile, IndexedParameter(), LightDir(), LightProperty(), RingShadowTexCoord(), ShaderStatus_OK, and TexCoord2D().

Referenced by buildProgram().

00552 {
00553     string source;
00554 
00555     source += DeclareLights(props);
00556     if (props.lightModel == ShaderProperties::SpecularModel)
00557         source += "uniform float shininess;\n";
00558 
00559     if (!props.usesFragmentLighting())
00560     {
00561         if (!props.usesShadows())
00562         {
00563             source += "uniform vec3 ambientColor;\n";
00564             source += "varying vec4 diff;\n";
00565         }
00566         else 
00567         {
00568             source += "varying vec4 diffFactors;\n";
00569         }
00570     }
00571 
00572     if (props.lightModel == ShaderProperties::SpecularModel)
00573     {
00574         if (!props.usesShadows())
00575             source += "varying vec4 spec;\n";
00576         else
00577             source += "varying vec4 specFactors;\n";
00578     }
00579 
00580     if (props.texUsage & ShaderProperties::DiffuseTexture)
00581         source += "varying vec2 diffTexCoord;\n";
00582     if (props.texUsage & ShaderProperties::NormalTexture)
00583     {
00584         source += "varying vec2 normTexCoord;\n";
00585         for (unsigned int i = 0; i < props.nLights; i++)
00586             source += "varying vec3 " + LightDir(i) + ";\n";
00587     }
00588     if (props.texUsage & ShaderProperties::SpecularTexture)
00589         source += "varying vec2 specTexCoord;\n";
00590     if (props.texUsage & ShaderProperties::NightTexture)
00591     {
00592         source += "varying vec2 nightTexCoord;\n";
00593         source += "varying float totalLight;\n";
00594     }
00595 
00596     if (props.texUsage & ShaderProperties::RingShadowTexture)
00597     {
00598         source += "uniform float ringWidth;\n";
00599         source += "uniform float ringRadius;\n";
00600         source += "varying vec4 ringShadowTexCoord;\n";
00601     }
00602 
00603     source += "uniform float textureOffset;\n";
00604 
00605     if (props.shadowCounts != 0)
00606     {
00607         for (unsigned int i = 0; i < props.nLights; i++)
00608         {
00609             for (unsigned int j = 0; j < props.getShadowCountForLight(i); j++)
00610             {
00611                 source += "varying vec2 " +
00612                     IndexedParameter("shadowTexCoord", i, j) + ";\n";
00613                 source += "uniform vec4 " +
00614                     IndexedParameter("shadowTexGenS", i, j) + ";\n";
00615                 source += "uniform vec4 " +
00616                     IndexedParameter("shadowTexGenT", i, j) + ";\n";
00617             }
00618         }
00619     }
00620 
00621     if (props.texUsage & ShaderProperties::NormalTexture)
00622         source += "attribute vec3 tangent;\n";
00623 
00624     source += "\nvoid main(void)\n{\n";
00625     source += "float nDotVP;\n";
00626     if (props.lightModel == ShaderProperties::SpecularModel)
00627     {
00628         source += "float nDotHV;\n";
00629     }
00630 
00631     if (!props.usesShadows() && !props.usesFragmentLighting())
00632     {
00633         source += "diff = vec4(ambientColor, 1.0);\n";
00634     }
00635         
00636     if (props.lightModel == ShaderProperties::SpecularModel && !props.usesShadows())
00637     {
00638         source += "spec = vec4(0.0, 0.0, 0.0, 0.0);\n";
00639     }
00640 
00641     if (props.texUsage & ShaderProperties::NightTexture)
00642     {
00643         source += "totalLight = 0.0;\n";
00644         }       
00645 
00646     for (unsigned int i = 0; i < props.nLights; i++)
00647     {
00648         source += DirectionalLight(i, props);
00649     }
00650 
00651     if (props.texUsage & ShaderProperties::NightTexture)
00652     {
00653         // Output the blend factor for night lights textures
00654         source += "totalLight = 1.0 - totalLight;\n";
00655         source += "totalLight = totalLight * totalLight * totalLight * totalLight;\n";
00656     }
00657 
00658     if (props.texUsage & ShaderProperties::NormalTexture)
00659     {
00660         source += "vec3 bitangent = cross(gl_Normal, tangent);\n";
00661         for (unsigned int j = 0; j < props.nLights; j++)
00662         {
00663             source += LightDir(j) + ".x = dot(tangent, " + LightProperty(j, "direction") + ");\n";
00664             source += LightDir(j) + ".y = dot(-bitangent, " + LightProperty(j, "direction") + ");\n";
00665             source += LightDir(j) + ".z = dot(gl_Normal, " + LightProperty(j, "direction") + ");\n";
00666         }
00667     }
00668 
00669     unsigned int nTexCoords = 0;
00670     if (props.texUsage & ShaderProperties::DiffuseTexture)
00671     {
00672         source += "diffTexCoord = " + TexCoord2D(nTexCoords) + ";\n";
00673         source += "diffTexCoord.x += textureOffset;\n";
00674         nTexCoords++;
00675     }
00676 
00677     if (props.texUsage & ShaderProperties::NormalTexture)
00678     {
00679         source += "normTexCoord = " + TexCoord2D(nTexCoords) + ";\n";
00680         nTexCoords++;
00681     }
00682 
00683     if (props.texUsage & ShaderProperties::SpecularTexture)
00684     {
00685         source += "specTexCoord = " + TexCoord2D(nTexCoords) + ";\n";
00686         nTexCoords++;
00687     }
00688 
00689     if (props.texUsage & ShaderProperties::NightTexture)
00690     {
00691         source += "nightTexCoord = " + TexCoord2D(nTexCoords) + ";\n";
00692         nTexCoords++;
00693     }
00694 
00695     if (props.texUsage & ShaderProperties::RingShadowTexture)
00696     {
00697         source += "vec3 ringShadowProj;\n";
00698         for (unsigned int j = 0; j < props.nLights; j++)
00699         {
00700             source += "ringShadowProj = gl_Vertex.xyz + " +
00701                 LightProperty(j, "direction") +
00702                 " * max(0.0, gl_Vertex.y / -" +
00703                 LightProperty(j, "direction") + ".y);\n";
00704             source += RingShadowTexCoord(j) +
00705                 " = (length(ringShadowProj) - ringRadius) * ringWidth;\n";
00706         }
00707     }
00708 
00709     if (props.shadowCounts != 0)
00710     {
00711         for (unsigned int i = 0; i < props.nLights; i++)
00712         {
00713             for (unsigned int j = 0; j < props.getShadowCountForLight(i); j++)
00714             {
00715                 source += IndexedParameter("shadowTexCoord", i, j) +
00716                     ".s = dot(gl_Vertex, " +
00717                     IndexedParameter("shadowTexGenS", i, j) + ");\n";
00718                 source += IndexedParameter("shadowTexCoord", i, j) +
00719                     ".t = dot(gl_Vertex, " +
00720                     IndexedParameter("shadowTexGenT", i, j) + ");\n";
00721             }
00722         }
00723     }
00724 
00725     source += "gl_Position = ftransform();\n";
00726     source += "}\n";
00727 
00728     if (g_shaderLogFile != NULL)
00729     {
00730         *g_shaderLogFile << "Vertex shader source:\n";
00731         DumpShaderSource(*g_shaderLogFile, source);
00732         *g_shaderLogFile << '\n';
00733     }
00734 
00735     GLVertexShader* vs = NULL;
00736     GLShaderStatus status = GLShaderLoader::CreateVertexShader(source, &vs);
00737     if (status != ShaderStatus_OK)
00738         return NULL;
00739     else
00740         return vs;
00741 }

CelestiaGLProgram * ShaderManager::getShader const ShaderProperties  ) 
 

Definition at line 140 of file shadermanager.cpp.

References buildProgram(), and shaders.

Referenced by GLSL_RenderContext::makeCurrent(), renderClouds_GLSL(), renderRings_GLSL(), and renderSphere_GLSL().

00141 {
00142     map<ShaderProperties, CelestiaGLProgram*>::iterator iter = shaders.find(props);
00143     if (iter != shaders.end())
00144     {
00145         // Shader already exists
00146         return iter->second;
00147     }
00148     else
00149     {
00150         // Create a new shader and add it to the table of created shaders
00151         CelestiaGLProgram* prog = buildProgram(props);
00152         shaders[props] = prog;
00153 
00154         return prog;
00155     }
00156 }


Member Data Documentation

std::map<ShaderProperties, CelestiaGLProgram*> ShaderManager::shaders [private]
 

Definition at line 122 of file shadermanager.h.

Referenced by getShader().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:35 2006 for Celestia by  doxygen 1.4.1