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 "framebuffer.h"
47 #include "swrast/swrast.h"
48 #if defined(USE_X86_ASM)
49 #include "x86/common_x86_asm.h"
53 #define TDFX_DATE "20040719"
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
};
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).
66 static const GLubyte
*tdfxDDGetString( GLcontext
*ctx
, GLenum name
)
68 tdfxContextPtr fxMesa
= (tdfxContextPtr
) ctx
->DriverCtx
;
73 /* The renderer string must be per-context state to handle
74 * multihead correctly.
76 char *buffer
= fxMesa
->rendererString
;
79 LOCK_HARDWARE(fxMesa
);
80 strcpy( hardware
, fxMesa
->Glide
.grGetString(GR_HARDWARE
) );
81 UNLOCK_HARDWARE(fxMesa
);
83 strcpy( buffer
, "Mesa DRI " );
84 strcat( buffer
, TDFX_DATE
);
85 strcat( buffer
, " " );
87 if ( strcmp( hardware
, "Voodoo3 (tm)" ) == 0 ) {
88 strcat( buffer
, "Voodoo3" );
90 else if ( strcmp( hardware
, "Voodoo Banshee (tm)" ) == 0 ) {
91 strcat( buffer
, "VoodooBanshee" );
93 else if ( strcmp( hardware
, "Voodoo4 (tm)" ) == 0 ) {
94 strcat( buffer
, "Voodoo4" );
96 else if ( strcmp( hardware
, "Voodoo5 (tm)" ) == 0 ) {
97 strcat( buffer
, "Voodoo5" );
100 /* unexpected result: replace spaces with hyphens */
102 for ( i
= 0 ; hardware
[i
] && i
< 60 ; i
++ ) {
103 if ( hardware
[i
] == ' ' || hardware
[i
] == '\t' )
106 strcat( buffer
, hardware
);
109 /* Append any CPU-specific information.
112 if ( _mesa_x86_cpu_features
) {
113 strncat( buffer
, " x86", 4 );
118 strncat( buffer
, "/MMX", 4 );
122 if ( cpu_has_3dnow
) {
123 strncat( buffer
, "/3DNow!", 7 );
128 strncat( buffer
, "/SSE", 4 );
131 return (const GLubyte
*) buffer
;
134 return (const GLubyte
*)"VA Linux Systems, Inc.";
141 /* Return uptodate buffer size information.
143 static void tdfxDDGetBufferSize( GLframebuffer
*buffer
,
144 GLuint
*width
, GLuint
*height
)
146 GET_CURRENT_CONTEXT(ctx
);
147 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
149 LOCK_HARDWARE( fxMesa
);
150 *width
= fxMesa
->width
;
151 *height
= fxMesa
->height
;
152 UNLOCK_HARDWARE( fxMesa
);
158 * Return the current value of the occlusion test flag and
159 * reset the flag (hardware counters) to false.
161 static GLboolean
get_occlusion_result( GLcontext
*ctx
)
163 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
166 LOCK_HARDWARE( fxMesa
);
167 fxMesa
->Glide
.grFinish(); /* required to flush the FIFO - FB 21-01-2002 */
169 if (ctx
->Depth
.OcclusionTest
) {
170 if (ctx
->OcclusionResult
) {
171 result
= GL_TRUE
; /* result of software rendering */
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
;
185 result
= ctx
->OcclusionResultSaved
;
188 /* reset results now */
189 fxMesa
->Glide
.grReset(GR_STATS_PIXELS
);
190 ctx
->OcclusionResult
= GL_FALSE
;
191 ctx
->OcclusionResultSaved
= GL_FALSE
;
193 UNLOCK_HARDWARE( fxMesa
);
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.
204 static GLboolean
tdfxDDGetBooleanv( GLcontext
*ctx
, GLenum pname
,
207 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
208 *result
= get_occlusion_result( ctx
);
214 static GLboolean
tdfxDDGetDoublev( GLcontext
*ctx
, GLenum pname
,
217 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
218 *result
= (GLdouble
) get_occlusion_result( ctx
);
224 static GLboolean
tdfxDDGetFloatv( GLcontext
*ctx
, GLenum pname
,
227 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
228 *result
= (GLfloat
) get_occlusion_result( ctx
);
234 static GLboolean
tdfxDDGetIntegerv( GLcontext
*ctx
, GLenum pname
,
237 if ( pname
== GL_OCCLUSION_TEST_RESULT_HP
) {
238 *result
= (GLint
) get_occlusion_result( ctx
);
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))
252 void tdfxDDInitDriverFuncs( const __GLcontextModes
*visual
,
253 struct dd_function_table
*functions
)
255 if ( MESA_VERBOSE
& VERBOSE_DRIVER
) {
256 fprintf( stderr
, "tdfx: %s()\n", __FUNCTION__
);
259 functions
->GetString
= tdfxDDGetString
;
260 functions
->GetBufferSize
= tdfxDDGetBufferSize
;
261 functions
->ResizeBuffers
= _mesa_resize_framebuffer
;
265 if ( VISUAL_EQUALS_RGBA(visual
, 8, 8, 8, 8) )
267 functions
->DrawPixels
= tdfx_drawpixels_R8G8B8A8
;
268 functions
->ReadPixels
= tdfx_readpixels_R8G8B8A8
;
270 else if ( VISUAL_EQUALS_RGBA(visual
, 5, 6, 5, 0) )
272 functions
->ReadPixels
= tdfx_readpixels_R5G6B5
;
275 functions
->GetBooleanv
= tdfxDDGetBooleanv
;
276 functions
->GetDoublev
= tdfxDDGetDoublev
;
277 functions
->GetFloatv
= tdfxDDGetFloatv
;
278 functions
->GetIntegerv
= tdfxDDGetIntegerv
;
283 * These are here for lack of a better place.
287 FX_grColorMaskv(GLcontext
*ctx
, const GLboolean rgba
[4])
289 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
290 LOCK_HARDWARE(fxMesa
);
291 if (ctx
->Visual
.redBits
== 8) {
293 ASSERT( fxMesa
->Glide
.grColorMaskExt
);
294 fxMesa
->Glide
.grColorMaskExt(rgba
[RCOMP
], rgba
[GCOMP
],
295 rgba
[BCOMP
], rgba
[ACOMP
]);
299 /* we never have an alpha buffer */
300 fxMesa
->Glide
.grColorMask(rgba
[RCOMP
] || rgba
[GCOMP
] || rgba
[BCOMP
],
303 UNLOCK_HARDWARE(fxMesa
);
307 FX_grColorMaskv_NoLock(GLcontext
*ctx
, const GLboolean rgba
[4])
309 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
310 if (ctx
->Visual
.redBits
== 8) {
312 ASSERT( fxMesa
->Glide
.grColorMaskExt
);
313 fxMesa
->Glide
.grColorMaskExt(rgba
[RCOMP
], rgba
[GCOMP
],
314 rgba
[BCOMP
], rgba
[ACOMP
]);
318 /* we never have an alpha buffer */
319 fxMesa
->Glide
.grColorMask(rgba
[RCOMP
] || rgba
[GCOMP
] || rgba
[BCOMP
],