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