Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / 3d / texture_near.cpp
blobe39279dd1df03a0b30e337aa35b4687816245d59
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std3d.h"
18 #include "nel/3d/texture_near.h"
20 using namespace NLMISC;
22 #ifdef DEBUG_NEW
23 #define new DEBUG_NEW
24 #endif
26 namespace NL3D
30 // ***************************************************************************
31 CTextureNear::CTextureNear(sint size)
33 nlassert(size>=NL_TILE_LIGHTMAP_SIZE);
34 nlassert(NLMISC::isPowerOf2(size));
36 // The near texture always reside in memory...
37 // NB: this is simplier like that, and this is not a problem, since only 1 or 2 Mo are allocated :o)
38 setReleasable(false);
39 // create the bitmap.
40 CBitmap::resize(size, size, CBitmap::RGBA);
41 // Format of texture, 32 bits and no mipmaps.
42 setUploadFormat(ITexture::RGBA8888);
43 setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
45 // Fill the array of free tiles.
46 uint nbTilesByLine= size/NL_TILE_LIGHTMAP_SIZE;
47 _FreeTiles.resize(nbTilesByLine*nbTilesByLine);
48 _AvailableTiles.resize(nbTilesByLine*nbTilesByLine);
49 for(sint i=0;i<(sint)_FreeTiles.size();i++)
51 // This tile is free!!
52 _FreeTiles[i]=i;
53 _AvailableTiles[i]= true;
58 // ***************************************************************************
59 sint CTextureNear::getNbAvailableTiles()
61 return (sint)_FreeTiles.size();
63 // ***************************************************************************
64 uint CTextureNear::getTileAndFillRect(CRGBA map[NL_TILE_LIGHTMAP_SIZE*NL_TILE_LIGHTMAP_SIZE])
66 nlassert(getNbAvailableTiles()>0);
67 uint id= _FreeTiles.back();
68 // This tile is now more free.
69 _AvailableTiles[id]= false;
70 _FreeTiles.pop_back();
72 // Fill the texture
73 refillRect(id, map);
75 return id;
78 // ***************************************************************************
79 void CTextureNear::refillRect(uint id, CRGBA map[NL_TILE_LIGHTMAP_SIZE*NL_TILE_LIGHTMAP_SIZE])
81 uint dstWidth= getWidth();
82 // Copy the map into the texture
83 uint nbTilesByLine= dstWidth/NL_TILE_LIGHTMAP_SIZE;
84 uint s= id% nbTilesByLine;
85 uint t= id/ nbTilesByLine;
86 s*= NL_TILE_LIGHTMAP_SIZE;
87 t*= NL_TILE_LIGHTMAP_SIZE;
88 CRGBA *src= map;
89 CRGBA *dst= (CRGBA*)getPixels().getPtr();
90 dst+= t*dstWidth+s;
91 for(sint n= NL_TILE_LIGHTMAP_SIZE;n>0;n--, src+= NL_TILE_LIGHTMAP_SIZE, dst+= dstWidth)
93 memcpy(dst, src, NL_TILE_LIGHTMAP_SIZE*sizeof(CRGBA));
96 // Invalidate the rectangle.
97 ITexture::touchRect(CRect(s, t, NL_TILE_LIGHTMAP_SIZE, NL_TILE_LIGHTMAP_SIZE));
100 // ***************************************************************************
101 void CTextureNear::releaseTile(uint id)
103 nlassert(!_AvailableTiles[id]);
104 // This tile is now free.
105 _AvailableTiles[id]= true;
106 // insert this tile at the end of the free list.
107 _FreeTiles.push_back(id);
111 } // NL3D