Get s3v building with a minimum of warnings.
[mesa.git] / src / mesa / drivers / dri / s3v / s3v_context.h
1 /*
2 * Author: Max Lingua <sunmax@libero.it>
3 */
4
5 #ifndef _S3V_CONTEXT_H_
6 #define _S3V_CONTEXT_H_
7
8 #include "dri_util.h"
9
10 #include "s3v_dri.h"
11 #include "s3v_regs.h"
12 #include "s3v_macros.h"
13 #include "s3v_screen.h"
14 #include "colormac.h"
15 #include "macros.h"
16 #include "mtypes.h"
17 #include "drm.h"
18 #include "mm.h"
19
20 /* Flags for context */
21 #define S3V_FRONT_BUFFER 0x00000001
22 #define S3V_BACK_BUFFER 0x00000002
23 #define S3V_DEPTH_BUFFER 0x00000004
24
25 /* FIXME: check */
26 #define S3V_MAX_TEXTURE_SIZE 2048
27
28 /* These are the minimum requirements and should probably be increased */
29 #define MAX_MODELVIEW_STACK 16
30 #define MAX_PROJECTION_STACK 2
31 #define MAX_TEXTURE_STACK 2
32
33 extern void s3vDDUpdateHWState(GLcontext *ctx);
34 extern s3vScreenPtr s3vCreateScreen(__DRIscreenPrivate *sPriv);
35 extern void s3vDestroyScreen(__DRIscreenPrivate *sPriv);
36 extern GLboolean s3vCreateContext(const __GLcontextModes *glVisual,
37 __DRIcontextPrivate *driContextPriv,
38 void *sharedContextPrivate);
39
40 #define S3V_UPLOAD_ALL 0xffffffff
41 /* #define S3V_UPLOAD_CLIPRECTS 0x00000002 */
42 #define S3V_UPLOAD_ALPHA 0x00000004
43 #define S3V_UPLOAD_BLEND 0x00000008
44 #define S3V_UPLOAD_DEPTH 0x00000010
45 #define S3V_UPLOAD_VIEWPORT 0x00000020
46 #define S3V_UPLOAD_SHADE 0x00000040
47 #define S3V_UPLOAD_CLIP 0x00000080
48 #define S3V_UPLOAD_MASKS 0x00000100
49 #define S3V_UPLOAD_WINDOW 0x00000200 /* defunct */
50 #define S3V_UPLOAD_GEOMETRY 0x00000400
51 #define S3V_UPLOAD_POLYGON 0x00000800
52 #define S3V_UPLOAD_DITHER 0x00001000
53 #define S3V_UPLOAD_LOGICOP 0x00002000
54 #define S3V_UPLOAD_FOG 0x00004000
55 #define S3V_UPLOAD_LIGHT 0x00008000
56 #define S3V_UPLOAD_CONTEXT 0x00010000
57 #define S3V_UPLOAD_TEX0 0x00020000
58 #define S3V_UPLOAD_STIPPLE 0x00040000
59 #define S3V_UPLOAD_TRANSFORM 0x00080000
60 #define S3V_UPLOAD_LINEMODE 0x00100000
61 #define S3V_UPLOAD_POINTMODE 0x00200000
62 #define S3V_UPLOAD_TRIMODE 0x00400000
63
64 #define S3V_NEW_CLIP 0x00000001
65 #define S3V_NEW_WINDOW 0x00000002
66 #define S3V_NEW_CONTEXT 0x00000004
67 #define S3V_NEW_TEXTURE 0x00000008 /* defunct */
68 #define S3V_NEW_ALPHA 0x00000010
69 #define S3V_NEW_DEPTH 0x00000020
70 #define S3V_NEW_MASKS 0x00000040
71 #define S3V_NEW_POLYGON 0x00000080
72 #define S3V_NEW_CULL 0x00000100
73 #define S3V_NEW_LOGICOP 0x00000200
74 #define S3V_NEW_FOG 0x00000400
75 #define S3V_NEW_LIGHT 0x00000800
76 #define S3V_NEW_STIPPLE 0x00001000
77 #define S3V_NEW_ALL 0xffffffff
78
79 #define S3V_FALLBACK_TRI 0x00000001
80 #define S3V_FALLBACK_TEXTURE 0x00000002
81
82 struct s3v_context;
83 typedef struct s3v_context s3vContextRec;
84 typedef struct s3v_context *s3vContextPtr;
85 typedef struct s3v_texture_object_t *s3vTextureObjectPtr;
86
87 #define VALID_S3V_TEXTURE_OBJECT(tobj) (tobj)
88
89 #define S3V_TEX_MAXLEVELS 12
90
91 /* For shared texture space managment, these texture objects may also
92 * be used as proxies for regions of texture memory containing other
93 * client's textures. Such proxy textures (not to be confused with GL
94 * proxy textures) are subject to the same LRU aging we use for our
95 * own private textures, and thus we have a mechanism where we can
96 * fairly decide between kicking out our own textures and those of
97 * other clients.
98 *
99 * Non-local texture objects have a valid MemBlock to describe the
100 * region managed by the other client, and can be identified by
101 * 't->globj == 0'
102 */
103 struct s3v_texture_object_t {
104 struct s3v_texture_object_t *next, *prev;
105
106 GLuint age;
107 struct gl_texture_object *globj;
108
109 int Pitch;
110 int Height;
111 int WidthLog2;
112 int texelBytes;
113 int totalSize;
114 int bound;
115
116 PMemBlock MemBlock;
117 GLuint BufAddr;
118
119 GLuint min_level;
120 GLuint max_level;
121 GLuint dirty_images;
122
123 GLint firstLevel, lastLevel; /* upload tObj->Image[first .. lastLevel] */
124
125 struct {
126 const struct gl_texture_image *image;
127 int offset; /* into BufAddr */
128 int height;
129 int internalFormat;
130 } image[S3V_TEX_MAXLEVELS];
131
132 GLuint TextureCMD;
133
134 GLuint TextureColorMode;
135 GLuint TextureFilterMode;
136 GLuint TextureBorderColor;
137 GLuint TextureWrap;
138 GLuint TextureMipSize;
139
140 GLuint TextureBaseAddr[S3V_TEX_MAXLEVELS];
141 GLuint TextureFormat;
142 GLuint TextureReadMode;
143 };
144
145 #define S3V_NO_PALETTE 0x0
146 #define S3V_USE_PALETTE 0x1
147 #define S3V_UPDATE_PALETTE 0x2
148 #define S3V_FALLBACK_PALETTE 0x4
149
150 void s3vUpdateTextureState( GLcontext *ctx );
151
152 void s3vDestroyTexObj( s3vContextPtr vmesa, s3vTextureObjectPtr t);
153 void s3vUploadTexImages( s3vContextPtr vmesa, s3vTextureObjectPtr t );
154
155 void s3vResetGlobalLRU( s3vContextPtr vmesa );
156 void s3vTexturesGone( s3vContextPtr vmesa,
157 GLuint start, GLuint end,
158 GLuint in_use );
159
160 void s3vEmitHwState( s3vContextPtr vmesa );
161 void s3vGetLock( s3vContextPtr vmesa, GLuint flags );
162 void s3vInitExtensions( GLcontext *ctx );
163 void s3vInitDriverFuncs( GLcontext *ctx );
164 void s3vInitSpanFuncs( GLcontext *ctx );
165 void s3vInitState( s3vContextPtr vmesa );
166 void s3vInitHW( s3vContextPtr vmesa );
167 void s3vInitStateFuncs( GLcontext *ctx );
168 void s3vInitTextureFuncs( GLcontext *ctx );
169 void s3vInitTriFuncs( GLcontext *ctx );
170
171 void s3vUpdateWindow( GLcontext *ctx );
172 void s3vUpdateViewportOffset( GLcontext *ctx );
173
174 void s3vPrintLocalLRU( s3vContextPtr vmesa );
175 void s3vPrintGlobalLRU( s3vContextPtr vmesa );
176
177 extern void s3vFallback( s3vContextPtr vmesa, GLuint bit, GLboolean mode );
178 #define FALLBACK( imesa, bit, mode ) s3vFallback( imesa, bit, mode )
179
180 /* Use the templated vertex formats. Only one of these is used in s3v.
181 */
182 #define TAG(x) s3v##x
183 #include "tnl_dd/t_dd_vertex.h"
184 #undef TAG
185
186 typedef void (*s3v_quad_func)( s3vContextPtr,
187 const s3vVertex *,
188 const s3vVertex *,
189 const s3vVertex *,
190 const s3vVertex * );
191 typedef void (*s3v_tri_func)( s3vContextPtr,
192 const s3vVertex *,
193 const s3vVertex *,
194 const s3vVertex * );
195 typedef void (*s3v_line_func)( s3vContextPtr,
196 const s3vVertex *,
197 const s3vVertex * );
198 typedef void (*s3v_point_func)( s3vContextPtr,
199 const s3vVertex * );
200
201
202 /* static void s3v_lines_emit(GLcontext *ctx, GLuint start, GLuint end); */
203 typedef void (*emit_func)( GLcontext *, GLuint, GLuint);
204
205 struct s3v_context {
206 GLcontext *glCtx; /* Mesa context */
207
208 __DRIcontextPrivate *driContext;
209 __DRIscreenPrivate *driScreen;
210 __DRIdrawablePrivate *driDrawable;
211
212 GLuint new_gl_state;
213 GLuint new_state;
214 GLuint dirty;
215
216 S3VSAREAPtr sarea;
217
218 /* Temporaries for translating away float colors
219 */
220 struct gl_client_array UbyteColor;
221 struct gl_client_array UbyteSecondaryColor;
222
223 /* Mirrors of some DRI state
224 */
225
226 drm_context_t hHWContext;
227 drmLock *driHwLock;
228 int driFd;
229
230 GLuint numClipRects; /* Cliprects for the draw buffer */
231 drm_clip_rect_t *pClipRects;
232
233 GLuint* buf; /* FIXME */
234 GLuint* _buf[2];
235 int _bufNum;
236 int bufIndex[2];
237 int bufSize;
238 int bufCount;
239
240 s3vScreenPtr s3vScreen; /* Screen private DRI data */
241
242 int drawOffset;
243 int readOffset;
244
245 s3v_point_func draw_point;
246 s3v_line_func draw_line;
247 s3v_tri_func draw_tri;
248 s3v_quad_func draw_quad;
249
250 GLuint Fallback;
251 GLuint RenderIndex;
252 GLuint SetupNewInputs;
253 GLuint SetupIndex;
254
255 GLuint vertex_format;
256 GLuint vertex_size;
257 GLuint vertex_stride_shift;
258 char *verts;
259
260 GLfloat hw_viewport[16];
261 GLuint hw_primitive;
262 GLenum render_primitive;
263
264 GLfloat depth_scale;
265
266 s3vTextureObjectPtr CurrentTexObj[2];
267 struct s3v_texture_object_t TexObjList;
268 struct s3v_texture_object_t SwappedOut;
269 GLenum TexEnvImageFmt[2];
270
271 memHeap_t *texHeap;
272
273 int lastSwap;
274 int texAge;
275 int ctxAge;
276 int dirtyAge;
277 int lastStamp;
278
279 /* max was here: don't touch */
280
281 unsigned int S3V_REG[S3V_REGS_NUM];
282
283 GLuint texMode;
284 GLuint alphaMode;
285 GLuint lightMode;
286
287 GLuint SrcBase;
288 GLuint DestBase;
289 GLuint DestBlit;
290 GLuint ScissorLR;
291 GLuint ScissorTB;
292 GLuint ScissorWH; /* SubScissorWH */ /* RectWH */
293 GLuint FrontStride;
294 GLuint BackStride;
295 GLuint SrcStride;
296 GLuint DestStride;
297 GLuint SrcXY;
298 GLuint DestXY;
299
300 GLuint ClearColor;
301 GLuint Color;
302 GLuint DitherMode;
303 GLuint ClearDepth;
304
305 GLuint TextureBorderColor;
306 GLuint TexOffset;
307 GLuint TexStride;
308
309 GLuint CMD;
310 GLuint prim_cmd;
311 GLuint _tri[2]; /* 0 = gouraud; 1 = tex (lit or unlit) */
312 GLuint alpha_cmd; /* actual alpha cmd */
313 GLuint _alpha[2];
314 GLuint _alpha_tex; /* tex alpha type */
315 /* (3d_mode) 0 = 3d line/gourad tri; 1 = 3d tex tri */
316 GLuint _3d_mode;
317
318 GLfloat backface_sign;
319 GLfloat cull_zero;
320
321 int restore_primitive;
322
323 /* *** 2check *** */
324
325 GLuint FogMode;
326 GLuint AreaStippleMode;
327 GLuint LBReadFormat;
328 GLuint LBWriteFormat;
329 GLuint LineMode;
330 GLuint PointMode;
331 GLuint TriangleMode;
332 GLuint AntialiasMode;
333 GLfloat ViewportScaleX;
334 GLfloat ViewportScaleY;
335 GLfloat ViewportScaleZ;
336 GLfloat ViewportOffsetX;
337 GLfloat ViewportOffsetY;
338 GLfloat ViewportOffsetZ;
339 int MatrixMode;
340 int DepthMode;
341 int TransformMode;
342 int LBReadMode;
343 int FBReadMode;
344 int FBWindowBase;
345 int LBWindowBase;
346 int ColorDDAMode;
347 int GeometryMode;
348 int AlphaTestMode;
349 int AlphaBlendMode;
350 int AB_FBReadMode;
351 int AB_FBReadMode_Save;
352 int DeltaMode;
353 int ColorMaterialMode;
354 int FBHardwareWriteMask;
355 int MaterialMode;
356 int NormalizeMode;
357 int LightingMode;
358 int Light0Mode;
359 int Light1Mode;
360 int Light2Mode;
361 int Light3Mode;
362 int Light4Mode;
363 int Light5Mode;
364 int Light6Mode;
365 int Light7Mode;
366 int Light8Mode;
367 int Light9Mode;
368 int Light10Mode;
369 int Light11Mode;
370 int Light12Mode;
371 int Light13Mode;
372 int Light14Mode;
373 int Light15Mode;
374 int LogicalOpMode;
375 int ScissorMode;
376 int ScissorMaxXY;
377 int ScissorMinXY;
378 int Window; /* GID part probably should be in draw priv */
379 int WindowOrigin;
380 int x, y, w, h; /* Probably should be in drawable priv */
381 int FrameCount; /* Probably should be in drawable priv */
382 int NotClipped; /* Probably should be in drawable priv */
383 int WindowChanged; /* Probably should be in drawabl... */
384 int Flags;
385 int EnabledFlags;
386 int DepthSize;
387 int Begin;
388 GLenum ErrorValue;
389 int Texture1DEnabled;
390 int Texture2DEnabled;
391
392 float ModelView[16];
393 float Proj[16];
394 float ModelViewProj[16];
395 float Texture[16];
396
397 float ModelViewStack[(MAX_MODELVIEW_STACK-1)*16];
398 int ModelViewCount;
399 float ProjStack[(MAX_PROJECTION_STACK-1)*16];
400 int ProjCount;
401 float TextureStack[(MAX_TEXTURE_STACK-1)*16];
402 int TextureCount;
403 };
404
405 #define S3VIRGEPACKCOLOR555( r, g, b, a ) \
406 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
407 ((a) ? 0x8000 : 0))
408
409 #define S3VIRGEPACKCOLOR565( r, g, b ) \
410 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
411
412 #define S3VIRGEPACKCOLOR888( r, g, b ) \
413 (((r) << 16) | ((g) << 8) | (b))
414
415 #define S3VIRGEPACKCOLOR8888( r, g, b, a ) \
416 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
417
418 #define S3VIRGEPACKCOLOR4444( r, g, b, a ) \
419 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
420
421 static __inline GLuint s3vPackColor( GLuint cpp,
422 GLubyte r, GLubyte g,
423 GLubyte b, GLubyte a )
424 {
425 unsigned int ret;
426 DEBUG(("cpp = %i, r=0x%x, g=0x%x, b=0x%x, a=0x%x\n", cpp, r, g, b, a));
427
428 switch ( cpp ) {
429 case 2:
430 ret = S3VIRGEPACKCOLOR555( r, g, b, a );
431 DEBUG(("ret = 0x%x\n", ret));
432 return ret;
433 case 4:
434 return PACK_COLOR_8888( a, r, g, b );
435 default:
436 return 0;
437 }
438 }
439
440 #define S3V_CONTEXT(ctx) ((s3vContextPtr)(ctx->DriverCtx))
441
442 #endif /* _S3V_CONTEXT_H_ */