3a908d7a1b30bef43df30d1fad6b0792453deb44
[mesa.git] / src / mesa / drivers / dri / r128 / r128_context.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_context.h,v 1.12 2002/12/16 16:18:52 dawes Exp $ */
2 /**************************************************************************
3
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
5 Cedar Park, Texas.
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
17 Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Kevin E. Martin <martin@valinux.com>
32 * Gareth Hughes <gareth@valinux.com>
33 *
34 */
35
36 #ifndef __R128_CONTEXT_H__
37 #define __R128_CONTEXT_H__
38
39 #ifdef GLX_DIRECT_RENDERING
40
41 #include "dri_util.h"
42
43 #include "xf86drm.h"
44 #include "r128_common.h"
45
46 #include "mtypes.h"
47
48 #include "r128_reg.h"
49
50 #include "texmem.h"
51
52 struct r128_context;
53 typedef struct r128_context r128ContextRec;
54 typedef struct r128_context *r128ContextPtr;
55
56 #include "r128_lock.h"
57 #include "r128_texobj.h"
58 #include "r128_screen.h"
59
60 /* Flags for what context state needs to be updated:
61 */
62 #define R128_NEW_ALPHA 0x0001
63 #define R128_NEW_DEPTH 0x0002
64 #define R128_NEW_FOG 0x0004
65 #define R128_NEW_CLIP 0x0008
66 #define R128_NEW_CULL 0x0010
67 #define R128_NEW_MASKS 0x0020
68 #define R128_NEW_RENDER_NOT 0x0040
69 #define R128_NEW_WINDOW 0x0080
70 #define R128_NEW_CONTEXT 0x0100
71 #define R128_NEW_ALL 0x01ff
72
73 /* Flags for software fallback cases:
74 */
75 #define R128_FALLBACK_TEXTURE 0x0001
76 #define R128_FALLBACK_DRAW_BUFFER 0x0002
77 #define R128_FALLBACK_READ_BUFFER 0x0004
78 #define R128_FALLBACK_STENCIL 0x0008
79 #define R128_FALLBACK_RENDER_MODE 0x0010
80 #define R128_FALLBACK_MULTIDRAW 0x0020
81 #define R128_FALLBACK_LOGICOP 0x0040
82 #define R128_FALLBACK_SEP_SPECULAR 0x0080
83 #define R128_FALLBACK_BLEND_EQ 0x0100
84 #define R128_FALLBACK_BLEND_FUNC 0x0200
85
86
87 /* Use the templated vertex format:
88 */
89 #define TAG(x) r128##x
90 #include "tnl_dd/t_dd_vertex.h"
91 #undef TAG
92
93 /* Reasons why the GL_BLEND fallback mightn't work:
94 */
95 #define R128_BLEND_ENV_COLOR 0x1
96 #define R128_BLEND_MULTITEX 0x2
97
98 /* Subpixel offsets for window coordinates (triangles):
99 */
100 #define SUBPIXEL_X (0.0F)
101 #define SUBPIXEL_Y (0.125F)
102
103
104 typedef void (*r128_tri_func)( r128ContextPtr,
105 r128Vertex *,
106 r128Vertex *,
107 r128Vertex * );
108
109 typedef void (*r128_line_func)( r128ContextPtr,
110 r128Vertex *,
111 r128Vertex * );
112
113 typedef void (*r128_point_func)( r128ContextPtr,
114 r128Vertex * );
115
116
117 struct r128_context {
118 GLcontext *glCtx; /* Mesa context */
119
120 /* Driver and hardware state management
121 */
122 GLuint new_state;
123 GLuint dirty; /* Hardware state to be updated */
124 r128_context_regs_t setup;
125
126 /* Temporaries for translating away float colors:
127 */
128 struct gl_client_array UbyteColor;
129 struct gl_client_array UbyteSecondaryColor;
130
131 GLuint NewGLState;
132 GLuint Fallback;
133 GLuint SetupIndex;
134 GLuint SetupNewInputs;
135 GLuint RenderIndex;
136 GLfloat hw_viewport[16];
137 GLfloat depth_scale;
138 GLuint vertex_size;
139 GLuint vertex_stride_shift;
140 GLuint vertex_format;
141 GLuint num_verts;
142 GLubyte *verts;
143
144 CARD32 ClearColor; /* Color used to clear color buffer */
145 CARD32 ClearDepth; /* Value used to clear depth buffer */
146 CARD32 ClearStencil; /* Value used to clear stencil */
147
148 /* Map GL texture units onto hardware
149 */
150 GLint multitex;
151 GLint tmu_source[2];
152 GLuint tex_combine[2];
153 GLuint blend_flags;
154 GLuint env_color;
155
156 /* Texture object bookkeeping
157 */
158 unsigned nr_heaps;
159 driTexHeap * texture_heaps[ R128_NR_TEX_HEAPS ];
160 driTextureObject swapped;
161
162 r128TexObjPtr CurrentTexObj[2];
163
164 int texture_depth;
165
166 /* Fallback rasterization functions
167 */
168 r128_point_func draw_point;
169 r128_line_func draw_line;
170 r128_tri_func draw_tri;
171
172 /* Vertex buffers
173 */
174 drmBufPtr vert_buf;
175
176 GLuint hw_primitive;
177 GLenum render_primitive;
178
179 /* Page flipping
180 */
181 GLuint doPageFlip;
182
183 /* Drawable, cliprect and scissor information
184 */
185 GLint drawOffset, drawPitch;
186 GLint readOffset, readPitch;
187
188 GLuint numClipRects; /* Cliprects for the draw buffer */
189 XF86DRIClipRectPtr pClipRects;
190
191 GLuint scissor;
192 XF86DRIClipRectRec ScissorRect; /* Current software scissor */
193
194 /* Mirrors of some DRI state
195 */
196 __DRIcontextPrivate *driContext; /* DRI context */
197 __DRIscreenPrivate *driScreen; /* DRI screen */
198 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
199
200 unsigned int lastStamp; /* mirror driDrawable->lastStamp */
201
202 drmContext hHWContext;
203 drmLock *driHwLock;
204 int driFd;
205
206 r128ScreenPtr r128Screen; /* Screen private DRI data */
207 R128SAREAPrivPtr sarea; /* Private SAREA data */
208
209 /* Performance counters
210 */
211 GLuint boxes; /* Draw performance boxes */
212 GLuint hardwareWentIdle;
213 GLuint c_clears;
214 GLuint c_drawWaits;
215 GLuint c_textureSwaps;
216 GLuint c_textureBytes;
217 GLuint c_vertexBuffers;
218
219 /* VBI
220 */
221 GLuint vbl_seq;
222 GLuint vblank_flags;
223
224 /* Configuration cache
225 */
226 driOptionCache optionCache;
227 };
228
229 #define R128_CONTEXT(ctx) ((r128ContextPtr)(ctx->DriverCtx))
230
231 #define R128_IS_PLAIN( rmesa ) \
232 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128)
233 #define R128_IS_PRO( rmesa ) \
234 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_PRO)
235 #define R128_IS_MOBILITY( rmesa ) \
236 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_MOBILITY)
237
238
239 extern GLboolean r128CreateContext( const __GLcontextModes *glVisual,
240 __DRIcontextPrivate *driContextPriv,
241 void *sharedContextPrivate );
242
243 extern void r128DestroyContext( __DRIcontextPrivate * );
244
245 extern GLboolean r128MakeCurrent( __DRIcontextPrivate *driContextPriv,
246 __DRIdrawablePrivate *driDrawPriv,
247 __DRIdrawablePrivate *driReadPriv );
248
249 extern GLboolean r128UnbindContext( __DRIcontextPrivate *driContextPriv );
250
251 /* ================================================================
252 * Debugging:
253 */
254 #define DO_DEBUG 0
255 #define ENABLE_PERF_BOXES 0
256
257 #if DO_DEBUG
258 extern int R128_DEBUG;
259 #else
260 #define R128_DEBUG 0
261 #endif
262
263 #define DEBUG_ALWAYS_SYNC 0x01
264 #define DEBUG_VERBOSE_API 0x02
265 #define DEBUG_VERBOSE_MSG 0x04
266 #define DEBUG_VERBOSE_LRU 0x08
267 #define DEBUG_VERBOSE_DRI 0x10
268 #define DEBUG_VERBOSE_IOCTL 0x20
269 #define DEBUG_VERBOSE_2D 0x40
270
271 #endif
272 #endif /* __R128_CONTEXT_H__ */