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