3dbd24d49b7ccb412f70b070fc14249f48d8506c
[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 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.c,v 1.10 2002/10/30 12:52:00 alanh Exp $ */
27
28 /*
29 * Original rewrite:
30 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
31 *
32 * Authors:
33 * Gareth Hughes <gareth@valinux.com>
34 * Brian Paul <brianp@valinux.com>
35 *
36 */
37
38 #include "tdfx_context.h"
39 #include "tdfx_dd.h"
40 #include "tdfx_lock.h"
41 #include "tdfx_vb.h"
42 #include "tdfx_pixels.h"
43
44 #include "context.h"
45 #include "enums.h"
46 #include "framebuffer.h"
47 #include "swrast/swrast.h"
48 #if defined(USE_X86_ASM)
49 #include "x86/common_x86_asm.h"
50 #endif
51
52
53 #define TDFX_DATE "20040719"
54
55
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 };
59
60
61
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).
64 * Why?
65 */
66 static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
67 {
68 tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx;
69
70 switch ( name ) {
71 case GL_RENDERER:
72 {
73 /* The renderer string must be per-context state to handle
74 * multihead correctly.
75 */
76 char *buffer = fxMesa->rendererString;
77 char hardware[100];
78
79 LOCK_HARDWARE(fxMesa);
80 strcpy( hardware, fxMesa->Glide.grGetString(GR_HARDWARE) );
81 UNLOCK_HARDWARE(fxMesa);
82
83 strcpy( buffer, "Mesa DRI " );
84 strcat( buffer, TDFX_DATE );
85 strcat( buffer, " " );
86
87 if ( strcmp( hardware, "Voodoo3 (tm)" ) == 0 ) {
88 strcat( buffer, "Voodoo3" );
89 }
90 else if ( strcmp( hardware, "Voodoo Banshee (tm)" ) == 0 ) {
91 strcat( buffer, "VoodooBanshee" );
92 }
93 else if ( strcmp( hardware, "Voodoo4 (tm)" ) == 0 ) {
94 strcat( buffer, "Voodoo4" );
95 }
96 else if ( strcmp( hardware, "Voodoo5 (tm)" ) == 0 ) {
97 strcat( buffer, "Voodoo5" );
98 }
99 else {
100 /* unexpected result: replace spaces with hyphens */
101 int i;
102 for ( i = 0 ; hardware[i] && i < 60 ; i++ ) {
103 if ( hardware[i] == ' ' || hardware[i] == '\t' )
104 hardware[i] = '-';
105 }
106 strcat( buffer, hardware );
107 }
108
109 /* Append any CPU-specific information.
110 */
111 #ifdef USE_X86_ASM
112 if ( _mesa_x86_cpu_features ) {
113 strncat( buffer, " x86", 4 );
114 }
115 #endif
116 #ifdef USE_MMX_ASM
117 if ( cpu_has_mmx ) {
118 strncat( buffer, "/MMX", 4 );
119 }
120 #endif
121 #ifdef USE_3DNOW_ASM
122 if ( cpu_has_3dnow ) {
123 strncat( buffer, "/3DNow!", 7 );
124 }
125 #endif
126 #ifdef USE_SSE_ASM
127 if ( cpu_has_xmm ) {
128 strncat( buffer, "/SSE", 4 );
129 }
130 #endif
131 return (const GLubyte *) buffer;
132 }
133 case GL_VENDOR:
134 return (const GLubyte *)"VA Linux Systems, Inc.";
135 default:
136 return NULL;
137 }
138 }
139
140
141 /* Return uptodate buffer size information.
142 */
143 static void tdfxDDGetBufferSize( GLframebuffer *buffer,
144 GLuint *width, GLuint *height )
145 {
146 GET_CURRENT_CONTEXT(ctx);
147 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
148
149 LOCK_HARDWARE( fxMesa );
150 *width = fxMesa->width;
151 *height = fxMesa->height;
152 UNLOCK_HARDWARE( fxMesa );
153 }
154
155
156 #define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \
157 ((vis->redBits == r) && \
158 (vis->greenBits == g) && \
159 (vis->blueBits == b) && \
160 (vis->alphaBits == a))
161
162 void tdfxDDInitDriverFuncs( const __GLcontextModes *visual,
163 struct dd_function_table *functions )
164 {
165 if ( MESA_VERBOSE & VERBOSE_DRIVER ) {
166 fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ );
167 }
168
169 functions->GetString = tdfxDDGetString;
170 functions->GetBufferSize = tdfxDDGetBufferSize;
171 functions->ResizeBuffers = _mesa_resize_framebuffer;
172
173 /* Accelerated paths
174 */
175 if ( VISUAL_EQUALS_RGBA(visual, 8, 8, 8, 8) )
176 {
177 functions->DrawPixels = tdfx_drawpixels_R8G8B8A8;
178 functions->ReadPixels = tdfx_readpixels_R8G8B8A8;
179 }
180 else if ( VISUAL_EQUALS_RGBA(visual, 5, 6, 5, 0) )
181 {
182 functions->ReadPixels = tdfx_readpixels_R5G6B5;
183 }
184 }
185
186
187 /*
188 * These are here for lack of a better place.
189 */
190
191 void
192 FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4])
193 {
194 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
195 LOCK_HARDWARE(fxMesa);
196 if (ctx->Visual.redBits == 8) {
197 /* 32bpp mode */
198 ASSERT( fxMesa->Glide.grColorMaskExt );
199 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
200 rgba[BCOMP], rgba[ACOMP]);
201 }
202 else {
203 /* 16 bpp mode */
204 /* we never have an alpha buffer */
205 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
206 GL_FALSE);
207 }
208 UNLOCK_HARDWARE(fxMesa);
209 }
210
211 void
212 FX_grColorMaskv_NoLock(GLcontext *ctx, const GLboolean rgba[4])
213 {
214 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
215 if (ctx->Visual.redBits == 8) {
216 /* 32bpp mode */
217 ASSERT( fxMesa->Glide.grColorMaskExt );
218 fxMesa->Glide.grColorMaskExt(rgba[RCOMP], rgba[GCOMP],
219 rgba[BCOMP], rgba[ACOMP]);
220 }
221 else {
222 /* 16 bpp mode */
223 /* we never have an alpha buffer */
224 fxMesa->Glide.grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP],
225 GL_FALSE);
226 }
227 }