00001
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_material_h
00008 #define ps2gl_material_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 class CMaterial {
00022 protected:
00023 CGLContext &GLContext;
00024
00025 public:
00026 CMaterial(CGLContext &context) : GLContext(context) {}
00027
00028 virtual void SetAmbient( cpu_vec_xyzw ambient ) = 0;
00029 virtual void SetDiffuse( cpu_vec_xyzw diffuse ) = 0;
00030 virtual void SetSpecular( cpu_vec_xyzw specular ) = 0;
00031 virtual void SetEmission( cpu_vec_xyzw emission ) = 0;
00032 virtual void SetShininess( float shine ) = 0;
00033 };
00034
00035 class CImmMaterial : public CMaterial {
00036 cpu_vec_xyzw Ambient, Diffuse, Specular, Emission;
00037 float Shininess;
00038
00039 inline void TellRendererMaterialChanged() {
00040 GLContext.CurMaterialChanged();
00041 }
00042 public:
00043 CImmMaterial( CGLContext &context );
00044
00045
00046 void SetAmbient( cpu_vec_xyzw ambient ) { Ambient = ambient; TellRendererMaterialChanged(); }
00047 void SetDiffuse( cpu_vec_xyzw diffuse ) { Diffuse = diffuse; TellRendererMaterialChanged(); }
00048 void SetSpecular( cpu_vec_xyzw specular );
00049 void SetEmission( cpu_vec_xyzw emission ) { Emission = emission; TellRendererMaterialChanged(); }
00050 void SetShininess( float shine ) { Shininess = shine; TellRendererMaterialChanged(); }
00051
00052 inline cpu_vec_xyzw GetAmbient() const { return Ambient; }
00053 inline cpu_vec_xyzw GetDiffuse() const { return Diffuse; }
00054 inline cpu_vec_xyzw GetSpecular() const { return Specular; }
00055 inline cpu_vec_xyzw GetEmission() const { return Emission; }
00056 inline float GetShininess() const { return Shininess; }
00057
00058 void LightsHaveSpecular();
00059 };
00060
00061 class CDListMaterial : public CMaterial {
00062 inline void TellRendererMaterialChanged() {
00063 GLContext.CurMaterialChanged();
00064 }
00065 public:
00066 CDListMaterial( CGLContext &context ) : CMaterial(context) {}
00067
00068 void SetAmbient( cpu_vec_xyzw ambient );
00069 void SetDiffuse( cpu_vec_xyzw diffuse );
00070 void SetSpecular( cpu_vec_xyzw specular );
00071 void SetEmission( cpu_vec_xyzw emission );
00072 void SetShininess( float shine );
00073 };
00074
00075 class CMaterialManager {
00076 CGLContext &GLContext;
00077
00078 CImmMaterial ImmMaterial;
00079 CDListMaterial DListMaterial;
00080 CMaterial *CurMaterial;
00081
00082 cpu_vec_xyzw CurColor;
00083 GLenum ColorMaterialMode;
00084 bool UseColorMaterial;
00085 bool InDListDef;
00086
00087 public:
00088 CMaterialManager( CGLContext &context )
00089 : GLContext(context),
00090 ImmMaterial(context), DListMaterial(context),
00091 CurMaterial(&ImmMaterial),
00092 CurColor(1, 1, 1, 1),
00093 ColorMaterialMode(GL_AMBIENT_AND_DIFFUSE),
00094 UseColorMaterial(false),
00095 InDListDef(false)
00096 {
00097 ImmMaterial.SetDiffuse( cpu_vec_xyzw(0.8f, 0.8f, 0.8f, 1.0f) );
00098 }
00099
00100 CMaterial& GetCurMaterial() { return *CurMaterial; }
00101 CImmMaterial& GetImmMaterial() { return ImmMaterial; }
00102 CDListMaterial& GetDListMaterial() { return DListMaterial; }
00103 cpu_vec_xyzw GetCurColor() const { return CurColor; }
00104 GLenum GetColorMaterialMode() const { return ColorMaterialMode; }
00105 bool GetColorMaterialEnabled() const { return UseColorMaterial; }
00106
00107 void Color( cpu_vec_xyzw color );
00108 void SetUseColorMaterial( bool yesNo );
00109 void SetColorMaterialMode( GLenum mode );
00110
00111 void BeginDListDef() { CurMaterial = &DListMaterial; InDListDef = true; }
00112 void EndDListDef() { CurMaterial = &ImmMaterial; InDListDef = false; }
00113 };
00114
00115 #endif // ps2gl_material_h