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