00001
00002
00003
00004
00005 #ifndef ps2gl_lighting_h
00006 #define ps2gl_lighting_h
00007
00008 #include "GL/gl.h"
00009
00010 #include "ps2s/cpu_vector.h"
00011
00012 #include "ps2gl/debug.h"
00013 #include "ps2gl/glcontext.h"
00014 #include "ps2gl/immgmanager.h"
00015 #include "ps2gl/dlgmanager.h"
00016
00017 class CGLContext;
00018
00019
00020
00021
00022
00023 class CLight {
00024 protected:
00025 CGLContext &GLContext;
00026 int LightNum;
00027 public:
00028 CLight( CGLContext &context, int lightNum )
00029 : GLContext(context), LightNum(lightNum) {}
00030
00031 virtual void SetAmbient( cpu_vec_xyzw ambient ) = 0;
00032 virtual void SetDiffuse( cpu_vec_xyzw diffuse ) = 0;
00033 virtual void SetSpecular( cpu_vec_xyzw specular ) = 0;
00034 virtual void SetPosition( cpu_vec_xyzw position ) = 0;
00035 virtual void SetDirection( cpu_vec_xyzw direction ) = 0;
00036 virtual void SetSpotDirection( cpu_vec_xyzw dir ) = 0;
00037 virtual void SetSpotCutoff( float cutoff ) = 0;
00038 virtual void SetSpotExponent( float exp ) = 0;
00039 virtual void SetConstantAtten( float atten ) = 0;
00040 virtual void SetLinearAtten( float atten ) = 0;
00041 virtual void SetQuadAtten( float atten ) = 0;
00042
00043 virtual void SetEnabled( bool yesNo ) = 0;
00044 };
00045
00046
00047
00048
00049
00050 class CImmLight : public CLight {
00051 cpu_vec_xyzw Ambient, Diffuse, Specular;
00052 cpu_vec_xyzw Position, SpotDirection;
00053 float SpotCutoff, SpotExponent;
00054 float ConstantAtten, LinearAtten, QuadAtten;
00055 bool bIsEnabled;
00056
00057
00058 tLightType Type;
00059
00060 static int NumLights[3];
00061
00062 inline void TellRendererLightPropChanged() {
00063 GLContext.LightPropChanged();
00064 }
00065
00066 void CheckTypeChange( tLightType oldType );
00067
00068 public:
00069 CImmLight( CGLContext &context, int lightNum );
00070
00071 void SetAmbient( cpu_vec_xyzw ambient ) {
00072 Ambient = ambient;
00073 TellRendererLightPropChanged();
00074 }
00075 void SetDiffuse( cpu_vec_xyzw diffuse ) {
00076 Diffuse = diffuse;
00077 TellRendererLightPropChanged();
00078 }
00079 void SetSpecular( cpu_vec_xyzw specular );
00080 void SetPosition( cpu_vec_xyzw position );
00081 void SetDirection( cpu_vec_xyzw direction );
00082
00083 void SetSpotDirection( cpu_vec_xyzw dir ) {
00084 SpotDirection = dir;
00085 TellRendererLightPropChanged();
00086 }
00087 void SetSpotCutoff( float cutoff ) {
00088 tLightType oldType = Type;
00089 if ( Type != kDirectional )
00090 Type = (cutoff == 180.0f) ? kPoint : kSpot;
00091 CheckTypeChange(oldType);
00092 SpotCutoff = cutoff;
00093 TellRendererLightPropChanged();
00094 }
00095 void SetSpotExponent( float exp ) {
00096 SpotExponent = exp;
00097 TellRendererLightPropChanged();
00098 }
00099
00100 void SetConstantAtten( float atten ) {
00101 ConstantAtten = atten;
00102 TellRendererLightPropChanged();
00103 }
00104 void SetLinearAtten( float atten ) {
00105 LinearAtten = atten;
00106 TellRendererLightPropChanged();
00107 }
00108 void SetQuadAtten( float atten ) {
00109 QuadAtten = atten;
00110 TellRendererLightPropChanged();
00111 }
00112
00113 void SetEnabled( bool enabled );
00114
00115 inline cpu_vec_xyzw GetAmbient() const { return Ambient; }
00116 inline cpu_vec_xyzw GetDiffuse() const { return Diffuse; }
00117 inline cpu_vec_xyzw GetSpecular() const { return Specular; }
00118 inline cpu_vec_xyzw GetPosition() const { return Position; }
00119
00120 inline cpu_vec_xyzw GetSpotDir() const { return SpotDirection; }
00121 inline float GetSpotCutoff() const { return SpotCutoff; }
00122 inline float GetSpotExponent() const { return SpotExponent; }
00123
00124 inline float GetConstantAtten() const { return ConstantAtten; }
00125 inline float GetLinearAtten() const { return LinearAtten; }
00126 inline float GetQuadAtten() const { return QuadAtten; }
00127
00128 inline bool IsEnabled() const { return bIsEnabled; }
00129 inline bool IsDirectional() const { return (Type == kDirectional); }
00130 inline bool IsPoint() const { return (Type == kPoint); }
00131 inline bool IsSpot() const { return (Type == kSpot); }
00132 };
00133
00134
00135
00136
00137
00138 class CDListLight : public CLight {
00139 inline void TellRendererLightPropChanged() {
00140 GLContext.LightPropChanged();
00141 }
00142 inline void TellRendererLightsEnabledChanged() {
00143 GLContext.NumLightsChanged();
00144 }
00145 public:
00146 CDListLight( CGLContext &context, int lightNum )
00147 : CLight(context, lightNum) {}
00148
00149 void SetAmbient( cpu_vec_xyzw ambient );
00150 void SetDiffuse( cpu_vec_xyzw diffuse );
00151 void SetSpecular( cpu_vec_xyzw specular );
00152 void SetPosition( cpu_vec_xyzw position );
00153 void SetDirection( cpu_vec_xyzw direction );
00154
00155 void SetSpotDirection( cpu_vec_xyzw dir );
00156 void SetSpotCutoff( float cutoff );
00157 void SetSpotExponent( float exp );
00158
00159 void SetConstantAtten( float atten );
00160 void SetLinearAtten( float atten );
00161 void SetQuadAtten( float atten );
00162
00163 void SetEnabled( bool yesNo );
00164 };
00165
00166
00167
00168
00169
00170 class CLighting {
00171 protected:
00172 CGLContext &GLContext;
00173 static const int NumLights = 8;
00174
00175 public:
00176 CLighting( CGLContext &context ) : GLContext(context) {}
00177
00178 virtual CLight& GetLight( int num ) = 0;
00179
00180 virtual void SetLightingEnabled( bool enabled ) = 0;
00181 virtual void SetGlobalAmbient( cpu_vec_xyzw newAmb ) = 0;
00182 };
00183
00184
00185
00186
00187
00188 class CImmLighting : public CLighting {
00189 cpu_vec_xyzw CurrentColor;
00190 cpu_vec_xyzw GlobalAmbient;
00191 CImmLight Light0, Light1, Light2, Light3, Light4, Light5, Light6, Light7;
00192 CImmLight *Lights[NumLights];
00193 bool IsEnabled;
00194 int NumLightsWithNonzeroSpecular;
00195
00196 inline void TellRendererLightPropChanged() {
00197 GLContext.LightPropChanged();
00198 }
00199
00200 public:
00201 CImmLighting( CGLContext &context );
00202
00203 CImmLight& GetImmLight( int num ) {
00204 mAssert(num < NumLights);
00205 return *Lights[num];
00206 }
00207 CLight& GetLight( int num ) { return GetImmLight(num); }
00208
00209 void SetLightingEnabled( bool enabled ) {
00210 GLContext.LightingEnabledChanged();
00211 GLContext.GetImmGeomManager().GetVsmManager().LightingEnabledChanged(enabled);
00212 IsEnabled = enabled;
00213 }
00214 bool GetLightingEnabled() const { return IsEnabled; }
00215
00216 void SetGlobalAmbient( cpu_vec_xyzw newAmb ) {
00217 GlobalAmbient = newAmb;
00218 TellRendererLightPropChanged();
00219 }
00220 cpu_vec_xyzw GetGlobalAmbient() { return GlobalAmbient; }
00221
00222 void SpecularChanged();
00223 void MaterialHasSpecular();
00224 };
00225
00226
00227
00228
00229
00230 class CDListLighting : public CLighting {
00231 CDListLight Light0, Light1, Light2, Light3, Light4, Light5, Light6, Light7;
00232 CDListLight *Lights[NumLights];
00233
00234 inline void TellRendererLightPropChanged() {
00235 GLContext.LightPropChanged();
00236 }
00237
00238 public:
00239 CDListLighting( CGLContext &context );
00240
00241 CDListLight& GetDListLight( int num ) {
00242 mAssert(num < NumLights);
00243 return *Lights[num];
00244 }
00245 CLight& GetLight( int num ) { return GetDListLight(num); }
00246
00247 void SetLightingEnabled( bool enabled );
00248 void SetGlobalAmbient( cpu_vec_xyzw newAmb );
00249 };
00250
00251 #endif // ps2gl_lighting_h