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