blob: 49146ce079d9b08d6802870d9ff1b5144aa507fc [file] [log] [blame]
davem69775355a2001-06-05 23:54:00 +00001/* $Id: context.c,v 1.141 2001/06/05 23:54:00 davem69 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
davem69775355a2001-06-05 23:54:00 +000069#ifdef USE_SPARC_ASM
70#include "SPARC/sparc.h"
71#endif
jtgafb833d1999-08-19 00:55:39 +000072
Keith Whitwell23caf202000-11-16 21:05:34 +000073#ifndef MESA_VERBOSE
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000074int MESA_VERBOSE = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000075/* | VERBOSE_PIPELINE */
76/* | VERBOSE_IMMEDIATE */
77/* | VERBOSE_VARRAY */
78/* | VERBOSE_TEXTURE */
79/* | VERBOSE_API */
80/* | VERBOSE_DRIVER */
81/* | VERBOSE_STATE */
Keith Whitwell23caf202000-11-16 21:05:34 +000082/* | VERBOSE_DISPLAY_LIST */
83;
84#endif
85
86#ifndef MESA_DEBUG_FLAGS
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000087int MESA_DEBUG_FLAGS = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000088/* | DEBUG_ALWAYS_FLUSH */
89;
90#endif
Brian Paulb1394fa2000-09-26 20:53:53 +000091
92/**********************************************************************/
93/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
94/**********************************************************************/
95
96static GLboolean
97_mesa_DestroyContext(__GLcontext *gc)
98{
99 if (gc) {
100 _mesa_free_context_data(gc);
101 (*gc->imports.free)(gc, gc);
102 }
103 return GL_TRUE;
104}
105
106
107/* exported OpenGL SI interface */
108__GLcontext *
109__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
110{
111 GLcontext *ctx;
112
113 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
114 if (ctx == NULL) {
115 return NULL;
116 }
117 ctx->imports = *imports;
118
119 _mesa_initialize_visual(&ctx->Visual,
120 modes->rgbMode,
121 modes->doubleBufferMode,
122 modes->stereoMode,
123 modes->redBits,
124 modes->greenBits,
125 modes->blueBits,
126 modes->alphaBits,
127 modes->indexBits,
128 modes->depthBits,
129 modes->stencilBits,
130 modes->accumRedBits,
131 modes->accumGreenBits,
132 modes->accumBlueBits,
133 modes->accumAlphaBits,
134 0);
135
Keith Whitwellb980b2e2001-01-08 04:09:41 +0000136 /* KW: was imports->wscx */
137 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
Brian Paulb1394fa2000-09-26 20:53:53 +0000138
139 ctx->exports.destroyContext = _mesa_DestroyContext;
140
141 return ctx;
142}
143
144
145/* exported OpenGL SI interface */
146void
147__glCoreNopDispatch(void)
148{
149#if 0
150 /* SI */
151 __gl_dispatch = __glNopDispatchState;
152#else
153 /* Mesa */
154 _glapi_set_dispatch(NULL);
155#endif
156}
157
158
jtgafb833d1999-08-19 00:55:39 +0000159/**********************************************************************/
160/***** Context and Thread management *****/
161/**********************************************************************/
162
163
jtgafb833d1999-08-19 00:55:39 +0000164
jtgafb833d1999-08-19 00:55:39 +0000165/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000166/***** GL Visual allocation/destruction *****/
167/**********************************************************************/
168
169
170/*
171 * Allocate a new GLvisual object.
172 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000173 * dbFlag - double buffering?
174 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000175 * depthBits - requested bits per depth buffer value
176 * Any value in [0, 32] is acceptable but the actual
177 * depth type will be GLushort or GLuint as needed.
178 * stencilBits - requested minimum bits per stencil buffer value
179 * accumBits - requested minimum bits per accum buffer component
180 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
181 * red/green/blue/alphaBits - number of bits per color component
182 * in frame buffer for RGB(A) mode.
183 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000184 * Return: pointer to new GLvisual or NULL if requested parameters can't
185 * be met.
186 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000187GLvisual *
188_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000189 GLboolean dbFlag,
190 GLboolean stereoFlag,
191 GLint redBits,
192 GLint greenBits,
193 GLint blueBits,
194 GLint alphaBits,
195 GLint indexBits,
196 GLint depthBits,
197 GLint stencilBits,
198 GLint accumRedBits,
199 GLint accumGreenBits,
200 GLint accumBlueBits,
201 GLint accumAlphaBits,
202 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000203{
Brian Paul178a1c52000-04-22 01:05:00 +0000204 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
205 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000206 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000207 redBits, greenBits, blueBits, alphaBits,
208 indexBits, depthBits, stencilBits,
209 accumRedBits, accumGreenBits,
210 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000211 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000212 FREE(vis);
213 return NULL;
214 }
215 }
216 return vis;
217}
218
219
220/*
221 * Initialize the fields of the given GLvisual.
222 * Input: see _mesa_create_visual() above.
223 * Return: GL_TRUE = success
224 * GL_FALSE = failure.
225 */
226GLboolean
227_mesa_initialize_visual( GLvisual *vis,
228 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000229 GLboolean dbFlag,
230 GLboolean stereoFlag,
231 GLint redBits,
232 GLint greenBits,
233 GLint blueBits,
234 GLint alphaBits,
235 GLint indexBits,
236 GLint depthBits,
237 GLint stencilBits,
238 GLint accumRedBits,
239 GLint accumGreenBits,
240 GLint accumBlueBits,
241 GLint accumAlphaBits,
242 GLint numSamples )
243{
Brian Paulb6bcae52001-01-23 23:39:36 +0000244 (void) numSamples;
245
Brian Paul178a1c52000-04-22 01:05:00 +0000246 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000247
Brian Pauled30dfa2000-03-03 17:47:39 +0000248 /* This is to catch bad values from device drivers not updated for
249 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
250 * bad value now (a 1-bit depth buffer!?!).
251 */
252 assert(depthBits == 0 || depthBits > 1);
253
254 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000255 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000256 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000257 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000258 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000259 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000260 if (accumRedBits < 0 || accumRedBits > (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 (accumGreenBits < 0 || accumGreenBits > (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 (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000267 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000268 }
269 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000270 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000271 }
272
Brian Paulb6bcae52001-01-23 23:39:36 +0000273 vis->rgbMode = rgbFlag;
274 vis->doubleBufferMode = dbFlag;
275 vis->stereoMode = stereoFlag;
276 vis->redBits = redBits;
277 vis->greenBits = greenBits;
278 vis->blueBits = blueBits;
279 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000280
Brian Paulb6bcae52001-01-23 23:39:36 +0000281 vis->indexBits = indexBits;
282 vis->depthBits = depthBits;
283 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
284 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
285 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
286 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
287 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000288
Brian Paul178a1c52000-04-22 01:05:00 +0000289 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000290}
291
292
Brian Paulb371e0d2000-03-31 01:05:51 +0000293void
294_mesa_destroy_visual( GLvisual *vis )
295{
296 FREE(vis);
297}
298
299
Brian Paul4d053dd2000-01-14 04:45:47 +0000300/**********************************************************************/
301/***** GL Framebuffer allocation/destruction *****/
302/**********************************************************************/
303
304
305/*
306 * Create a new framebuffer. A GLframebuffer is a struct which
307 * encapsulates the depth, stencil and accum buffers and related
308 * parameters.
Brian Paulbe3602d2001-02-28 00:27:48 +0000309 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +0000310 * softwareDepth - create/use a software depth buffer?
311 * softwareStencil - create/use a software stencil buffer?
312 * softwareAccum - create/use a software accum buffer?
313 * softwareAlpha - create/use a software alpha buffer?
Brian Paul4d053dd2000-01-14 04:45:47 +0000314 * Return: pointer to new GLframebuffer struct or NULL if error.
315 */
Brian Paul178a1c52000-04-22 01:05:00 +0000316GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000317_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000318 GLboolean softwareDepth,
319 GLboolean softwareStencil,
320 GLboolean softwareAccum,
321 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000322{
Brian Paul178a1c52000-04-22 01:05:00 +0000323 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
324 assert(visual);
325 if (buffer) {
326 _mesa_initialize_framebuffer(buffer, visual,
327 softwareDepth, softwareStencil,
328 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000329 }
Brian Paul178a1c52000-04-22 01:05:00 +0000330 return buffer;
331}
332
333
334/*
335 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000336 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000337 */
338void
339_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000340 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000341 GLboolean softwareDepth,
342 GLboolean softwareStencil,
343 GLboolean softwareAccum,
344 GLboolean softwareAlpha )
345{
346 assert(buffer);
347 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000348
349 /* sanity checks */
350 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000351 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000352 }
353 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000354 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000355 }
356 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000357 assert(visual->rgbMode);
358 assert(visual->accumRedBits > 0);
359 assert(visual->accumGreenBits > 0);
360 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000361 }
362 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000363 assert(visual->rgbMode);
364 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000365 }
366
Brian Paul75978bd2001-04-27 21:17:20 +0000367 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000368 buffer->UseSoftwareDepthBuffer = softwareDepth;
369 buffer->UseSoftwareStencilBuffer = softwareStencil;
370 buffer->UseSoftwareAccumBuffer = softwareAccum;
371 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000372}
373
374
Brian Paul4d053dd2000-01-14 04:45:47 +0000375/*
376 * Free a framebuffer struct and its buffers.
377 */
Brian Paul178a1c52000-04-22 01:05:00 +0000378void
Brian Paulb1394fa2000-09-26 20:53:53 +0000379_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000380{
381 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000382 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000383 FREE(buffer);
384 }
385}
386
387
Brian Paul75978bd2001-04-27 21:17:20 +0000388/*
389 * Free the data hanging off of <buffer>, but not <buffer> itself.
390 */
391void
392_mesa_free_framebuffer_data( GLframebuffer *buffer )
393{
394 if (!buffer)
395 return;
396
397 if (buffer->DepthBuffer) {
398 FREE( buffer->DepthBuffer );
399 buffer->DepthBuffer = NULL;
400 }
401 if (buffer->Accum) {
402 FREE( buffer->Accum );
403 buffer->Accum = NULL;
404 }
405 if (buffer->Stencil) {
406 FREE( buffer->Stencil );
407 buffer->Stencil = NULL;
408 }
409 if (buffer->FrontLeftAlpha) {
410 FREE( buffer->FrontLeftAlpha );
411 buffer->FrontLeftAlpha = NULL;
412 }
413 if (buffer->BackLeftAlpha) {
414 FREE( buffer->BackLeftAlpha );
415 buffer->BackLeftAlpha = NULL;
416 }
417 if (buffer->FrontRightAlpha) {
418 FREE( buffer->FrontRightAlpha );
419 buffer->FrontRightAlpha = NULL;
420 }
421 if (buffer->BackRightAlpha) {
422 FREE( buffer->BackRightAlpha );
423 buffer->BackRightAlpha = NULL;
424 }
425}
426
427
Brian Paul4d053dd2000-01-14 04:45:47 +0000428
429/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000430/***** Context allocation, initialization, destroying *****/
431/**********************************************************************/
432
433
Brian Paul9560f052000-01-31 23:11:39 +0000434_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
435
436
jtgafb833d1999-08-19 00:55:39 +0000437/*
438 * This function just calls all the various one-time-init functions in Mesa.
439 */
Brian Paul178a1c52000-04-22 01:05:00 +0000440static void
441one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000442{
443 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000444 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000445 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000446 /* do some implementation tests */
447 assert( sizeof(GLbyte) == 1 );
448 assert( sizeof(GLshort) >= 2 );
449 assert( sizeof(GLint) >= 4 );
450 assert( sizeof(GLubyte) == 1 );
451 assert( sizeof(GLushort) >= 2 );
452 assert( sizeof(GLuint) >= 4 );
453
Brian Paul08836342001-03-03 20:33:27 +0000454 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000455
Keith Whitwell23caf202000-11-16 21:05:34 +0000456 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000457 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000458
davem69775355a2001-06-05 23:54:00 +0000459#ifdef USE_SPARC_ASM
460 _mesa_init_sparc_glapi_relocs();
461#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000462 if (getenv("MESA_DEBUG")) {
463 _glapi_noop_enable_warnings(GL_TRUE);
464 }
465 else {
466 _glapi_noop_enable_warnings(GL_FALSE);
467 }
468
jtgafb833d1999-08-19 00:55:39 +0000469#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
470 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
471#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000472
473 alreadyCalled = GL_TRUE;
474 }
Brian Paul9560f052000-01-31 23:11:39 +0000475 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000476}
477
478
Brian Paul4d053dd2000-01-14 04:45:47 +0000479
jtgafb833d1999-08-19 00:55:39 +0000480/*
481 * Allocate and initialize a shared context state structure.
482 */
Brian Paul178a1c52000-04-22 01:05:00 +0000483static struct gl_shared_state *
484alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000485{
jtgafb833d1999-08-19 00:55:39 +0000486 struct gl_shared_state *ss;
487 GLboolean outOfMemory;
488
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000489 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000490 if (!ss)
491 return NULL;
492
Brian Paule4b684c2000-09-12 21:07:40 +0000493 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000494
Brian Paule4b684c2000-09-12 21:07:40 +0000495 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000496 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000497
498 /* Default Texture objects */
499 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000500
501 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
502 if (!ss->Default1D) {
503 outOfMemory = GL_TRUE;
504 }
jtgafb833d1999-08-19 00:55:39 +0000505
Brian Paula8523782000-11-19 23:10:25 +0000506 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
507 if (!ss->Default2D) {
508 outOfMemory = GL_TRUE;
509 }
Brian Paula8523782000-11-19 23:10:25 +0000510
511 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
512 if (!ss->Default3D) {
513 outOfMemory = GL_TRUE;
514 }
Brian Paula8523782000-11-19 23:10:25 +0000515
516 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000517 if (!ss->DefaultCubeMap) {
518 outOfMemory = GL_TRUE;
519 }
Brian Paul413d6a22000-05-26 14:44:59 +0000520
jtgafb833d1999-08-19 00:55:39 +0000521 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
522 /* Ran out of memory at some point. Free everything and return NULL */
523 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000524 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000525 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000526 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula8523782000-11-19 23:10:25 +0000527 if (ss->Default1D)
528 _mesa_free_texture_object(ss, ss->Default1D);
529 if (ss->Default2D)
530 _mesa_free_texture_object(ss, ss->Default2D);
531 if (ss->Default3D)
532 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000533 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000534 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000535 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000536 return NULL;
537 }
538 else {
539 return ss;
540 }
541}
542
543
544/*
545 * Deallocate a shared state context and all children structures.
546 */
Brian Paul178a1c52000-04-22 01:05:00 +0000547static void
548free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000549{
550 /* Free display lists */
551 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000552 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000553 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000554 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000555 }
556 else {
557 break;
558 }
559 }
Brian Paulbb797902000-01-24 16:19:54 +0000560 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000561
562 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000563 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000564 if (ctx->Driver.DeleteTexture)
565 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
566 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000567 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000568 }
Brian Paulbb797902000-01-24 16:19:54 +0000569 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000570
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000571 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000572}
573
574
575
jtgafb833d1999-08-19 00:55:39 +0000576/*
577 * Initialize the nth light. Note that the defaults for light 0 are
578 * different than the other lights.
579 */
Brian Paul178a1c52000-04-22 01:05:00 +0000580static void
581init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000582{
583 make_empty_list( l );
584
585 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
586 if (n==0) {
587 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
588 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
589 }
590 else {
591 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
592 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
593 }
594 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
595 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
596 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000597 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000598 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000599 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000600 l->ConstantAttenuation = 1.0;
601 l->LinearAttenuation = 0.0;
602 l->QuadraticAttenuation = 0.0;
603 l->Enabled = GL_FALSE;
604}
605
606
607
Brian Paul178a1c52000-04-22 01:05:00 +0000608static void
609init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000610{
611 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
612 lm->LocalViewer = GL_FALSE;
613 lm->TwoSide = GL_FALSE;
614 lm->ColorControl = GL_SINGLE_COLOR;
615}
616
617
Brian Paul178a1c52000-04-22 01:05:00 +0000618static void
619init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000620{
621 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
622 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
623 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
624 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
625 m->Shininess = 0.0;
626 m->AmbientIndex = 0;
627 m->DiffuseIndex = 1;
628 m->SpecularIndex = 1;
629}
630
631
632
Brian Paul178a1c52000-04-22 01:05:00 +0000633static void
634init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000635{
636 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
637
638 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000639 texUnit->CombineModeRGB = GL_MODULATE;
640 texUnit->CombineModeA = GL_MODULATE;
641 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
642 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
643 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
644 texUnit->CombineSourceA[0] = GL_TEXTURE;
645 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
646 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
647 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
648 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
649 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
650 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
651 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
652 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
653 texUnit->CombineScaleShiftRGB = 0;
654 texUnit->CombineScaleShiftA = 0;
655
jtgafb833d1999-08-19 00:55:39 +0000656 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
657 texUnit->TexGenEnabled = 0;
658 texUnit->GenModeS = GL_EYE_LINEAR;
659 texUnit->GenModeT = GL_EYE_LINEAR;
660 texUnit->GenModeR = GL_EYE_LINEAR;
661 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000662 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
663 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
664 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
665 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000666
jtgafb833d1999-08-19 00:55:39 +0000667 /* Yes, these plane coefficients are correct! */
668 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
669 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
670 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
671 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
672 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
673 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
674 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
675 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
676
Brian Paula8523782000-11-19 23:10:25 +0000677 texUnit->Current1D = ctx->Shared->Default1D;
678 texUnit->Current2D = ctx->Shared->Default2D;
679 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000680 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000681}
682
683
jtgafb833d1999-08-19 00:55:39 +0000684
Brian Paul4d053dd2000-01-14 04:45:47 +0000685
jtgafb833d1999-08-19 00:55:39 +0000686/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000687static void
688init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000689{
690 map->Order = 1;
691 map->u1 = 0.0;
692 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000693 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000694 if (map->Points) {
695 GLint i;
696 for (i=0;i<n;i++)
697 map->Points[i] = initial[i];
698 }
jtgafb833d1999-08-19 00:55:39 +0000699}
700
701
702/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000703static void
704init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000705{
706 map->Uorder = 1;
707 map->Vorder = 1;
708 map->u1 = 0.0;
709 map->u2 = 1.0;
710 map->v1 = 0.0;
711 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000712 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000713 if (map->Points) {
714 GLint i;
715 for (i=0;i<n;i++)
716 map->Points[i] = initial[i];
717 }
jtgafb833d1999-08-19 00:55:39 +0000718}
719
720
jtgafb833d1999-08-19 00:55:39 +0000721/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000722 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000723 */
Brian Paul178a1c52000-04-22 01:05:00 +0000724static void
725init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000726{
727 GLuint i, j;
728
Brian Paul4d053dd2000-01-14 04:45:47 +0000729 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000730
Brian Paul539cce52000-02-03 19:40:07 +0000731 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000732 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
733 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000734 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000735 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000736 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul4d053dd2000-01-14 04:45:47 +0000737 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000738 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
739 ctx->Const.MinPointSize = MIN_POINT_SIZE;
740 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
741 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
742 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
743 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
744 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
745 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
746 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
747 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
748 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
749 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000750 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000751 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
752 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000753 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000754 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
755 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000756
Brian Paul4d053dd2000-01-14 04:45:47 +0000757 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000758 _math_matrix_ctr( &ctx->ModelView );
759 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000760
761 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000762 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000763 _math_matrix_ctr( &ctx->ModelViewStack[i] );
764 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000765 }
766
767 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000768 _math_matrix_ctr( &ctx->ProjectionMatrix );
769 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000770
771 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000772 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000773 _math_matrix_ctr( &ctx->ProjectionStack[i] );
774 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000775 }
776
Keith Whitwell23caf202000-11-16 21:05:34 +0000777 /* Derived ModelProject matrix */
778 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
779
Brian Paul4d053dd2000-01-14 04:45:47 +0000780 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000781 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000782 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000783 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000784 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000785 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000786 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000787 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000788 }
jtgafb833d1999-08-19 00:55:39 +0000789
Brian Paul250069d2000-04-08 18:57:45 +0000790 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000791 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000792 ctx->ColorStackDepth = 0;
793 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000794 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000795 }
796
Brian Paul4d053dd2000-01-14 04:45:47 +0000797 /* Accumulate buffer group */
798 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000799
Brian Paul4d053dd2000-01-14 04:45:47 +0000800 /* Color buffer group */
801 ctx->Color.IndexMask = 0xffffffff;
802 ctx->Color.ColorMask[0] = 0xff;
803 ctx->Color.ColorMask[1] = 0xff;
804 ctx->Color.ColorMask[2] = 0xff;
805 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000806 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000807 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000808 ctx->Color.DrawBuffer = GL_FRONT;
809 ctx->Color.AlphaEnabled = GL_FALSE;
810 ctx->Color.AlphaFunc = GL_ALWAYS;
811 ctx->Color.AlphaRef = 0;
812 ctx->Color.BlendEnabled = GL_FALSE;
813 ctx->Color.BlendSrcRGB = GL_ONE;
814 ctx->Color.BlendDstRGB = GL_ZERO;
815 ctx->Color.BlendSrcA = GL_ONE;
816 ctx->Color.BlendDstA = GL_ZERO;
817 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000818 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
819 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
820 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000821 ctx->Color.LogicOp = GL_COPY;
822 ctx->Color.DitherFlag = GL_TRUE;
823 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000824
Brian Paul4d053dd2000-01-14 04:45:47 +0000825 /* Current group */
Keith Whitwell51c0c712001-04-28 08:39:17 +0000826 ASSIGN_4V( ctx->Current.Color, 1.0, 1.0, 1.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000827 ctx->Current.Index = 1;
828 for (i=0; i<MAX_TEXTURE_UNITS; i++)
829 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
830 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
831 ctx->Current.RasterDistance = 0.0;
832 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
833 ctx->Current.RasterIndex = 1;
834 for (i=0; i<MAX_TEXTURE_UNITS; i++)
835 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
836 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
837 ctx->Current.RasterPosValid = GL_TRUE;
838 ctx->Current.EdgeFlag = GL_TRUE;
839 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000840
jtgafb833d1999-08-19 00:55:39 +0000841
Brian Paul4d053dd2000-01-14 04:45:47 +0000842 /* Depth buffer group */
843 ctx->Depth.Test = GL_FALSE;
844 ctx->Depth.Clear = 1.0;
845 ctx->Depth.Func = GL_LESS;
846 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000847 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000848
Brian Paul4d053dd2000-01-14 04:45:47 +0000849 /* Evaluators group */
850 ctx->Eval.Map1Color4 = GL_FALSE;
851 ctx->Eval.Map1Index = GL_FALSE;
852 ctx->Eval.Map1Normal = GL_FALSE;
853 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
854 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
855 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
856 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
857 ctx->Eval.Map1Vertex3 = GL_FALSE;
858 ctx->Eval.Map1Vertex4 = GL_FALSE;
859 ctx->Eval.Map2Color4 = GL_FALSE;
860 ctx->Eval.Map2Index = GL_FALSE;
861 ctx->Eval.Map2Normal = GL_FALSE;
862 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
863 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
864 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
865 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
866 ctx->Eval.Map2Vertex3 = GL_FALSE;
867 ctx->Eval.Map2Vertex4 = GL_FALSE;
868 ctx->Eval.AutoNormal = GL_FALSE;
869 ctx->Eval.MapGrid1un = 1;
870 ctx->Eval.MapGrid1u1 = 0.0;
871 ctx->Eval.MapGrid1u2 = 1.0;
872 ctx->Eval.MapGrid2un = 1;
873 ctx->Eval.MapGrid2vn = 1;
874 ctx->Eval.MapGrid2u1 = 0.0;
875 ctx->Eval.MapGrid2u2 = 1.0;
876 ctx->Eval.MapGrid2v1 = 0.0;
877 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000878
Brian Paul4d053dd2000-01-14 04:45:47 +0000879 /* Evaluator data */
880 {
881 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
882 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
883 static GLfloat index[1] = { 1.0 };
884 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
885 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000886
Brian Paul4d053dd2000-01-14 04:45:47 +0000887 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
888 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
889 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
890 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
891 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
892 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
893 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
894 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
895 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000896
Brian Paul4d053dd2000-01-14 04:45:47 +0000897 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
898 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
899 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
900 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
901 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
902 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
903 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
904 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
905 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
906 }
jtgafb833d1999-08-19 00:55:39 +0000907
Brian Paul4d053dd2000-01-14 04:45:47 +0000908 /* Fog group */
909 ctx->Fog.Enabled = GL_FALSE;
910 ctx->Fog.Mode = GL_EXP;
911 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
912 ctx->Fog.Index = 0.0;
913 ctx->Fog.Density = 1.0;
914 ctx->Fog.Start = 0.0;
915 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000916 ctx->Fog.ColorSumEnabled = GL_FALSE;
917 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000918
Brian Paul4d053dd2000-01-14 04:45:47 +0000919 /* Hint group */
920 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
921 ctx->Hint.PointSmooth = GL_DONT_CARE;
922 ctx->Hint.LineSmooth = GL_DONT_CARE;
923 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
924 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000925 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
926 ctx->Hint.TextureCompression = GL_DONT_CARE;
Brian Paul3893e632001-05-21 16:41:03 +0000927 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000928
Brian Paul0771d152000-04-07 00:19:41 +0000929 /* Histogram group */
930 ctx->Histogram.Width = 0;
931 ctx->Histogram.Format = GL_RGBA;
932 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000933 ctx->Histogram.RedSize = 0;
934 ctx->Histogram.GreenSize = 0;
935 ctx->Histogram.BlueSize = 0;
936 ctx->Histogram.AlphaSize = 0;
937 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000938 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
939 ctx->Histogram.Count[i][0] = 0;
940 ctx->Histogram.Count[i][1] = 0;
941 ctx->Histogram.Count[i][2] = 0;
942 ctx->Histogram.Count[i][3] = 0;
943 }
944
945 /* Min/Max group */
946 ctx->MinMax.Format = GL_RGBA;
947 ctx->MinMax.Sink = GL_FALSE;
948 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
949 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
950 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
951 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
952
Brian Paul4d053dd2000-01-14 04:45:47 +0000953 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000954 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000955
Brian Paul4d053dd2000-01-14 04:45:47 +0000956 /* Lighting group */
957 for (i=0;i<MAX_LIGHTS;i++) {
958 init_light( &ctx->Light.Light[i], i );
959 }
960 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000961
Brian Paul4d053dd2000-01-14 04:45:47 +0000962 init_lightmodel( &ctx->Light.Model );
963 init_material( &ctx->Light.Material[0] );
964 init_material( &ctx->Light.Material[1] );
965 ctx->Light.ShadeModel = GL_SMOOTH;
966 ctx->Light.Enabled = GL_FALSE;
967 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
968 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +0000969 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
970 GL_FRONT_AND_BACK,
971 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000972
Brian Paul4d053dd2000-01-14 04:45:47 +0000973 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000974
Brian Paul4d053dd2000-01-14 04:45:47 +0000975 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +0000976 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
977 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +0000978 for (i = 0 ; i < 10 ; i++) {
979 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
980 s->shininess = -1;
981 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000982 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +0000983 }
Brian Paul77d61af2000-06-28 04:20:21 +0000984
jtgafb833d1999-08-19 00:55:39 +0000985
Brian Paul4d053dd2000-01-14 04:45:47 +0000986 /* Line group */
987 ctx->Line.SmoothFlag = GL_FALSE;
988 ctx->Line.StippleFlag = GL_FALSE;
989 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +0000990 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000991 ctx->Line.StipplePattern = 0xffff;
992 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000993
Brian Paul4d053dd2000-01-14 04:45:47 +0000994 /* Display List group */
995 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +0000996
Brian Paul736fcbe2001-05-29 15:23:48 +0000997 /* Multisample */
998 ctx->Multisample.Enabled = GL_FALSE;
999 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
1000 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
1001 ctx->Multisample.SampleCoverage = GL_FALSE;
1002 ctx->Multisample.SampleCoverageValue = 1.0;
1003 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
1004
Brian Paul4d053dd2000-01-14 04:45:47 +00001005 /* Pixel group */
1006 ctx->Pixel.RedBias = 0.0;
1007 ctx->Pixel.RedScale = 1.0;
1008 ctx->Pixel.GreenBias = 0.0;
1009 ctx->Pixel.GreenScale = 1.0;
1010 ctx->Pixel.BlueBias = 0.0;
1011 ctx->Pixel.BlueScale = 1.0;
1012 ctx->Pixel.AlphaBias = 0.0;
1013 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001014 ctx->Pixel.DepthBias = 0.0;
1015 ctx->Pixel.DepthScale = 1.0;
1016 ctx->Pixel.IndexOffset = 0;
1017 ctx->Pixel.IndexShift = 0;
1018 ctx->Pixel.ZoomX = 1.0;
1019 ctx->Pixel.ZoomY = 1.0;
1020 ctx->Pixel.MapColorFlag = GL_FALSE;
1021 ctx->Pixel.MapStencilFlag = GL_FALSE;
1022 ctx->Pixel.MapStoSsize = 1;
1023 ctx->Pixel.MapItoIsize = 1;
1024 ctx->Pixel.MapItoRsize = 1;
1025 ctx->Pixel.MapItoGsize = 1;
1026 ctx->Pixel.MapItoBsize = 1;
1027 ctx->Pixel.MapItoAsize = 1;
1028 ctx->Pixel.MapRtoRsize = 1;
1029 ctx->Pixel.MapGtoGsize = 1;
1030 ctx->Pixel.MapBtoBsize = 1;
1031 ctx->Pixel.MapAtoAsize = 1;
1032 ctx->Pixel.MapStoS[0] = 0;
1033 ctx->Pixel.MapItoI[0] = 0;
1034 ctx->Pixel.MapItoR[0] = 0.0;
1035 ctx->Pixel.MapItoG[0] = 0.0;
1036 ctx->Pixel.MapItoB[0] = 0.0;
1037 ctx->Pixel.MapItoA[0] = 0.0;
1038 ctx->Pixel.MapItoR8[0] = 0;
1039 ctx->Pixel.MapItoG8[0] = 0;
1040 ctx->Pixel.MapItoB8[0] = 0;
1041 ctx->Pixel.MapItoA8[0] = 0;
1042 ctx->Pixel.MapRtoR[0] = 0.0;
1043 ctx->Pixel.MapGtoG[0] = 0.0;
1044 ctx->Pixel.MapBtoB[0] = 0.0;
1045 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001046 ctx->Pixel.HistogramEnabled = GL_FALSE;
1047 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1048 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1049 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1050 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001051 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1052 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1053 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1054 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001055 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1056 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1057 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1058 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001059 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1060 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1061 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001062 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1063 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1064 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1065 for (i = 0; i < 3; i++) {
1066 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1067 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1068 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1069 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1070 }
Brian Paul67adba12000-12-09 20:35:54 +00001071 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1072 ctx->Convolution1D.Filter[i] = 0.0;
1073 ctx->Convolution2D.Filter[i] = 0.0;
1074 ctx->Separable2D.Filter[i] = 0.0;
1075 }
Brian Paul82b02f02000-05-07 20:37:40 +00001076 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1077 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001078
Brian Paul4d053dd2000-01-14 04:45:47 +00001079 /* Point group */
1080 ctx->Point.SmoothFlag = GL_FALSE;
1081 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001082 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001083 ctx->Point.Params[0] = 1.0;
1084 ctx->Point.Params[1] = 0.0;
1085 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001086 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001087 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001088 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001089 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001090 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001091
Brian Paul4d053dd2000-01-14 04:45:47 +00001092 /* Polygon group */
1093 ctx->Polygon.CullFlag = GL_FALSE;
1094 ctx->Polygon.CullFaceMode = GL_BACK;
1095 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001096 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001097 ctx->Polygon.FrontMode = GL_FILL;
1098 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001099 ctx->Polygon.SmoothFlag = GL_FALSE;
1100 ctx->Polygon.StippleFlag = GL_FALSE;
1101 ctx->Polygon.OffsetFactor = 0.0F;
1102 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001103 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001104 ctx->Polygon.OffsetPoint = GL_FALSE;
1105 ctx->Polygon.OffsetLine = GL_FALSE;
1106 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001107
Brian Paul4d053dd2000-01-14 04:45:47 +00001108 /* Polygon Stipple group */
1109 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001110
Brian Paul4d053dd2000-01-14 04:45:47 +00001111 /* Scissor group */
1112 ctx->Scissor.Enabled = GL_FALSE;
1113 ctx->Scissor.X = 0;
1114 ctx->Scissor.Y = 0;
1115 ctx->Scissor.Width = 0;
1116 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001117
Brian Paul4d053dd2000-01-14 04:45:47 +00001118 /* Stencil group */
1119 ctx->Stencil.Enabled = GL_FALSE;
1120 ctx->Stencil.Function = GL_ALWAYS;
1121 ctx->Stencil.FailFunc = GL_KEEP;
1122 ctx->Stencil.ZPassFunc = GL_KEEP;
1123 ctx->Stencil.ZFailFunc = GL_KEEP;
1124 ctx->Stencil.Ref = 0;
1125 ctx->Stencil.ValueMask = STENCIL_MAX;
1126 ctx->Stencil.Clear = 0;
1127 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001128
Brian Paul4d053dd2000-01-14 04:45:47 +00001129 /* Texture group */
1130 ctx->Texture.CurrentUnit = 0; /* multitexture */
1131 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001132 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1134 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001135 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001136 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001137
Brian Paul4d053dd2000-01-14 04:45:47 +00001138 /* Transformation group */
1139 ctx->Transform.MatrixMode = GL_MODELVIEW;
1140 ctx->Transform.Normalize = GL_FALSE;
1141 ctx->Transform.RescaleNormals = GL_FALSE;
1142 for (i=0;i<MAX_CLIP_PLANES;i++) {
1143 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1144 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1145 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001146 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001147
Brian Paul4d053dd2000-01-14 04:45:47 +00001148 /* Viewport group */
1149 ctx->Viewport.X = 0;
1150 ctx->Viewport.Y = 0;
1151 ctx->Viewport.Width = 0;
1152 ctx->Viewport.Height = 0;
1153 ctx->Viewport.Near = 0.0;
1154 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001155 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001156
1157#define Sz 10
1158#define Tz 14
Brian Paulb6bcae52001-01-23 23:39:36 +00001159 ctx->Viewport._WindowMap.m[Sz] = 0.5 * ctx->DepthMaxF;
1160 ctx->Viewport._WindowMap.m[Tz] = 0.5 * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001161#undef Sz
1162#undef Tz
1163
Keith Whitwell14940c42000-11-05 18:40:57 +00001164 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1165 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001166
Brian Paul4d053dd2000-01-14 04:45:47 +00001167 /* Vertex arrays */
1168 ctx->Array.Vertex.Size = 4;
1169 ctx->Array.Vertex.Type = GL_FLOAT;
1170 ctx->Array.Vertex.Stride = 0;
1171 ctx->Array.Vertex.StrideB = 0;
1172 ctx->Array.Vertex.Ptr = NULL;
1173 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001174 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001175 ctx->Array.Normal.Type = GL_FLOAT;
1176 ctx->Array.Normal.Stride = 0;
1177 ctx->Array.Normal.StrideB = 0;
1178 ctx->Array.Normal.Ptr = NULL;
1179 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001180 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001181 ctx->Array.Color.Size = 4;
1182 ctx->Array.Color.Type = GL_FLOAT;
1183 ctx->Array.Color.Stride = 0;
1184 ctx->Array.Color.StrideB = 0;
1185 ctx->Array.Color.Ptr = NULL;
1186 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001187 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1188 ctx->Array.SecondaryColor.Size = 4;
1189 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1190 ctx->Array.SecondaryColor.Stride = 0;
1191 ctx->Array.SecondaryColor.StrideB = 0;
1192 ctx->Array.SecondaryColor.Ptr = NULL;
1193 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1194 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1195 ctx->Array.FogCoord.Size = 1;
1196 ctx->Array.FogCoord.Type = GL_FLOAT;
1197 ctx->Array.FogCoord.Stride = 0;
1198 ctx->Array.FogCoord.StrideB = 0;
1199 ctx->Array.FogCoord.Ptr = NULL;
1200 ctx->Array.FogCoord.Enabled = GL_FALSE;
1201 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001202 ctx->Array.Index.Type = GL_FLOAT;
1203 ctx->Array.Index.Stride = 0;
1204 ctx->Array.Index.StrideB = 0;
1205 ctx->Array.Index.Ptr = NULL;
1206 ctx->Array.Index.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001207 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001208 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1209 ctx->Array.TexCoord[i].Size = 4;
1210 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1211 ctx->Array.TexCoord[i].Stride = 0;
1212 ctx->Array.TexCoord[i].StrideB = 0;
1213 ctx->Array.TexCoord[i].Ptr = NULL;
1214 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001215 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001216 }
1217 ctx->Array.TexCoordInterleaveFactor = 1;
1218 ctx->Array.EdgeFlag.Stride = 0;
1219 ctx->Array.EdgeFlag.StrideB = 0;
1220 ctx->Array.EdgeFlag.Ptr = NULL;
1221 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001222 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001223 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1224
1225 /* Pixel transfer */
1226 ctx->Pack.Alignment = 4;
1227 ctx->Pack.RowLength = 0;
1228 ctx->Pack.ImageHeight = 0;
1229 ctx->Pack.SkipPixels = 0;
1230 ctx->Pack.SkipRows = 0;
1231 ctx->Pack.SkipImages = 0;
1232 ctx->Pack.SwapBytes = GL_FALSE;
1233 ctx->Pack.LsbFirst = GL_FALSE;
1234 ctx->Unpack.Alignment = 4;
1235 ctx->Unpack.RowLength = 0;
1236 ctx->Unpack.ImageHeight = 0;
1237 ctx->Unpack.SkipPixels = 0;
1238 ctx->Unpack.SkipRows = 0;
1239 ctx->Unpack.SkipImages = 0;
1240 ctx->Unpack.SwapBytes = GL_FALSE;
1241 ctx->Unpack.LsbFirst = GL_FALSE;
1242
1243 /* Feedback */
1244 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1245 ctx->Feedback.Buffer = NULL;
1246 ctx->Feedback.BufferSize = 0;
1247 ctx->Feedback.Count = 0;
1248
1249 /* Selection/picking */
1250 ctx->Select.Buffer = NULL;
1251 ctx->Select.BufferSize = 0;
1252 ctx->Select.BufferCount = 0;
1253 ctx->Select.Hits = 0;
1254 ctx->Select.NameStackDepth = 0;
1255
Brian Paul4d053dd2000-01-14 04:45:47 +00001256 /* Renderer and client attribute stacks */
1257 ctx->AttribStackDepth = 0;
1258 ctx->ClientAttribStackDepth = 0;
1259
Brian Paul13811372000-04-12 00:27:37 +00001260 /* Display list */
1261 ctx->CallDepth = 0;
1262 ctx->ExecuteFlag = GL_TRUE;
1263 ctx->CompileFlag = GL_FALSE;
1264 ctx->CurrentListPtr = NULL;
1265 ctx->CurrentBlock = NULL;
1266 ctx->CurrentListNum = 0;
1267 ctx->CurrentPos = 0;
1268
1269 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001270 _mesa_init_colortable(&ctx->ColorTable);
1271 _mesa_init_colortable(&ctx->ProxyColorTable);
1272 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1273 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1274 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1275 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001276
Brian Paul4d053dd2000-01-14 04:45:47 +00001277 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001278 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001279 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001280 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001281
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001282 ctx->_NeedNormals = 0;
1283 ctx->_NeedEyeCoords = 0;
1284 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001285
Brian Paul4d053dd2000-01-14 04:45:47 +00001286 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1287
1288 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001289 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001290 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001291
1292 /* For debug/development only */
1293 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1294 ctx->FirstTimeCurrent = GL_TRUE;
1295
1296 /* Dither disable */
1297 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1298 if (ctx->NoDither) {
1299 if (getenv("MESA_DEBUG")) {
1300 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001301 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001302 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001303 }
1304}
1305
1306
1307
1308
jtgafb833d1999-08-19 00:55:39 +00001309/*
1310 * Allocate the proxy textures. If we run out of memory part way through
1311 * the allocations clean up and return GL_FALSE.
1312 * Return: GL_TRUE=success, GL_FALSE=failure
1313 */
Brian Paul178a1c52000-04-22 01:05:00 +00001314static GLboolean
1315alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001316{
1317 GLboolean out_of_memory;
1318 GLint i;
1319
Brian Paula8523782000-11-19 23:10:25 +00001320 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001321 if (!ctx->Texture.Proxy1D) {
1322 return GL_FALSE;
1323 }
1324
Brian Paula8523782000-11-19 23:10:25 +00001325 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001326 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001327 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001328 return GL_FALSE;
1329 }
1330
Brian Paula8523782000-11-19 23:10:25 +00001331 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001332 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001333 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1334 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1335 return GL_FALSE;
1336 }
1337
1338 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1339 if (!ctx->Texture.ProxyCubeMap) {
1340 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1341 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1342 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001343 return GL_FALSE;
1344 }
1345
1346 out_of_memory = GL_FALSE;
1347 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001348 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1349 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1350 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001351 if (!ctx->Texture.Proxy1D->Image[i]
1352 || !ctx->Texture.Proxy2D->Image[i]
1353 || !ctx->Texture.Proxy3D->Image[i]) {
1354 out_of_memory = GL_TRUE;
1355 }
1356 }
1357 if (out_of_memory) {
1358 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1359 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001360 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001361 }
1362 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001363 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001364 }
1365 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001366 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001367 }
1368 }
Brian Paula8523782000-11-19 23:10:25 +00001369 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1370 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1371 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001372 return GL_FALSE;
1373 }
1374 else {
1375 return GL_TRUE;
1376 }
1377}
1378
1379
jtgafb833d1999-08-19 00:55:39 +00001380/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001381 * Initialize a GLcontext struct. This includes allocating all the
1382 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001383 */
Brian Paul178a1c52000-04-22 01:05:00 +00001384GLboolean
1385_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001386 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001387 GLcontext *share_list,
1388 void *driver_ctx,
1389 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001390{
Brian Paul5fb84d22000-05-24 15:04:45 +00001391 GLuint dispatchSize;
1392
jtgafb833d1999-08-19 00:55:39 +00001393 (void) direct; /* not used */
1394
jtgafb833d1999-08-19 00:55:39 +00001395 /* misc one-time initializations */
1396 one_time_init();
1397
Brian Paulb1394fa2000-09-26 20:53:53 +00001398 /**
1399 ** OpenGL SI stuff
1400 **/
1401 if (!ctx->imports.malloc) {
1402 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1403 }
1404 /* exports are setup by the device driver */
1405
jtgafb833d1999-08-19 00:55:39 +00001406 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001407 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001408 ctx->DrawBuffer = NULL;
1409 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001410
jtgafb833d1999-08-19 00:55:39 +00001411 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001412 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001413 ctx->Shared = share_list->Shared;
1414 }
1415 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001416 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001417 ctx->Shared = alloc_shared_state();
1418 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001419 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001420 }
1421 }
Brian Paul9560f052000-01-31 23:11:39 +00001422 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001423 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001424 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001425
Brian Paul5a2f32b2001-04-25 18:21:05 +00001426 /* Effectively bind the default textures to all texture units */
1427 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1428 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1429 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1430 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1431
Brian Paul4d053dd2000-01-14 04:45:47 +00001432 init_attrib_groups( ctx );
1433
Brian Paulb6bcae52001-01-23 23:39:36 +00001434 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001435 ctx->Color.DrawBuffer = GL_BACK;
1436 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1437 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1438 ctx->Pixel.ReadBuffer = GL_BACK;
1439 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1440 }
1441 else {
1442 ctx->Color.DrawBuffer = GL_FRONT;
1443 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1444 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1445 ctx->Pixel.ReadBuffer = GL_FRONT;
1446 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1447 }
1448
jtgafb833d1999-08-19 00:55:39 +00001449 if (!alloc_proxy_textures(ctx)) {
1450 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001451 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001452 }
jtgafb833d1999-08-19 00:55:39 +00001453
Brian Paulf59afc92000-05-23 23:23:00 +00001454 /* register the most recent extension functions with libGL */
1455 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1456 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1457 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1458 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1459 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1460 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1461 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1462 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1463
Brian Paul5fb84d22000-05-24 15:04:45 +00001464 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1465 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1466 * Mesa we do this to accomodate different versions of libGL and various
1467 * DRI drivers.
1468 */
1469 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1470 sizeof(struct _glapi_table) / sizeof(void *));
1471
Brian Paulfbd8f211999-11-11 01:22:25 +00001472 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001473 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1474 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001475 if (!ctx->Exec || !ctx->Save) {
1476 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001477 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001478 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001479 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001480 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1481 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001482 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001483
Keith Whitwellad2ac212000-11-24 10:25:05 +00001484 ctx->ExecPrefersFloat = GL_FALSE;
1485 ctx->SavePrefersFloat = GL_FALSE;
1486
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001487 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001488 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001489 ctx->TnlModule.Current = NULL;
1490 ctx->TnlModule.SwapCount = 0;
1491
Brian Paulb6bcae52001-01-23 23:39:36 +00001492 /* Z buffer stuff */
1493 if (ctx->Visual.depthBits == 0) {
1494 /* Special case. Even if we don't have a depth buffer we need
1495 * good values for DepthMax for Z vertex transformation purposes
1496 * and for per-fragment fog computation.
1497 */
1498 ctx->DepthMax = 1 << 16;
1499 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1500 }
1501 else if (ctx->Visual.depthBits < 32) {
1502 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1503 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1504 }
1505 else {
1506 /* Special case since shift values greater than or equal to the
1507 * number of bits in the left hand expression's type are undefined.
1508 */
1509 ctx->DepthMax = 0xffffffff;
1510 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1511 }
Brian Paulbc920f02001-05-07 16:32:51 +00001512 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001513
1514
Brian Paul3b18a362000-09-26 15:27:20 +00001515#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001516 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001517#if 0
1518 /* Brian: do you want to have CreateContext fail here,
1519 or should we just trap in NewTrace (currently done)? */
1520 if (!(ctx->TraceCtx)) {
1521 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001522 FREE( ctx->Exec );
1523 FREE( ctx->Save );
1524 return GL_FALSE;
1525 }
1526#endif
1527 trInitContext(ctx->TraceCtx);
1528
1529 ctx->TraceDispatch = (struct _glapi_table *)
1530 CALLOC(dispatchSize * sizeof(void*));
1531#if 0
1532 if (!(ctx->TraceCtx)) {
1533 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001534 FREE( ctx->Exec );
1535 FREE( ctx->Save );
1536 FREE( ctx->TraceCtx );
1537 return GL_FALSE;
1538 }
1539#endif
1540 trInitDispatch(ctx->TraceDispatch);
1541#endif
1542
Brian Paul4d053dd2000-01-14 04:45:47 +00001543 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001544}
1545
jtgafb833d1999-08-19 00:55:39 +00001546
1547
1548/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001549 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001550 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001551 * sharelist - another context to share display lists with or NULL
1552 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001553 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001554 */
Brian Paul178a1c52000-04-22 01:05:00 +00001555GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001556_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001557 GLcontext *share_list,
1558 void *driver_ctx,
1559 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001560{
1561 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1562 if (!ctx) {
1563 return NULL;
1564 }
1565
Brian Paul178a1c52000-04-22 01:05:00 +00001566 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001567 return ctx;
1568 }
1569 else {
1570 FREE(ctx);
1571 return NULL;
1572 }
1573}
1574
1575
1576
1577/*
1578 * Free the data associated with the given context.
1579 * But don't free() the GLcontext struct itself!
1580 */
Brian Paul178a1c52000-04-22 01:05:00 +00001581void
Brian Paulb1394fa2000-09-26 20:53:53 +00001582_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001583{
Brian Paul4d053dd2000-01-14 04:45:47 +00001584 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001585 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001586
1587 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001588 if (ctx == _mesa_get_current_context()) {
1589 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001590 }
1591
Keith Whitwell23caf202000-11-16 21:05:34 +00001592 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001593 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001594 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001595 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001596 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001597 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001598 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001599 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001600 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001601 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001602 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001603 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001604 }
1605 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001606
Brian Paul9560f052000-01-31 23:11:39 +00001607 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001608 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001609 assert(ctx->Shared->RefCount >= 0);
1610 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1611 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001612 /* free shared state */
1613 free_shared_state( ctx, ctx->Shared );
1614 }
1615
Keith Whitwell14940c42000-11-05 18:40:57 +00001616 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001617 FREE( s );
1618 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001619 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001620
1621 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001622 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1623 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1624 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paul4d053dd2000-01-14 04:45:47 +00001625
1626 /* Free evaluator data */
1627 if (ctx->EvalMap.Map1Vertex3.Points)
1628 FREE( ctx->EvalMap.Map1Vertex3.Points );
1629 if (ctx->EvalMap.Map1Vertex4.Points)
1630 FREE( ctx->EvalMap.Map1Vertex4.Points );
1631 if (ctx->EvalMap.Map1Index.Points)
1632 FREE( ctx->EvalMap.Map1Index.Points );
1633 if (ctx->EvalMap.Map1Color4.Points)
1634 FREE( ctx->EvalMap.Map1Color4.Points );
1635 if (ctx->EvalMap.Map1Normal.Points)
1636 FREE( ctx->EvalMap.Map1Normal.Points );
1637 if (ctx->EvalMap.Map1Texture1.Points)
1638 FREE( ctx->EvalMap.Map1Texture1.Points );
1639 if (ctx->EvalMap.Map1Texture2.Points)
1640 FREE( ctx->EvalMap.Map1Texture2.Points );
1641 if (ctx->EvalMap.Map1Texture3.Points)
1642 FREE( ctx->EvalMap.Map1Texture3.Points );
1643 if (ctx->EvalMap.Map1Texture4.Points)
1644 FREE( ctx->EvalMap.Map1Texture4.Points );
1645
1646 if (ctx->EvalMap.Map2Vertex3.Points)
1647 FREE( ctx->EvalMap.Map2Vertex3.Points );
1648 if (ctx->EvalMap.Map2Vertex4.Points)
1649 FREE( ctx->EvalMap.Map2Vertex4.Points );
1650 if (ctx->EvalMap.Map2Index.Points)
1651 FREE( ctx->EvalMap.Map2Index.Points );
1652 if (ctx->EvalMap.Map2Color4.Points)
1653 FREE( ctx->EvalMap.Map2Color4.Points );
1654 if (ctx->EvalMap.Map2Normal.Points)
1655 FREE( ctx->EvalMap.Map2Normal.Points );
1656 if (ctx->EvalMap.Map2Texture1.Points)
1657 FREE( ctx->EvalMap.Map2Texture1.Points );
1658 if (ctx->EvalMap.Map2Texture2.Points)
1659 FREE( ctx->EvalMap.Map2Texture2.Points );
1660 if (ctx->EvalMap.Map2Texture3.Points)
1661 FREE( ctx->EvalMap.Map2Texture3.Points );
1662 if (ctx->EvalMap.Map2Texture4.Points)
1663 FREE( ctx->EvalMap.Map2Texture4.Points );
1664
Brian Paul4bdcfe52000-04-17 17:57:04 +00001665 _mesa_free_colortable_data( &ctx->ColorTable );
1666 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1667 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1668 _mesa_free_colortable_data( &ctx->Texture.Palette );
1669
Brian Paul69755402001-02-26 23:58:12 +00001670 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001671
1672 FREE(ctx->Exec);
1673 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001674}
1675
1676
1677
1678/*
1679 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001680 */
Brian Paul178a1c52000-04-22 01:05:00 +00001681void
Brian Paulb1394fa2000-09-26 20:53:53 +00001682_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001683{
1684 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001685 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001686 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001687 }
1688}
1689
1690
1691
1692/*
jtgafb833d1999-08-19 00:55:39 +00001693 * Copy attribute groups from one context to another.
1694 * Input: src - source context
1695 * dst - destination context
1696 * mask - bitwise OR of GL_*_BIT flags
1697 */
Brian Paul178a1c52000-04-22 01:05:00 +00001698void
Brian Paulb1394fa2000-09-26 20:53:53 +00001699_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001700{
1701 if (mask & GL_ACCUM_BUFFER_BIT) {
1702 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1703 }
1704 if (mask & GL_COLOR_BUFFER_BIT) {
1705 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1706 }
1707 if (mask & GL_CURRENT_BIT) {
1708 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1709 }
1710 if (mask & GL_DEPTH_BUFFER_BIT) {
1711 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1712 }
1713 if (mask & GL_ENABLE_BIT) {
1714 /* no op */
1715 }
1716 if (mask & GL_EVAL_BIT) {
1717 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1718 }
1719 if (mask & GL_FOG_BIT) {
1720 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1721 }
1722 if (mask & GL_HINT_BIT) {
1723 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1724 }
1725 if (mask & GL_LIGHTING_BIT) {
1726 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001727 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001728 }
1729 if (mask & GL_LINE_BIT) {
1730 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1731 }
1732 if (mask & GL_LIST_BIT) {
1733 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1734 }
1735 if (mask & GL_PIXEL_MODE_BIT) {
1736 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1737 }
1738 if (mask & GL_POINT_BIT) {
1739 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1740 }
1741 if (mask & GL_POLYGON_BIT) {
1742 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1743 }
1744 if (mask & GL_POLYGON_STIPPLE_BIT) {
1745 /* Use loop instead of MEMCPY due to problem with Portland Group's
1746 * C compiler. Reported by John Stone.
1747 */
1748 int i;
1749 for (i=0;i<32;i++) {
1750 dst->PolygonStipple[i] = src->PolygonStipple[i];
1751 }
1752 }
1753 if (mask & GL_SCISSOR_BIT) {
1754 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1755 }
1756 if (mask & GL_STENCIL_BUFFER_BIT) {
1757 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1758 }
1759 if (mask & GL_TEXTURE_BIT) {
1760 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1761 }
1762 if (mask & GL_TRANSFORM_BIT) {
1763 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1764 }
1765 if (mask & GL_VIEWPORT_BIT) {
1766 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1767 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001768 /* XXX FIXME: Call callbacks?
1769 */
1770 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001771}
1772
1773
jtgafb833d1999-08-19 00:55:39 +00001774/*
Brian Paul00037781999-12-17 14:52:35 +00001775 * Set the current context, binding the given frame buffer to the context.
1776 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001777void
1778_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001779{
Brian Paulb1394fa2000-09-26 20:53:53 +00001780 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001781}
1782
1783
Keith Whitwell23caf202000-11-16 21:05:34 +00001784static void print_info( void )
1785{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001786 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001787 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001788 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001789 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001790 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001791 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001792 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001793 (char *) _mesa_GetString(GL_EXTENSIONS));
1794#if defined(THREADS)
1795 fprintf(stderr, "Mesa thread-safe: YES\n");
1796#else
1797 fprintf(stderr, "Mesa thread-safe: NO\n");
1798#endif
1799#if defined(USE_X86_ASM)
1800 fprintf(stderr, "Mesa x86-optimized: YES\n");
1801#else
1802 fprintf(stderr, "Mesa x86-optimized: NO\n");
1803#endif
davem69e4f84b42001-06-05 03:58:20 +00001804#if defined(USE_SPARC_ASM)
1805 fprintf(stderr, "Mesa sparc-optimized: YES\n");
1806#else
1807 fprintf(stderr, "Mesa sparc-optimized: NO\n");
1808#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001809}
1810
1811
Brian Paul00037781999-12-17 14:52:35 +00001812/*
1813 * Bind the given context to the given draw-buffer and read-buffer
1814 * and make it the current context for this thread.
1815 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001816void
1817_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1818 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001819{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001820 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001821 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001822
Brian Paulbe3602d2001-02-28 00:27:48 +00001823 /* Check that the context's and framebuffer's visuals are compatible.
1824 * We could do a lot more checking here but this'll catch obvious
1825 * problems.
1826 */
1827 if (newCtx && drawBuffer && readBuffer) {
1828 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1829 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1830 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1831 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1832 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1833 return; /* incompatible */
1834 }
1835 }
1836
Brian Paul00037781999-12-17 14:52:35 +00001837 /* We call this function periodically (just here for now) in
1838 * order to detect when multithreading has begun.
1839 */
1840 _glapi_check_multithread();
1841
Brian Paulf9b97d92000-01-28 20:17:42 +00001842 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001843 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001844
1845
1846 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001847 _glapi_set_dispatch(NULL); /* none current */
1848 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001849 else {
1850 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001851
Keith Whitwell23caf202000-11-16 21:05:34 +00001852 if (drawBuffer && readBuffer) {
1853 /* TODO: check if newCtx and buffer's visual match??? */
1854 newCtx->DrawBuffer = drawBuffer;
1855 newCtx->ReadBuffer = readBuffer;
1856 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001857 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001858 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001859
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001860 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001861 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1862
1863 /* We can use this to help debug user's problems. Tell them to set
1864 * the MESA_INFO env variable before running their app. Then the
1865 * first time each context is made current we'll print some useful
1866 * information.
1867 */
1868 if (newCtx->FirstTimeCurrent) {
1869 if (getenv("MESA_INFO")) {
1870 print_info();
1871 }
1872 newCtx->FirstTimeCurrent = GL_FALSE;
1873 }
Brian Paul00037781999-12-17 14:52:35 +00001874 }
1875}
1876
1877
1878
1879/*
1880 * Return current context handle for the calling thread.
1881 * This isn't the fastest way to get the current context.
1882 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1883 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001884GLcontext *
1885_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001886{
Brian Paulf9b97d92000-01-28 20:17:42 +00001887 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001888}
1889
1890
1891
1892/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001893 * This should be called by device drivers just before they do a
1894 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001895 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001896void
1897_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001898{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001899 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001900}
1901
1902
Brian Paul00037781999-12-17 14:52:35 +00001903
Brian Paulfbd8f211999-11-11 01:22:25 +00001904/*
1905 * Return pointer to this context's current API dispatch table.
1906 * It'll either be the immediate-mode execute dispatcher or the
1907 * display list compile dispatcher.
1908 */
1909struct _glapi_table *
1910_mesa_get_dispatch(GLcontext *ctx)
1911{
1912 return ctx->CurrentDispatch;
1913}
1914
1915
1916
jtgafb833d1999-08-19 00:55:39 +00001917/**********************************************************************/
1918/***** Miscellaneous functions *****/
1919/**********************************************************************/
1920
1921
1922/*
1923 * This function is called when the Mesa user has stumbled into a code
1924 * path which may not be implemented fully or correctly.
1925 */
Brian Paul08836342001-03-03 20:33:27 +00001926void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001927{
1928 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00001929#ifdef XF86DRI
1930 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
1931#else
1932 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
1933#endif
jtgafb833d1999-08-19 00:55:39 +00001934 (void) ctx;
1935}
1936
1937
1938
1939/*
1940 * This is called to inform the user that he or she has tried to do
1941 * something illogical or if there's likely a bug in their program
1942 * (like enabled depth testing without a depth buffer).
1943 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001944void
1945_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001946{
Brian Paulb1394fa2000-09-26 20:53:53 +00001947 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001948}
1949
1950
1951
Brian Paulfa9df402000-02-02 19:16:46 +00001952/*
1953 * Compile an error into current display list.
1954 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001955void
1956_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001957{
1958 if (ctx->CompileFlag)
Brian Paul08836342001-03-03 20:33:27 +00001959 _mesa_save_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001960
1961 if (ctx->ExecuteFlag)
Brian Paul08836342001-03-03 20:33:27 +00001962 _mesa_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001963}
1964
1965
Brian Paulfa9df402000-02-02 19:16:46 +00001966
jtgafb833d1999-08-19 00:55:39 +00001967/*
1968 * This is Mesa's error handler. Normally, all that's done is the updating
1969 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1970 * environment variable "MESA_DEBUG" is defined then a real error message
1971 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001972 * Input: ctx - the GL context
1973 * error - the error value
1974 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001975 */
Brian Paul7eb06032000-07-14 04:13:40 +00001976void
Brian Paul08836342001-03-03 20:33:27 +00001977_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001978{
Brian Paul7eb06032000-07-14 04:13:40 +00001979 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001980 GLboolean debug;
1981
1982#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00001983 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00001984 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00001985 else
1986 debug = GL_TRUE;
1987#else
1988 if (debugEnv)
1989 debug = GL_TRUE;
1990 else
1991 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001992#endif
1993
1994 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00001995 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00001996 switch (error) {
1997 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00001998 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00001999 break;
2000 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002001 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002002 break;
2003 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002004 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002005 break;
2006 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002007 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002008 break;
2009 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002010 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002011 break;
2012 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002013 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002014 break;
2015 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002016 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002017 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002018 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002019 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002020 break;
jtgafb833d1999-08-19 00:55:39 +00002021 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002022 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002023 break;
2024 }
Brian Paul7eb06032000-07-14 04:13:40 +00002025 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002026 }
2027
Brian Paul7eb06032000-07-14 04:13:40 +00002028 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002029 ctx->ErrorValue = error;
2030 }
2031
2032 /* Call device driver's error handler, if any. This is used on the Mac. */
2033 if (ctx->Driver.Error) {
2034 (*ctx->Driver.Error)( ctx );
2035 }
2036}
2037
2038
2039
Brian Paulfa9df402000-02-02 19:16:46 +00002040void
2041_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002042{
Brian Paulfa9df402000-02-02 19:16:46 +00002043 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002044 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002045 if (ctx->Driver.Finish) {
2046 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002047 }
2048}
2049
2050
2051
Brian Paulfa9df402000-02-02 19:16:46 +00002052void
2053_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002054{
Brian Paulfa9df402000-02-02 19:16:46 +00002055 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002056 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002057 if (ctx->Driver.Flush) {
2058 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002059 }
jtgafb833d1999-08-19 00:55:39 +00002060}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002061
2062
2063
Keith Whitwellcab974c2000-12-26 05:09:27 +00002064const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002065 "GL_POINTS",
2066 "GL_LINES",
2067 "GL_LINE_LOOP",
2068 "GL_LINE_STRIP",
2069 "GL_TRIANGLES",
2070 "GL_TRIANGLE_STRIP",
2071 "GL_TRIANGLE_FAN",
2072 "GL_QUADS",
2073 "GL_QUAD_STRIP",
2074 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002075 "outside begin/end",
2076 "inside unkown primitive",
2077 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002078};