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