2 * Copyright 2001 by Alan Hourihane.
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.
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.
22 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
24 * 3DLabs Gamma driver.
27 #include "gammacontext.h"
29 #include "swrast/swrast.h"
30 #include "swrast_setup/swrast_setup.h"
34 #include "tnl/t_pipeline.h"
36 #include "drivers/common/driverfuncs.h"
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"
46 #include "main/simple_list.h"
51 #include "gamma_tris.h"
53 extern const struct tnl_pipeline_stage _gamma_render_stage
;
55 static const struct tnl_pipeline_stage
*gamma_pipeline
[] = {
56 &_tnl_vertex_transform_stage
,
57 &_tnl_normal_transform_stage
,
59 &_tnl_fog_coordinate_stage
,
61 &_tnl_texture_transform_stage
,
62 /* REMOVE: point attenuation stage */
64 &_gamma_render_stage
, /* ADD: unclipped rastersetup-to-dma */
70 GLboolean
gammaCreateContext( const __GLcontextModes
*glVisual
,
71 __DRIcontextPrivate
*driContextPriv
,
72 void *sharedContextPrivate
)
74 GLcontext
*ctx
, *shareCtx
;
75 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
76 gammaContextPtr gmesa
;
77 gammaScreenPtr gammascrn
;
78 GLINTSAREADRIPtr saPriv
=(GLINTSAREADRIPtr
)(((char*)sPriv
->pSAREA
)+
80 struct dd_function_table functions
;
82 gmesa
= (gammaContextPtr
) CALLOC( sizeof(*gmesa
) );
86 /* Init default driver functions then plug in our gamma-specific functions
87 * (the texture functions are especially important)
89 _mesa_init_driver_functions( &functions
);
90 gammaDDInitTextureFuncs( &functions
);
92 /* Allocate the Mesa context */
93 if (sharedContextPrivate
)
94 shareCtx
= ((gammaContextPtr
) sharedContextPrivate
)->glCtx
;
98 gmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
99 &functions
, (void *) gmesa
);
105 gmesa
->driContext
= driContextPriv
;
106 gmesa
->driScreen
= sPriv
;
107 gmesa
->driDrawable
= NULL
; /* Set by XMesaMakeCurrent */
109 gmesa
->hHWContext
= driContextPriv
->hHWContext
;
110 gmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
111 gmesa
->driFd
= sPriv
->fd
;
112 gmesa
->sarea
= saPriv
;
114 gammascrn
= gmesa
->gammaScreen
= (gammaScreenPtr
)(sPriv
->private);
118 ctx
->Const
.MaxTextureLevels
= GAMMA_TEX_MAXLEVELS
;
119 ctx
->Const
.MaxTextureUnits
= 1; /* Permedia 3 */
120 ctx
->Const
.MaxTextureImageUnits
= 1;
121 ctx
->Const
.MaxTextureCoordUnits
= 1;
123 ctx
->Const
.MinLineWidth
= 0.0;
124 ctx
->Const
.MaxLineWidth
= 255.0;
126 ctx
->Const
.MinLineWidthAA
= 0.0;
127 ctx
->Const
.MaxLineWidthAA
= 65536.0;
129 ctx
->Const
.MinPointSize
= 0.0;
130 ctx
->Const
.MaxPointSize
= 255.0;
132 ctx
->Const
.MinPointSizeAA
= 0.5; /* 4x4 quality mode */
133 ctx
->Const
.MaxPointSizeAA
= 16.0;
134 ctx
->Const
.PointSizeGranularity
= 0.25;
136 gmesa
->texHeap
= mmInit( 0, gmesa
->gammaScreen
->textureSize
);
138 make_empty_list(&gmesa
->TexObjList
);
139 make_empty_list(&gmesa
->SwappedOut
);
141 gmesa
->CurrentTexObj
[0] = 0;
142 gmesa
->CurrentTexObj
[1] = 0; /* Permedia 3, second texture */
144 gmesa
->RenderIndex
= ~0;
147 /* Initialize the software rasterizer and helper modules.
149 _swrast_CreateContext( ctx
);
150 _vbo_CreateContext( ctx
);
151 _tnl_CreateContext( ctx
);
152 _swsetup_CreateContext( ctx
);
154 /* Install the customized pipeline:
156 _tnl_destroy_pipeline( ctx
);
157 _tnl_install_pipeline( ctx
, gamma_pipeline
);
159 /* Configure swrast & TNL to match hardware characteristics:
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
);
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
);
175 gammaInitTextureObjects( ctx
);
177 driContextPriv
->driverPrivate
= (void *)gmesa
;
179 GET_FIRST_DMA(gmesa
->driFd
, gmesa
->hHWContext
,
180 1, &gmesa
->bufIndex
, &gmesa
->bufSize
,
181 &gmesa
->buf
, &gmesa
->bufCount
, gammascrn
);
184 GET_FIRST_DMA(gmesa
->driFd
, gmesa
->hHWContext
,
185 1, &gmesa
->WCbufIndex
, &gmesa
->WCbufSize
,
186 &gmesa
->WCbuf
, &gmesa
->WCbufCount
, gammascrn
);
189 switch (glVisual
->depthBits
) {
191 gmesa
->DeltaMode
= DM_Depth16
;
192 gmesa
->depth_scale
= 1.0f
/ 0xffff;
195 gmesa
->DeltaMode
= DM_Depth24
;
196 gmesa
->depth_scale
= 1.0f
/ 0xffffff;
199 gmesa
->DeltaMode
= DM_Depth32
;
200 gmesa
->depth_scale
= 1.0f
/ 0xffffffff;
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);
211 gmesa
->EnabledFlags
= GAMMA_FRONT_BUFFER
;
212 gmesa
->EnabledFlags
|= (glVisual
->doubleBufferMode
? GAMMA_BACK_BUFFER
: 0);
215 if (gmesa
->Flags
& GAMMA_BACK_BUFFER
) {
216 gmesa
->readOffset
= gmesa
->drawOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
218 gmesa
->readOffset
= gmesa
->drawOffset
= 0;
221 gammaInitHW( gmesa
);
223 driContextPriv
->driverPrivate
= (void *)gmesa
;