blob: 5ea29d924dc9473b7f18fb94dbf181278e9d304f [file] [log] [blame]
Brian Paul48c6a6e2000-09-08 21:28:04 +00001/* $Id: context.c,v 1.84 2000/09/08 21:28:04 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paulfbd8f211999-11-11 01:22:25 +00005 * Version: 3.3
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paul54287052000-01-17 20:00:15 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "accum.h"
33#include "alphabuf.h"
jtgafb833d1999-08-19 00:55:39 +000034#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000035#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "context.h"
37#include "cva.h"
38#include "depth.h"
39#include "dlist.h"
40#include "eval.h"
41#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000042#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000044#include "get.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000045#include "glapi.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000046#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000047#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "hash.h"
49#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000050#include "macros.h"
51#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000052#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000053#include "mmath.h"
54#include "pb.h"
55#include "pipeline.h"
jtgafb833d1999-08-19 00:55:39 +000056#include "shade.h"
57#include "simple_list.h"
58#include "stencil.h"
59#include "stages.h"
Brian Paulfa9df402000-02-02 19:16:46 +000060#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000061#include "translate.h"
62#include "teximage.h"
63#include "texobj.h"
64#include "texstate.h"
65#include "texture.h"
66#include "types.h"
67#include "varray.h"
68#include "vb.h"
69#include "vbcull.h"
jtgafb833d1999-08-19 00:55:39 +000070#include "vbrender.h"
71#include "vbxform.h"
Keith Whitwell38756791999-08-29 10:26:31 +000072#include "vertices.h"
jtgafb833d1999-08-19 00:55:39 +000073#include "xform.h"
jtgafb833d1999-08-19 00:55:39 +000074#endif
75
76
Brian Paul45f36342000-09-05 20:28:06 +000077#if defined(TRACE)
78#include "Trace/tr_context.h"
79#include "Trace/tr_wrapper.h"
80#endif
81
jtgafb833d1999-08-19 00:55:39 +000082
83/**********************************************************************/
84/***** Context and Thread management *****/
85/**********************************************************************/
86
87
Brian Paul00037781999-12-17 14:52:35 +000088#if !defined(THREADS)
jtgafb833d1999-08-19 00:55:39 +000089
Brian Paul5666c632000-01-18 17:36:16 +000090struct immediate *_mesa_CurrentInput = NULL;
jtgafb833d1999-08-19 00:55:39 +000091
Brian Paul00037781999-12-17 14:52:35 +000092#endif
jtgafb833d1999-08-19 00:55:39 +000093
94
jtgafb833d1999-08-19 00:55:39 +000095/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +000096/***** GL Visual allocation/destruction *****/
97/**********************************************************************/
98
99
100/*
101 * Allocate a new GLvisual object.
102 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000103 * dbFlag - double buffering?
104 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000105 * depthBits - requested bits per depth buffer value
106 * Any value in [0, 32] is acceptable but the actual
107 * depth type will be GLushort or GLuint as needed.
108 * stencilBits - requested minimum bits per stencil buffer value
109 * accumBits - requested minimum bits per accum buffer component
110 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
111 * red/green/blue/alphaBits - number of bits per color component
112 * in frame buffer for RGB(A) mode.
113 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000114 * Return: pointer to new GLvisual or NULL if requested parameters can't
115 * be met.
116 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000117GLvisual *
118_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000119 GLboolean dbFlag,
120 GLboolean stereoFlag,
121 GLint redBits,
122 GLint greenBits,
123 GLint blueBits,
124 GLint alphaBits,
125 GLint indexBits,
126 GLint depthBits,
127 GLint stencilBits,
128 GLint accumRedBits,
129 GLint accumGreenBits,
130 GLint accumBlueBits,
131 GLint accumAlphaBits,
132 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000133{
Brian Paul178a1c52000-04-22 01:05:00 +0000134 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
135 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000136 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000137 redBits, greenBits, blueBits, alphaBits,
138 indexBits, depthBits, stencilBits,
139 accumRedBits, accumGreenBits,
140 accumBlueBits, accumAlphaBits,
141 numSamples )) {
142 FREE(vis);
143 return NULL;
144 }
145 }
146 return vis;
147}
148
149
150/*
151 * Initialize the fields of the given GLvisual.
152 * Input: see _mesa_create_visual() above.
153 * Return: GL_TRUE = success
154 * GL_FALSE = failure.
155 */
156GLboolean
157_mesa_initialize_visual( GLvisual *vis,
158 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000159 GLboolean dbFlag,
160 GLboolean stereoFlag,
161 GLint redBits,
162 GLint greenBits,
163 GLint blueBits,
164 GLint alphaBits,
165 GLint indexBits,
166 GLint depthBits,
167 GLint stencilBits,
168 GLint accumRedBits,
169 GLint accumGreenBits,
170 GLint accumBlueBits,
171 GLint accumAlphaBits,
172 GLint numSamples )
173{
174 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000175
Brian Pauled30dfa2000-03-03 17:47:39 +0000176 /* This is to catch bad values from device drivers not updated for
177 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
178 * bad value now (a 1-bit depth buffer!?!).
179 */
180 assert(depthBits == 0 || depthBits > 1);
181
182 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000183 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000184 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000185 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000186 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000187 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000188 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000189 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000190 }
191 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000192 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000193 }
194 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000195 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000196 }
197 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000198 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000199 }
200
201 vis->RGBAflag = rgbFlag;
202 vis->DBflag = dbFlag;
203 vis->StereoFlag = stereoFlag;
204 vis->RedBits = redBits;
205 vis->GreenBits = greenBits;
206 vis->BlueBits = blueBits;
Brian Paule70c6232000-05-04 13:53:55 +0000207 vis->AlphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000208
Brian Paulb371e0d2000-03-31 01:05:51 +0000209 vis->IndexBits = indexBits;
210 vis->DepthBits = depthBits;
211 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
212 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
213 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
214 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
215 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000216
Brian Pauled30dfa2000-03-03 17:47:39 +0000217 if (depthBits == 0) {
218 /* Special case. Even if we don't have a depth buffer we need
219 * good values for DepthMax for Z vertex transformation purposes.
220 */
221 vis->DepthMax = 1;
222 vis->DepthMaxF = 1.0F;
223 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000224 else if (depthBits < 32) {
Brian Pauled30dfa2000-03-03 17:47:39 +0000225 vis->DepthMax = (1 << depthBits) - 1;
226 vis->DepthMaxF = (GLfloat) vis->DepthMax;
227 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000228 else {
229 /* Special case since shift values greater than or equal to the
230 * number of bits in the left hand expression's type are
231 * undefined.
232 */
233 vis->DepthMax = 0xffffffff;
234 vis->DepthMaxF = (GLfloat) vis->DepthMax;
235 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000236
Brian Paul178a1c52000-04-22 01:05:00 +0000237 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000238}
239
240
Brian Paulb371e0d2000-03-31 01:05:51 +0000241/* This function should no longer be used. Use _mesa_create_visual() instead */
Brian Paul178a1c52000-04-22 01:05:00 +0000242GLvisual *
243gl_create_visual( GLboolean rgbFlag,
244 GLboolean alphaFlag,
245 GLboolean dbFlag,
246 GLboolean stereoFlag,
247 GLint depthBits,
248 GLint stencilBits,
249 GLint accumBits,
250 GLint indexBits,
251 GLint redBits,
252 GLint greenBits,
253 GLint blueBits,
254 GLint alphaBits )
Brian Paulb371e0d2000-03-31 01:05:51 +0000255{
Brian Paule70c6232000-05-04 13:53:55 +0000256 (void) alphaFlag;
257 return _mesa_create_visual(rgbFlag, dbFlag, stereoFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000258 redBits, greenBits, blueBits, alphaBits,
259 indexBits, depthBits, stencilBits,
260 accumBits, accumBits, accumBits, accumBits, 0);
261}
Brian Paul4d053dd2000-01-14 04:45:47 +0000262
Brian Paulb371e0d2000-03-31 01:05:51 +0000263
264void
265_mesa_destroy_visual( GLvisual *vis )
266{
267 FREE(vis);
268}
269
270
271/* obsolete */
Brian Paul178a1c52000-04-22 01:05:00 +0000272void
273gl_destroy_visual( GLvisual *vis )
Brian Paul4d053dd2000-01-14 04:45:47 +0000274{
Brian Paulb371e0d2000-03-31 01:05:51 +0000275 _mesa_destroy_visual(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000276}
277
278
279
280/**********************************************************************/
281/***** GL Framebuffer allocation/destruction *****/
282/**********************************************************************/
283
284
285/*
286 * Create a new framebuffer. A GLframebuffer is a struct which
287 * encapsulates the depth, stencil and accum buffers and related
288 * parameters.
289 * Input: visual - a GLvisual pointer
290 * softwareDepth - create/use a software depth buffer?
291 * softwareStencil - create/use a software stencil buffer?
292 * softwareAccum - create/use a software accum buffer?
293 * softwareAlpha - create/use a software alpha buffer?
294
295 * Return: pointer to new GLframebuffer struct or NULL if error.
296 */
Brian Paul178a1c52000-04-22 01:05:00 +0000297GLframebuffer *
298gl_create_framebuffer( GLvisual *visual,
299 GLboolean softwareDepth,
300 GLboolean softwareStencil,
301 GLboolean softwareAccum,
302 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000303{
Brian Paul178a1c52000-04-22 01:05:00 +0000304 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
305 assert(visual);
306 if (buffer) {
307 _mesa_initialize_framebuffer(buffer, visual,
308 softwareDepth, softwareStencil,
309 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000310 }
Brian Paul178a1c52000-04-22 01:05:00 +0000311 return buffer;
312}
313
314
315/*
316 * Initialize a GLframebuffer object.
317 * Input: See gl_create_framebuffer() above.
318 */
319void
320_mesa_initialize_framebuffer( GLframebuffer *buffer,
321 GLvisual *visual,
322 GLboolean softwareDepth,
323 GLboolean softwareStencil,
324 GLboolean softwareAccum,
325 GLboolean softwareAlpha )
326{
327 assert(buffer);
328 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000329
330 /* sanity checks */
331 if (softwareDepth ) {
332 assert(visual->DepthBits > 0);
333 }
334 if (softwareStencil) {
335 assert(visual->StencilBits > 0);
336 }
337 if (softwareAccum) {
338 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000339 assert(visual->AccumRedBits > 0);
340 assert(visual->AccumGreenBits > 0);
341 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000342 }
343 if (softwareAlpha) {
344 assert(visual->RGBAflag);
345 assert(visual->AlphaBits > 0);
346 }
347
348 buffer->Visual = visual;
349 buffer->UseSoftwareDepthBuffer = softwareDepth;
350 buffer->UseSoftwareStencilBuffer = softwareStencil;
351 buffer->UseSoftwareAccumBuffer = softwareAccum;
352 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000353}
354
355
Brian Paul4d053dd2000-01-14 04:45:47 +0000356/*
357 * Free a framebuffer struct and its buffers.
358 */
Brian Paul178a1c52000-04-22 01:05:00 +0000359void
360gl_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000361{
362 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000363 if (buffer->DepthBuffer) {
364 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000365 }
366 if (buffer->Accum) {
367 FREE( buffer->Accum );
368 }
369 if (buffer->Stencil) {
370 FREE( buffer->Stencil );
371 }
372 if (buffer->FrontLeftAlpha) {
373 FREE( buffer->FrontLeftAlpha );
374 }
375 if (buffer->BackLeftAlpha) {
376 FREE( buffer->BackLeftAlpha );
377 }
378 if (buffer->FrontRightAlpha) {
379 FREE( buffer->FrontRightAlpha );
380 }
381 if (buffer->BackRightAlpha) {
382 FREE( buffer->BackRightAlpha );
383 }
384 FREE(buffer);
385 }
386}
387
388
389
390/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000391/***** Context allocation, initialization, destroying *****/
392/**********************************************************************/
393
394
Brian Paul9560f052000-01-31 23:11:39 +0000395_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
396
397
jtgafb833d1999-08-19 00:55:39 +0000398/*
399 * This function just calls all the various one-time-init functions in Mesa.
400 */
Brian Paul178a1c52000-04-22 01:05:00 +0000401static void
402one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000403{
404 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000405 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000406 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000407 /* do some implementation tests */
408 assert( sizeof(GLbyte) == 1 );
409 assert( sizeof(GLshort) >= 2 );
410 assert( sizeof(GLint) >= 4 );
411 assert( sizeof(GLubyte) == 1 );
412 assert( sizeof(GLushort) >= 2 );
413 assert( sizeof(GLuint) >= 4 );
414
jtgafb833d1999-08-19 00:55:39 +0000415 gl_init_clip();
416 gl_init_eval();
Brian Paul5829f0c2000-02-02 22:21:39 +0000417 _mesa_init_fog();
Brian Paul780c4e02000-03-22 23:20:12 +0000418 _mesa_init_math();
jtgafb833d1999-08-19 00:55:39 +0000419 gl_init_lists();
420 gl_init_shade();
421 gl_init_texture();
422 gl_init_transformation();
423 gl_init_translate();
424 gl_init_vbrender();
425 gl_init_vbxform();
Keith Whitwell38756791999-08-29 10:26:31 +0000426 gl_init_vertices();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000427
428 if (getenv("MESA_DEBUG")) {
429 _glapi_noop_enable_warnings(GL_TRUE);
430 }
431 else {
432 _glapi_noop_enable_warnings(GL_FALSE);
433 }
434
jtgafb833d1999-08-19 00:55:39 +0000435#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
436 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
437#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000438
439 alreadyCalled = GL_TRUE;
440 }
Brian Paul9560f052000-01-31 23:11:39 +0000441 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000442}
443
444
Brian Paul4d053dd2000-01-14 04:45:47 +0000445
jtgafb833d1999-08-19 00:55:39 +0000446/*
447 * Allocate and initialize a shared context state structure.
448 */
Brian Paul178a1c52000-04-22 01:05:00 +0000449static struct gl_shared_state *
450alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000451{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000452 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000453 struct gl_shared_state *ss;
454 GLboolean outOfMemory;
455
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000456 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000457 if (!ss)
458 return NULL;
459
Brian Paulbb797902000-01-24 16:19:54 +0000460 ss->DisplayList = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000461
Brian Paulbb797902000-01-24 16:19:54 +0000462 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000463
464 /* Default Texture objects */
465 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000466 for (d = 1 ; d <= 3 ; d++) {
467 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
468 if (!ss->DefaultD[d]) {
469 outOfMemory = GL_TRUE;
470 break;
jtgafb833d1999-08-19 00:55:39 +0000471 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000472 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000473 }
474
Brian Paul413d6a22000-05-26 14:44:59 +0000475 ss->DefaultCubeMap = gl_alloc_texture_object(ss, 0, 6);
476 if (!ss->DefaultCubeMap) {
477 outOfMemory = GL_TRUE;
478 }
479 else {
480 ss->DefaultCubeMap->RefCount++;
481 }
482
jtgafb833d1999-08-19 00:55:39 +0000483 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
484 /* Ran out of memory at some point. Free everything and return NULL */
485 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000486 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000487 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000488 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000489 if (ss->DefaultD[1])
490 gl_free_texture_object(ss, ss->DefaultD[1]);
491 if (ss->DefaultD[2])
492 gl_free_texture_object(ss, ss->DefaultD[2]);
493 if (ss->DefaultD[3])
494 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paul413d6a22000-05-26 14:44:59 +0000495 if (ss->DefaultCubeMap)
496 gl_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000497 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000498 return NULL;
499 }
500 else {
501 return ss;
502 }
503}
504
505
506/*
507 * Deallocate a shared state context and all children structures.
508 */
Brian Paul178a1c52000-04-22 01:05:00 +0000509static void
510free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000511{
512 /* Free display lists */
513 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000514 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000515 if (list) {
516 gl_destroy_list(ctx, list);
517 }
518 else {
519 break;
520 }
521 }
Brian Paulbb797902000-01-24 16:19:54 +0000522 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000523
524 /* Free texture objects */
525 while (ss->TexObjectList)
526 {
527 if (ctx->Driver.DeleteTexture)
528 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
529 /* this function removes from linked list too! */
530 gl_free_texture_object(ss, ss->TexObjectList);
531 }
Brian Paulbb797902000-01-24 16:19:54 +0000532 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000533
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000534 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000535}
536
537
538
jtgafb833d1999-08-19 00:55:39 +0000539/*
540 * Initialize the nth light. Note that the defaults for light 0 are
541 * different than the other lights.
542 */
Brian Paul178a1c52000-04-22 01:05:00 +0000543static void
544init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000545{
546 make_empty_list( l );
547
548 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
549 if (n==0) {
550 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
551 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
552 }
553 else {
554 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
555 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
556 }
557 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
558 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
559 l->SpotExponent = 0.0;
560 gl_compute_spot_exp_table( l );
561 l->SpotCutoff = 180.0;
562 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
563 l->ConstantAttenuation = 1.0;
564 l->LinearAttenuation = 0.0;
565 l->QuadraticAttenuation = 0.0;
566 l->Enabled = GL_FALSE;
567}
568
569
570
Brian Paul178a1c52000-04-22 01:05:00 +0000571static void
572init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000573{
574 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
575 lm->LocalViewer = GL_FALSE;
576 lm->TwoSide = GL_FALSE;
577 lm->ColorControl = GL_SINGLE_COLOR;
578}
579
580
Brian Paul178a1c52000-04-22 01:05:00 +0000581static void
582init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000583{
584 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
585 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
586 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
587 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
588 m->Shininess = 0.0;
589 m->AmbientIndex = 0;
590 m->DiffuseIndex = 1;
591 m->SpecularIndex = 1;
592}
593
594
595
Brian Paul178a1c52000-04-22 01:05:00 +0000596static void
597init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000598{
599 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
600
601 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000602 texUnit->CombineModeRGB = GL_MODULATE;
603 texUnit->CombineModeA = GL_MODULATE;
604 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
605 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
606 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
607 texUnit->CombineSourceA[0] = GL_TEXTURE;
608 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
609 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
610 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
611 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
612 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
613 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
614 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
615 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
616 texUnit->CombineScaleShiftRGB = 0;
617 texUnit->CombineScaleShiftA = 0;
618
jtgafb833d1999-08-19 00:55:39 +0000619 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
620 texUnit->TexGenEnabled = 0;
621 texUnit->GenModeS = GL_EYE_LINEAR;
622 texUnit->GenModeT = GL_EYE_LINEAR;
623 texUnit->GenModeR = GL_EYE_LINEAR;
624 texUnit->GenModeQ = GL_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000625 texUnit->GenBitS = TEXGEN_EYE_LINEAR;
626 texUnit->GenBitT = TEXGEN_EYE_LINEAR;
627 texUnit->GenBitR = TEXGEN_EYE_LINEAR;
628 texUnit->GenBitQ = TEXGEN_EYE_LINEAR;
629
jtgafb833d1999-08-19 00:55:39 +0000630 /* Yes, these plane coefficients are correct! */
631 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
632 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
633 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
634 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
635 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
636 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
637 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
638 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
639
Brian Paul6e6d4c61999-10-09 20:17:07 +0000640 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
641 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
642 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
Brian Paul413d6a22000-05-26 14:44:59 +0000643 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000644}
645
646
Brian Paul178a1c52000-04-22 01:05:00 +0000647static void
648init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000649{
650 struct gl_client_array *cl;
651 GLuint i;
652
653 cl = &ctx->Fallback.Normal;
654 cl->Size = 3;
655 cl->Type = GL_FLOAT;
656 cl->Stride = 0;
657 cl->StrideB = 0;
658 cl->Ptr = (void *) ctx->Current.Normal;
659 cl->Enabled = 1;
660
661 cl = &ctx->Fallback.Color;
662 cl->Size = 4;
663 cl->Type = GL_UNSIGNED_BYTE;
664 cl->Stride = 0;
665 cl->StrideB = 0;
666 cl->Ptr = (void *) ctx->Current.ByteColor;
667 cl->Enabled = 1;
668
669 cl = &ctx->Fallback.Index;
670 cl->Size = 1;
671 cl->Type = GL_UNSIGNED_INT;
672 cl->Stride = 0;
673 cl->StrideB = 0;
674 cl->Ptr = (void *) &ctx->Current.Index;
675 cl->Enabled = 1;
676
677 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
678 cl = &ctx->Fallback.TexCoord[i];
679 cl->Size = 4;
680 cl->Type = GL_FLOAT;
681 cl->Stride = 0;
682 cl->StrideB = 0;
683 cl->Ptr = (void *) ctx->Current.Texcoord[i];
684 cl->Enabled = 1;
685 }
686
687 cl = &ctx->Fallback.EdgeFlag;
688 cl->Size = 1;
689 cl->Type = GL_UNSIGNED_BYTE;
690 cl->Stride = 0;
691 cl->StrideB = 0;
692 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
693 cl->Enabled = 1;
694}
695
Brian Paul4d053dd2000-01-14 04:45:47 +0000696
jtgafb833d1999-08-19 00:55:39 +0000697/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000698static void
699init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000700{
701 map->Order = 1;
702 map->u1 = 0.0;
703 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000704 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000705 if (map->Points) {
706 GLint i;
707 for (i=0;i<n;i++)
708 map->Points[i] = initial[i];
709 }
jtgafb833d1999-08-19 00:55:39 +0000710}
711
712
713/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000714static void
715init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000716{
717 map->Uorder = 1;
718 map->Vorder = 1;
719 map->u1 = 0.0;
720 map->u2 = 1.0;
721 map->v1 = 0.0;
722 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000723 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000724 if (map->Points) {
725 GLint i;
726 for (i=0;i<n;i++)
727 map->Points[i] = initial[i];
728 }
jtgafb833d1999-08-19 00:55:39 +0000729}
730
731
jtgafb833d1999-08-19 00:55:39 +0000732/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000733 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000734 */
Brian Paul178a1c52000-04-22 01:05:00 +0000735static void
736init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000737{
738 GLuint i, j;
739
Brian Paul4d053dd2000-01-14 04:45:47 +0000740 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000741
Brian Paul539cce52000-02-03 19:40:07 +0000742 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000743 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
744 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000745 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000746 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
747 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000748 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
749 ctx->Const.MinPointSize = MIN_POINT_SIZE;
750 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
751 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
752 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
753 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
754 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
755 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
756 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
757 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
758 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
759 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000760 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000761 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
762 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000763 ctx->Const.NumCompressedTextureFormats = 0;
jtgafb833d1999-08-19 00:55:39 +0000764
Brian Paul4d053dd2000-01-14 04:45:47 +0000765 /* Modelview matrix */
766 gl_matrix_ctr( &ctx->ModelView );
767 gl_matrix_alloc_inv( &ctx->ModelView );
768
769 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000770 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000771 gl_matrix_ctr( &ctx->ModelViewStack[i] );
772 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
773 }
774
775 /* Projection matrix - need inv for user clipping in clip space*/
776 gl_matrix_ctr( &ctx->ProjectionMatrix );
777 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
778
779 gl_matrix_ctr( &ctx->ModelProjectMatrix );
780 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
781 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
782
783 ctx->ProjectionStackDepth = 0;
784 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
785 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
786
Brian Paul7fc29c52000-03-06 17:03:03 +0000787 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000788 gl_matrix_ctr( &ctx->ProjectionStack[i] );
789 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
790 }
791
792 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000793 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000794 gl_matrix_ctr( &ctx->TextureMatrix[i] );
795 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000796 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Brian Paul904ecb22000-06-27 23:38:45 +0000797 gl_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000798 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000799 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000800 }
jtgafb833d1999-08-19 00:55:39 +0000801
Brian Paul250069d2000-04-08 18:57:45 +0000802 /* Color matrix */
803 gl_matrix_ctr(&ctx->ColorMatrix);
804 ctx->ColorStackDepth = 0;
805 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
806 gl_matrix_ctr(&ctx->ColorStack[j]);
807 }
808
Brian Paul4d053dd2000-01-14 04:45:47 +0000809 /* Accumulate buffer group */
810 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000811
Brian Paul4d053dd2000-01-14 04:45:47 +0000812 /* Color buffer group */
813 ctx->Color.IndexMask = 0xffffffff;
814 ctx->Color.ColorMask[0] = 0xff;
815 ctx->Color.ColorMask[1] = 0xff;
816 ctx->Color.ColorMask[2] = 0xff;
817 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000818 ctx->Color.ClearIndex = 0;
819 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
820 ctx->Color.DrawBuffer = GL_FRONT;
821 ctx->Color.AlphaEnabled = GL_FALSE;
822 ctx->Color.AlphaFunc = GL_ALWAYS;
823 ctx->Color.AlphaRef = 0;
824 ctx->Color.BlendEnabled = GL_FALSE;
825 ctx->Color.BlendSrcRGB = GL_ONE;
826 ctx->Color.BlendDstRGB = GL_ZERO;
827 ctx->Color.BlendSrcA = GL_ONE;
828 ctx->Color.BlendDstA = GL_ZERO;
829 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
830 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
831 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
832 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
833 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000834 ctx->Color.LogicOp = GL_COPY;
835 ctx->Color.DitherFlag = GL_TRUE;
836 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000837
Brian Paul4d053dd2000-01-14 04:45:47 +0000838 /* Current group */
839 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
840 ctx->Current.Index = 1;
841 for (i=0; i<MAX_TEXTURE_UNITS; i++)
842 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
843 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
844 ctx->Current.RasterDistance = 0.0;
845 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
846 ctx->Current.RasterIndex = 1;
847 for (i=0; i<MAX_TEXTURE_UNITS; i++)
848 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
849 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
850 ctx->Current.RasterPosValid = GL_TRUE;
851 ctx->Current.EdgeFlag = GL_TRUE;
852 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
853 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
jtgafb833d1999-08-19 00:55:39 +0000854
Brian Paul4d053dd2000-01-14 04:45:47 +0000855 ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
856 VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
jtgafb833d1999-08-19 00:55:39 +0000857
Brian Paul4d053dd2000-01-14 04:45:47 +0000858 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000859
Brian Paul4d053dd2000-01-14 04:45:47 +0000860 /* Depth buffer group */
861 ctx->Depth.Test = GL_FALSE;
862 ctx->Depth.Clear = 1.0;
863 ctx->Depth.Func = GL_LESS;
864 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000865 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000866
Brian Paul4d053dd2000-01-14 04:45:47 +0000867 /* Evaluators group */
868 ctx->Eval.Map1Color4 = GL_FALSE;
869 ctx->Eval.Map1Index = GL_FALSE;
870 ctx->Eval.Map1Normal = GL_FALSE;
871 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
872 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
873 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
874 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
875 ctx->Eval.Map1Vertex3 = GL_FALSE;
876 ctx->Eval.Map1Vertex4 = GL_FALSE;
877 ctx->Eval.Map2Color4 = GL_FALSE;
878 ctx->Eval.Map2Index = GL_FALSE;
879 ctx->Eval.Map2Normal = GL_FALSE;
880 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
881 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
882 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
883 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
884 ctx->Eval.Map2Vertex3 = GL_FALSE;
885 ctx->Eval.Map2Vertex4 = GL_FALSE;
886 ctx->Eval.AutoNormal = GL_FALSE;
887 ctx->Eval.MapGrid1un = 1;
888 ctx->Eval.MapGrid1u1 = 0.0;
889 ctx->Eval.MapGrid1u2 = 1.0;
890 ctx->Eval.MapGrid2un = 1;
891 ctx->Eval.MapGrid2vn = 1;
892 ctx->Eval.MapGrid2u1 = 0.0;
893 ctx->Eval.MapGrid2u2 = 1.0;
894 ctx->Eval.MapGrid2v1 = 0.0;
895 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000896
Brian Paul4d053dd2000-01-14 04:45:47 +0000897 /* Evaluator data */
898 {
899 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
900 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
901 static GLfloat index[1] = { 1.0 };
902 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
903 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000904
Brian Paul4d053dd2000-01-14 04:45:47 +0000905 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
906 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
907 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
908 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
909 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
910 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
911 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
912 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
913 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000914
Brian Paul4d053dd2000-01-14 04:45:47 +0000915 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
916 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
917 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
918 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
919 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
920 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
921 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
922 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
923 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
924 }
jtgafb833d1999-08-19 00:55:39 +0000925
Brian Paul4d053dd2000-01-14 04:45:47 +0000926 /* Fog group */
927 ctx->Fog.Enabled = GL_FALSE;
928 ctx->Fog.Mode = GL_EXP;
929 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
930 ctx->Fog.Index = 0.0;
931 ctx->Fog.Density = 1.0;
932 ctx->Fog.Start = 0.0;
933 ctx->Fog.End = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000934
Brian Paul4d053dd2000-01-14 04:45:47 +0000935 /* Hint group */
936 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
937 ctx->Hint.PointSmooth = GL_DONT_CARE;
938 ctx->Hint.LineSmooth = GL_DONT_CARE;
939 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
940 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000941 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000942 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000943 ctx->Hint.AllowDrawMem = GL_TRUE;
944 ctx->Hint.StrictLighting = GL_TRUE;
Brian Paul1207bf02000-05-23 20:10:49 +0000945 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
946 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000947
Brian Paul0771d152000-04-07 00:19:41 +0000948 /* Histogram group */
949 ctx->Histogram.Width = 0;
950 ctx->Histogram.Format = GL_RGBA;
951 ctx->Histogram.Sink = GL_FALSE;
952 ctx->Histogram.RedSize = 0xffffffff;
953 ctx->Histogram.GreenSize = 0xffffffff;
954 ctx->Histogram.BlueSize = 0xffffffff;
955 ctx->Histogram.AlphaSize = 0xffffffff;
956 ctx->Histogram.LuminanceSize = 0xffffffff;
957 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
958 ctx->Histogram.Count[i][0] = 0;
959 ctx->Histogram.Count[i][1] = 0;
960 ctx->Histogram.Count[i][2] = 0;
961 ctx->Histogram.Count[i][3] = 0;
962 }
963
964 /* Min/Max group */
965 ctx->MinMax.Format = GL_RGBA;
966 ctx->MinMax.Sink = GL_FALSE;
967 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
968 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
969 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
970 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
971
972
973
Brian Paul4d053dd2000-01-14 04:45:47 +0000974 /* Pipeline */
975 gl_pipeline_init( ctx );
976 gl_cva_init( ctx );
jtgafb833d1999-08-19 00:55:39 +0000977
Brian Paul4d053dd2000-01-14 04:45:47 +0000978 /* Extensions */
979 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000980
Brian Paul4d053dd2000-01-14 04:45:47 +0000981 ctx->AllowVertexCull = CLIP_CULLED_BIT;
jtgafb833d1999-08-19 00:55:39 +0000982
Brian Paul4d053dd2000-01-14 04:45:47 +0000983 /* Lighting group */
984 for (i=0;i<MAX_LIGHTS;i++) {
985 init_light( &ctx->Light.Light[i], i );
986 }
987 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000988
Brian Paul4d053dd2000-01-14 04:45:47 +0000989 init_lightmodel( &ctx->Light.Model );
990 init_material( &ctx->Light.Material[0] );
991 init_material( &ctx->Light.Material[1] );
992 ctx->Light.ShadeModel = GL_SMOOTH;
993 ctx->Light.Enabled = GL_FALSE;
994 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
995 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
996 ctx->Light.ColorMaterialBitmask
997 = gl_material_bitmask( ctx,
998 GL_FRONT_AND_BACK,
999 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001000
Brian Paul4d053dd2000-01-14 04:45:47 +00001001 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001002
Brian Paul4d053dd2000-01-14 04:45:47 +00001003 /* Lighting miscellaneous */
1004 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1005 make_empty_list( ctx->ShineTabList );
1006 for (i = 0 ; i < 10 ; i++) {
1007 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1008 s->shininess = -1;
1009 s->refcount = 0;
1010 insert_at_tail( ctx->ShineTabList, s );
1011 }
1012 for (i = 0 ; i < 4 ; i++) {
1013 ctx->ShineTable[i] = ctx->ShineTabList->prev;
1014 ctx->ShineTable[i]->refcount++;
1015 }
jtgafb833d1999-08-19 00:55:39 +00001016
Brian Paul77d61af2000-06-28 04:20:21 +00001017 gl_compute_shine_table( ctx, 0, ctx->Light.Material[0].Shininess );
1018 gl_compute_shine_table( ctx, 2, ctx->Light.Material[0].Shininess * .5 );
1019 gl_compute_shine_table( ctx, 1, ctx->Light.Material[1].Shininess );
1020 gl_compute_shine_table( ctx, 3, ctx->Light.Material[1].Shininess * .5 );
1021
jtgafb833d1999-08-19 00:55:39 +00001022
Brian Paul4d053dd2000-01-14 04:45:47 +00001023 /* Line group */
1024 ctx->Line.SmoothFlag = GL_FALSE;
1025 ctx->Line.StippleFlag = GL_FALSE;
1026 ctx->Line.Width = 1.0;
1027 ctx->Line.StipplePattern = 0xffff;
1028 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001029
Brian Paul4d053dd2000-01-14 04:45:47 +00001030 /* Display List group */
1031 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001032
Brian Paul4d053dd2000-01-14 04:45:47 +00001033 /* Pixel group */
1034 ctx->Pixel.RedBias = 0.0;
1035 ctx->Pixel.RedScale = 1.0;
1036 ctx->Pixel.GreenBias = 0.0;
1037 ctx->Pixel.GreenScale = 1.0;
1038 ctx->Pixel.BlueBias = 0.0;
1039 ctx->Pixel.BlueScale = 1.0;
1040 ctx->Pixel.AlphaBias = 0.0;
1041 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001042 ctx->Pixel.DepthBias = 0.0;
1043 ctx->Pixel.DepthScale = 1.0;
1044 ctx->Pixel.IndexOffset = 0;
1045 ctx->Pixel.IndexShift = 0;
1046 ctx->Pixel.ZoomX = 1.0;
1047 ctx->Pixel.ZoomY = 1.0;
1048 ctx->Pixel.MapColorFlag = GL_FALSE;
1049 ctx->Pixel.MapStencilFlag = GL_FALSE;
1050 ctx->Pixel.MapStoSsize = 1;
1051 ctx->Pixel.MapItoIsize = 1;
1052 ctx->Pixel.MapItoRsize = 1;
1053 ctx->Pixel.MapItoGsize = 1;
1054 ctx->Pixel.MapItoBsize = 1;
1055 ctx->Pixel.MapItoAsize = 1;
1056 ctx->Pixel.MapRtoRsize = 1;
1057 ctx->Pixel.MapGtoGsize = 1;
1058 ctx->Pixel.MapBtoBsize = 1;
1059 ctx->Pixel.MapAtoAsize = 1;
1060 ctx->Pixel.MapStoS[0] = 0;
1061 ctx->Pixel.MapItoI[0] = 0;
1062 ctx->Pixel.MapItoR[0] = 0.0;
1063 ctx->Pixel.MapItoG[0] = 0.0;
1064 ctx->Pixel.MapItoB[0] = 0.0;
1065 ctx->Pixel.MapItoA[0] = 0.0;
1066 ctx->Pixel.MapItoR8[0] = 0;
1067 ctx->Pixel.MapItoG8[0] = 0;
1068 ctx->Pixel.MapItoB8[0] = 0;
1069 ctx->Pixel.MapItoA8[0] = 0;
1070 ctx->Pixel.MapRtoR[0] = 0.0;
1071 ctx->Pixel.MapGtoG[0] = 0.0;
1072 ctx->Pixel.MapBtoB[0] = 0.0;
1073 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001074 ctx->Pixel.HistogramEnabled = GL_FALSE;
1075 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1076 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1077 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1078 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001079 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1080 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1081 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1082 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001083 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1084 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1085 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1086 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001087 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1088 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1089 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001090 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1091 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1092 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1093 for (i = 0; i < 3; i++) {
1094 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1095 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1096 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1097 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1098 }
1099 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1100 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001101
Brian Paul4d053dd2000-01-14 04:45:47 +00001102 /* Point group */
1103 ctx->Point.SmoothFlag = GL_FALSE;
Brian Paula25f7e12000-06-27 04:29:22 +00001104 ctx->Point.UserSize = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001105 ctx->Point.Size = 1.0;
1106 ctx->Point.Params[0] = 1.0;
1107 ctx->Point.Params[1] = 0.0;
1108 ctx->Point.Params[2] = 0.0;
1109 ctx->Point.Attenuated = GL_FALSE;
1110 ctx->Point.MinSize = 0.0;
1111 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1112 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001113
Brian Paul4d053dd2000-01-14 04:45:47 +00001114 /* Polygon group */
1115 ctx->Polygon.CullFlag = GL_FALSE;
1116 ctx->Polygon.CullFaceMode = GL_BACK;
1117 ctx->Polygon.FrontFace = GL_CCW;
1118 ctx->Polygon.FrontBit = 0;
1119 ctx->Polygon.FrontMode = GL_FILL;
1120 ctx->Polygon.BackMode = GL_FILL;
1121 ctx->Polygon.Unfilled = GL_FALSE;
1122 ctx->Polygon.SmoothFlag = GL_FALSE;
1123 ctx->Polygon.StippleFlag = GL_FALSE;
1124 ctx->Polygon.OffsetFactor = 0.0F;
1125 ctx->Polygon.OffsetUnits = 0.0F;
1126 ctx->Polygon.OffsetPoint = GL_FALSE;
1127 ctx->Polygon.OffsetLine = GL_FALSE;
1128 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001129
Brian Paul4d053dd2000-01-14 04:45:47 +00001130 /* Polygon Stipple group */
1131 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001132
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 /* Scissor group */
1134 ctx->Scissor.Enabled = GL_FALSE;
1135 ctx->Scissor.X = 0;
1136 ctx->Scissor.Y = 0;
1137 ctx->Scissor.Width = 0;
1138 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001139
Brian Paul4d053dd2000-01-14 04:45:47 +00001140 /* Stencil group */
1141 ctx->Stencil.Enabled = GL_FALSE;
1142 ctx->Stencil.Function = GL_ALWAYS;
1143 ctx->Stencil.FailFunc = GL_KEEP;
1144 ctx->Stencil.ZPassFunc = GL_KEEP;
1145 ctx->Stencil.ZFailFunc = GL_KEEP;
1146 ctx->Stencil.Ref = 0;
1147 ctx->Stencil.ValueMask = STENCIL_MAX;
1148 ctx->Stencil.Clear = 0;
1149 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001150
Brian Paul4d053dd2000-01-14 04:45:47 +00001151 /* Texture group */
1152 ctx->Texture.CurrentUnit = 0; /* multitexture */
1153 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
1154 ctx->Texture.Enabled = 0;
1155 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1156 init_texture_unit( ctx, i );
Brian Paul4bdcfe52000-04-17 17:57:04 +00001157 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001158
Brian Paul4d053dd2000-01-14 04:45:47 +00001159 /* Transformation group */
1160 ctx->Transform.MatrixMode = GL_MODELVIEW;
1161 ctx->Transform.Normalize = GL_FALSE;
1162 ctx->Transform.RescaleNormals = GL_FALSE;
1163 for (i=0;i<MAX_CLIP_PLANES;i++) {
1164 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1165 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1166 }
1167 ctx->Transform.AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001168
Brian Paul4d053dd2000-01-14 04:45:47 +00001169 /* Viewport group */
1170 ctx->Viewport.X = 0;
1171 ctx->Viewport.Y = 0;
1172 ctx->Viewport.Width = 0;
1173 ctx->Viewport.Height = 0;
1174 ctx->Viewport.Near = 0.0;
1175 ctx->Viewport.Far = 1.0;
1176 gl_matrix_ctr(&ctx->Viewport.WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001177
1178#define Sz 10
1179#define Tz 14
Brian Pauled30dfa2000-03-03 17:47:39 +00001180 ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual->DepthMaxF;
1181 ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001182#undef Sz
1183#undef Tz
1184
Brian Paul4d053dd2000-01-14 04:45:47 +00001185 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1186 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001187
Brian Paul4d053dd2000-01-14 04:45:47 +00001188 /* Vertex arrays */
1189 ctx->Array.Vertex.Size = 4;
1190 ctx->Array.Vertex.Type = GL_FLOAT;
1191 ctx->Array.Vertex.Stride = 0;
1192 ctx->Array.Vertex.StrideB = 0;
1193 ctx->Array.Vertex.Ptr = NULL;
1194 ctx->Array.Vertex.Enabled = GL_FALSE;
1195 ctx->Array.Normal.Type = GL_FLOAT;
1196 ctx->Array.Normal.Stride = 0;
1197 ctx->Array.Normal.StrideB = 0;
1198 ctx->Array.Normal.Ptr = NULL;
1199 ctx->Array.Normal.Enabled = GL_FALSE;
1200 ctx->Array.Color.Size = 4;
1201 ctx->Array.Color.Type = GL_FLOAT;
1202 ctx->Array.Color.Stride = 0;
1203 ctx->Array.Color.StrideB = 0;
1204 ctx->Array.Color.Ptr = NULL;
1205 ctx->Array.Color.Enabled = GL_FALSE;
1206 ctx->Array.Index.Type = GL_FLOAT;
1207 ctx->Array.Index.Stride = 0;
1208 ctx->Array.Index.StrideB = 0;
1209 ctx->Array.Index.Ptr = NULL;
1210 ctx->Array.Index.Enabled = GL_FALSE;
1211 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1212 ctx->Array.TexCoord[i].Size = 4;
1213 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1214 ctx->Array.TexCoord[i].Stride = 0;
1215 ctx->Array.TexCoord[i].StrideB = 0;
1216 ctx->Array.TexCoord[i].Ptr = NULL;
1217 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1218 }
1219 ctx->Array.TexCoordInterleaveFactor = 1;
1220 ctx->Array.EdgeFlag.Stride = 0;
1221 ctx->Array.EdgeFlag.StrideB = 0;
1222 ctx->Array.EdgeFlag.Ptr = NULL;
1223 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1224 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1225
1226 /* Pixel transfer */
1227 ctx->Pack.Alignment = 4;
1228 ctx->Pack.RowLength = 0;
1229 ctx->Pack.ImageHeight = 0;
1230 ctx->Pack.SkipPixels = 0;
1231 ctx->Pack.SkipRows = 0;
1232 ctx->Pack.SkipImages = 0;
1233 ctx->Pack.SwapBytes = GL_FALSE;
1234 ctx->Pack.LsbFirst = GL_FALSE;
1235 ctx->Unpack.Alignment = 4;
1236 ctx->Unpack.RowLength = 0;
1237 ctx->Unpack.ImageHeight = 0;
1238 ctx->Unpack.SkipPixels = 0;
1239 ctx->Unpack.SkipRows = 0;
1240 ctx->Unpack.SkipImages = 0;
1241 ctx->Unpack.SwapBytes = GL_FALSE;
1242 ctx->Unpack.LsbFirst = GL_FALSE;
1243
1244 /* Feedback */
1245 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1246 ctx->Feedback.Buffer = NULL;
1247 ctx->Feedback.BufferSize = 0;
1248 ctx->Feedback.Count = 0;
1249
1250 /* Selection/picking */
1251 ctx->Select.Buffer = NULL;
1252 ctx->Select.BufferSize = 0;
1253 ctx->Select.BufferCount = 0;
1254 ctx->Select.Hits = 0;
1255 ctx->Select.NameStackDepth = 0;
1256
1257 /* Optimized Accum buffer */
1258 ctx->IntegerAccumMode = GL_TRUE;
1259 ctx->IntegerAccumScaler = 0.0;
1260
1261 /* Renderer and client attribute stacks */
1262 ctx->AttribStackDepth = 0;
1263 ctx->ClientAttribStackDepth = 0;
1264
Brian Paul13811372000-04-12 00:27:37 +00001265 /* Display list */
1266 ctx->CallDepth = 0;
1267 ctx->ExecuteFlag = GL_TRUE;
1268 ctx->CompileFlag = GL_FALSE;
1269 ctx->CurrentListPtr = NULL;
1270 ctx->CurrentBlock = NULL;
1271 ctx->CurrentListNum = 0;
1272 ctx->CurrentPos = 0;
1273
1274 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001275 _mesa_init_colortable(&ctx->ColorTable);
1276 _mesa_init_colortable(&ctx->ProxyColorTable);
1277 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1278 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1279 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1280 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001281
Brian Paul4d053dd2000-01-14 04:45:47 +00001282 /* Miscellaneous */
1283 ctx->NewState = NEW_ALL;
1284 ctx->RenderMode = GL_RENDER;
1285 ctx->StippleCounter = 0;
1286 ctx->NeedNormals = GL_FALSE;
1287 ctx->DoViewportMapping = GL_TRUE;
Brian Paulfa4525e2000-08-21 14:22:24 +00001288 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001289
1290 ctx->NeedEyeCoords = GL_FALSE;
1291 ctx->NeedEyeNormals = GL_FALSE;
1292 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1293
Brian Paul4d053dd2000-01-14 04:45:47 +00001294 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1295
1296 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001297 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001298 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001299
1300 /* For debug/development only */
1301 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1302 ctx->FirstTimeCurrent = GL_TRUE;
1303
1304 /* Dither disable */
1305 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1306 if (ctx->NoDither) {
1307 if (getenv("MESA_DEBUG")) {
1308 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001309 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001310 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001311 }
1312}
1313
1314
1315
1316
jtgafb833d1999-08-19 00:55:39 +00001317/*
1318 * Allocate the proxy textures. If we run out of memory part way through
1319 * the allocations clean up and return GL_FALSE.
1320 * Return: GL_TRUE=success, GL_FALSE=failure
1321 */
Brian Paul178a1c52000-04-22 01:05:00 +00001322static GLboolean
1323alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001324{
1325 GLboolean out_of_memory;
1326 GLint i;
1327
1328 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1329 if (!ctx->Texture.Proxy1D) {
1330 return GL_FALSE;
1331 }
1332
1333 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1334 if (!ctx->Texture.Proxy2D) {
1335 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1336 return GL_FALSE;
1337 }
1338
1339 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1340 if (!ctx->Texture.Proxy3D) {
1341 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1342 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1343 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 }
1369 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1370 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1371 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1372 return GL_FALSE;
1373 }
1374 else {
1375 return GL_TRUE;
1376 }
1377}
1378
1379
1380
jtgafb833d1999-08-19 00:55:39 +00001381/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001382 * Initialize a GLcontext struct. This includes allocating all the
1383 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001384 */
Brian Paul178a1c52000-04-22 01:05:00 +00001385GLboolean
1386_mesa_initialize_context( GLcontext *ctx,
1387 GLvisual *visual,
1388 GLcontext *share_list,
1389 void *driver_ctx,
1390 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001391{
Brian Paul5fb84d22000-05-24 15:04:45 +00001392 GLuint dispatchSize;
1393
jtgafb833d1999-08-19 00:55:39 +00001394 (void) direct; /* not used */
1395
jtgafb833d1999-08-19 00:55:39 +00001396 /* misc one-time initializations */
1397 one_time_init();
1398
jtgafb833d1999-08-19 00:55:39 +00001399 ctx->DriverCtx = driver_ctx;
1400 ctx->Visual = visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001401 ctx->DrawBuffer = NULL;
1402 ctx->ReadBuffer = NULL;
jtgafb833d1999-08-19 00:55:39 +00001403
1404 ctx->VB = gl_vb_create_for_immediate( ctx );
1405 if (!ctx->VB) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001406 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001407 }
1408 ctx->input = ctx->VB->IM;
1409
1410 ctx->PB = gl_alloc_pb();
1411 if (!ctx->PB) {
Brian Paul2d8db392000-06-27 22:10:00 +00001412 ALIGN_FREE( ctx->VB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001413 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001414 }
1415
1416 if (share_list) {
1417 /* share the group of display lists of another context */
1418 ctx->Shared = share_list->Shared;
1419 }
1420 else {
1421 /* allocate new group of display lists */
1422 ctx->Shared = alloc_shared_state();
1423 if (!ctx->Shared) {
Brian Paul2d8db392000-06-27 22:10:00 +00001424 ALIGN_FREE( ctx->VB );
1425 FREE( ctx->PB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001426 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001427 }
1428 }
Brian Paul9560f052000-01-31 23:11:39 +00001429 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001430 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001431 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001432
Brian Paul4d053dd2000-01-14 04:45:47 +00001433 init_attrib_groups( ctx );
1434
jtgafb833d1999-08-19 00:55:39 +00001435 gl_reset_vb( ctx->VB );
1436 gl_reset_input( ctx );
1437
jtgafb833d1999-08-19 00:55:39 +00001438 if (visual->DBflag) {
1439 ctx->Color.DrawBuffer = GL_BACK;
1440 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1441 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1442 ctx->Pixel.ReadBuffer = GL_BACK;
1443 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1444 }
1445 else {
1446 ctx->Color.DrawBuffer = GL_FRONT;
1447 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1448 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1449 ctx->Pixel.ReadBuffer = GL_FRONT;
1450 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1451 }
1452
jtgafb833d1999-08-19 00:55:39 +00001453 if (!alloc_proxy_textures(ctx)) {
1454 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001455 ALIGN_FREE( ctx->VB );
1456 FREE( ctx->PB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001457 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001458 }
jtgafb833d1999-08-19 00:55:39 +00001459
Brian Paulf59afc92000-05-23 23:23:00 +00001460 /* register the most recent extension functions with libGL */
1461 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1462 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1463 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1464 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1465 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1466 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1467 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1468 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1469
Brian Paul5fb84d22000-05-24 15:04:45 +00001470 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1471 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1472 * Mesa we do this to accomodate different versions of libGL and various
1473 * DRI drivers.
1474 */
1475 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1476 sizeof(struct _glapi_table) / sizeof(void *));
1477
Brian Paulfbd8f211999-11-11 01:22:25 +00001478 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001479 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1480 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001481 if (!ctx->Exec || !ctx->Save) {
1482 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001483 ALIGN_FREE( ctx->VB );
1484 FREE( ctx->PB );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001485 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001486 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001487 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001488 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1489 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001490 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001491
Brian Paul45f36342000-09-05 20:28:06 +00001492#if defined(TRACE)
1493 ctx->TraceCtx = CALLOC( sizeof(trace_context_t) );
1494#if 0
1495 /* Brian: do you want to have CreateContext fail here,
1496 or should we just trap in NewTrace (currently done)? */
1497 if (!(ctx->TraceCtx)) {
1498 free_shared_state(ctx, ctx->Shared);
1499 ALIGN_FREE( ctx->VB );
1500 FREE( ctx->PB );
1501 FREE( ctx->Exec );
1502 FREE( ctx->Save );
1503 return GL_FALSE;
1504 }
1505#endif
1506 trInitContext(ctx->TraceCtx);
1507
1508 ctx->TraceDispatch = (struct _glapi_table *)
1509 CALLOC(dispatchSize * sizeof(void*));
1510#if 0
1511 if (!(ctx->TraceCtx)) {
1512 free_shared_state(ctx, ctx->Shared);
1513 ALIGN_FREE( ctx->VB );
1514 FREE( ctx->PB );
1515 FREE( ctx->Exec );
1516 FREE( ctx->Save );
1517 FREE( ctx->TraceCtx );
1518 return GL_FALSE;
1519 }
1520#endif
1521 trInitDispatch(ctx->TraceDispatch);
1522#endif
1523
Brian Paul4d053dd2000-01-14 04:45:47 +00001524 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001525}
1526
jtgafb833d1999-08-19 00:55:39 +00001527
1528
1529/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001530 * Allocate and initialize a GLcontext structure.
1531 * Input: visual - a GLvisual pointer
1532 * sharelist - another context to share display lists with or NULL
1533 * driver_ctx - pointer to device driver's context state struct
1534 * Return: pointer to a new gl_context struct or NULL if error.
1535 */
Brian Paul178a1c52000-04-22 01:05:00 +00001536GLcontext *
1537gl_create_context( GLvisual *visual,
1538 GLcontext *share_list,
1539 void *driver_ctx,
1540 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001541{
1542 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1543 if (!ctx) {
1544 return NULL;
1545 }
1546
Brian Paul178a1c52000-04-22 01:05:00 +00001547 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001548 return ctx;
1549 }
1550 else {
1551 FREE(ctx);
1552 return NULL;
1553 }
1554}
1555
1556
1557
1558/*
1559 * Free the data associated with the given context.
1560 * But don't free() the GLcontext struct itself!
1561 */
Brian Paul178a1c52000-04-22 01:05:00 +00001562void
1563gl_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001564{
Brian Paul4d053dd2000-01-14 04:45:47 +00001565 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001566 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001567
1568 /* if we're destroying the current context, unbind it first */
1569 if (ctx == gl_get_current_context()) {
1570 gl_make_current(NULL, NULL);
1571 }
1572
Brian Paul4d053dd2000-01-14 04:45:47 +00001573 gl_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001574 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001575 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1576 }
1577 gl_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001578 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001579 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1580 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001581 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1582 gl_matrix_dtr( &ctx->TextureMatrix[i] );
1583 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1584 gl_matrix_dtr( &ctx->TextureStack[i][j] );
1585 }
1586 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001587
1588 FREE( ctx->PB );
1589
Brian Paul4bdcfe52000-04-17 17:57:04 +00001590 if (ctx->input != ctx->VB->IM)
Brian Paul4d053dd2000-01-14 04:45:47 +00001591 gl_immediate_free( ctx->input );
1592
1593 gl_vb_free( ctx->VB );
1594
Brian Paul9560f052000-01-31 23:11:39 +00001595 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001596 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001597 assert(ctx->Shared->RefCount >= 0);
1598 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1599 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001600 /* free shared state */
1601 free_shared_state( ctx, ctx->Shared );
1602 }
1603
1604 foreach_s( s, tmps, ctx->ShineTabList ) {
1605 FREE( s );
1606 }
1607 FREE( ctx->ShineTabList );
1608
1609 /* Free proxy texture objects */
1610 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1611 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1612 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1613
1614 /* Free evaluator data */
1615 if (ctx->EvalMap.Map1Vertex3.Points)
1616 FREE( ctx->EvalMap.Map1Vertex3.Points );
1617 if (ctx->EvalMap.Map1Vertex4.Points)
1618 FREE( ctx->EvalMap.Map1Vertex4.Points );
1619 if (ctx->EvalMap.Map1Index.Points)
1620 FREE( ctx->EvalMap.Map1Index.Points );
1621 if (ctx->EvalMap.Map1Color4.Points)
1622 FREE( ctx->EvalMap.Map1Color4.Points );
1623 if (ctx->EvalMap.Map1Normal.Points)
1624 FREE( ctx->EvalMap.Map1Normal.Points );
1625 if (ctx->EvalMap.Map1Texture1.Points)
1626 FREE( ctx->EvalMap.Map1Texture1.Points );
1627 if (ctx->EvalMap.Map1Texture2.Points)
1628 FREE( ctx->EvalMap.Map1Texture2.Points );
1629 if (ctx->EvalMap.Map1Texture3.Points)
1630 FREE( ctx->EvalMap.Map1Texture3.Points );
1631 if (ctx->EvalMap.Map1Texture4.Points)
1632 FREE( ctx->EvalMap.Map1Texture4.Points );
1633
1634 if (ctx->EvalMap.Map2Vertex3.Points)
1635 FREE( ctx->EvalMap.Map2Vertex3.Points );
1636 if (ctx->EvalMap.Map2Vertex4.Points)
1637 FREE( ctx->EvalMap.Map2Vertex4.Points );
1638 if (ctx->EvalMap.Map2Index.Points)
1639 FREE( ctx->EvalMap.Map2Index.Points );
1640 if (ctx->EvalMap.Map2Color4.Points)
1641 FREE( ctx->EvalMap.Map2Color4.Points );
1642 if (ctx->EvalMap.Map2Normal.Points)
1643 FREE( ctx->EvalMap.Map2Normal.Points );
1644 if (ctx->EvalMap.Map2Texture1.Points)
1645 FREE( ctx->EvalMap.Map2Texture1.Points );
1646 if (ctx->EvalMap.Map2Texture2.Points)
1647 FREE( ctx->EvalMap.Map2Texture2.Points );
1648 if (ctx->EvalMap.Map2Texture3.Points)
1649 FREE( ctx->EvalMap.Map2Texture3.Points );
1650 if (ctx->EvalMap.Map2Texture4.Points)
1651 FREE( ctx->EvalMap.Map2Texture4.Points );
1652
Brian Paul4bdcfe52000-04-17 17:57:04 +00001653 _mesa_free_colortable_data( &ctx->ColorTable );
1654 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1655 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1656 _mesa_free_colortable_data( &ctx->Texture.Palette );
1657
Brian Paul4d053dd2000-01-14 04:45:47 +00001658 /* Free cache of immediate buffers. */
1659 while (ctx->nr_im_queued-- > 0) {
1660 struct immediate * next = ctx->freed_im_queue->next;
Brian Paul2d8db392000-06-27 22:10:00 +00001661 ALIGN_FREE( ctx->freed_im_queue );
Brian Paul4d053dd2000-01-14 04:45:47 +00001662 ctx->freed_im_queue = next;
1663 }
1664 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001665
1666 FREE(ctx->Exec);
1667 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001668}
1669
1670
1671
1672/*
1673 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001674 */
Brian Paul178a1c52000-04-22 01:05:00 +00001675void
1676gl_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001677{
1678 if (ctx) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001679 gl_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001680 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001681 }
1682}
1683
1684
1685
1686/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001687 * Called by the driver after both the context and driver are fully
1688 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001689 */
Brian Paul178a1c52000-04-22 01:05:00 +00001690void
1691gl_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001692{
Brian Paul00037781999-12-17 14:52:35 +00001693 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001694}
1695
1696
1697
1698/*
1699 * Copy attribute groups from one context to another.
1700 * Input: src - source context
1701 * dst - destination context
1702 * mask - bitwise OR of GL_*_BIT flags
1703 */
Brian Paul178a1c52000-04-22 01:05:00 +00001704void
1705gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001706{
1707 if (mask & GL_ACCUM_BUFFER_BIT) {
1708 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1709 }
1710 if (mask & GL_COLOR_BUFFER_BIT) {
1711 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1712 }
1713 if (mask & GL_CURRENT_BIT) {
1714 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1715 }
1716 if (mask & GL_DEPTH_BUFFER_BIT) {
1717 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1718 }
1719 if (mask & GL_ENABLE_BIT) {
1720 /* no op */
1721 }
1722 if (mask & GL_EVAL_BIT) {
1723 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1724 }
1725 if (mask & GL_FOG_BIT) {
1726 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1727 }
1728 if (mask & GL_HINT_BIT) {
1729 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1730 }
1731 if (mask & GL_LIGHTING_BIT) {
1732 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001733 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001734 }
1735 if (mask & GL_LINE_BIT) {
1736 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1737 }
1738 if (mask & GL_LIST_BIT) {
1739 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1740 }
1741 if (mask & GL_PIXEL_MODE_BIT) {
1742 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1743 }
1744 if (mask & GL_POINT_BIT) {
1745 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1746 }
1747 if (mask & GL_POLYGON_BIT) {
1748 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1749 }
1750 if (mask & GL_POLYGON_STIPPLE_BIT) {
1751 /* Use loop instead of MEMCPY due to problem with Portland Group's
1752 * C compiler. Reported by John Stone.
1753 */
1754 int i;
1755 for (i=0;i<32;i++) {
1756 dst->PolygonStipple[i] = src->PolygonStipple[i];
1757 }
1758 }
1759 if (mask & GL_SCISSOR_BIT) {
1760 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1761 }
1762 if (mask & GL_STENCIL_BUFFER_BIT) {
1763 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1764 }
1765 if (mask & GL_TEXTURE_BIT) {
1766 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1767 }
1768 if (mask & GL_TRANSFORM_BIT) {
1769 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1770 }
1771 if (mask & GL_VIEWPORT_BIT) {
1772 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1773 }
1774}
1775
1776
jtgafb833d1999-08-19 00:55:39 +00001777/*
Brian Paul00037781999-12-17 14:52:35 +00001778 * Set the current context, binding the given frame buffer to the context.
1779 */
1780void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1781{
1782 gl_make_current2( newCtx, buffer, buffer );
1783}
1784
1785
1786/*
1787 * Bind the given context to the given draw-buffer and read-buffer
1788 * and make it the current context for this thread.
1789 */
1790void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1791 GLframebuffer *readBuffer )
1792{
1793#if 0
Brian Paulf9b97d92000-01-28 20:17:42 +00001794 GLcontext *oldCtx = gl_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001795
1796 /* Flush the old context
1797 */
1798 if (oldCtx) {
1799 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
1800
1801 /* unbind frame buffers from context */
1802 if (oldCtx->DrawBuffer) {
1803 oldCtx->DrawBuffer = NULL;
1804 }
1805 if (oldCtx->ReadBuffer) {
1806 oldCtx->ReadBuffer = NULL;
1807 }
1808 }
1809#endif
1810
1811 /* We call this function periodically (just here for now) in
1812 * order to detect when multithreading has begun.
1813 */
1814 _glapi_check_multithread();
1815
Brian Paulf9b97d92000-01-28 20:17:42 +00001816 _glapi_set_context((void *) newCtx);
Brian Paul00037781999-12-17 14:52:35 +00001817 ASSERT(gl_get_current_context() == newCtx);
1818 if (newCtx) {
1819 SET_IMMEDIATE(newCtx, newCtx->input);
1820 _glapi_set_dispatch(newCtx->CurrentDispatch);
1821 }
1822 else {
1823 _glapi_set_dispatch(NULL); /* none current */
1824 }
1825
1826 if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
1827
1828 if (newCtx && drawBuffer && readBuffer) {
1829 /* TODO: check if newCtx and buffer's visual match??? */
1830 newCtx->DrawBuffer = drawBuffer;
1831 newCtx->ReadBuffer = readBuffer;
1832 newCtx->NewState = NEW_ALL; /* just to be safe */
1833 gl_update_state( newCtx );
1834 }
1835
1836 /* We can use this to help debug user's problems. Tell the to set
1837 * the MESA_INFO env variable before running their app. Then the
1838 * first time each context is made current we'll print some useful
1839 * information.
1840 */
1841 if (newCtx && newCtx->FirstTimeCurrent) {
1842 if (getenv("MESA_INFO")) {
1843 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1844 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1845 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1846 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
Brian Paul09cb1481999-12-17 17:00:32 +00001847#if defined(THREADS)
1848 fprintf(stderr, "Mesa thread-safe: YES\n");
1849#else
1850 fprintf(stderr, "Mesa thread-safe: NO\n");
1851#endif
Brian Paul54287052000-01-17 20:00:15 +00001852#if defined(USE_X86_ASM)
1853 fprintf(stderr, "Mesa x86-optimized: YES\n");
1854#else
1855 fprintf(stderr, "Mesa x86-optimized: NO\n");
1856#endif
Brian Paul00037781999-12-17 14:52:35 +00001857 }
1858 newCtx->FirstTimeCurrent = GL_FALSE;
1859 }
1860}
1861
1862
1863
1864/*
1865 * Return current context handle for the calling thread.
1866 * This isn't the fastest way to get the current context.
1867 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1868 */
1869GLcontext *gl_get_current_context( void )
1870{
Brian Paulf9b97d92000-01-28 20:17:42 +00001871 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001872}
1873
1874
1875
1876/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001877 * This should be called by device drivers just before they do a
1878 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001879 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001880void
1881_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001882{
Brian Paulfbd8f211999-11-11 01:22:25 +00001883 FLUSH_VB( ctx, "swap buffers" );
jtgafb833d1999-08-19 00:55:39 +00001884}
1885
1886
Brian Paul00037781999-12-17 14:52:35 +00001887
Brian Paulfbd8f211999-11-11 01:22:25 +00001888/*
1889 * Return pointer to this context's current API dispatch table.
1890 * It'll either be the immediate-mode execute dispatcher or the
1891 * display list compile dispatcher.
1892 */
1893struct _glapi_table *
1894_mesa_get_dispatch(GLcontext *ctx)
1895{
1896 return ctx->CurrentDispatch;
1897}
1898
1899
1900
jtgafb833d1999-08-19 00:55:39 +00001901/**********************************************************************/
1902/***** Miscellaneous functions *****/
1903/**********************************************************************/
1904
1905
1906/*
1907 * This function is called when the Mesa user has stumbled into a code
1908 * path which may not be implemented fully or correctly.
1909 */
1910void gl_problem( const GLcontext *ctx, const char *s )
1911{
1912 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paul413d6a22000-05-26 14:44:59 +00001913 fprintf( stderr, "Report to Mesa bug database at www.mesa3d.org\n" );
jtgafb833d1999-08-19 00:55:39 +00001914 (void) ctx;
1915}
1916
1917
1918
1919/*
1920 * This is called to inform the user that he or she has tried to do
1921 * something illogical or if there's likely a bug in their program
1922 * (like enabled depth testing without a depth buffer).
1923 */
1924void gl_warning( const GLcontext *ctx, const char *s )
1925{
1926 GLboolean debug;
1927#ifdef DEBUG
1928 debug = GL_TRUE;
1929#else
1930 if (getenv("MESA_DEBUG")) {
1931 debug = GL_TRUE;
1932 }
1933 else {
1934 debug = GL_FALSE;
1935 }
1936#endif
1937 if (debug) {
1938 fprintf( stderr, "Mesa warning: %s\n", s );
1939 }
1940 (void) ctx;
1941}
1942
1943
1944
Brian Paulfa9df402000-02-02 19:16:46 +00001945/*
1946 * Compile an error into current display list.
1947 */
jtgafb833d1999-08-19 00:55:39 +00001948void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
1949{
1950 if (ctx->CompileFlag)
1951 gl_save_error( ctx, error, s );
1952
1953 if (ctx->ExecuteFlag)
1954 gl_error( ctx, error, s );
1955}
1956
1957
Brian Paulfa9df402000-02-02 19:16:46 +00001958
jtgafb833d1999-08-19 00:55:39 +00001959/*
1960 * This is Mesa's error handler. Normally, all that's done is the updating
1961 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1962 * environment variable "MESA_DEBUG" is defined then a real error message
1963 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001964 * Input: ctx - the GL context
1965 * error - the error value
1966 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001967 */
Brian Paul7eb06032000-07-14 04:13:40 +00001968void
1969gl_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001970{
Brian Paul7eb06032000-07-14 04:13:40 +00001971 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001972 GLboolean debug;
1973
1974#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00001975 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00001976 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00001977 else
1978 debug = GL_TRUE;
1979#else
1980 if (debugEnv)
1981 debug = GL_TRUE;
1982 else
1983 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001984#endif
1985
1986 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00001987 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00001988 switch (error) {
1989 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00001990 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00001991 break;
1992 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00001993 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00001994 break;
1995 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00001996 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00001997 break;
1998 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00001999 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002000 break;
2001 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002002 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002003 break;
2004 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002005 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002006 break;
2007 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002008 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002009 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002010 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002011 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002012 break;
jtgafb833d1999-08-19 00:55:39 +00002013 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002014 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002015 break;
2016 }
Brian Paul7eb06032000-07-14 04:13:40 +00002017 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002018 }
2019
Brian Paul7eb06032000-07-14 04:13:40 +00002020 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002021 ctx->ErrorValue = error;
2022 }
2023
2024 /* Call device driver's error handler, if any. This is used on the Mac. */
2025 if (ctx->Driver.Error) {
2026 (*ctx->Driver.Error)( ctx );
2027 }
2028}
2029
2030
2031
Brian Paulfa9df402000-02-02 19:16:46 +00002032void
2033_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002034{
Brian Paulfa9df402000-02-02 19:16:46 +00002035 GET_CURRENT_CONTEXT(ctx);
2036 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
2037 if (ctx->Driver.Finish) {
2038 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002039 }
2040}
2041
2042
2043
Brian Paulfa9df402000-02-02 19:16:46 +00002044void
2045_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002046{
Brian Paulfa9df402000-02-02 19:16:46 +00002047 GET_CURRENT_CONTEXT(ctx);
2048 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
2049 if (ctx->Driver.Flush) {
2050 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002051 }
jtgafb833d1999-08-19 00:55:39 +00002052}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002053
2054
2055
2056const char *_mesa_prim_name[GL_POLYGON+2] = {
2057 "GL_POINTS",
2058 "GL_LINES",
2059 "GL_LINE_LOOP",
2060 "GL_LINE_STRIP",
2061 "GL_TRIANGLES",
2062 "GL_TRIANGLE_STRIP",
2063 "GL_TRIANGLE_FAN",
2064 "GL_QUADS",
2065 "GL_QUAD_STRIP",
2066 "GL_POLYGON",
2067 "culled primitive"
2068};
2069