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