2 * Copyright 2001 by Alan Hourihane.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
22 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
26 #ifndef _GAMMA_CONTEXT_H_
27 #define _GAMMA_CONTEXT_H_
31 #include "drm_sarea.h"
33 #include "gamma_regs.h"
34 #include "gamma_main/macros.h"
35 #include "gamma_screen.h"
36 #include "main/macros.h"
37 #include "main/mtypes.h"
38 #include "glint_dri.h"
46 /* Flags for context */
47 #define GAMMA_FRONT_BUFFER 0x00000001
48 #define GAMMA_BACK_BUFFER 0x00000002
49 #define GAMMA_DEPTH_BUFFER 0x00000004
50 #define GAMMA_STENCIL_BUFFER 0x00000008
51 #define GAMMA_ACCUM_BUFFER 0x00000010
53 #define GAMMA_MAX_TEXTURE_SIZE 2048
55 /* These are the minimum requirements and should probably be increased */
56 #define MAX_MODELVIEW_STACK 16
57 #define MAX_PROJECTION_STACK 2
58 #define MAX_TEXTURE_STACK 2
60 extern void gammaDDUpdateHWState(GLcontext
*ctx
);
61 extern gammaScreenPtr
gammaCreateScreen(__DRIscreenPrivate
*sPriv
);
62 extern void gammaDestroyScreen(__DRIscreenPrivate
*sPriv
);
63 extern GLboolean
gammaCreateContext( const __GLcontextModes
*glVisual
,
64 __DRIcontextPrivate
*driContextPriv
,
65 void *sharedContextPrivate
);
67 #define GAMMA_UPLOAD_ALL 0xffffffff
68 #define GAMMA_UPLOAD_CLIPRECTS 0x00000002
69 #define GAMMA_UPLOAD_ALPHA 0x00000004
70 #define GAMMA_UPLOAD_BLEND 0x00000008
71 #define GAMMA_UPLOAD_DEPTH 0x00000010
72 #define GAMMA_UPLOAD_VIEWPORT 0x00000020
73 #define GAMMA_UPLOAD_SHADE 0x00000040
74 #define GAMMA_UPLOAD_CLIP 0x00000080
75 #define GAMMA_UPLOAD_MASKS 0x00000100
76 #define GAMMA_UPLOAD_WINDOW 0x00000200 /* defunct */
77 #define GAMMA_UPLOAD_GEOMETRY 0x00000400
78 #define GAMMA_UPLOAD_POLYGON 0x00000800
79 #define GAMMA_UPLOAD_DITHER 0x00001000
80 #define GAMMA_UPLOAD_LOGICOP 0x00002000
81 #define GAMMA_UPLOAD_FOG 0x00004000
82 #define GAMMA_UPLOAD_LIGHT 0x00008000
83 #define GAMMA_UPLOAD_CONTEXT 0x00010000
84 #define GAMMA_UPLOAD_TEX0 0x00020000
85 #define GAMMA_UPLOAD_STIPPLE 0x00040000
86 #define GAMMA_UPLOAD_TRANSFORM 0x00080000
87 #define GAMMA_UPLOAD_LINEMODE 0x00100000
88 #define GAMMA_UPLOAD_POINTMODE 0x00200000
89 #define GAMMA_UPLOAD_TRIMODE 0x00400000
91 #define GAMMA_NEW_CLIP 0x00000001
92 #define GAMMA_NEW_WINDOW 0x00000002
93 #define GAMMA_NEW_CONTEXT 0x00000004
94 #define GAMMA_NEW_TEXTURE 0x00000008 /* defunct */
95 #define GAMMA_NEW_ALPHA 0x00000010
96 #define GAMMA_NEW_DEPTH 0x00000020
97 #define GAMMA_NEW_MASKS 0x00000040
98 #define GAMMA_NEW_POLYGON 0x00000080
99 #define GAMMA_NEW_CULL 0x00000100
100 #define GAMMA_NEW_LOGICOP 0x00000200
101 #define GAMMA_NEW_FOG 0x00000400
102 #define GAMMA_NEW_LIGHT 0x00000800
103 #define GAMMA_NEW_STIPPLE 0x00001000
104 #define GAMMA_NEW_ALL 0xffffffff
106 #define GAMMA_FALLBACK_TRI 0x00000001
107 #define GAMMA_FALLBACK_TEXTURE 0x00000002
109 #define FLUSH_BATCH(gmesa) do { \
110 /*FLUSH_DMA_BUFFER(gmesa);*/ \
113 struct gamma_context
;
114 typedef struct gamma_context gammaContextRec
;
115 typedef struct gamma_context
*gammaContextPtr
;
116 typedef struct gamma_texture_object_t
*gammaTextureObjectPtr
;
118 #define VALID_GAMMA_TEXTURE_OBJECT(tobj) (tobj)
120 #define GAMMA_TEX_MAXLEVELS 12 /* 2K x 2K */
122 /* For shared texture space managment, these texture objects may also
123 * be used as proxies for regions of texture memory containing other
124 * client's textures. Such proxy textures (not to be confused with GL
125 * proxy textures) are subject to the same LRU aging we use for our
126 * own private textures, and thus we have a mechanism where we can
127 * fairly decide between kicking out our own textures and those of
130 * Non-local texture objects have a valid MemBlock to describe the
131 * region managed by the other client, and can be identified by
134 struct gamma_texture_object_t
{
135 struct gamma_texture_object_t
*next
, *prev
;
138 struct gl_texture_object
*globj
;
146 struct mem_block
*MemBlock
;
153 GLint firstLevel
, lastLevel
; /* upload tObj->Image[0][first .. lastLevel] */
156 const struct gl_texture_image
*image
;
157 int offset
; /* into BufAddr */
160 } image
[GAMMA_TEX_MAXLEVELS
];
162 uint32_t TextureBaseAddr
[GAMMA_TEX_MAXLEVELS
];
163 uint32_t TextureAddressMode
;
164 uint32_t TextureColorMode
;
165 uint32_t TextureFilterMode
;
166 uint32_t TextureFormat
;
167 uint32_t TextureReadMode
;
168 uint32_t TextureBorderColor
;
171 #define GAMMA_NO_PALETTE 0x0
172 #define GAMMA_USE_PALETTE 0x1
173 #define GAMMA_UPDATE_PALETTE 0x2
174 #define GAMMA_FALLBACK_PALETTE 0x4
176 void gammaUpdateTextureState( GLcontext
*ctx
);
178 void gammaDestroyTexObj( gammaContextPtr gmesa
, gammaTextureObjectPtr t
);
179 void gammaSwapOutTexObj( gammaContextPtr gmesa
, gammaTextureObjectPtr t
);
180 void gammaUploadTexImages( gammaContextPtr gmesa
, gammaTextureObjectPtr t
);
182 void gammaResetGlobalLRU( gammaContextPtr gmesa
);
183 void gammaUpdateTexLRU( gammaContextPtr gmesa
, gammaTextureObjectPtr t
);
184 void gammaTexturesGone( gammaContextPtr gmesa
,
185 GLuint start
, GLuint end
,
188 void gammaEmitHwState( gammaContextPtr gmesa
);
189 void gammaDDInitExtensions( GLcontext
*ctx
);
190 void gammaDDInitDriverFuncs( GLcontext
*ctx
);
191 void gammaDDInitSpanFuncs( GLcontext
*ctx
);
192 void gammaDDInitState( gammaContextPtr gmesa
);
193 void gammaInitHW( gammaContextPtr gmesa
);
194 void gammaDDInitStateFuncs( GLcontext
*ctx
);
195 void gammaDDInitTextureFuncs( struct dd_function_table
*table
);
196 void gammaInitTextureObjects( GLcontext
*ctx
);
197 void gammaDDInitTriFuncs( GLcontext
*ctx
);
199 void gammaUpdateWindow( GLcontext
*ctx
);
200 void gammaUpdateViewportOffset( GLcontext
*ctx
);
202 void gammaPrintLocalLRU( gammaContextPtr gmesa
);
203 void gammaPrintGlobalLRU( gammaContextPtr gmesa
);
205 extern void gammaFallback( gammaContextPtr gmesa
, GLuint bit
, GLboolean mode
);
206 #define FALLBACK( imesa, bit, mode ) gammaFallback( imesa, bit, mode )
208 /* Use the templated vertex formats. Only one of these is used in gamma.
210 #define TAG(x) gamma##x
211 #include "tnl_dd/t_dd_vertex.h"
214 typedef void (*gamma_quad_func
)( gammaContextPtr
,
218 const gammaVertex
* );
219 typedef void (*gamma_tri_func
)( gammaContextPtr
,
222 const gammaVertex
* );
223 typedef void (*gamma_line_func
)( gammaContextPtr
,
225 const gammaVertex
* );
226 typedef void (*gamma_point_func
)( gammaContextPtr
,
227 const gammaVertex
* );
230 struct gamma_context
{
231 GLcontext
*glCtx
; /* Mesa context */
233 __DRIcontextPrivate
*driContext
;
234 __DRIscreenPrivate
*driScreen
;
235 __DRIdrawablePrivate
*driDrawable
;
241 GLINTSAREADRIPtr sarea
;
243 /* Mirrors of some DRI state
245 drm_context_t hHWContext
;
246 drm_hw_lock_t
*driHwLock
;
249 GLuint numClipRects
; /* Cliprects for the draw buffer */
250 drm_clip_rect_t
*pClipRects
;
252 dmaBuf buf
; /* DMA buffer for regular cmds */
257 dmaBuf WCbuf
; /* DMA buffer for window changed cmds */
262 gammaScreenPtr gammaScreen
; /* Screen private DRI data */
267 gamma_point_func draw_point
;
268 gamma_line_func draw_line
;
269 gamma_tri_func draw_tri
;
270 gamma_quad_func draw_quad
;
274 GLuint SetupNewInputs
;
277 GLuint vertex_format
;
279 GLuint vertex_stride_shift
;
282 GLfloat hw_viewport
[16];
284 GLenum render_primitive
;
288 gammaTextureObjectPtr CurrentTexObj
[2];
289 struct gamma_texture_object_t TexObjList
;
290 struct gamma_texture_object_t SwappedOut
;
291 GLenum TexEnvImageFmt
[2];
293 struct mem_block
*texHeap
;
295 unsigned int lastSwap
;
299 unsigned int lastStamp
;
307 uint32_t AreaStippleMode
;
308 uint32_t LBReadFormat
;
309 uint32_t LBWriteFormat
;
312 uint32_t TriangleMode
;
313 uint32_t AntialiasMode
;
314 GLfloat ViewportScaleX
;
315 GLfloat ViewportScaleY
;
316 GLfloat ViewportScaleZ
;
317 GLfloat ViewportOffsetX
;
318 GLfloat ViewportOffsetY
;
319 GLfloat ViewportOffsetZ
;
332 int AB_FBReadMode_Save
;
334 int ColorMaterialMode
;
335 int FBHardwareWriteMask
;
359 int Window
; /* GID part probably should be in draw priv */
361 int x
, y
, w
, h
; /* Probably should be in drawable priv */
362 int FrameCount
; /* Probably should be in drawable priv */
363 int NotClipped
; /* Probably should be in drawable priv */
364 int WindowChanged
; /* Probably should be in drawabl... */
370 int Texture1DEnabled
;
371 int Texture2DEnabled
;
375 float ModelViewProj
[16];
378 float ModelViewStack
[(MAX_MODELVIEW_STACK
-1)*16];
380 float ProjStack
[(MAX_PROJECTION_STACK
-1)*16];
382 float TextureStack
[(MAX_TEXTURE_STACK
-1)*16];
386 static INLINE GLuint
gammaPackColor( GLuint cpp
,
387 GLubyte r
, GLubyte g
,
388 GLubyte b
, GLubyte a
)
392 return PACK_COLOR_565( r
, g
, b
);
394 return PACK_COLOR_8888( a
, r
, g
, b
);
400 #define GAMMA_CONTEXT(ctx) ((gammaContextPtr)(ctx->DriverCtx))
402 #endif /* _GAMMA_CONTEXT_H_ */