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.
60 #include "main/core.h" /* for gl_config */
61 #include "state_tracker/st_api.h"
62 #include "os/os_thread.h"
64 #include "state_tracker/xlibsw_api.h"
66 # include <X11/Xlib.h>
67 # include <X11/Xlibint.h>
68 # include <X11/Xutil.h>
72 typedef struct xmesa_display
*XMesaDisplay
;
73 typedef struct xmesa_buffer
*XMesaBuffer
;
74 typedef struct xmesa_context
*XMesaContext
;
75 typedef struct xmesa_visual
*XMesaVisual
;
78 struct xmesa_display
{
82 struct pipe_screen
*screen
;
83 struct st_manager
*smapi
;
85 struct pipe_context
*pipe
;
90 * Create a new X/Mesa visual.
91 * Input: display - X11 display
92 * visinfo - an XVisualInfo pointer
93 * rgb_flag - GL_TRUE = RGB mode,
94 * GL_FALSE = color index mode
95 * alpha_flag - alpha buffer requested?
96 * db_flag - GL_TRUE = double-buffered,
97 * GL_FALSE = single buffered
98 * stereo_flag - stereo visual?
99 * ximage_flag - GL_TRUE = use an XImage for back buffer,
100 * GL_FALSE = use an off-screen pixmap for back buffer
101 * depth_size - requested bits/depth values, or zero
102 * stencil_size - requested bits/stencil values, or zero
103 * accum_red_size - requested bits/red accum values, or zero
104 * accum_green_size - requested bits/green accum values, or zero
105 * accum_blue_size - requested bits/blue accum values, or zero
106 * accum_alpha_size - requested bits/alpha accum values, or zero
107 * num_samples - number of samples/pixel if multisampling, or zero
108 * level - visual level, usually 0
109 * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT
110 * Return; a new XMesaVisual or 0 if error.
112 extern XMesaVisual
XMesaCreateVisual( Display
*display
,
113 XVisualInfo
* visinfo
,
115 GLboolean alpha_flag
,
117 GLboolean stereo_flag
,
118 GLboolean ximage_flag
,
121 GLint accum_red_size
,
122 GLint accum_green_size
,
123 GLint accum_blue_size
,
124 GLint accum_alpha_size
,
127 GLint visualCaveat
);
130 * Destroy an XMesaVisual, but not the associated XVisualInfo.
132 extern void XMesaDestroyVisual( XMesaVisual v
);
137 * Create a new XMesaContext for rendering into an X11 window.
139 * Input: visual - an XMesaVisual
140 * share_list - another XMesaContext with which to share display
141 * lists or NULL if no sharing is wanted.
142 * Return: an XMesaContext or NULL if error.
144 extern XMesaContext
XMesaCreateContext( XMesaVisual v
,
145 XMesaContext share_list
,
146 GLuint major
, GLuint minor
,
148 GLuint contextFlags
);
152 * Destroy a rendering context as returned by XMesaCreateContext()
154 extern void XMesaDestroyContext( XMesaContext c
);
159 * Create an XMesaBuffer from an X window.
161 extern XMesaBuffer
XMesaCreateWindowBuffer( XMesaVisual v
, Window w
);
165 * Create an XMesaBuffer from an X pixmap.
167 extern XMesaBuffer
XMesaCreatePixmapBuffer( XMesaVisual v
,
173 * Destroy an XMesaBuffer, but not the corresponding window or pixmap.
175 extern void XMesaDestroyBuffer( XMesaBuffer b
);
179 * Return the XMesaBuffer handle which corresponds to an X drawable, if any.
183 extern XMesaBuffer
XMesaFindBuffer( Display
*dpy
,
189 * Bind two buffers (read and draw) to a context and make the
190 * context the current one.
193 extern GLboolean
XMesaMakeCurrent2( XMesaContext c
,
194 XMesaBuffer drawBuffer
,
195 XMesaBuffer readBuffer
);
199 * Unbind the current context from its buffer.
201 extern GLboolean
XMesaUnbindContext( XMesaContext c
);
205 * Return a handle to the current context.
207 extern XMesaContext
XMesaGetCurrentContext( void );
211 * Swap the front and back buffers for the given buffer. No action is
212 * taken if the buffer is not double buffered.
214 extern void XMesaSwapBuffers( XMesaBuffer b
);
218 * Copy a sub-region of the back buffer to the front buffer.
222 extern void XMesaCopySubBuffer( XMesaBuffer b
,
233 * Flush/sync a context
235 extern void XMesaFlush( XMesaContext c
);
240 * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free
241 * any memory used by that buffer.
245 extern void XMesaGarbageCollect( void );
253 extern XMesaBuffer
XMesaCreatePBuffer(XMesaVisual v
, Colormap cmap
,
254 unsigned int width
, unsigned int height
);
259 * Texture from Pixmap
263 XMesaBindTexImage(Display
*dpy
, XMesaBuffer drawable
, int buffer
,
264 const int *attrib_list
);
267 XMesaReleaseTexImage(Display
*dpy
, XMesaBuffer drawable
, int buffer
);
271 XMesaCreatePixmapTextureBuffer(XMesaVisual v
, Pixmap p
,
273 int format
, int target
, int mipmap
);
277 XMesaCopyContext(XMesaContext src
, XMesaContext dst
, unsigned long mask
);
280 /***********************************************************************
284 * Visual inforation, derived from GLvisual.
285 * Basically corresponds to an XVisualInfo.
287 struct xmesa_visual
{
288 struct gl_config mesa_visual
;/* Device independent visual parameters */
289 int screen
, visualID
, visualType
;
290 Display
*display
; /* The X11 display */
291 XVisualInfo
* visinfo
; /* X's visual info (pointer to private copy) */
292 XVisualInfo
*vishandle
; /* Only used in fakeglx.c */
293 GLint BitsPerPixel
; /* True bits per pixel for XImages */
295 GLboolean ximage_flag
; /* Use XImage for back buffer (not pixmap)? */
297 struct st_visual stvis
;
302 * Context info, derived from st_context.
303 * Basically corresponds to a GLXContext.
305 struct xmesa_context
{
306 struct st_context_iface
*st
;
307 XMesaVisual xm_visual
; /** pixel format info */
308 XMesaBuffer xm_buffer
; /** current drawbuffer */
309 XMesaBuffer xm_read_buffer
; /** current readbuffer */
310 struct hud_context
*hud
;
315 * Types of X/GLX drawables we might render into.
318 WINDOW
, /* An X window */
319 GLXWINDOW
, /* GLX window */
320 PIXMAP
, /* GLX pixmap */
321 PBUFFER
/* GLX Pbuffer */
326 * Framebuffer information, derived from.
327 * Basically corresponds to a GLXDrawable.
329 struct xmesa_buffer
{
330 struct st_framebuffer_iface
*stfb
;
331 struct xlib_drawable ws
;
333 GLboolean wasCurrent
; /* was ever the current buffer? */
334 XMesaVisual xm_visual
; /* the X/Mesa visual */
335 Colormap cmap
; /* the X colormap */
336 BufferType type
; /* window, pixmap, pbuffer or glxwindow */
338 GLboolean largestPbuffer
; /**< for pbuffers */
339 GLboolean preservedContents
; /**< for pbuffers */
342 unsigned long selectedEvents
;/* for pbuffers only */
345 GC gc
; /* scratch GC for span, line, tri drawing */
347 /* GLX_EXT_texture_from_pixmap */
348 GLint TextureTarget
; /** GLX_TEXTURE_1D_EXT, for example */
349 GLint TextureFormat
; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
350 GLint TextureMipmap
; /** 0 or 1 */
352 struct xmesa_buffer
*Next
; /* Linked list pointer: */
354 unsigned width
, height
;
360 xmesa_get_name(void);
363 xmesa_init(Display
*dpy
);
366 xmesa_find_buffer(Display
*dpy
, Colormap cmap
, XMesaBuffer notThis
);
369 xmesa_get_window_size(Display
*dpy
, XMesaBuffer b
,
370 GLuint
*width
, GLuint
*height
);
373 xmesa_notify_invalid_buffer(XMesaBuffer b
);
376 xmesa_check_buffer_size(XMesaBuffer b
);
379 xmesa_destroy_buffers_on_display(Display
*dpy
);
382 xmesa_close_display(Display
*dpy
);
385 xmesa_buffer_width(XMesaBuffer b
)
391 xmesa_buffer_height(XMesaBuffer b
)
396 extern boolean xmesa_strict_invalidate
;