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