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