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