diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/SoftwareDriver2_helper.h')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/SoftwareDriver2_helper.h | 2084 |
1 files changed, 1042 insertions, 1042 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/SoftwareDriver2_helper.h b/libraries/irrlicht-1.8/source/Irrlicht/SoftwareDriver2_helper.h index 263548b..fa50860 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/SoftwareDriver2_helper.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/SoftwareDriver2_helper.h | |||
@@ -1,1042 +1,1042 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | /* | 5 | /* |
6 | History: | 6 | History: |
7 | - changed behavior for log2 textures ( replaced multiplies by shift ) | 7 | - changed behavior for log2 textures ( replaced multiplies by shift ) |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #ifndef __S_VIDEO_2_SOFTWARE_HELPER_H_INCLUDED__ | 10 | #ifndef __S_VIDEO_2_SOFTWARE_HELPER_H_INCLUDED__ |
11 | #define __S_VIDEO_2_SOFTWARE_HELPER_H_INCLUDED__ | 11 | #define __S_VIDEO_2_SOFTWARE_HELPER_H_INCLUDED__ |
12 | 12 | ||
13 | #include "SoftwareDriver2_compile_config.h" | 13 | #include "SoftwareDriver2_compile_config.h" |
14 | #include "irrMath.h" | 14 | #include "irrMath.h" |
15 | #include "CSoftwareTexture2.h" | 15 | #include "CSoftwareTexture2.h" |
16 | #include "SMaterial.h" | 16 | #include "SMaterial.h" |
17 | 17 | ||
18 | 18 | ||
19 | 19 | ||
20 | namespace irr | 20 | namespace irr |
21 | { | 21 | { |
22 | 22 | ||
23 | // supporting different packed pixel needs many defines... | 23 | // supporting different packed pixel needs many defines... |
24 | 24 | ||
25 | #ifdef SOFTWARE_DRIVER_2_32BIT | 25 | #ifdef SOFTWARE_DRIVER_2_32BIT |
26 | typedef u32 tVideoSample; | 26 | typedef u32 tVideoSample; |
27 | 27 | ||
28 | #define MASK_A 0xFF000000 | 28 | #define MASK_A 0xFF000000 |
29 | #define MASK_R 0x00FF0000 | 29 | #define MASK_R 0x00FF0000 |
30 | #define MASK_G 0x0000FF00 | 30 | #define MASK_G 0x0000FF00 |
31 | #define MASK_B 0x000000FF | 31 | #define MASK_B 0x000000FF |
32 | 32 | ||
33 | #define SHIFT_A 24 | 33 | #define SHIFT_A 24 |
34 | #define SHIFT_R 16 | 34 | #define SHIFT_R 16 |
35 | #define SHIFT_G 8 | 35 | #define SHIFT_G 8 |
36 | #define SHIFT_B 0 | 36 | #define SHIFT_B 0 |
37 | 37 | ||
38 | #define COLOR_MAX 0xFF | 38 | #define COLOR_MAX 0xFF |
39 | #define COLOR_MAX_LOG2 8 | 39 | #define COLOR_MAX_LOG2 8 |
40 | #define COLOR_BRIGHT_WHITE 0xFFFFFFFF | 40 | #define COLOR_BRIGHT_WHITE 0xFFFFFFFF |
41 | 41 | ||
42 | #define VIDEO_SAMPLE_GRANULARITY 2 | 42 | #define VIDEO_SAMPLE_GRANULARITY 2 |
43 | 43 | ||
44 | #else | 44 | #else |
45 | typedef u16 tVideoSample; | 45 | typedef u16 tVideoSample; |
46 | 46 | ||
47 | #define MASK_A 0x8000 | 47 | #define MASK_A 0x8000 |
48 | #define MASK_R 0x7C00 | 48 | #define MASK_R 0x7C00 |
49 | #define MASK_G 0x03E0 | 49 | #define MASK_G 0x03E0 |
50 | #define MASK_B 0x001F | 50 | #define MASK_B 0x001F |
51 | 51 | ||
52 | #define SHIFT_A 15 | 52 | #define SHIFT_A 15 |
53 | #define SHIFT_R 10 | 53 | #define SHIFT_R 10 |
54 | #define SHIFT_G 5 | 54 | #define SHIFT_G 5 |
55 | #define SHIFT_B 0 | 55 | #define SHIFT_B 0 |
56 | 56 | ||
57 | #define COLOR_MAX 0x1F | 57 | #define COLOR_MAX 0x1F |
58 | #define COLOR_MAX_LOG2 5 | 58 | #define COLOR_MAX_LOG2 5 |
59 | #define COLOR_BRIGHT_WHITE 0xFFFF | 59 | #define COLOR_BRIGHT_WHITE 0xFFFF |
60 | #define VIDEO_SAMPLE_GRANULARITY 1 | 60 | #define VIDEO_SAMPLE_GRANULARITY 1 |
61 | 61 | ||
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | 64 | ||
65 | 65 | ||
66 | 66 | ||
67 | // ----------------------- Generic ---------------------------------- | 67 | // ----------------------- Generic ---------------------------------- |
68 | 68 | ||
69 | //! a more useful memset for pixel | 69 | //! a more useful memset for pixel |
70 | // (standard memset only works with 8-bit values) | 70 | // (standard memset only works with 8-bit values) |
71 | inline void memset32(void * dest, const u32 value, u32 bytesize) | 71 | inline void memset32(void * dest, const u32 value, u32 bytesize) |
72 | { | 72 | { |
73 | u32 * d = (u32*) dest; | 73 | u32 * d = (u32*) dest; |
74 | 74 | ||
75 | u32 i; | 75 | u32 i; |
76 | 76 | ||
77 | // loops unrolled to reduce the number of increments by factor ~8. | 77 | // loops unrolled to reduce the number of increments by factor ~8. |
78 | i = bytesize >> (2 + 3); | 78 | i = bytesize >> (2 + 3); |
79 | while (i) | 79 | while (i) |
80 | { | 80 | { |
81 | d[0] = value; | 81 | d[0] = value; |
82 | d[1] = value; | 82 | d[1] = value; |
83 | d[2] = value; | 83 | d[2] = value; |
84 | d[3] = value; | 84 | d[3] = value; |
85 | 85 | ||
86 | d[4] = value; | 86 | d[4] = value; |
87 | d[5] = value; | 87 | d[5] = value; |
88 | d[6] = value; | 88 | d[6] = value; |
89 | d[7] = value; | 89 | d[7] = value; |
90 | 90 | ||
91 | d += 8; | 91 | d += 8; |
92 | i -= 1; | 92 | i -= 1; |
93 | } | 93 | } |
94 | 94 | ||
95 | i = (bytesize >> 2 ) & 7; | 95 | i = (bytesize >> 2 ) & 7; |
96 | while (i) | 96 | while (i) |
97 | { | 97 | { |
98 | d[0] = value; | 98 | d[0] = value; |
99 | d += 1; | 99 | d += 1; |
100 | i -= 1; | 100 | i -= 1; |
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
104 | //! a more useful memset for pixel | 104 | //! a more useful memset for pixel |
105 | // (standard memset only works with 8-bit values) | 105 | // (standard memset only works with 8-bit values) |
106 | inline void memset16(void * dest, const u16 value, u32 bytesize) | 106 | inline void memset16(void * dest, const u16 value, u32 bytesize) |
107 | { | 107 | { |
108 | u16 * d = (u16*) dest; | 108 | u16 * d = (u16*) dest; |
109 | 109 | ||
110 | u32 i; | 110 | u32 i; |
111 | 111 | ||
112 | // loops unrolled to reduce the number of increments by factor ~8. | 112 | // loops unrolled to reduce the number of increments by factor ~8. |
113 | i = bytesize >> (1 + 3); | 113 | i = bytesize >> (1 + 3); |
114 | while (i) | 114 | while (i) |
115 | { | 115 | { |
116 | d[0] = value; | 116 | d[0] = value; |
117 | d[1] = value; | 117 | d[1] = value; |
118 | d[2] = value; | 118 | d[2] = value; |
119 | d[3] = value; | 119 | d[3] = value; |
120 | 120 | ||
121 | d[4] = value; | 121 | d[4] = value; |
122 | d[5] = value; | 122 | d[5] = value; |
123 | d[6] = value; | 123 | d[6] = value; |
124 | d[7] = value; | 124 | d[7] = value; |
125 | 125 | ||
126 | d += 8; | 126 | d += 8; |
127 | --i; | 127 | --i; |
128 | } | 128 | } |
129 | 129 | ||
130 | i = (bytesize >> 1 ) & 7; | 130 | i = (bytesize >> 1 ) & 7; |
131 | while (i) | 131 | while (i) |
132 | { | 132 | { |
133 | d[0] = value; | 133 | d[0] = value; |
134 | ++d; | 134 | ++d; |
135 | --i; | 135 | --i; |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | /* | 139 | /* |
140 | use biased loop counter | 140 | use biased loop counter |
141 | --> 0 byte copy is forbidden | 141 | --> 0 byte copy is forbidden |
142 | */ | 142 | */ |
143 | REALINLINE void memcpy32_small ( void * dest, const void *source, u32 bytesize ) | 143 | REALINLINE void memcpy32_small ( void * dest, const void *source, u32 bytesize ) |
144 | { | 144 | { |
145 | u32 c = bytesize >> 2; | 145 | u32 c = bytesize >> 2; |
146 | 146 | ||
147 | do | 147 | do |
148 | { | 148 | { |
149 | ((u32*) dest ) [ c-1 ] = ((u32*) source) [ c-1 ]; | 149 | ((u32*) dest ) [ c-1 ] = ((u32*) source) [ c-1 ]; |
150 | } while ( --c ); | 150 | } while ( --c ); |
151 | 151 | ||
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | 155 | ||
156 | // integer log2 of a float ieee 754. TODO: non ieee floating point | 156 | // integer log2 of a float ieee 754. TODO: non ieee floating point |
157 | static inline s32 s32_log2_f32( f32 f) | 157 | static inline s32 s32_log2_f32( f32 f) |
158 | { | 158 | { |
159 | u32 x = IR ( f ); | 159 | u32 x = IR ( f ); |
160 | return ((x & 0x7F800000) >> 23) - 127; | 160 | return ((x & 0x7F800000) >> 23) - 127; |
161 | } | 161 | } |
162 | 162 | ||
163 | static inline s32 s32_log2_s32(u32 x) | 163 | static inline s32 s32_log2_s32(u32 x) |
164 | { | 164 | { |
165 | return s32_log2_f32( (f32) x); | 165 | return s32_log2_f32( (f32) x); |
166 | } | 166 | } |
167 | 167 | ||
168 | static inline s32 s32_abs(s32 x) | 168 | static inline s32 s32_abs(s32 x) |
169 | { | 169 | { |
170 | s32 b = x >> 31; | 170 | s32 b = x >> 31; |
171 | return (x ^ b ) - b; | 171 | return (x ^ b ) - b; |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | //! conditional set based on mask and arithmetic shift | 175 | //! conditional set based on mask and arithmetic shift |
176 | REALINLINE u32 if_mask_a_else_b ( const u32 mask, const u32 a, const u32 b ) | 176 | REALINLINE u32 if_mask_a_else_b ( const u32 mask, const u32 a, const u32 b ) |
177 | { | 177 | { |
178 | return ( mask & ( a ^ b ) ) ^ b; | 178 | return ( mask & ( a ^ b ) ) ^ b; |
179 | } | 179 | } |
180 | 180 | ||
181 | // ------------------ Video--------------------------------------- | 181 | // ------------------ Video--------------------------------------- |
182 | /*! | 182 | /*! |
183 | Pixel = dest * ( 1 - alpha ) + source * alpha | 183 | Pixel = dest * ( 1 - alpha ) + source * alpha |
184 | alpha [0;256] | 184 | alpha [0;256] |
185 | */ | 185 | */ |
186 | REALINLINE u32 PixelBlend32 ( const u32 c2, const u32 c1, u32 alpha ) | 186 | REALINLINE u32 PixelBlend32 ( const u32 c2, const u32 c1, u32 alpha ) |
187 | { | 187 | { |
188 | u32 srcRB = c1 & 0x00FF00FF; | 188 | u32 srcRB = c1 & 0x00FF00FF; |
189 | u32 srcXG = c1 & 0x0000FF00; | 189 | u32 srcXG = c1 & 0x0000FF00; |
190 | 190 | ||
191 | u32 dstRB = c2 & 0x00FF00FF; | 191 | u32 dstRB = c2 & 0x00FF00FF; |
192 | u32 dstXG = c2 & 0x0000FF00; | 192 | u32 dstXG = c2 & 0x0000FF00; |
193 | 193 | ||
194 | 194 | ||
195 | u32 rb = srcRB - dstRB; | 195 | u32 rb = srcRB - dstRB; |
196 | u32 xg = srcXG - dstXG; | 196 | u32 xg = srcXG - dstXG; |
197 | 197 | ||
198 | rb *= alpha; | 198 | rb *= alpha; |
199 | xg *= alpha; | 199 | xg *= alpha; |
200 | rb >>= 8; | 200 | rb >>= 8; |
201 | xg >>= 8; | 201 | xg >>= 8; |
202 | 202 | ||
203 | rb += dstRB; | 203 | rb += dstRB; |
204 | xg += dstXG; | 204 | xg += dstXG; |
205 | 205 | ||
206 | rb &= 0x00FF00FF; | 206 | rb &= 0x00FF00FF; |
207 | xg &= 0x0000FF00; | 207 | xg &= 0x0000FF00; |
208 | 208 | ||
209 | return rb | xg; | 209 | return rb | xg; |
210 | } | 210 | } |
211 | 211 | ||
212 | /*! | 212 | /*! |
213 | Pixel = dest * ( 1 - alpha ) + source * alpha | 213 | Pixel = dest * ( 1 - alpha ) + source * alpha |
214 | alpha [0;32] | 214 | alpha [0;32] |
215 | */ | 215 | */ |
216 | inline u16 PixelBlend16 ( const u16 c2, const u32 c1, const u16 alpha ) | 216 | inline u16 PixelBlend16 ( const u16 c2, const u32 c1, const u16 alpha ) |
217 | { | 217 | { |
218 | const u16 srcRB = c1 & 0x7C1F; | 218 | const u16 srcRB = c1 & 0x7C1F; |
219 | const u16 srcXG = c1 & 0x03E0; | 219 | const u16 srcXG = c1 & 0x03E0; |
220 | 220 | ||
221 | const u16 dstRB = c2 & 0x7C1F; | 221 | const u16 dstRB = c2 & 0x7C1F; |
222 | const u16 dstXG = c2 & 0x03E0; | 222 | const u16 dstXG = c2 & 0x03E0; |
223 | 223 | ||
224 | u32 rb = srcRB - dstRB; | 224 | u32 rb = srcRB - dstRB; |
225 | u32 xg = srcXG - dstXG; | 225 | u32 xg = srcXG - dstXG; |
226 | 226 | ||
227 | rb *= alpha; | 227 | rb *= alpha; |
228 | xg *= alpha; | 228 | xg *= alpha; |
229 | rb >>= 5; | 229 | rb >>= 5; |
230 | xg >>= 5; | 230 | xg >>= 5; |
231 | 231 | ||
232 | rb += dstRB; | 232 | rb += dstRB; |
233 | xg += dstXG; | 233 | xg += dstXG; |
234 | 234 | ||
235 | rb &= 0x7C1F; | 235 | rb &= 0x7C1F; |
236 | xg &= 0x03E0; | 236 | xg &= 0x03E0; |
237 | 237 | ||
238 | return (u16)(rb | xg); | 238 | return (u16)(rb | xg); |
239 | } | 239 | } |
240 | 240 | ||
241 | /* | 241 | /* |
242 | Pixel = c0 * (c1/31). c0 Alpha retain | 242 | Pixel = c0 * (c1/31). c0 Alpha retain |
243 | */ | 243 | */ |
244 | inline u16 PixelMul16 ( const u16 c0, const u16 c1) | 244 | inline u16 PixelMul16 ( const u16 c0, const u16 c1) |
245 | { | 245 | { |
246 | return (u16)((( ( (c0 & 0x7C00) * (c1 & 0x7C00) ) & 0x3E000000 ) >> 15 ) | | 246 | return (u16)((( ( (c0 & 0x7C00) * (c1 & 0x7C00) ) & 0x3E000000 ) >> 15 ) | |
247 | (( ( (c0 & 0x03E0) * (c1 & 0x03E0) ) & 0x000F8000 ) >> 10 ) | | 247 | (( ( (c0 & 0x03E0) * (c1 & 0x03E0) ) & 0x000F8000 ) >> 10 ) | |
248 | (( ( (c0 & 0x001F) * (c1 & 0x001F) ) & 0x000003E0 ) >> 5 ) | | 248 | (( ( (c0 & 0x001F) * (c1 & 0x001F) ) & 0x000003E0 ) >> 5 ) | |
249 | (c0 & 0x8000)); | 249 | (c0 & 0x8000)); |
250 | } | 250 | } |
251 | 251 | ||
252 | /* | 252 | /* |
253 | Pixel = c0 * (c1/31). | 253 | Pixel = c0 * (c1/31). |
254 | */ | 254 | */ |
255 | inline u16 PixelMul16_2 ( u16 c0, u16 c1) | 255 | inline u16 PixelMul16_2 ( u16 c0, u16 c1) |
256 | { | 256 | { |
257 | return (u16)(( ( (c0 & 0x7C00) * (c1 & 0x7C00) ) & 0x3E000000 ) >> 15 | | 257 | return (u16)(( ( (c0 & 0x7C00) * (c1 & 0x7C00) ) & 0x3E000000 ) >> 15 | |
258 | ( ( (c0 & 0x03E0) * (c1 & 0x03E0) ) & 0x000F8000 ) >> 10 | | 258 | ( ( (c0 & 0x03E0) * (c1 & 0x03E0) ) & 0x000F8000 ) >> 10 | |
259 | ( ( (c0 & 0x001F) * (c1 & 0x001F) ) & 0x000003E0 ) >> 5 | | 259 | ( ( (c0 & 0x001F) * (c1 & 0x001F) ) & 0x000003E0 ) >> 5 | |
260 | ( c0 & c1 & 0x8000)); | 260 | ( c0 & c1 & 0x8000)); |
261 | } | 261 | } |
262 | 262 | ||
263 | /* | 263 | /* |
264 | Pixel = c0 * (c1/255). c0 Alpha Retain | 264 | Pixel = c0 * (c1/255). c0 Alpha Retain |
265 | */ | 265 | */ |
266 | REALINLINE u32 PixelMul32 ( const u32 c0, const u32 c1) | 266 | REALINLINE u32 PixelMul32 ( const u32 c0, const u32 c1) |
267 | { | 267 | { |
268 | return (c0 & 0xFF000000) | | 268 | return (c0 & 0xFF000000) | |
269 | (( ( (c0 & 0x00FF0000) >> 12 ) * ( (c1 & 0x00FF0000) >> 12 ) ) & 0x00FF0000 ) | | 269 | (( ( (c0 & 0x00FF0000) >> 12 ) * ( (c1 & 0x00FF0000) >> 12 ) ) & 0x00FF0000 ) | |
270 | (( ( (c0 & 0x0000FF00) * (c1 & 0x0000FF00) ) >> 16 ) & 0x0000FF00 ) | | 270 | (( ( (c0 & 0x0000FF00) * (c1 & 0x0000FF00) ) >> 16 ) & 0x0000FF00 ) | |
271 | (( ( (c0 & 0x000000FF) * (c1 & 0x000000FF) ) >> 8 ) & 0x000000FF); | 271 | (( ( (c0 & 0x000000FF) * (c1 & 0x000000FF) ) >> 8 ) & 0x000000FF); |
272 | } | 272 | } |
273 | 273 | ||
274 | /* | 274 | /* |
275 | Pixel = c0 * (c1/255). | 275 | Pixel = c0 * (c1/255). |
276 | */ | 276 | */ |
277 | REALINLINE u32 PixelMul32_2 ( const u32 c0, const u32 c1) | 277 | REALINLINE u32 PixelMul32_2 ( const u32 c0, const u32 c1) |
278 | { | 278 | { |
279 | return (( ( (c0 & 0xFF000000) >> 16 ) * ( (c1 & 0xFF000000) >> 16 ) ) & 0xFF000000 ) | | 279 | return (( ( (c0 & 0xFF000000) >> 16 ) * ( (c1 & 0xFF000000) >> 16 ) ) & 0xFF000000 ) | |
280 | (( ( (c0 & 0x00FF0000) >> 12 ) * ( (c1 & 0x00FF0000) >> 12 ) ) & 0x00FF0000 ) | | 280 | (( ( (c0 & 0x00FF0000) >> 12 ) * ( (c1 & 0x00FF0000) >> 12 ) ) & 0x00FF0000 ) | |
281 | (( ( (c0 & 0x0000FF00) * (c1 & 0x0000FF00) ) >> 16 ) & 0x0000FF00 ) | | 281 | (( ( (c0 & 0x0000FF00) * (c1 & 0x0000FF00) ) >> 16 ) & 0x0000FF00 ) | |
282 | (( ( (c0 & 0x000000FF) * (c1 & 0x000000FF) ) >> 8 ) & 0x000000FF); | 282 | (( ( (c0 & 0x000000FF) * (c1 & 0x000000FF) ) >> 8 ) & 0x000000FF); |
283 | } | 283 | } |
284 | 284 | ||
285 | /* | 285 | /* |
286 | Pixel = clamp ( c0 + c1, 0, 255 ) | 286 | Pixel = clamp ( c0 + c1, 0, 255 ) |
287 | */ | 287 | */ |
288 | REALINLINE u32 PixelAdd32 ( const u32 c2, const u32 c1) | 288 | REALINLINE u32 PixelAdd32 ( const u32 c2, const u32 c1) |
289 | { | 289 | { |
290 | u32 sum = ( c2 & 0x00FFFFFF ) + ( c1 & 0x00FFFFFF ); | 290 | u32 sum = ( c2 & 0x00FFFFFF ) + ( c1 & 0x00FFFFFF ); |
291 | u32 low_bits = ( c2 ^ c1 ) & 0x00010101; | 291 | u32 low_bits = ( c2 ^ c1 ) & 0x00010101; |
292 | s32 carries = ( sum - low_bits ) & 0x01010100; | 292 | s32 carries = ( sum - low_bits ) & 0x01010100; |
293 | u32 modulo = sum - carries; | 293 | u32 modulo = sum - carries; |
294 | u32 clamp = carries - ( carries >> 8 ); | 294 | u32 clamp = carries - ( carries >> 8 ); |
295 | return modulo | clamp; | 295 | return modulo | clamp; |
296 | } | 296 | } |
297 | 297 | ||
298 | #if 0 | 298 | #if 0 |
299 | 299 | ||
300 | // 1 - Bit Alpha Blending | 300 | // 1 - Bit Alpha Blending |
301 | inline u16 PixelBlend16 ( const u16 destination, const u16 source ) | 301 | inline u16 PixelBlend16 ( const u16 destination, const u16 source ) |
302 | { | 302 | { |
303 | if((source & 0x8000) == 0x8000) | 303 | if((source & 0x8000) == 0x8000) |
304 | return source; // The source is visible, so use it. | 304 | return source; // The source is visible, so use it. |
305 | else | 305 | else |
306 | return destination; // The source is transparent, so use the destination. | 306 | return destination; // The source is transparent, so use the destination. |
307 | } | 307 | } |
308 | 308 | ||
309 | // 1 - Bit Alpha Blending 16Bit SIMD | 309 | // 1 - Bit Alpha Blending 16Bit SIMD |
310 | inline u32 PixelBlend16_simd ( const u32 destination, const u32 source ) | 310 | inline u32 PixelBlend16_simd ( const u32 destination, const u32 source ) |
311 | { | 311 | { |
312 | switch(source & 0x80008000) | 312 | switch(source & 0x80008000) |
313 | { | 313 | { |
314 | case 0x80008000: // Both source pixels are visible | 314 | case 0x80008000: // Both source pixels are visible |
315 | return source; | 315 | return source; |
316 | 316 | ||
317 | case 0x80000000: // Only the first source pixel is visible | 317 | case 0x80000000: // Only the first source pixel is visible |
318 | return (source & 0xFFFF0000) | (destination & 0x0000FFFF); | 318 | return (source & 0xFFFF0000) | (destination & 0x0000FFFF); |
319 | 319 | ||
320 | case 0x00008000: // Only the second source pixel is visible. | 320 | case 0x00008000: // Only the second source pixel is visible. |
321 | return (destination & 0xFFFF0000) | (source & 0x0000FFFF); | 321 | return (destination & 0xFFFF0000) | (source & 0x0000FFFF); |
322 | 322 | ||
323 | default: // Neither source pixel is visible. | 323 | default: // Neither source pixel is visible. |
324 | return destination; | 324 | return destination; |
325 | } | 325 | } |
326 | } | 326 | } |
327 | #else | 327 | #else |
328 | 328 | ||
329 | // 1 - Bit Alpha Blending | 329 | // 1 - Bit Alpha Blending |
330 | inline u16 PixelBlend16 ( const u16 c2, const u16 c1 ) | 330 | inline u16 PixelBlend16 ( const u16 c2, const u16 c1 ) |
331 | { | 331 | { |
332 | u16 mask = ((c1 & 0x8000) >> 15 ) + 0x7fff; | 332 | u16 mask = ((c1 & 0x8000) >> 15 ) + 0x7fff; |
333 | return (c2 & mask ) | ( c1 & ~mask ); | 333 | return (c2 & mask ) | ( c1 & ~mask ); |
334 | } | 334 | } |
335 | 335 | ||
336 | // 1 - Bit Alpha Blending 16Bit SIMD | 336 | // 1 - Bit Alpha Blending 16Bit SIMD |
337 | inline u32 PixelBlend16_simd ( const u32 c2, const u32 c1 ) | 337 | inline u32 PixelBlend16_simd ( const u32 c2, const u32 c1 ) |
338 | { | 338 | { |
339 | u32 mask = ((c1 & 0x80008000) >> 15 ) + 0x7fff7fff; | 339 | u32 mask = ((c1 & 0x80008000) >> 15 ) + 0x7fff7fff; |
340 | return (c2 & mask ) | ( c1 & ~mask ); | 340 | return (c2 & mask ) | ( c1 & ~mask ); |
341 | } | 341 | } |
342 | 342 | ||
343 | #endif | 343 | #endif |
344 | 344 | ||
345 | /*! | 345 | /*! |
346 | Pixel = dest * ( 1 - SourceAlpha ) + source * SourceAlpha | 346 | Pixel = dest * ( 1 - SourceAlpha ) + source * SourceAlpha |
347 | */ | 347 | */ |
348 | inline u32 PixelBlend32 ( const u32 c2, const u32 c1 ) | 348 | inline u32 PixelBlend32 ( const u32 c2, const u32 c1 ) |
349 | { | 349 | { |
350 | // alpha test | 350 | // alpha test |
351 | u32 alpha = c1 & 0xFF000000; | 351 | u32 alpha = c1 & 0xFF000000; |
352 | 352 | ||
353 | if ( 0 == alpha ) | 353 | if ( 0 == alpha ) |
354 | return c2; | 354 | return c2; |
355 | 355 | ||
356 | if ( 0xFF000000 == alpha ) | 356 | if ( 0xFF000000 == alpha ) |
357 | { | 357 | { |
358 | return c1; | 358 | return c1; |
359 | } | 359 | } |
360 | 360 | ||
361 | alpha >>= 24; | 361 | alpha >>= 24; |
362 | 362 | ||
363 | // add highbit alpha, if ( alpha > 127 ) alpha += 1; | 363 | // add highbit alpha, if ( alpha > 127 ) alpha += 1; |
364 | alpha += ( alpha >> 7); | 364 | alpha += ( alpha >> 7); |
365 | 365 | ||
366 | u32 srcRB = c1 & 0x00FF00FF; | 366 | u32 srcRB = c1 & 0x00FF00FF; |
367 | u32 srcXG = c1 & 0x0000FF00; | 367 | u32 srcXG = c1 & 0x0000FF00; |
368 | 368 | ||
369 | u32 dstRB = c2 & 0x00FF00FF; | 369 | u32 dstRB = c2 & 0x00FF00FF; |
370 | u32 dstXG = c2 & 0x0000FF00; | 370 | u32 dstXG = c2 & 0x0000FF00; |
371 | 371 | ||
372 | 372 | ||
373 | u32 rb = srcRB - dstRB; | 373 | u32 rb = srcRB - dstRB; |
374 | u32 xg = srcXG - dstXG; | 374 | u32 xg = srcXG - dstXG; |
375 | 375 | ||
376 | rb *= alpha; | 376 | rb *= alpha; |
377 | xg *= alpha; | 377 | xg *= alpha; |
378 | rb >>= 8; | 378 | rb >>= 8; |
379 | xg >>= 8; | 379 | xg >>= 8; |
380 | 380 | ||
381 | rb += dstRB; | 381 | rb += dstRB; |
382 | xg += dstXG; | 382 | xg += dstXG; |
383 | 383 | ||
384 | rb &= 0x00FF00FF; | 384 | rb &= 0x00FF00FF; |
385 | xg &= 0x0000FF00; | 385 | xg &= 0x0000FF00; |
386 | 386 | ||
387 | return (c1 & 0xFF000000) | rb | xg; | 387 | return (c1 & 0xFF000000) | rb | xg; |
388 | } | 388 | } |
389 | 389 | ||
390 | 390 | ||
391 | 391 | ||
392 | // ------------------ Fix Point ---------------------------------- | 392 | // ------------------ Fix Point ---------------------------------- |
393 | 393 | ||
394 | typedef s32 tFixPoint; | 394 | typedef s32 tFixPoint; |
395 | typedef u32 tFixPointu; | 395 | typedef u32 tFixPointu; |
396 | 396 | ||
397 | // Fix Point 12 | 397 | // Fix Point 12 |
398 | #if 0 | 398 | #if 0 |
399 | #define FIX_POINT_PRE 12 | 399 | #define FIX_POINT_PRE 12 |
400 | #define FIX_POINT_FRACT_MASK 0xFFF | 400 | #define FIX_POINT_FRACT_MASK 0xFFF |
401 | #define FIX_POINT_SIGNED_MASK 0xFFFFF000 | 401 | #define FIX_POINT_SIGNED_MASK 0xFFFFF000 |
402 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFF000 | 402 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFF000 |
403 | #define FIX_POINT_ONE 0x1000 | 403 | #define FIX_POINT_ONE 0x1000 |
404 | #define FIX_POINT_ZERO_DOT_FIVE 0x0800 | 404 | #define FIX_POINT_ZERO_DOT_FIVE 0x0800 |
405 | #define FIX_POINT_F32_MUL 4096.f | 405 | #define FIX_POINT_F32_MUL 4096.f |
406 | #endif | 406 | #endif |
407 | 407 | ||
408 | // Fix Point 10 | 408 | // Fix Point 10 |
409 | #if 1 | 409 | #if 1 |
410 | #define FIX_POINT_PRE 10 | 410 | #define FIX_POINT_PRE 10 |
411 | #define FIX_POINT_FRACT_MASK 0x3FF | 411 | #define FIX_POINT_FRACT_MASK 0x3FF |
412 | #define FIX_POINT_SIGNED_MASK 0xFFFFFC00 | 412 | #define FIX_POINT_SIGNED_MASK 0xFFFFFC00 |
413 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFFE00 | 413 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFFE00 |
414 | #define FIX_POINT_ONE 0x400 | 414 | #define FIX_POINT_ONE 0x400 |
415 | #define FIX_POINT_ZERO_DOT_FIVE 0x200 | 415 | #define FIX_POINT_ZERO_DOT_FIVE 0x200 |
416 | #define FIX_POINT_F32_MUL 1024.f | 416 | #define FIX_POINT_F32_MUL 1024.f |
417 | #endif | 417 | #endif |
418 | 418 | ||
419 | // Fix Point 9 | 419 | // Fix Point 9 |
420 | #if 0 | 420 | #if 0 |
421 | #define FIX_POINT_PRE 9 | 421 | #define FIX_POINT_PRE 9 |
422 | #define FIX_POINT_FRACT_MASK 0x1FF | 422 | #define FIX_POINT_FRACT_MASK 0x1FF |
423 | #define FIX_POINT_SIGNED_MASK 0xFFFFFE00 | 423 | #define FIX_POINT_SIGNED_MASK 0xFFFFFE00 |
424 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFFE00 | 424 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFFE00 |
425 | #define FIX_POINT_ONE 0x200 | 425 | #define FIX_POINT_ONE 0x200 |
426 | #define FIX_POINT_ZERO_DOT_FIVE 0x100 | 426 | #define FIX_POINT_ZERO_DOT_FIVE 0x100 |
427 | #define FIX_POINT_F32_MUL 512.f | 427 | #define FIX_POINT_F32_MUL 512.f |
428 | #endif | 428 | #endif |
429 | 429 | ||
430 | // Fix Point 7 | 430 | // Fix Point 7 |
431 | #if 0 | 431 | #if 0 |
432 | #define FIX_POINT_PRE 7 | 432 | #define FIX_POINT_PRE 7 |
433 | #define FIX_POINT_FRACT_MASK 0x7F | 433 | #define FIX_POINT_FRACT_MASK 0x7F |
434 | #define FIX_POINT_SIGNED_MASK 0xFFFFFF80 | 434 | #define FIX_POINT_SIGNED_MASK 0xFFFFFF80 |
435 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFFF80 | 435 | #define FIX_POINT_UNSIGNED_MASK 0x7FFFFF80 |
436 | #define FIX_POINT_ONE 0x80 | 436 | #define FIX_POINT_ONE 0x80 |
437 | #define FIX_POINT_ZERO_DOT_FIVE 0x40 | 437 | #define FIX_POINT_ZERO_DOT_FIVE 0x40 |
438 | #define FIX_POINT_F32_MUL 128.f | 438 | #define FIX_POINT_F32_MUL 128.f |
439 | #endif | 439 | #endif |
440 | 440 | ||
441 | #define FIXPOINT_COLOR_MAX ( COLOR_MAX << FIX_POINT_PRE ) | 441 | #define FIXPOINT_COLOR_MAX ( COLOR_MAX << FIX_POINT_PRE ) |
442 | #define FIX_POINT_HALF_COLOR ( (tFixPoint) ( ((f32) COLOR_MAX / 2.f * FIX_POINT_F32_MUL ) ) ) | 442 | #define FIX_POINT_HALF_COLOR ( (tFixPoint) ( ((f32) COLOR_MAX / 2.f * FIX_POINT_F32_MUL ) ) ) |
443 | 443 | ||
444 | 444 | ||
445 | /* | 445 | /* |
446 | convert signed integer to fixpoint | 446 | convert signed integer to fixpoint |
447 | */ | 447 | */ |
448 | inline tFixPoint s32_to_fixPoint (const s32 x) | 448 | inline tFixPoint s32_to_fixPoint (const s32 x) |
449 | { | 449 | { |
450 | return x << FIX_POINT_PRE; | 450 | return x << FIX_POINT_PRE; |
451 | } | 451 | } |
452 | 452 | ||
453 | inline tFixPointu u32_to_fixPoint (const u32 x) | 453 | inline tFixPointu u32_to_fixPoint (const u32 x) |
454 | { | 454 | { |
455 | return x << FIX_POINT_PRE; | 455 | return x << FIX_POINT_PRE; |
456 | } | 456 | } |
457 | 457 | ||
458 | inline u32 fixPointu_to_u32 (const tFixPointu x) | 458 | inline u32 fixPointu_to_u32 (const tFixPointu x) |
459 | { | 459 | { |
460 | return x >> FIX_POINT_PRE; | 460 | return x >> FIX_POINT_PRE; |
461 | } | 461 | } |
462 | 462 | ||
463 | 463 | ||
464 | // 1/x * FIX_POINT | 464 | // 1/x * FIX_POINT |
465 | REALINLINE f32 fix_inverse32 ( const f32 x ) | 465 | REALINLINE f32 fix_inverse32 ( const f32 x ) |
466 | { | 466 | { |
467 | return FIX_POINT_F32_MUL / x; | 467 | return FIX_POINT_F32_MUL / x; |
468 | } | 468 | } |
469 | 469 | ||
470 | 470 | ||
471 | /* | 471 | /* |
472 | convert float to fixpoint | 472 | convert float to fixpoint |
473 | fast convert (fistp on x86) HAS to be used.. | 473 | fast convert (fistp on x86) HAS to be used.. |
474 | hints: compileflag /QIfist for msvc7. msvc 8.0 has smth different | 474 | hints: compileflag /QIfist for msvc7. msvc 8.0 has smth different |
475 | others should use their favourite assembler.. | 475 | others should use their favourite assembler.. |
476 | */ | 476 | */ |
477 | static inline int f_round2(f32 f) | 477 | static inline int f_round2(f32 f) |
478 | { | 478 | { |
479 | f += (3<<22); | 479 | f += (3<<22); |
480 | return IR(f) - 0x4b400000; | 480 | return IR(f) - 0x4b400000; |
481 | } | 481 | } |
482 | 482 | ||
483 | /* | 483 | /* |
484 | convert f32 to Fix Point. | 484 | convert f32 to Fix Point. |
485 | multiply is needed anyway, so scale mulby | 485 | multiply is needed anyway, so scale mulby |
486 | */ | 486 | */ |
487 | REALINLINE tFixPoint tofix (const f32 x, const f32 mulby = FIX_POINT_F32_MUL ) | 487 | REALINLINE tFixPoint tofix (const f32 x, const f32 mulby = FIX_POINT_F32_MUL ) |
488 | { | 488 | { |
489 | return (tFixPoint) (x * mulby); | 489 | return (tFixPoint) (x * mulby); |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | /* | 493 | /* |
494 | Fix Point , Fix Point Multiply | 494 | Fix Point , Fix Point Multiply |
495 | */ | 495 | */ |
496 | REALINLINE tFixPointu imulFixu(const tFixPointu x, const tFixPointu y) | 496 | REALINLINE tFixPointu imulFixu(const tFixPointu x, const tFixPointu y) |
497 | { | 497 | { |
498 | return (x * y) >> (tFixPointu) FIX_POINT_PRE; | 498 | return (x * y) >> (tFixPointu) FIX_POINT_PRE; |
499 | } | 499 | } |
500 | 500 | ||
501 | /* | 501 | /* |
502 | Fix Point , Fix Point Multiply | 502 | Fix Point , Fix Point Multiply |
503 | */ | 503 | */ |
504 | REALINLINE tFixPoint imulFix(const tFixPoint x, const tFixPoint y) | 504 | REALINLINE tFixPoint imulFix(const tFixPoint x, const tFixPoint y) |
505 | { | 505 | { |
506 | return ( x * y) >> ( FIX_POINT_PRE ); | 506 | return ( x * y) >> ( FIX_POINT_PRE ); |
507 | } | 507 | } |
508 | 508 | ||
509 | /* | 509 | /* |
510 | Fix Point , Fix Point Multiply x * y * 2 | 510 | Fix Point , Fix Point Multiply x * y * 2 |
511 | */ | 511 | */ |
512 | REALINLINE tFixPoint imulFix2(const tFixPoint x, const tFixPoint y) | 512 | REALINLINE tFixPoint imulFix2(const tFixPoint x, const tFixPoint y) |
513 | { | 513 | { |
514 | return ( x * y) >> ( FIX_POINT_PRE -1 ); | 514 | return ( x * y) >> ( FIX_POINT_PRE -1 ); |
515 | } | 515 | } |
516 | 516 | ||
517 | 517 | ||
518 | /* | 518 | /* |
519 | Multiply x * y * 1 | 519 | Multiply x * y * 1 |
520 | */ | 520 | */ |
521 | REALINLINE tFixPoint imulFix_tex1(const tFixPoint x, const tFixPoint y) | 521 | REALINLINE tFixPoint imulFix_tex1(const tFixPoint x, const tFixPoint y) |
522 | { | 522 | { |
523 | return ( ( (tFixPointu) x >> 2 ) * ( (tFixPointu) y >> 2 ) ) >> (tFixPointu) ( FIX_POINT_PRE + 4 ); | 523 | return ( ( (tFixPointu) x >> 2 ) * ( (tFixPointu) y >> 2 ) ) >> (tFixPointu) ( FIX_POINT_PRE + 4 ); |
524 | } | 524 | } |
525 | 525 | ||
526 | /* | 526 | /* |
527 | Multiply x * y * 2 | 527 | Multiply x * y * 2 |
528 | */ | 528 | */ |
529 | REALINLINE tFixPoint imulFix_tex2(const tFixPoint x, const tFixPoint y) | 529 | REALINLINE tFixPoint imulFix_tex2(const tFixPoint x, const tFixPoint y) |
530 | { | 530 | { |
531 | return ( ( (tFixPointu) x >> 2 ) * ( (tFixPointu) y >> 2 ) ) >> (tFixPointu) ( FIX_POINT_PRE + 3 ); | 531 | return ( ( (tFixPointu) x >> 2 ) * ( (tFixPointu) y >> 2 ) ) >> (tFixPointu) ( FIX_POINT_PRE + 3 ); |
532 | } | 532 | } |
533 | 533 | ||
534 | /* | 534 | /* |
535 | Multiply x * y * 4 | 535 | Multiply x * y * 4 |
536 | */ | 536 | */ |
537 | REALINLINE tFixPoint imulFix_tex4(const tFixPoint x, const tFixPoint y) | 537 | REALINLINE tFixPoint imulFix_tex4(const tFixPoint x, const tFixPoint y) |
538 | { | 538 | { |
539 | #ifdef SOFTWARE_DRIVER_2_32BIT | 539 | #ifdef SOFTWARE_DRIVER_2_32BIT |
540 | return ( ( (tFixPointu) x >> 2 ) * ( (tFixPointu) y >> 2 ) ) >> (tFixPointu) ( FIX_POINT_PRE + 2 ); | 540 | return ( ( (tFixPointu) x >> 2 ) * ( (tFixPointu) y >> 2 ) ) >> (tFixPointu) ( FIX_POINT_PRE + 2 ); |
541 | #else | 541 | #else |
542 | return ( x * y) >> ( FIX_POINT_PRE + ( VIDEO_SAMPLE_GRANULARITY * 3 ) ); | 542 | return ( x * y) >> ( FIX_POINT_PRE + ( VIDEO_SAMPLE_GRANULARITY * 3 ) ); |
543 | #endif | 543 | #endif |
544 | } | 544 | } |
545 | 545 | ||
546 | /*! | 546 | /*! |
547 | clamp FixPoint to maxcolor in FixPoint, min(a,31) | 547 | clamp FixPoint to maxcolor in FixPoint, min(a,31) |
548 | */ | 548 | */ |
549 | REALINLINE tFixPoint clampfix_maxcolor ( const tFixPoint a) | 549 | REALINLINE tFixPoint clampfix_maxcolor ( const tFixPoint a) |
550 | { | 550 | { |
551 | tFixPoint c = (a - FIXPOINT_COLOR_MAX) >> 31; | 551 | tFixPoint c = (a - FIXPOINT_COLOR_MAX) >> 31; |
552 | return (a & c) | ( FIXPOINT_COLOR_MAX & ~c); | 552 | return (a & c) | ( FIXPOINT_COLOR_MAX & ~c); |
553 | } | 553 | } |
554 | 554 | ||
555 | /*! | 555 | /*! |
556 | clamp FixPoint to 0 in FixPoint, max(a,0) | 556 | clamp FixPoint to 0 in FixPoint, max(a,0) |
557 | */ | 557 | */ |
558 | REALINLINE tFixPoint clampfix_mincolor ( const tFixPoint a) | 558 | REALINLINE tFixPoint clampfix_mincolor ( const tFixPoint a) |
559 | { | 559 | { |
560 | return a - ( a & ( a >> 31 ) ); | 560 | return a - ( a & ( a >> 31 ) ); |
561 | } | 561 | } |
562 | 562 | ||
563 | REALINLINE tFixPoint saturateFix ( const tFixPoint a) | 563 | REALINLINE tFixPoint saturateFix ( const tFixPoint a) |
564 | { | 564 | { |
565 | return clampfix_mincolor ( clampfix_maxcolor ( a ) ); | 565 | return clampfix_mincolor ( clampfix_maxcolor ( a ) ); |
566 | } | 566 | } |
567 | 567 | ||
568 | 568 | ||
569 | // rount fixpoint to int | 569 | // rount fixpoint to int |
570 | inline s32 roundFix ( const tFixPoint x ) | 570 | inline s32 roundFix ( const tFixPoint x ) |
571 | { | 571 | { |
572 | return ( x + FIX_POINT_ZERO_DOT_FIVE ) >> FIX_POINT_PRE; | 572 | return ( x + FIX_POINT_ZERO_DOT_FIVE ) >> FIX_POINT_PRE; |
573 | } | 573 | } |
574 | 574 | ||
575 | 575 | ||
576 | 576 | ||
577 | // x in [0;1[ | 577 | // x in [0;1[ |
578 | inline s32 f32_to_23Bits(const f32 x) | 578 | inline s32 f32_to_23Bits(const f32 x) |
579 | { | 579 | { |
580 | f32 y = x + 1.f; | 580 | f32 y = x + 1.f; |
581 | return IR(y) & 0x7FFFFF; // last 23 bits | 581 | return IR(y) & 0x7FFFFF; // last 23 bits |
582 | } | 582 | } |
583 | 583 | ||
584 | /*! | 584 | /*! |
585 | return VideoSample from fixpoint | 585 | return VideoSample from fixpoint |
586 | */ | 586 | */ |
587 | REALINLINE tVideoSample fix_to_color ( const tFixPoint r, const tFixPoint g, const tFixPoint b ) | 587 | REALINLINE tVideoSample fix_to_color ( const tFixPoint r, const tFixPoint g, const tFixPoint b ) |
588 | { | 588 | { |
589 | #ifdef __BIG_ENDIAN__ | 589 | #ifdef __BIG_ENDIAN__ |
590 | return FIXPOINT_COLOR_MAX | | 590 | return FIXPOINT_COLOR_MAX | |
591 | ( r & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - 8) | | 591 | ( r & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - 8) | |
592 | ( g & FIXPOINT_COLOR_MAX) << ( 16 - FIX_POINT_PRE ) | | 592 | ( g & FIXPOINT_COLOR_MAX) << ( 16 - FIX_POINT_PRE ) | |
593 | ( b & FIXPOINT_COLOR_MAX) << ( 24 - FIX_POINT_PRE ); | 593 | ( b & FIXPOINT_COLOR_MAX) << ( 24 - FIX_POINT_PRE ); |
594 | #else | 594 | #else |
595 | return ( FIXPOINT_COLOR_MAX & FIXPOINT_COLOR_MAX) << ( SHIFT_A - FIX_POINT_PRE ) | | 595 | return ( FIXPOINT_COLOR_MAX & FIXPOINT_COLOR_MAX) << ( SHIFT_A - FIX_POINT_PRE ) | |
596 | ( r & FIXPOINT_COLOR_MAX) << ( SHIFT_R - FIX_POINT_PRE ) | | 596 | ( r & FIXPOINT_COLOR_MAX) << ( SHIFT_R - FIX_POINT_PRE ) | |
597 | ( g & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_G ) | | 597 | ( g & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_G ) | |
598 | ( b & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_B ); | 598 | ( b & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_B ); |
599 | #endif | 599 | #endif |
600 | } | 600 | } |
601 | 601 | ||
602 | 602 | ||
603 | /*! | 603 | /*! |
604 | return VideoSample from fixpoint | 604 | return VideoSample from fixpoint |
605 | */ | 605 | */ |
606 | REALINLINE tVideoSample fix4_to_color ( const tFixPoint a, const tFixPoint r, const tFixPoint g, const tFixPoint b ) | 606 | REALINLINE tVideoSample fix4_to_color ( const tFixPoint a, const tFixPoint r, const tFixPoint g, const tFixPoint b ) |
607 | { | 607 | { |
608 | #ifdef __BIG_ENDIAN__ | 608 | #ifdef __BIG_ENDIAN__ |
609 | return ( a & (FIX_POINT_FRACT_MASK - 1 )) >> ( FIX_POINT_PRE ) | | 609 | return ( a & (FIX_POINT_FRACT_MASK - 1 )) >> ( FIX_POINT_PRE ) | |
610 | ( r & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - 8) | | 610 | ( r & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - 8) | |
611 | ( g & FIXPOINT_COLOR_MAX) << ( 16 - FIX_POINT_PRE ) | | 611 | ( g & FIXPOINT_COLOR_MAX) << ( 16 - FIX_POINT_PRE ) | |
612 | ( b & FIXPOINT_COLOR_MAX) << ( 24 - FIX_POINT_PRE ); | 612 | ( b & FIXPOINT_COLOR_MAX) << ( 24 - FIX_POINT_PRE ); |
613 | #else | 613 | #else |
614 | return ( a & (FIX_POINT_FRACT_MASK - 1 )) << ( SHIFT_A - 1 ) | | 614 | return ( a & (FIX_POINT_FRACT_MASK - 1 )) << ( SHIFT_A - 1 ) | |
615 | ( r & FIXPOINT_COLOR_MAX) << ( SHIFT_R - FIX_POINT_PRE ) | | 615 | ( r & FIXPOINT_COLOR_MAX) << ( SHIFT_R - FIX_POINT_PRE ) | |
616 | ( g & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_G ) | | 616 | ( g & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_G ) | |
617 | ( b & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_B ); | 617 | ( b & FIXPOINT_COLOR_MAX) >> ( FIX_POINT_PRE - SHIFT_B ); |
618 | #endif | 618 | #endif |
619 | 619 | ||
620 | } | 620 | } |
621 | 621 | ||
622 | /*! | 622 | /*! |
623 | return fixpoint from VideoSample granularity COLOR_MAX | 623 | return fixpoint from VideoSample granularity COLOR_MAX |
624 | */ | 624 | */ |
625 | inline void color_to_fix ( tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) | 625 | inline void color_to_fix ( tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) |
626 | { | 626 | { |
627 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE ); | 627 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE ); |
628 | (tFixPointu&) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); | 628 | (tFixPointu&) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); |
629 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); | 629 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); |
630 | } | 630 | } |
631 | 631 | ||
632 | /*! | 632 | /*! |
633 | return fixpoint from VideoSample granularity COLOR_MAX | 633 | return fixpoint from VideoSample granularity COLOR_MAX |
634 | */ | 634 | */ |
635 | inline void color_to_fix ( tFixPoint &a, tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) | 635 | inline void color_to_fix ( tFixPoint &a, tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) |
636 | { | 636 | { |
637 | (tFixPointu&) a = (t00 & MASK_A) >> ( SHIFT_A - FIX_POINT_PRE ); | 637 | (tFixPointu&) a = (t00 & MASK_A) >> ( SHIFT_A - FIX_POINT_PRE ); |
638 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE ); | 638 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE ); |
639 | (tFixPointu&) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); | 639 | (tFixPointu&) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); |
640 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); | 640 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); |
641 | } | 641 | } |
642 | 642 | ||
643 | /*! | 643 | /*! |
644 | return fixpoint from VideoSample granularity 0..FIX_POINT_ONE | 644 | return fixpoint from VideoSample granularity 0..FIX_POINT_ONE |
645 | */ | 645 | */ |
646 | inline void color_to_fix1 ( tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) | 646 | inline void color_to_fix1 ( tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) |
647 | { | 647 | { |
648 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R + COLOR_MAX_LOG2 - FIX_POINT_PRE ); | 648 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R + COLOR_MAX_LOG2 - FIX_POINT_PRE ); |
649 | (tFixPointu&) g = (t00 & MASK_G) >> ( SHIFT_G + COLOR_MAX_LOG2 - FIX_POINT_PRE ); | 649 | (tFixPointu&) g = (t00 & MASK_G) >> ( SHIFT_G + COLOR_MAX_LOG2 - FIX_POINT_PRE ); |
650 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - COLOR_MAX_LOG2 ); | 650 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - COLOR_MAX_LOG2 ); |
651 | } | 651 | } |
652 | 652 | ||
653 | /*! | 653 | /*! |
654 | return fixpoint from VideoSample granularity 0..FIX_POINT_ONE | 654 | return fixpoint from VideoSample granularity 0..FIX_POINT_ONE |
655 | */ | 655 | */ |
656 | inline void color_to_fix1 ( tFixPoint &a, tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) | 656 | inline void color_to_fix1 ( tFixPoint &a, tFixPoint &r, tFixPoint &g, tFixPoint &b, const tVideoSample t00 ) |
657 | { | 657 | { |
658 | (tFixPointu&) a = (t00 & MASK_A) >> ( SHIFT_A + COLOR_MAX_LOG2 - FIX_POINT_PRE ); | 658 | (tFixPointu&) a = (t00 & MASK_A) >> ( SHIFT_A + COLOR_MAX_LOG2 - FIX_POINT_PRE ); |
659 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R + COLOR_MAX_LOG2 - FIX_POINT_PRE ); | 659 | (tFixPointu&) r = (t00 & MASK_R) >> ( SHIFT_R + COLOR_MAX_LOG2 - FIX_POINT_PRE ); |
660 | (tFixPointu&) g = (t00 & MASK_G) >> ( SHIFT_G + COLOR_MAX_LOG2 - FIX_POINT_PRE ); | 660 | (tFixPointu&) g = (t00 & MASK_G) >> ( SHIFT_G + COLOR_MAX_LOG2 - FIX_POINT_PRE ); |
661 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - COLOR_MAX_LOG2 ); | 661 | (tFixPointu&) b = (t00 & MASK_B) << ( FIX_POINT_PRE - COLOR_MAX_LOG2 ); |
662 | } | 662 | } |
663 | 663 | ||
664 | 664 | ||
665 | 665 | ||
666 | // ----- FP24 ---- floating point z-buffer | 666 | // ----- FP24 ---- floating point z-buffer |
667 | 667 | ||
668 | #if 1 | 668 | #if 1 |
669 | typedef f32 fp24; | 669 | typedef f32 fp24; |
670 | #else | 670 | #else |
671 | struct fp24 | 671 | struct fp24 |
672 | { | 672 | { |
673 | u32 v; | 673 | u32 v; |
674 | 674 | ||
675 | fp24() {} | 675 | fp24() {} |
676 | 676 | ||
677 | fp24 ( const f32 f ) | 677 | fp24 ( const f32 f ) |
678 | { | 678 | { |
679 | f32 y = f + 1.f; | 679 | f32 y = f + 1.f; |
680 | v = ((u32&)y) & 0x7FFFFF; // last 23 bits | 680 | v = ((u32&)y) & 0x7FFFFF; // last 23 bits |
681 | } | 681 | } |
682 | 682 | ||
683 | void operator=(const f32 f ) | 683 | void operator=(const f32 f ) |
684 | { | 684 | { |
685 | f32 y = f + 1.f; | 685 | f32 y = f + 1.f; |
686 | v = ((u32&)y) & 0x7FFFFF; // last 23 bits | 686 | v = ((u32&)y) & 0x7FFFFF; // last 23 bits |
687 | } | 687 | } |
688 | 688 | ||
689 | void operator+=(const fp24 &other ) | 689 | void operator+=(const fp24 &other ) |
690 | { | 690 | { |
691 | v += other.v; | 691 | v += other.v; |
692 | } | 692 | } |
693 | 693 | ||
694 | operator f32 () const | 694 | operator f32 () const |
695 | { | 695 | { |
696 | f32 r = FR ( v ); | 696 | f32 r = FR ( v ); |
697 | return r + 1.f; | 697 | return r + 1.f; |
698 | } | 698 | } |
699 | 699 | ||
700 | }; | 700 | }; |
701 | #endif | 701 | #endif |
702 | 702 | ||
703 | 703 | ||
704 | // ------------------------ Internal Texture ----------------------------- | 704 | // ------------------------ Internal Texture ----------------------------- |
705 | 705 | ||
706 | struct sInternalTexture | 706 | struct sInternalTexture |
707 | { | 707 | { |
708 | u32 textureXMask; | 708 | u32 textureXMask; |
709 | u32 textureYMask; | 709 | u32 textureYMask; |
710 | 710 | ||
711 | u32 pitchlog2; | 711 | u32 pitchlog2; |
712 | void *data; | 712 | void *data; |
713 | 713 | ||
714 | video::CSoftwareTexture2 *Texture; | 714 | video::CSoftwareTexture2 *Texture; |
715 | s32 lodLevel; | 715 | s32 lodLevel; |
716 | }; | 716 | }; |
717 | 717 | ||
718 | 718 | ||
719 | 719 | ||
720 | // get video sample plain | 720 | // get video sample plain |
721 | inline tVideoSample getTexel_plain ( const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty ) | 721 | inline tVideoSample getTexel_plain ( const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty ) |
722 | { | 722 | { |
723 | u32 ofs; | 723 | u32 ofs; |
724 | 724 | ||
725 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 725 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
726 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 726 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
727 | 727 | ||
728 | // texel | 728 | // texel |
729 | return *((tVideoSample*)( (u8*) t->data + ofs )); | 729 | return *((tVideoSample*)( (u8*) t->data + ofs )); |
730 | } | 730 | } |
731 | 731 | ||
732 | // get video sample to fix | 732 | // get video sample to fix |
733 | inline void getTexel_fix ( tFixPoint &r, tFixPoint &g, tFixPoint &b, | 733 | inline void getTexel_fix ( tFixPoint &r, tFixPoint &g, tFixPoint &b, |
734 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 734 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
735 | ) | 735 | ) |
736 | { | 736 | { |
737 | u32 ofs; | 737 | u32 ofs; |
738 | 738 | ||
739 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 739 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
740 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 740 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
741 | 741 | ||
742 | // texel | 742 | // texel |
743 | tVideoSample t00; | 743 | tVideoSample t00; |
744 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); | 744 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); |
745 | 745 | ||
746 | r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); | 746 | r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); |
747 | g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); | 747 | g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); |
748 | b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); | 748 | b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); |
749 | 749 | ||
750 | } | 750 | } |
751 | 751 | ||
752 | // get video sample to fixpoint | 752 | // get video sample to fixpoint |
753 | REALINLINE void getTexel_fix ( tFixPoint &a, | 753 | REALINLINE void getTexel_fix ( tFixPoint &a, |
754 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 754 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
755 | ) | 755 | ) |
756 | { | 756 | { |
757 | u32 ofs; | 757 | u32 ofs; |
758 | 758 | ||
759 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 759 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
760 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 760 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
761 | 761 | ||
762 | // texel | 762 | // texel |
763 | tVideoSample t00; | 763 | tVideoSample t00; |
764 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); | 764 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); |
765 | 765 | ||
766 | a = (t00 & MASK_A) >> ( SHIFT_A - FIX_POINT_PRE); | 766 | a = (t00 & MASK_A) >> ( SHIFT_A - FIX_POINT_PRE); |
767 | } | 767 | } |
768 | 768 | ||
769 | 769 | ||
770 | inline void getSample_texture_dither ( tFixPoint &r, tFixPoint &g, tFixPoint &b, | 770 | inline void getSample_texture_dither ( tFixPoint &r, tFixPoint &g, tFixPoint &b, |
771 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty, | 771 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty, |
772 | const u32 x, const u32 y | 772 | const u32 x, const u32 y |
773 | ) | 773 | ) |
774 | { | 774 | { |
775 | static const tFixPointu dithermask[] = | 775 | static const tFixPointu dithermask[] = |
776 | { | 776 | { |
777 | 0x00,0x80,0x20,0xa0, | 777 | 0x00,0x80,0x20,0xa0, |
778 | 0xc0,0x40,0xe0,0x60, | 778 | 0xc0,0x40,0xe0,0x60, |
779 | 0x30,0xb0,0x10,0x90, | 779 | 0x30,0xb0,0x10,0x90, |
780 | 0xf0,0x70,0xd0,0x50 | 780 | 0xf0,0x70,0xd0,0x50 |
781 | }; | 781 | }; |
782 | 782 | ||
783 | const u32 index = (y & 3 ) << 2 | (x & 3); | 783 | const u32 index = (y & 3 ) << 2 | (x & 3); |
784 | 784 | ||
785 | const tFixPointu _ntx = (tx + dithermask [ index ] ) & t->textureXMask; | 785 | const tFixPointu _ntx = (tx + dithermask [ index ] ) & t->textureXMask; |
786 | const tFixPointu _nty = (ty + dithermask [ index ] ) & t->textureYMask; | 786 | const tFixPointu _nty = (ty + dithermask [ index ] ) & t->textureYMask; |
787 | 787 | ||
788 | u32 ofs; | 788 | u32 ofs; |
789 | ofs = ( ( _nty ) >> FIX_POINT_PRE ) << t->pitchlog2; | 789 | ofs = ( ( _nty ) >> FIX_POINT_PRE ) << t->pitchlog2; |
790 | ofs |= ( _ntx ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 790 | ofs |= ( _ntx ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
791 | 791 | ||
792 | // texel | 792 | // texel |
793 | const tVideoSample t00 = *((tVideoSample*)( (u8*) t->data + ofs )); | 793 | const tVideoSample t00 = *((tVideoSample*)( (u8*) t->data + ofs )); |
794 | 794 | ||
795 | (tFixPointu &) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); | 795 | (tFixPointu &) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); |
796 | (tFixPointu &) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); | 796 | (tFixPointu &) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); |
797 | (tFixPointu &) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); | 797 | (tFixPointu &) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); |
798 | 798 | ||
799 | } | 799 | } |
800 | 800 | ||
801 | /* | 801 | /* |
802 | load a sample from internal texture at position tx,ty to fixpoint | 802 | load a sample from internal texture at position tx,ty to fixpoint |
803 | */ | 803 | */ |
804 | #ifndef SOFTWARE_DRIVER_2_BILINEAR | 804 | #ifndef SOFTWARE_DRIVER_2_BILINEAR |
805 | 805 | ||
806 | // get Sample linear == getSample_fixpoint | 806 | // get Sample linear == getSample_fixpoint |
807 | 807 | ||
808 | inline void getSample_texture ( tFixPoint &r, tFixPoint &g, tFixPoint &b, | 808 | inline void getSample_texture ( tFixPoint &r, tFixPoint &g, tFixPoint &b, |
809 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 809 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
810 | ) | 810 | ) |
811 | { | 811 | { |
812 | u32 ofs; | 812 | u32 ofs; |
813 | 813 | ||
814 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 814 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
815 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 815 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
816 | 816 | ||
817 | // texel | 817 | // texel |
818 | const tVideoSample t00 = *((tVideoSample*)( (u8*) t->data + ofs )); | 818 | const tVideoSample t00 = *((tVideoSample*)( (u8*) t->data + ofs )); |
819 | 819 | ||
820 | (tFixPointu &) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); | 820 | (tFixPointu &) r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); |
821 | (tFixPointu &) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); | 821 | (tFixPointu &) g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); |
822 | (tFixPointu &) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); | 822 | (tFixPointu &) b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); |
823 | } | 823 | } |
824 | 824 | ||
825 | inline void getSample_texture ( tFixPointu &a, tFixPointu &r, tFixPointu &g, tFixPointu &b, | 825 | inline void getSample_texture ( tFixPointu &a, tFixPointu &r, tFixPointu &g, tFixPointu &b, |
826 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 826 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
827 | ) | 827 | ) |
828 | { | 828 | { |
829 | u32 ofs; | 829 | u32 ofs; |
830 | 830 | ||
831 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 831 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
832 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 832 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
833 | 833 | ||
834 | // texel | 834 | // texel |
835 | const tVideoSample t00 = *((tVideoSample*)( (u8*) t->data + ofs )); | 835 | const tVideoSample t00 = *((tVideoSample*)( (u8*) t->data + ofs )); |
836 | 836 | ||
837 | (tFixPointu &)a = (t00 & MASK_A) >> ( SHIFT_A - FIX_POINT_PRE); | 837 | (tFixPointu &)a = (t00 & MASK_A) >> ( SHIFT_A - FIX_POINT_PRE); |
838 | (tFixPointu &)r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); | 838 | (tFixPointu &)r = (t00 & MASK_R) >> ( SHIFT_R - FIX_POINT_PRE); |
839 | (tFixPointu &)g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); | 839 | (tFixPointu &)g = (t00 & MASK_G) << ( FIX_POINT_PRE - SHIFT_G ); |
840 | (tFixPointu &)b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); | 840 | (tFixPointu &)b = (t00 & MASK_B) << ( FIX_POINT_PRE - SHIFT_B ); |
841 | } | 841 | } |
842 | 842 | ||
843 | 843 | ||
844 | #else | 844 | #else |
845 | 845 | ||
846 | 846 | ||
847 | // get sample linear | 847 | // get sample linear |
848 | REALINLINE void getSample_linear ( tFixPointu &r, tFixPointu &g, tFixPointu &b, | 848 | REALINLINE void getSample_linear ( tFixPointu &r, tFixPointu &g, tFixPointu &b, |
849 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 849 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
850 | ) | 850 | ) |
851 | { | 851 | { |
852 | u32 ofs; | 852 | u32 ofs; |
853 | 853 | ||
854 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 854 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
855 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 855 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
856 | 856 | ||
857 | // texel | 857 | // texel |
858 | tVideoSample t00; | 858 | tVideoSample t00; |
859 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); | 859 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); |
860 | 860 | ||
861 | r = (t00 & MASK_R) >> SHIFT_R; | 861 | r = (t00 & MASK_R) >> SHIFT_R; |
862 | g = (t00 & MASK_G) >> SHIFT_G; | 862 | g = (t00 & MASK_G) >> SHIFT_G; |
863 | b = (t00 & MASK_B); | 863 | b = (t00 & MASK_B); |
864 | } | 864 | } |
865 | 865 | ||
866 | // get Sample bilinear | 866 | // get Sample bilinear |
867 | REALINLINE void getSample_texture ( tFixPoint &r, tFixPoint &g, tFixPoint &b, | 867 | REALINLINE void getSample_texture ( tFixPoint &r, tFixPoint &g, tFixPoint &b, |
868 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 868 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
869 | ) | 869 | ) |
870 | { | 870 | { |
871 | 871 | ||
872 | tFixPointu r00,g00,b00; | 872 | tFixPointu r00,g00,b00; |
873 | tFixPointu r01,g01,b01; | 873 | tFixPointu r01,g01,b01; |
874 | tFixPointu r10,g10,b10; | 874 | tFixPointu r10,g10,b10; |
875 | tFixPointu r11,g11,b11; | 875 | tFixPointu r11,g11,b11; |
876 | 876 | ||
877 | #if 0 | 877 | #if 0 |
878 | getSample_linear ( r00, g00, b00, t, tx,ty ); | 878 | getSample_linear ( r00, g00, b00, t, tx,ty ); |
879 | getSample_linear ( r10, g10, b10, t, tx + FIX_POINT_ONE,ty ); | 879 | getSample_linear ( r10, g10, b10, t, tx + FIX_POINT_ONE,ty ); |
880 | getSample_linear ( r01, g01, b01, t, tx,ty + FIX_POINT_ONE ); | 880 | getSample_linear ( r01, g01, b01, t, tx,ty + FIX_POINT_ONE ); |
881 | getSample_linear ( r11, g11, b11, t, tx + FIX_POINT_ONE,ty + FIX_POINT_ONE ); | 881 | getSample_linear ( r11, g11, b11, t, tx + FIX_POINT_ONE,ty + FIX_POINT_ONE ); |
882 | #else | 882 | #else |
883 | u32 o0, o1,o2,o3; | 883 | u32 o0, o1,o2,o3; |
884 | tVideoSample t00; | 884 | tVideoSample t00; |
885 | 885 | ||
886 | o0 = ( ( (ty) & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 886 | o0 = ( ( (ty) & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
887 | o1 = ( ( (ty+FIX_POINT_ONE) & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 887 | o1 = ( ( (ty+FIX_POINT_ONE) & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
888 | o2 = ( (tx) & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 888 | o2 = ( (tx) & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
889 | o3 = ( (tx+FIX_POINT_ONE) & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 889 | o3 = ( (tx+FIX_POINT_ONE) & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
890 | 890 | ||
891 | t00 = *((tVideoSample*)( (u8*) t->data + (o0 | o2 ) )); | 891 | t00 = *((tVideoSample*)( (u8*) t->data + (o0 | o2 ) )); |
892 | r00 = (t00 & MASK_R) >> SHIFT_R; g00 = (t00 & MASK_G) >> SHIFT_G; b00 = (t00 & MASK_B); | 892 | r00 = (t00 & MASK_R) >> SHIFT_R; g00 = (t00 & MASK_G) >> SHIFT_G; b00 = (t00 & MASK_B); |
893 | 893 | ||
894 | t00 = *((tVideoSample*)( (u8*) t->data + (o0 | o3 ) )); | 894 | t00 = *((tVideoSample*)( (u8*) t->data + (o0 | o3 ) )); |
895 | r10 = (t00 & MASK_R) >> SHIFT_R; g10 = (t00 & MASK_G) >> SHIFT_G; b10 = (t00 & MASK_B); | 895 | r10 = (t00 & MASK_R) >> SHIFT_R; g10 = (t00 & MASK_G) >> SHIFT_G; b10 = (t00 & MASK_B); |
896 | 896 | ||
897 | t00 = *((tVideoSample*)( (u8*) t->data + (o1 | o2 ) )); | 897 | t00 = *((tVideoSample*)( (u8*) t->data + (o1 | o2 ) )); |
898 | r01 = (t00 & MASK_R) >> SHIFT_R; g01 = (t00 & MASK_G) >> SHIFT_G; b01 = (t00 & MASK_B); | 898 | r01 = (t00 & MASK_R) >> SHIFT_R; g01 = (t00 & MASK_G) >> SHIFT_G; b01 = (t00 & MASK_B); |
899 | 899 | ||
900 | t00 = *((tVideoSample*)( (u8*) t->data + (o1 | o3 ) )); | 900 | t00 = *((tVideoSample*)( (u8*) t->data + (o1 | o3 ) )); |
901 | r11 = (t00 & MASK_R) >> SHIFT_R; g11 = (t00 & MASK_G) >> SHIFT_G; b11 = (t00 & MASK_B); | 901 | r11 = (t00 & MASK_R) >> SHIFT_R; g11 = (t00 & MASK_G) >> SHIFT_G; b11 = (t00 & MASK_B); |
902 | 902 | ||
903 | #endif | 903 | #endif |
904 | 904 | ||
905 | const tFixPointu txFract = tx & FIX_POINT_FRACT_MASK; | 905 | const tFixPointu txFract = tx & FIX_POINT_FRACT_MASK; |
906 | const tFixPointu txFractInv = FIX_POINT_ONE - txFract; | 906 | const tFixPointu txFractInv = FIX_POINT_ONE - txFract; |
907 | 907 | ||
908 | const tFixPointu tyFract = ty & FIX_POINT_FRACT_MASK; | 908 | const tFixPointu tyFract = ty & FIX_POINT_FRACT_MASK; |
909 | const tFixPointu tyFractInv = FIX_POINT_ONE - tyFract; | 909 | const tFixPointu tyFractInv = FIX_POINT_ONE - tyFract; |
910 | 910 | ||
911 | const tFixPointu w00 = imulFixu ( txFractInv, tyFractInv ); | 911 | const tFixPointu w00 = imulFixu ( txFractInv, tyFractInv ); |
912 | const tFixPointu w10 = imulFixu ( txFract , tyFractInv ); | 912 | const tFixPointu w10 = imulFixu ( txFract , tyFractInv ); |
913 | const tFixPointu w01 = imulFixu ( txFractInv, tyFract ); | 913 | const tFixPointu w01 = imulFixu ( txFractInv, tyFract ); |
914 | const tFixPointu w11 = imulFixu ( txFract , tyFract ); | 914 | const tFixPointu w11 = imulFixu ( txFract , tyFract ); |
915 | 915 | ||
916 | r = (r00 * w00 ) + | 916 | r = (r00 * w00 ) + |
917 | (r01 * w01 ) + | 917 | (r01 * w01 ) + |
918 | (r10 * w10 ) + | 918 | (r10 * w10 ) + |
919 | (r11 * w11 ); | 919 | (r11 * w11 ); |
920 | 920 | ||
921 | g = (g00 * w00 ) + | 921 | g = (g00 * w00 ) + |
922 | (g01 * w01 ) + | 922 | (g01 * w01 ) + |
923 | (g10 * w10 ) + | 923 | (g10 * w10 ) + |
924 | (g11 * w11 ); | 924 | (g11 * w11 ); |
925 | 925 | ||
926 | b = (b00 * w00 ) + | 926 | b = (b00 * w00 ) + |
927 | (b01 * w01 ) + | 927 | (b01 * w01 ) + |
928 | (b10 * w10 ) + | 928 | (b10 * w10 ) + |
929 | (b11 * w11 ); | 929 | (b11 * w11 ); |
930 | 930 | ||
931 | } | 931 | } |
932 | 932 | ||
933 | 933 | ||
934 | // get sample linear | 934 | // get sample linear |
935 | REALINLINE void getSample_linear ( tFixPointu &a, tFixPointu &r, tFixPointu &g, tFixPointu &b, | 935 | REALINLINE void getSample_linear ( tFixPointu &a, tFixPointu &r, tFixPointu &g, tFixPointu &b, |
936 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 936 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
937 | ) | 937 | ) |
938 | { | 938 | { |
939 | u32 ofs; | 939 | u32 ofs; |
940 | 940 | ||
941 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; | 941 | ofs = ( ( ty & t->textureYMask ) >> FIX_POINT_PRE ) << t->pitchlog2; |
942 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); | 942 | ofs |= ( tx & t->textureXMask ) >> ( FIX_POINT_PRE - VIDEO_SAMPLE_GRANULARITY ); |
943 | 943 | ||
944 | // texel | 944 | // texel |
945 | tVideoSample t00; | 945 | tVideoSample t00; |
946 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); | 946 | t00 = *((tVideoSample*)( (u8*) t->data + ofs )); |
947 | 947 | ||
948 | a = (t00 & MASK_A) >> SHIFT_A; | 948 | a = (t00 & MASK_A) >> SHIFT_A; |
949 | r = (t00 & MASK_R) >> SHIFT_R; | 949 | r = (t00 & MASK_R) >> SHIFT_R; |
950 | g = (t00 & MASK_G) >> SHIFT_G; | 950 | g = (t00 & MASK_G) >> SHIFT_G; |
951 | b = (t00 & MASK_B); | 951 | b = (t00 & MASK_B); |
952 | } | 952 | } |
953 | 953 | ||
954 | // get Sample bilinear | 954 | // get Sample bilinear |
955 | REALINLINE void getSample_texture ( tFixPoint &a, tFixPoint &r, tFixPoint &g, tFixPoint &b, | 955 | REALINLINE void getSample_texture ( tFixPoint &a, tFixPoint &r, tFixPoint &g, tFixPoint &b, |
956 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty | 956 | const sInternalTexture * t, const tFixPointu tx, const tFixPointu ty |
957 | ) | 957 | ) |
958 | { | 958 | { |
959 | 959 | ||
960 | tFixPointu a00, r00,g00,b00; | 960 | tFixPointu a00, r00,g00,b00; |
961 | tFixPointu a01, r01,g01,b01; | 961 | tFixPointu a01, r01,g01,b01; |
962 | tFixPointu a10, r10,g10,b10; | 962 | tFixPointu a10, r10,g10,b10; |
963 | tFixPointu a11, r11,g11,b11; | 963 | tFixPointu a11, r11,g11,b11; |
964 | 964 | ||
965 | getSample_linear ( a00, r00, g00, b00, t, tx,ty ); | 965 | getSample_linear ( a00, r00, g00, b00, t, tx,ty ); |
966 | getSample_linear ( a10, r10, g10, b10, t, tx + FIX_POINT_ONE,ty ); | 966 | getSample_linear ( a10, r10, g10, b10, t, tx + FIX_POINT_ONE,ty ); |
967 | getSample_linear ( a01, r01, g01, b01, t, tx,ty + FIX_POINT_ONE ); | 967 | getSample_linear ( a01, r01, g01, b01, t, tx,ty + FIX_POINT_ONE ); |
968 | getSample_linear ( a11, r11, g11, b11, t, tx + FIX_POINT_ONE,ty + FIX_POINT_ONE ); | 968 | getSample_linear ( a11, r11, g11, b11, t, tx + FIX_POINT_ONE,ty + FIX_POINT_ONE ); |
969 | 969 | ||
970 | const tFixPointu txFract = tx & FIX_POINT_FRACT_MASK; | 970 | const tFixPointu txFract = tx & FIX_POINT_FRACT_MASK; |
971 | const tFixPointu txFractInv = FIX_POINT_ONE - txFract; | 971 | const tFixPointu txFractInv = FIX_POINT_ONE - txFract; |
972 | 972 | ||
973 | const tFixPointu tyFract = ty & FIX_POINT_FRACT_MASK; | 973 | const tFixPointu tyFract = ty & FIX_POINT_FRACT_MASK; |
974 | const tFixPointu tyFractInv = FIX_POINT_ONE - tyFract; | 974 | const tFixPointu tyFractInv = FIX_POINT_ONE - tyFract; |
975 | 975 | ||
976 | const tFixPointu w00 = imulFixu ( txFractInv, tyFractInv ); | 976 | const tFixPointu w00 = imulFixu ( txFractInv, tyFractInv ); |
977 | const tFixPointu w10 = imulFixu ( txFract , tyFractInv ); | 977 | const tFixPointu w10 = imulFixu ( txFract , tyFractInv ); |
978 | const tFixPointu w01 = imulFixu ( txFractInv, tyFract ); | 978 | const tFixPointu w01 = imulFixu ( txFractInv, tyFract ); |
979 | const tFixPointu w11 = imulFixu ( txFract , tyFract ); | 979 | const tFixPointu w11 = imulFixu ( txFract , tyFract ); |
980 | 980 | ||
981 | a = (a00 * w00 ) + | 981 | a = (a00 * w00 ) + |
982 | (a01 * w01 ) + | 982 | (a01 * w01 ) + |
983 | (a10 * w10 ) + | 983 | (a10 * w10 ) + |
984 | (a11 * w11 ); | 984 | (a11 * w11 ); |
985 | 985 | ||
986 | r = (r00 * w00 ) + | 986 | r = (r00 * w00 ) + |
987 | (r01 * w01 ) + | 987 | (r01 * w01 ) + |
988 | (r10 * w10 ) + | 988 | (r10 * w10 ) + |
989 | (r11 * w11 ); | 989 | (r11 * w11 ); |
990 | 990 | ||
991 | g = (g00 * w00 ) + | 991 | g = (g00 * w00 ) + |
992 | (g01 * w01 ) + | 992 | (g01 * w01 ) + |
993 | (g10 * w10 ) + | 993 | (g10 * w10 ) + |
994 | (g11 * w11 ); | 994 | (g11 * w11 ); |
995 | 995 | ||
996 | b = (b00 * w00 ) + | 996 | b = (b00 * w00 ) + |
997 | (b01 * w01 ) + | 997 | (b01 * w01 ) + |
998 | (b10 * w10 ) + | 998 | (b10 * w10 ) + |
999 | (b11 * w11 ); | 999 | (b11 * w11 ); |
1000 | 1000 | ||
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | 1003 | ||
1004 | #endif | 1004 | #endif |
1005 | 1005 | ||
1006 | // some 2D Defines | 1006 | // some 2D Defines |
1007 | struct AbsRectangle | 1007 | struct AbsRectangle |
1008 | { | 1008 | { |
1009 | s32 x0; | 1009 | s32 x0; |
1010 | s32 y0; | 1010 | s32 y0; |
1011 | s32 x1; | 1011 | s32 x1; |
1012 | s32 y1; | 1012 | s32 y1; |
1013 | }; | 1013 | }; |
1014 | 1014 | ||
1015 | //! 2D Intersection test | 1015 | //! 2D Intersection test |
1016 | inline bool intersect ( AbsRectangle &dest, const AbsRectangle& a, const AbsRectangle& b) | 1016 | inline bool intersect ( AbsRectangle &dest, const AbsRectangle& a, const AbsRectangle& b) |
1017 | { | 1017 | { |
1018 | dest.x0 = core::s32_max( a.x0, b.x0 ); | 1018 | dest.x0 = core::s32_max( a.x0, b.x0 ); |
1019 | dest.y0 = core::s32_max( a.y0, b.y0 ); | 1019 | dest.y0 = core::s32_max( a.y0, b.y0 ); |
1020 | dest.x1 = core::s32_min( a.x1, b.x1 ); | 1020 | dest.x1 = core::s32_min( a.x1, b.x1 ); |
1021 | dest.y1 = core::s32_min( a.y1, b.y1 ); | 1021 | dest.y1 = core::s32_min( a.y1, b.y1 ); |
1022 | return dest.x0 < dest.x1 && dest.y0 < dest.y1; | 1022 | return dest.x0 < dest.x1 && dest.y0 < dest.y1; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | // some 1D defines | 1025 | // some 1D defines |
1026 | struct sIntervall | 1026 | struct sIntervall |
1027 | { | 1027 | { |
1028 | s32 start; | 1028 | s32 start; |
1029 | s32 end; | 1029 | s32 end; |
1030 | }; | 1030 | }; |
1031 | 1031 | ||
1032 | // returning intersection width | 1032 | // returning intersection width |
1033 | inline s32 intervall_intersect_test( const sIntervall& a, const sIntervall& b) | 1033 | inline s32 intervall_intersect_test( const sIntervall& a, const sIntervall& b) |
1034 | { | 1034 | { |
1035 | return core::s32_min( a.end, b.end ) - core::s32_max( a.start, b.start ); | 1035 | return core::s32_min( a.end, b.end ) - core::s32_max( a.start, b.start ); |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | 1038 | ||
1039 | } // end namespace irr | 1039 | } // end namespace irr |
1040 | 1040 | ||
1041 | #endif | 1041 | #endif |
1042 | 1042 | ||