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/>.
18 #include "nel/3d/ps_attrib_maker_template.h"
19 #include "nel/misc/system_info.h"
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
);
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
];
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
));
59 pxor mm0
, mm0
// mm0 = 0
61 punpcklbw mm0
, mm1
// store current col in mm0, each component is stored in 7:8 fixed integer
63 movq mm2
, stepPacked
// store step for gradient
69 // unpack current color
71 add edi
, eax
// advance destination
74 movd
[edi
], mm1
// store result
75 paddsw mm0
, mm2
// increment color
86 // copy the tab performing linear interpolation between values given in parameter
87 for (uint32 k
= 0; k
< (numValues
- 1); ++k
)
91 for(uint32 l
= 0; l
< nbStages
; ++l
)
93 // use the right version of the template function PSValueBlend
95 *dest
++ = PSValueBlend(valueTab
[k
], valueTab
[k
+ 1], alpha
);
100 *dest
= valueTab
[numValues
- 1];