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