blob: 2d39b526897653f048675229fa7748684cb3a430 [file] [log] [blame]
Brian Paul5a2f32b2001-04-25 18:21:05 +00001/* $Id: context.c,v 1.133 2001/04/25 18:21:05 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paule4b684c2000-09-12 21:07:40 +00005 * Version: 3.5
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paulb6bcae52001-01-23 23:39:36 +00007 * Copyright (C) 1999-2001 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"
Brian Paulb1394fa2000-09-26 20:53:53 +000032#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000034#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000035#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "dlist.h"
37#include "eval.h"
38#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000039#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000041#include "get.h"
Brian Paul9560f052000-01-31 23:11:39 +000042#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000044#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000045#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000046#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000047#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "mmath.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +000050#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000051#include "teximage.h"
52#include "texobj.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000053#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "varray.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +000055#include "vtxfmt.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000056
57#include "math/m_translate.h"
58#include "math/m_vertices.h"
59#include "math/m_matrix.h"
60#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +000061#include "math/mathmod.h"
jtgafb833d1999-08-19 00:55:39 +000062#endif
63
Brian Paul3b18a362000-09-26 15:27:20 +000064#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000065#include "Trace/tr_context.h"
66#include "Trace/tr_wrapper.h"
67#endif
68
jtgafb833d1999-08-19 00:55:39 +000069
Keith Whitwell23caf202000-11-16 21:05:34 +000070#ifndef MESA_VERBOSE
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000071int MESA_VERBOSE = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000072/* | VERBOSE_PIPELINE */
73/* | VERBOSE_IMMEDIATE */
74/* | VERBOSE_VARRAY */
75/* | VERBOSE_TEXTURE */
76/* | VERBOSE_API */
77/* | VERBOSE_DRIVER */
78/* | VERBOSE_STATE */
Keith Whitwell23caf202000-11-16 21:05:34 +000079/* | VERBOSE_DISPLAY_LIST */
80;
81#endif
82
83#ifndef MESA_DEBUG_FLAGS
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000084int MESA_DEBUG_FLAGS = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000085/* | DEBUG_ALWAYS_FLUSH */
86;
87#endif
Brian Paulb1394fa2000-09-26 20:53:53 +000088
89/**********************************************************************/
90/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
91/**********************************************************************/
92
93static GLboolean
94_mesa_DestroyContext(__GLcontext *gc)
95{
96 if (gc) {
97 _mesa_free_context_data(gc);
98 (*gc->imports.free)(gc, gc);
99 }
100 return GL_TRUE;
101}
102
103
104/* exported OpenGL SI interface */
105__GLcontext *
106__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
107{
108 GLcontext *ctx;
109
110 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
111 if (ctx == NULL) {
112 return NULL;
113 }
114 ctx->imports = *imports;
115
116 _mesa_initialize_visual(&ctx->Visual,
117 modes->rgbMode,
118 modes->doubleBufferMode,
119 modes->stereoMode,
120 modes->redBits,
121 modes->greenBits,
122 modes->blueBits,
123 modes->alphaBits,
124 modes->indexBits,
125 modes->depthBits,
126 modes->stencilBits,
127 modes->accumRedBits,
128 modes->accumGreenBits,
129 modes->accumBlueBits,
130 modes->accumAlphaBits,
131 0);
132
Keith Whitwellb980b2e2001-01-08 04:09:41 +0000133 /* KW: was imports->wscx */
134 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
Brian Paulb1394fa2000-09-26 20:53:53 +0000135
136 ctx->exports.destroyContext = _mesa_DestroyContext;
137
138 return ctx;
139}
140
141
142/* exported OpenGL SI interface */
143void
144__glCoreNopDispatch(void)
145{
146#if 0
147 /* SI */
148 __gl_dispatch = __glNopDispatchState;
149#else
150 /* Mesa */
151 _glapi_set_dispatch(NULL);
152#endif
153}
154
155
jtgafb833d1999-08-19 00:55:39 +0000156/**********************************************************************/
157/***** Context and Thread management *****/
158/**********************************************************************/
159
160
jtgafb833d1999-08-19 00:55:39 +0000161
jtgafb833d1999-08-19 00:55:39 +0000162/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000163/***** GL Visual allocation/destruction *****/
164/**********************************************************************/
165
166
167/*
168 * Allocate a new GLvisual object.
169 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000170 * dbFlag - double buffering?
171 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000172 * depthBits - requested bits per depth buffer value
173 * Any value in [0, 32] is acceptable but the actual
174 * depth type will be GLushort or GLuint as needed.
175 * stencilBits - requested minimum bits per stencil buffer value
176 * accumBits - requested minimum bits per accum buffer component
177 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
178 * red/green/blue/alphaBits - number of bits per color component
179 * in frame buffer for RGB(A) mode.
180 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000181 * Return: pointer to new GLvisual or NULL if requested parameters can't
182 * be met.
183 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000184GLvisual *
185_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000186 GLboolean dbFlag,
187 GLboolean stereoFlag,
188 GLint redBits,
189 GLint greenBits,
190 GLint blueBits,
191 GLint alphaBits,
192 GLint indexBits,
193 GLint depthBits,
194 GLint stencilBits,
195 GLint accumRedBits,
196 GLint accumGreenBits,
197 GLint accumBlueBits,
198 GLint accumAlphaBits,
199 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000200{
Brian Paul178a1c52000-04-22 01:05:00 +0000201 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
202 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000203 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000204 redBits, greenBits, blueBits, alphaBits,
205 indexBits, depthBits, stencilBits,
206 accumRedBits, accumGreenBits,
207 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000208 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000209 FREE(vis);
210 return NULL;
211 }
212 }
213 return vis;
214}
215
216
217/*
218 * Initialize the fields of the given GLvisual.
219 * Input: see _mesa_create_visual() above.
220 * Return: GL_TRUE = success
221 * GL_FALSE = failure.
222 */
223GLboolean
224_mesa_initialize_visual( GLvisual *vis,
225 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000226 GLboolean dbFlag,
227 GLboolean stereoFlag,
228 GLint redBits,
229 GLint greenBits,
230 GLint blueBits,
231 GLint alphaBits,
232 GLint indexBits,
233 GLint depthBits,
234 GLint stencilBits,
235 GLint accumRedBits,
236 GLint accumGreenBits,
237 GLint accumBlueBits,
238 GLint accumAlphaBits,
239 GLint numSamples )
240{
Brian Paulb6bcae52001-01-23 23:39:36 +0000241 (void) numSamples;
242
Brian Paul178a1c52000-04-22 01:05:00 +0000243 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000244
Brian Pauled30dfa2000-03-03 17:47:39 +0000245 /* This is to catch bad values from device drivers not updated for
246 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
247 * bad value now (a 1-bit depth buffer!?!).
248 */
249 assert(depthBits == 0 || depthBits > 1);
250
251 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000252 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000253 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000254 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000255 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000256 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000257 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000258 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000259 }
260 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000261 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000262 }
263 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000264 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000265 }
266 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000267 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000268 }
269
Brian Paulb6bcae52001-01-23 23:39:36 +0000270 vis->rgbMode = rgbFlag;
271 vis->doubleBufferMode = dbFlag;
272 vis->stereoMode = stereoFlag;
273 vis->redBits = redBits;
274 vis->greenBits = greenBits;
275 vis->blueBits = blueBits;
276 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000277
Brian Paulb6bcae52001-01-23 23:39:36 +0000278 vis->indexBits = indexBits;
279 vis->depthBits = depthBits;
280 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
281 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
282 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
283 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
284 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000285
Brian Paul178a1c52000-04-22 01:05:00 +0000286 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000287}
288
289
Brian Paulb371e0d2000-03-31 01:05:51 +0000290void
291_mesa_destroy_visual( GLvisual *vis )
292{
293 FREE(vis);
294}
295
296
Brian Paul4d053dd2000-01-14 04:45:47 +0000297/**********************************************************************/
298/***** GL Framebuffer allocation/destruction *****/
299/**********************************************************************/
300
301
302/*
303 * Create a new framebuffer. A GLframebuffer is a struct which
304 * encapsulates the depth, stencil and accum buffers and related
305 * parameters.
Brian Paulbe3602d2001-02-28 00:27:48 +0000306 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +0000307 * softwareDepth - create/use a software depth buffer?
308 * softwareStencil - create/use a software stencil buffer?
309 * softwareAccum - create/use a software accum buffer?
310 * softwareAlpha - create/use a software alpha buffer?
Brian Paul4d053dd2000-01-14 04:45:47 +0000311 * Return: pointer to new GLframebuffer struct or NULL if error.
312 */
Brian Paul178a1c52000-04-22 01:05:00 +0000313GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000314_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000315 GLboolean softwareDepth,
316 GLboolean softwareStencil,
317 GLboolean softwareAccum,
318 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000319{
Brian Paul178a1c52000-04-22 01:05:00 +0000320 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
321 assert(visual);
322 if (buffer) {
323 _mesa_initialize_framebuffer(buffer, visual,
324 softwareDepth, softwareStencil,
325 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000326 }
Brian Paul178a1c52000-04-22 01:05:00 +0000327 return buffer;
328}
329
330
331/*
332 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000333 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000334 */
335void
336_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000337 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000338 GLboolean softwareDepth,
339 GLboolean softwareStencil,
340 GLboolean softwareAccum,
341 GLboolean softwareAlpha )
342{
343 assert(buffer);
344 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000345
346 /* sanity checks */
347 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000348 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000349 }
350 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000351 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000352 }
353 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000354 assert(visual->rgbMode);
355 assert(visual->accumRedBits > 0);
356 assert(visual->accumGreenBits > 0);
357 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000358 }
359 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000360 assert(visual->rgbMode);
361 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000362 }
363
Brian Paulbe3602d2001-02-28 00:27:48 +0000364 buffer->Visual = *visual; /* XXX copy instead? */
Brian Paul4d053dd2000-01-14 04:45:47 +0000365 buffer->UseSoftwareDepthBuffer = softwareDepth;
366 buffer->UseSoftwareStencilBuffer = softwareStencil;
367 buffer->UseSoftwareAccumBuffer = softwareAccum;
368 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000369}
370
371
Brian Paul4d053dd2000-01-14 04:45:47 +0000372/*
373 * Free a framebuffer struct and its buffers.
374 */
Brian Paul178a1c52000-04-22 01:05:00 +0000375void
Brian Paulb1394fa2000-09-26 20:53:53 +0000376_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000377{
378 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000379 if (buffer->DepthBuffer) {
380 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000381 }
382 if (buffer->Accum) {
383 FREE( buffer->Accum );
384 }
385 if (buffer->Stencil) {
386 FREE( buffer->Stencil );
387 }
388 if (buffer->FrontLeftAlpha) {
389 FREE( buffer->FrontLeftAlpha );
390 }
391 if (buffer->BackLeftAlpha) {
392 FREE( buffer->BackLeftAlpha );
393 }
394 if (buffer->FrontRightAlpha) {
395 FREE( buffer->FrontRightAlpha );
396 }
397 if (buffer->BackRightAlpha) {
398 FREE( buffer->BackRightAlpha );
399 }
400 FREE(buffer);
401 }
402}
403
404
405
406/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000407/***** Context allocation, initialization, destroying *****/
408/**********************************************************************/
409
410
Brian Paul9560f052000-01-31 23:11:39 +0000411_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
412
413
jtgafb833d1999-08-19 00:55:39 +0000414/*
415 * This function just calls all the various one-time-init functions in Mesa.
416 */
Brian Paul178a1c52000-04-22 01:05:00 +0000417static void
418one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000419{
420 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000421 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000422 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000423 /* do some implementation tests */
424 assert( sizeof(GLbyte) == 1 );
425 assert( sizeof(GLshort) >= 2 );
426 assert( sizeof(GLint) >= 4 );
427 assert( sizeof(GLubyte) == 1 );
428 assert( sizeof(GLushort) >= 2 );
429 assert( sizeof(GLuint) >= 4 );
430
Brian Paul08836342001-03-03 20:33:27 +0000431 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000432
Keith Whitwell23caf202000-11-16 21:05:34 +0000433 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000434 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000435
436 if (getenv("MESA_DEBUG")) {
437 _glapi_noop_enable_warnings(GL_TRUE);
438 }
439 else {
440 _glapi_noop_enable_warnings(GL_FALSE);
441 }
442
jtgafb833d1999-08-19 00:55:39 +0000443#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
444 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
445#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000446
447 alreadyCalled = GL_TRUE;
448 }
Brian Paul9560f052000-01-31 23:11:39 +0000449 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000450}
451
452
Brian Paul4d053dd2000-01-14 04:45:47 +0000453
jtgafb833d1999-08-19 00:55:39 +0000454/*
455 * Allocate and initialize a shared context state structure.
456 */
Brian Paul178a1c52000-04-22 01:05:00 +0000457static struct gl_shared_state *
458alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000459{
jtgafb833d1999-08-19 00:55:39 +0000460 struct gl_shared_state *ss;
461 GLboolean outOfMemory;
462
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000463 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000464 if (!ss)
465 return NULL;
466
Brian Paule4b684c2000-09-12 21:07:40 +0000467 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000468
Brian Paule4b684c2000-09-12 21:07:40 +0000469 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000470 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000471
472 /* Default Texture objects */
473 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000474
475 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
476 if (!ss->Default1D) {
477 outOfMemory = GL_TRUE;
478 }
jtgafb833d1999-08-19 00:55:39 +0000479
Brian Paula8523782000-11-19 23:10:25 +0000480 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
481 if (!ss->Default2D) {
482 outOfMemory = GL_TRUE;
483 }
Brian Paula8523782000-11-19 23:10:25 +0000484
485 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
486 if (!ss->Default3D) {
487 outOfMemory = GL_TRUE;
488 }
Brian Paula8523782000-11-19 23:10:25 +0000489
490 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000491 if (!ss->DefaultCubeMap) {
492 outOfMemory = GL_TRUE;
493 }
Brian Paul413d6a22000-05-26 14:44:59 +0000494
jtgafb833d1999-08-19 00:55:39 +0000495 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
496 /* Ran out of memory at some point. Free everything and return NULL */
497 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000498 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000499 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000500 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula8523782000-11-19 23:10:25 +0000501 if (ss->Default1D)
502 _mesa_free_texture_object(ss, ss->Default1D);
503 if (ss->Default2D)
504 _mesa_free_texture_object(ss, ss->Default2D);
505 if (ss->Default3D)
506 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000507 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000508 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000509 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000510 return NULL;
511 }
512 else {
513 return ss;
514 }
515}
516
517
518/*
519 * Deallocate a shared state context and all children structures.
520 */
Brian Paul178a1c52000-04-22 01:05:00 +0000521static void
522free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000523{
524 /* Free display lists */
525 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000526 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000527 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000528 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000529 }
530 else {
531 break;
532 }
533 }
Brian Paulbb797902000-01-24 16:19:54 +0000534 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000535
536 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000537 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000538 if (ctx->Driver.DeleteTexture)
539 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
540 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000541 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000542 }
Brian Paulbb797902000-01-24 16:19:54 +0000543 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000544
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000545 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000546}
547
548
549
jtgafb833d1999-08-19 00:55:39 +0000550/*
551 * Initialize the nth light. Note that the defaults for light 0 are
552 * different than the other lights.
553 */
Brian Paul178a1c52000-04-22 01:05:00 +0000554static void
555init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000556{
557 make_empty_list( l );
558
559 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
560 if (n==0) {
561 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
562 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
563 }
564 else {
565 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
566 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
567 }
568 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
569 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
570 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000571 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000572 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000573 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000574 l->ConstantAttenuation = 1.0;
575 l->LinearAttenuation = 0.0;
576 l->QuadraticAttenuation = 0.0;
577 l->Enabled = GL_FALSE;
578}
579
580
581
Brian Paul178a1c52000-04-22 01:05:00 +0000582static void
583init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000584{
585 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
586 lm->LocalViewer = GL_FALSE;
587 lm->TwoSide = GL_FALSE;
588 lm->ColorControl = GL_SINGLE_COLOR;
589}
590
591
Brian Paul178a1c52000-04-22 01:05:00 +0000592static void
593init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000594{
595 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
596 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
597 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
598 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
599 m->Shininess = 0.0;
600 m->AmbientIndex = 0;
601 m->DiffuseIndex = 1;
602 m->SpecularIndex = 1;
603}
604
605
606
Brian Paul178a1c52000-04-22 01:05:00 +0000607static void
608init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000609{
610 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
611
612 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000613 texUnit->CombineModeRGB = GL_MODULATE;
614 texUnit->CombineModeA = GL_MODULATE;
615 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
616 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
617 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
618 texUnit->CombineSourceA[0] = GL_TEXTURE;
619 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
620 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
621 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
622 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
623 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
624 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
625 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
626 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
627 texUnit->CombineScaleShiftRGB = 0;
628 texUnit->CombineScaleShiftA = 0;
629
jtgafb833d1999-08-19 00:55:39 +0000630 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
631 texUnit->TexGenEnabled = 0;
632 texUnit->GenModeS = GL_EYE_LINEAR;
633 texUnit->GenModeT = GL_EYE_LINEAR;
634 texUnit->GenModeR = GL_EYE_LINEAR;
635 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000636 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
637 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
638 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
639 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000640
jtgafb833d1999-08-19 00:55:39 +0000641 /* Yes, these plane coefficients are correct! */
642 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
643 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
644 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
645 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
646 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
647 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
648 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
649 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
650
Brian Paula8523782000-11-19 23:10:25 +0000651 texUnit->Current1D = ctx->Shared->Default1D;
652 texUnit->Current2D = ctx->Shared->Default2D;
653 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000654 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000655}
656
657
jtgafb833d1999-08-19 00:55:39 +0000658
Brian Paul4d053dd2000-01-14 04:45:47 +0000659
jtgafb833d1999-08-19 00:55:39 +0000660/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000661static void
662init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000663{
664 map->Order = 1;
665 map->u1 = 0.0;
666 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000667 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000668 if (map->Points) {
669 GLint i;
670 for (i=0;i<n;i++)
671 map->Points[i] = initial[i];
672 }
jtgafb833d1999-08-19 00:55:39 +0000673}
674
675
676/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000677static void
678init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000679{
680 map->Uorder = 1;
681 map->Vorder = 1;
682 map->u1 = 0.0;
683 map->u2 = 1.0;
684 map->v1 = 0.0;
685 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000686 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000687 if (map->Points) {
688 GLint i;
689 for (i=0;i<n;i++)
690 map->Points[i] = initial[i];
691 }
jtgafb833d1999-08-19 00:55:39 +0000692}
693
694
jtgafb833d1999-08-19 00:55:39 +0000695/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000696 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000697 */
Brian Paul178a1c52000-04-22 01:05:00 +0000698static void
699init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000700{
701 GLuint i, j;
702
Brian Paul4d053dd2000-01-14 04:45:47 +0000703 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000704
Brian Paul539cce52000-02-03 19:40:07 +0000705 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000706 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
707 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000708 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000709 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000710 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul4d053dd2000-01-14 04:45:47 +0000711 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000712 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
713 ctx->Const.MinPointSize = MIN_POINT_SIZE;
714 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
715 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
716 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
717 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
718 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
719 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
720 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
721 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
722 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
723 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000724 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000725 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
726 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000727 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000728 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
729 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000730
Brian Paul4d053dd2000-01-14 04:45:47 +0000731 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000732 _math_matrix_ctr( &ctx->ModelView );
733 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000734
735 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000736 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000737 _math_matrix_ctr( &ctx->ModelViewStack[i] );
738 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000739 }
740
741 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000742 _math_matrix_ctr( &ctx->ProjectionMatrix );
743 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000744
745 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000746 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000747 _math_matrix_ctr( &ctx->ProjectionStack[i] );
748 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000749 }
750
Keith Whitwell23caf202000-11-16 21:05:34 +0000751 /* Derived ModelProject matrix */
752 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
753
Brian Paul4d053dd2000-01-14 04:45:47 +0000754 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000755 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000756 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000757 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000758 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000759 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000760 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000761 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000762 }
jtgafb833d1999-08-19 00:55:39 +0000763
Brian Paul250069d2000-04-08 18:57:45 +0000764 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000765 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000766 ctx->ColorStackDepth = 0;
767 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000768 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000769 }
770
Brian Paul4d053dd2000-01-14 04:45:47 +0000771 /* Accumulate buffer group */
772 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000773
Brian Paul4d053dd2000-01-14 04:45:47 +0000774 /* Color buffer group */
775 ctx->Color.IndexMask = 0xffffffff;
776 ctx->Color.ColorMask[0] = 0xff;
777 ctx->Color.ColorMask[1] = 0xff;
778 ctx->Color.ColorMask[2] = 0xff;
779 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000780 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000781 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000782 ctx->Color.DrawBuffer = GL_FRONT;
783 ctx->Color.AlphaEnabled = GL_FALSE;
784 ctx->Color.AlphaFunc = GL_ALWAYS;
785 ctx->Color.AlphaRef = 0;
786 ctx->Color.BlendEnabled = GL_FALSE;
787 ctx->Color.BlendSrcRGB = GL_ONE;
788 ctx->Color.BlendDstRGB = GL_ZERO;
789 ctx->Color.BlendSrcA = GL_ONE;
790 ctx->Color.BlendDstA = GL_ZERO;
791 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000792 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
793 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
794 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000795 ctx->Color.LogicOp = GL_COPY;
796 ctx->Color.DitherFlag = GL_TRUE;
797 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000798
Brian Paul4d053dd2000-01-14 04:45:47 +0000799 /* Current group */
Brian Paul19300532000-10-29 19:02:23 +0000800 ASSIGN_4V( ctx->Current.Color, CHAN_MAX, CHAN_MAX, CHAN_MAX, CHAN_MAX );
Brian Paul4d053dd2000-01-14 04:45:47 +0000801 ctx->Current.Index = 1;
802 for (i=0; i<MAX_TEXTURE_UNITS; i++)
803 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
804 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
805 ctx->Current.RasterDistance = 0.0;
806 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
807 ctx->Current.RasterIndex = 1;
808 for (i=0; i<MAX_TEXTURE_UNITS; i++)
809 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
810 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
811 ctx->Current.RasterPosValid = GL_TRUE;
812 ctx->Current.EdgeFlag = GL_TRUE;
813 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000814
jtgafb833d1999-08-19 00:55:39 +0000815
Brian Paul4d053dd2000-01-14 04:45:47 +0000816 /* Depth buffer group */
817 ctx->Depth.Test = GL_FALSE;
818 ctx->Depth.Clear = 1.0;
819 ctx->Depth.Func = GL_LESS;
820 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000821 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000822
Brian Paul4d053dd2000-01-14 04:45:47 +0000823 /* Evaluators group */
824 ctx->Eval.Map1Color4 = GL_FALSE;
825 ctx->Eval.Map1Index = GL_FALSE;
826 ctx->Eval.Map1Normal = GL_FALSE;
827 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
828 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
829 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
830 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
831 ctx->Eval.Map1Vertex3 = GL_FALSE;
832 ctx->Eval.Map1Vertex4 = GL_FALSE;
833 ctx->Eval.Map2Color4 = GL_FALSE;
834 ctx->Eval.Map2Index = GL_FALSE;
835 ctx->Eval.Map2Normal = GL_FALSE;
836 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
837 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
838 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
839 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
840 ctx->Eval.Map2Vertex3 = GL_FALSE;
841 ctx->Eval.Map2Vertex4 = GL_FALSE;
842 ctx->Eval.AutoNormal = GL_FALSE;
843 ctx->Eval.MapGrid1un = 1;
844 ctx->Eval.MapGrid1u1 = 0.0;
845 ctx->Eval.MapGrid1u2 = 1.0;
846 ctx->Eval.MapGrid2un = 1;
847 ctx->Eval.MapGrid2vn = 1;
848 ctx->Eval.MapGrid2u1 = 0.0;
849 ctx->Eval.MapGrid2u2 = 1.0;
850 ctx->Eval.MapGrid2v1 = 0.0;
851 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000852
Brian Paul4d053dd2000-01-14 04:45:47 +0000853 /* Evaluator data */
854 {
855 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
856 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
857 static GLfloat index[1] = { 1.0 };
858 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
859 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000860
Brian Paul4d053dd2000-01-14 04:45:47 +0000861 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
862 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
863 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
864 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
865 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
866 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
867 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
868 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
869 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000870
Brian Paul4d053dd2000-01-14 04:45:47 +0000871 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
872 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
873 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
874 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
875 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
876 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
877 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
878 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
879 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
880 }
jtgafb833d1999-08-19 00:55:39 +0000881
Brian Paul4d053dd2000-01-14 04:45:47 +0000882 /* Fog group */
883 ctx->Fog.Enabled = GL_FALSE;
884 ctx->Fog.Mode = GL_EXP;
885 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
886 ctx->Fog.Index = 0.0;
887 ctx->Fog.Density = 1.0;
888 ctx->Fog.Start = 0.0;
889 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000890 ctx->Fog.ColorSumEnabled = GL_FALSE;
891 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000892
Brian Paul4d053dd2000-01-14 04:45:47 +0000893 /* Hint group */
894 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
895 ctx->Hint.PointSmooth = GL_DONT_CARE;
896 ctx->Hint.LineSmooth = GL_DONT_CARE;
897 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
898 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000899 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
900 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000901
Brian Paul0771d152000-04-07 00:19:41 +0000902 /* Histogram group */
903 ctx->Histogram.Width = 0;
904 ctx->Histogram.Format = GL_RGBA;
905 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000906 ctx->Histogram.RedSize = 0;
907 ctx->Histogram.GreenSize = 0;
908 ctx->Histogram.BlueSize = 0;
909 ctx->Histogram.AlphaSize = 0;
910 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000911 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
912 ctx->Histogram.Count[i][0] = 0;
913 ctx->Histogram.Count[i][1] = 0;
914 ctx->Histogram.Count[i][2] = 0;
915 ctx->Histogram.Count[i][3] = 0;
916 }
917
918 /* Min/Max group */
919 ctx->MinMax.Format = GL_RGBA;
920 ctx->MinMax.Sink = GL_FALSE;
921 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
922 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
923 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
924 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
925
Brian Paul4d053dd2000-01-14 04:45:47 +0000926 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000927 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000928
Brian Paul4d053dd2000-01-14 04:45:47 +0000929 /* Lighting group */
930 for (i=0;i<MAX_LIGHTS;i++) {
931 init_light( &ctx->Light.Light[i], i );
932 }
933 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000934
Brian Paul4d053dd2000-01-14 04:45:47 +0000935 init_lightmodel( &ctx->Light.Model );
936 init_material( &ctx->Light.Material[0] );
937 init_material( &ctx->Light.Material[1] );
938 ctx->Light.ShadeModel = GL_SMOOTH;
939 ctx->Light.Enabled = GL_FALSE;
940 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
941 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +0000942 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
943 GL_FRONT_AND_BACK,
944 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000945
Brian Paul4d053dd2000-01-14 04:45:47 +0000946 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000947
Brian Paul4d053dd2000-01-14 04:45:47 +0000948 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +0000949 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
950 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +0000951 for (i = 0 ; i < 10 ; i++) {
952 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
953 s->shininess = -1;
954 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000955 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +0000956 }
Brian Paul77d61af2000-06-28 04:20:21 +0000957
jtgafb833d1999-08-19 00:55:39 +0000958
Brian Paul4d053dd2000-01-14 04:45:47 +0000959 /* Line group */
960 ctx->Line.SmoothFlag = GL_FALSE;
961 ctx->Line.StippleFlag = GL_FALSE;
962 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +0000963 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000964 ctx->Line.StipplePattern = 0xffff;
965 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000966
Brian Paul4d053dd2000-01-14 04:45:47 +0000967 /* Display List group */
968 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +0000969
Brian Paul4d053dd2000-01-14 04:45:47 +0000970 /* Pixel group */
971 ctx->Pixel.RedBias = 0.0;
972 ctx->Pixel.RedScale = 1.0;
973 ctx->Pixel.GreenBias = 0.0;
974 ctx->Pixel.GreenScale = 1.0;
975 ctx->Pixel.BlueBias = 0.0;
976 ctx->Pixel.BlueScale = 1.0;
977 ctx->Pixel.AlphaBias = 0.0;
978 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000979 ctx->Pixel.DepthBias = 0.0;
980 ctx->Pixel.DepthScale = 1.0;
981 ctx->Pixel.IndexOffset = 0;
982 ctx->Pixel.IndexShift = 0;
983 ctx->Pixel.ZoomX = 1.0;
984 ctx->Pixel.ZoomY = 1.0;
985 ctx->Pixel.MapColorFlag = GL_FALSE;
986 ctx->Pixel.MapStencilFlag = GL_FALSE;
987 ctx->Pixel.MapStoSsize = 1;
988 ctx->Pixel.MapItoIsize = 1;
989 ctx->Pixel.MapItoRsize = 1;
990 ctx->Pixel.MapItoGsize = 1;
991 ctx->Pixel.MapItoBsize = 1;
992 ctx->Pixel.MapItoAsize = 1;
993 ctx->Pixel.MapRtoRsize = 1;
994 ctx->Pixel.MapGtoGsize = 1;
995 ctx->Pixel.MapBtoBsize = 1;
996 ctx->Pixel.MapAtoAsize = 1;
997 ctx->Pixel.MapStoS[0] = 0;
998 ctx->Pixel.MapItoI[0] = 0;
999 ctx->Pixel.MapItoR[0] = 0.0;
1000 ctx->Pixel.MapItoG[0] = 0.0;
1001 ctx->Pixel.MapItoB[0] = 0.0;
1002 ctx->Pixel.MapItoA[0] = 0.0;
1003 ctx->Pixel.MapItoR8[0] = 0;
1004 ctx->Pixel.MapItoG8[0] = 0;
1005 ctx->Pixel.MapItoB8[0] = 0;
1006 ctx->Pixel.MapItoA8[0] = 0;
1007 ctx->Pixel.MapRtoR[0] = 0.0;
1008 ctx->Pixel.MapGtoG[0] = 0.0;
1009 ctx->Pixel.MapBtoB[0] = 0.0;
1010 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001011 ctx->Pixel.HistogramEnabled = GL_FALSE;
1012 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1013 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1014 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1015 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001016 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1017 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1018 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1019 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001020 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1021 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1022 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1023 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001024 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1025 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1026 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001027 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1028 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1029 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1030 for (i = 0; i < 3; i++) {
1031 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1032 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1033 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1034 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1035 }
Brian Paul67adba12000-12-09 20:35:54 +00001036 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1037 ctx->Convolution1D.Filter[i] = 0.0;
1038 ctx->Convolution2D.Filter[i] = 0.0;
1039 ctx->Separable2D.Filter[i] = 0.0;
1040 }
Brian Paul82b02f02000-05-07 20:37:40 +00001041 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1042 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001043
Brian Paul4d053dd2000-01-14 04:45:47 +00001044 /* Point group */
1045 ctx->Point.SmoothFlag = GL_FALSE;
1046 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001047 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001048 ctx->Point.Params[0] = 1.0;
1049 ctx->Point.Params[1] = 0.0;
1050 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001051 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001052 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001053 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001054 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001055 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001056
Brian Paul4d053dd2000-01-14 04:45:47 +00001057 /* Polygon group */
1058 ctx->Polygon.CullFlag = GL_FALSE;
1059 ctx->Polygon.CullFaceMode = GL_BACK;
1060 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001061 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001062 ctx->Polygon.FrontMode = GL_FILL;
1063 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001064 ctx->Polygon.SmoothFlag = GL_FALSE;
1065 ctx->Polygon.StippleFlag = GL_FALSE;
1066 ctx->Polygon.OffsetFactor = 0.0F;
1067 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001068 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001069 ctx->Polygon.OffsetPoint = GL_FALSE;
1070 ctx->Polygon.OffsetLine = GL_FALSE;
1071 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001072
Brian Paul4d053dd2000-01-14 04:45:47 +00001073 /* Polygon Stipple group */
1074 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001075
Brian Paul4d053dd2000-01-14 04:45:47 +00001076 /* Scissor group */
1077 ctx->Scissor.Enabled = GL_FALSE;
1078 ctx->Scissor.X = 0;
1079 ctx->Scissor.Y = 0;
1080 ctx->Scissor.Width = 0;
1081 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001082
Brian Paul4d053dd2000-01-14 04:45:47 +00001083 /* Stencil group */
1084 ctx->Stencil.Enabled = GL_FALSE;
1085 ctx->Stencil.Function = GL_ALWAYS;
1086 ctx->Stencil.FailFunc = GL_KEEP;
1087 ctx->Stencil.ZPassFunc = GL_KEEP;
1088 ctx->Stencil.ZFailFunc = GL_KEEP;
1089 ctx->Stencil.Ref = 0;
1090 ctx->Stencil.ValueMask = STENCIL_MAX;
1091 ctx->Stencil.Clear = 0;
1092 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001093
Brian Paul4d053dd2000-01-14 04:45:47 +00001094 /* Texture group */
1095 ctx->Texture.CurrentUnit = 0; /* multitexture */
1096 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001097 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001098 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1099 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001100 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001101 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001102
Brian Paul4d053dd2000-01-14 04:45:47 +00001103 /* Transformation group */
1104 ctx->Transform.MatrixMode = GL_MODELVIEW;
1105 ctx->Transform.Normalize = GL_FALSE;
1106 ctx->Transform.RescaleNormals = GL_FALSE;
1107 for (i=0;i<MAX_CLIP_PLANES;i++) {
1108 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1109 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1110 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001111 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001112
Brian Paul4d053dd2000-01-14 04:45:47 +00001113 /* Viewport group */
1114 ctx->Viewport.X = 0;
1115 ctx->Viewport.Y = 0;
1116 ctx->Viewport.Width = 0;
1117 ctx->Viewport.Height = 0;
1118 ctx->Viewport.Near = 0.0;
1119 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001120 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001121
1122#define Sz 10
1123#define Tz 14
Brian Paulb6bcae52001-01-23 23:39:36 +00001124 ctx->Viewport._WindowMap.m[Sz] = 0.5 * ctx->DepthMaxF;
1125 ctx->Viewport._WindowMap.m[Tz] = 0.5 * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001126#undef Sz
1127#undef Tz
1128
Keith Whitwell14940c42000-11-05 18:40:57 +00001129 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1130 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001131
Brian Paul4d053dd2000-01-14 04:45:47 +00001132 /* Vertex arrays */
1133 ctx->Array.Vertex.Size = 4;
1134 ctx->Array.Vertex.Type = GL_FLOAT;
1135 ctx->Array.Vertex.Stride = 0;
1136 ctx->Array.Vertex.StrideB = 0;
1137 ctx->Array.Vertex.Ptr = NULL;
1138 ctx->Array.Vertex.Enabled = GL_FALSE;
1139 ctx->Array.Normal.Type = GL_FLOAT;
1140 ctx->Array.Normal.Stride = 0;
1141 ctx->Array.Normal.StrideB = 0;
1142 ctx->Array.Normal.Ptr = NULL;
1143 ctx->Array.Normal.Enabled = GL_FALSE;
1144 ctx->Array.Color.Size = 4;
1145 ctx->Array.Color.Type = GL_FLOAT;
1146 ctx->Array.Color.Stride = 0;
1147 ctx->Array.Color.StrideB = 0;
1148 ctx->Array.Color.Ptr = NULL;
1149 ctx->Array.Color.Enabled = GL_FALSE;
1150 ctx->Array.Index.Type = GL_FLOAT;
1151 ctx->Array.Index.Stride = 0;
1152 ctx->Array.Index.StrideB = 0;
1153 ctx->Array.Index.Ptr = NULL;
1154 ctx->Array.Index.Enabled = GL_FALSE;
1155 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1156 ctx->Array.TexCoord[i].Size = 4;
1157 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1158 ctx->Array.TexCoord[i].Stride = 0;
1159 ctx->Array.TexCoord[i].StrideB = 0;
1160 ctx->Array.TexCoord[i].Ptr = NULL;
1161 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1162 }
1163 ctx->Array.TexCoordInterleaveFactor = 1;
1164 ctx->Array.EdgeFlag.Stride = 0;
1165 ctx->Array.EdgeFlag.StrideB = 0;
1166 ctx->Array.EdgeFlag.Ptr = NULL;
1167 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1168 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1169
1170 /* Pixel transfer */
1171 ctx->Pack.Alignment = 4;
1172 ctx->Pack.RowLength = 0;
1173 ctx->Pack.ImageHeight = 0;
1174 ctx->Pack.SkipPixels = 0;
1175 ctx->Pack.SkipRows = 0;
1176 ctx->Pack.SkipImages = 0;
1177 ctx->Pack.SwapBytes = GL_FALSE;
1178 ctx->Pack.LsbFirst = GL_FALSE;
1179 ctx->Unpack.Alignment = 4;
1180 ctx->Unpack.RowLength = 0;
1181 ctx->Unpack.ImageHeight = 0;
1182 ctx->Unpack.SkipPixels = 0;
1183 ctx->Unpack.SkipRows = 0;
1184 ctx->Unpack.SkipImages = 0;
1185 ctx->Unpack.SwapBytes = GL_FALSE;
1186 ctx->Unpack.LsbFirst = GL_FALSE;
1187
1188 /* Feedback */
1189 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1190 ctx->Feedback.Buffer = NULL;
1191 ctx->Feedback.BufferSize = 0;
1192 ctx->Feedback.Count = 0;
1193
1194 /* Selection/picking */
1195 ctx->Select.Buffer = NULL;
1196 ctx->Select.BufferSize = 0;
1197 ctx->Select.BufferCount = 0;
1198 ctx->Select.Hits = 0;
1199 ctx->Select.NameStackDepth = 0;
1200
Brian Paul4d053dd2000-01-14 04:45:47 +00001201 /* Renderer and client attribute stacks */
1202 ctx->AttribStackDepth = 0;
1203 ctx->ClientAttribStackDepth = 0;
1204
Brian Paul13811372000-04-12 00:27:37 +00001205 /* Display list */
1206 ctx->CallDepth = 0;
1207 ctx->ExecuteFlag = GL_TRUE;
1208 ctx->CompileFlag = GL_FALSE;
1209 ctx->CurrentListPtr = NULL;
1210 ctx->CurrentBlock = NULL;
1211 ctx->CurrentListNum = 0;
1212 ctx->CurrentPos = 0;
1213
1214 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001215 _mesa_init_colortable(&ctx->ColorTable);
1216 _mesa_init_colortable(&ctx->ProxyColorTable);
1217 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1218 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1219 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1220 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001221
Brian Paul4d053dd2000-01-14 04:45:47 +00001222 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001223 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001224 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001225 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001226
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001227 ctx->_NeedNormals = 0;
1228 ctx->_NeedEyeCoords = 0;
1229 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001230
Brian Paul4d053dd2000-01-14 04:45:47 +00001231 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1232
1233 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001234 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001235 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001236
1237 /* For debug/development only */
1238 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1239 ctx->FirstTimeCurrent = GL_TRUE;
1240
1241 /* Dither disable */
1242 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1243 if (ctx->NoDither) {
1244 if (getenv("MESA_DEBUG")) {
1245 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001246 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001247 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001248 }
1249}
1250
1251
1252
1253
jtgafb833d1999-08-19 00:55:39 +00001254/*
1255 * Allocate the proxy textures. If we run out of memory part way through
1256 * the allocations clean up and return GL_FALSE.
1257 * Return: GL_TRUE=success, GL_FALSE=failure
1258 */
Brian Paul178a1c52000-04-22 01:05:00 +00001259static GLboolean
1260alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001261{
1262 GLboolean out_of_memory;
1263 GLint i;
1264
Brian Paula8523782000-11-19 23:10:25 +00001265 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001266 if (!ctx->Texture.Proxy1D) {
1267 return GL_FALSE;
1268 }
1269
Brian Paula8523782000-11-19 23:10:25 +00001270 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001271 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001272 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001273 return GL_FALSE;
1274 }
1275
Brian Paula8523782000-11-19 23:10:25 +00001276 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001277 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001278 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1279 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1280 return GL_FALSE;
1281 }
1282
1283 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1284 if (!ctx->Texture.ProxyCubeMap) {
1285 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1286 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1287 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001288 return GL_FALSE;
1289 }
1290
1291 out_of_memory = GL_FALSE;
1292 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001293 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1294 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1295 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001296 if (!ctx->Texture.Proxy1D->Image[i]
1297 || !ctx->Texture.Proxy2D->Image[i]
1298 || !ctx->Texture.Proxy3D->Image[i]) {
1299 out_of_memory = GL_TRUE;
1300 }
1301 }
1302 if (out_of_memory) {
1303 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1304 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001305 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001306 }
1307 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001308 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001309 }
1310 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001311 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001312 }
1313 }
Brian Paula8523782000-11-19 23:10:25 +00001314 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1315 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1316 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001317 return GL_FALSE;
1318 }
1319 else {
1320 return GL_TRUE;
1321 }
1322}
1323
1324
jtgafb833d1999-08-19 00:55:39 +00001325/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001326 * Initialize a GLcontext struct. This includes allocating all the
1327 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001328 */
Brian Paul178a1c52000-04-22 01:05:00 +00001329GLboolean
1330_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001331 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001332 GLcontext *share_list,
1333 void *driver_ctx,
1334 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001335{
Brian Paul5fb84d22000-05-24 15:04:45 +00001336 GLuint dispatchSize;
1337
jtgafb833d1999-08-19 00:55:39 +00001338 (void) direct; /* not used */
1339
jtgafb833d1999-08-19 00:55:39 +00001340 /* misc one-time initializations */
1341 one_time_init();
1342
Brian Paulb1394fa2000-09-26 20:53:53 +00001343 /**
1344 ** OpenGL SI stuff
1345 **/
1346 if (!ctx->imports.malloc) {
1347 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1348 }
1349 /* exports are setup by the device driver */
1350
jtgafb833d1999-08-19 00:55:39 +00001351 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001352 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001353 ctx->DrawBuffer = NULL;
1354 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001355
jtgafb833d1999-08-19 00:55:39 +00001356 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001357 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001358 ctx->Shared = share_list->Shared;
1359 }
1360 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001361 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001362 ctx->Shared = alloc_shared_state();
1363 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001364 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001365 }
1366 }
Brian Paul9560f052000-01-31 23:11:39 +00001367 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001368 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001369 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001370
Brian Paul5a2f32b2001-04-25 18:21:05 +00001371 /* Effectively bind the default textures to all texture units */
1372 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1373 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1374 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1375 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1376
Brian Paul4d053dd2000-01-14 04:45:47 +00001377 init_attrib_groups( ctx );
1378
Brian Paulb6bcae52001-01-23 23:39:36 +00001379 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001380 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 Paul4d053dd2000-01-14 04:45:47 +00001396 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001397 }
jtgafb833d1999-08-19 00:55:39 +00001398
Brian Paulf59afc92000-05-23 23:23:00 +00001399 /* register the most recent extension functions with libGL */
1400 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1401 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1402 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1403 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1404 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1405 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1406 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1407 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1408
Brian Paul5fb84d22000-05-24 15:04:45 +00001409 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1410 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1411 * Mesa we do this to accomodate different versions of libGL and various
1412 * DRI drivers.
1413 */
1414 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1415 sizeof(struct _glapi_table) / sizeof(void *));
1416
Brian Paulfbd8f211999-11-11 01:22:25 +00001417 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001418 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1419 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001420 if (!ctx->Exec || !ctx->Save) {
1421 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001422 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001423 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001424 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001425 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1426 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001427 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001428
Keith Whitwellad2ac212000-11-24 10:25:05 +00001429 ctx->ExecPrefersFloat = GL_FALSE;
1430 ctx->SavePrefersFloat = GL_FALSE;
1431
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001432 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001433 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001434 ctx->TnlModule.Current = NULL;
1435 ctx->TnlModule.SwapCount = 0;
1436
Brian Paulb6bcae52001-01-23 23:39:36 +00001437 /* Z buffer stuff */
1438 if (ctx->Visual.depthBits == 0) {
1439 /* Special case. Even if we don't have a depth buffer we need
1440 * good values for DepthMax for Z vertex transformation purposes
1441 * and for per-fragment fog computation.
1442 */
1443 ctx->DepthMax = 1 << 16;
1444 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1445 }
1446 else if (ctx->Visual.depthBits < 32) {
1447 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1448 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1449 }
1450 else {
1451 /* Special case since shift values greater than or equal to the
1452 * number of bits in the left hand expression's type are undefined.
1453 */
1454 ctx->DepthMax = 0xffffffff;
1455 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1456 }
1457 ctx->MRD = 2.0; /* XXX temporary value */
1458
1459
Brian Paul3b18a362000-09-26 15:27:20 +00001460#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +00001461 ctx->TraceCtx = CALLOC( sizeof(trace_context_t) );
1462#if 0
1463 /* Brian: do you want to have CreateContext fail here,
1464 or should we just trap in NewTrace (currently done)? */
1465 if (!(ctx->TraceCtx)) {
1466 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001467 FREE( ctx->Exec );
1468 FREE( ctx->Save );
1469 return GL_FALSE;
1470 }
1471#endif
1472 trInitContext(ctx->TraceCtx);
1473
1474 ctx->TraceDispatch = (struct _glapi_table *)
1475 CALLOC(dispatchSize * sizeof(void*));
1476#if 0
1477 if (!(ctx->TraceCtx)) {
1478 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001479 FREE( ctx->Exec );
1480 FREE( ctx->Save );
1481 FREE( ctx->TraceCtx );
1482 return GL_FALSE;
1483 }
1484#endif
1485 trInitDispatch(ctx->TraceDispatch);
1486#endif
1487
Brian Paul4d053dd2000-01-14 04:45:47 +00001488 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001489}
1490
jtgafb833d1999-08-19 00:55:39 +00001491
1492
1493/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001494 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001495 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001496 * sharelist - another context to share display lists with or NULL
1497 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001498 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001499 */
Brian Paul178a1c52000-04-22 01:05:00 +00001500GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001501_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001502 GLcontext *share_list,
1503 void *driver_ctx,
1504 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001505{
1506 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1507 if (!ctx) {
1508 return NULL;
1509 }
1510
Brian Paul178a1c52000-04-22 01:05:00 +00001511 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001512 return ctx;
1513 }
1514 else {
1515 FREE(ctx);
1516 return NULL;
1517 }
1518}
1519
1520
1521
1522/*
1523 * Free the data associated with the given context.
1524 * But don't free() the GLcontext struct itself!
1525 */
Brian Paul178a1c52000-04-22 01:05:00 +00001526void
Brian Paulb1394fa2000-09-26 20:53:53 +00001527_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001528{
Brian Paul4d053dd2000-01-14 04:45:47 +00001529 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001530 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001531
1532 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001533 if (ctx == _mesa_get_current_context()) {
1534 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001535 }
1536
Keith Whitwell23caf202000-11-16 21:05:34 +00001537 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001538 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001539 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001540 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001541 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001542 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001543 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001544 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001545 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001546 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001547 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001548 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001549 }
1550 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001551
Brian Paul9560f052000-01-31 23:11:39 +00001552 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001553 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001554 assert(ctx->Shared->RefCount >= 0);
1555 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1556 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001557 /* free shared state */
1558 free_shared_state( ctx, ctx->Shared );
1559 }
1560
Keith Whitwell14940c42000-11-05 18:40:57 +00001561 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001562 FREE( s );
1563 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001564 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001565
1566 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001567 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1568 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1569 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paul4d053dd2000-01-14 04:45:47 +00001570
1571 /* Free evaluator data */
1572 if (ctx->EvalMap.Map1Vertex3.Points)
1573 FREE( ctx->EvalMap.Map1Vertex3.Points );
1574 if (ctx->EvalMap.Map1Vertex4.Points)
1575 FREE( ctx->EvalMap.Map1Vertex4.Points );
1576 if (ctx->EvalMap.Map1Index.Points)
1577 FREE( ctx->EvalMap.Map1Index.Points );
1578 if (ctx->EvalMap.Map1Color4.Points)
1579 FREE( ctx->EvalMap.Map1Color4.Points );
1580 if (ctx->EvalMap.Map1Normal.Points)
1581 FREE( ctx->EvalMap.Map1Normal.Points );
1582 if (ctx->EvalMap.Map1Texture1.Points)
1583 FREE( ctx->EvalMap.Map1Texture1.Points );
1584 if (ctx->EvalMap.Map1Texture2.Points)
1585 FREE( ctx->EvalMap.Map1Texture2.Points );
1586 if (ctx->EvalMap.Map1Texture3.Points)
1587 FREE( ctx->EvalMap.Map1Texture3.Points );
1588 if (ctx->EvalMap.Map1Texture4.Points)
1589 FREE( ctx->EvalMap.Map1Texture4.Points );
1590
1591 if (ctx->EvalMap.Map2Vertex3.Points)
1592 FREE( ctx->EvalMap.Map2Vertex3.Points );
1593 if (ctx->EvalMap.Map2Vertex4.Points)
1594 FREE( ctx->EvalMap.Map2Vertex4.Points );
1595 if (ctx->EvalMap.Map2Index.Points)
1596 FREE( ctx->EvalMap.Map2Index.Points );
1597 if (ctx->EvalMap.Map2Color4.Points)
1598 FREE( ctx->EvalMap.Map2Color4.Points );
1599 if (ctx->EvalMap.Map2Normal.Points)
1600 FREE( ctx->EvalMap.Map2Normal.Points );
1601 if (ctx->EvalMap.Map2Texture1.Points)
1602 FREE( ctx->EvalMap.Map2Texture1.Points );
1603 if (ctx->EvalMap.Map2Texture2.Points)
1604 FREE( ctx->EvalMap.Map2Texture2.Points );
1605 if (ctx->EvalMap.Map2Texture3.Points)
1606 FREE( ctx->EvalMap.Map2Texture3.Points );
1607 if (ctx->EvalMap.Map2Texture4.Points)
1608 FREE( ctx->EvalMap.Map2Texture4.Points );
1609
Brian Paul4bdcfe52000-04-17 17:57:04 +00001610 _mesa_free_colortable_data( &ctx->ColorTable );
1611 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1612 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1613 _mesa_free_colortable_data( &ctx->Texture.Palette );
1614
Brian Paul69755402001-02-26 23:58:12 +00001615 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001616
1617 FREE(ctx->Exec);
1618 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001619}
1620
1621
1622
1623/*
1624 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001625 */
Brian Paul178a1c52000-04-22 01:05:00 +00001626void
Brian Paulb1394fa2000-09-26 20:53:53 +00001627_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001628{
1629 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001630 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001631 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001632 }
1633}
1634
1635
1636
1637/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001638 * Called by the driver after both the context and driver are fully
1639 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001640 */
Brian Paul178a1c52000-04-22 01:05:00 +00001641void
Brian Paulb1394fa2000-09-26 20:53:53 +00001642_mesa_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001643{
Brian Paul08836342001-03-03 20:33:27 +00001644 _mesa_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001645}
1646
1647
1648
1649/*
1650 * Copy attribute groups from one context to another.
1651 * Input: src - source context
1652 * dst - destination context
1653 * mask - bitwise OR of GL_*_BIT flags
1654 */
Brian Paul178a1c52000-04-22 01:05:00 +00001655void
Brian Paulb1394fa2000-09-26 20:53:53 +00001656_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001657{
1658 if (mask & GL_ACCUM_BUFFER_BIT) {
1659 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1660 }
1661 if (mask & GL_COLOR_BUFFER_BIT) {
1662 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1663 }
1664 if (mask & GL_CURRENT_BIT) {
1665 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1666 }
1667 if (mask & GL_DEPTH_BUFFER_BIT) {
1668 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1669 }
1670 if (mask & GL_ENABLE_BIT) {
1671 /* no op */
1672 }
1673 if (mask & GL_EVAL_BIT) {
1674 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1675 }
1676 if (mask & GL_FOG_BIT) {
1677 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1678 }
1679 if (mask & GL_HINT_BIT) {
1680 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1681 }
1682 if (mask & GL_LIGHTING_BIT) {
1683 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001684 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001685 }
1686 if (mask & GL_LINE_BIT) {
1687 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1688 }
1689 if (mask & GL_LIST_BIT) {
1690 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1691 }
1692 if (mask & GL_PIXEL_MODE_BIT) {
1693 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1694 }
1695 if (mask & GL_POINT_BIT) {
1696 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1697 }
1698 if (mask & GL_POLYGON_BIT) {
1699 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1700 }
1701 if (mask & GL_POLYGON_STIPPLE_BIT) {
1702 /* Use loop instead of MEMCPY due to problem with Portland Group's
1703 * C compiler. Reported by John Stone.
1704 */
1705 int i;
1706 for (i=0;i<32;i++) {
1707 dst->PolygonStipple[i] = src->PolygonStipple[i];
1708 }
1709 }
1710 if (mask & GL_SCISSOR_BIT) {
1711 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1712 }
1713 if (mask & GL_STENCIL_BUFFER_BIT) {
1714 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1715 }
1716 if (mask & GL_TEXTURE_BIT) {
1717 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1718 }
1719 if (mask & GL_TRANSFORM_BIT) {
1720 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1721 }
1722 if (mask & GL_VIEWPORT_BIT) {
1723 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1724 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001725 /* XXX FIXME: Call callbacks?
1726 */
1727 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001728}
1729
1730
jtgafb833d1999-08-19 00:55:39 +00001731/*
Brian Paul00037781999-12-17 14:52:35 +00001732 * Set the current context, binding the given frame buffer to the context.
1733 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001734void
1735_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001736{
Brian Paulb1394fa2000-09-26 20:53:53 +00001737 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001738}
1739
1740
Keith Whitwell23caf202000-11-16 21:05:34 +00001741static void print_info( void )
1742{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001743 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001744 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001745 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001746 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001747 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001748 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001749 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001750 (char *) _mesa_GetString(GL_EXTENSIONS));
1751#if defined(THREADS)
1752 fprintf(stderr, "Mesa thread-safe: YES\n");
1753#else
1754 fprintf(stderr, "Mesa thread-safe: NO\n");
1755#endif
1756#if defined(USE_X86_ASM)
1757 fprintf(stderr, "Mesa x86-optimized: YES\n");
1758#else
1759 fprintf(stderr, "Mesa x86-optimized: NO\n");
1760#endif
1761}
1762
1763
Brian Paul00037781999-12-17 14:52:35 +00001764/*
1765 * Bind the given context to the given draw-buffer and read-buffer
1766 * and make it the current context for this thread.
1767 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001768void
1769_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1770 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001771{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001772 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001773 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001774
Brian Paulbe3602d2001-02-28 00:27:48 +00001775 /* Check that the context's and framebuffer's visuals are compatible.
1776 * We could do a lot more checking here but this'll catch obvious
1777 * problems.
1778 */
1779 if (newCtx && drawBuffer && readBuffer) {
1780 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1781 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1782 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1783 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1784 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1785 return; /* incompatible */
1786 }
1787 }
1788
Brian Paul00037781999-12-17 14:52:35 +00001789 /* We call this function periodically (just here for now) in
1790 * order to detect when multithreading has begun.
1791 */
1792 _glapi_check_multithread();
1793
Brian Paulf9b97d92000-01-28 20:17:42 +00001794 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001795 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001796
1797
1798 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001799 _glapi_set_dispatch(NULL); /* none current */
1800 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001801 else {
1802 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001803
Keith Whitwell23caf202000-11-16 21:05:34 +00001804 if (drawBuffer && readBuffer) {
1805 /* TODO: check if newCtx and buffer's visual match??? */
1806 newCtx->DrawBuffer = drawBuffer;
1807 newCtx->ReadBuffer = readBuffer;
1808 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001809 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001810 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001811
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001812 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001813 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1814
1815 /* We can use this to help debug user's problems. Tell them to set
1816 * the MESA_INFO env variable before running their app. Then the
1817 * first time each context is made current we'll print some useful
1818 * information.
1819 */
1820 if (newCtx->FirstTimeCurrent) {
1821 if (getenv("MESA_INFO")) {
1822 print_info();
1823 }
1824 newCtx->FirstTimeCurrent = GL_FALSE;
1825 }
Brian Paul00037781999-12-17 14:52:35 +00001826 }
1827}
1828
1829
1830
1831/*
1832 * Return current context handle for the calling thread.
1833 * This isn't the fastest way to get the current context.
1834 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1835 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001836GLcontext *
1837_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001838{
Brian Paulf9b97d92000-01-28 20:17:42 +00001839 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001840}
1841
1842
1843
1844/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001845 * This should be called by device drivers just before they do a
1846 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001847 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001848void
1849_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001850{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001851 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001852}
1853
1854
Brian Paul00037781999-12-17 14:52:35 +00001855
Brian Paulfbd8f211999-11-11 01:22:25 +00001856/*
1857 * Return pointer to this context's current API dispatch table.
1858 * It'll either be the immediate-mode execute dispatcher or the
1859 * display list compile dispatcher.
1860 */
1861struct _glapi_table *
1862_mesa_get_dispatch(GLcontext *ctx)
1863{
1864 return ctx->CurrentDispatch;
1865}
1866
1867
1868
jtgafb833d1999-08-19 00:55:39 +00001869/**********************************************************************/
1870/***** Miscellaneous functions *****/
1871/**********************************************************************/
1872
1873
1874/*
1875 * This function is called when the Mesa user has stumbled into a code
1876 * path which may not be implemented fully or correctly.
1877 */
Brian Paul08836342001-03-03 20:33:27 +00001878void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001879{
1880 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00001881#ifdef XF86DRI
1882 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
1883#else
1884 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
1885#endif
jtgafb833d1999-08-19 00:55:39 +00001886 (void) ctx;
1887}
1888
1889
1890
1891/*
1892 * This is called to inform the user that he or she has tried to do
1893 * something illogical or if there's likely a bug in their program
1894 * (like enabled depth testing without a depth buffer).
1895 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001896void
1897_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001898{
Brian Paulb1394fa2000-09-26 20:53:53 +00001899 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001900}
1901
1902
1903
Brian Paulfa9df402000-02-02 19:16:46 +00001904/*
1905 * Compile an error into current display list.
1906 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001907void
1908_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001909{
1910 if (ctx->CompileFlag)
Brian Paul08836342001-03-03 20:33:27 +00001911 _mesa_save_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001912
1913 if (ctx->ExecuteFlag)
Brian Paul08836342001-03-03 20:33:27 +00001914 _mesa_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001915}
1916
1917
Brian Paulfa9df402000-02-02 19:16:46 +00001918
jtgafb833d1999-08-19 00:55:39 +00001919/*
1920 * This is Mesa's error handler. Normally, all that's done is the updating
1921 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1922 * environment variable "MESA_DEBUG" is defined then a real error message
1923 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001924 * Input: ctx - the GL context
1925 * error - the error value
1926 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001927 */
Brian Paul7eb06032000-07-14 04:13:40 +00001928void
Brian Paul08836342001-03-03 20:33:27 +00001929_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001930{
Brian Paul7eb06032000-07-14 04:13:40 +00001931 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001932 GLboolean debug;
1933
1934#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00001935 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00001936 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00001937 else
1938 debug = GL_TRUE;
1939#else
1940 if (debugEnv)
1941 debug = GL_TRUE;
1942 else
1943 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001944#endif
1945
1946 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00001947 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00001948 switch (error) {
1949 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00001950 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00001951 break;
1952 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00001953 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00001954 break;
1955 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00001956 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00001957 break;
1958 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00001959 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00001960 break;
1961 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001962 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001963 break;
1964 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001965 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001966 break;
1967 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00001968 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00001969 break;
Brian Paul86586aa2000-06-29 18:55:52 +00001970 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00001971 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00001972 break;
jtgafb833d1999-08-19 00:55:39 +00001973 default:
Brian Paul7eb06032000-07-14 04:13:40 +00001974 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00001975 break;
1976 }
Brian Paul7eb06032000-07-14 04:13:40 +00001977 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00001978 }
1979
Brian Paul7eb06032000-07-14 04:13:40 +00001980 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00001981 ctx->ErrorValue = error;
1982 }
1983
1984 /* Call device driver's error handler, if any. This is used on the Mac. */
1985 if (ctx->Driver.Error) {
1986 (*ctx->Driver.Error)( ctx );
1987 }
1988}
1989
1990
1991
Brian Paulfa9df402000-02-02 19:16:46 +00001992void
1993_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00001994{
Brian Paulfa9df402000-02-02 19:16:46 +00001995 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00001996 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00001997 if (ctx->Driver.Finish) {
1998 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001999 }
2000}
2001
2002
2003
Brian Paulfa9df402000-02-02 19:16:46 +00002004void
2005_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002006{
Brian Paulfa9df402000-02-02 19:16:46 +00002007 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002008 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002009 if (ctx->Driver.Flush) {
2010 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002011 }
jtgafb833d1999-08-19 00:55:39 +00002012}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002013
2014
2015
Keith Whitwellcab974c2000-12-26 05:09:27 +00002016const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002017 "GL_POINTS",
2018 "GL_LINES",
2019 "GL_LINE_LOOP",
2020 "GL_LINE_STRIP",
2021 "GL_TRIANGLES",
2022 "GL_TRIANGLE_STRIP",
2023 "GL_TRIANGLE_FAN",
2024 "GL_QUADS",
2025 "GL_QUAD_STRIP",
2026 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002027 "outside begin/end",
2028 "inside unkown primitive",
2029 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002030};