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