Merge branch 'mesa_7_7_branch'
[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
27 /**
28 * \file tdfx_dd.c
29 * Device driver interface functions for 3Dfx based cards.
30 *
31 * \author Gareth Hughes <gareth@valinux.com> (Original rewrite 29 Sep - 1 Oct 2000)
32 * \author Brian Paul <brianp@valinux.com>
33 */
34
35 #include "tdfx_context.h"
36 #include "tdfx_dd.h"
37 #include "tdfx_lock.h"
38 #include "tdfx_pixels.h"
39
40 #include "utils.h"
41 #include "main/context.h"
42
43
44 #define DRIVER_DATE "20061113"
45
46
47 /* These are used in calls to FX_grColorMaskv() */
48 const GLboolean false4[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
49 const GLboolean true4[4] = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
50
51
52
53 /* KW: Put the word Mesa in the render string because quakeworld
54 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
55 * Why?
56 */
57 static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
58 {
59 tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx;
60
61 switch (name) {
62 case GL_RENDERER:
63 {
64 /* The renderer string must be per-context state to handle
65 * multihead correctly.
66 */
67 char *const buffer = fxMesa->rendererString;
68 char hardware[64];
69
70 LOCK_HARDWARE(fxMesa);
71 strncpy(hardware, fxMesa->Glide.grGetString(GR_HARDWARE),
72 sizeof(hardware));
73 hardware[sizeof(hardware) - 1] = '\0';
74 UNLOCK_HARDWARE(fxMesa);
75
76 if ((strncmp(hardware, "Voodoo3", 7) == 0)
77 || (strncmp(hardware, "Voodoo4", 7) == 0)
78 || (strncmp(hardware, "Voodoo5", 7) == 0)) {
79 hardware[7] = '\0';
80 }
81 else if (strncmp(hardware, "Voodoo Banshee", 14) == 0) {
82 strcpy(&hardware[6], "Banshee");
83 }
84 else {
85 /* unexpected result: replace spaces with hyphens */
86 int i;
87 for (i = 0; i < sizeof(hardware) && hardware[i]; i++) {
88 if (hardware[i] == ' ' || hardware[i] == '\t') {
89 hardware[i] = '-';
90 }
91 }
92 }
93
94 (void) driGetRendererString(buffer, hardware, DRIVER_DATE, 0);
95 return (const GLubyte *) buffer;
96 }
97 case GL_VENDOR:
98 return (const GLubyte *)"VA Linux Systems, Inc.";
99 default:
100 return NULL;
101 }
102 }
103
104
105 static void
106 tdfxBeginQuery(GLcontext *ctx, struct gl_query_object *q)
107 {
108 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
109
110 (void) q;
111
112 if (q->Target == GL_SAMPLES_PASSED_ARB) {
113 LOCK_HARDWARE(fxMesa);
114 fxMesa->Glide.grFinish();
115 fxMesa->Glide.grReset(GR_STATS_PIXELS);
116 UNLOCK_HARDWARE(fxMesa);
117 }
118 }
119
120
121 static void
122 tdfxEndQuery(GLcontext *ctx, struct gl_query_object *q)
123 {
124 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
125 FxI32 total_pixels;
126 FxI32 z_fail_pixels;
127
128
129 if (q->Target == GL_SAMPLES_PASSED_ARB) {
130 LOCK_HARDWARE(fxMesa);
131 fxMesa->Glide.grFinish();
132
133 fxMesa->Glide.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, sizeof(FxI32),
134 &z_fail_pixels);
135 fxMesa->Glide.grGet(GR_STATS_PIXELS_IN, sizeof(FxI32), &total_pixels);
136
137 q->Result = total_pixels - z_fail_pixels;
138
139 /* Apparently, people have seen z_fail_pixels > total_pixels under
140 * some conditions on some 3Dfx hardware. The occlusion query spec
141 * requires that we clamp to 0.
142 */
143 if (q->Result < 0) {
144 q->Result = 0;
145 }
146
147 q->Ready = GL_TRUE;
148
149 UNLOCK_HARDWARE(fxMesa);
150 }
151 }
152
153
154 #define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \
155 ((vis->redBits == r) && \
156 (vis->greenBits == g) && \
157 (vis->blueBits == b) && \
158 (vis->alphaBits == a))
159
160 void tdfxDDInitDriverFuncs( const __GLcontextModes *visual,
161 struct dd_function_table *functions )
162 {
163 if ( MESA_VERBOSE & VERBOSE_DRIVER ) {
164 fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ );
165 }
166
167 functions->GetString = tdfxDDGetString;
168 functions->BeginQuery = tdfxBeginQuery;
169 functions->EndQuery = tdfxEndQuery;
170
171 /* Accelerated paths
172 */
173 if ( VISUAL_EQUALS_RGBA(visual, 8, 8, 8, 8) )
174 {
175 functions->DrawPixels = tdfx_drawpixels_R8G8B8A8;
176 functions->ReadPixels = tdfx_readpixels_R8G8B8A8;
177 }
178 else if ( VISUAL_EQUALS_RGBA(visual, 5, 6, 5, 0) )
179 {
180 functions->ReadPixels = tdfx_readpixels_R5G6B5;
181 }
182 }
183
184
185 /*
186 * These are here for lack of a better place.
187 */
188
189 void
190 FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4])
191 {
192 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
193 LOCK_HARDWARE(fxMesa);
194 if (ctx->Visual.redBits == 8) {
195 /* 32bpp mode */
196 ASSERT( fxMesa->Glide.grColorMaskExt );
197 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
198 rgba[BCOMP], rgba[ACOMP]);
199 }
200 else {
201 /* 16 bpp mode */
202 /* we never have an alpha buffer */
203 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
204 GL_FALSE);
205 }
206 UNLOCK_HARDWARE(fxMesa);
207 }
208
209 void
210 FX_grColorMaskv_NoLock(GLcontext *ctx, const GLboolean rgba[4])
211 {
212 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
213 if (ctx->Visual.redBits == 8) {
214 /* 32bpp mode */
215 ASSERT( fxMesa->Glide.grColorMaskExt );
216 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
217 rgba[BCOMP], rgba[ACOMP]);
218 }
219 else {
220 /* 16 bpp mode */
221 /* we never have an alpha buffer */
222 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
223 GL_FALSE);
224 }
225 }