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