summaryrefslogtreecommitdiff
path: root/include/GL/miniglx.h
blob: 8c6180be60b4ef695de81eea700f033c49ffbdc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/*
 * Mesa 3-D graphics library
 * 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
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


/**
 * \file miniglx.h
 * \brief Mini GLX interface functions.
 * \author Brian Paul
 *
 * See comments miniglx.c for more information.
 */

#ifndef MINIGLX_H
#define MINIGLX_H

#include <GL/gl.h>
#include <stdlib.h>


#ifdef __cplusplus
extern "C" {
#endif


/**
 * \name Replacement Xlib/GLX types
 */
/*@{*/
/**
 * \brief Boolean type.
 * 
 * It can have the values #True or #False.
 */
#ifndef MINIGLX_NO_XTYPES
typedef int Bool;
#endif
typedef int MINI_Bool;

/**
 * \brief Color map.
 *
 * Alias for private ::MiniGLXColormapRec structure.
 */
typedef struct MiniGLXColormapRec *MINI_Colormap;
#ifndef MINIGLX_NO_XTYPES
typedef struct MiniGLXColormapRec *Colormap;
#endif

/**
 * \brief Window attributes.
 */
typedef struct MiniGLXSetWindowAttributesRec {
   int background_pixel; /**< \brief background pixel */
   int border_pixel;     /**< \brief border pixel value */
   MINI_Colormap colormap;    /**< \brief color map to be associated with window */
   int event_mask;       /**< \brief set of events that should be saved */
} XSetWindowAttributes;

/**
 * \brief Visual.
 *
 * Alias for the private ::MiniGLXVisualRec structure.
 *
 * \sa \ref datatypes.
 */
typedef struct MiniGLXVisualRec Visual;

/**
 * \brief Visual information.
 *
 * \sa \ref datatypes.
 */
#ifndef MINIGLX_NO_XTYPES
typedef unsigned long VisualID;
#endif
typedef unsigned long MINI_VisualID;
typedef struct MiniGLXXVisualInfoRec {
   Visual *visual;	/**< \brief pointer to the GLX Visual */
   MINI_VisualID visualid;	/**< \brief visual ID */
   int screen;		/**< \brief screen number */
   int depth;		/**< \brief bit depth */
#if defined(__cplusplus) || defined(c_plusplus)
   int c_class;		/**< \brief class */
#else
   int class;		/**< \brief class */
#endif
   int bits_per_rgb;	/**< \brief total bits per pixel */
} XVisualInfo;

/**
 * \brief GLX Frame Buffer Configuration (for pbuffers)
 * \sa \ref datatypes.
 */
typedef struct MiniGLXFBConfigRec {
   XVisualInfo *visInfo;
} GLXFBConfig;


/**
 * \brief Display handle.
 *
 * Alias for the private ::MiniGLXDisplayRec structure.
 *
 * \sa \ref datatypes.
 */
#ifndef MINIGLX_NO_XTYPES
typedef struct MiniGLXDisplayRec   Display;
#endif
typedef struct MiniGLXDisplayRec   MINI_Display;

/**
 * \brief Window handle.
 *
 * Alias for the private ::MiniGLXWindowRec structure.
 *
 * \sa \ref datatypes.
 */
#ifndef MINIGLX_NO_XTYPES
typedef struct MiniGLXWindowRec   *Window;
#endif
typedef struct MiniGLXWindowRec   *MINI_Window;

/**
 * \brief Drawable.
 *
 * Alias for the private ::MiniGLXWindowRec structure.
 * 
 * For Mini GLX only the full-screen window can be used as source and
 * destination in graphics operations.
 *
 * \sa \ref datatypes.
 */
#ifndef MINIGLX_NO_XTYPES
typedef struct MiniGLXWindowRec   *Drawable;
#endif
typedef struct MiniGLXWindowRec   *MINI_Drawable;

/**
 * \brief GLX drawable.
 *
 * Alias for the private ::MiniGLXWindowRec structure.
 * 
 * Same as #Drawable.
 *
 * \sa \ref datatypes.
 */
typedef struct MiniGLXWindowRec   *GLXDrawable;

/**
 * \brief GLX pbuffer.
 *
 * Alias for the private ::MiniGLXWindowRec structure.
 * 
 * Same as #Drawable.
 *
 * \sa \ref datatypes.
 */
typedef struct MiniGLXWindowRec   *GLXPbuffer;

/**
 * \brief GLX context.
 * 
 * Alias for the private ::MiniGLXContext structure.
 *
 * \sa \ref datatypes.
 */
typedef struct MiniGLXContextRec  *GLXContext;
/*@}*/


typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	MINI_Bool send_event;	/* true if this came from a SendEvent request */
	MINI_Display *display;	/* Display the event was read from */
	MINI_Window window;
	int x, y;
	int width, height;
	int count;		/* if non-zero, at least this many more */
} XExposeEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	MINI_Bool send_event;	/* true if this came from a SendEvent request */
	MINI_Display *display;	/* Display the event was read from */
	MINI_Window parent;		/* parent of the window */
        MINI_Window window;		/* window id of window created */
	int x, y;		/* window location */
	int width, height;	/* size of window */
	int border_width;	/* border width */
	MINI_Bool override_redirect;	/* creation should be overridden */
} XCreateWindowEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	MINI_Bool send_event;	/* true if this came from a SendEvent request */
	MINI_Display *display;	/* Display the event was read from */
	MINI_Window event;
	MINI_Window window;
} XDestroyWindowEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	MINI_Bool send_event;	/* true if this came from a SendEvent request */
	MINI_Display *display;	/* Display the event was read from */
	MINI_Window event;
	MINI_Window window;
	MINI_Bool from_configure;
} XUnmapEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	MINI_Bool send_event;	/* true if this came from a SendEvent request */
	MINI_Display *display;	/* Display the event was read from */
	MINI_Window event;
	MINI_Window window;
	MINI_Bool override_redirect;	/* boolean, is override set... */
} XMapEvent;


typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	MINI_Bool send_event;	/* true if this came from a SendEvent request */
	MINI_Display *display;	/* Display the event was read from */
	MINI_Window parent;
	MINI_Window window;
} XMapRequestEvent;

typedef union _XEvent {
        int type;		/* must not be changed; first element */
	XExposeEvent xexpose;
        XCreateWindowEvent xcreatewindow;
	XDestroyWindowEvent xdestroywindow;
	XUnmapEvent xunmap;
	XMapEvent xmap;
	XMapRequestEvent xmaprequest;
	long pad[24];
} XEvent;


/**
 * \name Xlib constants
 */
/*@{*/
#define False                0
#define True                 1
#define None                 0
#define AllocNone            0
#define InputOutput          1
#define ExposureMask         (1L<<15) 
#define StructureNotifyMask  (1L<<17) 
#define CWBackPixel          (1L<<1)
#define CWBorderPixel        (1L<<3)
#define CWEventMask          (1L<<11)
#define CWColormap           (1L<<13)
#define PseudoColor          3
#define TrueColor            4
#define VisualIDMask     0x1
#define VisualScreenMask     0x2
#define Expose		     12
#define CreateNotify	     16
#define DestroyNotify	     17
#define UnmapNotify	     18
#define MapNotify	     19
#define MapRequest	     20

/*@}*/

/**
 * \name Standard GLX tokens
 */
/*@{*/
#define GLX_USE_GL		1
#define GLX_BUFFER_SIZE		2
#define GLX_LEVEL		3
#define GLX_RGBA		4
#define GLX_DOUBLEBUFFER	5
#define GLX_STEREO		6
#define GLX_AUX_BUFFERS		7
#define GLX_RED_SIZE		8
#define GLX_GREEN_SIZE		9
#define GLX_BLUE_SIZE		10
#define GLX_ALPHA_SIZE		11
#define GLX_DEPTH_SIZE		12
#define GLX_STENCIL_SIZE	13
#define GLX_ACCUM_RED_SIZE	14
#define GLX_ACCUM_GREEN_SIZE	15
#define GLX_ACCUM_BLUE_SIZE	16
#define GLX_ACCUM_ALPHA_SIZE	17
#define GLX_BAD_ATTRIBUTE       1
#define GLX_BAD_VISUAL          4
/*@}*/


/**
 * \name Unique to Mini GLX
 *
 * At compile time, the Mini GLX interface version can be tested with the
 * MINI_GLX_VERSION_1_x preprocessor tokens.
 *
 * \sa glXQueryVersion()
 */
/*@{*/
/** \brief Defined if version 1.0 of Mini GLX is supported. */
#define MINI_GLX_VERSION_1_0    1
/** \brief Defined if version 1.1 of Mini GLX is supported. */
#define MINI_GLX_VERSION_1_1    1
/*@}*/


/**
 * \name Server-specific functions
 */
extern MINI_Display *
__miniglx_StartServer( const char *display_name );

extern int
__miniglx_Select( MINI_Display *dpy, int maxfd,
		  fd_set *rfds, fd_set *wfds, fd_set *xfds,
		  struct timeval *tv );


/**
 * \name Simulated Xlib functions
 */
/*@{*/
extern MINI_Display *
XOpenDisplay( const char *dpy_name );


extern void
XCloseDisplay( MINI_Display *display );

extern MINI_Window
XCreateWindow( MINI_Display *display, MINI_Window parent, int x, int y,
               unsigned int width, unsigned int height,
               unsigned int border_width, int depth, unsigned int winclass,
               Visual *visual, unsigned long valuemask,
               XSetWindowAttributes *attributes );

extern int 
XNextEvent(MINI_Display *display, XEvent *event_return);

extern MINI_Bool 
XCheckMaskEvent( MINI_Display *dpy, long event_mask, XEvent *event_return );

/**
 * \brief Return the root window.
 * 
 * \param display the display handle. It is ignored by Mini GLX, but should be
 * the value returned by XOpenDisplay().
 * \param screen the screen number on the host server. It is ignored by Mini
 * GLX but should be zero.
 *
 * \return the root window. Always zero on Mini GLX.
 */
#define RootWindow(display, screen) 0
#define DefaultScreen(dpy)  0

extern void
XDestroyWindow( MINI_Display *display, MINI_Window w );

extern void
XMapWindow( MINI_Display *display, MINI_Window w );

/* Should clients have access to this?
 */
extern void
XUnmapWindow( MINI_Display *display, MINI_Window w );

extern MINI_Colormap
XCreateColormap( MINI_Display *display, MINI_Window w, Visual *visual, int alloc );

extern void
XFreeColormap( MINI_Display *display, MINI_Colormap cmap );

extern void
XFree( void *data );

extern XVisualInfo *
XGetVisualInfo( MINI_Display *display, long vinfo_mask,
                XVisualInfo *vinfo_template, int *nitems_return );
/*@}*/



/**
 * \name GLX functions
 */
/*@{*/
extern XVisualInfo*
glXChooseVisual( MINI_Display *dpy, int screen, int *attribList );

extern int
glXGetConfig( MINI_Display *dpy, XVisualInfo *vis, int attrib, int *value );

extern GLXContext
glXCreateContext( MINI_Display *dpy, XVisualInfo *vis,
                  GLXContext shareList, MINI_Bool direct );

extern void
glXDestroyContext( MINI_Display *dpy, GLXContext ctx );

extern MINI_Bool
glXMakeCurrent( MINI_Display *dpy, GLXDrawable drawable, GLXContext ctx);

extern void
glXSwapBuffers( MINI_Display *dpy, GLXDrawable drawable );

extern GLXContext
glXGetCurrentContext( void );

extern GLXDrawable
glXGetCurrentDrawable( void );

extern void 
(*glXGetProcAddress(const GLubyte *procname))( void );

extern MINI_Bool
glXQueryVersion( MINI_Display *dpy, int *major, int *minor );

/* Added in MiniGLX 1.1 */
extern GLXPbuffer
glXCreatePbuffer( MINI_Display *dpy, GLXFBConfig config, const int *attribList );

extern void
glXDestroyPbuffer( MINI_Display *dpy, GLXPbuffer pbuf );

extern GLXFBConfig *
glXChooseFBConfig( MINI_Display *dpy, int screen, const int *attribList,
                   int *nitems );

extern XVisualInfo *
glXGetVisualFromFBConfig( MINI_Display *dpy, GLXFBConfig config );

extern void *glXAllocateMemoryMESA(Display *dpy, int scrn,
				   size_t size, float readFreq,
				   float writeFreq, float priority);

extern void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer);

extern GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn,
				      const void *pointer );
/*@}*/

extern void
__glXScrEnableExtension( void *, const char * name );

/*@}*/


#ifdef __cplusplus
}
#endif

#endif /* MINIGLX_H */