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