00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_LIGHTMAP_H__
00020 #define __CS_LIGHTMAP_H__
00021
00022 #include "csutil/scf.h"
00023 #include "csutil/sarray.h"
00024 #include "csgfx/rgbpixel.h"
00025 #include "imesh/thing/lightmap.h"
00026
00027 class csPolyTexture;
00028 class csThing;
00029 class csPolygon3D;
00030 class csCurve;
00031 class csLight;
00032 class csEngine;
00033 class csDelayedLightingInfo;
00034 class csObject;
00035 struct iLight;
00036
00037 CS_DECLARE_STATIC_ARRAY (csRGBMap, csRGBpixel);
00038 CS_DECLARE_STATIC_ARRAY (csShadowMapHelper, unsigned char);
00039
00040 class csShadowMap : public csShadowMapHelper
00041 {
00042 public:
00043 iLight *Light;
00044 csShadowMap *next;
00045
00046 csShadowMap ();
00047 void Alloc (iLight *l, int w, int h);
00048 void Copy (const csShadowMap *other);
00049 };
00050
00054 class csLightMap : public iLightMap
00055 {
00057 friend class csPolyTexture;
00058
00059 private:
00064 csRGBMap static_lm;
00065
00072 csRGBMap real_lm;
00073
00078 bool dyn_dirty;
00079
00084 csShadowMap* first_smap;
00085
00087 long lm_size;
00088
00090 int lwidth, lheight;
00092 int rwidth, rheight;
00093
00098 csRGBpixel mean_color;
00099
00101 void *cachedata;
00102
00104 csDelayedLightingInfo *delayed_light_info;
00105
00106 #if 0
00107
00116 void ConvertToMixingMode (unsigned char* mr, unsigned char* mg,
00117 unsigned char* mb, int sz);
00118 #endif
00119
00123 void SetSize (int w, int h);
00124
00125 public:
00127 static int lightcell_size;
00129 static int lightcell_shift;
00130
00132 static int CalcLightMapWidth (int w)
00133 {
00134 return 1 + ((w + lightcell_size - 1) >> lightcell_shift);
00135
00136 }
00138 static int CalcLightMapHeight (int h)
00139 {
00140 return 1 + ((h + lightcell_size - 1) >> lightcell_shift);
00141
00142 }
00143
00145 csLightMap ();
00147 virtual ~csLightMap ();
00148
00150 void MakeDirtyDynamicLights () { dyn_dirty = true; }
00151
00152 bool UpdateRealLightMap ();
00153
00155 csRGBMap& GetStaticMap () { return static_lm; }
00157 csRGBMap& GetRealMap () { return real_lm; }
00158
00164 void Alloc (int w, int h, int r, int g, int b);
00165
00167 void CopyLightMap (csLightMap* source);
00168
00172 csShadowMap* NewShadowMap (csLight* light, int w, int h);
00173
00177 void AllocStaticLM (int w, int h);
00178
00182 csShadowMap* FindShadowMap (csLight* light);
00183
00190 void DelShadowMap (csShadowMap* plm);
00191
00196 bool ReadFromCache (int id, int w, int h,
00197 csObject* obj, bool isPolygon, csEngine*);
00198
00203 void Cache (int id, csPolygon3D* poly, csCurve* curve, csEngine*);
00204
00212 void ConvertToMixingMode ();
00213
00217 void ConvertFor3dDriver (bool requirePO2, int maxAspect = 32767);
00218
00224 static void SetLightCellSize (int size);
00225
00226
00227 SCF_DECLARE_IBASE;
00229 virtual csRGBpixel *GetMapData ();
00231 virtual int GetWidth ()
00232 { return lwidth; }
00234 virtual int GetHeight ()
00235 { return lheight; }
00237 virtual int GetRealWidth ()
00238 { return rwidth; }
00240 virtual int GetRealHeight ()
00241 { return rheight; }
00243 virtual void *GetCacheData ()
00244 { return cachedata; }
00246 virtual void SetCacheData (void *d)
00247 { cachedata = d; }
00249 virtual void GetMeanLighting (int &r, int &g, int &b)
00250 { r = mean_color.red; g = mean_color.green; b = mean_color.blue; }
00252 virtual long GetSize ()
00253 { return lm_size; }
00254 };
00255
00256 #endif // __CS_LIGHTMAP_H__