glxclient.h revision e81a0f50
1cdc920a0Smrg/* 2cdc920a0Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3cdc920a0Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4cdc920a0Smrg * 5cdc920a0Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6cdc920a0Smrg * copy of this software and associated documentation files (the "Software"), 7cdc920a0Smrg * to deal in the Software without restriction, including without limitation 8cdc920a0Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9cdc920a0Smrg * and/or sell copies of the Software, and to permit persons to whom the 10cdc920a0Smrg * Software is furnished to do so, subject to the following conditions: 11cdc920a0Smrg * 12cdc920a0Smrg * The above copyright notice including the dates of first publication and 13cdc920a0Smrg * either this permission notice or a reference to 14cdc920a0Smrg * http://oss.sgi.com/projects/FreeB/ 15cdc920a0Smrg * shall be included in all copies or substantial portions of the Software. 16cdc920a0Smrg * 17cdc920a0Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18cdc920a0Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19cdc920a0Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20cdc920a0Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21cdc920a0Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22cdc920a0Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23cdc920a0Smrg * SOFTWARE. 24cdc920a0Smrg * 25cdc920a0Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26cdc920a0Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27cdc920a0Smrg * other dealings in this Software without prior written authorization from 28cdc920a0Smrg * Silicon Graphics, Inc. 29cdc920a0Smrg */ 30cdc920a0Smrg 31cdc920a0Smrg/** 32cdc920a0Smrg * \file glxclient.h 33cdc920a0Smrg * Direct rendering support added by Precision Insight, Inc. 34cdc920a0Smrg * 35cdc920a0Smrg * \author Kevin E. Martin <kevin@precisioninsight.com> 36cdc920a0Smrg */ 37cdc920a0Smrg 38cdc920a0Smrg#ifndef _GLX_client_h_ 39cdc920a0Smrg#define _GLX_client_h_ 40cdc920a0Smrg#include <X11/Xproto.h> 41cdc920a0Smrg#include <X11/Xlibint.h> 423464ebd5Sriastradh#include <X11/Xfuncproto.h> 43cdc920a0Smrg#include <X11/extensions/extutil.h> 44cdc920a0Smrg#define GLX_GLXEXT_PROTOTYPES 45cdc920a0Smrg#include <GL/glx.h> 46cdc920a0Smrg#include <GL/glxext.h> 47cdc920a0Smrg#include <string.h> 48cdc920a0Smrg#include <stdlib.h> 49cdc920a0Smrg#include <stdio.h> 50cdc920a0Smrg#include <stdint.h> 5101e04c3fSmrg#include <pthread.h> 52cdc920a0Smrg#include "GL/glxproto.h" 533464ebd5Sriastradh#include "glxconfig.h" 54cdc920a0Smrg#include "glxhash.h" 5501e04c3fSmrg#include "util/macros.h" 56cdc920a0Smrg 57cdc920a0Smrg#include "glxextensions.h" 58cdc920a0Smrg 5901e04c3fSmrg#if defined(USE_LIBGLVND) 6001e04c3fSmrg#define _GLX_PUBLIC _X_HIDDEN 6101e04c3fSmrg#else 6201e04c3fSmrg#define _GLX_PUBLIC _X_EXPORT 6301e04c3fSmrg#endif 6401e04c3fSmrg 6501e04c3fSmrg#ifdef __cplusplus 6601e04c3fSmrgextern "C" { 6701e04c3fSmrg#endif 6801e04c3fSmrg 69cdc920a0Smrg 70cdc920a0Smrg#define GLX_MAJOR_VERSION 1 /* current version numbers */ 71cdc920a0Smrg#define GLX_MINOR_VERSION 4 72cdc920a0Smrg 73cdc920a0Smrg#define __GLX_MAX_TEXTURE_UNITS 32 74cdc920a0Smrg 753464ebd5Sriastradhstruct glx_display; 763464ebd5Sriastradhstruct glx_context; 77cdc920a0Smrg 78cdc920a0Smrg/************************************************************************/ 79cdc920a0Smrg 80cdc920a0Smrg#ifdef GLX_DIRECT_RENDERING 81cdc920a0Smrg 823464ebd5Sriastradhextern void DRI_glXUseXFont(struct glx_context *ctx, 833464ebd5Sriastradh Font font, int first, int count, int listbase); 84cdc920a0Smrg 85cdc920a0Smrg#endif 86cdc920a0Smrg 87cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 88cdc920a0Smrg 89cdc920a0Smrg/** 90cdc920a0Smrg * Display dependent methods. This structure is initialized during the 91cdc920a0Smrg * \c driCreateDisplay call. 92cdc920a0Smrg */ 93cdc920a0Smrgtypedef struct __GLXDRIdisplayRec __GLXDRIdisplay; 94cdc920a0Smrgtypedef struct __GLXDRIscreenRec __GLXDRIscreen; 95cdc920a0Smrgtypedef struct __GLXDRIdrawableRec __GLXDRIdrawable; 96cdc920a0Smrg 97cdc920a0Smrgstruct __GLXDRIdisplayRec 98cdc920a0Smrg{ 99cdc920a0Smrg /** 100cdc920a0Smrg * Method to destroy the private DRI display data. 101cdc920a0Smrg */ 102cdc920a0Smrg void (*destroyDisplay) (__GLXDRIdisplay * display); 103cdc920a0Smrg 1043464ebd5Sriastradh struct glx_screen *(*createScreen)(int screen, struct glx_display * priv); 105cdc920a0Smrg}; 106cdc920a0Smrg 107cdc920a0Smrgstruct __GLXDRIscreenRec { 108cdc920a0Smrg 1093464ebd5Sriastradh void (*destroyScreen)(struct glx_screen *psc); 110cdc920a0Smrg 1113464ebd5Sriastradh struct glx_context *(*createContext)(struct glx_screen *psc, 1123464ebd5Sriastradh struct glx_config *config, 1133464ebd5Sriastradh struct glx_context *shareList, 1143464ebd5Sriastradh int renderType); 115cdc920a0Smrg 1163464ebd5Sriastradh __GLXDRIdrawable *(*createDrawable)(struct glx_screen *psc, 117cdc920a0Smrg XID drawable, 118cdc920a0Smrg GLXDrawable glxDrawable, 1193464ebd5Sriastradh struct glx_config *config); 120cdc920a0Smrg 121cdc920a0Smrg int64_t (*swapBuffers)(__GLXDRIdrawable *pdraw, int64_t target_msc, 122af69d88dSmrg int64_t divisor, int64_t remainder, Bool flush); 123cdc920a0Smrg void (*copySubBuffer)(__GLXDRIdrawable *pdraw, 124af69d88dSmrg int x, int y, int width, int height, Bool flush); 1253464ebd5Sriastradh int (*getDrawableMSC)(struct glx_screen *psc, __GLXDRIdrawable *pdraw, 126cdc920a0Smrg int64_t *ust, int64_t *msc, int64_t *sbc); 127cdc920a0Smrg int (*waitForMSC)(__GLXDRIdrawable *pdraw, int64_t target_msc, 128cdc920a0Smrg int64_t divisor, int64_t remainder, int64_t *ust, 129cdc920a0Smrg int64_t *msc, int64_t *sbc); 130cdc920a0Smrg int (*waitForSBC)(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, 131cdc920a0Smrg int64_t *msc, int64_t *sbc); 1323464ebd5Sriastradh int (*setSwapInterval)(__GLXDRIdrawable *pdraw, int interval); 133cdc920a0Smrg int (*getSwapInterval)(__GLXDRIdrawable *pdraw); 134af69d88dSmrg int (*getBufferAge)(__GLXDRIdrawable *pdraw); 135cdc920a0Smrg}; 136cdc920a0Smrg 137cdc920a0Smrgstruct __GLXDRIdrawableRec 138cdc920a0Smrg{ 139cdc920a0Smrg void (*destroyDrawable) (__GLXDRIdrawable * drawable); 140cdc920a0Smrg 141cdc920a0Smrg XID xDrawable; 142cdc920a0Smrg XID drawable; 1433464ebd5Sriastradh struct glx_screen *psc; 144cdc920a0Smrg GLenum textureTarget; 145cdc920a0Smrg GLenum textureFormat; /* EXT_texture_from_pixmap support */ 1463464ebd5Sriastradh unsigned long eventMask; 1473464ebd5Sriastradh int refcount; 148cdc920a0Smrg}; 149cdc920a0Smrg 150cdc920a0Smrg/* 151cdc920a0Smrg** Function to create and DRI display data and initialize the display 152cdc920a0Smrg** dependent methods. 153cdc920a0Smrg*/ 154cdc920a0Smrgextern __GLXDRIdisplay *driswCreateDisplay(Display * dpy); 155cdc920a0Smrgextern __GLXDRIdisplay *driCreateDisplay(Display * dpy); 156cdc920a0Smrgextern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy); 15701e04c3fSmrgextern __GLXDRIdisplay *dri3_create_display(Display * dpy); 15801e04c3fSmrgextern __GLXDRIdisplay *driwindowsCreateDisplay(Display * dpy); 15901e04c3fSmrg 16001e04c3fSmrg/* 16101e04c3fSmrg** 16201e04c3fSmrg*/ 163cdc920a0Smrgextern void dri2InvalidateBuffers(Display *dpy, XID drawable); 1643464ebd5Sriastradhextern unsigned dri2GetSwapEventType(Display *dpy, XID drawable); 165cdc920a0Smrg 166cdc920a0Smrg/* 167cdc920a0Smrg** Functions to obtain driver configuration information from a direct 168cdc920a0Smrg** rendering client application 169cdc920a0Smrg*/ 170cdc920a0Smrgextern const char *glXGetScreenDriver(Display * dpy, int scrNum); 171cdc920a0Smrg 172cdc920a0Smrgextern const char *glXGetDriverConfig(const char *driverName); 173cdc920a0Smrg 174cdc920a0Smrg#endif 175cdc920a0Smrg 176cdc920a0Smrg/************************************************************************/ 177cdc920a0Smrg 178cdc920a0Smrg#define __GL_CLIENT_ATTRIB_STACK_DEPTH 16 179cdc920a0Smrg 180cdc920a0Smrgtypedef struct __GLXpixelStoreModeRec 181cdc920a0Smrg{ 182cdc920a0Smrg GLboolean swapEndian; 183cdc920a0Smrg GLboolean lsbFirst; 184cdc920a0Smrg GLuint rowLength; 185cdc920a0Smrg GLuint imageHeight; 186cdc920a0Smrg GLuint imageDepth; 187cdc920a0Smrg GLuint skipRows; 188cdc920a0Smrg GLuint skipPixels; 189cdc920a0Smrg GLuint skipImages; 190cdc920a0Smrg GLuint alignment; 191cdc920a0Smrg} __GLXpixelStoreMode; 192cdc920a0Smrg 193cdc920a0Smrg 194cdc920a0Smrgtypedef struct __GLXattributeRec 195cdc920a0Smrg{ 196cdc920a0Smrg GLuint mask; 197cdc920a0Smrg 198cdc920a0Smrg /** 199cdc920a0Smrg * Pixel storage state. Most of the pixel store mode state is kept 200cdc920a0Smrg * here and used by the client code to manage the packing and 201cdc920a0Smrg * unpacking of data sent to/received from the server. 202cdc920a0Smrg */ 203cdc920a0Smrg __GLXpixelStoreMode storePack, storeUnpack; 204cdc920a0Smrg 205cdc920a0Smrg /** 206cdc920a0Smrg * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically 207cdc920a0Smrg * disabled? 208cdc920a0Smrg */ 209cdc920a0Smrg GLboolean NoDrawArraysProtocol; 210cdc920a0Smrg 211cdc920a0Smrg /** 212cdc920a0Smrg * Vertex Array storage state. The vertex array component 213cdc920a0Smrg * state is stored here and is used to manage the packing of 214cdc920a0Smrg * DrawArrays data sent to the server. 215cdc920a0Smrg */ 216cdc920a0Smrg struct array_state_vector *array_state; 217cdc920a0Smrg} __GLXattribute; 218cdc920a0Smrg 219cdc920a0Smrgtypedef struct __GLXattributeMachineRec 220cdc920a0Smrg{ 221cdc920a0Smrg __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; 222cdc920a0Smrg __GLXattribute **stackPointer; 223cdc920a0Smrg} __GLXattributeMachine; 224cdc920a0Smrg 22501e04c3fSmrgstruct mesa_glinterop_device_info; 22601e04c3fSmrgstruct mesa_glinterop_export_in; 22701e04c3fSmrgstruct mesa_glinterop_export_out; 22801e04c3fSmrg 2293464ebd5Sriastradhstruct glx_context_vtable { 2303464ebd5Sriastradh void (*destroy)(struct glx_context *ctx); 2313464ebd5Sriastradh int (*bind)(struct glx_context *context, struct glx_context *old, 2323464ebd5Sriastradh GLXDrawable draw, GLXDrawable read); 233af69d88dSmrg void (*unbind)(struct glx_context *context, struct glx_context *new_ctx); 2343464ebd5Sriastradh void (*wait_gl)(struct glx_context *ctx); 2353464ebd5Sriastradh void (*wait_x)(struct glx_context *ctx); 2363464ebd5Sriastradh void (*use_x_font)(struct glx_context *ctx, 2373464ebd5Sriastradh Font font, int first, int count, int listBase); 2383464ebd5Sriastradh void (*bind_tex_image)(Display * dpy, 2393464ebd5Sriastradh GLXDrawable drawable, 2403464ebd5Sriastradh int buffer, const int *attrib_list); 2413464ebd5Sriastradh void (*release_tex_image)(Display * dpy, GLXDrawable drawable, int buffer); 2423464ebd5Sriastradh void * (*get_proc_address)(const char *symbol); 24301e04c3fSmrg int (*interop_query_device_info)(struct glx_context *ctx, 24401e04c3fSmrg struct mesa_glinterop_device_info *out); 24501e04c3fSmrg int (*interop_export_object)(struct glx_context *ctx, 24601e04c3fSmrg struct mesa_glinterop_export_in *in, 24701e04c3fSmrg struct mesa_glinterop_export_out *out); 2483464ebd5Sriastradh}; 2493464ebd5Sriastradh 250cdc920a0Smrg/** 251cdc920a0Smrg * GLX state that needs to be kept on the client. One of these records 252cdc920a0Smrg * exist for each context that has been made current by this client. 253cdc920a0Smrg */ 2543464ebd5Sriastradhstruct glx_context 255cdc920a0Smrg{ 256cdc920a0Smrg /** 257cdc920a0Smrg * \name Drawing command buffer. 258cdc920a0Smrg * 259cdc920a0Smrg * Drawing commands are packed into this buffer before being sent as a 260cdc920a0Smrg * single GLX protocol request. The buffer is sent when it overflows or 261cdc920a0Smrg * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location 262cdc920a0Smrg * in the buffer to be filled. \c limit is described above in the buffer 263cdc920a0Smrg * slop discussion. 264cdc920a0Smrg * 265cdc920a0Smrg * Commands that require large amounts of data to be transfered will 266cdc920a0Smrg * also use this buffer to hold a header that describes the large 267cdc920a0Smrg * command. 268cdc920a0Smrg * 269cdc920a0Smrg * These must be the first 6 fields since they are static initialized 270cdc920a0Smrg * in the dummy context in glxext.c 271cdc920a0Smrg */ 272cdc920a0Smrg /*@{ */ 273cdc920a0Smrg GLubyte *buf; 274cdc920a0Smrg GLubyte *pc; 275cdc920a0Smrg GLubyte *limit; 276cdc920a0Smrg GLubyte *bufEnd; 277cdc920a0Smrg GLint bufSize; 278cdc920a0Smrg /*@} */ 279cdc920a0Smrg 2803464ebd5Sriastradh const struct glx_context_vtable *vtable; 2813464ebd5Sriastradh 282cdc920a0Smrg /** 283cdc920a0Smrg * The XID of this rendering context. When the context is created a 284cdc920a0Smrg * new XID is allocated. This is set to None when the context is 285cdc920a0Smrg * destroyed but is still current to some thread. In this case the 286cdc920a0Smrg * context will be freed on next MakeCurrent. 287cdc920a0Smrg */ 288cdc920a0Smrg XID xid; 289cdc920a0Smrg 290cdc920a0Smrg /** 291cdc920a0Smrg * The XID of the \c shareList context. 292cdc920a0Smrg */ 293cdc920a0Smrg XID share_xid; 294cdc920a0Smrg 295cdc920a0Smrg /** 296cdc920a0Smrg * Screen number. 297cdc920a0Smrg */ 298cdc920a0Smrg GLint screen; 2993464ebd5Sriastradh struct glx_screen *psc; 300cdc920a0Smrg 301cdc920a0Smrg /** 302cdc920a0Smrg * \c GL_TRUE if the context was created with ImportContext, which 303cdc920a0Smrg * means the server-side context was created by another X client. 304cdc920a0Smrg */ 305cdc920a0Smrg GLboolean imported; 306cdc920a0Smrg 307cdc920a0Smrg /** 308cdc920a0Smrg * The context tag returned by MakeCurrent when this context is made 309cdc920a0Smrg * current. This tag is used to identify the context that a thread has 310cdc920a0Smrg * current so that proper server context management can be done. It is 311cdc920a0Smrg * used for all context specific commands (i.e., \c Render, \c RenderLarge, 312cdc920a0Smrg * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old 313cdc920a0Smrg * context)). 314cdc920a0Smrg */ 315cdc920a0Smrg GLXContextTag currentContextTag; 316cdc920a0Smrg 317cdc920a0Smrg /** 318cdc920a0Smrg * \name Rendering mode 319cdc920a0Smrg * 320cdc920a0Smrg * The rendering mode is kept on the client as well as the server. 321cdc920a0Smrg * When \c glRenderMode is called, the buffer associated with the 322cdc920a0Smrg * previous rendering mode (feedback or select) is filled. 323cdc920a0Smrg */ 324cdc920a0Smrg /*@{ */ 325cdc920a0Smrg GLenum renderMode; 326cdc920a0Smrg GLfloat *feedbackBuf; 327cdc920a0Smrg GLuint *selectBuf; 328cdc920a0Smrg /*@} */ 329cdc920a0Smrg 330cdc920a0Smrg /** 331cdc920a0Smrg * Fill newImage with the unpacked form of \c oldImage getting it 332cdc920a0Smrg * ready for transport to the server. 333cdc920a0Smrg */ 3343464ebd5Sriastradh void (*fillImage) (struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 335cdc920a0Smrg GLenum, const GLvoid *, GLubyte *, GLubyte *); 336cdc920a0Smrg 337cdc920a0Smrg /** 338cdc920a0Smrg * Client side attribs. 339cdc920a0Smrg */ 340cdc920a0Smrg __GLXattributeMachine attributes; 341cdc920a0Smrg 342cdc920a0Smrg /** 343cdc920a0Smrg * Client side error code. This is set when client side gl API 344cdc920a0Smrg * routines need to set an error because of a bad enumerant or 345cdc920a0Smrg * running out of memory, etc. 346cdc920a0Smrg */ 347cdc920a0Smrg GLenum error; 348cdc920a0Smrg 349cdc920a0Smrg /** 350cdc920a0Smrg * Whether this context does direct rendering. 351cdc920a0Smrg */ 352cdc920a0Smrg Bool isDirect; 353cdc920a0Smrg 3543464ebd5Sriastradh#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL) 3553464ebd5Sriastradh void *driContext; 3563464ebd5Sriastradh#endif 3573464ebd5Sriastradh 358cdc920a0Smrg /** 359cdc920a0Smrg * \c dpy of current display for this context. Will be \c NULL if not 360cdc920a0Smrg * current to any display, or if this is the "dummy context". 361cdc920a0Smrg */ 362cdc920a0Smrg Display *currentDpy; 363cdc920a0Smrg 364cdc920a0Smrg /** 365cdc920a0Smrg * The current drawable for this context. Will be None if this 366cdc920a0Smrg * context is not current to any drawable. currentReadable is below. 367cdc920a0Smrg */ 368cdc920a0Smrg GLXDrawable currentDrawable; 369cdc920a0Smrg 370cdc920a0Smrg /** 371cdc920a0Smrg * \name GL Constant Strings 372cdc920a0Smrg * 373cdc920a0Smrg * Constant strings that describe the server implementation 374cdc920a0Smrg * These pertain to GL attributes, not to be confused with 375cdc920a0Smrg * GLX versioning attributes. 376cdc920a0Smrg */ 377cdc920a0Smrg /*@{ */ 378cdc920a0Smrg GLubyte *vendor; 379cdc920a0Smrg GLubyte *renderer; 380cdc920a0Smrg GLubyte *version; 381cdc920a0Smrg GLubyte *extensions; 382cdc920a0Smrg /*@} */ 383cdc920a0Smrg 384cdc920a0Smrg /** 385cdc920a0Smrg * Maximum small render command size. This is the smaller of 64k and 386cdc920a0Smrg * the size of the above buffer. 387cdc920a0Smrg */ 388cdc920a0Smrg GLint maxSmallRenderCommandSize; 389cdc920a0Smrg 390cdc920a0Smrg /** 391cdc920a0Smrg * Major opcode for the extension. Copied here so a lookup isn't 392cdc920a0Smrg * needed. 393cdc920a0Smrg */ 394cdc920a0Smrg GLint majorOpcode; 395cdc920a0Smrg 396cdc920a0Smrg /** 3973464ebd5Sriastradh * Pointer to the config used to create this context. 398cdc920a0Smrg */ 3993464ebd5Sriastradh struct glx_config *config; 400cdc920a0Smrg 401cdc920a0Smrg /** 402cdc920a0Smrg * The current read-drawable for this context. Will be None if this 403cdc920a0Smrg * context is not current to any drawable. 404cdc920a0Smrg * 405cdc920a0Smrg * \since Internal API version 20030606. 406cdc920a0Smrg */ 407cdc920a0Smrg GLXDrawable currentReadable; 408cdc920a0Smrg 409cdc920a0Smrg /** 410cdc920a0Smrg * Pointer to client-state data that is private to libGL. This is only 411cdc920a0Smrg * used for indirect rendering contexts. 412cdc920a0Smrg * 413cdc920a0Smrg * No internal API version change was made for this change. Client-side 414cdc920a0Smrg * drivers should NEVER use this data or even care that it exists. 415cdc920a0Smrg */ 416cdc920a0Smrg void *client_state_private; 417cdc920a0Smrg 418cdc920a0Smrg /** 419cdc920a0Smrg * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE. 420cdc920a0Smrg */ 421cdc920a0Smrg int renderType; 422cdc920a0Smrg 423cdc920a0Smrg /** 424cdc920a0Smrg * \name Raw server GL version 425cdc920a0Smrg * 426cdc920a0Smrg * True core GL version supported by the server. This is the raw value 427cdc920a0Smrg * returned by the server, and it may not reflect what is actually 428cdc920a0Smrg * supported (or reported) by the client-side library. 429cdc920a0Smrg */ 430cdc920a0Smrg /*@{ */ 431cdc920a0Smrg int server_major; /**< Major version number. */ 432cdc920a0Smrg int server_minor; /**< Minor version number. */ 433cdc920a0Smrg /*@} */ 434cdc920a0Smrg 435cdc920a0Smrg /** 4363464ebd5Sriastradh * Number of threads we're currently current in. 437cdc920a0Smrg */ 4383464ebd5Sriastradh unsigned long thread_refcount; 439cdc920a0Smrg 440cdc920a0Smrg char gl_extension_bits[__GL_EXT_BYTES]; 441cdc920a0Smrg}; 442cdc920a0Smrg 4433464ebd5Sriastradhextern Bool 4443464ebd5Sriastradhglx_context_init(struct glx_context *gc, 4453464ebd5Sriastradh struct glx_screen *psc, struct glx_config *fbconfig); 4463464ebd5Sriastradh 447cdc920a0Smrg#define __glXSetError(gc,code) \ 448cdc920a0Smrg if (!(gc)->error) { \ 449cdc920a0Smrg (gc)->error = code; \ 450cdc920a0Smrg } 451cdc920a0Smrg 4523464ebd5Sriastradhextern void __glFreeAttributeState(struct glx_context *); 453cdc920a0Smrg 454cdc920a0Smrg/************************************************************************/ 455cdc920a0Smrg 456cdc920a0Smrg/** 457cdc920a0Smrg * The size of the largest drawing command known to the implementation 458cdc920a0Smrg * that will use the GLXRender GLX command. In this case it is 459cdc920a0Smrg * \c glPolygonStipple. 460cdc920a0Smrg */ 461cdc920a0Smrg#define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156 462cdc920a0Smrg 463cdc920a0Smrg/** 464cdc920a0Smrg * To keep the implementation fast, the code uses a "limit" pointer 465cdc920a0Smrg * to determine when the drawing command buffer is too full to hold 466cdc920a0Smrg * another fixed size command. This constant defines the amount of 467cdc920a0Smrg * space that must always be available in the drawing command buffer 468cdc920a0Smrg * at all times for the implementation to work. It is important that 469cdc920a0Smrg * the number be just large enough, but not so large as to reduce the 470cdc920a0Smrg * efficacy of the buffer. The "+32" is just to keep the code working 471cdc920a0Smrg * in case somebody counts wrong. 472cdc920a0Smrg */ 473cdc920a0Smrg#define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32) 474cdc920a0Smrg 475cdc920a0Smrg/** 476cdc920a0Smrg * This implementation uses a smaller threshold for switching 477cdc920a0Smrg * to the RenderLarge protocol than the protcol requires so that 478cdc920a0Smrg * large copies don't occur. 479cdc920a0Smrg */ 480cdc920a0Smrg#define __GLX_RENDER_CMD_SIZE_LIMIT 4096 481cdc920a0Smrg 482cdc920a0Smrg/** 483cdc920a0Smrg * One of these records exists per screen of the display. It contains 484cdc920a0Smrg * a pointer to the config data for that screen (if the screen supports GL). 485cdc920a0Smrg */ 4863464ebd5Sriastradhstruct glx_screen_vtable { 4873464ebd5Sriastradh struct glx_context *(*create_context)(struct glx_screen *psc, 4883464ebd5Sriastradh struct glx_config *config, 4893464ebd5Sriastradh struct glx_context *shareList, 4903464ebd5Sriastradh int renderType); 491af69d88dSmrg 492af69d88dSmrg struct glx_context *(*create_context_attribs)(struct glx_screen *psc, 493af69d88dSmrg struct glx_config *config, 494af69d88dSmrg struct glx_context *shareList, 495af69d88dSmrg unsigned num_attrib, 496af69d88dSmrg const uint32_t *attribs, 497af69d88dSmrg unsigned *error); 498af69d88dSmrg int (*query_renderer_integer)(struct glx_screen *psc, 499af69d88dSmrg int attribute, 500af69d88dSmrg unsigned int *value); 501af69d88dSmrg int (*query_renderer_string)(struct glx_screen *psc, 502af69d88dSmrg int attribute, 503af69d88dSmrg const char **value); 5043464ebd5Sriastradh}; 5053464ebd5Sriastradh 5063464ebd5Sriastradhstruct glx_screen 507cdc920a0Smrg{ 5083464ebd5Sriastradh const struct glx_screen_vtable *vtable; 5093464ebd5Sriastradh 510cdc920a0Smrg /** 511cdc920a0Smrg * GLX extension string reported by the X-server. 512cdc920a0Smrg */ 513cdc920a0Smrg const char *serverGLXexts; 514cdc920a0Smrg 515cdc920a0Smrg /** 516cdc920a0Smrg * GLX extension string to be reported to applications. This is the 517cdc920a0Smrg * set of extensions that the application can actually use. 518cdc920a0Smrg */ 519cdc920a0Smrg char *effectiveGLXexts; 520cdc920a0Smrg 5213464ebd5Sriastradh struct glx_display *display; 5223464ebd5Sriastradh 5233464ebd5Sriastradh Display *dpy; 5243464ebd5Sriastradh int scr; 5253464ebd5Sriastradh 526cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 527cdc920a0Smrg /** 528cdc920a0Smrg * Per screen direct rendering interface functions and data. 529cdc920a0Smrg */ 530cdc920a0Smrg __GLXDRIscreen *driScreen; 531cdc920a0Smrg#endif 532cdc920a0Smrg 533cdc920a0Smrg /** 534cdc920a0Smrg * Linked list of glx visuals and fbconfigs for this screen. 535cdc920a0Smrg */ 5363464ebd5Sriastradh struct glx_config *visuals, *configs; 537cdc920a0Smrg 538cdc920a0Smrg /** 539cdc920a0Smrg * Per-screen dynamic GLX extension tracking. The \c direct_support 540cdc920a0Smrg * field only contains enough bits for 64 extensions. Should libGL 541cdc920a0Smrg * ever need to track more than 64 GLX extensions, we can safely grow 5423464ebd5Sriastradh * this field. The \c struct glx_screen structure is not used outside 543cdc920a0Smrg * libGL. 544cdc920a0Smrg */ 545cdc920a0Smrg /*@{ */ 546cdc920a0Smrg unsigned char direct_support[8]; 547cdc920a0Smrg GLboolean ext_list_first_time; 548cdc920a0Smrg /*@} */ 549cdc920a0Smrg 550cdc920a0Smrg}; 551cdc920a0Smrg 552cdc920a0Smrg/** 553cdc920a0Smrg * Per display private data. One of these records exists for each display 554cdc920a0Smrg * that is using the OpenGL (GLX) extension. 555cdc920a0Smrg */ 5563464ebd5Sriastradhstruct glx_display 557cdc920a0Smrg{ 5583464ebd5Sriastradh /* The extension protocol codes */ 5593464ebd5Sriastradh XExtCodes *codes; 5603464ebd5Sriastradh struct glx_display *next; 5613464ebd5Sriastradh 562cdc920a0Smrg /** 563cdc920a0Smrg * Back pointer to the display 564cdc920a0Smrg */ 565cdc920a0Smrg Display *dpy; 566cdc920a0Smrg 567cdc920a0Smrg /** 568cdc920a0Smrg * The \c majorOpcode is common to all connections to the same server. 569cdc920a0Smrg * It is also copied into the context structure. 570cdc920a0Smrg */ 571cdc920a0Smrg int majorOpcode; 572cdc920a0Smrg 573cdc920a0Smrg /** 574cdc920a0Smrg * \name Server Version 575cdc920a0Smrg * 576cdc920a0Smrg * Major and minor version returned by the server during initialization. 577cdc920a0Smrg */ 578cdc920a0Smrg /*@{ */ 579cdc920a0Smrg int majorVersion, minorVersion; 580cdc920a0Smrg /*@} */ 581cdc920a0Smrg 582cdc920a0Smrg /** 583cdc920a0Smrg * \name Storage for the servers GLX vendor and versions strings. 584cdc920a0Smrg * 585cdc920a0Smrg * These are the same for all screens on this display. These fields will 586cdc920a0Smrg * be filled in on demand. 587cdc920a0Smrg */ 588cdc920a0Smrg /*@{ */ 589cdc920a0Smrg const char *serverGLXvendor; 590cdc920a0Smrg const char *serverGLXversion; 591cdc920a0Smrg /*@} */ 592cdc920a0Smrg 593cdc920a0Smrg /** 594cdc920a0Smrg * Configurations of visuals for all screens on this display. 595cdc920a0Smrg * Also, per screen data which now includes the server \c GLX_EXTENSION 596cdc920a0Smrg * string. 597cdc920a0Smrg */ 5983464ebd5Sriastradh struct glx_screen **screens; 599cdc920a0Smrg 600af69d88dSmrg __glxHashTable *glXDrawHash; 601af69d88dSmrg 602cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 6033464ebd5Sriastradh __glxHashTable *drawHash; 6043464ebd5Sriastradh 605cdc920a0Smrg /** 606cdc920a0Smrg * Per display direct rendering interface functions and data. 607cdc920a0Smrg */ 608cdc920a0Smrg __GLXDRIdisplay *driswDisplay; 609cdc920a0Smrg __GLXDRIdisplay *driDisplay; 610cdc920a0Smrg __GLXDRIdisplay *dri2Display; 611af69d88dSmrg __GLXDRIdisplay *dri3Display; 612cdc920a0Smrg#endif 61301e04c3fSmrg#ifdef GLX_USE_WINDOWSGL 61401e04c3fSmrg __GLXDRIdisplay *windowsdriDisplay; 61501e04c3fSmrg#endif 616cdc920a0Smrg}; 617cdc920a0Smrg 618af69d88dSmrgstruct glx_drawable { 619af69d88dSmrg XID xDrawable; 620af69d88dSmrg XID drawable; 621af69d88dSmrg 622af69d88dSmrg uint32_t lastEventSbc; 623af69d88dSmrg int64_t eventSbcWrap; 624af69d88dSmrg}; 625af69d88dSmrg 6263464ebd5Sriastradhextern int 6273464ebd5Sriastradhglx_screen_init(struct glx_screen *psc, 6283464ebd5Sriastradh int screen, struct glx_display * priv); 6293464ebd5Sriastradhextern void 6303464ebd5Sriastradhglx_screen_cleanup(struct glx_screen *psc); 631cdc920a0Smrg 6323464ebd5Sriastradh#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 6333464ebd5Sriastradhextern __GLXDRIdrawable * 6343464ebd5Sriastradhdri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id); 6353464ebd5Sriastradh#endif 636cdc920a0Smrg 6373464ebd5Sriastradhextern GLubyte *__glXFlushRenderBuffer(struct glx_context *, GLubyte *); 6383464ebd5Sriastradh 6393464ebd5Sriastradhextern void __glXSendLargeChunk(struct glx_context * gc, GLint requestNumber, 640cdc920a0Smrg GLint totalRequests, 641cdc920a0Smrg const GLvoid * data, GLint dataLen); 642cdc920a0Smrg 6433464ebd5Sriastradhextern void __glXSendLargeCommand(struct glx_context *, const GLvoid *, GLint, 644cdc920a0Smrg const GLvoid *, GLint); 645cdc920a0Smrg 646cdc920a0Smrg/* Initialize the GLX extension for dpy */ 6473464ebd5Sriastradhextern struct glx_display *__glXInitialize(Display *); 648cdc920a0Smrg 649cdc920a0Smrg/************************************************************************/ 650cdc920a0Smrg 651cdc920a0Smrgextern int __glXDebug; 652cdc920a0Smrg 653cdc920a0Smrg/* This is per-thread storage in an MT environment */ 654cdc920a0Smrg 6553464ebd5Sriastradhextern void __glXSetCurrentContext(struct glx_context * c); 656cdc920a0Smrg 657cdc920a0Smrg# if defined( GLX_USE_TLS ) 658cdc920a0Smrg 659cdc920a0Smrgextern __thread void *__glX_tls_Context 660cdc920a0Smrg __attribute__ ((tls_model("initial-exec"))); 661cdc920a0Smrg 662e81a0f50Smaya#if defined(__NetBSD__) 663e81a0f50Smaya# define __glXGetCurrentContext() (likely(__glX_tls_Context) ? __glX_tls_Context : (void*)&dummyContext) 664e81a0f50Smaya#else 665cdc920a0Smrg# define __glXGetCurrentContext() __glX_tls_Context 666e81a0f50Smaya#endif 667cdc920a0Smrg 668cdc920a0Smrg# else 669cdc920a0Smrg 6703464ebd5Sriastradhextern struct glx_context *__glXGetCurrentContext(void); 671cdc920a0Smrg 672cdc920a0Smrg# endif /* defined( GLX_USE_TLS ) */ 673cdc920a0Smrg 674cdc920a0Smrgextern void __glXSetCurrentContextNull(void); 675cdc920a0Smrg 676cdc920a0Smrg 677cdc920a0Smrg/* 678cdc920a0Smrg** Global lock for all threads in this address space using the GLX 679cdc920a0Smrg** extension 680cdc920a0Smrg*/ 681cdc920a0Smrgextern pthread_mutex_t __glXmutex; 682cdc920a0Smrg#define __glXLock() pthread_mutex_lock(&__glXmutex) 683cdc920a0Smrg#define __glXUnlock() pthread_mutex_unlock(&__glXmutex) 684cdc920a0Smrg 685cdc920a0Smrg/* 686cdc920a0Smrg** Setup for a command. Initialize the extension for dpy if necessary. 687cdc920a0Smrg*/ 688cdc920a0Smrgextern CARD8 __glXSetupForCommand(Display * dpy); 689cdc920a0Smrg 690cdc920a0Smrg/************************************************************************/ 691cdc920a0Smrg 692cdc920a0Smrg/* 693cdc920a0Smrg** Data conversion and packing support. 694cdc920a0Smrg*/ 695cdc920a0Smrg 696cdc920a0Smrgextern const GLuint __glXDefaultPixelStore[9]; 697cdc920a0Smrg 698cdc920a0Smrg/* Send an image to the server using RenderLarge. */ 6993464ebd5Sriastradhextern void __glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim, 700cdc920a0Smrg GLint width, GLint height, GLint depth, 701cdc920a0Smrg GLenum format, GLenum type, 702cdc920a0Smrg const GLvoid * src, GLubyte * pc, 703cdc920a0Smrg GLubyte * modes); 704cdc920a0Smrg 705cdc920a0Smrg/* Return the size, in bytes, of some pixel data */ 706cdc920a0Smrgextern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum); 707cdc920a0Smrg 708cdc920a0Smrg/* Return the number of elements per group of a specified format*/ 709cdc920a0Smrgextern GLint __glElementsPerGroup(GLenum format, GLenum type); 710cdc920a0Smrg 711cdc920a0Smrg/* Return the number of bytes per element, based on the element type (other 712cdc920a0Smrg** than GL_BITMAP). 713cdc920a0Smrg*/ 714cdc920a0Smrgextern GLint __glBytesPerElement(GLenum type); 715cdc920a0Smrg 716cdc920a0Smrg/* 717cdc920a0Smrg** Fill the transport buffer with the data from the users buffer, 718cdc920a0Smrg** applying some of the pixel store modes (unpack modes) to the data 719cdc920a0Smrg** first. As a side effect of this call, the "modes" field is 720cdc920a0Smrg** updated to contain the modes needed by the server to decode the 721cdc920a0Smrg** sent data. 722cdc920a0Smrg*/ 7233464ebd5Sriastradhextern void __glFillImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 724cdc920a0Smrg GLenum, const GLvoid *, GLubyte *, GLubyte *); 725cdc920a0Smrg 726cdc920a0Smrg/* Copy map data with a stride into a packed buffer */ 727cdc920a0Smrgextern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *); 728cdc920a0Smrgextern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *); 729cdc920a0Smrgextern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint, 730cdc920a0Smrg const GLfloat *, GLfloat *); 731cdc920a0Smrgextern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint, 732cdc920a0Smrg const GLdouble *, GLdouble *); 733cdc920a0Smrg 734cdc920a0Smrg/* 735cdc920a0Smrg** Empty an image out of the reply buffer into the clients memory applying 736cdc920a0Smrg** the pack modes to pack back into the clients requested format. 737cdc920a0Smrg*/ 7383464ebd5Sriastradhextern void __glEmptyImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 739cdc920a0Smrg GLenum, const GLubyte *, GLvoid *); 740cdc920a0Smrg 741cdc920a0Smrg 742cdc920a0Smrg/* 743cdc920a0Smrg** Allocate and Initialize Vertex Array client state, and free. 744cdc920a0Smrg*/ 7453464ebd5Sriastradhextern void __glXInitVertexArrayState(struct glx_context *); 7463464ebd5Sriastradhextern void __glXFreeVertexArrayState(struct glx_context *); 747cdc920a0Smrg 748cdc920a0Smrg/* 749cdc920a0Smrg** Inform the Server of the major and minor numbers and of the client 750cdc920a0Smrg** libraries extension string. 751cdc920a0Smrg*/ 752cdc920a0Smrgextern void __glXClientInfo(Display * dpy, int opcode); 753cdc920a0Smrg 754af69d88dSmrg_X_HIDDEN void 755af69d88dSmrg__glX_send_client_info(struct glx_display *glx_dpy); 756af69d88dSmrg 757cdc920a0Smrg/************************************************************************/ 758cdc920a0Smrg 759cdc920a0Smrg/* 760cdc920a0Smrg** Declarations that should be in Xlib 761cdc920a0Smrg*/ 762cdc920a0Smrg#ifdef __GL_USE_OUR_PROTOTYPES 763cdc920a0Smrgextern void _XFlush(Display *); 764cdc920a0Smrgextern Status _XReply(Display *, xReply *, int, Bool); 765cdc920a0Smrgextern void _XRead(Display *, void *, long); 766cdc920a0Smrgextern void _XSend(Display *, const void *, long); 767cdc920a0Smrg#endif 768cdc920a0Smrg 769cdc920a0Smrg 7703464ebd5Sriastradhextern void __glXInitializeVisualConfigFromTags(struct glx_config * config, 771cdc920a0Smrg int count, const INT32 * bp, 772cdc920a0Smrg Bool tagged_only, 773cdc920a0Smrg Bool fbconfig_style_tags); 774cdc920a0Smrg 775cdc920a0Smrgextern char *__glXQueryServerString(Display * dpy, int opcode, 776cdc920a0Smrg CARD32 screen, CARD32 name); 777cdc920a0Smrgextern char *__glXGetString(Display * dpy, int opcode, 778cdc920a0Smrg CARD32 screen, CARD32 name); 779cdc920a0Smrg 780cdc920a0Smrgextern const char __glXGLClientVersion[]; 781cdc920a0Smrgextern const char __glXGLClientExtensions[]; 782cdc920a0Smrg 783cdc920a0Smrg/* Get the unadjusted system time */ 784cdc920a0Smrgextern int __glXGetUST(int64_t * ust); 785cdc920a0Smrg 786cdc920a0Smrgextern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, 787cdc920a0Smrg int32_t * numerator, 788cdc920a0Smrg int32_t * denominator); 789cdc920a0Smrg 790cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 7913464ebd5Sriastradhextern GLboolean 792af69d88dSmrg__glxGetMscRate(struct glx_screen *psc, 7933464ebd5Sriastradh int32_t * numerator, int32_t * denominator); 794cdc920a0Smrg 795cdc920a0Smrg/* So that dri2.c:DRI2WireToEvent() can access 796cdc920a0Smrg * glx_info->codes->first_event */ 797cdc920a0SmrgXExtDisplayInfo *__glXFindDisplay (Display *dpy); 798cdc920a0Smrg 7993464ebd5Sriastradhextern void 8003464ebd5SriastradhGarbageCollectDRIDrawables(struct glx_screen *psc); 8013464ebd5Sriastradh 802cdc920a0Smrgextern __GLXDRIdrawable * 8033464ebd5SriastradhGetGLXDRIDrawable(Display *dpy, GLXDrawable drawable); 8043464ebd5Sriastradh#endif 805cdc920a0Smrg 806af69d88dSmrgextern struct glx_screen *GetGLXScreenConfigs(Display * dpy, int scrn); 807af69d88dSmrg 8083464ebd5Sriastradh#ifdef GLX_USE_APPLEGL 8093464ebd5Sriastradhextern struct glx_screen * 8103464ebd5Sriastradhapplegl_create_screen(int screen, struct glx_display * priv); 8113464ebd5Sriastradh 8123464ebd5Sriastradhextern struct glx_context * 8133464ebd5Sriastradhapplegl_create_context(struct glx_screen *psc, 8143464ebd5Sriastradh struct glx_config *mode, 8153464ebd5Sriastradh struct glx_context *shareList, int renderType); 8163464ebd5Sriastradh 8173464ebd5Sriastradhextern int 8183464ebd5Sriastradhapplegl_create_display(struct glx_display *display); 819cdc920a0Smrg#endif 820cdc920a0Smrg 821af69d88dSmrgextern Bool validate_renderType_against_config(const struct glx_config *config, 822af69d88dSmrg int renderType); 823af69d88dSmrg 824af69d88dSmrg 825af69d88dSmrgextern struct glx_drawable *GetGLXDrawable(Display *dpy, GLXDrawable drawable); 826af69d88dSmrgextern int InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, 827af69d88dSmrg XID xDrawable, GLXDrawable drawable); 828af69d88dSmrgextern void DestroyGLXDrawable(Display *dpy, GLXDrawable drawable); 829af69d88dSmrg 8303464ebd5Sriastradhextern struct glx_context dummyContext; 8313464ebd5Sriastradh 8323464ebd5Sriastradhextern struct glx_screen * 8333464ebd5Sriastradhindirect_create_screen(int screen, struct glx_display * priv); 8343464ebd5Sriastradhextern struct glx_context * 8353464ebd5Sriastradhindirect_create_context(struct glx_screen *psc, 8363464ebd5Sriastradh struct glx_config *mode, 8373464ebd5Sriastradh struct glx_context *shareList, int renderType); 838af69d88dSmrgextern struct glx_context * 839af69d88dSmrgindirect_create_context_attribs(struct glx_screen *base, 840af69d88dSmrg struct glx_config *config_base, 841af69d88dSmrg struct glx_context *shareList, 842af69d88dSmrg unsigned num_attribs, 843af69d88dSmrg const uint32_t *attribs, 844af69d88dSmrg unsigned *error); 8453464ebd5Sriastradh 84601e04c3fSmrg 84701e04c3fSmrgextern int __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable, 84801e04c3fSmrg int attribute, unsigned int *value); 84901e04c3fSmrg 85001e04c3fSmrg#ifdef __cplusplus 85101e04c3fSmrg} 85201e04c3fSmrg#endif 85301e04c3fSmrg 854cdc920a0Smrg#endif /* !__GLX_client_h__ */ 855