gl: Remove unused GLcontextModes fields
[mesa.git] / src / mesa / drivers / x11 / xmesaP.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #ifndef XMESAP_H
27 #define XMESAP_H
28
29
30 #include "xmesa.h"
31 #include "main/mtypes.h"
32 #if defined(FX)
33 #include "fxmesa.h"
34 #include "xm_glide.h"
35 #endif
36 #ifdef XFree86Server
37 #include "xm_image.h"
38 #endif
39
40
41 extern _glthread_Mutex _xmesa_lock;
42
43 extern XMesaBuffer XMesaBufferList;
44
45 /* for PF_8R8G8B24 pixel format */
46 typedef struct {
47 GLubyte b;
48 GLubyte g;
49 GLubyte r;
50 } bgr_t;
51
52
53 struct xmesa_renderbuffer;
54
55
56 /* Function pointer for clearing color buffers */
57 typedef void (*ClearFunc)( GLcontext *ctx, struct xmesa_renderbuffer *xrb,
58 GLint x, GLint y, GLint width, GLint height );
59
60
61
62
63 /** Framebuffer pixel formats */
64 enum pixel_format {
65 PF_Index, /**< Color Index mode */
66 PF_Truecolor, /**< TrueColor or DirectColor, any depth */
67 PF_Dither_True, /**< TrueColor with dithering */
68 PF_8A8R8G8B, /**< 32-bit TrueColor: 8-A, 8-R, 8-G, 8-B bits */
69 PF_8A8B8G8R, /**< 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R bits */
70 PF_8R8G8B, /**< 32-bit TrueColor: 8-R, 8-G, 8-B bits */
71 PF_8R8G8B24, /**< 24-bit TrueColor: 8-R, 8-G, 8-B bits */
72 PF_5R6G5B, /**< 16-bit TrueColor: 5-R, 6-G, 5-B bits */
73 PF_Dither, /**< Color-mapped RGB with dither */
74 PF_Lookup, /**< Color-mapped RGB without dither */
75 PF_HPCR, /**< HP Color Recovery (ad@lms.be 30/08/95) */
76 PF_1Bit, /**< monochrome dithering of RGB */
77 PF_Grayscale, /**< Grayscale or StaticGray */
78 PF_Dither_5R6G5B /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */
79 };
80
81
82 /**
83 * Visual inforation, derived from GLvisual.
84 * Basically corresponds to an XVisualInfo.
85 */
86 struct xmesa_visual {
87 GLvisual mesa_visual; /* Device independent visual parameters */
88 XMesaDisplay *display; /* The X11 display */
89 int screen, visualID;
90 #ifdef XFree86Server
91 GLint ColormapEntries;
92 GLint nplanes;
93 #else
94 XMesaVisualInfo visinfo; /* X's visual info (pointer to private copy) */
95 XVisualInfo *vishandle; /* Only used in fakeglx.c */
96 #endif
97 GLint BitsPerPixel; /* True bits per pixel for XImages */
98
99 GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
100
101 enum pixel_format dithered_pf; /* Pixel format when dithering */
102 enum pixel_format undithered_pf;/* Pixel format when not dithering */
103
104 GLfloat RedGamma; /* Gamma values, 1.0 is default */
105 GLfloat GreenGamma;
106 GLfloat BlueGamma;
107
108 /* For PF_TRUECOLOR */
109 GLint rshift, gshift, bshift;/* Pixel color component shifts */
110 GLubyte Kernel[16]; /* Dither kernel */
111 unsigned long RtoPixel[512]; /* RGB to pixel conversion */
112 unsigned long GtoPixel[512];
113 unsigned long BtoPixel[512];
114 GLubyte PixelToR[256]; /* Pixel to RGB conversion */
115 GLubyte PixelToG[256];
116 GLubyte PixelToB[256];
117
118 /* For PF_HPCR */
119 short hpcr_rgbTbl[3][256];
120 GLboolean hpcr_clear_flag;
121 GLubyte hpcr_clear_ximage_pattern[2][16];
122 XMesaImage *hpcr_clear_ximage;
123 XMesaPixmap hpcr_clear_pixmap;
124
125 /* For PF_1BIT */
126 int bitFlip;
127 };
128
129
130 /**
131 * Context info, derived from GLcontext.
132 * Basically corresponds to a GLXContext.
133 */
134 struct xmesa_context {
135 GLcontext mesa; /* the core library context (containment) */
136 XMesaVisual xm_visual; /* Describes the buffers */
137 XMesaBuffer xm_buffer; /* current span/point/line/triangle buffer */
138
139 XMesaDisplay *display; /* == xm_visual->display */
140 GLboolean swapbytes; /* Host byte order != display byte order? */
141 GLboolean direct; /* Direct rendering context? */
142
143 enum pixel_format pixelformat;
144
145 GLubyte clearcolor[4]; /* current clearing color */
146 unsigned long clearpixel; /* current clearing pixel value */
147 };
148
149
150 /**
151 * Types of X/GLX drawables we might render into.
152 */
153 typedef enum {
154 WINDOW, /* An X window */
155 GLXWINDOW, /* GLX window */
156 PIXMAP, /* GLX pixmap */
157 PBUFFER /* GLX Pbuffer */
158 } BufferType;
159
160
161 /** Values for db_mode: */
162 /*@{*/
163 #define BACK_PIXMAP 1
164 #define BACK_XIMAGE 2
165 /*@}*/
166
167
168 /**
169 * An xmesa_renderbuffer represents the back or front color buffer.
170 * For the front color buffer:
171 * <drawable> is the X window
172 * For the back color buffer:
173 * Either <ximage> or <pixmap> will be used, never both.
174 * In any case, <drawable> always equals <pixmap>.
175 * For stand-alone Mesa, we could merge <drawable> and <pixmap> into one
176 * field. We don't do that for the server-side GLcore module because
177 * pixmaps and drawables are different and we'd need a bunch of casts.
178 */
179 struct xmesa_renderbuffer
180 {
181 struct gl_renderbuffer Base; /* Base class */
182
183 XMesaBuffer Parent; /**< The XMesaBuffer this renderbuffer belongs to */
184 XMesaDrawable drawable; /* Usually the X window ID */
185 XMesaPixmap pixmap; /* Back color buffer */
186 XMesaImage *ximage; /* The back buffer, if not using a Pixmap */
187
188 GLubyte *origin1; /* used for PIXEL_ADDR1 macro */
189 GLint width1;
190 GLushort *origin2; /* used for PIXEL_ADDR2 macro */
191 GLint width2;
192 GLubyte *origin3; /* used for PIXEL_ADDR3 macro */
193 GLint width3;
194 GLuint *origin4; /* used for PIXEL_ADDR4 macro */
195 GLint width4;
196
197 GLint bottom; /* used for FLIP macro, equals height - 1 */
198
199 ClearFunc clearFunc;
200 };
201
202
203 /**
204 * Framebuffer information, derived from.
205 * Basically corresponds to a GLXDrawable.
206 */
207 struct xmesa_buffer {
208 GLframebuffer mesa_buffer; /* depth, stencil, accum, etc buffers */
209 /* This MUST BE FIRST! */
210 GLboolean wasCurrent; /* was ever the current buffer? */
211 XMesaVisual xm_visual; /* the X/Mesa visual */
212
213 XMesaDisplay *display;
214 BufferType type; /* window, pixmap, pbuffer or glxwindow */
215
216 GLboolean largestPbuffer; /**< for pbuffers */
217 GLboolean preservedContents; /**< for pbuffers */
218
219 struct xmesa_renderbuffer *frontxrb; /* front color renderbuffer */
220 struct xmesa_renderbuffer *backxrb; /* back color renderbuffer */
221
222 XMesaColormap cmap; /* the X colormap */
223
224 unsigned long selectedEvents;/* for pbuffers only */
225
226 GLint db_mode; /* 0 = single buffered */
227 /* BACK_PIXMAP = use Pixmap for back buffer */
228 /* BACK_XIMAGE = use XImage for back buffer */
229 GLboolean swAlpha;
230
231 GLuint shm; /* X Shared Memory extension status: */
232 /* 0 = not available */
233 /* 1 = XImage support available */
234 /* 2 = Pixmap support available too */
235 #if defined(USE_XSHM) && !defined(XFree86Server)
236 XShmSegmentInfo shminfo;
237 #endif
238
239 XMesaImage *rowimage; /* Used for optimized span writing */
240 XMesaPixmap stipple_pixmap; /* For polygon stippling */
241 XMesaGC stipple_gc; /* For polygon stippling */
242
243 XMesaGC gc; /* scratch GC for span, line, tri drawing */
244 XMesaGC cleargc; /* GC for clearing the color buffer */
245 XMesaGC swapgc; /* GC for swapping the color buffers */
246
247 /* The following are here instead of in the XMesaVisual
248 * because they depend on the window's colormap.
249 */
250
251 /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
252 unsigned long color_table[576]; /* RGB -> pixel value */
253
254 /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
255 GLubyte pixel_to_r[65536]; /* pixel value -> red */
256 GLubyte pixel_to_g[65536]; /* pixel value -> green */
257 GLubyte pixel_to_b[65536]; /* pixel value -> blue */
258
259 /* Used to do XAllocColor/XFreeColors accounting: */
260 int num_alloced;
261 #if defined(XFree86Server)
262 Pixel alloced_colors[256];
263 #else
264 unsigned long alloced_colors[256];
265 #endif
266
267 #if defined( FX )
268 /* For 3Dfx Glide only */
269 GLboolean FXisHackUsable; /* Can we render into window? */
270 GLboolean FXwindowHack; /* Are we rendering into a window? */
271 fxMesaContext FXctx;
272 #endif
273
274 /* GLX_EXT_texture_from_pixmap */
275 GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
276 GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
277 GLint TextureMipmap; /** 0 or 1 */
278
279 struct xmesa_buffer *Next; /* Linked list pointer: */
280 };
281
282
283 /**
284 * If pixelformat==PF_TRUECOLOR:
285 */
286 #define PACK_TRUECOLOR( PIXEL, R, G, B ) \
287 PIXEL = xmesa->xm_visual->RtoPixel[R] \
288 | xmesa->xm_visual->GtoPixel[G] \
289 | xmesa->xm_visual->BtoPixel[B]; \
290
291
292 /**
293 * If pixelformat==PF_TRUEDITHER:
294 */
295 #define PACK_TRUEDITHER( PIXEL, X, Y, R, G, B ) \
296 { \
297 int d = xmesa->xm_visual->Kernel[((X)&3) | (((Y)&3)<<2)]; \
298 PIXEL = xmesa->xm_visual->RtoPixel[(R)+d] \
299 | xmesa->xm_visual->GtoPixel[(G)+d] \
300 | xmesa->xm_visual->BtoPixel[(B)+d]; \
301 }
302
303
304
305 /**
306 * If pixelformat==PF_8A8B8G8R:
307 */
308 #define PACK_8A8B8G8R( R, G, B, A ) \
309 ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
310
311
312 /**
313 * Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable
314 * shortcut.
315 */
316 #define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
317
318
319
320 /**
321 * If pixelformat==PF_8R8G8B:
322 */
323 #define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) )
324
325
326 /**
327 * If pixelformat==PF_5R6G5B:
328 */
329 #define PACK_5R6G5B( R, G, B) ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) )
330
331
332 /**
333 * If pixelformat==PF_8A8R8G8B:
334 */
335 #define PACK_8A8R8G8B( R, G, B, A ) \
336 ( ((A) << 24) | ((R) << 16) | ((G) << 8) | (B) )
337
338
339
340 /**
341 * If pixelformat==PF_DITHER:
342 *
343 * Improved 8-bit RGB dithering code contributed by Bob Mercier
344 * (mercier@hollywood.cinenet.net). Thanks Bob!
345 */
346 #ifdef DITHER666
347 # define DITH_R 6
348 # define DITH_G 6
349 # define DITH_B 6
350 # define DITH_MIX(r,g,b) (((r) * DITH_G + (g)) * DITH_B + (b))
351 #else
352 # define DITH_R 5
353 # define DITH_G 9
354 # define DITH_B 5
355 # define DITH_MIX(r,g,b) (((g) << 6) | ((b) << 3) | (r))
356 #endif
357 #define DITH_DX 4
358 #define DITH_DY 4
359 #define DITH_N (DITH_DX * DITH_DY)
360
361 #define _dither(C, c, d) (((unsigned)((DITH_N * (C - 1) + 1) * c + d)) >> 12)
362
363 #define MAXC 256
364 extern const int xmesa_kernel8[DITH_DY * DITH_DX];
365
366 /* Dither for random X,Y */
367 #define DITHER_SETUP \
368 int __d; \
369 unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table;
370
371 #define DITHER( X, Y, R, G, B ) \
372 (__d = xmesa_kernel8[(((Y)&3)<<2) | ((X)&3)], \
373 ctable[DITH_MIX(_dither(DITH_R, (R), __d), \
374 _dither(DITH_G, (G), __d), \
375 _dither(DITH_B, (B), __d))])
376
377 /* Dither for random X, fixed Y */
378 #define XDITHER_SETUP(Y) \
379 int __d; \
380 unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table; \
381 const int *kernel = &xmesa_kernel8[ ((Y)&3) << 2 ];
382
383 #define XDITHER( X, R, G, B ) \
384 (__d = kernel[(X)&3], \
385 ctable[DITH_MIX(_dither(DITH_R, (R), __d), \
386 _dither(DITH_G, (G), __d), \
387 _dither(DITH_B, (B), __d))])
388
389
390
391 /*
392 * Dithering for flat-shaded triangles. Precompute all 16 possible
393 * pixel values given the triangle's RGB color. Contributed by Martin Shenk.
394 */
395 #define FLAT_DITHER_SETUP( R, G, B ) \
396 GLushort ditherValues[16]; \
397 { \
398 unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table; \
399 int msdr = (DITH_N*((DITH_R)-1)+1) * (R); \
400 int msdg = (DITH_N*((DITH_G)-1)+1) * (G); \
401 int msdb = (DITH_N*((DITH_B)-1)+1) * (B); \
402 int i; \
403 for (i=0;i<16;i++) { \
404 int k = xmesa_kernel8[i]; \
405 int j = DITH_MIX( (msdr+k)>>12, (msdg+k)>>12, (msdb+k)>>12 );\
406 ditherValues[i] = (GLushort) ctable[j]; \
407 } \
408 }
409
410 #define FLAT_DITHER_ROW_SETUP(Y) \
411 GLushort *ditherRow = ditherValues + ( ((Y)&3) << 2);
412
413 #define FLAT_DITHER(X) ditherRow[(X)&3]
414
415
416
417 /**
418 * If pixelformat==PF_LOOKUP:
419 */
420 #define _dither_lookup(C, c) (((unsigned)((DITH_N * (C - 1) + 1) * c)) >> 12)
421
422 #define LOOKUP_SETUP \
423 unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table
424
425 #define LOOKUP( R, G, B ) \
426 ctable[DITH_MIX(_dither_lookup(DITH_R, (R)), \
427 _dither_lookup(DITH_G, (G)), \
428 _dither_lookup(DITH_B, (B)))]
429
430
431 /**
432 * If pixelformat==PF_HPCR:
433 *
434 * HP Color Recovery dithering (ad@lms.be 30/08/95)
435 * HP has on its 8-bit 700-series computers, a feature called
436 * 'Color Recovery'. This allows near 24-bit output (so they say).
437 * It is enabled by selecting the 8-bit TrueColor visual AND
438 * corresponding colormap (see tkInitWindow) AND doing some special
439 * dither.
440 */
441 extern const short xmesa_HPCR_DRGB[3][2][16];
442
443 #define DITHER_HPCR( X, Y, R, G, B ) \
444 ( ((xmesa->xm_visual->hpcr_rgbTbl[0][R] + xmesa_HPCR_DRGB[0][(Y)&1][(X)&15]) & 0xE0) \
445 |(((xmesa->xm_visual->hpcr_rgbTbl[1][G] + xmesa_HPCR_DRGB[1][(Y)&1][(X)&15]) & 0xE0)>>3) \
446 | ((xmesa->xm_visual->hpcr_rgbTbl[2][B] + xmesa_HPCR_DRGB[2][(Y)&1][(X)&15])>>6) \
447 )
448
449
450
451 /**
452 * If pixelformat==PF_1BIT:
453 */
454 extern const int xmesa_kernel1[16];
455
456 #define SETUP_1BIT int bitFlip = xmesa->xm_visual->bitFlip
457 #define DITHER_1BIT( X, Y, R, G, B ) \
458 (( ((int)(R)+(int)(G)+(int)(B)) > xmesa_kernel1[(((Y)&3) << 2) | ((X)&3)] ) ^ bitFlip)
459
460
461
462 /**
463 * If pixelformat==PF_GRAYSCALE:
464 */
465 #define GRAY_RGB( R, G, B ) XMESA_BUFFER(ctx->DrawBuffer)->color_table[((R) + (G) + (B))/3]
466
467
468
469 /**
470 * Converts a GL window Y coord to an X window Y coord:
471 */
472 #define YFLIP(XRB, Y) ((XRB)->bottom - (Y))
473
474
475 /**
476 * Return the address of a 1, 2 or 4-byte pixel in the buffer's XImage:
477 * X==0 is left, Y==0 is bottom.
478 */
479 #define PIXEL_ADDR1(XRB, X, Y) \
480 ( (XRB)->origin1 - (Y) * (XRB)->width1 + (X) )
481
482 #define PIXEL_ADDR2(XRB, X, Y) \
483 ( (XRB)->origin2 - (Y) * (XRB)->width2 + (X) )
484
485 #define PIXEL_ADDR3(XRB, X, Y) \
486 ( (bgr_t *) ( (XRB)->origin3 - (Y) * (XRB)->width3 + 3 * (X) ))
487
488 #define PIXEL_ADDR4(XRB, X, Y) \
489 ( (XRB)->origin4 - (Y) * (XRB)->width4 + (X) )
490
491
492
493 /*
494 * External functions:
495 */
496
497 extern struct xmesa_renderbuffer *
498 xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual,
499 GLboolean backBuffer);
500
501 extern void
502 xmesa_delete_framebuffer(struct gl_framebuffer *fb);
503
504 extern XMesaBuffer
505 xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis);
506
507 extern unsigned long
508 xmesa_color_to_pixel( GLcontext *ctx,
509 GLubyte r, GLubyte g, GLubyte b, GLubyte a,
510 GLuint pixelFormat );
511
512 extern void
513 xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b,
514 GLuint *width, GLuint *height);
515
516 extern void
517 xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer);
518
519 extern void
520 xmesa_init_driver_functions( XMesaVisual xmvisual,
521 struct dd_function_table *driver );
522
523 extern void
524 xmesa_update_state( GLcontext *ctx, GLbitfield new_state );
525
526 extern void
527 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
528 enum pixel_format pixelformat, GLint depth);
529
530 extern void
531 xmesa_destroy_buffers_on_display(XMesaDisplay *dpy);
532
533
534 /**
535 * Using a function instead of an ordinary cast is safer.
536 */
537 static INLINE struct xmesa_renderbuffer *
538 xmesa_renderbuffer(struct gl_renderbuffer *rb)
539 {
540 return (struct xmesa_renderbuffer *) rb;
541 }
542
543
544 /**
545 * Return pointer to XMesaContext corresponding to a Mesa GLcontext.
546 * Since we're using structure containment, it's just a cast!.
547 */
548 static INLINE XMesaContext
549 XMESA_CONTEXT(GLcontext *ctx)
550 {
551 return (XMesaContext) ctx;
552 }
553
554
555 /**
556 * Return pointer to XMesaBuffer corresponding to a Mesa GLframebuffer.
557 * Since we're using structure containment, it's just a cast!.
558 */
559 static INLINE XMesaBuffer
560 XMESA_BUFFER(GLframebuffer *b)
561 {
562 return (XMesaBuffer) b;
563 }
564
565
566 /* Plugged into the software rasterizer. Try to use internal
567 * swrast-style point, line and triangle functions.
568 */
569 extern void xmesa_choose_point( GLcontext *ctx );
570 extern void xmesa_choose_line( GLcontext *ctx );
571 extern void xmesa_choose_triangle( GLcontext *ctx );
572
573
574 extern void xmesa_register_swrast_functions( GLcontext *ctx );
575
576
577
578 #define ENABLE_EXT_texure_compression_s3tc 0 /* SW texture compression */
579
580 #ifdef XFree86Server
581 #define ENABLE_EXT_timer_query 0
582 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
583 #define ENABLE_EXT_timer_query 1 /* should have 64-bit GLuint64EXT */
584 #else
585 #define ENABLE_EXT_timer_query 0 /* may not have 64-bit GLuint64EXT */
586 #endif
587
588
589 #define TEST_META_FUNCS 0
590
591
592 #endif