| Jouk Jansen | 12e875c | 2001-10-18 08:04:57 +0000 | [diff] [blame^] | 1 | /* $Id: context.c,v 1.148 2001/10/18 08:04:57 joukj Exp $ */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 5 | * Version: 3.5 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 6 | * |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 28 | #ifdef PC_HEADER |
| 29 | #include "all.h" |
| 30 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 31 | #include "glheader.h" |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 32 | #include "buffers.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 33 | #include "clip.h" |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 34 | #include "colortab.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 35 | #include "context.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 36 | #include "dlist.h" |
| 37 | #include "eval.h" |
| 38 | #include "enums.h" |
| Brian Paul | 585a68c | 1999-09-11 11:31:34 +0000 | [diff] [blame] | 39 | #include "extensions.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 40 | #include "fog.h" |
| Brian Paul | b7a4304 | 1999-11-30 20:34:51 +0000 | [diff] [blame] | 41 | #include "get.h" |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 42 | #include "glthread.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 43 | #include "hash.h" |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 44 | #include "imports.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 45 | #include "light.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 46 | #include "macros.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 47 | #include "mem.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 48 | #include "mmath.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 49 | #include "simple_list.h" |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 50 | #include "state.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 51 | #include "teximage.h" |
| 52 | #include "texobj.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 53 | #include "mtypes.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 54 | #include "varray.h" |
| Gareth Hughes | d4eb665 | 2001-03-12 01:32:20 +0000 | [diff] [blame] | 55 | #include "vtxfmt.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 56 | |
| 57 | #include "math/m_translate.h" |
| 58 | #include "math/m_vertices.h" |
| 59 | #include "math/m_matrix.h" |
| 60 | #include "math/m_xform.h" |
| Keith Whitwell | f4b02d1 | 2001-01-05 05:31:42 +0000 | [diff] [blame] | 61 | #include "math/mathmod.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
| Brian Paul | 3b18a36 | 2000-09-26 15:27:20 +0000 | [diff] [blame] | 64 | #if defined(MESA_TRACE) |
| Brian Paul | 45f3634 | 2000-09-05 20:28:06 +0000 | [diff] [blame] | 65 | #include "Trace/tr_context.h" |
| 66 | #include "Trace/tr_wrapper.h" |
| 67 | #endif |
| 68 | |
| davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 69 | #ifdef USE_SPARC_ASM |
| 70 | #include "SPARC/sparc.h" |
| 71 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 72 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 73 | #ifndef MESA_VERBOSE |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 74 | int MESA_VERBOSE = 0 |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 75 | /* | VERBOSE_PIPELINE */ |
| 76 | /* | VERBOSE_IMMEDIATE */ |
| 77 | /* | VERBOSE_VARRAY */ |
| 78 | /* | VERBOSE_TEXTURE */ |
| 79 | /* | VERBOSE_API */ |
| 80 | /* | VERBOSE_DRIVER */ |
| 81 | /* | VERBOSE_STATE */ |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 82 | /* | VERBOSE_DISPLAY_LIST */ |
| 83 | ; |
| 84 | #endif |
| 85 | |
| 86 | #ifndef MESA_DEBUG_FLAGS |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 87 | int MESA_DEBUG_FLAGS = 0 |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 88 | /* | DEBUG_ALWAYS_FLUSH */ |
| 89 | ; |
| 90 | #endif |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 91 | |
| 92 | /**********************************************************************/ |
| 93 | /***** OpenGL SI-style interface (new in Mesa 3.5) *****/ |
| 94 | /**********************************************************************/ |
| 95 | |
| 96 | static GLboolean |
| 97 | _mesa_DestroyContext(__GLcontext *gc) |
| 98 | { |
| 99 | if (gc) { |
| 100 | _mesa_free_context_data(gc); |
| 101 | (*gc->imports.free)(gc, gc); |
| 102 | } |
| 103 | return GL_TRUE; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /* exported OpenGL SI interface */ |
| 108 | __GLcontext * |
| 109 | __glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes) |
| 110 | { |
| 111 | GLcontext *ctx; |
| 112 | |
| 113 | ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext)); |
| 114 | if (ctx == NULL) { |
| 115 | return NULL; |
| 116 | } |
| Jouk Jansen | 12e875c | 2001-10-18 08:04:57 +0000 | [diff] [blame^] | 117 | ctx->Driver.CurrentExecPrimitive=0; |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 118 | ctx->imports = *imports; |
| 119 | |
| 120 | _mesa_initialize_visual(&ctx->Visual, |
| 121 | modes->rgbMode, |
| 122 | modes->doubleBufferMode, |
| 123 | modes->stereoMode, |
| 124 | modes->redBits, |
| 125 | modes->greenBits, |
| 126 | modes->blueBits, |
| 127 | modes->alphaBits, |
| 128 | modes->indexBits, |
| 129 | modes->depthBits, |
| 130 | modes->stencilBits, |
| 131 | modes->accumRedBits, |
| 132 | modes->accumGreenBits, |
| 133 | modes->accumBlueBits, |
| 134 | modes->accumAlphaBits, |
| 135 | 0); |
| 136 | |
| Keith Whitwell | b980b2e | 2001-01-08 04:09:41 +0000 | [diff] [blame] | 137 | /* KW: was imports->wscx */ |
| 138 | _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE); |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 139 | |
| 140 | ctx->exports.destroyContext = _mesa_DestroyContext; |
| 141 | |
| 142 | return ctx; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | /* exported OpenGL SI interface */ |
| 147 | void |
| 148 | __glCoreNopDispatch(void) |
| 149 | { |
| 150 | #if 0 |
| 151 | /* SI */ |
| 152 | __gl_dispatch = __glNopDispatchState; |
| 153 | #else |
| 154 | /* Mesa */ |
| 155 | _glapi_set_dispatch(NULL); |
| 156 | #endif |
| 157 | } |
| 158 | |
| 159 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 160 | /**********************************************************************/ |
| 161 | /***** Context and Thread management *****/ |
| 162 | /**********************************************************************/ |
| 163 | |
| 164 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 165 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 166 | /**********************************************************************/ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 167 | /***** GL Visual allocation/destruction *****/ |
| 168 | /**********************************************************************/ |
| 169 | |
| 170 | |
| 171 | /* |
| 172 | * Allocate a new GLvisual object. |
| 173 | * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 174 | * dbFlag - double buffering? |
| 175 | * stereoFlag - stereo buffer? |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 176 | * depthBits - requested bits per depth buffer value |
| 177 | * Any value in [0, 32] is acceptable but the actual |
| 178 | * depth type will be GLushort or GLuint as needed. |
| 179 | * stencilBits - requested minimum bits per stencil buffer value |
| 180 | * accumBits - requested minimum bits per accum buffer component |
| 181 | * indexBits - number of bits per pixel if rgbFlag==GL_FALSE |
| 182 | * red/green/blue/alphaBits - number of bits per color component |
| 183 | * in frame buffer for RGB(A) mode. |
| 184 | * We always use 8 in core Mesa though. |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 185 | * Return: pointer to new GLvisual or NULL if requested parameters can't |
| 186 | * be met. |
| 187 | */ |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 188 | GLvisual * |
| 189 | _mesa_create_visual( GLboolean rgbFlag, |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 190 | GLboolean dbFlag, |
| 191 | GLboolean stereoFlag, |
| 192 | GLint redBits, |
| 193 | GLint greenBits, |
| 194 | GLint blueBits, |
| 195 | GLint alphaBits, |
| 196 | GLint indexBits, |
| 197 | GLint depthBits, |
| 198 | GLint stencilBits, |
| 199 | GLint accumRedBits, |
| 200 | GLint accumGreenBits, |
| 201 | GLint accumBlueBits, |
| 202 | GLint accumAlphaBits, |
| 203 | GLint numSamples ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 204 | { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 205 | GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) ); |
| 206 | if (vis) { |
| Brian Paul | e70c623 | 2000-05-04 13:53:55 +0000 | [diff] [blame] | 207 | if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 208 | redBits, greenBits, blueBits, alphaBits, |
| 209 | indexBits, depthBits, stencilBits, |
| 210 | accumRedBits, accumGreenBits, |
| 211 | accumBlueBits, accumAlphaBits, |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 212 | numSamples)) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 213 | FREE(vis); |
| 214 | return NULL; |
| 215 | } |
| 216 | } |
| 217 | return vis; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /* |
| 222 | * Initialize the fields of the given GLvisual. |
| 223 | * Input: see _mesa_create_visual() above. |
| 224 | * Return: GL_TRUE = success |
| 225 | * GL_FALSE = failure. |
| 226 | */ |
| 227 | GLboolean |
| 228 | _mesa_initialize_visual( GLvisual *vis, |
| 229 | GLboolean rgbFlag, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 230 | GLboolean dbFlag, |
| 231 | GLboolean stereoFlag, |
| 232 | GLint redBits, |
| 233 | GLint greenBits, |
| 234 | GLint blueBits, |
| 235 | GLint alphaBits, |
| 236 | GLint indexBits, |
| 237 | GLint depthBits, |
| 238 | GLint stencilBits, |
| 239 | GLint accumRedBits, |
| 240 | GLint accumGreenBits, |
| 241 | GLint accumBlueBits, |
| 242 | GLint accumAlphaBits, |
| 243 | GLint numSamples ) |
| 244 | { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 245 | (void) numSamples; |
| 246 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 247 | assert(vis); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 248 | |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 249 | /* This is to catch bad values from device drivers not updated for |
| 250 | * Mesa 3.3. Some device drivers just passed 1. That's a REALLY |
| 251 | * bad value now (a 1-bit depth buffer!?!). |
| 252 | */ |
| 253 | assert(depthBits == 0 || depthBits > 1); |
| 254 | |
| 255 | if (depthBits < 0 || depthBits > 32) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 256 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 257 | } |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 258 | if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 259 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 260 | } |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 261 | if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 262 | return GL_FALSE; |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 263 | } |
| 264 | if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 265 | return GL_FALSE; |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 266 | } |
| 267 | if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 268 | return GL_FALSE; |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 269 | } |
| 270 | if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 271 | return GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 274 | vis->rgbMode = rgbFlag; |
| 275 | vis->doubleBufferMode = dbFlag; |
| 276 | vis->stereoMode = stereoFlag; |
| 277 | vis->redBits = redBits; |
| 278 | vis->greenBits = greenBits; |
| 279 | vis->blueBits = blueBits; |
| 280 | vis->alphaBits = alphaBits; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 281 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 282 | vis->indexBits = indexBits; |
| 283 | vis->depthBits = depthBits; |
| 284 | vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 285 | vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 286 | vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 287 | vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0; |
| 288 | vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0; |
| Brian Paul | ed30dfa | 2000-03-03 17:47:39 +0000 | [diff] [blame] | 289 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 290 | return GL_TRUE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
| Brian Paul | b371e0d | 2000-03-31 01:05:51 +0000 | [diff] [blame] | 294 | void |
| 295 | _mesa_destroy_visual( GLvisual *vis ) |
| 296 | { |
| 297 | FREE(vis); |
| 298 | } |
| 299 | |
| 300 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 301 | /**********************************************************************/ |
| 302 | /***** GL Framebuffer allocation/destruction *****/ |
| 303 | /**********************************************************************/ |
| 304 | |
| 305 | |
| 306 | /* |
| 307 | * Create a new framebuffer. A GLframebuffer is a struct which |
| 308 | * encapsulates the depth, stencil and accum buffers and related |
| 309 | * parameters. |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 310 | * Input: visual - a GLvisual pointer (we copy the struct contents) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 311 | * softwareDepth - create/use a software depth buffer? |
| 312 | * softwareStencil - create/use a software stencil buffer? |
| 313 | * softwareAccum - create/use a software accum buffer? |
| 314 | * softwareAlpha - create/use a software alpha buffer? |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 315 | * Return: pointer to new GLframebuffer struct or NULL if error. |
| 316 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 317 | GLframebuffer * |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 318 | _mesa_create_framebuffer( const GLvisual *visual, |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 319 | GLboolean softwareDepth, |
| 320 | GLboolean softwareStencil, |
| 321 | GLboolean softwareAccum, |
| 322 | GLboolean softwareAlpha ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 323 | { |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 324 | GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer); |
| 325 | assert(visual); |
| 326 | if (buffer) { |
| 327 | _mesa_initialize_framebuffer(buffer, visual, |
| 328 | softwareDepth, softwareStencil, |
| 329 | softwareAccum, softwareAlpha ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 330 | } |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 331 | return buffer; |
| 332 | } |
| 333 | |
| 334 | |
| 335 | /* |
| 336 | * Initialize a GLframebuffer object. |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 337 | * Input: See _mesa_create_framebuffer() above. |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 338 | */ |
| 339 | void |
| 340 | _mesa_initialize_framebuffer( GLframebuffer *buffer, |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 341 | const GLvisual *visual, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 342 | GLboolean softwareDepth, |
| 343 | GLboolean softwareStencil, |
| 344 | GLboolean softwareAccum, |
| 345 | GLboolean softwareAlpha ) |
| 346 | { |
| 347 | assert(buffer); |
| 348 | assert(visual); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 349 | |
| 350 | /* sanity checks */ |
| 351 | if (softwareDepth ) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 352 | assert(visual->depthBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 353 | } |
| 354 | if (softwareStencil) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 355 | assert(visual->stencilBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 356 | } |
| 357 | if (softwareAccum) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 358 | assert(visual->rgbMode); |
| 359 | assert(visual->accumRedBits > 0); |
| 360 | assert(visual->accumGreenBits > 0); |
| 361 | assert(visual->accumBlueBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 362 | } |
| 363 | if (softwareAlpha) { |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 364 | assert(visual->rgbMode); |
| 365 | assert(visual->alphaBits > 0); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 368 | buffer->Visual = *visual; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 369 | buffer->UseSoftwareDepthBuffer = softwareDepth; |
| 370 | buffer->UseSoftwareStencilBuffer = softwareStencil; |
| 371 | buffer->UseSoftwareAccumBuffer = softwareAccum; |
| 372 | buffer->UseSoftwareAlphaBuffers = softwareAlpha; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 376 | /* |
| 377 | * Free a framebuffer struct and its buffers. |
| 378 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 379 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 380 | _mesa_destroy_framebuffer( GLframebuffer *buffer ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 381 | { |
| 382 | if (buffer) { |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 383 | _mesa_free_framebuffer_data(buffer); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 384 | FREE(buffer); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | |
| Brian Paul | 75978bd | 2001-04-27 21:17:20 +0000 | [diff] [blame] | 389 | /* |
| 390 | * Free the data hanging off of <buffer>, but not <buffer> itself. |
| 391 | */ |
| 392 | void |
| 393 | _mesa_free_framebuffer_data( GLframebuffer *buffer ) |
| 394 | { |
| 395 | if (!buffer) |
| 396 | return; |
| 397 | |
| 398 | if (buffer->DepthBuffer) { |
| 399 | FREE( buffer->DepthBuffer ); |
| 400 | buffer->DepthBuffer = NULL; |
| 401 | } |
| 402 | if (buffer->Accum) { |
| 403 | FREE( buffer->Accum ); |
| 404 | buffer->Accum = NULL; |
| 405 | } |
| 406 | if (buffer->Stencil) { |
| 407 | FREE( buffer->Stencil ); |
| 408 | buffer->Stencil = NULL; |
| 409 | } |
| 410 | if (buffer->FrontLeftAlpha) { |
| 411 | FREE( buffer->FrontLeftAlpha ); |
| 412 | buffer->FrontLeftAlpha = NULL; |
| 413 | } |
| 414 | if (buffer->BackLeftAlpha) { |
| 415 | FREE( buffer->BackLeftAlpha ); |
| 416 | buffer->BackLeftAlpha = NULL; |
| 417 | } |
| 418 | if (buffer->FrontRightAlpha) { |
| 419 | FREE( buffer->FrontRightAlpha ); |
| 420 | buffer->FrontRightAlpha = NULL; |
| 421 | } |
| 422 | if (buffer->BackRightAlpha) { |
| 423 | FREE( buffer->BackRightAlpha ); |
| 424 | buffer->BackRightAlpha = NULL; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 429 | |
| 430 | /**********************************************************************/ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 431 | /***** Context allocation, initialization, destroying *****/ |
| 432 | /**********************************************************************/ |
| 433 | |
| 434 | |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 435 | _glthread_DECLARE_STATIC_MUTEX(OneTimeLock); |
| 436 | |
| 437 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 438 | /* |
| 439 | * This function just calls all the various one-time-init functions in Mesa. |
| 440 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 441 | static void |
| 442 | one_time_init( void ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 443 | { |
| 444 | static GLboolean alreadyCalled = GL_FALSE; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 445 | _glthread_LOCK_MUTEX(OneTimeLock); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 446 | if (!alreadyCalled) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 447 | /* do some implementation tests */ |
| 448 | assert( sizeof(GLbyte) == 1 ); |
| 449 | assert( sizeof(GLshort) >= 2 ); |
| 450 | assert( sizeof(GLint) >= 4 ); |
| 451 | assert( sizeof(GLubyte) == 1 ); |
| 452 | assert( sizeof(GLushort) >= 2 ); |
| 453 | assert( sizeof(GLuint) >= 4 ); |
| 454 | |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 455 | _mesa_init_lists(); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 456 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 457 | _math_init(); |
| Brian Paul | 6975540 | 2001-02-26 23:58:12 +0000 | [diff] [blame] | 458 | _mesa_init_math(); |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 459 | |
| davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 460 | #ifdef USE_SPARC_ASM |
| 461 | _mesa_init_sparc_glapi_relocs(); |
| 462 | #endif |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 463 | if (getenv("MESA_DEBUG")) { |
| 464 | _glapi_noop_enable_warnings(GL_TRUE); |
| 465 | } |
| 466 | else { |
| 467 | _glapi_noop_enable_warnings(GL_FALSE); |
| 468 | } |
| 469 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 470 | #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__) |
| 471 | fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__); |
| 472 | #endif |
| Brian Paul | 68ee4bc | 2000-01-28 19:02:22 +0000 | [diff] [blame] | 473 | |
| 474 | alreadyCalled = GL_TRUE; |
| 475 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 476 | _glthread_UNLOCK_MUTEX(OneTimeLock); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 480 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 481 | /* |
| 482 | * Allocate and initialize a shared context state structure. |
| 483 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 484 | static struct gl_shared_state * |
| 485 | alloc_shared_state( void ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 486 | { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 487 | struct gl_shared_state *ss; |
| 488 | GLboolean outOfMemory; |
| 489 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 490 | ss = CALLOC_STRUCT(gl_shared_state); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 491 | if (!ss) |
| 492 | return NULL; |
| 493 | |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 494 | _glthread_INIT_MUTEX(ss->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 495 | |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 496 | ss->DisplayList = _mesa_NewHashTable(); |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 497 | ss->TexObjects = _mesa_NewHashTable(); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 498 | |
| 499 | /* Default Texture objects */ |
| 500 | outOfMemory = GL_FALSE; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 501 | |
| 502 | ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1); |
| 503 | if (!ss->Default1D) { |
| 504 | outOfMemory = GL_TRUE; |
| 505 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 506 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 507 | ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2); |
| 508 | if (!ss->Default2D) { |
| 509 | outOfMemory = GL_TRUE; |
| 510 | } |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 511 | |
| 512 | ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3); |
| 513 | if (!ss->Default3D) { |
| 514 | outOfMemory = GL_TRUE; |
| 515 | } |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 516 | |
| 517 | ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6); |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 518 | if (!ss->DefaultCubeMap) { |
| 519 | outOfMemory = GL_TRUE; |
| 520 | } |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 521 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 522 | if (!ss->DisplayList || !ss->TexObjects || outOfMemory) { |
| 523 | /* Ran out of memory at some point. Free everything and return NULL */ |
| 524 | if (ss->DisplayList) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 525 | _mesa_DeleteHashTable(ss->DisplayList); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 526 | if (ss->TexObjects) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 527 | _mesa_DeleteHashTable(ss->TexObjects); |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 528 | if (ss->Default1D) |
| 529 | _mesa_free_texture_object(ss, ss->Default1D); |
| 530 | if (ss->Default2D) |
| 531 | _mesa_free_texture_object(ss, ss->Default2D); |
| 532 | if (ss->Default3D) |
| 533 | _mesa_free_texture_object(ss, ss->Default3D); |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 534 | if (ss->DefaultCubeMap) |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 535 | _mesa_free_texture_object(ss, ss->DefaultCubeMap); |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 536 | FREE(ss); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 537 | return NULL; |
| 538 | } |
| 539 | else { |
| 540 | return ss; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | |
| 545 | /* |
| 546 | * Deallocate a shared state context and all children structures. |
| 547 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 548 | static void |
| 549 | free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 550 | { |
| 551 | /* Free display lists */ |
| 552 | while (1) { |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 553 | GLuint list = _mesa_HashFirstEntry(ss->DisplayList); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 554 | if (list) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 555 | _mesa_destroy_list(ctx, list); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 556 | } |
| 557 | else { |
| 558 | break; |
| 559 | } |
| 560 | } |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 561 | _mesa_DeleteHashTable(ss->DisplayList); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 562 | |
| 563 | /* Free texture objects */ |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 564 | while (ss->TexObjectList) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 565 | if (ctx->Driver.DeleteTexture) |
| 566 | (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList ); |
| 567 | /* this function removes from linked list too! */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 568 | _mesa_free_texture_object(ss, ss->TexObjectList); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 569 | } |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 570 | _mesa_DeleteHashTable(ss->TexObjects); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 571 | |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 572 | FREE(ss); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | |
| 576 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 577 | /* |
| 578 | * Initialize the nth light. Note that the defaults for light 0 are |
| 579 | * different than the other lights. |
| 580 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 581 | static void |
| 582 | init_light( struct gl_light *l, GLuint n ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 583 | { |
| 584 | make_empty_list( l ); |
| 585 | |
| 586 | ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 ); |
| 587 | if (n==0) { |
| 588 | ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 ); |
| 589 | ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 ); |
| 590 | } |
| 591 | else { |
| 592 | ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 ); |
| 593 | ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 ); |
| 594 | } |
| 595 | ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 ); |
| 596 | ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 ); |
| 597 | l->SpotExponent = 0.0; |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 598 | _mesa_invalidate_spot_exp_table( l ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 599 | l->SpotCutoff = 180.0; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 600 | l->_CosCutoff = 0.0; /* KW: -ve values not admitted */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 601 | l->ConstantAttenuation = 1.0; |
| 602 | l->LinearAttenuation = 0.0; |
| 603 | l->QuadraticAttenuation = 0.0; |
| 604 | l->Enabled = GL_FALSE; |
| 605 | } |
| 606 | |
| 607 | |
| 608 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 609 | static void |
| 610 | init_lightmodel( struct gl_lightmodel *lm ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 611 | { |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 612 | ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 613 | lm->LocalViewer = GL_FALSE; |
| 614 | lm->TwoSide = GL_FALSE; |
| 615 | lm->ColorControl = GL_SINGLE_COLOR; |
| 616 | } |
| 617 | |
| 618 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 619 | static void |
| 620 | init_material( struct gl_material *m ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 621 | { |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 622 | ASSIGN_4V( m->Ambient, 0.2F, 0.2F, 0.2F, 1.0F ); |
| 623 | ASSIGN_4V( m->Diffuse, 0.8F, 0.8F, 0.8F, 1.0F ); |
| 624 | ASSIGN_4V( m->Specular, 0.0F, 0.0F, 0.0F, 1.0F ); |
| 625 | ASSIGN_4V( m->Emission, 0.0F, 0.0F, 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 626 | m->Shininess = 0.0; |
| 627 | m->AmbientIndex = 0; |
| 628 | m->DiffuseIndex = 1; |
| 629 | m->SpecularIndex = 1; |
| 630 | } |
| 631 | |
| 632 | |
| 633 | |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 634 | static void |
| 635 | init_texture_unit( GLcontext *ctx, GLuint unit ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 636 | { |
| 637 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; |
| 638 | |
| 639 | texUnit->EnvMode = GL_MODULATE; |
| Brian Paul | 24507ff | 2000-06-27 21:42:13 +0000 | [diff] [blame] | 640 | texUnit->CombineModeRGB = GL_MODULATE; |
| 641 | texUnit->CombineModeA = GL_MODULATE; |
| 642 | texUnit->CombineSourceRGB[0] = GL_TEXTURE; |
| 643 | texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT; |
| 644 | texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT; |
| 645 | texUnit->CombineSourceA[0] = GL_TEXTURE; |
| 646 | texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT; |
| 647 | texUnit->CombineSourceA[2] = GL_CONSTANT_EXT; |
| 648 | texUnit->CombineOperandRGB[0] = GL_SRC_COLOR; |
| 649 | texUnit->CombineOperandRGB[1] = GL_SRC_COLOR; |
| 650 | texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA; |
| 651 | texUnit->CombineOperandA[0] = GL_SRC_ALPHA; |
| 652 | texUnit->CombineOperandA[1] = GL_SRC_ALPHA; |
| 653 | texUnit->CombineOperandA[2] = GL_SRC_ALPHA; |
| 654 | texUnit->CombineScaleShiftRGB = 0; |
| 655 | texUnit->CombineScaleShiftA = 0; |
| 656 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 657 | ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 ); |
| 658 | texUnit->TexGenEnabled = 0; |
| 659 | texUnit->GenModeS = GL_EYE_LINEAR; |
| 660 | texUnit->GenModeT = GL_EYE_LINEAR; |
| 661 | texUnit->GenModeR = GL_EYE_LINEAR; |
| 662 | texUnit->GenModeQ = GL_EYE_LINEAR; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 663 | texUnit->_GenBitS = TEXGEN_EYE_LINEAR; |
| 664 | texUnit->_GenBitT = TEXGEN_EYE_LINEAR; |
| 665 | texUnit->_GenBitR = TEXGEN_EYE_LINEAR; |
| 666 | texUnit->_GenBitQ = TEXGEN_EYE_LINEAR; |
| Brian Paul | 26f3b05 | 2000-07-19 20:58:59 +0000 | [diff] [blame] | 667 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 668 | /* Yes, these plane coefficients are correct! */ |
| 669 | ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 ); |
| 670 | ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 ); |
| 671 | ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 ); |
| 672 | ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 ); |
| 673 | ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 ); |
| 674 | ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 ); |
| 675 | ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 ); |
| 676 | ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 ); |
| 677 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 678 | texUnit->Current1D = ctx->Shared->Default1D; |
| 679 | texUnit->Current2D = ctx->Shared->Default2D; |
| 680 | texUnit->Current3D = ctx->Shared->Default3D; |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 681 | texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 685 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 686 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 687 | /* Initialize a 1-D evaluator map */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 688 | static void |
| 689 | init_1d_map( struct gl_1d_map *map, int n, const float *initial ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 690 | { |
| 691 | map->Order = 1; |
| 692 | map->u1 = 0.0; |
| 693 | map->u2 = 1.0; |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 694 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat)); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 695 | if (map->Points) { |
| 696 | GLint i; |
| 697 | for (i=0;i<n;i++) |
| 698 | map->Points[i] = initial[i]; |
| 699 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | |
| 703 | /* Initialize a 2-D evaluator map */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 704 | static void |
| 705 | init_2d_map( struct gl_2d_map *map, int n, const float *initial ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 706 | { |
| 707 | map->Uorder = 1; |
| 708 | map->Vorder = 1; |
| 709 | map->u1 = 0.0; |
| 710 | map->u2 = 1.0; |
| 711 | map->v1 = 0.0; |
| 712 | map->v2 = 1.0; |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 713 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat)); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 714 | if (map->Points) { |
| 715 | GLint i; |
| 716 | for (i=0;i<n;i++) |
| 717 | map->Points[i] = initial[i]; |
| 718 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 722 | /* |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 723 | * Initialize the attribute groups in a GLcontext. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 724 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 725 | static void |
| 726 | init_attrib_groups( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 727 | { |
| 728 | GLuint i, j; |
| 729 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 730 | assert(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 731 | |
| Brian Paul | cd1cefa | 2001-06-13 14:56:14 +0000 | [diff] [blame] | 732 | assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS); |
| 733 | assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS); |
| 734 | |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 735 | /* Constants, may be overriden by device drivers */ |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 736 | ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS; |
| Brian Paul | cd1cefa | 2001-06-13 14:56:14 +0000 | [diff] [blame] | 737 | ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS; |
| 738 | ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 739 | ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 740 | ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 741 | ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 742 | ctx->Const.SubPixelBits = SUB_PIXEL_BITS; |
| 743 | ctx->Const.MinPointSize = MIN_POINT_SIZE; |
| 744 | ctx->Const.MaxPointSize = MAX_POINT_SIZE; |
| 745 | ctx->Const.MinPointSizeAA = MIN_POINT_SIZE; |
| 746 | ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE; |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 747 | ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 748 | ctx->Const.MinLineWidth = MIN_LINE_WIDTH; |
| 749 | ctx->Const.MaxLineWidth = MAX_LINE_WIDTH; |
| 750 | ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH; |
| 751 | ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH; |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 752 | ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY; |
| Brian Paul | 539cce5 | 2000-02-03 19:40:07 +0000 | [diff] [blame] | 753 | ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 754 | ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE; |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 755 | ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH; |
| 756 | ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT; |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 757 | ctx->Const.NumCompressedTextureFormats = 0; |
| Brian Paul | a864432 | 2000-11-27 18:22:13 +0000 | [diff] [blame] | 758 | ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES; |
| 759 | ctx->Const.MaxLights = MAX_LIGHTS; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 760 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 761 | /* Modelview matrix */ |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 762 | _math_matrix_ctr( &ctx->ModelView ); |
| 763 | _math_matrix_alloc_inv( &ctx->ModelView ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 764 | |
| 765 | ctx->ModelViewStackDepth = 0; |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 766 | for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 767 | _math_matrix_ctr( &ctx->ModelViewStack[i] ); |
| 768 | _math_matrix_alloc_inv( &ctx->ModelViewStack[i] ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /* Projection matrix - need inv for user clipping in clip space*/ |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 772 | _math_matrix_ctr( &ctx->ProjectionMatrix ); |
| 773 | _math_matrix_alloc_inv( &ctx->ProjectionMatrix ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 774 | |
| 775 | ctx->ProjectionStackDepth = 0; |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 776 | for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 777 | _math_matrix_ctr( &ctx->ProjectionStack[i] ); |
| 778 | _math_matrix_alloc_inv( &ctx->ProjectionStack[i] ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 781 | /* Derived ModelProject matrix */ |
| 782 | _math_matrix_ctr( &ctx->_ModelProjectMatrix ); |
| 783 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 784 | /* Texture matrix */ |
| Brian Paul | 904ecb2 | 2000-06-27 23:38:45 +0000 | [diff] [blame] | 785 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 786 | _math_matrix_ctr( &ctx->TextureMatrix[i] ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 787 | ctx->TextureStackDepth[i] = 0; |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 788 | for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 789 | _math_matrix_ctr( &ctx->TextureStack[i][j] ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 790 | ctx->TextureStack[i][j].inv = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 791 | } |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 792 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 793 | |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 794 | /* Color matrix */ |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 795 | _math_matrix_ctr(&ctx->ColorMatrix); |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 796 | ctx->ColorStackDepth = 0; |
| 797 | for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 798 | _math_matrix_ctr(&ctx->ColorStack[j]); |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 801 | /* Accumulate buffer group */ |
| 802 | ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 803 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 804 | /* Color buffer group */ |
| 805 | ctx->Color.IndexMask = 0xffffffff; |
| 806 | ctx->Color.ColorMask[0] = 0xff; |
| 807 | ctx->Color.ColorMask[1] = 0xff; |
| 808 | ctx->Color.ColorMask[2] = 0xff; |
| 809 | ctx->Color.ColorMask[3] = 0xff; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 810 | ctx->Color.ClearIndex = 0; |
| Brian Paul | 74b493a | 2001-01-24 00:04:58 +0000 | [diff] [blame] | 811 | ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 812 | ctx->Color.DrawBuffer = GL_FRONT; |
| 813 | ctx->Color.AlphaEnabled = GL_FALSE; |
| 814 | ctx->Color.AlphaFunc = GL_ALWAYS; |
| 815 | ctx->Color.AlphaRef = 0; |
| 816 | ctx->Color.BlendEnabled = GL_FALSE; |
| 817 | ctx->Color.BlendSrcRGB = GL_ONE; |
| 818 | ctx->Color.BlendDstRGB = GL_ZERO; |
| 819 | ctx->Color.BlendSrcA = GL_ONE; |
| 820 | ctx->Color.BlendDstA = GL_ZERO; |
| 821 | ctx->Color.BlendEquation = GL_FUNC_ADD_EXT; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 822 | ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 ); |
| 823 | ctx->Color.IndexLogicOpEnabled = GL_FALSE; |
| 824 | ctx->Color.ColorLogicOpEnabled = GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 825 | ctx->Color.LogicOp = GL_COPY; |
| 826 | ctx->Color.DitherFlag = GL_TRUE; |
| 827 | ctx->Color.MultiDrawBuffer = GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 828 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 829 | /* Current group */ |
| Keith Whitwell | 51c0c71 | 2001-04-28 08:39:17 +0000 | [diff] [blame] | 830 | ASSIGN_4V( ctx->Current.Color, 1.0, 1.0, 1.0, 1.0 ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 831 | ctx->Current.Index = 1; |
| 832 | for (i=0; i<MAX_TEXTURE_UNITS; i++) |
| 833 | ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 ); |
| 834 | ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 ); |
| 835 | ctx->Current.RasterDistance = 0.0; |
| 836 | ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 ); |
| 837 | ctx->Current.RasterIndex = 1; |
| 838 | for (i=0; i<MAX_TEXTURE_UNITS; i++) |
| 839 | ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 ); |
| 840 | ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0]; |
| 841 | ctx->Current.RasterPosValid = GL_TRUE; |
| 842 | ctx->Current.EdgeFlag = GL_TRUE; |
| 843 | ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 844 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 845 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 846 | /* Depth buffer group */ |
| 847 | ctx->Depth.Test = GL_FALSE; |
| 848 | ctx->Depth.Clear = 1.0; |
| 849 | ctx->Depth.Func = GL_LESS; |
| 850 | ctx->Depth.Mask = GL_TRUE; |
| Brian Paul | 1b2ff69 | 2000-03-11 23:23:26 +0000 | [diff] [blame] | 851 | ctx->Depth.OcclusionTest = GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 852 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 853 | /* Evaluators group */ |
| 854 | ctx->Eval.Map1Color4 = GL_FALSE; |
| 855 | ctx->Eval.Map1Index = GL_FALSE; |
| 856 | ctx->Eval.Map1Normal = GL_FALSE; |
| 857 | ctx->Eval.Map1TextureCoord1 = GL_FALSE; |
| 858 | ctx->Eval.Map1TextureCoord2 = GL_FALSE; |
| 859 | ctx->Eval.Map1TextureCoord3 = GL_FALSE; |
| 860 | ctx->Eval.Map1TextureCoord4 = GL_FALSE; |
| 861 | ctx->Eval.Map1Vertex3 = GL_FALSE; |
| 862 | ctx->Eval.Map1Vertex4 = GL_FALSE; |
| 863 | ctx->Eval.Map2Color4 = GL_FALSE; |
| 864 | ctx->Eval.Map2Index = GL_FALSE; |
| 865 | ctx->Eval.Map2Normal = GL_FALSE; |
| 866 | ctx->Eval.Map2TextureCoord1 = GL_FALSE; |
| 867 | ctx->Eval.Map2TextureCoord2 = GL_FALSE; |
| 868 | ctx->Eval.Map2TextureCoord3 = GL_FALSE; |
| 869 | ctx->Eval.Map2TextureCoord4 = GL_FALSE; |
| 870 | ctx->Eval.Map2Vertex3 = GL_FALSE; |
| 871 | ctx->Eval.Map2Vertex4 = GL_FALSE; |
| 872 | ctx->Eval.AutoNormal = GL_FALSE; |
| 873 | ctx->Eval.MapGrid1un = 1; |
| 874 | ctx->Eval.MapGrid1u1 = 0.0; |
| 875 | ctx->Eval.MapGrid1u2 = 1.0; |
| 876 | ctx->Eval.MapGrid2un = 1; |
| 877 | ctx->Eval.MapGrid2vn = 1; |
| 878 | ctx->Eval.MapGrid2u1 = 0.0; |
| 879 | ctx->Eval.MapGrid2u2 = 1.0; |
| 880 | ctx->Eval.MapGrid2v1 = 0.0; |
| 881 | ctx->Eval.MapGrid2v2 = 1.0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 882 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 883 | /* Evaluator data */ |
| 884 | { |
| 885 | static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 }; |
| 886 | static GLfloat normal[3] = { 0.0, 0.0, 1.0 }; |
| 887 | static GLfloat index[1] = { 1.0 }; |
| 888 | static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 889 | static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 }; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 890 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 891 | init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex ); |
| 892 | init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex ); |
| 893 | init_1d_map( &ctx->EvalMap.Map1Index, 1, index ); |
| 894 | init_1d_map( &ctx->EvalMap.Map1Color4, 4, color ); |
| 895 | init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal ); |
| 896 | init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord ); |
| 897 | init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord ); |
| 898 | init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord ); |
| 899 | init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 900 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 901 | init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex ); |
| 902 | init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex ); |
| 903 | init_2d_map( &ctx->EvalMap.Map2Index, 1, index ); |
| 904 | init_2d_map( &ctx->EvalMap.Map2Color4, 4, color ); |
| 905 | init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal ); |
| 906 | init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord ); |
| 907 | init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord ); |
| 908 | init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord ); |
| 909 | init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord ); |
| 910 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 911 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 912 | /* Fog group */ |
| 913 | ctx->Fog.Enabled = GL_FALSE; |
| 914 | ctx->Fog.Mode = GL_EXP; |
| 915 | ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 ); |
| 916 | ctx->Fog.Index = 0.0; |
| 917 | ctx->Fog.Density = 1.0; |
| 918 | ctx->Fog.Start = 0.0; |
| 919 | ctx->Fog.End = 1.0; |
| Keith Whitwell | fe5d67d | 2000-10-27 16:44:40 +0000 | [diff] [blame] | 920 | ctx->Fog.ColorSumEnabled = GL_FALSE; |
| 921 | ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 922 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 923 | /* Hint group */ |
| 924 | ctx->Hint.PerspectiveCorrection = GL_DONT_CARE; |
| 925 | ctx->Hint.PointSmooth = GL_DONT_CARE; |
| 926 | ctx->Hint.LineSmooth = GL_DONT_CARE; |
| 927 | ctx->Hint.PolygonSmooth = GL_DONT_CARE; |
| 928 | ctx->Hint.Fog = GL_DONT_CARE; |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 929 | ctx->Hint.ClipVolumeClipping = GL_DONT_CARE; |
| 930 | ctx->Hint.TextureCompression = GL_DONT_CARE; |
| Brian Paul | 3893e63 | 2001-05-21 16:41:03 +0000 | [diff] [blame] | 931 | ctx->Hint.GenerateMipmap = GL_DONT_CARE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 932 | |
| Brian Paul | 0771d15 | 2000-04-07 00:19:41 +0000 | [diff] [blame] | 933 | /* Histogram group */ |
| 934 | ctx->Histogram.Width = 0; |
| 935 | ctx->Histogram.Format = GL_RGBA; |
| 936 | ctx->Histogram.Sink = GL_FALSE; |
| Brian Paul | e75d242 | 2001-02-17 18:41:01 +0000 | [diff] [blame] | 937 | ctx->Histogram.RedSize = 0; |
| 938 | ctx->Histogram.GreenSize = 0; |
| 939 | ctx->Histogram.BlueSize = 0; |
| 940 | ctx->Histogram.AlphaSize = 0; |
| 941 | ctx->Histogram.LuminanceSize = 0; |
| Brian Paul | 0771d15 | 2000-04-07 00:19:41 +0000 | [diff] [blame] | 942 | for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) { |
| 943 | ctx->Histogram.Count[i][0] = 0; |
| 944 | ctx->Histogram.Count[i][1] = 0; |
| 945 | ctx->Histogram.Count[i][2] = 0; |
| 946 | ctx->Histogram.Count[i][3] = 0; |
| 947 | } |
| 948 | |
| 949 | /* Min/Max group */ |
| 950 | ctx->MinMax.Format = GL_RGBA; |
| 951 | ctx->MinMax.Sink = GL_FALSE; |
| 952 | ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000; |
| 953 | ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000; |
| 954 | ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000; |
| 955 | ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000; |
| 956 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 957 | /* Extensions */ |
| Brian Paul | 6975540 | 2001-02-26 23:58:12 +0000 | [diff] [blame] | 958 | _mesa_extensions_ctr( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 959 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 960 | /* Lighting group */ |
| 961 | for (i=0;i<MAX_LIGHTS;i++) { |
| 962 | init_light( &ctx->Light.Light[i], i ); |
| 963 | } |
| 964 | make_empty_list( &ctx->Light.EnabledList ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 965 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 966 | init_lightmodel( &ctx->Light.Model ); |
| 967 | init_material( &ctx->Light.Material[0] ); |
| 968 | init_material( &ctx->Light.Material[1] ); |
| 969 | ctx->Light.ShadeModel = GL_SMOOTH; |
| 970 | ctx->Light.Enabled = GL_FALSE; |
| 971 | ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK; |
| 972 | ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE; |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 973 | ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx, |
| 974 | GL_FRONT_AND_BACK, |
| 975 | GL_AMBIENT_AND_DIFFUSE, ~0, 0 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 976 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 977 | ctx->Light.ColorMaterialEnabled = GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 978 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 979 | /* Lighting miscellaneous */ |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 980 | ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab ); |
| 981 | make_empty_list( ctx->_ShineTabList ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 982 | for (i = 0 ; i < 10 ; i++) { |
| 983 | struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab ); |
| 984 | s->shininess = -1; |
| 985 | s->refcount = 0; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 986 | insert_at_tail( ctx->_ShineTabList, s ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 987 | } |
| Brian Paul | 77d61af | 2000-06-28 04:20:21 +0000 | [diff] [blame] | 988 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 989 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 990 | /* Line group */ |
| 991 | ctx->Line.SmoothFlag = GL_FALSE; |
| 992 | ctx->Line.StippleFlag = GL_FALSE; |
| 993 | ctx->Line.Width = 1.0; |
| Keith Whitwell | bed4c5b | 2001-02-27 16:14:35 +0000 | [diff] [blame] | 994 | ctx->Line._Width = 1.0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 995 | ctx->Line.StipplePattern = 0xffff; |
| 996 | ctx->Line.StippleFactor = 1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 997 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 998 | /* Display List group */ |
| 999 | ctx->List.ListBase = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1000 | |
| Brian Paul | 736fcbe | 2001-05-29 15:23:48 +0000 | [diff] [blame] | 1001 | /* Multisample */ |
| 1002 | ctx->Multisample.Enabled = GL_FALSE; |
| 1003 | ctx->Multisample.SampleAlphaToCoverage = GL_FALSE; |
| 1004 | ctx->Multisample.SampleAlphaToOne = GL_FALSE; |
| 1005 | ctx->Multisample.SampleCoverage = GL_FALSE; |
| 1006 | ctx->Multisample.SampleCoverageValue = 1.0; |
| 1007 | ctx->Multisample.SampleCoverageInvert = GL_FALSE; |
| 1008 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1009 | /* Pixel group */ |
| 1010 | ctx->Pixel.RedBias = 0.0; |
| 1011 | ctx->Pixel.RedScale = 1.0; |
| 1012 | ctx->Pixel.GreenBias = 0.0; |
| 1013 | ctx->Pixel.GreenScale = 1.0; |
| 1014 | ctx->Pixel.BlueBias = 0.0; |
| 1015 | ctx->Pixel.BlueScale = 1.0; |
| 1016 | ctx->Pixel.AlphaBias = 0.0; |
| 1017 | ctx->Pixel.AlphaScale = 1.0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1018 | ctx->Pixel.DepthBias = 0.0; |
| 1019 | ctx->Pixel.DepthScale = 1.0; |
| 1020 | ctx->Pixel.IndexOffset = 0; |
| 1021 | ctx->Pixel.IndexShift = 0; |
| 1022 | ctx->Pixel.ZoomX = 1.0; |
| 1023 | ctx->Pixel.ZoomY = 1.0; |
| 1024 | ctx->Pixel.MapColorFlag = GL_FALSE; |
| 1025 | ctx->Pixel.MapStencilFlag = GL_FALSE; |
| 1026 | ctx->Pixel.MapStoSsize = 1; |
| 1027 | ctx->Pixel.MapItoIsize = 1; |
| 1028 | ctx->Pixel.MapItoRsize = 1; |
| 1029 | ctx->Pixel.MapItoGsize = 1; |
| 1030 | ctx->Pixel.MapItoBsize = 1; |
| 1031 | ctx->Pixel.MapItoAsize = 1; |
| 1032 | ctx->Pixel.MapRtoRsize = 1; |
| 1033 | ctx->Pixel.MapGtoGsize = 1; |
| 1034 | ctx->Pixel.MapBtoBsize = 1; |
| 1035 | ctx->Pixel.MapAtoAsize = 1; |
| 1036 | ctx->Pixel.MapStoS[0] = 0; |
| 1037 | ctx->Pixel.MapItoI[0] = 0; |
| 1038 | ctx->Pixel.MapItoR[0] = 0.0; |
| 1039 | ctx->Pixel.MapItoG[0] = 0.0; |
| 1040 | ctx->Pixel.MapItoB[0] = 0.0; |
| 1041 | ctx->Pixel.MapItoA[0] = 0.0; |
| 1042 | ctx->Pixel.MapItoR8[0] = 0; |
| 1043 | ctx->Pixel.MapItoG8[0] = 0; |
| 1044 | ctx->Pixel.MapItoB8[0] = 0; |
| 1045 | ctx->Pixel.MapItoA8[0] = 0; |
| 1046 | ctx->Pixel.MapRtoR[0] = 0.0; |
| 1047 | ctx->Pixel.MapGtoG[0] = 0.0; |
| 1048 | ctx->Pixel.MapBtoB[0] = 0.0; |
| 1049 | ctx->Pixel.MapAtoA[0] = 0.0; |
| Brian Paul | 2b2e925 | 2000-04-07 16:27:26 +0000 | [diff] [blame] | 1050 | ctx->Pixel.HistogramEnabled = GL_FALSE; |
| 1051 | ctx->Pixel.MinMaxEnabled = GL_FALSE; |
| 1052 | ctx->Pixel.PixelTextureEnabled = GL_FALSE; |
| 1053 | ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS; |
| 1054 | ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS; |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 1055 | ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0); |
| 1056 | ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0); |
| 1057 | ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0); |
| 1058 | ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0); |
| Brian Paul | 6c50e16 | 2000-06-30 22:11:04 +0000 | [diff] [blame] | 1059 | ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0); |
| 1060 | ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0); |
| 1061 | ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0); |
| 1062 | ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0); |
| Brian Paul | 4fe34b2 | 2000-04-11 15:07:48 +0000 | [diff] [blame] | 1063 | ctx->Pixel.ColorTableEnabled = GL_FALSE; |
| 1064 | ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE; |
| 1065 | ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE; |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 1066 | ctx->Pixel.Convolution1DEnabled = GL_FALSE; |
| 1067 | ctx->Pixel.Convolution2DEnabled = GL_FALSE; |
| 1068 | ctx->Pixel.Separable2DEnabled = GL_FALSE; |
| 1069 | for (i = 0; i < 3; i++) { |
| 1070 | ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0); |
| 1071 | ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE; |
| 1072 | ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0); |
| 1073 | ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0); |
| 1074 | } |
| Brian Paul | 67adba1 | 2000-12-09 20:35:54 +0000 | [diff] [blame] | 1075 | for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) { |
| 1076 | ctx->Convolution1D.Filter[i] = 0.0; |
| 1077 | ctx->Convolution2D.Filter[i] = 0.0; |
| 1078 | ctx->Separable2D.Filter[i] = 0.0; |
| 1079 | } |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 1080 | ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0); |
| 1081 | ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1082 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1083 | /* Point group */ |
| 1084 | ctx->Point.SmoothFlag = GL_FALSE; |
| 1085 | ctx->Point.Size = 1.0; |
| Brian Paul | 24a3262 | 2000-11-15 16:38:40 +0000 | [diff] [blame] | 1086 | ctx->Point._Size = 1.0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1087 | ctx->Point.Params[0] = 1.0; |
| 1088 | ctx->Point.Params[1] = 0.0; |
| 1089 | ctx->Point.Params[2] = 0.0; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1090 | ctx->Point._Attenuated = GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1091 | ctx->Point.MinSize = 0.0; |
| Brian Paul | 24a3262 | 2000-11-15 16:38:40 +0000 | [diff] [blame] | 1092 | ctx->Point.MaxSize = ctx->Const.MaxPointSize; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1093 | ctx->Point.Threshold = 1.0; |
| Brian Paul | 06d05af | 2000-12-08 00:20:15 +0000 | [diff] [blame] | 1094 | ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1095 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1096 | /* Polygon group */ |
| 1097 | ctx->Polygon.CullFlag = GL_FALSE; |
| 1098 | ctx->Polygon.CullFaceMode = GL_BACK; |
| 1099 | ctx->Polygon.FrontFace = GL_CCW; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1100 | ctx->Polygon._FrontBit = 0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1101 | ctx->Polygon.FrontMode = GL_FILL; |
| 1102 | ctx->Polygon.BackMode = GL_FILL; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1103 | ctx->Polygon.SmoothFlag = GL_FALSE; |
| 1104 | ctx->Polygon.StippleFlag = GL_FALSE; |
| 1105 | ctx->Polygon.OffsetFactor = 0.0F; |
| 1106 | ctx->Polygon.OffsetUnits = 0.0F; |
| Brian Paul | d0d7d62 | 2000-10-21 00:02:47 +0000 | [diff] [blame] | 1107 | ctx->Polygon.OffsetMRD = 0.0F; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1108 | ctx->Polygon.OffsetPoint = GL_FALSE; |
| 1109 | ctx->Polygon.OffsetLine = GL_FALSE; |
| 1110 | ctx->Polygon.OffsetFill = GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1111 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1112 | /* Polygon Stipple group */ |
| 1113 | MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1114 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1115 | /* Scissor group */ |
| 1116 | ctx->Scissor.Enabled = GL_FALSE; |
| 1117 | ctx->Scissor.X = 0; |
| 1118 | ctx->Scissor.Y = 0; |
| 1119 | ctx->Scissor.Width = 0; |
| 1120 | ctx->Scissor.Height = 0; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1121 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1122 | /* Stencil group */ |
| 1123 | ctx->Stencil.Enabled = GL_FALSE; |
| 1124 | ctx->Stencil.Function = GL_ALWAYS; |
| 1125 | ctx->Stencil.FailFunc = GL_KEEP; |
| 1126 | ctx->Stencil.ZPassFunc = GL_KEEP; |
| 1127 | ctx->Stencil.ZFailFunc = GL_KEEP; |
| 1128 | ctx->Stencil.Ref = 0; |
| 1129 | ctx->Stencil.ValueMask = STENCIL_MAX; |
| 1130 | ctx->Stencil.Clear = 0; |
| 1131 | ctx->Stencil.WriteMask = STENCIL_MAX; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1132 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1133 | /* Texture group */ |
| 1134 | ctx->Texture.CurrentUnit = 0; /* multitexture */ |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1135 | ctx->Texture._ReallyEnabled = 0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1136 | for (i=0; i<MAX_TEXTURE_UNITS; i++) |
| 1137 | init_texture_unit( ctx, i ); |
| Brian Paul | 2331603 | 2000-09-14 23:13:23 +0000 | [diff] [blame] | 1138 | ctx->Texture.SharedPalette = GL_FALSE; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1139 | _mesa_init_colortable(&ctx->Texture.Palette); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1140 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1141 | /* Transformation group */ |
| 1142 | ctx->Transform.MatrixMode = GL_MODELVIEW; |
| 1143 | ctx->Transform.Normalize = GL_FALSE; |
| 1144 | ctx->Transform.RescaleNormals = GL_FALSE; |
| Brian Paul | 8c2f6c5 | 2001-06-26 01:32:48 +0000 | [diff] [blame] | 1145 | ctx->Transform.RasterPositionUnclipped = GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1146 | for (i=0;i<MAX_CLIP_PLANES;i++) { |
| 1147 | ctx->Transform.ClipEnabled[i] = GL_FALSE; |
| 1148 | ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 ); |
| 1149 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1150 | ctx->Transform._AnyClip = GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1151 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1152 | /* Viewport group */ |
| 1153 | ctx->Viewport.X = 0; |
| 1154 | ctx->Viewport.Y = 0; |
| 1155 | ctx->Viewport.Width = 0; |
| 1156 | ctx->Viewport.Height = 0; |
| 1157 | ctx->Viewport.Near = 0.0; |
| 1158 | ctx->Viewport.Far = 1.0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1159 | _math_matrix_ctr(&ctx->Viewport._WindowMap); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1160 | |
| 1161 | #define Sz 10 |
| 1162 | #define Tz 14 |
| Brian Paul | fde5e2c | 2001-09-15 18:02:49 +0000 | [diff] [blame] | 1163 | ctx->Viewport._WindowMap.m[Sz] = 0.5F * ctx->DepthMaxF; |
| 1164 | ctx->Viewport._WindowMap.m[Tz] = 0.5F * ctx->DepthMaxF; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1165 | #undef Sz |
| 1166 | #undef Tz |
| 1167 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1168 | ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION; |
| 1169 | ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1170 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1171 | /* Vertex arrays */ |
| 1172 | ctx->Array.Vertex.Size = 4; |
| 1173 | ctx->Array.Vertex.Type = GL_FLOAT; |
| 1174 | ctx->Array.Vertex.Stride = 0; |
| 1175 | ctx->Array.Vertex.StrideB = 0; |
| 1176 | ctx->Array.Vertex.Ptr = NULL; |
| 1177 | ctx->Array.Vertex.Enabled = GL_FALSE; |
| Keith Whitwell | 51c0c71 | 2001-04-28 08:39:17 +0000 | [diff] [blame] | 1178 | ctx->Array.Vertex.Flags = CA_CLIENT_DATA; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1179 | ctx->Array.Normal.Type = GL_FLOAT; |
| 1180 | ctx->Array.Normal.Stride = 0; |
| 1181 | ctx->Array.Normal.StrideB = 0; |
| 1182 | ctx->Array.Normal.Ptr = NULL; |
| 1183 | ctx->Array.Normal.Enabled = GL_FALSE; |
| Keith Whitwell | 51c0c71 | 2001-04-28 08:39:17 +0000 | [diff] [blame] | 1184 | ctx->Array.Normal.Flags = CA_CLIENT_DATA; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1185 | ctx->Array.Color.Size = 4; |
| 1186 | ctx->Array.Color.Type = GL_FLOAT; |
| 1187 | ctx->Array.Color.Stride = 0; |
| 1188 | ctx->Array.Color.StrideB = 0; |
| 1189 | ctx->Array.Color.Ptr = NULL; |
| 1190 | ctx->Array.Color.Enabled = GL_FALSE; |
| Keith Whitwell | 51c0c71 | 2001-04-28 08:39:17 +0000 | [diff] [blame] | 1191 | ctx->Array.Color.Flags = CA_CLIENT_DATA; |
| 1192 | ctx->Array.SecondaryColor.Size = 4; |
| 1193 | ctx->Array.SecondaryColor.Type = GL_FLOAT; |
| 1194 | ctx->Array.SecondaryColor.Stride = 0; |
| 1195 | ctx->Array.SecondaryColor.StrideB = 0; |
| 1196 | ctx->Array.SecondaryColor.Ptr = NULL; |
| 1197 | ctx->Array.SecondaryColor.Enabled = GL_FALSE; |
| 1198 | ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA; |
| 1199 | ctx->Array.FogCoord.Size = 1; |
| 1200 | ctx->Array.FogCoord.Type = GL_FLOAT; |
| 1201 | ctx->Array.FogCoord.Stride = 0; |
| 1202 | ctx->Array.FogCoord.StrideB = 0; |
| 1203 | ctx->Array.FogCoord.Ptr = NULL; |
| 1204 | ctx->Array.FogCoord.Enabled = GL_FALSE; |
| 1205 | ctx->Array.FogCoord.Flags = CA_CLIENT_DATA; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1206 | ctx->Array.Index.Type = GL_FLOAT; |
| 1207 | ctx->Array.Index.Stride = 0; |
| 1208 | ctx->Array.Index.StrideB = 0; |
| 1209 | ctx->Array.Index.Ptr = NULL; |
| 1210 | ctx->Array.Index.Enabled = GL_FALSE; |
| Keith Whitwell | 51c0c71 | 2001-04-28 08:39:17 +0000 | [diff] [blame] | 1211 | ctx->Array.Index.Flags = CA_CLIENT_DATA; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1212 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) { |
| 1213 | ctx->Array.TexCoord[i].Size = 4; |
| 1214 | ctx->Array.TexCoord[i].Type = GL_FLOAT; |
| 1215 | ctx->Array.TexCoord[i].Stride = 0; |
| 1216 | ctx->Array.TexCoord[i].StrideB = 0; |
| 1217 | ctx->Array.TexCoord[i].Ptr = NULL; |
| 1218 | ctx->Array.TexCoord[i].Enabled = GL_FALSE; |
| Keith Whitwell | 51c0c71 | 2001-04-28 08:39:17 +0000 | [diff] [blame] | 1219 | ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1220 | } |
| 1221 | ctx->Array.TexCoordInterleaveFactor = 1; |
| 1222 | ctx->Array.EdgeFlag.Stride = 0; |
| 1223 | ctx->Array.EdgeFlag.StrideB = 0; |
| 1224 | ctx->Array.EdgeFlag.Ptr = NULL; |
| 1225 | ctx->Array.EdgeFlag.Enabled = GL_FALSE; |
| Keith Whitwell | 51c0c71 | 2001-04-28 08:39:17 +0000 | [diff] [blame] | 1226 | ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1227 | ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ |
| 1228 | |
| 1229 | /* Pixel transfer */ |
| 1230 | ctx->Pack.Alignment = 4; |
| 1231 | ctx->Pack.RowLength = 0; |
| 1232 | ctx->Pack.ImageHeight = 0; |
| 1233 | ctx->Pack.SkipPixels = 0; |
| 1234 | ctx->Pack.SkipRows = 0; |
| 1235 | ctx->Pack.SkipImages = 0; |
| 1236 | ctx->Pack.SwapBytes = GL_FALSE; |
| 1237 | ctx->Pack.LsbFirst = GL_FALSE; |
| 1238 | ctx->Unpack.Alignment = 4; |
| 1239 | ctx->Unpack.RowLength = 0; |
| 1240 | ctx->Unpack.ImageHeight = 0; |
| 1241 | ctx->Unpack.SkipPixels = 0; |
| 1242 | ctx->Unpack.SkipRows = 0; |
| 1243 | ctx->Unpack.SkipImages = 0; |
| 1244 | ctx->Unpack.SwapBytes = GL_FALSE; |
| 1245 | ctx->Unpack.LsbFirst = GL_FALSE; |
| 1246 | |
| 1247 | /* Feedback */ |
| 1248 | ctx->Feedback.Type = GL_2D; /* TODO: verify */ |
| 1249 | ctx->Feedback.Buffer = NULL; |
| 1250 | ctx->Feedback.BufferSize = 0; |
| 1251 | ctx->Feedback.Count = 0; |
| 1252 | |
| 1253 | /* Selection/picking */ |
| 1254 | ctx->Select.Buffer = NULL; |
| 1255 | ctx->Select.BufferSize = 0; |
| 1256 | ctx->Select.BufferCount = 0; |
| 1257 | ctx->Select.Hits = 0; |
| 1258 | ctx->Select.NameStackDepth = 0; |
| 1259 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1260 | /* Renderer and client attribute stacks */ |
| 1261 | ctx->AttribStackDepth = 0; |
| 1262 | ctx->ClientAttribStackDepth = 0; |
| 1263 | |
| Brian Paul | 1381137 | 2000-04-12 00:27:37 +0000 | [diff] [blame] | 1264 | /* Display list */ |
| 1265 | ctx->CallDepth = 0; |
| 1266 | ctx->ExecuteFlag = GL_TRUE; |
| 1267 | ctx->CompileFlag = GL_FALSE; |
| 1268 | ctx->CurrentListPtr = NULL; |
| 1269 | ctx->CurrentBlock = NULL; |
| 1270 | ctx->CurrentListNum = 0; |
| 1271 | ctx->CurrentPos = 0; |
| 1272 | |
| 1273 | /* Color tables */ |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1274 | _mesa_init_colortable(&ctx->ColorTable); |
| 1275 | _mesa_init_colortable(&ctx->ProxyColorTable); |
| 1276 | _mesa_init_colortable(&ctx->PostConvolutionColorTable); |
| 1277 | _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable); |
| 1278 | _mesa_init_colortable(&ctx->PostColorMatrixColorTable); |
| 1279 | _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable); |
| Brian Paul | 1381137 | 2000-04-12 00:27:37 +0000 | [diff] [blame] | 1280 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1281 | /* Miscellaneous */ |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1282 | ctx->NewState = _NEW_ALL; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1283 | ctx->RenderMode = GL_RENDER; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1284 | ctx->_ImageTransferState = 0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1285 | |
| Keith Whitwell | 1e1aac0 | 2000-11-13 20:02:56 +0000 | [diff] [blame] | 1286 | ctx->_NeedNormals = 0; |
| 1287 | ctx->_NeedEyeCoords = 0; |
| 1288 | ctx->_ModelViewInvScale = 1.0; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1289 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1290 | ctx->ErrorValue = (GLenum) GL_NO_ERROR; |
| 1291 | |
| 1292 | ctx->CatchSignals = GL_TRUE; |
| Brian Paul | 1b2ff69 | 2000-03-11 23:23:26 +0000 | [diff] [blame] | 1293 | ctx->OcclusionResult = GL_FALSE; |
| Brian Paul | 7e67fb4 | 2000-04-04 15:14:10 +0000 | [diff] [blame] | 1294 | ctx->OcclusionResultSaved = GL_FALSE; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1295 | |
| 1296 | /* For debug/development only */ |
| 1297 | ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE; |
| 1298 | ctx->FirstTimeCurrent = GL_TRUE; |
| 1299 | |
| 1300 | /* Dither disable */ |
| 1301 | ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE; |
| 1302 | if (ctx->NoDither) { |
| 1303 | if (getenv("MESA_DEBUG")) { |
| 1304 | fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1305 | } |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1306 | ctx->Color.DitherFlag = GL_FALSE; |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1313 | /* |
| 1314 | * Allocate the proxy textures. If we run out of memory part way through |
| 1315 | * the allocations clean up and return GL_FALSE. |
| 1316 | * Return: GL_TRUE=success, GL_FALSE=failure |
| 1317 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1318 | static GLboolean |
| 1319 | alloc_proxy_textures( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1320 | { |
| 1321 | GLboolean out_of_memory; |
| 1322 | GLint i; |
| 1323 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1324 | ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1325 | if (!ctx->Texture.Proxy1D) { |
| 1326 | return GL_FALSE; |
| 1327 | } |
| 1328 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1329 | ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1330 | if (!ctx->Texture.Proxy2D) { |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1331 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1332 | return GL_FALSE; |
| 1333 | } |
| 1334 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1335 | ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1336 | if (!ctx->Texture.Proxy3D) { |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1337 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D); |
| 1338 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D); |
| 1339 | return GL_FALSE; |
| 1340 | } |
| 1341 | |
| 1342 | ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6); |
| 1343 | if (!ctx->Texture.ProxyCubeMap) { |
| 1344 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D); |
| 1345 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D); |
| 1346 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1347 | return GL_FALSE; |
| 1348 | } |
| 1349 | |
| 1350 | out_of_memory = GL_FALSE; |
| 1351 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 1352 | ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image(); |
| 1353 | ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image(); |
| 1354 | ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image(); |
| Brian Paul | 172281d | 2001-07-26 20:02:10 +0000 | [diff] [blame] | 1355 | ctx->Texture.ProxyCubeMap->Image[i] = _mesa_alloc_texture_image(); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1356 | if (!ctx->Texture.Proxy1D->Image[i] |
| 1357 | || !ctx->Texture.Proxy2D->Image[i] |
| Brian Paul | 172281d | 2001-07-26 20:02:10 +0000 | [diff] [blame] | 1358 | || !ctx->Texture.Proxy3D->Image[i] |
| 1359 | || !ctx->Texture.ProxyCubeMap->Image[i]) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1360 | out_of_memory = GL_TRUE; |
| 1361 | } |
| 1362 | } |
| 1363 | if (out_of_memory) { |
| 1364 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) { |
| 1365 | if (ctx->Texture.Proxy1D->Image[i]) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 1366 | _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1367 | } |
| 1368 | if (ctx->Texture.Proxy2D->Image[i]) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 1369 | _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1370 | } |
| 1371 | if (ctx->Texture.Proxy3D->Image[i]) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 1372 | _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1373 | } |
| Brian Paul | 172281d | 2001-07-26 20:02:10 +0000 | [diff] [blame] | 1374 | if (ctx->Texture.ProxyCubeMap->Image[i]) { |
| 1375 | _mesa_free_texture_image(ctx->Texture.ProxyCubeMap->Image[i]); |
| 1376 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1377 | } |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1378 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D); |
| 1379 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D); |
| 1380 | _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D); |
| Brian Paul | 172281d | 2001-07-26 20:02:10 +0000 | [diff] [blame] | 1381 | _mesa_free_texture_object(NULL, ctx->Texture.ProxyCubeMap); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1382 | return GL_FALSE; |
| 1383 | } |
| 1384 | else { |
| 1385 | return GL_TRUE; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1390 | /* |
| Brian Paul | 8aee2a3 | 2000-08-29 18:57:58 +0000 | [diff] [blame] | 1391 | * Initialize a GLcontext struct. This includes allocating all the |
| 1392 | * other structs and arrays which hang off of the context by pointers. |
| 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 | GLboolean |
| 1395 | _mesa_initialize_context( GLcontext *ctx, |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1396 | const GLvisual *visual, |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1397 | GLcontext *share_list, |
| 1398 | void *driver_ctx, |
| 1399 | GLboolean direct ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1400 | { |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1401 | GLuint dispatchSize; |
| 1402 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1403 | (void) direct; /* not used */ |
| 1404 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1405 | /* misc one-time initializations */ |
| 1406 | one_time_init(); |
| 1407 | |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1408 | /** |
| 1409 | ** OpenGL SI stuff |
| 1410 | **/ |
| 1411 | if (!ctx->imports.malloc) { |
| 1412 | _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL); |
| 1413 | } |
| 1414 | /* exports are setup by the device driver */ |
| 1415 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1416 | ctx->DriverCtx = driver_ctx; |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1417 | ctx->Visual = *visual; |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1418 | ctx->DrawBuffer = NULL; |
| 1419 | ctx->ReadBuffer = NULL; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1420 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1421 | if (share_list) { |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 1422 | /* share state with another context */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1423 | ctx->Shared = share_list->Shared; |
| 1424 | } |
| 1425 | else { |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 1426 | /* allocate new, unshared state */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1427 | ctx->Shared = alloc_shared_state(); |
| 1428 | if (!ctx->Shared) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1429 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1430 | } |
| 1431 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1432 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1433 | ctx->Shared->RefCount++; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1434 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1435 | |
| Brian Paul | 5a2f32b | 2001-04-25 18:21:05 +0000 | [diff] [blame] | 1436 | /* Effectively bind the default textures to all texture units */ |
| 1437 | ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS; |
| 1438 | ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS; |
| 1439 | ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS; |
| 1440 | ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS; |
| 1441 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1442 | init_attrib_groups( ctx ); |
| 1443 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 1444 | if (visual->doubleBufferMode) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1445 | ctx->Color.DrawBuffer = GL_BACK; |
| 1446 | ctx->Color.DriverDrawBuffer = GL_BACK_LEFT; |
| 1447 | ctx->Color.DrawDestMask = BACK_LEFT_BIT; |
| 1448 | ctx->Pixel.ReadBuffer = GL_BACK; |
| 1449 | ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT; |
| 1450 | } |
| 1451 | else { |
| 1452 | ctx->Color.DrawBuffer = GL_FRONT; |
| 1453 | ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT; |
| 1454 | ctx->Color.DrawDestMask = FRONT_LEFT_BIT; |
| 1455 | ctx->Pixel.ReadBuffer = GL_FRONT; |
| 1456 | ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT; |
| 1457 | } |
| 1458 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1459 | if (!alloc_proxy_textures(ctx)) { |
| 1460 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1461 | return GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1462 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1463 | |
| Brian Paul | f59afc9 | 2000-05-23 23:23:00 +0000 | [diff] [blame] | 1464 | /* register the most recent extension functions with libGL */ |
| 1465 | _glapi_add_entrypoint("glTbufferMask3DFX", 553); |
| 1466 | _glapi_add_entrypoint("glCompressedTexImage3DARB", 554); |
| 1467 | _glapi_add_entrypoint("glCompressedTexImage2DARB", 555); |
| 1468 | _glapi_add_entrypoint("glCompressedTexImage1DARB", 556); |
| 1469 | _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557); |
| 1470 | _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558); |
| 1471 | _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559); |
| 1472 | _glapi_add_entrypoint("glGetCompressedTexImageARB", 560); |
| 1473 | |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1474 | /* Find the larger of Mesa's dispatch table and libGL's dispatch table. |
| 1475 | * In practice, this'll be the same for stand-alone Mesa. But for DRI |
| 1476 | * Mesa we do this to accomodate different versions of libGL and various |
| 1477 | * DRI drivers. |
| 1478 | */ |
| 1479 | dispatchSize = MAX2(_glapi_get_dispatch_table_size(), |
| 1480 | sizeof(struct _glapi_table) / sizeof(void *)); |
| 1481 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1482 | /* setup API dispatch tables */ |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1483 | ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*)); |
| 1484 | ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*)); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1485 | if (!ctx->Exec || !ctx->Save) { |
| 1486 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1487 | if (ctx->Exec) |
| Brian Paul | 2d8db39 | 2000-06-27 22:10:00 +0000 | [diff] [blame] | 1488 | FREE( ctx->Exec ); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1489 | } |
| Brian Paul | 5fb84d2 | 2000-05-24 15:04:45 +0000 | [diff] [blame] | 1490 | _mesa_init_exec_table(ctx->Exec, dispatchSize); |
| 1491 | _mesa_init_dlist_table(ctx->Save, dispatchSize); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1492 | ctx->CurrentDispatch = ctx->Exec; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1493 | |
| Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 1494 | ctx->ExecPrefersFloat = GL_FALSE; |
| 1495 | ctx->SavePrefersFloat = GL_FALSE; |
| 1496 | |
| Gareth Hughes | d8aa026 | 2001-03-11 18:49:11 +0000 | [diff] [blame] | 1497 | /* Neutral tnl module stuff */ |
| Gareth Hughes | de6a2e0 | 2001-03-11 23:49:20 +0000 | [diff] [blame] | 1498 | _mesa_init_exec_vtxfmt( ctx ); |
| Gareth Hughes | d8aa026 | 2001-03-11 18:49:11 +0000 | [diff] [blame] | 1499 | ctx->TnlModule.Current = NULL; |
| 1500 | ctx->TnlModule.SwapCount = 0; |
| 1501 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 1502 | /* Z buffer stuff */ |
| 1503 | if (ctx->Visual.depthBits == 0) { |
| 1504 | /* Special case. Even if we don't have a depth buffer we need |
| 1505 | * good values for DepthMax for Z vertex transformation purposes |
| 1506 | * and for per-fragment fog computation. |
| 1507 | */ |
| 1508 | ctx->DepthMax = 1 << 16; |
| 1509 | ctx->DepthMaxF = (GLfloat) ctx->DepthMax; |
| 1510 | } |
| 1511 | else if (ctx->Visual.depthBits < 32) { |
| 1512 | ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1; |
| 1513 | ctx->DepthMaxF = (GLfloat) ctx->DepthMax; |
| 1514 | } |
| 1515 | else { |
| 1516 | /* Special case since shift values greater than or equal to the |
| 1517 | * number of bits in the left hand expression's type are undefined. |
| 1518 | */ |
| 1519 | ctx->DepthMax = 0xffffffff; |
| 1520 | ctx->DepthMaxF = (GLfloat) ctx->DepthMax; |
| 1521 | } |
| Brian Paul | bc920f0 | 2001-05-07 16:32:51 +0000 | [diff] [blame] | 1522 | ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */ |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 1523 | |
| 1524 | |
| Brian Paul | 3b18a36 | 2000-09-26 15:27:20 +0000 | [diff] [blame] | 1525 | #if defined(MESA_TRACE) |
| Brian Paul | 9e351d5 | 2001-05-03 14:11:18 +0000 | [diff] [blame] | 1526 | ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) ); |
| Brian Paul | 45f3634 | 2000-09-05 20:28:06 +0000 | [diff] [blame] | 1527 | #if 0 |
| 1528 | /* Brian: do you want to have CreateContext fail here, |
| 1529 | or should we just trap in NewTrace (currently done)? */ |
| 1530 | if (!(ctx->TraceCtx)) { |
| 1531 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 45f3634 | 2000-09-05 20:28:06 +0000 | [diff] [blame] | 1532 | FREE( ctx->Exec ); |
| 1533 | FREE( ctx->Save ); |
| 1534 | return GL_FALSE; |
| 1535 | } |
| 1536 | #endif |
| 1537 | trInitContext(ctx->TraceCtx); |
| 1538 | |
| 1539 | ctx->TraceDispatch = (struct _glapi_table *) |
| 1540 | CALLOC(dispatchSize * sizeof(void*)); |
| 1541 | #if 0 |
| 1542 | if (!(ctx->TraceCtx)) { |
| 1543 | free_shared_state(ctx, ctx->Shared); |
| Brian Paul | 45f3634 | 2000-09-05 20:28:06 +0000 | [diff] [blame] | 1544 | FREE( ctx->Exec ); |
| 1545 | FREE( ctx->Save ); |
| 1546 | FREE( ctx->TraceCtx ); |
| 1547 | return GL_FALSE; |
| 1548 | } |
| 1549 | #endif |
| 1550 | trInitDispatch(ctx->TraceDispatch); |
| 1551 | #endif |
| 1552 | |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1553 | return GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1556 | |
| 1557 | |
| 1558 | /* |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1559 | * Allocate and initialize a GLcontext structure. |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1560 | * Input: visual - a GLvisual pointer (we copy the struct contents) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1561 | * sharelist - another context to share display lists with or NULL |
| 1562 | * driver_ctx - pointer to device driver's context state struct |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1563 | * Return: pointer to a new __GLcontextRec or NULL if error. |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1564 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1565 | GLcontext * |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1566 | _mesa_create_context( const GLvisual *visual, |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1567 | GLcontext *share_list, |
| 1568 | void *driver_ctx, |
| 1569 | GLboolean direct ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1570 | { |
| 1571 | GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) ); |
| 1572 | if (!ctx) { |
| 1573 | return NULL; |
| 1574 | } |
| Jouk Jansen | 12e875c | 2001-10-18 08:04:57 +0000 | [diff] [blame^] | 1575 | ctx->Driver.CurrentExecPrimitive = 0; |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1576 | if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1577 | return ctx; |
| 1578 | } |
| 1579 | else { |
| 1580 | FREE(ctx); |
| 1581 | return NULL; |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | /* |
| 1588 | * Free the data associated with the given context. |
| 1589 | * But don't free() the GLcontext struct itself! |
| 1590 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1591 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1592 | _mesa_free_context_data( GLcontext *ctx ) |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1593 | { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1594 | struct gl_shine_tab *s, *tmps; |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 1595 | GLuint i, j; |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1596 | |
| 1597 | /* if we're destroying the current context, unbind it first */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1598 | if (ctx == _mesa_get_current_context()) { |
| 1599 | _mesa_make_current(NULL, NULL); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1602 | _math_matrix_dtr( &ctx->ModelView ); |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 1603 | for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1604 | _math_matrix_dtr( &ctx->ModelViewStack[i] ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1605 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1606 | _math_matrix_dtr( &ctx->ProjectionMatrix ); |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 1607 | for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1608 | _math_matrix_dtr( &ctx->ProjectionStack[i] ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1609 | } |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 1610 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1611 | _math_matrix_dtr( &ctx->TextureMatrix[i] ); |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 1612 | for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1613 | _math_matrix_dtr( &ctx->TextureStack[i][j] ); |
| Brian Paul | 7fc29c5 | 2000-03-06 17:03:03 +0000 | [diff] [blame] | 1614 | } |
| 1615 | } |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1616 | |
| Brian Paul | fd28445 | 2001-07-19 15:54:34 +0000 | [diff] [blame] | 1617 | _math_matrix_dtr( &ctx->_ModelProjectMatrix ); |
| 1618 | |
| 1619 | _math_matrix_dtr(&ctx->ColorMatrix); |
| 1620 | for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) { |
| 1621 | _math_matrix_dtr(&ctx->ColorStack[j]); |
| 1622 | } |
| 1623 | |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1624 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1625 | ctx->Shared->RefCount--; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 1626 | assert(ctx->Shared->RefCount >= 0); |
| 1627 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
| 1628 | if (ctx->Shared->RefCount == 0) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1629 | /* free shared state */ |
| 1630 | free_shared_state( ctx, ctx->Shared ); |
| 1631 | } |
| 1632 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1633 | foreach_s( s, tmps, ctx->_ShineTabList ) { |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1634 | FREE( s ); |
| 1635 | } |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1636 | FREE( ctx->_ShineTabList ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1637 | |
| 1638 | /* Free proxy texture objects */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1639 | _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D ); |
| 1640 | _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D ); |
| 1641 | _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D ); |
| Brian Paul | fd28445 | 2001-07-19 15:54:34 +0000 | [diff] [blame] | 1642 | _mesa_free_texture_object( NULL, ctx->Texture.ProxyCubeMap ); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1643 | |
| 1644 | /* Free evaluator data */ |
| 1645 | if (ctx->EvalMap.Map1Vertex3.Points) |
| 1646 | FREE( ctx->EvalMap.Map1Vertex3.Points ); |
| 1647 | if (ctx->EvalMap.Map1Vertex4.Points) |
| 1648 | FREE( ctx->EvalMap.Map1Vertex4.Points ); |
| 1649 | if (ctx->EvalMap.Map1Index.Points) |
| 1650 | FREE( ctx->EvalMap.Map1Index.Points ); |
| 1651 | if (ctx->EvalMap.Map1Color4.Points) |
| 1652 | FREE( ctx->EvalMap.Map1Color4.Points ); |
| 1653 | if (ctx->EvalMap.Map1Normal.Points) |
| 1654 | FREE( ctx->EvalMap.Map1Normal.Points ); |
| 1655 | if (ctx->EvalMap.Map1Texture1.Points) |
| 1656 | FREE( ctx->EvalMap.Map1Texture1.Points ); |
| 1657 | if (ctx->EvalMap.Map1Texture2.Points) |
| 1658 | FREE( ctx->EvalMap.Map1Texture2.Points ); |
| 1659 | if (ctx->EvalMap.Map1Texture3.Points) |
| 1660 | FREE( ctx->EvalMap.Map1Texture3.Points ); |
| 1661 | if (ctx->EvalMap.Map1Texture4.Points) |
| 1662 | FREE( ctx->EvalMap.Map1Texture4.Points ); |
| 1663 | |
| 1664 | if (ctx->EvalMap.Map2Vertex3.Points) |
| 1665 | FREE( ctx->EvalMap.Map2Vertex3.Points ); |
| 1666 | if (ctx->EvalMap.Map2Vertex4.Points) |
| 1667 | FREE( ctx->EvalMap.Map2Vertex4.Points ); |
| 1668 | if (ctx->EvalMap.Map2Index.Points) |
| 1669 | FREE( ctx->EvalMap.Map2Index.Points ); |
| 1670 | if (ctx->EvalMap.Map2Color4.Points) |
| 1671 | FREE( ctx->EvalMap.Map2Color4.Points ); |
| 1672 | if (ctx->EvalMap.Map2Normal.Points) |
| 1673 | FREE( ctx->EvalMap.Map2Normal.Points ); |
| 1674 | if (ctx->EvalMap.Map2Texture1.Points) |
| 1675 | FREE( ctx->EvalMap.Map2Texture1.Points ); |
| 1676 | if (ctx->EvalMap.Map2Texture2.Points) |
| 1677 | FREE( ctx->EvalMap.Map2Texture2.Points ); |
| 1678 | if (ctx->EvalMap.Map2Texture3.Points) |
| 1679 | FREE( ctx->EvalMap.Map2Texture3.Points ); |
| 1680 | if (ctx->EvalMap.Map2Texture4.Points) |
| 1681 | FREE( ctx->EvalMap.Map2Texture4.Points ); |
| 1682 | |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1683 | _mesa_free_colortable_data( &ctx->ColorTable ); |
| 1684 | _mesa_free_colortable_data( &ctx->PostConvolutionColorTable ); |
| 1685 | _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable ); |
| 1686 | _mesa_free_colortable_data( &ctx->Texture.Palette ); |
| 1687 | |
| Brian Paul | fd28445 | 2001-07-19 15:54:34 +0000 | [diff] [blame] | 1688 | _math_matrix_dtr(&ctx->Viewport._WindowMap); |
| 1689 | |
| Brian Paul | 6975540 | 2001-02-26 23:58:12 +0000 | [diff] [blame] | 1690 | _mesa_extensions_dtr(ctx); |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1691 | |
| 1692 | FREE(ctx->Exec); |
| 1693 | FREE(ctx->Save); |
| Brian Paul | 4d053dd | 2000-01-14 04:45:47 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | /* |
| 1699 | * Destroy a GLcontext structure. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1700 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1701 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1702 | _mesa_destroy_context( GLcontext *ctx ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1703 | { |
| 1704 | if (ctx) { |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1705 | _mesa_free_context_data(ctx); |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 1706 | FREE( (void *) ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | |
| 1711 | |
| 1712 | /* |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1713 | * Copy attribute groups from one context to another. |
| 1714 | * Input: src - source context |
| 1715 | * dst - destination context |
| 1716 | * mask - bitwise OR of GL_*_BIT flags |
| 1717 | */ |
| Brian Paul | 178a1c5 | 2000-04-22 01:05:00 +0000 | [diff] [blame] | 1718 | void |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1719 | _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1720 | { |
| 1721 | if (mask & GL_ACCUM_BUFFER_BIT) { |
| 1722 | MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) ); |
| 1723 | } |
| 1724 | if (mask & GL_COLOR_BUFFER_BIT) { |
| 1725 | MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) ); |
| 1726 | } |
| 1727 | if (mask & GL_CURRENT_BIT) { |
| 1728 | MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) ); |
| 1729 | } |
| 1730 | if (mask & GL_DEPTH_BUFFER_BIT) { |
| 1731 | MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) ); |
| 1732 | } |
| 1733 | if (mask & GL_ENABLE_BIT) { |
| 1734 | /* no op */ |
| 1735 | } |
| 1736 | if (mask & GL_EVAL_BIT) { |
| 1737 | MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) ); |
| 1738 | } |
| 1739 | if (mask & GL_FOG_BIT) { |
| 1740 | MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) ); |
| 1741 | } |
| 1742 | if (mask & GL_HINT_BIT) { |
| 1743 | MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) ); |
| 1744 | } |
| 1745 | if (mask & GL_LIGHTING_BIT) { |
| 1746 | MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) ); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1747 | /* gl_reinit_light_attrib( &dst->Light ); */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1748 | } |
| 1749 | if (mask & GL_LINE_BIT) { |
| 1750 | MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) ); |
| 1751 | } |
| 1752 | if (mask & GL_LIST_BIT) { |
| 1753 | MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) ); |
| 1754 | } |
| 1755 | if (mask & GL_PIXEL_MODE_BIT) { |
| 1756 | MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) ); |
| 1757 | } |
| 1758 | if (mask & GL_POINT_BIT) { |
| 1759 | MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) ); |
| 1760 | } |
| 1761 | if (mask & GL_POLYGON_BIT) { |
| 1762 | MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) ); |
| 1763 | } |
| 1764 | if (mask & GL_POLYGON_STIPPLE_BIT) { |
| 1765 | /* Use loop instead of MEMCPY due to problem with Portland Group's |
| 1766 | * C compiler. Reported by John Stone. |
| 1767 | */ |
| 1768 | int i; |
| 1769 | for (i=0;i<32;i++) { |
| 1770 | dst->PolygonStipple[i] = src->PolygonStipple[i]; |
| 1771 | } |
| 1772 | } |
| 1773 | if (mask & GL_SCISSOR_BIT) { |
| 1774 | MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) ); |
| 1775 | } |
| 1776 | if (mask & GL_STENCIL_BUFFER_BIT) { |
| 1777 | MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) ); |
| 1778 | } |
| 1779 | if (mask & GL_TEXTURE_BIT) { |
| 1780 | MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) ); |
| 1781 | } |
| 1782 | if (mask & GL_TRANSFORM_BIT) { |
| 1783 | MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) ); |
| 1784 | } |
| 1785 | if (mask & GL_VIEWPORT_BIT) { |
| 1786 | MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) ); |
| 1787 | } |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1788 | /* XXX FIXME: Call callbacks? |
| 1789 | */ |
| 1790 | dst->NewState = _NEW_ALL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1794 | /* |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1795 | * Set the current context, binding the given frame buffer to the context. |
| 1796 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1797 | void |
| 1798 | _mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer ) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1799 | { |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1800 | _mesa_make_current2( newCtx, buffer, buffer ); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1804 | static void print_info( void ) |
| 1805 | { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1806 | fprintf(stderr, "Mesa GL_VERSION = %s\n", |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1807 | (char *) _mesa_GetString(GL_VERSION)); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1808 | fprintf(stderr, "Mesa GL_RENDERER = %s\n", |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1809 | (char *) _mesa_GetString(GL_RENDERER)); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1810 | fprintf(stderr, "Mesa GL_VENDOR = %s\n", |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1811 | (char *) _mesa_GetString(GL_VENDOR)); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1812 | fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1813 | (char *) _mesa_GetString(GL_EXTENSIONS)); |
| 1814 | #if defined(THREADS) |
| 1815 | fprintf(stderr, "Mesa thread-safe: YES\n"); |
| 1816 | #else |
| 1817 | fprintf(stderr, "Mesa thread-safe: NO\n"); |
| 1818 | #endif |
| 1819 | #if defined(USE_X86_ASM) |
| 1820 | fprintf(stderr, "Mesa x86-optimized: YES\n"); |
| 1821 | #else |
| 1822 | fprintf(stderr, "Mesa x86-optimized: NO\n"); |
| 1823 | #endif |
| davem69 | e4f84b4 | 2001-06-05 03:58:20 +0000 | [diff] [blame] | 1824 | #if defined(USE_SPARC_ASM) |
| 1825 | fprintf(stderr, "Mesa sparc-optimized: YES\n"); |
| 1826 | #else |
| 1827 | fprintf(stderr, "Mesa sparc-optimized: NO\n"); |
| 1828 | #endif |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1832 | /* |
| 1833 | * Bind the given context to the given draw-buffer and read-buffer |
| 1834 | * and make it the current context for this thread. |
| 1835 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1836 | void |
| 1837 | _mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer, |
| 1838 | GLframebuffer *readBuffer ) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1839 | { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1840 | if (MESA_VERBOSE) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1841 | fprintf(stderr, "_mesa_make_current2()\n"); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1842 | |
| Brian Paul | be3602d | 2001-02-28 00:27:48 +0000 | [diff] [blame] | 1843 | /* Check that the context's and framebuffer's visuals are compatible. |
| 1844 | * We could do a lot more checking here but this'll catch obvious |
| 1845 | * problems. |
| 1846 | */ |
| 1847 | if (newCtx && drawBuffer && readBuffer) { |
| 1848 | if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode || |
| 1849 | newCtx->Visual.redBits != drawBuffer->Visual.redBits || |
| 1850 | newCtx->Visual.depthBits != drawBuffer->Visual.depthBits || |
| 1851 | newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits || |
| 1852 | newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) { |
| 1853 | return; /* incompatible */ |
| 1854 | } |
| 1855 | } |
| 1856 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1857 | /* We call this function periodically (just here for now) in |
| 1858 | * order to detect when multithreading has begun. |
| 1859 | */ |
| 1860 | _glapi_check_multithread(); |
| 1861 | |
| Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 1862 | _glapi_set_context((void *) newCtx); |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1863 | ASSERT(_mesa_get_current_context() == newCtx); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1864 | |
| 1865 | |
| 1866 | if (!newCtx) { |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1867 | _glapi_set_dispatch(NULL); /* none current */ |
| 1868 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1869 | else { |
| 1870 | _glapi_set_dispatch(newCtx->CurrentDispatch); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1871 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1872 | if (drawBuffer && readBuffer) { |
| 1873 | /* TODO: check if newCtx and buffer's visual match??? */ |
| 1874 | newCtx->DrawBuffer = drawBuffer; |
| 1875 | newCtx->ReadBuffer = readBuffer; |
| 1876 | newCtx->NewState |= _NEW_BUFFERS; |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1877 | /* _mesa_update_state( newCtx ); */ |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1878 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1879 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1880 | if (newCtx->Driver.MakeCurrent) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1881 | newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer ); |
| 1882 | |
| 1883 | /* We can use this to help debug user's problems. Tell them to set |
| 1884 | * the MESA_INFO env variable before running their app. Then the |
| 1885 | * first time each context is made current we'll print some useful |
| 1886 | * information. |
| 1887 | */ |
| 1888 | if (newCtx->FirstTimeCurrent) { |
| 1889 | if (getenv("MESA_INFO")) { |
| 1890 | print_info(); |
| 1891 | } |
| 1892 | newCtx->FirstTimeCurrent = GL_FALSE; |
| 1893 | } |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | |
| 1898 | |
| 1899 | /* |
| 1900 | * Return current context handle for the calling thread. |
| 1901 | * This isn't the fastest way to get the current context. |
| 1902 | * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h |
| 1903 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1904 | GLcontext * |
| 1905 | _mesa_get_current_context( void ) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1906 | { |
| Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 1907 | return (GLcontext *) _glapi_get_context(); |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | /* |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1913 | * This should be called by device drivers just before they do a |
| 1914 | * swapbuffers. Any pending rendering commands will be executed. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1915 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1916 | void |
| 1917 | _mesa_swapbuffers(GLcontext *ctx) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1918 | { |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1919 | FLUSH_VERTICES( ctx, 0 ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 1923 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1924 | /* |
| 1925 | * Return pointer to this context's current API dispatch table. |
| 1926 | * It'll either be the immediate-mode execute dispatcher or the |
| 1927 | * display list compile dispatcher. |
| 1928 | */ |
| 1929 | struct _glapi_table * |
| 1930 | _mesa_get_dispatch(GLcontext *ctx) |
| 1931 | { |
| 1932 | return ctx->CurrentDispatch; |
| 1933 | } |
| 1934 | |
| 1935 | |
| 1936 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1937 | /**********************************************************************/ |
| 1938 | /***** Miscellaneous functions *****/ |
| 1939 | /**********************************************************************/ |
| 1940 | |
| 1941 | |
| 1942 | /* |
| 1943 | * This function is called when the Mesa user has stumbled into a code |
| 1944 | * path which may not be implemented fully or correctly. |
| 1945 | */ |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1946 | void _mesa_problem( const GLcontext *ctx, const char *s ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1947 | { |
| 1948 | fprintf( stderr, "Mesa implementation error: %s\n", s ); |
| Brian Paul | bb0830d | 2001-04-04 13:38:51 +0000 | [diff] [blame] | 1949 | #ifdef XF86DRI |
| 1950 | fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n"); |
| 1951 | #else |
| 1952 | fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" ); |
| 1953 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1954 | (void) ctx; |
| 1955 | } |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | /* |
| 1960 | * This is called to inform the user that he or she has tried to do |
| 1961 | * something illogical or if there's likely a bug in their program |
| 1962 | * (like enabled depth testing without a depth buffer). |
| 1963 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1964 | void |
| 1965 | _mesa_warning( const GLcontext *ctx, const char *s ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1966 | { |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1967 | (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | |
| 1971 | |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1972 | /* |
| 1973 | * Compile an error into current display list. |
| 1974 | */ |
| Brian Paul | b1394fa | 2000-09-26 20:53:53 +0000 | [diff] [blame] | 1975 | void |
| 1976 | _mesa_compile_error( GLcontext *ctx, GLenum error, const char *s ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1977 | { |
| 1978 | if (ctx->CompileFlag) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1979 | _mesa_save_error( ctx, error, s ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1980 | |
| 1981 | if (ctx->ExecuteFlag) |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1982 | _mesa_error( ctx, error, s ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 1986 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1987 | /* |
| 1988 | * This is Mesa's error handler. Normally, all that's done is the updating |
| 1989 | * of the current error value. If Mesa is compiled with -DDEBUG or if the |
| 1990 | * environment variable "MESA_DEBUG" is defined then a real error message |
| 1991 | * is printed to stderr. |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 1992 | * Input: ctx - the GL context |
| 1993 | * error - the error value |
| 1994 | * where - usually the name of function where error was detected |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1995 | */ |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 1996 | void |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1997 | _mesa_error( GLcontext *ctx, GLenum error, const char *where ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1998 | { |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 1999 | const char *debugEnv = getenv("MESA_DEBUG"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2000 | GLboolean debug; |
| 2001 | |
| 2002 | #ifdef DEBUG |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2003 | if (debugEnv && strstr(debugEnv, "silent")) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2004 | debug = GL_FALSE; |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2005 | else |
| 2006 | debug = GL_TRUE; |
| 2007 | #else |
| 2008 | if (debugEnv) |
| 2009 | debug = GL_TRUE; |
| 2010 | else |
| 2011 | debug = GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2012 | #endif |
| 2013 | |
| 2014 | if (debug) { |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2015 | const char *errstr; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2016 | switch (error) { |
| 2017 | case GL_NO_ERROR: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2018 | errstr = "GL_NO_ERROR"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | case GL_INVALID_VALUE: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2021 | errstr = "GL_INVALID_VALUE"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2022 | break; |
| 2023 | case GL_INVALID_ENUM: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2024 | errstr = "GL_INVALID_ENUM"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2025 | break; |
| 2026 | case GL_INVALID_OPERATION: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2027 | errstr = "GL_INVALID_OPERATION"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2028 | break; |
| 2029 | case GL_STACK_OVERFLOW: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2030 | errstr = "GL_STACK_OVERFLOW"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2031 | break; |
| 2032 | case GL_STACK_UNDERFLOW: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2033 | errstr = "GL_STACK_UNDERFLOW"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2034 | break; |
| 2035 | case GL_OUT_OF_MEMORY: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2036 | errstr = "GL_OUT_OF_MEMORY"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2037 | break; |
| Brian Paul | 86586aa | 2000-06-29 18:55:52 +0000 | [diff] [blame] | 2038 | case GL_TABLE_TOO_LARGE: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2039 | errstr = "GL_TABLE_TOO_LARGE"; |
| Brian Paul | 86586aa | 2000-06-29 18:55:52 +0000 | [diff] [blame] | 2040 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2041 | default: |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2042 | errstr = "unknown"; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | } |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2045 | fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
| Brian Paul | 7eb0603 | 2000-07-14 04:13:40 +0000 | [diff] [blame] | 2048 | if (ctx->ErrorValue == GL_NO_ERROR) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2049 | ctx->ErrorValue = error; |
| 2050 | } |
| 2051 | |
| 2052 | /* Call device driver's error handler, if any. This is used on the Mac. */ |
| 2053 | if (ctx->Driver.Error) { |
| 2054 | (*ctx->Driver.Error)( ctx ); |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | |
| 2059 | |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 2060 | void |
| 2061 | _mesa_Finish( void ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2062 | { |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 2063 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2064 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 2065 | if (ctx->Driver.Finish) { |
| 2066 | (*ctx->Driver.Finish)( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 2072 | void |
| 2073 | _mesa_Flush( void ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2074 | { |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 2075 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2076 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | fa9df40 | 2000-02-02 19:16:46 +0000 | [diff] [blame] | 2077 | if (ctx->Driver.Flush) { |
| 2078 | (*ctx->Driver.Flush)( ctx ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2079 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2080 | } |
| Brian Paul | 48c6a6e | 2000-09-08 21:28:04 +0000 | [diff] [blame] | 2081 | |
| 2082 | |
| 2083 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2084 | const char *_mesa_prim_name[GL_POLYGON+4] = { |
| Brian Paul | 48c6a6e | 2000-09-08 21:28:04 +0000 | [diff] [blame] | 2085 | "GL_POINTS", |
| 2086 | "GL_LINES", |
| 2087 | "GL_LINE_LOOP", |
| 2088 | "GL_LINE_STRIP", |
| 2089 | "GL_TRIANGLES", |
| 2090 | "GL_TRIANGLE_STRIP", |
| 2091 | "GL_TRIANGLE_FAN", |
| 2092 | "GL_QUADS", |
| 2093 | "GL_QUAD_STRIP", |
| 2094 | "GL_POLYGON", |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2095 | "outside begin/end", |
| 2096 | "inside unkown primitive", |
| 2097 | "unknown state" |
| Brian Paul | 48c6a6e | 2000-09-08 21:28:04 +0000 | [diff] [blame] | 2098 | }; |