477566cc46469ce5a7da18a268b4db8fa957af41
[mesa.git] / src / glx / x11 / glxclient.h
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
33 */
34 /* $XFree86: xc/lib/GL/glx/glxclient.h,v 1.21 2004/02/09 23:46:31 alanh Exp $ */
35
36 /**
37 * \file glxclient.h
38 * Direct rendering support added by Precision Insight, Inc.
39 *
40 * \author Kevin E. Martin <kevin@precisioninsight.com>
41 */
42
43 #ifndef _GLX_client_h_
44 #define _GLX_client_h_
45 #define NEED_REPLIES
46 #define NEED_EVENTS
47 #include <X11/Xproto.h>
48 #include <X11/Xlibint.h>
49 #define GLX_GLXEXT_PROTOTYPES
50 #include <GL/glx.h>
51 #include <GL/glxext.h>
52 #include <string.h>
53 #include <stdlib.h>
54 #include <stdio.h>
55 #ifdef WIN32
56 #include <stdint.h>
57 #endif
58 #include "GL/glxint.h"
59 #include "GL/glxproto.h"
60 #include "GL/internal/glcore.h"
61 #include "glapitable.h"
62 #include "glxextensions.h"
63 #if defined( USE_XTHREADS )
64 # include <X11/Xthreads.h>
65 #elif defined( PTHREADS )
66 # include <pthread.h>
67 #endif
68
69 #define GLX_MAJOR_VERSION 1 /* current version numbers */
70 #define GLX_MINOR_VERSION 4
71
72 #define __GLX_MAX_TEXTURE_UNITS 32
73
74 typedef struct __GLXcontextRec __GLXcontext;
75 typedef struct __GLXdisplayPrivateRec __GLXdisplayPrivate;
76 typedef struct _glapi_table __GLapi;
77
78 /************************************************************************/
79
80 #ifdef GLX_DIRECT_RENDERING
81
82 #include <GL/internal/dri_interface.h>
83
84
85 /**
86 * Display dependent methods. This structure is initialized during the
87 * \c driCreateDisplay call.
88 */
89 struct __DRIdisplayRec {
90 /**
91 * Method to destroy the private DRI display data.
92 */
93 void (*destroyDisplay)(Display *dpy, void *displayPrivate);
94
95 /**
96 * Opaque pointer to private per display direct rendering data.
97 * \c NULL if direct rendering is not supported on this display.
98 */
99 struct __DRIdisplayPrivateRec *private;
100
101 /**
102 * Array of pointers to methods to create and initialize the private DRI
103 * screen data.
104 */
105 PFNCREATENEWSCREENFUNC * createNewScreen;
106 };
107
108
109 /*
110 ** We keep a linked list of these structures, one per DRI device driver.
111 */
112 struct __DRIdriverRec {
113 const char *name;
114 void *handle;
115 PFNCREATENEWSCREENFUNC createNewScreenFunc;
116 struct __DRIdriverRec *next;
117 };
118
119 /*
120 ** Function to create and DRI display data and initialize the display
121 ** dependent methods.
122 */
123 extern void *driCreateDisplay(Display *dpy, __DRIdisplay *pdisp);
124
125 extern __DRIdriver *driGetDriver(Display *dpy, int scrNum);
126
127 extern void DRI_glXUseXFont( Font font, int first, int count, int listbase );
128
129 /*
130 ** Functions to obtain driver configuration information from a direct
131 ** rendering client application
132 */
133 extern const char *glXGetScreenDriver (Display *dpy, int scrNum);
134
135 extern const char *glXGetDriverConfig (const char *driverName);
136
137 extern Bool __glXWindowExists(Display *dpy, GLXDrawable draw);
138
139 #endif
140
141 /************************************************************************/
142
143 #define __GL_CLIENT_ATTRIB_STACK_DEPTH 16
144
145 typedef struct __GLXpixelStoreModeRec {
146 GLboolean swapEndian;
147 GLboolean lsbFirst;
148 GLuint rowLength;
149 GLuint imageHeight;
150 GLuint imageDepth;
151 GLuint skipRows;
152 GLuint skipPixels;
153 GLuint skipImages;
154 GLuint alignment;
155 } __GLXpixelStoreMode;
156
157
158 typedef struct __GLXattributeRec {
159 GLuint mask;
160
161 /**
162 * Pixel storage state. Most of the pixel store mode state is kept
163 * here and used by the client code to manage the packing and
164 * unpacking of data sent to/received from the server.
165 */
166 __GLXpixelStoreMode storePack, storeUnpack;
167
168 /**
169 * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically
170 * disabled?
171 */
172 GLboolean NoDrawArraysProtocol;
173
174 /**
175 * Vertex Array storage state. The vertex array component
176 * state is stored here and is used to manage the packing of
177 * DrawArrays data sent to the server.
178 */
179 struct array_state_vector * array_state;
180 } __GLXattribute;
181
182 typedef struct __GLXattributeMachineRec {
183 __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH];
184 __GLXattribute **stackPointer;
185 } __GLXattributeMachine;
186
187 /**
188 * GLX state that needs to be kept on the client. One of these records
189 * exist for each context that has been made current by this client.
190 */
191 struct __GLXcontextRec {
192 /**
193 * \name Drawing command buffer.
194 *
195 * Drawing commands are packed into this buffer before being sent as a
196 * single GLX protocol request. The buffer is sent when it overflows or
197 * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location
198 * in the buffer to be filled. \c limit is described above in the buffer
199 * slop discussion.
200 *
201 * Commands that require large amounts of data to be transfered will
202 * also use this buffer to hold a header that describes the large
203 * command.
204 *
205 * These must be the first 6 fields since they are static initialized
206 * in the dummy context in glxext.c
207 */
208 /*@{*/
209 GLubyte *buf;
210 GLubyte *pc;
211 GLubyte *limit;
212 GLubyte *bufEnd;
213 GLint bufSize;
214 /*@}*/
215
216 /**
217 * The XID of this rendering context. When the context is created a
218 * new XID is allocated. This is set to None when the context is
219 * destroyed but is still current to some thread. In this case the
220 * context will be freed on next MakeCurrent.
221 */
222 XID xid;
223
224 /**
225 * The XID of the \c shareList context.
226 */
227 XID share_xid;
228
229 /**
230 * Visual id.
231 *
232 * \deprecated
233 * This filed has been largely been replaced by the \c mode field, but
234 * the work is not quite done.
235 */
236 VisualID vid;
237
238 /**
239 * Screen number.
240 */
241 GLint screen;
242
243 /**
244 * \c GL_TRUE if the context was created with ImportContext, which
245 * means the server-side context was created by another X client.
246 */
247 GLboolean imported;
248
249 /**
250 * The context tag returned by MakeCurrent when this context is made
251 * current. This tag is used to identify the context that a thread has
252 * current so that proper server context management can be done. It is
253 * used for all context specific commands (i.e., \c Render, \c RenderLarge,
254 * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old
255 * context)).
256 */
257 GLXContextTag currentContextTag;
258
259 /**
260 * \name Rendering mode
261 *
262 * The rendering mode is kept on the client as well as the server.
263 * When \c glRenderMode is called, the buffer associated with the
264 * previous rendering mode (feedback or select) is filled.
265 */
266 /*@{*/
267 GLenum renderMode;
268 GLfloat *feedbackBuf;
269 GLuint *selectBuf;
270 /*@}*/
271
272 /**
273 * This is \c GL_TRUE if the pixel unpack modes are such that an image
274 * can be unpacked from the clients memory by just copying. It may
275 * still be true that the server will have to do some work. This
276 * just promises that a straight copy will fetch the correct bytes.
277 */
278 GLboolean fastImageUnpack;
279
280 /**
281 * Fill newImage with the unpacked form of \c oldImage getting it
282 * ready for transport to the server.
283 */
284 void (*fillImage)(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum,
285 GLenum, const GLvoid*, GLubyte*, GLubyte*);
286
287 /**
288 * Client side attribs.
289 */
290 __GLXattributeMachine attributes;
291
292 /**
293 * Client side error code. This is set when client side gl API
294 * routines need to set an error because of a bad enumerant or
295 * running out of memory, etc.
296 */
297 GLenum error;
298
299 /**
300 * Whether this context does direct rendering.
301 */
302 Bool isDirect;
303
304 /**
305 * \c dpy of current display for this context. Will be \c NULL if not
306 * current to any display, or if this is the "dummy context".
307 */
308 Display *currentDpy;
309
310 /**
311 * The current drawable for this context. Will be None if this
312 * context is not current to any drawable. currentReadable is below.
313 */
314 GLXDrawable currentDrawable;
315
316 /**
317 * \name GL Constant Strings
318 *
319 * Constant strings that describe the server implementation
320 * These pertain to GL attributes, not to be confused with
321 * GLX versioning attributes.
322 */
323 /*@{*/
324 GLubyte *vendor;
325 GLubyte *renderer;
326 GLubyte *version;
327 GLubyte *extensions;
328 /*@}*/
329
330 /**
331 * Record the dpy this context was created on for later freeing
332 */
333 Display *createDpy;
334
335 /**
336 * Maximum small render command size. This is the smaller of 64k and
337 * the size of the above buffer.
338 */
339 GLint maxSmallRenderCommandSize;
340
341 /**
342 * Major opcode for the extension. Copied here so a lookup isn't
343 * needed.
344 */
345 GLint majorOpcode;
346
347 #ifdef GLX_DIRECT_RENDERING
348 /**
349 * Per context direct rendering interface functions and data.
350 */
351 __DRIcontext driContext;
352 #endif
353
354 /**
355 * \c GLXFBConfigID used to create this context. May be \c None. This
356 * field has been replaced by the \c mode field.
357 *
358 * \since Internal API version 20030317.
359 *
360 * \deprecated
361 * This filed has been largely been replaced by the \c mode field, but
362 * the work is not quite done.
363 */
364 GLXFBConfigID fbconfigID;
365
366 /**
367 * The current read-drawable for this context. Will be None if this
368 * context is not current to any drawable.
369 *
370 * \since Internal API version 20030606.
371 */
372 GLXDrawable currentReadable;
373
374 /**
375 * Pointer to client-state data that is private to libGL. This is only
376 * used for indirect rendering contexts.
377 *
378 * No internal API version change was made for this change. Client-side
379 * drivers should NEVER use this data or even care that it exists.
380 */
381 void * client_state_private;
382
383 /**
384 * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE.
385 */
386 int renderType;
387
388 /**
389 * \name Raw server GL version
390 *
391 * True core GL version supported by the server. This is the raw value
392 * returned by the server, and it may not reflect what is actually
393 * supported (or reported) by the client-side library.
394 */
395 /*@{*/
396 int server_major; /**< Major version number. */
397 int server_minor; /**< Minor version number. */
398 /*@}*/
399
400 char gl_extension_bits[ __GL_EXT_BYTES ];
401 };
402
403 #define __glXSetError(gc,code) \
404 if (!(gc)->error) { \
405 (gc)->error = code; \
406 }
407
408 extern void __glFreeAttributeState(__GLXcontext *);
409
410 /************************************************************************/
411
412 /**
413 * The size of the largest drawing command known to the implementation
414 * that will use the GLXRender GLX command. In this case it is
415 * \c glPolygonStipple.
416 */
417 #define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156
418
419 /**
420 * To keep the implementation fast, the code uses a "limit" pointer
421 * to determine when the drawing command buffer is too full to hold
422 * another fixed size command. This constant defines the amount of
423 * space that must always be available in the drawing command buffer
424 * at all times for the implementation to work. It is important that
425 * the number be just large enough, but not so large as to reduce the
426 * efficacy of the buffer. The "+32" is just to keep the code working
427 * in case somebody counts wrong.
428 */
429 #define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32)
430
431 /**
432 * This implementation uses a smaller threshold for switching
433 * to the RenderLarge protocol than the protcol requires so that
434 * large copies don't occur.
435 */
436 #define __GLX_RENDER_CMD_SIZE_LIMIT 4096
437
438 /**
439 * One of these records exists per screen of the display. It contains
440 * a pointer to the config data for that screen (if the screen supports GL).
441 */
442 typedef struct __GLXscreenConfigsRec {
443 /**
444 * GLX extension string reported by the X-server.
445 */
446 const char *serverGLXexts;
447
448 /**
449 * GLX extension string to be reported to applications. This is the
450 * set of extensions that the application can actually use.
451 */
452 char *effectiveGLXexts;
453
454 #ifdef GLX_DIRECT_RENDERING
455 /**
456 * Per screen direct rendering interface functions and data.
457 */
458 __DRIscreen driScreen;
459 #endif
460
461 /**
462 * Linked list of configurations for this screen.
463 */
464 __GLcontextModes *configs;
465
466 /**
467 * Per-screen dynamic GLX extension tracking. The \c direct_support
468 * field only contains enough bits for 64 extensions. Should libGL
469 * ever need to track more than 64 GLX extensions, we can safely grow
470 * this field. The \c __GLXscreenConfigs structure is not used outside
471 * libGL.
472 */
473 /*@{*/
474 unsigned char direct_support[8];
475 GLboolean ext_list_first_time;
476 /*@}*/
477
478 } __GLXscreenConfigs;
479
480 /**
481 * Per display private data. One of these records exists for each display
482 * that is using the OpenGL (GLX) extension.
483 */
484 struct __GLXdisplayPrivateRec {
485 /**
486 * Back pointer to the display
487 */
488 Display *dpy;
489
490 /**
491 * The \c majorOpcode is common to all connections to the same server.
492 * It is also copied into the context structure.
493 */
494 int majorOpcode;
495
496 /**
497 * \name Server Version
498 *
499 * Major and minor version returned by the server during initialization.
500 */
501 /*@{*/
502 int majorVersion, minorVersion;
503 /*@}*/
504
505 /**
506 * \name Storage for the servers GLX vendor and versions strings.
507 *
508 * These are the same for all screens on this display. These fields will
509 * be filled in on demand.
510 */
511 /*@{*/
512 const char *serverGLXvendor;
513 const char *serverGLXversion;
514 /*@}*/
515
516 /**
517 * Configurations of visuals for all screens on this display.
518 * Also, per screen data which now includes the server \c GLX_EXTENSION
519 * string.
520 */
521 __GLXscreenConfigs *screenConfigs;
522
523 #ifdef GLX_DIRECT_RENDERING
524 /**
525 * Per display direct rendering interface functions and data.
526 */
527 __DRIdisplay driDisplay;
528 #endif
529 };
530
531 void __glXFreeContext(__GLXcontext*);
532
533 extern GLubyte *__glXFlushRenderBuffer(__GLXcontext*, GLubyte*);
534
535 extern void __glXSendLargeChunk(__GLXcontext *gc, GLint requestNumber,
536 GLint totalRequests,
537 const GLvoid * data, GLint dataLen);
538
539 extern void __glXSendLargeCommand(__GLXcontext *, const GLvoid *, GLint,
540 const GLvoid *, GLint);
541
542 /* Initialize the GLX extension for dpy */
543 extern __GLXdisplayPrivate *__glXInitialize(Display*);
544
545 /************************************************************************/
546
547 extern int __glXDebug;
548
549 /* This is per-thread storage in an MT environment */
550 #if defined( USE_XTHREADS ) || defined( PTHREADS )
551
552 extern void __glXSetCurrentContext(__GLXcontext *c);
553
554 # if defined( GLX_USE_TLS )
555
556 extern __thread void * __glX_tls_Context
557 __attribute__((tls_model("initial-exec")));
558
559 # define __glXGetCurrentContext() __glX_tls_Context
560
561 # else
562
563 extern __GLXcontext *__glXGetCurrentContext(void);
564
565 # endif /* defined( GLX_USE_TLS ) */
566
567 #else
568
569 extern __GLXcontext *__glXcurrentContext;
570 #define __glXGetCurrentContext() __glXcurrentContext
571 #define __glXSetCurrentContext(gc) __glXcurrentContext = gc
572
573 #endif /* defined( USE_XTHREADS ) || defined( PTHREADS ) */
574
575
576 /*
577 ** Global lock for all threads in this address space using the GLX
578 ** extension
579 */
580 #if defined( USE_XTHREADS )
581 extern xmutex_rec __glXmutex;
582 #define __glXLock() xmutex_lock(&__glXmutex)
583 #define __glXUnlock() xmutex_unlock(&__glXmutex)
584 #elif defined( PTHREADS )
585 extern pthread_mutex_t __glXmutex;
586 #define __glXLock() pthread_mutex_lock(&__glXmutex)
587 #define __glXUnlock() pthread_mutex_unlock(&__glXmutex)
588 #else
589 #define __glXLock()
590 #define __glXUnlock()
591 #endif
592
593 /*
594 ** Setup for a command. Initialize the extension for dpy if necessary.
595 */
596 extern CARD8 __glXSetupForCommand(Display *dpy);
597
598 /************************************************************************/
599
600 /*
601 ** Data conversion and packing support.
602 */
603
604 extern const GLuint __glXDefaultPixelStore[9];
605
606 /* Send an image to the server using RenderLarge. */
607 extern void __glXSendLargeImage(__GLXcontext *gc, GLint compsize, GLint dim,
608 GLint width, GLint height, GLint depth, GLenum format, GLenum type,
609 const GLvoid *src, GLubyte *pc, GLubyte *modes);
610
611 /* Return the size, in bytes, of some pixel data */
612 extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum);
613
614 /* Return the number of elements per group of a specified format*/
615 extern GLint __glElementsPerGroup(GLenum format, GLenum type);
616
617 /* Return the number of bytes per element, based on the element type (other
618 ** than GL_BITMAP).
619 */
620 extern GLint __glBytesPerElement(GLenum type);
621
622 /*
623 ** Fill the transport buffer with the data from the users buffer,
624 ** applying some of the pixel store modes (unpack modes) to the data
625 ** first. As a side effect of this call, the "modes" field is
626 ** updated to contain the modes needed by the server to decode the
627 ** sent data.
628 */
629 extern void __glFillImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum,
630 GLenum, const GLvoid*, GLubyte*, GLubyte*);
631
632 /* Copy map data with a stride into a packed buffer */
633 extern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *);
634 extern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *);
635 extern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint,
636 const GLfloat *, GLfloat *);
637 extern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint,
638 const GLdouble *, GLdouble *);
639
640 /*
641 ** Empty an image out of the reply buffer into the clients memory applying
642 ** the pack modes to pack back into the clients requested format.
643 */
644 extern void __glEmptyImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum,
645 GLenum, const GLubyte *, GLvoid *);
646
647
648 /*
649 ** Allocate and Initialize Vertex Array client state
650 */
651 extern void __glXInitVertexArrayState(__GLXcontext*);
652
653 /*
654 ** Inform the Server of the major and minor numbers and of the client
655 ** libraries extension string.
656 */
657 extern void __glXClientInfo ( Display *dpy, int opcode );
658
659 /************************************************************************/
660
661 /*
662 ** Declarations that should be in Xlib
663 */
664 #ifdef __GL_USE_OUR_PROTOTYPES
665 extern void _XFlush(Display*);
666 extern Status _XReply(Display*, xReply*, int, Bool);
667 extern void _XRead(Display*, void*, long);
668 extern void _XSend(Display*, const void*, long);
669 #endif
670
671
672 extern void __glXInitializeVisualConfigFromTags( __GLcontextModes *config,
673 int count, const INT32 *bp, Bool tagged_only, Bool fbconfig_style_tags );
674
675 extern char * __glXGetStringFromServer( Display * dpy, int opcode,
676 CARD32 glxCode, CARD32 for_whom, CARD32 name );
677
678 extern char *__glXstrdup(const char *str);
679
680
681 extern const char __glXGLClientVersion[];
682 extern const char __glXGLClientExtensions[];
683
684 /* Determine the internal API version */
685 extern int __glXGetInternalVersion(void);
686
687 /* Get the unadjusted system time */
688 extern int __glXGetUST( int64_t * ust );
689
690 extern Bool __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
691 int32_t * numerator, int32_t * denominator);
692
693 #endif /* !__GLX_client_h__ */