xm_api.h revision 576d9af505bd19ccaac04a68c8744f36f887bd5c
1/* 2 * Mesa 3-D graphics library 3 * Version: 7.1 4 * 5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 26 27/* Sample Usage: 28 29In addition to the usual X calls to select a visual, create a colormap 30and create a window, you must do the following to use the X/Mesa interface: 31 321. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo. 33 342. Call XMesaCreateContext() to create an X/Mesa rendering context, given 35 the XMesaVisual. 36 373. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window 38 and XMesaVisual. 39 404. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and 41 to make the context the current one. 42 435. Make gl* calls to render your graphics. 44 456. Use XMesaSwapBuffers() when double buffering to swap front/back buffers. 46 477. Before the X window is destroyed, call XMesaDestroyBuffer(). 48 498. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext. 50 51*/ 52 53 54 55 56#ifndef XMESA_H 57#define XMESA_H 58 59 60#include "main/mtypes.h" 61#include "state_tracker/st_api.h" 62#include "os/os_thread.h" 63 64#include "state_tracker/xlib_sw_winsys.h" 65 66# include <X11/Xlib.h> 67# include <X11/Xlibint.h> 68# include <X11/Xutil.h> 69 70typedef struct xmesa_buffer *XMesaBuffer; 71typedef struct xmesa_context *XMesaContext; 72typedef struct xmesa_visual *XMesaVisual; 73 74 75 76/* 77 * Create a new X/Mesa visual. 78 * Input: display - X11 display 79 * visinfo - an XVisualInfo pointer 80 * rgb_flag - GL_TRUE = RGB mode, 81 * GL_FALSE = color index mode 82 * alpha_flag - alpha buffer requested? 83 * db_flag - GL_TRUE = double-buffered, 84 * GL_FALSE = single buffered 85 * stereo_flag - stereo visual? 86 * ximage_flag - GL_TRUE = use an XImage for back buffer, 87 * GL_FALSE = use an off-screen pixmap for back buffer 88 * depth_size - requested bits/depth values, or zero 89 * stencil_size - requested bits/stencil values, or zero 90 * accum_red_size - requested bits/red accum values, or zero 91 * accum_green_size - requested bits/green accum values, or zero 92 * accum_blue_size - requested bits/blue accum values, or zero 93 * accum_alpha_size - requested bits/alpha accum values, or zero 94 * num_samples - number of samples/pixel if multisampling, or zero 95 * level - visual level, usually 0 96 * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT 97 * Return; a new XMesaVisual or 0 if error. 98 */ 99extern XMesaVisual XMesaCreateVisual( Display *display, 100 XVisualInfo * visinfo, 101 GLboolean rgb_flag, 102 GLboolean alpha_flag, 103 GLboolean db_flag, 104 GLboolean stereo_flag, 105 GLboolean ximage_flag, 106 GLint depth_size, 107 GLint stencil_size, 108 GLint accum_red_size, 109 GLint accum_green_size, 110 GLint accum_blue_size, 111 GLint accum_alpha_size, 112 GLint num_samples, 113 GLint level, 114 GLint visualCaveat ); 115 116/* 117 * Destroy an XMesaVisual, but not the associated XVisualInfo. 118 */ 119extern void XMesaDestroyVisual( XMesaVisual v ); 120 121 122 123/* 124 * Create a new XMesaContext for rendering into an X11 window. 125 * 126 * Input: visual - an XMesaVisual 127 * share_list - another XMesaContext with which to share display 128 * lists or NULL if no sharing is wanted. 129 * Return: an XMesaContext or NULL if error. 130 */ 131extern XMesaContext XMesaCreateContext( XMesaVisual v, 132 XMesaContext share_list ); 133 134 135/* 136 * Destroy a rendering context as returned by XMesaCreateContext() 137 */ 138extern void XMesaDestroyContext( XMesaContext c ); 139 140 141 142/* 143 * Create an XMesaBuffer from an X window. 144 */ 145extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, Window w ); 146 147 148/* 149 * Create an XMesaBuffer from an X pixmap. 150 */ 151extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v, 152 Pixmap p, 153 Colormap cmap ); 154 155 156/* 157 * Destroy an XMesaBuffer, but not the corresponding window or pixmap. 158 */ 159extern void XMesaDestroyBuffer( XMesaBuffer b ); 160 161 162/* 163 * Return the XMesaBuffer handle which corresponds to an X drawable, if any. 164 * 165 * New in Mesa 2.3. 166 */ 167extern XMesaBuffer XMesaFindBuffer( Display *dpy, 168 Drawable d ); 169 170 171 172/* 173 * Bind two buffers (read and draw) to a context and make the 174 * context the current one. 175 * New in Mesa 3.3 176 */ 177extern GLboolean XMesaMakeCurrent2( XMesaContext c, 178 XMesaBuffer drawBuffer, 179 XMesaBuffer readBuffer ); 180 181 182/* 183 * Unbind the current context from its buffer. 184 */ 185extern GLboolean XMesaUnbindContext( XMesaContext c ); 186 187 188/* 189 * Return a handle to the current context. 190 */ 191extern XMesaContext XMesaGetCurrentContext( void ); 192 193 194/* 195 * Swap the front and back buffers for the given buffer. No action is 196 * taken if the buffer is not double buffered. 197 */ 198extern void XMesaSwapBuffers( XMesaBuffer b ); 199 200 201/* 202 * Copy a sub-region of the back buffer to the front buffer. 203 * 204 * New in Mesa 2.6 205 */ 206extern void XMesaCopySubBuffer( XMesaBuffer b, 207 int x, 208 int y, 209 int width, 210 int height ); 211 212 213 214 215 216/* 217 * Flush/sync a context 218 */ 219extern void XMesaFlush( XMesaContext c ); 220 221 222 223/* 224 * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free 225 * any memory used by that buffer. 226 * 227 * New in Mesa 2.3. 228 */ 229extern void XMesaGarbageCollect( void ); 230 231 232 233/* 234 * Create a pbuffer. 235 * New in Mesa 4.1 236 */ 237extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, Colormap cmap, 238 unsigned int width, unsigned int height); 239 240 241 242/* 243 * Texture from Pixmap 244 * New in Mesa 7.1 245 */ 246extern void 247XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, 248 const int *attrib_list); 249 250extern void 251XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer); 252 253 254extern XMesaBuffer 255XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, 256 Colormap cmap, 257 int format, int target, int mipmap); 258 259 260extern void 261XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask); 262 263 264/*********************************************************************** 265 */ 266 267extern pipe_mutex _xmesa_lock; 268 269extern struct xmesa_buffer *XMesaBufferList; 270 271 272/** 273 * Visual inforation, derived from GLvisual. 274 * Basically corresponds to an XVisualInfo. 275 */ 276struct xmesa_visual { 277 GLvisual mesa_visual; /* Device independent visual parameters */ 278 Display *display; /* The X11 display */ 279 XVisualInfo * visinfo; /* X's visual info (pointer to private copy) */ 280 XVisualInfo *vishandle; /* Only used in fakeglx.c */ 281 GLint BitsPerPixel; /* True bits per pixel for XImages */ 282 283 GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */ 284 285 struct st_visual stvis; 286}; 287 288 289/** 290 * Context info, derived from st_context. 291 * Basically corresponds to a GLXContext. 292 */ 293struct xmesa_context { 294 struct st_context_iface *st; 295 XMesaVisual xm_visual; /** pixel format info */ 296 XMesaBuffer xm_buffer; /** current drawbuffer */ 297 XMesaBuffer xm_read_buffer; /** current readbuffer */ 298}; 299 300 301/** 302 * Types of X/GLX drawables we might render into. 303 */ 304typedef enum { 305 WINDOW, /* An X window */ 306 GLXWINDOW, /* GLX window */ 307 PIXMAP, /* GLX pixmap */ 308 PBUFFER /* GLX Pbuffer */ 309} BufferType; 310 311 312/** 313 * Framebuffer information, derived from. 314 * Basically corresponds to a GLXDrawable. 315 */ 316struct xmesa_buffer { 317 struct st_framebuffer_iface *stfb; 318 struct xlib_drawable ws; 319 320 GLboolean wasCurrent; /* was ever the current buffer? */ 321 XMesaVisual xm_visual; /* the X/Mesa visual */ 322 Drawable drawable; /* Usually the X window ID */ 323 Colormap cmap; /* the X colormap */ 324 BufferType type; /* window, pixmap, pbuffer or glxwindow */ 325 326 GLboolean largestPbuffer; /**< for pbuffers */ 327 GLboolean preservedContents; /**< for pbuffers */ 328 329 XImage *tempImage; 330 unsigned long selectedEvents;/* for pbuffers only */ 331 332 333 GC gc; /* scratch GC for span, line, tri drawing */ 334 335 /* GLX_EXT_texture_from_pixmap */ 336 GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */ 337 GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */ 338 GLint TextureMipmap; /** 0 or 1 */ 339 340 struct xmesa_buffer *Next; /* Linked list pointer: */ 341 342 unsigned width, height; 343}; 344 345 346 347extern void 348xmesa_init(Display *dpy); 349 350extern XMesaBuffer 351xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis); 352 353extern void 354xmesa_get_window_size(Display *dpy, XMesaBuffer b, 355 GLuint *width, GLuint *height); 356 357extern void 358xmesa_check_buffer_size(XMesaBuffer b); 359 360extern void 361xmesa_destroy_buffers_on_display(Display *dpy); 362 363static INLINE GLuint 364xmesa_buffer_width(XMesaBuffer b) 365{ 366 return b->width; 367} 368 369static INLINE GLuint 370xmesa_buffer_height(XMesaBuffer b) 371{ 372 return b->height; 373} 374 375 376 377#endif 378