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