mga driver, brought over by Jon Smirl
[mesa.git] / src / mesa / drivers / dri / mga / mgadd.c
1 /*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27 /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgadd.c,v 1.14 2002/10/30 12:51:35 alanh Exp $ */
28
29
30 #include "mtypes.h"
31
32
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 #include "mm.h"
37 #include "mgacontext.h"
38 #include "mgadd.h"
39 #include "mgastate.h"
40 #include "mgaspan.h"
41 #include "mgatex.h"
42 #include "mgatris.h"
43 #include "mgavb.h"
44 #include "mga_xmesa.h"
45 #include "extensions.h"
46 #if defined(USE_X86_ASM)
47 #include "X86/common_x86_asm.h"
48 #endif
49
50 #define MGA_DATE "20020221"
51
52
53 /***************************************
54 * Mesa's Driver Functions
55 ***************************************/
56
57
58 static const GLubyte *mgaDDGetString( GLcontext *ctx, GLenum name )
59 {
60 mgaContextPtr mmesa = MGA_CONTEXT( ctx );
61 static char buffer[128];
62
63 switch ( name ) {
64 case GL_VENDOR:
65 return (GLubyte *) "VA Linux Systems Inc.";
66
67 case GL_RENDERER:
68 sprintf( buffer, "Mesa DRI %s " MGA_DATE,
69 MGA_IS_G400(mmesa) ? "G400" :
70 MGA_IS_G200(mmesa) ? "G200" : "MGA" );
71
72 /* Append any AGP-specific information.
73 */
74 switch ( mmesa->mgaScreen->agpMode ) {
75 case 1:
76 strncat( buffer, " AGP 1x", 7 );
77 break;
78 case 2:
79 strncat( buffer, " AGP 2x", 7 );
80 break;
81 case 4:
82 strncat( buffer, " AGP 4x", 7 );
83 break;
84 }
85
86 /* Append any CPU-specific information.
87 */
88 #ifdef USE_X86_ASM
89 if ( _mesa_x86_cpu_features ) {
90 strncat( buffer, " x86", 4 );
91 }
92 #endif
93 #ifdef USE_MMX_ASM
94 if ( cpu_has_mmx ) {
95 strncat( buffer, "/MMX", 4 );
96 }
97 #endif
98 #ifdef USE_3DNOW_ASM
99 if ( cpu_has_3dnow ) {
100 strncat( buffer, "/3DNow!", 7 );
101 }
102 #endif
103 #ifdef USE_SSE_ASM
104 if ( cpu_has_xmm ) {
105 strncat( buffer, "/SSE", 4 );
106 }
107 #endif
108 return (GLubyte *)buffer;
109
110 default:
111 return NULL;
112 }
113 }
114
115
116
117 static void mgaBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height)
118 {
119 GET_CURRENT_CONTEXT(ctx);
120 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
121
122 /* Need to lock to make sure the driDrawable is uptodate. This
123 * information is used to resize Mesa's software buffers, so it has
124 * to be correct.
125 */
126 LOCK_HARDWARE( mmesa );
127 *width = mmesa->driDrawable->w;
128 *height = mmesa->driDrawable->h;
129 UNLOCK_HARDWARE( mmesa );
130 }
131
132 void mgaDDExtensionsInit( GLcontext *ctx )
133 {
134 /* paletted_textures currently doesn't work, but we could fix them later */
135 /*
136 _mesa_enable_extension( ctx, "GL_EXT_shared_texture_palette" );
137 _mesa_enable_extension( ctx, "GL_EXT_paletted_texture" );
138 */
139
140 _mesa_enable_extension( ctx, "GL_ARB_texture_compression" );
141 _mesa_enable_extension( ctx, "GL_ARB_multisample" );
142
143 _mesa_enable_extension( ctx, "GL_SGIS_generate_mipmap" );
144
145 /* Turn on multitexture and texenv_add for the G400.
146 */
147 if (MGA_IS_G400(MGA_CONTEXT(ctx))) {
148 _mesa_enable_extension( ctx, "GL_ARB_multitexture" );
149 _mesa_enable_extension( ctx, "GL_ARB_texture_env_add" );
150
151 _mesa_enable_extension( ctx, "GL_EXT_texture_env_add" );
152
153 #if defined (MESA_packed_depth_stencil)
154 _mesa_enable_extension( ctx, "GL_MESA_packed_depth_stencil" );
155 #endif
156
157 #if defined (MESA_experimetal_agp_allocator)
158 if (!getenv("MGA_DISABLE_AGP_ALLOCATOR"))
159 _mesa_enable_extension( ctx, "GL_MESA_experimental_agp_allocator" );
160 #endif
161 }
162 }
163
164
165
166 void mgaDDInitDriverFuncs( GLcontext *ctx )
167 {
168 ctx->Driver.GetBufferSize = mgaBufferSize;
169 ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
170 ctx->Driver.GetString = mgaDDGetString;
171 }