source: trunk/src/opengl/mesa/context.c@ 2959

Last change on this file since 2959 was 2938, checked in by sandervl, 25 years ago

created

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