fix GL_BACK color material bug
[mesa.git] / src / mesa / drivers / glide / fxglidew.c
1 /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 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 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
28 * terms stated above.
29 *
30 * Thank you for your contribution, David!
31 *
32 * Please make note of the above copyright/license statement. If you
33 * contributed code or bug fixes to this code under the previous (GNU
34 * Library) license and object to the new license, your code will be
35 * removed at your request. Please see the Mesa docs/COPYRIGHT file
36 * for more information.
37 *
38 * Additional Mesa/3Dfx driver developers:
39 * Daryll Strauss <daryll@precisioninsight.com>
40 * Keith Whitwell <keith@precisioninsight.com>
41 *
42 * See fxapi.h for more revision/author details.
43 */
44
45
46 #ifdef HAVE_CONFIG_H
47 #include "conf.h"
48 #endif
49
50 #if defined(FX)
51 #include "glide.h"
52 #include "fxglidew.h"
53 #include "fxdrv.h"
54
55 #include <stdlib.h>
56 #include <string.h>
57
58 FxI32 FX_grGetInteger_NoLock(FxU32 pname)
59 {
60 #if !defined(FX_GLIDE3)
61 switch (pname)
62 {
63 case FX_FOG_TABLE_ENTRIES:
64 return GR_FOG_TABLE_SIZE;
65 case FX_GLIDE_STATE_SIZE:
66 return sizeof(GrState);
67 case FX_LFB_PIXEL_PIPE:
68 return FXFALSE;
69 case FX_PENDING_BUFFERSWAPS:
70 return grBufferNumPending();
71 case FX_TEXTURE_ALIGN:
72 /* This is a guess from reading the glide3 docs */
73 return 8;
74 default:
75 if (MESA_VERBOSE&VERBOSE_DRIVER) {
76 fprintf(stderr,"Wrong parameter in FX_grGetInteger!\n");
77 }
78 return -1;
79 }
80 #else
81 FxU32 grname;
82 FxI32 result;
83
84 switch (pname)
85 {
86 case FX_FOG_TABLE_ENTRIES:
87 case FX_GLIDE_STATE_SIZE:
88 case FX_LFB_PIXEL_PIPE:
89 case FX_PENDING_BUFFERSWAPS:
90 case FX_TEXTURE_ALIGN:
91 grname = pname;
92 break;
93 default:
94 if (MESA_VERBOSE&VERBOSE_DRIVER) {
95 fprintf(stderr,"Wrong parameter in FX_grGetInteger!\n");
96 }
97 return -1;
98 }
99
100 grGet(grname,4,&result);
101 return result;
102 #endif
103 }
104
105 FxI32 FX_grGetInteger(FxU32 pname)
106 {
107 int result;
108
109 BEGIN_BOARD_LOCK();
110 result=FX_grGetInteger_NoLock(pname);
111 END_BOARD_LOCK();
112 return result;
113 }
114
115
116 FxBool FX_grLfbLock(GrLock_t type, GrBuffer_t buffer,
117 GrLfbWriteMode_t writeMode, GrOriginLocation_t origin,
118 FxBool pixelPipeline, GrLfbInfo_t *info ) {
119 FxBool result;
120
121 BEGIN_BOARD_LOCK();
122 result=grLfbLock(type, buffer, writeMode, origin, pixelPipeline, info);
123 END_BOARD_LOCK();
124 return result;
125 }
126
127 FxU32 FX_grTexTextureMemRequired(FxU32 evenOdd, GrTexInfo *info) {
128 FxU32 result;
129
130 BEGIN_BOARD_LOCK();
131 result=grTexTextureMemRequired(evenOdd, info);
132 END_BOARD_LOCK();
133 return result;
134 }
135
136 FxU32 FX_grTexMinAddress(GrChipID_t tmu) {
137 FxU32 result;
138
139 BEGIN_BOARD_LOCK();
140 result=grTexMinAddress(tmu);
141 END_BOARD_LOCK();
142 return result;
143 }
144
145 extern FxU32 FX_grTexMaxAddress(GrChipID_t tmu) {
146 FxU32 result;
147
148 BEGIN_BOARD_LOCK();
149 result=grTexMaxAddress(tmu);
150 END_BOARD_LOCK();
151 return result;
152 }
153
154 FxBool 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 FX_grGammaCorrectionValue(float val)
182 {
183 (void)val;
184 /* ToDo */
185 }
186
187 int FX_getFogTableSize(void)
188 {
189 int result;
190 BEGIN_BOARD_LOCK();
191 grGet(GR_FOG_TABLE_ENTRIES,sizeof(int),(void*)&result);
192 END_BOARD_LOCK();
193 return result;
194 }
195
196 int FX_getGrStateSize(void)
197 {
198 int result;
199 BEGIN_BOARD_LOCK();
200 grGet(GR_GLIDE_STATE_SIZE,sizeof(int),(void*)&result);
201 END_BOARD_LOCK();
202
203 return result;
204
205 }
206
207 int FX_grSstScreenWidth()
208 {
209 FxI32 result[4];
210
211 BEGIN_BOARD_LOCK();
212 grGet(GR_VIEWPORT,sizeof(FxI32)*4,result);
213 END_BOARD_LOCK();
214
215 return result[2];
216 }
217
218 int FX_grSstScreenHeight()
219 {
220 FxI32 result[4];
221
222 BEGIN_BOARD_LOCK();
223 grGet(GR_VIEWPORT,sizeof(FxI32)*4,result);
224 END_BOARD_LOCK();
225
226 return result[3];
227 }
228
229 void FX_grGlideGetVersion(char *buf)
230 {
231 BEGIN_BOARD_LOCK();
232 strcpy(buf,grGetString(GR_VERSION));
233 END_BOARD_LOCK();
234 }
235
236 void FX_grSstPerfStats(GrSstPerfStats_t *st)
237 {
238 FxI32 n;
239 grGet(GR_STATS_PIXELS_IN, 4, &n); st->pixelsIn = n;
240 grGet(GR_STATS_PIXELS_CHROMA_FAIL, 4, &n); st->chromaFail = n;
241 grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &n); st->zFuncFail = n;
242 grGet(GR_STATS_PIXELS_AFUNC_FAIL, 4, &n); st->aFuncFail = n;
243 grGet(GR_STATS_PIXELS_OUT, 4, &n); st->pixelsOut = n;
244 }
245
246 void FX_grAADrawLine(GrVertex *a,GrVertex *b)
247 {
248 /* ToDo */
249 BEGIN_CLIP_LOOP();
250 grDrawLine(a,b);
251 END_CLIP_LOOP();
252 }
253
254 void FX_grAADrawPoint(GrVertex *a)
255 {
256 BEGIN_CLIP_LOOP();
257 grDrawPoint(a);
258 END_CLIP_LOOP();
259 }
260
261 void FX_grDrawPolygonVertexList(int n, GrVertex *verts)
262 {
263 BEGIN_CLIP_LOOP();
264 grDrawVertexArrayContiguous(GR_POLYGON, n, verts, sizeof(GrVertex));
265 END_CLIP_LOOP();
266 }
267
268 #if FX_USE_PARGB
269 void FX_setupGrVertexLayout(void)
270 {
271 BEGIN_BOARD_LOCK();
272 grReset(GR_VERTEX_PARAMETER);
273
274 grCoordinateSpace(GR_WINDOW_COORDS);
275 grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
276 grVertexLayout(GR_PARAM_PARGB, GR_VERTEX_PARGB_OFFSET << 2, GR_PARAM_ENABLE);
277 grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
278 grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE);
279 grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);
280 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE);
281 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
282 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
283 END_BOARD_LOCK();
284 }
285 #else /* FX_USE_PARGB */
286 void FX_setupGrVertexLayout(void)
287 {
288 BEGIN_BOARD_LOCK();
289 grReset(GR_VERTEX_PARAMETER);
290
291 grCoordinateSpace(GR_WINDOW_COORDS);
292 grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
293 grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
294 grVertexLayout(GR_PARAM_A, GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE);
295 grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
296 grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE);
297 grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);
298 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE);
299 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
300 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
301 END_BOARD_LOCK();
302 }
303 #endif
304
305 void FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask)
306 {
307 switch(hintType) {
308 case GR_HINT_STWHINT:
309 {
310 if (hintMask & GR_STWHINT_W_DIFF_TMU0)
311 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);
312 else
313 grVertexLayout(GR_PARAM_Q0,GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE);
314
315 if (hintMask & GR_STWHINT_ST_DIFF_TMU1)
316 grVertexLayout(GR_PARAM_ST1,GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_ENABLE);
317 else
318 grVertexLayout(GR_PARAM_ST1,GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
319
320 if (hintMask & GR_STWHINT_W_DIFF_TMU1)
321 grVertexLayout(GR_PARAM_Q1,GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_ENABLE);
322 else
323 grVertexLayout(GR_PARAM_Q1,GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
324
325 }
326 }
327 }
328
329 void FX_grHints(GrHint_t hintType, FxU32 hintMask) {
330 BEGIN_BOARD_LOCK();
331 FX_grHints_NoLock(hintType, hintMask);
332 END_BOARD_LOCK();
333 }
334
335 int FX_grSstQueryHardware(GrHwConfiguration *config)
336 {
337 int i,j;
338 int numFB;
339
340 BEGIN_BOARD_LOCK();
341 grGet(GR_NUM_BOARDS,4,(void*)&(config->num_sst));
342 if (config->num_sst == 0)
343 return 0;
344 for (i = 0; i< config->num_sst; i++)
345 {
346 config->SSTs[i].type = GR_SSTTYPE_VOODOO;
347 grSstSelect(i);
348 grGet(GR_MEMORY_FB,4,(void*)&(config->SSTs[i].sstBoard.VoodooConfig.fbRam));
349 config->SSTs[i].sstBoard.VoodooConfig.fbRam/= 1024*1024;
350
351 grGet(GR_NUM_TMU,4,(void*)&(config->SSTs[i].sstBoard.VoodooConfig.nTexelfx));
352
353
354 grGet(GR_NUM_FB,4,(void*)&numFB);
355 if (numFB > 1)
356 config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXTRUE;
357 else
358 config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXFALSE;
359 for (j = 0; j < config->SSTs[i].sstBoard.VoodooConfig.nTexelfx; j++)
360 {
361 grGet(GR_MEMORY_TMU,4,(void*)&(config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRam));
362 config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRam /= 1024*1024;
363 }
364 }
365 END_BOARD_LOCK();
366 return 1;
367 }
368
369 #else
370
371 int FX_grSstScreenWidth()
372 {
373 int i;
374 BEGIN_BOARD_LOCK();
375 i = grSstScreenWidth();
376 END_BOARD_LOCK();
377 return i;
378 }
379
380 int FX_grSstScreenHeight()
381 {
382 int i;
383 BEGIN_BOARD_LOCK();
384 i = grSstScreenHeight();
385 END_BOARD_LOCK();
386 return i;
387 }
388
389 int FX_grSstQueryHardware(GrHwConfiguration *c)
390 {
391 int i;
392 BEGIN_BOARD_LOCK();
393 i = grSstQueryHardware(c);
394 END_BOARD_LOCK();
395 return i;
396 }
397
398
399 #endif /* FX_GLIDE3 */
400
401 /* It appears to me that this function is needed either way. */
402 FX_GrContext_t FX_grSstWinOpen( FxU32 hWnd,
403 GrScreenResolution_t screen_resolution,
404 GrScreenRefresh_t refresh_rate,
405 GrColorFormat_t color_format,
406 GrOriginLocation_t origin_location,
407 int nColBuffers,
408 int nAuxBuffers)
409 {
410 FX_GrContext_t i;
411 BEGIN_BOARD_LOCK();
412 i = grSstWinOpen( hWnd,
413 screen_resolution,
414 refresh_rate,
415 color_format,
416 origin_location,
417 nColBuffers,
418 nAuxBuffers );
419
420 /*
421 fprintf(stderr,
422 "grSstWinOpen( win %d res %d ref %d fmt %d\n"
423 " org %d ncol %d naux %d )\n"
424 " ==> %d\n",
425 hWnd,
426 screen_resolution,
427 refresh_rate,
428 color_format,
429 origin_location,
430 nColBuffers,
431 nAuxBuffers,
432 i);
433 */
434 END_BOARD_LOCK();
435 return i;
436 }
437
438
439
440 #else
441
442 /*
443 * Need this to provide at least one external definition.
444 */
445
446 int gl_fx_dummy_function_glidew(void)
447 {
448 return 0;
449 }
450
451 #endif /* FX */