@@ -72,90 +72,89 @@ static void SetupLightLUT()
72
72
73
73
74
74
////////////////////////////////////////////////////////////////////////////////
75
- // Create packed Gouraud fixed-pt 8.3:8.3:8.2 rgb triplet
75
+ // Create packed Gouraud fixed-pt 8.8 rgb triplet
76
76
//
77
77
// INPUT:
78
78
// 'r','g','b' are 8.10 fixed-pt color components (r shown here)
79
79
// 'r' input: --------------rrrrrrrrXXXXXXXXXX
80
80
// ^ bit 31
81
81
// RETURNS:
82
- // u32 output: rrrrrrrrXXXggggggggXXXbbbbbbbbXX
83
- // ^ bit 31
82
+ // gcol_t output: ccccccccXXXXXXXX for c in [r, g, b]
83
+ // ^ bit 16
84
84
// Where 'r,g,b' are integer bits of colors, 'X' fixed-pt, and '-' don't care
85
85
////////////////////////////////////////////////////////////////////////////////
86
- GPU_INLINE u32 gpuPackGouraudCol (u32 r , u32 g , u32 b )
86
+ GPU_INLINE gcol_t gpuPackGouraudCol (u32 r , u32 g , u32 b )
87
87
{
88
- return ((u32 )(b >> 8 )& (0x03ff ))
89
- | ((u32 )(g << 3 )& (0x07ff <<10 ))
90
- | ((u32 )(r <<14 )& (0x07ff <<21 ));
88
+ return (gcol_t ){
89
+ (u16 )(r >> 2 ),
90
+ (u16 )(g >> 2 ),
91
+ (u16 )(b >> 2 ),
92
+ };
91
93
}
92
94
93
-
94
95
////////////////////////////////////////////////////////////////////////////////
95
- // Create packed increment for Gouraud fixed-pt 8.3:8.3:8.2 rgb triplet
96
+ // Create packed increment for Gouraud fixed-pt 8.8 rgb triplet
96
97
//
97
98
// INPUT:
98
99
// Sign-extended 8.10 fixed-pt r,g,b color increment values (only dr is shown)
99
100
// 'dr' input: ssssssssssssssrrrrrrrrXXXXXXXXXX
100
101
// ^ bit 31
101
102
// RETURNS:
102
- // u32 output: rrrrrrrrXXXggggggggXXXbbbbbbbbXX
103
- // ^ bit 31
103
+ // gcol_t output: ccccccccXXXXXXXX for c in [r, g, b]
104
+ // ^ bit 16
104
105
// Where 'r,g,b' are integer bits of colors, 'X' fixed-pt, and 's' sign bits
105
106
//
106
107
// NOTE: The correctness of this code/method has not been fully verified,
107
108
// having been merely factored out from original code in
108
109
// poly-drawing functions. Feel free to check/improve it -senquack
109
110
////////////////////////////////////////////////////////////////////////////////
110
- GPU_INLINE u32 gpuPackGouraudColInc (s32 dr , s32 dg , s32 db )
111
+ GPU_INLINE gcol_t gpuPackGouraudColInc (s32 dr , s32 dg , s32 db )
111
112
{
112
- u32 dr_tmp = (u32 )(dr << 14 )& (0xffffffff <<21 ); if (dr < 0 ) dr_tmp += 1 <<21 ;
113
- u32 dg_tmp = (u32 )(dg << 3 )& (0xffffffff <<10 ); if (dg < 0 ) dg_tmp += 1 <<10 ;
114
- u32 db_tmp = (u32 )(db >> 8 )& (0xffffffff ); if (db < 0 ) db_tmp += 1 << 0 ;
115
- return db_tmp + dg_tmp + dr_tmp ;
113
+ return (gcol_t ){
114
+ (u16 )((dr >> 2 ) + (dr < 0 )),
115
+ (u16 )((dg >> 2 ) + (dg < 0 )),
116
+ (u16 )((db >> 2 ) + (db < 0 )),
117
+ };
116
118
}
117
119
118
-
119
120
////////////////////////////////////////////////////////////////////////////////
120
- // Extract bgr555 color from Gouraud u32 fixed-pt 8.3:8.3:8.2 rgb triplet
121
+ // Extract bgr555 color from Gouraud u32 fixed-pt 8.8 rgb triplet
121
122
//
122
123
// INPUT:
123
- // 'gCol' input: rrrrrrrrXXXggggggggXXXbbbbbbbbXX
124
- // ^ bit 31
124
+ // 'gCol' input: ccccccccXXXXXXXX for c in [r, g, b]
125
+ // ^ bit 16
125
126
// RETURNS:
126
127
// u16 output: 0bbbbbgggggrrrrr
127
128
// ^ bit 16
128
129
// Where 'r,g,b' are integer bits of colors, 'X' fixed-pt, and '0' zero
129
130
////////////////////////////////////////////////////////////////////////////////
130
- GPU_INLINE uint_fast16_t gpuLightingRGBGeneric ( u32 gCol )
131
+ GPU_INLINE uint_fast16_t gpuLightingRGB ( gcol_t gCol )
131
132
{
132
- return (( gCol << 5 ) & 0x7C00 ) |
133
- ((gCol >> 11 ) & 0x03E0 ) |
134
- ( gCol >> 27 );
133
+ return (gCol . c . r >> 11 ) |
134
+ ((gCol . c . g >> 6 ) & 0x3e0 ) |
135
+ (( gCol . c . b >> 1 ) & 0x7c00 );
135
136
}
136
137
137
-
138
138
////////////////////////////////////////////////////////////////////////////////
139
- // Convert packed Gouraud u32 fixed-pt 8.3:8.3:8.2 rgb triplet in 'gCol'
140
- // to padded u32 5.4:5.4:5.4 bgr fixed-pt triplet, suitable for use
139
+ // Convert packed Gouraud u32 fixed-pt 8.8 rgb triplet in 'gCol'
140
+ // to padded u32 5.4 bgr fixed-pt triplet, suitable for use
141
141
// with HQ 24-bit lighting/quantization.
142
142
//
143
143
// INPUT:
144
- // 'gCol' input: rrrrrrrrXXXggggggggXXXbbbbbbbbXX
145
- // ^ bit 31
144
+ // 'gCol' input: ccccccccXXXXXXXX for c in [r, g, b]
145
+ // ^ bit 16
146
146
// RETURNS:
147
147
// u32 output: 000bbbbbXXXX0gggggXXXX0rrrrrXXXX
148
148
// ^ bit 31
149
149
// Where 'X' are fixed-pt bits, '0' zero-padding, and '-' is don't care
150
150
////////////////////////////////////////////////////////////////////////////////
151
- GPU_INLINE u32 gpuLightingRGB24 (u32 gCol )
151
+ GPU_INLINE u32 gpuLightingRGB24 (gcol_t gCol )
152
152
{
153
- return (( gCol << 19 ) & ( 0x1FF << 20 )) |
154
- ((gCol >> 2 ) & ( 0x1FF << 10 )) |
155
- ( gCol >> 23 );
153
+ return (gCol . c . r >> 7 )
154
+ | ((gCol . c . g >> 7 ) << 10 )
155
+ | (( gCol . c . b >> 7 ) << 20 );
156
156
}
157
157
158
-
159
158
////////////////////////////////////////////////////////////////////////////////
160
159
// Apply fast (low-precision) 5-bit lighting to bgr555 texture color:
161
160
//
@@ -181,25 +180,23 @@ GPU_INLINE uint_fast16_t gpuLightingTXTGeneric(uint_fast16_t uSrc, u8 r5, u8 g5,
181
180
// Apply fast (low-precision) 5-bit Gouraud lighting to bgr555 texture color:
182
181
//
183
182
// INPUT:
184
- // 'gCol' is a packed Gouraud u32 fixed-pt 8.3:8.3:8.2 rgb triplet, value of
185
- // 15.0 is midpoint that does not modify color of texture
186
- // gCol input : rrrrrXXXXXXgggggXXXXXXbbbbbXXXXX
187
- // ^ bit 31
183
+ // 'gCol' is a Gouraud fixed-pt 8.8 rgb triplet
184
+ // 'gCol' input: ccccccccXXXXXXXX for c in [r, g, b]
185
+ // ^ bit 16
188
186
// 'uSrc' input: -bbbbbgggggrrrrr
189
187
// ^ bit 16
190
188
// RETURNS:
191
189
// u16 output: 0bbbbbgggggrrrrr
192
190
// Where 'X' are fixed-pt bits, '0' is zero-padding, and '-' is don't care
193
191
////////////////////////////////////////////////////////////////////////////////
194
- GPU_INLINE uint_fast16_t gpuLightingTXTGouraudGeneric (uint_fast16_t uSrc , u32 gCol )
192
+ GPU_INLINE uint_fast16_t gpuLightingTXTGouraud (uint_fast16_t uSrc , gcol_t gCol )
195
193
{
196
- return (gpu_unai .LightLUT [((uSrc & 0x7C00 )>>5 ) | (( gCol >> 5 ) & 0x1F )]<< 10 ) |
197
- (gpu_unai .LightLUT [ (uSrc & 0x03E0 ) | (( gCol >> 16 ) & 0x1F )] << 5 ) |
198
- (gpu_unai .LightLUT [((uSrc & 0x001F )<<5 ) | (gCol >> 27 ) ]) |
194
+ return (gpu_unai .LightLUT [((uSrc & 0x7C00 )>>5 ) | (gCol . c . b >> 11 )] << 10 ) |
195
+ (gpu_unai .LightLUT [ (uSrc & 0x03E0 ) | (gCol . c . g >> 11 )] << 5 ) |
196
+ (gpu_unai .LightLUT [((uSrc & 0x001F )<<5 ) | (gCol . c . r >> 11 ) ]) |
199
197
(uSrc & 0x8000 );
200
198
}
201
199
202
-
203
200
////////////////////////////////////////////////////////////////////////////////
204
201
// Apply high-precision 8-bit lighting to bgr555 texture color,
205
202
// returning a padded u32 5.4:5.4:5.4 bgr fixed-pt triplet
@@ -244,22 +241,22 @@ GPU_INLINE u32 gpuLightingTXT24(uint_fast16_t uSrc, u8 r8, u8 g8, u8 b8)
244
241
// INPUT:
245
242
// 'uSrc' input: -bbbbbgggggrrrrr
246
243
// ^ bit 16
247
- // 'gCol' input: rrrrrrrrXXXggggggggXXXbbbbbbbbXX
248
- // ^ bit 31
244
+ // 'gCol' input: ccccccccXXXXXXXX for c in [r, g, b]
245
+ // ^ bit 16
249
246
// RETURNS:
250
247
// u32 output: 000bbbbbXXXX0gggggXXXX0rrrrrXXXX
251
248
// ^ bit 31
252
249
// Where 'X' are fixed-pt bits, '0' is zero-padding, and '-' is don't care
253
250
////////////////////////////////////////////////////////////////////////////////
254
- GPU_INLINE u32 gpuLightingTXT24Gouraud (uint_fast16_t uSrc , u32 gCol )
251
+ GPU_INLINE u32 gpuLightingTXT24Gouraud (uint_fast16_t uSrc , gcol_t gCol )
255
252
{
256
253
uint_fast16_t r1 = uSrc & 0x001F ;
257
254
uint_fast16_t g1 = uSrc & 0x03E0 ;
258
255
uint_fast16_t b1 = uSrc & 0x7C00 ;
259
256
260
- uint_fast16_t r2 = ( gCol >> 24 ) & 0xFF ;
261
- uint_fast16_t g2 = ( gCol >> 13 ) & 0xFF ;
262
- uint_fast16_t b2 = ( gCol >> 2 ) & 0xFF ;
257
+ uint_fast16_t r2 = gCol . c . r >> 8 ;
258
+ uint_fast16_t g2 = gCol . c . g >> 8 ;
259
+ uint_fast16_t b2 = gCol . c . b >> 8 ;
263
260
264
261
u32 r3 = r1 * r2 ; if (r3 & 0xFFFFF000 ) r3 = ~0xFFFFF000 ;
265
262
u32 g3 = g1 * g2 ; if (g3 & 0xFFFE0000 ) g3 = ~0xFFFE0000 ;
0 commit comments