| 1 | /* $Id: context.c,v 1.3 2000-03-02 13:27:30 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Mesa 3-D graphics library
|
|---|
| 5 | * Version: 3.1
|
|---|
| 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 | /* $XFree86: xc/lib/GL/mesa/src/context.c,v 1.4 1999/04/04 00:20:21 dawes Exp $ */
|
|---|
| 29 |
|
|---|
| 30 | /*
|
|---|
| 31 | * If multi-threading is enabled (-DTHREADS) then each thread has it's
|
|---|
| 32 | * own rendering context. A thread obtains the pointer to its GLcontext
|
|---|
| 33 | * with the gl_get_thread_context() function. Otherwise, the global
|
|---|
| 34 | * pointer, CC, points to the current context used by all threads in
|
|---|
| 35 | * the address space.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #ifdef __WIN32OS2__
|
|---|
| 39 | #include <os2win.h>
|
|---|
| 40 | #ifdef DIVE
|
|---|
| 41 | #include "types.h"
|
|---|
| 42 | #include "wmesadef.h"
|
|---|
| 43 | #include "mesadive.h"
|
|---|
| 44 | #endif
|
|---|
| 45 | #endif
|
|---|
| 46 |
|
|---|
| 47 | #ifdef PC_HEADER
|
|---|
| 48 | #include "all.h"
|
|---|
| 49 | #else
|
|---|
| 50 | #ifndef XFree86Server
|
|---|
| 51 | #include <assert.h>
|
|---|
| 52 | #include <math.h>
|
|---|
| 53 | #include <stdio.h>
|
|---|
| 54 | #include <stdlib.h>
|
|---|
| 55 | #include <string.h>
|
|---|
| 56 | #else
|
|---|
| 57 | #include "GL/xf86glx.h"
|
|---|
| 58 | #endif
|
|---|
| 59 | #include "accum.h"
|
|---|
| 60 | #include "alphabuf.h"
|
|---|
| 61 | #include "api.h"
|
|---|
| 62 | #include "clip.h"
|
|---|
| 63 | #include "context.h"
|
|---|
| 64 | #include "cva.h"
|
|---|
| 65 | #include "depth.h"
|
|---|
| 66 | #include "dlist.h"
|
|---|
| 67 | #include "eval.h"
|
|---|
| 68 | #include "enums.h"
|
|---|
| 69 | #include "extensions.h"
|
|---|
| 70 | #include "fog.h"
|
|---|
| 71 | #include "get.h"
|
|---|
| 72 | #include "hash.h"
|
|---|
| 73 | #include "light.h"
|
|---|
| 74 | #include "lines.h"
|
|---|
| 75 | #include "dlist.h"
|
|---|
| 76 | #include "macros.h"
|
|---|
| 77 | #include "matrix.h"
|
|---|
| 78 | #include "mmath.h"
|
|---|
| 79 | #include "pb.h"
|
|---|
| 80 | #include "pipeline.h"
|
|---|
| 81 | #include "points.h"
|
|---|
| 82 | #include "pointers.h"
|
|---|
| 83 | #include "quads.h"
|
|---|
| 84 | #include "shade.h"
|
|---|
| 85 | #include "simple_list.h"
|
|---|
| 86 | #include "stencil.h"
|
|---|
| 87 | #include "stages.h"
|
|---|
| 88 | #include "triangle.h"
|
|---|
| 89 | #include "translate.h"
|
|---|
| 90 | #include "teximage.h"
|
|---|
| 91 | #include "texobj.h"
|
|---|
| 92 | #include "texstate.h"
|
|---|
| 93 | #include "texture.h"
|
|---|
| 94 | #include "types.h"
|
|---|
| 95 | #include "varray.h"
|
|---|
| 96 | #include "vb.h"
|
|---|
| 97 | #include "vbcull.h"
|
|---|
| 98 | #include "vbfill.h"
|
|---|
| 99 | #include "vbrender.h"
|
|---|
| 100 | #include "vbxform.h"
|
|---|
| 101 | #include "vertices.h"
|
|---|
| 102 | #include "xform.h"
|
|---|
| 103 | #include "config.h"
|
|---|
| 104 | #endif
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | /*
|
|---|
| 108 | * Memory allocation functions. Called via the MALLOC, CALLOC and
|
|---|
| 109 | * FREE macros when DEBUG symbol is defined.
|
|---|
| 110 | * You might want to set breakpoints on these functions or plug in
|
|---|
| 111 | * other memory allocation functions. The Mesa sources should only
|
|---|
| 112 | * use the MALLOC and FREE macros (which could also be overriden).
|
|---|
| 113 | *
|
|---|
| 114 | * XXX these functions should probably go into a new glmemory.c file.
|
|---|
| 115 | */
|
|---|
| 116 |
|
|---|
| 117 | /*
|
|---|
| 118 | * Allocate memory (uninitialized)
|
|---|
| 119 | */
|
|---|
| 120 | void *gl_malloc(size_t bytes)
|
|---|
| 121 | {
|
|---|
| 122 | return malloc(bytes);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | /*
|
|---|
| 126 | * Allocate memory and initialize to zero.
|
|---|
| 127 | */
|
|---|
| 128 | void *gl_calloc(size_t bytes)
|
|---|
| 129 | {
|
|---|
| 130 | return calloc(1, bytes);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | /*
|
|---|
| 134 | * Free memory
|
|---|
| 135 | */
|
|---|
| 136 | void gl_free(void *ptr)
|
|---|
| 137 | {
|
|---|
| 138 | free(ptr);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | /**********************************************************************/
|
|---|
| 143 | /***** Context and Thread management *****/
|
|---|
| 144 | /**********************************************************************/
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | #ifdef THREADS
|
|---|
| 148 |
|
|---|
| 149 | #include "mthreads.h" /* Mesa platform independent threads interface*/
|
|---|
| 150 |
|
|---|
| 151 | #ifdef __WIN32OS2__
|
|---|
| 152 | //SvL: Initialize this struct
|
|---|
| 153 | static MesaTSD mesa_ctx_tsd = {-1, -1};
|
|---|
| 154 | #else
|
|---|
| 155 | static MesaTSD mesa_ctx_tsd;
|
|---|
| 156 | #endif
|
|---|
| 157 |
|
|---|
| 158 | static void mesa_ctx_thread_init() {
|
|---|
| 159 | MesaInitTSD(&mesa_ctx_tsd);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | GLcontext *gl_get_thread_context( void ) {
|
|---|
| 163 | #ifdef __WIN32OS2__
|
|---|
| 164 | return (GLcontext *) MesaGetTSD(&mesa_ctx_tsd, mesa_ctx_thread_init);
|
|---|
| 165 | #else
|
|---|
| 166 | return (GLcontext *) MesaGetTSD(&mesa_ctx_tsd);
|
|---|
| 167 | #endif
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | static void set_thread_context( GLcontext *ctx ) {
|
|---|
| 171 | MesaSetTSD(&mesa_ctx_tsd, ctx, mesa_ctx_thread_init);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 | #else
|
|---|
| 176 |
|
|---|
| 177 | /* One Current Context pointer for all threads in the address space */
|
|---|
| 178 | GLcontext *CC = NULL;
|
|---|
| 179 | struct immediate *CURRENT_INPUT = NULL;
|
|---|
| 180 |
|
|---|
| 181 | #endif /*THREADS*/
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 | /**********************************************************************/
|
|---|
| 187 | /***** Profiling functions *****/
|
|---|
| 188 | /**********************************************************************/
|
|---|
| 189 |
|
|---|
| 190 | #ifdef PROFILE
|
|---|
| 191 |
|
|---|
| 192 | #include <sys/times.h>
|
|---|
| 193 | #include <sys/param.h>
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | /*
|
|---|
| 197 | * Return system time in seconds.
|
|---|
| 198 | * NOTE: this implementation may not be very portable!
|
|---|
| 199 | */
|
|---|
| 200 | GLdouble gl_time( void )
|
|---|
| 201 | {
|
|---|
| 202 | static GLdouble prev_time = 0.0;
|
|---|
| 203 | static GLdouble time;
|
|---|
| 204 | struct tms tm;
|
|---|
| 205 | clock_t clk;
|
|---|
| 206 |
|
|---|
| 207 | clk = times(&tm);
|
|---|
| 208 |
|
|---|
| 209 | #ifdef CLK_TCK
|
|---|
| 210 | time = (double)clk / (double)CLK_TCK;
|
|---|
| 211 | #else
|
|---|
| 212 | time = (double)clk / (double)HZ;
|
|---|
| 213 | #endif
|
|---|
| 214 |
|
|---|
| 215 | if (time>prev_time) {
|
|---|
| 216 | prev_time = time;
|
|---|
| 217 | return time;
|
|---|
| 218 | }
|
|---|
| 219 | else {
|
|---|
| 220 | return prev_time;
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | /*
|
|---|
| 225 | * Reset the timing/profiling counters
|
|---|
| 226 | */
|
|---|
| 227 | static void init_timings( GLcontext *ctx )
|
|---|
| 228 | {
|
|---|
| 229 | ctx->BeginEndCount = 0;
|
|---|
| 230 | ctx->BeginEndTime = 0.0;
|
|---|
| 231 | ctx->VertexCount = 0;
|
|---|
| 232 | ctx->VertexTime = 0.0;
|
|---|
| 233 | ctx->PointCount = 0;
|
|---|
| 234 | ctx->PointTime = 0.0;
|
|---|
| 235 | ctx->LineCount = 0;
|
|---|
| 236 | ctx->LineTime = 0.0;
|
|---|
| 237 | ctx->PolygonCount = 0;
|
|---|
| 238 | ctx->PolygonTime = 0.0;
|
|---|
| 239 | ctx->ClearCount = 0;
|
|---|
| 240 | ctx->ClearTime = 0.0;
|
|---|
| 241 | ctx->SwapCount = 0;
|
|---|
| 242 | ctx->SwapTime = 0.0;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 | /*
|
|---|
| 247 | * Print the accumulated timing/profiling data.
|
|---|
| 248 | */
|
|---|
| 249 | static void print_timings( GLcontext *ctx )
|
|---|
| 250 | {
|
|---|
| 251 | GLdouble beginendrate;
|
|---|
| 252 | GLdouble vertexrate;
|
|---|
| 253 | GLdouble pointrate;
|
|---|
| 254 | GLdouble linerate;
|
|---|
| 255 | GLdouble polygonrate;
|
|---|
| 256 | GLdouble overhead;
|
|---|
| 257 | GLdouble clearrate;
|
|---|
| 258 | GLdouble swaprate;
|
|---|
| 259 | GLdouble avgvertices;
|
|---|
| 260 |
|
|---|
| 261 | if (ctx->BeginEndTime>0.0) {
|
|---|
| 262 | beginendrate = ctx->BeginEndCount / ctx->BeginEndTime;
|
|---|
| 263 | }
|
|---|
| 264 | else {
|
|---|
| 265 | beginendrate = 0.0;
|
|---|
| 266 | }
|
|---|
| 267 | if (ctx->VertexTime>0.0) {
|
|---|
| 268 | vertexrate = ctx->VertexCount / ctx->VertexTime;
|
|---|
| 269 | }
|
|---|
| 270 | else {
|
|---|
| 271 | vertexrate = 0.0;
|
|---|
| 272 | }
|
|---|
| 273 | if (ctx->PointTime>0.0) {
|
|---|
| 274 | pointrate = ctx->PointCount / ctx->PointTime;
|
|---|
| 275 | }
|
|---|
| 276 | else {
|
|---|
| 277 | pointrate = 0.0;
|
|---|
| 278 | }
|
|---|
| 279 | if (ctx->LineTime>0.0) {
|
|---|
| 280 | linerate = ctx->LineCount / ctx->LineTime;
|
|---|
| 281 | }
|
|---|
| 282 | else {
|
|---|
| 283 | linerate = 0.0;
|
|---|
| 284 | }
|
|---|
| 285 | if (ctx->PolygonTime>0.0) {
|
|---|
| 286 | polygonrate = ctx->PolygonCount / ctx->PolygonTime;
|
|---|
| 287 | }
|
|---|
| 288 | else {
|
|---|
| 289 | polygonrate = 0.0;
|
|---|
| 290 | }
|
|---|
| 291 | if (ctx->ClearTime>0.0) {
|
|---|
| 292 | clearrate = ctx->ClearCount / ctx->ClearTime;
|
|---|
| 293 | }
|
|---|
| 294 | else {
|
|---|
| 295 | clearrate = 0.0;
|
|---|
| 296 | }
|
|---|
| 297 | if (ctx->SwapTime>0.0) {
|
|---|
| 298 | swaprate = ctx->SwapCount / ctx->SwapTime;
|
|---|
| 299 | }
|
|---|
| 300 | else {
|
|---|
| 301 | swaprate = 0.0;
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | if (ctx->BeginEndCount>0) {
|
|---|
| 305 | avgvertices = (GLdouble) ctx->VertexCount / (GLdouble) ctx->BeginEndCount;
|
|---|
| 306 | }
|
|---|
| 307 | else {
|
|---|
| 308 | avgvertices = 0.0;
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | overhead = ctx->BeginEndTime - ctx->VertexTime - ctx->PointTime
|
|---|
| 312 | - ctx->LineTime - ctx->PolygonTime;
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 | printf(" Count Time (s) Rate (/s) \n");
|
|---|
| 316 | printf("--------------------------------------------------------\n");
|
|---|
| 317 | printf("glBegin/glEnd %7d %8.3f %10.3f\n",
|
|---|
| 318 | ctx->BeginEndCount, ctx->BeginEndTime, beginendrate);
|
|---|
| 319 | printf(" vertexes transformed %7d %8.3f %10.3f\n",
|
|---|
| 320 | ctx->VertexCount, ctx->VertexTime, vertexrate );
|
|---|
| 321 | printf(" points rasterized %7d %8.3f %10.3f\n",
|
|---|
| 322 | ctx->PointCount, ctx->PointTime, pointrate );
|
|---|
| 323 | printf(" lines rasterized %7d %8.3f %10.3f\n",
|
|---|
| 324 | ctx->LineCount, ctx->LineTime, linerate );
|
|---|
| 325 | printf(" polygons rasterized %7d %8.3f %10.3f\n",
|
|---|
| 326 | ctx->PolygonCount, ctx->PolygonTime, polygonrate );
|
|---|
| 327 | printf(" overhead %8.3f\n", overhead );
|
|---|
| 328 | printf("glClear %7d %8.3f %10.3f\n",
|
|---|
| 329 | ctx->ClearCount, ctx->ClearTime, clearrate );
|
|---|
| 330 | printf("SwapBuffers %7d %8.3f %10.3f\n",
|
|---|
| 331 | ctx->SwapCount, ctx->SwapTime, swaprate );
|
|---|
| 332 | printf("\n");
|
|---|
| 333 |
|
|---|
| 334 | printf("Average number of vertices per begin/end: %8.3f\n", avgvertices );
|
|---|
| 335 | }
|
|---|
| 336 | #endif
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 | /**********************************************************************/
|
|---|
| 343 | /***** Context allocation, initialization, destroying *****/
|
|---|
| 344 | /**********************************************************************/
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 | /*
|
|---|
| 348 | * This function just calls all the various one-time-init functions in Mesa.
|
|---|
| 349 | */
|
|---|
| 350 | static void one_time_init( void )
|
|---|
| 351 | {
|
|---|
| 352 | static GLboolean alreadyCalled = GL_FALSE;
|
|---|
| 353 |
|
|---|
| 354 | if (!alreadyCalled) {
|
|---|
| 355 | gl_init_clip();
|
|---|
| 356 | gl_init_eval();
|
|---|
| 357 | gl_init_fog();
|
|---|
| 358 | gl_init_math();
|
|---|
| 359 | gl_init_lists();
|
|---|
| 360 | gl_init_shade();
|
|---|
| 361 | gl_init_texture();
|
|---|
| 362 | gl_init_transformation();
|
|---|
| 363 | gl_init_translate();
|
|---|
| 364 | gl_init_vbrender();
|
|---|
| 365 | gl_init_vbxform();
|
|---|
| 366 | gl_init_vertices();
|
|---|
| 367 | #ifdef THREADS
|
|---|
| 368 | mesa_ctx_thread_init();
|
|---|
| 369 | #endif
|
|---|
| 370 | alreadyCalled = GL_TRUE;
|
|---|
| 371 | }
|
|---|
| 372 | #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
|
|---|
| 373 | fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
|
|---|
| 374 | #endif
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 | /*
|
|---|
| 379 | * Allocate and initialize a shared context state structure.
|
|---|
| 380 | */
|
|---|
| 381 | static struct gl_shared_state *alloc_shared_state( void )
|
|---|
| 382 | {
|
|---|
| 383 | GLuint d;
|
|---|
| 384 | struct gl_shared_state *ss;
|
|---|
| 385 | GLboolean outOfMemory;
|
|---|
| 386 |
|
|---|
| 387 | ss = CALLOC_STRUCT(gl_shared_state);
|
|---|
| 388 | if (!ss)
|
|---|
| 389 | return NULL;
|
|---|
| 390 |
|
|---|
| 391 | ss->DisplayList = NewHashTable();
|
|---|
| 392 |
|
|---|
| 393 | ss->TexObjects = NewHashTable();
|
|---|
| 394 |
|
|---|
| 395 | /* Default Texture objects */
|
|---|
| 396 | outOfMemory = GL_FALSE;
|
|---|
| 397 | for (d = 1 ; d <= 3 ; d++) {
|
|---|
| 398 | ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
|
|---|
| 399 | if (!ss->DefaultD[d]) {
|
|---|
| 400 | outOfMemory = GL_TRUE;
|
|---|
| 401 | break;
|
|---|
| 402 | }
|
|---|
| 403 | ss->DefaultD[d]->RefCount++; /* don't free if not in use */
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 | if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
|
|---|
| 407 | /* Ran out of memory at some point. Free everything and return NULL */
|
|---|
| 408 | if (ss->DisplayList)
|
|---|
| 409 | DeleteHashTable(ss->DisplayList);
|
|---|
| 410 | if (ss->TexObjects)
|
|---|
| 411 | DeleteHashTable(ss->TexObjects);
|
|---|
| 412 | if (ss->DefaultD[1])
|
|---|
| 413 | gl_free_texture_object(ss, ss->DefaultD[1]);
|
|---|
| 414 | if (ss->DefaultD[2])
|
|---|
| 415 | gl_free_texture_object(ss, ss->DefaultD[2]);
|
|---|
| 416 | if (ss->DefaultD[3])
|
|---|
| 417 | gl_free_texture_object(ss, ss->DefaultD[3]);
|
|---|
| 418 | FREE(ss);
|
|---|
| 419 | return NULL;
|
|---|
| 420 | }
|
|---|
| 421 | else {
|
|---|
| 422 | return ss;
|
|---|
| 423 | }
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 | /*
|
|---|
| 428 | * Deallocate a shared state context and all children structures.
|
|---|
| 429 | */
|
|---|
| 430 | static void free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
|
|---|
| 431 | {
|
|---|
| 432 | /* Free display lists */
|
|---|
| 433 | while (1) {
|
|---|
| 434 | GLuint list = HashFirstEntry(ss->DisplayList);
|
|---|
| 435 | if (list) {
|
|---|
| 436 | gl_destroy_list(ctx, list);
|
|---|
| 437 | }
|
|---|
| 438 | else {
|
|---|
| 439 | break;
|
|---|
| 440 | }
|
|---|
| 441 | }
|
|---|
| 442 | DeleteHashTable(ss->DisplayList);
|
|---|
| 443 |
|
|---|
| 444 | /* Free texture objects */
|
|---|
| 445 | while (ss->TexObjectList)
|
|---|
| 446 | {
|
|---|
| 447 | if (ctx->Driver.DeleteTexture)
|
|---|
| 448 | (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
|
|---|
| 449 | /* this function removes from linked list too! */
|
|---|
| 450 | gl_free_texture_object(ss, ss->TexObjectList);
|
|---|
| 451 | }
|
|---|
| 452 | DeleteHashTable(ss->TexObjects);
|
|---|
| 453 |
|
|---|
| 454 | FREE(ss);
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 | /*
|
|---|
| 463 | * Initialize the nth light. Note that the defaults for light 0 are
|
|---|
| 464 | * different than the other lights.
|
|---|
| 465 | */
|
|---|
| 466 | static void init_light( struct gl_light *l, GLuint n )
|
|---|
| 467 | {
|
|---|
| 468 | make_empty_list( l );
|
|---|
| 469 |
|
|---|
| 470 | ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 471 | if (n==0) {
|
|---|
| 472 | ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
|
|---|
| 473 | ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
|
|---|
| 474 | }
|
|---|
| 475 | else {
|
|---|
| 476 | ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 477 | ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 478 | }
|
|---|
| 479 | ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
|
|---|
| 480 | ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
|
|---|
| 481 | l->SpotExponent = 0.0;
|
|---|
| 482 | gl_compute_spot_exp_table( l );
|
|---|
| 483 | l->SpotCutoff = 180.0;
|
|---|
| 484 | l->CosCutoff = 0.0; /* KW: -ve values not admitted */
|
|---|
| 485 | l->ConstantAttenuation = 1.0;
|
|---|
| 486 | l->LinearAttenuation = 0.0;
|
|---|
| 487 | l->QuadraticAttenuation = 0.0;
|
|---|
| 488 | l->Enabled = GL_FALSE;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 | static void init_lightmodel( struct gl_lightmodel *lm )
|
|---|
| 494 | {
|
|---|
| 495 | ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
|
|---|
| 496 | lm->LocalViewer = GL_FALSE;
|
|---|
| 497 | lm->TwoSide = GL_FALSE;
|
|---|
| 498 | lm->ColorControl = GL_SINGLE_COLOR;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 | static void init_material( struct gl_material *m )
|
|---|
| 503 | {
|
|---|
| 504 | ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
|
|---|
| 505 | ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
|
|---|
| 506 | ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 507 | ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 508 | m->Shininess = 0.0;
|
|---|
| 509 | m->AmbientIndex = 0;
|
|---|
| 510 | m->DiffuseIndex = 1;
|
|---|
| 511 | m->SpecularIndex = 1;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 | static void init_texture_unit( GLcontext *ctx, GLuint unit )
|
|---|
| 517 | {
|
|---|
| 518 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
|
|---|
| 519 |
|
|---|
| 520 | texUnit->EnvMode = GL_MODULATE;
|
|---|
| 521 | ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 522 | texUnit->TexGenEnabled = 0;
|
|---|
| 523 | texUnit->GenModeS = GL_EYE_LINEAR;
|
|---|
| 524 | texUnit->GenModeT = GL_EYE_LINEAR;
|
|---|
| 525 | texUnit->GenModeR = GL_EYE_LINEAR;
|
|---|
| 526 | texUnit->GenModeQ = GL_EYE_LINEAR;
|
|---|
| 527 | /* Yes, these plane coefficients are correct! */
|
|---|
| 528 | ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
|
|---|
| 529 | ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
|
|---|
| 530 | ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 531 | ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 532 | ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
|
|---|
| 533 | ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
|
|---|
| 534 | ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 535 | ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 536 |
|
|---|
| 537 | texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
|
|---|
| 538 | texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
|
|---|
| 539 | texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 | static void init_fallback_arrays( GLcontext *ctx )
|
|---|
| 544 | {
|
|---|
| 545 | struct gl_client_array *cl;
|
|---|
| 546 | GLuint i;
|
|---|
| 547 |
|
|---|
| 548 | cl = &ctx->Fallback.Normal;
|
|---|
| 549 | cl->Size = 3;
|
|---|
| 550 | cl->Type = GL_FLOAT;
|
|---|
| 551 | cl->Stride = 0;
|
|---|
| 552 | cl->StrideB = 0;
|
|---|
| 553 | cl->Ptr = (void *) ctx->Current.Normal;
|
|---|
| 554 | cl->Enabled = 1;
|
|---|
| 555 |
|
|---|
| 556 | cl = &ctx->Fallback.Color;
|
|---|
| 557 | cl->Size = 4;
|
|---|
| 558 | cl->Type = GL_UNSIGNED_BYTE;
|
|---|
| 559 | cl->Stride = 0;
|
|---|
| 560 | cl->StrideB = 0;
|
|---|
| 561 | cl->Ptr = (void *) ctx->Current.ByteColor;
|
|---|
| 562 | cl->Enabled = 1;
|
|---|
| 563 |
|
|---|
| 564 | cl = &ctx->Fallback.Index;
|
|---|
| 565 | cl->Size = 1;
|
|---|
| 566 | cl->Type = GL_UNSIGNED_INT;
|
|---|
| 567 | cl->Stride = 0;
|
|---|
| 568 | cl->StrideB = 0;
|
|---|
| 569 | cl->Ptr = (void *) &ctx->Current.Index;
|
|---|
| 570 | cl->Enabled = 1;
|
|---|
| 571 |
|
|---|
| 572 | for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
|
|---|
| 573 | cl = &ctx->Fallback.TexCoord[i];
|
|---|
| 574 | cl->Size = 4;
|
|---|
| 575 | cl->Type = GL_FLOAT;
|
|---|
| 576 | cl->Stride = 0;
|
|---|
| 577 | cl->StrideB = 0;
|
|---|
| 578 | cl->Ptr = (void *) ctx->Current.Texcoord[i];
|
|---|
| 579 | cl->Enabled = 1;
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | cl = &ctx->Fallback.EdgeFlag;
|
|---|
| 583 | cl->Size = 1;
|
|---|
| 584 | cl->Type = GL_UNSIGNED_BYTE;
|
|---|
| 585 | cl->Stride = 0;
|
|---|
| 586 | cl->StrideB = 0;
|
|---|
| 587 | cl->Ptr = (void *) &ctx->Current.EdgeFlag;
|
|---|
| 588 | cl->Enabled = 1;
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | /* Initialize a 1-D evaluator map */
|
|---|
| 592 | static void init_1d_map( struct gl_1d_map *map, int n, const float *initial )
|
|---|
| 593 | {
|
|---|
| 594 | map->Order = 1;
|
|---|
| 595 | map->u1 = 0.0;
|
|---|
| 596 | map->u2 = 1.0;
|
|---|
| 597 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
|
|---|
| 598 | if (map->Points) {
|
|---|
| 599 | GLint i;
|
|---|
| 600 | for (i=0;i<n;i++)
|
|---|
| 601 | map->Points[i] = initial[i];
|
|---|
| 602 | }
|
|---|
| 603 | map->Retain = GL_FALSE;
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 | /* Initialize a 2-D evaluator map */
|
|---|
| 608 | static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
|
|---|
| 609 | {
|
|---|
| 610 | map->Uorder = 1;
|
|---|
| 611 | map->Vorder = 1;
|
|---|
| 612 | map->u1 = 0.0;
|
|---|
| 613 | map->u2 = 1.0;
|
|---|
| 614 | map->v1 = 0.0;
|
|---|
| 615 | map->v2 = 1.0;
|
|---|
| 616 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
|
|---|
| 617 | if (map->Points) {
|
|---|
| 618 | GLint i;
|
|---|
| 619 | for (i=0;i<n;i++)
|
|---|
| 620 | map->Points[i] = initial[i];
|
|---|
| 621 | }
|
|---|
| 622 | map->Retain = GL_FALSE;
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 | /*
|
|---|
| 628 | * Initialize a gl_context structure to default values.
|
|---|
| 629 | */
|
|---|
| 630 | static void initialize_context( GLcontext *ctx )
|
|---|
| 631 | {
|
|---|
| 632 | GLuint i, j;
|
|---|
| 633 |
|
|---|
| 634 | if (ctx) {
|
|---|
| 635 | /* Constants, may be overriden by device driver */
|
|---|
| 636 | ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
|
|---|
| 637 | ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
|
|---|
| 638 | ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
|
|---|
| 639 | ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
|
|---|
| 640 |
|
|---|
| 641 | /* Modelview matrix */
|
|---|
| 642 | gl_matrix_ctr( &ctx->ModelView );
|
|---|
| 643 | gl_matrix_alloc_inv( &ctx->ModelView );
|
|---|
| 644 |
|
|---|
| 645 | ctx->ModelViewStackDepth = 0;
|
|---|
| 646 | for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
|
|---|
| 647 | gl_matrix_ctr( &ctx->ModelViewStack[i] );
|
|---|
| 648 | gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
|
|---|
| 649 | }
|
|---|
| 650 |
|
|---|
| 651 | /* Projection matrix - need inv for user clipping in clip space*/
|
|---|
| 652 | gl_matrix_ctr( &ctx->ProjectionMatrix );
|
|---|
| 653 | gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
|
|---|
| 654 |
|
|---|
| 655 | gl_matrix_ctr( &ctx->ModelProjectMatrix );
|
|---|
| 656 | gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
|
|---|
| 657 | ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
|
|---|
| 658 |
|
|---|
| 659 | ctx->ProjectionStackDepth = 0;
|
|---|
| 660 | ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
|
|---|
| 661 | ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
|
|---|
| 662 |
|
|---|
| 663 | for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
|
|---|
| 664 | gl_matrix_ctr( &ctx->ProjectionStack[i] );
|
|---|
| 665 | gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
|
|---|
| 666 | }
|
|---|
| 667 |
|
|---|
| 668 | /* Texture matrix */
|
|---|
| 669 | for (i=0; i<MAX_TEXTURE_UNITS; i++) {
|
|---|
| 670 | gl_matrix_ctr( &ctx->TextureMatrix[i] );
|
|---|
| 671 | ctx->TextureStackDepth[i] = 0;
|
|---|
| 672 | for (j = 0 ; j < MAX_TEXTURE_STACK_DEPTH ; j++) {
|
|---|
| 673 | ctx->TextureStack[i][j].inv = 0;
|
|---|
| 674 | }
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | /* Accumulate buffer group */
|
|---|
| 678 | ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 679 |
|
|---|
| 680 | /* Color buffer group */
|
|---|
| 681 | ctx->Color.IndexMask = 0xffffffff;
|
|---|
| 682 | ctx->Color.ColorMask[0] = 0xff;
|
|---|
| 683 | ctx->Color.ColorMask[1] = 0xff;
|
|---|
| 684 | ctx->Color.ColorMask[2] = 0xff;
|
|---|
| 685 | ctx->Color.ColorMask[3] = 0xff;
|
|---|
| 686 | ctx->Color.SWmasking = GL_FALSE;
|
|---|
| 687 | ctx->Color.ClearIndex = 0;
|
|---|
| 688 | ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 689 | ctx->Color.DrawBuffer = GL_FRONT;
|
|---|
| 690 | ctx->Color.AlphaEnabled = GL_FALSE;
|
|---|
| 691 | ctx->Color.AlphaFunc = GL_ALWAYS;
|
|---|
| 692 | ctx->Color.AlphaRef = 0;
|
|---|
| 693 | ctx->Color.BlendEnabled = GL_FALSE;
|
|---|
| 694 | ctx->Color.BlendSrcRGB = GL_ONE;
|
|---|
| 695 | ctx->Color.BlendDstRGB = GL_ZERO;
|
|---|
| 696 | ctx->Color.BlendSrcA = GL_ONE;
|
|---|
| 697 | ctx->Color.BlendDstA = GL_ZERO;
|
|---|
| 698 | ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
|
|---|
| 699 | ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
|
|---|
| 700 | ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 701 | ctx->Color.IndexLogicOpEnabled = GL_FALSE;
|
|---|
| 702 | ctx->Color.ColorLogicOpEnabled = GL_FALSE;
|
|---|
| 703 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
|---|
| 704 | ctx->Color.LogicOp = GL_COPY;
|
|---|
| 705 | ctx->Color.DitherFlag = GL_TRUE;
|
|---|
| 706 | ctx->Color.MultiDrawBuffer = GL_FALSE;
|
|---|
| 707 |
|
|---|
| 708 | /* Current group */
|
|---|
| 709 | ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
|
|---|
| 710 | ctx->Current.Index = 1;
|
|---|
| 711 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
|---|
| 712 | ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 713 | ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 714 | ctx->Current.RasterDistance = 0.0;
|
|---|
| 715 | ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
|
|---|
| 716 | ctx->Current.RasterIndex = 1;
|
|---|
| 717 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
|---|
| 718 | ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
|
|---|
| 719 | ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
|
|---|
| 720 | ctx->Current.RasterPosValid = GL_TRUE;
|
|---|
| 721 | ctx->Current.EdgeFlag = GL_TRUE;
|
|---|
| 722 | ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
|
|---|
| 723 | ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
|
|---|
| 724 |
|
|---|
| 725 | ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
|
|---|
| 726 | VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
|
|---|
| 727 |
|
|---|
| 728 | init_fallback_arrays( ctx );
|
|---|
| 729 |
|
|---|
| 730 | /* Depth buffer group */
|
|---|
| 731 | ctx->Depth.Test = GL_FALSE;
|
|---|
| 732 | ctx->Depth.Clear = 1.0;
|
|---|
| 733 | ctx->Depth.Func = GL_LESS;
|
|---|
| 734 | ctx->Depth.Mask = GL_TRUE;
|
|---|
| 735 |
|
|---|
| 736 | /* Evaluators group */
|
|---|
| 737 | ctx->Eval.Map1Color4 = GL_FALSE;
|
|---|
| 738 | ctx->Eval.Map1Index = GL_FALSE;
|
|---|
| 739 | ctx->Eval.Map1Normal = GL_FALSE;
|
|---|
| 740 | ctx->Eval.Map1TextureCoord1 = GL_FALSE;
|
|---|
| 741 | ctx->Eval.Map1TextureCoord2 = GL_FALSE;
|
|---|
| 742 | ctx->Eval.Map1TextureCoord3 = GL_FALSE;
|
|---|
| 743 | ctx->Eval.Map1TextureCoord4 = GL_FALSE;
|
|---|
| 744 | ctx->Eval.Map1Vertex3 = GL_FALSE;
|
|---|
| 745 | ctx->Eval.Map1Vertex4 = GL_FALSE;
|
|---|
| 746 | ctx->Eval.Map2Color4 = GL_FALSE;
|
|---|
| 747 | ctx->Eval.Map2Index = GL_FALSE;
|
|---|
| 748 | ctx->Eval.Map2Normal = GL_FALSE;
|
|---|
| 749 | ctx->Eval.Map2TextureCoord1 = GL_FALSE;
|
|---|
| 750 | ctx->Eval.Map2TextureCoord2 = GL_FALSE;
|
|---|
| 751 | ctx->Eval.Map2TextureCoord3 = GL_FALSE;
|
|---|
| 752 | ctx->Eval.Map2TextureCoord4 = GL_FALSE;
|
|---|
| 753 | ctx->Eval.Map2Vertex3 = GL_FALSE;
|
|---|
| 754 | ctx->Eval.Map2Vertex4 = GL_FALSE;
|
|---|
| 755 | ctx->Eval.AutoNormal = GL_FALSE;
|
|---|
| 756 | ctx->Eval.MapGrid1un = 1;
|
|---|
| 757 | ctx->Eval.MapGrid1u1 = 0.0;
|
|---|
| 758 | ctx->Eval.MapGrid1u2 = 1.0;
|
|---|
| 759 | ctx->Eval.MapGrid2un = 1;
|
|---|
| 760 | ctx->Eval.MapGrid2vn = 1;
|
|---|
| 761 | ctx->Eval.MapGrid2u1 = 0.0;
|
|---|
| 762 | ctx->Eval.MapGrid2u2 = 1.0;
|
|---|
| 763 | ctx->Eval.MapGrid2v1 = 0.0;
|
|---|
| 764 | ctx->Eval.MapGrid2v2 = 1.0;
|
|---|
| 765 |
|
|---|
| 766 | /* Evaluator data */
|
|---|
| 767 | {
|
|---|
| 768 | static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
|
|---|
| 769 | static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
|
|---|
| 770 | static GLfloat index[1] = { 1.0 };
|
|---|
| 771 | static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
|
|---|
| 772 | static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
|
|---|
| 773 |
|
|---|
| 774 | init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
|
|---|
| 775 | init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
|
|---|
| 776 | init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
|
|---|
| 777 | init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
|
|---|
| 778 | init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
|
|---|
| 779 | init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
|
|---|
| 780 | init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
|
|---|
| 781 | init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
|
|---|
| 782 | init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
|
|---|
| 783 |
|
|---|
| 784 | init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
|
|---|
| 785 | init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
|
|---|
| 786 | init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
|
|---|
| 787 | init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
|
|---|
| 788 | init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
|
|---|
| 789 | init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
|
|---|
| 790 | init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
|
|---|
| 791 | init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
|
|---|
| 792 | init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
|
|---|
| 793 | }
|
|---|
| 794 |
|
|---|
| 795 | /* Fog group */
|
|---|
| 796 | ctx->Fog.Enabled = GL_FALSE;
|
|---|
| 797 | ctx->Fog.Mode = GL_EXP;
|
|---|
| 798 | ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 799 | ctx->Fog.Index = 0.0;
|
|---|
| 800 | ctx->Fog.Density = 1.0;
|
|---|
| 801 | ctx->Fog.Start = 0.0;
|
|---|
| 802 | ctx->Fog.End = 1.0;
|
|---|
| 803 |
|
|---|
| 804 | /* Hint group */
|
|---|
| 805 | ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
|
|---|
| 806 | ctx->Hint.PointSmooth = GL_DONT_CARE;
|
|---|
| 807 | ctx->Hint.LineSmooth = GL_DONT_CARE;
|
|---|
| 808 | ctx->Hint.PolygonSmooth = GL_DONT_CARE;
|
|---|
| 809 | ctx->Hint.Fog = GL_DONT_CARE;
|
|---|
| 810 |
|
|---|
| 811 | ctx->Hint.AllowDrawWin = GL_TRUE;
|
|---|
| 812 | ctx->Hint.AllowDrawSpn = GL_TRUE;
|
|---|
| 813 | ctx->Hint.AllowDrawMem = GL_TRUE;
|
|---|
| 814 | ctx->Hint.StrictLighting = GL_TRUE;
|
|---|
| 815 |
|
|---|
| 816 | /* Pipeline */
|
|---|
| 817 | gl_pipeline_init( ctx );
|
|---|
| 818 | gl_cva_init( ctx );
|
|---|
| 819 |
|
|---|
| 820 | /* Extensions */
|
|---|
| 821 | gl_extensions_ctr( ctx );
|
|---|
| 822 |
|
|---|
| 823 | ctx->AllowVertexCull = CLIP_CULLED_BIT;
|
|---|
| 824 |
|
|---|
| 825 | /* Lighting group */
|
|---|
| 826 | for (i=0;i<MAX_LIGHTS;i++) {
|
|---|
| 827 | init_light( &ctx->Light.Light[i], i );
|
|---|
| 828 | }
|
|---|
| 829 | make_empty_list( &ctx->Light.EnabledList );
|
|---|
| 830 |
|
|---|
| 831 | init_lightmodel( &ctx->Light.Model );
|
|---|
| 832 | init_material( &ctx->Light.Material[0] );
|
|---|
| 833 | init_material( &ctx->Light.Material[1] );
|
|---|
| 834 | ctx->Light.ShadeModel = GL_SMOOTH;
|
|---|
| 835 | ctx->Light.Enabled = GL_FALSE;
|
|---|
| 836 | ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
|
|---|
| 837 | ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
|
|---|
| 838 | ctx->Light.ColorMaterialBitmask
|
|---|
| 839 | = gl_material_bitmask( ctx,
|
|---|
| 840 | GL_FRONT_AND_BACK,
|
|---|
| 841 | GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
|
|---|
| 842 |
|
|---|
| 843 | ctx->Light.ColorMaterialEnabled = GL_FALSE;
|
|---|
| 844 |
|
|---|
| 845 | /* Line group */
|
|---|
| 846 | ctx->Line.SmoothFlag = GL_FALSE;
|
|---|
| 847 | ctx->Line.StippleFlag = GL_FALSE;
|
|---|
| 848 | ctx->Line.Width = 1.0;
|
|---|
| 849 | ctx->Line.StipplePattern = 0xffff;
|
|---|
| 850 | ctx->Line.StippleFactor = 1;
|
|---|
| 851 |
|
|---|
| 852 | /* Display List group */
|
|---|
| 853 | ctx->List.ListBase = 0;
|
|---|
| 854 |
|
|---|
| 855 | /* Pixel group */
|
|---|
| 856 | ctx->Pixel.RedBias = 0.0;
|
|---|
| 857 | ctx->Pixel.RedScale = 1.0;
|
|---|
| 858 | ctx->Pixel.GreenBias = 0.0;
|
|---|
| 859 | ctx->Pixel.GreenScale = 1.0;
|
|---|
| 860 | ctx->Pixel.BlueBias = 0.0;
|
|---|
| 861 | ctx->Pixel.BlueScale = 1.0;
|
|---|
| 862 | ctx->Pixel.AlphaBias = 0.0;
|
|---|
| 863 | ctx->Pixel.AlphaScale = 1.0;
|
|---|
| 864 | ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
|
|---|
| 865 | ctx->Pixel.DepthBias = 0.0;
|
|---|
| 866 | ctx->Pixel.DepthScale = 1.0;
|
|---|
| 867 | ctx->Pixel.IndexOffset = 0;
|
|---|
| 868 | ctx->Pixel.IndexShift = 0;
|
|---|
| 869 | ctx->Pixel.ZoomX = 1.0;
|
|---|
| 870 | ctx->Pixel.ZoomY = 1.0;
|
|---|
| 871 | ctx->Pixel.MapColorFlag = GL_FALSE;
|
|---|
| 872 | ctx->Pixel.MapStencilFlag = GL_FALSE;
|
|---|
| 873 | ctx->Pixel.MapStoSsize = 1;
|
|---|
| 874 | ctx->Pixel.MapItoIsize = 1;
|
|---|
| 875 | ctx->Pixel.MapItoRsize = 1;
|
|---|
| 876 | ctx->Pixel.MapItoGsize = 1;
|
|---|
| 877 | ctx->Pixel.MapItoBsize = 1;
|
|---|
| 878 | ctx->Pixel.MapItoAsize = 1;
|
|---|
| 879 | ctx->Pixel.MapRtoRsize = 1;
|
|---|
| 880 | ctx->Pixel.MapGtoGsize = 1;
|
|---|
| 881 | ctx->Pixel.MapBtoBsize = 1;
|
|---|
| 882 | ctx->Pixel.MapAtoAsize = 1;
|
|---|
| 883 | ctx->Pixel.MapStoS[0] = 0;
|
|---|
| 884 | ctx->Pixel.MapItoI[0] = 0;
|
|---|
| 885 | ctx->Pixel.MapItoR[0] = 0.0;
|
|---|
| 886 | ctx->Pixel.MapItoG[0] = 0.0;
|
|---|
| 887 | ctx->Pixel.MapItoB[0] = 0.0;
|
|---|
| 888 | ctx->Pixel.MapItoA[0] = 0.0;
|
|---|
| 889 | ctx->Pixel.MapItoR8[0] = 0;
|
|---|
| 890 | ctx->Pixel.MapItoG8[0] = 0;
|
|---|
| 891 | ctx->Pixel.MapItoB8[0] = 0;
|
|---|
| 892 | ctx->Pixel.MapItoA8[0] = 0;
|
|---|
| 893 | ctx->Pixel.MapRtoR[0] = 0.0;
|
|---|
| 894 | ctx->Pixel.MapGtoG[0] = 0.0;
|
|---|
| 895 | ctx->Pixel.MapBtoB[0] = 0.0;
|
|---|
| 896 | ctx->Pixel.MapAtoA[0] = 0.0;
|
|---|
| 897 |
|
|---|
| 898 | /* Point group */
|
|---|
| 899 | ctx->Point.SmoothFlag = GL_FALSE;
|
|---|
| 900 | ctx->Point.Size = 1.0;
|
|---|
| 901 | ctx->Point.Params[0] = 1.0;
|
|---|
| 902 | ctx->Point.Params[1] = 0.0;
|
|---|
| 903 | ctx->Point.Params[2] = 0.0;
|
|---|
| 904 | ctx->Point.Attenuated = GL_FALSE;
|
|---|
| 905 | ctx->Point.MinSize = 0.0;
|
|---|
| 906 | ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
|
|---|
| 907 | ctx->Point.Threshold = 1.0;
|
|---|
| 908 |
|
|---|
| 909 | /* Polygon group */
|
|---|
| 910 | ctx->Polygon.CullFlag = GL_FALSE;
|
|---|
| 911 | ctx->Polygon.CullFaceMode = GL_BACK;
|
|---|
| 912 | ctx->Polygon.FrontFace = GL_CCW;
|
|---|
| 913 | ctx->Polygon.FrontBit = 0;
|
|---|
| 914 | ctx->Polygon.FrontMode = GL_FILL;
|
|---|
| 915 | ctx->Polygon.BackMode = GL_FILL;
|
|---|
| 916 | ctx->Polygon.Unfilled = GL_FALSE;
|
|---|
| 917 | ctx->Polygon.SmoothFlag = GL_FALSE;
|
|---|
| 918 | ctx->Polygon.StippleFlag = GL_FALSE;
|
|---|
| 919 | ctx->Polygon.OffsetFactor = 0.0F;
|
|---|
| 920 | ctx->Polygon.OffsetUnits = 0.0F;
|
|---|
| 921 | ctx->Polygon.OffsetPoint = GL_FALSE;
|
|---|
| 922 | ctx->Polygon.OffsetLine = GL_FALSE;
|
|---|
| 923 | ctx->Polygon.OffsetFill = GL_FALSE;
|
|---|
| 924 |
|
|---|
| 925 | /* Polygon Stipple group */
|
|---|
| 926 | MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
|
|---|
| 927 |
|
|---|
| 928 | /* Scissor group */
|
|---|
| 929 | ctx->Scissor.Enabled = GL_FALSE;
|
|---|
| 930 | ctx->Scissor.X = 0;
|
|---|
| 931 | ctx->Scissor.Y = 0;
|
|---|
| 932 | ctx->Scissor.Width = 0;
|
|---|
| 933 | ctx->Scissor.Height = 0;
|
|---|
| 934 |
|
|---|
| 935 | /* Stencil group */
|
|---|
| 936 | ctx->Stencil.Enabled = GL_FALSE;
|
|---|
| 937 | ctx->Stencil.Function = GL_ALWAYS;
|
|---|
| 938 | ctx->Stencil.FailFunc = GL_KEEP;
|
|---|
| 939 | ctx->Stencil.ZPassFunc = GL_KEEP;
|
|---|
| 940 | ctx->Stencil.ZFailFunc = GL_KEEP;
|
|---|
| 941 | ctx->Stencil.Ref = 0;
|
|---|
| 942 | ctx->Stencil.ValueMask = STENCIL_MAX;
|
|---|
| 943 | ctx->Stencil.Clear = 0;
|
|---|
| 944 | ctx->Stencil.WriteMask = STENCIL_MAX;
|
|---|
| 945 |
|
|---|
| 946 | /* Texture group */
|
|---|
| 947 | ctx->Texture.CurrentUnit = 0; /* multitexture */
|
|---|
| 948 | ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
|
|---|
| 949 | ctx->Texture.Enabled = 0;
|
|---|
| 950 |
|
|---|
| 951 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
|---|
| 952 | init_texture_unit( ctx, i );
|
|---|
| 953 |
|
|---|
| 954 | ctx->Texture.SharedPalette = GL_FALSE;
|
|---|
| 955 | ctx->Texture.Palette[0] = 255;
|
|---|
| 956 | ctx->Texture.Palette[1] = 255;
|
|---|
| 957 | ctx->Texture.Palette[2] = 255;
|
|---|
| 958 | ctx->Texture.Palette[3] = 255;
|
|---|
| 959 | ctx->Texture.PaletteSize = 1;
|
|---|
| 960 | ctx->Texture.PaletteIntFormat = GL_RGBA;
|
|---|
| 961 | ctx->Texture.PaletteFormat = GL_RGBA;
|
|---|
| 962 |
|
|---|
| 963 | /* Transformation group */
|
|---|
| 964 | ctx->Transform.MatrixMode = GL_MODELVIEW;
|
|---|
| 965 | ctx->Transform.Normalize = GL_FALSE;
|
|---|
| 966 | ctx->Transform.RescaleNormals = GL_FALSE;
|
|---|
| 967 | for (i=0;i<MAX_CLIP_PLANES;i++) {
|
|---|
| 968 | ctx->Transform.ClipEnabled[i] = GL_FALSE;
|
|---|
| 969 | ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
|
|---|
| 970 | }
|
|---|
| 971 | ctx->Transform.AnyClip = GL_FALSE;
|
|---|
| 972 |
|
|---|
| 973 | /* Viewport group */
|
|---|
| 974 | ctx->Viewport.X = 0;
|
|---|
| 975 | ctx->Viewport.Y = 0;
|
|---|
| 976 | ctx->Viewport.Width = 0;
|
|---|
| 977 | ctx->Viewport.Height = 0;
|
|---|
| 978 | ctx->Viewport.Near = 0.0;
|
|---|
| 979 | ctx->Viewport.Far = 1.0;
|
|---|
| 980 | gl_matrix_ctr(&ctx->Viewport.WindowMap);
|
|---|
| 981 |
|
|---|
| 982 | #define Sz 10
|
|---|
| 983 | #define Tz 14
|
|---|
| 984 | ctx->Viewport.WindowMap.m[Sz] = 0.5 * DEPTH_SCALE;
|
|---|
| 985 | ctx->Viewport.WindowMap.m[Tz] = 0.5 * DEPTH_SCALE;
|
|---|
| 986 | #undef Sz
|
|---|
| 987 | #undef Tz
|
|---|
| 988 |
|
|---|
| 989 | ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
|
|---|
| 990 | ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
|
|---|
| 991 |
|
|---|
| 992 | /* Vertex arrays */
|
|---|
| 993 | ctx->Array.Vertex.Size = 4;
|
|---|
| 994 | ctx->Array.Vertex.Type = GL_FLOAT;
|
|---|
| 995 | ctx->Array.Vertex.Stride = 0;
|
|---|
| 996 | ctx->Array.Vertex.StrideB = 0;
|
|---|
| 997 | ctx->Array.Vertex.Ptr = NULL;
|
|---|
| 998 | ctx->Array.Vertex.Enabled = GL_FALSE;
|
|---|
| 999 | ctx->Array.Normal.Type = GL_FLOAT;
|
|---|
| 1000 | ctx->Array.Normal.Stride = 0;
|
|---|
| 1001 | ctx->Array.Normal.StrideB = 0;
|
|---|
| 1002 | ctx->Array.Normal.Ptr = NULL;
|
|---|
| 1003 | ctx->Array.Normal.Enabled = GL_FALSE;
|
|---|
| 1004 | ctx->Array.Color.Size = 4;
|
|---|
| 1005 | ctx->Array.Color.Type = GL_FLOAT;
|
|---|
| 1006 | ctx->Array.Color.Stride = 0;
|
|---|
| 1007 | ctx->Array.Color.StrideB = 0;
|
|---|
| 1008 | ctx->Array.Color.Ptr = NULL;
|
|---|
| 1009 | ctx->Array.Color.Enabled = GL_FALSE;
|
|---|
| 1010 | ctx->Array.Index.Type = GL_FLOAT;
|
|---|
| 1011 | ctx->Array.Index.Stride = 0;
|
|---|
| 1012 | ctx->Array.Index.StrideB = 0;
|
|---|
| 1013 | ctx->Array.Index.Ptr = NULL;
|
|---|
| 1014 | ctx->Array.Index.Enabled = GL_FALSE;
|
|---|
| 1015 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
|
|---|
| 1016 | ctx->Array.TexCoord[i].Size = 4;
|
|---|
| 1017 | ctx->Array.TexCoord[i].Type = GL_FLOAT;
|
|---|
| 1018 | ctx->Array.TexCoord[i].Stride = 0;
|
|---|
| 1019 | ctx->Array.TexCoord[i].StrideB = 0;
|
|---|
| 1020 | ctx->Array.TexCoord[i].Ptr = NULL;
|
|---|
| 1021 | ctx->Array.TexCoord[i].Enabled = GL_FALSE;
|
|---|
| 1022 | }
|
|---|
| 1023 | ctx->Array.TexCoordInterleaveFactor = 1;
|
|---|
| 1024 | ctx->Array.EdgeFlag.Stride = 0;
|
|---|
| 1025 | ctx->Array.EdgeFlag.StrideB = 0;
|
|---|
| 1026 | ctx->Array.EdgeFlag.Ptr = NULL;
|
|---|
| 1027 | ctx->Array.EdgeFlag.Enabled = GL_FALSE;
|
|---|
| 1028 | ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
|
|---|
| 1029 |
|
|---|
| 1030 | /* Pixel transfer */
|
|---|
| 1031 | ctx->Pack.Alignment = 4;
|
|---|
| 1032 | ctx->Pack.RowLength = 0;
|
|---|
| 1033 | ctx->Pack.ImageHeight = 0;
|
|---|
| 1034 | ctx->Pack.SkipPixels = 0;
|
|---|
| 1035 | ctx->Pack.SkipRows = 0;
|
|---|
| 1036 | ctx->Pack.SkipImages = 0;
|
|---|
| 1037 | ctx->Pack.SwapBytes = GL_FALSE;
|
|---|
| 1038 | ctx->Pack.LsbFirst = GL_FALSE;
|
|---|
| 1039 | ctx->Unpack.Alignment = 4;
|
|---|
| 1040 | ctx->Unpack.RowLength = 0;
|
|---|
| 1041 | ctx->Unpack.ImageHeight = 0;
|
|---|
| 1042 | ctx->Unpack.SkipPixels = 0;
|
|---|
| 1043 | ctx->Unpack.SkipRows = 0;
|
|---|
| 1044 | ctx->Unpack.SkipImages = 0;
|
|---|
| 1045 | ctx->Unpack.SwapBytes = GL_FALSE;
|
|---|
| 1046 | ctx->Unpack.LsbFirst = GL_FALSE;
|
|---|
| 1047 |
|
|---|
| 1048 | /* Feedback */
|
|---|
| 1049 | ctx->Feedback.Type = GL_2D; /* TODO: verify */
|
|---|
| 1050 | ctx->Feedback.Buffer = NULL;
|
|---|
| 1051 | ctx->Feedback.BufferSize = 0;
|
|---|
| 1052 | ctx->Feedback.Count = 0;
|
|---|
| 1053 |
|
|---|
| 1054 | /* Selection/picking */
|
|---|
| 1055 | ctx->Select.Buffer = NULL;
|
|---|
| 1056 | ctx->Select.BufferSize = 0;
|
|---|
| 1057 | ctx->Select.BufferCount = 0;
|
|---|
| 1058 | ctx->Select.Hits = 0;
|
|---|
| 1059 | ctx->Select.NameStackDepth = 0;
|
|---|
| 1060 |
|
|---|
| 1061 | /* Optimized Accum buffer */
|
|---|
| 1062 | ctx->IntegerAccumMode = GL_TRUE;
|
|---|
| 1063 | ctx->IntegerAccumScaler = 0.0;
|
|---|
| 1064 |
|
|---|
| 1065 | /* Renderer and client attribute stacks */
|
|---|
| 1066 | ctx->AttribStackDepth = 0;
|
|---|
| 1067 | ctx->ClientAttribStackDepth = 0;
|
|---|
| 1068 |
|
|---|
| 1069 | /*** Miscellaneous ***/
|
|---|
| 1070 | ctx->NewState = NEW_ALL;
|
|---|
| 1071 | ctx->RenderMode = GL_RENDER;
|
|---|
| 1072 | ctx->StippleCounter = 0;
|
|---|
| 1073 | ctx->NeedNormals = GL_FALSE;
|
|---|
| 1074 | ctx->DoViewportMapping = GL_TRUE;
|
|---|
| 1075 |
|
|---|
| 1076 | ctx->NeedEyeCoords = GL_FALSE;
|
|---|
| 1077 | ctx->NeedEyeNormals = GL_FALSE;
|
|---|
| 1078 | ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
|
|---|
| 1079 |
|
|---|
| 1080 | /* Display list */
|
|---|
| 1081 | ctx->CallDepth = 0;
|
|---|
| 1082 | ctx->ExecuteFlag = GL_TRUE;
|
|---|
| 1083 | ctx->CompileFlag = GL_FALSE;
|
|---|
| 1084 | ctx->CurrentListPtr = NULL;
|
|---|
| 1085 | ctx->CurrentBlock = NULL;
|
|---|
| 1086 | ctx->CurrentListNum = 0;
|
|---|
| 1087 | ctx->CurrentPos = 0;
|
|---|
| 1088 |
|
|---|
| 1089 | ctx->ErrorValue = (GLenum) GL_NO_ERROR;
|
|---|
| 1090 |
|
|---|
| 1091 | ctx->CatchSignals = GL_TRUE;
|
|---|
| 1092 |
|
|---|
| 1093 | /* For debug/development only */
|
|---|
| 1094 | ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
|
|---|
| 1095 | ctx->FirstTimeCurrent = GL_TRUE;
|
|---|
| 1096 |
|
|---|
| 1097 | /* Dither disable */
|
|---|
| 1098 | ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
|
|---|
| 1099 | if (ctx->NoDither) {
|
|---|
| 1100 | if (getenv("MESA_DEBUG")) {
|
|---|
| 1101 | fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
|
|---|
| 1102 | }
|
|---|
| 1103 | ctx->Color.DitherFlag = GL_FALSE;
|
|---|
| 1104 | }
|
|---|
| 1105 | }
|
|---|
| 1106 | }
|
|---|
| 1107 |
|
|---|
| 1108 |
|
|---|
| 1109 |
|
|---|
| 1110 | /*
|
|---|
| 1111 | * Allocate a new GLvisual object.
|
|---|
| 1112 | * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
|
|---|
| 1113 | * alphaFlag - alloc software alpha buffers?
|
|---|
| 1114 | * dbFlag - double buffering?
|
|---|
| 1115 | * stereoFlag - stereo buffer?
|
|---|
| 1116 | * depthFits - requested minimum bits per depth buffer value
|
|---|
| 1117 | * stencilFits - requested minimum bits per stencil buffer value
|
|---|
| 1118 | * accumFits - requested minimum bits per accum buffer component
|
|---|
| 1119 | * indexFits - number of bits per pixel if rgbFlag==GL_FALSE
|
|---|
| 1120 | * red/green/blue/alphaFits - number of bits per color component
|
|---|
| 1121 | * in frame buffer for RGB(A) mode.
|
|---|
| 1122 | * Return: pointer to new GLvisual or NULL if requested parameters can't
|
|---|
| 1123 | * be met.
|
|---|
| 1124 | */
|
|---|
| 1125 | GLvisual *gl_create_visual( GLboolean rgbFlag,
|
|---|
| 1126 | GLboolean alphaFlag,
|
|---|
| 1127 | GLboolean dbFlag,
|
|---|
| 1128 | GLboolean stereoFlag,
|
|---|
| 1129 | GLint depthBits,
|
|---|
| 1130 | GLint stencilBits,
|
|---|
| 1131 | GLint accumBits,
|
|---|
| 1132 | GLint indexBits,
|
|---|
| 1133 | GLint redBits,
|
|---|
| 1134 | GLint greenBits,
|
|---|
| 1135 | GLint blueBits,
|
|---|
| 1136 | GLint alphaBits )
|
|---|
| 1137 | {
|
|---|
| 1138 | GLvisual *vis;
|
|---|
| 1139 |
|
|---|
| 1140 | if (depthBits > (GLint) (8*sizeof(GLdepth))) {
|
|---|
| 1141 | /* can't meet depth buffer requirements */
|
|---|
| 1142 | return NULL;
|
|---|
| 1143 | }
|
|---|
| 1144 | if (stencilBits > (GLint) (8*sizeof(GLstencil))) {
|
|---|
| 1145 | /* can't meet stencil buffer requirements */
|
|---|
| 1146 | return NULL;
|
|---|
| 1147 | }
|
|---|
| 1148 | if (accumBits > (GLint) (8*sizeof(GLaccum))) {
|
|---|
| 1149 | /* can't meet accum buffer requirements */
|
|---|
| 1150 | return NULL;
|
|---|
| 1151 | }
|
|---|
| 1152 |
|
|---|
| 1153 | vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
|
|---|
| 1154 | if (!vis) {
|
|---|
| 1155 | return NULL;
|
|---|
| 1156 | }
|
|---|
| 1157 |
|
|---|
| 1158 | vis->RGBAflag = rgbFlag;
|
|---|
| 1159 | vis->DBflag = dbFlag;
|
|---|
| 1160 | vis->StereoFlag = stereoFlag;
|
|---|
| 1161 | vis->RedBits = redBits;
|
|---|
| 1162 | vis->GreenBits = greenBits;
|
|---|
| 1163 | vis->BlueBits = blueBits;
|
|---|
| 1164 | vis->AlphaBits = alphaFlag ? 8*sizeof(GLubyte) : alphaBits;
|
|---|
| 1165 |
|
|---|
| 1166 | vis->IndexBits = indexBits;
|
|---|
| 1167 | vis->DepthBits = (depthBits>0) ? 8*sizeof(GLdepth) : 0;
|
|---|
| 1168 | vis->AccumBits = (accumBits>0) ? 8*sizeof(GLaccum) : 0;
|
|---|
| 1169 | vis->StencilBits = (stencilBits>0) ? 8*sizeof(GLstencil) : 0;
|
|---|
| 1170 |
|
|---|
| 1171 | vis->SoftwareAlpha = alphaFlag;
|
|---|
| 1172 |
|
|---|
| 1173 | return vis;
|
|---|
| 1174 | }
|
|---|
| 1175 |
|
|---|
| 1176 |
|
|---|
| 1177 |
|
|---|
| 1178 | void gl_destroy_visual( GLvisual *vis )
|
|---|
| 1179 | {
|
|---|
| 1180 | FREE( vis );
|
|---|
| 1181 | }
|
|---|
| 1182 |
|
|---|
| 1183 |
|
|---|
| 1184 |
|
|---|
| 1185 | /*
|
|---|
| 1186 | * Allocate the proxy textures. If we run out of memory part way through
|
|---|
| 1187 | * the allocations clean up and return GL_FALSE.
|
|---|
| 1188 | * Return: GL_TRUE=success, GL_FALSE=failure
|
|---|
| 1189 | */
|
|---|
| 1190 | static GLboolean alloc_proxy_textures( GLcontext *ctx )
|
|---|
| 1191 | {
|
|---|
| 1192 | GLboolean out_of_memory;
|
|---|
| 1193 | GLint i;
|
|---|
| 1194 |
|
|---|
| 1195 | ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
|
|---|
| 1196 | if (!ctx->Texture.Proxy1D) {
|
|---|
| 1197 | return GL_FALSE;
|
|---|
| 1198 | }
|
|---|
| 1199 |
|
|---|
| 1200 | ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
|
|---|
| 1201 | if (!ctx->Texture.Proxy2D) {
|
|---|
| 1202 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
|---|
| 1203 | return GL_FALSE;
|
|---|
| 1204 | }
|
|---|
| 1205 |
|
|---|
| 1206 | ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
|
|---|
| 1207 | if (!ctx->Texture.Proxy3D) {
|
|---|
| 1208 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
|---|
| 1209 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
|
|---|
| 1210 | return GL_FALSE;
|
|---|
| 1211 | }
|
|---|
| 1212 |
|
|---|
| 1213 | out_of_memory = GL_FALSE;
|
|---|
| 1214 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
|
|---|
| 1215 | ctx->Texture.Proxy1D->Image[i] = gl_alloc_texture_image();
|
|---|
| 1216 | ctx->Texture.Proxy2D->Image[i] = gl_alloc_texture_image();
|
|---|
| 1217 | ctx->Texture.Proxy3D->Image[i] = gl_alloc_texture_image();
|
|---|
| 1218 | if (!ctx->Texture.Proxy1D->Image[i]
|
|---|
| 1219 | || !ctx->Texture.Proxy2D->Image[i]
|
|---|
| 1220 | || !ctx->Texture.Proxy3D->Image[i]) {
|
|---|
| 1221 | out_of_memory = GL_TRUE;
|
|---|
| 1222 | }
|
|---|
| 1223 | }
|
|---|
| 1224 | if (out_of_memory) {
|
|---|
| 1225 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
|
|---|
| 1226 | if (ctx->Texture.Proxy1D->Image[i]) {
|
|---|
| 1227 | gl_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
|
|---|
| 1228 | }
|
|---|
| 1229 | if (ctx->Texture.Proxy2D->Image[i]) {
|
|---|
| 1230 | gl_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
|
|---|
| 1231 | }
|
|---|
| 1232 | if (ctx->Texture.Proxy3D->Image[i]) {
|
|---|
| 1233 | gl_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
|
|---|
| 1234 | }
|
|---|
| 1235 | }
|
|---|
| 1236 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
|---|
| 1237 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
|
|---|
| 1238 | gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
|
|---|
| 1239 | return GL_FALSE;
|
|---|
| 1240 | }
|
|---|
| 1241 | else {
|
|---|
| 1242 | return GL_TRUE;
|
|---|
| 1243 | }
|
|---|
| 1244 | }
|
|---|
| 1245 |
|
|---|
| 1246 |
|
|---|
| 1247 |
|
|---|
| 1248 | /*
|
|---|
| 1249 | * Allocate and initialize a GLcontext structure.
|
|---|
| 1250 | * Input: visual - a GLvisual pointer
|
|---|
| 1251 | * sharelist - another context to share display lists with or NULL
|
|---|
| 1252 | * driver_ctx - pointer to device driver's context state struct
|
|---|
| 1253 | * Return: pointer to a new gl_context struct or NULL if error.
|
|---|
| 1254 | */
|
|---|
| 1255 | GLcontext *gl_create_context( GLvisual *visual,
|
|---|
| 1256 | GLcontext *share_list,
|
|---|
| 1257 | void *driver_ctx,
|
|---|
| 1258 | GLboolean direct )
|
|---|
| 1259 | {
|
|---|
| 1260 | GLcontext *ctx;
|
|---|
| 1261 | GLuint i;
|
|---|
| 1262 |
|
|---|
| 1263 | (void) direct; /* not used */
|
|---|
| 1264 |
|
|---|
| 1265 | /* do some implementation tests */
|
|---|
| 1266 | assert( sizeof(GLbyte) == 1 );
|
|---|
| 1267 | assert( sizeof(GLshort) >= 2 );
|
|---|
| 1268 | assert( sizeof(GLint) >= 4 );
|
|---|
| 1269 | assert( sizeof(GLubyte) == 1 );
|
|---|
| 1270 | assert( sizeof(GLushort) >= 2 );
|
|---|
| 1271 | assert( sizeof(GLuint) >= 4 );
|
|---|
| 1272 |
|
|---|
| 1273 | /* misc one-time initializations */
|
|---|
| 1274 | one_time_init();
|
|---|
| 1275 |
|
|---|
| 1276 | ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
|
|---|
| 1277 | if (!ctx) {
|
|---|
| 1278 | return NULL;
|
|---|
| 1279 | }
|
|---|
| 1280 |
|
|---|
| 1281 | ctx->DriverCtx = driver_ctx;
|
|---|
| 1282 | ctx->Visual = visual;
|
|---|
| 1283 | ctx->Buffer = NULL;
|
|---|
| 1284 |
|
|---|
| 1285 | ctx->VB = gl_vb_create_for_immediate( ctx );
|
|---|
| 1286 |
|
|---|
| 1287 | if (!ctx->VB) {
|
|---|
| 1288 | FREE( ctx );
|
|---|
| 1289 | return NULL;
|
|---|
| 1290 | }
|
|---|
| 1291 | ctx->input = ctx->VB->IM;
|
|---|
| 1292 |
|
|---|
| 1293 | ctx->PB = gl_alloc_pb();
|
|---|
| 1294 |
|
|---|
| 1295 | if (!ctx->PB) {
|
|---|
| 1296 | FREE( ctx->VB );
|
|---|
| 1297 | FREE( ctx );
|
|---|
| 1298 | return NULL;
|
|---|
| 1299 | }
|
|---|
| 1300 |
|
|---|
| 1301 | if (share_list) {
|
|---|
| 1302 | /* share the group of display lists of another context */
|
|---|
| 1303 | ctx->Shared = share_list->Shared;
|
|---|
| 1304 | }
|
|---|
| 1305 | else {
|
|---|
| 1306 | /* allocate new group of display lists */
|
|---|
| 1307 | ctx->Shared = alloc_shared_state();
|
|---|
| 1308 | if (!ctx->Shared) {
|
|---|
| 1309 | FREE(ctx->VB);
|
|---|
| 1310 | FREE(ctx->PB);
|
|---|
| 1311 | FREE(ctx);
|
|---|
| 1312 | return NULL;
|
|---|
| 1313 | }
|
|---|
| 1314 | }
|
|---|
| 1315 | ctx->Shared->RefCount++;
|
|---|
| 1316 |
|
|---|
| 1317 | initialize_context( ctx );
|
|---|
| 1318 | gl_reset_vb( ctx->VB );
|
|---|
| 1319 | gl_reset_input( ctx );
|
|---|
| 1320 |
|
|---|
| 1321 |
|
|---|
| 1322 | ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
|
|---|
| 1323 | make_empty_list( ctx->ShineTabList );
|
|---|
| 1324 |
|
|---|
| 1325 | for (i = 0 ; i < 10 ; i++) {
|
|---|
| 1326 | struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
|
|---|
| 1327 | s->shininess = -1;
|
|---|
| 1328 | s->refcount = 0;
|
|---|
| 1329 | insert_at_tail( ctx->ShineTabList, s );
|
|---|
| 1330 | }
|
|---|
| 1331 |
|
|---|
| 1332 | for (i = 0 ; i < 4 ; i++) {
|
|---|
| 1333 | ctx->ShineTable[i] = ctx->ShineTabList->prev;
|
|---|
| 1334 | ctx->ShineTable[i]->refcount++;
|
|---|
| 1335 | }
|
|---|
| 1336 |
|
|---|
| 1337 | if (visual->DBflag) {
|
|---|
| 1338 | ctx->Color.DrawBuffer = GL_BACK;
|
|---|
| 1339 | ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
|
|---|
| 1340 | ctx->Color.DrawDestMask = BACK_LEFT_BIT;
|
|---|
| 1341 | ctx->Pixel.ReadBuffer = GL_BACK;
|
|---|
| 1342 | ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
|
|---|
| 1343 | }
|
|---|
| 1344 | else {
|
|---|
| 1345 | ctx->Color.DrawBuffer = GL_FRONT;
|
|---|
| 1346 | ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
|
|---|
| 1347 | ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
|
|---|
| 1348 | ctx->Pixel.ReadBuffer = GL_FRONT;
|
|---|
| 1349 | ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
|
|---|
| 1350 | }
|
|---|
| 1351 |
|
|---|
| 1352 |
|
|---|
| 1353 | /* Fill in some driver defaults now.
|
|---|
| 1354 | */
|
|---|
| 1355 | ctx->Driver.AllocDepthBuffer = gl_alloc_depth_buffer;
|
|---|
| 1356 | ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float;
|
|---|
| 1357 | ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int;
|
|---|
| 1358 |
|
|---|
| 1359 |
|
|---|
| 1360 | #ifdef PROFILE
|
|---|
| 1361 | init_timings( ctx );
|
|---|
| 1362 | #endif
|
|---|
| 1363 |
|
|---|
| 1364 | #ifdef GL_VERSION_1_1
|
|---|
| 1365 | if (!alloc_proxy_textures(ctx)) {
|
|---|
| 1366 | free_shared_state(ctx, ctx->Shared);
|
|---|
| 1367 | FREE(ctx->VB);
|
|---|
| 1368 | FREE(ctx->PB);
|
|---|
| 1369 | FREE(ctx);
|
|---|
| 1370 | return NULL;
|
|---|
| 1371 | }
|
|---|
| 1372 | #endif
|
|---|
| 1373 |
|
|---|
| 1374 | gl_init_api_function_pointers( ctx );
|
|---|
| 1375 | ctx->API = ctx->Exec; /* GL_EXECUTE is default */
|
|---|
| 1376 |
|
|---|
| 1377 | return ctx;
|
|---|
| 1378 | }
|
|---|
| 1379 |
|
|---|
| 1380 | /* Just reads the config files...
|
|---|
| 1381 | */
|
|---|
| 1382 | void gl_context_initialize( GLcontext *ctx )
|
|---|
| 1383 | {
|
|---|
| 1384 | gl_read_config_file( ctx );
|
|---|
| 1385 | }
|
|---|
| 1386 |
|
|---|
| 1387 |
|
|---|
| 1388 |
|
|---|
| 1389 |
|
|---|
| 1390 | /*
|
|---|
| 1391 | * Destroy a gl_context structure.
|
|---|
| 1392 | */
|
|---|
| 1393 | void gl_destroy_context( GLcontext *ctx )
|
|---|
| 1394 | {
|
|---|
| 1395 | if (ctx) {
|
|---|
| 1396 |
|
|---|
| 1397 | GLuint i;
|
|---|
| 1398 | struct gl_shine_tab *s, *tmps;
|
|---|
| 1399 |
|
|---|
| 1400 | #ifdef PROFILE
|
|---|
| 1401 | if (getenv("MESA_PROFILE")) {
|
|---|
| 1402 | print_timings( ctx );
|
|---|
| 1403 | }
|
|---|
| 1404 | #endif
|
|---|
| 1405 |
|
|---|
| 1406 | gl_matrix_dtr( &ctx->ModelView );
|
|---|
| 1407 | for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
|
|---|
| 1408 | gl_matrix_dtr( &ctx->ModelViewStack[i] );
|
|---|
| 1409 | }
|
|---|
| 1410 | gl_matrix_dtr( &ctx->ProjectionMatrix );
|
|---|
| 1411 | for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
|
|---|
| 1412 | gl_matrix_dtr( &ctx->ProjectionStack[i] );
|
|---|
| 1413 | }
|
|---|
| 1414 |
|
|---|
| 1415 | FREE( ctx->PB );
|
|---|
| 1416 |
|
|---|
| 1417 | if(ctx->input != ctx->VB->IM)
|
|---|
| 1418 | gl_immediate_free( ctx->input );
|
|---|
| 1419 |
|
|---|
| 1420 | gl_vb_free( ctx->VB );
|
|---|
| 1421 |
|
|---|
| 1422 | ctx->Shared->RefCount--;
|
|---|
| 1423 | assert(ctx->Shared->RefCount>=0);
|
|---|
| 1424 | if (ctx->Shared->RefCount==0) {
|
|---|
| 1425 | /* free shared state */
|
|---|
| 1426 | free_shared_state( ctx, ctx->Shared );
|
|---|
| 1427 | }
|
|---|
| 1428 |
|
|---|
| 1429 | foreach_s( s, tmps, ctx->ShineTabList ) {
|
|---|
| 1430 | FREE( s );
|
|---|
| 1431 | }
|
|---|
| 1432 | FREE( ctx->ShineTabList );
|
|---|
| 1433 |
|
|---|
| 1434 | /* Free proxy texture objects */
|
|---|
| 1435 | gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
|
|---|
| 1436 | gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
|
|---|
| 1437 | gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
|
|---|
| 1438 |
|
|---|
| 1439 | /* Free evaluator data */
|
|---|
| 1440 | if (ctx->EvalMap.Map1Vertex3.Points)
|
|---|
| 1441 | FREE( ctx->EvalMap.Map1Vertex3.Points );
|
|---|
| 1442 | if (ctx->EvalMap.Map1Vertex4.Points)
|
|---|
| 1443 | FREE( ctx->EvalMap.Map1Vertex4.Points );
|
|---|
| 1444 | if (ctx->EvalMap.Map1Index.Points)
|
|---|
| 1445 | FREE( ctx->EvalMap.Map1Index.Points );
|
|---|
| 1446 | if (ctx->EvalMap.Map1Color4.Points)
|
|---|
| 1447 | FREE( ctx->EvalMap.Map1Color4.Points );
|
|---|
| 1448 | if (ctx->EvalMap.Map1Normal.Points)
|
|---|
| 1449 | FREE( ctx->EvalMap.Map1Normal.Points );
|
|---|
| 1450 | if (ctx->EvalMap.Map1Texture1.Points)
|
|---|
| 1451 | FREE( ctx->EvalMap.Map1Texture1.Points );
|
|---|
| 1452 | if (ctx->EvalMap.Map1Texture2.Points)
|
|---|
| 1453 | FREE( ctx->EvalMap.Map1Texture2.Points );
|
|---|
| 1454 | if (ctx->EvalMap.Map1Texture3.Points)
|
|---|
| 1455 | FREE( ctx->EvalMap.Map1Texture3.Points );
|
|---|
| 1456 | if (ctx->EvalMap.Map1Texture4.Points)
|
|---|
| 1457 | FREE( ctx->EvalMap.Map1Texture4.Points );
|
|---|
| 1458 |
|
|---|
| 1459 | if (ctx->EvalMap.Map2Vertex3.Points)
|
|---|
| 1460 | FREE( ctx->EvalMap.Map2Vertex3.Points );
|
|---|
| 1461 | if (ctx->EvalMap.Map2Vertex4.Points)
|
|---|
| 1462 | FREE( ctx->EvalMap.Map2Vertex4.Points );
|
|---|
| 1463 | if (ctx->EvalMap.Map2Index.Points)
|
|---|
| 1464 | FREE( ctx->EvalMap.Map2Index.Points );
|
|---|
| 1465 | if (ctx->EvalMap.Map2Color4.Points)
|
|---|
| 1466 | FREE( ctx->EvalMap.Map2Color4.Points );
|
|---|
| 1467 | if (ctx->EvalMap.Map2Normal.Points)
|
|---|
| 1468 | FREE( ctx->EvalMap.Map2Normal.Points );
|
|---|
| 1469 | if (ctx->EvalMap.Map2Texture1.Points)
|
|---|
| 1470 | FREE( ctx->EvalMap.Map2Texture1.Points );
|
|---|
| 1471 | if (ctx->EvalMap.Map2Texture2.Points)
|
|---|
| 1472 | FREE( ctx->EvalMap.Map2Texture2.Points );
|
|---|
| 1473 | if (ctx->EvalMap.Map2Texture3.Points)
|
|---|
| 1474 | FREE( ctx->EvalMap.Map2Texture3.Points );
|
|---|
| 1475 | if (ctx->EvalMap.Map2Texture4.Points)
|
|---|
| 1476 | FREE( ctx->EvalMap.Map2Texture4.Points );
|
|---|
| 1477 |
|
|---|
| 1478 | /* Free cache of immediate buffers. */
|
|---|
| 1479 | while (ctx->nr_im_queued-- > 0) {
|
|---|
| 1480 | struct immediate * next = ctx->freed_im_queue->next;
|
|---|
| 1481 | FREE( ctx->freed_im_queue );
|
|---|
| 1482 | ctx->freed_im_queue = next;
|
|---|
| 1483 | }
|
|---|
| 1484 | gl_extensions_dtr(ctx);
|
|---|
| 1485 |
|
|---|
| 1486 | FREE( (void *) ctx );
|
|---|
| 1487 |
|
|---|
| 1488 | #ifndef THREADS
|
|---|
| 1489 | if (ctx==CC) {
|
|---|
| 1490 | CC = NULL;
|
|---|
| 1491 | CURRENT_INPUT = NULL;
|
|---|
| 1492 | }
|
|---|
| 1493 | #endif
|
|---|
| 1494 |
|
|---|
| 1495 | }
|
|---|
| 1496 | }
|
|---|
| 1497 |
|
|---|
| 1498 |
|
|---|
| 1499 |
|
|---|
| 1500 | /*
|
|---|
| 1501 | * Create a new framebuffer. A GLframebuffer is a struct which
|
|---|
| 1502 | * encapsulates the depth, stencil and accum buffers and related
|
|---|
| 1503 | * parameters.
|
|---|
| 1504 | * Input: visual - a GLvisual pointer
|
|---|
| 1505 | * Return: pointer to new GLframebuffer struct or NULL if error.
|
|---|
| 1506 | */
|
|---|
| 1507 | GLframebuffer *gl_create_framebuffer( GLvisual *visual )
|
|---|
| 1508 | {
|
|---|
| 1509 | GLframebuffer *buffer;
|
|---|
| 1510 |
|
|---|
| 1511 | buffer = (GLframebuffer *) CALLOC( sizeof(GLframebuffer) );
|
|---|
| 1512 | if (!buffer) {
|
|---|
| 1513 | return NULL;
|
|---|
| 1514 | }
|
|---|
| 1515 |
|
|---|
| 1516 | buffer->Visual = visual;
|
|---|
| 1517 |
|
|---|
| 1518 | return buffer;
|
|---|
| 1519 | }
|
|---|
| 1520 |
|
|---|
| 1521 |
|
|---|
| 1522 |
|
|---|
| 1523 | /*
|
|---|
| 1524 | * Free a framebuffer struct and its buffers.
|
|---|
| 1525 | */
|
|---|
| 1526 | void gl_destroy_framebuffer( GLframebuffer *buffer )
|
|---|
| 1527 | {
|
|---|
| 1528 | if (buffer) {
|
|---|
| 1529 | if (buffer->Depth) {
|
|---|
| 1530 | FREE( buffer->Depth );
|
|---|
| 1531 | }
|
|---|
| 1532 | if (buffer->Accum) {
|
|---|
| 1533 | FREE( buffer->Accum );
|
|---|
| 1534 | }
|
|---|
| 1535 | if (buffer->Stencil) {
|
|---|
| 1536 | FREE( buffer->Stencil );
|
|---|
| 1537 | }
|
|---|
| 1538 | if (buffer->FrontLeftAlpha) {
|
|---|
| 1539 | FREE( buffer->FrontLeftAlpha );
|
|---|
| 1540 | }
|
|---|
| 1541 | if (buffer->BackLeftAlpha) {
|
|---|
| 1542 | FREE( buffer->BackLeftAlpha );
|
|---|
| 1543 | }
|
|---|
| 1544 | if (buffer->FrontRightAlpha) {
|
|---|
| 1545 | FREE( buffer->FrontRightAlpha );
|
|---|
| 1546 | }
|
|---|
| 1547 | if (buffer->BackRightAlpha) {
|
|---|
| 1548 | FREE( buffer->BackRightAlpha );
|
|---|
| 1549 | }
|
|---|
| 1550 | FREE(buffer);
|
|---|
| 1551 | }
|
|---|
| 1552 | }
|
|---|
| 1553 |
|
|---|
| 1554 |
|
|---|
| 1555 |
|
|---|
| 1556 | /*
|
|---|
| 1557 | * Set the current context, binding the given frame buffer to the context.
|
|---|
| 1558 | */
|
|---|
| 1559 | void gl_make_current( GLcontext *ctx, GLframebuffer *buffer )
|
|---|
| 1560 | {
|
|---|
| 1561 | GET_CONTEXT;
|
|---|
| 1562 |
|
|---|
| 1563 | /* Flush the old context
|
|---|
| 1564 | */
|
|---|
| 1565 | if (CC) {
|
|---|
| 1566 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(CC, "gl_make_current");
|
|---|
| 1567 | }
|
|---|
| 1568 |
|
|---|
| 1569 | #ifdef THREADS
|
|---|
| 1570 | /* TODO: unbind old buffer from context? */
|
|---|
| 1571 | set_thread_context( ctx );
|
|---|
| 1572 | #else
|
|---|
| 1573 | if (CC && CC->Buffer) {
|
|---|
| 1574 | /* unbind frame buffer from context */
|
|---|
| 1575 | CC->Buffer = NULL;
|
|---|
| 1576 | }
|
|---|
| 1577 |
|
|---|
| 1578 | CC = ctx;
|
|---|
| 1579 | if (ctx) {
|
|---|
| 1580 | SET_IMMEDIATE(ctx, ctx->input);
|
|---|
| 1581 | }
|
|---|
| 1582 | #endif
|
|---|
| 1583 |
|
|---|
| 1584 | if (ctx && buffer) {
|
|---|
| 1585 | /* TODO: check if ctx and buffer's visual match??? */
|
|---|
| 1586 | ctx->Buffer = buffer; /* Bind the frame buffer to the context*/
|
|---|
| 1587 | ctx->NewState = NEW_ALL; /* just to be safe*/
|
|---|
| 1588 | gl_update_state( ctx );
|
|---|
| 1589 | }
|
|---|
| 1590 |
|
|---|
| 1591 | /* We can use this to help debug user's problems. Tell the to set
|
|---|
| 1592 | * the MESA_INFO env variable before running their app. Then the
|
|---|
| 1593 | * first time each context is made current we'll print some useful
|
|---|
| 1594 | * information.
|
|---|
| 1595 | */
|
|---|
| 1596 | if (ctx && ctx->FirstTimeCurrent)
|
|---|
| 1597 | {
|
|---|
| 1598 | dprintf(("Mesa GL_VERSION = %s\n", (char *) gl_GetString(ctx, GL_VERSION)));
|
|---|
| 1599 | dprintf(("Mesa GL_RENDERER = %s\n", (char *) gl_GetString(ctx, GL_RENDERER)));
|
|---|
| 1600 | dprintf(("Mesa GL_VENDOR = %s\n", (char *) gl_GetString(ctx, GL_VENDOR)));
|
|---|
| 1601 | dprintf(("Mesa GL_EXTENSIONS = %s\n", (char *) gl_GetString(ctx, GL_EXTENSIONS)));
|
|---|
| 1602 |
|
|---|
| 1603 | ctx->FirstTimeCurrent = GL_FALSE;
|
|---|
| 1604 | }
|
|---|
| 1605 | }
|
|---|
| 1606 |
|
|---|
| 1607 |
|
|---|
| 1608 | /*
|
|---|
| 1609 | * Return current context handle.
|
|---|
| 1610 | */
|
|---|
| 1611 | GLcontext *gl_get_current_context( void )
|
|---|
| 1612 | {
|
|---|
| 1613 | #ifdef THREADS
|
|---|
| 1614 | return gl_get_thread_context();
|
|---|
| 1615 | #else
|
|---|
| 1616 | return CC;
|
|---|
| 1617 | #endif
|
|---|
| 1618 | }
|
|---|
| 1619 |
|
|---|
| 1620 |
|
|---|
| 1621 |
|
|---|
| 1622 | /*
|
|---|
| 1623 | * Copy attribute groups from one context to another.
|
|---|
| 1624 | * Input: src - source context
|
|---|
| 1625 | * dst - destination context
|
|---|
| 1626 | * mask - bitwise OR of GL_*_BIT flags
|
|---|
| 1627 | */
|
|---|
| 1628 | void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
|
|---|
| 1629 | {
|
|---|
| 1630 | if (mask & GL_ACCUM_BUFFER_BIT) {
|
|---|
| 1631 | MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
|
|---|
| 1632 | }
|
|---|
| 1633 | if (mask & GL_COLOR_BUFFER_BIT) {
|
|---|
| 1634 | MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
|
|---|
| 1635 | }
|
|---|
| 1636 | if (mask & GL_CURRENT_BIT) {
|
|---|
| 1637 | MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
|
|---|
| 1638 | }
|
|---|
| 1639 | if (mask & GL_DEPTH_BUFFER_BIT) {
|
|---|
| 1640 | MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
|
|---|
| 1641 | }
|
|---|
| 1642 | if (mask & GL_ENABLE_BIT) {
|
|---|
| 1643 | /* no op */
|
|---|
| 1644 | }
|
|---|
| 1645 | if (mask & GL_EVAL_BIT) {
|
|---|
| 1646 | MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
|
|---|
| 1647 | }
|
|---|
| 1648 | if (mask & GL_FOG_BIT) {
|
|---|
| 1649 | MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
|
|---|
| 1650 | }
|
|---|
| 1651 | if (mask & GL_HINT_BIT) {
|
|---|
| 1652 | MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
|
|---|
| 1653 | }
|
|---|
| 1654 | if (mask & GL_LIGHTING_BIT) {
|
|---|
| 1655 | MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
|
|---|
| 1656 | /* gl_reinit_light_attrib( &dst->Light ); */
|
|---|
| 1657 | }
|
|---|
| 1658 | if (mask & GL_LINE_BIT) {
|
|---|
| 1659 | MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
|
|---|
| 1660 | }
|
|---|
| 1661 | if (mask & GL_LIST_BIT) {
|
|---|
| 1662 | MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
|
|---|
| 1663 | }
|
|---|
| 1664 | if (mask & GL_PIXEL_MODE_BIT) {
|
|---|
| 1665 | MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
|
|---|
| 1666 | }
|
|---|
| 1667 | if (mask & GL_POINT_BIT) {
|
|---|
| 1668 | MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
|
|---|
| 1669 | }
|
|---|
| 1670 | if (mask & GL_POLYGON_BIT) {
|
|---|
| 1671 | MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
|
|---|
| 1672 | }
|
|---|
| 1673 | if (mask & GL_POLYGON_STIPPLE_BIT) {
|
|---|
| 1674 | #ifdef __WIN32OS2__
|
|---|
| 1675 | MEMCPY( &dst->PolygonStipple, &src->PolygonStipple, 32*sizeof(GLint) );
|
|---|
| 1676 | #else
|
|---|
| 1677 | /* Use loop instead of MEMCPY due to problem with Portland Group's
|
|---|
| 1678 | * C compiler. Reported by John Stone.
|
|---|
| 1679 | */
|
|---|
| 1680 | int i;
|
|---|
| 1681 | for (i=0;i<32;i++) {
|
|---|
| 1682 | dst->PolygonStipple[i] = src->PolygonStipple[i];
|
|---|
| 1683 | }
|
|---|
| 1684 | #endif
|
|---|
| 1685 | }
|
|---|
| 1686 | if (mask & GL_SCISSOR_BIT) {
|
|---|
| 1687 | MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
|
|---|
| 1688 | }
|
|---|
| 1689 | if (mask & GL_STENCIL_BUFFER_BIT) {
|
|---|
| 1690 | MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
|
|---|
| 1691 | }
|
|---|
| 1692 | if (mask & GL_TEXTURE_BIT) {
|
|---|
| 1693 | MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
|
|---|
| 1694 | }
|
|---|
| 1695 | if (mask & GL_TRANSFORM_BIT) {
|
|---|
| 1696 | MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
|
|---|
| 1697 | }
|
|---|
| 1698 | if (mask & GL_VIEWPORT_BIT) {
|
|---|
| 1699 | MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
|
|---|
| 1700 | }
|
|---|
| 1701 | }
|
|---|
| 1702 |
|
|---|
| 1703 |
|
|---|
| 1704 |
|
|---|
| 1705 | /*
|
|---|
| 1706 | * Someday a GLS library or OpenGL-like debugger may call this function
|
|---|
| 1707 | * to register it's own set of API entry points.
|
|---|
| 1708 | * Input: ctx - the context to set API pointers for
|
|---|
| 1709 | * api - if NULL, restore original API pointers
|
|---|
| 1710 | * else, set API function table to this table.
|
|---|
| 1711 | */
|
|---|
| 1712 | void gl_set_api_table( GLcontext *ctx, const struct gl_api_table *api )
|
|---|
| 1713 | {
|
|---|
| 1714 | if (api) {
|
|---|
| 1715 | MEMCPY( &ctx->API, api, sizeof(struct gl_api_table) );
|
|---|
| 1716 | }
|
|---|
| 1717 | else {
|
|---|
| 1718 | MEMCPY( &ctx->API, &ctx->Exec, sizeof(struct gl_api_table) );
|
|---|
| 1719 | }
|
|---|
| 1720 | }
|
|---|
| 1721 |
|
|---|
| 1722 |
|
|---|
| 1723 |
|
|---|
| 1724 |
|
|---|
| 1725 | /**********************************************************************/
|
|---|
| 1726 | /***** Miscellaneous functions *****/
|
|---|
| 1727 | /**********************************************************************/
|
|---|
| 1728 |
|
|---|
| 1729 |
|
|---|
| 1730 | /*
|
|---|
| 1731 | * This function is called when the Mesa user has stumbled into a code
|
|---|
| 1732 | * path which may not be implemented fully or correctly.
|
|---|
| 1733 | */
|
|---|
| 1734 | void gl_problem( const GLcontext *ctx, const char *s )
|
|---|
| 1735 | {
|
|---|
| 1736 | #ifdef __WIN32OS2__
|
|---|
| 1737 | dprintf(("OPENGL32: Mesa implementation error: %s\n", s) );
|
|---|
| 1738 | dprintf(("OPENGL32: Report to J.vandenHorn@fibre.a2000.nl\n" ));
|
|---|
| 1739 | #else
|
|---|
| 1740 | fprintf( stderr, "Mesa implementation error: %s\n", s );
|
|---|
| 1741 | fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" );
|
|---|
| 1742 | (void) ctx;
|
|---|
| 1743 | #endif
|
|---|
| 1744 | }
|
|---|
| 1745 |
|
|---|
| 1746 |
|
|---|
| 1747 |
|
|---|
| 1748 | /*
|
|---|
| 1749 | * This is called to inform the user that he or she has tried to do
|
|---|
| 1750 | * something illogical or if there's likely a bug in their program
|
|---|
| 1751 | * (like enabled depth testing without a depth buffer).
|
|---|
| 1752 | */
|
|---|
| 1753 | void gl_warning( const GLcontext *ctx, const char *s )
|
|---|
| 1754 | {
|
|---|
| 1755 | GLboolean debug;
|
|---|
| 1756 | #ifdef DEBUG
|
|---|
| 1757 | debug = GL_TRUE;
|
|---|
| 1758 | #else
|
|---|
| 1759 | if (getenv("MESA_DEBUG")) {
|
|---|
| 1760 | debug = GL_TRUE;
|
|---|
| 1761 | }
|
|---|
| 1762 | else {
|
|---|
| 1763 | debug = GL_FALSE;
|
|---|
| 1764 | }
|
|---|
| 1765 | #endif
|
|---|
| 1766 | #ifdef __WIN32OS2__
|
|---|
| 1767 | dprintf(("OPENGL32: Mesa warning: %s\n", s ));
|
|---|
| 1768 | #else
|
|---|
| 1769 | if (debug) {
|
|---|
| 1770 | fprintf( stderr, "Mesa warning: %s\n", s );
|
|---|
| 1771 | }
|
|---|
| 1772 | #endif
|
|---|
| 1773 | (void) ctx;
|
|---|
| 1774 | }
|
|---|
| 1775 |
|
|---|
| 1776 |
|
|---|
| 1777 |
|
|---|
| 1778 | void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
|
|---|
| 1779 | {
|
|---|
| 1780 | if (ctx->CompileFlag)
|
|---|
| 1781 | gl_save_error( ctx, error, s );
|
|---|
| 1782 |
|
|---|
| 1783 | if (ctx->ExecuteFlag)
|
|---|
| 1784 | gl_error( ctx, error, s );
|
|---|
| 1785 | }
|
|---|
| 1786 |
|
|---|
| 1787 |
|
|---|
| 1788 | /*
|
|---|
| 1789 | * This is Mesa's error handler. Normally, all that's done is the updating
|
|---|
| 1790 | * of the current error value. If Mesa is compiled with -DDEBUG or if the
|
|---|
| 1791 | * environment variable "MESA_DEBUG" is defined then a real error message
|
|---|
| 1792 | * is printed to stderr.
|
|---|
| 1793 | * Input: error - the error value
|
|---|
| 1794 | * s - a diagnostic string
|
|---|
| 1795 | */
|
|---|
| 1796 | void gl_error( GLcontext *ctx, GLenum error, const char *s )
|
|---|
| 1797 | {
|
|---|
| 1798 | GLboolean debug;
|
|---|
| 1799 |
|
|---|
| 1800 | #ifdef DEBUG
|
|---|
| 1801 | debug = GL_TRUE;
|
|---|
| 1802 | #else
|
|---|
| 1803 | if (getenv("MESA_DEBUG")) {
|
|---|
| 1804 | debug = GL_TRUE;
|
|---|
| 1805 | }
|
|---|
| 1806 | else {
|
|---|
| 1807 | debug = GL_FALSE;
|
|---|
| 1808 | }
|
|---|
| 1809 | #endif
|
|---|
| 1810 | #ifdef __WIN32OS2__
|
|---|
| 1811 | {
|
|---|
| 1812 | #else
|
|---|
| 1813 | if (debug) {
|
|---|
| 1814 | #endif
|
|---|
| 1815 | char errstr[1000];
|
|---|
| 1816 |
|
|---|
| 1817 | switch (error) {
|
|---|
| 1818 | case GL_NO_ERROR:
|
|---|
| 1819 | strcpy( errstr, "GL_NO_ERROR" );
|
|---|
| 1820 | break;
|
|---|
| 1821 | case GL_INVALID_VALUE:
|
|---|
| 1822 | strcpy( errstr, "GL_INVALID_VALUE" );
|
|---|
| 1823 | break;
|
|---|
| 1824 | case GL_INVALID_ENUM:
|
|---|
| 1825 | strcpy( errstr, "GL_INVALID_ENUM" );
|
|---|
| 1826 | break;
|
|---|
| 1827 | case GL_INVALID_OPERATION:
|
|---|
| 1828 | strcpy( errstr, "GL_INVALID_OPERATION" );
|
|---|
| 1829 | break;
|
|---|
| 1830 | case GL_STACK_OVERFLOW:
|
|---|
| 1831 | strcpy( errstr, "GL_STACK_OVERFLOW" );
|
|---|
| 1832 | break;
|
|---|
| 1833 | case GL_STACK_UNDERFLOW:
|
|---|
| 1834 | strcpy( errstr, "GL_STACK_UNDERFLOW" );
|
|---|
| 1835 | break;
|
|---|
| 1836 | case GL_OUT_OF_MEMORY:
|
|---|
| 1837 | strcpy( errstr, "GL_OUT_OF_MEMORY" );
|
|---|
| 1838 | break;
|
|---|
| 1839 | default:
|
|---|
| 1840 | strcpy( errstr, "unknown" );
|
|---|
| 1841 | break;
|
|---|
| 1842 | }
|
|---|
| 1843 | #ifdef __WIN32OS2__
|
|---|
| 1844 | dprintf( ("OPENGL32: Mesa user error: %s in %s\n", errstr, s ));
|
|---|
| 1845 | #else
|
|---|
| 1846 | fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
|
|---|
| 1847 | #endif
|
|---|
| 1848 | }
|
|---|
| 1849 |
|
|---|
| 1850 | if (ctx->ErrorValue==GL_NO_ERROR) {
|
|---|
| 1851 | ctx->ErrorValue = error;
|
|---|
| 1852 | }
|
|---|
| 1853 |
|
|---|
| 1854 | /* Call device driver's error handler, if any. This is used on the Mac. */
|
|---|
| 1855 | if (ctx->Driver.Error) {
|
|---|
| 1856 | (*ctx->Driver.Error)( ctx );
|
|---|
| 1857 | }
|
|---|
| 1858 | }
|
|---|
| 1859 |
|
|---|
| 1860 |
|
|---|
| 1861 |
|
|---|
| 1862 | /*
|
|---|
| 1863 | * Execute a glGetError command
|
|---|
| 1864 | */
|
|---|
| 1865 | GLenum gl_GetError( GLcontext *ctx )
|
|---|
| 1866 | {
|
|---|
| 1867 | GLenum e = ctx->ErrorValue;
|
|---|
| 1868 |
|
|---|
| 1869 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL( ctx, "glGetError", (GLenum) 0);
|
|---|
| 1870 |
|
|---|
| 1871 | if (MESA_VERBOSE & VERBOSE_API)
|
|---|
| 1872 | fprintf(stderr, "glGetError <-- %s\n", gl_lookup_enum_by_nr(e));
|
|---|
| 1873 |
|
|---|
| 1874 | ctx->ErrorValue = (GLenum) GL_NO_ERROR;
|
|---|
| 1875 | return e;
|
|---|
| 1876 | }
|
|---|
| 1877 |
|
|---|
| 1878 |
|
|---|
| 1879 |
|
|---|
| 1880 | void gl_ResizeBuffersMESA( GLcontext *ctx )
|
|---|
| 1881 | {
|
|---|
| 1882 | GLuint buf_width, buf_height;
|
|---|
| 1883 |
|
|---|
| 1884 | if (MESA_VERBOSE & VERBOSE_API)
|
|---|
| 1885 | fprintf(stderr, "glResizeBuffersMESA\n");
|
|---|
| 1886 |
|
|---|
| 1887 | /* ask device driver for size of output buffer */
|
|---|
| 1888 | (*ctx->Driver.GetBufferSize)( ctx, &buf_width, &buf_height );
|
|---|
| 1889 |
|
|---|
| 1890 | dprintf(("OPENGL32: gl_ResizeBuffersMESA - new w/h %d/%d\n",buf_width,buf_height));
|
|---|
| 1891 |
|
|---|
| 1892 | /* see if size of device driver's color buffer (window) has changed */
|
|---|
| 1893 | if (ctx->Buffer->Width == (GLint) buf_width &&
|
|---|
| 1894 | ctx->Buffer->Height == (GLint) buf_height)
|
|---|
| 1895 | return;
|
|---|
| 1896 |
|
|---|
| 1897 | ctx->NewState |= NEW_RASTER_OPS; /* to update scissor / window bounds*/
|
|---|
| 1898 |
|
|---|
| 1899 | /* save buffer size */
|
|---|
| 1900 | ctx->Buffer->Width = buf_width;
|
|---|
| 1901 | ctx->Buffer->Height = buf_height;
|
|---|
| 1902 |
|
|---|
| 1903 | /* Reallocate other buffers if needed. */
|
|---|
| 1904 | if (ctx->Visual->DepthBits>0) {
|
|---|
| 1905 | /* reallocate depth buffer */
|
|---|
| 1906 | (*ctx->Driver.AllocDepthBuffer)( ctx );
|
|---|
| 1907 | }
|
|---|
| 1908 | if (ctx->Visual->StencilBits>0) {
|
|---|
| 1909 | /* reallocate stencil buffer */
|
|---|
| 1910 | gl_alloc_stencil_buffer( ctx );
|
|---|
| 1911 | }
|
|---|
| 1912 | if (ctx->Visual->AccumBits>0) {
|
|---|
| 1913 | /* reallocate accum buffer */
|
|---|
| 1914 | gl_alloc_accum_buffer( ctx );
|
|---|
| 1915 | }
|
|---|
| 1916 | if (ctx->Visual->SoftwareAlpha) {
|
|---|
| 1917 | gl_alloc_alpha_buffers( ctx );
|
|---|
| 1918 | }
|
|---|
| 1919 |
|
|---|
| 1920 | #ifdef DIVE
|
|---|
| 1921 | DiveResizeBuffers(ctx->Buffer->Width,ctx->Buffer->Height);
|
|---|
| 1922 | #endif
|
|---|
| 1923 | }
|
|---|
| 1924 |
|
|---|
| 1925 |
|
|---|
| 1926 |
|
|---|
| 1927 |
|
|---|
| 1928 | /**********************************************************************/
|
|---|
| 1929 | /***** State update logic *****/
|
|---|
| 1930 | /**********************************************************************/
|
|---|
| 1931 |
|
|---|
| 1932 |
|
|---|
| 1933 | /*
|
|---|
| 1934 | * Since the device driver may or may not support pixel logic ops we
|
|---|
| 1935 | * have to make some extensive tests to determine whether or not
|
|---|
| 1936 | * software-implemented logic operations have to be used.
|
|---|
| 1937 | */
|
|---|
| 1938 | static void update_pixel_logic( GLcontext *ctx )
|
|---|
| 1939 | {
|
|---|
| 1940 | if (ctx->Visual->RGBAflag) {
|
|---|
| 1941 | /* RGBA mode blending w/ Logic Op */
|
|---|
| 1942 | if (ctx->Color.ColorLogicOpEnabled) {
|
|---|
| 1943 | if (ctx->Driver.LogicOp
|
|---|
| 1944 | && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) {
|
|---|
| 1945 | /* Device driver can do logic, don't have to do it in software */
|
|---|
| 1946 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
|---|
| 1947 | }
|
|---|
| 1948 | else {
|
|---|
| 1949 | /* Device driver can't do logic op so we do it in software */
|
|---|
| 1950 | ctx->Color.SWLogicOpEnabled = GL_TRUE;
|
|---|
| 1951 | }
|
|---|
| 1952 | }
|
|---|
| 1953 | else {
|
|---|
| 1954 | /* no logic op */
|
|---|
| 1955 | if (ctx->Driver.LogicOp) {
|
|---|
| 1956 | (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY );
|
|---|
| 1957 | }
|
|---|
| 1958 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
|---|
| 1959 | }
|
|---|
| 1960 | }
|
|---|
| 1961 | else {
|
|---|
| 1962 | /* CI mode Logic Op */
|
|---|
| 1963 | if (ctx->Color.IndexLogicOpEnabled) {
|
|---|
| 1964 | if (ctx->Driver.LogicOp
|
|---|
| 1965 | && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) {
|
|---|
| 1966 | /* Device driver can do logic, don't have to do it in software */
|
|---|
| 1967 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
|---|
| 1968 | }
|
|---|
| 1969 | else {
|
|---|
| 1970 | /* Device driver can't do logic op so we do it in software */
|
|---|
| 1971 | ctx->Color.SWLogicOpEnabled = GL_TRUE;
|
|---|
| 1972 | }
|
|---|
| 1973 | }
|
|---|
| 1974 | else {
|
|---|
| 1975 | /* no logic op */
|
|---|
| 1976 | if (ctx->Driver.LogicOp) {
|
|---|
| 1977 | (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY );
|
|---|
| 1978 | }
|
|---|
| 1979 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
|---|
| 1980 | }
|
|---|
| 1981 | }
|
|---|
| 1982 | }
|
|---|
| 1983 |
|
|---|
| 1984 |
|
|---|
| 1985 |
|
|---|
| 1986 | /*
|
|---|
| 1987 | * Check if software implemented RGBA or Color Index masking is needed.
|
|---|
| 1988 | */
|
|---|
| 1989 | static void update_pixel_masking( GLcontext *ctx )
|
|---|
| 1990 | {
|
|---|
| 1991 | if (ctx->Visual->RGBAflag) {
|
|---|
| 1992 | GLuint *colorMask = (GLuint *) ctx->Color.ColorMask;
|
|---|
| 1993 | if (*colorMask == 0xffffffff) {
|
|---|
| 1994 | /* disable masking */
|
|---|
| 1995 | if (ctx->Driver.ColorMask) {
|
|---|
| 1996 | (void) (*ctx->Driver.ColorMask)( ctx, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
|
|---|
| 1997 | }
|
|---|
| 1998 | ctx->Color.SWmasking = GL_FALSE;
|
|---|
| 1999 | }
|
|---|
| 2000 | else {
|
|---|
| 2001 | /* Ask driver to do color masking, if it can't then
|
|---|
| 2002 | * do it in software
|
|---|
| 2003 | */
|
|---|
| 2004 | GLboolean red = ctx->Color.ColorMask[RCOMP] ? GL_TRUE : GL_FALSE;
|
|---|
| 2005 | GLboolean green = ctx->Color.ColorMask[GCOMP] ? GL_TRUE : GL_FALSE;
|
|---|
| 2006 | GLboolean blue = ctx->Color.ColorMask[BCOMP] ? GL_TRUE : GL_FALSE;
|
|---|
| 2007 | GLboolean alpha = ctx->Color.ColorMask[ACOMP] ? GL_TRUE : GL_FALSE;
|
|---|
| 2008 | if (ctx->Driver.ColorMask
|
|---|
| 2009 | && (*ctx->Driver.ColorMask)( ctx, red, green, blue, alpha )) {
|
|---|
| 2010 | ctx->Color.SWmasking = GL_FALSE;
|
|---|
| 2011 | }
|
|---|
| 2012 | else {
|
|---|
| 2013 | ctx->Color.SWmasking = GL_TRUE;
|
|---|
| 2014 | }
|
|---|
| 2015 | }
|
|---|
| 2016 | }
|
|---|
| 2017 | else {
|
|---|
| 2018 | if (ctx->Color.IndexMask==0xffffffff) {
|
|---|
| 2019 | /* disable masking */
|
|---|
| 2020 | if (ctx->Driver.IndexMask) {
|
|---|
| 2021 | (void) (*ctx->Driver.IndexMask)( ctx, 0xffffffff );
|
|---|
| 2022 | }
|
|---|
| 2023 | ctx->Color.SWmasking = GL_FALSE;
|
|---|
| 2024 | }
|
|---|
| 2025 | else {
|
|---|
| 2026 | /* Ask driver to do index masking, if it can't then
|
|---|
| 2027 | * do it in software
|
|---|
| 2028 | */
|
|---|
| 2029 | if (ctx->Driver.IndexMask
|
|---|
| 2030 | && (*ctx->Driver.IndexMask)( ctx, ctx->Color.IndexMask )) {
|
|---|
| 2031 | ctx->Color.SWmasking = GL_FALSE;
|
|---|
| 2032 | }
|
|---|
| 2033 | else {
|
|---|
| 2034 | ctx->Color.SWmasking = GL_TRUE;
|
|---|
| 2035 | }
|
|---|
| 2036 | }
|
|---|
| 2037 | }
|
|---|
| 2038 | }
|
|---|
| 2039 |
|
|---|
| 2040 |
|
|---|
| 2041 | static void update_fog_mode( GLcontext *ctx )
|
|---|
| 2042 | {
|
|---|
| 2043 | int old_mode = ctx->FogMode;
|
|---|
| 2044 | ctx->FogMode = FOG_NONE;
|
|---|
| 2045 |
|
|---|
| 2046 | if (ctx->Fog.Enabled) {
|
|---|
| 2047 | ctx->FogMode = FOG_VERTEX;
|
|---|
| 2048 |
|
|---|
| 2049 | if (ctx->Texture.Enabled || ctx->Hint.Fog == GL_NICEST)
|
|---|
| 2050 | ctx->FogMode = FOG_FRAGMENT;
|
|---|
| 2051 |
|
|---|
| 2052 | if ( ctx->Driver.GetParameteri &&
|
|---|
| 2053 | ctx->Driver.GetParameteri( ctx, DD_HAVE_HARDWARE_FOG ) )
|
|---|
| 2054 | ctx->FogMode = FOG_FRAGMENT;
|
|---|
| 2055 | }
|
|---|
| 2056 |
|
|---|
| 2057 | if (old_mode != ctx->FogMode)
|
|---|
| 2058 | ctx->NewState |= NEW_FOG;
|
|---|
| 2059 | }
|
|---|
| 2060 |
|
|---|
| 2061 |
|
|---|
| 2062 | /*
|
|---|
| 2063 | * Recompute the value of ctx->RasterMask, etc. according to
|
|---|
| 2064 | * the current context.
|
|---|
| 2065 | */
|
|---|
| 2066 | static void update_rasterflags( GLcontext *ctx )
|
|---|
| 2067 | {
|
|---|
| 2068 | ctx->RasterMask = 0;
|
|---|
| 2069 |
|
|---|
| 2070 | if (ctx->Color.AlphaEnabled) ctx->RasterMask |= ALPHATEST_BIT;
|
|---|
| 2071 | if (ctx->Color.BlendEnabled) ctx->RasterMask |= BLEND_BIT;
|
|---|
| 2072 | if (ctx->Depth.Test) ctx->RasterMask |= DEPTH_BIT;
|
|---|
| 2073 | if (ctx->FogMode==FOG_FRAGMENT) ctx->RasterMask |= FOG_BIT;
|
|---|
| 2074 | if (ctx->Color.SWLogicOpEnabled) ctx->RasterMask |= LOGIC_OP_BIT;
|
|---|
| 2075 | if (ctx->Scissor.Enabled) ctx->RasterMask |= SCISSOR_BIT;
|
|---|
| 2076 | if (ctx->Stencil.Enabled) ctx->RasterMask |= STENCIL_BIT;
|
|---|
| 2077 | if (ctx->Color.SWmasking) ctx->RasterMask |= MASKING_BIT;
|
|---|
| 2078 |
|
|---|
| 2079 | if (ctx->Visual->SoftwareAlpha && ctx->Color.ColorMask[ACOMP]
|
|---|
| 2080 | && ctx->Color.DrawBuffer != GL_NONE)
|
|---|
| 2081 | ctx->RasterMask |= ALPHABUF_BIT;
|
|---|
| 2082 |
|
|---|
| 2083 | if ( ctx->Viewport.X<0
|
|---|
| 2084 | || ctx->Viewport.X + ctx->Viewport.Width > ctx->Buffer->Width
|
|---|
| 2085 | || ctx->Viewport.Y<0
|
|---|
| 2086 | || ctx->Viewport.Y + ctx->Viewport.Height > ctx->Buffer->Height) {
|
|---|
| 2087 | ctx->RasterMask |= WINCLIP_BIT;
|
|---|
| 2088 | }
|
|---|
| 2089 |
|
|---|
| 2090 | /* If we're not drawing to exactly one color buffer set the
|
|---|
| 2091 | * MULTI_DRAW_BIT flag. Also set it if we're drawing to no
|
|---|
| 2092 | * buffers or the RGBA or CI mask disables all writes.
|
|---|
| 2093 | */
|
|---|
| 2094 |
|
|---|
| 2095 | ctx->TriangleCaps &= ~DD_MULTIDRAW;
|
|---|
| 2096 |
|
|---|
| 2097 | if (ctx->Color.MultiDrawBuffer) {
|
|---|
| 2098 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
|---|
| 2099 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
|---|
| 2100 | }
|
|---|
| 2101 | else if (ctx->Color.DrawBuffer==GL_NONE) {
|
|---|
| 2102 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
|---|
| 2103 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
|---|
| 2104 | }
|
|---|
| 2105 | else if (ctx->Visual->RGBAflag && ctx->Color.ColorMask==0) {
|
|---|
| 2106 | /* all RGBA channels disabled */
|
|---|
| 2107 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
|---|
| 2108 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
|---|
| 2109 | ctx->Color.DrawDestMask = 0;
|
|---|
| 2110 | }
|
|---|
| 2111 | else if (!ctx->Visual->RGBAflag && ctx->Color.IndexMask==0) {
|
|---|
| 2112 | /* all color index bits disabled */
|
|---|
| 2113 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
|---|
| 2114 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
|---|
| 2115 | ctx->Color.DrawDestMask = 0;
|
|---|
| 2116 | }
|
|---|
| 2117 | }
|
|---|
| 2118 |
|
|---|
| 2119 |
|
|---|
| 2120 | void gl_print_state( const char *msg, GLuint state )
|
|---|
| 2121 | {
|
|---|
| 2122 | fprintf(stderr,
|
|---|
| 2123 | "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
|
|---|
| 2124 | msg,
|
|---|
| 2125 | state,
|
|---|
| 2126 | (state & NEW_LIGHTING) ? "lighting, " : "",
|
|---|
| 2127 | (state & NEW_RASTER_OPS) ? "raster-ops, " : "",
|
|---|
| 2128 | (state & NEW_TEXTURING) ? "texturing, " : "",
|
|---|
| 2129 | (state & NEW_POLYGON) ? "polygon, " : "",
|
|---|
| 2130 | (state & NEW_DRVSTATE0) ? "driver-0, " : "",
|
|---|
| 2131 | (state & NEW_DRVSTATE1) ? "driver-1, " : "",
|
|---|
| 2132 | (state & NEW_DRVSTATE2) ? "driver-2, " : "",
|
|---|
| 2133 | (state & NEW_DRVSTATE3) ? "driver-3, " : "",
|
|---|
| 2134 | (state & NEW_MODELVIEW) ? "modelview, " : "",
|
|---|
| 2135 | (state & NEW_PROJECTION) ? "projection, " : "",
|
|---|
| 2136 | (state & NEW_TEXTURE_MATRIX) ? "texture-matrix, " : "",
|
|---|
| 2137 | (state & NEW_USER_CLIP) ? "user-clip, " : "",
|
|---|
| 2138 | (state & NEW_TEXTURE_ENV) ? "texture-env, " : "",
|
|---|
| 2139 | (state & NEW_CLIENT_STATE) ? "client-state, " : "",
|
|---|
| 2140 | (state & NEW_FOG) ? "fog, " : "",
|
|---|
| 2141 | (state & NEW_NORMAL_TRANSFORM) ? "normal-transform, " : "",
|
|---|
| 2142 | (state & NEW_VIEWPORT) ? "viewport, " : "",
|
|---|
| 2143 | (state & NEW_TEXTURE_ENABLE) ? "texture-enable, " : "");
|
|---|
| 2144 | }
|
|---|
| 2145 |
|
|---|
| 2146 | void gl_print_enable_flags( const char *msg, GLuint flags )
|
|---|
| 2147 | {
|
|---|
| 2148 | fprintf(stderr,
|
|---|
| 2149 | "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s\n",
|
|---|
| 2150 | msg,
|
|---|
| 2151 | flags,
|
|---|
| 2152 | (flags & ENABLE_TEX0) ? "tex-0, " : "",
|
|---|
| 2153 | (flags & ENABLE_TEX1) ? "tex-1, " : "",
|
|---|
| 2154 | (flags & ENABLE_LIGHT) ? "light, " : "",
|
|---|
| 2155 | (flags & ENABLE_FOG) ? "fog, " : "",
|
|---|
| 2156 | (flags & ENABLE_USERCLIP) ? "userclip, " : "",
|
|---|
| 2157 | (flags & ENABLE_TEXGEN0) ? "tex-gen-0, " : "",
|
|---|
| 2158 | (flags & ENABLE_TEXGEN1) ? "tex-gen-1, " : "",
|
|---|
| 2159 | (flags & ENABLE_TEXMAT0) ? "tex-mat-0, " : "",
|
|---|
| 2160 | (flags & ENABLE_TEXMAT1) ? "tex-mat-1, " : "",
|
|---|
| 2161 | (flags & ENABLE_NORMALIZE) ? "normalize, " : "",
|
|---|
| 2162 | (flags & ENABLE_RESCALE) ? "rescale, " : "");
|
|---|
| 2163 | }
|
|---|
| 2164 |
|
|---|
| 2165 |
|
|---|
| 2166 | /*
|
|---|
| 2167 | * If ctx->NewState is non-zero then this function MUST be called before
|
|---|
| 2168 | * rendering any primitive. Basically, function pointers and miscellaneous
|
|---|
| 2169 | * flags are updated to reflect the current state of the state machine.
|
|---|
| 2170 | */
|
|---|
| 2171 | void gl_update_state( GLcontext *ctx )
|
|---|
| 2172 | {
|
|---|
| 2173 | GLuint i;
|
|---|
| 2174 |
|
|---|
| 2175 | if (MESA_VERBOSE & VERBOSE_STATE)
|
|---|
| 2176 | gl_print_state("", ctx->NewState);
|
|---|
| 2177 |
|
|---|
| 2178 | if (ctx->NewState & NEW_CLIENT_STATE)
|
|---|
| 2179 | gl_update_client_state( ctx );
|
|---|
| 2180 |
|
|---|
| 2181 | if ((ctx->NewState & NEW_TEXTURE_ENABLE) &&
|
|---|
| 2182 | (ctx->Enabled & ENABLE_TEX_ANY) != ctx->Texture.Enabled)
|
|---|
| 2183 | ctx->NewState |= NEW_TEXTURING | NEW_RASTER_OPS;
|
|---|
| 2184 |
|
|---|
| 2185 | if (ctx->NewState & NEW_TEXTURE_ENV) {
|
|---|
| 2186 | if (ctx->Texture.Unit[0].EnvMode == ctx->Texture.Unit[0].LastEnvMode &&
|
|---|
| 2187 | ctx->Texture.Unit[1].EnvMode == ctx->Texture.Unit[1].LastEnvMode)
|
|---|
| 2188 | ctx->NewState &= ~NEW_TEXTURE_ENV;
|
|---|
| 2189 | ctx->Texture.Unit[0].LastEnvMode = ctx->Texture.Unit[0].EnvMode;
|
|---|
| 2190 | ctx->Texture.Unit[1].LastEnvMode = ctx->Texture.Unit[1].EnvMode;
|
|---|
| 2191 | }
|
|---|
| 2192 |
|
|---|
| 2193 | if (ctx->NewState & NEW_TEXTURE_MATRIX) {
|
|---|
| 2194 | ctx->Enabled &= ~(ENABLE_TEXMAT0|ENABLE_TEXMAT1);
|
|---|
| 2195 |
|
|---|
| 2196 | for (i=0; i < MAX_TEXTURE_UNITS; i++) {
|
|---|
| 2197 | if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER)
|
|---|
| 2198 | {
|
|---|
| 2199 | gl_matrix_analyze( &ctx->TextureMatrix[i] );
|
|---|
| 2200 | ctx->TextureMatrix[i].flags &= ~MAT_DIRTY_DEPENDENTS;
|
|---|
| 2201 |
|
|---|
| 2202 | if (ctx->Texture.Unit[i].Enabled &&
|
|---|
| 2203 | ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
|
|---|
| 2204 | ctx->Enabled |= ENABLE_TEXMAT0 << i;
|
|---|
| 2205 | }
|
|---|
| 2206 | }
|
|---|
| 2207 | }
|
|---|
| 2208 |
|
|---|
| 2209 | if (ctx->NewState & (NEW_TEXTURING | NEW_TEXTURE_ENABLE)) {
|
|---|
| 2210 | ctx->Texture.NeedNormals = GL_FALSE;
|
|---|
| 2211 | gl_update_dirty_texobjs(ctx);
|
|---|
| 2212 | ctx->Enabled &= ~(ENABLE_TEXGEN0|ENABLE_TEXGEN1);
|
|---|
| 2213 | ctx->Texture.ReallyEnabled = 0;
|
|---|
| 2214 |
|
|---|
| 2215 | for (i=0; i < MAX_TEXTURE_UNITS; i++) {
|
|---|
| 2216 | if (ctx->Texture.Unit[i].Enabled) {
|
|---|
| 2217 | gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );
|
|---|
| 2218 |
|
|---|
| 2219 | ctx->Texture.ReallyEnabled |=
|
|---|
| 2220 | ctx->Texture.Unit[i].ReallyEnabled<<(i*4);
|
|---|
| 2221 |
|
|---|
| 2222 | if (ctx->Texture.Unit[i].GenFlags != 0) {
|
|---|
| 2223 | ctx->Enabled |= ENABLE_TEXGEN0 << i;
|
|---|
| 2224 |
|
|---|
| 2225 | if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS)
|
|---|
| 2226 | {
|
|---|
| 2227 | ctx->Texture.NeedNormals = GL_TRUE;
|
|---|
| 2228 | ctx->Texture.NeedEyeCoords = GL_TRUE;
|
|---|
| 2229 | }
|
|---|
| 2230 |
|
|---|
| 2231 | if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD)
|
|---|
| 2232 | {
|
|---|
| 2233 | ctx->Texture.NeedEyeCoords = GL_TRUE;
|
|---|
| 2234 | }
|
|---|
| 2235 | }
|
|---|
| 2236 | }
|
|---|
| 2237 | }
|
|---|
| 2238 |
|
|---|
| 2239 | ctx->Texture.Enabled = ctx->Enabled & ENABLE_TEX_ANY;
|
|---|
| 2240 | ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
|
|---|
| 2241 | }
|
|---|
| 2242 |
|
|---|
| 2243 | if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING | NEW_FOG)) {
|
|---|
| 2244 |
|
|---|
| 2245 |
|
|---|
| 2246 | if (ctx->NewState & NEW_RASTER_OPS) {
|
|---|
| 2247 | update_pixel_logic(ctx);
|
|---|
| 2248 | update_pixel_masking(ctx);
|
|---|
| 2249 | update_fog_mode(ctx);
|
|---|
| 2250 | update_rasterflags(ctx);
|
|---|
| 2251 | if (ctx->Driver.Dither) {
|
|---|
| 2252 | (*ctx->Driver.Dither)( ctx, ctx->Color.DitherFlag );
|
|---|
| 2253 | }
|
|---|
| 2254 |
|
|---|
| 2255 | /* Check if incoming colors can be modified during rasterization */
|
|---|
| 2256 | if (ctx->Fog.Enabled ||
|
|---|
| 2257 | ctx->Texture.Enabled ||
|
|---|
| 2258 | ctx->Color.BlendEnabled ||
|
|---|
| 2259 | ctx->Color.SWmasking ||
|
|---|
| 2260 | ctx->Color.SWLogicOpEnabled) {
|
|---|
| 2261 | ctx->MutablePixels = GL_TRUE;
|
|---|
| 2262 | }
|
|---|
| 2263 | else {
|
|---|
| 2264 | ctx->MutablePixels = GL_FALSE;
|
|---|
| 2265 | }
|
|---|
| 2266 |
|
|---|
| 2267 | /* update scissor region */
|
|---|
| 2268 |
|
|---|
| 2269 | ctx->Buffer->Xmin = 0;
|
|---|
| 2270 | ctx->Buffer->Ymin = 0;
|
|---|
| 2271 | ctx->Buffer->Xmax = ctx->Buffer->Width-1;
|
|---|
| 2272 | ctx->Buffer->Ymax = ctx->Buffer->Height-1;
|
|---|
| 2273 | if (ctx->Scissor.Enabled) {
|
|---|
| 2274 | if (ctx->Scissor.X > ctx->Buffer->Xmin) {
|
|---|
| 2275 | ctx->Buffer->Xmin = ctx->Scissor.X;
|
|---|
| 2276 | }
|
|---|
| 2277 | if (ctx->Scissor.Y > ctx->Buffer->Ymin) {
|
|---|
| 2278 | ctx->Buffer->Ymin = ctx->Scissor.Y;
|
|---|
| 2279 | }
|
|---|
| 2280 | if (ctx->Scissor.X + ctx->Scissor.Width - 1 < ctx->Buffer->Xmax) {
|
|---|
| 2281 | ctx->Buffer->Xmax = ctx->Scissor.X + ctx->Scissor.Width - 1;
|
|---|
| 2282 | }
|
|---|
| 2283 | if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < ctx->Buffer->Ymax) {
|
|---|
| 2284 | ctx->Buffer->Ymax = ctx->Scissor.Y + ctx->Scissor.Height - 1;
|
|---|
| 2285 | }
|
|---|
| 2286 | }
|
|---|
| 2287 |
|
|---|
| 2288 | /* The driver isn't managing the depth buffer.
|
|---|
| 2289 | */
|
|---|
| 2290 | if (ctx->Driver.AllocDepthBuffer == gl_alloc_depth_buffer)
|
|---|
| 2291 | {
|
|---|
| 2292 | if (ctx->Depth.Mask) {
|
|---|
| 2293 | switch (ctx->Depth.Func) {
|
|---|
| 2294 | case GL_LESS:
|
|---|
| 2295 | ctx->Driver.DepthTestSpan = gl_depth_test_span_less;
|
|---|
| 2296 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_less;
|
|---|
| 2297 | break;
|
|---|
| 2298 | case GL_GREATER:
|
|---|
| 2299 | ctx->Driver.DepthTestSpan = gl_depth_test_span_greater;
|
|---|
| 2300 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_greater;
|
|---|
| 2301 | break;
|
|---|
| 2302 | default:
|
|---|
| 2303 | ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
|
|---|
| 2304 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
|
|---|
| 2305 | }
|
|---|
| 2306 | }
|
|---|
| 2307 | else {
|
|---|
| 2308 | ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
|
|---|
| 2309 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
|
|---|
| 2310 | }
|
|---|
| 2311 | }
|
|---|
| 2312 | }
|
|---|
| 2313 |
|
|---|
| 2314 | if (ctx->NewState & NEW_LIGHTING) {
|
|---|
| 2315 | ctx->TriangleCaps &= ~(DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
|
|---|
| 2316 | if (ctx->Light.Enabled) {
|
|---|
| 2317 | if (ctx->Light.Model.TwoSide)
|
|---|
| 2318 | ctx->TriangleCaps |= (DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
|
|---|
| 2319 | gl_update_lighting(ctx);
|
|---|
| 2320 | }
|
|---|
| 2321 | }
|
|---|
| 2322 | }
|
|---|
| 2323 |
|
|---|
| 2324 | if (ctx->NewState & (NEW_POLYGON | NEW_LIGHTING)) {
|
|---|
| 2325 |
|
|---|
| 2326 | ctx->TriangleCaps &= ~DD_TRI_CULL_FRONT_BACK;
|
|---|
| 2327 |
|
|---|
| 2328 | if (ctx->NewState & NEW_POLYGON) {
|
|---|
| 2329 | /* Setup CullBits bitmask */
|
|---|
| 2330 | if (ctx->Polygon.CullFlag) {
|
|---|
| 2331 | ctx->backface_sign = 1;
|
|---|
| 2332 | switch(ctx->Polygon.CullFaceMode) {
|
|---|
| 2333 | case GL_BACK:
|
|---|
| 2334 | if(ctx->Polygon.FrontFace==GL_CCW)
|
|---|
| 2335 | ctx->backface_sign = -1;
|
|---|
| 2336 | ctx->Polygon.CullBits = 1;
|
|---|
| 2337 | break;
|
|---|
| 2338 | case GL_FRONT:
|
|---|
| 2339 | if(ctx->Polygon.FrontFace!=GL_CCW)
|
|---|
| 2340 | ctx->backface_sign = -1;
|
|---|
| 2341 | ctx->Polygon.CullBits = 2;
|
|---|
| 2342 | break;
|
|---|
| 2343 | default:
|
|---|
| 2344 | case GL_FRONT_AND_BACK:
|
|---|
| 2345 | ctx->backface_sign = 0;
|
|---|
| 2346 | ctx->Polygon.CullBits = 0;
|
|---|
| 2347 | ctx->TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
|
|---|
| 2348 | break;
|
|---|
| 2349 | }
|
|---|
| 2350 | }
|
|---|
| 2351 | else {
|
|---|
| 2352 | ctx->Polygon.CullBits = 3;
|
|---|
| 2353 | ctx->backface_sign = 0;
|
|---|
| 2354 | }
|
|---|
| 2355 |
|
|---|
| 2356 | /* Any Polygon offsets enabled? */
|
|---|
| 2357 | ctx->TriangleCaps &= ~DD_TRI_OFFSET;
|
|---|
| 2358 |
|
|---|
| 2359 | if (ctx->Polygon.OffsetPoint ||
|
|---|
| 2360 | ctx->Polygon.OffsetLine ||
|
|---|
| 2361 | ctx->Polygon.OffsetFill)
|
|---|
| 2362 | ctx->TriangleCaps |= DD_TRI_OFFSET;
|
|---|
| 2363 |
|
|---|
| 2364 | /* reset Z offsets now */
|
|---|
| 2365 | ctx->PointZoffset = 0.0;
|
|---|
| 2366 | ctx->LineZoffset = 0.0;
|
|---|
| 2367 | ctx->PolygonZoffset = 0.0;
|
|---|
| 2368 | }
|
|---|
| 2369 | }
|
|---|
| 2370 |
|
|---|
| 2371 | if (ctx->NewState & ~(NEW_CLIENT_STATE|
|
|---|
| 2372 | NEW_DRIVER_STATE|NEW_USER_CLIP|
|
|---|
| 2373 | NEW_POLYGON))
|
|---|
| 2374 | gl_update_clipmask(ctx);
|
|---|
| 2375 |
|
|---|
| 2376 | if (ctx->NewState & (NEW_LIGHTING|
|
|---|
| 2377 | NEW_RASTER_OPS|
|
|---|
| 2378 | NEW_TEXTURING|
|
|---|
| 2379 | NEW_TEXTURE_ENABLE|
|
|---|
| 2380 | NEW_TEXTURE_ENV|
|
|---|
| 2381 | NEW_POLYGON|
|
|---|
| 2382 | NEW_DRVSTATE0|
|
|---|
| 2383 | NEW_DRVSTATE1|
|
|---|
| 2384 | NEW_DRVSTATE2|
|
|---|
| 2385 | NEW_DRVSTATE3|
|
|---|
| 2386 | NEW_USER_CLIP))
|
|---|
| 2387 | {
|
|---|
| 2388 | ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps;
|
|---|
| 2389 | ctx->IndirectTriangles |= DD_SW_RASTERIZE;
|
|---|
| 2390 |
|
|---|
| 2391 | if (MESA_VERBOSE&VERBOSE_CULL)
|
|---|
| 2392 | gl_print_tri_caps("initial indirect tris", ctx->IndirectTriangles);
|
|---|
| 2393 |
|
|---|
| 2394 | ctx->Driver.PointsFunc = NULL;
|
|---|
| 2395 | ctx->Driver.LineFunc = NULL;
|
|---|
| 2396 | ctx->Driver.TriangleFunc = NULL;
|
|---|
| 2397 | ctx->Driver.QuadFunc = NULL;
|
|---|
| 2398 | ctx->Driver.RectFunc = NULL;
|
|---|
| 2399 | ctx->Driver.RenderVBClippedTab = NULL;
|
|---|
| 2400 | ctx->Driver.RenderVBCulledTab = NULL;
|
|---|
| 2401 | ctx->Driver.RenderVBRawTab = NULL;
|
|---|
| 2402 |
|
|---|
| 2403 | /*
|
|---|
| 2404 | * Here the driver sets up all the ctx->Driver function pointers to
|
|---|
| 2405 | * it's specific, private functions.
|
|---|
| 2406 | */
|
|---|
| 2407 | ctx->Driver.UpdateState(ctx);
|
|---|
| 2408 |
|
|---|
| 2409 | if (MESA_VERBOSE&VERBOSE_CULL)
|
|---|
| 2410 | gl_print_tri_caps("indirect tris", ctx->IndirectTriangles);
|
|---|
| 2411 |
|
|---|
| 2412 | /*
|
|---|
| 2413 | * In case the driver didn't hook in an optimized point, line or
|
|---|
| 2414 | * triangle function we'll now select "core/fallback" point, line
|
|---|
| 2415 | * and triangle functions.
|
|---|
| 2416 | */
|
|---|
| 2417 | if (ctx->IndirectTriangles & DD_SW_RASTERIZE) {
|
|---|
| 2418 | gl_set_point_function(ctx);
|
|---|
| 2419 | gl_set_line_function(ctx);
|
|---|
| 2420 | gl_set_triangle_function(ctx);
|
|---|
| 2421 | gl_set_quad_function(ctx);
|
|---|
| 2422 |
|
|---|
| 2423 | if ((ctx->IndirectTriangles &
|
|---|
| 2424 | (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL)) ==
|
|---|
| 2425 | (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL))
|
|---|
| 2426 | ctx->IndirectTriangles &= ~DD_TRI_CULL;
|
|---|
| 2427 | }
|
|---|
| 2428 |
|
|---|
| 2429 | if (MESA_VERBOSE&VERBOSE_CULL)
|
|---|
| 2430 | gl_print_tri_caps("indirect tris 2", ctx->IndirectTriangles);
|
|---|
| 2431 |
|
|---|
| 2432 | gl_set_render_vb_function(ctx);
|
|---|
| 2433 | }
|
|---|
| 2434 |
|
|---|
| 2435 | /* Should only be calc'd when !need_eye_coords and not culling.
|
|---|
| 2436 | */
|
|---|
| 2437 | if (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) {
|
|---|
| 2438 | if (ctx->NewState & NEW_MODELVIEW) {
|
|---|
| 2439 | gl_matrix_analyze( &ctx->ModelView );
|
|---|
| 2440 | ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
|
|---|
| 2441 | }
|
|---|
| 2442 |
|
|---|
| 2443 | if (ctx->NewState & NEW_PROJECTION) {
|
|---|
| 2444 | gl_matrix_analyze( &ctx->ProjectionMatrix );
|
|---|
| 2445 | ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
|
|---|
| 2446 |
|
|---|
| 2447 | if (ctx->Transform.AnyClip) {
|
|---|
| 2448 | gl_update_userclip( ctx );
|
|---|
| 2449 | }
|
|---|
| 2450 | }
|
|---|
| 2451 |
|
|---|
| 2452 | gl_calculate_model_project_matrix( ctx );
|
|---|
| 2453 | ctx->ModelProjectWinMatrixUptodate = 0;
|
|---|
| 2454 | }
|
|---|
| 2455 |
|
|---|
| 2456 | /* Figure out whether we can light in object space or not. If we
|
|---|
| 2457 | * can, find the current positions of the lights in object space
|
|---|
| 2458 | */
|
|---|
| 2459 | if ((ctx->Enabled & (ENABLE_POINT_ATTEN | ENABLE_LIGHT | ENABLE_FOG |
|
|---|
| 2460 | ENABLE_TEXGEN0 | ENABLE_TEXGEN1)) &&
|
|---|
| 2461 | (ctx->NewState & (NEW_LIGHTING |
|
|---|
| 2462 | NEW_FOG |
|
|---|
| 2463 | NEW_MODELVIEW |
|
|---|
| 2464 | NEW_PROJECTION |
|
|---|
| 2465 | NEW_TEXTURING |
|
|---|
| 2466 | NEW_RASTER_OPS |
|
|---|
| 2467 | NEW_USER_CLIP)))
|
|---|
| 2468 | {
|
|---|
| 2469 | GLboolean oldcoord, oldnorm;
|
|---|
| 2470 |
|
|---|
| 2471 | oldcoord = ctx->NeedEyeCoords;
|
|---|
| 2472 | oldnorm = ctx->NeedEyeNormals;
|
|---|
| 2473 |
|
|---|
| 2474 | ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
|
|---|
| 2475 | ctx->NeedEyeCoords = (ctx->FogMode == FOG_VERTEX ||
|
|---|
| 2476 | ctx->Point.Attenuated);
|
|---|
| 2477 | ctx->NeedEyeNormals = GL_FALSE;
|
|---|
| 2478 |
|
|---|
| 2479 | if (ctx->Light.Enabled) {
|
|---|
| 2480 | if (ctx->Light.Flags & LIGHT_POSITIONAL) {
|
|---|
| 2481 | /* Need length for attenuation */
|
|---|
| 2482 | if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING))
|
|---|
| 2483 | ctx->NeedEyeCoords = GL_TRUE;
|
|---|
| 2484 | } else if (ctx->Light.NeedVertices) {
|
|---|
| 2485 | /* Need angle for spot calculations */
|
|---|
| 2486 | if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_ANGLE_PRESERVING))
|
|---|
| 2487 | ctx->NeedEyeCoords = GL_TRUE;
|
|---|
| 2488 | }
|
|---|
| 2489 | ctx->NeedEyeNormals = ctx->NeedEyeCoords;
|
|---|
| 2490 | }
|
|---|
| 2491 | if (ctx->Texture.Enabled || ctx->RenderMode==GL_FEEDBACK) {
|
|---|
| 2492 | if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE;
|
|---|
| 2493 | if (ctx->Texture.NeedNormals)
|
|---|
| 2494 | ctx->NeedNormals = ctx->NeedEyeNormals = GL_TRUE;
|
|---|
| 2495 | }
|
|---|
| 2496 |
|
|---|
| 2497 | ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
|
|---|
| 2498 |
|
|---|
| 2499 | if (ctx->NeedEyeCoords)
|
|---|
| 2500 | ctx->vb_proj_matrix = &ctx->ProjectionMatrix;
|
|---|
| 2501 |
|
|---|
| 2502 | if (ctx->Light.Enabled) {
|
|---|
| 2503 | gl_update_lighting_function(ctx);
|
|---|
| 2504 |
|
|---|
| 2505 | if ( (ctx->NewState & NEW_LIGHTING) ||
|
|---|
| 2506 | ((ctx->NewState & (NEW_MODELVIEW| NEW_PROJECTION)) &&
|
|---|
| 2507 | !ctx->NeedEyeCoords) ||
|
|---|
| 2508 | oldcoord != ctx->NeedEyeCoords ||
|
|---|
| 2509 | oldnorm != ctx->NeedEyeNormals) {
|
|---|
| 2510 | gl_compute_light_positions(ctx);
|
|---|
| 2511 | }
|
|---|
| 2512 |
|
|---|
| 2513 | ctx->rescale_factor = 1.0F;
|
|---|
| 2514 |
|
|---|
| 2515 | if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE |
|
|---|
| 2516 | MAT_FLAG_GENERAL_SCALE |
|
|---|
| 2517 | MAT_FLAG_GENERAL_3D |
|
|---|
| 2518 | MAT_FLAG_GENERAL) )
|
|---|
| 2519 |
|
|---|
| 2520 | {
|
|---|
| 2521 | GLfloat *m = ctx->ModelView.inv;
|
|---|
| 2522 | GLfloat f = m[2]*m[2] + m[6]*m[6] + m[10]*m[10];
|
|---|
| 2523 | if (f > 1e-12 && (f-1)*(f-1) > 1e-12)
|
|---|
| 2524 | ctx->rescale_factor = 1.0/GL_SQRT(f);
|
|---|
| 2525 | }
|
|---|
| 2526 | }
|
|---|
| 2527 |
|
|---|
| 2528 | gl_update_normal_transform( ctx );
|
|---|
| 2529 | }
|
|---|
| 2530 |
|
|---|
| 2531 | gl_update_pipelines(ctx);
|
|---|
| 2532 | ctx->NewState = 0;
|
|---|
| 2533 | }
|
|---|