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