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