fix some float/ubyte mistakes (Daniel Borca)
[mesa.git] / src / mesa / drivers / glide / fxglidew.c
1 /* $Id: fxglidew.c,v 1.19 2001/09/23 16:50:01 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.0
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 /* Authors:
28 * David Bucciarelli
29 * Brian Paul
30 * Daryll Strauss
31 * Keith Whitwell
32 */
33
34 /* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */
35
36
37 #ifdef HAVE_CONFIG_H
38 #include "conf.h"
39 #endif
40
41 #if defined(FX)
42 #include "glide.h"
43 #include "fxglidew.h"
44 #include "fxdrv.h"
45
46 #include <stdlib.h>
47 #include <string.h>
48
49 FxI32
50 FX_grGetInteger_NoLock(FxU32 pname)
51 {
52 #if !defined(FX_GLIDE3)
53 switch (pname) {
54 case FX_FOG_TABLE_ENTRIES:
55 return GR_FOG_TABLE_SIZE;
56 case FX_GLIDE_STATE_SIZE:
57 return sizeof(GrState);
58 case FX_LFB_PIXEL_PIPE:
59 return FXFALSE;
60 case FX_PENDING_BUFFERSWAPS:
61 return grBufferNumPending();
62 case FX_TEXTURE_ALIGN:
63 /* This is a guess from reading the glide3 docs */
64 return 8;
65 default:
66 if (MESA_VERBOSE & VERBOSE_DRIVER) {
67 fprintf(stderr, "Wrong parameter in FX_grGetInteger!\n");
68 }
69 return -1;
70 }
71 #else
72 FxU32 grname;
73 FxI32 result;
74
75 switch (pname) {
76 case FX_FOG_TABLE_ENTRIES:
77 case FX_GLIDE_STATE_SIZE:
78 case FX_LFB_PIXEL_PIPE:
79 case FX_PENDING_BUFFERSWAPS:
80 case FX_TEXTURE_ALIGN:
81 grname = pname;
82 break;
83 default:
84 if (MESA_VERBOSE & VERBOSE_DRIVER) {
85 fprintf(stderr, "Wrong parameter in FX_grGetInteger!\n");
86 }
87 return -1;
88 }
89
90 grGet(grname, 4, &result);
91 return result;
92 #endif
93 }
94
95 FxI32
96 FX_grGetInteger(FxU32 pname)
97 {
98 int result;
99
100 BEGIN_BOARD_LOCK();
101 result = FX_grGetInteger_NoLock(pname);
102 END_BOARD_LOCK();
103 return result;
104 }
105
106
107 FxBool
108 FX_grLfbLock(GrLock_t type, GrBuffer_t buffer,
109 GrLfbWriteMode_t writeMode, GrOriginLocation_t origin,
110 FxBool pixelPipeline, GrLfbInfo_t * info)
111 {
112 FxBool result;
113
114 BEGIN_BOARD_LOCK();
115 result = grLfbLock(type, buffer, writeMode, origin, pixelPipeline, info);
116 END_BOARD_LOCK();
117 return result;
118 }
119
120 FxU32
121 FX_grTexTextureMemRequired(FxU32 evenOdd, GrTexInfo * info)
122 {
123 FxU32 result;
124
125 BEGIN_BOARD_LOCK();
126 result = grTexTextureMemRequired(evenOdd, info);
127 END_BOARD_LOCK();
128 return result;
129 }
130
131 FxU32
132 FX_grTexMinAddress(GrChipID_t tmu)
133 {
134 FxU32 result;
135
136 BEGIN_BOARD_LOCK();
137 result = grTexMinAddress(tmu);
138 END_BOARD_LOCK();
139 return result;
140 }
141
142 extern FxU32
143 FX_grTexMaxAddress(GrChipID_t tmu)
144 {
145 FxU32 result;
146
147 BEGIN_BOARD_LOCK();
148 result = grTexMaxAddress(tmu);
149 END_BOARD_LOCK();
150 return result;
151 }
152
153 FxBool
154 FX_grSstControl(FxU32 code)
155 {
156 #if defined(FX_GLIDE3)
157 /* The glide 3 sources call for grEnable/grDisable to be called in exchange
158 * for grSstControl. */
159 switch (code) {
160 case GR_CONTROL_ACTIVATE:
161 grEnable(GR_PASSTHRU);
162 break;
163 case GR_CONTROL_DEACTIVATE:
164 grDisable(GR_PASSTHRU);
165 break;
166 }
167 /* Appearently GR_CONTROL_RESIZE can be ignored. */
168 return 1; /* OK? */
169 #else
170 FxU32 result;
171 BEGIN_BOARD_LOCK();
172 result = grSstControl(code);
173 END_BOARD_LOCK();
174 return result;
175 #endif
176 }
177
178
179 #if defined(FX_GLIDE3)
180
181 void
182 FX_grGammaCorrectionValue(float val)
183 {
184 (void) val;
185 /* ToDo */
186 }
187
188 int
189 FX_getFogTableSize(void)
190 {
191 int result;
192 BEGIN_BOARD_LOCK();
193 grGet(GR_FOG_TABLE_ENTRIES, sizeof(int), (void *) &result);
194 END_BOARD_LOCK();
195 return result;
196 }
197
198 int
199 FX_getGrStateSize(void)
200 {
201 int result;
202 BEGIN_BOARD_LOCK();
203 grGet(GR_GLIDE_STATE_SIZE, sizeof(int), (void *) &result);
204 END_BOARD_LOCK();
205
206 return result;
207
208 }
209
210 int
211 FX_grSstScreenWidth()
212 {
213 FxI32 result[4];
214
215 BEGIN_BOARD_LOCK();
216 grGet(GR_VIEWPORT, sizeof(FxI32) * 4, result);
217 END_BOARD_LOCK();
218
219 return result[2];
220 }
221
222 int
223 FX_grSstScreenHeight()
224 {
225 FxI32 result[4];
226
227 BEGIN_BOARD_LOCK();
228 grGet(GR_VIEWPORT, sizeof(FxI32) * 4, result);
229 END_BOARD_LOCK();
230
231 return result[3];
232 }
233
234 void
235 FX_grGlideGetVersion(char *buf)
236 {
237 BEGIN_BOARD_LOCK();
238 strcpy(buf, grGetString(GR_VERSION));
239 END_BOARD_LOCK();
240 }
241
242 void
243 FX_grSstPerfStats(GrSstPerfStats_t * st)
244 {
245 FxI32 n;
246 grGet(GR_STATS_PIXELS_IN, 4, &n);
247 st->pixelsIn = n;
248 grGet(GR_STATS_PIXELS_CHROMA_FAIL, 4, &n);
249 st->chromaFail = n;
250 grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &n);
251 st->zFuncFail = n;
252 grGet(GR_STATS_PIXELS_AFUNC_FAIL, 4, &n);
253 st->aFuncFail = n;
254 grGet(GR_STATS_PIXELS_OUT, 4, &n);
255 st->pixelsOut = n;
256 }
257
258 void
259 FX_grAADrawLine(GrVertex * a, GrVertex * b)
260 {
261 /* ToDo */
262 BEGIN_CLIP_LOOP();
263 grDrawLine(a, b);
264 END_CLIP_LOOP();
265 }
266
267 void
268 FX_grAADrawPoint(GrVertex * a)
269 {
270 BEGIN_CLIP_LOOP();
271 grDrawPoint(a);
272 END_CLIP_LOOP();
273 }
274
275 void
276 FX_grDrawPolygonVertexList(int n, GrVertex * verts)
277 {
278 BEGIN_CLIP_LOOP();
279 grDrawVertexArrayContiguous(GR_POLYGON, n, verts, sizeof(GrVertex));
280 END_CLIP_LOOP();
281 }
282
283 void
284 FX_setupGrVertexLayout(void)
285 {
286 BEGIN_BOARD_LOCK();
287 grReset(GR_VERTEX_PARAMETER);
288
289 grCoordinateSpace(GR_WINDOW_COORDS);
290 grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
291 grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
292 grVertexLayout(GR_PARAM_A, GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE);
293 grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
294 grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE);
295 grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2,
296 GR_PARAM_ENABLE);
297 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
298 GR_PARAM_DISABLE);
299 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
300 GR_PARAM_DISABLE);
301 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
302 GR_PARAM_DISABLE);
303 END_BOARD_LOCK();
304 }
305
306 void
307 FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask)
308 {
309 switch (hintType) {
310 case GR_HINT_STWHINT:
311 {
312 if (hintMask & GR_STWHINT_W_DIFF_TMU0)
313 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
314 GR_PARAM_ENABLE);
315 else
316 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
317 GR_PARAM_DISABLE);
318
319 if (hintMask & GR_STWHINT_ST_DIFF_TMU1)
320 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
321 GR_PARAM_ENABLE);
322 else
323 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
324 GR_PARAM_DISABLE);
325
326 if (hintMask & GR_STWHINT_W_DIFF_TMU1)
327 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
328 GR_PARAM_ENABLE);
329 else
330 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
331 GR_PARAM_DISABLE);
332
333 }
334 }
335 }
336
337 void
338 FX_grHints(GrHint_t hintType, FxU32 hintMask)
339 {
340 BEGIN_BOARD_LOCK();
341 FX_grHints_NoLock(hintType, hintMask);
342 END_BOARD_LOCK();
343 }
344
345 /*
346 * Glide3 doesn't have the grSstQueryHardware function anymore.
347 * Instead, we call grGet() and fill in the data structures ourselves.
348 */
349 int
350 FX_grSstQueryHardware(GrHwConfiguration * config)
351 {
352 int i, j;
353 int numFB;
354
355 BEGIN_BOARD_LOCK();
356
357 grGet(GR_NUM_BOARDS, 4, (void *) &(config->num_sst));
358 if (config->num_sst == 0)
359 return 0;
360
361 for (i = 0; i < config->num_sst; i++) {
362 FxI32 result;
363
364 config->SSTs[i].type = GR_SSTTYPE_VOODOO;
365 grSstSelect(i);
366
367 grGet(GR_MEMORY_FB, 4, &result);
368 config->SSTs[i].sstBoard.VoodooConfig.fbRam = result / (1024 * 1024);
369
370 grGet(GR_NUM_TMU, 4, &result);
371 config->SSTs[i].sstBoard.VoodooConfig.nTexelfx = result;
372
373 grGet(GR_REVISION_FB, 4, &result);
374 config->SSTs[i].sstBoard.VoodooConfig.fbiRev = result;
375
376 grGet(GR_NUM_FB, 4, (void *) &numFB);
377 if (numFB > 1)
378 config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXTRUE;
379 else
380 config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXFALSE;
381
382 for (j = 0; j < config->SSTs[i].sstBoard.VoodooConfig.nTexelfx; j++) {
383 grGet(GR_MEMORY_TMU, 4, &result);
384 config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRam =
385 result / (1024 * 1024);
386 grGet(GR_REVISION_TMU, 4, &result);
387 config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRev = result;
388 }
389 }
390 END_BOARD_LOCK();
391 return 1;
392 }
393
394 #else
395
396 int
397 FX_grSstScreenWidth()
398 {
399 int i;
400 BEGIN_BOARD_LOCK();
401 i = grSstScreenWidth();
402 END_BOARD_LOCK();
403 return i;
404 }
405
406 int
407 FX_grSstScreenHeight()
408 {
409 int i;
410 BEGIN_BOARD_LOCK();
411 i = grSstScreenHeight();
412 END_BOARD_LOCK();
413 return i;
414 }
415
416 int
417 FX_grSstQueryHardware(GrHwConfiguration * c)
418 {
419 int i;
420 BEGIN_BOARD_LOCK();
421 i = grSstQueryHardware(c);
422 END_BOARD_LOCK();
423 return i;
424 }
425
426
427 #endif /* FX_GLIDE3 */
428
429 /* It appears to me that this function is needed either way. */
430 FX_GrContext_t
431 FX_grSstWinOpen(FxU32 hWnd,
432 GrScreenResolution_t screen_resolution,
433 GrScreenRefresh_t refresh_rate,
434 GrColorFormat_t color_format,
435 GrOriginLocation_t origin_location,
436 int nColBuffers, int nAuxBuffers)
437 {
438 FX_GrContext_t i;
439 BEGIN_BOARD_LOCK();
440 i = grSstWinOpen(hWnd,
441 screen_resolution,
442 refresh_rate,
443 color_format, origin_location, nColBuffers, nAuxBuffers);
444
445 /*
446 fprintf(stderr,
447 "grSstWinOpen( win %d res %d ref %d fmt %d\n"
448 " org %d ncol %d naux %d )\n"
449 " ==> %d\n",
450 hWnd,
451 screen_resolution,
452 refresh_rate,
453 color_format,
454 origin_location,
455 nColBuffers,
456 nAuxBuffers,
457 i);
458 */
459 END_BOARD_LOCK();
460 return i;
461 }
462
463
464
465 #else
466
467 /*
468 * Need this to provide at least one external definition.
469 */
470
471 extern int gl_fx_dummy_function_glidew(void);
472 int
473 gl_fx_dummy_function_glidew(void)
474 {
475 return 0;
476 }
477
478 #endif /* FX */