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
29 * Device driver interface functions for 3Dfx based cards.
31 * \author Gareth Hughes <gareth@valinux.com> (Original rewrite 29 Sep - 1 Oct 2000)
32 * \author Brian Paul <brianp@valinux.com>
35 #include "tdfx_context.h"
37 #include "tdfx_lock.h"
39 #include "tdfx_pixels.h"
42 #include "main/context.h"
43 #include "main/enums.h"
44 #include "main/framebuffer.h"
45 #include "swrast/swrast.h"
46 #if defined(USE_X86_ASM)
47 #include "x86/common_x86_asm.h"
51 #define DRIVER_DATE "20061113"
54 /* These are used in calls to FX_grColorMaskv() */
55 const GLboolean false4
[4] = { GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
};
56 const GLboolean true4
[4] = { GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
};
60 /* KW: Put the word Mesa in the render string because quakeworld
61 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
64 static const GLubyte
*tdfxDDGetString( GLcontext
*ctx
, GLenum name
)
66 tdfxContextPtr fxMesa
= (tdfxContextPtr
) ctx
->DriverCtx
;
71 /* The renderer string must be per-context state to handle
72 * multihead correctly.
74 char *const buffer
= fxMesa
->rendererString
;
77 LOCK_HARDWARE(fxMesa
);
78 strncpy(hardware
, fxMesa
->Glide
.grGetString(GR_HARDWARE
),
80 hardware
[sizeof(hardware
) - 1] = '\0';
81 UNLOCK_HARDWARE(fxMesa
);
83 if ((strncmp(hardware
, "Voodoo3", 7) == 0)
84 || (strncmp(hardware
, "Voodoo4", 7) == 0)
85 || (strncmp(hardware
, "Voodoo5", 7) == 0)) {
88 else if (strncmp(hardware
, "Voodoo Banshee", 14) == 0) {
89 strcpy(&hardware
[6], "Banshee");
92 /* unexpected result: replace spaces with hyphens */
94 for (i
= 0; i
< sizeof(hardware
) && hardware
[i
]; i
++) {
95 if (hardware
[i
] == ' ' || hardware
[i
] == '\t') {
101 (void) driGetRendererString(buffer
, hardware
, DRIVER_DATE
, 0);
102 return (const GLubyte
*) buffer
;
105 return (const GLubyte
*)"VA Linux Systems, Inc.";
113 tdfxBeginQuery(GLcontext
*ctx
, struct gl_query_object
*q
)
115 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
119 if (q
->Target
== GL_SAMPLES_PASSED_ARB
) {
120 LOCK_HARDWARE(fxMesa
);
121 fxMesa
->Glide
.grFinish();
122 fxMesa
->Glide
.grReset(GR_STATS_PIXELS
);
123 UNLOCK_HARDWARE(fxMesa
);
129 tdfxEndQuery(GLcontext
*ctx
, struct gl_query_object
*q
)
131 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
136 if (q
->Target
== GL_SAMPLES_PASSED_ARB
) {
137 LOCK_HARDWARE(fxMesa
);
138 fxMesa
->Glide
.grFinish();
140 fxMesa
->Glide
.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL
, sizeof(FxI32
),
142 fxMesa
->Glide
.grGet(GR_STATS_PIXELS_IN
, sizeof(FxI32
), &total_pixels
);
144 q
->Result
= total_pixels
- z_fail_pixels
;
146 /* Apparently, people have seen z_fail_pixels > total_pixels under
147 * some conditions on some 3Dfx hardware. The occlusion query spec
148 * requires that we clamp to 0.
156 UNLOCK_HARDWARE(fxMesa
);
161 #define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \
162 ((vis->redBits == r) && \
163 (vis->greenBits == g) && \
164 (vis->blueBits == b) && \
165 (vis->alphaBits == a))
167 void tdfxDDInitDriverFuncs( const __GLcontextModes
*visual
,
168 struct dd_function_table
*functions
)
170 if ( MESA_VERBOSE
& VERBOSE_DRIVER
) {
171 fprintf( stderr
, "tdfx: %s()\n", __FUNCTION__
);
174 functions
->GetString
= tdfxDDGetString
;
175 functions
->BeginQuery
= tdfxBeginQuery
;
176 functions
->EndQuery
= tdfxEndQuery
;
180 if ( VISUAL_EQUALS_RGBA(visual
, 8, 8, 8, 8) )
182 functions
->DrawPixels
= tdfx_drawpixels_R8G8B8A8
;
183 functions
->ReadPixels
= tdfx_readpixels_R8G8B8A8
;
185 else if ( VISUAL_EQUALS_RGBA(visual
, 5, 6, 5, 0) )
187 functions
->ReadPixels
= tdfx_readpixels_R5G6B5
;
193 * These are here for lack of a better place.
197 FX_grColorMaskv(GLcontext
*ctx
, const GLboolean rgba
[4])
199 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
200 LOCK_HARDWARE(fxMesa
);
201 if (ctx
->Visual
.redBits
== 8) {
203 ASSERT( fxMesa
->Glide
.grColorMaskExt
);
204 fxMesa
->Glide
.grColorMaskExt(rgba
[RCOMP
], rgba
[GCOMP
],
205 rgba
[BCOMP
], rgba
[ACOMP
]);
209 /* we never have an alpha buffer */
210 fxMesa
->Glide
.grColorMask(rgba
[RCOMP
] || rgba
[GCOMP
] || rgba
[BCOMP
],
213 UNLOCK_HARDWARE(fxMesa
);
217 FX_grColorMaskv_NoLock(GLcontext
*ctx
, const GLboolean rgba
[4])
219 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
220 if (ctx
->Visual
.redBits
== 8) {
222 ASSERT( fxMesa
->Glide
.grColorMaskExt
);
223 fxMesa
->Glide
.grColorMaskExt(rgba
[RCOMP
], rgba
[GCOMP
],
224 rgba
[BCOMP
], rgba
[ACOMP
]);
228 /* we never have an alpha buffer */
229 fxMesa
->Glide
.grColorMask(rgba
[RCOMP
] || rgba
[GCOMP
] || rgba
[BCOMP
],