2
* Mesa 3-D graphics library
4
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the "Software"),
8
* to deal in the Software without restriction, including without limitation
9
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included
14
* in all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
* OTHER DEALINGS IN THE SOFTWARE.
29
In addition to the usual X calls to select a visual, create a colormap
30
and create a window, you must do the following to use the X/Mesa interface:
32
1. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo.
34
2. Call XMesaCreateContext() to create an X/Mesa rendering context, given
37
3. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window
40
4. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and
41
to make the context the current one.
43
5. Make gl* calls to render your graphics.
45
6. Use XMesaSwapBuffers() when double buffering to swap front/back buffers.
47
7. Before the X window is destroyed, call XMesaDestroyBuffer().
49
8. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext.
61
#include "main/glconfig.h" /* for gl_config */
62
#include "frontend/api.h"
63
#include "os/os_thread.h"
65
#include "frontend/xlibsw_api.h"
67
# include <X11/Xlib.h>
68
# include <X11/Xlibint.h>
69
# include <X11/Xutil.h>
73
typedef struct xmesa_display *XMesaDisplay;
74
typedef struct xmesa_buffer *XMesaBuffer;
75
typedef struct xmesa_context *XMesaContext;
76
typedef struct xmesa_visual *XMesaVisual;
79
struct xmesa_display {
83
struct pipe_screen *screen;
84
struct st_manager *smapi;
86
struct pipe_context *pipe;
91
* Create a new X/Mesa visual.
92
* Input: display - X11 display
93
* visinfo - an XVisualInfo pointer
94
* rgb_flag - GL_TRUE = RGB mode,
95
* GL_FALSE = color index mode
96
* alpha_flag - alpha buffer requested?
97
* db_flag - GL_TRUE = double-buffered,
98
* GL_FALSE = single buffered
99
* stereo_flag - stereo visual?
100
* ximage_flag - GL_TRUE = use an XImage for back buffer,
101
* GL_FALSE = use an off-screen pixmap for back buffer
102
* depth_size - requested bits/depth values, or zero
103
* stencil_size - requested bits/stencil values, or zero
104
* accum_red_size - requested bits/red accum values, or zero
105
* accum_green_size - requested bits/green accum values, or zero
106
* accum_blue_size - requested bits/blue accum values, or zero
107
* accum_alpha_size - requested bits/alpha accum values, or zero
108
* num_samples - number of samples/pixel if multisampling, or zero
109
* level - visual level, usually 0
110
* visualCaveat - ala the GLX extension, usually GLX_NONE_EXT
111
* Return; a new XMesaVisual or 0 if error.
113
extern XMesaVisual XMesaCreateVisual( Display *display,
114
XVisualInfo * visinfo,
116
GLboolean alpha_flag,
118
GLboolean stereo_flag,
119
GLboolean ximage_flag,
122
GLint accum_red_size,
123
GLint accum_green_size,
124
GLint accum_blue_size,
125
GLint accum_alpha_size,
128
GLint visualCaveat );
131
* Destroy an XMesaVisual, but not the associated XVisualInfo.
133
extern void XMesaDestroyVisual( XMesaVisual v );
138
* Create a new XMesaContext for rendering into an X11 window.
140
* Input: visual - an XMesaVisual
141
* share_list - another XMesaContext with which to share display
142
* lists or NULL if no sharing is wanted.
143
* Return: an XMesaContext or NULL if error.
145
extern XMesaContext XMesaCreateContext( XMesaVisual v,
146
XMesaContext share_list,
147
GLuint major, GLuint minor,
149
GLuint contextFlags);
153
* Destroy a rendering context as returned by XMesaCreateContext()
155
extern void XMesaDestroyContext( XMesaContext c );
160
* Create an XMesaBuffer from an X window.
162
extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, Window w );
166
* Create an XMesaBuffer from an X pixmap.
168
extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v,
174
* Destroy an XMesaBuffer, but not the corresponding window or pixmap.
176
extern void XMesaDestroyBuffer( XMesaBuffer b );
180
* Return the XMesaBuffer handle which corresponds to an X drawable, if any.
184
extern XMesaBuffer XMesaFindBuffer( Display *dpy,
190
* Bind two buffers (read and draw) to a context and make the
191
* context the current one.
194
extern GLboolean XMesaMakeCurrent2( XMesaContext c,
195
XMesaBuffer drawBuffer,
196
XMesaBuffer readBuffer );
200
* Unbind the current context from its buffer.
202
extern GLboolean XMesaUnbindContext( XMesaContext c );
206
* Return a handle to the current context.
208
extern XMesaContext XMesaGetCurrentContext( void );
212
* Swap the front and back buffers for the given buffer. No action is
213
* taken if the buffer is not double buffered.
215
extern void XMesaSwapBuffers( XMesaBuffer b );
219
* Copy a sub-region of the back buffer to the front buffer.
223
extern void XMesaCopySubBuffer( XMesaBuffer b,
234
* Flush/sync a context
236
extern void XMesaFlush( XMesaContext c );
241
* Scan for XMesaBuffers whose window/pixmap has been destroyed, then free
242
* any memory used by that buffer.
246
extern void XMesaGarbageCollect( void );
254
extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, Colormap cmap,
255
unsigned int width, unsigned int height);
260
* Texture from Pixmap
264
XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer,
265
const int *attrib_list);
268
XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer);
272
XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p,
274
int format, int target, int mipmap);
278
XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask);
281
/***********************************************************************
285
* Visual inforation, derived from GLvisual.
286
* Basically corresponds to an XVisualInfo.
288
struct xmesa_visual {
289
struct gl_config mesa_visual;/* Device independent visual parameters */
290
int screen, visualID, visualType;
291
Display *display; /* The X11 display */
292
XVisualInfo * visinfo; /* X's visual info (pointer to private copy) */
293
XVisualInfo *vishandle; /* Only used in fakeglx.c */
294
GLint BitsPerPixel; /* True bits per pixel for XImages */
296
GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
298
struct st_visual stvis;
303
* Context info, derived from st_context.
304
* Basically corresponds to a GLXContext.
306
struct xmesa_context {
307
struct st_context_iface *st;
308
XMesaVisual xm_visual; /** pixel format info */
309
XMesaBuffer xm_buffer; /** current drawbuffer */
310
XMesaBuffer xm_read_buffer; /** current readbuffer */
311
struct hud_context *hud;
316
* Types of X/GLX drawables we might render into.
319
WINDOW, /* An X window */
320
GLXWINDOW, /* GLX window */
321
PIXMAP, /* GLX pixmap */
322
PBUFFER /* GLX Pbuffer */
327
* Framebuffer information, derived from.
328
* Basically corresponds to a GLXDrawable.
330
struct xmesa_buffer {
331
struct st_framebuffer_iface *stfb;
332
struct xlib_drawable ws;
334
GLboolean wasCurrent; /* was ever the current buffer? */
335
XMesaVisual xm_visual; /* the X/Mesa visual */
336
Colormap cmap; /* the X colormap */
337
BufferType type; /* window, pixmap, pbuffer or glxwindow */
339
GLboolean largestPbuffer; /**< for pbuffers */
340
GLboolean preservedContents; /**< for pbuffers */
343
unsigned long selectedEvents;/* for pbuffers only */
346
GC gc; /* scratch GC for span, line, tri drawing */
348
/* GLX_EXT_texture_from_pixmap */
349
GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
350
GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
351
GLint TextureMipmap; /** 0 or 1 */
353
struct xmesa_buffer *Next; /* Linked list pointer: */
355
unsigned width, height;
361
xmesa_get_name(void);
364
xmesa_init(Display *dpy);
367
xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis);
370
xmesa_get_window_size(Display *dpy, XMesaBuffer b,
371
GLuint *width, GLuint *height);
374
xmesa_notify_invalid_buffer(XMesaBuffer b);
377
xmesa_check_buffer_size(XMesaBuffer b);
380
xmesa_destroy_buffers_on_display(Display *dpy);
383
xmesa_close_display(Display *dpy);
386
xmesa_buffer_width(XMesaBuffer b)
392
xmesa_buffer_height(XMesaBuffer b)
397
extern boolean xmesa_strict_invalidate;