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 struct iCacheManager;
00037
00038 CS_DECLARE_STATIC_ARRAY (csRGBMap, csRGBpixel);
00039 CS_DECLARE_STATIC_ARRAY (csShadowMapHelper, unsigned char);
00040
00041 class csShadowMap : public csShadowMapHelper
00042 {
00043 public:
00044 iLight *Light;
00045 csShadowMap *next;
00046
00047 csShadowMap ();
00048 virtual ~csShadowMap ();
00049 void Alloc (iLight *l, int w, int h);
00050 void Copy (const csShadowMap *other);
00051 };
00052
00056 class csLightMap : public iLightMap
00057 {
00059 friend class csPolyTexture;
00060
00061 private:
00066 csRGBMap static_lm;
00067
00074 csRGBMap real_lm;
00075
00080 bool dyn_dirty;
00081
00086 csShadowMap* first_smap;
00087
00089 long lm_size;
00090
00092 int lwidth, lheight;
00094 int rwidth, rheight;
00095
00100 csRGBpixel mean_color;
00101
00103 void *cachedata;
00104
00106 csDelayedLightingInfo *delayed_light_info;
00107
00108 #if 0
00109
00118 void ConvertToMixingMode (unsigned char* mr, unsigned char* mg,
00119 unsigned char* mb, int sz);
00120 #endif
00121
00125 void SetSize (int w, int h);
00126
00127 public:
00129 static int lightcell_size;
00131 static int lightcell_shift;
00132
00134 static int CalcLightMapWidth (int w)
00135 {
00136 return 1 + ((w + lightcell_size - 1) >> lightcell_shift);
00137
00138 }
00140 static int CalcLightMapHeight (int h)
00141 {
00142 return 1 + ((h + lightcell_size - 1) >> lightcell_shift);
00143
00144 }
00145
00147 csLightMap ();
00149 virtual ~csLightMap ();
00150
00152 void MakeDirtyDynamicLights () { dyn_dirty = true; }
00153
00154 bool UpdateRealLightMap ();
00155
00157 csRGBMap& GetStaticMap () { return static_lm; }
00159 csRGBMap& GetRealMap () { return real_lm; }
00160
00166 void Alloc (int w, int h, int r, int g, int b);
00167
00169 void CopyLightMap (csLightMap* source);
00170
00174 csShadowMap* NewShadowMap (csLight* light, int w, int h);
00175
00179 void AllocStaticLM (int w, int h);
00180
00184 csShadowMap* FindShadowMap (csLight* light);
00185
00192 void DelShadowMap (csShadowMap* plm);
00193
00198 bool ReadFromCache (iCacheManager* cache_mgr, int id, int w, int h,
00199 csObject* obj, bool isPolygon, csEngine*);
00200
00205 void Cache (iCacheManager* cache_mgr, int id, csPolygon3D* poly,
00206 csCurve* curve, csEngine*);
00207
00215 void ConvertToMixingMode ();
00216
00220 void ConvertFor3dDriver (bool requirePO2, int maxAspect = 32767);
00221
00227 static void SetLightCellSize (int size);
00228
00229
00230 SCF_DECLARE_IBASE;
00232 virtual csRGBpixel *GetMapData ();
00234 virtual int GetWidth ()
00235 { return lwidth; }
00237 virtual int GetHeight ()
00238 { return lheight; }
00240 virtual int GetRealWidth ()
00241 { return rwidth; }
00243 virtual int GetRealHeight ()
00244 { return rheight; }
00246 virtual void *GetCacheData ()
00247 { return cachedata; }
00249 virtual void SetCacheData (void *d)
00250 { cachedata = d; }
00252 virtual void GetMeanLighting (int &r, int &g, int &b)
00253 { r = mean_color.red; g = mean_color.green; b = mean_color.blue; }
00255 virtual long GetSize ()
00256 { return lm_size; }
00257 };
00258
00259 #endif // __CS_LIGHTMAP_H__