2 * Author: Max Lingua <sunmax@libero.it>
5 #ifndef _S3V_CONTEXT_H_
6 #define _S3V_CONTEXT_H_
12 #include "s3v_macros.h"
13 #include "s3v_screen.h"
19 #include "drirenderbuffer.h"
21 /* Flags for context */
22 #define S3V_FRONT_BUFFER 0x00000001
23 #define S3V_BACK_BUFFER 0x00000002
24 #define S3V_DEPTH_BUFFER 0x00000004
27 #define S3V_MAX_TEXTURE_SIZE 2048
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
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
);
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
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
80 #define S3V_FALLBACK_TRI 0x00000001
81 #define S3V_FALLBACK_TEXTURE 0x00000002
84 typedef struct s3v_context s3vContextRec
;
85 typedef struct s3v_context
*s3vContextPtr
;
86 typedef struct s3v_texture_object_t
*s3vTextureObjectPtr
;
88 #define VALID_S3V_TEXTURE_OBJECT(tobj) (tobj)
90 #define S3V_TEX_MAXLEVELS 12
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
100 * Non-local texture objects have a valid MemBlock to describe the
101 * region managed by the other client, and can be identified by
104 struct s3v_texture_object_t
{
105 struct s3v_texture_object_t
*next
, *prev
;
108 struct gl_texture_object
*globj
;
124 GLint firstLevel
, lastLevel
; /* upload tObj->Image[first .. lastLevel] */
127 const struct gl_texture_image
*image
;
128 int offset
; /* into BufAddr */
131 } image
[S3V_TEX_MAXLEVELS
];
135 GLuint TextureColorMode
;
136 GLuint TextureFilterMode
;
137 GLuint TextureBorderColor
;
139 GLuint TextureMipSize
;
141 GLuint TextureBaseAddr
[S3V_TEX_MAXLEVELS
];
142 GLuint TextureFormat
;
143 GLuint TextureReadMode
;
146 #define S3V_NO_PALETTE 0x0
147 #define S3V_USE_PALETTE 0x1
148 #define S3V_UPDATE_PALETTE 0x2
149 #define S3V_FALLBACK_PALETTE 0x4
151 void s3vUpdateTextureState( GLcontext
*ctx
);
153 void s3vDestroyTexObj( s3vContextPtr vmesa
, s3vTextureObjectPtr t
);
154 void s3vUploadTexImages( s3vContextPtr vmesa
, s3vTextureObjectPtr t
);
156 void s3vResetGlobalLRU( s3vContextPtr vmesa
);
157 void s3vTexturesGone( s3vContextPtr vmesa
,
158 GLuint start
, GLuint end
,
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
);
172 void s3vUpdateWindow( GLcontext
*ctx
);
173 void s3vUpdateViewportOffset( GLcontext
*ctx
);
175 void s3vPrintLocalLRU( s3vContextPtr vmesa
);
176 void s3vPrintGlobalLRU( s3vContextPtr vmesa
);
178 extern void s3vFallback( s3vContextPtr vmesa
, GLuint bit
, GLboolean mode
);
179 #define FALLBACK( imesa, bit, mode ) s3vFallback( imesa, bit, mode )
181 /* Use the templated vertex formats. Only one of these is used in s3v.
183 #define TAG(x) s3v##x
184 #include "tnl_dd/t_dd_vertex.h"
187 typedef void (*s3v_quad_func
)( s3vContextPtr
,
192 typedef void (*s3v_tri_func
)( s3vContextPtr
,
196 typedef void (*s3v_line_func
)( s3vContextPtr
,
199 typedef void (*s3v_point_func
)( s3vContextPtr
,
203 /* static void s3v_lines_emit(GLcontext *ctx, GLuint start, GLuint end); */
204 typedef void (*emit_func
)( GLcontext
*, GLuint
, GLuint
);
207 GLcontext
*glCtx
; /* Mesa context */
209 __DRIcontextPrivate
*driContext
;
210 __DRIscreenPrivate
*driScreen
;
211 __DRIdrawablePrivate
*driDrawable
;
219 /* Temporaries for translating away float colors
221 struct gl_client_array UbyteColor
;
222 struct gl_client_array UbyteSecondaryColor
;
224 /* Mirrors of some DRI state
227 drm_context_t hHWContext
;
231 GLuint numClipRects
; /* Cliprects for the draw buffer */
232 drm_clip_rect_t
*pClipRects
;
234 GLuint
* buf
; /* FIXME */
241 s3vScreenPtr s3vScreen
; /* Screen private DRI data */
246 s3v_point_func draw_point
;
247 s3v_line_func draw_line
;
248 s3v_tri_func draw_tri
;
249 s3v_quad_func draw_quad
;
253 GLuint SetupNewInputs
;
256 GLuint vertex_format
;
258 GLuint vertex_stride_shift
;
261 GLfloat hw_viewport
[16];
263 GLenum render_primitive
;
267 s3vTextureObjectPtr CurrentTexObj
[2];
268 struct s3v_texture_object_t TexObjList
;
269 struct s3v_texture_object_t SwappedOut
;
270 GLenum TexEnvImageFmt
[2];
280 /* max was here: don't touch */
282 unsigned int S3V_REG
[S3V_REGS_NUM
];
293 GLuint ScissorWH
; /* SubScissorWH */ /* RectWH */
306 GLuint TextureBorderColor
;
312 GLuint _tri
[2]; /* 0 = gouraud; 1 = tex (lit or unlit) */
313 GLuint alpha_cmd
; /* actual alpha cmd */
315 GLuint _alpha_tex
; /* tex alpha type */
316 /* (3d_mode) 0 = 3d line/gourad tri; 1 = 3d tex tri */
319 GLfloat backface_sign
;
322 int restore_primitive
;
327 GLuint AreaStippleMode
;
329 GLuint LBWriteFormat
;
333 GLuint AntialiasMode
;
334 GLfloat ViewportScaleX
;
335 GLfloat ViewportScaleY
;
336 GLfloat ViewportScaleZ
;
337 GLfloat ViewportOffsetX
;
338 GLfloat ViewportOffsetY
;
339 GLfloat ViewportOffsetZ
;
352 int AB_FBReadMode_Save
;
354 int ColorMaterialMode
;
355 int FBHardwareWriteMask
;
379 int Window
; /* GID part probably should be in draw priv */
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... */
390 int Texture1DEnabled
;
391 int Texture2DEnabled
;
395 float ModelViewProj
[16];
398 float ModelViewStack
[(MAX_MODELVIEW_STACK
-1)*16];
400 float ProjStack
[(MAX_PROJECTION_STACK
-1)*16];
402 float TextureStack
[(MAX_TEXTURE_STACK
-1)*16];
406 #define S3VIRGEPACKCOLOR555( r, g, b, a ) \
407 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
410 #define S3VIRGEPACKCOLOR565( r, g, b ) \
411 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
413 #define S3VIRGEPACKCOLOR888( r, g, b ) \
414 (((r) << 16) | ((g) << 8) | (b))
416 #define S3VIRGEPACKCOLOR8888( r, g, b, a ) \
417 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
419 #define S3VIRGEPACKCOLOR4444( r, g, b, a ) \
420 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
422 static __inline GLuint
s3vPackColor( GLuint cpp
,
423 GLubyte r
, GLubyte g
,
424 GLubyte b
, GLubyte a
)
427 DEBUG(("cpp = %i, r=0x%x, g=0x%x, b=0x%x, a=0x%x\n", cpp
, r
, g
, b
, a
));
431 ret
= S3VIRGEPACKCOLOR555( r
, g
, b
, a
);
432 DEBUG(("ret = 0x%x\n", ret
));
435 return PACK_COLOR_8888( a
, r
, g
, b
);
441 #define S3V_CONTEXT(ctx) ((s3vContextPtr)(ctx->DriverCtx))
443 #endif /* _S3V_CONTEXT_H_ */