2 * Author: Max Lingua <sunmax@libero.it>
5 #include "s3v_context.h"
7 #include "swrast/swrast.h"
8 #include "swrast_setup/swrast_setup.h"
12 #include "tnl/t_pipeline.h"
14 #include "main/context.h"
15 #include "main/simple_list.h"
16 #include "main/matrix.h"
17 #include "main/extensions.h"
18 #if defined(USE_X86_ASM)
19 #include "x86/common_x86_asm.h"
21 #include "main/simple_list.h"
24 #include "drivers/common/driverfuncs.h"
29 extern const struct tnl_pipeline_stage _s3v_render_stage
;
31 static const struct tnl_pipeline_stage
*s3v_pipeline
[] = {
32 &_tnl_vertex_transform_stage
,
33 &_tnl_normal_transform_stage
,
35 &_tnl_fog_coordinate_stage
,
37 &_tnl_texture_transform_stage
,
38 /* REMOVE: point attenuation stage */
40 &_s3v_render_stage
, /* ADD: unclipped rastersetup-to-dma */
47 GLboolean
s3vCreateContext(const __GLcontextModes
*glVisual
,
48 __DRIcontextPrivate
*driContextPriv
,
49 void *sharedContextPrivate
)
51 GLcontext
*ctx
, *shareCtx
;
52 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
55 S3VSAREAPtr saPriv
=(S3VSAREAPtr
)(((char*)sPriv
->pSAREA
) +
57 struct dd_function_table functions
;
59 DEBUG_WHERE(("*** s3vCreateContext ***\n"));
61 vmesa
= (s3vContextPtr
) CALLOC( sizeof(*vmesa
) );
62 if ( !vmesa
) return GL_FALSE
;
64 /* Allocate the Mesa context */
65 if (sharedContextPrivate
)
66 shareCtx
= ((s3vContextPtr
) sharedContextPrivate
)->glCtx
;
70 _mesa_init_driver_functions(&functions
);
72 vmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
, &functions
,
79 vmesa
->driContext
= driContextPriv
;
80 vmesa
->driScreen
= sPriv
;
81 vmesa
->driDrawable
= NULL
; /* Set by XMesaMakeCurrent */
83 vmesa
->hHWContext
= driContextPriv
->hHWContext
;
84 vmesa
->driHwLock
= (drmLock
*)&sPriv
->pSAREA
->lock
;
85 vmesa
->driFd
= sPriv
->fd
;
86 vmesa
->sarea
= saPriv
;
88 s3vScrn
= vmesa
->s3vScreen
= (s3vScreenPtr
)(sPriv
->private);
92 ctx
->Const
.MaxTextureLevels
= 11; /* it is (11-1) -> 1024 * 1024 FIXME */
94 ctx
->Const
.MaxTextureUnits
= 1; /* FIXME: or 2 ? */
98 ctx
->Const
.MinPointSize
= 1.0;
99 ctx
->Const
.MinPointSizeAA
= 1.0;
100 ctx
->Const
.MaxPointSize
= 1.0;
101 ctx
->Const
.MaxPointSizeAA
= 1.0;
105 ctx
->Const
.MinLineWidth
= 1.0;
106 ctx
->Const
.MinLineWidthAA
= 1.0;
107 ctx
->Const
.MaxLineWidth
= 1.0;
108 ctx
->Const
.MaxLineWidthAA
= 1.0;
109 ctx
->Const
.LineWidthGranularity
= 1.0;
111 ctx
->Const
.MaxDrawBuffers
= 1;
113 vmesa
->texHeap
= mmInit( 0, vmesa
->s3vScreen
->textureSize
);
114 DEBUG(("vmesa->s3vScreen->textureSize = 0x%x\n",
115 vmesa
->s3vScreen
->textureSize
));
118 /* mmInit(offset, size); */
120 /* allocates a structure like this:
123 struct mem_block_t *next;
124 struct mem_block_t *heap;
133 make_empty_list(&vmesa
->TexObjList
);
134 make_empty_list(&vmesa
->SwappedOut
);
136 vmesa
->CurrentTexObj
[0] = 0;
137 vmesa
->CurrentTexObj
[1] = 0; /* FIXME */
139 vmesa
->RenderIndex
= ~0;
141 /* Initialize the software rasterizer and helper modules.
143 _swrast_CreateContext( ctx
);
144 _vbo_CreateContext( ctx
);
145 _tnl_CreateContext( ctx
);
146 _swsetup_CreateContext( ctx
);
148 /* Install the customized pipeline:
151 _tnl_destroy_pipeline( ctx
);
152 _tnl_install_pipeline( ctx
, s3v_pipeline
);
154 /* Configure swrast to match hardware characteristics:
157 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
158 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
162 /* 3D lines / gouraud tris */
163 vmesa
->CMD
= ( AUTO_EXEC_ON
| HW_CLIP_ON
| DEST_COL_1555
164 | FOG_OFF
| ALPHA_OFF
| Z_OFF
| Z_UPDATE_OFF
165 | Z_LESS
| TEX_WRAP_ON
| TEX_MODULATE
| LINEAR
166 | TEX_COL_ARGB1555
| CMD_3D
);
168 vmesa
->_alpha
[0] = vmesa
->_alpha
[1] = ALPHA_OFF
;
169 vmesa
->alpha_cmd
= vmesa
->_alpha
[0];
170 vmesa
->_tri
[0] = DO_GOURAUD_TRI
;
171 vmesa
->_tri
[1] = DO_TEX_LIT_TRI
;
172 vmesa
->prim_cmd
= vmesa
->_tri
[0];
174 /* printf("first vmesa->CMD = 0x%x\n", vmesa->CMD); */
176 vmesa
->TexOffset
= vmesa
->s3vScreen
->texOffset
;
179 s3vInitExtensions( ctx
);
180 s3vInitDriverFuncs( ctx
);
181 s3vInitStateFuncs( ctx
);
182 s3vInitSpanFuncs( ctx
);
183 s3vInitTextureFuncs( ctx
);
184 s3vInitTriFuncs( ctx
);
185 s3vInitState( vmesa
);
187 driContextPriv
->driverPrivate
= (void *)vmesa
;
190 vmesa
->bufSize
= S3V_DMA_BUF_SZ
;
192 DEBUG(("vmesa->bufSize = %i\n", vmesa
->bufSize
));
193 DEBUG(("vmesa->bufCount = %i\n", vmesa
->bufCount
));
197 DEBUG_BUFS(("GET_FIRST_DMA\n"));
201 GET_FIRST_DMA(vmesa
->driFd
, vmesa
->hHWContext
,
202 1, &(vmesa
->bufIndex
[0]), &(vmesa
->bufSize
),
203 &vmesa
->_buf
[0], &vmesa
->bufCount
, s3vScrn
);
205 GET_FIRST_DMA(vmesa
->driFd
, vmesa
->hHWContext
,
206 1, &(vmesa
->bufIndex
[1]), &(vmesa
->bufSize
),
207 &vmesa
->_buf
[1], &vmesa
->bufCount
, s3vScrn
);
209 vmesa
->buf
= vmesa
->_buf
[vmesa
->_bufNum
];
212 vmesa->CMD = (AUTO_EXEC_ON | HW_CLIP_ON | DEST_COL_1555
213 | FOG_OFF | ALPHA_OFF | Z_OFF | Z_UPDATE_OFF
214 | DO_GOURAUD_TRI | CMD_3D);
216 vmesa->TexOffset = vmesa->s3vScreen->texOffset;
219 /* ... but we should support only 15 bit in virge (out of 8/15/24)... */
221 DEBUG(("glVisual->depthBits = %i\n", glVisual
->depthBits
));
223 switch (glVisual
->depthBits
) {
229 vmesa
->depth_scale
= 1.0f
/ 0xffff;
232 vmesa
->depth_scale
= 1.0f
/ 0xffffff;
238 vmesa
->cull_zero
= 0.0f
;
240 vmesa
->DepthSize
= glVisual
->depthBits
;
241 vmesa
->Flags
= S3V_FRONT_BUFFER
;
242 vmesa
->Flags
|= (glVisual
->doubleBufferMode
? S3V_BACK_BUFFER
: 0);
243 vmesa
->Flags
|= (vmesa
->DepthSize
> 0 ? S3V_DEPTH_BUFFER
: 0);
245 vmesa
->EnabledFlags
= S3V_FRONT_BUFFER
;
246 vmesa
->EnabledFlags
|= (glVisual
->doubleBufferMode
? S3V_BACK_BUFFER
: 0);
249 if (vmesa
->Flags
& S3V_BACK_BUFFER
) {
250 vmesa
->readOffset
= vmesa
->drawOffset
= vmesa
->s3vScreen
->backOffset
;
252 vmesa
->readOffset
= vmesa
->drawOffset
= 0;
257 driContextPriv
->driverPrivate
= (void *)vmesa
;