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"
15 #include "simple_list.h"
17 #include "extensions.h"
18 #if defined(USE_X86_ASM)
19 #include "x86/common_x86_asm.h"
21 #include "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 vmesa
->texHeap
= mmInit( 0, vmesa
->s3vScreen
->textureSize
);
112 DEBUG(("vmesa->s3vScreen->textureSize = 0x%x\n",
113 vmesa
->s3vScreen
->textureSize
));
116 /* mmInit(offset, size); */
118 /* allocates a structure like this:
121 struct mem_block_t *next;
122 struct mem_block_t *heap;
131 make_empty_list(&vmesa
->TexObjList
);
132 make_empty_list(&vmesa
->SwappedOut
);
134 vmesa
->CurrentTexObj
[0] = 0;
135 vmesa
->CurrentTexObj
[1] = 0; /* FIXME */
137 vmesa
->RenderIndex
= ~0;
139 /* Initialize the software rasterizer and helper modules.
141 _swrast_CreateContext( ctx
);
142 _vbo_CreateContext( ctx
);
143 _tnl_CreateContext( ctx
);
144 _swsetup_CreateContext( ctx
);
146 /* Install the customized pipeline:
149 _tnl_destroy_pipeline( ctx
);
150 _tnl_install_pipeline( ctx
, s3v_pipeline
);
152 /* Configure swrast to match hardware characteristics:
155 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
156 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
160 /* 3D lines / gouraud tris */
161 vmesa
->CMD
= ( AUTO_EXEC_ON
| HW_CLIP_ON
| DEST_COL_1555
162 | FOG_OFF
| ALPHA_OFF
| Z_OFF
| Z_UPDATE_OFF
163 | Z_LESS
| TEX_WRAP_ON
| TEX_MODULATE
| LINEAR
164 | TEX_COL_ARGB1555
| CMD_3D
);
166 vmesa
->_alpha
[0] = vmesa
->_alpha
[1] = ALPHA_OFF
;
167 vmesa
->alpha_cmd
= vmesa
->_alpha
[0];
168 vmesa
->_tri
[0] = DO_GOURAUD_TRI
;
169 vmesa
->_tri
[1] = DO_TEX_LIT_TRI
;
170 vmesa
->prim_cmd
= vmesa
->_tri
[0];
172 /* printf("first vmesa->CMD = 0x%x\n", vmesa->CMD); */
174 vmesa
->TexOffset
= vmesa
->s3vScreen
->texOffset
;
177 s3vInitExtensions( ctx
);
178 s3vInitDriverFuncs( ctx
);
179 s3vInitStateFuncs( ctx
);
180 s3vInitSpanFuncs( ctx
);
181 s3vInitTextureFuncs( ctx
);
182 s3vInitTriFuncs( ctx
);
183 s3vInitState( vmesa
);
185 driContextPriv
->driverPrivate
= (void *)vmesa
;
188 vmesa
->bufSize
= S3V_DMA_BUF_SZ
;
190 DEBUG(("vmesa->bufSize = %i\n", vmesa
->bufSize
));
191 DEBUG(("vmesa->bufCount = %i\n", vmesa
->bufCount
));
195 DEBUG_BUFS(("GET_FIRST_DMA\n"));
199 GET_FIRST_DMA(vmesa
->driFd
, vmesa
->hHWContext
,
200 1, &(vmesa
->bufIndex
[0]), &(vmesa
->bufSize
),
201 &vmesa
->_buf
[0], &vmesa
->bufCount
, s3vScrn
);
203 GET_FIRST_DMA(vmesa
->driFd
, vmesa
->hHWContext
,
204 1, &(vmesa
->bufIndex
[1]), &(vmesa
->bufSize
),
205 &vmesa
->_buf
[1], &vmesa
->bufCount
, s3vScrn
);
207 vmesa
->buf
= vmesa
->_buf
[vmesa
->_bufNum
];
210 vmesa->CMD = (AUTO_EXEC_ON | HW_CLIP_ON | DEST_COL_1555
211 | FOG_OFF | ALPHA_OFF | Z_OFF | Z_UPDATE_OFF
212 | DO_GOURAUD_TRI | CMD_3D);
214 vmesa->TexOffset = vmesa->s3vScreen->texOffset;
217 /* ... but we should support only 15 bit in virge (out of 8/15/24)... */
219 DEBUG(("glVisual->depthBits = %i\n", glVisual
->depthBits
));
221 switch (glVisual
->depthBits
) {
227 vmesa
->depth_scale
= 1.0f
/ 0xffff;
230 vmesa
->depth_scale
= 1.0f
/ 0xffffff;
236 vmesa
->cull_zero
= 0.0f
;
238 vmesa
->DepthSize
= glVisual
->depthBits
;
239 vmesa
->Flags
= S3V_FRONT_BUFFER
;
240 vmesa
->Flags
|= (glVisual
->doubleBufferMode
? S3V_BACK_BUFFER
: 0);
241 vmesa
->Flags
|= (vmesa
->DepthSize
> 0 ? S3V_DEPTH_BUFFER
: 0);
243 vmesa
->EnabledFlags
= S3V_FRONT_BUFFER
;
244 vmesa
->EnabledFlags
|= (glVisual
->doubleBufferMode
? S3V_BACK_BUFFER
: 0);
247 if (vmesa
->Flags
& S3V_BACK_BUFFER
) {
248 vmesa
->readOffset
= vmesa
->drawOffset
= vmesa
->s3vScreen
->backOffset
;
250 vmesa
->readOffset
= vmesa
->drawOffset
= 0;
255 driContextPriv
->driverPrivate
= (void *)vmesa
;