Show bonus/malus timer text if available
[ryzomcore.git] / nel / src / 3d / texture_blend.cpp
blobaad39cc6dcd03c60a445a3e1a3fa1dc3626247c7
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"
19 #include "nel/3d/texture_blend.h"
20 #include "nel/misc/common.h"
22 #ifdef DEBUG_NEW
23 #define new DEBUG_NEW
24 #endif
26 namespace NL3D {
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());
46 char fmt[1024];
47 NLMISC::smprintf(fmt, 1024, "BlendTex0:%s:BlendTex1:%s:blendFactor:%d",
48 _BlendTex[0]->getShareName().c_str(), _BlendTex[1]->getShareName().c_str(),
49 (uint) _BlendFactor
51 return fmt;
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();
67 ITexture::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
78 return true;
80 return false;
84 // ************************************************************************
85 void CTextureBlend::setBlendTexture(uint index, ITexture *tex)
87 nlassert(index < 2);
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])
101 makeDummy();
102 return;
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)
117 f.serialVersion(0);
118 ITexture::serial(f);
119 for (uint k = 0; k < 2; ++k)
121 ITexture *tex = NULL;
122 if (f.isReading())
124 f.serialPolyPtr(tex);
125 _BlendTex[k] = tex;
126 touch();
128 else
130 tex = _BlendTex[k];
131 f.serialPolyPtr(tex);
134 f.serial(_SharingEnabled, _BlendFactor);
137 } // NL3D