00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_MATERIAL_H__
00021 #define __CS_MATERIAL_H__
00022
00023 #include "csgfx/rgbpixel.h"
00024 #include "csutil/csobject.h"
00025 #include "csutil/nobjvec.h"
00026 #include "ivideo/material.h"
00027 #include "iengine/material.h"
00028 #include "ivideo/effects/efdef.h"
00029
00030 #ifdef CS_USE_NEW_RENDERER
00031 #include "ivideo/shader/shader.h"
00032 #endif
00033
00034 struct iTextureWrapper;
00035 struct iTextureManager;
00036
00037
00038
00039 SCF_VERSION (csMaterialWrapper, 0, 0, 1);
00040
00044 class csMaterial : public iMaterial
00045 {
00046 private:
00048 csRGBcolor flat_color;
00050 csRef<iTextureWrapper> texture;
00052 int num_texture_layers;
00054 csTextureLayer texture_layers[4];
00056 csRef<iTextureWrapper> texture_layer_wrappers[4];
00057
00059 float diffuse;
00061 float ambient;
00063 float reflection;
00064
00066 iEffectDefinition* effect;
00067
00068 #ifdef CS_USE_NEW_RENDERER
00069
00070 csRef<iShader> shader;
00071 #endif
00072
00073 public:
00077 csMaterial ();
00081 csMaterial (iTextureWrapper *txt);
00082
00086 virtual ~csMaterial ();
00087
00089 csRGBcolor& GetFlatColor () { return flat_color; }
00090
00092 float GetDiffuse () const { return diffuse; }
00094 void SetDiffuse (float val) { diffuse = val; }
00095
00097 float GetAmbient () const { return ambient; }
00099 void SetAmbient (float val) { ambient = val; }
00100
00102 float GetReflection () const { return reflection; }
00104 void SetReflection (float val) { reflection = val; }
00105
00107 iTextureWrapper *GetTextureWrapper () const { return texture; }
00109 void SetTextureWrapper (iTextureWrapper *tex);
00110
00112 void AddTextureLayer (iTextureWrapper* txtwrap, uint mode,
00113 float uscale, float vscale, float ushift, float vshift);
00114
00115
00116
00117 #ifdef CS_USE_NEW_RENDERER
00118
00119 virtual void SetShader (iShader* shader);
00121 virtual iShader* GetShader ();
00122
00123 #endif
00124
00126 virtual void SetEffect (iEffectDefinition *ed);
00128 virtual iEffectDefinition *GetEffect ();
00130 virtual iTextureHandle* GetTexture ();
00132 virtual int GetTextureLayerCount ();
00134 virtual csTextureLayer* GetTextureLayer (int idx);
00136 virtual void GetFlatColor (csRGBpixel &oColor, bool useTextureMean=1);
00138 virtual void SetFlatColor (const csRGBcolor& col) { flat_color = col; }
00140 virtual void GetReflection (float &oDiffuse, float &oAmbient,
00141 float &oReflection);
00143 virtual void SetReflection (float oDiffuse, float oAmbient,
00144 float oReflection)
00145 {
00146 diffuse = oDiffuse;
00147 ambient = oAmbient;
00148 reflection = oReflection;
00149 }
00150
00151 SCF_DECLARE_IBASE;
00152
00154 struct MaterialEngine : public iMaterialEngine
00155 {
00156 SCF_DECLARE_EMBEDDED_IBASE (csMaterial);
00157 virtual iTextureWrapper *GetTextureWrapper ()
00158 {
00159 return scfParent->texture;
00160 }
00161 virtual iTextureWrapper* GetTextureWrapper (int idx)
00162 {
00163 return scfParent->texture_layer_wrappers[idx];
00164 }
00165 } scfiMaterialEngine;
00166 friend struct MaterialEngine;
00167 };
00168
00173 class csMaterialWrapper : public csObject
00174 {
00175 private:
00177 csRef<iMaterial> material;
00179 csRef<iMaterialHandle> handle;
00180
00181 private:
00183 virtual ~csMaterialWrapper ();
00184
00185 public:
00187 csMaterialWrapper (iMaterial* Image);
00189 csMaterialWrapper (iMaterialHandle *ith);
00191 csMaterialWrapper (csMaterialWrapper &);
00192
00197 void SetMaterialHandle (iMaterialHandle *mat);
00199 iMaterialHandle* GetMaterialHandle () { return handle; }
00200
00205 void SetMaterial (iMaterial* material);
00207 iMaterial* GetMaterial () { return material; }
00208
00210 void Register (iTextureManager *txtmng);
00211
00217 void Visit ();
00218
00219 SCF_DECLARE_IBASE_EXT (csObject);
00220
00221
00222 struct MaterialWrapper : public iMaterialWrapper
00223 {
00224 SCF_DECLARE_EMBEDDED_IBASE (csMaterialWrapper);
00225 virtual csMaterialWrapper* GetPrivateObject ()
00226 { return (csMaterialWrapper*)scfParent; }
00227 virtual iObject *QueryObject()
00228 { return scfParent; }
00229 virtual iMaterialWrapper *Clone () const
00230 { return &(new csMaterialWrapper (*scfParent))->scfiMaterialWrapper; }
00231 virtual void SetMaterialHandle (iMaterialHandle *mat)
00232 { scfParent->SetMaterialHandle (mat); }
00233 virtual iMaterialHandle* GetMaterialHandle ()
00234 { return scfParent->GetMaterialHandle (); }
00235 virtual void SetMaterial (iMaterial* material)
00236 { scfParent->SetMaterial (material); }
00237 virtual iMaterial* GetMaterial ()
00238 { return scfParent->GetMaterial (); }
00239 virtual void Register (iTextureManager *txtmng)
00240 { scfParent->Register (txtmng); }
00241 virtual void Visit ()
00242 { scfParent->Visit (); }
00243 } scfiMaterialWrapper;
00244 friend struct MaterialWrapper;
00245 };
00246
00250 class csMaterialList : public csRefArrayObject<iMaterialWrapper>
00251 {
00252 public:
00254 csMaterialList ();
00255 virtual ~csMaterialList () { }
00256
00258 iMaterialWrapper* NewMaterial (iMaterial* material);
00259
00264 iMaterialWrapper* NewMaterial (iMaterialHandle *ith);
00265
00266 SCF_DECLARE_IBASE;
00267
00268
00269 class MaterialList : public iMaterialList
00270 {
00271 public:
00272 SCF_DECLARE_EMBEDDED_IBASE (csMaterialList);
00273
00274 virtual iMaterialWrapper* NewMaterial (iMaterial* material);
00275 virtual iMaterialWrapper* NewMaterial (iMaterialHandle *ith);
00276 virtual int GetCount () const;
00277 virtual iMaterialWrapper *Get (int n) const;
00278 virtual int Add (iMaterialWrapper *obj);
00279 virtual bool Remove (iMaterialWrapper *obj);
00280 virtual bool Remove (int n);
00281 virtual void RemoveAll ();
00282 virtual int Find (iMaterialWrapper *obj) const;
00283 virtual iMaterialWrapper *FindByName (const char *Name) const;
00284 } scfiMaterialList;
00285 };
00286
00287 #endif // __CS_MATERIAL_H__