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