| 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 | 145d762 | 2007-08-16 10:05:00 +0100 | [diff] [blame] | 9 | * Version: 7.1 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 10 | * |
| Brian | 145d762 | 2007-08-16 10:05:00 +0100 | [diff] [blame] | 11 | * Copyright (C) 1999-2007 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 | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 81 | #if FEATURE_accum |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 82 | #include "accum.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 83 | #endif |
| Brian Paul | c9e5671 | 2008-06-09 14:49:04 -0600 | [diff] [blame] | 84 | #include "api_exec.h" |
| Brian Paul | c04bb51 | 2006-07-11 21:56:43 +0000 | [diff] [blame] | 85 | #include "arrayobj.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 86 | #if FEATURE_attrib_stack |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 87 | #include "attrib.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 88 | #endif |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 89 | #include "blend.h" |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 90 | #include "buffers.h" |
| Brian Paul | 148a284 | 2003-09-17 03:40:11 +0000 | [diff] [blame] | 91 | #include "bufferobj.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 92 | #if FEATURE_colortable |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 93 | #include "colortab.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 94 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 95 | #include "context.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 96 | #include "debug.h" |
| 97 | #include "depth.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 98 | #if FEATURE_dlist |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 99 | #include "dlist.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 100 | #endif |
| 101 | #if FEATURE_evaluators |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 102 | #include "eval.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 103 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 104 | #include "enums.h" |
| Brian Paul | 585a68c | 1999-09-11 11:31:34 +0000 | [diff] [blame] | 105 | #include "extensions.h" |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 106 | #include "fbobject.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 107 | #if FEATURE_feedback |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 108 | #include "feedback.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 109 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 110 | #include "fog.h" |
| Brian | e6a9381 | 2007-02-26 11:37:37 -0700 | [diff] [blame] | 111 | #include "framebuffer.h" |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 112 | #include "get.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 113 | #if FEATURE_histogram |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 114 | #include "histogram.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 115 | #endif |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 116 | #include "hint.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 117 | #include "hash.h" |
| 118 | #include "light.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 119 | #include "lines.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 120 | #include "macros.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 121 | #include "matrix.h" |
| Brian Paul | c132e2b | 2008-06-09 15:09:21 -0600 | [diff] [blame] | 122 | #include "multisample.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 123 | #if FEATURE_pixel_transfer |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 124 | #include "pixel.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 125 | #endif |
| Brian Paul | 533c1db | 2008-06-09 14:25:23 -0600 | [diff] [blame] | 126 | #include "pixelstore.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 127 | #include "points.h" |
| 128 | #include "polygon.h" |
| Brian Paul | 4e3ae76 | 2008-06-13 13:56:53 -0600 | [diff] [blame] | 129 | #if FEATURE_ARB_occlusion_query |
| Brian | 74afcab | 2007-04-21 12:42:54 -0600 | [diff] [blame] | 130 | #include "queryobj.h" |
| Brian Paul | 4e3ae76 | 2008-06-13 13:56:53 -0600 | [diff] [blame] | 131 | #endif |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 132 | #if FEATURE_drawpix |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 133 | #include "rastpos.h" |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 134 | #endif |
| Brian Paul | 55e341c | 2008-06-09 14:55:24 -0600 | [diff] [blame] | 135 | #include "scissor.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 136 | #include "simple_list.h" |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 137 | #include "state.h" |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 138 | #include "stencil.h" |
| Brian Paul | 8f04c12 | 2004-04-27 13:39:20 +0000 | [diff] [blame] | 139 | #include "texcompress.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 140 | #include "teximage.h" |
| 141 | #include "texobj.h" |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 142 | #include "texstate.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 143 | #include "mtypes.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 144 | #include "varray.h" |
| Brian Paul | 363344f | 2005-09-13 14:48:28 +0000 | [diff] [blame] | 145 | #include "version.h" |
| Gareth Hughes | d4eb665 | 2001-03-12 01:32:20 +0000 | [diff] [blame] | 146 | #include "vtxfmt.h" |
| Brian | c223c6b | 2007-07-04 13:15:20 -0600 | [diff] [blame] | 147 | #include "glapi/glthread.h" |
| Brian Paul | 2dbc515 | 2008-06-13 16:45:15 -0600 | [diff] [blame] | 148 | #include "glapi/glapioffsets.h" |
| 149 | #include "glapi/glapitable.h" |
| Brian | c223c6b | 2007-07-04 13:15:20 -0600 | [diff] [blame] | 150 | #if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program |
| 151 | #include "shader/program.h" |
| 152 | #endif |
| 153 | #include "shader/shader_api.h" |
| Brian Paul | b51d73d | 2008-06-20 08:07:38 -0600 | [diff] [blame] | 154 | #if FEATURE_ATI_fragment_shader |
| Brian | c223c6b | 2007-07-04 13:15:20 -0600 | [diff] [blame] | 155 | #include "shader/atifragshader.h" |
| Brian Paul | b51d73d | 2008-06-20 08:07:38 -0600 | [diff] [blame] | 156 | #endif |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 157 | #if _HAVE_FULL_GL |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 158 | #include "math/m_translate.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 159 | #include "math/m_matrix.h" |
| 160 | #include "math/m_xform.h" |
| Keith Whitwell | f4b02d1 | 2001-01-05 05:31:42 +0000 | [diff] [blame] | 161 | #include "math/mathmod.h" |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 162 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 163 | |
| davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 164 | #ifdef USE_SPARC_ASM |
| Ian Romanick | e16f6e3 | 2004-06-26 00:02:51 +0000 | [diff] [blame] | 165 | #include "sparc/sparc.h" |
| davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 166 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 167 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 168 | #ifndef MESA_VERBOSE |
| Keith Whitwell | 306d3fc | 2002-04-09 16:56:50 +0000 | [diff] [blame] | 169 | int MESA_VERBOSE = 0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 170 | #endif |
| 171 | |
| 172 | #ifndef MESA_DEBUG_FLAGS |
| Keith Whitwell | 306d3fc | 2002-04-09 16:56:50 +0000 | [diff] [blame] | 173 | int MESA_DEBUG_FLAGS = 0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 174 | #endif |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 175 | |
| Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 176 | |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 177 | /* ubyte -> float conversion */ |
| 178 | GLfloat _mesa_ubyte_to_float_color_tab[256]; |
| 179 | |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 180 | |
| Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 181 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 182 | /** |
| 183 | * Swap buffers notification callback. |
| 184 | * |
| 185 | * \param gc GL context. |
| 186 | * |
| 187 | * Called by window system just before swapping buffers. |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 188 | * We have to finish any pending rendering. |
| 189 | */ |
| 190 | void |
| 191 | _mesa_notifySwapBuffers(__GLcontext *gc) |
| 192 | { |
| 193 | FLUSH_VERTICES( gc, 0 ); |
| 194 | } |
| 195 | |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 196 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 197 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 198 | /** \name GL Visual allocation/destruction */ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 199 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 200 | /*@{*/ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 201 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 202 | /** |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 203 | * Allocates a GLvisual structure and initializes it via |
| 204 | * _mesa_initialize_visual(). |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 205 | * |
| 206 | * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode. |
| 207 | * \param dbFlag double buffering |
| 208 | * \param stereoFlag stereo buffer |
| 209 | * \param depthBits requested bits per depth buffer value. Any value in [0, 32] |
| 210 | * is acceptable but the actual depth type will be GLushort or GLuint as |
| 211 | * needed. |
| 212 | * \param stencilBits requested minimum bits per stencil buffer value |
| 213 | * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer. |
| 214 | * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE |
| 215 | * \param redBits number of bits per color component in frame buffer for RGB(A) |
| 216 | * mode. We always use 8 in core Mesa though. |
| 217 | * \param greenBits same as above. |
| 218 | * \param blueBits same as above. |
| 219 | * \param alphaBits same as above. |
| 220 | * \param numSamples not really used. |
| 221 | * |
| 222 | * \return pointer to new GLvisual or NULL if requested parameters can't be |
| 223 | * met. |
| 224 | * |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 225 | * \note Need to add params for level and numAuxBuffers (at least) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 226 | */ |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 227 | GLvisual * |
| 228 | _mesa_create_visual( GLboolean rgbFlag, |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 229 | GLboolean dbFlag, |
| 230 | GLboolean stereoFlag, |
| 231 | GLint redBits, |
| 232 | GLint greenBits, |
| 233 | GLint blueBits, |
| 234 | GLint alphaBits, |
| 235 | GLint indexBits, |
| 236 | GLint depthBits, |
| 237 | GLint stencilBits, |
| 238 | GLint accumRedBits, |
| 239 | GLint accumGreenBits, |
| 240 | GLint accumBlueBits, |
| 241 | GLint accumAlphaBits, |
| 242 | GLint numSamples ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 243 | { |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 244 | GLvisual *vis = (GLvisual *) _mesa_calloc(sizeof(GLvisual)); |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 245 | if (vis) { |
| Brian Paul | e70c623 | 2000-05-04 13:53:55 +0000 | [diff] [blame] | 246 | if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 247 | redBits, greenBits, blueBits, alphaBits, |
| 248 | indexBits, depthBits, stencilBits, |
| 249 | accumRedBits, accumGreenBits, |
| 250 | accumBlueBits, accumAlphaBits, |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 251 | numSamples)) { |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 252 | _mesa_free(vis); |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 253 | return NULL; |
| 254 | } |
| 255 | } |
| 256 | return vis; |
| 257 | } |
| 258 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 259 | /** |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 260 | * Makes some sanity checks and fills in the fields of the |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 261 | * GLvisual object with the given parameters. If the caller needs |
| 262 | * to set additional fields, he should just probably init the whole GLvisual |
| 263 | * object himself. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 264 | * \return GL_TRUE on success, or GL_FALSE on failure. |
| 265 | * |
| 266 | * \sa _mesa_create_visual() above for the parameter description. |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 267 | */ |
| 268 | GLboolean |
| 269 | _mesa_initialize_visual( GLvisual *vis, |
| 270 | GLboolean rgbFlag, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 271 | GLboolean dbFlag, |
| 272 | GLboolean stereoFlag, |
| 273 | GLint redBits, |
| 274 | GLint greenBits, |
| 275 | GLint blueBits, |
| 276 | GLint alphaBits, |
| 277 | GLint indexBits, |
| 278 | GLint depthBits, |
| 279 | GLint stencilBits, |
| 280 | GLint accumRedBits, |
| 281 | GLint accumGreenBits, |
| 282 | GLint accumBlueBits, |
| 283 | GLint accumAlphaBits, |
| 284 | GLint numSamples ) |
| 285 | { |
| 286 | assert(vis); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 287 | |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 288 | if (depthBits < 0 || depthBits > 32) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 289 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 290 | } |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 291 | if (stencilBits < 0 || stencilBits > STENCIL_BITS) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 292 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 293 | } |
| Brian Paul | 978ef2b | 2005-09-21 03:35:08 +0000 | [diff] [blame] | 294 | assert(accumRedBits >= 0); |
| 295 | assert(accumGreenBits >= 0); |
| 296 | assert(accumBlueBits >= 0); |
| 297 | assert(accumAlphaBits >= 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 298 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 299 | vis->rgbMode = rgbFlag; |
| 300 | vis->doubleBufferMode = dbFlag; |
| 301 | vis->stereoMode = stereoFlag; |
| Brian Paul | 153f154 | 2002-10-29 15:04:35 +0000 | [diff] [blame] | 302 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 303 | vis->redBits = redBits; |
| 304 | vis->greenBits = greenBits; |
| 305 | vis->blueBits = blueBits; |
| 306 | vis->alphaBits = alphaBits; |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 307 | vis->rgbBits = redBits + greenBits + blueBits; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 308 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 309 | vis->indexBits = indexBits; |
| 310 | vis->depthBits = depthBits; |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 311 | vis->stencilBits = stencilBits; |
| 312 | |
| 313 | vis->accumRedBits = accumRedBits; |
| 314 | vis->accumGreenBits = accumGreenBits; |
| 315 | vis->accumBlueBits = accumBlueBits; |
| 316 | vis->accumAlphaBits = accumAlphaBits; |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 317 | |
| Brian Paul | 153f154 | 2002-10-29 15:04:35 +0000 | [diff] [blame] | 318 | vis->haveAccumBuffer = accumRedBits > 0; |
| 319 | vis->haveDepthBuffer = depthBits > 0; |
| 320 | vis->haveStencilBuffer = stencilBits > 0; |
| 321 | |
| 322 | vis->numAuxBuffers = 0; |
| 323 | vis->level = 0; |
| 324 | vis->pixmapMode = 0; |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 325 | vis->sampleBuffers = numSamples > 0 ? 1 : 0; |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 326 | vis->samples = numSamples; |
| Brian Paul | 153f154 | 2002-10-29 15:04:35 +0000 | [diff] [blame] | 327 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 328 | return GL_TRUE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 331 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 332 | /** |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 333 | * Destroy a visual and free its memory. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 334 | * |
| 335 | * \param vis visual. |
| 336 | * |
| 337 | * Frees the visual structure. |
| 338 | */ |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 339 | void |
| 340 | _mesa_destroy_visual( GLvisual *vis ) |
| 341 | { |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 342 | _mesa_free(vis); |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 345 | /*@}*/ |
| 346 | |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 347 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 348 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 349 | /** \name Context allocation, initialization, destroying |
| 350 | * |
| 351 | * The purpose of the most initialization functions here is to provide the |
| 352 | * default state values according to the OpenGL specification. |
| 353 | */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 354 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 355 | /*@{*/ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 356 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 357 | /** |
| 358 | * One-time initialization mutex lock. |
| 359 | * |
| 360 | * \sa Used by one_time_init(). |
| 361 | */ |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 362 | _glthread_DECLARE_STATIC_MUTEX(OneTimeLock); |
| 363 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 364 | /** |
| 365 | * Calls all the various one-time-init functions in Mesa. |
| 366 | * |
| 367 | * While holding a global mutex lock, calls several initialization functions, |
| 368 | * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is |
| 369 | * defined. |
| 370 | * |
| Brian Paul | a764b7e | 2006-02-26 17:16:37 +0000 | [diff] [blame] | 371 | * \sa _math_init(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 372 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 373 | static void |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 374 | one_time_init( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 375 | { |
| 376 | static GLboolean alreadyCalled = GL_FALSE; |
| Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 377 | (void) ctx; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 378 | _glthread_LOCK_MUTEX(OneTimeLock); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 379 | if (!alreadyCalled) { |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 380 | GLuint i; |
| 381 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 382 | /* do some implementation tests */ |
| 383 | assert( sizeof(GLbyte) == 1 ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 384 | assert( sizeof(GLubyte) == 1 ); |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 385 | assert( sizeof(GLshort) == 2 ); |
| 386 | assert( sizeof(GLushort) == 2 ); |
| 387 | assert( sizeof(GLint) == 4 ); |
| 388 | assert( sizeof(GLuint) == 4 ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 389 | |
| Brian | 33c3739 | 2007-04-04 22:18:53 -0600 | [diff] [blame] | 390 | _mesa_init_sqrt_table(); |
| 391 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 392 | #if _HAVE_FULL_GL |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 393 | _math_init(); |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 394 | |
| 395 | for (i = 0; i < 256; i++) { |
| 396 | _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F; |
| 397 | } |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 398 | #endif |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 399 | |
| davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 400 | #ifdef USE_SPARC_ASM |
| 401 | _mesa_init_sparc_glapi_relocs(); |
| 402 | #endif |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 403 | if (_mesa_getenv("MESA_DEBUG")) { |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 404 | _glapi_noop_enable_warnings(GL_TRUE); |
| Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 405 | _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning ); |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 406 | } |
| 407 | else { |
| 408 | _glapi_noop_enable_warnings(GL_FALSE); |
| 409 | } |
| 410 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 411 | #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__) |
| Brian Paul | 363344f | 2005-09-13 14:48:28 +0000 | [diff] [blame] | 412 | _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n", |
| 413 | MESA_VERSION_STRING, __DATE__, __TIME__); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 414 | #endif |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 415 | |
| 416 | alreadyCalled = GL_TRUE; |
| 417 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 418 | _glthread_UNLOCK_MUTEX(OneTimeLock); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 421 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 422 | /** |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 423 | * Allocate and initialize a shared context state structure. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 424 | * Initializes the display list, texture objects and vertex programs hash |
| 425 | * tables, allocates the texture objects. If it runs out of memory, frees |
| 426 | * everything already allocated before returning NULL. |
| Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 427 | * |
| 428 | * \return pointer to a gl_shared_state structure on success, or NULL on |
| 429 | * failure. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 430 | */ |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 431 | static GLboolean |
| 432 | alloc_shared_state( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 433 | { |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 434 | struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 435 | if (!ss) |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 436 | return GL_FALSE; |
| 437 | |
| 438 | ctx->Shared = ss; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 439 | |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 440 | _glthread_INIT_MUTEX(ss->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 441 | |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 442 | ss->DisplayList = _mesa_NewHashTable(); |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 443 | ss->TexObjects = _mesa_NewHashTable(); |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 444 | ss->Programs = _mesa_NewHashTable(); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 445 | |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 446 | #if FEATURE_ARB_vertex_program |
| Brian | df43fb6 | 2008-05-06 23:08:51 -0600 | [diff] [blame] | 447 | ss->DefaultVertexProgram = (struct gl_vertex_program *) |
| 448 | ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 449 | if (!ss->DefaultVertexProgram) |
| 450 | goto cleanup; |
| 451 | #endif |
| 452 | #if FEATURE_ARB_fragment_program |
| Brian | df43fb6 | 2008-05-06 23:08:51 -0600 | [diff] [blame] | 453 | ss->DefaultFragmentProgram = (struct gl_fragment_program *) |
| 454 | ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 455 | if (!ss->DefaultFragmentProgram) |
| 456 | goto cleanup; |
| 457 | #endif |
| Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 458 | #if FEATURE_ATI_fragment_shader |
| Brian Paul | 63d6830 | 2005-11-19 16:43:04 +0000 | [diff] [blame] | 459 | ss->ATIShaders = _mesa_NewHashTable(); |
| 460 | ss->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0); |
| Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 461 | if (!ss->DefaultFragmentShader) |
| 462 | goto cleanup; |
| 463 | #endif |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 464 | |
| Tilman Sauerbeck | 17b5063 | 2006-07-11 19:03:21 +0000 | [diff] [blame] | 465 | #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 466 | ss->BufferObjects = _mesa_NewHashTable(); |
| Tilman Sauerbeck | 17b5063 | 2006-07-11 19:03:21 +0000 | [diff] [blame] | 467 | #endif |
| 468 | |
| Ian Romanick | ee34e6e | 2006-06-12 16:26:29 +0000 | [diff] [blame] | 469 | ss->ArrayObjects = _mesa_NewHashTable(); |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 470 | |
| Michal Krol | 365582d | 2006-08-01 20:07:31 +0000 | [diff] [blame] | 471 | #if FEATURE_ARB_shader_objects |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 472 | ss->ShaderObjects = _mesa_NewHashTable(); |
| Michal Krol | 365582d | 2006-08-01 20:07:31 +0000 | [diff] [blame] | 473 | #endif |
| Ian Romanick | 0207b47 | 2003-09-09 00:10:12 +0000 | [diff] [blame] | 474 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 475 | ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D); |
| 476 | if (!ss->Default1D) |
| 477 | goto cleanup; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 478 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 479 | ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D); |
| 480 | if (!ss->Default2D) |
| 481 | goto cleanup; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 482 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 483 | ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D); |
| 484 | if (!ss->Default3D) |
| 485 | goto cleanup; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 486 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 487 | ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB); |
| 488 | if (!ss->DefaultCubeMap) |
| 489 | goto cleanup; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 490 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 491 | ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV); |
| 492 | if (!ss->DefaultRect) |
| 493 | goto cleanup; |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 494 | |
| Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 495 | ss->Default1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT); |
| 496 | if (!ss->Default1DArray) |
| 497 | goto cleanup; |
| 498 | |
| 499 | ss->Default2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT); |
| 500 | if (!ss->Default2DArray) |
| 501 | goto cleanup; |
| 502 | |
| Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 503 | /* sanity check */ |
| 504 | assert(ss->Default1D->RefCount == 1); |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 505 | |
| Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 506 | _glthread_INIT_MUTEX(ss->TexMutex); |
| 507 | ss->TextureStateStamp = 0; |
| 508 | |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 509 | #if FEATURE_EXT_framebuffer_object |
| 510 | ss->FrameBuffers = _mesa_NewHashTable(); |
| 511 | if (!ss->FrameBuffers) |
| 512 | goto cleanup; |
| 513 | ss->RenderBuffers = _mesa_NewHashTable(); |
| 514 | if (!ss->RenderBuffers) |
| 515 | goto cleanup; |
| 516 | #endif |
| 517 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 518 | return GL_TRUE; |
| 519 | |
| Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 520 | cleanup: |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 521 | /* Ran out of memory at some point. Free everything and return NULL */ |
| 522 | if (ss->DisplayList) |
| 523 | _mesa_DeleteHashTable(ss->DisplayList); |
| 524 | if (ss->TexObjects) |
| 525 | _mesa_DeleteHashTable(ss->TexObjects); |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 526 | if (ss->Programs) |
| 527 | _mesa_DeleteHashTable(ss->Programs); |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 528 | #if FEATURE_ARB_vertex_program |
| Brian | df43fb6 | 2008-05-06 23:08:51 -0600 | [diff] [blame] | 529 | _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL); |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 530 | #endif |
| 531 | #if FEATURE_ARB_fragment_program |
| Brian | df43fb6 | 2008-05-06 23:08:51 -0600 | [diff] [blame] | 532 | _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL); |
| Brian Paul | 451f310 | 2003-04-17 01:48:19 +0000 | [diff] [blame] | 533 | #endif |
| Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 534 | #if FEATURE_ATI_fragment_shader |
| 535 | if (ss->DefaultFragmentShader) |
| Brian Paul | 63d6830 | 2005-11-19 16:43:04 +0000 | [diff] [blame] | 536 | _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader); |
| Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 537 | #endif |
| Tilman Sauerbeck | 17b5063 | 2006-07-11 19:03:21 +0000 | [diff] [blame] | 538 | #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object |
| Ian Romanick | 0207b47 | 2003-09-09 00:10:12 +0000 | [diff] [blame] | 539 | if (ss->BufferObjects) |
| 540 | _mesa_DeleteHashTable(ss->BufferObjects); |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 541 | #endif |
| 542 | |
| Tilman Sauerbeck | c0eb777 | 2006-07-11 19:36:27 +0000 | [diff] [blame] | 543 | if (ss->ArrayObjects) |
| 544 | _mesa_DeleteHashTable (ss->ArrayObjects); |
| 545 | |
| Michal Krol | 365582d | 2006-08-01 20:07:31 +0000 | [diff] [blame] | 546 | #if FEATURE_ARB_shader_objects |
| Brian | 0bf5dbe | 2006-12-19 18:02:41 -0700 | [diff] [blame] | 547 | if (ss->ShaderObjects) |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 548 | _mesa_DeleteHashTable (ss->ShaderObjects); |
| Michal Krol | 365582d | 2006-08-01 20:07:31 +0000 | [diff] [blame] | 549 | #endif |
| Ian Romanick | 0207b47 | 2003-09-09 00:10:12 +0000 | [diff] [blame] | 550 | |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 551 | #if FEATURE_EXT_framebuffer_object |
| 552 | if (ss->FrameBuffers) |
| 553 | _mesa_DeleteHashTable(ss->FrameBuffers); |
| 554 | if (ss->RenderBuffers) |
| 555 | _mesa_DeleteHashTable(ss->RenderBuffers); |
| 556 | #endif |
| 557 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 558 | if (ss->Default1D) |
| 559 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D); |
| 560 | if (ss->Default2D) |
| 561 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D); |
| 562 | if (ss->Default3D) |
| 563 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D); |
| 564 | if (ss->DefaultCubeMap) |
| 565 | (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap); |
| 566 | if (ss->DefaultRect) |
| 567 | (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect); |
| Brian | 6f47250 | 2007-08-13 11:09:48 +0100 | [diff] [blame] | 568 | if (ss->Default1DArray) |
| 569 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default1DArray); |
| 570 | if (ss->Default2DArray) |
| 571 | (*ctx->Driver.DeleteTexture)(ctx, ss->Default2DArray); |
| Brian | a5c84de | 2008-01-01 10:20:21 -0700 | [diff] [blame] | 572 | |
| 573 | _mesa_free(ss); |
| 574 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 575 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 578 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 579 | /** |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 580 | * Callback for deleting a display list. Called by _mesa_HashDeleteAll(). |
| 581 | */ |
| 582 | static void |
| 583 | delete_displaylist_cb(GLuint id, void *data, void *userData) |
| 584 | { |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 585 | #if FEATURE_dlist |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 586 | struct mesa_display_list *list = (struct mesa_display_list *) data; |
| 587 | GLcontext *ctx = (GLcontext *) userData; |
| 588 | _mesa_delete_list(ctx, list); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 589 | #endif |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Callback for deleting a texture object. Called by _mesa_HashDeleteAll(). |
| 594 | */ |
| 595 | static void |
| 596 | delete_texture_cb(GLuint id, void *data, void *userData) |
| 597 | { |
| 598 | struct gl_texture_object *texObj = (struct gl_texture_object *) data; |
| 599 | GLcontext *ctx = (GLcontext *) userData; |
| 600 | ctx->Driver.DeleteTexture(ctx, texObj); |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Callback for deleting a program object. Called by _mesa_HashDeleteAll(). |
| 605 | */ |
| 606 | static void |
| 607 | delete_program_cb(GLuint id, void *data, void *userData) |
| 608 | { |
| Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 609 | struct gl_program *prog = (struct gl_program *) data; |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 610 | GLcontext *ctx = (GLcontext *) userData; |
| Brian Paul | fbfe2a5 | 2008-05-19 08:43:36 -0600 | [diff] [blame] | 611 | ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */ |
| 612 | prog->RefCount = 0; /* now going away */ |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 613 | ctx->Driver.DeleteProgram(ctx, prog); |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Callback for deleting an ATI fragment shader object. |
| 618 | * Called by _mesa_HashDeleteAll(). |
| 619 | */ |
| 620 | static void |
| 621 | delete_fragshader_cb(GLuint id, void *data, void *userData) |
| 622 | { |
| 623 | struct ati_fragment_shader *shader = (struct ati_fragment_shader *) data; |
| 624 | GLcontext *ctx = (GLcontext *) userData; |
| 625 | _mesa_delete_ati_fragment_shader(ctx, shader); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Callback for deleting a buffer object. Called by _mesa_HashDeleteAll(). |
| 630 | */ |
| 631 | static void |
| 632 | delete_bufferobj_cb(GLuint id, void *data, void *userData) |
| 633 | { |
| 634 | struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data; |
| 635 | GLcontext *ctx = (GLcontext *) userData; |
| 636 | ctx->Driver.DeleteBuffer(ctx, bufObj); |
| 637 | } |
| 638 | |
| Brian Paul | c04bb51 | 2006-07-11 21:56:43 +0000 | [diff] [blame] | 639 | /** |
| 640 | * Callback for deleting an array object. Called by _mesa_HashDeleteAll(). |
| 641 | */ |
| 642 | static void |
| 643 | delete_arrayobj_cb(GLuint id, void *data, void *userData) |
| 644 | { |
| 645 | struct gl_array_object *arrayObj = (struct gl_array_object *) data; |
| 646 | GLcontext *ctx = (GLcontext *) userData; |
| 647 | _mesa_delete_array_object(ctx, arrayObj); |
| 648 | } |
| 649 | |
| Brian Paul | 4d4373b | 2006-11-18 17:44:28 +0000 | [diff] [blame] | 650 | /** |
| Xiang, Haihao | 63d8a84 | 2008-03-31 17:02:47 +0800 | [diff] [blame] | 651 | * Callback for freeing shader program data. Call it before delete_shader_cb |
| 652 | * to avoid memory access error. |
| 653 | */ |
| 654 | static void |
| 655 | free_shader_program_data_cb(GLuint id, void *data, void *userData) |
| 656 | { |
| 657 | GLcontext *ctx = (GLcontext *) userData; |
| 658 | struct gl_shader_program *shProg = (struct gl_shader_program *) data; |
| 659 | |
| 660 | if (shProg->Type == GL_SHADER_PROGRAM_MESA) { |
| 661 | _mesa_free_shader_program_data(ctx, shProg); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | /** |
| Brian | 9e4bae9 | 2006-12-20 09:27:42 -0700 | [diff] [blame] | 666 | * Callback for deleting shader and shader programs objects. |
| 667 | * Called by _mesa_HashDeleteAll(). |
| Brian Paul | 4d4373b | 2006-11-18 17:44:28 +0000 | [diff] [blame] | 668 | */ |
| 669 | static void |
| Brian | 9e4bae9 | 2006-12-20 09:27:42 -0700 | [diff] [blame] | 670 | delete_shader_cb(GLuint id, void *data, void *userData) |
| Brian Paul | 4d4373b | 2006-11-18 17:44:28 +0000 | [diff] [blame] | 671 | { |
| Brian | 9e4bae9 | 2006-12-20 09:27:42 -0700 | [diff] [blame] | 672 | GLcontext *ctx = (GLcontext *) userData; |
| 673 | struct gl_shader *sh = (struct gl_shader *) data; |
| Xiang, Haihao | aef47c4 | 2008-03-31 16:27:47 +0800 | [diff] [blame] | 674 | if (sh->Type == GL_FRAGMENT_SHADER || sh->Type == GL_VERTEX_SHADER) { |
| 675 | _mesa_free_shader(ctx, sh); |
| 676 | } |
| 677 | else { |
| 678 | struct gl_shader_program *shProg = (struct gl_shader_program *) data; |
| 679 | ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA); |
| 680 | _mesa_free_shader_program(ctx, shProg); |
| 681 | } |
| Brian Paul | 4d4373b | 2006-11-18 17:44:28 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| Brian | 393a625 | 2007-08-13 17:37:30 +0100 | [diff] [blame] | 684 | /** |
| 685 | * Callback for deleting a framebuffer object. Called by _mesa_HashDeleteAll() |
| 686 | */ |
| 687 | static void |
| 688 | delete_framebuffer_cb(GLuint id, void *data, void *userData) |
| 689 | { |
| 690 | struct gl_framebuffer *fb = (struct gl_framebuffer *) data; |
| Brian | dc73217 | 2007-08-14 11:56:59 +0100 | [diff] [blame] | 691 | /* The fact that the framebuffer is in the hashtable means its refcount |
| 692 | * is one, but we're removing from the hashtable now. So clear refcount. |
| 693 | */ |
| 694 | /*assert(fb->RefCount == 1);*/ |
| 695 | fb->RefCount = 0; |
| Brian | 2f7c804 | 2008-01-30 08:08:23 -0700 | [diff] [blame] | 696 | |
| 697 | /* NOTE: Delete should always be defined but there are two reports |
| 698 | * of it being NULL (bugs 13507, 14293). Work-around for now. |
| 699 | */ |
| 700 | if (fb->Delete) |
| 701 | fb->Delete(fb); |
| Brian | 393a625 | 2007-08-13 17:37:30 +0100 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Callback for deleting a renderbuffer object. Called by _mesa_HashDeleteAll() |
| 706 | */ |
| 707 | static void |
| 708 | delete_renderbuffer_cb(GLuint id, void *data, void *userData) |
| 709 | { |
| 710 | struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data; |
| Brian | dc73217 | 2007-08-14 11:56:59 +0100 | [diff] [blame] | 711 | rb->RefCount = 0; /* see comment for FBOs above */ |
| Brian Paul | 61b3ce8 | 2008-08-03 11:13:12 -0600 | [diff] [blame] | 712 | if (rb->Delete) |
| 713 | rb->Delete(rb); |
| Brian | 393a625 | 2007-08-13 17:37:30 +0100 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 717 | |
| 718 | /** |
| 719 | * Deallocate a shared state object and all children structures. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 720 | * |
| 721 | * \param ctx GL context. |
| 722 | * \param ss shared state pointer. |
| 723 | * |
| 724 | * Frees the display lists, the texture objects (calling the driver texture |
| 725 | * deletion callback to free its private data) and the vertex programs, as well |
| 726 | * as their hash tables. |
| 727 | * |
| 728 | * \sa alloc_shared_state(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 729 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 730 | static void |
| 731 | free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 732 | { |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 733 | /* |
| 734 | * Free display lists |
| 735 | */ |
| 736 | _mesa_HashDeleteAll(ss->DisplayList, delete_displaylist_cb, ctx); |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 737 | _mesa_DeleteHashTable(ss->DisplayList); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 738 | |
| Brian Paul | fbfe2a5 | 2008-05-19 08:43:36 -0600 | [diff] [blame] | 739 | #if FEATURE_ARB_shader_objects |
| 740 | _mesa_HashWalk(ss->ShaderObjects, free_shader_program_data_cb, ctx); |
| 741 | _mesa_HashDeleteAll(ss->ShaderObjects, delete_shader_cb, ctx); |
| 742 | _mesa_DeleteHashTable(ss->ShaderObjects); |
| 743 | #endif |
| 744 | |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 745 | _mesa_HashDeleteAll(ss->Programs, delete_program_cb, ctx); |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 746 | _mesa_DeleteHashTable(ss->Programs); |
| Brian Paul | 85f553d | 2008-06-20 10:47:38 -0600 | [diff] [blame^] | 747 | |
| Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 748 | #if FEATURE_ARB_vertex_program |
| Brian | df43fb6 | 2008-05-06 23:08:51 -0600 | [diff] [blame] | 749 | _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL); |
| Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 750 | #endif |
| 751 | #if FEATURE_ARB_fragment_program |
| Brian | df43fb6 | 2008-05-06 23:08:51 -0600 | [diff] [blame] | 752 | _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL); |
| Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 753 | #endif |
| Brian Paul | 1096eae | 2006-01-16 16:35:13 +0000 | [diff] [blame] | 754 | |
| Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 755 | #if FEATURE_ATI_fragment_shader |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 756 | _mesa_HashDeleteAll(ss->ATIShaders, delete_fragshader_cb, ctx); |
| Brian Paul | 1096eae | 2006-01-16 16:35:13 +0000 | [diff] [blame] | 757 | _mesa_DeleteHashTable(ss->ATIShaders); |
| 758 | _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader); |
| Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 759 | #endif |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 760 | |
| Tilman Sauerbeck | 17b5063 | 2006-07-11 19:03:21 +0000 | [diff] [blame] | 761 | #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 762 | _mesa_HashDeleteAll(ss->BufferObjects, delete_bufferobj_cb, ctx); |
| Ian Romanick | 0207b47 | 2003-09-09 00:10:12 +0000 | [diff] [blame] | 763 | _mesa_DeleteHashTable(ss->BufferObjects); |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 764 | #endif |
| 765 | |
| Brian Paul | c04bb51 | 2006-07-11 21:56:43 +0000 | [diff] [blame] | 766 | _mesa_HashDeleteAll(ss->ArrayObjects, delete_arrayobj_cb, ctx); |
| Tilman Sauerbeck | c0eb777 | 2006-07-11 19:36:27 +0000 | [diff] [blame] | 767 | _mesa_DeleteHashTable(ss->ArrayObjects); |
| 768 | |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 769 | #if FEATURE_EXT_framebuffer_object |
| Brian | 393a625 | 2007-08-13 17:37:30 +0100 | [diff] [blame] | 770 | _mesa_HashDeleteAll(ss->FrameBuffers, delete_framebuffer_cb, ctx); |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 771 | _mesa_DeleteHashTable(ss->FrameBuffers); |
| Brian | 393a625 | 2007-08-13 17:37:30 +0100 | [diff] [blame] | 772 | _mesa_HashDeleteAll(ss->RenderBuffers, delete_renderbuffer_cb, ctx); |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 773 | _mesa_DeleteHashTable(ss->RenderBuffers); |
| 774 | #endif |
| Michal Krol | 9b3752c | 2005-01-13 14:08:47 +0000 | [diff] [blame] | 775 | |
| Brian | dc73217 | 2007-08-14 11:56:59 +0100 | [diff] [blame] | 776 | /* |
| 777 | * Free texture objects (after FBOs since some textures might have |
| 778 | * been bound to FBOs). |
| 779 | */ |
| 780 | ASSERT(ctx->Driver.DeleteTexture); |
| 781 | /* the default textures */ |
| 782 | ctx->Driver.DeleteTexture(ctx, ss->Default1D); |
| 783 | ctx->Driver.DeleteTexture(ctx, ss->Default2D); |
| 784 | ctx->Driver.DeleteTexture(ctx, ss->Default3D); |
| 785 | ctx->Driver.DeleteTexture(ctx, ss->DefaultCubeMap); |
| 786 | ctx->Driver.DeleteTexture(ctx, ss->DefaultRect); |
| 787 | ctx->Driver.DeleteTexture(ctx, ss->Default1DArray); |
| 788 | ctx->Driver.DeleteTexture(ctx, ss->Default2DArray); |
| 789 | /* all other textures */ |
| 790 | _mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx); |
| 791 | _mesa_DeleteHashTable(ss->TexObjects); |
| 792 | |
| Keith Whitwell | e15fd85 | 2002-12-12 13:03:15 +0000 | [diff] [blame] | 793 | _glthread_DESTROY_MUTEX(ss->Mutex); |
| 794 | |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 795 | _mesa_free(ss); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | |
| Brian Paul | 4d859f7 | 2004-01-23 18:57:05 +0000 | [diff] [blame] | 799 | /** |
| 800 | * Initialize fields of gl_current_attrib (aka ctx->Current.*) |
| 801 | */ |
| 802 | static void |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 803 | _mesa_init_current(GLcontext *ctx) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 804 | { |
| Brian Paul | 88bf038 | 2004-02-13 15:30:08 +0000 | [diff] [blame] | 805 | GLuint i; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 806 | |
| Brian Paul | 94b30dc | 2006-04-25 00:53:25 +0000 | [diff] [blame] | 807 | /* Init all to (0,0,0,1) */ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 808 | for (i = 0; i < VERT_ATTRIB_MAX; i++) { |
| 809 | 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] | 810 | } |
| Brian Paul | 94b30dc | 2006-04-25 00:53:25 +0000 | [diff] [blame] | 811 | |
| 812 | /* redo special cases: */ |
| Markus Amsler | 507da247 | 2008-03-09 17:51:11 -0600 | [diff] [blame] | 813 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 ); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 814 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 ); |
| 815 | 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] | 816 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 ); |
| Keith Whitwell | fd27560 | 2006-10-30 20:16:35 +0000 | [diff] [blame] | 817 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 ); |
| 818 | ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | |
| Brian Paul | 4d859f7 | 2004-01-23 18:57:05 +0000 | [diff] [blame] | 822 | /** |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 823 | * Init vertex/fragment program native limits from logical limits. |
| 824 | */ |
| 825 | static void |
| 826 | init_natives(struct gl_program_constants *prog) |
| 827 | { |
| 828 | prog->MaxNativeInstructions = prog->MaxInstructions; |
| 829 | prog->MaxNativeAluInstructions = prog->MaxAluInstructions; |
| 830 | prog->MaxNativeTexInstructions = prog->MaxTexInstructions; |
| 831 | prog->MaxNativeTexIndirections = prog->MaxTexIndirections; |
| 832 | prog->MaxNativeAttribs = prog->MaxAttribs; |
| 833 | prog->MaxNativeTemps = prog->MaxTemps; |
| 834 | prog->MaxNativeAddressRegs = prog->MaxAddressRegs; |
| 835 | prog->MaxNativeParameters = prog->MaxParameters; |
| 836 | } |
| 837 | |
| 838 | |
| 839 | /** |
| Brian Paul | 4d859f7 | 2004-01-23 18:57:05 +0000 | [diff] [blame] | 840 | * Initialize fields of gl_constants (aka ctx->Const.*). |
| 841 | * Use defaults from config.h. The device drivers will often override |
| 842 | * some of these values (such as number of texture units). |
| 843 | */ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 844 | static void |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 845 | _mesa_init_constants(GLcontext *ctx) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 846 | { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 847 | assert(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 848 | |
| Brian Paul | cd1cefa | 2001-06-13 14:56:14 +0000 | [diff] [blame] | 849 | assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS); |
| 850 | assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS); |
| 851 | |
| Brian Paul | da238ee | 2006-04-13 19:21:58 +0000 | [diff] [blame] | 852 | assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_COORD_UNITS); |
| 853 | assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_IMAGE_UNITS); |
| 854 | |
| Brian Paul | 53f82c5 | 2004-10-02 16:39:09 +0000 | [diff] [blame] | 855 | /* Constants, may be overriden (usually only reduced) by device drivers */ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 856 | ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS; |
| Brian Paul | cd1cefa | 2001-06-13 14:56:14 +0000 | [diff] [blame] | 857 | ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS; |
| 858 | ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS; |
| Brian Paul | 8afe7de | 2002-06-15 03:03:06 +0000 | [diff] [blame] | 859 | ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE; |
| Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 860 | ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS; |
| Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 861 | ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS; |
| 862 | ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS; |
| Brian Paul | da238ee | 2006-04-13 19:21:58 +0000 | [diff] [blame] | 863 | ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits, |
| 864 | ctx->Const.MaxTextureImageUnits); |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 865 | ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY; |
| Brian Paul | 87c964d | 2001-11-06 15:53:00 +0000 | [diff] [blame] | 866 | ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 867 | ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 868 | ctx->Const.SubPixelBits = SUB_PIXEL_BITS; |
| 869 | ctx->Const.MinPointSize = MIN_POINT_SIZE; |
| 870 | ctx->Const.MaxPointSize = MAX_POINT_SIZE; |
| 871 | ctx->Const.MinPointSizeAA = MIN_POINT_SIZE; |
| 872 | ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE; |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 873 | ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 874 | ctx->Const.MinLineWidth = MIN_LINE_WIDTH; |
| 875 | ctx->Const.MaxLineWidth = MAX_LINE_WIDTH; |
| 876 | ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH; |
| 877 | ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH; |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 878 | ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 879 | ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE; |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 880 | ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH; |
| 881 | ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT; |
| Brian Paul | a864432 | 2000-11-27 18:22:13 +0000 | [diff] [blame] | 882 | ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES; |
| 883 | ctx->Const.MaxLights = MAX_LIGHTS; |
| Ian Romanick | 882caa1 | 2003-05-30 21:37:14 +0000 | [diff] [blame] | 884 | ctx->Const.MaxShininess = 128.0; |
| Brian Paul | 53f82c5 | 2004-10-02 16:39:09 +0000 | [diff] [blame] | 885 | ctx->Const.MaxSpotExponent = 128.0; |
| 886 | ctx->Const.MaxViewportWidth = MAX_WIDTH; |
| 887 | ctx->Const.MaxViewportHeight = MAX_HEIGHT; |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 888 | #if FEATURE_ARB_vertex_program |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 889 | ctx->Const.VertexProgram.MaxInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS; |
| 890 | ctx->Const.VertexProgram.MaxAluInstructions = 0; |
| 891 | ctx->Const.VertexProgram.MaxTexInstructions = 0; |
| 892 | ctx->Const.VertexProgram.MaxTexIndirections = 0; |
| 893 | ctx->Const.VertexProgram.MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS; |
| Brian | 64e8088 | 2007-04-16 10:36:28 -0600 | [diff] [blame] | 894 | ctx->Const.VertexProgram.MaxTemps = MAX_PROGRAM_TEMPS; |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 895 | ctx->Const.VertexProgram.MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS; |
| 896 | ctx->Const.VertexProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS; |
| Brian | 64e8088 | 2007-04-16 10:36:28 -0600 | [diff] [blame] | 897 | ctx->Const.VertexProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS; |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 898 | ctx->Const.VertexProgram.MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS; |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 899 | ctx->Const.VertexProgram.MaxUniformComponents = 4 * MAX_UNIFORMS; |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 900 | init_natives(&ctx->Const.VertexProgram); |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 901 | #endif |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 902 | |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 903 | #if FEATURE_ARB_fragment_program |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 904 | ctx->Const.FragmentProgram.MaxInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS; |
| 905 | ctx->Const.FragmentProgram.MaxAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS; |
| 906 | ctx->Const.FragmentProgram.MaxTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS; |
| 907 | ctx->Const.FragmentProgram.MaxTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS; |
| 908 | ctx->Const.FragmentProgram.MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS; |
| Brian | 64e8088 | 2007-04-16 10:36:28 -0600 | [diff] [blame] | 909 | ctx->Const.FragmentProgram.MaxTemps = MAX_PROGRAM_TEMPS; |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 910 | ctx->Const.FragmentProgram.MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS; |
| 911 | ctx->Const.FragmentProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS; |
| Brian | 64e8088 | 2007-04-16 10:36:28 -0600 | [diff] [blame] | 912 | ctx->Const.FragmentProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS; |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 913 | ctx->Const.FragmentProgram.MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS; |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 914 | ctx->Const.FragmentProgram.MaxUniformComponents = 4 * MAX_UNIFORMS; |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 915 | init_natives(&ctx->Const.FragmentProgram); |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 916 | #endif |
| Brian Paul | edd6774 | 2003-04-18 18:02:43 +0000 | [diff] [blame] | 917 | ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES; |
| 918 | ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH; |
| Brian Paul | d0492cf | 2003-04-11 01:20:06 +0000 | [diff] [blame] | 919 | |
| George Sapountzis | 507167d | 2006-12-06 06:54:13 +0200 | [diff] [blame] | 920 | /* CheckArrayBounds is overriden by drivers/x11 for X server */ |
| Brian Paul | a2b9bad | 2003-11-10 19:08:37 +0000 | [diff] [blame] | 921 | ctx->Const.CheckArrayBounds = GL_FALSE; |
| Brian Paul | a2b9bad | 2003-11-10 19:08:37 +0000 | [diff] [blame] | 922 | |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 923 | /* GL_ARB_draw_buffers */ |
| Brian Paul | 53f82c5 | 2004-10-02 16:39:09 +0000 | [diff] [blame] | 924 | ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS; |
| 925 | |
| Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 926 | /* GL_OES_read_format */ |
| Ian Romanick | 33899b7 | 2004-10-16 01:16:54 +0000 | [diff] [blame] | 927 | ctx->Const.ColorReadFormat = GL_RGBA; |
| 928 | ctx->Const.ColorReadType = GL_UNSIGNED_BYTE; |
| 929 | |
| Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 930 | #if FEATURE_EXT_framebuffer_object |
| 931 | ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS; |
| 932 | ctx->Const.MaxRenderbufferSize = MAX_WIDTH; |
| 933 | #endif |
| 934 | |
| Brian Paul | 90fcf6c | 2006-11-01 00:12:41 +0000 | [diff] [blame] | 935 | #if FEATURE_ARB_vertex_shader |
| 936 | ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS; |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 937 | ctx->Const.MaxVarying = MAX_VARYING; |
| Brian Paul | 90fcf6c | 2006-11-01 00:12:41 +0000 | [diff] [blame] | 938 | #endif |
| 939 | |
| Brian Paul | 53f82c5 | 2004-10-02 16:39:09 +0000 | [diff] [blame] | 940 | /* sanity checks */ |
| Brian Paul | da238ee | 2006-04-13 19:21:58 +0000 | [diff] [blame] | 941 | ASSERT(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits, |
| 942 | ctx->Const.MaxTextureCoordUnits)); |
| Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 943 | ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS); |
| 944 | ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS); |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 945 | |
| 946 | ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS); |
| 947 | ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS); |
| 948 | ASSERT(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX); |
| 949 | ASSERT(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 950 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 951 | |
| Brian Paul | 4d859f7 | 2004-01-23 18:57:05 +0000 | [diff] [blame] | 952 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 953 | /** |
| Brian Paul | 5e2e96b | 2006-05-15 15:26:04 +0000 | [diff] [blame] | 954 | * Do some sanity checks on the limits/constants for the given context. |
| 955 | * Only called the first time a context is bound. |
| 956 | */ |
| 957 | static void |
| 958 | check_context_limits(GLcontext *ctx) |
| 959 | { |
| 960 | /* Many context limits/constants are limited by the size of |
| 961 | * internal arrays. |
| 962 | */ |
| 963 | assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS); |
| 964 | assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS); |
| 965 | assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS); |
| 966 | assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS); |
| 967 | |
| 968 | assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH); |
| 969 | assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH); |
| 970 | |
| 971 | /* make sure largest texture image is <= MAX_WIDTH in size */ |
| 972 | assert((1 << (ctx->Const.MaxTextureLevels -1 )) <= MAX_WIDTH); |
| 973 | assert((1 << (ctx->Const.MaxCubeTextureLevels -1 )) <= MAX_WIDTH); |
| 974 | assert((1 << (ctx->Const.Max3DTextureLevels -1 )) <= MAX_WIDTH); |
| 975 | |
| 976 | assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS); |
| 977 | |
| 978 | /* XXX probably add more tests */ |
| 979 | } |
| 980 | |
| 981 | |
| 982 | /** |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 983 | * Initialize the attribute groups in a GL context. |
| 984 | * |
| 985 | * \param ctx GL context. |
| 986 | * |
| 987 | * Initializes all the attributes, calling the respective <tt>init*</tt> |
| 988 | * functions for the more complex data structures. |
| 989 | */ |
| 990 | static GLboolean |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 991 | init_attrib_groups(GLcontext *ctx) |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 992 | { |
| 993 | assert(ctx); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 994 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 995 | /* Constants */ |
| 996 | _mesa_init_constants( ctx ); |
| Brian Paul | 0771d15 | 2000-04-07 00:19:41 +0000 | [diff] [blame] | 997 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 998 | /* Extensions */ |
| Brian Paul | de4f460 | 2003-07-03 02:15:06 +0000 | [diff] [blame] | 999 | _mesa_init_extensions( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1000 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1001 | /* Attribute Groups */ |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1002 | #if FEATURE_accum |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1003 | _mesa_init_accum( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1004 | #endif |
| 1005 | #if FEATURE_attrib_stack |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1006 | _mesa_init_attrib( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1007 | #endif |
| Brian Paul | 148a284 | 2003-09-17 03:40:11 +0000 | [diff] [blame] | 1008 | _mesa_init_buffer_objects( ctx ); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1009 | _mesa_init_color( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1010 | #if FEATURE_colortable |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 1011 | _mesa_init_colortables( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1012 | #endif |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1013 | _mesa_init_current( ctx ); |
| 1014 | _mesa_init_depth( ctx ); |
| 1015 | _mesa_init_debug( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1016 | #if FEATURE_dlist |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1017 | _mesa_init_display_list( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1018 | #endif |
| 1019 | #if FEATURE_evaluators |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1020 | _mesa_init_eval( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1021 | #endif |
| Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 1022 | _mesa_init_fbobjects( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1023 | #if FEATURE_feedback |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1024 | _mesa_init_feedback( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1025 | #endif |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1026 | _mesa_init_fog( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1027 | #if FEATURE_histogram |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1028 | _mesa_init_histogram( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1029 | #endif |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1030 | _mesa_init_hint( ctx ); |
| 1031 | _mesa_init_line( ctx ); |
| 1032 | _mesa_init_lighting( ctx ); |
| 1033 | _mesa_init_matrix( ctx ); |
| Brian Paul | 6774238 | 2005-02-26 17:16:12 +0000 | [diff] [blame] | 1034 | _mesa_init_multisample( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1035 | #if FEATURE_pixel_transfer |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1036 | _mesa_init_pixel( ctx ); |
| Brian Paul | 715715e | 2008-06-18 09:30:13 -0600 | [diff] [blame] | 1037 | #else |
| 1038 | ctx->Pixel.ReadBuffer = ctx->Visual.doubleBufferMode ? GL_BACK : GL_FRONT; |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1039 | #endif |
| Brian Paul | 533c1db | 2008-06-09 14:25:23 -0600 | [diff] [blame] | 1040 | _mesa_init_pixelstore( ctx ); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1041 | _mesa_init_point( ctx ); |
| 1042 | _mesa_init_polygon( ctx ); |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 1043 | _mesa_init_program( ctx ); |
| Brian Paul | 4e3ae76 | 2008-06-13 13:56:53 -0600 | [diff] [blame] | 1044 | #if FEATURE_ARB_occlusion_query |
| Brian Paul | 4fb9950 | 2005-09-02 13:42:49 +0000 | [diff] [blame] | 1045 | _mesa_init_query( ctx ); |
| Brian Paul | 4e3ae76 | 2008-06-13 13:56:53 -0600 | [diff] [blame] | 1046 | #endif |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1047 | #if FEATURE_drawpix |
| Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1048 | _mesa_init_rastpos( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1049 | #endif |
| Brian Paul | 6774238 | 2005-02-26 17:16:12 +0000 | [diff] [blame] | 1050 | _mesa_init_scissor( ctx ); |
| Brian | 0bf5dbe | 2006-12-19 18:02:41 -0700 | [diff] [blame] | 1051 | _mesa_init_shader_state( ctx ); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1052 | _mesa_init_stencil( ctx ); |
| 1053 | _mesa_init_transform( ctx ); |
| 1054 | _mesa_init_varray( ctx ); |
| 1055 | _mesa_init_viewport( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1056 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1057 | if (!_mesa_init_texture( ctx )) |
| 1058 | return GL_FALSE; |
| Brian Paul | b17a722 | 2003-06-13 02:37:27 +0000 | [diff] [blame] | 1059 | |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1060 | #if FEATURE_texture_s3tc |
| Brian Paul | 8f04c12 | 2004-04-27 13:39:20 +0000 | [diff] [blame] | 1061 | _mesa_init_texture_s3tc( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1062 | #endif |
| 1063 | #if FEATURE_texture_fxt1 |
| Brian Paul | 8f04c12 | 2004-04-27 13:39:20 +0000 | [diff] [blame] | 1064 | _mesa_init_texture_fxt1( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1065 | #endif |
| Brian Paul | 8f04c12 | 2004-04-27 13:39:20 +0000 | [diff] [blame] | 1066 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1067 | /* Miscellaneous */ |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1068 | ctx->NewState = _NEW_ALL; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1069 | ctx->ErrorValue = (GLenum) GL_NO_ERROR; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1070 | |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 1071 | return GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | |
| Brian Paul | f44898c | 2003-07-18 15:44:57 +0000 | [diff] [blame] | 1075 | /** |
| Brian | 4b654d4 | 2007-08-23 08:53:43 +0100 | [diff] [blame] | 1076 | * Update default objects in a GL context with respect to shared state. |
| 1077 | * |
| 1078 | * \param ctx GL context. |
| 1079 | * |
| 1080 | * Removes references to old default objects, (texture objects, program |
| 1081 | * objects, etc.) and changes to reference those from the current shared |
| 1082 | * state. |
| 1083 | */ |
| 1084 | static GLboolean |
| 1085 | update_default_objects(GLcontext *ctx) |
| 1086 | { |
| 1087 | assert(ctx); |
| 1088 | |
| 1089 | _mesa_update_default_objects_program(ctx); |
| 1090 | _mesa_update_default_objects_texture(ctx); |
| 1091 | _mesa_update_default_objects_buffer_objects(ctx); |
| 1092 | |
| 1093 | return GL_TRUE; |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | /** |
| Brian Paul | 21f6978 | 2004-11-27 05:05:32 +0000 | [diff] [blame] | 1098 | * This is the default function we plug into all dispatch table slots |
| 1099 | * This helps prevents a segfault when someone calls a GL function without |
| 1100 | * first checking if the extension's supported. |
| 1101 | */ |
| 1102 | static int |
| 1103 | generic_nop(void) |
| 1104 | { |
| Brian | cf239ce | 2007-06-11 10:57:01 -0600 | [diff] [blame] | 1105 | _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)"); |
| Brian Paul | 21f6978 | 2004-11-27 05:05:32 +0000 | [diff] [blame] | 1106 | return 0; |
| 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | /** |
| 1111 | * Allocate and initialize a new dispatch table. |
| 1112 | */ |
| 1113 | static struct _glapi_table * |
| 1114 | alloc_dispatch_table(void) |
| 1115 | { |
| 1116 | /* Find the larger of Mesa's dispatch table and libGL's dispatch table. |
| 1117 | * In practice, this'll be the same for stand-alone Mesa. But for DRI |
| 1118 | * Mesa we do this to accomodate different versions of libGL and various |
| 1119 | * DRI drivers. |
| 1120 | */ |
| 1121 | GLint numEntries = MAX2(_glapi_get_dispatch_table_size(), |
| 1122 | sizeof(struct _glapi_table) / sizeof(_glapi_proc)); |
| 1123 | struct _glapi_table *table = |
| 1124 | (struct _glapi_table *) _mesa_malloc(numEntries * sizeof(_glapi_proc)); |
| 1125 | if (table) { |
| 1126 | _glapi_proc *entry = (_glapi_proc *) table; |
| Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 1127 | GLint i; |
| Brian Paul | 21f6978 | 2004-11-27 05:05:32 +0000 | [diff] [blame] | 1128 | for (i = 0; i < numEntries; i++) { |
| 1129 | entry[i] = (_glapi_proc) generic_nop; |
| 1130 | } |
| 1131 | } |
| 1132 | return table; |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | /** |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1137 | * Initialize a GLcontext struct (rendering context). |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1138 | * |
| 1139 | * This includes allocating all the other structs and arrays which hang off of |
| 1140 | * the context by pointers. |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1141 | * Note that the driver needs to pass in its dd_function_table here since |
| 1142 | * we need to at least call driverFunctions->NewTextureObject to create the |
| 1143 | * default texture objects. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1144 | * |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1145 | * Called by _mesa_create_context(). |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1146 | * |
| 1147 | * Performs the imports and exports callback tables initialization, and |
| 1148 | * miscellaneous one-time initializations. If no shared context is supplied one |
| 1149 | * is allocated, and increase its reference count. Setups the GL API dispatch |
| 1150 | * tables. Initialize the TNL module. Sets the maximum Z buffer depth. |
| 1151 | * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables |
| 1152 | * for debug flags. |
| 1153 | * |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1154 | * \param ctx the context to initialize |
| 1155 | * \param visual describes the visual attributes for this context |
| 1156 | * \param share_list points to context to share textures, display lists, |
| 1157 | * etc with, or NULL |
| 1158 | * \param driverFunctions table of device driver functions for this context |
| 1159 | * to use |
| 1160 | * \param driverContext pointer to driver-specific context data |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1161 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1162 | GLboolean |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1163 | _mesa_initialize_context(GLcontext *ctx, |
| 1164 | const GLvisual *visual, |
| 1165 | GLcontext *share_list, |
| 1166 | const struct dd_function_table *driverFunctions, |
| 1167 | void *driverContext) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1168 | { |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1169 | ASSERT(driverContext); |
| 1170 | assert(driverFunctions->NewTextureObject); |
| Keith Whitwell | 3e62d3a | 2005-03-22 14:27:10 +0000 | [diff] [blame] | 1171 | assert(driverFunctions->FreeTexImageData); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1172 | |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1173 | /* misc one-time initializations */ |
| 1174 | one_time_init(ctx); |
| Brian Paul | 9a33a11 | 2002-06-13 04:28:29 +0000 | [diff] [blame] | 1175 | |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1176 | ctx->Visual = *visual; |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1177 | ctx->DrawBuffer = NULL; |
| 1178 | ctx->ReadBuffer = NULL; |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1179 | ctx->WinSysDrawBuffer = NULL; |
| 1180 | ctx->WinSysReadBuffer = NULL; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1181 | |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1182 | /* Plug in driver functions and context pointer here. |
| 1183 | * This is important because when we call alloc_shared_state() below |
| 1184 | * we'll call ctx->Driver.NewTextureObject() to create the default |
| 1185 | * textures. |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 1186 | */ |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1187 | ctx->Driver = *driverFunctions; |
| 1188 | ctx->DriverCtx = driverContext; |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 1189 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1190 | if (share_list) { |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 1191 | /* share state with another context */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1192 | ctx->Shared = share_list->Shared; |
| 1193 | } |
| 1194 | else { |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 1195 | /* allocate new, unshared state */ |
| Brian Paul | a3f1370 | 2003-04-01 16:41:50 +0000 | [diff] [blame] | 1196 | if (!alloc_shared_state( ctx )) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1197 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1198 | } |
| 1199 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1200 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1201 | ctx->Shared->RefCount++; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1202 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1203 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1204 | if (!init_attrib_groups( ctx )) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1205 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1206 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1207 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1208 | |
| Brian Paul | 21f6978 | 2004-11-27 05:05:32 +0000 | [diff] [blame] | 1209 | /* setup the API dispatch tables */ |
| 1210 | ctx->Exec = alloc_dispatch_table(); |
| 1211 | ctx->Save = alloc_dispatch_table(); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1212 | if (!ctx->Exec || !ctx->Save) { |
| 1213 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1214 | if (ctx->Exec) |
| Brian Paul | 21f6978 | 2004-11-27 05:05:32 +0000 | [diff] [blame] | 1215 | _mesa_free(ctx->Exec); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1216 | } |
| Brian Paul | cd4d4f5 | 2008-06-17 16:56:32 -0600 | [diff] [blame] | 1217 | #if FEATURE_dispatch |
| Brian Paul | 21f6978 | 2004-11-27 05:05:32 +0000 | [diff] [blame] | 1218 | _mesa_init_exec_table(ctx->Exec); |
| Brian Paul | cd4d4f5 | 2008-06-17 16:56:32 -0600 | [diff] [blame] | 1219 | #endif |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1220 | ctx->CurrentDispatch = ctx->Exec; |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1221 | #if FEATURE_dlist |
| Brian Paul | 21f6978 | 2004-11-27 05:05:32 +0000 | [diff] [blame] | 1222 | _mesa_init_dlist_table(ctx->Save); |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 1223 | _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1224 | #endif |
| Gareth Hughes | d8aa026 | 2001-03-11 18:49:11 +0000 | [diff] [blame] | 1225 | /* Neutral tnl module stuff */ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1226 | _mesa_init_exec_vtxfmt( ctx ); |
| Gareth Hughes | d8aa026 | 2001-03-11 18:49:11 +0000 | [diff] [blame] | 1227 | ctx->TnlModule.Current = NULL; |
| 1228 | ctx->TnlModule.SwapCount = 0; |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 1229 | |
| Brian | 3e45db6 | 2007-03-27 09:51:52 -0600 | [diff] [blame] | 1230 | ctx->FragmentProgram._MaintainTexEnvProgram |
| 1231 | = (_mesa_getenv("MESA_TEX_PROG") != NULL); |
| 1232 | ctx->FragmentProgram._UseTexEnvProgram = ctx->FragmentProgram._MaintainTexEnvProgram; |
| 1233 | |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 1234 | ctx->VertexProgram._MaintainTnlProgram |
| 1235 | = (_mesa_getenv("MESA_TNL_PROG") != NULL); |
| Brian | 3e45db6 | 2007-03-27 09:51:52 -0600 | [diff] [blame] | 1236 | if (ctx->VertexProgram._MaintainTnlProgram) { |
| Brian | a90046f | 2006-12-15 10:07:26 -0700 | [diff] [blame] | 1237 | /* this is required... */ |
| 1238 | ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; |
| Brian | 3e45db6 | 2007-03-27 09:51:52 -0600 | [diff] [blame] | 1239 | } |
| Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 1240 | |
| Brian Paul | a96f889 | 2005-09-13 01:19:29 +0000 | [diff] [blame] | 1241 | ctx->FirstTimeCurrent = GL_TRUE; |
| 1242 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1243 | return GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1246 | |
| Brian Paul | de4f460 | 2003-07-03 02:15:06 +0000 | [diff] [blame] | 1247 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1248 | * Allocate and initialize a GLcontext structure. |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1249 | * Note that the driver needs to pass in its dd_function_table here since |
| 1250 | * we need to at least call driverFunctions->NewTextureObject to initialize |
| 1251 | * the rendering context. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1252 | * |
| 1253 | * \param visual a GLvisual pointer (we copy the struct contents) |
| 1254 | * \param share_list another context to share display lists with or NULL |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1255 | * \param driverFunctions points to the dd_function_table into which the |
| 1256 | * driver has plugged in all its special functions. |
| 1257 | * \param driverCtx points to the device driver's private context state |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1258 | * |
| 1259 | * \return pointer to a new __GLcontextRec or NULL if error. |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1260 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1261 | GLcontext * |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1262 | _mesa_create_context(const GLvisual *visual, |
| 1263 | GLcontext *share_list, |
| 1264 | const struct dd_function_table *driverFunctions, |
| 1265 | void *driverContext) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1266 | { |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1267 | GLcontext *ctx; |
| 1268 | |
| 1269 | ASSERT(visual); |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1270 | ASSERT(driverContext); |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1271 | |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1272 | ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext)); |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1273 | if (!ctx) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1274 | return NULL; |
| Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 1275 | |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1276 | if (_mesa_initialize_context(ctx, visual, share_list, |
| 1277 | driverFunctions, driverContext)) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1278 | return ctx; |
| 1279 | } |
| 1280 | else { |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1281 | _mesa_free(ctx); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1282 | return NULL; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1286 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1287 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1288 | * Free the data associated with the given context. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1289 | * |
| 1290 | * But doesn't free the GLcontext struct itself. |
| 1291 | * |
| 1292 | * \sa _mesa_initialize_context() and init_attrib_groups(). |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1293 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1294 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1295 | _mesa_free_context_data( GLcontext *ctx ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1296 | { |
| Brian | dc73217 | 2007-08-14 11:56:59 +0100 | [diff] [blame] | 1297 | if (!_mesa_get_current_context()){ |
| 1298 | /* No current context, but we may need one in order to delete |
| 1299 | * texture objs, etc. So temporarily bind the context now. |
| 1300 | */ |
| 1301 | _mesa_make_current(ctx, NULL, NULL); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1302 | } |
| Brian | dc73217 | 2007-08-14 11:56:59 +0100 | [diff] [blame] | 1303 | |
| 1304 | /* unreference WinSysDraw/Read buffers */ |
| 1305 | _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer); |
| 1306 | _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer); |
| 1307 | _mesa_unreference_framebuffer(&ctx->DrawBuffer); |
| 1308 | _mesa_unreference_framebuffer(&ctx->ReadBuffer); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1309 | |
| Brian | df43fb6 | 2008-05-06 23:08:51 -0600 | [diff] [blame] | 1310 | _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL); |
| 1311 | _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL); |
| 1312 | _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL); |
| 1313 | |
| 1314 | _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL); |
| 1315 | _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL); |
| 1316 | _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL); |
| 1317 | |
| Brian | 145d762 | 2007-08-16 10:05:00 +0100 | [diff] [blame] | 1318 | _mesa_free_attrib_data(ctx); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1319 | _mesa_free_lighting_data( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1320 | #if FEATURE_evaluators |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1321 | _mesa_free_eval_data( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1322 | #endif |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1323 | _mesa_free_texture_data( ctx ); |
| 1324 | _mesa_free_matrix_data( ctx ); |
| 1325 | _mesa_free_viewport_data( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1326 | #if FEATURE_colortable |
| Brian Paul | 05944c0 | 2003-07-22 03:51:46 +0000 | [diff] [blame] | 1327 | _mesa_free_colortables_data( ctx ); |
| Keith Whitwell | 34a61c6 | 2008-09-21 19:29:15 -0700 | [diff] [blame] | 1328 | #endif |
| Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 1329 | _mesa_free_program_data(ctx); |
| Brian | 935f93f | 2007-03-24 16:20:02 -0600 | [diff] [blame] | 1330 | _mesa_free_shader_state(ctx); |
| Brian Paul | 4e3ae76 | 2008-06-13 13:56:53 -0600 | [diff] [blame] | 1331 | #if FEATURE_ARB_occlusion_query |
| Brian Paul | 4fb9950 | 2005-09-02 13:42:49 +0000 | [diff] [blame] | 1332 | _mesa_free_query_data(ctx); |
| Brian Paul | 4e3ae76 | 2008-06-13 13:56:53 -0600 | [diff] [blame] | 1333 | #endif |
| Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 1334 | |
| 1335 | #if FEATURE_ARB_vertex_buffer_object |
| 1336 | _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj); |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 1337 | #endif |
| Brian Paul | c04bb51 | 2006-07-11 21:56:43 +0000 | [diff] [blame] | 1338 | _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj); |
| Brian Paul | fd28445 | 2001-07-19 15:54:34 +0000 | [diff] [blame] | 1339 | |
| Brian Paul | 65a66f5 | 2004-11-27 22:47:59 +0000 | [diff] [blame] | 1340 | /* free dispatch tables */ |
| 1341 | _mesa_free(ctx->Exec); |
| 1342 | _mesa_free(ctx->Save); |
| 1343 | |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 1344 | /* Shared context state (display lists, textures, etc) */ |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1345 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1346 | ctx->Shared->RefCount--; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1347 | assert(ctx->Shared->RefCount >= 0); |
| 1348 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
| 1349 | if (ctx->Shared->RefCount == 0) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1350 | /* free shared state */ |
| 1351 | free_shared_state( ctx, ctx->Shared ); |
| 1352 | } |
| 1353 | |
| Brian Paul | 702ca20 | 2003-07-18 15:22:16 +0000 | [diff] [blame] | 1354 | if (ctx->Extensions.String) |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 1355 | _mesa_free((void *) ctx->Extensions.String); |
| Brian | dc73217 | 2007-08-14 11:56:59 +0100 | [diff] [blame] | 1356 | |
| 1357 | /* unbind the context if it's currently bound */ |
| 1358 | if (ctx == _mesa_get_current_context()) { |
| 1359 | _mesa_make_current(NULL, NULL, NULL); |
| 1360 | } |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1363 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1364 | /** |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1365 | * Destroy a GLcontext structure. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1366 | * |
| 1367 | * \param ctx GL context. |
| 1368 | * |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1369 | * Calls _mesa_free_context_data() and frees the GLcontext structure itself. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1370 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1371 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1372 | _mesa_destroy_context( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1373 | { |
| 1374 | if (ctx) { |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1375 | _mesa_free_context_data(ctx); |
| Brian Paul | c7e164f | 2006-06-30 15:44:30 +0000 | [diff] [blame] | 1376 | _mesa_free( (void *) ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | |
| Brian Paul | d3fd7ba | 2004-01-20 02:49:27 +0000 | [diff] [blame] | 1380 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1381 | #if _HAVE_FULL_GL |
| 1382 | /** |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1383 | * Copy attribute groups from one context to another. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1384 | * |
| 1385 | * \param src source context |
| 1386 | * \param dst destination context |
| 1387 | * \param mask bitwise OR of GL_*_BIT flags |
| 1388 | * |
| 1389 | * According to the bits specified in \p mask, copies the corresponding |
| Jose Fonseca | 375457b | 2004-09-09 22:23:24 +0000 | [diff] [blame] | 1390 | * 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] | 1391 | * memcpy is not enough due to the existence of internal pointers in their data |
| 1392 | * structures. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1393 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1394 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1395 | _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1396 | { |
| 1397 | if (mask & GL_ACCUM_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1398 | /* OK to memcpy */ |
| 1399 | dst->Accum = src->Accum; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1400 | } |
| 1401 | if (mask & GL_COLOR_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1402 | /* OK to memcpy */ |
| 1403 | dst->Color = src->Color; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1404 | } |
| 1405 | if (mask & GL_CURRENT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1406 | /* OK to memcpy */ |
| 1407 | dst->Current = src->Current; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1408 | } |
| 1409 | if (mask & GL_DEPTH_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1410 | /* OK to memcpy */ |
| 1411 | dst->Depth = src->Depth; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1412 | } |
| 1413 | if (mask & GL_ENABLE_BIT) { |
| 1414 | /* no op */ |
| 1415 | } |
| 1416 | if (mask & GL_EVAL_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1417 | /* OK to memcpy */ |
| 1418 | dst->Eval = src->Eval; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1419 | } |
| 1420 | if (mask & GL_FOG_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1421 | /* OK to memcpy */ |
| 1422 | dst->Fog = src->Fog; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1423 | } |
| 1424 | if (mask & GL_HINT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1425 | /* OK to memcpy */ |
| 1426 | dst->Hint = src->Hint; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1427 | } |
| 1428 | if (mask & GL_LIGHTING_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1429 | GLuint i; |
| 1430 | /* begin with memcpy */ |
| Brian Paul | 2aabdc7 | 2006-02-24 18:19:11 +0000 | [diff] [blame] | 1431 | dst->Light = src->Light; |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1432 | /* fixup linked lists to prevent pointer insanity */ |
| 1433 | make_empty_list( &(dst->Light.EnabledList) ); |
| 1434 | for (i = 0; i < MAX_LIGHTS; i++) { |
| 1435 | if (dst->Light.Light[i].Enabled) { |
| 1436 | insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i])); |
| 1437 | } |
| 1438 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1439 | } |
| 1440 | if (mask & GL_LINE_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1441 | /* OK to memcpy */ |
| 1442 | dst->Line = src->Line; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1443 | } |
| 1444 | if (mask & GL_LIST_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1445 | /* OK to memcpy */ |
| 1446 | dst->List = src->List; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1447 | } |
| 1448 | if (mask & GL_PIXEL_MODE_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1449 | /* OK to memcpy */ |
| 1450 | dst->Pixel = src->Pixel; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1451 | } |
| 1452 | if (mask & GL_POINT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1453 | /* OK to memcpy */ |
| 1454 | dst->Point = src->Point; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1455 | } |
| 1456 | if (mask & GL_POLYGON_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1457 | /* OK to memcpy */ |
| 1458 | dst->Polygon = src->Polygon; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1459 | } |
| 1460 | if (mask & GL_POLYGON_STIPPLE_BIT) { |
| 1461 | /* Use loop instead of MEMCPY due to problem with Portland Group's |
| 1462 | * C compiler. Reported by John Stone. |
| 1463 | */ |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1464 | GLuint i; |
| 1465 | for (i = 0; i < 32; i++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1466 | dst->PolygonStipple[i] = src->PolygonStipple[i]; |
| 1467 | } |
| 1468 | } |
| 1469 | if (mask & GL_SCISSOR_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1470 | /* OK to memcpy */ |
| 1471 | dst->Scissor = src->Scissor; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1472 | } |
| 1473 | if (mask & GL_STENCIL_BUFFER_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1474 | /* OK to memcpy */ |
| 1475 | dst->Stencil = src->Stencil; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1476 | } |
| 1477 | if (mask & GL_TEXTURE_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1478 | /* Cannot memcpy because of pointers */ |
| 1479 | _mesa_copy_texture_state(src, dst); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1480 | } |
| 1481 | if (mask & GL_TRANSFORM_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1482 | /* OK to memcpy */ |
| 1483 | dst->Transform = src->Transform; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1484 | } |
| 1485 | if (mask & GL_VIEWPORT_BIT) { |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1486 | /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */ |
| 1487 | dst->Viewport.X = src->Viewport.X; |
| 1488 | dst->Viewport.Y = src->Viewport.Y; |
| 1489 | dst->Viewport.Width = src->Viewport.Width; |
| 1490 | dst->Viewport.Height = src->Viewport.Height; |
| 1491 | dst->Viewport.Near = src->Viewport.Near; |
| 1492 | dst->Viewport.Far = src->Viewport.Far; |
| 1493 | _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1494 | } |
| Brian Paul | 85d8160 | 2002-06-17 23:36:31 +0000 | [diff] [blame] | 1495 | |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1496 | /* XXX FIXME: Call callbacks? |
| 1497 | */ |
| 1498 | dst->NewState = _NEW_ALL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1499 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1500 | #endif |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1501 | |
| 1502 | |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1503 | /** |
| 1504 | * Check if the given context can render into the given framebuffer |
| 1505 | * by checking visual attributes. |
| Brian Paul | ca007cb | 2006-03-07 03:01:26 +0000 | [diff] [blame] | 1506 | * |
| Brian | ee170f2 | 2007-06-08 14:12:27 -0600 | [diff] [blame] | 1507 | * Most of these tests could go away because Mesa is now pretty flexible |
| 1508 | * in terms of mixing rendering contexts with framebuffers. As long |
| 1509 | * as RGB vs. CI mode agree, we're probably good. |
| Brian Paul | ca007cb | 2006-03-07 03:01:26 +0000 | [diff] [blame] | 1510 | * |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1511 | * \return GL_TRUE if compatible, GL_FALSE otherwise. |
| 1512 | */ |
| 1513 | static GLboolean |
| 1514 | check_compatible(const GLcontext *ctx, const GLframebuffer *buffer) |
| 1515 | { |
| 1516 | const GLvisual *ctxvis = &ctx->Visual; |
| 1517 | const GLvisual *bufvis = &buffer->Visual; |
| 1518 | |
| 1519 | if (ctxvis == bufvis) |
| 1520 | return GL_TRUE; |
| 1521 | |
| 1522 | if (ctxvis->rgbMode != bufvis->rgbMode) |
| 1523 | return GL_FALSE; |
| Brian Paul | d75963d | 2006-03-07 02:57:04 +0000 | [diff] [blame] | 1524 | #if 0 |
| 1525 | /* disabling this fixes the fgl_glxgears pbuffer demo */ |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1526 | if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode) |
| 1527 | return GL_FALSE; |
| Brian Paul | d75963d | 2006-03-07 02:57:04 +0000 | [diff] [blame] | 1528 | #endif |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1529 | if (ctxvis->stereoMode && !bufvis->stereoMode) |
| 1530 | return GL_FALSE; |
| 1531 | if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer) |
| 1532 | return GL_FALSE; |
| 1533 | if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer) |
| 1534 | return GL_FALSE; |
| 1535 | if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer) |
| 1536 | return GL_FALSE; |
| 1537 | if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask) |
| 1538 | return GL_FALSE; |
| 1539 | if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask) |
| 1540 | return GL_FALSE; |
| 1541 | if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask) |
| 1542 | return GL_FALSE; |
| Brian | ee170f2 | 2007-06-08 14:12:27 -0600 | [diff] [blame] | 1543 | #if 0 |
| 1544 | /* disabled (see bug 11161) */ |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1545 | if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits) |
| 1546 | return GL_FALSE; |
| Brian | ee170f2 | 2007-06-08 14:12:27 -0600 | [diff] [blame] | 1547 | #endif |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1548 | if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits) |
| 1549 | return GL_FALSE; |
| 1550 | |
| 1551 | return GL_TRUE; |
| 1552 | } |
| 1553 | |
| 1554 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1555 | /** |
| Brian Paul | a702bbf | 2005-09-14 03:11:36 +0000 | [diff] [blame] | 1556 | * Do one-time initialization for the given framebuffer. Specifically, |
| 1557 | * ask the driver for the window's current size and update the framebuffer |
| 1558 | * object to match. |
| 1559 | * Really, the device driver should totally take care of this. |
| 1560 | */ |
| 1561 | static void |
| 1562 | initialize_framebuffer_size(GLcontext *ctx, GLframebuffer *fb) |
| 1563 | { |
| 1564 | GLuint width, height; |
| Brian Paul | 55e42e5 | 2006-10-17 17:43:47 +0000 | [diff] [blame] | 1565 | if (ctx->Driver.GetBufferSize) { |
| 1566 | ctx->Driver.GetBufferSize(fb, &width, &height); |
| 1567 | if (ctx->Driver.ResizeBuffers) |
| 1568 | ctx->Driver.ResizeBuffers(ctx, fb, width, height); |
| 1569 | fb->Initialized = GL_TRUE; |
| 1570 | } |
| Brian Paul | a702bbf | 2005-09-14 03:11:36 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | |
| 1574 | /** |
| 1575 | * Bind the given context to the given drawBuffer and readBuffer and |
| 1576 | * make it the current context for the calling thread. |
| 1577 | * We'll render into the drawBuffer and read pixels from the |
| 1578 | * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc). |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1579 | * |
| Brian Paul | a702bbf | 2005-09-14 03:11:36 +0000 | [diff] [blame] | 1580 | * We check that the context's and framebuffer's visuals are compatible |
| 1581 | * and return immediately if they're not. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1582 | * |
| Brian Paul | a702bbf | 2005-09-14 03:11:36 +0000 | [diff] [blame] | 1583 | * \param newCtx the new GL context. If NULL then there will be no current GL |
| 1584 | * context. |
| 1585 | * \param drawBuffer the drawing framebuffer |
| 1586 | * \param readBuffer the reading framebuffer |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1587 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1588 | void |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1589 | _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer, |
| 1590 | GLframebuffer *readBuffer ) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1591 | { |
| Keith Whitwell | 5c72837 | 2005-05-12 10:22:29 +0000 | [diff] [blame] | 1592 | if (MESA_VERBOSE & VERBOSE_API) |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1593 | _mesa_debug(newCtx, "_mesa_make_current()\n"); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1594 | |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1595 | /* Check that the context's and framebuffer's visuals are compatible. |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1596 | */ |
| Brian Paul | f1038f8 | 2006-03-20 15:20:57 +0000 | [diff] [blame] | 1597 | if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) { |
| Brian Paul | d75963d | 2006-03-07 02:57:04 +0000 | [diff] [blame] | 1598 | if (!check_compatible(newCtx, drawBuffer)) { |
| 1599 | _mesa_warning(newCtx, |
| 1600 | "MakeCurrent: incompatible visuals for context and drawbuffer"); |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1601 | return; |
| Brian Paul | d75963d | 2006-03-07 02:57:04 +0000 | [diff] [blame] | 1602 | } |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1603 | } |
| Brian Paul | f1038f8 | 2006-03-20 15:20:57 +0000 | [diff] [blame] | 1604 | if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) { |
| Brian Paul | d75963d | 2006-03-07 02:57:04 +0000 | [diff] [blame] | 1605 | if (!check_compatible(newCtx, readBuffer)) { |
| 1606 | _mesa_warning(newCtx, |
| 1607 | "MakeCurrent: incompatible visuals for context and readbuffer"); |
| Brian Paul | b1d53d9 | 2003-06-11 18:48:19 +0000 | [diff] [blame] | 1608 | return; |
| Brian Paul | d75963d | 2006-03-07 02:57:04 +0000 | [diff] [blame] | 1609 | } |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
| Brian Paul | c6c0f94 | 2006-03-16 18:05:25 +0000 | [diff] [blame] | 1612 | /* We used to call _glapi_check_multithread() here. Now do it in drivers */ |
| Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 1613 | _glapi_set_context((void *) newCtx); |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1614 | ASSERT(_mesa_get_current_context() == newCtx); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1615 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1616 | if (!newCtx) { |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1617 | _glapi_set_dispatch(NULL); /* none current */ |
| 1618 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1619 | else { |
| 1620 | _glapi_set_dispatch(newCtx->CurrentDispatch); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1621 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1622 | if (drawBuffer && readBuffer) { |
| 1623 | /* TODO: check if newCtx and buffer's visual match??? */ |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1624 | |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1625 | ASSERT(drawBuffer->Name == 0); |
| 1626 | ASSERT(readBuffer->Name == 0); |
| Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 1627 | _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer); |
| 1628 | _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer); |
| Brian Paul | f1038f8 | 2006-03-20 15:20:57 +0000 | [diff] [blame] | 1629 | |
| 1630 | /* |
| 1631 | * Only set the context's Draw/ReadBuffer fields if they're NULL |
| 1632 | * or not bound to a user-created FBO. |
| 1633 | */ |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1634 | if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) { |
| Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 1635 | _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer); |
| Brian Paul | f1038f8 | 2006-03-20 15:20:57 +0000 | [diff] [blame] | 1636 | } |
| 1637 | if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) { |
| Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 1638 | _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer); |
| Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1639 | } |
| Brian Paul | bb5c84f | 2005-07-01 01:22:25 +0000 | [diff] [blame] | 1640 | |
| Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 1641 | /* XXX only set this flag if we're really changing the draw/read |
| 1642 | * framebuffer bindings. |
| 1643 | */ |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1644 | newCtx->NewState |= _NEW_BUFFERS; |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1645 | |
| Brian Paul | 4d4add0 | 2006-10-15 19:26:43 +0000 | [diff] [blame] | 1646 | #if 1 |
| 1647 | /* We want to get rid of these lines: */ |
| 1648 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1649 | #if _HAVE_FULL_GL |
| Brian Paul | 65a66f5 | 2004-11-27 22:47:59 +0000 | [diff] [blame] | 1650 | if (!drawBuffer->Initialized) { |
| Brian Paul | a702bbf | 2005-09-14 03:11:36 +0000 | [diff] [blame] | 1651 | initialize_framebuffer_size(newCtx, drawBuffer); |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1652 | } |
| Brian Paul | 65a66f5 | 2004-11-27 22:47:59 +0000 | [diff] [blame] | 1653 | if (readBuffer != drawBuffer && !readBuffer->Initialized) { |
| Brian Paul | a702bbf | 2005-09-14 03:11:36 +0000 | [diff] [blame] | 1654 | initialize_framebuffer_size(newCtx, readBuffer); |
| Brian Paul | 10d7f54 | 2002-06-17 23:38:14 +0000 | [diff] [blame] | 1655 | } |
| Keith Whitwell | f9bfdb1 | 2006-09-22 11:36:30 +0000 | [diff] [blame] | 1656 | |
| 1657 | _mesa_resizebuffers(newCtx); |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1658 | #endif |
| Brian Paul | 4d4add0 | 2006-10-15 19:26:43 +0000 | [diff] [blame] | 1659 | |
| 1660 | #else |
| 1661 | /* We want the drawBuffer and readBuffer to be initialized by |
| 1662 | * the driver. |
| 1663 | * This generally means the Width and Height match the actual |
| 1664 | * window size and the renderbuffers (both hardware and software |
| 1665 | * based) are allocated to match. The later can generally be |
| 1666 | * done with a call to _mesa_resize_framebuffer(). |
| 1667 | * |
| 1668 | * It's theoretically possible for a buffer to have zero width |
| 1669 | * or height, but for now, assert check that the driver did what's |
| 1670 | * expected of it. |
| 1671 | */ |
| 1672 | ASSERT(drawBuffer->Width > 0); |
| 1673 | ASSERT(drawBuffer->Height > 0); |
| 1674 | #endif |
| 1675 | |
| Brian Paul | 65a66f5 | 2004-11-27 22:47:59 +0000 | [diff] [blame] | 1676 | if (newCtx->FirstTimeCurrent) { |
| 1677 | /* set initial viewport and scissor size now */ |
| Brian Paul | a702bbf | 2005-09-14 03:11:36 +0000 | [diff] [blame] | 1678 | _mesa_set_viewport(newCtx, 0, 0, |
| 1679 | drawBuffer->Width, drawBuffer->Height); |
| Brian Paul | db79d2a | 2006-03-29 18:41:19 +0000 | [diff] [blame] | 1680 | _mesa_set_scissor(newCtx, 0, 0, |
| 1681 | drawBuffer->Width, drawBuffer->Height ); |
| Brian Paul | 5e2e96b | 2006-05-15 15:26:04 +0000 | [diff] [blame] | 1682 | check_context_limits(newCtx); |
| Brian Paul | 65a66f5 | 2004-11-27 22:47:59 +0000 | [diff] [blame] | 1683 | } |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1684 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1685 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1686 | /* We can use this to help debug user's problems. Tell them to set |
| 1687 | * the MESA_INFO env variable before running their app. Then the |
| 1688 | * first time each context is made current we'll print some useful |
| 1689 | * information. |
| 1690 | */ |
| 1691 | if (newCtx->FirstTimeCurrent) { |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 1692 | if (_mesa_getenv("MESA_INFO")) { |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1693 | _mesa_print_info(); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1694 | } |
| 1695 | newCtx->FirstTimeCurrent = GL_FALSE; |
| 1696 | } |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | |
| Brian Paul | 635ee2d | 2005-04-15 17:25:07 +0000 | [diff] [blame] | 1700 | |
| 1701 | /** |
| 1702 | * Make context 'ctx' share the display lists, textures and programs |
| 1703 | * that are associated with 'ctxToShare'. |
| 1704 | * Any display lists, textures or programs associated with 'ctx' will |
| 1705 | * be deleted if nobody else is sharing them. |
| 1706 | */ |
| 1707 | GLboolean |
| 1708 | _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare) |
| 1709 | { |
| 1710 | if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) { |
| Brian | 4b654d4 | 2007-08-23 08:53:43 +0100 | [diff] [blame] | 1711 | struct gl_shared_state *oldSharedState = ctx->Shared; |
| 1712 | |
| Brian Paul | 635ee2d | 2005-04-15 17:25:07 +0000 | [diff] [blame] | 1713 | ctx->Shared = ctxToShare->Shared; |
| 1714 | ctx->Shared->RefCount++; |
| Brian | 4b654d4 | 2007-08-23 08:53:43 +0100 | [diff] [blame] | 1715 | |
| 1716 | update_default_objects(ctx); |
| 1717 | |
| 1718 | oldSharedState->RefCount--; |
| 1719 | if (oldSharedState->RefCount == 0) { |
| 1720 | free_shared_state(ctx, oldSharedState); |
| 1721 | } |
| 1722 | |
| Brian Paul | 635ee2d | 2005-04-15 17:25:07 +0000 | [diff] [blame] | 1723 | return GL_TRUE; |
| 1724 | } |
| 1725 | else { |
| 1726 | return GL_FALSE; |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | |
| 1731 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1732 | /** |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1733 | * \return pointer to the current GL context for this thread. |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1734 | * |
| 1735 | * Calls _glapi_get_context(). This isn't the fastest way to get the current |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1736 | * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in |
| 1737 | * context.h. |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1738 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1739 | GLcontext * |
| 1740 | _mesa_get_current_context( void ) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1741 | { |
| Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 1742 | return (GLcontext *) _glapi_get_context(); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1745 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1746 | /** |
| 1747 | * Get context's current API dispatch table. |
| 1748 | * |
| 1749 | * It'll either be the immediate-mode execute dispatcher or the display list |
| 1750 | * compile dispatcher. |
| 1751 | * |
| 1752 | * \param ctx GL context. |
| 1753 | * |
| 1754 | * \return pointer to dispatch_table. |
| 1755 | * |
| 1756 | * Simply returns __GLcontextRec::CurrentDispatch. |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1757 | */ |
| 1758 | struct _glapi_table * |
| 1759 | _mesa_get_dispatch(GLcontext *ctx) |
| 1760 | { |
| 1761 | return ctx->CurrentDispatch; |
| 1762 | } |
| 1763 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1764 | /*@}*/ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1765 | |
| 1766 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1767 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1768 | /** \name Miscellaneous functions */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1769 | /**********************************************************************/ |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1770 | /*@{*/ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1771 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1772 | /** |
| 1773 | * Record an error. |
| 1774 | * |
| 1775 | * \param ctx GL context. |
| 1776 | * \param error error code. |
| 1777 | * |
| 1778 | * Records the given error code and call the driver's dd_function_table::Error |
| 1779 | * function if defined. |
| 1780 | * |
| 1781 | * \sa |
| Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 1782 | * This is called via _mesa_error(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1783 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1784 | void |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1785 | _mesa_record_error(GLcontext *ctx, GLenum error) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1786 | { |
| Brian Paul | 18a285a | 2002-03-16 00:53:15 +0000 | [diff] [blame] | 1787 | if (!ctx) |
| 1788 | return; |
| 1789 | |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 1790 | if (ctx->ErrorValue == GL_NO_ERROR) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1791 | ctx->ErrorValue = error; |
| 1792 | } |
| 1793 | |
| 1794 | /* Call device driver's error handler, if any. This is used on the Mac. */ |
| 1795 | if (ctx->Driver.Error) { |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1796 | ctx->Driver.Error(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1800 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1801 | /** |
| 1802 | * Execute glFinish(). |
| 1803 | * |
| 1804 | * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the |
| 1805 | * dd_function_table::Finish driver callback, if not NULL. |
| 1806 | */ |
| Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1807 | void GLAPIENTRY |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1808 | _mesa_Finish(void) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1809 | { |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1810 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1811 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1812 | if (ctx->Driver.Finish) { |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1813 | ctx->Driver.Finish(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1814 | } |
| 1815 | } |
| 1816 | |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1817 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1818 | /** |
| 1819 | * Execute glFlush(). |
| 1820 | * |
| 1821 | * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the |
| 1822 | * dd_function_table::Flush driver callback, if not NULL. |
| 1823 | */ |
| Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 1824 | void GLAPIENTRY |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1825 | _mesa_Flush(void) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1826 | { |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1827 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1828 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1829 | if (ctx->Driver.Flush) { |
| Brian | d881a9c | 2006-12-20 09:31:07 -0700 | [diff] [blame] | 1830 | ctx->Driver.Flush(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1831 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1832 | } |
| Brian Paul | 48c6a6e | 2000-09-08 21:28:04 +0000 | [diff] [blame] | 1833 | |
| 1834 | |
| Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1835 | /*@}*/ |