home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / src / xmesap.h < prev   
C/C++ Source or Header  |  1996-05-27  |  12KB  |  400 lines

  1. /* $Id: xmesaP.h,v 1.28 1996/04/25 20:56:58 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995-1996  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Log: xmesaP.h,v $
  26.  * Revision 1.28  1996/04/25  20:56:58  brianp
  27.  * added depth/stencil/accum_size and scrnum fields
  28.  *
  29.  * Revision 1.27  1996/03/02  21:41:05  brianp
  30.  * added PF_8R8G8B pixel format
  31.  *
  32.  * Revision 1.26  1996/03/01  20:04:36  brianp
  33.  * put the swapbytes field back in!
  34.  *
  35.  * Revision 1.25  1996/02/26  16:23:09  brianp
  36.  * added PF_5R6G5B pixel format from Joerg Hessdoerfer
  37.  *
  38.  * Revision 1.24  1996/02/23  17:13:23  brianp
  39.  * removed swapbytes field
  40.  *
  41.  * Revision 1.23  1996/02/06  03:25:43  brianp
  42.  * added new gamma correction code
  43.  *
  44.  * Revision 1.22  1995/12/30  01:04:24  brianp
  45.  * added PACK_8A8B8G8R macro
  46.  * renamed DITHER_8BIT macro as just DITHER
  47.  *
  48.  * Revision 1.21  1995/12/21  17:57:21  brianp
  49.  * added PIXELADDR2 macro, cleaned up the file a bit
  50.  *
  51.  * Revision 1.20  1995/12/13  23:29:48  brianp
  52.  * replaced OFFSET macros with PIXELADDR macros
  53.  *
  54.  * Revision 1.19  1995/11/30  00:51:40  brianp
  55.  * added casts to DITHER_HPCR macro to silence Sun compiler warnings
  56.  *
  57.  * Revision 1.18  1995/11/30  00:20:39  brianp
  58.  * added new PF_GRAYSCALE mode
  59.  *
  60.  * Revision 1.17  1995/10/30  15:14:21  brianp
  61.  * replaced Current variable with XMesa
  62.  *
  63.  * Revision 1.16  1995/10/19  15:50:38  brianp
  64.  * added rgb_flag and share_list fields
  65.  *
  66.  * Revision 1.15  1995/10/17  21:38:17  brianp
  67.  * many changes for new X/Mesa device driver
  68.  *
  69.  * Revision 1.14  1995/09/15  18:49:25  brianp
  70.  * added rowimage span buffer
  71.  *
  72.  * Revision 1.13  1995/08/24  22:07:40  brianp
  73.  * added swapbytes field
  74.  *
  75.  * Revision 1.12  1995/07/24  19:02:30  brianp
  76.  * new comments for PF_DITHER and its tables
  77.  *
  78.  * Revision 1.11  1995/05/31  14:59:55  brianp
  79.  * shm field not dependent on SHM symbol
  80.  *
  81.  * Revision 1.10  1995/05/22  20:59:34  brianp
  82.  * Release 1.2
  83.  *
  84.  * Revision 1.9  1995/04/17  13:57:14  brianp
  85.  * changed to support GLXPixmaps
  86.  *
  87.  * Revision 1.8  1995/03/30  21:10:12  brianp
  88.  * replaced colorpacking with pixelformat
  89.  *
  90.  * Revision 1.7  1995/03/22  21:38:17  brianp
  91.  * *** empty log message ***
  92.  *
  93.  * Revision 1.6  1995/03/13  20:56:23  brianp
  94.  * removed drawbuffer and readbuffer fields
  95.  *
  96.  * Revision 1.5  1995/03/08  15:10:02  brianp
  97.  * added support for dd_logicop
  98.  * added dd_clear_index and dd_clear_color
  99.  *
  100.  * Revision 1.4  1995/03/07  14:21:36  brianp
  101.  * updated for new XSetForeground/GC scheme
  102.  *
  103.  * Revision 1.3  1995/03/04  19:25:29  brianp
  104.  * 1.1 beta revision
  105.  *
  106.  * Revision 1.2  1995/03/02  19:31:42  brianp
  107.  * added defines for FRONT_PIXMAP, BACK_PIXMAP, and BACK_XIMAGE
  108.  *
  109.  * Revision 1.1  1995/02/28  21:23:31  brianp
  110.  * Initial revision
  111.  *
  112.  */
  113.  
  114.  
  115. #ifndef XMESAP_H
  116. #define XMESAP_H
  117.  
  118.  
  119. #ifdef SHM
  120. #  include <X11/extensions/XShm.h>
  121. #endif
  122. #include "GL/xmesa.h"
  123. #include "context.h"
  124.  
  125.  
  126. /*
  127.  * This struct is used by xmesa[12].c and glx.c only!
  128.  */
  129.  
  130.  
  131.  
  132. struct xmesa_context {
  133.         struct gl_context *gl_ctx;    /* the core library context */
  134.  
  135.     GLboolean initialized;    /* Is this context initialized yet? */
  136.  
  137.         GLboolean rgb_flag;    /* In RGBA mode? */
  138.         GLboolean alpha_flag;    /* Need alpha buffer? */
  139.     GLint depth_size;
  140.     GLint stencil_size;
  141.     GLint accum_size;
  142.  
  143.         struct xmesa_context *share_list;
  144.  
  145.     Display *display;    /* the X11 display */
  146.     Visual *visual;        /* the X11 visual */
  147.         int scrnum;        /* screen number */
  148.  
  149.     GC gc1;            /* GC for infrequent color changes */
  150.     GC gc2;            /* GC for frequent color changes */
  151.     GC cleargc;        /* GC for clearing the color buffer */
  152.  
  153.         GLboolean swapbytes;    /* Host byte order != display byte order? */
  154.  
  155.     GLuint db_state;    /* 0 = single buffered */
  156.                 /* BACK_PIXMAP = use Pixmap for back buffer */
  157.                 /* BACK_XIMAGE = use XImage for back buffer */
  158.  
  159.     Drawable frontbuffer;    /* either a window or pixmap */
  160.     Pixmap backpixmap;    /* back buffer Pixmap */
  161.     XImage *backimage;    /* back buffer XImage */
  162.  
  163.         Drawable buffer;    /* the current buffer, either equal to */
  164.                 /* frontbuffer, backpixmap or XIMAGE (None) */
  165.  
  166.     GLuint shm;        /* X Shared Memory extension status:    */
  167.                 /*    0 = not available            */
  168.                 /*    1 = XImage support available    */
  169.                 /*    2 = Pixmap support available too    */
  170. #ifdef SHM
  171.     XShmSegmentInfo shminfo;
  172. #endif
  173.  
  174.         XImage *rowimage;    /* Used for optimized span writing */
  175.  
  176.     GLuint width, height;    /* size of buffer */
  177.     GLuint depth;        /* bits per pixel (1, 8, 24, etc) */
  178.  
  179.         GLint bottom;              /* used for FLIP macro below */
  180.         GLubyte *ximage_origin1;   /* used for PIXELADDR1 macro */
  181.         GLint ximage_width1;
  182.         GLushort *ximage_origin2;  /* used for PIXELADDR2 macro */
  183.         GLint ximage_width2;
  184.         GLuint *ximage_origin4;    /* used for PIXELADDR4 macro */
  185.         GLint ximage_width4;
  186.  
  187.         GLfloat RedGamma;    /* Gamma values, 1.0 is default */
  188.         GLfloat GreenGamma;
  189.         GLfloat BlueGamma;
  190.  
  191.         GLubyte red, green, blue; /* current drawing color */
  192.     unsigned long pixel;      /* current color index or RGBA pixel value */
  193.  
  194.     unsigned long clearpixel; /* pixel for clearing the color buffers */
  195.  
  196.     GLuint pixelformat;    /* Current pixel format */
  197.         GLuint dithered_pf;    /* Pixel format when dithering */
  198.         GLuint undithered_pf;    /* Pixel format when not dithering */
  199.  
  200.     /* For PF_TRUECOLOR */
  201.         GLint rmult, gmult, bmult;    /* Multiplier */
  202.     GLint rshift, gshift, bshift;    /* Bit shifts */
  203.     unsigned long r_to_pixel[256];    /* Converts red to pixel bits */
  204.     unsigned long g_to_pixel[256];    /* Converts green to pixel bits */
  205.     unsigned long b_to_pixel[256];    /* Converts blue to pixel bits */
  206.  
  207.     /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
  208.     unsigned long color_table[256];        /* RGB -> pixel value */
  209.  
  210.     /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
  211.     GLubyte pixel_to_r[65536];        /* pixel value -> red */
  212.     GLubyte pixel_to_g[65536];        /* pixel value -> green */
  213.     GLubyte pixel_to_b[65536];        /* pixel value -> blue */
  214. };
  215.  
  216.  
  217.  
  218. /* Values for XMesa->dest: */
  219. #define FRONT_PIXMAP    1
  220. #define BACK_PIXMAP    2
  221. #define BACK_XIMAGE    4
  222.  
  223.  
  224. /* Values for XMesa->pixelformat: */
  225. #define PF_INDEX    1    /* Color Index mode */
  226. #define PF_TRUECOLOR    2    /* TrueColor or DirectColor, any depth */
  227. #define PF_8A8B8G8R    3    /* 32-bit TrueColor:  8-A, 8-B, 8-G, 8-R */
  228. #define PF_8R8G8B    4    /* 32-bit TrueColor:  8-R, 8-G, 8-B */
  229. #define PF_5R6G5B    5    /* 16-bit TrueColor:  5-R, 6-G, 5-B bits */
  230. #define PF_DITHER    6    /* Dithered RGB using a lookup table */
  231. #define PF_LOOKUP    7    /* Undithered RGB using a lookup table */
  232. #define PF_HPCR        8    /* HP Color Recovery (ad@lms.be 30/08/95) */
  233. #define PF_1BIT        9    /* monochrome dithering of RGB */
  234. #define PF_GRAYSCALE    10    /* Grayscale or StaticGray */
  235.  
  236.  
  237.  
  238. /*
  239.  * If pixelformat==PF_TRUECOLOR:
  240.  */
  241. #define PACK_RGB( R, G, B )        \
  242.     (XMesa->r_to_pixel[R] | XMesa->g_to_pixel[G] | XMesa->b_to_pixel[B])
  243.  
  244.  
  245. /*
  246.  * If pixelformat==PF_8A8B8G8R:
  247.  */
  248. #define PACK_8A8B8G8R( R, G, B, A )    \
  249.     ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
  250.  
  251.  
  252. /*
  253.  * If pixelformat==PF_8R8G8B:
  254.  */
  255. #define PACK_8R8G8B( R, G, B)     ( ((R) << 16) | ((G) << 8) | (B) )
  256.  
  257.  
  258. /*
  259.  * If pixelformat==PF_5R6G5B:
  260.  */
  261. #define PACK_5R6G5B( R, G, B)     ( ((R) << 11) | ((G) << 5) | (B) )
  262.  
  263.  
  264.  
  265. /*
  266.  * If pixelformat==PF_DITHER:
  267.  *
  268.  * Improved 8-bit RGB dithering code contributed by Bob Mercier
  269.  * (mercier@hollywood.cinenet.net).  Thanks Bob!
  270.  */
  271. #define _R    5
  272. #define _G    9
  273. #define _B    5
  274. #define _DX    4
  275. #define _DY    4
  276. #define _D    (_DX*_DY)
  277. #define _MIX(r,g,b)    (((r)*_G+(g))*_B+(b))
  278. /*#define _DITH(C,c,d)    (((unsigned)((_D*(C-1)+1)*c+d))/(_D*256))*/
  279. #define _DITH(C,c,d)    (((unsigned)((_D*(C-1)+1)*c+d)) >> 12)
  280.  
  281. #define MAXC    256
  282. static int kernel8[_DY][_DX] = {
  283.    { 0 * MAXC,  8 * MAXC,  2 * MAXC, 10 * MAXC},
  284.    {12 * MAXC,  4 * MAXC, 14 * MAXC,  6 * MAXC},
  285.    { 3 * MAXC, 11 * MAXC,  1 * MAXC,  9 * MAXC},
  286.    {15 * MAXC,  7 * MAXC, 13 * MAXC,  5 * MAXC},
  287. };
  288. static int __d;
  289. #define DITHER( X, Y, R, G, B )                \
  290.     (__d = kernel8[(Y)&(_DY-1)][(X)&(_DX-1)],    \
  291.      XMesa->color_table[_MIX(_DITH(_R, (R), __d),    \
  292.                  _DITH(_G, (G), __d),    \
  293.                  _DITH(_B, (B), __d))])
  294.  
  295.  
  296.  
  297. /*
  298.  * If pixelformat==PF_LOOKUP:
  299.  */
  300. #define _DITH0(C,c)    (((unsigned)((_D*(C-1)+1)*c)) >> 12)
  301. #define LOOKUP( R, G, B )                \
  302.      XMesa->color_table[_MIX(_DITH0(_R, (R)),    \
  303.                  _DITH0(_G, (G)),    \
  304.                  _DITH0(_B, (B)))]
  305.  
  306.  
  307.  
  308. /*
  309.  * If pixelformat==PF_HPCR:
  310.  *
  311.  *      HP Color Recovery dithering               (ad@lms.be 30/08/95)
  312.  *      HP has on it's 8-bit 700-series computers, a feature called
  313.  *      'Color Recovery'.  This allows near 24-bit output (so they say).
  314.  *      It is enabled by selecting the 8-bit  TrueColor  visual AND
  315.  *      corresponding  colormap (see tkInitWindow) AND doing some special
  316.  *      dither.
  317.  */
  318. static short HPCR_DR[2][16] = {
  319.     { 16, -4,  1,-11, 14, -6,  3, -9, 15, -5,  2,-10, 13, -7,  4, -8},
  320.     {-15,  5,  0, 12,-13,  7, -2, 10,-14,  6, -1, 11,-12,  8, -3,  9} };
  321. static short HPCR_DG[2][16] = {
  322.     {-11, 15, -7,  3, -8, 14, -4,  2,-10, 16, -6,  4, -9, 13, -5,  1},
  323.     { 12,-14,  8, -2,  9,-13,  5, -1, 11,-15,  7, -3, 10,-12,  6,  0} };
  324. static short HPCR_DB[2][16] = {
  325.     {  6,-18, 26,-14,  2,-22, 30,-10,  8,-16, 28,-12,  4,-20, 32, -8},
  326.     { -4, 20,-24, 16,  0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10} };
  327.  
  328. extern short hpcr_rTbl[256], hpcr_gTbl[256], hpcr_bTbl[256];
  329. static int _hpcr_x, _hpcr_y;
  330. #define DITHER_HPCR( X, Y, R, G, B )                \
  331.   (_hpcr_x=((X)%16), _hpcr_y=((Y)%2),                \
  332.    ( ((hpcr_rTbl[R] + HPCR_DR[_hpcr_y][_hpcr_x]) & 0xE0)    \
  333.    |(((hpcr_gTbl[G] + HPCR_DG[_hpcr_y][_hpcr_x]) & 0xE0)>>3)    \
  334.    | ((hpcr_bTbl[B] + HPCR_DB[_hpcr_y][_hpcr_x])>>6)        \
  335.    )                                \
  336.   )
  337.  
  338.  
  339.  
  340. /*
  341.  * If pixelformat==PF_1BIT:
  342.  */
  343. static int kernel1[4][4] = {  0*47,  9*47,  4*47, 12*47,
  344.                   6*47,  2*47, 14*47,  8*47,
  345.                  10*47,  1*47,  5*47, 11*47,
  346.                   7*47, 13*47,  3*47, 15*47 };
  347. #define DITHER_1BIT( X, Y, R, G, B )    \
  348.     ( ((int)(R)+(int)(G)+(int)(B)) > kernel1[(X)&3][(Y)&3] )
  349.  
  350.  
  351.  
  352. /*
  353.  * If pixelformat==PF_GRAYSCALE:
  354.  */
  355. #define GRAY_RGB( R, G, B )   XMesa->color_table[(R) + (G) + (B)]
  356.  
  357.  
  358.  
  359. #define XIMAGE None
  360.  
  361.  
  362. /*
  363.  * Converts a GL window Y coord to an X window Y coord:
  364.  */
  365. #define FLIP(Y)  (XMesa->bottom-(Y))
  366.  
  367.  
  368. /*
  369.  * Return the address of a 1, 2 or 4-byte pixel in the back XImage:
  370.  * X==0 is left, Y==0 is bottom.
  371.  */
  372. #define PIXELADDR1( X, Y )  \
  373.            ( XMesa->ximage_origin1 - (Y) * XMesa->ximage_width1 + (X) )
  374.  
  375. #define PIXELADDR2( X, Y )  \
  376.            ( XMesa->ximage_origin2 - (Y) * XMesa->ximage_width2 + (X) )
  377.  
  378. #define PIXELADDR4( X, Y )  \
  379.            ( XMesa->ximage_origin4 - (Y) * XMesa->ximage_width4 + (X) )
  380.  
  381.  
  382.  
  383. /*
  384.  * External variables:
  385.  */
  386. extern XMesaContext XMesa;
  387.  
  388.  
  389. /*
  390.  * External functions:
  391.  */
  392. extern void xmesa_alloc_back_buffer( XMesaContext c );
  393. extern void xmesa_setup_DD_pointers( void );
  394. extern points_func xmesa_get_points_func( void );
  395. extern line_func xmesa_get_line_func( void );
  396. extern polygon_func xmesa_get_polygon_func( void );
  397.  
  398.  
  399. #endif
  400.