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