SetBuffer, renderbuffer changes
[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 #include "dri_util.h"
40 #include "drm.h"
41 #include "r128_drm.h"
42
43 #include "mtypes.h"
44 #include "tnl/t_vertex.h"
45
46 #include "r128_reg.h"
47
48 #include "texmem.h"
49
50 struct r128_context;
51 typedef struct r128_context r128ContextRec;
52 typedef struct r128_context *r128ContextPtr;
53
54 #include "r128_lock.h"
55 #include "r128_texobj.h"
56 #include "r128_screen.h"
57
58 /* Flags for what context state needs to be updated:
59 */
60 #define R128_NEW_ALPHA 0x0001
61 #define R128_NEW_DEPTH 0x0002
62 #define R128_NEW_FOG 0x0004
63 #define R128_NEW_CLIP 0x0008
64 #define R128_NEW_CULL 0x0010
65 #define R128_NEW_MASKS 0x0020
66 #define R128_NEW_RENDER_NOT 0x0040
67 #define R128_NEW_WINDOW 0x0080
68 #define R128_NEW_CONTEXT 0x0100
69 #define R128_NEW_ALL 0x01ff
70
71 /* Flags for software fallback cases:
72 */
73 #define R128_FALLBACK_TEXTURE 0x0001
74 #define R128_FALLBACK_DRAW_BUFFER 0x0002
75 #define R128_FALLBACK_READ_BUFFER 0x0004
76 #define R128_FALLBACK_STENCIL 0x0008
77 #define R128_FALLBACK_RENDER_MODE 0x0010
78 #define R128_FALLBACK_LOGICOP 0x0020
79 #define R128_FALLBACK_SEP_SPECULAR 0x0040
80 #define R128_FALLBACK_BLEND_EQ 0x0080
81 #define R128_FALLBACK_BLEND_FUNC 0x0100
82 #define R128_FALLBACK_PROJTEX 0x0200
83 #define R128_FALLBACK_DISABLE 0x0400
84
85
86 /* Use the templated vertex format:
87 */
88 #define TAG(x) r128##x
89 #include "tnl_dd/t_dd_vertex.h"
90 #undef TAG
91
92 /* Reasons why the GL_BLEND fallback mightn't work:
93 */
94 #define R128_BLEND_ENV_COLOR 0x1
95 #define R128_BLEND_MULTITEX 0x2
96
97 /* Subpixel offsets for window coordinates (triangles):
98 */
99 #define SUBPIXEL_X (0.0F)
100 #define SUBPIXEL_Y (0.125F)
101
102
103 typedef void (*r128_tri_func)( r128ContextPtr,
104 r128Vertex *,
105 r128Vertex *,
106 r128Vertex * );
107
108 typedef void (*r128_line_func)( r128ContextPtr,
109 r128Vertex *,
110 r128Vertex * );
111
112 typedef void (*r128_point_func)( r128ContextPtr,
113 r128Vertex * );
114
115
116 struct r128_context {
117 GLcontext *glCtx; /* Mesa context */
118
119 /* Driver and hardware state management
120 */
121 GLuint new_state;
122 GLuint dirty; /* Hardware state to be updated */
123 drm_r128_context_regs_t setup;
124
125 /* Vertex state */
126 GLuint vertex_size;
127 GLuint vertex_format;
128 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
129 GLuint vertex_attr_count;
130 char *verts; /* points to tnl->clipspace.vertex_buf */
131 GLuint num_verts;
132 int coloroffset, specoffset;
133 int tnl_state; /* tnl->render_inputs for this _tnl_install_attrs */
134
135 GLuint NewGLState;
136 GLuint Fallback;
137 GLuint RenderIndex;
138 GLfloat hw_viewport[16];
139 GLfloat depth_scale;
140
141 u_int32_t ClearColor; /* Color used to clear color buffer */
142 u_int32_t ClearDepth; /* Value used to clear depth buffer */
143 u_int32_t ClearStencil; /* Value used to clear stencil */
144
145 /* Map GL texture units onto hardware
146 */
147 GLint multitex;
148 GLint tmu_source[2];
149 GLuint tex_combine[2];
150 GLuint blend_flags;
151 GLuint env_color;
152
153 /* Texture object bookkeeping
154 */
155 unsigned nr_heaps;
156 driTexHeap * texture_heaps[ R128_NR_TEX_HEAPS ];
157 driTextureObject swapped;
158
159 r128TexObjPtr CurrentTexObj[2];
160
161 int texture_depth;
162
163 /* Fallback rasterization functions
164 */
165 r128_point_func draw_point;
166 r128_line_func draw_line;
167 r128_tri_func draw_tri;
168
169 /* Vertex buffers
170 */
171 drmBufPtr vert_buf;
172
173 GLuint hw_primitive;
174 GLenum render_primitive;
175
176 /* Page flipping
177 */
178 GLuint doPageFlip;
179
180 /* Cliprect and scissor information
181 */
182 GLuint numClipRects; /* Cliprects for the draw buffer */
183 drm_clip_rect_t *pClipRects;
184
185 GLuint scissor;
186 drm_clip_rect_t ScissorRect; /* Current software scissor */
187
188 /* Mirrors of some DRI state
189 */
190 __DRIcontextPrivate *driContext; /* DRI context */
191 __DRIscreenPrivate *driScreen; /* DRI screen */
192 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
193
194 unsigned int lastStamp; /* mirror driDrawable->lastStamp */
195
196 drm_context_t hHWContext;
197 drm_hw_lock_t *driHwLock;
198 int driFd;
199
200 r128ScreenPtr r128Screen; /* Screen private DRI data */
201 drm_r128_sarea_t *sarea; /* Private SAREA data */
202
203 /* Performance counters
204 */
205 GLuint boxes; /* Draw performance boxes */
206 GLuint hardwareWentIdle;
207 GLuint c_clears;
208 GLuint c_drawWaits;
209 GLuint c_textureSwaps;
210 GLuint c_textureBytes;
211 GLuint c_vertexBuffers;
212
213 /* VBI
214 */
215 GLuint vbl_seq;
216 GLuint vblank_flags;
217
218 /* Configuration cache
219 */
220 driOptionCache optionCache;
221 };
222
223 #define R128_CONTEXT(ctx) ((r128ContextPtr)(ctx->DriverCtx))
224
225 #define R128_IS_PLAIN( rmesa ) \
226 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128)
227 #define R128_IS_PRO( rmesa ) \
228 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_PRO)
229 #define R128_IS_MOBILITY( rmesa ) \
230 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_MOBILITY)
231
232
233 extern GLboolean r128CreateContext( const __GLcontextModes *glVisual,
234 __DRIcontextPrivate *driContextPriv,
235 void *sharedContextPrivate );
236
237 extern void r128DestroyContext( __DRIcontextPrivate * );
238
239 extern GLboolean r128MakeCurrent( __DRIcontextPrivate *driContextPriv,
240 __DRIdrawablePrivate *driDrawPriv,
241 __DRIdrawablePrivate *driReadPriv );
242
243 extern GLboolean r128UnbindContext( __DRIcontextPrivate *driContextPriv );
244
245 /* ================================================================
246 * Debugging:
247 */
248 #define DO_DEBUG 1
249 #define ENABLE_PERF_BOXES 0
250
251 #if DO_DEBUG
252 extern int R128_DEBUG;
253 #else
254 #define R128_DEBUG 0
255 #endif
256
257 #define DEBUG_ALWAYS_SYNC 0x01
258 #define DEBUG_VERBOSE_API 0x02
259 #define DEBUG_VERBOSE_MSG 0x04
260 #define DEBUG_VERBOSE_LRU 0x08
261 #define DEBUG_VERBOSE_DRI 0x10
262 #define DEBUG_VERBOSE_IOCTL 0x20
263 #define DEBUG_VERBOSE_2D 0x40
264 #define DEBUG_VERBOSE_FALL 0x80
265
266 #endif /* __R128_CONTEXT_H__ */