1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
21 #include "nel/3d/hls_texture_bank.h"
25 using namespace NLMISC
;
35 // ***************************************************************************
36 // ***************************************************************************
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
);
65 nlassert(colorTextureId
<_ColorTextures
.size());
66 CHLSColorTexture
&colText
= _ColorTextures
[colorTextureId
];
67 nlassert(cols
.size()==colText
.getNumMasks());
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
;
78 uint32 nameSize
= (uint32
)(nameLwr
.size()+1);
79 uint32 colSize
= (uint32
)cols
.size()*sizeof(CHLSColorDelta
);
80 _TextureInstanceData
.resize(_TextureInstanceData
.size() + nameSize
+ colSize
);
82 if (nameSize
!= 0) memcpy(&_TextureInstanceData
[textInst
._DataIndex
], nameLwr
.c_str(), nameSize
);
84 if (colSize
!= 0) memcpy(&_TextureInstanceData
[textInst
._DataIndex
+nameSize
], &cols
[0], colSize
);
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()
110 // No other ops for now.
114 // ***************************************************************************
115 void CHLSTextureBank::serial(NLMISC::IStream
&f
)
119 f
.serialCont(_ColorTextures
);
120 f
.serialCont(_TextureInstanceData
);
121 f
.serialCont(_TextureInstances
);
123 // Must compile ptrs.
126 // compile the ptrs only.
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
];
144 // ***************************************************************************
145 // ***************************************************************************
146 // CHLSTextureBank::CTextureInstance
147 // ***************************************************************************
148 // ***************************************************************************
151 // ***************************************************************************
152 void CHLSTextureBank::CTextureInstance::serial(NLMISC::IStream
&f
)
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
);