Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

/Users/blackie/Documents/myRepository/phobosengine-vc2005/phobosengine/phobosengine/LightShader.h

Go to the documentation of this file.
00001 
00002 
00003 #ifndef LIGHTSHADER_H
00004 #define LIGHTSHADER_H
00005 
00006 
00007 #include "Camera.h"
00008 #include "CoreEngine.h"
00009 #include "DayNightCycle.h"
00010 #include "GPUProgram.h"
00011 #include "Light.h"
00012 #include "Renderer.h"
00013 #include "TextureDatabase.h"
00014 #include "Texture.h"
00015 #include "ValueFader.h"
00016 #include "Vector3f.h"
00017 #include "Vector4f.h"
00018 #include "World.h"
00019 
00020 #include <vector>
00021 
00022 
00023 namespace pge {
00024 
00025 
00026         class LightShader {
00027 
00028 
00029         public:
00030                 //************************************************************************
00031                 //
00032                 // Constructor
00033                 //
00034                 //************************************************************************
00036                 LightShader(GPUProgram *lightProgram) {
00037                         m_program = lightProgram;
00038                 }
00039 
00040 
00041                 //************************************************************************
00042                 //
00043                 // Destructor
00044                 //
00045                 //************************************************************************
00047                 virtual ~LightShader(void) {
00048                         m_program = NULL;
00049                 }
00050 
00051 
00052                 //************************************************************************
00053                 //
00054                 // Functions
00055                 //
00056                 //************************************************************************
00057                 //
00058                 //
00059                 //
00060                 bool addActiveLight(Light *light) {
00061                         if(m_activeLights.size() >= 3) {
00062                                 return false;
00063                         } else {
00064                                 m_activeLights.push_back(light);
00065                                 return true;
00066                         }
00067                 }
00068 
00069 
00070                 //
00071                 //
00072                 //
00073                 void preRender(void) {
00074                         if(m_activeLights.size() != 3) {
00075                                 return;
00076                         }
00077                         Light *light0 = m_activeLights.at(0);
00078                         Light *light1 = m_activeLights.at(1);
00079                         Light *light2 = m_activeLights.at(2);
00080 
00081                         m_program->bind();
00082                         m_program->passUniform1f("dayNightCycle", DayNightCycle::getInstance()->getDayNightCycle());
00083                         m_program->passUniform4f("lightPosition0", light0->m_position);
00084                         m_program->passUniform4f("lightColor0", light0->m_diffuse);
00085 
00086                         m_program->passUniform4f("lightPosition1", light1->m_position);
00087                         m_program->passUniform4f("lightColor1", light1->m_diffuse);
00088 
00089                         m_program->passUniform4f("lightPosition2", light2->m_position);
00090                         m_program->passUniform4f("lightColor2", light2->m_diffuse);
00091                         m_program->passUniform1i("texture", 0);
00092                 }
00093 
00094 
00095                 //
00096                 //
00097                 //
00098                 void postRender(void) {
00099                         if(m_activeLights.size() != 3) {
00100                                 return;
00101                         }
00102                         m_program->release();
00103                 }
00104 
00105 
00106         private:
00107                 //************************************************************************
00108                 //
00109                 // Functions
00110                 //
00111                 //************************************************************************
00112 
00113 
00114                 //************************************************************************
00115                 //
00116                 // Variables
00117                 //
00118                 //************************************************************************
00119                 GPUProgram *m_program;
00120                 std::vector<Light*> m_activeLights;
00121         };
00122 };
00123 
00124 #endif

Generated on Mon Oct 16 12:08:10 2006 for Phobosengine by doxygen 1.3.4