Support for swappable t&l modules, including an example one in the FX
[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 FX_grGetInteger_NoLock(FxU32 pname)
58 {
59 #if !defined(FX_GLIDE3)
60 switch (pname)
61 {
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 {
85 case FX_FOG_TABLE_ENTRIES:
86 case FX_GLIDE_STATE_SIZE:
87 case FX_LFB_PIXEL_PIPE:
88 case FX_PENDING_BUFFERSWAPS:
89 case FX_TEXTURE_ALIGN:
90 grname = pname;
91 break;
92 default:
93 if (MESA_VERBOSE&VERBOSE_DRIVER) {
94 fprintf(stderr,"Wrong parameter in FX_grGetInteger!\n");
95 }
96 return -1;
97 }
98
99 grGet(grname,4,&result);
100 return result;
101 #endif
102 }
103
104 FxI32 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 FX_grLfbLock(GrLock_t type, GrBuffer_t buffer,
116 GrLfbWriteMode_t writeMode, GrOriginLocation_t origin,
117 FxBool pixelPipeline, GrLfbInfo_t *info ) {
118 FxBool result;
119
120 BEGIN_BOARD_LOCK();
121 result=grLfbLock(type, buffer, writeMode, origin, pixelPipeline, info);
122 END_BOARD_LOCK();
123 return result;
124 }
125
126 FxU32 FX_grTexTextureMemRequired(FxU32 evenOdd, GrTexInfo *info) {
127 FxU32 result;
128
129 BEGIN_BOARD_LOCK();
130 result=grTexTextureMemRequired(evenOdd, info);
131 END_BOARD_LOCK();
132 return result;
133 }
134
135 FxU32 FX_grTexMinAddress(GrChipID_t tmu) {
136 FxU32 result;
137
138 BEGIN_BOARD_LOCK();
139 result=grTexMinAddress(tmu);
140 END_BOARD_LOCK();
141 return result;
142 }
143
144 extern FxU32 FX_grTexMaxAddress(GrChipID_t tmu) {
145 FxU32 result;
146
147 BEGIN_BOARD_LOCK();
148 result=grTexMaxAddress(tmu);
149 END_BOARD_LOCK();
150 return result;
151 }
152
153 FxBool FX_grSstControl(FxU32 code)
154 {
155 #if defined(FX_GLIDE3)
156 /* The glide 3 sources call for grEnable/grDisable to be called in exchange
157 * for grSstControl. */
158 switch(code) {
159 case GR_CONTROL_ACTIVATE:
160 grEnable(GR_PASSTHRU);
161 break;
162 case GR_CONTROL_DEACTIVATE:
163 grDisable(GR_PASSTHRU);
164 break;
165 }
166 /* Appearently GR_CONTROL_RESIZE can be ignored. */
167 return 1; /* OK? */
168 #else
169 FxU32 result;
170 BEGIN_BOARD_LOCK();
171 result = grSstControl(code);
172 END_BOARD_LOCK();
173 return result;
174 #endif
175 }
176
177
178 #if defined(FX_GLIDE3)
179
180 void FX_grGammaCorrectionValue(float val)
181 {
182 (void)val;
183 /* ToDo */
184 }
185
186 int FX_getFogTableSize(void)
187 {
188 int result;
189 BEGIN_BOARD_LOCK();
190 grGet(GR_FOG_TABLE_ENTRIES,sizeof(int),(void*)&result);
191 END_BOARD_LOCK();
192 return result;
193 }
194
195 int FX_getGrStateSize(void)
196 {
197 int result;
198 BEGIN_BOARD_LOCK();
199 grGet(GR_GLIDE_STATE_SIZE,sizeof(int),(void*)&result);
200 END_BOARD_LOCK();
201
202 return result;
203
204 }
205
206 int FX_grSstScreenWidth()
207 {
208 FxI32 result[4];
209
210 BEGIN_BOARD_LOCK();
211 grGet(GR_VIEWPORT,sizeof(FxI32)*4,result);
212 END_BOARD_LOCK();
213
214 return result[2];
215 }
216
217 int FX_grSstScreenHeight()
218 {
219 FxI32 result[4];
220
221 BEGIN_BOARD_LOCK();
222 grGet(GR_VIEWPORT,sizeof(FxI32)*4,result);
223 END_BOARD_LOCK();
224
225 return result[3];
226 }
227
228 void FX_grGlideGetVersion(char *buf)
229 {
230 BEGIN_BOARD_LOCK();
231 strcpy(buf,grGetString(GR_VERSION));
232 END_BOARD_LOCK();
233 }
234
235 void FX_grSstPerfStats(GrSstPerfStats_t *st)
236 {
237 FxI32 n;
238 grGet(GR_STATS_PIXELS_IN, 4, &n); st->pixelsIn = n;
239 grGet(GR_STATS_PIXELS_CHROMA_FAIL, 4, &n); st->chromaFail = n;
240 grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &n); st->zFuncFail = n;
241 grGet(GR_STATS_PIXELS_AFUNC_FAIL, 4, &n); st->aFuncFail = n;
242 grGet(GR_STATS_PIXELS_OUT, 4, &n); st->pixelsOut = n;
243 }
244
245 void FX_grAADrawLine(GrVertex *a,GrVertex *b)
246 {
247 /* ToDo */
248 BEGIN_CLIP_LOOP();
249 grDrawLine(a,b);
250 END_CLIP_LOOP();
251 }
252
253 void FX_grAADrawPoint(GrVertex *a)
254 {
255 BEGIN_CLIP_LOOP();
256 grDrawPoint(a);
257 END_CLIP_LOOP();
258 }
259
260 void FX_grDrawPolygonVertexList(int n, GrVertex *verts)
261 {
262 BEGIN_CLIP_LOOP();
263 grDrawVertexArrayContiguous(GR_POLYGON, n, verts, sizeof(GrVertex));
264 END_CLIP_LOOP();
265 }
266
267 void FX_setupGrVertexLayout(void)
268 {
269 BEGIN_BOARD_LOCK();
270 grReset(GR_VERTEX_PARAMETER);
271
272 grCoordinateSpace(GR_WINDOW_COORDS);
273 grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
274 grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
275 grVertexLayout(GR_PARAM_A, GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE);
276 grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
277 grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE);
278 grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);
279 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE);
280 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
281 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
282 END_BOARD_LOCK();
283 }
284
285 void FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask)
286 {
287 switch(hintType) {
288 case GR_HINT_STWHINT:
289 {
290 if (hintMask & GR_STWHINT_W_DIFF_TMU0)
291 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);
292 else
293 grVertexLayout(GR_PARAM_Q0,GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE);
294
295 if (hintMask & GR_STWHINT_ST_DIFF_TMU1)
296 grVertexLayout(GR_PARAM_ST1,GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_ENABLE);
297 else
298 grVertexLayout(GR_PARAM_ST1,GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
299
300 if (hintMask & GR_STWHINT_W_DIFF_TMU1)
301 grVertexLayout(GR_PARAM_Q1,GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_ENABLE);
302 else
303 grVertexLayout(GR_PARAM_Q1,GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE);
304
305 }
306 }
307 }
308
309 void FX_grHints(GrHint_t hintType, FxU32 hintMask) {
310 BEGIN_BOARD_LOCK();
311 FX_grHints_NoLock(hintType, hintMask);
312 END_BOARD_LOCK();
313 }
314
315 /*
316 * Glide3 doesn't have the grSstQueryHardware function anymore.
317 * Instead, we call grGet() and fill in the data structures ourselves.
318 */
319 int FX_grSstQueryHardware(GrHwConfiguration *config)
320 {
321 int i, j;
322 int numFB;
323
324 BEGIN_BOARD_LOCK();
325
326 grGet(GR_NUM_BOARDS, 4, (void*)&(config->num_sst));
327 if (config->num_sst == 0)
328 return 0;
329
330 for (i = 0; i< config->num_sst; i++) {
331 FxI32 result;
332
333 config->SSTs[i].type = GR_SSTTYPE_VOODOO;
334 grSstSelect(i);
335
336 grGet(GR_MEMORY_FB, 4, &result);
337 config->SSTs[i].sstBoard.VoodooConfig.fbRam = result / (1024 * 1024);
338
339 grGet(GR_NUM_TMU, 4, &result);
340 config->SSTs[i].sstBoard.VoodooConfig.nTexelfx = result;
341
342 grGet(GR_REVISION_FB, 4, &result);
343 config->SSTs[i].sstBoard.VoodooConfig.fbiRev = result;
344
345 grGet(GR_NUM_FB,4,(void*)&numFB);
346 if (numFB > 1)
347 config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXTRUE;
348 else
349 config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXFALSE;
350
351 for (j = 0; j < config->SSTs[i].sstBoard.VoodooConfig.nTexelfx; j++) {
352 grGet(GR_MEMORY_TMU, 4, &result);
353 config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRam = result / (1024*1024);
354 grGet(GR_REVISION_TMU, 4, &result);
355 config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRev = result;
356 }
357 }
358 END_BOARD_LOCK();
359 return 1;
360 }
361
362 #else
363
364 int FX_grSstScreenWidth()
365 {
366 int i;
367 BEGIN_BOARD_LOCK();
368 i = grSstScreenWidth();
369 END_BOARD_LOCK();
370 return i;
371 }
372
373 int FX_grSstScreenHeight()
374 {
375 int i;
376 BEGIN_BOARD_LOCK();
377 i = grSstScreenHeight();
378 END_BOARD_LOCK();
379 return i;
380 }
381
382 int FX_grSstQueryHardware(GrHwConfiguration *c)
383 {
384 int i;
385 BEGIN_BOARD_LOCK();
386 i = grSstQueryHardware(c);
387 END_BOARD_LOCK();
388 return i;
389 }
390
391
392 #endif /* FX_GLIDE3 */
393
394 /* It appears to me that this function is needed either way. */
395 FX_GrContext_t FX_grSstWinOpen( FxU32 hWnd,
396 GrScreenResolution_t screen_resolution,
397 GrScreenRefresh_t refresh_rate,
398 GrColorFormat_t color_format,
399 GrOriginLocation_t origin_location,
400 int nColBuffers,
401 int nAuxBuffers)
402 {
403 FX_GrContext_t i;
404 BEGIN_BOARD_LOCK();
405 i = grSstWinOpen( hWnd,
406 screen_resolution,
407 refresh_rate,
408 color_format,
409 origin_location,
410 nColBuffers,
411 nAuxBuffers );
412
413 /*
414 fprintf(stderr,
415 "grSstWinOpen( win %d res %d ref %d fmt %d\n"
416 " org %d ncol %d naux %d )\n"
417 " ==> %d\n",
418 hWnd,
419 screen_resolution,
420 refresh_rate,
421 color_format,
422 origin_location,
423 nColBuffers,
424 nAuxBuffers,
425 i);
426 */
427 END_BOARD_LOCK();
428 return i;
429 }
430
431
432
433 #else
434
435 /*
436 * Need this to provide at least one external definition.
437 */
438
439 extern int gl_fx_dummy_function_glidew(void);
440 int gl_fx_dummy_function_glidew(void)
441 {
442 return 0;
443 }
444
445 #endif /* FX */