blob: 018e709d900fed283ae1ae88447d46e1476794df [file] [log] [blame]
Brian Pauleb6c6432000-09-28 22:44:30 +00001/* $Id: context.c,v 1.91 2000/09/28 22:44:30 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 Paul54287052000-01-17 20:00:15 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
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"
36#include "cva.h"
jtgafb833d1999-08-19 00:55:39 +000037#include "dlist.h"
38#include "eval.h"
39#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000040#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000041#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000042#include "get.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000043#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000044#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000045#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000046#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000047#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "macros.h"
49#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000050#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000051#include "mmath.h"
52#include "pb.h"
53#include "pipeline.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "shade.h"
55#include "simple_list.h"
jtgafb833d1999-08-19 00:55:39 +000056#include "stages.h"
Brian Paulfa9df402000-02-02 19:16:46 +000057#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000058#include "translate.h"
59#include "teximage.h"
60#include "texobj.h"
jtgafb833d1999-08-19 00:55:39 +000061#include "texture.h"
62#include "types.h"
63#include "varray.h"
64#include "vb.h"
jtgafb833d1999-08-19 00:55:39 +000065#include "vbrender.h"
66#include "vbxform.h"
Keith Whitwell38756791999-08-29 10:26:31 +000067#include "vertices.h"
jtgafb833d1999-08-19 00:55:39 +000068#include "xform.h"
jtgafb833d1999-08-19 00:55:39 +000069#endif
70
Brian Paul3b18a362000-09-26 15:27:20 +000071#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000072#include "Trace/tr_context.h"
73#include "Trace/tr_wrapper.h"
74#endif
75
jtgafb833d1999-08-19 00:55:39 +000076
Brian Paulb1394fa2000-09-26 20:53:53 +000077
78/**********************************************************************/
79/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
80/**********************************************************************/
81
82static GLboolean
83_mesa_DestroyContext(__GLcontext *gc)
84{
85 if (gc) {
86 _mesa_free_context_data(gc);
87 (*gc->imports.free)(gc, gc);
88 }
89 return GL_TRUE;
90}
91
92
93/* exported OpenGL SI interface */
94__GLcontext *
95__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
96{
97 GLcontext *ctx;
98
99 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
100 if (ctx == NULL) {
101 return NULL;
102 }
103 ctx->imports = *imports;
104
105 _mesa_initialize_visual(&ctx->Visual,
106 modes->rgbMode,
107 modes->doubleBufferMode,
108 modes->stereoMode,
109 modes->redBits,
110 modes->greenBits,
111 modes->blueBits,
112 modes->alphaBits,
113 modes->indexBits,
114 modes->depthBits,
115 modes->stencilBits,
116 modes->accumRedBits,
117 modes->accumGreenBits,
118 modes->accumBlueBits,
119 modes->accumAlphaBits,
120 0);
121
122 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->wscx, GL_FALSE);
123
124 ctx->exports.destroyContext = _mesa_DestroyContext;
125
126 return ctx;
127}
128
129
130/* exported OpenGL SI interface */
131void
132__glCoreNopDispatch(void)
133{
134#if 0
135 /* SI */
136 __gl_dispatch = __glNopDispatchState;
137#else
138 /* Mesa */
139 _glapi_set_dispatch(NULL);
140#endif
141}
142
143
jtgafb833d1999-08-19 00:55:39 +0000144/**********************************************************************/
145/***** Context and Thread management *****/
146/**********************************************************************/
147
148
Brian Paul00037781999-12-17 14:52:35 +0000149#if !defined(THREADS)
jtgafb833d1999-08-19 00:55:39 +0000150
Brian Paul5666c632000-01-18 17:36:16 +0000151struct immediate *_mesa_CurrentInput = NULL;
jtgafb833d1999-08-19 00:55:39 +0000152
Brian Paul00037781999-12-17 14:52:35 +0000153#endif
jtgafb833d1999-08-19 00:55:39 +0000154
155
jtgafb833d1999-08-19 00:55:39 +0000156/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000157/***** GL Visual allocation/destruction *****/
158/**********************************************************************/
159
160
161/*
162 * Allocate a new GLvisual object.
163 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000164 * dbFlag - double buffering?
165 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000166 * depthBits - requested bits per depth buffer value
167 * Any value in [0, 32] is acceptable but the actual
168 * depth type will be GLushort or GLuint as needed.
169 * stencilBits - requested minimum bits per stencil buffer value
170 * accumBits - requested minimum bits per accum buffer component
171 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
172 * red/green/blue/alphaBits - number of bits per color component
173 * in frame buffer for RGB(A) mode.
174 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000175 * Return: pointer to new GLvisual or NULL if requested parameters can't
176 * be met.
177 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000178GLvisual *
179_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000180 GLboolean dbFlag,
181 GLboolean stereoFlag,
182 GLint redBits,
183 GLint greenBits,
184 GLint blueBits,
185 GLint alphaBits,
186 GLint indexBits,
187 GLint depthBits,
188 GLint stencilBits,
189 GLint accumRedBits,
190 GLint accumGreenBits,
191 GLint accumBlueBits,
192 GLint accumAlphaBits,
193 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000194{
Brian Paul178a1c52000-04-22 01:05:00 +0000195 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
196 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000197 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000198 redBits, greenBits, blueBits, alphaBits,
199 indexBits, depthBits, stencilBits,
200 accumRedBits, accumGreenBits,
201 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000202 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000203 FREE(vis);
204 return NULL;
205 }
206 }
207 return vis;
208}
209
210
211/*
212 * Initialize the fields of the given GLvisual.
213 * Input: see _mesa_create_visual() above.
214 * Return: GL_TRUE = success
215 * GL_FALSE = failure.
216 */
217GLboolean
218_mesa_initialize_visual( GLvisual *vis,
219 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000220 GLboolean dbFlag,
221 GLboolean stereoFlag,
222 GLint redBits,
223 GLint greenBits,
224 GLint blueBits,
225 GLint alphaBits,
226 GLint indexBits,
227 GLint depthBits,
228 GLint stencilBits,
229 GLint accumRedBits,
230 GLint accumGreenBits,
231 GLint accumBlueBits,
232 GLint accumAlphaBits,
233 GLint numSamples )
234{
235 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000236
Brian Pauled30dfa2000-03-03 17:47:39 +0000237 /* This is to catch bad values from device drivers not updated for
238 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
239 * bad value now (a 1-bit depth buffer!?!).
240 */
241 assert(depthBits == 0 || depthBits > 1);
242
243 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000244 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000245 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000246 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000247 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000248 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000249 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000250 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000251 }
252 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000253 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000254 }
255 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000256 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000257 }
258 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000259 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000260 }
261
262 vis->RGBAflag = rgbFlag;
263 vis->DBflag = dbFlag;
264 vis->StereoFlag = stereoFlag;
265 vis->RedBits = redBits;
266 vis->GreenBits = greenBits;
267 vis->BlueBits = blueBits;
Brian Paule70c6232000-05-04 13:53:55 +0000268 vis->AlphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000269
Brian Paulb371e0d2000-03-31 01:05:51 +0000270 vis->IndexBits = indexBits;
271 vis->DepthBits = depthBits;
272 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
273 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
274 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
275 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
276 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000277
Brian Pauled30dfa2000-03-03 17:47:39 +0000278 if (depthBits == 0) {
279 /* Special case. Even if we don't have a depth buffer we need
280 * good values for DepthMax for Z vertex transformation purposes.
281 */
282 vis->DepthMax = 1;
283 vis->DepthMaxF = 1.0F;
284 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000285 else if (depthBits < 32) {
Brian Pauled30dfa2000-03-03 17:47:39 +0000286 vis->DepthMax = (1 << depthBits) - 1;
287 vis->DepthMaxF = (GLfloat) vis->DepthMax;
288 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000289 else {
290 /* Special case since shift values greater than or equal to the
291 * number of bits in the left hand expression's type are
292 * undefined.
293 */
294 vis->DepthMax = 0xffffffff;
295 vis->DepthMaxF = (GLfloat) vis->DepthMax;
296 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000297
Brian Paul178a1c52000-04-22 01:05:00 +0000298 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000299}
300
301
Brian Paulb371e0d2000-03-31 01:05:51 +0000302void
303_mesa_destroy_visual( GLvisual *vis )
304{
305 FREE(vis);
306}
307
308
Brian Paul4d053dd2000-01-14 04:45:47 +0000309/**********************************************************************/
310/***** GL Framebuffer allocation/destruction *****/
311/**********************************************************************/
312
313
314/*
315 * Create a new framebuffer. A GLframebuffer is a struct which
316 * encapsulates the depth, stencil and accum buffers and related
317 * parameters.
318 * Input: visual - a GLvisual pointer
319 * softwareDepth - create/use a software depth buffer?
320 * softwareStencil - create/use a software stencil buffer?
321 * softwareAccum - create/use a software accum buffer?
322 * softwareAlpha - create/use a software alpha buffer?
323
324 * Return: pointer to new GLframebuffer struct or NULL if error.
325 */
Brian Paul178a1c52000-04-22 01:05:00 +0000326GLframebuffer *
Brian Paulb1394fa2000-09-26 20:53:53 +0000327_mesa_create_framebuffer( GLvisual *visual,
328 GLboolean softwareDepth,
329 GLboolean softwareStencil,
330 GLboolean softwareAccum,
331 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000332{
Brian Paul178a1c52000-04-22 01:05:00 +0000333 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
334 assert(visual);
335 if (buffer) {
336 _mesa_initialize_framebuffer(buffer, visual,
337 softwareDepth, softwareStencil,
338 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000339 }
Brian Paul178a1c52000-04-22 01:05:00 +0000340 return buffer;
341}
342
343
344/*
345 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000346 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000347 */
348void
349_mesa_initialize_framebuffer( GLframebuffer *buffer,
350 GLvisual *visual,
351 GLboolean softwareDepth,
352 GLboolean softwareStencil,
353 GLboolean softwareAccum,
354 GLboolean softwareAlpha )
355{
356 assert(buffer);
357 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000358
359 /* sanity checks */
360 if (softwareDepth ) {
361 assert(visual->DepthBits > 0);
362 }
363 if (softwareStencil) {
364 assert(visual->StencilBits > 0);
365 }
366 if (softwareAccum) {
367 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000368 assert(visual->AccumRedBits > 0);
369 assert(visual->AccumGreenBits > 0);
370 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000371 }
372 if (softwareAlpha) {
373 assert(visual->RGBAflag);
374 assert(visual->AlphaBits > 0);
375 }
376
377 buffer->Visual = visual;
378 buffer->UseSoftwareDepthBuffer = softwareDepth;
379 buffer->UseSoftwareStencilBuffer = softwareStencil;
380 buffer->UseSoftwareAccumBuffer = softwareAccum;
381 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000382}
383
384
Brian Paul4d053dd2000-01-14 04:45:47 +0000385/*
386 * Free a framebuffer struct and its buffers.
387 */
Brian Paul178a1c52000-04-22 01:05:00 +0000388void
Brian Paulb1394fa2000-09-26 20:53:53 +0000389_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000390{
391 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000392 if (buffer->DepthBuffer) {
393 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000394 }
395 if (buffer->Accum) {
396 FREE( buffer->Accum );
397 }
398 if (buffer->Stencil) {
399 FREE( buffer->Stencil );
400 }
401 if (buffer->FrontLeftAlpha) {
402 FREE( buffer->FrontLeftAlpha );
403 }
404 if (buffer->BackLeftAlpha) {
405 FREE( buffer->BackLeftAlpha );
406 }
407 if (buffer->FrontRightAlpha) {
408 FREE( buffer->FrontRightAlpha );
409 }
410 if (buffer->BackRightAlpha) {
411 FREE( buffer->BackRightAlpha );
412 }
413 FREE(buffer);
414 }
415}
416
417
418
419/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000420/***** Context allocation, initialization, destroying *****/
421/**********************************************************************/
422
423
Brian Paul9560f052000-01-31 23:11:39 +0000424_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
425
426
jtgafb833d1999-08-19 00:55:39 +0000427/*
428 * This function just calls all the various one-time-init functions in Mesa.
429 */
Brian Paul178a1c52000-04-22 01:05:00 +0000430static void
431one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000432{
433 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000434 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000435 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000436 /* do some implementation tests */
437 assert( sizeof(GLbyte) == 1 );
438 assert( sizeof(GLshort) >= 2 );
439 assert( sizeof(GLint) >= 4 );
440 assert( sizeof(GLubyte) == 1 );
441 assert( sizeof(GLushort) >= 2 );
442 assert( sizeof(GLuint) >= 4 );
443
jtgafb833d1999-08-19 00:55:39 +0000444 gl_init_clip();
445 gl_init_eval();
Brian Paul5829f0c2000-02-02 22:21:39 +0000446 _mesa_init_fog();
Brian Paul780c4e02000-03-22 23:20:12 +0000447 _mesa_init_math();
jtgafb833d1999-08-19 00:55:39 +0000448 gl_init_lists();
449 gl_init_shade();
450 gl_init_texture();
451 gl_init_transformation();
452 gl_init_translate();
453 gl_init_vbrender();
454 gl_init_vbxform();
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{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000480 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000481 struct gl_shared_state *ss;
482 GLboolean outOfMemory;
483
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000484 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000485 if (!ss)
486 return NULL;
487
Brian Paule4b684c2000-09-12 21:07:40 +0000488 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000489
Brian Paule4b684c2000-09-12 21:07:40 +0000490 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000491 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000492
493 /* Default Texture objects */
494 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000495 for (d = 1 ; d <= 3 ; d++) {
496 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
497 if (!ss->DefaultD[d]) {
498 outOfMemory = GL_TRUE;
499 break;
jtgafb833d1999-08-19 00:55:39 +0000500 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000501 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000502 }
503
Brian Paul413d6a22000-05-26 14:44:59 +0000504 ss->DefaultCubeMap = gl_alloc_texture_object(ss, 0, 6);
505 if (!ss->DefaultCubeMap) {
506 outOfMemory = GL_TRUE;
507 }
508 else {
509 ss->DefaultCubeMap->RefCount++;
510 }
511
jtgafb833d1999-08-19 00:55:39 +0000512 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
513 /* Ran out of memory at some point. Free everything and return NULL */
514 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000515 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000516 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000517 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000518 if (ss->DefaultD[1])
519 gl_free_texture_object(ss, ss->DefaultD[1]);
520 if (ss->DefaultD[2])
521 gl_free_texture_object(ss, ss->DefaultD[2]);
522 if (ss->DefaultD[3])
523 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paul413d6a22000-05-26 14:44:59 +0000524 if (ss->DefaultCubeMap)
525 gl_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000526 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000527 return NULL;
528 }
529 else {
530 return ss;
531 }
532}
533
534
535/*
536 * Deallocate a shared state context and all children structures.
537 */
Brian Paul178a1c52000-04-22 01:05:00 +0000538static void
539free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000540{
541 /* Free display lists */
542 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000543 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000544 if (list) {
545 gl_destroy_list(ctx, list);
546 }
547 else {
548 break;
549 }
550 }
Brian Paulbb797902000-01-24 16:19:54 +0000551 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000552
553 /* Free texture objects */
554 while (ss->TexObjectList)
555 {
556 if (ctx->Driver.DeleteTexture)
557 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
558 /* this function removes from linked list too! */
559 gl_free_texture_object(ss, ss->TexObjectList);
560 }
Brian Paulbb797902000-01-24 16:19:54 +0000561 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000562
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000563 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000564}
565
566
567
jtgafb833d1999-08-19 00:55:39 +0000568/*
569 * Initialize the nth light. Note that the defaults for light 0 are
570 * different than the other lights.
571 */
Brian Paul178a1c52000-04-22 01:05:00 +0000572static void
573init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000574{
575 make_empty_list( l );
576
577 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
578 if (n==0) {
579 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
580 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
581 }
582 else {
583 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
584 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
585 }
586 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
587 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
588 l->SpotExponent = 0.0;
589 gl_compute_spot_exp_table( l );
590 l->SpotCutoff = 180.0;
591 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
592 l->ConstantAttenuation = 1.0;
593 l->LinearAttenuation = 0.0;
594 l->QuadraticAttenuation = 0.0;
595 l->Enabled = GL_FALSE;
596}
597
598
599
Brian Paul178a1c52000-04-22 01:05:00 +0000600static void
601init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000602{
603 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
604 lm->LocalViewer = GL_FALSE;
605 lm->TwoSide = GL_FALSE;
606 lm->ColorControl = GL_SINGLE_COLOR;
607}
608
609
Brian Paul178a1c52000-04-22 01:05:00 +0000610static void
611init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000612{
613 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
614 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
615 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
616 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
617 m->Shininess = 0.0;
618 m->AmbientIndex = 0;
619 m->DiffuseIndex = 1;
620 m->SpecularIndex = 1;
621}
622
623
624
Brian Paul178a1c52000-04-22 01:05:00 +0000625static void
626init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000627{
628 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
629
630 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000631 texUnit->CombineModeRGB = GL_MODULATE;
632 texUnit->CombineModeA = GL_MODULATE;
633 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
634 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
635 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
636 texUnit->CombineSourceA[0] = GL_TEXTURE;
637 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
638 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
639 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
640 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
641 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
642 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
643 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
644 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
645 texUnit->CombineScaleShiftRGB = 0;
646 texUnit->CombineScaleShiftA = 0;
647
jtgafb833d1999-08-19 00:55:39 +0000648 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
649 texUnit->TexGenEnabled = 0;
650 texUnit->GenModeS = GL_EYE_LINEAR;
651 texUnit->GenModeT = GL_EYE_LINEAR;
652 texUnit->GenModeR = GL_EYE_LINEAR;
653 texUnit->GenModeQ = GL_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000654 texUnit->GenBitS = TEXGEN_EYE_LINEAR;
655 texUnit->GenBitT = TEXGEN_EYE_LINEAR;
656 texUnit->GenBitR = TEXGEN_EYE_LINEAR;
657 texUnit->GenBitQ = TEXGEN_EYE_LINEAR;
658
jtgafb833d1999-08-19 00:55:39 +0000659 /* Yes, these plane coefficients are correct! */
660 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
661 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
662 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
664 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
665 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
666 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
667 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
668
Brian Paul6e6d4c61999-10-09 20:17:07 +0000669 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
670 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
671 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
Brian Paul413d6a22000-05-26 14:44:59 +0000672 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000673}
674
675
Brian Paul178a1c52000-04-22 01:05:00 +0000676static void
677init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000678{
679 struct gl_client_array *cl;
680 GLuint i;
681
682 cl = &ctx->Fallback.Normal;
683 cl->Size = 3;
684 cl->Type = GL_FLOAT;
685 cl->Stride = 0;
686 cl->StrideB = 0;
687 cl->Ptr = (void *) ctx->Current.Normal;
688 cl->Enabled = 1;
689
690 cl = &ctx->Fallback.Color;
691 cl->Size = 4;
692 cl->Type = GL_UNSIGNED_BYTE;
693 cl->Stride = 0;
694 cl->StrideB = 0;
695 cl->Ptr = (void *) ctx->Current.ByteColor;
696 cl->Enabled = 1;
697
698 cl = &ctx->Fallback.Index;
699 cl->Size = 1;
700 cl->Type = GL_UNSIGNED_INT;
701 cl->Stride = 0;
702 cl->StrideB = 0;
703 cl->Ptr = (void *) &ctx->Current.Index;
704 cl->Enabled = 1;
705
706 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
707 cl = &ctx->Fallback.TexCoord[i];
708 cl->Size = 4;
709 cl->Type = GL_FLOAT;
710 cl->Stride = 0;
711 cl->StrideB = 0;
712 cl->Ptr = (void *) ctx->Current.Texcoord[i];
713 cl->Enabled = 1;
714 }
715
716 cl = &ctx->Fallback.EdgeFlag;
717 cl->Size = 1;
718 cl->Type = GL_UNSIGNED_BYTE;
719 cl->Stride = 0;
720 cl->StrideB = 0;
721 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
722 cl->Enabled = 1;
723}
724
Brian Paul4d053dd2000-01-14 04:45:47 +0000725
jtgafb833d1999-08-19 00:55:39 +0000726/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000727static void
728init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000729{
730 map->Order = 1;
731 map->u1 = 0.0;
732 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000733 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000734 if (map->Points) {
735 GLint i;
736 for (i=0;i<n;i++)
737 map->Points[i] = initial[i];
738 }
jtgafb833d1999-08-19 00:55:39 +0000739}
740
741
742/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000743static void
744init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000745{
746 map->Uorder = 1;
747 map->Vorder = 1;
748 map->u1 = 0.0;
749 map->u2 = 1.0;
750 map->v1 = 0.0;
751 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000752 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000753 if (map->Points) {
754 GLint i;
755 for (i=0;i<n;i++)
756 map->Points[i] = initial[i];
757 }
jtgafb833d1999-08-19 00:55:39 +0000758}
759
760
jtgafb833d1999-08-19 00:55:39 +0000761/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000762 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000763 */
Brian Paul178a1c52000-04-22 01:05:00 +0000764static void
765init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000766{
767 GLuint i, j;
768
Brian Paul4d053dd2000-01-14 04:45:47 +0000769 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000770
Brian Paul539cce52000-02-03 19:40:07 +0000771 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000772 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
773 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000774 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000775 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
776 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000777 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
778 ctx->Const.MinPointSize = MIN_POINT_SIZE;
779 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
780 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
781 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
782 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
783 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
784 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
785 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
786 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
787 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
788 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000789 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000790 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
791 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000792 ctx->Const.NumCompressedTextureFormats = 0;
jtgafb833d1999-08-19 00:55:39 +0000793
Brian Paul4d053dd2000-01-14 04:45:47 +0000794 /* Modelview matrix */
795 gl_matrix_ctr( &ctx->ModelView );
796 gl_matrix_alloc_inv( &ctx->ModelView );
797
798 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000799 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000800 gl_matrix_ctr( &ctx->ModelViewStack[i] );
801 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
802 }
803
804 /* Projection matrix - need inv for user clipping in clip space*/
805 gl_matrix_ctr( &ctx->ProjectionMatrix );
806 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
807
808 gl_matrix_ctr( &ctx->ModelProjectMatrix );
809 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
810 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
811
812 ctx->ProjectionStackDepth = 0;
813 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
814 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
815
Brian Paul7fc29c52000-03-06 17:03:03 +0000816 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000817 gl_matrix_ctr( &ctx->ProjectionStack[i] );
818 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
819 }
820
821 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000822 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000823 gl_matrix_ctr( &ctx->TextureMatrix[i] );
824 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000825 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Brian Paul904ecb22000-06-27 23:38:45 +0000826 gl_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000827 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000828 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000829 }
jtgafb833d1999-08-19 00:55:39 +0000830
Brian Paul250069d2000-04-08 18:57:45 +0000831 /* Color matrix */
832 gl_matrix_ctr(&ctx->ColorMatrix);
833 ctx->ColorStackDepth = 0;
834 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
835 gl_matrix_ctr(&ctx->ColorStack[j]);
836 }
837
Brian Paul4d053dd2000-01-14 04:45:47 +0000838 /* Accumulate buffer group */
839 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000840
Brian Paul4d053dd2000-01-14 04:45:47 +0000841 /* Color buffer group */
842 ctx->Color.IndexMask = 0xffffffff;
843 ctx->Color.ColorMask[0] = 0xff;
844 ctx->Color.ColorMask[1] = 0xff;
845 ctx->Color.ColorMask[2] = 0xff;
846 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000847 ctx->Color.ClearIndex = 0;
848 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
849 ctx->Color.DrawBuffer = GL_FRONT;
850 ctx->Color.AlphaEnabled = GL_FALSE;
851 ctx->Color.AlphaFunc = GL_ALWAYS;
852 ctx->Color.AlphaRef = 0;
853 ctx->Color.BlendEnabled = GL_FALSE;
854 ctx->Color.BlendSrcRGB = GL_ONE;
855 ctx->Color.BlendDstRGB = GL_ZERO;
856 ctx->Color.BlendSrcA = GL_ONE;
857 ctx->Color.BlendDstA = GL_ZERO;
858 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
859 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
860 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
861 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
862 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000863 ctx->Color.LogicOp = GL_COPY;
864 ctx->Color.DitherFlag = GL_TRUE;
865 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000866
Brian Paul4d053dd2000-01-14 04:45:47 +0000867 /* Current group */
868 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
869 ctx->Current.Index = 1;
870 for (i=0; i<MAX_TEXTURE_UNITS; i++)
871 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
872 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
873 ctx->Current.RasterDistance = 0.0;
874 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
875 ctx->Current.RasterIndex = 1;
876 for (i=0; i<MAX_TEXTURE_UNITS; i++)
877 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
878 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
879 ctx->Current.RasterPosValid = GL_TRUE;
880 ctx->Current.EdgeFlag = GL_TRUE;
881 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
882 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
jtgafb833d1999-08-19 00:55:39 +0000883
Brian Paul4d053dd2000-01-14 04:45:47 +0000884 ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
885 VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
jtgafb833d1999-08-19 00:55:39 +0000886
Brian Paul4d053dd2000-01-14 04:45:47 +0000887 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000888
Brian Paul4d053dd2000-01-14 04:45:47 +0000889 /* Depth buffer group */
890 ctx->Depth.Test = GL_FALSE;
891 ctx->Depth.Clear = 1.0;
892 ctx->Depth.Func = GL_LESS;
893 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000894 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000895
Brian Paul4d053dd2000-01-14 04:45:47 +0000896 /* Evaluators group */
897 ctx->Eval.Map1Color4 = GL_FALSE;
898 ctx->Eval.Map1Index = GL_FALSE;
899 ctx->Eval.Map1Normal = GL_FALSE;
900 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
901 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
902 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
903 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
904 ctx->Eval.Map1Vertex3 = GL_FALSE;
905 ctx->Eval.Map1Vertex4 = GL_FALSE;
906 ctx->Eval.Map2Color4 = GL_FALSE;
907 ctx->Eval.Map2Index = GL_FALSE;
908 ctx->Eval.Map2Normal = GL_FALSE;
909 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
910 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
911 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
912 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
913 ctx->Eval.Map2Vertex3 = GL_FALSE;
914 ctx->Eval.Map2Vertex4 = GL_FALSE;
915 ctx->Eval.AutoNormal = GL_FALSE;
916 ctx->Eval.MapGrid1un = 1;
917 ctx->Eval.MapGrid1u1 = 0.0;
918 ctx->Eval.MapGrid1u2 = 1.0;
919 ctx->Eval.MapGrid2un = 1;
920 ctx->Eval.MapGrid2vn = 1;
921 ctx->Eval.MapGrid2u1 = 0.0;
922 ctx->Eval.MapGrid2u2 = 1.0;
923 ctx->Eval.MapGrid2v1 = 0.0;
924 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000925
Brian Paul4d053dd2000-01-14 04:45:47 +0000926 /* Evaluator data */
927 {
928 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
929 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
930 static GLfloat index[1] = { 1.0 };
931 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
932 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000933
Brian Paul4d053dd2000-01-14 04:45:47 +0000934 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
935 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
936 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
937 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
938 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
939 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
940 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
941 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
942 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000943
Brian Paul4d053dd2000-01-14 04:45:47 +0000944 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
945 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
946 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
947 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
948 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
949 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
950 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
951 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
952 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
953 }
jtgafb833d1999-08-19 00:55:39 +0000954
Brian Paul4d053dd2000-01-14 04:45:47 +0000955 /* Fog group */
956 ctx->Fog.Enabled = GL_FALSE;
957 ctx->Fog.Mode = GL_EXP;
958 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
959 ctx->Fog.Index = 0.0;
960 ctx->Fog.Density = 1.0;
961 ctx->Fog.Start = 0.0;
962 ctx->Fog.End = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000963
Brian Paul4d053dd2000-01-14 04:45:47 +0000964 /* Hint group */
965 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
966 ctx->Hint.PointSmooth = GL_DONT_CARE;
967 ctx->Hint.LineSmooth = GL_DONT_CARE;
968 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
969 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000970 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000971 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000972 ctx->Hint.AllowDrawMem = GL_TRUE;
973 ctx->Hint.StrictLighting = GL_TRUE;
Brian Paul1207bf02000-05-23 20:10:49 +0000974 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
975 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000976
Brian Paul0771d152000-04-07 00:19:41 +0000977 /* Histogram group */
978 ctx->Histogram.Width = 0;
979 ctx->Histogram.Format = GL_RGBA;
980 ctx->Histogram.Sink = GL_FALSE;
981 ctx->Histogram.RedSize = 0xffffffff;
982 ctx->Histogram.GreenSize = 0xffffffff;
983 ctx->Histogram.BlueSize = 0xffffffff;
984 ctx->Histogram.AlphaSize = 0xffffffff;
985 ctx->Histogram.LuminanceSize = 0xffffffff;
986 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
987 ctx->Histogram.Count[i][0] = 0;
988 ctx->Histogram.Count[i][1] = 0;
989 ctx->Histogram.Count[i][2] = 0;
990 ctx->Histogram.Count[i][3] = 0;
991 }
992
993 /* Min/Max group */
994 ctx->MinMax.Format = GL_RGBA;
995 ctx->MinMax.Sink = GL_FALSE;
996 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
997 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
998 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
999 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
1000
Brian Paul4d053dd2000-01-14 04:45:47 +00001001 /* Pipeline */
1002 gl_pipeline_init( ctx );
1003 gl_cva_init( ctx );
jtgafb833d1999-08-19 00:55:39 +00001004
Brian Paul4d053dd2000-01-14 04:45:47 +00001005 /* Extensions */
1006 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +00001007
Brian Paul4d053dd2000-01-14 04:45:47 +00001008 ctx->AllowVertexCull = CLIP_CULLED_BIT;
jtgafb833d1999-08-19 00:55:39 +00001009
Brian Paul4d053dd2000-01-14 04:45:47 +00001010 /* Lighting group */
1011 for (i=0;i<MAX_LIGHTS;i++) {
1012 init_light( &ctx->Light.Light[i], i );
1013 }
1014 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001015
Brian Paul4d053dd2000-01-14 04:45:47 +00001016 init_lightmodel( &ctx->Light.Model );
1017 init_material( &ctx->Light.Material[0] );
1018 init_material( &ctx->Light.Material[1] );
1019 ctx->Light.ShadeModel = GL_SMOOTH;
1020 ctx->Light.Enabled = GL_FALSE;
1021 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1022 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
1023 ctx->Light.ColorMaterialBitmask
1024 = gl_material_bitmask( ctx,
1025 GL_FRONT_AND_BACK,
1026 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001027
Brian Paul4d053dd2000-01-14 04:45:47 +00001028 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001029
Brian Paul4d053dd2000-01-14 04:45:47 +00001030 /* Lighting miscellaneous */
1031 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1032 make_empty_list( ctx->ShineTabList );
1033 for (i = 0 ; i < 10 ; i++) {
1034 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1035 s->shininess = -1;
1036 s->refcount = 0;
1037 insert_at_tail( ctx->ShineTabList, s );
1038 }
1039 for (i = 0 ; i < 4 ; i++) {
1040 ctx->ShineTable[i] = ctx->ShineTabList->prev;
1041 ctx->ShineTable[i]->refcount++;
1042 }
jtgafb833d1999-08-19 00:55:39 +00001043
Brian Paul77d61af2000-06-28 04:20:21 +00001044 gl_compute_shine_table( ctx, 0, ctx->Light.Material[0].Shininess );
1045 gl_compute_shine_table( ctx, 2, ctx->Light.Material[0].Shininess * .5 );
1046 gl_compute_shine_table( ctx, 1, ctx->Light.Material[1].Shininess );
1047 gl_compute_shine_table( ctx, 3, ctx->Light.Material[1].Shininess * .5 );
1048
jtgafb833d1999-08-19 00:55:39 +00001049
Brian Paul4d053dd2000-01-14 04:45:47 +00001050 /* Line group */
1051 ctx->Line.SmoothFlag = GL_FALSE;
1052 ctx->Line.StippleFlag = GL_FALSE;
1053 ctx->Line.Width = 1.0;
1054 ctx->Line.StipplePattern = 0xffff;
1055 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001056
Brian Paul4d053dd2000-01-14 04:45:47 +00001057 /* Display List group */
1058 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001059
Brian Paul4d053dd2000-01-14 04:45:47 +00001060 /* Pixel group */
1061 ctx->Pixel.RedBias = 0.0;
1062 ctx->Pixel.RedScale = 1.0;
1063 ctx->Pixel.GreenBias = 0.0;
1064 ctx->Pixel.GreenScale = 1.0;
1065 ctx->Pixel.BlueBias = 0.0;
1066 ctx->Pixel.BlueScale = 1.0;
1067 ctx->Pixel.AlphaBias = 0.0;
1068 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001069 ctx->Pixel.DepthBias = 0.0;
1070 ctx->Pixel.DepthScale = 1.0;
1071 ctx->Pixel.IndexOffset = 0;
1072 ctx->Pixel.IndexShift = 0;
1073 ctx->Pixel.ZoomX = 1.0;
1074 ctx->Pixel.ZoomY = 1.0;
1075 ctx->Pixel.MapColorFlag = GL_FALSE;
1076 ctx->Pixel.MapStencilFlag = GL_FALSE;
1077 ctx->Pixel.MapStoSsize = 1;
1078 ctx->Pixel.MapItoIsize = 1;
1079 ctx->Pixel.MapItoRsize = 1;
1080 ctx->Pixel.MapItoGsize = 1;
1081 ctx->Pixel.MapItoBsize = 1;
1082 ctx->Pixel.MapItoAsize = 1;
1083 ctx->Pixel.MapRtoRsize = 1;
1084 ctx->Pixel.MapGtoGsize = 1;
1085 ctx->Pixel.MapBtoBsize = 1;
1086 ctx->Pixel.MapAtoAsize = 1;
1087 ctx->Pixel.MapStoS[0] = 0;
1088 ctx->Pixel.MapItoI[0] = 0;
1089 ctx->Pixel.MapItoR[0] = 0.0;
1090 ctx->Pixel.MapItoG[0] = 0.0;
1091 ctx->Pixel.MapItoB[0] = 0.0;
1092 ctx->Pixel.MapItoA[0] = 0.0;
1093 ctx->Pixel.MapItoR8[0] = 0;
1094 ctx->Pixel.MapItoG8[0] = 0;
1095 ctx->Pixel.MapItoB8[0] = 0;
1096 ctx->Pixel.MapItoA8[0] = 0;
1097 ctx->Pixel.MapRtoR[0] = 0.0;
1098 ctx->Pixel.MapGtoG[0] = 0.0;
1099 ctx->Pixel.MapBtoB[0] = 0.0;
1100 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001101 ctx->Pixel.HistogramEnabled = GL_FALSE;
1102 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1103 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1104 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1105 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001106 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1107 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1108 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1109 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001110 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1111 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1112 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1113 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001114 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1115 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1116 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001117 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1118 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1119 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1120 for (i = 0; i < 3; i++) {
1121 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1122 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1123 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1124 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1125 }
1126 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1127 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001128
Brian Paul4d053dd2000-01-14 04:45:47 +00001129 /* Point group */
1130 ctx->Point.SmoothFlag = GL_FALSE;
Brian Paula25f7e12000-06-27 04:29:22 +00001131 ctx->Point.UserSize = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001132 ctx->Point.Size = 1.0;
1133 ctx->Point.Params[0] = 1.0;
1134 ctx->Point.Params[1] = 0.0;
1135 ctx->Point.Params[2] = 0.0;
1136 ctx->Point.Attenuated = GL_FALSE;
1137 ctx->Point.MinSize = 0.0;
1138 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1139 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001140
Brian Paul4d053dd2000-01-14 04:45:47 +00001141 /* Polygon group */
1142 ctx->Polygon.CullFlag = GL_FALSE;
1143 ctx->Polygon.CullFaceMode = GL_BACK;
1144 ctx->Polygon.FrontFace = GL_CCW;
1145 ctx->Polygon.FrontBit = 0;
1146 ctx->Polygon.FrontMode = GL_FILL;
1147 ctx->Polygon.BackMode = GL_FILL;
1148 ctx->Polygon.Unfilled = GL_FALSE;
1149 ctx->Polygon.SmoothFlag = GL_FALSE;
1150 ctx->Polygon.StippleFlag = GL_FALSE;
1151 ctx->Polygon.OffsetFactor = 0.0F;
1152 ctx->Polygon.OffsetUnits = 0.0F;
1153 ctx->Polygon.OffsetPoint = GL_FALSE;
1154 ctx->Polygon.OffsetLine = GL_FALSE;
1155 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001156
Brian Paul4d053dd2000-01-14 04:45:47 +00001157 /* Polygon Stipple group */
1158 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001159
Brian Paul4d053dd2000-01-14 04:45:47 +00001160 /* Scissor group */
1161 ctx->Scissor.Enabled = GL_FALSE;
1162 ctx->Scissor.X = 0;
1163 ctx->Scissor.Y = 0;
1164 ctx->Scissor.Width = 0;
1165 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001166
Brian Paul4d053dd2000-01-14 04:45:47 +00001167 /* Stencil group */
1168 ctx->Stencil.Enabled = GL_FALSE;
1169 ctx->Stencil.Function = GL_ALWAYS;
1170 ctx->Stencil.FailFunc = GL_KEEP;
1171 ctx->Stencil.ZPassFunc = GL_KEEP;
1172 ctx->Stencil.ZFailFunc = GL_KEEP;
1173 ctx->Stencil.Ref = 0;
1174 ctx->Stencil.ValueMask = STENCIL_MAX;
1175 ctx->Stencil.Clear = 0;
1176 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001177
Brian Paul4d053dd2000-01-14 04:45:47 +00001178 /* Texture group */
1179 ctx->Texture.CurrentUnit = 0; /* multitexture */
1180 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Brian Paul23316032000-09-14 23:13:23 +00001181 ctx->Texture.ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001182 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1183 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001184 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001185 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001186
Brian Paul4d053dd2000-01-14 04:45:47 +00001187 /* Transformation group */
1188 ctx->Transform.MatrixMode = GL_MODELVIEW;
1189 ctx->Transform.Normalize = GL_FALSE;
1190 ctx->Transform.RescaleNormals = GL_FALSE;
1191 for (i=0;i<MAX_CLIP_PLANES;i++) {
1192 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1193 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1194 }
1195 ctx->Transform.AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001196
Brian Paul4d053dd2000-01-14 04:45:47 +00001197 /* Viewport group */
1198 ctx->Viewport.X = 0;
1199 ctx->Viewport.Y = 0;
1200 ctx->Viewport.Width = 0;
1201 ctx->Viewport.Height = 0;
1202 ctx->Viewport.Near = 0.0;
1203 ctx->Viewport.Far = 1.0;
1204 gl_matrix_ctr(&ctx->Viewport.WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001205
1206#define Sz 10
1207#define Tz 14
Brian Paulb1394fa2000-09-26 20:53:53 +00001208 ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual.DepthMaxF;
1209 ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual.DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001210#undef Sz
1211#undef Tz
1212
Brian Paul4d053dd2000-01-14 04:45:47 +00001213 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1214 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001215
Brian Paul4d053dd2000-01-14 04:45:47 +00001216 /* Vertex arrays */
1217 ctx->Array.Vertex.Size = 4;
1218 ctx->Array.Vertex.Type = GL_FLOAT;
1219 ctx->Array.Vertex.Stride = 0;
1220 ctx->Array.Vertex.StrideB = 0;
1221 ctx->Array.Vertex.Ptr = NULL;
1222 ctx->Array.Vertex.Enabled = GL_FALSE;
1223 ctx->Array.Normal.Type = GL_FLOAT;
1224 ctx->Array.Normal.Stride = 0;
1225 ctx->Array.Normal.StrideB = 0;
1226 ctx->Array.Normal.Ptr = NULL;
1227 ctx->Array.Normal.Enabled = GL_FALSE;
1228 ctx->Array.Color.Size = 4;
1229 ctx->Array.Color.Type = GL_FLOAT;
1230 ctx->Array.Color.Stride = 0;
1231 ctx->Array.Color.StrideB = 0;
1232 ctx->Array.Color.Ptr = NULL;
1233 ctx->Array.Color.Enabled = GL_FALSE;
1234 ctx->Array.Index.Type = GL_FLOAT;
1235 ctx->Array.Index.Stride = 0;
1236 ctx->Array.Index.StrideB = 0;
1237 ctx->Array.Index.Ptr = NULL;
1238 ctx->Array.Index.Enabled = GL_FALSE;
1239 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1240 ctx->Array.TexCoord[i].Size = 4;
1241 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1242 ctx->Array.TexCoord[i].Stride = 0;
1243 ctx->Array.TexCoord[i].StrideB = 0;
1244 ctx->Array.TexCoord[i].Ptr = NULL;
1245 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1246 }
1247 ctx->Array.TexCoordInterleaveFactor = 1;
1248 ctx->Array.EdgeFlag.Stride = 0;
1249 ctx->Array.EdgeFlag.StrideB = 0;
1250 ctx->Array.EdgeFlag.Ptr = NULL;
1251 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1252 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1253
1254 /* Pixel transfer */
1255 ctx->Pack.Alignment = 4;
1256 ctx->Pack.RowLength = 0;
1257 ctx->Pack.ImageHeight = 0;
1258 ctx->Pack.SkipPixels = 0;
1259 ctx->Pack.SkipRows = 0;
1260 ctx->Pack.SkipImages = 0;
1261 ctx->Pack.SwapBytes = GL_FALSE;
1262 ctx->Pack.LsbFirst = GL_FALSE;
1263 ctx->Unpack.Alignment = 4;
1264 ctx->Unpack.RowLength = 0;
1265 ctx->Unpack.ImageHeight = 0;
1266 ctx->Unpack.SkipPixels = 0;
1267 ctx->Unpack.SkipRows = 0;
1268 ctx->Unpack.SkipImages = 0;
1269 ctx->Unpack.SwapBytes = GL_FALSE;
1270 ctx->Unpack.LsbFirst = GL_FALSE;
1271
1272 /* Feedback */
1273 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1274 ctx->Feedback.Buffer = NULL;
1275 ctx->Feedback.BufferSize = 0;
1276 ctx->Feedback.Count = 0;
1277
1278 /* Selection/picking */
1279 ctx->Select.Buffer = NULL;
1280 ctx->Select.BufferSize = 0;
1281 ctx->Select.BufferCount = 0;
1282 ctx->Select.Hits = 0;
1283 ctx->Select.NameStackDepth = 0;
1284
1285 /* Optimized Accum buffer */
1286 ctx->IntegerAccumMode = GL_TRUE;
1287 ctx->IntegerAccumScaler = 0.0;
1288
1289 /* Renderer and client attribute stacks */
1290 ctx->AttribStackDepth = 0;
1291 ctx->ClientAttribStackDepth = 0;
1292
Brian Paul13811372000-04-12 00:27:37 +00001293 /* Display list */
1294 ctx->CallDepth = 0;
1295 ctx->ExecuteFlag = GL_TRUE;
1296 ctx->CompileFlag = GL_FALSE;
1297 ctx->CurrentListPtr = NULL;
1298 ctx->CurrentBlock = NULL;
1299 ctx->CurrentListNum = 0;
1300 ctx->CurrentPos = 0;
1301
1302 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001303 _mesa_init_colortable(&ctx->ColorTable);
1304 _mesa_init_colortable(&ctx->ProxyColorTable);
1305 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1306 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1307 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1308 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001309
Brian Paul4d053dd2000-01-14 04:45:47 +00001310 /* Miscellaneous */
1311 ctx->NewState = NEW_ALL;
1312 ctx->RenderMode = GL_RENDER;
1313 ctx->StippleCounter = 0;
1314 ctx->NeedNormals = GL_FALSE;
1315 ctx->DoViewportMapping = GL_TRUE;
Brian Paulfa4525e2000-08-21 14:22:24 +00001316 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001317
1318 ctx->NeedEyeCoords = GL_FALSE;
1319 ctx->NeedEyeNormals = GL_FALSE;
1320 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1321
Brian Paul4d053dd2000-01-14 04:45:47 +00001322 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1323
1324 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001325 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001326 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001327
1328 /* For debug/development only */
1329 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1330 ctx->FirstTimeCurrent = GL_TRUE;
1331
1332 /* Dither disable */
1333 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1334 if (ctx->NoDither) {
1335 if (getenv("MESA_DEBUG")) {
1336 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001337 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001338 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001339 }
1340}
1341
1342
1343
1344
jtgafb833d1999-08-19 00:55:39 +00001345/*
1346 * Allocate the proxy textures. If we run out of memory part way through
1347 * the allocations clean up and return GL_FALSE.
1348 * Return: GL_TRUE=success, GL_FALSE=failure
1349 */
Brian Paul178a1c52000-04-22 01:05:00 +00001350static GLboolean
1351alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001352{
1353 GLboolean out_of_memory;
1354 GLint i;
1355
1356 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1357 if (!ctx->Texture.Proxy1D) {
1358 return GL_FALSE;
1359 }
1360
1361 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1362 if (!ctx->Texture.Proxy2D) {
1363 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1364 return GL_FALSE;
1365 }
1366
1367 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1368 if (!ctx->Texture.Proxy3D) {
1369 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1370 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1371 return GL_FALSE;
1372 }
1373
1374 out_of_memory = GL_FALSE;
1375 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001376 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1377 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1378 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001379 if (!ctx->Texture.Proxy1D->Image[i]
1380 || !ctx->Texture.Proxy2D->Image[i]
1381 || !ctx->Texture.Proxy3D->Image[i]) {
1382 out_of_memory = GL_TRUE;
1383 }
1384 }
1385 if (out_of_memory) {
1386 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1387 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001388 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001389 }
1390 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001391 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001392 }
1393 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001394 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001395 }
1396 }
1397 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1398 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1399 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1400 return GL_FALSE;
1401 }
1402 else {
1403 return GL_TRUE;
1404 }
1405}
1406
1407
jtgafb833d1999-08-19 00:55:39 +00001408/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001409 * Initialize a GLcontext struct. This includes allocating all the
1410 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001411 */
Brian Paul178a1c52000-04-22 01:05:00 +00001412GLboolean
1413_mesa_initialize_context( GLcontext *ctx,
1414 GLvisual *visual,
1415 GLcontext *share_list,
1416 void *driver_ctx,
1417 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001418{
Brian Paul5fb84d22000-05-24 15:04:45 +00001419 GLuint dispatchSize;
1420
jtgafb833d1999-08-19 00:55:39 +00001421 (void) direct; /* not used */
1422
jtgafb833d1999-08-19 00:55:39 +00001423 /* misc one-time initializations */
1424 one_time_init();
1425
Brian Paulb1394fa2000-09-26 20:53:53 +00001426 /**
1427 ** OpenGL SI stuff
1428 **/
1429 if (!ctx->imports.malloc) {
1430 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1431 }
1432 /* exports are setup by the device driver */
1433
jtgafb833d1999-08-19 00:55:39 +00001434 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001435 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001436 ctx->DrawBuffer = NULL;
1437 ctx->ReadBuffer = NULL;
jtgafb833d1999-08-19 00:55:39 +00001438
1439 ctx->VB = gl_vb_create_for_immediate( ctx );
1440 if (!ctx->VB) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001441 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001442 }
1443 ctx->input = ctx->VB->IM;
1444
1445 ctx->PB = gl_alloc_pb();
1446 if (!ctx->PB) {
Brian Paul2d8db392000-06-27 22:10:00 +00001447 ALIGN_FREE( ctx->VB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001448 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001449 }
1450
1451 if (share_list) {
1452 /* share the group of display lists of another context */
1453 ctx->Shared = share_list->Shared;
1454 }
1455 else {
1456 /* allocate new group of display lists */
1457 ctx->Shared = alloc_shared_state();
1458 if (!ctx->Shared) {
Brian Paul2d8db392000-06-27 22:10:00 +00001459 ALIGN_FREE( ctx->VB );
1460 FREE( ctx->PB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001461 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001462 }
1463 }
Brian Paul9560f052000-01-31 23:11:39 +00001464 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001465 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001466 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001467
Brian Paul4d053dd2000-01-14 04:45:47 +00001468 init_attrib_groups( ctx );
1469
jtgafb833d1999-08-19 00:55:39 +00001470 gl_reset_vb( ctx->VB );
1471 gl_reset_input( ctx );
1472
jtgafb833d1999-08-19 00:55:39 +00001473 if (visual->DBflag) {
1474 ctx->Color.DrawBuffer = GL_BACK;
1475 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1476 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1477 ctx->Pixel.ReadBuffer = GL_BACK;
1478 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1479 }
1480 else {
1481 ctx->Color.DrawBuffer = GL_FRONT;
1482 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1483 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1484 ctx->Pixel.ReadBuffer = GL_FRONT;
1485 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1486 }
1487
jtgafb833d1999-08-19 00:55:39 +00001488 if (!alloc_proxy_textures(ctx)) {
1489 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001490 ALIGN_FREE( ctx->VB );
1491 FREE( ctx->PB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001492 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001493 }
jtgafb833d1999-08-19 00:55:39 +00001494
Brian Paulf59afc92000-05-23 23:23:00 +00001495 /* register the most recent extension functions with libGL */
1496 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1497 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1498 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1499 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1500 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1501 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1502 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1503 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1504
Brian Paul5fb84d22000-05-24 15:04:45 +00001505 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1506 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1507 * Mesa we do this to accomodate different versions of libGL and various
1508 * DRI drivers.
1509 */
1510 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1511 sizeof(struct _glapi_table) / sizeof(void *));
1512
Brian Paulfbd8f211999-11-11 01:22:25 +00001513 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001514 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1515 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001516 if (!ctx->Exec || !ctx->Save) {
1517 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001518 ALIGN_FREE( ctx->VB );
1519 FREE( ctx->PB );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001520 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001521 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001522 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001523 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1524 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001525 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001526
Brian Paul3b18a362000-09-26 15:27:20 +00001527#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +00001528 ctx->TraceCtx = CALLOC( sizeof(trace_context_t) );
1529#if 0
1530 /* Brian: do you want to have CreateContext fail here,
1531 or should we just trap in NewTrace (currently done)? */
1532 if (!(ctx->TraceCtx)) {
1533 free_shared_state(ctx, ctx->Shared);
1534 ALIGN_FREE( ctx->VB );
1535 FREE( ctx->PB );
1536 FREE( ctx->Exec );
1537 FREE( ctx->Save );
1538 return GL_FALSE;
1539 }
1540#endif
1541 trInitContext(ctx->TraceCtx);
1542
1543 ctx->TraceDispatch = (struct _glapi_table *)
1544 CALLOC(dispatchSize * sizeof(void*));
1545#if 0
1546 if (!(ctx->TraceCtx)) {
1547 free_shared_state(ctx, ctx->Shared);
1548 ALIGN_FREE( ctx->VB );
1549 FREE( ctx->PB );
1550 FREE( ctx->Exec );
1551 FREE( ctx->Save );
1552 FREE( ctx->TraceCtx );
1553 return GL_FALSE;
1554 }
1555#endif
1556 trInitDispatch(ctx->TraceDispatch);
1557#endif
1558
Brian Paul4d053dd2000-01-14 04:45:47 +00001559 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001560}
1561
jtgafb833d1999-08-19 00:55:39 +00001562
1563
1564/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001565 * Allocate and initialize a GLcontext structure.
1566 * Input: visual - a GLvisual pointer
1567 * sharelist - another context to share display lists with or NULL
1568 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001569 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001570 */
Brian Paul178a1c52000-04-22 01:05:00 +00001571GLcontext *
Brian Paulb1394fa2000-09-26 20:53:53 +00001572_mesa_create_context( GLvisual *visual,
1573 GLcontext *share_list,
1574 void *driver_ctx,
1575 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001576{
1577 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1578 if (!ctx) {
1579 return NULL;
1580 }
1581
Brian Paul178a1c52000-04-22 01:05:00 +00001582 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001583 return ctx;
1584 }
1585 else {
1586 FREE(ctx);
1587 return NULL;
1588 }
1589}
1590
1591
1592
1593/*
1594 * Free the data associated with the given context.
1595 * But don't free() the GLcontext struct itself!
1596 */
Brian Paul178a1c52000-04-22 01:05:00 +00001597void
Brian Paulb1394fa2000-09-26 20:53:53 +00001598_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001599{
Brian Paul4d053dd2000-01-14 04:45:47 +00001600 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001601 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001602
1603 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001604 if (ctx == _mesa_get_current_context()) {
1605 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001606 }
1607
Brian Paul4d053dd2000-01-14 04:45:47 +00001608 gl_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001609 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001610 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1611 }
1612 gl_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001613 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001614 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1615 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001616 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1617 gl_matrix_dtr( &ctx->TextureMatrix[i] );
1618 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1619 gl_matrix_dtr( &ctx->TextureStack[i][j] );
1620 }
1621 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001622
1623 FREE( ctx->PB );
1624
Brian Paul4bdcfe52000-04-17 17:57:04 +00001625 if (ctx->input != ctx->VB->IM)
Brian Paul4d053dd2000-01-14 04:45:47 +00001626 gl_immediate_free( ctx->input );
1627
1628 gl_vb_free( ctx->VB );
1629
Brian Paul9560f052000-01-31 23:11:39 +00001630 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001631 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001632 assert(ctx->Shared->RefCount >= 0);
1633 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1634 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001635 /* free shared state */
1636 free_shared_state( ctx, ctx->Shared );
1637 }
1638
1639 foreach_s( s, tmps, ctx->ShineTabList ) {
1640 FREE( s );
1641 }
1642 FREE( ctx->ShineTabList );
1643
1644 /* Free proxy texture objects */
1645 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1646 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1647 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1648
1649 /* Free evaluator data */
1650 if (ctx->EvalMap.Map1Vertex3.Points)
1651 FREE( ctx->EvalMap.Map1Vertex3.Points );
1652 if (ctx->EvalMap.Map1Vertex4.Points)
1653 FREE( ctx->EvalMap.Map1Vertex4.Points );
1654 if (ctx->EvalMap.Map1Index.Points)
1655 FREE( ctx->EvalMap.Map1Index.Points );
1656 if (ctx->EvalMap.Map1Color4.Points)
1657 FREE( ctx->EvalMap.Map1Color4.Points );
1658 if (ctx->EvalMap.Map1Normal.Points)
1659 FREE( ctx->EvalMap.Map1Normal.Points );
1660 if (ctx->EvalMap.Map1Texture1.Points)
1661 FREE( ctx->EvalMap.Map1Texture1.Points );
1662 if (ctx->EvalMap.Map1Texture2.Points)
1663 FREE( ctx->EvalMap.Map1Texture2.Points );
1664 if (ctx->EvalMap.Map1Texture3.Points)
1665 FREE( ctx->EvalMap.Map1Texture3.Points );
1666 if (ctx->EvalMap.Map1Texture4.Points)
1667 FREE( ctx->EvalMap.Map1Texture4.Points );
1668
1669 if (ctx->EvalMap.Map2Vertex3.Points)
1670 FREE( ctx->EvalMap.Map2Vertex3.Points );
1671 if (ctx->EvalMap.Map2Vertex4.Points)
1672 FREE( ctx->EvalMap.Map2Vertex4.Points );
1673 if (ctx->EvalMap.Map2Index.Points)
1674 FREE( ctx->EvalMap.Map2Index.Points );
1675 if (ctx->EvalMap.Map2Color4.Points)
1676 FREE( ctx->EvalMap.Map2Color4.Points );
1677 if (ctx->EvalMap.Map2Normal.Points)
1678 FREE( ctx->EvalMap.Map2Normal.Points );
1679 if (ctx->EvalMap.Map2Texture1.Points)
1680 FREE( ctx->EvalMap.Map2Texture1.Points );
1681 if (ctx->EvalMap.Map2Texture2.Points)
1682 FREE( ctx->EvalMap.Map2Texture2.Points );
1683 if (ctx->EvalMap.Map2Texture3.Points)
1684 FREE( ctx->EvalMap.Map2Texture3.Points );
1685 if (ctx->EvalMap.Map2Texture4.Points)
1686 FREE( ctx->EvalMap.Map2Texture4.Points );
1687
Brian Paul4bdcfe52000-04-17 17:57:04 +00001688 _mesa_free_colortable_data( &ctx->ColorTable );
1689 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1690 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1691 _mesa_free_colortable_data( &ctx->Texture.Palette );
1692
Brian Paul4d053dd2000-01-14 04:45:47 +00001693 /* Free cache of immediate buffers. */
1694 while (ctx->nr_im_queued-- > 0) {
1695 struct immediate * next = ctx->freed_im_queue->next;
Brian Paul2d8db392000-06-27 22:10:00 +00001696 ALIGN_FREE( ctx->freed_im_queue );
Brian Paul4d053dd2000-01-14 04:45:47 +00001697 ctx->freed_im_queue = next;
1698 }
1699 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001700
1701 FREE(ctx->Exec);
1702 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001703}
1704
1705
1706
1707/*
1708 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001709 */
Brian Paul178a1c52000-04-22 01:05:00 +00001710void
Brian Paulb1394fa2000-09-26 20:53:53 +00001711_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001712{
1713 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001714 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001715 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001716 }
1717}
1718
1719
1720
1721/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001722 * Called by the driver after both the context and driver are fully
1723 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001724 */
Brian Paul178a1c52000-04-22 01:05:00 +00001725void
Brian Paulb1394fa2000-09-26 20:53:53 +00001726_mesa_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001727{
Brian Paul00037781999-12-17 14:52:35 +00001728 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001729}
1730
1731
1732
1733/*
1734 * Copy attribute groups from one context to another.
1735 * Input: src - source context
1736 * dst - destination context
1737 * mask - bitwise OR of GL_*_BIT flags
1738 */
Brian Paul178a1c52000-04-22 01:05:00 +00001739void
Brian Paulb1394fa2000-09-26 20:53:53 +00001740_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001741{
1742 if (mask & GL_ACCUM_BUFFER_BIT) {
1743 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1744 }
1745 if (mask & GL_COLOR_BUFFER_BIT) {
1746 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1747 }
1748 if (mask & GL_CURRENT_BIT) {
1749 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1750 }
1751 if (mask & GL_DEPTH_BUFFER_BIT) {
1752 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1753 }
1754 if (mask & GL_ENABLE_BIT) {
1755 /* no op */
1756 }
1757 if (mask & GL_EVAL_BIT) {
1758 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1759 }
1760 if (mask & GL_FOG_BIT) {
1761 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1762 }
1763 if (mask & GL_HINT_BIT) {
1764 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1765 }
1766 if (mask & GL_LIGHTING_BIT) {
1767 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001768 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001769 }
1770 if (mask & GL_LINE_BIT) {
1771 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1772 }
1773 if (mask & GL_LIST_BIT) {
1774 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1775 }
1776 if (mask & GL_PIXEL_MODE_BIT) {
1777 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1778 }
1779 if (mask & GL_POINT_BIT) {
1780 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1781 }
1782 if (mask & GL_POLYGON_BIT) {
1783 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1784 }
1785 if (mask & GL_POLYGON_STIPPLE_BIT) {
1786 /* Use loop instead of MEMCPY due to problem with Portland Group's
1787 * C compiler. Reported by John Stone.
1788 */
1789 int i;
1790 for (i=0;i<32;i++) {
1791 dst->PolygonStipple[i] = src->PolygonStipple[i];
1792 }
1793 }
1794 if (mask & GL_SCISSOR_BIT) {
1795 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1796 }
1797 if (mask & GL_STENCIL_BUFFER_BIT) {
1798 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1799 }
1800 if (mask & GL_TEXTURE_BIT) {
1801 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1802 }
1803 if (mask & GL_TRANSFORM_BIT) {
1804 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1805 }
1806 if (mask & GL_VIEWPORT_BIT) {
1807 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1808 }
1809}
1810
1811
jtgafb833d1999-08-19 00:55:39 +00001812/*
Brian Paul00037781999-12-17 14:52:35 +00001813 * Set the current context, binding the given frame buffer to the context.
1814 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001815void
1816_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001817{
Brian Paulb1394fa2000-09-26 20:53:53 +00001818 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001819}
1820
1821
1822/*
1823 * Bind the given context to the given draw-buffer and read-buffer
1824 * and make it the current context for this thread.
1825 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001826void
1827_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1828 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001829{
1830#if 0
Brian Paulf9b97d92000-01-28 20:17:42 +00001831 GLcontext *oldCtx = gl_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001832
1833 /* Flush the old context
1834 */
1835 if (oldCtx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001836 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "_mesa_make_current");
Brian Paul00037781999-12-17 14:52:35 +00001837
1838 /* unbind frame buffers from context */
1839 if (oldCtx->DrawBuffer) {
1840 oldCtx->DrawBuffer = NULL;
1841 }
1842 if (oldCtx->ReadBuffer) {
1843 oldCtx->ReadBuffer = NULL;
1844 }
1845 }
1846#endif
1847
1848 /* We call this function periodically (just here for now) in
1849 * order to detect when multithreading has begun.
1850 */
1851 _glapi_check_multithread();
1852
Brian Paulf9b97d92000-01-28 20:17:42 +00001853 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001854 ASSERT(_mesa_get_current_context() == newCtx);
Brian Paul00037781999-12-17 14:52:35 +00001855 if (newCtx) {
1856 SET_IMMEDIATE(newCtx, newCtx->input);
1857 _glapi_set_dispatch(newCtx->CurrentDispatch);
1858 }
1859 else {
1860 _glapi_set_dispatch(NULL); /* none current */
1861 }
1862
Brian Paulb1394fa2000-09-26 20:53:53 +00001863 if (MESA_VERBOSE) fprintf(stderr, "_mesa_make_current()\n");
Brian Paul00037781999-12-17 14:52:35 +00001864
1865 if (newCtx && drawBuffer && readBuffer) {
1866 /* TODO: check if newCtx and buffer's visual match??? */
1867 newCtx->DrawBuffer = drawBuffer;
1868 newCtx->ReadBuffer = readBuffer;
1869 newCtx->NewState = NEW_ALL; /* just to be safe */
1870 gl_update_state( newCtx );
1871 }
1872
1873 /* We can use this to help debug user's problems. Tell the to set
1874 * the MESA_INFO env variable before running their app. Then the
1875 * first time each context is made current we'll print some useful
1876 * information.
1877 */
1878 if (newCtx && newCtx->FirstTimeCurrent) {
1879 if (getenv("MESA_INFO")) {
1880 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1881 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1882 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1883 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
Brian Paul09cb1481999-12-17 17:00:32 +00001884#if defined(THREADS)
1885 fprintf(stderr, "Mesa thread-safe: YES\n");
1886#else
1887 fprintf(stderr, "Mesa thread-safe: NO\n");
1888#endif
Brian Paul54287052000-01-17 20:00:15 +00001889#if defined(USE_X86_ASM)
1890 fprintf(stderr, "Mesa x86-optimized: YES\n");
1891#else
1892 fprintf(stderr, "Mesa x86-optimized: NO\n");
1893#endif
Brian Paul00037781999-12-17 14:52:35 +00001894 }
1895 newCtx->FirstTimeCurrent = GL_FALSE;
1896 }
1897}
1898
1899
1900
1901/*
1902 * Return current context handle for the calling thread.
1903 * This isn't the fastest way to get the current context.
1904 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1905 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001906GLcontext *
1907_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001908{
Brian Paulf9b97d92000-01-28 20:17:42 +00001909 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001910}
1911
1912
1913
1914/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001915 * This should be called by device drivers just before they do a
1916 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001917 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001918void
1919_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001920{
Brian Paulfbd8f211999-11-11 01:22:25 +00001921 FLUSH_VB( ctx, "swap buffers" );
jtgafb833d1999-08-19 00:55:39 +00001922}
1923
1924
Brian Paul00037781999-12-17 14:52:35 +00001925
Brian Paulfbd8f211999-11-11 01:22:25 +00001926/*
1927 * Return pointer to this context's current API dispatch table.
1928 * It'll either be the immediate-mode execute dispatcher or the
1929 * display list compile dispatcher.
1930 */
1931struct _glapi_table *
1932_mesa_get_dispatch(GLcontext *ctx)
1933{
1934 return ctx->CurrentDispatch;
1935}
1936
1937
1938
jtgafb833d1999-08-19 00:55:39 +00001939/**********************************************************************/
1940/***** Miscellaneous functions *****/
1941/**********************************************************************/
1942
1943
1944/*
1945 * This function is called when the Mesa user has stumbled into a code
1946 * path which may not be implemented fully or correctly.
1947 */
1948void gl_problem( const GLcontext *ctx, const char *s )
1949{
1950 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paul413d6a22000-05-26 14:44:59 +00001951 fprintf( stderr, "Report to Mesa bug database at www.mesa3d.org\n" );
jtgafb833d1999-08-19 00:55:39 +00001952 (void) ctx;
1953}
1954
1955
1956
1957/*
1958 * This is called to inform the user that he or she has tried to do
1959 * something illogical or if there's likely a bug in their program
1960 * (like enabled depth testing without a depth buffer).
1961 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001962void
1963_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001964{
Brian Paulb1394fa2000-09-26 20:53:53 +00001965 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001966}
1967
1968
1969
Brian Paulfa9df402000-02-02 19:16:46 +00001970/*
1971 * Compile an error into current display list.
1972 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001973void
1974_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001975{
1976 if (ctx->CompileFlag)
1977 gl_save_error( ctx, error, s );
1978
1979 if (ctx->ExecuteFlag)
1980 gl_error( ctx, error, s );
1981}
1982
1983
Brian Paulfa9df402000-02-02 19:16:46 +00001984
jtgafb833d1999-08-19 00:55:39 +00001985/*
1986 * This is Mesa's error handler. Normally, all that's done is the updating
1987 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1988 * environment variable "MESA_DEBUG" is defined then a real error message
1989 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001990 * Input: ctx - the GL context
1991 * error - the error value
1992 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001993 */
Brian Paul7eb06032000-07-14 04:13:40 +00001994void
1995gl_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001996{
Brian Paul7eb06032000-07-14 04:13:40 +00001997 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001998 GLboolean debug;
1999
2000#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002001 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002002 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002003 else
2004 debug = GL_TRUE;
2005#else
2006 if (debugEnv)
2007 debug = GL_TRUE;
2008 else
2009 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002010#endif
2011
2012 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002013 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002014 switch (error) {
2015 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002016 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002017 break;
2018 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002019 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002020 break;
2021 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002022 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002023 break;
2024 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002025 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002026 break;
2027 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002028 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002029 break;
2030 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002031 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002032 break;
2033 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002034 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002035 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002036 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002037 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002038 break;
jtgafb833d1999-08-19 00:55:39 +00002039 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002040 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002041 break;
2042 }
Brian Paul7eb06032000-07-14 04:13:40 +00002043 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002044 }
2045
Brian Paul7eb06032000-07-14 04:13:40 +00002046 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002047 ctx->ErrorValue = error;
2048 }
2049
2050 /* Call device driver's error handler, if any. This is used on the Mac. */
2051 if (ctx->Driver.Error) {
2052 (*ctx->Driver.Error)( ctx );
2053 }
2054}
2055
2056
2057
Brian Paulfa9df402000-02-02 19:16:46 +00002058void
2059_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002060{
Brian Paulfa9df402000-02-02 19:16:46 +00002061 GET_CURRENT_CONTEXT(ctx);
2062 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
2063 if (ctx->Driver.Finish) {
2064 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002065 }
2066}
2067
2068
2069
Brian Paulfa9df402000-02-02 19:16:46 +00002070void
2071_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002072{
Brian Paulfa9df402000-02-02 19:16:46 +00002073 GET_CURRENT_CONTEXT(ctx);
2074 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
2075 if (ctx->Driver.Flush) {
2076 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002077 }
jtgafb833d1999-08-19 00:55:39 +00002078}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002079
2080
2081
2082const char *_mesa_prim_name[GL_POLYGON+2] = {
2083 "GL_POINTS",
2084 "GL_LINES",
2085 "GL_LINE_LOOP",
2086 "GL_LINE_STRIP",
2087 "GL_TRIANGLES",
2088 "GL_TRIANGLE_STRIP",
2089 "GL_TRIANGLE_FAN",
2090 "GL_QUADS",
2091 "GL_QUAD_STRIP",
2092 "GL_POLYGON",
2093 "culled primitive"
2094};
2095
Brian Paul1c56fdc2000-09-17 21:56:07 +00002096
2097GLenum gl_reduce_prim[GL_POLYGON+1] = {
2098 GL_POINTS,
2099 GL_LINES,
2100 GL_LINES,
2101 GL_LINES,
2102 GL_TRIANGLES,
2103 GL_TRIANGLES,
2104 GL_TRIANGLES,
2105 GL_TRIANGLES,
2106 GL_TRIANGLES,
2107 GL_TRIANGLES,
2108};