1 /* -*- mode: c; c-basic-offset: 3 -*-
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
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:
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
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
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.c,v 1.10 2002/10/30 12:52:00 alanh Exp $ */
30 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
33 * Gareth Hughes <gareth@valinux.com>
34 * Brian Paul <brianp@valinux.com>
38 #include "tdfx_context.h"
40 #include "tdfx_lock.h"
42 #include "tdfx_pixels.h"
46 #include "swrast/swrast.h"
47 #if defined(USE_X86_ASM)
48 #include "x86/common_x86_asm.h"
52 #define TDFX_DATE "20021125"
55 /* These are used in calls to FX_grColorMaskv() */
56 const GLboolean false4
[4] = { GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
};
57 const GLboolean true4
[4] = { GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
};
61 /* KW: Put the word Mesa in the render string because quakeworld
62 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
65 static const GLubyte
*tdfxDDGetString( GLcontext
*ctx
, GLenum name
)
67 tdfxContextPtr fxMesa
= (tdfxContextPtr
) ctx
->DriverCtx
;
72 /* The renderer string must be per-context state to handle
73 * multihead correctly.
75 char *buffer
= fxMesa
->rendererString
;
78 LOCK_HARDWARE(fxMesa
);
79 strcpy( hardware
, fxMesa
->Glide
.grGetString(GR_HARDWARE
) );
80 UNLOCK_HARDWARE(fxMesa
);
82 strcpy( buffer
, "Mesa DRI " );
83 strcat( buffer
, TDFX_DATE
);
84 strcat( buffer
, " " );
86 if ( strcmp( hardware
, "Voodoo3 (tm)" ) == 0 ) {
87 strcat( buffer
, "Voodoo3" );
89 else if ( strcmp( hardware
, "Voodoo Banshee (tm)" ) == 0 ) {
90 strcat( buffer
, "VoodooBanshee" );
92 else if ( strcmp( hardware
, "Voodoo4 (tm)" ) == 0 ) {
93 strcat( buffer
, "Voodoo4" );
95 else if ( strcmp( hardware
, "Voodoo5 (tm)" ) == 0 ) {
96 strcat( buffer
, "Voodoo5" );
99 /* unexpected result: replace spaces with hyphens */
101 for ( i
= 0 ; hardware
[i
] && i
< 60 ; i
++ ) {
102 if ( hardware
[i
] == ' ' || hardware
[i
] == '\t' )
105 strcat( buffer
, hardware
);
108 /* Append any CPU-specific information.
111 if ( _mesa_x86_cpu_features
) {
112 strncat( buffer
, " x86", 4 );
117 strncat( buffer
, "/MMX", 4 );
121 if ( cpu_has_3dnow
) {
122 strncat( buffer
, "/3DNow!", 7 );
127 strncat( buffer
, "/SSE", 4 );
130 return (const GLubyte
*) buffer
;
133 return (const GLubyte
*)"VA Linux Systems, Inc.";
140 /* Return uptodate buffer size information.
142 static void tdfxDDGetBufferSize( GLframebuffer
*buffer
,
143 GLuint
*width
, GLuint
*height
)
145 GET_CURRENT_CONTEXT(ctx
);
146 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
148 LOCK_HARDWARE( fxMesa
);
149 *width
= fxMesa
->width
;
150 *height
= fxMesa
->height
;
151 UNLOCK_HARDWARE( fxMesa
);
157 * Return the current value of the occlusion test flag and
158 * reset the flag (hardware counters) to false.
160 static GLboolean
get_occlusion_result( GLcontext
*ctx
)
162 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
165 LOCK_HARDWARE( fxMesa
);
166 fxMesa
->Glide
.grFinish(); /* required to flush the FIFO - FB 21-01-2002 */
168 if (ctx
->Depth
.OcclusionTest
) {
169 if (ctx
->OcclusionResult
) {
170 result
= GL_TRUE
; /* result of software rendering */
174 fxMesa
->Glide
.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL
, 4, &zfail
);
175 fxMesa
->Glide
.grGet(GR_STATS_PIXELS_IN
, 4, &in
);
176 /* Geometry is occluded if there is no input (in == 0) */
177 /* or if all pixels failed the depth test (zfail == in) */
178 /* The < 1 is there because I have empirically seen cases where */
179 /* zfail > in.... go figure. FB - 21-01-2002. */
180 result
= ((in
- zfail
) < 1 || in
== 0) ? GL_FALSE
: GL_TRUE
;
184 result
= ctx
->OcclusionResultSaved
;
187 /* reset results now */
188 fxMesa
->Glide
.grReset(GR_STATS_PIXELS
);
189 ctx
->OcclusionResult
= GL_FALSE
;
190 ctx
->OcclusionResultSaved
= GL_FALSE
;
192 UNLOCK_HARDWARE( fxMesa
);
199 * We're only implementing this function to handle the
200 * GL_OCCLUSTION_TEST_RESULT_HP case. It's special because it
201 * has a side-effect: resetting the occlustion result flag.
203 static GLboolean
tdfxDDGetBooleanv( GLcontext
*ctx
, GLenum pname
,
206 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
207 *result
= get_occlusion_result( ctx
);
213 static GLboolean
tdfxDDGetDoublev( GLcontext
*ctx
, GLenum pname
,
216 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
217 *result
= (GLdouble
) get_occlusion_result( ctx
);
223 static GLboolean
tdfxDDGetFloatv( GLcontext
*ctx
, GLenum pname
,
226 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
227 *result
= (GLfloat
) get_occlusion_result( ctx
);
233 static GLboolean
tdfxDDGetIntegerv( GLcontext
*ctx
, GLenum pname
,
236 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
237 *result
= (GLint
) get_occlusion_result( ctx
);
245 #define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \
246 ((vis.redBits == r) && \
247 (vis.greenBits == g) && \
248 (vis.blueBits == b) && \
249 (vis.alphaBits == a))
251 void tdfxDDInitDriverFuncs( GLcontext
*ctx
)
253 if ( MESA_VERBOSE
& VERBOSE_DRIVER
) {
254 fprintf( stderr
, "tdfx: %s()\n", __FUNCTION__
);
257 ctx
->Driver
.GetString
= tdfxDDGetString
;
258 ctx
->Driver
.GetBufferSize
= tdfxDDGetBufferSize
;
259 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
260 ctx
->Driver
.Error
= NULL
;
262 /* Pixel path fallbacks.
264 ctx
->Driver
.Accum
= _swrast_Accum
;
265 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
266 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
267 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
268 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
272 if ( VISUAL_EQUALS_RGBA(ctx
->Visual
, 8, 8, 8, 8) )
274 ctx
->Driver
.DrawPixels
= tdfx_drawpixels_R8G8B8A8
;
275 ctx
->Driver
.ReadPixels
= tdfx_readpixels_R8G8B8A8
;
277 else if ( VISUAL_EQUALS_RGBA(ctx
->Visual
, 5, 6, 5, 0) )
279 ctx
->Driver
.ReadPixels
= tdfx_readpixels_R5G6B5
;
282 ctx
->Driver
.GetBooleanv
= tdfxDDGetBooleanv
;
283 ctx
->Driver
.GetDoublev
= tdfxDDGetDoublev
;
284 ctx
->Driver
.GetFloatv
= tdfxDDGetFloatv
;
285 ctx
->Driver
.GetIntegerv
= tdfxDDGetIntegerv
;
286 ctx
->Driver
.GetPointerv
= NULL
;
291 * These are here for lack of a better place.
295 FX_grColorMaskv(GLcontext
*ctx
, const GLboolean rgba
[4])
297 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
298 LOCK_HARDWARE(fxMesa
);
299 if (ctx
->Visual
.redBits
== 8) {
301 ASSERT( fxMesa
->Glide
.grColorMaskExt
);
302 fxMesa
->Glide
.grColorMaskExt(rgba
[RCOMP
], rgba
[GCOMP
],
303 rgba
[BCOMP
], rgba
[ACOMP
]);
307 /* we never have an alpha buffer */
308 fxMesa
->Glide
.grColorMask(rgba
[RCOMP
] || rgba
[GCOMP
] || rgba
[BCOMP
],
311 UNLOCK_HARDWARE(fxMesa
);
315 FX_grColorMaskv_NoLock(GLcontext
*ctx
, const GLboolean rgba
[4])
317 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
318 if (ctx
->Visual
.redBits
== 8) {
320 ASSERT( fxMesa
->Glide
.grColorMaskExt
);
321 fxMesa
->Glide
.grColorMaskExt(rgba
[RCOMP
], rgba
[GCOMP
],
322 rgba
[BCOMP
], rgba
[ACOMP
]);
326 /* we never have an alpha buffer */
327 fxMesa
->Glide
.grColorMask(rgba
[RCOMP
] || rgba
[GCOMP
] || rgba
[BCOMP
],