| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file context.c |
| 3 | * Mesa context/visual/framebuffer management functions. |
| 4 | * \author Brian Paul |
| 5 | */ |
| 6 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 7 | /* |
| 8 | * Mesa 3-D graphics library |
| Brian Paul | 3a21203 | 2002-11-19 15:25:00 +0000 | [diff] [blame] | 9 | * Version: 5.1 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 10 | * |
| Brian Paul | bc42c19 | 2002-01-05 21:53:20 +0000 | [diff] [blame] | 11 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 12 | * |
| 13 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 14 | * copy of this software and associated documentation files (the "Software"), |
| 15 | * to deal in the Software without restriction, including without limitation |
| 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 17 | * and/or sell copies of the Software, and to permit persons to whom the |
| 18 | * Software is furnished to do so, subject to the following conditions: |
| 19 | * |
| 20 | * The above copyright notice and this permission notice shall be included |
| 21 | * in all copies or substantial portions of the Software. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 24 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 26 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 27 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 28 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 29 | */ |
| 30 | |
| 31 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 32 | /** |
| 33 | * \mainpage Mesa Core Module |
| 34 | * |
| 35 | * \section CoreIntroduction Introduction |
| 36 | * |
| 37 | * The Mesa core module consists of all the top-level files in the src |
| 38 | * directory. The core module basically takes care of API dispatch, |
| 39 | * and OpenGL state management. |
| 40 | * |
| 41 | * For example, calls to glPolygonMode() are routed to _mesa_PolygonMode() |
| 42 | * which updates the state related to polygonmode. Furthermore, dirty |
| 43 | * state flags related to polygon mode are set and if the device driver |
| 44 | * implements a special routine for PolygonMode, it will be called. |
| 45 | * |
| 46 | * |
| 47 | * \section AboutDoxygen About Doxygen |
| 48 | * |
| 49 | * If you're viewing this information as Doxygen-generated HTML you'll |
| 50 | * see the documentation index at the top of this page. |
| 51 | * |
| 52 | * The first line lists the Mesa source code modules. |
| 53 | * The second line lists the indexes available for viewing the documentation |
| 54 | * for each module. |
| 55 | * |
| 56 | * Selecting the <b>Main page</b> link will display a summary of the module |
| 57 | * (this page). |
| 58 | * |
| 59 | * Selecting <b>Compound List</b> will list all C structures. |
| 60 | * |
| 61 | * Selecting the <b>File List</b> link will list all the source files in |
| 62 | * the module. |
| 63 | * Selecting a filename will show a list of all functions defined in that file. |
| 64 | * |
| 65 | * Selecting the <b>Compound Members</b> link will display a list of all |
| 66 | * documented structure members. |
| 67 | * |
| 68 | * Selecting the <b>File Members</b> link will display a list |
| 69 | * of all functions, structures, global variables and macros in the module. |
| 70 | * |
| 71 | */ |
| 72 | |
| 73 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 74 | #include "glheader.h" |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 75 | #include "imports.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 76 | #include "accum.h" |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 77 | #include "arbprogram.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 78 | #include "attrib.h" |
| 79 | #include "blend.h" |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 80 | #include "buffers.h" |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 81 | #include "colortab.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 82 | #include "context.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 83 | #include "debug.h" |
| 84 | #include "depth.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 85 | #include "dlist.h" |
| 86 | #include "eval.h" |
| 87 | #include "enums.h" |
| Brian Paul | 585a68c | 1999-09-11 11:31:34 +0000 | [diff] [blame] | 88 | #include "extensions.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 89 | #include "feedback.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 90 | #include "fog.h" |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 91 | #include "get.h" |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 92 | #include "glthread.h" |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 93 | #include "glapioffsets.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 94 | #include "histogram.h" |
| 95 | #include "hint.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 96 | #include "hash.h" |
| 97 | #include "light.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 98 | #include "lines.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 99 | #include "macros.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 100 | #include "matrix.h" |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 101 | #include "occlude.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 102 | #include "pixel.h" |
| 103 | #include "points.h" |
| 104 | #include "polygon.h" |
| 105 | #include "rastpos.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 106 | #include "simple_list.h" |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 107 | #include "state.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 108 | #include "stencil.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 109 | #include "teximage.h" |
| 110 | #include "texobj.h" |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 111 | #include "texstate.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 112 | #include "mtypes.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 113 | #include "varray.h" |
| Brian Paul | 3a21203 | 2002-11-19 15:25:00 +0000 | [diff] [blame] | 114 | #if FEATURE_NV_vertex_program |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 115 | #include "nvprogram.h" |
| Brian Paul | 3a21203 | 2002-11-19 15:25:00 +0000 | [diff] [blame] | 116 | #endif |
| Gareth Hughes | d4eb665 | 2001-03-12 01:32:20 +0000 | [diff] [blame] | 117 | #include "vtxfmt.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 118 | #if _HAVE_FULL_GL |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 119 | #include "math/m_translate.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 120 | #include "math/m_matrix.h" |
| 121 | #include "math/m_xform.h" |
| Keith Whitwell | f4b02d1 | 2001-01-05 05:31:42 +0000 | [diff] [blame] | 122 | #include "math/mathmod.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 123 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 124 | |
| Brian Paul | 3b18a36 | 2000-09-26 15:27:20 +0000 | [diff] [blame] | 125 | #if defined(MESA_TRACE) |
| Brian Paul | 45f3634 | 2000-09-05 20:28:06 +0000 | [diff] [blame] | 126 | #include "Trace/tr_context.h" |
| 127 | #include "Trace/tr_wrapper.h" |
| 128 | #endif |
| 129 | |
| davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 130 | #ifdef USE_SPARC_ASM |
| 131 | #include "SPARC/sparc.h" |
| 132 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 133 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 134 | #ifndef MESA_VERBOSE |
| Keith Whitwell | 306d3fc | 2002-04-09 16:56:50 +0000 | [diff] [blame] | 135 | int MESA_VERBOSE = 0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 136 | #endif |
| 137 | |
| 138 | #ifndef MESA_DEBUG_FLAGS |
| Keith Whitwell | 306d3fc | 2002-04-09 16:56:50 +0000 | [diff] [blame] | 139 | int MESA_DEBUG_FLAGS = 0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 140 | #endif |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 141 | |
| Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 142 | |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 143 | /* ubyte -> float conversion */ |
| 144 | GLfloat _mesa_ubyte_to_float_color_tab[256]; |
| 145 | |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 146 | static void |
| 147 | free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ); |
| 148 | |
| Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 149 | |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 150 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 151 | /** \name OpenGL SI-style interface (new in Mesa 3.5) |
| 152 | * |
| 153 | * \if subset |
| 154 | * \note Most of these functions are never called in the Mesa subset. |
| 155 | * \endif |
| 156 | */ |
| 157 | /*@{*/ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 158 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 159 | /** |
| 160 | * Destroy context callback. |
| 161 | * |
| 162 | * \param gc context. |
| 163 | * \return GL_TRUE on success, or GL_FALSE on failure. |
| 164 | * |
| 165 | * \ifnot subset |
| 166 | * Called by window system/device driver (via __GLexports::destroyCurrent) when |
| 167 | * the rendering context is to be destroyed. |
| 168 | * \endif |
| 169 | * |
| 170 | * Frees the context data and the context structure. |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 171 | */ |
| 172 | GLboolean |
| 173 | _mesa_destroyContext(__GLcontext *gc) |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 174 | { |
| 175 | if (gc) { |
| 176 | _mesa_free_context_data(gc); |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 177 | _mesa_free(gc); |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 178 | } |
| 179 | return GL_TRUE; |
| 180 | } |
| 181 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 182 | /** |
| 183 | * Unbind context callback. |
| 184 | * |
| 185 | * \param gc context. |
| 186 | * \return GL_TRUE on success, or GL_FALSE on failure. |
| 187 | * |
| 188 | * \ifnot subset |
| 189 | * Called by window system/device driver (via __GLexports::loseCurrent) |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 190 | * when the rendering context is made non-current. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 191 | * \endif |
| 192 | * |
| 193 | * No-op |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 194 | */ |
| 195 | GLboolean |
| 196 | _mesa_loseCurrent(__GLcontext *gc) |
| 197 | { |
| 198 | /* XXX unbind context from thread */ |
| 199 | return GL_TRUE; |
| 200 | } |
| 201 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 202 | /** |
| 203 | * Bind context callback. |
| 204 | * |
| 205 | * \param gc context. |
| 206 | * \return GL_TRUE on success, or GL_FALSE on failure. |
| 207 | * |
| 208 | * \ifnot subset |
| 209 | * Called by window system/device driver (via __GLexports::makeCurrent) |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 210 | * when the rendering context is made current. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 211 | * \endif |
| 212 | * |
| 213 | * No-op |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 214 | */ |
| 215 | GLboolean |
| 216 | _mesa_makeCurrent(__GLcontext *gc) |
| 217 | { |
| 218 | /* XXX bind context to thread */ |
| 219 | return GL_TRUE; |
| 220 | } |
| 221 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 222 | /** |
| 223 | * Share context callback. |
| 224 | * |
| 225 | * \param gc context. |
| 226 | * \param gcShare shared context. |
| 227 | * \return GL_TRUE on success, or GL_FALSE on failure. |
| 228 | * |
| 229 | * \ifnot subset |
| 230 | * Called by window system/device driver (via __GLexports::shareContext) |
| 231 | * \endif |
| 232 | * |
| 233 | * Update the shared context reference count, gl_shared_state::RefCount. |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 234 | */ |
| 235 | GLboolean |
| 236 | _mesa_shareContext(__GLcontext *gc, __GLcontext *gcShare) |
| 237 | { |
| 238 | if (gc && gcShare && gc->Shared && gcShare->Shared) { |
| 239 | gc->Shared->RefCount--; |
| 240 | if (gc->Shared->RefCount == 0) { |
| 241 | free_shared_state(gc, gc->Shared); |
| 242 | } |
| 243 | gc->Shared = gcShare->Shared; |
| 244 | gc->Shared->RefCount++; |
| 245 | return GL_TRUE; |
| 246 | } |
| 247 | else { |
| 248 | return GL_FALSE; |
| 249 | } |
| 250 | } |
| 251 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 252 | |
| 253 | #if _HAVE_FULL_GL |
| 254 | /** |
| 255 | * Copy context callback. |
| 256 | */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 257 | GLboolean |
| 258 | _mesa_copyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask) |
| 259 | { |
| 260 | if (dst && src) { |
| 261 | _mesa_copy_context( src, dst, mask ); |
| 262 | return GL_TRUE; |
| 263 | } |
| 264 | else { |
| 265 | return GL_FALSE; |
| 266 | } |
| 267 | } |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 268 | #endif |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 269 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 270 | /** No-op */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 271 | GLboolean |
| 272 | _mesa_forceCurrent(__GLcontext *gc) |
| 273 | { |
| 274 | return GL_TRUE; |
| 275 | } |
| 276 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 277 | /** |
| 278 | * Windows/buffer resizing notification callback. |
| 279 | * |
| 280 | * \param gc GL context. |
| 281 | * \return GL_TRUE on success, or GL_FALSE on failure. |
| 282 | */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 283 | GLboolean |
| 284 | _mesa_notifyResize(__GLcontext *gc) |
| 285 | { |
| 286 | GLint x, y; |
| 287 | GLuint width, height; |
| 288 | __GLdrawablePrivate *d = gc->imports.getDrawablePrivate(gc); |
| 289 | if (!d || !d->getDrawableSize) |
| 290 | return GL_FALSE; |
| 291 | d->getDrawableSize( d, &x, &y, &width, &height ); |
| 292 | /* update viewport, resize software buffers, etc. */ |
| 293 | return GL_TRUE; |
| 294 | } |
| 295 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 296 | /** |
| 297 | * Window/buffer destruction notification callback. |
| 298 | * |
| 299 | * \param gc GL context. |
| 300 | * |
| 301 | * Called when the context's window/buffer is going to be destroyed. |
| 302 | * |
| 303 | * No-op |
| 304 | */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 305 | void |
| 306 | _mesa_notifyDestroy(__GLcontext *gc) |
| 307 | { |
| Brian Paul | 60b6e4f | 2002-10-14 17:08:17 +0000 | [diff] [blame] | 308 | /* Unbind from it. */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 311 | /** |
| 312 | * Swap buffers notification callback. |
| 313 | * |
| 314 | * \param gc GL context. |
| 315 | * |
| 316 | * Called by window system just before swapping buffers. |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 317 | * We have to finish any pending rendering. |
| 318 | */ |
| 319 | void |
| 320 | _mesa_notifySwapBuffers(__GLcontext *gc) |
| 321 | { |
| 322 | FLUSH_VERTICES( gc, 0 ); |
| 323 | } |
| 324 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 325 | /** No-op */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 326 | struct __GLdispatchStateRec * |
| 327 | _mesa_dispatchExec(__GLcontext *gc) |
| 328 | { |
| 329 | return NULL; |
| 330 | } |
| 331 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 332 | /** No-op */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 333 | void |
| 334 | _mesa_beginDispatchOverride(__GLcontext *gc) |
| 335 | { |
| 336 | } |
| 337 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 338 | /** No-op */ |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 339 | void |
| 340 | _mesa_endDispatchOverride(__GLcontext *gc) |
| 341 | { |
| 342 | } |
| 343 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 344 | /** |
| 345 | * \ifnot subset |
| 346 | * Setup the exports. |
| 347 | * |
| 348 | * The window system will call these functions when it needs Mesa to do |
| 349 | * something. |
| 350 | * |
| 351 | * \note Device drivers should override these functions! For example, |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 352 | * the Xlib driver should plug in the XMesa*-style functions into this |
| 353 | * structure. The XMesa-style functions should then call the _mesa_* |
| 354 | * version of these functions. This is an approximation to OO design |
| 355 | * (inheritance and virtual functions). |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 356 | * \endif |
| 357 | * |
| 358 | * \if subset |
| 359 | * No-op. |
| 360 | * |
| 361 | * \endif |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 362 | */ |
| 363 | static void |
| 364 | _mesa_init_default_exports(__GLexports *exports) |
| 365 | { |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 366 | #if _HAVE_FULL_GL |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 367 | exports->destroyContext = _mesa_destroyContext; |
| 368 | exports->loseCurrent = _mesa_loseCurrent; |
| 369 | exports->makeCurrent = _mesa_makeCurrent; |
| 370 | exports->shareContext = _mesa_shareContext; |
| 371 | exports->copyContext = _mesa_copyContext; |
| 372 | exports->forceCurrent = _mesa_forceCurrent; |
| 373 | exports->notifyResize = _mesa_notifyResize; |
| Brian Paul | 2f35d5e | 2002-06-13 04:31:09 +0000 | [diff] [blame] | 374 | exports->notifyDestroy = _mesa_notifyDestroy; |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 375 | exports->notifySwapBuffers = _mesa_notifySwapBuffers; |
| 376 | exports->dispatchExec = _mesa_dispatchExec; |
| 377 | exports->beginDispatchOverride = _mesa_beginDispatchOverride; |
| 378 | exports->endDispatchOverride = _mesa_endDispatchOverride; |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 379 | #endif |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 382 | /** |
| 383 | * Exported OpenGL SI interface. |
| 384 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 385 | __GLcontext * |
| 386 | __glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes) |
| 387 | { |
| 388 | GLcontext *ctx; |
| 389 | |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 390 | ctx = (GLcontext *) (*imports->calloc)(NULL, 1, sizeof(GLcontext)); |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 391 | if (ctx == NULL) { |
| 392 | return NULL; |
| 393 | } |
| Brian Paul | 60b6e4f | 2002-10-14 17:08:17 +0000 | [diff] [blame] | 394 | |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 395 | _mesa_initialize_context(ctx, modes, NULL, imports, GL_FALSE); |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 396 | ctx->imports = *imports; |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 397 | |
| 398 | return ctx; |
| 399 | } |
| 400 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 401 | /** |
| 402 | * Exported OpenGL SI interface. |
| 403 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 404 | void |
| 405 | __glCoreNopDispatch(void) |
| 406 | { |
| 407 | #if 0 |
| 408 | /* SI */ |
| 409 | __gl_dispatch = __glNopDispatchState; |
| 410 | #else |
| 411 | /* Mesa */ |
| 412 | _glapi_set_dispatch(NULL); |
| 413 | #endif |
| 414 | } |
| 415 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 416 | /*@}*/ |
| 417 | |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 418 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 419 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 420 | /** \name GL Visual allocation/destruction */ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 421 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 422 | /*@{*/ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 423 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 424 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 425 | * Allocate a new GLvisual object. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 426 | * |
| 427 | * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode. |
| 428 | * \param dbFlag double buffering |
| 429 | * \param stereoFlag stereo buffer |
| 430 | * \param depthBits requested bits per depth buffer value. Any value in [0, 32] |
| 431 | * is acceptable but the actual depth type will be GLushort or GLuint as |
| 432 | * needed. |
| 433 | * \param stencilBits requested minimum bits per stencil buffer value |
| 434 | * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer. |
| 435 | * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE |
| 436 | * \param redBits number of bits per color component in frame buffer for RGB(A) |
| 437 | * mode. We always use 8 in core Mesa though. |
| 438 | * \param greenBits same as above. |
| 439 | * \param blueBits same as above. |
| 440 | * \param alphaBits same as above. |
| 441 | * \param numSamples not really used. |
| 442 | * |
| 443 | * \return pointer to new GLvisual or NULL if requested parameters can't be |
| 444 | * met. |
| 445 | * |
| 446 | * Allocates a GLvisual structure and initializes it via |
| 447 | * _mesa_initialize_visual(). |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 448 | */ |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 449 | GLvisual * |
| 450 | _mesa_create_visual( GLboolean rgbFlag, |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 451 | GLboolean dbFlag, |
| 452 | GLboolean stereoFlag, |
| 453 | GLint redBits, |
| 454 | GLint greenBits, |
| 455 | GLint blueBits, |
| 456 | GLint alphaBits, |
| 457 | GLint indexBits, |
| 458 | GLint depthBits, |
| 459 | GLint stencilBits, |
| 460 | GLint accumRedBits, |
| 461 | GLint accumGreenBits, |
| 462 | GLint accumBlueBits, |
| 463 | GLint accumAlphaBits, |
| 464 | GLint numSamples ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 465 | { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 466 | GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) ); |
| 467 | if (vis) { |
| Brian Paul | e70c623 | 2000-05-04 13:53:55 +0000 | [diff] [blame] | 468 | if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 469 | redBits, greenBits, blueBits, alphaBits, |
| 470 | indexBits, depthBits, stencilBits, |
| 471 | accumRedBits, accumGreenBits, |
| 472 | accumBlueBits, accumAlphaBits, |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 473 | numSamples)) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 474 | FREE(vis); |
| 475 | return NULL; |
| 476 | } |
| 477 | } |
| 478 | return vis; |
| 479 | } |
| 480 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 481 | /** |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 482 | * Initialize the fields of the given GLvisual. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 483 | * |
| 484 | * \return GL_TRUE on success, or GL_FALSE on failure. |
| 485 | * |
| 486 | * \sa _mesa_create_visual() above for the parameter description. |
| 487 | * |
| 488 | * Makes some sanity checks and fills in the fields of the |
| 489 | * GLvisual structure with the given parameters. |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 490 | */ |
| 491 | GLboolean |
| 492 | _mesa_initialize_visual( GLvisual *vis, |
| 493 | GLboolean rgbFlag, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 494 | GLboolean dbFlag, |
| 495 | GLboolean stereoFlag, |
| 496 | GLint redBits, |
| 497 | GLint greenBits, |
| 498 | GLint blueBits, |
| 499 | GLint alphaBits, |
| 500 | GLint indexBits, |
| 501 | GLint depthBits, |
| 502 | GLint stencilBits, |
| 503 | GLint accumRedBits, |
| 504 | GLint accumGreenBits, |
| 505 | GLint accumBlueBits, |
| 506 | GLint accumAlphaBits, |
| 507 | GLint numSamples ) |
| 508 | { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 509 | (void) numSamples; |
| 510 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 511 | assert(vis); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 512 | |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 513 | /* This is to catch bad values from device drivers not updated for |
| 514 | * Mesa 3.3. Some device drivers just passed 1. That's a REALLY |
| 515 | * bad value now (a 1-bit depth buffer!?!). |
| 516 | */ |
| 517 | assert(depthBits == 0 || depthBits > 1); |
| 518 | |
| 519 | if (depthBits < 0 || depthBits > 32) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 520 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 521 | } |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 522 | if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 523 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 524 | } |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 525 | if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 526 | return GL_FALSE; |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 527 | } |
| 528 | if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 529 | return GL_FALSE; |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 530 | } |
| 531 | if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 532 | return GL_FALSE; |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 533 | } |
| 534 | if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 535 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 538 | vis->rgbMode = rgbFlag; |
| 539 | vis->doubleBufferMode = dbFlag; |
| 540 | vis->stereoMode = stereoFlag; |
| Brian Paul | 153f154 | 2002-10-29 15:04:35 +0000 | [diff] [blame] | 541 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 542 | vis->redBits = redBits; |
| 543 | vis->greenBits = greenBits; |
| 544 | vis->blueBits = blueBits; |
| 545 | vis->alphaBits = alphaBits; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 546 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 547 | vis->indexBits = indexBits; |
| 548 | vis->depthBits = depthBits; |
| 549 | vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 550 | vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 551 | vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 552 | vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 553 | vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0; |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 554 | |
| Brian Paul | 153f154 | 2002-10-29 15:04:35 +0000 | [diff] [blame] | 555 | vis->haveAccumBuffer = accumRedBits > 0; |
| 556 | vis->haveDepthBuffer = depthBits > 0; |
| 557 | vis->haveStencilBuffer = stencilBits > 0; |
| 558 | |
| 559 | vis->numAuxBuffers = 0; |
| 560 | vis->level = 0; |
| 561 | vis->pixmapMode = 0; |
| 562 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 563 | return GL_TRUE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 566 | /** |
| 567 | * Destroy a visual. |
| 568 | * |
| 569 | * \param vis visual. |
| 570 | * |
| 571 | * Frees the visual structure. |
| 572 | */ |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 573 | void |
| 574 | _mesa_destroy_visual( GLvisual *vis ) |
| 575 | { |
| 576 | FREE(vis); |
| 577 | } |
| 578 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 579 | /*@}*/ |
| 580 | |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 581 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 582 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 583 | /** \name GL Framebuffer allocation/destruction */ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 584 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 585 | /*@{*/ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 586 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 587 | /** |
| 588 | * Create a new framebuffer. |
| 589 | * |
| 590 | * A GLframebuffer is a structure which encapsulates the depth, stencil and |
| 591 | * accum buffers and related parameters. |
| 592 | * |
| 593 | * \param visual a GLvisual pointer (we copy the struct contents) |
| 594 | * \param softwareDepth create/use a software depth buffer? |
| 595 | * \param softwareStencil create/use a software stencil buffer? |
| 596 | * \param softwareAccum create/use a software accum buffer? |
| 597 | * \param softwareAlpha create/use a software alpha buffer? |
| 598 | * |
| 599 | * \return pointer to new GLframebuffer struct or NULL if error. |
| 600 | * |
| 601 | * Allocate a GLframebuffer structure and initializes it via |
| 602 | * _mesa_initialize_framebuffer(). |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 603 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 604 | GLframebuffer * |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 605 | _mesa_create_framebuffer( const GLvisual *visual, |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 606 | GLboolean softwareDepth, |
| 607 | GLboolean softwareStencil, |
| 608 | GLboolean softwareAccum, |
| 609 | GLboolean softwareAlpha ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 610 | { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 611 | GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer); |
| 612 | assert(visual); |
| 613 | if (buffer) { |
| 614 | _mesa_initialize_framebuffer(buffer, visual, |
| 615 | softwareDepth, softwareStencil, |
| 616 | softwareAccum, softwareAlpha ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 617 | } |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 618 | return buffer; |
| 619 | } |
| 620 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 621 | /** |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 622 | * Initialize a GLframebuffer object. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 623 | * |
| 624 | * \sa _mesa_create_framebuffer() above for the parameter description. |
| 625 | * |
| 626 | * Makes some sanity checks and fills in the fields of the |
| 627 | * GLframebuffer structure with the given parameters. |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 628 | */ |
| 629 | void |
| 630 | _mesa_initialize_framebuffer( GLframebuffer *buffer, |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 631 | const GLvisual *visual, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 632 | GLboolean softwareDepth, |
| 633 | GLboolean softwareStencil, |
| 634 | GLboolean softwareAccum, |
| 635 | GLboolean softwareAlpha ) |
| 636 | { |
| 637 | assert(buffer); |
| 638 | assert(visual); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 639 | |
| Brian Paul | 6ec6b84 | 2002-10-30 19:49:29 +0000 | [diff] [blame] | 640 | _mesa_bzero(buffer, sizeof(GLframebuffer)); |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 641 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 642 | /* sanity checks */ |
| 643 | if (softwareDepth ) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 644 | assert(visual->depthBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 645 | } |
| 646 | if (softwareStencil) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 647 | assert(visual->stencilBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 648 | } |
| 649 | if (softwareAccum) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 650 | assert(visual->rgbMode); |
| 651 | assert(visual->accumRedBits > 0); |
| 652 | assert(visual->accumGreenBits > 0); |
| 653 | assert(visual->accumBlueBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 654 | } |
| 655 | if (softwareAlpha) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 656 | assert(visual->rgbMode); |
| 657 | assert(visual->alphaBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 660 | buffer->Visual = *visual; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 661 | buffer->UseSoftwareDepthBuffer = softwareDepth; |
| 662 | buffer->UseSoftwareStencilBuffer = softwareStencil; |
| 663 | buffer->UseSoftwareAccumBuffer = softwareAccum; |
| 664 | buffer->UseSoftwareAlphaBuffers = softwareAlpha; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 667 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 668 | * Free a framebuffer struct and its buffers. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 669 | * |
| 670 | * Calls _mesa_free_framebuffer_data() and frees the structure. |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 671 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 672 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 673 | _mesa_destroy_framebuffer( GLframebuffer *buffer ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 674 | { |
| 675 | if (buffer) { |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 676 | _mesa_free_framebuffer_data(buffer); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 677 | FREE(buffer); |
| 678 | } |
| 679 | } |
| 680 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 681 | /** |
| 682 | * Free the data hanging off of \p buffer, but not \p buffer itself. |
| 683 | * |
| 684 | * \param buffer framebuffer. |
| 685 | * |
| 686 | * Frees all the buffers associated with the structure. |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 687 | */ |
| 688 | void |
| 689 | _mesa_free_framebuffer_data( GLframebuffer *buffer ) |
| 690 | { |
| 691 | if (!buffer) |
| 692 | return; |
| 693 | |
| Brian Paul | 8750668 | 2003-05-27 15:20:43 +0000 | [diff] [blame] | 694 | if (buffer->UseSoftwareDepthBuffer && buffer->DepthBuffer) { |
| Brian Paul | aeb4434 | 2002-03-19 16:47:04 +0000 | [diff] [blame] | 695 | MESA_PBUFFER_FREE( buffer->DepthBuffer ); |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 696 | buffer->DepthBuffer = NULL; |
| 697 | } |
| Brian Paul | 8750668 | 2003-05-27 15:20:43 +0000 | [diff] [blame] | 698 | if (buffer->UseSoftwareAccumBuffer && buffer->Accum) { |
| Brian Paul | aeb4434 | 2002-03-19 16:47:04 +0000 | [diff] [blame] | 699 | MESA_PBUFFER_FREE( buffer->Accum ); |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 700 | buffer->Accum = NULL; |
| 701 | } |
| Brian Paul | 8750668 | 2003-05-27 15:20:43 +0000 | [diff] [blame] | 702 | if (buffer->UseSoftwareStencilBuffer && buffer->Stencil) { |
| Brian Paul | aeb4434 | 2002-03-19 16:47:04 +0000 | [diff] [blame] | 703 | MESA_PBUFFER_FREE( buffer->Stencil ); |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 704 | buffer->Stencil = NULL; |
| 705 | } |
| Brian Paul | 8750668 | 2003-05-27 15:20:43 +0000 | [diff] [blame] | 706 | if (buffer->UseSoftwareAlphaBuffers){ |
| 707 | if (buffer->FrontLeftAlpha) { |
| 708 | MESA_PBUFFER_FREE( buffer->FrontLeftAlpha ); |
| 709 | buffer->FrontLeftAlpha = NULL; |
| 710 | } |
| 711 | if (buffer->BackLeftAlpha) { |
| 712 | MESA_PBUFFER_FREE( buffer->BackLeftAlpha ); |
| 713 | buffer->BackLeftAlpha = NULL; |
| 714 | } |
| 715 | if (buffer->FrontRightAlpha) { |
| 716 | MESA_PBUFFER_FREE( buffer->FrontRightAlpha ); |
| 717 | buffer->FrontRightAlpha = NULL; |
| 718 | } |
| 719 | if (buffer->BackRightAlpha) { |
| 720 | MESA_PBUFFER_FREE( buffer->BackRightAlpha ); |
| 721 | buffer->BackRightAlpha = NULL; |
| 722 | } |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 726 | /*@}*/ |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 727 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 728 | |
| 729 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 730 | /** \name Context allocation, initialization, destroying |
| 731 | * |
| 732 | * The purpose of the most initialization functions here is to provide the |
| 733 | * default state values according to the OpenGL specification. |
| 734 | */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 735 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 736 | /*@{*/ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 737 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 738 | /** |
| 739 | * One-time initialization mutex lock. |
| 740 | * |
| 741 | * \sa Used by one_time_init(). |
| 742 | */ |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 743 | _glthread_DECLARE_STATIC_MUTEX(OneTimeLock); |
| 744 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 745 | /** |
| 746 | * Calls all the various one-time-init functions in Mesa. |
| 747 | * |
| 748 | * While holding a global mutex lock, calls several initialization functions, |
| 749 | * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is |
| 750 | * defined. |
| 751 | * |
| 752 | * \sa _mesa_init_lists(), _math_init(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 753 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 754 | static void |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 755 | one_time_init( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 756 | { |
| 757 | static GLboolean alreadyCalled = GL_FALSE; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 758 | _glthread_LOCK_MUTEX(OneTimeLock); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 759 | if (!alreadyCalled) { |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 760 | GLuint i; |
| 761 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 762 | /* do some implementation tests */ |
| 763 | assert( sizeof(GLbyte) == 1 ); |
| 764 | assert( sizeof(GLshort) >= 2 ); |
| 765 | assert( sizeof(GLint) >= 4 ); |
| 766 | assert( sizeof(GLubyte) == 1 ); |
| 767 | assert( sizeof(GLushort) >= 2 ); |
| 768 | assert( sizeof(GLuint) >= 4 ); |
| 769 | |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 770 | _mesa_init_lists(); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 771 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 772 | #if _HAVE_FULL_GL |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 773 | _math_init(); |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 774 | |
| 775 | for (i = 0; i < 256; i++) { |
| 776 | _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F; |
| 777 | } |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 778 | #endif |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 779 | |
| davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 780 | #ifdef USE_SPARC_ASM |
| 781 | _mesa_init_sparc_glapi_relocs(); |
| 782 | #endif |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 783 | if (_mesa_getenv("MESA_DEBUG")) { |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 784 | _glapi_noop_enable_warnings(GL_TRUE); |
| Brian Paul | 71072be | 2002-10-10 00:22:13 +0000 | [diff] [blame] | 785 | #ifndef GLX_DIRECT_RENDERING |
| 786 | /* libGL from before 2002/06/28 don't have this function. Someday, |
| 787 | * when newer libGL libs are common, remove the #ifdef test. This |
| 788 | * only serves to print warnings when calling undefined GL functions. |
| 789 | */ |
| Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 790 | _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning ); |
| Brian Paul | 71072be | 2002-10-10 00:22:13 +0000 | [diff] [blame] | 791 | #endif |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 792 | } |
| 793 | else { |
| 794 | _glapi_noop_enable_warnings(GL_FALSE); |
| 795 | } |
| 796 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 797 | #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__) |
| Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 798 | _mesa_debug(ctx, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 799 | #endif |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 800 | |
| 801 | alreadyCalled = GL_TRUE; |
| 802 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 803 | _glthread_UNLOCK_MUTEX(OneTimeLock); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 806 | /** |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 807 | * Allocate and initialize a shared context state structure. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 808 | * |
| 809 | * \return pointer to a gl_shared_state structure on success, or NULL on |
| 810 | * failure. |
| 811 | * |
| 812 | * Initializes the display list, texture objects and vertex programs hash |
| 813 | * tables, allocates the texture objects. If it runs out of memory, frees |
| 814 | * everything already allocated before returning NULL. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 815 | */ |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 816 | static GLboolean |
| 817 | alloc_shared_state( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 818 | { |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 819 | struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 820 | if (!ss) |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 821 | return GL_FALSE; |
| 822 | |
| 823 | ctx->Shared = ss; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 824 | |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 825 | _glthread_INIT_MUTEX(ss->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 826 | |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 827 | ss->DisplayList = _mesa_NewHashTable(); |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 828 | ss->TexObjects = _mesa_NewHashTable(); |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 829 | #if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 830 | ss->Programs = _mesa_NewHashTable(); |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 831 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 832 | |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 833 | #if FEATURE_ARB_vertex_program |
| 834 | ss->DefaultVertexProgram = _mesa_alloc_program(ctx, GL_VERTEX_PROGRAM_ARB, 0); |
| 835 | if (!ss->DefaultVertexProgram) |
| 836 | goto cleanup; |
| 837 | #endif |
| 838 | #if FEATURE_ARB_fragment_program |
| 839 | ss->DefaultFragmentProgram = _mesa_alloc_program(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); |
| 840 | if (!ss->DefaultFragmentProgram) |
| 841 | goto cleanup; |
| 842 | #endif |
| 843 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 844 | ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D); |
| 845 | if (!ss->Default1D) |
| 846 | goto cleanup; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 847 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 848 | ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D); |
| 849 | if (!ss->Default2D) |
| 850 | goto cleanup; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 851 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 852 | ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D); |
| 853 | if (!ss->Default3D) |
| 854 | goto cleanup; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 855 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 856 | ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB); |
| 857 | if (!ss->DefaultCubeMap) |
| 858 | goto cleanup; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 859 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 860 | ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV); |
| 861 | if (!ss->DefaultRect) |
| 862 | goto cleanup; |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 863 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 864 | #if 0 |
| 865 | _mesa_save_texture_object(ctx, ss->Default1D); |
| 866 | _mesa_save_texture_object(ctx, ss->Default2D); |
| 867 | _mesa_save_texture_object(ctx, ss->Default3D); |
| 868 | _mesa_save_texture_object(ctx, ss->DefaultCubeMap); |
| 869 | _mesa_save_texture_object(ctx, ss->DefaultRect); |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 870 | #endif |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 871 | |
| 872 | /* Effectively bind the default textures to all texture units */ |
| 873 | ss->Default1D->RefCount += MAX_TEXTURE_IMAGE_UNITS; |
| 874 | ss->Default2D->RefCount += MAX_TEXTURE_IMAGE_UNITS; |
| 875 | ss->Default3D->RefCount += MAX_TEXTURE_IMAGE_UNITS; |
| 876 | ss->DefaultCubeMap->RefCount += MAX_TEXTURE_IMAGE_UNITS; |
| 877 | ss->DefaultRect->RefCount += MAX_TEXTURE_IMAGE_UNITS; |
| 878 | |
| 879 | return GL_TRUE; |
| 880 | |
| 881 | cleanup: |
| 882 | /* Ran out of memory at some point. Free everything and return NULL */ |
| 883 | if (ss->DisplayList) |
| 884 | _mesa_DeleteHashTable(ss->DisplayList); |
| 885 | if (ss->TexObjects) |
| 886 | _mesa_DeleteHashTable(ss->TexObjects); |
| 887 | #if FEATURE_NV_vertex_program |
| 888 | if (ss->Programs) |
| 889 | _mesa_DeleteHashTable(ss->Programs); |
| 890 | #endif |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 891 | #if FEATURE_ARB_vertex_program |
| 892 | if (ss->DefaultVertexProgram) |
| 893 | _mesa_delete_program(ctx, ss->DefaultVertexProgram); |
| 894 | #endif |
| 895 | #if FEATURE_ARB_fragment_program |
| 896 | if (ss->DefaultFragmentProgram) |
| 897 | _mesa_delete_program(ctx, ss->DefaultFragmentProgram); |
| 898 | #endif |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 899 | if (ss->Default1D) |
| 900 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D); |
| 901 | if (ss->Default2D) |
| 902 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D); |
| 903 | if (ss->Default3D) |
| 904 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D); |
| 905 | if (ss->DefaultCubeMap) |
| 906 | (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap); |
| 907 | if (ss->DefaultRect) |
| 908 | (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect); |
| 909 | if (ss) |
| 910 | _mesa_free(ss); |
| 911 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 914 | /** |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 915 | * Deallocate a shared state context and all children structures. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 916 | * |
| 917 | * \param ctx GL context. |
| 918 | * \param ss shared state pointer. |
| 919 | * |
| 920 | * Frees the display lists, the texture objects (calling the driver texture |
| 921 | * deletion callback to free its private data) and the vertex programs, as well |
| 922 | * as their hash tables. |
| 923 | * |
| 924 | * \sa alloc_shared_state(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 925 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 926 | static void |
| 927 | free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 928 | { |
| 929 | /* Free display lists */ |
| 930 | while (1) { |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 931 | GLuint list = _mesa_HashFirstEntry(ss->DisplayList); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 932 | if (list) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 933 | _mesa_destroy_list(ctx, list); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 934 | } |
| 935 | else { |
| 936 | break; |
| 937 | } |
| 938 | } |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 939 | _mesa_DeleteHashTable(ss->DisplayList); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 940 | |
| 941 | /* Free texture objects */ |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 942 | ASSERT(ctx->Driver.DeleteTexture); |
| 943 | while (1) { |
| 944 | GLuint texName = _mesa_HashFirstEntry(ss->TexObjects); |
| 945 | if (texName) { |
| 946 | struct gl_texture_object *texObj = (struct gl_texture_object *) |
| 947 | _mesa_HashLookup(ss->TexObjects, texName); |
| 948 | ASSERT(texObj); |
| 949 | (*ctx->Driver.DeleteTexture)(ctx, texObj); |
| 950 | _mesa_HashRemove(ss->TexObjects, texName); |
| 951 | } |
| 952 | else { |
| 953 | break; |
| 954 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 955 | } |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 956 | _mesa_DeleteHashTable(ss->TexObjects); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 957 | |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 958 | #if FEATURE_NV_vertex_program |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 959 | /* Free vertex programs */ |
| 960 | while (1) { |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 961 | GLuint prog = _mesa_HashFirstEntry(ss->Programs); |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 962 | if (prog) { |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 963 | struct program *p = (struct program *) _mesa_HashLookup(ss->Programs, |
| 964 | prog); |
| 965 | ASSERT(p); |
| 966 | _mesa_delete_program(ctx, p); |
| 967 | _mesa_HashRemove(ss->Programs, prog); |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 968 | } |
| 969 | else { |
| 970 | break; |
| 971 | } |
| 972 | } |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 973 | _mesa_DeleteHashTable(ss->Programs); |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 974 | #endif |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 975 | |
| Keith Whitwell | e15fd85 | 2002-12-12 13:03:15 +0000 | [diff] [blame] | 976 | _glthread_DESTROY_MUTEX(ss->Mutex); |
| 977 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 978 | FREE(ss); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 982 | static void _mesa_init_current( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 983 | { |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 984 | int i; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 985 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 986 | /* Current group */ |
| 987 | for (i = 0; i < VERT_ATTRIB_MAX; i++) { |
| 988 | ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 989 | } |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 990 | /* special cases: */ |
| 991 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 1.0 ); |
| 992 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 ); |
| 993 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 ); |
| 994 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 0.0 ); |
| 995 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 ); |
| 996 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) |
| 997 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_TEX0 + i], 0.0, 0.0, 0.0, 1.0); |
| 998 | ctx->Current.Index = 1; |
| 999 | ctx->Current.EdgeFlag = GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1003 | static void |
| 1004 | _mesa_init_constants( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1005 | { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1006 | assert(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1007 | |
| Brian Paul | cd1cefa | 2001-06-13 14:56:14 +0000 | [diff] [blame] | 1008 | assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS); |
| 1009 | assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS); |
| 1010 | |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 1011 | /* Constants, may be overriden by device drivers */ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1012 | ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS; |
| Brian Paul | cd1cefa | 2001-06-13 14:56:14 +0000 | [diff] [blame] | 1013 | ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS; |
| 1014 | ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS; |
| Brian Paul | 8afe7de | 2002-06-15 03:03:06 +0000 | [diff] [blame] | 1015 | ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1016 | ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS; |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 1017 | ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS; |
| 1018 | ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 1019 | ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY; |
| Brian Paul | 87c964d | 2001-11-06 15:53:00 +0000 | [diff] [blame] | 1020 | ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1021 | ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 1022 | ctx->Const.SubPixelBits = SUB_PIXEL_BITS; |
| 1023 | ctx->Const.MinPointSize = MIN_POINT_SIZE; |
| 1024 | ctx->Const.MaxPointSize = MAX_POINT_SIZE; |
| 1025 | ctx->Const.MinPointSizeAA = MIN_POINT_SIZE; |
| 1026 | ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE; |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 1027 | ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 1028 | ctx->Const.MinLineWidth = MIN_LINE_WIDTH; |
| 1029 | ctx->Const.MaxLineWidth = MAX_LINE_WIDTH; |
| 1030 | ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH; |
| 1031 | ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH; |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 1032 | ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 1033 | ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1034 | ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE; |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 1035 | ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH; |
| 1036 | ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT; |
| Brian Paul | a864432 | 2000-11-27 18:22:13 +0000 | [diff] [blame] | 1037 | ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES; |
| 1038 | ctx->Const.MaxLights = MAX_LIGHTS; |
| Ian Romanick | 882caa1 | 2003-05-30 21:37:14 +0000 | [diff] [blame] | 1039 | ctx->Const.MaxSpotExponent = 128.0; |
| 1040 | ctx->Const.MaxShininess = 128.0; |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 1041 | #if FEATURE_ARB_vertex_program |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 1042 | ctx->Const.MaxVertexProgramInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS; |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 1043 | ctx->Const.MaxVertexProgramAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS; |
| 1044 | ctx->Const.MaxVertexProgramTemps = MAX_NV_VERTEX_PROGRAM_TEMPS; |
| 1045 | ctx->Const.MaxVertexProgramLocalParams = MAX_NV_VERTEX_PROGRAM_PARAMS; |
| 1046 | ctx->Const.MaxVertexProgramEnvParams = MAX_NV_VERTEX_PROGRAM_PARAMS;/*XXX*/ |
| 1047 | ctx->Const.MaxVertexProgramAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS; |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 1048 | #endif |
| 1049 | #if FEATURE_ARB_fragment_program |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 1050 | ctx->Const.MaxFragmentProgramInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS; |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 1051 | ctx->Const.MaxFragmentProgramAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS; |
| 1052 | ctx->Const.MaxFragmentProgramTemps = MAX_NV_FRAGMENT_PROGRAM_TEMPS; |
| 1053 | ctx->Const.MaxFragmentProgramLocalParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS; |
| 1054 | ctx->Const.MaxFragmentProgramEnvParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;/*XXX*/ |
| 1055 | ctx->Const.MaxFragmentProgramAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS; |
| 1056 | ctx->Const.MaxFragmentProgramAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS; |
| 1057 | ctx->Const.MaxFragmentProgramTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS; |
| 1058 | ctx->Const.MaxFragmentProgramTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS; |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 1059 | #endif |
| Brian Paul | edd6774 | 2003-04-18 18:02:43 +0000 | [diff] [blame] | 1060 | ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES; |
| 1061 | ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH; |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 1062 | |
| Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 1063 | ASSERT(ctx->Const.MaxTextureUnits == MAX2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits)); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1064 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1065 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1066 | /** |
| 1067 | * Initialize the attribute groups in a GL context. |
| 1068 | * |
| 1069 | * \param ctx GL context. |
| 1070 | * |
| 1071 | * Initializes all the attributes, calling the respective <tt>init*</tt> |
| 1072 | * functions for the more complex data structures. |
| 1073 | */ |
| 1074 | static GLboolean |
| 1075 | init_attrib_groups( GLcontext *ctx ) |
| 1076 | { |
| 1077 | assert(ctx); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1078 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1079 | /* Constants */ |
| 1080 | _mesa_init_constants( ctx ); |
| Brian Paul | 0771d15 | 2000-04-07 00:19:41 +0000 | [diff] [blame] | 1081 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1082 | /* Extensions */ |
| Brian Paul | de4f460 | 2003-07-03 02:15:06 +0000 | [diff] [blame] | 1083 | _mesa_init_extensions( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1084 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1085 | /* Attribute Groups */ |
| 1086 | _mesa_init_accum( ctx ); |
| 1087 | _mesa_init_attrib( ctx ); |
| 1088 | _mesa_init_buffers( ctx ); |
| 1089 | _mesa_init_color( ctx ); |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 1090 | _mesa_init_colortables( ctx ); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1091 | _mesa_init_current( ctx ); |
| 1092 | _mesa_init_depth( ctx ); |
| 1093 | _mesa_init_debug( ctx ); |
| 1094 | _mesa_init_display_list( ctx ); |
| 1095 | _mesa_init_eval( ctx ); |
| 1096 | _mesa_init_feedback( ctx ); |
| 1097 | _mesa_init_fog( ctx ); |
| 1098 | _mesa_init_histogram( ctx ); |
| 1099 | _mesa_init_hint( ctx ); |
| 1100 | _mesa_init_line( ctx ); |
| 1101 | _mesa_init_lighting( ctx ); |
| 1102 | _mesa_init_matrix( ctx ); |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 1103 | _mesa_init_occlude( ctx ); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1104 | _mesa_init_pixel( ctx ); |
| 1105 | _mesa_init_point( ctx ); |
| 1106 | _mesa_init_polygon( ctx ); |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 1107 | _mesa_init_program( ctx ); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1108 | _mesa_init_rastpos( ctx ); |
| 1109 | _mesa_init_stencil( ctx ); |
| 1110 | _mesa_init_transform( ctx ); |
| 1111 | _mesa_init_varray( ctx ); |
| 1112 | _mesa_init_viewport( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1113 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1114 | if (!_mesa_init_texture( ctx )) |
| 1115 | return GL_FALSE; |
| Brian Paul | b17a722 | 2003-06-13 02:37:27 +0000 | [diff] [blame] | 1116 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1117 | /* Miscellaneous */ |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1118 | ctx->NewState = _NEW_ALL; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1119 | ctx->ErrorValue = (GLenum) GL_NO_ERROR; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1120 | ctx->CatchSignals = GL_TRUE; |
| Brian Paul | f782b81 | 2002-10-04 17:37:45 +0000 | [diff] [blame] | 1121 | ctx->_Facing = 0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1122 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 1123 | return GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1127 | /** |
| 1128 | * If the DRI libGL.so library is old, it may not have the entrypoints for |
| 1129 | * some recent OpenGL extensions. Dynamically add them now. |
| 1130 | * If we're building stand-alone Mesa where libGL.so has both the dispatcher |
| 1131 | * and driver code, this won't be an issue (and calling this function won't |
| 1132 | * do any harm). |
| 1133 | */ |
| 1134 | static void |
| 1135 | add_newer_entrypoints(void) |
| 1136 | { |
| Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame^] | 1137 | unsigned i; |
| 1138 | static const struct { |
| 1139 | const char * const name; |
| 1140 | unsigned offset; |
| 1141 | } |
| 1142 | newer_entrypoints[] = { |
| 1143 | /* GL_ARB_window_pos aliases with GL_MESA_window_pos */ |
| 1144 | { "glWindowPos2dARB", 513 }, |
| 1145 | { "glWindowPos2dvARB", 514 }, |
| 1146 | { "glWindowPos2fARB", 515 }, |
| 1147 | { "glWindowPos2fvARB", 516 }, |
| 1148 | { "glWindowPos2iARB", 517 }, |
| 1149 | { "glWindowPos2ivARB", 518 }, |
| 1150 | { "glWindowPos2sARB", 519 }, |
| 1151 | { "glWindowPos2svARB", 520 }, |
| 1152 | { "glWindowPos3dARB", 521 }, |
| 1153 | { "glWindowPos3dvARB", 522 }, |
| 1154 | { "glWindowPos3fARB", 523 }, |
| 1155 | { "glWindowPos3fvARB", 524 }, |
| 1156 | { "glWindowPos3iARB", 525 }, |
| 1157 | { "glWindowPos3ivARB", 526 }, |
| 1158 | { "glWindowPos3sARB", 527 }, |
| 1159 | { "glWindowPos3svARB", 528 }, |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1160 | #if FEATURE_NV_vertex_program |
| Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame^] | 1161 | { "glAreProgramsResidentNV", 578 }, |
| 1162 | { "glBindProgramNV", 579 }, |
| 1163 | { "glDeleteProgramsNV", 580 }, |
| 1164 | { "glExecuteProgramNV", 581 }, |
| 1165 | { "glGenProgramsNV", 582 }, |
| 1166 | { "glGetProgramParameterdvNV", 583 }, |
| 1167 | { "glGetProgramParameterfvNV", 584 }, |
| 1168 | { "glGetProgramivNV", 585 }, |
| 1169 | { "glGetProgramStringNV", 586 }, |
| 1170 | { "glGetTrackMatrixivNV", 587 }, |
| 1171 | { "glGetVertexAttribdvNV", 588 }, |
| 1172 | { "glGetVertexAttribfvNV", 589 }, |
| 1173 | { "glGetVertexAttribivNV", 590 }, |
| 1174 | { "glGetVertexAttribPointervNV", 591 }, |
| 1175 | { "glIsProgramNV", 592 }, |
| 1176 | { "glLoadProgramNV", 593 }, |
| 1177 | { "glProgramParameter4dNV", 594 }, |
| 1178 | { "glProgramParameter4dvNV", 595 }, |
| 1179 | { "glProgramParameter4fNV", 596 }, |
| 1180 | { "glProgramParameter4fvNV", 597 }, |
| 1181 | { "glProgramParameters4dvNV", 598 }, |
| 1182 | { "glProgramParameters4fvNV", 599 }, |
| 1183 | { "glRequestResidentProgramsNV", 600 }, |
| 1184 | { "glTrackMatrixNV", 601 }, |
| 1185 | { "glVertexAttribPointerNV", 602 }, |
| 1186 | { "glVertexAttrib1dNV", 603 }, |
| 1187 | { "glVertexAttrib1dvNV", 604 }, |
| 1188 | { "glVertexAttrib1fNV", 605 }, |
| 1189 | { "glVertexAttrib1fvNV", 606 }, |
| 1190 | { "glVertexAttrib1sNV", 607 }, |
| 1191 | { "glVertexAttrib1svNV", 608 }, |
| 1192 | { "glVertexAttrib2dNV", 609 }, |
| 1193 | { "glVertexAttrib2dvNV", 610 }, |
| 1194 | { "glVertexAttrib2fNV", 611 }, |
| 1195 | { "glVertexAttrib2fvNV", 612 }, |
| 1196 | { "glVertexAttrib2sNV", 613 }, |
| 1197 | { "glVertexAttrib2svNV", 614 }, |
| 1198 | { "glVertexAttrib3dNV", 615 }, |
| 1199 | { "glVertexAttrib3dvNV", 616 }, |
| 1200 | { "glVertexAttrib3fNV", 617 }, |
| 1201 | { "glVertexAttrib3fvNV", 618 }, |
| 1202 | { "glVertexAttrib3sNV", 619 }, |
| 1203 | { "glVertexAttrib3svNV", 620 }, |
| 1204 | { "glVertexAttrib4dNV", 621 }, |
| 1205 | { "glVertexAttrib4dvNV", 622 }, |
| 1206 | { "glVertexAttrib4fNV", 623 }, |
| 1207 | { "glVertexAttrib4fvNV", 624 }, |
| 1208 | { "glVertexAttrib4sNV", 625 }, |
| 1209 | { "glVertexAttrib4svNV", 626 }, |
| 1210 | { "glVertexAttrib4ubNV", 627 }, |
| 1211 | { "glVertexAttrib4ubvNV", 628 }, |
| 1212 | { "glVertexAttribs1dvNV", 629 }, |
| 1213 | { "glVertexAttribs1fvNV", 630 }, |
| 1214 | { "glVertexAttribs1svNV", 631 }, |
| 1215 | { "glVertexAttribs2dvNV", 632 }, |
| 1216 | { "glVertexAttribs2fvNV", 633 }, |
| 1217 | { "glVertexAttribs2svNV", 634 }, |
| 1218 | { "glVertexAttribs3dvNV", 635 }, |
| 1219 | { "glVertexAttribs3fvNV", 636 }, |
| 1220 | { "glVertexAttribs3svNV", 637 }, |
| 1221 | { "glVertexAttribs4dvNV", 638 }, |
| 1222 | { "glVertexAttribs4fvNV", 639 }, |
| 1223 | { "glVertexAttribs4svNV", 640 }, |
| 1224 | { "glVertexAttribs4ubvNV", 641 }, |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1225 | #endif |
| Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame^] | 1226 | { "glPointParameteriNV", 642 }, |
| 1227 | { "glPointParameterivNV", 643 }, |
| 1228 | { "glMultiDrawArraysEXT", 644 }, |
| 1229 | { "glMultiDrawElementsEXT", 645 }, |
| 1230 | { "glMultiDrawArraysSUN", _gloffset_MultiDrawArraysEXT }, |
| 1231 | { "glMultiDrawElementsSUN", _gloffset_MultiDrawElementsEXT }, |
| 1232 | { "glActiveStencilFaceEXT", 646 }, |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1233 | #if FEATURE_NV_fence |
| Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame^] | 1234 | { "glDeleteFencesNV", 647 }, |
| 1235 | { "glGenFencesNV", 648 }, |
| 1236 | { "glIsFenceNV", 649 }, |
| 1237 | { "glTestFenceNV", 650 }, |
| 1238 | { "glGetFenceivNV", 651 }, |
| 1239 | { "glFinishFenceNV", 652 }, |
| 1240 | { "glSetFenceNV", 653 }, |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1241 | #endif |
| 1242 | #if FEATURE_NV_fragment_program |
| Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame^] | 1243 | { "glProgramNamedParameter4fNV", 682 }, |
| 1244 | { "glProgramNamedParameter4dNV", 683 }, |
| 1245 | { "glProgramNamedParameter4fvNV", 683 }, |
| 1246 | { "glProgramNamedParameter4dvNV", 684 }, |
| 1247 | { "glGetProgramNamedParameterfvNV", 685 }, |
| 1248 | { "glGetProgramNamedParameterdvNV", 686 }, |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1249 | #endif |
| 1250 | #if FEATURE_ARB_vertex_program |
| Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame^] | 1251 | { "glVertexAttrib1sARB", _gloffset_VertexAttrib1sNV }, |
| 1252 | { "glVertexAttrib1fARB", _gloffset_VertexAttrib1fNV }, |
| 1253 | { "glVertexAttrib1dARB", _gloffset_VertexAttrib1dNV }, |
| 1254 | { "glVertexAttrib2sARB", _gloffset_VertexAttrib2sNV }, |
| 1255 | { "glVertexAttrib2fARB", _gloffset_VertexAttrib2fNV }, |
| 1256 | { "glVertexAttrib2dARB", _gloffset_VertexAttrib2dNV }, |
| 1257 | { "glVertexAttrib3sARB", _gloffset_VertexAttrib3sNV }, |
| 1258 | { "glVertexAttrib3fARB", _gloffset_VertexAttrib3fNV }, |
| 1259 | { "glVertexAttrib3dARB", _gloffset_VertexAttrib3dNV }, |
| 1260 | { "glVertexAttrib4sARB", _gloffset_VertexAttrib4sNV }, |
| 1261 | { "glVertexAttrib4fARB", _gloffset_VertexAttrib4fNV }, |
| 1262 | { "glVertexAttrib4dARB", _gloffset_VertexAttrib4dNV }, |
| 1263 | { "glVertexAttrib4NubARB", _gloffset_VertexAttrib4ubNV }, |
| 1264 | { "glVertexAttrib1svARB", _gloffset_VertexAttrib1svNV }, |
| 1265 | { "glVertexAttrib1fvARB", _gloffset_VertexAttrib1fvNV }, |
| 1266 | { "glVertexAttrib1dvARB", _gloffset_VertexAttrib1dvNV }, |
| 1267 | { "glVertexAttrib2svARB", _gloffset_VertexAttrib2svNV }, |
| 1268 | { "glVertexAttrib2fvARB", _gloffset_VertexAttrib2fvNV }, |
| 1269 | { "glVertexAttrib2dvARB", _gloffset_VertexAttrib2dvNV }, |
| 1270 | { "glVertexAttrib3svARB", _gloffset_VertexAttrib3svNV }, |
| 1271 | { "glVertexAttrib3fvARB", _gloffset_VertexAttrib3fvNV }, |
| 1272 | { "glVertexAttrib3dvARB", _gloffset_VertexAttrib3dvNV }, |
| 1273 | { "glVertexAttrib4bvARB", _gloffset_VertexAttrib4bvARB }, |
| 1274 | { "glVertexAttrib4svARB", _gloffset_VertexAttrib4svNV }, |
| 1275 | { "glVertexAttrib4ivARB", _gloffset_VertexAttrib4ivARB }, |
| 1276 | { "glVertexAttrib4ubvARB", _gloffset_VertexAttrib4ubvARB }, |
| 1277 | { "glVertexAttrib4usvARB", _gloffset_VertexAttrib4usvARB }, |
| 1278 | { "glVertexAttrib4uivARB", _gloffset_VertexAttrib4uivARB }, |
| 1279 | { "glVertexAttrib4fvARB", _gloffset_VertexAttrib4fvNV }, |
| 1280 | { "glVertexAttrib4dvARB", _gloffset_VertexAttrib4dvNV }, |
| 1281 | { "glVertexAttrib4NbvARB", _gloffset_VertexAttrib4NbvARB }, |
| 1282 | { "glVertexAttrib4NsvARB", _gloffset_VertexAttrib4NsvARB }, |
| 1283 | { "glVertexAttrib4NivARB", _gloffset_VertexAttrib4NivARB }, |
| 1284 | { "glVertexAttrib4NubvARB", _gloffset_VertexAttrib4ubvNV }, |
| 1285 | { "glVertexAttrib4NusvARB", _gloffset_VertexAttrib4NusvARB }, |
| 1286 | { "glVertexAttrib4NuivARB", _gloffset_VertexAttrib4NuivARB }, |
| 1287 | { "glVertexAttribPointerARB", _gloffset_VertexAttribPointerARB }, |
| 1288 | { "glEnableVertexAttribArrayARB", _gloffset_EnableVertexAttribArrayARB }, |
| 1289 | { "glDisableVertexAttribArrayARB", _gloffset_DisableVertexAttribArrayARB }, |
| 1290 | { "glProgramStringARB", _gloffset_ProgramStringARB }, |
| 1291 | { "glBindProgramARB", _gloffset_BindProgramNV }, |
| 1292 | { "glDeleteProgramsARB", _gloffset_DeleteProgramsNV }, |
| 1293 | { "glGenProgramsARB", _gloffset_GenProgramsNV }, |
| 1294 | { "glIsProgramARB", _gloffset_IsProgramNV }, |
| 1295 | { "glProgramEnvParameter4dARB", _gloffset_ProgramEnvParameter4dARB }, |
| 1296 | { "glProgramEnvParameter4dvARB", _gloffset_ProgramEnvParameter4dvARB }, |
| 1297 | { "glProgramEnvParameter4fARB", _gloffset_ProgramEnvParameter4fARB }, |
| 1298 | { "glProgramEnvParameter4fvARB", _gloffset_ProgramEnvParameter4fvARB }, |
| 1299 | { "glProgramLocalParameter4dARB", _gloffset_ProgramLocalParameter4dARB }, |
| 1300 | { "glProgramLocalParameter4dvARB", _gloffset_ProgramLocalParameter4dvARB }, |
| 1301 | { "glProgramLocalParameter4fARB", _gloffset_ProgramLocalParameter4fARB }, |
| 1302 | { "glProgramLocalParameter4fvARB", _gloffset_ProgramLocalParameter4fvARB }, |
| 1303 | { "glGetProgramEnvParameterdvARB", _gloffset_GetProgramEnvParameterdvARB }, |
| 1304 | { "glGetProgramEnvParameterfvARB", _gloffset_GetProgramEnvParameterfvARB }, |
| 1305 | { "glGetProgramLocalParameterdvARB", _gloffset_GetProgramLocalParameterdvARB }, |
| 1306 | { "glGetProgramLocalParameterfvARB", _gloffset_GetProgramLocalParameterfvARB }, |
| 1307 | { "glGetProgramivARB", _gloffset_GetProgramivARB }, |
| 1308 | { "glGetProgramStringARB", _gloffset_GetProgramStringARB }, |
| 1309 | { "glGetVertexAttribdvARB", _gloffset_GetVertexAttribdvNV }, |
| 1310 | { "glGetVertexAttribfvARB", _gloffset_GetVertexAttribfvNV }, |
| 1311 | { "glGetVertexAttribivARB", _gloffset_GetVertexAttribivNV }, |
| 1312 | { "glGetVertexAttribPointervARB", _gloffset_GetVertexAttribPointervNV }, |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1313 | #endif |
| Ian Romanick | 3baefe6 | 2003-08-22 23:28:03 +0000 | [diff] [blame^] | 1314 | { "glMultiModeDrawArraysIBM", _gloffset_MultiModeDrawArraysIBM }, |
| 1315 | { "glMultiModeDrawElementsIBM", _gloffset_MultiModeDrawElementsIBM }, |
| 1316 | }; |
| 1317 | |
| 1318 | for ( i = 0 ; i < Elements(newer_entrypoints) ; i++ ) { |
| 1319 | _glapi_add_entrypoint( newer_entrypoints[i].name, |
| 1320 | newer_entrypoints[i].offset ); |
| 1321 | } |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| Keith Whitwell | 306d3fc | 2002-04-09 16:56:50 +0000 | [diff] [blame] | 1324 | |
| Brian Paul | de4f460 | 2003-07-03 02:15:06 +0000 | [diff] [blame] | 1325 | /** |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1326 | * Initialize a GLcontext struct. |
| 1327 | * |
| 1328 | * This includes allocating all the other structs and arrays which hang off of |
| 1329 | * the context by pointers. |
| 1330 | * |
| 1331 | * \sa _mesa_create_context() for the parameter description. |
| 1332 | * |
| 1333 | * Performs the imports and exports callback tables initialization, and |
| 1334 | * miscellaneous one-time initializations. If no shared context is supplied one |
| 1335 | * is allocated, and increase its reference count. Setups the GL API dispatch |
| 1336 | * tables. Initialize the TNL module. Sets the maximum Z buffer depth. |
| 1337 | * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables |
| 1338 | * for debug flags. |
| 1339 | * |
| Brian Paul | de4f460 | 2003-07-03 02:15:06 +0000 | [diff] [blame] | 1340 | * \note the direct parameter is ignored (obsolete). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1341 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1342 | GLboolean |
| 1343 | _mesa_initialize_context( GLcontext *ctx, |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1344 | const GLvisual *visual, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1345 | GLcontext *share_list, |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1346 | void *driver_ctx, |
| 1347 | GLboolean direct ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1348 | { |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1349 | GLuint dispatchSize; |
| 1350 | |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1351 | ASSERT(driver_ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1352 | |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1353 | /* If the driver wants core Mesa to use special imports, it'll have to |
| 1354 | * override these defaults. |
| 1355 | */ |
| 1356 | _mesa_init_default_imports( &(ctx->imports), driver_ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1357 | |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 1358 | /* initialize the exports (Mesa functions called by the window system) */ |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1359 | _mesa_init_default_exports( &(ctx->exports) ); |
| 1360 | |
| 1361 | /* misc one-time initializations */ |
| 1362 | one_time_init(ctx); |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 1363 | |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1364 | ctx->DriverCtx = driver_ctx; |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1365 | ctx->Visual = *visual; |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1366 | ctx->DrawBuffer = NULL; |
| 1367 | ctx->ReadBuffer = NULL; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1368 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 1369 | /* Set these pointers to defaults now in case they're not set since |
| 1370 | * we need them while creating the default textures. |
| 1371 | */ |
| 1372 | if (!ctx->Driver.NewTextureObject) |
| 1373 | ctx->Driver.NewTextureObject = _mesa_new_texture_object; |
| 1374 | if (!ctx->Driver.DeleteTexture) |
| 1375 | ctx->Driver.DeleteTexture = _mesa_delete_texture_object; |
| 1376 | if (!ctx->Driver.NewTextureImage) |
| 1377 | ctx->Driver.NewTextureImage = _mesa_new_texture_image; |
| 1378 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1379 | if (share_list) { |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 1380 | /* share state with another context */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1381 | ctx->Shared = share_list->Shared; |
| 1382 | } |
| 1383 | else { |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 1384 | /* allocate new, unshared state */ |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 1385 | if (!alloc_shared_state( ctx )) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1386 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1387 | } |
| 1388 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1389 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1390 | ctx->Shared->RefCount++; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1391 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1392 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1393 | if (!init_attrib_groups( ctx )) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1394 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1395 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1396 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1397 | |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1398 | /* libGL ABI coordination */ |
| 1399 | add_newer_entrypoints(); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1400 | |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1401 | /* Find the larger of Mesa's dispatch table and libGL's dispatch table. |
| 1402 | * In practice, this'll be the same for stand-alone Mesa. But for DRI |
| 1403 | * Mesa we do this to accomodate different versions of libGL and various |
| 1404 | * DRI drivers. |
| 1405 | */ |
| 1406 | dispatchSize = MAX2(_glapi_get_dispatch_table_size(), |
| 1407 | sizeof(struct _glapi_table) / sizeof(void *)); |
| 1408 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1409 | /* setup API dispatch tables */ |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1410 | ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*)); |
| 1411 | ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*)); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1412 | if (!ctx->Exec || !ctx->Save) { |
| 1413 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1414 | if (ctx->Exec) |
| Brian Paul | 2d8db39 | 2000-06-27 22:10:00 +0000 | [diff] [blame] | 1415 | FREE( ctx->Exec ); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1416 | } |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1417 | _mesa_init_exec_table(ctx->Exec, dispatchSize); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1418 | ctx->CurrentDispatch = ctx->Exec; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1419 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1420 | #if _HAVE_FULL_GL |
| 1421 | _mesa_init_dlist_table(ctx->Save, dispatchSize); |
| 1422 | |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1423 | ctx->ExecPrefersFloat = GL_FALSE; |
| 1424 | ctx->SavePrefersFloat = GL_FALSE; |
| 1425 | |
| Gareth Hughes | d8aa026 | 2001-03-11 18:49:11 +0000 | [diff] [blame] | 1426 | /* Neutral tnl module stuff */ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1427 | _mesa_init_exec_vtxfmt( ctx ); |
| Gareth Hughes | d8aa026 | 2001-03-11 18:49:11 +0000 | [diff] [blame] | 1428 | ctx->TnlModule.Current = NULL; |
| 1429 | ctx->TnlModule.SwapCount = 0; |
| 1430 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1431 | #endif |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 1432 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1433 | return GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| Brian Paul | de4f460 | 2003-07-03 02:15:06 +0000 | [diff] [blame] | 1436 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1437 | * Allocate and initialize a GLcontext structure. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1438 | * |
| 1439 | * \param visual a GLvisual pointer (we copy the struct contents) |
| 1440 | * \param share_list another context to share display lists with or NULL |
| 1441 | * \param driver_ctx pointer to device driver's context state struct |
| 1442 | * \param direct obsolete, ignored |
| 1443 | * |
| 1444 | * \return pointer to a new __GLcontextRec or NULL if error. |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1445 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1446 | GLcontext * |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1447 | _mesa_create_context( const GLvisual *visual, |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1448 | GLcontext *share_list, |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1449 | void *driver_ctx, |
| 1450 | GLboolean direct ) |
| 1451 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1452 | { |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1453 | GLcontext *ctx; |
| 1454 | |
| 1455 | ASSERT(visual); |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1456 | ASSERT(driver_ctx); |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1457 | |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1458 | ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext)); |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1459 | if (!ctx) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1460 | return NULL; |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1461 | |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1462 | if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1463 | return ctx; |
| 1464 | } |
| 1465 | else { |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1466 | _mesa_free(ctx); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1467 | return NULL; |
| 1468 | } |
| 1469 | } |
| 1470 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1471 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1472 | * Free the data associated with the given context. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1473 | * |
| 1474 | * But doesn't free the GLcontext struct itself. |
| 1475 | * |
| 1476 | * \sa _mesa_initialize_context() and init_attrib_groups(). |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1477 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1478 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1479 | _mesa_free_context_data( GLcontext *ctx ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1480 | { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1481 | /* if we're destroying the current context, unbind it first */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1482 | if (ctx == _mesa_get_current_context()) { |
| 1483 | _mesa_make_current(NULL, NULL); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1486 | _mesa_free_lighting_data( ctx ); |
| 1487 | _mesa_free_eval_data( ctx ); |
| 1488 | _mesa_free_texture_data( ctx ); |
| 1489 | _mesa_free_matrix_data( ctx ); |
| 1490 | _mesa_free_viewport_data( ctx ); |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 1491 | _mesa_free_colortables_data( ctx ); |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 1492 | #if FEATURE_NV_vertex_program |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 1493 | if (ctx->VertexProgram.Current) { |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 1494 | ctx->VertexProgram.Current->Base.RefCount--; |
| 1495 | if (ctx->VertexProgram.Current->Base.RefCount <= 0) |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 1496 | _mesa_delete_program(ctx, &(ctx->VertexProgram.Current->Base)); |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 1497 | } |
| 1498 | #endif |
| 1499 | #if FEATURE_NV_fragment_program |
| 1500 | if (ctx->FragmentProgram.Current) { |
| 1501 | ctx->FragmentProgram.Current->Base.RefCount--; |
| 1502 | if (ctx->FragmentProgram.Current->Base.RefCount <= 0) |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 1503 | _mesa_delete_program(ctx, &(ctx->FragmentProgram.Current->Base)); |
| Brian Paul | fd28445 | 2001-07-19 15:54:34 +0000 | [diff] [blame] | 1504 | } |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 1505 | #endif |
| Brian Paul | fd28445 | 2001-07-19 15:54:34 +0000 | [diff] [blame] | 1506 | |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 1507 | /* Shared context state (display lists, textures, etc) */ |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1508 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1509 | ctx->Shared->RefCount--; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1510 | assert(ctx->Shared->RefCount >= 0); |
| 1511 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
| 1512 | if (ctx->Shared->RefCount == 0) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1513 | /* free shared state */ |
| 1514 | free_shared_state( ctx, ctx->Shared ); |
| 1515 | } |
| 1516 | |
| Brian Paul | 702ca20 | 2003-07-18 15:22:16 +0000 | [diff] [blame] | 1517 | if (ctx->Extensions.String) |
| 1518 | FREE((void *) ctx->Extensions.String); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1519 | |
| 1520 | FREE(ctx->Exec); |
| 1521 | FREE(ctx->Save); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1524 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1525 | * Destroy a GLcontext structure. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1526 | * |
| 1527 | * \param ctx GL context. |
| 1528 | * |
| 1529 | * Calls _mesa_free_context_data() and free the structure. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1530 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1531 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1532 | _mesa_destroy_context( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1533 | { |
| 1534 | if (ctx) { |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1535 | _mesa_free_context_data(ctx); |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1536 | FREE( (void *) ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1540 | #if _HAVE_FULL_GL |
| 1541 | /** |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1542 | * Copy attribute groups from one context to another. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1543 | * |
| 1544 | * \param src source context |
| 1545 | * \param dst destination context |
| 1546 | * \param mask bitwise OR of GL_*_BIT flags |
| 1547 | * |
| 1548 | * According to the bits specified in \p mask, copies the corresponding |
| 1549 | * attributes from \p src into \dst. For many of the attributes a simple \c |
| 1550 | * memcpy is not enough due to the existence of internal pointers in their data |
| 1551 | * structures. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1552 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1553 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1554 | _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1555 | { |
| 1556 | if (mask & GL_ACCUM_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1557 | /* OK to memcpy */ |
| 1558 | dst->Accum = src->Accum; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1559 | } |
| 1560 | if (mask & GL_COLOR_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1561 | /* OK to memcpy */ |
| 1562 | dst->Color = src->Color; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1563 | } |
| 1564 | if (mask & GL_CURRENT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1565 | /* OK to memcpy */ |
| 1566 | dst->Current = src->Current; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1567 | } |
| 1568 | if (mask & GL_DEPTH_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1569 | /* OK to memcpy */ |
| 1570 | dst->Depth = src->Depth; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1571 | } |
| 1572 | if (mask & GL_ENABLE_BIT) { |
| 1573 | /* no op */ |
| 1574 | } |
| 1575 | if (mask & GL_EVAL_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1576 | /* OK to memcpy */ |
| 1577 | dst->Eval = src->Eval; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1578 | } |
| 1579 | if (mask & GL_FOG_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1580 | /* OK to memcpy */ |
| 1581 | dst->Fog = src->Fog; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1582 | } |
| 1583 | if (mask & GL_HINT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1584 | /* OK to memcpy */ |
| 1585 | dst->Hint = src->Hint; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1586 | } |
| 1587 | if (mask & GL_LIGHTING_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1588 | GLuint i; |
| 1589 | /* begin with memcpy */ |
| 1590 | MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light) ); |
| 1591 | /* fixup linked lists to prevent pointer insanity */ |
| 1592 | make_empty_list( &(dst->Light.EnabledList) ); |
| 1593 | for (i = 0; i < MAX_LIGHTS; i++) { |
| 1594 | if (dst->Light.Light[i].Enabled) { |
| 1595 | insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i])); |
| 1596 | } |
| 1597 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1598 | } |
| 1599 | if (mask & GL_LINE_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1600 | /* OK to memcpy */ |
| 1601 | dst->Line = src->Line; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1602 | } |
| 1603 | if (mask & GL_LIST_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1604 | /* OK to memcpy */ |
| 1605 | dst->List = src->List; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1606 | } |
| 1607 | if (mask & GL_PIXEL_MODE_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1608 | /* OK to memcpy */ |
| 1609 | dst->Pixel = src->Pixel; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1610 | } |
| 1611 | if (mask & GL_POINT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1612 | /* OK to memcpy */ |
| 1613 | dst->Point = src->Point; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1614 | } |
| 1615 | if (mask & GL_POLYGON_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1616 | /* OK to memcpy */ |
| 1617 | dst->Polygon = src->Polygon; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1618 | } |
| 1619 | if (mask & GL_POLYGON_STIPPLE_BIT) { |
| 1620 | /* Use loop instead of MEMCPY due to problem with Portland Group's |
| 1621 | * C compiler. Reported by John Stone. |
| 1622 | */ |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1623 | GLuint i; |
| 1624 | for (i = 0; i < 32; i++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1625 | dst->PolygonStipple[i] = src->PolygonStipple[i]; |
| 1626 | } |
| 1627 | } |
| 1628 | if (mask & GL_SCISSOR_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1629 | /* OK to memcpy */ |
| 1630 | dst->Scissor = src->Scissor; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1631 | } |
| 1632 | if (mask & GL_STENCIL_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1633 | /* OK to memcpy */ |
| 1634 | dst->Stencil = src->Stencil; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1635 | } |
| 1636 | if (mask & GL_TEXTURE_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1637 | /* Cannot memcpy because of pointers */ |
| 1638 | _mesa_copy_texture_state(src, dst); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1639 | } |
| 1640 | if (mask & GL_TRANSFORM_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1641 | /* OK to memcpy */ |
| 1642 | dst->Transform = src->Transform; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1643 | } |
| 1644 | if (mask & GL_VIEWPORT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1645 | /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */ |
| 1646 | dst->Viewport.X = src->Viewport.X; |
| 1647 | dst->Viewport.Y = src->Viewport.Y; |
| 1648 | dst->Viewport.Width = src->Viewport.Width; |
| 1649 | dst->Viewport.Height = src->Viewport.Height; |
| 1650 | dst->Viewport.Near = src->Viewport.Near; |
| 1651 | dst->Viewport.Far = src->Viewport.Far; |
| 1652 | _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1653 | } |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1654 | |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1655 | /* XXX FIXME: Call callbacks? |
| 1656 | */ |
| 1657 | dst->NewState = _NEW_ALL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1658 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1659 | #endif |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1660 | |
| 1661 | |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1662 | /** |
| 1663 | * Check if the given context can render into the given framebuffer |
| 1664 | * by checking visual attributes. |
| 1665 | * \return GL_TRUE if compatible, GL_FALSE otherwise. |
| 1666 | */ |
| 1667 | static GLboolean |
| 1668 | check_compatible(const GLcontext *ctx, const GLframebuffer *buffer) |
| 1669 | { |
| 1670 | const GLvisual *ctxvis = &ctx->Visual; |
| 1671 | const GLvisual *bufvis = &buffer->Visual; |
| 1672 | |
| 1673 | if (ctxvis == bufvis) |
| 1674 | return GL_TRUE; |
| 1675 | |
| 1676 | if (ctxvis->rgbMode != bufvis->rgbMode) |
| 1677 | return GL_FALSE; |
| 1678 | if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode) |
| 1679 | return GL_FALSE; |
| 1680 | if (ctxvis->stereoMode && !bufvis->stereoMode) |
| 1681 | return GL_FALSE; |
| 1682 | if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer) |
| 1683 | return GL_FALSE; |
| 1684 | if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer) |
| 1685 | return GL_FALSE; |
| 1686 | if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer) |
| 1687 | return GL_FALSE; |
| 1688 | if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask) |
| 1689 | return GL_FALSE; |
| 1690 | if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask) |
| 1691 | return GL_FALSE; |
| 1692 | if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask) |
| 1693 | return GL_FALSE; |
| 1694 | if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits) |
| 1695 | return GL_FALSE; |
| 1696 | if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits) |
| 1697 | return GL_FALSE; |
| 1698 | |
| 1699 | return GL_TRUE; |
| 1700 | } |
| 1701 | |
| 1702 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1703 | /** |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 1704 | * Set the current context, binding the given frame buffer to the context. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1705 | * |
| 1706 | * \param newCtx new GL context. |
| 1707 | * \param buffer framebuffer. |
| 1708 | * |
| 1709 | * Calls _mesa_make_current2() with \p buffer as read and write framebuffer. |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 1710 | */ |
| 1711 | void |
| 1712 | _mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer ) |
| 1713 | { |
| 1714 | _mesa_make_current2( newCtx, buffer, buffer ); |
| 1715 | } |
| 1716 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1717 | /** |
| 1718 | * Bind the given context to the given draw-buffer and read-buffer and |
| 1719 | * make it the current context for this thread. |
| 1720 | * |
| 1721 | * \param newCtx new GL context. If NULL then there will be no current GL |
| 1722 | * context. |
| 1723 | * \param drawBuffer draw framebuffer. |
| 1724 | * \param readBuffer read framebuffer. |
| 1725 | * |
| 1726 | * Check that the context's and framebuffer's visuals are compatible, returning |
| 1727 | * immediately otherwise. Sets the glapi current context via |
| 1728 | * _glapi_set_context(). If \p newCtx is not NULL, associates \p drawBuffer and |
| 1729 | * \p readBuffer with it and calls dd_function_table::ResizeBuffers if the buffers size has changed. |
| 1730 | * Calls dd_function_table::MakeCurrent callback if defined. |
| 1731 | * |
| 1732 | * When a context is bound by the first time and the \c MESA_INFO environment |
| 1733 | * variable is set it calls print_info() as an aid for remote user |
| 1734 | * troubleshooting. |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1735 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1736 | void |
| 1737 | _mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer, |
| 1738 | GLframebuffer *readBuffer ) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1739 | { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1740 | if (MESA_VERBOSE) |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1741 | _mesa_debug(newCtx, "_mesa_make_current2()\n"); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1742 | |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1743 | /* Check that the context's and framebuffer's visuals are compatible. |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1744 | */ |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1745 | if (newCtx && drawBuffer && newCtx->DrawBuffer != drawBuffer) { |
| 1746 | if (!check_compatible(newCtx, drawBuffer)) |
| 1747 | return; |
| 1748 | } |
| 1749 | if (newCtx && readBuffer && newCtx->ReadBuffer != readBuffer) { |
| 1750 | if (!check_compatible(newCtx, readBuffer)) |
| 1751 | return; |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1754 | /* We call this function periodically (just here for now) in |
| 1755 | * order to detect when multithreading has begun. |
| 1756 | */ |
| 1757 | _glapi_check_multithread(); |
| 1758 | |
| Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 1759 | _glapi_set_context((void *) newCtx); |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1760 | ASSERT(_mesa_get_current_context() == newCtx); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1761 | |
| 1762 | |
| 1763 | if (!newCtx) { |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1764 | _glapi_set_dispatch(NULL); /* none current */ |
| 1765 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1766 | else { |
| 1767 | _glapi_set_dispatch(newCtx->CurrentDispatch); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1768 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1769 | if (drawBuffer && readBuffer) { |
| 1770 | /* TODO: check if newCtx and buffer's visual match??? */ |
| 1771 | newCtx->DrawBuffer = drawBuffer; |
| 1772 | newCtx->ReadBuffer = readBuffer; |
| 1773 | newCtx->NewState |= _NEW_BUFFERS; |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1774 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1775 | #if _HAVE_FULL_GL |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1776 | if (drawBuffer->Width == 0 && drawBuffer->Height == 0) { |
| 1777 | /* get initial window size */ |
| 1778 | GLuint bufWidth, bufHeight; |
| 1779 | |
| 1780 | /* ask device driver for size of output buffer */ |
| 1781 | (*newCtx->Driver.GetBufferSize)( drawBuffer, &bufWidth, &bufHeight ); |
| 1782 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1783 | if (drawBuffer->Width != bufWidth || |
| 1784 | drawBuffer->Height != bufHeight) { |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1785 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1786 | drawBuffer->Width = bufWidth; |
| 1787 | drawBuffer->Height = bufHeight; |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1788 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1789 | newCtx->Driver.ResizeBuffers( drawBuffer ); |
| 1790 | } |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | if (readBuffer != drawBuffer && |
| 1794 | readBuffer->Width == 0 && readBuffer->Height == 0) { |
| 1795 | /* get initial window size */ |
| 1796 | GLuint bufWidth, bufHeight; |
| 1797 | |
| 1798 | /* ask device driver for size of output buffer */ |
| 1799 | (*newCtx->Driver.GetBufferSize)( readBuffer, &bufWidth, &bufHeight ); |
| 1800 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1801 | if (readBuffer->Width != bufWidth || |
| 1802 | readBuffer->Height != bufHeight) { |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1803 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1804 | readBuffer->Width = bufWidth; |
| 1805 | readBuffer->Height = bufHeight; |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1806 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1807 | newCtx->Driver.ResizeBuffers( readBuffer ); |
| 1808 | } |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1809 | } |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1810 | #endif |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1811 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1812 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1813 | /* Alert the driver - usually passed on to the sw t&l module, |
| 1814 | * but also used to detect threaded cases in the radeon codegen |
| 1815 | * hw t&l module. |
| 1816 | */ |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1817 | if (newCtx->Driver.MakeCurrent) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1818 | newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer ); |
| 1819 | |
| 1820 | /* We can use this to help debug user's problems. Tell them to set |
| 1821 | * the MESA_INFO env variable before running their app. Then the |
| 1822 | * first time each context is made current we'll print some useful |
| 1823 | * information. |
| 1824 | */ |
| 1825 | if (newCtx->FirstTimeCurrent) { |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1826 | if (_mesa_getenv("MESA_INFO")) { |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1827 | _mesa_print_info(); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1828 | } |
| 1829 | newCtx->FirstTimeCurrent = GL_FALSE; |
| 1830 | } |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1831 | } |
| 1832 | } |
| 1833 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1834 | /** |
| 1835 | * Get current context for the calling thread. |
| 1836 | * |
| 1837 | * \return pointer to the current GL context. |
| 1838 | * |
| 1839 | * Calls _glapi_get_context(). This isn't the fastest way to get the current |
| 1840 | * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in context.h. |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1841 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1842 | GLcontext * |
| 1843 | _mesa_get_current_context( void ) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1844 | { |
| Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 1845 | return (GLcontext *) _glapi_get_context(); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1848 | /** |
| 1849 | * Get context's current API dispatch table. |
| 1850 | * |
| 1851 | * It'll either be the immediate-mode execute dispatcher or the display list |
| 1852 | * compile dispatcher. |
| 1853 | * |
| 1854 | * \param ctx GL context. |
| 1855 | * |
| 1856 | * \return pointer to dispatch_table. |
| 1857 | * |
| 1858 | * Simply returns __GLcontextRec::CurrentDispatch. |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1859 | */ |
| 1860 | struct _glapi_table * |
| 1861 | _mesa_get_dispatch(GLcontext *ctx) |
| 1862 | { |
| 1863 | return ctx->CurrentDispatch; |
| 1864 | } |
| 1865 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1866 | /*@}*/ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1867 | |
| 1868 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1869 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1870 | /** \name Miscellaneous functions */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1871 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1872 | /*@{*/ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1873 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1874 | /** |
| 1875 | * Record an error. |
| 1876 | * |
| 1877 | * \param ctx GL context. |
| 1878 | * \param error error code. |
| 1879 | * |
| 1880 | * Records the given error code and call the driver's dd_function_table::Error |
| 1881 | * function if defined. |
| 1882 | * |
| 1883 | * \sa |
| Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 1884 | * This is called via _mesa_error(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1885 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1886 | void |
| Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 1887 | _mesa_record_error( GLcontext *ctx, GLenum error ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1888 | { |
| Brian Paul | 18a285a | 2002-03-16 00:53:15 +0000 | [diff] [blame] | 1889 | if (!ctx) |
| 1890 | return; |
| 1891 | |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 1892 | if (ctx->ErrorValue == GL_NO_ERROR) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1893 | ctx->ErrorValue = error; |
| 1894 | } |
| 1895 | |
| 1896 | /* Call device driver's error handler, if any. This is used on the Mac. */ |
| 1897 | if (ctx->Driver.Error) { |
| 1898 | (*ctx->Driver.Error)( ctx ); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1902 | /** |
| 1903 | * Execute glFinish(). |
| 1904 | * |
| 1905 | * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the |
| 1906 | * dd_function_table::Finish driver callback, if not NULL. |
| 1907 | */ |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1908 | void |
| 1909 | _mesa_Finish( void ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1910 | { |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1911 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1912 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1913 | if (ctx->Driver.Finish) { |
| 1914 | (*ctx->Driver.Finish)( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1915 | } |
| 1916 | } |
| 1917 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1918 | /** |
| 1919 | * Execute glFlush(). |
| 1920 | * |
| 1921 | * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the |
| 1922 | * dd_function_table::Flush driver callback, if not NULL. |
| 1923 | */ |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1924 | void |
| 1925 | _mesa_Flush( void ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1926 | { |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1927 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1928 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1929 | if (ctx->Driver.Flush) { |
| 1930 | (*ctx->Driver.Flush)( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1931 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1932 | } |
| Brian Paul | 48c6a6e | 2000-09-08 21:28:04 +0000 | [diff] [blame] | 1933 | |
| 1934 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1935 | /*@}*/ |