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 "gamma_context.h"
29 #include "swrast/swrast.h"
30 #include "swrast_setup/swrast_setup.h"
31 #include "array_cache/acache.h"
34 #include "tnl/t_pipeline.h"
37 #include "simple_list.h"
40 #include "extensions.h"
41 #if defined(USE_X86_ASM)
42 #include "x86/common_x86_asm.h"
44 #include "simple_list.h"
49 #include "gamma_tris.h"
51 extern const struct tnl_pipeline_stage _gamma_render_stage
;
53 static const struct tnl_pipeline_stage
*gamma_pipeline
[] = {
54 &_tnl_vertex_transform_stage
,
55 &_tnl_normal_transform_stage
,
57 &_tnl_fog_coordinate_stage
,
59 &_tnl_texture_transform_stage
,
60 /* REMOVE: point attenuation stage */
62 &_gamma_render_stage
, /* ADD: unclipped rastersetup-to-dma */
68 GLboolean
gammaCreateContext( const __GLcontextModes
*glVisual
,
69 __DRIcontextPrivate
*driContextPriv
,
70 void *sharedContextPrivate
)
72 GLcontext
*ctx
, *shareCtx
;
73 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
74 gammaContextPtr gmesa
;
75 gammaScreenPtr gammascrn
;
76 GLINTSAREADRIPtr saPriv
=(GLINTSAREADRIPtr
)(((char*)sPriv
->pSAREA
)+
77 sizeof(XF86DRISAREARec
));
79 gmesa
= (gammaContextPtr
) CALLOC( sizeof(*gmesa
) );
80 if ( !gmesa
) return GL_FALSE
;
82 /* Allocate the Mesa context */
83 if (sharedContextPrivate
)
84 shareCtx
= ((gammaContextPtr
) sharedContextPrivate
)->glCtx
;
88 gmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
, (void *) gmesa
, GL_TRUE
);
94 gmesa
->driContext
= driContextPriv
;
95 gmesa
->driScreen
= sPriv
;
96 gmesa
->driDrawable
= NULL
; /* Set by XMesaMakeCurrent */
98 gmesa
->hHWContext
= driContextPriv
->hHWContext
;
99 gmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
100 gmesa
->driFd
= sPriv
->fd
;
101 gmesa
->sarea
= saPriv
;
103 gammascrn
= gmesa
->gammaScreen
= (gammaScreenPtr
)(sPriv
->private);
107 ctx
->Const
.MaxTextureLevels
= 13; /* 4K by 4K? Is that right? */
108 ctx
->Const
.MaxTextureUnits
= 1; /* Permedia 3 */
110 ctx
->Const
.MinLineWidth
= 0.0;
111 ctx
->Const
.MaxLineWidth
= 255.0;
113 ctx
->Const
.MinLineWidthAA
= 0.0;
114 ctx
->Const
.MaxLineWidthAA
= 65536.0;
116 ctx
->Const
.MinPointSize
= 0.0;
117 ctx
->Const
.MaxPointSize
= 255.0;
119 ctx
->Const
.MinPointSizeAA
= 0.5; /* 4x4 quality mode */
120 ctx
->Const
.MaxPointSizeAA
= 16.0;
121 ctx
->Const
.PointSizeGranularity
= 0.25;
123 gmesa
->texHeap
= mmInit( 0, gmesa
->gammaScreen
->textureSize
);
125 make_empty_list(&gmesa
->TexObjList
);
126 make_empty_list(&gmesa
->SwappedOut
);
128 gmesa
->CurrentTexObj
[0] = 0;
129 gmesa
->CurrentTexObj
[1] = 0; /* Permedia 3, second texture */
131 gmesa
->RenderIndex
= ~0;
134 /* Initialize the software rasterizer and helper modules.
136 _swrast_CreateContext( ctx
);
137 _ac_CreateContext( ctx
);
138 _tnl_CreateContext( ctx
);
139 _swsetup_CreateContext( ctx
);
141 /* Install the customized pipeline:
143 _tnl_destroy_pipeline( ctx
);
144 _tnl_install_pipeline( ctx
, gamma_pipeline
);
146 /* Configure swrast to match hardware characteristics:
148 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
149 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
152 gammaDDInitExtensions( ctx
);
153 gammaDDInitDriverFuncs( ctx
);
154 gammaDDInitStateFuncs( ctx
);
155 gammaDDInitSpanFuncs( ctx
);
156 gammaDDInitTextureFuncs( ctx
);
157 gammaDDInitTriFuncs( ctx
);
158 gammaDDInitState( gmesa
);
160 driContextPriv
->driverPrivate
= (void *)gmesa
;
162 GET_FIRST_DMA(gmesa
->driFd
, gmesa
->hHWContext
,
163 1, &gmesa
->bufIndex
, &gmesa
->bufSize
,
164 &gmesa
->buf
, &gmesa
->bufCount
, gammascrn
);
167 GET_FIRST_DMA(gmesa
->driFd
, gmesa
->hHWContext
,
168 1, &gmesa
->WCbufIndex
, &gmesa
->WCbufSize
,
169 &gmesa
->WCbuf
, &gmesa
->WCbufCount
, gammascrn
);
172 switch (glVisual
->depthBits
) {
174 gmesa
->DeltaMode
= DM_Depth16
;
175 gmesa
->depth_scale
= 1.0f
/ 0xffff;
178 gmesa
->DeltaMode
= DM_Depth24
;
179 gmesa
->depth_scale
= 1.0f
/ 0xffffff;
182 gmesa
->DeltaMode
= DM_Depth32
;
183 gmesa
->depth_scale
= 1.0f
/ 0xffffffff;
189 gmesa
->DepthSize
= glVisual
->depthBits
;
190 gmesa
->Flags
= GAMMA_FRONT_BUFFER
;
191 gmesa
->Flags
|= (glVisual
->doubleBufferMode
? GAMMA_BACK_BUFFER
: 0);
192 gmesa
->Flags
|= (gmesa
->DepthSize
> 0 ? GAMMA_DEPTH_BUFFER
: 0);
194 gmesa
->EnabledFlags
= GAMMA_FRONT_BUFFER
;
195 gmesa
->EnabledFlags
|= (glVisual
->doubleBufferMode
? GAMMA_BACK_BUFFER
: 0);
198 if (gmesa
->Flags
& GAMMA_BACK_BUFFER
) {
199 gmesa
->readOffset
= gmesa
->drawOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
201 gmesa
->readOffset
= gmesa
->drawOffset
= 0;
204 gammaInitHW( gmesa
);
206 driContextPriv
->driverPrivate
= (void *)gmesa
;