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