Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / 3d / ps_attrib_maker_template.cpp
blob66fe5912dceb1611ec334ba3bda50b1fa3496d7a
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"
18 #include "nel/3d/ps_attrib_maker_template.h"
19 #include "nel/misc/system_info.h"
21 #ifdef DEBUG_NEW
22 #define new DEBUG_NEW
23 #endif
25 namespace NL3D
29 void computeGradient(const NLMISC::CRGBA *valueTab, uint32 numValues, uint32 nbStages, CPSVector<NLMISC::CRGBA>::V &grad, NLMISC::CRGBA &minValue, NLMISC::CRGBA &maxValue)
31 nlassert(numValues > 1);
32 nlassert(nbStages > 0);
34 maxValue = minValue = valueTab[0];
35 uint nbValues = (numValues - 1) * nbStages;
36 grad.resize(nbValues + 1);
39 float step = 1.0f / float(nbStages);
40 float alpha;
42 NLMISC::CRGBA *dest = &grad[0];
43 #if defined(NL_OS_WINDOWS) && !defined(NL_NO_ASM)
44 float stepX127 = 127.f * step;
45 if (NLMISC::CSystemInfo::hasMMX())
47 // do interpolation using mmx
48 for (uint32 k = 0; k < (numValues - 1); ++k)
50 uint32 col0 = *(uint32 *) &valueTab[k];
51 uint64 stepPacked;
52 sint16 *step = (sint16 *) &stepPacked;
53 step[0] = (sint16) (stepX127 * (valueTab[k + 1].R - valueTab[k].R));
54 step[1] = (sint16) (stepX127 * (valueTab[k + 1].G - valueTab[k].G));
55 step[2] = (sint16) (stepX127 * (valueTab[k + 1].B - valueTab[k].B));
56 step[3] = (sint16) (stepX127 * (valueTab[k + 1].A - valueTab[k].A));
57 __asm
59 pxor mm0, mm0 // mm0 = 0
60 movd mm1, col0
61 punpcklbw mm0, mm1 // store current col in mm0, each component is stored in 7:8 fixed integer
62 psrlw mm0, 1
63 movq mm2, stepPacked // store step for gradient
64 mov edi, dest
65 mov eax, 4
66 mov ecx, nbStages
67 sub edi, eax
68 myLoop:
69 // unpack current color
70 movq mm1, mm0
71 add edi, eax // advance destination
72 psrlw mm1, 7
73 packuswb mm1, mm1
74 movd [edi], mm1 // store result
75 paddsw mm0, mm2 // increment color
76 dec ecx
77 jne myLoop
78 emms
80 dest += nbStages;
83 else
84 #endif
86 // copy the tab performing linear interpolation between values given in parameter
87 for (uint32 k = 0; k < (numValues - 1); ++k)
89 alpha = 0;
91 for(uint32 l = 0; l < nbStages; ++l)
93 // use the right version of the template function PSValueBlend
94 // to do the job
95 *dest++ = PSValueBlend(valueTab[k], valueTab[k + 1], alpha);
96 alpha += step;
100 *dest = valueTab[numValues - 1];