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