Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / sky_material_setup.cpp
blob10074ba6b26c7d3e228137210b92a5e7ec32c05a
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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/>.
21 #include "stdpch.h"
22 #include "nel/3d/u_instance_material.h"
23 #include "sky_material_setup.h"
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 using namespace NL3D;
31 H_AUTO_DECL(RZ_SkyMaterialSetup)
33 //===================================================================================
34 void CSkyMaterialSetup::buildFromInstance(NL3D::UInstance instance, uint stage)
36 H_AUTO_USE(RZ_SkyMaterialSetup)
37 nlassert(stage < 2);
38 if (instance.empty())
40 Setup.clear();
41 return;
43 Setup.clear();
44 CTexInfo ti;
45 // take each texture at the given stage that is a texture file
46 for(uint k = 0; k < instance.getNumMaterials(); ++k)
48 UInstanceMaterial im = instance.getMaterial(k);
49 uint currStage;
50 if (im.getLastTextureStage() >= (sint) stage) currStage = stage;
51 else currStage = 0;
52 if (im.isTextureFile(currStage))
54 ti.MatNum = k;
55 ti.TexName = im.getTextureFileName(currStage);
56 Setup.push_back(ti);
61 //===================================================================================
62 void CSkyMaterialSetup::applyToInstance(NL3D::UInstance instance, uint stage, bool skipFirstMaterial /*= false*/)
64 H_AUTO_USE(RZ_SkyMaterialSetup)
65 nlassert(stage < 2);
66 if (instance.empty()) return;
67 for(uint k = 0; k < Setup.size(); ++k)
69 if (skipFirstMaterial && Setup[k].MatNum == 0) continue;
70 if (Setup[k].MatNum < instance.getNumMaterials())
72 NL3D::UInstanceMaterial im = instance.getMaterial(Setup[k].MatNum);
73 uint currStage;
74 if (im.getLastTextureStage() >= (sint) stage) currStage = stage;
75 else currStage = 0;
76 if (!im.isTextureFile(currStage)) continue;
77 if (NLMISC::nlstricmp(Setup[k].TexName, im.getTextureFileName(currStage)) != 0) // must change name ?
79 im.setTextureFileName(Setup[k].TexName, currStage);