blob: 3533b822773709f4049c67750c4d5066b408d93d [file] [log] [blame]
Brian Paule70c6232000-05-04 13:53:55 +00001/* $Id: context.c,v 1.62 2000/05/04 13:53:55 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"
Brian Paul4bdcfe52000-04-17 17:57:04 +000035#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "context.h"
37#include "cva.h"
38#include "depth.h"
39#include "dlist.h"
40#include "eval.h"
41#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000042#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000044#include "get.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000045#include "glapi.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000046#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000047#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "hash.h"
49#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000050#include "macros.h"
51#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000052#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000053#include "mmath.h"
54#include "pb.h"
55#include "pipeline.h"
jtgafb833d1999-08-19 00:55:39 +000056#include "shade.h"
57#include "simple_list.h"
58#include "stencil.h"
59#include "stages.h"
Brian Paulfa9df402000-02-02 19:16:46 +000060#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000061#include "translate.h"
62#include "teximage.h"
63#include "texobj.h"
64#include "texstate.h"
65#include "texture.h"
66#include "types.h"
67#include "varray.h"
68#include "vb.h"
69#include "vbcull.h"
jtgafb833d1999-08-19 00:55:39 +000070#include "vbrender.h"
71#include "vbxform.h"
Keith Whitwell38756791999-08-29 10:26:31 +000072#include "vertices.h"
jtgafb833d1999-08-19 00:55:39 +000073#include "xform.h"
jtgafb833d1999-08-19 00:55:39 +000074#endif
75
76
77
78/**********************************************************************/
79/***** Context and Thread management *****/
80/**********************************************************************/
81
82
Brian Paul00037781999-12-17 14:52:35 +000083#if !defined(THREADS)
jtgafb833d1999-08-19 00:55:39 +000084
Brian Paul5666c632000-01-18 17:36:16 +000085struct immediate *_mesa_CurrentInput = NULL;
jtgafb833d1999-08-19 00:55:39 +000086
Brian Paul00037781999-12-17 14:52:35 +000087#endif
jtgafb833d1999-08-19 00:55:39 +000088
89
jtgafb833d1999-08-19 00:55:39 +000090/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +000091/***** GL Visual allocation/destruction *****/
92/**********************************************************************/
93
94
95/*
96 * Allocate a new GLvisual object.
97 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +000098 * dbFlag - double buffering?
99 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000100 * depthBits - requested bits per depth buffer value
101 * Any value in [0, 32] is acceptable but the actual
102 * depth type will be GLushort or GLuint as needed.
103 * stencilBits - requested minimum bits per stencil buffer value
104 * accumBits - requested minimum bits per accum buffer component
105 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
106 * red/green/blue/alphaBits - number of bits per color component
107 * in frame buffer for RGB(A) mode.
108 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000109 * Return: pointer to new GLvisual or NULL if requested parameters can't
110 * be met.
111 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000112GLvisual *
113_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000114 GLboolean dbFlag,
115 GLboolean stereoFlag,
116 GLint redBits,
117 GLint greenBits,
118 GLint blueBits,
119 GLint alphaBits,
120 GLint indexBits,
121 GLint depthBits,
122 GLint stencilBits,
123 GLint accumRedBits,
124 GLint accumGreenBits,
125 GLint accumBlueBits,
126 GLint accumAlphaBits,
127 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000128{
Brian Paul178a1c52000-04-22 01:05:00 +0000129 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
130 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000131 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000132 redBits, greenBits, blueBits, alphaBits,
133 indexBits, depthBits, stencilBits,
134 accumRedBits, accumGreenBits,
135 accumBlueBits, accumAlphaBits,
136 numSamples )) {
137 FREE(vis);
138 return NULL;
139 }
140 }
141 return vis;
142}
143
144
145/*
146 * Initialize the fields of the given GLvisual.
147 * Input: see _mesa_create_visual() above.
148 * Return: GL_TRUE = success
149 * GL_FALSE = failure.
150 */
151GLboolean
152_mesa_initialize_visual( GLvisual *vis,
153 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000154 GLboolean dbFlag,
155 GLboolean stereoFlag,
156 GLint redBits,
157 GLint greenBits,
158 GLint blueBits,
159 GLint alphaBits,
160 GLint indexBits,
161 GLint depthBits,
162 GLint stencilBits,
163 GLint accumRedBits,
164 GLint accumGreenBits,
165 GLint accumBlueBits,
166 GLint accumAlphaBits,
167 GLint numSamples )
168{
169 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000170
Brian Pauled30dfa2000-03-03 17:47:39 +0000171 /* This is to catch bad values from device drivers not updated for
172 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
173 * bad value now (a 1-bit depth buffer!?!).
174 */
175 assert(depthBits == 0 || depthBits > 1);
176
177 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000178 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000179 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000180 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000181 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000182 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000183 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000184 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000185 }
186 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000187 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000188 }
189 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000190 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000191 }
192 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000193 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000194 }
195
196 vis->RGBAflag = rgbFlag;
197 vis->DBflag = dbFlag;
198 vis->StereoFlag = stereoFlag;
199 vis->RedBits = redBits;
200 vis->GreenBits = greenBits;
201 vis->BlueBits = blueBits;
Brian Paule70c6232000-05-04 13:53:55 +0000202 vis->AlphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000203
Brian Paulb371e0d2000-03-31 01:05:51 +0000204 vis->IndexBits = indexBits;
205 vis->DepthBits = depthBits;
206 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
207 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
208 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
209 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
210 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000211
Brian Pauled30dfa2000-03-03 17:47:39 +0000212 if (depthBits == 0) {
213 /* Special case. Even if we don't have a depth buffer we need
214 * good values for DepthMax for Z vertex transformation purposes.
215 */
216 vis->DepthMax = 1;
217 vis->DepthMaxF = 1.0F;
218 }
219 else {
220 vis->DepthMax = (1 << depthBits) - 1;
221 vis->DepthMaxF = (GLfloat) vis->DepthMax;
222 }
223
Brian Paul178a1c52000-04-22 01:05:00 +0000224 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000225}
226
227
Brian Paulb371e0d2000-03-31 01:05:51 +0000228/* This function should no longer be used. Use _mesa_create_visual() instead */
Brian Paul178a1c52000-04-22 01:05:00 +0000229GLvisual *
230gl_create_visual( GLboolean rgbFlag,
231 GLboolean alphaFlag,
232 GLboolean dbFlag,
233 GLboolean stereoFlag,
234 GLint depthBits,
235 GLint stencilBits,
236 GLint accumBits,
237 GLint indexBits,
238 GLint redBits,
239 GLint greenBits,
240 GLint blueBits,
241 GLint alphaBits )
Brian Paulb371e0d2000-03-31 01:05:51 +0000242{
Brian Paule70c6232000-05-04 13:53:55 +0000243 (void) alphaFlag;
244 return _mesa_create_visual(rgbFlag, dbFlag, stereoFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000245 redBits, greenBits, blueBits, alphaBits,
246 indexBits, depthBits, stencilBits,
247 accumBits, accumBits, accumBits, accumBits, 0);
248}
Brian Paul4d053dd2000-01-14 04:45:47 +0000249
Brian Paulb371e0d2000-03-31 01:05:51 +0000250
251void
252_mesa_destroy_visual( GLvisual *vis )
253{
254 FREE(vis);
255}
256
257
258/* obsolete */
Brian Paul178a1c52000-04-22 01:05:00 +0000259void
260gl_destroy_visual( GLvisual *vis )
Brian Paul4d053dd2000-01-14 04:45:47 +0000261{
Brian Paulb371e0d2000-03-31 01:05:51 +0000262 _mesa_destroy_visual(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000263}
264
265
266
267/**********************************************************************/
268/***** GL Framebuffer allocation/destruction *****/
269/**********************************************************************/
270
271
272/*
273 * Create a new framebuffer. A GLframebuffer is a struct which
274 * encapsulates the depth, stencil and accum buffers and related
275 * parameters.
276 * Input: visual - a GLvisual pointer
277 * softwareDepth - create/use a software depth buffer?
278 * softwareStencil - create/use a software stencil buffer?
279 * softwareAccum - create/use a software accum buffer?
280 * softwareAlpha - create/use a software alpha buffer?
281
282 * Return: pointer to new GLframebuffer struct or NULL if error.
283 */
Brian Paul178a1c52000-04-22 01:05:00 +0000284GLframebuffer *
285gl_create_framebuffer( GLvisual *visual,
286 GLboolean softwareDepth,
287 GLboolean softwareStencil,
288 GLboolean softwareAccum,
289 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000290{
Brian Paul178a1c52000-04-22 01:05:00 +0000291 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
292 assert(visual);
293 if (buffer) {
294 _mesa_initialize_framebuffer(buffer, visual,
295 softwareDepth, softwareStencil,
296 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000297 }
Brian Paul178a1c52000-04-22 01:05:00 +0000298 return buffer;
299}
300
301
302/*
303 * Initialize a GLframebuffer object.
304 * Input: See gl_create_framebuffer() above.
305 */
306void
307_mesa_initialize_framebuffer( GLframebuffer *buffer,
308 GLvisual *visual,
309 GLboolean softwareDepth,
310 GLboolean softwareStencil,
311 GLboolean softwareAccum,
312 GLboolean softwareAlpha )
313{
314 assert(buffer);
315 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000316
317 /* sanity checks */
318 if (softwareDepth ) {
319 assert(visual->DepthBits > 0);
320 }
321 if (softwareStencil) {
322 assert(visual->StencilBits > 0);
323 }
324 if (softwareAccum) {
325 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000326 assert(visual->AccumRedBits > 0);
327 assert(visual->AccumGreenBits > 0);
328 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000329 }
330 if (softwareAlpha) {
331 assert(visual->RGBAflag);
332 assert(visual->AlphaBits > 0);
333 }
334
335 buffer->Visual = visual;
336 buffer->UseSoftwareDepthBuffer = softwareDepth;
337 buffer->UseSoftwareStencilBuffer = softwareStencil;
338 buffer->UseSoftwareAccumBuffer = softwareAccum;
339 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000340}
341
342
Brian Paul4d053dd2000-01-14 04:45:47 +0000343/*
344 * Free a framebuffer struct and its buffers.
345 */
Brian Paul178a1c52000-04-22 01:05:00 +0000346void
347gl_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000348{
349 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000350 if (buffer->DepthBuffer) {
351 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000352 }
353 if (buffer->Accum) {
354 FREE( buffer->Accum );
355 }
356 if (buffer->Stencil) {
357 FREE( buffer->Stencil );
358 }
359 if (buffer->FrontLeftAlpha) {
360 FREE( buffer->FrontLeftAlpha );
361 }
362 if (buffer->BackLeftAlpha) {
363 FREE( buffer->BackLeftAlpha );
364 }
365 if (buffer->FrontRightAlpha) {
366 FREE( buffer->FrontRightAlpha );
367 }
368 if (buffer->BackRightAlpha) {
369 FREE( buffer->BackRightAlpha );
370 }
371 FREE(buffer);
372 }
373}
374
375
376
377/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000378/***** Context allocation, initialization, destroying *****/
379/**********************************************************************/
380
381
Brian Paul9560f052000-01-31 23:11:39 +0000382_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
383
384
jtgafb833d1999-08-19 00:55:39 +0000385/*
386 * This function just calls all the various one-time-init functions in Mesa.
387 */
Brian Paul178a1c52000-04-22 01:05:00 +0000388static void
389one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000390{
391 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000392 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000393 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000394 /* do some implementation tests */
395 assert( sizeof(GLbyte) == 1 );
396 assert( sizeof(GLshort) >= 2 );
397 assert( sizeof(GLint) >= 4 );
398 assert( sizeof(GLubyte) == 1 );
399 assert( sizeof(GLushort) >= 2 );
400 assert( sizeof(GLuint) >= 4 );
401
jtgafb833d1999-08-19 00:55:39 +0000402 gl_init_clip();
403 gl_init_eval();
Brian Paul5829f0c2000-02-02 22:21:39 +0000404 _mesa_init_fog();
Brian Paul780c4e02000-03-22 23:20:12 +0000405 _mesa_init_math();
jtgafb833d1999-08-19 00:55:39 +0000406 gl_init_lists();
407 gl_init_shade();
408 gl_init_texture();
409 gl_init_transformation();
410 gl_init_translate();
411 gl_init_vbrender();
412 gl_init_vbxform();
Keith Whitwell38756791999-08-29 10:26:31 +0000413 gl_init_vertices();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000414
415 if (getenv("MESA_DEBUG")) {
416 _glapi_noop_enable_warnings(GL_TRUE);
417 }
418 else {
419 _glapi_noop_enable_warnings(GL_FALSE);
420 }
421
jtgafb833d1999-08-19 00:55:39 +0000422#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
423 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
424#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000425
426 alreadyCalled = GL_TRUE;
427 }
Brian Paul9560f052000-01-31 23:11:39 +0000428 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000429}
430
431
Brian Paul4d053dd2000-01-14 04:45:47 +0000432
jtgafb833d1999-08-19 00:55:39 +0000433/*
434 * Allocate and initialize a shared context state structure.
435 */
Brian Paul178a1c52000-04-22 01:05:00 +0000436static struct gl_shared_state *
437alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000438{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000439 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000440 struct gl_shared_state *ss;
441 GLboolean outOfMemory;
442
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000443 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000444 if (!ss)
445 return NULL;
446
Brian Paulbb797902000-01-24 16:19:54 +0000447 ss->DisplayList = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000448
Brian Paulbb797902000-01-24 16:19:54 +0000449 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000450
451 /* Default Texture objects */
452 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000453 for (d = 1 ; d <= 3 ; d++) {
454 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
455 if (!ss->DefaultD[d]) {
456 outOfMemory = GL_TRUE;
457 break;
jtgafb833d1999-08-19 00:55:39 +0000458 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000459 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000460 }
461
462 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
463 /* Ran out of memory at some point. Free everything and return NULL */
464 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000465 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000466 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000467 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000468 if (ss->DefaultD[1])
469 gl_free_texture_object(ss, ss->DefaultD[1]);
470 if (ss->DefaultD[2])
471 gl_free_texture_object(ss, ss->DefaultD[2]);
472 if (ss->DefaultD[3])
473 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000474 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000475 return NULL;
476 }
477 else {
478 return ss;
479 }
480}
481
482
483/*
484 * Deallocate a shared state context and all children structures.
485 */
Brian Paul178a1c52000-04-22 01:05:00 +0000486static void
487free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000488{
489 /* Free display lists */
490 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000491 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000492 if (list) {
493 gl_destroy_list(ctx, list);
494 }
495 else {
496 break;
497 }
498 }
Brian Paulbb797902000-01-24 16:19:54 +0000499 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000500
501 /* Free texture objects */
502 while (ss->TexObjectList)
503 {
504 if (ctx->Driver.DeleteTexture)
505 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
506 /* this function removes from linked list too! */
507 gl_free_texture_object(ss, ss->TexObjectList);
508 }
Brian Paulbb797902000-01-24 16:19:54 +0000509 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000510
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000511 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000512}
513
514
515
jtgafb833d1999-08-19 00:55:39 +0000516/*
517 * Initialize the nth light. Note that the defaults for light 0 are
518 * different than the other lights.
519 */
Brian Paul178a1c52000-04-22 01:05:00 +0000520static void
521init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000522{
523 make_empty_list( l );
524
525 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
526 if (n==0) {
527 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
528 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
529 }
530 else {
531 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
532 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
533 }
534 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
535 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
536 l->SpotExponent = 0.0;
537 gl_compute_spot_exp_table( l );
538 l->SpotCutoff = 180.0;
539 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
540 l->ConstantAttenuation = 1.0;
541 l->LinearAttenuation = 0.0;
542 l->QuadraticAttenuation = 0.0;
543 l->Enabled = GL_FALSE;
544}
545
546
547
Brian Paul178a1c52000-04-22 01:05:00 +0000548static void
549init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000550{
551 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
552 lm->LocalViewer = GL_FALSE;
553 lm->TwoSide = GL_FALSE;
554 lm->ColorControl = GL_SINGLE_COLOR;
555}
556
557
Brian Paul178a1c52000-04-22 01:05:00 +0000558static void
559init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000560{
561 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
562 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
563 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
564 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
565 m->Shininess = 0.0;
566 m->AmbientIndex = 0;
567 m->DiffuseIndex = 1;
568 m->SpecularIndex = 1;
569}
570
571
572
Brian Paul178a1c52000-04-22 01:05:00 +0000573static void
574init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000575{
576 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
577
578 texUnit->EnvMode = GL_MODULATE;
579 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
580 texUnit->TexGenEnabled = 0;
581 texUnit->GenModeS = GL_EYE_LINEAR;
582 texUnit->GenModeT = GL_EYE_LINEAR;
583 texUnit->GenModeR = GL_EYE_LINEAR;
584 texUnit->GenModeQ = GL_EYE_LINEAR;
585 /* Yes, these plane coefficients are correct! */
586 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
587 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
588 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
589 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
590 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
591 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
592 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
593 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
594
Brian Paul6e6d4c61999-10-09 20:17:07 +0000595 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
596 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
597 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
jtgafb833d1999-08-19 00:55:39 +0000598}
599
600
Brian Paul178a1c52000-04-22 01:05:00 +0000601static void
602init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000603{
604 struct gl_client_array *cl;
605 GLuint i;
606
607 cl = &ctx->Fallback.Normal;
608 cl->Size = 3;
609 cl->Type = GL_FLOAT;
610 cl->Stride = 0;
611 cl->StrideB = 0;
612 cl->Ptr = (void *) ctx->Current.Normal;
613 cl->Enabled = 1;
614
615 cl = &ctx->Fallback.Color;
616 cl->Size = 4;
617 cl->Type = GL_UNSIGNED_BYTE;
618 cl->Stride = 0;
619 cl->StrideB = 0;
620 cl->Ptr = (void *) ctx->Current.ByteColor;
621 cl->Enabled = 1;
622
623 cl = &ctx->Fallback.Index;
624 cl->Size = 1;
625 cl->Type = GL_UNSIGNED_INT;
626 cl->Stride = 0;
627 cl->StrideB = 0;
628 cl->Ptr = (void *) &ctx->Current.Index;
629 cl->Enabled = 1;
630
631 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
632 cl = &ctx->Fallback.TexCoord[i];
633 cl->Size = 4;
634 cl->Type = GL_FLOAT;
635 cl->Stride = 0;
636 cl->StrideB = 0;
637 cl->Ptr = (void *) ctx->Current.Texcoord[i];
638 cl->Enabled = 1;
639 }
640
641 cl = &ctx->Fallback.EdgeFlag;
642 cl->Size = 1;
643 cl->Type = GL_UNSIGNED_BYTE;
644 cl->Stride = 0;
645 cl->StrideB = 0;
646 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
647 cl->Enabled = 1;
648}
649
Brian Paul4d053dd2000-01-14 04:45:47 +0000650
jtgafb833d1999-08-19 00:55:39 +0000651/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000652static void
653init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000654{
655 map->Order = 1;
656 map->u1 = 0.0;
657 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000658 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000659 if (map->Points) {
660 GLint i;
661 for (i=0;i<n;i++)
662 map->Points[i] = initial[i];
663 }
jtgafb833d1999-08-19 00:55:39 +0000664}
665
666
667/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000668static void
669init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000670{
671 map->Uorder = 1;
672 map->Vorder = 1;
673 map->u1 = 0.0;
674 map->u2 = 1.0;
675 map->v1 = 0.0;
676 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000677 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000678 if (map->Points) {
679 GLint i;
680 for (i=0;i<n;i++)
681 map->Points[i] = initial[i];
682 }
jtgafb833d1999-08-19 00:55:39 +0000683}
684
685
jtgafb833d1999-08-19 00:55:39 +0000686/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000687 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000688 */
Brian Paul178a1c52000-04-22 01:05:00 +0000689static void
690init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000691{
692 GLuint i, j;
693
Brian Paul4d053dd2000-01-14 04:45:47 +0000694 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000695
Brian Paul539cce52000-02-03 19:40:07 +0000696 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000697 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
698 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
699 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
700 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000701 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
702 ctx->Const.MinPointSize = MIN_POINT_SIZE;
703 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
704 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
705 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
706 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
707 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
708 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
709 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
710 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
711 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
712 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000713 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
jtgafb833d1999-08-19 00:55:39 +0000714
Brian Paul4d053dd2000-01-14 04:45:47 +0000715 /* Modelview matrix */
716 gl_matrix_ctr( &ctx->ModelView );
717 gl_matrix_alloc_inv( &ctx->ModelView );
718
719 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000720 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000721 gl_matrix_ctr( &ctx->ModelViewStack[i] );
722 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
723 }
724
725 /* Projection matrix - need inv for user clipping in clip space*/
726 gl_matrix_ctr( &ctx->ProjectionMatrix );
727 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
728
729 gl_matrix_ctr( &ctx->ModelProjectMatrix );
730 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
731 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
732
733 ctx->ProjectionStackDepth = 0;
734 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
735 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
736
Brian Paul7fc29c52000-03-06 17:03:03 +0000737 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000738 gl_matrix_ctr( &ctx->ProjectionStack[i] );
739 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
740 }
741
742 /* Texture matrix */
743 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
744 gl_matrix_ctr( &ctx->TextureMatrix[i] );
745 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000746 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000747 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000748 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000749 }
jtgafb833d1999-08-19 00:55:39 +0000750
Brian Paul250069d2000-04-08 18:57:45 +0000751 /* Color matrix */
752 gl_matrix_ctr(&ctx->ColorMatrix);
753 ctx->ColorStackDepth = 0;
754 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
755 gl_matrix_ctr(&ctx->ColorStack[j]);
756 }
757
Brian Paul4d053dd2000-01-14 04:45:47 +0000758 /* Accumulate buffer group */
759 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000760
Brian Paul4d053dd2000-01-14 04:45:47 +0000761 /* Color buffer group */
762 ctx->Color.IndexMask = 0xffffffff;
763 ctx->Color.ColorMask[0] = 0xff;
764 ctx->Color.ColorMask[1] = 0xff;
765 ctx->Color.ColorMask[2] = 0xff;
766 ctx->Color.ColorMask[3] = 0xff;
767 ctx->Color.SWmasking = GL_FALSE;
768 ctx->Color.ClearIndex = 0;
769 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
770 ctx->Color.DrawBuffer = GL_FRONT;
771 ctx->Color.AlphaEnabled = GL_FALSE;
772 ctx->Color.AlphaFunc = GL_ALWAYS;
773 ctx->Color.AlphaRef = 0;
774 ctx->Color.BlendEnabled = GL_FALSE;
775 ctx->Color.BlendSrcRGB = GL_ONE;
776 ctx->Color.BlendDstRGB = GL_ZERO;
777 ctx->Color.BlendSrcA = GL_ONE;
778 ctx->Color.BlendDstA = GL_ZERO;
779 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
780 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
781 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
782 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
783 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
784 ctx->Color.SWLogicOpEnabled = GL_FALSE;
785 ctx->Color.LogicOp = GL_COPY;
786 ctx->Color.DitherFlag = GL_TRUE;
787 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000788
Brian Paul4d053dd2000-01-14 04:45:47 +0000789 /* Current group */
790 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
791 ctx->Current.Index = 1;
792 for (i=0; i<MAX_TEXTURE_UNITS; i++)
793 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
794 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
795 ctx->Current.RasterDistance = 0.0;
796 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
797 ctx->Current.RasterIndex = 1;
798 for (i=0; i<MAX_TEXTURE_UNITS; i++)
799 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
800 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
801 ctx->Current.RasterPosValid = GL_TRUE;
802 ctx->Current.EdgeFlag = GL_TRUE;
803 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
804 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
jtgafb833d1999-08-19 00:55:39 +0000805
Brian Paul4d053dd2000-01-14 04:45:47 +0000806 ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
807 VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
jtgafb833d1999-08-19 00:55:39 +0000808
Brian Paul4d053dd2000-01-14 04:45:47 +0000809 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000810
Brian Paul4d053dd2000-01-14 04:45:47 +0000811 /* Depth buffer group */
812 ctx->Depth.Test = GL_FALSE;
813 ctx->Depth.Clear = 1.0;
814 ctx->Depth.Func = GL_LESS;
815 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000816 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000817
Brian Paul4d053dd2000-01-14 04:45:47 +0000818 /* Evaluators group */
819 ctx->Eval.Map1Color4 = GL_FALSE;
820 ctx->Eval.Map1Index = GL_FALSE;
821 ctx->Eval.Map1Normal = GL_FALSE;
822 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
823 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
824 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
825 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
826 ctx->Eval.Map1Vertex3 = GL_FALSE;
827 ctx->Eval.Map1Vertex4 = GL_FALSE;
828 ctx->Eval.Map2Color4 = GL_FALSE;
829 ctx->Eval.Map2Index = GL_FALSE;
830 ctx->Eval.Map2Normal = GL_FALSE;
831 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
832 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
833 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
834 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
835 ctx->Eval.Map2Vertex3 = GL_FALSE;
836 ctx->Eval.Map2Vertex4 = GL_FALSE;
837 ctx->Eval.AutoNormal = GL_FALSE;
838 ctx->Eval.MapGrid1un = 1;
839 ctx->Eval.MapGrid1u1 = 0.0;
840 ctx->Eval.MapGrid1u2 = 1.0;
841 ctx->Eval.MapGrid2un = 1;
842 ctx->Eval.MapGrid2vn = 1;
843 ctx->Eval.MapGrid2u1 = 0.0;
844 ctx->Eval.MapGrid2u2 = 1.0;
845 ctx->Eval.MapGrid2v1 = 0.0;
846 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000847
Brian Paul4d053dd2000-01-14 04:45:47 +0000848 /* Evaluator data */
849 {
850 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
851 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
852 static GLfloat index[1] = { 1.0 };
853 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
854 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000855
Brian Paul4d053dd2000-01-14 04:45:47 +0000856 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
857 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
858 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
859 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
860 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
861 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
862 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
863 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
864 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000865
Brian Paul4d053dd2000-01-14 04:45:47 +0000866 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
867 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
868 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
869 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
870 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
871 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
872 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
873 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
874 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
875 }
jtgafb833d1999-08-19 00:55:39 +0000876
Brian Paul4d053dd2000-01-14 04:45:47 +0000877 /* Fog group */
878 ctx->Fog.Enabled = GL_FALSE;
879 ctx->Fog.Mode = GL_EXP;
880 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
881 ctx->Fog.Index = 0.0;
882 ctx->Fog.Density = 1.0;
883 ctx->Fog.Start = 0.0;
884 ctx->Fog.End = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000885
Brian Paul4d053dd2000-01-14 04:45:47 +0000886 /* Hint group */
887 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
888 ctx->Hint.PointSmooth = GL_DONT_CARE;
889 ctx->Hint.LineSmooth = GL_DONT_CARE;
890 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
891 ctx->Hint.Fog = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000892
Brian Paul4d053dd2000-01-14 04:45:47 +0000893 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000894 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000895 ctx->Hint.AllowDrawMem = GL_TRUE;
896 ctx->Hint.StrictLighting = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000897
Brian Paul0771d152000-04-07 00:19:41 +0000898 /* Histogram group */
899 ctx->Histogram.Width = 0;
900 ctx->Histogram.Format = GL_RGBA;
901 ctx->Histogram.Sink = GL_FALSE;
902 ctx->Histogram.RedSize = 0xffffffff;
903 ctx->Histogram.GreenSize = 0xffffffff;
904 ctx->Histogram.BlueSize = 0xffffffff;
905 ctx->Histogram.AlphaSize = 0xffffffff;
906 ctx->Histogram.LuminanceSize = 0xffffffff;
907 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
908 ctx->Histogram.Count[i][0] = 0;
909 ctx->Histogram.Count[i][1] = 0;
910 ctx->Histogram.Count[i][2] = 0;
911 ctx->Histogram.Count[i][3] = 0;
912 }
913
914 /* Min/Max group */
915 ctx->MinMax.Format = GL_RGBA;
916 ctx->MinMax.Sink = GL_FALSE;
917 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
918 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
919 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
920 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
921
922
923
Brian Paul4d053dd2000-01-14 04:45:47 +0000924 /* Pipeline */
925 gl_pipeline_init( ctx );
926 gl_cva_init( ctx );
jtgafb833d1999-08-19 00:55:39 +0000927
Brian Paul4d053dd2000-01-14 04:45:47 +0000928 /* Extensions */
929 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000930
Brian Paul4d053dd2000-01-14 04:45:47 +0000931 ctx->AllowVertexCull = CLIP_CULLED_BIT;
jtgafb833d1999-08-19 00:55:39 +0000932
Brian Paul4d053dd2000-01-14 04:45:47 +0000933 /* Lighting group */
934 for (i=0;i<MAX_LIGHTS;i++) {
935 init_light( &ctx->Light.Light[i], i );
936 }
937 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000938
Brian Paul4d053dd2000-01-14 04:45:47 +0000939 init_lightmodel( &ctx->Light.Model );
940 init_material( &ctx->Light.Material[0] );
941 init_material( &ctx->Light.Material[1] );
942 ctx->Light.ShadeModel = GL_SMOOTH;
943 ctx->Light.Enabled = GL_FALSE;
944 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
945 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
946 ctx->Light.ColorMaterialBitmask
947 = gl_material_bitmask( ctx,
948 GL_FRONT_AND_BACK,
949 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000950
Brian Paul4d053dd2000-01-14 04:45:47 +0000951 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000952
Brian Paul4d053dd2000-01-14 04:45:47 +0000953 /* Lighting miscellaneous */
954 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
955 make_empty_list( ctx->ShineTabList );
956 for (i = 0 ; i < 10 ; i++) {
957 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
958 s->shininess = -1;
959 s->refcount = 0;
960 insert_at_tail( ctx->ShineTabList, s );
961 }
962 for (i = 0 ; i < 4 ; i++) {
963 ctx->ShineTable[i] = ctx->ShineTabList->prev;
964 ctx->ShineTable[i]->refcount++;
965 }
jtgafb833d1999-08-19 00:55:39 +0000966
jtgafb833d1999-08-19 00:55:39 +0000967
Brian Paul4d053dd2000-01-14 04:45:47 +0000968 /* Line group */
969 ctx->Line.SmoothFlag = GL_FALSE;
970 ctx->Line.StippleFlag = GL_FALSE;
971 ctx->Line.Width = 1.0;
972 ctx->Line.StipplePattern = 0xffff;
973 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000974
Brian Paul4d053dd2000-01-14 04:45:47 +0000975 /* Display List group */
976 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +0000977
Brian Paul4d053dd2000-01-14 04:45:47 +0000978 /* Pixel group */
979 ctx->Pixel.RedBias = 0.0;
980 ctx->Pixel.RedScale = 1.0;
981 ctx->Pixel.GreenBias = 0.0;
982 ctx->Pixel.GreenScale = 1.0;
983 ctx->Pixel.BlueBias = 0.0;
984 ctx->Pixel.BlueScale = 1.0;
985 ctx->Pixel.AlphaBias = 0.0;
986 ctx->Pixel.AlphaScale = 1.0;
987 ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
988 ctx->Pixel.DepthBias = 0.0;
989 ctx->Pixel.DepthScale = 1.0;
990 ctx->Pixel.IndexOffset = 0;
991 ctx->Pixel.IndexShift = 0;
992 ctx->Pixel.ZoomX = 1.0;
993 ctx->Pixel.ZoomY = 1.0;
994 ctx->Pixel.MapColorFlag = GL_FALSE;
995 ctx->Pixel.MapStencilFlag = GL_FALSE;
996 ctx->Pixel.MapStoSsize = 1;
997 ctx->Pixel.MapItoIsize = 1;
998 ctx->Pixel.MapItoRsize = 1;
999 ctx->Pixel.MapItoGsize = 1;
1000 ctx->Pixel.MapItoBsize = 1;
1001 ctx->Pixel.MapItoAsize = 1;
1002 ctx->Pixel.MapRtoRsize = 1;
1003 ctx->Pixel.MapGtoGsize = 1;
1004 ctx->Pixel.MapBtoBsize = 1;
1005 ctx->Pixel.MapAtoAsize = 1;
1006 ctx->Pixel.MapStoS[0] = 0;
1007 ctx->Pixel.MapItoI[0] = 0;
1008 ctx->Pixel.MapItoR[0] = 0.0;
1009 ctx->Pixel.MapItoG[0] = 0.0;
1010 ctx->Pixel.MapItoB[0] = 0.0;
1011 ctx->Pixel.MapItoA[0] = 0.0;
1012 ctx->Pixel.MapItoR8[0] = 0;
1013 ctx->Pixel.MapItoG8[0] = 0;
1014 ctx->Pixel.MapItoB8[0] = 0;
1015 ctx->Pixel.MapItoA8[0] = 0;
1016 ctx->Pixel.MapRtoR[0] = 0.0;
1017 ctx->Pixel.MapGtoG[0] = 0.0;
1018 ctx->Pixel.MapBtoB[0] = 0.0;
1019 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001020 ctx->Pixel.HistogramEnabled = GL_FALSE;
1021 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1022 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1023 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1024 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul250069d2000-04-08 18:57:45 +00001025 ctx->Pixel.PostColorMatrixRedBias = 0.0;
1026 ctx->Pixel.PostColorMatrixRedScale = 1.0;
1027 ctx->Pixel.PostColorMatrixGreenBias = 0.0;
1028 ctx->Pixel.PostColorMatrixGreenScale = 1.0;
1029 ctx->Pixel.PostColorMatrixBlueBias = 0.0;
1030 ctx->Pixel.PostColorMatrixBlueScale = 1.0;
1031 ctx->Pixel.PostColorMatrixAlphaBias = 0.0;
1032 ctx->Pixel.PostColorMatrixAlphaScale = 1.0;
Brian Paul4fe34b22000-04-11 15:07:48 +00001033 ctx->Pixel.ColorTableScale[0] = 1.0F;
1034 ctx->Pixel.ColorTableScale[1] = 1.0F;
1035 ctx->Pixel.ColorTableScale[2] = 1.0F;
1036 ctx->Pixel.ColorTableScale[3] = 1.0F;
1037 ctx->Pixel.ColorTableBias[0] = 0.0F;
1038 ctx->Pixel.ColorTableBias[1] = 0.0F;
1039 ctx->Pixel.ColorTableBias[2] = 0.0F;
1040 ctx->Pixel.ColorTableBias[3] = 0.0F;
1041 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1042 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1043 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001044
Brian Paul4d053dd2000-01-14 04:45:47 +00001045 /* Point group */
1046 ctx->Point.SmoothFlag = GL_FALSE;
1047 ctx->Point.Size = 1.0;
1048 ctx->Point.Params[0] = 1.0;
1049 ctx->Point.Params[1] = 0.0;
1050 ctx->Point.Params[2] = 0.0;
1051 ctx->Point.Attenuated = GL_FALSE;
1052 ctx->Point.MinSize = 0.0;
1053 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1054 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001055
Brian Paul4d053dd2000-01-14 04:45:47 +00001056 /* Polygon group */
1057 ctx->Polygon.CullFlag = GL_FALSE;
1058 ctx->Polygon.CullFaceMode = GL_BACK;
1059 ctx->Polygon.FrontFace = GL_CCW;
1060 ctx->Polygon.FrontBit = 0;
1061 ctx->Polygon.FrontMode = GL_FILL;
1062 ctx->Polygon.BackMode = GL_FILL;
1063 ctx->Polygon.Unfilled = GL_FALSE;
1064 ctx->Polygon.SmoothFlag = GL_FALSE;
1065 ctx->Polygon.StippleFlag = GL_FALSE;
1066 ctx->Polygon.OffsetFactor = 0.0F;
1067 ctx->Polygon.OffsetUnits = 0.0F;
1068 ctx->Polygon.OffsetPoint = GL_FALSE;
1069 ctx->Polygon.OffsetLine = GL_FALSE;
1070 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001071
Brian Paul4d053dd2000-01-14 04:45:47 +00001072 /* Polygon Stipple group */
1073 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001074
Brian Paul4d053dd2000-01-14 04:45:47 +00001075 /* Scissor group */
1076 ctx->Scissor.Enabled = GL_FALSE;
1077 ctx->Scissor.X = 0;
1078 ctx->Scissor.Y = 0;
1079 ctx->Scissor.Width = 0;
1080 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001081
Brian Paul4d053dd2000-01-14 04:45:47 +00001082 /* Stencil group */
1083 ctx->Stencil.Enabled = GL_FALSE;
1084 ctx->Stencil.Function = GL_ALWAYS;
1085 ctx->Stencil.FailFunc = GL_KEEP;
1086 ctx->Stencil.ZPassFunc = GL_KEEP;
1087 ctx->Stencil.ZFailFunc = GL_KEEP;
1088 ctx->Stencil.Ref = 0;
1089 ctx->Stencil.ValueMask = STENCIL_MAX;
1090 ctx->Stencil.Clear = 0;
1091 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001092
Brian Paul4d053dd2000-01-14 04:45:47 +00001093 /* Texture group */
1094 ctx->Texture.CurrentUnit = 0; /* multitexture */
1095 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
1096 ctx->Texture.Enabled = 0;
1097 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1098 init_texture_unit( ctx, i );
Brian Paul4bdcfe52000-04-17 17:57:04 +00001099 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001100
Brian Paul4d053dd2000-01-14 04:45:47 +00001101 /* Transformation group */
1102 ctx->Transform.MatrixMode = GL_MODELVIEW;
1103 ctx->Transform.Normalize = GL_FALSE;
1104 ctx->Transform.RescaleNormals = GL_FALSE;
1105 for (i=0;i<MAX_CLIP_PLANES;i++) {
1106 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1107 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1108 }
1109 ctx->Transform.AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001110
Brian Paul4d053dd2000-01-14 04:45:47 +00001111 /* Viewport group */
1112 ctx->Viewport.X = 0;
1113 ctx->Viewport.Y = 0;
1114 ctx->Viewport.Width = 0;
1115 ctx->Viewport.Height = 0;
1116 ctx->Viewport.Near = 0.0;
1117 ctx->Viewport.Far = 1.0;
1118 gl_matrix_ctr(&ctx->Viewport.WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001119
1120#define Sz 10
1121#define Tz 14
Brian Pauled30dfa2000-03-03 17:47:39 +00001122 ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual->DepthMaxF;
1123 ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001124#undef Sz
1125#undef Tz
1126
Brian Paul4d053dd2000-01-14 04:45:47 +00001127 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1128 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001129
Brian Paul4d053dd2000-01-14 04:45:47 +00001130 /* Vertex arrays */
1131 ctx->Array.Vertex.Size = 4;
1132 ctx->Array.Vertex.Type = GL_FLOAT;
1133 ctx->Array.Vertex.Stride = 0;
1134 ctx->Array.Vertex.StrideB = 0;
1135 ctx->Array.Vertex.Ptr = NULL;
1136 ctx->Array.Vertex.Enabled = GL_FALSE;
1137 ctx->Array.Normal.Type = GL_FLOAT;
1138 ctx->Array.Normal.Stride = 0;
1139 ctx->Array.Normal.StrideB = 0;
1140 ctx->Array.Normal.Ptr = NULL;
1141 ctx->Array.Normal.Enabled = GL_FALSE;
1142 ctx->Array.Color.Size = 4;
1143 ctx->Array.Color.Type = GL_FLOAT;
1144 ctx->Array.Color.Stride = 0;
1145 ctx->Array.Color.StrideB = 0;
1146 ctx->Array.Color.Ptr = NULL;
1147 ctx->Array.Color.Enabled = GL_FALSE;
1148 ctx->Array.Index.Type = GL_FLOAT;
1149 ctx->Array.Index.Stride = 0;
1150 ctx->Array.Index.StrideB = 0;
1151 ctx->Array.Index.Ptr = NULL;
1152 ctx->Array.Index.Enabled = GL_FALSE;
1153 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1154 ctx->Array.TexCoord[i].Size = 4;
1155 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1156 ctx->Array.TexCoord[i].Stride = 0;
1157 ctx->Array.TexCoord[i].StrideB = 0;
1158 ctx->Array.TexCoord[i].Ptr = NULL;
1159 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1160 }
1161 ctx->Array.TexCoordInterleaveFactor = 1;
1162 ctx->Array.EdgeFlag.Stride = 0;
1163 ctx->Array.EdgeFlag.StrideB = 0;
1164 ctx->Array.EdgeFlag.Ptr = NULL;
1165 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1166 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1167
1168 /* Pixel transfer */
1169 ctx->Pack.Alignment = 4;
1170 ctx->Pack.RowLength = 0;
1171 ctx->Pack.ImageHeight = 0;
1172 ctx->Pack.SkipPixels = 0;
1173 ctx->Pack.SkipRows = 0;
1174 ctx->Pack.SkipImages = 0;
1175 ctx->Pack.SwapBytes = GL_FALSE;
1176 ctx->Pack.LsbFirst = GL_FALSE;
1177 ctx->Unpack.Alignment = 4;
1178 ctx->Unpack.RowLength = 0;
1179 ctx->Unpack.ImageHeight = 0;
1180 ctx->Unpack.SkipPixels = 0;
1181 ctx->Unpack.SkipRows = 0;
1182 ctx->Unpack.SkipImages = 0;
1183 ctx->Unpack.SwapBytes = GL_FALSE;
1184 ctx->Unpack.LsbFirst = GL_FALSE;
1185
1186 /* Feedback */
1187 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1188 ctx->Feedback.Buffer = NULL;
1189 ctx->Feedback.BufferSize = 0;
1190 ctx->Feedback.Count = 0;
1191
1192 /* Selection/picking */
1193 ctx->Select.Buffer = NULL;
1194 ctx->Select.BufferSize = 0;
1195 ctx->Select.BufferCount = 0;
1196 ctx->Select.Hits = 0;
1197 ctx->Select.NameStackDepth = 0;
1198
1199 /* Optimized Accum buffer */
1200 ctx->IntegerAccumMode = GL_TRUE;
1201 ctx->IntegerAccumScaler = 0.0;
1202
1203 /* Renderer and client attribute stacks */
1204 ctx->AttribStackDepth = 0;
1205 ctx->ClientAttribStackDepth = 0;
1206
Brian Paul13811372000-04-12 00:27:37 +00001207 /* Display list */
1208 ctx->CallDepth = 0;
1209 ctx->ExecuteFlag = GL_TRUE;
1210 ctx->CompileFlag = GL_FALSE;
1211 ctx->CurrentListPtr = NULL;
1212 ctx->CurrentBlock = NULL;
1213 ctx->CurrentListNum = 0;
1214 ctx->CurrentPos = 0;
1215
1216 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001217 _mesa_init_colortable(&ctx->ColorTable);
1218 _mesa_init_colortable(&ctx->ProxyColorTable);
1219 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1220 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1221 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1222 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001223
Brian Paul4d053dd2000-01-14 04:45:47 +00001224 /* Miscellaneous */
1225 ctx->NewState = NEW_ALL;
1226 ctx->RenderMode = GL_RENDER;
1227 ctx->StippleCounter = 0;
1228 ctx->NeedNormals = GL_FALSE;
1229 ctx->DoViewportMapping = GL_TRUE;
1230
1231 ctx->NeedEyeCoords = GL_FALSE;
1232 ctx->NeedEyeNormals = GL_FALSE;
1233 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1234
Brian Paul4d053dd2000-01-14 04:45:47 +00001235 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1236
1237 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001238 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001239 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001240
1241 /* For debug/development only */
1242 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1243 ctx->FirstTimeCurrent = GL_TRUE;
1244
1245 /* Dither disable */
1246 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1247 if (ctx->NoDither) {
1248 if (getenv("MESA_DEBUG")) {
1249 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001250 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001251 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001252 }
1253}
1254
1255
1256
1257
jtgafb833d1999-08-19 00:55:39 +00001258/*
1259 * Allocate the proxy textures. If we run out of memory part way through
1260 * the allocations clean up and return GL_FALSE.
1261 * Return: GL_TRUE=success, GL_FALSE=failure
1262 */
Brian Paul178a1c52000-04-22 01:05:00 +00001263static GLboolean
1264alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001265{
1266 GLboolean out_of_memory;
1267 GLint i;
1268
1269 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1270 if (!ctx->Texture.Proxy1D) {
1271 return GL_FALSE;
1272 }
1273
1274 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1275 if (!ctx->Texture.Proxy2D) {
1276 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1277 return GL_FALSE;
1278 }
1279
1280 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1281 if (!ctx->Texture.Proxy3D) {
1282 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1283 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1284 return GL_FALSE;
1285 }
1286
1287 out_of_memory = GL_FALSE;
1288 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001289 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1290 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1291 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001292 if (!ctx->Texture.Proxy1D->Image[i]
1293 || !ctx->Texture.Proxy2D->Image[i]
1294 || !ctx->Texture.Proxy3D->Image[i]) {
1295 out_of_memory = GL_TRUE;
1296 }
1297 }
1298 if (out_of_memory) {
1299 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1300 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001301 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001302 }
1303 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001304 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001305 }
1306 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001307 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001308 }
1309 }
1310 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1311 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1312 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1313 return GL_FALSE;
1314 }
1315 else {
1316 return GL_TRUE;
1317 }
1318}
1319
1320
1321
jtgafb833d1999-08-19 00:55:39 +00001322/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001323 * Initialize a GLcontext struct.
jtgafb833d1999-08-19 00:55:39 +00001324 */
Brian Paul178a1c52000-04-22 01:05:00 +00001325GLboolean
1326_mesa_initialize_context( GLcontext *ctx,
1327 GLvisual *visual,
1328 GLcontext *share_list,
1329 void *driver_ctx,
1330 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001331{
jtgafb833d1999-08-19 00:55:39 +00001332 (void) direct; /* not used */
1333
jtgafb833d1999-08-19 00:55:39 +00001334 /* misc one-time initializations */
1335 one_time_init();
1336
jtgafb833d1999-08-19 00:55:39 +00001337 ctx->DriverCtx = driver_ctx;
1338 ctx->Visual = visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001339 ctx->DrawBuffer = NULL;
1340 ctx->ReadBuffer = NULL;
jtgafb833d1999-08-19 00:55:39 +00001341
1342 ctx->VB = gl_vb_create_for_immediate( ctx );
1343 if (!ctx->VB) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001344 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001345 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001346 }
1347 ctx->input = ctx->VB->IM;
1348
1349 ctx->PB = gl_alloc_pb();
1350 if (!ctx->PB) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001351 FREE( ctx->VB );
1352 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001353 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001354 }
1355
1356 if (share_list) {
1357 /* share the group of display lists of another context */
1358 ctx->Shared = share_list->Shared;
1359 }
1360 else {
1361 /* allocate new group of display lists */
1362 ctx->Shared = alloc_shared_state();
1363 if (!ctx->Shared) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001364 FREE(ctx->VB);
1365 FREE(ctx->PB);
1366 FREE(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001367 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001368 }
1369 }
Brian Paul9560f052000-01-31 23:11:39 +00001370 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001371 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001372 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001373
Brian Paul4d053dd2000-01-14 04:45:47 +00001374 init_attrib_groups( ctx );
1375
jtgafb833d1999-08-19 00:55:39 +00001376 gl_reset_vb( ctx->VB );
1377 gl_reset_input( ctx );
1378
jtgafb833d1999-08-19 00:55:39 +00001379 if (visual->DBflag) {
1380 ctx->Color.DrawBuffer = GL_BACK;
1381 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1382 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1383 ctx->Pixel.ReadBuffer = GL_BACK;
1384 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1385 }
1386 else {
1387 ctx->Color.DrawBuffer = GL_FRONT;
1388 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1389 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1390 ctx->Pixel.ReadBuffer = GL_FRONT;
1391 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1392 }
1393
jtgafb833d1999-08-19 00:55:39 +00001394 if (!alloc_proxy_textures(ctx)) {
1395 free_shared_state(ctx, ctx->Shared);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001396 FREE(ctx->VB);
1397 FREE(ctx->PB);
1398 FREE(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001399 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001400 }
jtgafb833d1999-08-19 00:55:39 +00001401
Brian Paulfbd8f211999-11-11 01:22:25 +00001402 /* setup API dispatch tables */
Brian Paul959f8022000-03-19 01:10:11 +00001403 ctx->Exec = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1404 ctx->Save = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001405 if (!ctx->Exec || !ctx->Save) {
1406 free_shared_state(ctx, ctx->Shared);
1407 FREE(ctx->VB);
1408 FREE(ctx->PB);
1409 if (ctx->Exec)
1410 FREE(ctx->Exec);
1411 FREE(ctx);
1412 }
1413 _mesa_init_exec_table( ctx->Exec );
1414 _mesa_init_dlist_table( ctx->Save );
1415 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001416
Brian Paul4d053dd2000-01-14 04:45:47 +00001417 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001418}
1419
jtgafb833d1999-08-19 00:55:39 +00001420
1421
1422/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001423 * Allocate and initialize a GLcontext structure.
1424 * Input: visual - a GLvisual pointer
1425 * sharelist - another context to share display lists with or NULL
1426 * driver_ctx - pointer to device driver's context state struct
1427 * Return: pointer to a new gl_context struct or NULL if error.
1428 */
Brian Paul178a1c52000-04-22 01:05:00 +00001429GLcontext *
1430gl_create_context( GLvisual *visual,
1431 GLcontext *share_list,
1432 void *driver_ctx,
1433 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001434{
1435 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1436 if (!ctx) {
1437 return NULL;
1438 }
1439
Brian Paul178a1c52000-04-22 01:05:00 +00001440 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001441 return ctx;
1442 }
1443 else {
1444 FREE(ctx);
1445 return NULL;
1446 }
1447}
1448
1449
1450
1451/*
1452 * Free the data associated with the given context.
1453 * But don't free() the GLcontext struct itself!
1454 */
Brian Paul178a1c52000-04-22 01:05:00 +00001455void
1456gl_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001457{
Brian Paul4d053dd2000-01-14 04:45:47 +00001458 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001459 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001460
1461 /* if we're destroying the current context, unbind it first */
1462 if (ctx == gl_get_current_context()) {
1463 gl_make_current(NULL, NULL);
1464 }
1465
Brian Paul4d053dd2000-01-14 04:45:47 +00001466 gl_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001467 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001468 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1469 }
1470 gl_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001471 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001472 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1473 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001474 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1475 gl_matrix_dtr( &ctx->TextureMatrix[i] );
1476 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1477 gl_matrix_dtr( &ctx->TextureStack[i][j] );
1478 }
1479 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001480
1481 FREE( ctx->PB );
1482
Brian Paul4bdcfe52000-04-17 17:57:04 +00001483 if (ctx->input != ctx->VB->IM)
Brian Paul4d053dd2000-01-14 04:45:47 +00001484 gl_immediate_free( ctx->input );
1485
1486 gl_vb_free( ctx->VB );
1487
Brian Paul9560f052000-01-31 23:11:39 +00001488 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001489 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001490 assert(ctx->Shared->RefCount >= 0);
1491 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1492 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001493 /* free shared state */
1494 free_shared_state( ctx, ctx->Shared );
1495 }
1496
1497 foreach_s( s, tmps, ctx->ShineTabList ) {
1498 FREE( s );
1499 }
1500 FREE( ctx->ShineTabList );
1501
1502 /* Free proxy texture objects */
1503 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1504 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1505 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1506
1507 /* Free evaluator data */
1508 if (ctx->EvalMap.Map1Vertex3.Points)
1509 FREE( ctx->EvalMap.Map1Vertex3.Points );
1510 if (ctx->EvalMap.Map1Vertex4.Points)
1511 FREE( ctx->EvalMap.Map1Vertex4.Points );
1512 if (ctx->EvalMap.Map1Index.Points)
1513 FREE( ctx->EvalMap.Map1Index.Points );
1514 if (ctx->EvalMap.Map1Color4.Points)
1515 FREE( ctx->EvalMap.Map1Color4.Points );
1516 if (ctx->EvalMap.Map1Normal.Points)
1517 FREE( ctx->EvalMap.Map1Normal.Points );
1518 if (ctx->EvalMap.Map1Texture1.Points)
1519 FREE( ctx->EvalMap.Map1Texture1.Points );
1520 if (ctx->EvalMap.Map1Texture2.Points)
1521 FREE( ctx->EvalMap.Map1Texture2.Points );
1522 if (ctx->EvalMap.Map1Texture3.Points)
1523 FREE( ctx->EvalMap.Map1Texture3.Points );
1524 if (ctx->EvalMap.Map1Texture4.Points)
1525 FREE( ctx->EvalMap.Map1Texture4.Points );
1526
1527 if (ctx->EvalMap.Map2Vertex3.Points)
1528 FREE( ctx->EvalMap.Map2Vertex3.Points );
1529 if (ctx->EvalMap.Map2Vertex4.Points)
1530 FREE( ctx->EvalMap.Map2Vertex4.Points );
1531 if (ctx->EvalMap.Map2Index.Points)
1532 FREE( ctx->EvalMap.Map2Index.Points );
1533 if (ctx->EvalMap.Map2Color4.Points)
1534 FREE( ctx->EvalMap.Map2Color4.Points );
1535 if (ctx->EvalMap.Map2Normal.Points)
1536 FREE( ctx->EvalMap.Map2Normal.Points );
1537 if (ctx->EvalMap.Map2Texture1.Points)
1538 FREE( ctx->EvalMap.Map2Texture1.Points );
1539 if (ctx->EvalMap.Map2Texture2.Points)
1540 FREE( ctx->EvalMap.Map2Texture2.Points );
1541 if (ctx->EvalMap.Map2Texture3.Points)
1542 FREE( ctx->EvalMap.Map2Texture3.Points );
1543 if (ctx->EvalMap.Map2Texture4.Points)
1544 FREE( ctx->EvalMap.Map2Texture4.Points );
1545
Brian Paul4bdcfe52000-04-17 17:57:04 +00001546 _mesa_free_colortable_data( &ctx->ColorTable );
1547 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1548 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1549 _mesa_free_colortable_data( &ctx->Texture.Palette );
1550
Brian Paul4d053dd2000-01-14 04:45:47 +00001551 /* Free cache of immediate buffers. */
1552 while (ctx->nr_im_queued-- > 0) {
1553 struct immediate * next = ctx->freed_im_queue->next;
1554 FREE( ctx->freed_im_queue );
1555 ctx->freed_im_queue = next;
1556 }
1557 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001558
1559 FREE(ctx->Exec);
1560 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001561}
1562
1563
1564
1565/*
1566 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001567 */
Brian Paul178a1c52000-04-22 01:05:00 +00001568void
1569gl_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001570{
1571 if (ctx) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001572 gl_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001573 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001574 }
1575}
1576
1577
1578
1579/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001580 * Called by the driver after both the context and driver are fully
1581 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001582 */
Brian Paul178a1c52000-04-22 01:05:00 +00001583void
1584gl_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001585{
Brian Paul00037781999-12-17 14:52:35 +00001586 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001587}
1588
1589
1590
1591/*
1592 * Copy attribute groups from one context to another.
1593 * Input: src - source context
1594 * dst - destination context
1595 * mask - bitwise OR of GL_*_BIT flags
1596 */
Brian Paul178a1c52000-04-22 01:05:00 +00001597void
1598gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001599{
1600 if (mask & GL_ACCUM_BUFFER_BIT) {
1601 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1602 }
1603 if (mask & GL_COLOR_BUFFER_BIT) {
1604 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1605 }
1606 if (mask & GL_CURRENT_BIT) {
1607 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1608 }
1609 if (mask & GL_DEPTH_BUFFER_BIT) {
1610 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1611 }
1612 if (mask & GL_ENABLE_BIT) {
1613 /* no op */
1614 }
1615 if (mask & GL_EVAL_BIT) {
1616 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1617 }
1618 if (mask & GL_FOG_BIT) {
1619 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1620 }
1621 if (mask & GL_HINT_BIT) {
1622 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1623 }
1624 if (mask & GL_LIGHTING_BIT) {
1625 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001626 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001627 }
1628 if (mask & GL_LINE_BIT) {
1629 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1630 }
1631 if (mask & GL_LIST_BIT) {
1632 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1633 }
1634 if (mask & GL_PIXEL_MODE_BIT) {
1635 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1636 }
1637 if (mask & GL_POINT_BIT) {
1638 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1639 }
1640 if (mask & GL_POLYGON_BIT) {
1641 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1642 }
1643 if (mask & GL_POLYGON_STIPPLE_BIT) {
1644 /* Use loop instead of MEMCPY due to problem with Portland Group's
1645 * C compiler. Reported by John Stone.
1646 */
1647 int i;
1648 for (i=0;i<32;i++) {
1649 dst->PolygonStipple[i] = src->PolygonStipple[i];
1650 }
1651 }
1652 if (mask & GL_SCISSOR_BIT) {
1653 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1654 }
1655 if (mask & GL_STENCIL_BUFFER_BIT) {
1656 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1657 }
1658 if (mask & GL_TEXTURE_BIT) {
1659 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1660 }
1661 if (mask & GL_TRANSFORM_BIT) {
1662 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1663 }
1664 if (mask & GL_VIEWPORT_BIT) {
1665 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1666 }
1667}
1668
1669
jtgafb833d1999-08-19 00:55:39 +00001670/*
Brian Paul00037781999-12-17 14:52:35 +00001671 * Set the current context, binding the given frame buffer to the context.
1672 */
1673void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1674{
1675 gl_make_current2( newCtx, buffer, buffer );
1676}
1677
1678
1679/*
1680 * Bind the given context to the given draw-buffer and read-buffer
1681 * and make it the current context for this thread.
1682 */
1683void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1684 GLframebuffer *readBuffer )
1685{
1686#if 0
Brian Paulf9b97d92000-01-28 20:17:42 +00001687 GLcontext *oldCtx = gl_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001688
1689 /* Flush the old context
1690 */
1691 if (oldCtx) {
1692 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
1693
1694 /* unbind frame buffers from context */
1695 if (oldCtx->DrawBuffer) {
1696 oldCtx->DrawBuffer = NULL;
1697 }
1698 if (oldCtx->ReadBuffer) {
1699 oldCtx->ReadBuffer = NULL;
1700 }
1701 }
1702#endif
1703
1704 /* We call this function periodically (just here for now) in
1705 * order to detect when multithreading has begun.
1706 */
1707 _glapi_check_multithread();
1708
Brian Paulf9b97d92000-01-28 20:17:42 +00001709 _glapi_set_context((void *) newCtx);
Brian Paul00037781999-12-17 14:52:35 +00001710 ASSERT(gl_get_current_context() == newCtx);
1711 if (newCtx) {
1712 SET_IMMEDIATE(newCtx, newCtx->input);
1713 _glapi_set_dispatch(newCtx->CurrentDispatch);
1714 }
1715 else {
1716 _glapi_set_dispatch(NULL); /* none current */
1717 }
1718
1719 if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
1720
1721 if (newCtx && drawBuffer && readBuffer) {
1722 /* TODO: check if newCtx and buffer's visual match??? */
1723 newCtx->DrawBuffer = drawBuffer;
1724 newCtx->ReadBuffer = readBuffer;
1725 newCtx->NewState = NEW_ALL; /* just to be safe */
1726 gl_update_state( newCtx );
1727 }
1728
1729 /* We can use this to help debug user's problems. Tell the to set
1730 * the MESA_INFO env variable before running their app. Then the
1731 * first time each context is made current we'll print some useful
1732 * information.
1733 */
1734 if (newCtx && newCtx->FirstTimeCurrent) {
1735 if (getenv("MESA_INFO")) {
1736 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1737 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1738 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1739 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
Brian Paul09cb1481999-12-17 17:00:32 +00001740#if defined(THREADS)
1741 fprintf(stderr, "Mesa thread-safe: YES\n");
1742#else
1743 fprintf(stderr, "Mesa thread-safe: NO\n");
1744#endif
Brian Paul54287052000-01-17 20:00:15 +00001745#if defined(USE_X86_ASM)
1746 fprintf(stderr, "Mesa x86-optimized: YES\n");
1747#else
1748 fprintf(stderr, "Mesa x86-optimized: NO\n");
1749#endif
Brian Paul00037781999-12-17 14:52:35 +00001750 }
1751 newCtx->FirstTimeCurrent = GL_FALSE;
1752 }
1753}
1754
1755
1756
1757/*
1758 * Return current context handle for the calling thread.
1759 * This isn't the fastest way to get the current context.
1760 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1761 */
1762GLcontext *gl_get_current_context( void )
1763{
Brian Paulf9b97d92000-01-28 20:17:42 +00001764 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001765}
1766
1767
1768
1769/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001770 * This should be called by device drivers just before they do a
1771 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001772 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001773void
1774_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001775{
Brian Paulfbd8f211999-11-11 01:22:25 +00001776 FLUSH_VB( ctx, "swap buffers" );
jtgafb833d1999-08-19 00:55:39 +00001777}
1778
1779
Brian Paul00037781999-12-17 14:52:35 +00001780
Brian Paulfbd8f211999-11-11 01:22:25 +00001781/*
1782 * Return pointer to this context's current API dispatch table.
1783 * It'll either be the immediate-mode execute dispatcher or the
1784 * display list compile dispatcher.
1785 */
1786struct _glapi_table *
1787_mesa_get_dispatch(GLcontext *ctx)
1788{
1789 return ctx->CurrentDispatch;
1790}
1791
1792
1793
jtgafb833d1999-08-19 00:55:39 +00001794/**********************************************************************/
1795/***** Miscellaneous functions *****/
1796/**********************************************************************/
1797
1798
1799/*
1800 * This function is called when the Mesa user has stumbled into a code
1801 * path which may not be implemented fully or correctly.
1802 */
1803void gl_problem( const GLcontext *ctx, const char *s )
1804{
1805 fprintf( stderr, "Mesa implementation error: %s\n", s );
1806 fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" );
1807 (void) ctx;
1808}
1809
1810
1811
1812/*
1813 * This is called to inform the user that he or she has tried to do
1814 * something illogical or if there's likely a bug in their program
1815 * (like enabled depth testing without a depth buffer).
1816 */
1817void gl_warning( const GLcontext *ctx, const char *s )
1818{
1819 GLboolean debug;
1820#ifdef DEBUG
1821 debug = GL_TRUE;
1822#else
1823 if (getenv("MESA_DEBUG")) {
1824 debug = GL_TRUE;
1825 }
1826 else {
1827 debug = GL_FALSE;
1828 }
1829#endif
1830 if (debug) {
1831 fprintf( stderr, "Mesa warning: %s\n", s );
1832 }
1833 (void) ctx;
1834}
1835
1836
1837
Brian Paulfa9df402000-02-02 19:16:46 +00001838/*
1839 * Compile an error into current display list.
1840 */
jtgafb833d1999-08-19 00:55:39 +00001841void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
1842{
1843 if (ctx->CompileFlag)
1844 gl_save_error( ctx, error, s );
1845
1846 if (ctx->ExecuteFlag)
1847 gl_error( ctx, error, s );
1848}
1849
1850
Brian Paulfa9df402000-02-02 19:16:46 +00001851
jtgafb833d1999-08-19 00:55:39 +00001852/*
1853 * This is Mesa's error handler. Normally, all that's done is the updating
1854 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1855 * environment variable "MESA_DEBUG" is defined then a real error message
1856 * is printed to stderr.
1857 * Input: error - the error value
1858 * s - a diagnostic string
1859 */
1860void gl_error( GLcontext *ctx, GLenum error, const char *s )
1861{
1862 GLboolean debug;
1863
1864#ifdef DEBUG
1865 debug = GL_TRUE;
1866#else
1867 if (getenv("MESA_DEBUG")) {
1868 debug = GL_TRUE;
1869 }
1870 else {
1871 debug = GL_FALSE;
1872 }
1873#endif
1874
1875 if (debug) {
1876 char errstr[1000];
1877
1878 switch (error) {
1879 case GL_NO_ERROR:
1880 strcpy( errstr, "GL_NO_ERROR" );
1881 break;
1882 case GL_INVALID_VALUE:
1883 strcpy( errstr, "GL_INVALID_VALUE" );
1884 break;
1885 case GL_INVALID_ENUM:
1886 strcpy( errstr, "GL_INVALID_ENUM" );
1887 break;
1888 case GL_INVALID_OPERATION:
1889 strcpy( errstr, "GL_INVALID_OPERATION" );
1890 break;
1891 case GL_STACK_OVERFLOW:
1892 strcpy( errstr, "GL_STACK_OVERFLOW" );
1893 break;
1894 case GL_STACK_UNDERFLOW:
1895 strcpy( errstr, "GL_STACK_UNDERFLOW" );
1896 break;
1897 case GL_OUT_OF_MEMORY:
1898 strcpy( errstr, "GL_OUT_OF_MEMORY" );
1899 break;
1900 default:
1901 strcpy( errstr, "unknown" );
1902 break;
1903 }
1904 fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
1905 }
1906
1907 if (ctx->ErrorValue==GL_NO_ERROR) {
1908 ctx->ErrorValue = error;
1909 }
1910
1911 /* Call device driver's error handler, if any. This is used on the Mac. */
1912 if (ctx->Driver.Error) {
1913 (*ctx->Driver.Error)( ctx );
1914 }
1915}
1916
1917
1918
Brian Paulfa9df402000-02-02 19:16:46 +00001919void
1920_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00001921{
Brian Paulfa9df402000-02-02 19:16:46 +00001922 GET_CURRENT_CONTEXT(ctx);
1923 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
1924 if (ctx->Driver.Finish) {
1925 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001926 }
1927}
1928
1929
1930
Brian Paulfa9df402000-02-02 19:16:46 +00001931void
1932_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00001933{
Brian Paulfa9df402000-02-02 19:16:46 +00001934 GET_CURRENT_CONTEXT(ctx);
1935 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
1936 if (ctx->Driver.Flush) {
1937 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001938 }
jtgafb833d1999-08-19 00:55:39 +00001939}