e20949e062e51bd67f94f464da170ef0b97a2747
[mesa.git] / src / mesa / drivers / glide / fxglidew.c
1 /* $Id: fxglidew.c,v 1.23 2003/10/13 11:14:58 dborca 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 * Daniel Borca
33 * Hiroshi Morii
34 */
35
36 /* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */
37
38
39 #ifdef HAVE_CONFIG_H
40 #include "conf.h"
41 #endif
42
43 #if defined(FX)
44 #include "fxglidew.h"
45 #include "fxdrv.h"
46
47 #include <stdlib.h>
48 #include <string.h>
49
50 FxI32
51 FX_grGetInteger_NoLock(FxU32 pname)
52 {
53 FxI32 result;
54
55 if (grGet(pname, 4, &result)) {
56 return result;
57 }
58
59 if (TDFX_DEBUG & VERBOSE_DRIVER) {
60 fprintf(stderr, "%s: wrong parameter (%lx)\n", __FUNCTION__, pname);
61 }
62 return -1;
63 }
64
65 FxBool
66 FX_grSstControl(FxU32 code)
67 {
68 /* The glide 3 sources call for grEnable/grDisable to be called in exchange
69 * for grSstControl. */
70 switch (code) {
71 case GR_CONTROL_ACTIVATE:
72 grEnable(GR_PASSTHRU);
73 break;
74 case GR_CONTROL_DEACTIVATE:
75 grDisable(GR_PASSTHRU);
76 break;
77 }
78 /* Appearently GR_CONTROL_RESIZE can be ignored. */
79 return 1; /* OK? */
80 }
81
82
83 int
84 FX_grSstScreenWidth()
85 {
86 FxI32 result[4];
87
88 BEGIN_BOARD_LOCK();
89 grGet(GR_VIEWPORT, sizeof(FxI32) * 4, result);
90 END_BOARD_LOCK();
91
92 return result[2];
93 }
94
95 int
96 FX_grSstScreenHeight()
97 {
98 FxI32 result[4];
99
100 BEGIN_BOARD_LOCK();
101 grGet(GR_VIEWPORT, sizeof(FxI32) * 4, result);
102 END_BOARD_LOCK();
103
104 return result[3];
105 }
106
107 void
108 FX_grSstPerfStats(GrSstPerfStats_t * st)
109 {
110 FxI32 n;
111 grGet(GR_STATS_PIXELS_IN, 4, &n);
112 st->pixelsIn = n;
113 grGet(GR_STATS_PIXELS_CHROMA_FAIL, 4, &n);
114 st->chromaFail = n;
115 grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &n);
116 st->zFuncFail = n;
117 grGet(GR_STATS_PIXELS_AFUNC_FAIL, 4, &n);
118 st->aFuncFail = n;
119 grGet(GR_STATS_PIXELS_OUT, 4, &n);
120 st->pixelsOut = n;
121 }
122
123 void
124 FX_setupGrVertexLayout(void)
125 {
126 BEGIN_BOARD_LOCK();
127 grReset(GR_VERTEX_PARAMETER);
128
129 grCoordinateSpace(GR_WINDOW_COORDS);
130 grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
131 grVertexLayout(GR_PARAM_PARGB, GR_VERTEX_PARGB_OFFSET << 2, GR_PARAM_ENABLE);
132 grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
133 grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE);
134 grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2,
135 GR_PARAM_ENABLE);
136 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
137 GR_PARAM_DISABLE);
138 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
139 GR_PARAM_DISABLE);
140 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
141 GR_PARAM_DISABLE);
142 END_BOARD_LOCK();
143 }
144
145 void
146 FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask)
147 {
148 switch (hintType) {
149 case GR_HINT_STWHINT:
150 {
151 if (hintMask & GR_STWHINT_W_DIFF_TMU0)
152 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
153 GR_PARAM_ENABLE);
154 else
155 grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
156 GR_PARAM_DISABLE);
157
158 if (hintMask & GR_STWHINT_ST_DIFF_TMU1)
159 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
160 GR_PARAM_ENABLE);
161 else
162 grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
163 GR_PARAM_DISABLE);
164
165 if (hintMask & GR_STWHINT_W_DIFF_TMU1)
166 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
167 GR_PARAM_ENABLE);
168 else
169 grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
170 GR_PARAM_DISABLE);
171
172 }
173 }
174 }
175
176 /*
177 * Glide3 doesn't have the grSstQueryHardware function anymore.
178 * Instead, we call grGet() and fill in the data structures ourselves.
179 */
180 int
181 FX_grSstQueryHardware(GrHwConfiguration * config)
182 {
183 int i, j;
184 int numFB;
185
186 BEGIN_BOARD_LOCK();
187
188 grGet(GR_NUM_BOARDS, 4, (void *) &(config->num_sst));
189 if (config->num_sst == 0)
190 return 0;
191
192 for (i = 0; i < config->num_sst; i++) {
193 FxI32 result;
194 const char *extension;
195
196 grSstSelect(i);
197
198 extension = grGetString(GR_HARDWARE);
199 if (strstr(extension, "Voodoo Banshee")) {
200 config->SSTs[i].type = GR_SSTTYPE_Banshee;
201 } else if (strstr(extension, "Voodoo3")) {
202 config->SSTs[i].type = GR_SSTTYPE_Voodoo3;
203 } else if (strstr(extension, "Voodoo4")) {
204 config->SSTs[i].type = GR_SSTTYPE_Voodoo4;
205 } else if (strstr(extension, "Voodoo5")) {
206 config->SSTs[i].type = GR_SSTTYPE_Voodoo5;
207 } else { /* Voodoo1,2,rush */
208 /* ZZZ TO DO: Need to distinguish whether we have V1 or V2 or Rush. */
209 config->SSTs[i].type = GR_SSTTYPE_VOODOO;
210 }
211
212 grGet(GR_MEMORY_FB, 4, &result); /* ZZZ: differs after grSstWinOpen */
213 config->SSTs[i].fbRam = result / (1024 * 1024);
214
215 grGet(GR_NUM_TMU, 4, &result);
216 config->SSTs[i].nTexelfx = result;
217
218 grGet(GR_REVISION_FB, 4, &result);
219 config->SSTs[i].fbiRev = result;
220
221 for (j = 0; j < config->SSTs[i].nTexelfx; j++) {
222 grGet(GR_MEMORY_TMU, 4, &result); /* ZZZ: differs after grSstWinOpen */
223 config->SSTs[i].tmuConfig[j].tmuRam = result / (1024 * 1024);
224 grGet(GR_REVISION_TMU, 4, &result);
225 config->SSTs[i].tmuConfig[j].tmuRev = result;
226 }
227
228 extension = grGetString(GR_EXTENSION);
229 config->SSTs[i].HavePixExt = (strstr(extension, " PIXEXT ") != NULL);
230 config->SSTs[i].HaveTexFmt = (strstr(extension, " TEXFMT ") != NULL);
231 config->SSTs[i].HaveCmbExt = (strstr(extension, " COMBINE ") != NULL);
232 config->SSTs[i].HaveMirExt = (strstr(extension, " TEXMIRROR ") != NULL);
233 config->SSTs[i].HaveTexus2 = GL_FALSE;
234
235 /* number of Voodoo chips */
236 grGet(GR_NUM_FB, 4, (void *) &numFB);
237 config->SSTs[i].numChips = numFB;
238
239 }
240
241 tdfx_hook_glide(&config->Glide);
242
243 END_BOARD_LOCK();
244 return 1;
245 }
246
247
248
249 #else
250
251 /*
252 * Need this to provide at least one external definition.
253 */
254
255 extern int gl_fx_dummy_function_glidew(void);
256 int
257 gl_fx_dummy_function_glidew(void)
258 {
259 return 0;
260 }
261
262 #endif /* FX */