blob: f855b90f3ce10c5050fb152488548c765db20582 [file] [log] [blame]
Brian Paulbc920f02001-05-07 16:32:51 +00001/* $Id: context.c,v 1.137 2001/05/07 16:32:51 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 Paul75978bd2001-04-27 21:17:20 +0000364 buffer->Visual = *visual;
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 Paul75978bd2001-04-27 21:17:20 +0000379 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000380 FREE(buffer);
381 }
382}
383
384
Brian Paul75978bd2001-04-27 21:17:20 +0000385/*
386 * Free the data hanging off of <buffer>, but not <buffer> itself.
387 */
388void
389_mesa_free_framebuffer_data( GLframebuffer *buffer )
390{
391 if (!buffer)
392 return;
393
394 if (buffer->DepthBuffer) {
395 FREE( buffer->DepthBuffer );
396 buffer->DepthBuffer = NULL;
397 }
398 if (buffer->Accum) {
399 FREE( buffer->Accum );
400 buffer->Accum = NULL;
401 }
402 if (buffer->Stencil) {
403 FREE( buffer->Stencil );
404 buffer->Stencil = NULL;
405 }
406 if (buffer->FrontLeftAlpha) {
407 FREE( buffer->FrontLeftAlpha );
408 buffer->FrontLeftAlpha = NULL;
409 }
410 if (buffer->BackLeftAlpha) {
411 FREE( buffer->BackLeftAlpha );
412 buffer->BackLeftAlpha = NULL;
413 }
414 if (buffer->FrontRightAlpha) {
415 FREE( buffer->FrontRightAlpha );
416 buffer->FrontRightAlpha = NULL;
417 }
418 if (buffer->BackRightAlpha) {
419 FREE( buffer->BackRightAlpha );
420 buffer->BackRightAlpha = NULL;
421 }
422}
423
424
Brian Paul4d053dd2000-01-14 04:45:47 +0000425
426/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000427/***** Context allocation, initialization, destroying *****/
428/**********************************************************************/
429
430
Brian Paul9560f052000-01-31 23:11:39 +0000431_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
432
433
jtgafb833d1999-08-19 00:55:39 +0000434/*
435 * This function just calls all the various one-time-init functions in Mesa.
436 */
Brian Paul178a1c52000-04-22 01:05:00 +0000437static void
438one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000439{
440 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000441 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000442 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000443 /* do some implementation tests */
444 assert( sizeof(GLbyte) == 1 );
445 assert( sizeof(GLshort) >= 2 );
446 assert( sizeof(GLint) >= 4 );
447 assert( sizeof(GLubyte) == 1 );
448 assert( sizeof(GLushort) >= 2 );
449 assert( sizeof(GLuint) >= 4 );
450
Brian Paul08836342001-03-03 20:33:27 +0000451 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000452
Keith Whitwell23caf202000-11-16 21:05:34 +0000453 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000454 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000455
456 if (getenv("MESA_DEBUG")) {
457 _glapi_noop_enable_warnings(GL_TRUE);
458 }
459 else {
460 _glapi_noop_enable_warnings(GL_FALSE);
461 }
462
jtgafb833d1999-08-19 00:55:39 +0000463#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
464 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
465#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000466
467 alreadyCalled = GL_TRUE;
468 }
Brian Paul9560f052000-01-31 23:11:39 +0000469 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000470}
471
472
Brian Paul4d053dd2000-01-14 04:45:47 +0000473
jtgafb833d1999-08-19 00:55:39 +0000474/*
475 * Allocate and initialize a shared context state structure.
476 */
Brian Paul178a1c52000-04-22 01:05:00 +0000477static struct gl_shared_state *
478alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000479{
jtgafb833d1999-08-19 00:55:39 +0000480 struct gl_shared_state *ss;
481 GLboolean outOfMemory;
482
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000483 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000484 if (!ss)
485 return NULL;
486
Brian Paule4b684c2000-09-12 21:07:40 +0000487 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000488
Brian Paule4b684c2000-09-12 21:07:40 +0000489 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000490 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000491
492 /* Default Texture objects */
493 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000494
495 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
496 if (!ss->Default1D) {
497 outOfMemory = GL_TRUE;
498 }
jtgafb833d1999-08-19 00:55:39 +0000499
Brian Paula8523782000-11-19 23:10:25 +0000500 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
501 if (!ss->Default2D) {
502 outOfMemory = GL_TRUE;
503 }
Brian Paula8523782000-11-19 23:10:25 +0000504
505 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
506 if (!ss->Default3D) {
507 outOfMemory = GL_TRUE;
508 }
Brian Paula8523782000-11-19 23:10:25 +0000509
510 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000511 if (!ss->DefaultCubeMap) {
512 outOfMemory = GL_TRUE;
513 }
Brian Paul413d6a22000-05-26 14:44:59 +0000514
jtgafb833d1999-08-19 00:55:39 +0000515 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
516 /* Ran out of memory at some point. Free everything and return NULL */
517 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000518 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000519 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000520 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula8523782000-11-19 23:10:25 +0000521 if (ss->Default1D)
522 _mesa_free_texture_object(ss, ss->Default1D);
523 if (ss->Default2D)
524 _mesa_free_texture_object(ss, ss->Default2D);
525 if (ss->Default3D)
526 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000527 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000528 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000529 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000530 return NULL;
531 }
532 else {
533 return ss;
534 }
535}
536
537
538/*
539 * Deallocate a shared state context and all children structures.
540 */
Brian Paul178a1c52000-04-22 01:05:00 +0000541static void
542free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000543{
544 /* Free display lists */
545 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000546 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000547 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000548 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000549 }
550 else {
551 break;
552 }
553 }
Brian Paulbb797902000-01-24 16:19:54 +0000554 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000555
556 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000557 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000558 if (ctx->Driver.DeleteTexture)
559 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
560 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000561 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000562 }
Brian Paulbb797902000-01-24 16:19:54 +0000563 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000564
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000565 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000566}
567
568
569
jtgafb833d1999-08-19 00:55:39 +0000570/*
571 * Initialize the nth light. Note that the defaults for light 0 are
572 * different than the other lights.
573 */
Brian Paul178a1c52000-04-22 01:05:00 +0000574static void
575init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000576{
577 make_empty_list( l );
578
579 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
580 if (n==0) {
581 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
582 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
583 }
584 else {
585 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
586 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
587 }
588 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
589 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
590 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000591 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000592 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000593 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000594 l->ConstantAttenuation = 1.0;
595 l->LinearAttenuation = 0.0;
596 l->QuadraticAttenuation = 0.0;
597 l->Enabled = GL_FALSE;
598}
599
600
601
Brian Paul178a1c52000-04-22 01:05:00 +0000602static void
603init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000604{
605 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
606 lm->LocalViewer = GL_FALSE;
607 lm->TwoSide = GL_FALSE;
608 lm->ColorControl = GL_SINGLE_COLOR;
609}
610
611
Brian Paul178a1c52000-04-22 01:05:00 +0000612static void
613init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000614{
615 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
616 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
617 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
618 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
619 m->Shininess = 0.0;
620 m->AmbientIndex = 0;
621 m->DiffuseIndex = 1;
622 m->SpecularIndex = 1;
623}
624
625
626
Brian Paul178a1c52000-04-22 01:05:00 +0000627static void
628init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000629{
630 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
631
632 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000633 texUnit->CombineModeRGB = GL_MODULATE;
634 texUnit->CombineModeA = GL_MODULATE;
635 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
636 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
637 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
638 texUnit->CombineSourceA[0] = GL_TEXTURE;
639 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
640 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
641 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
642 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
643 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
644 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
645 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
646 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
647 texUnit->CombineScaleShiftRGB = 0;
648 texUnit->CombineScaleShiftA = 0;
649
jtgafb833d1999-08-19 00:55:39 +0000650 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
651 texUnit->TexGenEnabled = 0;
652 texUnit->GenModeS = GL_EYE_LINEAR;
653 texUnit->GenModeT = GL_EYE_LINEAR;
654 texUnit->GenModeR = GL_EYE_LINEAR;
655 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000656 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
657 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
658 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
659 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000660
jtgafb833d1999-08-19 00:55:39 +0000661 /* Yes, these plane coefficients are correct! */
662 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
664 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
665 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
666 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
667 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
668 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
669 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
670
Brian Paula8523782000-11-19 23:10:25 +0000671 texUnit->Current1D = ctx->Shared->Default1D;
672 texUnit->Current2D = ctx->Shared->Default2D;
673 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000674 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000675}
676
677
jtgafb833d1999-08-19 00:55:39 +0000678
Brian Paul4d053dd2000-01-14 04:45:47 +0000679
jtgafb833d1999-08-19 00:55:39 +0000680/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000681static void
682init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000683{
684 map->Order = 1;
685 map->u1 = 0.0;
686 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000687 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000688 if (map->Points) {
689 GLint i;
690 for (i=0;i<n;i++)
691 map->Points[i] = initial[i];
692 }
jtgafb833d1999-08-19 00:55:39 +0000693}
694
695
696/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000697static void
698init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000699{
700 map->Uorder = 1;
701 map->Vorder = 1;
702 map->u1 = 0.0;
703 map->u2 = 1.0;
704 map->v1 = 0.0;
705 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000706 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000707 if (map->Points) {
708 GLint i;
709 for (i=0;i<n;i++)
710 map->Points[i] = initial[i];
711 }
jtgafb833d1999-08-19 00:55:39 +0000712}
713
714
jtgafb833d1999-08-19 00:55:39 +0000715/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000716 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000717 */
Brian Paul178a1c52000-04-22 01:05:00 +0000718static void
719init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000720{
721 GLuint i, j;
722
Brian Paul4d053dd2000-01-14 04:45:47 +0000723 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000724
Brian Paul539cce52000-02-03 19:40:07 +0000725 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000726 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
727 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000728 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000729 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000730 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul4d053dd2000-01-14 04:45:47 +0000731 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000732 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
733 ctx->Const.MinPointSize = MIN_POINT_SIZE;
734 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
735 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
736 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
737 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
738 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
739 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
740 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
741 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
742 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
743 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000744 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000745 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
746 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000747 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000748 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
749 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000750
Brian Paul4d053dd2000-01-14 04:45:47 +0000751 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000752 _math_matrix_ctr( &ctx->ModelView );
753 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000754
755 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000756 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000757 _math_matrix_ctr( &ctx->ModelViewStack[i] );
758 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000759 }
760
761 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000762 _math_matrix_ctr( &ctx->ProjectionMatrix );
763 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000764
765 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000766 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000767 _math_matrix_ctr( &ctx->ProjectionStack[i] );
768 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000769 }
770
Keith Whitwell23caf202000-11-16 21:05:34 +0000771 /* Derived ModelProject matrix */
772 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
773
Brian Paul4d053dd2000-01-14 04:45:47 +0000774 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000775 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000776 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000777 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000778 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000779 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000780 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000781 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000782 }
jtgafb833d1999-08-19 00:55:39 +0000783
Brian Paul250069d2000-04-08 18:57:45 +0000784 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000785 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000786 ctx->ColorStackDepth = 0;
787 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000788 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000789 }
790
Brian Paul4d053dd2000-01-14 04:45:47 +0000791 /* Accumulate buffer group */
792 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000793
Brian Paul4d053dd2000-01-14 04:45:47 +0000794 /* Color buffer group */
795 ctx->Color.IndexMask = 0xffffffff;
796 ctx->Color.ColorMask[0] = 0xff;
797 ctx->Color.ColorMask[1] = 0xff;
798 ctx->Color.ColorMask[2] = 0xff;
799 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000800 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000801 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000802 ctx->Color.DrawBuffer = GL_FRONT;
803 ctx->Color.AlphaEnabled = GL_FALSE;
804 ctx->Color.AlphaFunc = GL_ALWAYS;
805 ctx->Color.AlphaRef = 0;
806 ctx->Color.BlendEnabled = GL_FALSE;
807 ctx->Color.BlendSrcRGB = GL_ONE;
808 ctx->Color.BlendDstRGB = GL_ZERO;
809 ctx->Color.BlendSrcA = GL_ONE;
810 ctx->Color.BlendDstA = GL_ZERO;
811 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000812 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
813 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
814 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000815 ctx->Color.LogicOp = GL_COPY;
816 ctx->Color.DitherFlag = GL_TRUE;
817 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000818
Brian Paul4d053dd2000-01-14 04:45:47 +0000819 /* Current group */
Keith Whitwell51c0c712001-04-28 08:39:17 +0000820 ASSIGN_4V( ctx->Current.Color, 1.0, 1.0, 1.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000821 ctx->Current.Index = 1;
822 for (i=0; i<MAX_TEXTURE_UNITS; i++)
823 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
824 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
825 ctx->Current.RasterDistance = 0.0;
826 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
827 ctx->Current.RasterIndex = 1;
828 for (i=0; i<MAX_TEXTURE_UNITS; i++)
829 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
830 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
831 ctx->Current.RasterPosValid = GL_TRUE;
832 ctx->Current.EdgeFlag = GL_TRUE;
833 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000834
jtgafb833d1999-08-19 00:55:39 +0000835
Brian Paul4d053dd2000-01-14 04:45:47 +0000836 /* Depth buffer group */
837 ctx->Depth.Test = GL_FALSE;
838 ctx->Depth.Clear = 1.0;
839 ctx->Depth.Func = GL_LESS;
840 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000841 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000842
Brian Paul4d053dd2000-01-14 04:45:47 +0000843 /* Evaluators group */
844 ctx->Eval.Map1Color4 = GL_FALSE;
845 ctx->Eval.Map1Index = GL_FALSE;
846 ctx->Eval.Map1Normal = GL_FALSE;
847 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
848 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
849 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
850 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
851 ctx->Eval.Map1Vertex3 = GL_FALSE;
852 ctx->Eval.Map1Vertex4 = GL_FALSE;
853 ctx->Eval.Map2Color4 = GL_FALSE;
854 ctx->Eval.Map2Index = GL_FALSE;
855 ctx->Eval.Map2Normal = GL_FALSE;
856 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
857 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
858 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
859 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
860 ctx->Eval.Map2Vertex3 = GL_FALSE;
861 ctx->Eval.Map2Vertex4 = GL_FALSE;
862 ctx->Eval.AutoNormal = GL_FALSE;
863 ctx->Eval.MapGrid1un = 1;
864 ctx->Eval.MapGrid1u1 = 0.0;
865 ctx->Eval.MapGrid1u2 = 1.0;
866 ctx->Eval.MapGrid2un = 1;
867 ctx->Eval.MapGrid2vn = 1;
868 ctx->Eval.MapGrid2u1 = 0.0;
869 ctx->Eval.MapGrid2u2 = 1.0;
870 ctx->Eval.MapGrid2v1 = 0.0;
871 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000872
Brian Paul4d053dd2000-01-14 04:45:47 +0000873 /* Evaluator data */
874 {
875 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
876 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
877 static GLfloat index[1] = { 1.0 };
878 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
879 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000880
Brian Paul4d053dd2000-01-14 04:45:47 +0000881 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
882 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
883 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
884 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
885 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
886 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
887 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
888 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
889 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000890
Brian Paul4d053dd2000-01-14 04:45:47 +0000891 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
892 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
893 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
894 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
895 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
896 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
897 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
898 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
899 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
900 }
jtgafb833d1999-08-19 00:55:39 +0000901
Brian Paul4d053dd2000-01-14 04:45:47 +0000902 /* Fog group */
903 ctx->Fog.Enabled = GL_FALSE;
904 ctx->Fog.Mode = GL_EXP;
905 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
906 ctx->Fog.Index = 0.0;
907 ctx->Fog.Density = 1.0;
908 ctx->Fog.Start = 0.0;
909 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000910 ctx->Fog.ColorSumEnabled = GL_FALSE;
911 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000912
Brian Paul4d053dd2000-01-14 04:45:47 +0000913 /* Hint group */
914 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
915 ctx->Hint.PointSmooth = GL_DONT_CARE;
916 ctx->Hint.LineSmooth = GL_DONT_CARE;
917 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
918 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000919 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
920 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000921
Brian Paul0771d152000-04-07 00:19:41 +0000922 /* Histogram group */
923 ctx->Histogram.Width = 0;
924 ctx->Histogram.Format = GL_RGBA;
925 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000926 ctx->Histogram.RedSize = 0;
927 ctx->Histogram.GreenSize = 0;
928 ctx->Histogram.BlueSize = 0;
929 ctx->Histogram.AlphaSize = 0;
930 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000931 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
932 ctx->Histogram.Count[i][0] = 0;
933 ctx->Histogram.Count[i][1] = 0;
934 ctx->Histogram.Count[i][2] = 0;
935 ctx->Histogram.Count[i][3] = 0;
936 }
937
938 /* Min/Max group */
939 ctx->MinMax.Format = GL_RGBA;
940 ctx->MinMax.Sink = GL_FALSE;
941 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
942 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
943 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
944 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
945
Brian Paul4d053dd2000-01-14 04:45:47 +0000946 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000947 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000948
Brian Paul4d053dd2000-01-14 04:45:47 +0000949 /* Lighting group */
950 for (i=0;i<MAX_LIGHTS;i++) {
951 init_light( &ctx->Light.Light[i], i );
952 }
953 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000954
Brian Paul4d053dd2000-01-14 04:45:47 +0000955 init_lightmodel( &ctx->Light.Model );
956 init_material( &ctx->Light.Material[0] );
957 init_material( &ctx->Light.Material[1] );
958 ctx->Light.ShadeModel = GL_SMOOTH;
959 ctx->Light.Enabled = GL_FALSE;
960 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
961 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +0000962 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
963 GL_FRONT_AND_BACK,
964 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000965
Brian Paul4d053dd2000-01-14 04:45:47 +0000966 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000967
Brian Paul4d053dd2000-01-14 04:45:47 +0000968 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +0000969 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
970 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +0000971 for (i = 0 ; i < 10 ; i++) {
972 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
973 s->shininess = -1;
974 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000975 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +0000976 }
Brian Paul77d61af2000-06-28 04:20:21 +0000977
jtgafb833d1999-08-19 00:55:39 +0000978
Brian Paul4d053dd2000-01-14 04:45:47 +0000979 /* Line group */
980 ctx->Line.SmoothFlag = GL_FALSE;
981 ctx->Line.StippleFlag = GL_FALSE;
982 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +0000983 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000984 ctx->Line.StipplePattern = 0xffff;
985 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000986
Brian Paul4d053dd2000-01-14 04:45:47 +0000987 /* Display List group */
988 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +0000989
Brian Paul4d053dd2000-01-14 04:45:47 +0000990 /* Pixel group */
991 ctx->Pixel.RedBias = 0.0;
992 ctx->Pixel.RedScale = 1.0;
993 ctx->Pixel.GreenBias = 0.0;
994 ctx->Pixel.GreenScale = 1.0;
995 ctx->Pixel.BlueBias = 0.0;
996 ctx->Pixel.BlueScale = 1.0;
997 ctx->Pixel.AlphaBias = 0.0;
998 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000999 ctx->Pixel.DepthBias = 0.0;
1000 ctx->Pixel.DepthScale = 1.0;
1001 ctx->Pixel.IndexOffset = 0;
1002 ctx->Pixel.IndexShift = 0;
1003 ctx->Pixel.ZoomX = 1.0;
1004 ctx->Pixel.ZoomY = 1.0;
1005 ctx->Pixel.MapColorFlag = GL_FALSE;
1006 ctx->Pixel.MapStencilFlag = GL_FALSE;
1007 ctx->Pixel.MapStoSsize = 1;
1008 ctx->Pixel.MapItoIsize = 1;
1009 ctx->Pixel.MapItoRsize = 1;
1010 ctx->Pixel.MapItoGsize = 1;
1011 ctx->Pixel.MapItoBsize = 1;
1012 ctx->Pixel.MapItoAsize = 1;
1013 ctx->Pixel.MapRtoRsize = 1;
1014 ctx->Pixel.MapGtoGsize = 1;
1015 ctx->Pixel.MapBtoBsize = 1;
1016 ctx->Pixel.MapAtoAsize = 1;
1017 ctx->Pixel.MapStoS[0] = 0;
1018 ctx->Pixel.MapItoI[0] = 0;
1019 ctx->Pixel.MapItoR[0] = 0.0;
1020 ctx->Pixel.MapItoG[0] = 0.0;
1021 ctx->Pixel.MapItoB[0] = 0.0;
1022 ctx->Pixel.MapItoA[0] = 0.0;
1023 ctx->Pixel.MapItoR8[0] = 0;
1024 ctx->Pixel.MapItoG8[0] = 0;
1025 ctx->Pixel.MapItoB8[0] = 0;
1026 ctx->Pixel.MapItoA8[0] = 0;
1027 ctx->Pixel.MapRtoR[0] = 0.0;
1028 ctx->Pixel.MapGtoG[0] = 0.0;
1029 ctx->Pixel.MapBtoB[0] = 0.0;
1030 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001031 ctx->Pixel.HistogramEnabled = GL_FALSE;
1032 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1033 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1034 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1035 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001036 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1037 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1038 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1039 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001040 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1041 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1042 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1043 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001044 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1045 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1046 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001047 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1048 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1049 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1050 for (i = 0; i < 3; i++) {
1051 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1052 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1053 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1054 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1055 }
Brian Paul67adba12000-12-09 20:35:54 +00001056 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1057 ctx->Convolution1D.Filter[i] = 0.0;
1058 ctx->Convolution2D.Filter[i] = 0.0;
1059 ctx->Separable2D.Filter[i] = 0.0;
1060 }
Brian Paul82b02f02000-05-07 20:37:40 +00001061 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1062 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001063
Brian Paul4d053dd2000-01-14 04:45:47 +00001064 /* Point group */
1065 ctx->Point.SmoothFlag = GL_FALSE;
1066 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001067 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001068 ctx->Point.Params[0] = 1.0;
1069 ctx->Point.Params[1] = 0.0;
1070 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001071 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001072 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001073 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001074 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001075 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001076
Brian Paul4d053dd2000-01-14 04:45:47 +00001077 /* Polygon group */
1078 ctx->Polygon.CullFlag = GL_FALSE;
1079 ctx->Polygon.CullFaceMode = GL_BACK;
1080 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001081 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001082 ctx->Polygon.FrontMode = GL_FILL;
1083 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001084 ctx->Polygon.SmoothFlag = GL_FALSE;
1085 ctx->Polygon.StippleFlag = GL_FALSE;
1086 ctx->Polygon.OffsetFactor = 0.0F;
1087 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001088 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001089 ctx->Polygon.OffsetPoint = GL_FALSE;
1090 ctx->Polygon.OffsetLine = GL_FALSE;
1091 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001092
Brian Paul4d053dd2000-01-14 04:45:47 +00001093 /* Polygon Stipple group */
1094 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001095
Brian Paul4d053dd2000-01-14 04:45:47 +00001096 /* Scissor group */
1097 ctx->Scissor.Enabled = GL_FALSE;
1098 ctx->Scissor.X = 0;
1099 ctx->Scissor.Y = 0;
1100 ctx->Scissor.Width = 0;
1101 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001102
Brian Paul4d053dd2000-01-14 04:45:47 +00001103 /* Stencil group */
1104 ctx->Stencil.Enabled = GL_FALSE;
1105 ctx->Stencil.Function = GL_ALWAYS;
1106 ctx->Stencil.FailFunc = GL_KEEP;
1107 ctx->Stencil.ZPassFunc = GL_KEEP;
1108 ctx->Stencil.ZFailFunc = GL_KEEP;
1109 ctx->Stencil.Ref = 0;
1110 ctx->Stencil.ValueMask = STENCIL_MAX;
1111 ctx->Stencil.Clear = 0;
1112 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001113
Brian Paul4d053dd2000-01-14 04:45:47 +00001114 /* Texture group */
1115 ctx->Texture.CurrentUnit = 0; /* multitexture */
1116 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001117 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001118 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1119 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001120 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001121 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001122
Brian Paul4d053dd2000-01-14 04:45:47 +00001123 /* Transformation group */
1124 ctx->Transform.MatrixMode = GL_MODELVIEW;
1125 ctx->Transform.Normalize = GL_FALSE;
1126 ctx->Transform.RescaleNormals = GL_FALSE;
1127 for (i=0;i<MAX_CLIP_PLANES;i++) {
1128 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1129 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1130 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001131 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001132
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 /* Viewport group */
1134 ctx->Viewport.X = 0;
1135 ctx->Viewport.Y = 0;
1136 ctx->Viewport.Width = 0;
1137 ctx->Viewport.Height = 0;
1138 ctx->Viewport.Near = 0.0;
1139 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001140 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001141
1142#define Sz 10
1143#define Tz 14
Brian Paulb6bcae52001-01-23 23:39:36 +00001144 ctx->Viewport._WindowMap.m[Sz] = 0.5 * ctx->DepthMaxF;
1145 ctx->Viewport._WindowMap.m[Tz] = 0.5 * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001146#undef Sz
1147#undef Tz
1148
Keith Whitwell14940c42000-11-05 18:40:57 +00001149 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1150 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001151
Brian Paul4d053dd2000-01-14 04:45:47 +00001152 /* Vertex arrays */
1153 ctx->Array.Vertex.Size = 4;
1154 ctx->Array.Vertex.Type = GL_FLOAT;
1155 ctx->Array.Vertex.Stride = 0;
1156 ctx->Array.Vertex.StrideB = 0;
1157 ctx->Array.Vertex.Ptr = NULL;
1158 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001159 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001160 ctx->Array.Normal.Type = GL_FLOAT;
1161 ctx->Array.Normal.Stride = 0;
1162 ctx->Array.Normal.StrideB = 0;
1163 ctx->Array.Normal.Ptr = NULL;
1164 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001165 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001166 ctx->Array.Color.Size = 4;
1167 ctx->Array.Color.Type = GL_FLOAT;
1168 ctx->Array.Color.Stride = 0;
1169 ctx->Array.Color.StrideB = 0;
1170 ctx->Array.Color.Ptr = NULL;
1171 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001172 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1173 ctx->Array.SecondaryColor.Size = 4;
1174 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1175 ctx->Array.SecondaryColor.Stride = 0;
1176 ctx->Array.SecondaryColor.StrideB = 0;
1177 ctx->Array.SecondaryColor.Ptr = NULL;
1178 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1179 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1180 ctx->Array.FogCoord.Size = 1;
1181 ctx->Array.FogCoord.Type = GL_FLOAT;
1182 ctx->Array.FogCoord.Stride = 0;
1183 ctx->Array.FogCoord.StrideB = 0;
1184 ctx->Array.FogCoord.Ptr = NULL;
1185 ctx->Array.FogCoord.Enabled = GL_FALSE;
1186 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001187 ctx->Array.Index.Type = GL_FLOAT;
1188 ctx->Array.Index.Stride = 0;
1189 ctx->Array.Index.StrideB = 0;
1190 ctx->Array.Index.Ptr = NULL;
1191 ctx->Array.Index.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001192 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001193 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1194 ctx->Array.TexCoord[i].Size = 4;
1195 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1196 ctx->Array.TexCoord[i].Stride = 0;
1197 ctx->Array.TexCoord[i].StrideB = 0;
1198 ctx->Array.TexCoord[i].Ptr = NULL;
1199 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001200 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001201 }
1202 ctx->Array.TexCoordInterleaveFactor = 1;
1203 ctx->Array.EdgeFlag.Stride = 0;
1204 ctx->Array.EdgeFlag.StrideB = 0;
1205 ctx->Array.EdgeFlag.Ptr = NULL;
1206 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001207 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001208 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1209
1210 /* Pixel transfer */
1211 ctx->Pack.Alignment = 4;
1212 ctx->Pack.RowLength = 0;
1213 ctx->Pack.ImageHeight = 0;
1214 ctx->Pack.SkipPixels = 0;
1215 ctx->Pack.SkipRows = 0;
1216 ctx->Pack.SkipImages = 0;
1217 ctx->Pack.SwapBytes = GL_FALSE;
1218 ctx->Pack.LsbFirst = GL_FALSE;
1219 ctx->Unpack.Alignment = 4;
1220 ctx->Unpack.RowLength = 0;
1221 ctx->Unpack.ImageHeight = 0;
1222 ctx->Unpack.SkipPixels = 0;
1223 ctx->Unpack.SkipRows = 0;
1224 ctx->Unpack.SkipImages = 0;
1225 ctx->Unpack.SwapBytes = GL_FALSE;
1226 ctx->Unpack.LsbFirst = GL_FALSE;
1227
1228 /* Feedback */
1229 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1230 ctx->Feedback.Buffer = NULL;
1231 ctx->Feedback.BufferSize = 0;
1232 ctx->Feedback.Count = 0;
1233
1234 /* Selection/picking */
1235 ctx->Select.Buffer = NULL;
1236 ctx->Select.BufferSize = 0;
1237 ctx->Select.BufferCount = 0;
1238 ctx->Select.Hits = 0;
1239 ctx->Select.NameStackDepth = 0;
1240
Brian Paul4d053dd2000-01-14 04:45:47 +00001241 /* Renderer and client attribute stacks */
1242 ctx->AttribStackDepth = 0;
1243 ctx->ClientAttribStackDepth = 0;
1244
Brian Paul13811372000-04-12 00:27:37 +00001245 /* Display list */
1246 ctx->CallDepth = 0;
1247 ctx->ExecuteFlag = GL_TRUE;
1248 ctx->CompileFlag = GL_FALSE;
1249 ctx->CurrentListPtr = NULL;
1250 ctx->CurrentBlock = NULL;
1251 ctx->CurrentListNum = 0;
1252 ctx->CurrentPos = 0;
1253
1254 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001255 _mesa_init_colortable(&ctx->ColorTable);
1256 _mesa_init_colortable(&ctx->ProxyColorTable);
1257 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1258 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1259 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1260 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001261
Brian Paul4d053dd2000-01-14 04:45:47 +00001262 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001263 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001264 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001265 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001266
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001267 ctx->_NeedNormals = 0;
1268 ctx->_NeedEyeCoords = 0;
1269 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001270
Brian Paul4d053dd2000-01-14 04:45:47 +00001271 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1272
1273 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001274 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001275 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001276
1277 /* For debug/development only */
1278 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1279 ctx->FirstTimeCurrent = GL_TRUE;
1280
1281 /* Dither disable */
1282 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1283 if (ctx->NoDither) {
1284 if (getenv("MESA_DEBUG")) {
1285 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001286 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001287 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001288 }
1289}
1290
1291
1292
1293
jtgafb833d1999-08-19 00:55:39 +00001294/*
1295 * Allocate the proxy textures. If we run out of memory part way through
1296 * the allocations clean up and return GL_FALSE.
1297 * Return: GL_TRUE=success, GL_FALSE=failure
1298 */
Brian Paul178a1c52000-04-22 01:05:00 +00001299static GLboolean
1300alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001301{
1302 GLboolean out_of_memory;
1303 GLint i;
1304
Brian Paula8523782000-11-19 23:10:25 +00001305 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001306 if (!ctx->Texture.Proxy1D) {
1307 return GL_FALSE;
1308 }
1309
Brian Paula8523782000-11-19 23:10:25 +00001310 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001311 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001312 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001313 return GL_FALSE;
1314 }
1315
Brian Paula8523782000-11-19 23:10:25 +00001316 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001317 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001318 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1319 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1320 return GL_FALSE;
1321 }
1322
1323 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1324 if (!ctx->Texture.ProxyCubeMap) {
1325 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1326 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1327 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001328 return GL_FALSE;
1329 }
1330
1331 out_of_memory = GL_FALSE;
1332 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001333 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1334 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1335 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001336 if (!ctx->Texture.Proxy1D->Image[i]
1337 || !ctx->Texture.Proxy2D->Image[i]
1338 || !ctx->Texture.Proxy3D->Image[i]) {
1339 out_of_memory = GL_TRUE;
1340 }
1341 }
1342 if (out_of_memory) {
1343 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1344 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001345 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001346 }
1347 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001348 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001349 }
1350 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001351 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001352 }
1353 }
Brian Paula8523782000-11-19 23:10:25 +00001354 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1355 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1356 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001357 return GL_FALSE;
1358 }
1359 else {
1360 return GL_TRUE;
1361 }
1362}
1363
1364
jtgafb833d1999-08-19 00:55:39 +00001365/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001366 * Initialize a GLcontext struct. This includes allocating all the
1367 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001368 */
Brian Paul178a1c52000-04-22 01:05:00 +00001369GLboolean
1370_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001371 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001372 GLcontext *share_list,
1373 void *driver_ctx,
1374 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001375{
Brian Paul5fb84d22000-05-24 15:04:45 +00001376 GLuint dispatchSize;
1377
jtgafb833d1999-08-19 00:55:39 +00001378 (void) direct; /* not used */
1379
jtgafb833d1999-08-19 00:55:39 +00001380 /* misc one-time initializations */
1381 one_time_init();
1382
Brian Paulb1394fa2000-09-26 20:53:53 +00001383 /**
1384 ** OpenGL SI stuff
1385 **/
1386 if (!ctx->imports.malloc) {
1387 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1388 }
1389 /* exports are setup by the device driver */
1390
jtgafb833d1999-08-19 00:55:39 +00001391 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001392 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001393 ctx->DrawBuffer = NULL;
1394 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001395
jtgafb833d1999-08-19 00:55:39 +00001396 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001397 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001398 ctx->Shared = share_list->Shared;
1399 }
1400 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001401 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001402 ctx->Shared = alloc_shared_state();
1403 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001404 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001405 }
1406 }
Brian Paul9560f052000-01-31 23:11:39 +00001407 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001408 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001409 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001410
Brian Paul5a2f32b2001-04-25 18:21:05 +00001411 /* Effectively bind the default textures to all texture units */
1412 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1413 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1414 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1415 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1416
Brian Paul4d053dd2000-01-14 04:45:47 +00001417 init_attrib_groups( ctx );
1418
Brian Paulb6bcae52001-01-23 23:39:36 +00001419 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001420 ctx->Color.DrawBuffer = GL_BACK;
1421 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1422 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1423 ctx->Pixel.ReadBuffer = GL_BACK;
1424 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1425 }
1426 else {
1427 ctx->Color.DrawBuffer = GL_FRONT;
1428 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1429 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1430 ctx->Pixel.ReadBuffer = GL_FRONT;
1431 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1432 }
1433
jtgafb833d1999-08-19 00:55:39 +00001434 if (!alloc_proxy_textures(ctx)) {
1435 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001436 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001437 }
jtgafb833d1999-08-19 00:55:39 +00001438
Brian Paulf59afc92000-05-23 23:23:00 +00001439 /* register the most recent extension functions with libGL */
1440 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1441 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1442 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1443 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1444 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1445 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1446 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1447 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1448
Brian Paul5fb84d22000-05-24 15:04:45 +00001449 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1450 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1451 * Mesa we do this to accomodate different versions of libGL and various
1452 * DRI drivers.
1453 */
1454 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1455 sizeof(struct _glapi_table) / sizeof(void *));
1456
Brian Paulfbd8f211999-11-11 01:22:25 +00001457 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001458 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1459 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001460 if (!ctx->Exec || !ctx->Save) {
1461 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001462 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001463 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001464 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001465 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1466 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001467 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001468
Keith Whitwellad2ac212000-11-24 10:25:05 +00001469 ctx->ExecPrefersFloat = GL_FALSE;
1470 ctx->SavePrefersFloat = GL_FALSE;
1471
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001472 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001473 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001474 ctx->TnlModule.Current = NULL;
1475 ctx->TnlModule.SwapCount = 0;
1476
Brian Paulb6bcae52001-01-23 23:39:36 +00001477 /* Z buffer stuff */
1478 if (ctx->Visual.depthBits == 0) {
1479 /* Special case. Even if we don't have a depth buffer we need
1480 * good values for DepthMax for Z vertex transformation purposes
1481 * and for per-fragment fog computation.
1482 */
1483 ctx->DepthMax = 1 << 16;
1484 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1485 }
1486 else if (ctx->Visual.depthBits < 32) {
1487 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1488 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1489 }
1490 else {
1491 /* Special case since shift values greater than or equal to the
1492 * number of bits in the left hand expression's type are undefined.
1493 */
1494 ctx->DepthMax = 0xffffffff;
1495 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1496 }
Brian Paulbc920f02001-05-07 16:32:51 +00001497 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001498
1499
Brian Paul3b18a362000-09-26 15:27:20 +00001500#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001501 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001502#if 0
1503 /* Brian: do you want to have CreateContext fail here,
1504 or should we just trap in NewTrace (currently done)? */
1505 if (!(ctx->TraceCtx)) {
1506 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001507 FREE( ctx->Exec );
1508 FREE( ctx->Save );
1509 return GL_FALSE;
1510 }
1511#endif
1512 trInitContext(ctx->TraceCtx);
1513
1514 ctx->TraceDispatch = (struct _glapi_table *)
1515 CALLOC(dispatchSize * sizeof(void*));
1516#if 0
1517 if (!(ctx->TraceCtx)) {
1518 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001519 FREE( ctx->Exec );
1520 FREE( ctx->Save );
1521 FREE( ctx->TraceCtx );
1522 return GL_FALSE;
1523 }
1524#endif
1525 trInitDispatch(ctx->TraceDispatch);
1526#endif
1527
Brian Paul4d053dd2000-01-14 04:45:47 +00001528 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001529}
1530
jtgafb833d1999-08-19 00:55:39 +00001531
1532
1533/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001534 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001535 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001536 * sharelist - another context to share display lists with or NULL
1537 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001538 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001539 */
Brian Paul178a1c52000-04-22 01:05:00 +00001540GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001541_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001542 GLcontext *share_list,
1543 void *driver_ctx,
1544 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001545{
1546 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1547 if (!ctx) {
1548 return NULL;
1549 }
1550
Brian Paul178a1c52000-04-22 01:05:00 +00001551 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001552 return ctx;
1553 }
1554 else {
1555 FREE(ctx);
1556 return NULL;
1557 }
1558}
1559
1560
1561
1562/*
1563 * Free the data associated with the given context.
1564 * But don't free() the GLcontext struct itself!
1565 */
Brian Paul178a1c52000-04-22 01:05:00 +00001566void
Brian Paulb1394fa2000-09-26 20:53:53 +00001567_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001568{
Brian Paul4d053dd2000-01-14 04:45:47 +00001569 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001570 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001571
1572 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001573 if (ctx == _mesa_get_current_context()) {
1574 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001575 }
1576
Keith Whitwell23caf202000-11-16 21:05:34 +00001577 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001578 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001579 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001580 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001581 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001582 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001583 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001584 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001585 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001586 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001587 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001588 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001589 }
1590 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001591
Brian Paul9560f052000-01-31 23:11:39 +00001592 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001593 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001594 assert(ctx->Shared->RefCount >= 0);
1595 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1596 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001597 /* free shared state */
1598 free_shared_state( ctx, ctx->Shared );
1599 }
1600
Keith Whitwell14940c42000-11-05 18:40:57 +00001601 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001602 FREE( s );
1603 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001604 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001605
1606 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001607 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1608 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1609 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paul4d053dd2000-01-14 04:45:47 +00001610
1611 /* Free evaluator data */
1612 if (ctx->EvalMap.Map1Vertex3.Points)
1613 FREE( ctx->EvalMap.Map1Vertex3.Points );
1614 if (ctx->EvalMap.Map1Vertex4.Points)
1615 FREE( ctx->EvalMap.Map1Vertex4.Points );
1616 if (ctx->EvalMap.Map1Index.Points)
1617 FREE( ctx->EvalMap.Map1Index.Points );
1618 if (ctx->EvalMap.Map1Color4.Points)
1619 FREE( ctx->EvalMap.Map1Color4.Points );
1620 if (ctx->EvalMap.Map1Normal.Points)
1621 FREE( ctx->EvalMap.Map1Normal.Points );
1622 if (ctx->EvalMap.Map1Texture1.Points)
1623 FREE( ctx->EvalMap.Map1Texture1.Points );
1624 if (ctx->EvalMap.Map1Texture2.Points)
1625 FREE( ctx->EvalMap.Map1Texture2.Points );
1626 if (ctx->EvalMap.Map1Texture3.Points)
1627 FREE( ctx->EvalMap.Map1Texture3.Points );
1628 if (ctx->EvalMap.Map1Texture4.Points)
1629 FREE( ctx->EvalMap.Map1Texture4.Points );
1630
1631 if (ctx->EvalMap.Map2Vertex3.Points)
1632 FREE( ctx->EvalMap.Map2Vertex3.Points );
1633 if (ctx->EvalMap.Map2Vertex4.Points)
1634 FREE( ctx->EvalMap.Map2Vertex4.Points );
1635 if (ctx->EvalMap.Map2Index.Points)
1636 FREE( ctx->EvalMap.Map2Index.Points );
1637 if (ctx->EvalMap.Map2Color4.Points)
1638 FREE( ctx->EvalMap.Map2Color4.Points );
1639 if (ctx->EvalMap.Map2Normal.Points)
1640 FREE( ctx->EvalMap.Map2Normal.Points );
1641 if (ctx->EvalMap.Map2Texture1.Points)
1642 FREE( ctx->EvalMap.Map2Texture1.Points );
1643 if (ctx->EvalMap.Map2Texture2.Points)
1644 FREE( ctx->EvalMap.Map2Texture2.Points );
1645 if (ctx->EvalMap.Map2Texture3.Points)
1646 FREE( ctx->EvalMap.Map2Texture3.Points );
1647 if (ctx->EvalMap.Map2Texture4.Points)
1648 FREE( ctx->EvalMap.Map2Texture4.Points );
1649
Brian Paul4bdcfe52000-04-17 17:57:04 +00001650 _mesa_free_colortable_data( &ctx->ColorTable );
1651 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1652 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1653 _mesa_free_colortable_data( &ctx->Texture.Palette );
1654
Brian Paul69755402001-02-26 23:58:12 +00001655 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001656
1657 FREE(ctx->Exec);
1658 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001659}
1660
1661
1662
1663/*
1664 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001665 */
Brian Paul178a1c52000-04-22 01:05:00 +00001666void
Brian Paulb1394fa2000-09-26 20:53:53 +00001667_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001668{
1669 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001670 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001671 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001672 }
1673}
1674
1675
1676
1677/*
jtgafb833d1999-08-19 00:55:39 +00001678 * Copy attribute groups from one context to another.
1679 * Input: src - source context
1680 * dst - destination context
1681 * mask - bitwise OR of GL_*_BIT flags
1682 */
Brian Paul178a1c52000-04-22 01:05:00 +00001683void
Brian Paulb1394fa2000-09-26 20:53:53 +00001684_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001685{
1686 if (mask & GL_ACCUM_BUFFER_BIT) {
1687 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1688 }
1689 if (mask & GL_COLOR_BUFFER_BIT) {
1690 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1691 }
1692 if (mask & GL_CURRENT_BIT) {
1693 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1694 }
1695 if (mask & GL_DEPTH_BUFFER_BIT) {
1696 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1697 }
1698 if (mask & GL_ENABLE_BIT) {
1699 /* no op */
1700 }
1701 if (mask & GL_EVAL_BIT) {
1702 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1703 }
1704 if (mask & GL_FOG_BIT) {
1705 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1706 }
1707 if (mask & GL_HINT_BIT) {
1708 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1709 }
1710 if (mask & GL_LIGHTING_BIT) {
1711 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001712 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001713 }
1714 if (mask & GL_LINE_BIT) {
1715 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1716 }
1717 if (mask & GL_LIST_BIT) {
1718 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1719 }
1720 if (mask & GL_PIXEL_MODE_BIT) {
1721 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1722 }
1723 if (mask & GL_POINT_BIT) {
1724 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1725 }
1726 if (mask & GL_POLYGON_BIT) {
1727 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1728 }
1729 if (mask & GL_POLYGON_STIPPLE_BIT) {
1730 /* Use loop instead of MEMCPY due to problem with Portland Group's
1731 * C compiler. Reported by John Stone.
1732 */
1733 int i;
1734 for (i=0;i<32;i++) {
1735 dst->PolygonStipple[i] = src->PolygonStipple[i];
1736 }
1737 }
1738 if (mask & GL_SCISSOR_BIT) {
1739 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1740 }
1741 if (mask & GL_STENCIL_BUFFER_BIT) {
1742 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1743 }
1744 if (mask & GL_TEXTURE_BIT) {
1745 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1746 }
1747 if (mask & GL_TRANSFORM_BIT) {
1748 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1749 }
1750 if (mask & GL_VIEWPORT_BIT) {
1751 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1752 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001753 /* XXX FIXME: Call callbacks?
1754 */
1755 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001756}
1757
1758
jtgafb833d1999-08-19 00:55:39 +00001759/*
Brian Paul00037781999-12-17 14:52:35 +00001760 * Set the current context, binding the given frame buffer to the context.
1761 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001762void
1763_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001764{
Brian Paulb1394fa2000-09-26 20:53:53 +00001765 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001766}
1767
1768
Keith Whitwell23caf202000-11-16 21:05:34 +00001769static void print_info( void )
1770{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001771 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001772 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001773 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001774 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001775 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001776 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001777 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001778 (char *) _mesa_GetString(GL_EXTENSIONS));
1779#if defined(THREADS)
1780 fprintf(stderr, "Mesa thread-safe: YES\n");
1781#else
1782 fprintf(stderr, "Mesa thread-safe: NO\n");
1783#endif
1784#if defined(USE_X86_ASM)
1785 fprintf(stderr, "Mesa x86-optimized: YES\n");
1786#else
1787 fprintf(stderr, "Mesa x86-optimized: NO\n");
1788#endif
1789}
1790
1791
Brian Paul00037781999-12-17 14:52:35 +00001792/*
1793 * Bind the given context to the given draw-buffer and read-buffer
1794 * and make it the current context for this thread.
1795 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001796void
1797_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1798 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001799{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001800 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001801 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001802
Brian Paulbe3602d2001-02-28 00:27:48 +00001803 /* Check that the context's and framebuffer's visuals are compatible.
1804 * We could do a lot more checking here but this'll catch obvious
1805 * problems.
1806 */
1807 if (newCtx && drawBuffer && readBuffer) {
1808 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1809 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1810 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1811 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1812 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1813 return; /* incompatible */
1814 }
1815 }
1816
Brian Paul00037781999-12-17 14:52:35 +00001817 /* We call this function periodically (just here for now) in
1818 * order to detect when multithreading has begun.
1819 */
1820 _glapi_check_multithread();
1821
Brian Paulf9b97d92000-01-28 20:17:42 +00001822 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001823 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001824
1825
1826 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001827 _glapi_set_dispatch(NULL); /* none current */
1828 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001829 else {
1830 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001831
Keith Whitwell23caf202000-11-16 21:05:34 +00001832 if (drawBuffer && readBuffer) {
1833 /* TODO: check if newCtx and buffer's visual match??? */
1834 newCtx->DrawBuffer = drawBuffer;
1835 newCtx->ReadBuffer = readBuffer;
1836 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001837 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001838 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001839
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001840 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001841 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1842
1843 /* We can use this to help debug user's problems. Tell them to set
1844 * the MESA_INFO env variable before running their app. Then the
1845 * first time each context is made current we'll print some useful
1846 * information.
1847 */
1848 if (newCtx->FirstTimeCurrent) {
1849 if (getenv("MESA_INFO")) {
1850 print_info();
1851 }
1852 newCtx->FirstTimeCurrent = GL_FALSE;
1853 }
Brian Paul00037781999-12-17 14:52:35 +00001854 }
1855}
1856
1857
1858
1859/*
1860 * Return current context handle for the calling thread.
1861 * This isn't the fastest way to get the current context.
1862 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1863 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001864GLcontext *
1865_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001866{
Brian Paulf9b97d92000-01-28 20:17:42 +00001867 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001868}
1869
1870
1871
1872/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001873 * This should be called by device drivers just before they do a
1874 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001875 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001876void
1877_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001878{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001879 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001880}
1881
1882
Brian Paul00037781999-12-17 14:52:35 +00001883
Brian Paulfbd8f211999-11-11 01:22:25 +00001884/*
1885 * Return pointer to this context's current API dispatch table.
1886 * It'll either be the immediate-mode execute dispatcher or the
1887 * display list compile dispatcher.
1888 */
1889struct _glapi_table *
1890_mesa_get_dispatch(GLcontext *ctx)
1891{
1892 return ctx->CurrentDispatch;
1893}
1894
1895
1896
jtgafb833d1999-08-19 00:55:39 +00001897/**********************************************************************/
1898/***** Miscellaneous functions *****/
1899/**********************************************************************/
1900
1901
1902/*
1903 * This function is called when the Mesa user has stumbled into a code
1904 * path which may not be implemented fully or correctly.
1905 */
Brian Paul08836342001-03-03 20:33:27 +00001906void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001907{
1908 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00001909#ifdef XF86DRI
1910 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
1911#else
1912 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
1913#endif
jtgafb833d1999-08-19 00:55:39 +00001914 (void) ctx;
1915}
1916
1917
1918
1919/*
1920 * This is called to inform the user that he or she has tried to do
1921 * something illogical or if there's likely a bug in their program
1922 * (like enabled depth testing without a depth buffer).
1923 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001924void
1925_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001926{
Brian Paulb1394fa2000-09-26 20:53:53 +00001927 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001928}
1929
1930
1931
Brian Paulfa9df402000-02-02 19:16:46 +00001932/*
1933 * Compile an error into current display list.
1934 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001935void
1936_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001937{
1938 if (ctx->CompileFlag)
Brian Paul08836342001-03-03 20:33:27 +00001939 _mesa_save_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001940
1941 if (ctx->ExecuteFlag)
Brian Paul08836342001-03-03 20:33:27 +00001942 _mesa_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001943}
1944
1945
Brian Paulfa9df402000-02-02 19:16:46 +00001946
jtgafb833d1999-08-19 00:55:39 +00001947/*
1948 * This is Mesa's error handler. Normally, all that's done is the updating
1949 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1950 * environment variable "MESA_DEBUG" is defined then a real error message
1951 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001952 * Input: ctx - the GL context
1953 * error - the error value
1954 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001955 */
Brian Paul7eb06032000-07-14 04:13:40 +00001956void
Brian Paul08836342001-03-03 20:33:27 +00001957_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001958{
Brian Paul7eb06032000-07-14 04:13:40 +00001959 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001960 GLboolean debug;
1961
1962#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00001963 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00001964 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00001965 else
1966 debug = GL_TRUE;
1967#else
1968 if (debugEnv)
1969 debug = GL_TRUE;
1970 else
1971 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001972#endif
1973
1974 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00001975 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00001976 switch (error) {
1977 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00001978 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00001979 break;
1980 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00001981 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00001982 break;
1983 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00001984 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00001985 break;
1986 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00001987 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00001988 break;
1989 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001990 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001991 break;
1992 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001993 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001994 break;
1995 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00001996 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00001997 break;
Brian Paul86586aa2000-06-29 18:55:52 +00001998 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00001999 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002000 break;
jtgafb833d1999-08-19 00:55:39 +00002001 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002002 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002003 break;
2004 }
Brian Paul7eb06032000-07-14 04:13:40 +00002005 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002006 }
2007
Brian Paul7eb06032000-07-14 04:13:40 +00002008 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002009 ctx->ErrorValue = error;
2010 }
2011
2012 /* Call device driver's error handler, if any. This is used on the Mac. */
2013 if (ctx->Driver.Error) {
2014 (*ctx->Driver.Error)( ctx );
2015 }
2016}
2017
2018
2019
Brian Paulfa9df402000-02-02 19:16:46 +00002020void
2021_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002022{
Brian Paulfa9df402000-02-02 19:16:46 +00002023 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002024 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002025 if (ctx->Driver.Finish) {
2026 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002027 }
2028}
2029
2030
2031
Brian Paulfa9df402000-02-02 19:16:46 +00002032void
2033_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002034{
Brian Paulfa9df402000-02-02 19:16:46 +00002035 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002036 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002037 if (ctx->Driver.Flush) {
2038 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002039 }
jtgafb833d1999-08-19 00:55:39 +00002040}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002041
2042
2043
Keith Whitwellcab974c2000-12-26 05:09:27 +00002044const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002045 "GL_POINTS",
2046 "GL_LINES",
2047 "GL_LINE_LOOP",
2048 "GL_LINE_STRIP",
2049 "GL_TRIANGLES",
2050 "GL_TRIANGLE_STRIP",
2051 "GL_TRIANGLE_FAN",
2052 "GL_QUADS",
2053 "GL_QUAD_STRIP",
2054 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002055 "outside begin/end",
2056 "inside unkown primitive",
2057 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002058};