1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
19 #include "nel/3d/texture_blend.h"
20 #include "nel/misc/common.h"
30 CTextureBlend::CTextureBlend() : _BlendFactor(0), _SharingEnabled(true)
35 // ************************************************************************
36 bool CTextureBlend::supportSharing() const
38 return _BlendTex
[0] && _BlendTex
[0]->supportSharing()
39 && _BlendTex
[1] && _BlendTex
[1]->supportSharing();
42 // ************************************************************************
43 std::string
CTextureBlend::getShareName() const
45 nlassert(supportSharing());
47 NLMISC::smprintf(fmt
, 1024, "BlendTex0:%s:BlendTex1:%s:blendFactor:%d",
48 _BlendTex
[0]->getShareName().c_str(), _BlendTex
[1]->getShareName().c_str(),
55 // ************************************************************************
56 void CTextureBlend::enableSharing(bool enabled
/*= false*/)
58 _SharingEnabled
= enabled
;
62 // ************************************************************************
63 void CTextureBlend::release()
65 if (_BlendTex
[0] && _BlendTex
[0]->getReleasable()) _BlendTex
[0]->release();
66 if (_BlendTex
[1] && _BlendTex
[1]->getReleasable()) _BlendTex
[1]->release();
70 // ************************************************************************
71 bool CTextureBlend::setBlendFactor(uint16 factor
)
73 nlassert(factor
<= 256);
74 if (factor
!= _BlendFactor
)
76 _BlendFactor
= factor
;
77 touch(); // need to recompute blending
84 // ************************************************************************
85 void CTextureBlend::setBlendTexture(uint index
, ITexture
*tex
)
88 if (tex
!= _BlendTex
[index
])
90 _BlendTex
[index
] = tex
;
91 touch(); // need to recompute blending
96 // ************************************************************************
97 void CTextureBlend::doGenerate(bool async
)
99 if (!_BlendTex
[0] || !_BlendTex
[1])
104 //NLMISC::TTicks start = NLMISC::CTime::getPerformanceTime();
105 _BlendTex
[0]->generate();
106 _BlendTex
[1]->generate();
108 this->blend(*_BlendTex
[0], *_BlendTex
[1], _BlendFactor
, true);
109 /*NLMISC::TTicks end = NLMISC::CTime::getPerformanceTime();
110 nlinfo("blend time = %.2f", (float) (1000 * NLMISC::CTime::ticksToSecond(end - start)));*/
114 // ************************************************************************
115 void CTextureBlend::serial(NLMISC::IStream
&f
)
119 for (uint k
= 0; k
< 2; ++k
)
121 ITexture
*tex
= NULL
;
124 f
.serialPolyPtr(tex
);
131 f
.serialPolyPtr(tex
);
134 f
.serial(_SharingEnabled
, _BlendFactor
);