-/* $Id: xmesaP.h,v 1.11 2000/07/19 23:26:35 brianp Exp $ */
-
/*
* Mesa 3-D graphics library
- * Version: 3.3
- *
- * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
- *
+ * Version: 6.1
+ *
+ * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ *
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#ifdef XFree86Server
# include "GL/xf86glx.h"
# include "xf86glx_util.h"
-#else
-# ifdef GLX_DIRECT_RENDERING
-# include "dri_mesa.h"
-# endif
-# ifdef USE_XSHM
-# include <X11/extensions/XShm.h>
-# endif
+#elif defined(USE_XSHM)
+# include <X11/extensions/XShm.h>
#endif
#include "GL/xmesa.h"
-#include "types.h"
-#if defined(FX) && !defined(GLX_DIRECT_RENDERING)
+#include "mtypes.h"
+#if defined(FX)
#include "GL/fxmesa.h"
-#include "../FX/fxdrv.h"
-#endif
-
-
-#if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server)
-# include "xdriP.h"
-#else
-# define DRI_DRAWABLE_ARG
-# define DRI_DRAWABLE_PARM
-# define DRI_CTX_ARG
+#include "../glide/fxdrv.h"
#endif
GLint width, GLint height );
+
+
+/** Framebuffer pixel formats */
+enum pixel_format {
+ PF_Index, /**< Color Index mode */
+ PF_Truecolor, /**< TrueColor or DirectColor, any depth */
+ PF_Dither_True, /**< TrueColor with dithering */
+ PF_8A8B8G8R, /**< 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */
+ PF_8R8G8B, /**< 32-bit TrueColor: 8-R, 8-G, 8-B bits */
+ PF_5R6G5B, /**< 16-bit TrueColor: 5-R, 6-G, 5-B bits */
+ PF_Dither, /**< Color-mapped RGB with dither */
+ PF_Lookup, /**< Color-mapped RGB without dither */
+ PF_HPCR, /**< HP Color Recovery (ad@lms.be 30/08/95) */
+ PF_1Bit, /**< monochrome dithering of RGB */
+ PF_Grayscale, /**< Grayscale or StaticGray */
+ PF_8R8G8B24, /**< 24-bit TrueColor: 8-R, 8-G, 8-B bits */
+ PF_Dither_5R6G5B /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */
+};
+
+
/*
- * "Derived" from gl_visual. Basically corresponds to an XVisualInfo.
+ * "Derived" from GLvisual. Basically corresponds to an XVisualInfo.
*/
struct xmesa_visual {
- GLvisual *gl_visual; /* Device independent visual parameters */
+ GLvisual mesa_visual; /* Device independent visual parameters */
XMesaDisplay *display; /* The X11 display */
#ifdef XFree86Server
- GLint screen_depth; /* The depth of the screen */
+ GLint ColormapEntries;
+ GLint nplanes;
#else
- XVisualInfo *vishandle; /* The pointer returned by glXChooseVisual */
+ XMesaVisualInfo visinfo; /* X's visual info (pointer to private copy) */
+ XVisualInfo *vishandle; /* Only used in fakeglx.c */
#endif
- XMesaVisualInfo visinfo; /* X's visual info */
GLint BitsPerPixel; /* True bits per pixel for XImages */
- GLint level; /* 0=normal, 1=overlay, etc */
- GLint VisualCaveat; /* for GLX_EXT_visual_rating extension */
-
GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
- GLuint dithered_pf; /* Pixel format when dithering */
- GLuint undithered_pf; /* Pixel format when not dithering */
+ enum pixel_format dithered_pf; /* Pixel format when dithering */
+ enum pixel_format undithered_pf;/* Pixel format when not dithering */
GLfloat RedGamma; /* Gamma values, 1.0 is default */
GLfloat GreenGamma;
GLfloat BlueGamma;
- GLint rmult, gmult, bmult; /* Range of color values */
- GLint index_bits; /* Bits per pixel in CI mode */
-
/* For PF_TRUECOLOR */
GLint rshift, gshift, bshift;/* Pixel color component shifts */
GLubyte Kernel[16]; /* Dither kernel */
};
-
/*
- * "Derived" from gl_context. Basically corresponds to a GLXContext.
+ * "Derived" from __GLcontextRec. Basically corresponds to a GLXContext.
*/
struct xmesa_context {
- GLcontext *gl_ctx; /* the core library context */
+ GLcontext mesa; /* the core library context (containment) */
XMesaVisual xm_visual; /* Describes the buffers */
- XMesaBuffer xm_buffer; /* current draw framebuffer */
+ XMesaBuffer xm_draw_buffer; /* current draw framebuffer */
XMesaBuffer xm_read_buffer; /* current read framebuffer */
- GLboolean use_read_buffer; /* read from the xm_read_buffer/ */
+ XMesaBuffer xm_buffer; /* current span/point/line/triangle buffer */
XMesaDisplay *display; /* == xm_visual->display */
GLboolean swapbytes; /* Host byte order != display byte order? */
GLboolean direct; /* Direct rendering context? */
- GLuint pixelformat; /* Current pixel format */
-
- GLubyte red, green, blue, alpha; /* current drawing color */
- unsigned long pixel; /* current drawing pixel value */
+ enum pixel_format pixelformat;
GLubyte clearcolor[4]; /* current clearing color */
unsigned long clearpixel; /* current clearing pixel value */
-
-#if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server)
- __DRIcontextPrivate *driContextPriv; /* back pointer to DRI context
- * used for locking
- */
- void *private; /* device-specific private context */
-#endif
};
+typedef enum {
+ WINDOW, /* An X window */
+ GLXWINDOW, /* GLX window */
+ PIXMAP, /* GLX pixmap */
+ PBUFFER /* GLX Pbuffer */
+} BufferType;
+
+
/*
- * "Derived" from gl_buffer. Basically corresponds to a GLXDrawable.
+ * "Derived" from GLframebuffer. Basically corresponds to a GLXDrawable.
*/
struct xmesa_buffer {
+ GLframebuffer mesa_buffer; /* depth, stencil, accum, etc buffers */
+ /* This MUST BE FIRST! */
GLboolean wasCurrent; /* was ever the current buffer? */
- GLframebuffer *gl_buffer; /* depth, stencil, accum, etc buffers */
XMesaVisual xm_visual; /* the X/Mesa visual */
- XMesaContext xm_context; /* the context associated with this buffer */
XMesaDisplay *display;
- GLboolean pixmap_flag; /* is the buffer a Pixmap? */
+ BufferType type; /* window, pixmap, pbuffer or glxwindow */
XMesaDrawable frontbuffer; /* either a window or pixmap */
XMesaPixmap backpixmap; /* back buffer Pixmap */
XMesaImage *backimage; /* back buffer simulated XImage */
XMesaColormap cmap; /* the X colormap */
+ unsigned long selectedEvents;/* for pbuffers only */
+
GLint db_state; /* 0 = single buffered */
/* BACK_PIXMAP = use Pixmap for back buffer */
/* BACK_XIMAGE = use XImage for back buffer */
XMesaImage *rowimage; /* Used for optimized span writing */
- GLuint width, height; /* size of buffer */
-
GLint bottom; /* used for FLIP macro below */
GLubyte *ximage_origin1; /* used for PIXELADDR1 macro */
GLint ximage_width1;
XMesaPixmap stipple_pixmap; /* For polygon stippling */
XMesaGC stipple_gc; /* For polygon stippling */
- XMesaGC gc1; /* GC for infrequent color changes */
- XMesaGC gc2; /* GC for frequent color changes */
+ XMesaGC gc; /* scratch GC for span, line, tri drawing */
XMesaGC cleargc; /* GC for clearing the color buffer */
+ XMesaGC swapgc; /* GC for swapping the color buffers */
/* The following are here instead of in the XMesaVisual
* because they depend on the window's colormap.
/* Used to do XAllocColor/XFreeColors accounting: */
int num_alloced;
+#if defined(XFree86Server)
+ Pixel alloced_colors[256];
+#else
unsigned long alloced_colors[256];
-
-#if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server)
- __DRIdrawablePrivate *driDrawPriv; /* back pointer to DRI drawable
- * used for direct access to framebuffer
- */
- void *private; /* device-specific private drawable */
#endif
-#if defined( FX ) && !defined(GLX_DIRECT_RENDERING)
+#if defined( FX )
/* For 3Dfx Glide only */
GLboolean FXisHackUsable; /* Can we render into window? */
GLboolean FXwindowHack; /* Are we rendering into a window? */
#define BACK_PIXMAP 2
#define BACK_XIMAGE 4
-
-/* Values for xmesa->pixelformat: */
-#define PF_INDEX 1 /* Color Index mode */
-#define PF_TRUECOLOR 2 /* TrueColor or DirectColor, any depth */
-#define PF_TRUEDITHER 3 /* TrueColor with dithering */
-#define PF_8A8B8G8R 4 /* 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */
-#define PF_8R8G8B 5 /* 32-bit TrueColor: 8-R, 8-G, 8-B bits */
-#define PF_5R6G5B 6 /* 16-bit TrueColor: 5-R, 6-G, 5-B bits */
-#define PF_DITHER 7 /* Color-mapped RGB with dither */
-#define PF_LOOKUP 8 /* Color-mapped RGB without dither */
-#define PF_HPCR 9 /* HP Color Recovery (ad@lms.be 30/08/95) */
-#define PF_1BIT 10 /* monochrome dithering of RGB */
-#define PF_GRAYSCALE 11 /* Grayscale or StaticGray */
-#define PF_8R8G8B24 12 /* 24-bit TrueColor: 8-R, 8-G, 8-B bits */
-#define PF_DITHER_5R6G5B 13 /* 16-bit dithered TrueColor: 5-R, 6-G, 5-B */
+/* Special value for X Drawable variables to indicate use of XImage instead */
+#define XIMAGE None
/*
* Improved 8-bit RGB dithering code contributed by Bob Mercier
* (mercier@hollywood.cinenet.net). Thanks Bob!
*/
-#undef _R
-#undef _G
-#undef _B
-#undef _D
#ifdef DITHER666
-# define _R 6
-# define _G 6
-# define _B 6
-# define _MIX(r,g,b) (((r)*_G+(g))*_B+(b))
+# define DITH_R 6
+# define DITH_G 6
+# define DITH_B 6
+# define DITH_MIX(r,g,b) (((r) * DITH_G + (g)) * DITH_B + (b))
#else
-# define _R 5
-# define _G 9
-# define _B 5
-# define _MIX(r,g,b) ( ((g)<<6) | ((b)<<3) | (r) )
+# define DITH_R 5
+# define DITH_G 9
+# define DITH_B 5
+# define DITH_MIX(r,g,b) (((g) << 6) | ((b) << 3) | (r))
#endif
-#define _DX 4
-#define _DY 4
-#define _D (_DX*_DY)
+#define DITH_DX 4
+#define DITH_DY 4
+#define DITH_N (DITH_DX * DITH_DY)
-/*#define _DITH(C,c,d) (((unsigned)((_D*(C-1)+1)*c+d))/(_D*256))*/
-#define _DITH(C,c,d) (((unsigned)((_D*(C-1)+1)*c+d)) >> 12)
+#define _dither(C, c, d) (((unsigned)((DITH_N * (C - 1) + 1) * c + d)) >> 12)
#define MAXC 256
-static int kernel8[_DY*_DX] = {
- 0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC,
- 12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC,
- 3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC,
- 15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC,
-};
-/*static int __d;*/
+extern const int xmesa_kernel8[DITH_DY * DITH_DX];
/* Dither for random X,Y */
#define DITHER_SETUP \
unsigned long *ctable = xmesa->xm_buffer->color_table;
#define DITHER( X, Y, R, G, B ) \
- (__d = kernel8[(((Y)&3)<<2) | ((X)&3)], \
- ctable[_MIX(_DITH(_R, (R), __d), \
- _DITH(_G, (G), __d), \
- _DITH(_B, (B), __d))])
+ (__d = xmesa_kernel8[(((Y)&3)<<2) | ((X)&3)], \
+ ctable[DITH_MIX(_dither(DITH_R, (R), __d), \
+ _dither(DITH_G, (G), __d), \
+ _dither(DITH_B, (B), __d))])
/* Dither for random X, fixed Y */
#define XDITHER_SETUP(Y) \
int __d; \
unsigned long *ctable = xmesa->xm_buffer->color_table; \
- int *kernel = &kernel8[ ((Y)&3) << 2 ];
+ const int *kernel = &xmesa_kernel8[ ((Y)&3) << 2 ];
#define XDITHER( X, R, G, B ) \
(__d = kernel[(X)&3], \
- ctable[_MIX(_DITH(_R, (R), __d), \
- _DITH(_G, (G), __d), \
- _DITH(_B, (B), __d))])
+ ctable[DITH_MIX(_dither(DITH_R, (R), __d), \
+ _dither(DITH_G, (G), __d), \
+ _dither(DITH_B, (B), __d))])
* Dithering for flat-shaded triangles. Precompute all 16 possible
* pixel values given the triangle's RGB color. Contributed by Martin Shenk.
*/
-static GLushort DitherValues[16]; /* array of (up to) 16-bit pixel values */
-
#define FLAT_DITHER_SETUP( R, G, B ) \
+ GLushort ditherValues[16]; \
{ \
unsigned long *ctable = xmesa->xm_buffer->color_table; \
- int msdr = (_D*((_R)-1)+1) * (R); \
- int msdg = (_D*((_G)-1)+1) * (G); \
- int msdb = (_D*((_B)-1)+1) * (B); \
+ int msdr = (DITH_N*((DITH_R)-1)+1) * (R); \
+ int msdg = (DITH_N*((DITH_G)-1)+1) * (G); \
+ int msdb = (DITH_N*((DITH_B)-1)+1) * (B); \
int i; \
for (i=0;i<16;i++) { \
- int k = kernel8[i]; \
- int j = _MIX( (msdr+k)>>12, (msdg+k)>>12, (msdb+k)>>12 ); \
- DitherValues[i] = (GLushort) ctable[j]; \
+ int k = xmesa_kernel8[i]; \
+ int j = DITH_MIX( (msdr+k)>>12, (msdg+k)>>12, (msdb+k)>>12 );\
+ ditherValues[i] = (GLushort) ctable[j]; \
} \
}
#define FLAT_DITHER_ROW_SETUP(Y) \
- GLushort *ditherRow = DitherValues + ( ((Y)&3) << 2);
+ GLushort *ditherRow = ditherValues + ( ((Y)&3) << 2);
#define FLAT_DITHER(X) ditherRow[(X)&3]
/*
* If pixelformat==PF_LOOKUP:
*/
-#define _DITH0(C,c) (((unsigned)((_D*(C-1)+1)*c)) >> 12)
+#define _dither_lookup(C, c) (((unsigned)((DITH_N * (C - 1) + 1) * c)) >> 12)
#define LOOKUP_SETUP \
unsigned long *ctable = xmesa->xm_buffer->color_table
-#define LOOKUP( R, G, B ) \
- ctable[_MIX(_DITH0(_R, (R)), \
- _DITH0(_G, (G)), \
- _DITH0(_B, (B)))]
+#define LOOKUP( R, G, B ) \
+ ctable[DITH_MIX(_dither_lookup(DITH_R, (R)), \
+ _dither_lookup(DITH_G, (G)), \
+ _dither_lookup(DITH_B, (B)))]
* corresponding colormap (see tkInitWindow) AND doing some special
* dither.
*/
-static const short HPCR_DRGB[3][2][16] = {
-{
- { 16, -4, 1,-11, 14, -6, 3, -9, 15, -5, 2,-10, 13, -7, 4, -8},
- {-15, 5, 0, 12,-13, 7, -2, 10,-14, 6, -1, 11,-12, 8, -3, 9}
-},
-{
- {-11, 15, -7, 3, -8, 14, -4, 2,-10, 16, -6, 4, -9, 13, -5, 1},
- { 12,-14, 8, -2, 9,-13, 5, -1, 11,-15, 7, -3, 10,-12, 6, 0}
-},
-{
- { 6,-18, 26,-14, 2,-22, 30,-10, 8,-16, 28,-12, 4,-20, 32, -8},
- { -4, 20,-24, 16, 0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10}
-}
-};
+extern const short xmesa_HPCR_DRGB[3][2][16];
#define DITHER_HPCR( X, Y, R, G, B ) \
- ( ((xmesa->xm_visual->hpcr_rgbTbl[0][R] + HPCR_DRGB[0][(Y)&1][(X)&15]) & 0xE0) \
- |(((xmesa->xm_visual->hpcr_rgbTbl[1][G] + HPCR_DRGB[1][(Y)&1][(X)&15]) & 0xE0)>>3) \
- | ((xmesa->xm_visual->hpcr_rgbTbl[2][B] + HPCR_DRGB[2][(Y)&1][(X)&15])>>6) \
+ ( ((xmesa->xm_visual->hpcr_rgbTbl[0][R] + xmesa_HPCR_DRGB[0][(Y)&1][(X)&15]) & 0xE0) \
+ |(((xmesa->xm_visual->hpcr_rgbTbl[1][G] + xmesa_HPCR_DRGB[1][(Y)&1][(X)&15]) & 0xE0)>>3) \
+ | ((xmesa->xm_visual->hpcr_rgbTbl[2][B] + xmesa_HPCR_DRGB[2][(Y)&1][(X)&15])>>6) \
)
/*
* If pixelformat==PF_1BIT:
*/
-static int const kernel1[16] = {
- 0*47, 9*47, 4*47, 12*47, /* 47 = (255*3)/16 */
- 6*47, 2*47, 14*47, 8*47,
- 10*47, 1*47, 5*47, 11*47,
- 7*47, 13*47, 3*47, 15*47 };
+extern const int xmesa_kernel1[16];
#define SETUP_1BIT int bitFlip = xmesa->xm_visual->bitFlip
#define DITHER_1BIT( X, Y, R, G, B ) \
- (( ((int)(R)+(int)(G)+(int)(B)) > kernel1[(((Y)&3) << 2) | ((X)&3)] ) ^ bitFlip)
+ (( ((int)(R)+(int)(G)+(int)(B)) > xmesa_kernel1[(((Y)&3) << 2) | ((X)&3)] ) ^ bitFlip)
-#define XIMAGE None
-
-
/*
* Converts a GL window Y coord to an X window Y coord:
*/
+
+/*
+ * Return pointer to XMesaContext corresponding to a Mesa GLcontext.
+ * Since we're using structure containment, it's just a cast!.
+ */
+#define XMESA_CONTEXT(MESACTX) (XMesaContext) (MESACTX)
+
+
+
/*
* External functions:
*/
extern unsigned long
-xmesa_color_to_pixel( XMesaContext xmesa, GLubyte r, GLubyte g, GLubyte b, GLubyte a,
+xmesa_color_to_pixel( XMesaContext xmesa,
+ GLubyte r, GLubyte g, GLubyte b, GLubyte a,
GLuint pixelFormat );
extern void xmesa_alloc_back_buffer( XMesaBuffer b );
-extern void xmesa_update_state( GLcontext *ctx );
+extern void xmesa_resize_buffers( GLframebuffer *buffer );
+
+extern void xmesa_init_driver_functions( XMesaVisual xmvisual,
+ struct dd_function_table *driver );
-extern points_func xmesa_get_points_func( GLcontext *ctx );
+extern void xmesa_update_state( GLcontext *ctx, GLuint new_state );
-extern line_func xmesa_get_line_func( GLcontext *ctx );
+extern void xmesa_update_span_funcs( GLcontext *ctx );
+
+extern void xmesa_set_buffer( GLcontext *ctx, GLframebuffer *buffer,
+ GLuint bufferBit );
+
+
+/* Plugged into the software rasterizer. Try to use internal
+ * swrast-style point, line and triangle functions.
+ */
+extern void xmesa_choose_point( GLcontext *ctx );
+extern void xmesa_choose_line( GLcontext *ctx );
+extern void xmesa_choose_triangle( GLcontext *ctx );
+
+
+extern void xmesa_register_swrast_functions( GLcontext *ctx );
-extern triangle_func xmesa_get_triangle_func( GLcontext *ctx );
/* XXX this is a hack to implement shared display lists with 3Dfx */
extern XMesaBuffer XMesaCreateWindowBuffer2( XMesaVisual v,
XMesaWindow w,
- XMesaContext c
- DRI_DRAWABLE_ARG
- );
+ XMesaContext c );
/*
* These are the extra routines required for integration with XFree86.
extern GLboolean XMesaLoseCurrent(XMesaContext c);
extern void XMesaReset( void );
+
+#define SWTC 0 /* SW texture compression */
+
+
#endif