1c1f859d4Smrg/* 2c1f859d4Smrg * Mesa 3-D graphics library 3c1f859d4Smrg * 4c1f859d4Smrg * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 5c1f859d4Smrg * 6c1f859d4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7c1f859d4Smrg * copy of this software and associated documentation files (the "Software"), 8c1f859d4Smrg * to deal in the Software without restriction, including without limitation 9c1f859d4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10c1f859d4Smrg * and/or sell copies of the Software, and to permit persons to whom the 11c1f859d4Smrg * Software is furnished to do so, subject to the following conditions: 12c1f859d4Smrg * 13c1f859d4Smrg * The above copyright notice and this permission notice shall be included 14c1f859d4Smrg * in all copies or substantial portions of the Software. 15c1f859d4Smrg * 16c1f859d4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17c1f859d4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18c1f859d4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 23c1f859d4Smrg */ 24c1f859d4Smrg 25c1f859d4Smrg 26c1f859d4Smrg/* 27c1f859d4Smrg * Mesa/X11 interface. This header file serves as the documentation for 28c1f859d4Smrg * the Mesa/X11 interface functions. 29c1f859d4Smrg * 30c1f859d4Smrg * Note: this interface isn't intended for user programs. It's primarily 31c1f859d4Smrg * just for implementing the pseudo-GLX interface. 32c1f859d4Smrg */ 33c1f859d4Smrg 34c1f859d4Smrg 35c1f859d4Smrg/* Sample Usage: 36c1f859d4Smrg 37c1f859d4SmrgIn addition to the usual X calls to select a visual, create a colormap 38c1f859d4Smrgand create a window, you must do the following to use the X/Mesa interface: 39c1f859d4Smrg 40c1f859d4Smrg1. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo. 41c1f859d4Smrg 42c1f859d4Smrg2. Call XMesaCreateContext() to create an X/Mesa rendering context, given 43c1f859d4Smrg the XMesaVisual. 44c1f859d4Smrg 45c1f859d4Smrg3. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window 46c1f859d4Smrg and XMesaVisual. 47c1f859d4Smrg 48c1f859d4Smrg4. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and 49c1f859d4Smrg to make the context the current one. 50c1f859d4Smrg 51c1f859d4Smrg5. Make gl* calls to render your graphics. 52c1f859d4Smrg 53c1f859d4Smrg6. Use XMesaSwapBuffers() when double buffering to swap front/back buffers. 54c1f859d4Smrg 55c1f859d4Smrg7. Before the X window is destroyed, call XMesaDestroyBuffer(). 56c1f859d4Smrg 57c1f859d4Smrg8. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext. 58c1f859d4Smrg 59c1f859d4Smrg*/ 60c1f859d4Smrg 61c1f859d4Smrg 62c1f859d4Smrg 63c1f859d4Smrg 64c1f859d4Smrg#ifndef XMESA_H 65c1f859d4Smrg#define XMESA_H 66c1f859d4Smrg 67c1f859d4Smrg#include <X11/Xlib.h> 68c1f859d4Smrg#include <X11/Xutil.h> 69c1f859d4Smrg#include "xmesa_x.h" 70c1f859d4Smrg#include "GL/gl.h" 71c1f859d4Smrg 7201e04c3fSmrg#ifdef __cplusplus 7301e04c3fSmrgextern "C" { 7401e04c3fSmrg#endif 7501e04c3fSmrg 76c1f859d4Smrg#define XMESA_MAJOR_VERSION 6 77c1f859d4Smrg#define XMESA_MINOR_VERSION 3 78c1f859d4Smrg 79c1f859d4Smrg 80c1f859d4Smrg 81c1f859d4Smrg/* 82c1f859d4Smrg * Values passed to XMesaGetString: 83c1f859d4Smrg */ 84c1f859d4Smrg#define XMESA_VERSION 1 85c1f859d4Smrg#define XMESA_EXTENSIONS 2 86c1f859d4Smrg 87c1f859d4Smrg 88c1f859d4Smrgtypedef struct xmesa_context *XMesaContext; 89c1f859d4Smrg 90c1f859d4Smrgtypedef struct xmesa_visual *XMesaVisual; 91c1f859d4Smrg 92c1f859d4Smrgtypedef struct xmesa_buffer *XMesaBuffer; 93c1f859d4Smrg 94c1f859d4Smrg 95c1f859d4Smrg 96c1f859d4Smrg/* 97c1f859d4Smrg * Create a new X/Mesa visual. 98c1f859d4Smrg * Input: display - X11 display 99c1f859d4Smrg * visinfo - an XVisualInfo pointer 100c1f859d4Smrg * rgb_flag - GL_TRUE = RGB mode, 101c1f859d4Smrg * GL_FALSE = color index mode 102c1f859d4Smrg * alpha_flag - alpha buffer requested? 103c1f859d4Smrg * db_flag - GL_TRUE = double-buffered, 104c1f859d4Smrg * GL_FALSE = single buffered 105c1f859d4Smrg * stereo_flag - stereo visual? 106c1f859d4Smrg * ximage_flag - GL_TRUE = use an XImage for back buffer, 107c1f859d4Smrg * GL_FALSE = use an off-screen pixmap for back buffer 108c1f859d4Smrg * depth_size - requested bits/depth values, or zero 109c1f859d4Smrg * stencil_size - requested bits/stencil values, or zero 110c1f859d4Smrg * accum_red_size - requested bits/red accum values, or zero 111c1f859d4Smrg * accum_green_size - requested bits/green accum values, or zero 112c1f859d4Smrg * accum_blue_size - requested bits/blue accum values, or zero 113c1f859d4Smrg * accum_alpha_size - requested bits/alpha accum values, or zero 114c1f859d4Smrg * num_samples - number of samples/pixel if multisampling, or zero 115c1f859d4Smrg * level - visual level, usually 0 116c1f859d4Smrg * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT 117c1f859d4Smrg * Return; a new XMesaVisual or 0 if error. 118c1f859d4Smrg */ 119c1f859d4Smrgextern XMesaVisual XMesaCreateVisual( XMesaDisplay *display, 120c1f859d4Smrg XMesaVisualInfo visinfo, 121c1f859d4Smrg GLboolean rgb_flag, 122c1f859d4Smrg GLboolean alpha_flag, 123c1f859d4Smrg GLboolean db_flag, 124c1f859d4Smrg GLboolean stereo_flag, 125c1f859d4Smrg GLboolean ximage_flag, 126c1f859d4Smrg GLint depth_size, 127c1f859d4Smrg GLint stencil_size, 128c1f859d4Smrg GLint accum_red_size, 129c1f859d4Smrg GLint accum_green_size, 130c1f859d4Smrg GLint accum_blue_size, 131c1f859d4Smrg GLint accum_alpha_size, 132c1f859d4Smrg GLint num_samples, 133c1f859d4Smrg GLint level, 134c1f859d4Smrg GLint visualCaveat ); 135c1f859d4Smrg 136c1f859d4Smrg/* 137c1f859d4Smrg * Destroy an XMesaVisual, but not the associated XVisualInfo. 138c1f859d4Smrg */ 139c1f859d4Smrgextern void XMesaDestroyVisual( XMesaVisual v ); 140c1f859d4Smrg 141c1f859d4Smrg 142c1f859d4Smrg 143c1f859d4Smrg/* 144c1f859d4Smrg * Create a new XMesaContext for rendering into an X11 window. 145c1f859d4Smrg * 146c1f859d4Smrg * Input: visual - an XMesaVisual 147c1f859d4Smrg * share_list - another XMesaContext with which to share display 148c1f859d4Smrg * lists or NULL if no sharing is wanted. 149c1f859d4Smrg * Return: an XMesaContext or NULL if error. 150c1f859d4Smrg */ 151c1f859d4Smrgextern XMesaContext XMesaCreateContext( XMesaVisual v, 152c1f859d4Smrg XMesaContext share_list ); 153c1f859d4Smrg 154c1f859d4Smrg 155c1f859d4Smrg/* 156c1f859d4Smrg * Destroy a rendering context as returned by XMesaCreateContext() 157c1f859d4Smrg */ 158c1f859d4Smrgextern void XMesaDestroyContext( XMesaContext c ); 159c1f859d4Smrg 160c1f859d4Smrg 161c1f859d4Smrg 162c1f859d4Smrg 163c1f859d4Smrg/* 164c1f859d4Smrg * Create an XMesaBuffer from an X window. 165c1f859d4Smrg */ 166c1f859d4Smrgextern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, XMesaWindow w ); 167c1f859d4Smrg 168c1f859d4Smrg 169c1f859d4Smrg/* 170c1f859d4Smrg * Create an XMesaBuffer from an X pixmap. 171c1f859d4Smrg */ 172c1f859d4Smrgextern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v, 173c1f859d4Smrg XMesaPixmap p, 174c1f859d4Smrg XMesaColormap cmap ); 175c1f859d4Smrg 176c1f859d4Smrg 177c1f859d4Smrg/* 178c1f859d4Smrg * Destroy an XMesaBuffer, but not the corresponding window or pixmap. 179c1f859d4Smrg */ 180c1f859d4Smrgextern void XMesaDestroyBuffer( XMesaBuffer b ); 181c1f859d4Smrg 182c1f859d4Smrg 183c1f859d4Smrg/* 184c1f859d4Smrg * Return the XMesaBuffer handle which corresponds to an X drawable, if any. 185c1f859d4Smrg * 186c1f859d4Smrg * New in Mesa 2.3. 187c1f859d4Smrg */ 188c1f859d4Smrgextern XMesaBuffer XMesaFindBuffer( XMesaDisplay *dpy, 189c1f859d4Smrg XMesaDrawable d ); 190c1f859d4Smrg 191c1f859d4Smrg 192c1f859d4Smrg 193c1f859d4Smrg/* 194c1f859d4Smrg * Bind a buffer to a context and make the context the current one. 195c1f859d4Smrg */ 196c1f859d4Smrgextern GLboolean XMesaMakeCurrent( XMesaContext c, 197c1f859d4Smrg XMesaBuffer b ); 198c1f859d4Smrg 199c1f859d4Smrg 200c1f859d4Smrg/* 201c1f859d4Smrg * Bind two buffers (read and draw) to a context and make the 202c1f859d4Smrg * context the current one. 203c1f859d4Smrg * New in Mesa 3.3 204c1f859d4Smrg */ 205c1f859d4Smrgextern GLboolean XMesaMakeCurrent2( XMesaContext c, 206c1f859d4Smrg XMesaBuffer drawBuffer, 207c1f859d4Smrg XMesaBuffer readBuffer ); 208c1f859d4Smrg 209c1f859d4Smrg 210c1f859d4Smrg/* 211c1f859d4Smrg * Unbind the current context from its buffer. 212c1f859d4Smrg */ 213c1f859d4Smrgextern GLboolean XMesaUnbindContext( XMesaContext c ); 214c1f859d4Smrg 215c1f859d4Smrg 216c1f859d4Smrg/* 217c1f859d4Smrg * Return a handle to the current context. 218c1f859d4Smrg */ 219c1f859d4Smrgextern XMesaContext XMesaGetCurrentContext( void ); 220c1f859d4Smrg 221c1f859d4Smrg 222c1f859d4Smrg/* 223c1f859d4Smrg * Return handle to the current (draw) buffer. 224c1f859d4Smrg */ 225c1f859d4Smrgextern XMesaBuffer XMesaGetCurrentBuffer( void ); 226c1f859d4Smrg 227c1f859d4Smrg 228c1f859d4Smrg/* 229c1f859d4Smrg * Return handle to the current read buffer. 230c1f859d4Smrg * New in Mesa 3.3 231c1f859d4Smrg */ 232c1f859d4Smrgextern XMesaBuffer XMesaGetCurrentReadBuffer( void ); 233c1f859d4Smrg 234c1f859d4Smrg 23501e04c3fSmrg/* 23601e04c3fSmrg * Return display of current context. 23701e04c3fSmrg */ 23801e04c3fSmrgextern Display *XMesaGetCurrentDisplay( void ); 23901e04c3fSmrg 24001e04c3fSmrg 241c1f859d4Smrg/* 242c1f859d4Smrg * Swap the front and back buffers for the given buffer. No action is 243c1f859d4Smrg * taken if the buffer is not double buffered. 244c1f859d4Smrg */ 245c1f859d4Smrgextern void XMesaSwapBuffers( XMesaBuffer b ); 246c1f859d4Smrg 247c1f859d4Smrg 248c1f859d4Smrg/* 249c1f859d4Smrg * Copy a sub-region of the back buffer to the front buffer. 250c1f859d4Smrg * 251c1f859d4Smrg * New in Mesa 2.6 252c1f859d4Smrg */ 253c1f859d4Smrgextern void XMesaCopySubBuffer( XMesaBuffer b, 254c1f859d4Smrg int x, 255c1f859d4Smrg int y, 256c1f859d4Smrg int width, 257c1f859d4Smrg int height ); 258c1f859d4Smrg 259c1f859d4Smrg 260c1f859d4Smrg/* 261cdc920a0Smrg * Return a pointer to the Pixmap or XImage being used as the back 262c1f859d4Smrg * color buffer of an XMesaBuffer. This function is a way to get "under 263c1f859d4Smrg * the hood" of X/Mesa so one can manipulate the back buffer directly. 264c1f859d4Smrg * Input: b - the XMesaBuffer 265c1f859d4Smrg * Output: pixmap - pointer to back buffer's Pixmap, or 0 266c1f859d4Smrg * ximage - pointer to back buffer's XImage, or NULL 267c1f859d4Smrg * Return: GL_TRUE = context is double buffered 268c1f859d4Smrg * GL_FALSE = context is single buffered 269c1f859d4Smrg */ 270c1f859d4Smrgextern GLboolean XMesaGetBackBuffer( XMesaBuffer b, 271c1f859d4Smrg XMesaPixmap *pixmap, 272c1f859d4Smrg XMesaImage **ximage ); 273c1f859d4Smrg 274c1f859d4Smrg 275c1f859d4Smrg 276c1f859d4Smrg/* 277c1f859d4Smrg * Return the depth buffer associated with an XMesaBuffer. 278c1f859d4Smrg * Input: b - the XMesa buffer handle 279c1f859d4Smrg * Output: width, height - size of buffer in pixels 280c1f859d4Smrg * bytesPerValue - bytes per depth value (2 or 4) 281c1f859d4Smrg * buffer - pointer to depth buffer values 282c1f859d4Smrg * Return: GL_TRUE or GL_FALSE to indicate success or failure. 283c1f859d4Smrg * 284c1f859d4Smrg * New in Mesa 2.4. 285c1f859d4Smrg */ 286c1f859d4Smrgextern GLboolean XMesaGetDepthBuffer( XMesaBuffer b, 287c1f859d4Smrg GLint *width, 288c1f859d4Smrg GLint *height, 289c1f859d4Smrg GLint *bytesPerValue, 290c1f859d4Smrg void **buffer ); 291c1f859d4Smrg 292c1f859d4Smrg 293c1f859d4Smrg 294c1f859d4Smrg/* 295c1f859d4Smrg * Flush/sync a context 296c1f859d4Smrg */ 297c1f859d4Smrgextern void XMesaFlush( XMesaContext c ); 298c1f859d4Smrg 299c1f859d4Smrg 300c1f859d4Smrg 301c1f859d4Smrg/* 302c1f859d4Smrg * Get an X/Mesa-specific string. 303c1f859d4Smrg * Input: name - either XMESA_VERSION or XMESA_EXTENSIONS 304c1f859d4Smrg */ 305c1f859d4Smrgextern const char *XMesaGetString( XMesaContext c, int name ); 306c1f859d4Smrg 307c1f859d4Smrg 308c1f859d4Smrg 309c1f859d4Smrg/* 310c1f859d4Smrg * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free 311c1f859d4Smrg * any memory used by that buffer. 312c1f859d4Smrg * 313c1f859d4Smrg * New in Mesa 2.3. 314c1f859d4Smrg */ 3153464ebd5Sriastradhextern void XMesaGarbageCollect( XMesaDisplay* dpy ); 316c1f859d4Smrg 317c1f859d4Smrg 318c1f859d4Smrg 319c1f859d4Smrg/* 320c1f859d4Smrg * Return a dithered pixel value. 321c1f859d4Smrg * Input: c - XMesaContext 322c1f859d4Smrg * x, y - window coordinate 323c1f859d4Smrg * red, green, blue, alpha - color components in [0,1] 324c1f859d4Smrg * Return: pixel value 325c1f859d4Smrg * 326c1f859d4Smrg * New in Mesa 2.3. 327c1f859d4Smrg */ 328c1f859d4Smrgextern unsigned long XMesaDitherColor( XMesaContext xmesa, 329c1f859d4Smrg GLint x, 330c1f859d4Smrg GLint y, 331c1f859d4Smrg GLfloat red, 332c1f859d4Smrg GLfloat green, 333c1f859d4Smrg GLfloat blue, 334c1f859d4Smrg GLfloat alpha ); 335c1f859d4Smrg 336c1f859d4Smrg 337c1f859d4Smrg 338c1f859d4Smrg/* 339c1f859d4Smrg * Reallocate the back/depth/stencil/accum/etc/ buffers associated with 340c1f859d4Smrg * buffer <b> if its size has changed. 341c1f859d4Smrg * 342c1f859d4Smrg * New in Mesa 4.0.2 343c1f859d4Smrg */ 344c1f859d4Smrgextern void XMesaResizeBuffers( XMesaBuffer b ); 345c1f859d4Smrg 346c1f859d4Smrg 347c1f859d4Smrg 348c1f859d4Smrg/* 349c1f859d4Smrg * Create a pbuffer. 350c1f859d4Smrg * New in Mesa 4.1 351c1f859d4Smrg */ 352c1f859d4Smrgextern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap, 353c1f859d4Smrg unsigned int width, unsigned int height); 354c1f859d4Smrg 355c1f859d4Smrg 356c1f859d4Smrg 357c1f859d4Smrg/* 358c1f859d4Smrg * Texture from Pixmap 359c1f859d4Smrg * New in Mesa 7.1 360c1f859d4Smrg */ 361c1f859d4Smrgextern void 362c1f859d4SmrgXMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, 363c1f859d4Smrg const int *attrib_list); 364c1f859d4Smrg 365c1f859d4Smrgextern void 366c1f859d4SmrgXMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer); 367c1f859d4Smrg 368c1f859d4Smrg 369c1f859d4Smrgextern XMesaBuffer 370c1f859d4SmrgXMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p, 371c1f859d4Smrg XMesaColormap cmap, 372c1f859d4Smrg int format, int target, int mipmap); 373c1f859d4Smrg 374c1f859d4Smrg 375c1f859d4Smrg 376c1f859d4Smrg#ifdef __cplusplus 377c1f859d4Smrg} 378c1f859d4Smrg#endif 379c1f859d4Smrg 380c1f859d4Smrg 381c1f859d4Smrg#endif 382