source: trunk/src/opengl/glide/cvg/texus/gldutil.c

Last change on this file was 6653, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 8.9 KB
Line 
1/* $Id: gldutil.c,v 1.2 2001-09-05 14:30:45 bird Exp $ */
2
3/*
4** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
5** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
6** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
7** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
8** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
9** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
10** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
11** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
12**
13** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
14** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
15** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
16** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
17** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
18** THE UNITED STATES.
19**
20** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
21**
22** $Revision: 1.2 $
23** $Date: 2001-09-05 14:30:45 $
24*/
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <math.h>
30
31#include <3dfx.h>
32#include <glide.h>
33#include "texus.h"
34#include "texusint.h"
35
36/*
37 * Allocate memory via Glide for a texture.
38 * Assumes that the passed image is already quantized to
39 * the format that you want to download.
40 */
41GrMipMapId_t txAllocateTexMemory( GrChipID_t tmu,
42 FxU8 odd_even_mask,
43 TxMip *texture,
44 GrMipMapMode_t mm_mode,
45 GrTextureClampMode_t s_clamp_mode,
46 GrTextureClampMode_t t_clamp_mode,
47 GrTextureFilterMode_t minfilter_mode,
48 GrTextureFilterMode_t magfilter_mode,
49 float lod_bias,
50 FxBool trilinear )
51{
52 int aspect;
53 GrAspectRatio_t gr_aspect;
54 int longest_side;
55 GrLOD_t max_lod, min_lod;
56 int num_mipmap_levels = 0;
57 int i;
58
59 aspect = ( 8 * texture->width ) / texture->height;
60
61#ifdef GLIDE3
62 switch( aspect )
63 {
64 case 64:
65 gr_aspect = GR_ASPECT_LOG2_8x1;
66 longest_side = texture->width;
67 break;
68 case 32:
69 gr_aspect = GR_ASPECT_LOG2_4x1;
70 longest_side = texture->width;
71 break;
72 case 16:
73 gr_aspect = GR_ASPECT_LOG2_2x1;
74 longest_side = texture->width;
75 break;
76 case 8:
77 gr_aspect = GR_ASPECT_LOG2_1x1;
78 longest_side = texture->width;
79 break;
80 case 4:
81 gr_aspect = GR_ASPECT_LOG2_1x2;
82 longest_side = texture->height;
83 break;
84 case 2:
85 gr_aspect = GR_ASPECT_LOG2_1x4;
86 longest_side = texture->height;
87 break;
88 case 1:
89 gr_aspect = GR_ASPECT_LOG2_1x8;
90 longest_side = texture->height;
91 break;
92 }
93#else
94 switch( aspect )
95 {
96 case 64:
97 gr_aspect = GR_ASPECT_8x1;
98 longest_side = texture->width;
99 break;
100 case 32:
101 gr_aspect = GR_ASPECT_4x1;
102 longest_side = texture->width;
103 break;
104 case 16:
105 gr_aspect = GR_ASPECT_2x1;
106 longest_side = texture->width;
107 break;
108 case 8:
109 gr_aspect = GR_ASPECT_1x1;
110 longest_side = texture->width;
111 break;
112 case 4:
113 gr_aspect = GR_ASPECT_1x2;
114 longest_side = texture->height;
115 break;
116 case 2:
117 gr_aspect = GR_ASPECT_1x4;
118 longest_side = texture->height;
119 break;
120 case 1:
121 gr_aspect = GR_ASPECT_1x8;
122 longest_side = texture->height;
123 break;
124 }
125#endif /* GLIDE3 */
126
127 /*
128 * How many mipmap levels are there?
129 */
130 for( i = 0; i < 16; i++ )
131 {
132 if( texture->data[i] )
133 num_mipmap_levels++;
134 else
135 break;
136 }
137
138 /*
139 * Figure out the max lod.
140 */
141#ifdef GLIDE3
142 switch( longest_side )
143 {
144 case 256:
145 max_lod = GR_LOD_LOG2_256;
146 break;
147 case 128:
148 max_lod = GR_LOD_LOG2_128;
149 break;
150 case 64:
151 max_lod = GR_LOD_LOG2_64;
152 break;
153 case 32:
154 max_lod = GR_LOD_LOG2_32;
155 break;
156 case 16:
157 max_lod = GR_LOD_LOG2_16;
158 break;
159 case 8:
160 max_lod = GR_LOD_LOG2_8;
161 break;
162 case 4:
163 max_lod = GR_LOD_LOG2_4;
164 break;
165 case 2:
166 max_lod = GR_LOD_LOG2_2;
167 break;
168 case 1:
169 max_lod = GR_LOD_LOG2_1;
170 break;
171 }
172#else
173 switch( longest_side )
174 {
175 case 256:
176 max_lod = GR_LOD_256;
177 break;
178 case 128:
179 max_lod = GR_LOD_128;
180 break;
181 case 64:
182 max_lod = GR_LOD_64;
183 break;
184 case 32:
185 max_lod = GR_LOD_32;
186 break;
187 case 16:
188 max_lod = GR_LOD_16;
189 break;
190 case 8:
191 max_lod = GR_LOD_8;
192 break;
193 case 4:
194 max_lod = GR_LOD_4;
195 break;
196 case 2:
197 max_lod = GR_LOD_2;
198 break;
199 case 1:
200 max_lod = GR_LOD_1;
201 break;
202 }
203#endif /* GLIDE3 */
204
205 /*
206 * Figure out the minimum LOD.
207 */
208#ifdef GLIDE3
209 min_lod = max_lod - ( num_mipmap_levels - 1 );
210#else
211 min_lod = max_lod + num_mipmap_levels - 1;
212#endif
213
214 return grTexAllocateMemory( tmu, odd_even_mask,
215#if 0
216 texture->width, texture->height,
217#else
218 0, 0,
219#endif
220 texture->format, mm_mode,
221 min_lod, max_lod,
222 gr_aspect,
223 s_clamp_mode, t_clamp_mode,
224 minfilter_mode, magfilter_mode,
225 lod_bias,
226 trilinear );
227}
228
229void txDownloadMipmap( GrMipMapId_t mmid, TxMip *texture )
230{
231 int longest_side;
232 GrLOD_t lod;
233 int i;
234
235 if( texture->width > texture->height )
236 longest_side = texture->width;
237 else
238 longest_side = texture->height;
239
240 /*
241 * Figure out the max lod.
242 */
243#ifdef GLIDE3
244 switch( longest_side )
245 {
246 case 256:
247 lod = GR_LOD_LOG2_256;
248 break;
249 case 128:
250 lod = GR_LOD_LOG2_128;
251 break;
252 case 64:
253 lod = GR_LOD_LOG2_64;
254 break;
255 case 32:
256 lod = GR_LOD_LOG2_32;
257 break;
258 case 16:
259 lod = GR_LOD_LOG2_16;
260 break;
261 case 8:
262 lod = GR_LOD_LOG2_8;
263 break;
264 case 4:
265 lod = GR_LOD_LOG2_4;
266 break;
267 case 2:
268 lod = GR_LOD_LOG2_2;
269 break;
270 case 1:
271 lod = GR_LOD_LOG2_1;
272 break;
273 }
274#else
275 switch( longest_side )
276 {
277 case 256:
278 lod = GR_LOD_256;
279 break;
280 case 128:
281 lod = GR_LOD_128;
282 break;
283 case 64:
284 lod = GR_LOD_64;
285 break;
286 case 32:
287 lod = GR_LOD_32;
288 break;
289 case 16:
290 lod = GR_LOD_16;
291 break;
292 case 8:
293 lod = GR_LOD_8;
294 break;
295 case 4:
296 lod = GR_LOD_4;
297 break;
298 case 2:
299 lod = GR_LOD_2;
300 break;
301 case 1:
302 lod = GR_LOD_1;
303 break;
304 }
305#endif /* GLIDE3 */
306
307 for( i = 0; i < 16; i++ )
308 {
309 void *tmp;
310
311 if( !texture->data[i] )
312 break;
313 tmp = texture->data[i];
314 guTexDownloadMipMapLevel( mmid, lod, (const void **) &tmp );
315 lod++;
316 }
317
318 if( ( texture->format == GR_TEXFMT_YIQ_422 ) ||
319 ( texture->format == GR_TEXFMT_AYIQ_8422 ) )
320 {
321 int i, j;
322 GuNccTable ncc_table;
323
324 for( i = 0; i < 16; i++ )
325 {
326 ncc_table.yRGB[i] = ( FxU8 )texture->pal[i];
327 }
328
329 for( i = 0; i < 4; i++ )
330 {
331 for( j = 0; j < 3; j++ )
332 {
333 ncc_table.iRGB[i][j] = ( FxI16 )( texture->pal[16 + 3 * i + j] );
334 ncc_table.qRGB[i][j] = ( FxI16 )( texture->pal[28 + 3 * i + j] );
335 }
336 }
337
338 /*
339 ** pack the table Y entries
340 */
341 for ( i = 0; i < 4; i++ )
342 {
343 FxU32 packedvalue;
344
345 packedvalue = ( ( FxU32 )( ncc_table.yRGB[i*4+0] & 0xff ) );
346 packedvalue |= ( ( FxU32 )( ncc_table.yRGB[i*4+1] & 0xff ) ) << 8;
347 packedvalue |= ( ( FxU32 )( ncc_table.yRGB[i*4+2] & 0xff ) ) << 16;
348 packedvalue |= ( ( FxU32 )( ncc_table.yRGB[i*4+3] & 0xff ) ) << 24;
349
350 ncc_table.packed_data[i] = packedvalue;
351 }
352
353 /*
354 ** pack the table I entries
355 */
356 for ( i = 0; i < 4; i++ )
357 {
358 FxU32 packedvalue;
359
360 packedvalue = ( ( FxU32 )( ncc_table.iRGB[i][0] & 0x1ff ) ) << 18;
361 packedvalue |= ( ( FxU32 )( ncc_table.iRGB[i][1] & 0x1ff ) ) << 9;
362 packedvalue |= ( ( FxU32 )( ncc_table.iRGB[i][2] & 0x1ff ) ) << 0;
363
364 ncc_table.packed_data[i+4] = packedvalue;
365 }
366
367 /*
368 ** pack the table Q entries
369 */
370 for ( i = 0; i < 4; i++ )
371 {
372 FxU32 packedvalue;
373
374 packedvalue = ( ( FxU32 )( ncc_table.qRGB[i][0] & 0x1ff ) ) << 18;
375 packedvalue |= ( ( FxU32 )( ncc_table.qRGB[i][1] & 0x1ff ) ) << 9;;
376 packedvalue |= ( ( FxU32 )( ncc_table.qRGB[i][2] & 0x1ff ) ) << 0;
377
378 ncc_table.packed_data[i+8] = packedvalue;
379 }
380
381#if 0
382 HackSetNCCTable( mmid, &ncc_table );
383#endif
384 }
385}
Note: See TracBrowser for help on using the repository browser.