Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_context.c
1 /*
2 * Copyright 2001 by Alan Hourihane.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
13 *
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
23 *
24 * 3DLabs Gamma driver.
25 *
26 */
27 #include "gammacontext.h"
28
29 #include "swrast/swrast.h"
30 #include "swrast_setup/swrast_setup.h"
31 #include "vbo/vbo.h"
32
33 #include "tnl/tnl.h"
34 #include "tnl/t_pipeline.h"
35
36 #include "drivers/common/driverfuncs.h"
37
38 #include "main/context.h"
39 #include "main/simple_list.h"
40 #include "main/imports.h"
41 #include "main/matrix.h"
42 #include "main/extensions.h"
43 #if defined(USE_X86_ASM)
44 #include "x86/common_x86_asm.h"
45 #endif
46 #include "main/simple_list.h"
47 #include "main/mm.h"
48
49
50 #include "gamma_vb.h"
51 #include "gamma_tris.h"
52
53 extern const struct tnl_pipeline_stage _gamma_render_stage;
54
55 static const struct tnl_pipeline_stage *gamma_pipeline[] = {
56 &_tnl_vertex_transform_stage,
57 &_tnl_normal_transform_stage,
58 &_tnl_lighting_stage,
59 &_tnl_fog_coordinate_stage,
60 &_tnl_texgen_stage,
61 &_tnl_texture_transform_stage,
62 /* REMOVE: point attenuation stage */
63 #if 1
64 &_gamma_render_stage, /* ADD: unclipped rastersetup-to-dma */
65 #endif
66 &_tnl_render_stage,
67 0,
68 };
69
70 GLboolean gammaCreateContext( const __GLcontextModes *glVisual,
71 __DRIcontextPrivate *driContextPriv,
72 void *sharedContextPrivate)
73 {
74 GLcontext *ctx, *shareCtx;
75 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
76 gammaContextPtr gmesa;
77 gammaScreenPtr gammascrn;
78 GLINTSAREADRIPtr saPriv=(GLINTSAREADRIPtr)(((char*)sPriv->pSAREA)+
79 sizeof(drm_sarea_t));
80 struct dd_function_table functions;
81
82 gmesa = (gammaContextPtr) CALLOC( sizeof(*gmesa) );
83 if (!gmesa)
84 return GL_FALSE;
85
86 /* Init default driver functions then plug in our gamma-specific functions
87 * (the texture functions are especially important)
88 */
89 _mesa_init_driver_functions( &functions );
90 gammaDDInitTextureFuncs( &functions );
91
92 /* Allocate the Mesa context */
93 if (sharedContextPrivate)
94 shareCtx = ((gammaContextPtr) sharedContextPrivate)->glCtx;
95 else
96 shareCtx = NULL;
97
98 gmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
99 &functions, (void *) gmesa);
100 if (!gmesa->glCtx) {
101 FREE(gmesa);
102 return GL_FALSE;
103 }
104
105 gmesa->driContext = driContextPriv;
106 gmesa->driScreen = sPriv;
107 gmesa->driDrawable = NULL; /* Set by XMesaMakeCurrent */
108
109 gmesa->hHWContext = driContextPriv->hHWContext;
110 gmesa->driHwLock = &sPriv->pSAREA->lock;
111 gmesa->driFd = sPriv->fd;
112 gmesa->sarea = saPriv;
113
114 gammascrn = gmesa->gammaScreen = (gammaScreenPtr)(sPriv->private);
115
116 ctx = gmesa->glCtx;
117
118 ctx->Const.MaxTextureLevels = GAMMA_TEX_MAXLEVELS;
119 ctx->Const.MaxTextureUnits = 1; /* Permedia 3 */
120 ctx->Const.MaxTextureImageUnits = 1;
121 ctx->Const.MaxTextureCoordUnits = 1;
122
123 ctx->Const.MinLineWidth = 0.0;
124 ctx->Const.MaxLineWidth = 255.0;
125
126 ctx->Const.MinLineWidthAA = 0.0;
127 ctx->Const.MaxLineWidthAA = 65536.0;
128
129 ctx->Const.MinPointSize = 0.0;
130 ctx->Const.MaxPointSize = 255.0;
131
132 ctx->Const.MinPointSizeAA = 0.5; /* 4x4 quality mode */
133 ctx->Const.MaxPointSizeAA = 16.0;
134 ctx->Const.PointSizeGranularity = 0.25;
135
136 gmesa->texHeap = mmInit( 0, gmesa->gammaScreen->textureSize );
137
138 make_empty_list(&gmesa->TexObjList);
139 make_empty_list(&gmesa->SwappedOut);
140
141 gmesa->CurrentTexObj[0] = 0;
142 gmesa->CurrentTexObj[1] = 0; /* Permedia 3, second texture */
143
144 gmesa->RenderIndex = ~0;
145
146
147 /* Initialize the software rasterizer and helper modules.
148 */
149 _swrast_CreateContext( ctx );
150 _vbo_CreateContext( ctx );
151 _tnl_CreateContext( ctx );
152 _swsetup_CreateContext( ctx );
153
154 /* Install the customized pipeline:
155 */
156 _tnl_destroy_pipeline( ctx );
157 _tnl_install_pipeline( ctx, gamma_pipeline );
158
159 /* Configure swrast & TNL to match hardware characteristics:
160 */
161 _swrast_allow_pixel_fog( ctx, GL_FALSE );
162 _swrast_allow_vertex_fog( ctx, GL_TRUE );
163 _tnl_allow_pixel_fog( ctx, GL_FALSE );
164 _tnl_allow_vertex_fog( ctx, GL_TRUE );
165
166 gammaInitVB( ctx );
167 gammaDDInitExtensions( ctx );
168 /* XXX these should really go right after _mesa_init_driver_functions() */
169 gammaDDInitDriverFuncs( ctx );
170 gammaDDInitStateFuncs( ctx );
171 gammaDDInitSpanFuncs( ctx );
172 gammaDDInitTriFuncs( ctx );
173 gammaDDInitState( gmesa );
174
175 gammaInitTextureObjects( ctx );
176
177 driContextPriv->driverPrivate = (void *)gmesa;
178
179 GET_FIRST_DMA(gmesa->driFd, gmesa->hHWContext,
180 1, &gmesa->bufIndex, &gmesa->bufSize,
181 &gmesa->buf, &gmesa->bufCount, gammascrn);
182
183 #ifdef DO_VALIDATE
184 GET_FIRST_DMA(gmesa->driFd, gmesa->hHWContext,
185 1, &gmesa->WCbufIndex, &gmesa->WCbufSize,
186 &gmesa->WCbuf, &gmesa->WCbufCount, gammascrn);
187 #endif
188
189 switch (glVisual->depthBits) {
190 case 16:
191 gmesa->DeltaMode = DM_Depth16;
192 gmesa->depth_scale = 1.0f / 0xffff;
193 break;
194 case 24:
195 gmesa->DeltaMode = DM_Depth24;
196 gmesa->depth_scale = 1.0f / 0xffffff;
197 break;
198 case 32:
199 gmesa->DeltaMode = DM_Depth32;
200 gmesa->depth_scale = 1.0f / 0xffffffff;
201 break;
202 default:
203 break;
204 }
205
206 gmesa->DepthSize = glVisual->depthBits;
207 gmesa->Flags = GAMMA_FRONT_BUFFER;
208 gmesa->Flags |= (glVisual->doubleBufferMode ? GAMMA_BACK_BUFFER : 0);
209 gmesa->Flags |= (gmesa->DepthSize > 0 ? GAMMA_DEPTH_BUFFER : 0);
210
211 gmesa->EnabledFlags = GAMMA_FRONT_BUFFER;
212 gmesa->EnabledFlags |= (glVisual->doubleBufferMode ? GAMMA_BACK_BUFFER : 0);
213
214
215 if (gmesa->Flags & GAMMA_BACK_BUFFER) {
216 gmesa->readOffset = gmesa->drawOffset = gmesa->driScreen->fbHeight * gmesa->driScreen->fbWidth * gmesa->gammaScreen->cpp;
217 } else {
218 gmesa->readOffset = gmesa->drawOffset = 0;
219 }
220
221 gammaInitHW( gmesa );
222
223 driContextPriv->driverPrivate = (void *)gmesa;
224
225 return GL_TRUE;
226 }