Make GL_ARB_draw_buffers mandatory
[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_vb.h"
39 #include "tdfx_pixels.h"
40
41 #include "utils.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"
48 #endif
49
50
51 #define DRIVER_DATE "20061113"
52
53
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 };
57
58
59
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).
62 * Why?
63 */
64 static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
65 {
66 tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx;
67
68 switch (name) {
69 case GL_RENDERER:
70 {
71 /* The renderer string must be per-context state to handle
72 * multihead correctly.
73 */
74 char *const buffer = fxMesa->rendererString;
75 char hardware[64];
76
77 LOCK_HARDWARE(fxMesa);
78 strncpy(hardware, fxMesa->Glide.grGetString(GR_HARDWARE),
79 sizeof(hardware));
80 hardware[sizeof(hardware) - 1] = '\0';
81 UNLOCK_HARDWARE(fxMesa);
82
83 if ((strncmp(hardware, "Voodoo3", 7) == 0)
84 || (strncmp(hardware, "Voodoo4", 7) == 0)
85 || (strncmp(hardware, "Voodoo5", 7) == 0)) {
86 hardware[7] = '\0';
87 }
88 else if (strncmp(hardware, "Voodoo Banshee", 14) == 0) {
89 strcpy(&hardware[6], "Banshee");
90 }
91 else {
92 /* unexpected result: replace spaces with hyphens */
93 int i;
94 for (i = 0; hardware[i] && (i < sizeof(hardware)); i++) {
95 if (hardware[i] == ' ' || hardware[i] == '\t') {
96 hardware[i] = '-';
97 }
98 }
99 }
100
101 (void) driGetRendererString(buffer, hardware, DRIVER_DATE, 0);
102 return (const GLubyte *) buffer;
103 }
104 case GL_VENDOR:
105 return (const GLubyte *)"VA Linux Systems, Inc.";
106 default:
107 return NULL;
108 }
109 }
110
111
112 static void
113 tdfxBeginQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
114 {
115 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
116
117 (void) q;
118
119 if (target == GL_SAMPLES_PASSED_ARB) {
120 LOCK_HARDWARE(fxMesa);
121 fxMesa->Glide.grFinish();
122 fxMesa->Glide.grReset(GR_STATS_PIXELS);
123 UNLOCK_HARDWARE(fxMesa);
124 }
125 }
126
127
128 static void
129 tdfxEndQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
130 {
131 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
132 FxI32 total_pixels;
133 FxI32 z_fail_pixels;
134
135
136 if (target == GL_SAMPLES_PASSED_ARB) {
137 LOCK_HARDWARE(fxMesa);
138 fxMesa->Glide.grFinish();
139
140 fxMesa->Glide.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, sizeof(FxI32),
141 &z_fail_pixels);
142 fxMesa->Glide.grGet(GR_STATS_PIXELS_IN, sizeof(FxI32), &total_pixels);
143
144 q->Result = total_pixels - z_fail_pixels;
145
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.
149 */
150 if (q->Result < 0) {
151 q->Result = 0;
152 }
153
154 q->Ready = GL_TRUE;
155
156 UNLOCK_HARDWARE(fxMesa);
157 }
158 }
159
160
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))
166
167 void tdfxDDInitDriverFuncs( const __GLcontextModes *visual,
168 struct dd_function_table *functions )
169 {
170 if ( MESA_VERBOSE & VERBOSE_DRIVER ) {
171 fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ );
172 }
173
174 functions->GetString = tdfxDDGetString;
175 functions->BeginQuery = tdfxBeginQuery;
176 functions->EndQuery = tdfxEndQuery;
177
178 /* Accelerated paths
179 */
180 if ( VISUAL_EQUALS_RGBA(visual, 8, 8, 8, 8) )
181 {
182 functions->DrawPixels = tdfx_drawpixels_R8G8B8A8;
183 functions->ReadPixels = tdfx_readpixels_R8G8B8A8;
184 }
185 else if ( VISUAL_EQUALS_RGBA(visual, 5, 6, 5, 0) )
186 {
187 functions->ReadPixels = tdfx_readpixels_R5G6B5;
188 }
189 }
190
191
192 /*
193 * These are here for lack of a better place.
194 */
195
196 void
197 FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4])
198 {
199 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
200 LOCK_HARDWARE(fxMesa);
201 if (ctx->Visual.redBits == 8) {
202 /* 32bpp mode */
203 ASSERT( fxMesa->Glide.grColorMaskExt );
204 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
205 rgba[BCOMP], rgba[ACOMP]);
206 }
207 else {
208 /* 16 bpp mode */
209 /* we never have an alpha buffer */
210 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
211 GL_FALSE);
212 }
213 UNLOCK_HARDWARE(fxMesa);
214 }
215
216 void
217 FX_grColorMaskv_NoLock(GLcontext *ctx, const GLboolean rgba[4])
218 {
219 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
220 if (ctx->Visual.redBits == 8) {
221 /* 32bpp mode */
222 ASSERT( fxMesa->Glide.grColorMaskExt );
223 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
224 rgba[BCOMP], rgba[ACOMP]);
225 }
226 else {
227 /* 16 bpp mode */
228 /* we never have an alpha buffer */
229 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
230 GL_FALSE);
231 }
232 }