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