intel: make sure polygon mode is set properly in intel_clear_tris()
[mesa.git] / src / mesa / drivers / dri / s3v / s3v_context.c
1 /*
2 * Author: Max Lingua <sunmax@libero.it>
3 */
4
5 #include "s3v_context.h"
6
7 #include "swrast/swrast.h"
8 #include "swrast_setup/swrast_setup.h"
9 #include "vbo/vbo.h"
10
11 #include "tnl/tnl.h"
12 #include "tnl/t_pipeline.h"
13
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"
20 #endif
21 #include "main/simple_list.h"
22 #include "main/mm.h"
23
24 #include "drivers/common/driverfuncs.h"
25 #include "s3v_vb.h"
26 #include "s3v_tris.h"
27
28 #if 0
29 extern const struct tnl_pipeline_stage _s3v_render_stage;
30
31 static const struct tnl_pipeline_stage *s3v_pipeline[] = {
32 &_tnl_vertex_transform_stage,
33 &_tnl_normal_transform_stage,
34 &_tnl_lighting_stage,
35 &_tnl_fog_coordinate_stage,
36 &_tnl_texgen_stage,
37 &_tnl_texture_transform_stage,
38 /* REMOVE: point attenuation stage */
39 #if 1
40 &_s3v_render_stage, /* ADD: unclipped rastersetup-to-dma */
41 #endif
42 &_tnl_render_stage,
43 0,
44 };
45 #endif
46
47 GLboolean s3vCreateContext(const __GLcontextModes *glVisual,
48 __DRIcontextPrivate *driContextPriv,
49 void *sharedContextPrivate)
50 {
51 GLcontext *ctx, *shareCtx;
52 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
53 s3vContextPtr vmesa;
54 s3vScreenPtr s3vScrn;
55 S3VSAREAPtr saPriv=(S3VSAREAPtr)(((char*)sPriv->pSAREA) +
56 sizeof(drm_sarea_t));
57 struct dd_function_table functions;
58
59 DEBUG_WHERE(("*** s3vCreateContext ***\n"));
60
61 vmesa = (s3vContextPtr) CALLOC( sizeof(*vmesa) );
62 if ( !vmesa ) return GL_FALSE;
63
64 /* Allocate the Mesa context */
65 if (sharedContextPrivate)
66 shareCtx = ((s3vContextPtr) sharedContextPrivate)->glCtx;
67 else
68 shareCtx = NULL;
69
70 _mesa_init_driver_functions(&functions);
71
72 vmesa->glCtx = _mesa_create_context(glVisual, shareCtx, &functions,
73 (void *)vmesa);
74 if (!vmesa->glCtx) {
75 FREE(vmesa);
76 return GL_FALSE;
77 }
78
79 vmesa->driContext = driContextPriv;
80 vmesa->driScreen = sPriv;
81 vmesa->driDrawable = NULL; /* Set by XMesaMakeCurrent */
82
83 vmesa->hHWContext = driContextPriv->hHWContext;
84 vmesa->driHwLock = (drmLock *)&sPriv->pSAREA->lock;
85 vmesa->driFd = sPriv->fd;
86 vmesa->sarea = saPriv;
87
88 s3vScrn = vmesa->s3vScreen = (s3vScreenPtr)(sPriv->private);
89
90 ctx = vmesa->glCtx;
91
92 ctx->Const.MaxTextureLevels = 11; /* it is (11-1) -> 1024 * 1024 FIXME */
93
94 ctx->Const.MaxTextureUnits = 1; /* FIXME: or 2 ? */
95
96 /* No wide points.
97 */
98 ctx->Const.MinPointSize = 1.0;
99 ctx->Const.MinPointSizeAA = 1.0;
100 ctx->Const.MaxPointSize = 1.0;
101 ctx->Const.MaxPointSizeAA = 1.0;
102
103 /* No wide lines.
104 */
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;
110
111 ctx->Const.MaxDrawBuffers = 1;
112
113 vmesa->texHeap = mmInit( 0, vmesa->s3vScreen->textureSize );
114 DEBUG(("vmesa->s3vScreen->textureSize = 0x%x\n",
115 vmesa->s3vScreen->textureSize));
116
117 /* NOTE */
118 /* mmInit(offset, size); */
119
120 /* allocates a structure like this:
121
122 struct mem_block_t {
123 struct mem_block_t *next;
124 struct mem_block_t *heap;
125 int ofs,size;
126 int align;
127 int free:1;
128 int reserved:1;
129 };
130
131 */
132
133 make_empty_list(&vmesa->TexObjList);
134 make_empty_list(&vmesa->SwappedOut);
135
136 vmesa->CurrentTexObj[0] = 0;
137 vmesa->CurrentTexObj[1] = 0; /* FIXME */
138
139 vmesa->RenderIndex = ~0;
140
141 /* Initialize the software rasterizer and helper modules.
142 */
143 _swrast_CreateContext( ctx );
144 _vbo_CreateContext( ctx );
145 _tnl_CreateContext( ctx );
146 _swsetup_CreateContext( ctx );
147
148 /* Install the customized pipeline:
149 */
150 #if 0
151 _tnl_destroy_pipeline( ctx );
152 _tnl_install_pipeline( ctx, s3v_pipeline );
153 #endif
154 /* Configure swrast to match hardware characteristics:
155 */
156 #if 0
157 _swrast_allow_pixel_fog( ctx, GL_FALSE );
158 _swrast_allow_vertex_fog( ctx, GL_TRUE );
159 #endif
160 vmesa->_3d_mode = 0;
161
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 );
167
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];
173
174 /* printf("first vmesa->CMD = 0x%x\n", vmesa->CMD); */
175
176 vmesa->TexOffset = vmesa->s3vScreen->texOffset;
177
178 s3vInitVB( ctx );
179 s3vInitExtensions( ctx );
180 s3vInitDriverFuncs( ctx );
181 s3vInitStateFuncs( ctx );
182 s3vInitSpanFuncs( ctx );
183 s3vInitTextureFuncs( ctx );
184 s3vInitTriFuncs( ctx );
185 s3vInitState( vmesa );
186
187 driContextPriv->driverPrivate = (void *)vmesa;
188
189 /* HACK */
190 vmesa->bufSize = S3V_DMA_BUF_SZ;
191
192 DEBUG(("vmesa->bufSize = %i\n", vmesa->bufSize));
193 DEBUG(("vmesa->bufCount = %i\n", vmesa->bufCount));
194
195
196 /* dma init */
197 DEBUG_BUFS(("GET_FIRST_DMA\n"));
198
199 vmesa->_bufNum = 0;
200
201 GET_FIRST_DMA(vmesa->driFd, vmesa->hHWContext,
202 1, &(vmesa->bufIndex[0]), &(vmesa->bufSize),
203 &vmesa->_buf[0], &vmesa->bufCount, s3vScrn);
204
205 GET_FIRST_DMA(vmesa->driFd, vmesa->hHWContext,
206 1, &(vmesa->bufIndex[1]), &(vmesa->bufSize),
207 &vmesa->_buf[1], &vmesa->bufCount, s3vScrn);
208
209 vmesa->buf = vmesa->_buf[vmesa->_bufNum];
210
211 /*
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);
215
216 vmesa->TexOffset = vmesa->s3vScreen->texOffset;
217 */
218
219 /* ... but we should support only 15 bit in virge (out of 8/15/24)... */
220
221 DEBUG(("glVisual->depthBits = %i\n", glVisual->depthBits));
222
223 switch (glVisual->depthBits) {
224 case 8:
225 break;
226
227 case 15:
228 case 16:
229 vmesa->depth_scale = 1.0f / 0xffff;
230 break;
231 case 24:
232 vmesa->depth_scale = 1.0f / 0xffffff;
233 break;
234 default:
235 break;
236 }
237
238 vmesa->cull_zero = 0.0f;
239
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);
244
245 vmesa->EnabledFlags = S3V_FRONT_BUFFER;
246 vmesa->EnabledFlags |= (glVisual->doubleBufferMode ? S3V_BACK_BUFFER : 0);
247
248
249 if (vmesa->Flags & S3V_BACK_BUFFER) {
250 vmesa->readOffset = vmesa->drawOffset = vmesa->s3vScreen->backOffset;
251 } else {
252 vmesa->readOffset = vmesa->drawOffset = 0;
253 }
254
255 s3vInitHW( vmesa );
256
257 driContextPriv->driverPrivate = (void *)vmesa;
258
259 return GL_TRUE;
260 }