Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / 3d / hls_texture_bank.cpp
blob9c014bd28a66606c0443d472b3f186de4e99cba7
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "std3d.h"
21 #include "nel/3d/hls_texture_bank.h"
24 using namespace std;
25 using namespace NLMISC;
27 #ifdef DEBUG_NEW
28 #define new DEBUG_NEW
29 #endif
31 namespace NL3D
35 // ***************************************************************************
36 // ***************************************************************************
37 // CHLSTextureBank
38 // ***************************************************************************
39 // ***************************************************************************
42 // ***************************************************************************
43 CHLSTextureBank::CHLSTextureBank()
46 // ***************************************************************************
47 void CHLSTextureBank::reset()
49 contReset(_ColorTextures);
50 contReset(_TextureInstanceData);
51 contReset(_TextureInstances);
53 // ***************************************************************************
54 uint32 CHLSTextureBank::addColorTexture(const CHLSColorTexture &tex)
56 _ColorTextures.push_back(tex);
57 return (uint32)_ColorTextures.size()-1;
59 // ***************************************************************************
60 void CHLSTextureBank::addTextureInstance(const std::string &name, uint32 colorTextureId, const vector<CHLSColorDelta> &cols)
62 string nameLwr= toLowerAscii(name);
64 // checks
65 nlassert(colorTextureId<_ColorTextures.size());
66 CHLSColorTexture &colText= _ColorTextures[colorTextureId];
67 nlassert(cols.size()==colText.getNumMasks());
69 // new instance
70 CTextureInstance textInst;
71 textInst._ColorTextureId= colorTextureId;
72 textInst._DataIndex= (uint32)_TextureInstanceData.size();
73 // leave ptrs undefined
74 textInst._DataPtr= NULL;
75 textInst._ColorTexturePtr= NULL;
77 // allocate/fill data
78 uint32 nameSize= (uint32)(nameLwr.size()+1);
79 uint32 colSize= (uint32)cols.size()*sizeof(CHLSColorDelta);
80 _TextureInstanceData.resize(_TextureInstanceData.size() + nameSize + colSize);
81 // copy name
82 if (nameSize != 0) memcpy(&_TextureInstanceData[textInst._DataIndex], nameLwr.c_str(), nameSize);
83 // copy cols
84 if (colSize != 0) memcpy(&_TextureInstanceData[textInst._DataIndex+nameSize], &cols[0], colSize);
86 // add the instance.
87 _TextureInstances.push_back(textInst);
89 // ***************************************************************************
90 void CHLSTextureBank::compilePtrs()
92 uint8 *data= &_TextureInstanceData[0];
94 // For all texture instances, compute ptr.
95 for(uint i=0;i<_TextureInstances.size();i++)
97 CTextureInstance &text= _TextureInstances[i];
98 text._DataPtr= data + text._DataIndex;
99 text._ColorTexturePtr= &_ColorTextures[text._ColorTextureId];
104 // ***************************************************************************
105 void CHLSTextureBank::compile()
107 // compile the ptrs.
108 compilePtrs();
110 // No other ops for now.
114 // ***************************************************************************
115 void CHLSTextureBank::serial(NLMISC::IStream &f)
117 f.serialVersion(0);
119 f.serialCont(_ColorTextures);
120 f.serialCont(_TextureInstanceData);
121 f.serialCont(_TextureInstances);
123 // Must compile ptrs.
124 if(f.isReading())
126 // compile the ptrs only.
127 compilePtrs();
132 // ***************************************************************************
133 void CHLSTextureBank::fillHandleArray(std::vector<CTextureInstanceHandle> &array)
135 for(uint i=0;i<_TextureInstances.size();i++)
137 CTextureInstanceHandle h;
138 h.Texture= &_TextureInstances[i];
139 array.push_back(h);
144 // ***************************************************************************
145 // ***************************************************************************
146 // CHLSTextureBank::CTextureInstance
147 // ***************************************************************************
148 // ***************************************************************************
151 // ***************************************************************************
152 void CHLSTextureBank::CTextureInstance::serial(NLMISC::IStream &f)
154 f.serialVersion(0);
156 f.serial(_DataIndex);
157 f.serial(_ColorTextureId);
161 // ***************************************************************************
162 bool CHLSTextureBank::CTextureInstance::operator<(const CTextureInstance &t) const
164 // compare the 2 strings.
165 return (strcmp((const char*)_DataPtr, (const char*)t._DataPtr)<0);
167 // ***************************************************************************
168 bool CHLSTextureBank::CTextureInstance::operator<=(const CTextureInstance &t) const
170 // compare the 2 strings.
171 return (strcmp((const char*)_DataPtr, (const char*)t._DataPtr)<=0);
175 // ***************************************************************************
176 bool CHLSTextureBank::CTextureInstance::sameName(const char *str)
178 return (strcmp((const char*)_DataPtr, str)==0);
182 // ***************************************************************************
183 void CHLSTextureBank::CTextureInstance::buildColorVersion(NLMISC::CBitmap &out)
185 // get ptr to color deltas.
186 uint nameSize= (uint)strlen((const char*)_DataPtr)+1;
187 CHLSColorDelta *colDeltas= (CHLSColorDelta*)(_DataPtr + nameSize);
189 // build the texture.
190 _ColorTexturePtr->buildColorVersion(colDeltas, out);
194 } // NL3D