blob: 2822f080c1a2ce4df7f642a1202cce2a7c39301c [file] [log] [blame]
Brian Paul4fe34b22000-04-11 15:07:48 +00001/* $Id: context.c,v 1.58 2000/04/11 15:07:48 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paulfbd8f211999-11-11 01:22:25 +00005 * Version: 3.3
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paul54287052000-01-17 20:00:15 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
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
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "accum.h"
33#include "alphabuf.h"
jtgafb833d1999-08-19 00:55:39 +000034#include "clip.h"
35#include "context.h"
36#include "cva.h"
37#include "depth.h"
38#include "dlist.h"
39#include "eval.h"
40#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000041#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000042#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000043#include "get.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000044#include "glapi.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000045#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000046#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000047#include "hash.h"
48#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "macros.h"
50#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000051#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000052#include "mmath.h"
53#include "pb.h"
54#include "pipeline.h"
jtgafb833d1999-08-19 00:55:39 +000055#include "shade.h"
56#include "simple_list.h"
57#include "stencil.h"
58#include "stages.h"
Brian Paulfa9df402000-02-02 19:16:46 +000059#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000060#include "translate.h"
61#include "teximage.h"
62#include "texobj.h"
63#include "texstate.h"
64#include "texture.h"
65#include "types.h"
66#include "varray.h"
67#include "vb.h"
68#include "vbcull.h"
jtgafb833d1999-08-19 00:55:39 +000069#include "vbrender.h"
70#include "vbxform.h"
Keith Whitwell38756791999-08-29 10:26:31 +000071#include "vertices.h"
jtgafb833d1999-08-19 00:55:39 +000072#include "xform.h"
jtgafb833d1999-08-19 00:55:39 +000073#endif
74
75
76
77/**********************************************************************/
78/***** Context and Thread management *****/
79/**********************************************************************/
80
81
Brian Paul00037781999-12-17 14:52:35 +000082#if !defined(THREADS)
jtgafb833d1999-08-19 00:55:39 +000083
Brian Paul5666c632000-01-18 17:36:16 +000084struct immediate *_mesa_CurrentInput = NULL;
jtgafb833d1999-08-19 00:55:39 +000085
Brian Paul00037781999-12-17 14:52:35 +000086#endif
jtgafb833d1999-08-19 00:55:39 +000087
88
89
90
91/**********************************************************************/
92/***** Profiling functions *****/
93/**********************************************************************/
94
95#ifdef PROFILE
96
97#include <sys/times.h>
98#include <sys/param.h>
99
100
101/*
102 * Return system time in seconds.
103 * NOTE: this implementation may not be very portable!
104 */
105GLdouble gl_time( void )
106{
107 static GLdouble prev_time = 0.0;
108 static GLdouble time;
109 struct tms tm;
110 clock_t clk;
111
112 clk = times(&tm);
113
114#ifdef CLK_TCK
115 time = (double)clk / (double)CLK_TCK;
116#else
117 time = (double)clk / (double)HZ;
118#endif
119
120 if (time>prev_time) {
121 prev_time = time;
122 return time;
123 }
124 else {
125 return prev_time;
126 }
127}
128
129/*
130 * Reset the timing/profiling counters
131 */
132static void init_timings( GLcontext *ctx )
133{
134 ctx->BeginEndCount = 0;
135 ctx->BeginEndTime = 0.0;
136 ctx->VertexCount = 0;
137 ctx->VertexTime = 0.0;
138 ctx->PointCount = 0;
139 ctx->PointTime = 0.0;
140 ctx->LineCount = 0;
141 ctx->LineTime = 0.0;
142 ctx->PolygonCount = 0;
143 ctx->PolygonTime = 0.0;
144 ctx->ClearCount = 0;
145 ctx->ClearTime = 0.0;
146 ctx->SwapCount = 0;
147 ctx->SwapTime = 0.0;
148}
149
150
151/*
152 * Print the accumulated timing/profiling data.
153 */
154static void print_timings( GLcontext *ctx )
155{
156 GLdouble beginendrate;
157 GLdouble vertexrate;
158 GLdouble pointrate;
159 GLdouble linerate;
160 GLdouble polygonrate;
161 GLdouble overhead;
162 GLdouble clearrate;
163 GLdouble swaprate;
164 GLdouble avgvertices;
165
166 if (ctx->BeginEndTime>0.0) {
167 beginendrate = ctx->BeginEndCount / ctx->BeginEndTime;
168 }
169 else {
170 beginendrate = 0.0;
171 }
172 if (ctx->VertexTime>0.0) {
173 vertexrate = ctx->VertexCount / ctx->VertexTime;
174 }
175 else {
176 vertexrate = 0.0;
177 }
178 if (ctx->PointTime>0.0) {
179 pointrate = ctx->PointCount / ctx->PointTime;
180 }
181 else {
182 pointrate = 0.0;
183 }
184 if (ctx->LineTime>0.0) {
185 linerate = ctx->LineCount / ctx->LineTime;
186 }
187 else {
188 linerate = 0.0;
189 }
190 if (ctx->PolygonTime>0.0) {
191 polygonrate = ctx->PolygonCount / ctx->PolygonTime;
192 }
193 else {
194 polygonrate = 0.0;
195 }
196 if (ctx->ClearTime>0.0) {
197 clearrate = ctx->ClearCount / ctx->ClearTime;
198 }
199 else {
200 clearrate = 0.0;
201 }
202 if (ctx->SwapTime>0.0) {
203 swaprate = ctx->SwapCount / ctx->SwapTime;
204 }
205 else {
206 swaprate = 0.0;
207 }
208
209 if (ctx->BeginEndCount>0) {
210 avgvertices = (GLdouble) ctx->VertexCount / (GLdouble) ctx->BeginEndCount;
211 }
212 else {
213 avgvertices = 0.0;
214 }
215
216 overhead = ctx->BeginEndTime - ctx->VertexTime - ctx->PointTime
217 - ctx->LineTime - ctx->PolygonTime;
218
219
220 printf(" Count Time (s) Rate (/s) \n");
221 printf("--------------------------------------------------------\n");
222 printf("glBegin/glEnd %7d %8.3f %10.3f\n",
223 ctx->BeginEndCount, ctx->BeginEndTime, beginendrate);
224 printf(" vertexes transformed %7d %8.3f %10.3f\n",
225 ctx->VertexCount, ctx->VertexTime, vertexrate );
226 printf(" points rasterized %7d %8.3f %10.3f\n",
227 ctx->PointCount, ctx->PointTime, pointrate );
228 printf(" lines rasterized %7d %8.3f %10.3f\n",
229 ctx->LineCount, ctx->LineTime, linerate );
230 printf(" polygons rasterized %7d %8.3f %10.3f\n",
231 ctx->PolygonCount, ctx->PolygonTime, polygonrate );
232 printf(" overhead %8.3f\n", overhead );
233 printf("glClear %7d %8.3f %10.3f\n",
234 ctx->ClearCount, ctx->ClearTime, clearrate );
235 printf("SwapBuffers %7d %8.3f %10.3f\n",
236 ctx->SwapCount, ctx->SwapTime, swaprate );
237 printf("\n");
238
239 printf("Average number of vertices per begin/end: %8.3f\n", avgvertices );
240}
241#endif
242
243
244
245
246
247/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000248/***** GL Visual allocation/destruction *****/
249/**********************************************************************/
250
251
252/*
253 * Allocate a new GLvisual object.
254 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
255 * alphaFlag - alloc software alpha buffers?
256 * dbFlag - double buffering?
257 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000258 * depthBits - requested bits per depth buffer value
259 * Any value in [0, 32] is acceptable but the actual
260 * depth type will be GLushort or GLuint as needed.
261 * stencilBits - requested minimum bits per stencil buffer value
262 * accumBits - requested minimum bits per accum buffer component
263 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
264 * red/green/blue/alphaBits - number of bits per color component
265 * in frame buffer for RGB(A) mode.
266 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000267 * Return: pointer to new GLvisual or NULL if requested parameters can't
268 * be met.
269 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000270GLvisual *
271_mesa_create_visual( GLboolean rgbFlag,
272 GLboolean alphaFlag,
273 GLboolean dbFlag,
274 GLboolean stereoFlag,
275 GLint redBits,
276 GLint greenBits,
277 GLint blueBits,
278 GLint alphaBits,
279 GLint indexBits,
280 GLint depthBits,
281 GLint stencilBits,
282 GLint accumRedBits,
283 GLint accumGreenBits,
284 GLint accumBlueBits,
285 GLint accumAlphaBits,
286 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000287{
288 GLvisual *vis;
289
Brian Pauled30dfa2000-03-03 17:47:39 +0000290 /* This is to catch bad values from device drivers not updated for
291 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
292 * bad value now (a 1-bit depth buffer!?!).
293 */
294 assert(depthBits == 0 || depthBits > 1);
295
296 if (depthBits < 0 || depthBits > 32) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000297 return NULL;
298 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000299 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000300 return NULL;
301 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000302 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
303 return NULL;
304 }
305 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
306 return NULL;
307 }
308 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
309 return NULL;
310 }
311 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000312 return NULL;
313 }
314
315 vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
316 if (!vis) {
317 return NULL;
318 }
319
320 vis->RGBAflag = rgbFlag;
321 vis->DBflag = dbFlag;
322 vis->StereoFlag = stereoFlag;
323 vis->RedBits = redBits;
324 vis->GreenBits = greenBits;
325 vis->BlueBits = blueBits;
Brian Pauled30dfa2000-03-03 17:47:39 +0000326 vis->AlphaBits = alphaFlag ? (8 * sizeof(GLubyte)) : alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000327
Brian Paulb371e0d2000-03-31 01:05:51 +0000328 vis->IndexBits = indexBits;
329 vis->DepthBits = depthBits;
330 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
331 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
332 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
333 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
334 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000335
336 vis->SoftwareAlpha = alphaFlag;
337
Brian Pauled30dfa2000-03-03 17:47:39 +0000338 if (depthBits == 0) {
339 /* Special case. Even if we don't have a depth buffer we need
340 * good values for DepthMax for Z vertex transformation purposes.
341 */
342 vis->DepthMax = 1;
343 vis->DepthMaxF = 1.0F;
344 }
345 else {
346 vis->DepthMax = (1 << depthBits) - 1;
347 vis->DepthMaxF = (GLfloat) vis->DepthMax;
348 }
349
Brian Paul4d053dd2000-01-14 04:45:47 +0000350 return vis;
351}
352
353
Brian Paulb371e0d2000-03-31 01:05:51 +0000354/* This function should no longer be used. Use _mesa_create_visual() instead */
355GLvisual *gl_create_visual( GLboolean rgbFlag,
356 GLboolean alphaFlag,
357 GLboolean dbFlag,
358 GLboolean stereoFlag,
359 GLint depthBits,
360 GLint stencilBits,
361 GLint accumBits,
362 GLint indexBits,
363 GLint redBits,
364 GLint greenBits,
365 GLint blueBits,
366 GLint alphaBits )
367{
368 return _mesa_create_visual(rgbFlag, alphaFlag, dbFlag, stereoFlag,
369 redBits, greenBits, blueBits, alphaBits,
370 indexBits, depthBits, stencilBits,
371 accumBits, accumBits, accumBits, accumBits, 0);
372}
Brian Paul4d053dd2000-01-14 04:45:47 +0000373
Brian Paulb371e0d2000-03-31 01:05:51 +0000374
375void
376_mesa_destroy_visual( GLvisual *vis )
377{
378 FREE(vis);
379}
380
381
382/* obsolete */
Brian Paul4d053dd2000-01-14 04:45:47 +0000383void gl_destroy_visual( GLvisual *vis )
384{
Brian Paulb371e0d2000-03-31 01:05:51 +0000385 _mesa_destroy_visual(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000386}
387
388
389
390/**********************************************************************/
391/***** GL Framebuffer allocation/destruction *****/
392/**********************************************************************/
393
394
395/*
396 * Create a new framebuffer. A GLframebuffer is a struct which
397 * encapsulates the depth, stencil and accum buffers and related
398 * parameters.
399 * Input: visual - a GLvisual pointer
400 * softwareDepth - create/use a software depth buffer?
401 * softwareStencil - create/use a software stencil buffer?
402 * softwareAccum - create/use a software accum buffer?
403 * softwareAlpha - create/use a software alpha buffer?
404
405 * Return: pointer to new GLframebuffer struct or NULL if error.
406 */
407GLframebuffer *gl_create_framebuffer( GLvisual *visual,
408 GLboolean softwareDepth,
409 GLboolean softwareStencil,
410 GLboolean softwareAccum,
411 GLboolean softwareAlpha )
412{
413 GLframebuffer *buffer;
414
415 buffer = CALLOC_STRUCT(gl_frame_buffer);
416 if (!buffer) {
417 return NULL;
418 }
419
420 /* sanity checks */
421 if (softwareDepth ) {
422 assert(visual->DepthBits > 0);
423 }
424 if (softwareStencil) {
425 assert(visual->StencilBits > 0);
426 }
427 if (softwareAccum) {
428 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000429 assert(visual->AccumRedBits > 0);
430 assert(visual->AccumGreenBits > 0);
431 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000432 }
433 if (softwareAlpha) {
434 assert(visual->RGBAflag);
435 assert(visual->AlphaBits > 0);
436 }
437
438 buffer->Visual = visual;
439 buffer->UseSoftwareDepthBuffer = softwareDepth;
440 buffer->UseSoftwareStencilBuffer = softwareStencil;
441 buffer->UseSoftwareAccumBuffer = softwareAccum;
442 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
443
444 return buffer;
445}
446
447
448
449/*
450 * Free a framebuffer struct and its buffers.
451 */
452void gl_destroy_framebuffer( GLframebuffer *buffer )
453{
454 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000455 if (buffer->DepthBuffer) {
456 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000457 }
458 if (buffer->Accum) {
459 FREE( buffer->Accum );
460 }
461 if (buffer->Stencil) {
462 FREE( buffer->Stencil );
463 }
464 if (buffer->FrontLeftAlpha) {
465 FREE( buffer->FrontLeftAlpha );
466 }
467 if (buffer->BackLeftAlpha) {
468 FREE( buffer->BackLeftAlpha );
469 }
470 if (buffer->FrontRightAlpha) {
471 FREE( buffer->FrontRightAlpha );
472 }
473 if (buffer->BackRightAlpha) {
474 FREE( buffer->BackRightAlpha );
475 }
476 FREE(buffer);
477 }
478}
479
480
481
482/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000483/***** Context allocation, initialization, destroying *****/
484/**********************************************************************/
485
486
Brian Paul9560f052000-01-31 23:11:39 +0000487_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
488
489
jtgafb833d1999-08-19 00:55:39 +0000490/*
491 * This function just calls all the various one-time-init functions in Mesa.
492 */
493static void one_time_init( void )
494{
495 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000496 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000497 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000498 /* do some implementation tests */
499 assert( sizeof(GLbyte) == 1 );
500 assert( sizeof(GLshort) >= 2 );
501 assert( sizeof(GLint) >= 4 );
502 assert( sizeof(GLubyte) == 1 );
503 assert( sizeof(GLushort) >= 2 );
504 assert( sizeof(GLuint) >= 4 );
505
jtgafb833d1999-08-19 00:55:39 +0000506 gl_init_clip();
507 gl_init_eval();
Brian Paul5829f0c2000-02-02 22:21:39 +0000508 _mesa_init_fog();
Brian Paul780c4e02000-03-22 23:20:12 +0000509 _mesa_init_math();
jtgafb833d1999-08-19 00:55:39 +0000510 gl_init_lists();
511 gl_init_shade();
512 gl_init_texture();
513 gl_init_transformation();
514 gl_init_translate();
515 gl_init_vbrender();
516 gl_init_vbxform();
Keith Whitwell38756791999-08-29 10:26:31 +0000517 gl_init_vertices();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000518
519 if (getenv("MESA_DEBUG")) {
520 _glapi_noop_enable_warnings(GL_TRUE);
521 }
522 else {
523 _glapi_noop_enable_warnings(GL_FALSE);
524 }
525
jtgafb833d1999-08-19 00:55:39 +0000526#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
527 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
528#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000529
530 alreadyCalled = GL_TRUE;
531 }
Brian Paul9560f052000-01-31 23:11:39 +0000532 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000533}
534
535
Brian Paul4d053dd2000-01-14 04:45:47 +0000536
jtgafb833d1999-08-19 00:55:39 +0000537/*
538 * Allocate and initialize a shared context state structure.
539 */
540static struct gl_shared_state *alloc_shared_state( void )
541{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000542 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000543 struct gl_shared_state *ss;
544 GLboolean outOfMemory;
545
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000546 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000547 if (!ss)
548 return NULL;
549
Brian Paulbb797902000-01-24 16:19:54 +0000550 ss->DisplayList = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000551
Brian Paulbb797902000-01-24 16:19:54 +0000552 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000553
554 /* Default Texture objects */
555 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000556 for (d = 1 ; d <= 3 ; d++) {
557 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
558 if (!ss->DefaultD[d]) {
559 outOfMemory = GL_TRUE;
560 break;
jtgafb833d1999-08-19 00:55:39 +0000561 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000562 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000563 }
564
565 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
566 /* Ran out of memory at some point. Free everything and return NULL */
567 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000568 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000569 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000570 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000571 if (ss->DefaultD[1])
572 gl_free_texture_object(ss, ss->DefaultD[1]);
573 if (ss->DefaultD[2])
574 gl_free_texture_object(ss, ss->DefaultD[2]);
575 if (ss->DefaultD[3])
576 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000577 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000578 return NULL;
579 }
580 else {
581 return ss;
582 }
583}
584
585
586/*
587 * Deallocate a shared state context and all children structures.
588 */
589static void free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
590{
591 /* Free display lists */
592 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000593 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000594 if (list) {
595 gl_destroy_list(ctx, list);
596 }
597 else {
598 break;
599 }
600 }
Brian Paulbb797902000-01-24 16:19:54 +0000601 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000602
603 /* Free texture objects */
604 while (ss->TexObjectList)
605 {
606 if (ctx->Driver.DeleteTexture)
607 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
608 /* this function removes from linked list too! */
609 gl_free_texture_object(ss, ss->TexObjectList);
610 }
Brian Paulbb797902000-01-24 16:19:54 +0000611 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000612
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000613 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000614}
615
616
617
jtgafb833d1999-08-19 00:55:39 +0000618/*
619 * Initialize the nth light. Note that the defaults for light 0 are
620 * different than the other lights.
621 */
622static void init_light( struct gl_light *l, GLuint n )
623{
624 make_empty_list( l );
625
626 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
627 if (n==0) {
628 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
629 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
630 }
631 else {
632 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
633 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
634 }
635 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
636 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
637 l->SpotExponent = 0.0;
638 gl_compute_spot_exp_table( l );
639 l->SpotCutoff = 180.0;
640 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
641 l->ConstantAttenuation = 1.0;
642 l->LinearAttenuation = 0.0;
643 l->QuadraticAttenuation = 0.0;
644 l->Enabled = GL_FALSE;
645}
646
647
648
649static void init_lightmodel( struct gl_lightmodel *lm )
650{
651 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
652 lm->LocalViewer = GL_FALSE;
653 lm->TwoSide = GL_FALSE;
654 lm->ColorControl = GL_SINGLE_COLOR;
655}
656
657
658static void init_material( struct gl_material *m )
659{
660 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
661 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
662 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
663 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
664 m->Shininess = 0.0;
665 m->AmbientIndex = 0;
666 m->DiffuseIndex = 1;
667 m->SpecularIndex = 1;
668}
669
670
671
672static void init_texture_unit( GLcontext *ctx, GLuint unit )
673{
674 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
675
676 texUnit->EnvMode = GL_MODULATE;
677 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
678 texUnit->TexGenEnabled = 0;
679 texUnit->GenModeS = GL_EYE_LINEAR;
680 texUnit->GenModeT = GL_EYE_LINEAR;
681 texUnit->GenModeR = GL_EYE_LINEAR;
682 texUnit->GenModeQ = GL_EYE_LINEAR;
683 /* Yes, these plane coefficients are correct! */
684 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
685 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
686 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
687 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
688 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
689 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
690 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
691 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
692
Brian Paul6e6d4c61999-10-09 20:17:07 +0000693 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
694 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
695 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
jtgafb833d1999-08-19 00:55:39 +0000696}
697
698
699static void init_fallback_arrays( GLcontext *ctx )
700{
701 struct gl_client_array *cl;
702 GLuint i;
703
704 cl = &ctx->Fallback.Normal;
705 cl->Size = 3;
706 cl->Type = GL_FLOAT;
707 cl->Stride = 0;
708 cl->StrideB = 0;
709 cl->Ptr = (void *) ctx->Current.Normal;
710 cl->Enabled = 1;
711
712 cl = &ctx->Fallback.Color;
713 cl->Size = 4;
714 cl->Type = GL_UNSIGNED_BYTE;
715 cl->Stride = 0;
716 cl->StrideB = 0;
717 cl->Ptr = (void *) ctx->Current.ByteColor;
718 cl->Enabled = 1;
719
720 cl = &ctx->Fallback.Index;
721 cl->Size = 1;
722 cl->Type = GL_UNSIGNED_INT;
723 cl->Stride = 0;
724 cl->StrideB = 0;
725 cl->Ptr = (void *) &ctx->Current.Index;
726 cl->Enabled = 1;
727
728 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
729 cl = &ctx->Fallback.TexCoord[i];
730 cl->Size = 4;
731 cl->Type = GL_FLOAT;
732 cl->Stride = 0;
733 cl->StrideB = 0;
734 cl->Ptr = (void *) ctx->Current.Texcoord[i];
735 cl->Enabled = 1;
736 }
737
738 cl = &ctx->Fallback.EdgeFlag;
739 cl->Size = 1;
740 cl->Type = GL_UNSIGNED_BYTE;
741 cl->Stride = 0;
742 cl->StrideB = 0;
743 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
744 cl->Enabled = 1;
745}
746
Brian Paul4d053dd2000-01-14 04:45:47 +0000747
jtgafb833d1999-08-19 00:55:39 +0000748/* Initialize a 1-D evaluator map */
749static void init_1d_map( struct gl_1d_map *map, int n, const float *initial )
750{
751 map->Order = 1;
752 map->u1 = 0.0;
753 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000754 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000755 if (map->Points) {
756 GLint i;
757 for (i=0;i<n;i++)
758 map->Points[i] = initial[i];
759 }
jtgafb833d1999-08-19 00:55:39 +0000760}
761
762
763/* Initialize a 2-D evaluator map */
764static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
765{
766 map->Uorder = 1;
767 map->Vorder = 1;
768 map->u1 = 0.0;
769 map->u2 = 1.0;
770 map->v1 = 0.0;
771 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000772 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000773 if (map->Points) {
774 GLint i;
775 for (i=0;i<n;i++)
776 map->Points[i] = initial[i];
777 }
jtgafb833d1999-08-19 00:55:39 +0000778}
779
780
Brian Paulf0dee651999-11-19 22:51:29 +0000781static void init_color_table( struct gl_color_table *p )
Brian Paulfbd8f211999-11-11 01:22:25 +0000782{
783 p->Table[0] = 255;
784 p->Table[1] = 255;
785 p->Table[2] = 255;
786 p->Table[3] = 255;
787 p->Size = 1;
788 p->IntFormat = GL_RGBA;
789 p->Format = GL_RGBA;
790}
791
jtgafb833d1999-08-19 00:55:39 +0000792
793/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000794 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000795 */
Brian Paul4d053dd2000-01-14 04:45:47 +0000796static void init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000797{
798 GLuint i, j;
799
Brian Paul4d053dd2000-01-14 04:45:47 +0000800 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000801
Brian Paul539cce52000-02-03 19:40:07 +0000802 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000803 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
804 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
805 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
806 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000807 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
808 ctx->Const.MinPointSize = MIN_POINT_SIZE;
809 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
810 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
811 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
812 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
813 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
814 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
815 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
816 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
817 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
818 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
jtgafb833d1999-08-19 00:55:39 +0000819
Brian Paul4d053dd2000-01-14 04:45:47 +0000820 /* Modelview matrix */
821 gl_matrix_ctr( &ctx->ModelView );
822 gl_matrix_alloc_inv( &ctx->ModelView );
823
824 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000825 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000826 gl_matrix_ctr( &ctx->ModelViewStack[i] );
827 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
828 }
829
830 /* Projection matrix - need inv for user clipping in clip space*/
831 gl_matrix_ctr( &ctx->ProjectionMatrix );
832 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
833
834 gl_matrix_ctr( &ctx->ModelProjectMatrix );
835 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
836 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
837
838 ctx->ProjectionStackDepth = 0;
839 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
840 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
841
Brian Paul7fc29c52000-03-06 17:03:03 +0000842 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000843 gl_matrix_ctr( &ctx->ProjectionStack[i] );
844 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
845 }
846
847 /* Texture matrix */
848 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
849 gl_matrix_ctr( &ctx->TextureMatrix[i] );
850 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000851 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000852 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000853 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000854 }
jtgafb833d1999-08-19 00:55:39 +0000855
Brian Paul250069d2000-04-08 18:57:45 +0000856 /* Color matrix */
857 gl_matrix_ctr(&ctx->ColorMatrix);
858 ctx->ColorStackDepth = 0;
859 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
860 gl_matrix_ctr(&ctx->ColorStack[j]);
861 }
862
Brian Paul4d053dd2000-01-14 04:45:47 +0000863 /* Accumulate buffer group */
864 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000865
Brian Paul4d053dd2000-01-14 04:45:47 +0000866 /* Color buffer group */
867 ctx->Color.IndexMask = 0xffffffff;
868 ctx->Color.ColorMask[0] = 0xff;
869 ctx->Color.ColorMask[1] = 0xff;
870 ctx->Color.ColorMask[2] = 0xff;
871 ctx->Color.ColorMask[3] = 0xff;
872 ctx->Color.SWmasking = GL_FALSE;
873 ctx->Color.ClearIndex = 0;
874 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
875 ctx->Color.DrawBuffer = GL_FRONT;
876 ctx->Color.AlphaEnabled = GL_FALSE;
877 ctx->Color.AlphaFunc = GL_ALWAYS;
878 ctx->Color.AlphaRef = 0;
879 ctx->Color.BlendEnabled = GL_FALSE;
880 ctx->Color.BlendSrcRGB = GL_ONE;
881 ctx->Color.BlendDstRGB = GL_ZERO;
882 ctx->Color.BlendSrcA = GL_ONE;
883 ctx->Color.BlendDstA = GL_ZERO;
884 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
885 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
886 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
887 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
888 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
889 ctx->Color.SWLogicOpEnabled = GL_FALSE;
890 ctx->Color.LogicOp = GL_COPY;
891 ctx->Color.DitherFlag = GL_TRUE;
892 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000893
Brian Paul4d053dd2000-01-14 04:45:47 +0000894 /* Current group */
895 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
896 ctx->Current.Index = 1;
897 for (i=0; i<MAX_TEXTURE_UNITS; i++)
898 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
899 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
900 ctx->Current.RasterDistance = 0.0;
901 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
902 ctx->Current.RasterIndex = 1;
903 for (i=0; i<MAX_TEXTURE_UNITS; i++)
904 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
905 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
906 ctx->Current.RasterPosValid = GL_TRUE;
907 ctx->Current.EdgeFlag = GL_TRUE;
908 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
909 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
jtgafb833d1999-08-19 00:55:39 +0000910
Brian Paul4d053dd2000-01-14 04:45:47 +0000911 ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
912 VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
jtgafb833d1999-08-19 00:55:39 +0000913
Brian Paul4d053dd2000-01-14 04:45:47 +0000914 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000915
Brian Paul4d053dd2000-01-14 04:45:47 +0000916 /* Depth buffer group */
917 ctx->Depth.Test = GL_FALSE;
918 ctx->Depth.Clear = 1.0;
919 ctx->Depth.Func = GL_LESS;
920 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000921 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000922
Brian Paul4d053dd2000-01-14 04:45:47 +0000923 /* Evaluators group */
924 ctx->Eval.Map1Color4 = GL_FALSE;
925 ctx->Eval.Map1Index = GL_FALSE;
926 ctx->Eval.Map1Normal = GL_FALSE;
927 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
928 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
929 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
930 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
931 ctx->Eval.Map1Vertex3 = GL_FALSE;
932 ctx->Eval.Map1Vertex4 = GL_FALSE;
933 ctx->Eval.Map2Color4 = GL_FALSE;
934 ctx->Eval.Map2Index = GL_FALSE;
935 ctx->Eval.Map2Normal = GL_FALSE;
936 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
937 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
938 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
939 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
940 ctx->Eval.Map2Vertex3 = GL_FALSE;
941 ctx->Eval.Map2Vertex4 = GL_FALSE;
942 ctx->Eval.AutoNormal = GL_FALSE;
943 ctx->Eval.MapGrid1un = 1;
944 ctx->Eval.MapGrid1u1 = 0.0;
945 ctx->Eval.MapGrid1u2 = 1.0;
946 ctx->Eval.MapGrid2un = 1;
947 ctx->Eval.MapGrid2vn = 1;
948 ctx->Eval.MapGrid2u1 = 0.0;
949 ctx->Eval.MapGrid2u2 = 1.0;
950 ctx->Eval.MapGrid2v1 = 0.0;
951 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000952
Brian Paul4d053dd2000-01-14 04:45:47 +0000953 /* Evaluator data */
954 {
955 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
956 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
957 static GLfloat index[1] = { 1.0 };
958 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
959 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000960
Brian Paul4d053dd2000-01-14 04:45:47 +0000961 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
962 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
963 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
964 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
965 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
966 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
967 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
968 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
969 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000970
Brian Paul4d053dd2000-01-14 04:45:47 +0000971 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
972 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
973 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
974 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
975 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
976 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
977 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
978 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
979 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
980 }
jtgafb833d1999-08-19 00:55:39 +0000981
Brian Paul4d053dd2000-01-14 04:45:47 +0000982 /* Fog group */
983 ctx->Fog.Enabled = GL_FALSE;
984 ctx->Fog.Mode = GL_EXP;
985 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
986 ctx->Fog.Index = 0.0;
987 ctx->Fog.Density = 1.0;
988 ctx->Fog.Start = 0.0;
989 ctx->Fog.End = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000990
Brian Paul4d053dd2000-01-14 04:45:47 +0000991 /* Hint group */
992 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
993 ctx->Hint.PointSmooth = GL_DONT_CARE;
994 ctx->Hint.LineSmooth = GL_DONT_CARE;
995 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
996 ctx->Hint.Fog = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000997
Brian Paul4d053dd2000-01-14 04:45:47 +0000998 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000999 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001000 ctx->Hint.AllowDrawMem = GL_TRUE;
1001 ctx->Hint.StrictLighting = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001002
Brian Paul0771d152000-04-07 00:19:41 +00001003 /* Histogram group */
1004 ctx->Histogram.Width = 0;
1005 ctx->Histogram.Format = GL_RGBA;
1006 ctx->Histogram.Sink = GL_FALSE;
1007 ctx->Histogram.RedSize = 0xffffffff;
1008 ctx->Histogram.GreenSize = 0xffffffff;
1009 ctx->Histogram.BlueSize = 0xffffffff;
1010 ctx->Histogram.AlphaSize = 0xffffffff;
1011 ctx->Histogram.LuminanceSize = 0xffffffff;
1012 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
1013 ctx->Histogram.Count[i][0] = 0;
1014 ctx->Histogram.Count[i][1] = 0;
1015 ctx->Histogram.Count[i][2] = 0;
1016 ctx->Histogram.Count[i][3] = 0;
1017 }
1018
1019 /* Min/Max group */
1020 ctx->MinMax.Format = GL_RGBA;
1021 ctx->MinMax.Sink = GL_FALSE;
1022 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
1023 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
1024 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
1025 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
1026
1027
1028
Brian Paul4d053dd2000-01-14 04:45:47 +00001029 /* Pipeline */
1030 gl_pipeline_init( ctx );
1031 gl_cva_init( ctx );
jtgafb833d1999-08-19 00:55:39 +00001032
Brian Paul4d053dd2000-01-14 04:45:47 +00001033 /* Extensions */
1034 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +00001035
Brian Paul4d053dd2000-01-14 04:45:47 +00001036 ctx->AllowVertexCull = CLIP_CULLED_BIT;
jtgafb833d1999-08-19 00:55:39 +00001037
Brian Paul4d053dd2000-01-14 04:45:47 +00001038 /* Lighting group */
1039 for (i=0;i<MAX_LIGHTS;i++) {
1040 init_light( &ctx->Light.Light[i], i );
1041 }
1042 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001043
Brian Paul4d053dd2000-01-14 04:45:47 +00001044 init_lightmodel( &ctx->Light.Model );
1045 init_material( &ctx->Light.Material[0] );
1046 init_material( &ctx->Light.Material[1] );
1047 ctx->Light.ShadeModel = GL_SMOOTH;
1048 ctx->Light.Enabled = GL_FALSE;
1049 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1050 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
1051 ctx->Light.ColorMaterialBitmask
1052 = gl_material_bitmask( ctx,
1053 GL_FRONT_AND_BACK,
1054 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001055
Brian Paul4d053dd2000-01-14 04:45:47 +00001056 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001057
Brian Paul4d053dd2000-01-14 04:45:47 +00001058 /* Lighting miscellaneous */
1059 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1060 make_empty_list( ctx->ShineTabList );
1061 for (i = 0 ; i < 10 ; i++) {
1062 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1063 s->shininess = -1;
1064 s->refcount = 0;
1065 insert_at_tail( ctx->ShineTabList, s );
1066 }
1067 for (i = 0 ; i < 4 ; i++) {
1068 ctx->ShineTable[i] = ctx->ShineTabList->prev;
1069 ctx->ShineTable[i]->refcount++;
1070 }
jtgafb833d1999-08-19 00:55:39 +00001071
jtgafb833d1999-08-19 00:55:39 +00001072
Brian Paul4d053dd2000-01-14 04:45:47 +00001073 /* Line group */
1074 ctx->Line.SmoothFlag = GL_FALSE;
1075 ctx->Line.StippleFlag = GL_FALSE;
1076 ctx->Line.Width = 1.0;
1077 ctx->Line.StipplePattern = 0xffff;
1078 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001079
Brian Paul4d053dd2000-01-14 04:45:47 +00001080 /* Display List group */
1081 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001082
Brian Paul4d053dd2000-01-14 04:45:47 +00001083 /* Pixel group */
1084 ctx->Pixel.RedBias = 0.0;
1085 ctx->Pixel.RedScale = 1.0;
1086 ctx->Pixel.GreenBias = 0.0;
1087 ctx->Pixel.GreenScale = 1.0;
1088 ctx->Pixel.BlueBias = 0.0;
1089 ctx->Pixel.BlueScale = 1.0;
1090 ctx->Pixel.AlphaBias = 0.0;
1091 ctx->Pixel.AlphaScale = 1.0;
1092 ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
1093 ctx->Pixel.DepthBias = 0.0;
1094 ctx->Pixel.DepthScale = 1.0;
1095 ctx->Pixel.IndexOffset = 0;
1096 ctx->Pixel.IndexShift = 0;
1097 ctx->Pixel.ZoomX = 1.0;
1098 ctx->Pixel.ZoomY = 1.0;
1099 ctx->Pixel.MapColorFlag = GL_FALSE;
1100 ctx->Pixel.MapStencilFlag = GL_FALSE;
1101 ctx->Pixel.MapStoSsize = 1;
1102 ctx->Pixel.MapItoIsize = 1;
1103 ctx->Pixel.MapItoRsize = 1;
1104 ctx->Pixel.MapItoGsize = 1;
1105 ctx->Pixel.MapItoBsize = 1;
1106 ctx->Pixel.MapItoAsize = 1;
1107 ctx->Pixel.MapRtoRsize = 1;
1108 ctx->Pixel.MapGtoGsize = 1;
1109 ctx->Pixel.MapBtoBsize = 1;
1110 ctx->Pixel.MapAtoAsize = 1;
1111 ctx->Pixel.MapStoS[0] = 0;
1112 ctx->Pixel.MapItoI[0] = 0;
1113 ctx->Pixel.MapItoR[0] = 0.0;
1114 ctx->Pixel.MapItoG[0] = 0.0;
1115 ctx->Pixel.MapItoB[0] = 0.0;
1116 ctx->Pixel.MapItoA[0] = 0.0;
1117 ctx->Pixel.MapItoR8[0] = 0;
1118 ctx->Pixel.MapItoG8[0] = 0;
1119 ctx->Pixel.MapItoB8[0] = 0;
1120 ctx->Pixel.MapItoA8[0] = 0;
1121 ctx->Pixel.MapRtoR[0] = 0.0;
1122 ctx->Pixel.MapGtoG[0] = 0.0;
1123 ctx->Pixel.MapBtoB[0] = 0.0;
1124 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001125 ctx->Pixel.HistogramEnabled = GL_FALSE;
1126 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1127 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1128 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1129 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul250069d2000-04-08 18:57:45 +00001130 ctx->Pixel.PostColorMatrixRedBias = 0.0;
1131 ctx->Pixel.PostColorMatrixRedScale = 1.0;
1132 ctx->Pixel.PostColorMatrixGreenBias = 0.0;
1133 ctx->Pixel.PostColorMatrixGreenScale = 1.0;
1134 ctx->Pixel.PostColorMatrixBlueBias = 0.0;
1135 ctx->Pixel.PostColorMatrixBlueScale = 1.0;
1136 ctx->Pixel.PostColorMatrixAlphaBias = 0.0;
1137 ctx->Pixel.PostColorMatrixAlphaScale = 1.0;
Brian Paul4fe34b22000-04-11 15:07:48 +00001138 ctx->Pixel.ColorTableScale[0] = 1.0F;
1139 ctx->Pixel.ColorTableScale[1] = 1.0F;
1140 ctx->Pixel.ColorTableScale[2] = 1.0F;
1141 ctx->Pixel.ColorTableScale[3] = 1.0F;
1142 ctx->Pixel.ColorTableBias[0] = 0.0F;
1143 ctx->Pixel.ColorTableBias[1] = 0.0F;
1144 ctx->Pixel.ColorTableBias[2] = 0.0F;
1145 ctx->Pixel.ColorTableBias[3] = 0.0F;
1146 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1147 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1148 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001149
Brian Paul4d053dd2000-01-14 04:45:47 +00001150 /* Point group */
1151 ctx->Point.SmoothFlag = GL_FALSE;
1152 ctx->Point.Size = 1.0;
1153 ctx->Point.Params[0] = 1.0;
1154 ctx->Point.Params[1] = 0.0;
1155 ctx->Point.Params[2] = 0.0;
1156 ctx->Point.Attenuated = GL_FALSE;
1157 ctx->Point.MinSize = 0.0;
1158 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1159 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001160
Brian Paul4d053dd2000-01-14 04:45:47 +00001161 /* Polygon group */
1162 ctx->Polygon.CullFlag = GL_FALSE;
1163 ctx->Polygon.CullFaceMode = GL_BACK;
1164 ctx->Polygon.FrontFace = GL_CCW;
1165 ctx->Polygon.FrontBit = 0;
1166 ctx->Polygon.FrontMode = GL_FILL;
1167 ctx->Polygon.BackMode = GL_FILL;
1168 ctx->Polygon.Unfilled = GL_FALSE;
1169 ctx->Polygon.SmoothFlag = GL_FALSE;
1170 ctx->Polygon.StippleFlag = GL_FALSE;
1171 ctx->Polygon.OffsetFactor = 0.0F;
1172 ctx->Polygon.OffsetUnits = 0.0F;
1173 ctx->Polygon.OffsetPoint = GL_FALSE;
1174 ctx->Polygon.OffsetLine = GL_FALSE;
1175 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001176
Brian Paul4d053dd2000-01-14 04:45:47 +00001177 /* Polygon Stipple group */
1178 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001179
Brian Paul4d053dd2000-01-14 04:45:47 +00001180 /* Scissor group */
1181 ctx->Scissor.Enabled = GL_FALSE;
1182 ctx->Scissor.X = 0;
1183 ctx->Scissor.Y = 0;
1184 ctx->Scissor.Width = 0;
1185 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001186
Brian Paul4d053dd2000-01-14 04:45:47 +00001187 /* Stencil group */
1188 ctx->Stencil.Enabled = GL_FALSE;
1189 ctx->Stencil.Function = GL_ALWAYS;
1190 ctx->Stencil.FailFunc = GL_KEEP;
1191 ctx->Stencil.ZPassFunc = GL_KEEP;
1192 ctx->Stencil.ZFailFunc = GL_KEEP;
1193 ctx->Stencil.Ref = 0;
1194 ctx->Stencil.ValueMask = STENCIL_MAX;
1195 ctx->Stencil.Clear = 0;
1196 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001197
Brian Paul4d053dd2000-01-14 04:45:47 +00001198 /* Texture group */
1199 ctx->Texture.CurrentUnit = 0; /* multitexture */
1200 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
1201 ctx->Texture.Enabled = 0;
1202 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1203 init_texture_unit( ctx, i );
1204 init_color_table(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001205
Brian Paul4d053dd2000-01-14 04:45:47 +00001206 /* Transformation group */
1207 ctx->Transform.MatrixMode = GL_MODELVIEW;
1208 ctx->Transform.Normalize = GL_FALSE;
1209 ctx->Transform.RescaleNormals = GL_FALSE;
1210 for (i=0;i<MAX_CLIP_PLANES;i++) {
1211 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1212 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1213 }
1214 ctx->Transform.AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001215
Brian Paul4d053dd2000-01-14 04:45:47 +00001216 /* Viewport group */
1217 ctx->Viewport.X = 0;
1218 ctx->Viewport.Y = 0;
1219 ctx->Viewport.Width = 0;
1220 ctx->Viewport.Height = 0;
1221 ctx->Viewport.Near = 0.0;
1222 ctx->Viewport.Far = 1.0;
1223 gl_matrix_ctr(&ctx->Viewport.WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001224
1225#define Sz 10
1226#define Tz 14
Brian Pauled30dfa2000-03-03 17:47:39 +00001227 ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual->DepthMaxF;
1228 ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001229#undef Sz
1230#undef Tz
1231
Brian Paul4d053dd2000-01-14 04:45:47 +00001232 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1233 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001234
Brian Paul4d053dd2000-01-14 04:45:47 +00001235 /* Vertex arrays */
1236 ctx->Array.Vertex.Size = 4;
1237 ctx->Array.Vertex.Type = GL_FLOAT;
1238 ctx->Array.Vertex.Stride = 0;
1239 ctx->Array.Vertex.StrideB = 0;
1240 ctx->Array.Vertex.Ptr = NULL;
1241 ctx->Array.Vertex.Enabled = GL_FALSE;
1242 ctx->Array.Normal.Type = GL_FLOAT;
1243 ctx->Array.Normal.Stride = 0;
1244 ctx->Array.Normal.StrideB = 0;
1245 ctx->Array.Normal.Ptr = NULL;
1246 ctx->Array.Normal.Enabled = GL_FALSE;
1247 ctx->Array.Color.Size = 4;
1248 ctx->Array.Color.Type = GL_FLOAT;
1249 ctx->Array.Color.Stride = 0;
1250 ctx->Array.Color.StrideB = 0;
1251 ctx->Array.Color.Ptr = NULL;
1252 ctx->Array.Color.Enabled = GL_FALSE;
1253 ctx->Array.Index.Type = GL_FLOAT;
1254 ctx->Array.Index.Stride = 0;
1255 ctx->Array.Index.StrideB = 0;
1256 ctx->Array.Index.Ptr = NULL;
1257 ctx->Array.Index.Enabled = GL_FALSE;
1258 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1259 ctx->Array.TexCoord[i].Size = 4;
1260 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1261 ctx->Array.TexCoord[i].Stride = 0;
1262 ctx->Array.TexCoord[i].StrideB = 0;
1263 ctx->Array.TexCoord[i].Ptr = NULL;
1264 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1265 }
1266 ctx->Array.TexCoordInterleaveFactor = 1;
1267 ctx->Array.EdgeFlag.Stride = 0;
1268 ctx->Array.EdgeFlag.StrideB = 0;
1269 ctx->Array.EdgeFlag.Ptr = NULL;
1270 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1271 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1272
1273 /* Pixel transfer */
1274 ctx->Pack.Alignment = 4;
1275 ctx->Pack.RowLength = 0;
1276 ctx->Pack.ImageHeight = 0;
1277 ctx->Pack.SkipPixels = 0;
1278 ctx->Pack.SkipRows = 0;
1279 ctx->Pack.SkipImages = 0;
1280 ctx->Pack.SwapBytes = GL_FALSE;
1281 ctx->Pack.LsbFirst = GL_FALSE;
1282 ctx->Unpack.Alignment = 4;
1283 ctx->Unpack.RowLength = 0;
1284 ctx->Unpack.ImageHeight = 0;
1285 ctx->Unpack.SkipPixels = 0;
1286 ctx->Unpack.SkipRows = 0;
1287 ctx->Unpack.SkipImages = 0;
1288 ctx->Unpack.SwapBytes = GL_FALSE;
1289 ctx->Unpack.LsbFirst = GL_FALSE;
1290
1291 /* Feedback */
1292 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1293 ctx->Feedback.Buffer = NULL;
1294 ctx->Feedback.BufferSize = 0;
1295 ctx->Feedback.Count = 0;
1296
1297 /* Selection/picking */
1298 ctx->Select.Buffer = NULL;
1299 ctx->Select.BufferSize = 0;
1300 ctx->Select.BufferCount = 0;
1301 ctx->Select.Hits = 0;
1302 ctx->Select.NameStackDepth = 0;
1303
1304 /* Optimized Accum buffer */
1305 ctx->IntegerAccumMode = GL_TRUE;
1306 ctx->IntegerAccumScaler = 0.0;
1307
1308 /* Renderer and client attribute stacks */
1309 ctx->AttribStackDepth = 0;
1310 ctx->ClientAttribStackDepth = 0;
1311
1312 /* Miscellaneous */
1313 ctx->NewState = NEW_ALL;
1314 ctx->RenderMode = GL_RENDER;
1315 ctx->StippleCounter = 0;
1316 ctx->NeedNormals = GL_FALSE;
1317 ctx->DoViewportMapping = GL_TRUE;
1318
1319 ctx->NeedEyeCoords = GL_FALSE;
1320 ctx->NeedEyeNormals = GL_FALSE;
1321 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1322
1323 /* Display list */
1324 ctx->CallDepth = 0;
1325 ctx->ExecuteFlag = GL_TRUE;
1326 ctx->CompileFlag = GL_FALSE;
1327 ctx->CurrentListPtr = NULL;
1328 ctx->CurrentBlock = NULL;
1329 ctx->CurrentListNum = 0;
1330 ctx->CurrentPos = 0;
1331
1332 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1333
1334 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001335 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001336 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001337
1338 /* For debug/development only */
1339 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1340 ctx->FirstTimeCurrent = GL_TRUE;
1341
1342 /* Dither disable */
1343 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1344 if (ctx->NoDither) {
1345 if (getenv("MESA_DEBUG")) {
1346 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001347 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001348 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001349 }
1350}
1351
1352
1353
1354
jtgafb833d1999-08-19 00:55:39 +00001355/*
1356 * Allocate the proxy textures. If we run out of memory part way through
1357 * the allocations clean up and return GL_FALSE.
1358 * Return: GL_TRUE=success, GL_FALSE=failure
1359 */
1360static GLboolean alloc_proxy_textures( GLcontext *ctx )
1361{
1362 GLboolean out_of_memory;
1363 GLint i;
1364
1365 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1366 if (!ctx->Texture.Proxy1D) {
1367 return GL_FALSE;
1368 }
1369
1370 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1371 if (!ctx->Texture.Proxy2D) {
1372 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1373 return GL_FALSE;
1374 }
1375
1376 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1377 if (!ctx->Texture.Proxy3D) {
1378 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1379 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1380 return GL_FALSE;
1381 }
1382
1383 out_of_memory = GL_FALSE;
1384 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001385 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1386 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1387 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001388 if (!ctx->Texture.Proxy1D->Image[i]
1389 || !ctx->Texture.Proxy2D->Image[i]
1390 || !ctx->Texture.Proxy3D->Image[i]) {
1391 out_of_memory = GL_TRUE;
1392 }
1393 }
1394 if (out_of_memory) {
1395 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1396 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001397 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001398 }
1399 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001400 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001401 }
1402 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001403 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001404 }
1405 }
1406 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1407 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1408 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1409 return GL_FALSE;
1410 }
1411 else {
1412 return GL_TRUE;
1413 }
1414}
1415
1416
1417
jtgafb833d1999-08-19 00:55:39 +00001418/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001419 * Initialize a GLcontext struct.
jtgafb833d1999-08-19 00:55:39 +00001420 */
Brian Paul4d053dd2000-01-14 04:45:47 +00001421GLboolean gl_initialize_context_data( GLcontext *ctx,
1422 GLvisual *visual,
1423 GLcontext *share_list,
1424 void *driver_ctx,
1425 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001426{
jtgafb833d1999-08-19 00:55:39 +00001427 (void) direct; /* not used */
1428
jtgafb833d1999-08-19 00:55:39 +00001429 /* misc one-time initializations */
1430 one_time_init();
1431
jtgafb833d1999-08-19 00:55:39 +00001432 ctx->DriverCtx = driver_ctx;
1433 ctx->Visual = visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001434 ctx->DrawBuffer = NULL;
1435 ctx->ReadBuffer = NULL;
jtgafb833d1999-08-19 00:55:39 +00001436
1437 ctx->VB = gl_vb_create_for_immediate( ctx );
1438 if (!ctx->VB) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001439 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001440 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001441 }
1442 ctx->input = ctx->VB->IM;
1443
1444 ctx->PB = gl_alloc_pb();
1445 if (!ctx->PB) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001446 FREE( ctx->VB );
1447 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001448 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001449 }
1450
1451 if (share_list) {
1452 /* share the group of display lists of another context */
1453 ctx->Shared = share_list->Shared;
1454 }
1455 else {
1456 /* allocate new group of display lists */
1457 ctx->Shared = alloc_shared_state();
1458 if (!ctx->Shared) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001459 FREE(ctx->VB);
1460 FREE(ctx->PB);
1461 FREE(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001462 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001463 }
1464 }
Brian Paul9560f052000-01-31 23:11:39 +00001465 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001466 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001467 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001468
Brian Paul4d053dd2000-01-14 04:45:47 +00001469 init_attrib_groups( ctx );
1470
jtgafb833d1999-08-19 00:55:39 +00001471 gl_reset_vb( ctx->VB );
1472 gl_reset_input( ctx );
1473
jtgafb833d1999-08-19 00:55:39 +00001474 if (visual->DBflag) {
1475 ctx->Color.DrawBuffer = GL_BACK;
1476 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1477 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1478 ctx->Pixel.ReadBuffer = GL_BACK;
1479 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1480 }
1481 else {
1482 ctx->Color.DrawBuffer = GL_FRONT;
1483 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1484 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1485 ctx->Pixel.ReadBuffer = GL_FRONT;
1486 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1487 }
1488
1489#ifdef PROFILE
1490 init_timings( ctx );
1491#endif
1492
jtgafb833d1999-08-19 00:55:39 +00001493 if (!alloc_proxy_textures(ctx)) {
1494 free_shared_state(ctx, ctx->Shared);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001495 FREE(ctx->VB);
1496 FREE(ctx->PB);
1497 FREE(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001498 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001499 }
jtgafb833d1999-08-19 00:55:39 +00001500
Brian Paulfbd8f211999-11-11 01:22:25 +00001501 /* setup API dispatch tables */
Brian Paul959f8022000-03-19 01:10:11 +00001502 ctx->Exec = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1503 ctx->Save = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001504 if (!ctx->Exec || !ctx->Save) {
1505 free_shared_state(ctx, ctx->Shared);
1506 FREE(ctx->VB);
1507 FREE(ctx->PB);
1508 if (ctx->Exec)
1509 FREE(ctx->Exec);
1510 FREE(ctx);
1511 }
1512 _mesa_init_exec_table( ctx->Exec );
1513 _mesa_init_dlist_table( ctx->Save );
1514 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001515
Brian Paul4d053dd2000-01-14 04:45:47 +00001516 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001517}
1518
jtgafb833d1999-08-19 00:55:39 +00001519
1520
1521/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001522 * Allocate and initialize a GLcontext structure.
1523 * Input: visual - a GLvisual pointer
1524 * sharelist - another context to share display lists with or NULL
1525 * driver_ctx - pointer to device driver's context state struct
1526 * Return: pointer to a new gl_context struct or NULL if error.
1527 */
1528GLcontext *gl_create_context( GLvisual *visual,
1529 GLcontext *share_list,
1530 void *driver_ctx,
1531 GLboolean direct )
1532{
1533 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1534 if (!ctx) {
1535 return NULL;
1536 }
1537
1538 if (gl_initialize_context_data(ctx, visual, share_list,
1539 driver_ctx, direct)) {
1540 return ctx;
1541 }
1542 else {
1543 FREE(ctx);
1544 return NULL;
1545 }
1546}
1547
1548
1549
1550/*
1551 * Free the data associated with the given context.
1552 * But don't free() the GLcontext struct itself!
1553 */
1554void gl_free_context_data( GLcontext *ctx )
1555{
Brian Paul4d053dd2000-01-14 04:45:47 +00001556 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001557 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001558
1559 /* if we're destroying the current context, unbind it first */
1560 if (ctx == gl_get_current_context()) {
1561 gl_make_current(NULL, NULL);
1562 }
1563
1564#ifdef PROFILE
1565 if (getenv("MESA_PROFILE")) {
1566 print_timings( ctx );
1567 }
1568#endif
1569
1570 gl_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001571 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001572 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1573 }
1574 gl_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001575 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001576 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1577 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001578 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1579 gl_matrix_dtr( &ctx->TextureMatrix[i] );
1580 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1581 gl_matrix_dtr( &ctx->TextureStack[i][j] );
1582 }
1583 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001584
1585 FREE( ctx->PB );
1586
1587 if(ctx->input != ctx->VB->IM)
1588 gl_immediate_free( ctx->input );
1589
1590 gl_vb_free( ctx->VB );
1591
Brian Paul9560f052000-01-31 23:11:39 +00001592 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001593 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001594 assert(ctx->Shared->RefCount >= 0);
1595 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1596 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001597 /* free shared state */
1598 free_shared_state( ctx, ctx->Shared );
1599 }
1600
1601 foreach_s( s, tmps, ctx->ShineTabList ) {
1602 FREE( s );
1603 }
1604 FREE( ctx->ShineTabList );
1605
1606 /* Free proxy texture objects */
1607 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1608 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1609 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1610
1611 /* Free evaluator data */
1612 if (ctx->EvalMap.Map1Vertex3.Points)
1613 FREE( ctx->EvalMap.Map1Vertex3.Points );
1614 if (ctx->EvalMap.Map1Vertex4.Points)
1615 FREE( ctx->EvalMap.Map1Vertex4.Points );
1616 if (ctx->EvalMap.Map1Index.Points)
1617 FREE( ctx->EvalMap.Map1Index.Points );
1618 if (ctx->EvalMap.Map1Color4.Points)
1619 FREE( ctx->EvalMap.Map1Color4.Points );
1620 if (ctx->EvalMap.Map1Normal.Points)
1621 FREE( ctx->EvalMap.Map1Normal.Points );
1622 if (ctx->EvalMap.Map1Texture1.Points)
1623 FREE( ctx->EvalMap.Map1Texture1.Points );
1624 if (ctx->EvalMap.Map1Texture2.Points)
1625 FREE( ctx->EvalMap.Map1Texture2.Points );
1626 if (ctx->EvalMap.Map1Texture3.Points)
1627 FREE( ctx->EvalMap.Map1Texture3.Points );
1628 if (ctx->EvalMap.Map1Texture4.Points)
1629 FREE( ctx->EvalMap.Map1Texture4.Points );
1630
1631 if (ctx->EvalMap.Map2Vertex3.Points)
1632 FREE( ctx->EvalMap.Map2Vertex3.Points );
1633 if (ctx->EvalMap.Map2Vertex4.Points)
1634 FREE( ctx->EvalMap.Map2Vertex4.Points );
1635 if (ctx->EvalMap.Map2Index.Points)
1636 FREE( ctx->EvalMap.Map2Index.Points );
1637 if (ctx->EvalMap.Map2Color4.Points)
1638 FREE( ctx->EvalMap.Map2Color4.Points );
1639 if (ctx->EvalMap.Map2Normal.Points)
1640 FREE( ctx->EvalMap.Map2Normal.Points );
1641 if (ctx->EvalMap.Map2Texture1.Points)
1642 FREE( ctx->EvalMap.Map2Texture1.Points );
1643 if (ctx->EvalMap.Map2Texture2.Points)
1644 FREE( ctx->EvalMap.Map2Texture2.Points );
1645 if (ctx->EvalMap.Map2Texture3.Points)
1646 FREE( ctx->EvalMap.Map2Texture3.Points );
1647 if (ctx->EvalMap.Map2Texture4.Points)
1648 FREE( ctx->EvalMap.Map2Texture4.Points );
1649
1650 /* Free cache of immediate buffers. */
1651 while (ctx->nr_im_queued-- > 0) {
1652 struct immediate * next = ctx->freed_im_queue->next;
1653 FREE( ctx->freed_im_queue );
1654 ctx->freed_im_queue = next;
1655 }
1656 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001657
1658 FREE(ctx->Exec);
1659 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001660}
1661
1662
1663
1664/*
1665 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001666 */
1667void gl_destroy_context( GLcontext *ctx )
1668{
1669 if (ctx) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001670 gl_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001671 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001672 }
1673}
1674
1675
1676
1677/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001678 * Called by the driver after both the context and driver are fully
1679 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001680 */
Brian Paul00037781999-12-17 14:52:35 +00001681void gl_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001682{
Brian Paul00037781999-12-17 14:52:35 +00001683 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001684}
1685
1686
1687
1688/*
1689 * Copy attribute groups from one context to another.
1690 * Input: src - source context
1691 * dst - destination context
1692 * mask - bitwise OR of GL_*_BIT flags
1693 */
1694void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
1695{
1696 if (mask & GL_ACCUM_BUFFER_BIT) {
1697 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1698 }
1699 if (mask & GL_COLOR_BUFFER_BIT) {
1700 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1701 }
1702 if (mask & GL_CURRENT_BIT) {
1703 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1704 }
1705 if (mask & GL_DEPTH_BUFFER_BIT) {
1706 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1707 }
1708 if (mask & GL_ENABLE_BIT) {
1709 /* no op */
1710 }
1711 if (mask & GL_EVAL_BIT) {
1712 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1713 }
1714 if (mask & GL_FOG_BIT) {
1715 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1716 }
1717 if (mask & GL_HINT_BIT) {
1718 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1719 }
1720 if (mask & GL_LIGHTING_BIT) {
1721 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001722 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001723 }
1724 if (mask & GL_LINE_BIT) {
1725 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1726 }
1727 if (mask & GL_LIST_BIT) {
1728 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1729 }
1730 if (mask & GL_PIXEL_MODE_BIT) {
1731 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1732 }
1733 if (mask & GL_POINT_BIT) {
1734 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1735 }
1736 if (mask & GL_POLYGON_BIT) {
1737 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1738 }
1739 if (mask & GL_POLYGON_STIPPLE_BIT) {
1740 /* Use loop instead of MEMCPY due to problem with Portland Group's
1741 * C compiler. Reported by John Stone.
1742 */
1743 int i;
1744 for (i=0;i<32;i++) {
1745 dst->PolygonStipple[i] = src->PolygonStipple[i];
1746 }
1747 }
1748 if (mask & GL_SCISSOR_BIT) {
1749 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1750 }
1751 if (mask & GL_STENCIL_BUFFER_BIT) {
1752 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1753 }
1754 if (mask & GL_TEXTURE_BIT) {
1755 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1756 }
1757 if (mask & GL_TRANSFORM_BIT) {
1758 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1759 }
1760 if (mask & GL_VIEWPORT_BIT) {
1761 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1762 }
1763}
1764
1765
jtgafb833d1999-08-19 00:55:39 +00001766/*
Brian Paul00037781999-12-17 14:52:35 +00001767 * Set the current context, binding the given frame buffer to the context.
1768 */
1769void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1770{
1771 gl_make_current2( newCtx, buffer, buffer );
1772}
1773
1774
1775/*
1776 * Bind the given context to the given draw-buffer and read-buffer
1777 * and make it the current context for this thread.
1778 */
1779void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1780 GLframebuffer *readBuffer )
1781{
1782#if 0
Brian Paulf9b97d92000-01-28 20:17:42 +00001783 GLcontext *oldCtx = gl_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001784
1785 /* Flush the old context
1786 */
1787 if (oldCtx) {
1788 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
1789
1790 /* unbind frame buffers from context */
1791 if (oldCtx->DrawBuffer) {
1792 oldCtx->DrawBuffer = NULL;
1793 }
1794 if (oldCtx->ReadBuffer) {
1795 oldCtx->ReadBuffer = NULL;
1796 }
1797 }
1798#endif
1799
1800 /* We call this function periodically (just here for now) in
1801 * order to detect when multithreading has begun.
1802 */
1803 _glapi_check_multithread();
1804
Brian Paulf9b97d92000-01-28 20:17:42 +00001805 _glapi_set_context((void *) newCtx);
Brian Paul00037781999-12-17 14:52:35 +00001806 ASSERT(gl_get_current_context() == newCtx);
1807 if (newCtx) {
1808 SET_IMMEDIATE(newCtx, newCtx->input);
1809 _glapi_set_dispatch(newCtx->CurrentDispatch);
1810 }
1811 else {
1812 _glapi_set_dispatch(NULL); /* none current */
1813 }
1814
1815 if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
1816
1817 if (newCtx && drawBuffer && readBuffer) {
1818 /* TODO: check if newCtx and buffer's visual match??? */
1819 newCtx->DrawBuffer = drawBuffer;
1820 newCtx->ReadBuffer = readBuffer;
1821 newCtx->NewState = NEW_ALL; /* just to be safe */
1822 gl_update_state( newCtx );
1823 }
1824
1825 /* We can use this to help debug user's problems. Tell the to set
1826 * the MESA_INFO env variable before running their app. Then the
1827 * first time each context is made current we'll print some useful
1828 * information.
1829 */
1830 if (newCtx && newCtx->FirstTimeCurrent) {
1831 if (getenv("MESA_INFO")) {
1832 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1833 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1834 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1835 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
Brian Paul09cb1481999-12-17 17:00:32 +00001836#if defined(THREADS)
1837 fprintf(stderr, "Mesa thread-safe: YES\n");
1838#else
1839 fprintf(stderr, "Mesa thread-safe: NO\n");
1840#endif
Brian Paul54287052000-01-17 20:00:15 +00001841#if defined(USE_X86_ASM)
1842 fprintf(stderr, "Mesa x86-optimized: YES\n");
1843#else
1844 fprintf(stderr, "Mesa x86-optimized: NO\n");
1845#endif
Brian Paul00037781999-12-17 14:52:35 +00001846 }
1847 newCtx->FirstTimeCurrent = GL_FALSE;
1848 }
1849}
1850
1851
1852
1853/*
1854 * Return current context handle for the calling thread.
1855 * This isn't the fastest way to get the current context.
1856 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1857 */
1858GLcontext *gl_get_current_context( void )
1859{
Brian Paulf9b97d92000-01-28 20:17:42 +00001860 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001861}
1862
1863
1864
1865/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001866 * This should be called by device drivers just before they do a
1867 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001868 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001869void
1870_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001871{
Brian Paulfbd8f211999-11-11 01:22:25 +00001872 FLUSH_VB( ctx, "swap buffers" );
jtgafb833d1999-08-19 00:55:39 +00001873}
1874
1875
Brian Paul00037781999-12-17 14:52:35 +00001876
Brian Paulfbd8f211999-11-11 01:22:25 +00001877/*
1878 * Return pointer to this context's current API dispatch table.
1879 * It'll either be the immediate-mode execute dispatcher or the
1880 * display list compile dispatcher.
1881 */
1882struct _glapi_table *
1883_mesa_get_dispatch(GLcontext *ctx)
1884{
1885 return ctx->CurrentDispatch;
1886}
1887
1888
1889
jtgafb833d1999-08-19 00:55:39 +00001890/**********************************************************************/
1891/***** Miscellaneous functions *****/
1892/**********************************************************************/
1893
1894
1895/*
1896 * This function is called when the Mesa user has stumbled into a code
1897 * path which may not be implemented fully or correctly.
1898 */
1899void gl_problem( const GLcontext *ctx, const char *s )
1900{
1901 fprintf( stderr, "Mesa implementation error: %s\n", s );
1902 fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" );
1903 (void) ctx;
1904}
1905
1906
1907
1908/*
1909 * This is called to inform the user that he or she has tried to do
1910 * something illogical or if there's likely a bug in their program
1911 * (like enabled depth testing without a depth buffer).
1912 */
1913void gl_warning( const GLcontext *ctx, const char *s )
1914{
1915 GLboolean debug;
1916#ifdef DEBUG
1917 debug = GL_TRUE;
1918#else
1919 if (getenv("MESA_DEBUG")) {
1920 debug = GL_TRUE;
1921 }
1922 else {
1923 debug = GL_FALSE;
1924 }
1925#endif
1926 if (debug) {
1927 fprintf( stderr, "Mesa warning: %s\n", s );
1928 }
1929 (void) ctx;
1930}
1931
1932
1933
Brian Paulfa9df402000-02-02 19:16:46 +00001934/*
1935 * Compile an error into current display list.
1936 */
jtgafb833d1999-08-19 00:55:39 +00001937void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
1938{
1939 if (ctx->CompileFlag)
1940 gl_save_error( ctx, error, s );
1941
1942 if (ctx->ExecuteFlag)
1943 gl_error( ctx, error, s );
1944}
1945
1946
Brian Paulfa9df402000-02-02 19:16:46 +00001947
jtgafb833d1999-08-19 00:55:39 +00001948/*
1949 * This is Mesa's error handler. Normally, all that's done is the updating
1950 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1951 * environment variable "MESA_DEBUG" is defined then a real error message
1952 * is printed to stderr.
1953 * Input: error - the error value
1954 * s - a diagnostic string
1955 */
1956void gl_error( GLcontext *ctx, GLenum error, const char *s )
1957{
1958 GLboolean debug;
1959
1960#ifdef DEBUG
1961 debug = GL_TRUE;
1962#else
1963 if (getenv("MESA_DEBUG")) {
1964 debug = GL_TRUE;
1965 }
1966 else {
1967 debug = GL_FALSE;
1968 }
1969#endif
1970
1971 if (debug) {
1972 char errstr[1000];
1973
1974 switch (error) {
1975 case GL_NO_ERROR:
1976 strcpy( errstr, "GL_NO_ERROR" );
1977 break;
1978 case GL_INVALID_VALUE:
1979 strcpy( errstr, "GL_INVALID_VALUE" );
1980 break;
1981 case GL_INVALID_ENUM:
1982 strcpy( errstr, "GL_INVALID_ENUM" );
1983 break;
1984 case GL_INVALID_OPERATION:
1985 strcpy( errstr, "GL_INVALID_OPERATION" );
1986 break;
1987 case GL_STACK_OVERFLOW:
1988 strcpy( errstr, "GL_STACK_OVERFLOW" );
1989 break;
1990 case GL_STACK_UNDERFLOW:
1991 strcpy( errstr, "GL_STACK_UNDERFLOW" );
1992 break;
1993 case GL_OUT_OF_MEMORY:
1994 strcpy( errstr, "GL_OUT_OF_MEMORY" );
1995 break;
1996 default:
1997 strcpy( errstr, "unknown" );
1998 break;
1999 }
2000 fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
2001 }
2002
2003 if (ctx->ErrorValue==GL_NO_ERROR) {
2004 ctx->ErrorValue = error;
2005 }
2006
2007 /* Call device driver's error handler, if any. This is used on the Mac. */
2008 if (ctx->Driver.Error) {
2009 (*ctx->Driver.Error)( ctx );
2010 }
2011}
2012
2013
2014
Brian Paulfa9df402000-02-02 19:16:46 +00002015void
2016_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002017{
Brian Paulfa9df402000-02-02 19:16:46 +00002018 GET_CURRENT_CONTEXT(ctx);
2019 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
2020 if (ctx->Driver.Finish) {
2021 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002022 }
2023}
2024
2025
2026
Brian Paulfa9df402000-02-02 19:16:46 +00002027void
2028_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002029{
Brian Paulfa9df402000-02-02 19:16:46 +00002030 GET_CURRENT_CONTEXT(ctx);
2031 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
2032 if (ctx->Driver.Flush) {
2033 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002034 }
jtgafb833d1999-08-19 00:55:39 +00002035}