Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

lighting.h

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

ps2gl version cvs