Debian Codegraph @

debian/external_deps/fetk/sg/src/gl/xmesaP.h

raw
1 /* $Id: xmesaP.h,v 1.2 2000/10/27 15:21:41 mholst Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 2.2
6 * Copyright (C) 1995-1997 Brian Paul
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 #ifndef XMESAP_H
24 #define XMESAP_H
25
26
27 #ifdef SHM
28 # include <X11/extensions/XShm.h>
29 #endif
30 #include "GL/xmesa.h"
31 #include "types.h"
32
33
34
35 /*
36 * Mesa wrapper for XVisualInfo
37 */
38 struct xmesa_visual {
39 GLvisual *gl_visual; /* Device independent visual parameters */
40 Display *display; /* The X11 display */
41 XVisualInfo *vishandle; /* The pointer returned by glXChooseVisual */
42 XVisualInfo *visinfo; /* Private copy of vishandle's struct */
43
44 GLint level; /* 0=normal, 1=overlay, etc */
45
46 GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
47
48 GLuint dithered_pf; /* Pixel format when dithering */
49 GLuint undithered_pf; /* Pixel format when not dithering */
50
51 GLfloat RedGamma; /* Gamma values, 1.0 is default */
52 GLfloat GreenGamma;
53 GLfloat BlueGamma;
54
55 GLint rmult, gmult, bmult; /* Range of color values */
56 GLint index_bits; /* Bits per pixel in CI mode */
57
58 /* For PF_TRUECOLOR */
59 GLint rshift, gshift, bshift; /* Bit shifts */
60 unsigned long r_to_pixel[256]; /* Converts red to pixel bits */
61 unsigned long g_to_pixel[256]; /* Converts green to pixel bits */
62 unsigned long b_to_pixel[256]; /* Converts blue to pixel bits */
63
64 /* For PF_HPCR */
65 short hpcr_rTbl[256], hpcr_gTbl[256], hpcr_bTbl[256];
66 };
67
68
69
70 /*
71 * Mesa wrapper for core rendering context
72 */
73 struct xmesa_context {
74 GLcontext *gl_ctx; /* the core library context */
75 XMesaVisual xm_visual; /* Describes the buffers */
76 XMesaBuffer xm_buffer; /* current framebuffer */
77
78 Display *display; /* == xm_visual->display */
79 GLboolean swapbytes; /* Host byte order != display byte order? */
80
81 GLuint pixelformat; /* Current pixel format */
82
83 GLubyte red, green, blue, alpha;/* current drawing color */
84 unsigned long pixel; /* current drawing pixel value */
85
86 GLubyte clearcolor[4]; /* current clearing color */
87 unsigned long clearpixel; /* current clearing pixel value */
88 };
89
90
91
92 /*
93 * Mesa wrapper for X window or Pixmap
94 */
95 struct xmesa_buffer {
96 GLframebuffer *gl_buffer;/* depth, stencil, accum, etc buffers */
97 XMesaVisual xm_visual; /* the X/Mesa visual */
98
99 GLboolean pixmap_flag; /* is the buffer a Pixmap? */
100 Drawable frontbuffer; /* either a window or pixmap */
101 Pixmap backpixmap; /* back buffer Pixmap */
102 XImage *backimage; /* back buffer XImage */
103
104 Drawable buffer; /* the current buffer, either equal to */
105 /* frontbuffer, backpixmap or XIMAGE (None) */
106
107 Colormap cmap; /* the X colormap */
108
109 GLint db_state; /* 0 = single buffered */
110 /* BACK_PIXMAP = use Pixmap for back buffer */
111 /* BACK_XIMAGE = use XImage for back buffer */
112
113 GLuint shm; /* X Shared Memory extension status: */
114 /* 0 = not available */
115 /* 1 = XImage support available */
116 /* 2 = Pixmap support available too */
117 #ifdef SHM
118 XShmSegmentInfo shminfo;
119 #endif
120
121 XImage *rowimage; /* Used for optimized span writing */
122
123 GLuint width, height; /* size of buffer */
124
125 GLint bottom; /* used for FLIP macro below */
126 GLubyte *ximage_origin1; /* used for PIXELADDR1 macro */
127 GLint ximage_width1;
128 GLushort *ximage_origin2; /* used for PIXELADDR2 macro */
129 GLint ximage_width2;
130 GLuint *ximage_origin4; /* used for PIXELADDR4 macro */
131 GLint ximage_width4;
132
133 Pixmap stipple_pixmap; /* For polygon stippling */
134 GC stipple_gc; /* For polygon stippling */
135 XImage *stipple_ximage; /* For polygon stippling */
136
137 GC gc1; /* GC for infrequent color changes */
138 GC gc2; /* GC for frequent color changes */
139 GC cleargc; /* GC for clearing the color buffer */
140
141 /* The following are here instead of in the XMesaVisual
142 * because they depend on the window's colormap.
143 */
144
145 /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
146 unsigned long color_table[576]; /* RGB -> pixel value */
147
148 /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
149 GLubyte pixel_to_r[65536]; /* pixel value -> red */
150 GLubyte pixel_to_g[65536]; /* pixel value -> green */
151 GLubyte pixel_to_b[65536]; /* pixel value -> blue */
152 };
153
154
155
156 /* Values for xmesa->dest: */
157 #define FRONT_PIXMAP 1
158 #define BACK_PIXMAP 2
159 #define BACK_XIMAGE 4
160
161
162 /* Values for xmesa->pixelformat: */
163 #define PF_INDEX 1 /* Color Index mode */
164 #define PF_TRUECOLOR 2 /* TrueColor or DirectColor, any depth */
165 #define PF_8A8B8G8R 3 /* 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */
166 #define PF_8R8G8B 4 /* 32-bit TrueColor: 8-R, 8-G, 8-B */
167 #define PF_5R6G5B 5 /* 16-bit TrueColor: 5-R, 6-G, 5-B bits */
168 #define PF_DITHER 6 /* Dithered RGB using a lookup table */
169 #define PF_LOOKUP 7 /* Undithered RGB using a lookup table */
170 #define PF_HPCR 8 /* HP Color Recovery ([email protected] 30/08/95) */
171 #define PF_1BIT 9 /* monochrome dithering of RGB */
172 #define PF_GRAYSCALE 10 /* Grayscale or StaticGray */
173
174
175
176 /*
177 * If pixelformat==PF_TRUECOLOR:
178 */
179 #define PACK_RGB( R, G, B ) \
180 (xmesa->xm_visual->r_to_pixel[R] | xmesa->xm_visual->g_to_pixel[G] | xmesa->xm_visual->b_to_pixel[B])
181
182
183 /*
184 * If pixelformat==PF_8A8B8G8R:
185 */
186 #define PACK_8A8B8G8R( R, G, B, A ) \
187 ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
188
189
190 /*
191 * If pixelformat==PF_8R8G8B:
192 */
193 #define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) )
194
195
196 /*
197 * If pixelformat==PF_5R6G5B:
198 */
199 #define PACK_5R6G5B( R, G, B) ( ((R) << 11) | ((G) << 5) | (B) )
200
201
202
203 /*
204 * If pixelformat==PF_DITHER:
205 *
206 * Improved 8-bit RGB dithering code contributed by Bob Mercier
207 * ([email protected]). Thanks Bob!
208 */
209 #ifdef DITHER666
210 # define _R 6
211 # define _G 6
212 # define _B 6
213 # define _MIX(r,g,b) (((r)*_G+(g))*_B+(b))
214 #else
215 # define _R 5
216 # define _G 9
217 # define _B 5
218 # define _MIX(r,g,b) ( ((g)<<6) | ((b)<<3) | (r) )
219 #endif
220 #define _DX 4
221 #define _DY 4
222 #define _D (_DX*_DY)
223
224 /*#define _DITH(C,c,d) (((unsigned)((_D*(C-1)+1)*c+d))/(_D*256))*/
225 #define _DITH(C,c,d) (((unsigned)((_D*(C-1)+1)*c+d)) >> 12)
226
227 #define MAXC 256
228 static int kernel8[_DY*_DX] = {
229 0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC,
230 12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC,
231 3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC,
232 15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC,
233 };
234 /*static int __d;*/
235
236 /* Dither for random X,Y */
237 #define DITHER_SETUP \
238 int __d; \
239 unsigned long *ctable = xmesa->xm_buffer->color_table;
240
241 #define DITHER( X, Y, R, G, B ) \
242 (__d = kernel8[(((Y)&3)<<2) | ((X)&3)], \
243 ctable[_MIX(_DITH(_R, (R), __d), \
244 _DITH(_G, (G), __d), \
245 _DITH(_B, (B), __d))])
246
247 /* Dither for random X, fixed Y */
248 #define XDITHER_SETUP(Y) \
249 int __d; \
250 unsigned long *ctable = xmesa->xm_buffer->color_table; \
251 int *kernel = &kernel8[ ((Y)&3) << 2 ];
252
253 #define XDITHER( X, R, G, B ) \
254 (__d = kernel[(X)&3], \
255 ctable[_MIX(_DITH(_R, (R), __d), \
256 _DITH(_G, (G), __d), \
257 _DITH(_B, (B), __d))])
258
259
260 /*
261 * Dithering for flat-shaded triangles. Precompute all 16 possible
262 * pixel values given the triangle's RGB color. Contributed by Martin Shenk.
263 */
264 static GLushort DitherValues[16]; /* array of (up to) 16-bit pixel values */
265
266 #define FLAT_DITHER_SETUP( R, G, B ) \
267 { \
268 unsigned long *ctable = xmesa->xm_buffer->color_table; \
269 int msdr = (_D*((_R)-1)+1) * (R); \
270 int msdg = (_D*((_G)-1)+1) * (G); \
271 int msdb = (_D*((_B)-1)+1) * (B); \
272 int i; \
273 for (i=0;i<16;i++) { \
274 int k = kernel8[i]; \
275 int j = _MIX( (msdr+k)>>12, (msdg+k)>>12, (msdb+k)>>12 ); \
276 DitherValues[i] = ctable[j]; \
277 } \
278 }
279
280 #define FLAT_DITHER_ROW_SETUP(Y) \
281 GLushort *ditherRow = DitherValues + ( ((Y)&3) << 2);
282
283 #define FLAT_DITHER(X) ditherRow[(X)&3]
284
285
286
287 /*
288 * If pixelformat==PF_LOOKUP:
289 */
290 #define _DITH0(C,c) (((unsigned)((_D*(C-1)+1)*c)) >> 12)
291
292 #define LOOKUP_SETUP \
293 unsigned long *ctable = xmesa->xm_buffer->color_table
294
295 #define LOOKUP( R, G, B ) \
296 ctable[_MIX(_DITH0(_R, (R)), \
297 _DITH0(_G, (G)), \
298 _DITH0(_B, (B)))]
299
300
301
302 /*
303 * If pixelformat==PF_HPCR:
304 *
305 * HP Color Recovery dithering ([email protected] 30/08/95)
306 * HP has on it's 8-bit 700-series computers, a feature called
307 * 'Color Recovery'. This allows near 24-bit output (so they say).
308 * It is enabled by selecting the 8-bit TrueColor visual AND
309 * corresponding colormap (see tkInitWindow) AND doing some special
310 * dither.
311 */
312 static const short HPCR_DR[2][16] = {
313 { 16, -4, 1,-11, 14, -6, 3, -9, 15, -5, 2,-10, 13, -7, 4, -8},
314 {-15, 5, 0, 12,-13, 7, -2, 10,-14, 6, -1, 11,-12, 8, -3, 9} };
315 static const short HPCR_DG[2][16] = {
316 {-11, 15, -7, 3, -8, 14, -4, 2,-10, 16, -6, 4, -9, 13, -5, 1},
317 { 12,-14, 8, -2, 9,-13, 5, -1, 11,-15, 7, -3, 10,-12, 6, 0} };
318 static const short HPCR_DB[2][16] = {
319 { 6,-18, 26,-14, 2,-22, 30,-10, 8,-16, 28,-12, 4,-20, 32, -8},
320 { -4, 20,-24, 16, 0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10} };
321
322 #define DITHER_HPCR( X, Y, R, G, B ) \
323 ( ((xmesa->xm_visual->hpcr_rTbl[R] + HPCR_DR[(Y)&1][(X)&15]) & 0xE0) \
324 |(((xmesa->xm_visual->hpcr_gTbl[G] + HPCR_DG[(Y)&1][(X)&15]) & 0xE0)>>3) \
325 | ((xmesa->xm_visual->hpcr_bTbl[B] + HPCR_DB[(Y)&1][(X)&15])>>6) \
326 )
327
328
329
330 /*
331 * If pixelformat==PF_1BIT:
332 */
333 static int const kernel1[16] = {
334 0*47, 9*47, 4*47, 12*47,
335 6*47, 2*47, 14*47, 8*47,
336 10*47, 1*47, 5*47, 11*47,
337 7*47, 13*47, 3*47, 15*47 };
338
339 #define DITHER_1BIT( X, Y, R, G, B ) \
340 ( ((int)(R)+(int)(G)+(int)(B)) > kernel1[(((Y)&3) << 2) | ((X)&3)] )
341
342
343
344 /*
345 * If pixelformat==PF_GRAYSCALE:
346 */
347 #define GRAY_RGB( R, G, B ) xmesa->xm_buffer->color_table[(R) + (G) + (B)]
348
349
350
351 #define XIMAGE None
352
353
354 /*
355 * Converts a GL window Y coord to an X window Y coord:
356 */
357 #define FLIP(Y) (xmesa->xm_buffer->bottom-(Y))
358
359
360 /*
361 * Return the address of a 1, 2 or 4-byte pixel in the back XImage:
362 * X==0 is left, Y==0 is bottom.
363 */
364 #define PIXELADDR1( X, Y ) \
365 ( xmesa->xm_buffer->ximage_origin1 - (Y) * xmesa->xm_buffer->ximage_width1 + (X) )
366
367 #define PIXELADDR2( X, Y ) \
368 ( xmesa->xm_buffer->ximage_origin2 - (Y) * xmesa->xm_buffer->ximage_width2 + (X) )
369
370 #define PIXELADDR4( X, Y ) \
371 ( xmesa->xm_buffer->ximage_origin4 - (Y) * xmesa->xm_buffer->ximage_width4 + (X) )
372
373
374
375 /*
376 * External variables:
377 */
378 extern XMesaContext XMesa;
379
380
381
382 /*
383 * External functions:
384 */
385
386 extern unsigned long xmesa_color_to_pixel( XMesaContext xmesa,
387 GLubyte r, GLubyte g, GLubyte b, GLubyte a );
388
389 extern void xmesa_alloc_back_buffer( XMesaBuffer b );
390
391 extern void xmesa_setup_DD_pointers( GLcontext *ctx );
392
393 extern points_func xmesa_get_points_func( GLcontext *ctx );
394
395 extern line_func xmesa_get_line_func( GLcontext *ctx );
396
397 extern polygon_func xmesa_get_polygon_func( GLcontext *ctx );
398
399 extern triangle_func xmesa_get_triangle_func( GLcontext *ctx );
400
401
402
403 #endif