Turn off VBO's.
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_dd.c
1 /* -*- mode: c; c-basic-offset: 3 -*-
2 *
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.c,v 1.10 2002/10/30 12:52:00 alanh Exp $ */
27
28 /*
29 * Original rewrite:
30 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
31 *
32 * Authors:
33 * Gareth Hughes <gareth@valinux.com>
34 * Brian Paul <brianp@valinux.com>
35 *
36 */
37
38 #include "tdfx_context.h"
39 #include "tdfx_dd.h"
40 #include "tdfx_lock.h"
41 #include "tdfx_vb.h"
42 #include "tdfx_pixels.h"
43
44 #include "context.h"
45 #include "enums.h"
46 #include "framebuffer.h"
47 #include "swrast/swrast.h"
48 #if defined(USE_X86_ASM)
49 #include "x86/common_x86_asm.h"
50 #endif
51
52
53 #define TDFX_DATE "20040719"
54
55
56 /* These are used in calls to FX_grColorMaskv() */
57 const GLboolean false4[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
58 const GLboolean true4[4] = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
59
60
61
62 /* KW: Put the word Mesa in the render string because quakeworld
63 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
64 * Why?
65 */
66 static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
67 {
68 tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx;
69
70 switch ( name ) {
71 case GL_RENDERER:
72 {
73 /* The renderer string must be per-context state to handle
74 * multihead correctly.
75 */
76 char *buffer = fxMesa->rendererString;
77 char hardware[100];
78
79 LOCK_HARDWARE(fxMesa);
80 strcpy( hardware, fxMesa->Glide.grGetString(GR_HARDWARE) );
81 UNLOCK_HARDWARE(fxMesa);
82
83 strcpy( buffer, "Mesa DRI " );
84 strcat( buffer, TDFX_DATE );
85 strcat( buffer, " " );
86
87 if ( strcmp( hardware, "Voodoo3 (tm)" ) == 0 ) {
88 strcat( buffer, "Voodoo3" );
89 }
90 else if ( strcmp( hardware, "Voodoo Banshee (tm)" ) == 0 ) {
91 strcat( buffer, "VoodooBanshee" );
92 }
93 else if ( strcmp( hardware, "Voodoo4 (tm)" ) == 0 ) {
94 strcat( buffer, "Voodoo4" );
95 }
96 else if ( strcmp( hardware, "Voodoo5 (tm)" ) == 0 ) {
97 strcat( buffer, "Voodoo5" );
98 }
99 else {
100 /* unexpected result: replace spaces with hyphens */
101 int i;
102 for ( i = 0 ; hardware[i] && i < 60 ; i++ ) {
103 if ( hardware[i] == ' ' || hardware[i] == '\t' )
104 hardware[i] = '-';
105 }
106 strcat( buffer, hardware );
107 }
108
109 /* Append any CPU-specific information.
110 */
111 #ifdef USE_X86_ASM
112 if ( _mesa_x86_cpu_features ) {
113 strncat( buffer, " x86", 4 );
114 }
115 #endif
116 #ifdef USE_MMX_ASM
117 if ( cpu_has_mmx ) {
118 strncat( buffer, "/MMX", 4 );
119 }
120 #endif
121 #ifdef USE_3DNOW_ASM
122 if ( cpu_has_3dnow ) {
123 strncat( buffer, "/3DNow!", 7 );
124 }
125 #endif
126 #ifdef USE_SSE_ASM
127 if ( cpu_has_xmm ) {
128 strncat( buffer, "/SSE", 4 );
129 }
130 #endif
131 return (const GLubyte *) buffer;
132 }
133 case GL_VENDOR:
134 return (const GLubyte *)"VA Linux Systems, Inc.";
135 default:
136 return NULL;
137 }
138 }
139
140
141 /* Return uptodate buffer size information.
142 */
143 static void tdfxDDGetBufferSize( GLframebuffer *buffer,
144 GLuint *width, GLuint *height )
145 {
146 GET_CURRENT_CONTEXT(ctx);
147 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
148
149 LOCK_HARDWARE( fxMesa );
150 *width = fxMesa->width;
151 *height = fxMesa->height;
152 UNLOCK_HARDWARE( fxMesa );
153 }
154
155
156
157 /*
158 * Return the current value of the occlusion test flag and
159 * reset the flag (hardware counters) to false.
160 */
161 static GLboolean get_occlusion_result( GLcontext *ctx )
162 {
163 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
164 GLboolean result;
165
166 LOCK_HARDWARE( fxMesa );
167 fxMesa->Glide.grFinish(); /* required to flush the FIFO - FB 21-01-2002 */
168
169 if (ctx->Depth.OcclusionTest) {
170 if (ctx->OcclusionResult) {
171 result = GL_TRUE; /* result of software rendering */
172 }
173 else {
174 FxI32 zfail, in;
175 fxMesa->Glide.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &zfail);
176 fxMesa->Glide.grGet(GR_STATS_PIXELS_IN, 4, &in);
177 /* Geometry is occluded if there is no input (in == 0) */
178 /* or if all pixels failed the depth test (zfail == in) */
179 /* The < 1 is there because I have empirically seen cases where */
180 /* zfail > in.... go figure. FB - 21-01-2002. */
181 result = ((in - zfail) < 1 || in == 0) ? GL_FALSE : GL_TRUE;
182 }
183 }
184 else {
185 result = ctx->OcclusionResultSaved;
186 }
187
188 /* reset results now */
189 fxMesa->Glide.grReset(GR_STATS_PIXELS);
190 ctx->OcclusionResult = GL_FALSE;
191 ctx->OcclusionResultSaved = GL_FALSE;
192
193 UNLOCK_HARDWARE( fxMesa );
194
195 return result;
196 }
197
198
199 /*
200 * We're only implementing this function to handle the
201 * GL_OCCLUSTION_TEST_RESULT_HP case. It's special because it
202 * has a side-effect: resetting the occlustion result flag.
203 */
204 static GLboolean tdfxDDGetBooleanv( GLcontext *ctx, GLenum pname,
205 GLboolean *result )
206 {
207 if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
208 *result = get_occlusion_result( ctx );
209 return GL_TRUE;
210 }
211 return GL_FALSE;
212 }
213
214 static GLboolean tdfxDDGetDoublev( GLcontext *ctx, GLenum pname,
215 GLdouble *result )
216 {
217 if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
218 *result = (GLdouble) get_occlusion_result( ctx );
219 return GL_TRUE;
220 }
221 return GL_FALSE;
222 }
223
224 static GLboolean tdfxDDGetFloatv( GLcontext *ctx, GLenum pname,
225 GLfloat *result )
226 {
227 if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
228 *result = (GLfloat) get_occlusion_result( ctx );
229 return GL_TRUE;
230 }
231 return GL_FALSE;
232 }
233
234 static GLboolean tdfxDDGetIntegerv( GLcontext *ctx, GLenum pname,
235 GLint *result )
236 {
237 if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
238 *result = (GLint) get_occlusion_result( ctx );
239 return GL_TRUE;
240 }
241 return GL_FALSE;
242 }
243
244
245
246 #define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \
247 ((vis->redBits == r) && \
248 (vis->greenBits == g) && \
249 (vis->blueBits == b) && \
250 (vis->alphaBits == a))
251
252 void tdfxDDInitDriverFuncs( const __GLcontextModes *visual,
253 struct dd_function_table *functions )
254 {
255 if ( MESA_VERBOSE & VERBOSE_DRIVER ) {
256 fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ );
257 }
258
259 functions->GetString = tdfxDDGetString;
260 functions->GetBufferSize = tdfxDDGetBufferSize;
261 functions->ResizeBuffers = _mesa_resize_framebuffer;
262
263 /* Accelerated paths
264 */
265 if ( VISUAL_EQUALS_RGBA(visual, 8, 8, 8, 8) )
266 {
267 functions->DrawPixels = tdfx_drawpixels_R8G8B8A8;
268 functions->ReadPixels = tdfx_readpixels_R8G8B8A8;
269 }
270 else if ( VISUAL_EQUALS_RGBA(visual, 5, 6, 5, 0) )
271 {
272 functions->ReadPixels = tdfx_readpixels_R5G6B5;
273 }
274
275 functions->GetBooleanv = tdfxDDGetBooleanv;
276 functions->GetDoublev = tdfxDDGetDoublev;
277 functions->GetFloatv = tdfxDDGetFloatv;
278 functions->GetIntegerv = tdfxDDGetIntegerv;
279 }
280
281
282 /*
283 * These are here for lack of a better place.
284 */
285
286 void
287 FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4])
288 {
289 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
290 LOCK_HARDWARE(fxMesa);
291 if (ctx->Visual.redBits == 8) {
292 /* 32bpp mode */
293 ASSERT( fxMesa->Glide.grColorMaskExt );
294 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
295 rgba[BCOMP], rgba[ACOMP]);
296 }
297 else {
298 /* 16 bpp mode */
299 /* we never have an alpha buffer */
300 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
301 GL_FALSE);
302 }
303 UNLOCK_HARDWARE(fxMesa);
304 }
305
306 void
307 FX_grColorMaskv_NoLock(GLcontext *ctx, const GLboolean rgba[4])
308 {
309 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
310 if (ctx->Visual.redBits == 8) {
311 /* 32bpp mode */
312 ASSERT( fxMesa->Glide.grColorMaskExt );
313 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
314 rgba[BCOMP], rgba[ACOMP]);
315 }
316 else {
317 /* 16 bpp mode */
318 /* we never have an alpha buffer */
319 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
320 GL_FALSE);
321 }
322 }