Initial multitexturing support. Old behaviour can be re-enabled by changing ifdefs...
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_context.h
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /*
31 * Authors:
32 * Keith Whitwell <keith@tungstengraphics.com>
33 * Nicolai Haehnle <prefect_@gmx.net>
34 */
35
36 #ifndef __RADEON_CONTEXT_H__
37 #define __RADEON_CONTEXT_H__
38
39 #include "mtypes.h"
40 #include "radeon_screen.h"
41 #include "drm.h"
42 #include "dri_util.h"
43
44 struct radeon_context;
45 typedef struct radeon_context radeonContextRec;
46 typedef struct radeon_context* radeonContextPtr;
47
48 static __inline GLuint radeonPackColor(GLuint cpp,
49 GLubyte r, GLubyte g, GLubyte b, GLubyte a)
50 {
51 switch (cpp) {
52 case 2:
53 return PACK_COLOR_565(r, g, b);
54 case 4:
55 return PACK_COLOR_8888(a, r, g, b);
56 default:
57 return 0;
58 }
59 }
60
61 #define TEX_0 0x1
62 #define TEX_1 0x2
63 #define TEX_2 0x4
64 #define TEX_3 0x8
65 #define TEX_4 0x10
66 #define TEX_5 0x20
67 #define TEX_6 0x40
68 #define TEX_7 0x80
69 #define TEX_ALL 0xff
70
71
72 /* Rasterizing fallbacks */
73 /* See correponding strings in r200_swtcl.c */
74 #define RADEON_FALLBACK_TEXTURE 0x01
75 #define RADEON_FALLBACK_DRAW_BUFFER 0x02
76 #define RADEON_FALLBACK_STENCIL 0x04
77 #define RADEON_FALLBACK_RENDER_MODE 0x08
78 #define RADEON_FALLBACK_BLEND_EQ 0x10
79 #define RADEON_FALLBACK_BLEND_FUNC 0x20
80 #define RADEON_FALLBACK_DISABLE 0x40
81 #define RADEON_FALLBACK_BORDER_MODE 0x80
82
83 extern void radeonFallback(GLcontext * ctx, GLuint bit, GLboolean mode);
84
85 #define FALLBACK( radeon, bit, mode ) do { \
86 if ( 0 ) fprintf( stderr, "FALLBACK in %s: #%d=%d\n", \
87 __FUNCTION__, bit, mode ); \
88 radeonFallback( (radeon)->glCtx, bit, mode ); \
89 } while (0)
90
91
92 /* TCL fallbacks */
93 extern void radeonTclFallback(GLcontext * ctx, GLuint bit, GLboolean mode);
94
95 #define RADEON_TCL_FALLBACK_RASTER 0x0001 /* rasterization */
96 #define RADEON_TCL_FALLBACK_UNFILLED 0x0002 /* unfilled tris */
97 #define RADEON_TCL_FALLBACK_LIGHT_TWOSIDE 0x0004 /* twoside tris */
98 #define RADEON_TCL_FALLBACK_MATERIAL 0x0008 /* material in vb */
99 #define RADEON_TCL_FALLBACK_TEXGEN_0 0x0010 /* texgen, unit 0 */
100 #define RADEON_TCL_FALLBACK_TEXGEN_1 0x0020 /* texgen, unit 1 */
101 #define RADEON_TCL_FALLBACK_TEXGEN_2 0x0040 /* texgen, unit 2 */
102 #define RADEON_TCL_FALLBACK_TEXGEN_3 0x0080 /* texgen, unit 3 */
103 #define RADEON_TCL_FALLBACK_TEXGEN_4 0x0100 /* texgen, unit 4 */
104 #define RADEON_TCL_FALLBACK_TEXGEN_5 0x0200 /* texgen, unit 5 */
105 #define RADEON_TCL_FALLBACK_TCL_DISABLE 0x0400 /* user disable */
106 #define RADEON_TCL_FALLBACK_BITMAP 0x0800 /* draw bitmap with points */
107 #define RADEON_TCL_FALLBACK_VERTEX_PROGRAM 0x1000 /* vertex program active */
108
109 #define TCL_FALLBACK( ctx, bit, mode ) radeonTclFallback( ctx, bit, mode )
110
111
112 struct radeon_dri_mirror {
113 __DRIcontextPrivate *context; /* DRI context */
114 __DRIscreenPrivate *screen; /* DRI screen */
115 __DRIdrawablePrivate *drawable; /* DRI drawable bound to this ctx */
116
117 drm_context_t hwContext;
118 drm_hw_lock_t *hwLock;
119 int fd;
120 int drmMinor;
121 };
122
123 /**
124 * Derived state for internal purposes.
125 */
126 struct radeon_scissor_state {
127 drm_clip_rect_t rect;
128 GLboolean enabled;
129
130 GLuint numClipRects; /* Cliprects active */
131 GLuint numAllocedClipRects; /* Cliprects available */
132 drm_clip_rect_t *pClipRects;
133 };
134
135 struct radeon_colorbuffer_state {
136 GLuint clear;
137 GLint drawOffset, drawPitch;
138 };
139
140 struct radeon_pixel_state {
141 GLint readOffset, readPitch;
142 };
143
144 struct radeon_state {
145 struct radeon_colorbuffer_state color;
146 struct radeon_pixel_state pixel;
147 struct radeon_scissor_state scissor;
148 };
149
150 /**
151 * Common per-context variables shared by R200 and R300.
152 * R200- and R300-specific code "derive" their own context from this
153 * structure.
154 */
155 struct radeon_context {
156 GLcontext *glCtx; /* Mesa context */
157 radeonScreenPtr radeonScreen; /* Screen private DRI data */
158
159 /* Fallback state */
160 GLuint Fallback;
161 GLuint TclFallback;
162
163 /* Page flipping */
164 GLuint doPageFlip;
165
166 /* Drawable, cliprect and scissor information */
167 GLuint numClipRects; /* Cliprects for the draw buffer */
168 drm_clip_rect_t *pClipRects;
169 unsigned int lastStamp;
170 GLboolean lost_context;
171 drm_radeon_sarea_t *sarea; /* Private SAREA data */
172
173 /* Mirrors of some DRI state */
174 struct radeon_dri_mirror dri;
175
176 /* Busy waiting */
177 GLuint do_usleeps;
178 GLuint do_irqs;
179 GLuint irqsEmitted;
180 drm_radeon_irq_wait_t iw;
181
182 /* VBI / buffer swap */
183 GLuint vbl_seq;
184 GLuint vblank_flags;
185
186 int64_t swap_ust;
187 int64_t swap_missed_ust;
188
189 GLuint swap_count;
190 GLuint swap_missed_count;
191
192 PFNGLXGETUSTPROC get_ust;
193
194 /* Derived state */
195 struct radeon_state state;
196
197 /* Configuration cache
198 */
199 driOptionCache optionCache;
200 };
201
202 #define RADEON_CONTEXT(glctx) ((radeonContextPtr)(ctx->DriverCtx))
203
204 extern void radeonSwapBuffers(__DRIdrawablePrivate * dPriv);
205 extern GLboolean radeonInitContext(radeonContextPtr radeon,
206 struct dd_function_table* functions,
207 const __GLcontextModes * glVisual,
208 __DRIcontextPrivate * driContextPriv,
209 void *sharedContextPrivate);
210 extern void radeonCleanupContext(radeonContextPtr radeon);
211 extern GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
212 __DRIdrawablePrivate * driDrawPriv,
213 __DRIdrawablePrivate * driReadPriv);
214 extern GLboolean radeonUnbindContext(__DRIcontextPrivate * driContextPriv);
215
216 /* ================================================================
217 * Debugging:
218 */
219 #define DO_DEBUG 1
220
221 #if DO_DEBUG
222 extern int RADEON_DEBUG;
223 #else
224 #define RADEON_DEBUG 0
225 #endif
226
227 #define DEBUG_TEXTURE 0x0001
228 #define DEBUG_STATE 0x0002
229 #define DEBUG_IOCTL 0x0004
230 #define DEBUG_PRIMS 0x0008
231 #define DEBUG_VERTS 0x0010
232 #define DEBUG_FALLBACKS 0x0020
233 #define DEBUG_VFMT 0x0040
234 #define DEBUG_CODEGEN 0x0080
235 #define DEBUG_VERBOSE 0x0100
236 #define DEBUG_DRI 0x0200
237 #define DEBUG_DMA 0x0400
238 #define DEBUG_SANITY 0x0800
239 #define DEBUG_SYNC 0x1000
240 #define DEBUG_PIXEL 0x2000
241 #define DEBUG_MEMORY 0x4000
242
243 #endif /* __RADEON_CONTEXT_H__ */