CrystalSpace

Public API Reference

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

material.h

00001 /*
00002     Copyright (C) 2001 by Jorrit Tyberghein
00003     Copyright (C) 2000 by W.C.A. Wijngaards
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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   //--------------------- iMaterial implementation ---------------------
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   //------------------- iMaterialWrapper implementation -----------------------
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   //------------------- iMaterialList implementation -----------------------
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__

Generated for Crystal Space by doxygen 1.2.14