00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_TEXTURE_FAR_H
00027 #define NL_TEXTURE_FAR_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/rect.h"
00031 #include "3d/texture.h"
00032 #include "3d/tile_far_bank.h"
00033
00034
00035
00036
00037
00038
00039
00040 #define NL_NUM_FAR_PATCH_EDGE_LEVEL (4+NL_NUM_PIXELS_ON_FAR_TILE_EDGE_SHIFT)
00041
00042
00043 #define NL_MAX_FAR_PATCH_EDGE (16*NL_NUM_PIXELS_ON_FAR_TILE_EDGE) // Max is 16x16 tiles for 4 pix/tiles.
00044
00045
00046 #define NL_MIN_FAR_PATCH_EDGE 2 // Min is 2x2 tiles for 1 pix/tile
00047
00048
00049 #define NL_NUM_FAR_RECTANGLE_RATIO 4 // 16x16, 16x8, 16x4, 16x2
00050 #define NL_MAX_FAR_RECTANGLE_RATIO_SHIFT (NL_NUM_RECTANGLE_ASPECT_RATIO-1)
00051 #define NL_MAX_FAR_RECTANGLE_RATIO (1<<NL_MAX_RECTANGLE_RATIO_SHIFT) // Max is 16 tiles fo 2 tiles => 8.
00052
00053
00054 #define NL_NUM_FAR_BIGGEST_PATCH_PER_EDGE 8
00055 #define NL_NUM_FAR_BIGGEST_PATCH_PER_TEXTURE (NL_NUM_FAR_BIGGEST_PATCH_PER_EDGE*NL_NUM_FAR_BIGGEST_PATCH_PER_EDGE)
00056
00057
00058 #define NL_FAR_TEXTURE_EDGE_SIZE (NL_MAX_FAR_PATCH_EDGE*NL_NUM_FAR_BIGGEST_PATCH_PER_EDGE)
00059
00060
00061 namespace NLMISC
00062 {
00063 class CRGBA;
00064 }
00065
00066 namespace NL3D
00067 {
00068
00069 class CPatch;
00070 class CTileFarBank;
00071 class CTileColor;
00072
00085 class CTextureFar : public ITexture
00086 {
00087 public:
00089 CTextureFar();
00090 virtual ~CTextureFar();
00091
00092
00098 sint tryAllocatePatch (CPatch *pPatch, uint farIndex);
00099
00100
00111 void allocatePatch (CPatch *pPatch, uint farIndex, float& farUScale, float& farVScale, float& farUBias, float& farVBias, bool& bRot);
00112
00116 void removePatch (CPatch *pPatch, uint farIndex);
00117
00123 virtual void doGenerate(bool async = false);
00124
00129 uint touchPatchULAndNext();
00130 void startPatchULTouch();
00131 bool endPatchULTouch() const;
00132
00133
00135 void linkBeforeUL(CTextureFar *textNext);
00137 void unlinkUL();
00139 CTextureFar *getNextUL() const {return _ULNext;}
00140
00141
00143 CTileFarBank* _Bank;
00144
00145
00146 private:
00147
00148 struct CPatchIdent
00149 {
00150 CPatch *Patch;
00151 uint FarIndex;
00152
00153 bool operator < (const CPatchIdent &rhs) const
00154 {
00155 return (Patch != rhs.Patch) ? Patch < rhs.Patch : FarIndex < rhs.FarIndex;
00156 }
00157 };
00158
00159 struct CVector2s
00160 {
00161 uint16 x, y;
00162
00163 CVector2s() {}
00164 CVector2s(uint16 _x, uint16 _y) {x= _x; y= _y;}
00165
00166 bool operator < (const CVector2s &rhs) const
00167 {
00168 return (x != rhs.x) ? x < rhs.x : y < rhs.y;
00169 }
00170 };
00171
00176 typedef std::map<CPatchIdent, CVector2s> TPatchToPosMap;
00177 typedef std::map<CVector2s, CPatchIdent> TPosToPatchMap;
00178 TPatchToPosMap _PatchToPosMap;
00179 TPosToPatchMap _PosToPatchMap;
00180
00183 std::list<CVector2s> _FreeSpaces[NL_NUM_FAR_PATCH_EDGE_LEVEL * NL_NUM_FAR_RECTANGLE_RATIO];
00184
00185
00186
00187 bool getUpperSize(uint &width, uint &height);
00188 uint getFreeListId(uint width, uint height);
00189 void recursSplitNext(uint width, uint height);
00190
00194 void rebuildPatch (const CVector2s texturePos, const CPatchIdent &pid);
00195
00197 virtual void serial(NLMISC::IStream &f) throw(NLMISC::EStream) {};
00198
00199
00200 static NLMISC::CRGBA _LightmapExpanded[];
00201 static uint8 _LumelExpanded[];
00202 static NLMISC::CRGBA _TileTLIColors[];
00203
00204 NLMISC_DECLARE_CLASS(CTextureFar);
00205
00207 CTextureFar *_ULPrec;
00208 CTextureFar *_ULNext;
00209
00210 TPatchToPosMap::iterator _ItULPatch;
00211
00212 };
00213
00214 }
00215
00216
00217 struct NL3D_CComputeTileFar
00218 {
00219 public:
00220
00221 const NLMISC::CRGBA* SrcDiffusePixels;
00222
00223
00224 const NLMISC::CRGBA* SrcAdditivePixels;
00225
00226
00227 sint32 SrcDeltaX;
00228
00229
00230 sint32 SrcDeltaY;
00231
00232
00233 const NLMISC::CRGBA* SrcLightingPixels;
00234
00235
00236 sint32 SrcLightingDeltaY;
00237
00238
00239 NLMISC::CRGBA* DstPixels;
00240
00241
00242 sint32 DstDeltaX;
00243
00244
00245 sint32 DstDeltaY;
00246
00247
00248 sint32 Size;
00249
00250
00251 bool AsmMMX;
00252 };
00253
00254
00255 struct NL3D_CExpandLightmap
00256 {
00257 public:
00258
00259 const NL3D::CTileColor* ColorTile;
00260
00261 const NLMISC::CRGBA* TLIColor;
00262
00263
00264 const uint8* LumelTile;
00265
00266
00267 uint32 Width;
00268
00269
00270 uint32 Height;
00271
00272
00273 uint32 MulFactor;
00274
00275
00276 const NLMISC::CRGBA* StaticLightColor;
00277
00278
00279 NLMISC::CRGBA* DstPixels;
00280 };
00281
00282
00283 extern "C" void NL3D_expandLightmap (const NL3D_CExpandLightmap* pLightmap);
00284 extern "C" void NL3D_drawFarTileInFarTexture (const NL3D_CComputeTileFar* pTileFar);
00285 extern "C" void NL3D_drawFarTileInFarTextureAdditive (const NL3D_CComputeTileFar* pTileFar);
00286 extern "C" void NL3D_drawFarTileInFarTextureAlpha (const NL3D_CComputeTileFar* pTileFar);
00287 extern "C" void NL3D_drawFarTileInFarTextureAdditiveAlpha (const NL3D_CComputeTileFar* pTileFar);
00288
00289 #endif // NL_TEXTURE_FAR_H
00290
00291