blob: c0e75e929848570293f9369defaac812f1ae63f2 [file] [log] [blame]
Keith Whitwell23caf202000-11-16 21:05:34 +00001/* $Id: context.c,v 1.106 2000/11/16 21:05:34 keithw 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"
jtgafb833d1999-08-19 00:55:39 +000036#include "dlist.h"
37#include "eval.h"
38#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000039#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000041#include "get.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000042#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000043#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000044#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000045#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000046#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000047#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000048#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "mmath.h"
jtgafb833d1999-08-19 00:55:39 +000050#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +000051#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000052#include "teximage.h"
53#include "texobj.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "texture.h"
55#include "types.h"
56#include "varray.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000057
58#include "math/m_translate.h"
59#include "math/m_vertices.h"
60#include "math/m_matrix.h"
61#include "math/m_xform.h"
62#include "math/math.h"
jtgafb833d1999-08-19 00:55:39 +000063#endif
64
Brian Paul3b18a362000-09-26 15:27:20 +000065#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000066#include "Trace/tr_context.h"
67#include "Trace/tr_wrapper.h"
68#endif
69
jtgafb833d1999-08-19 00:55:39 +000070
Keith Whitwell23caf202000-11-16 21:05:34 +000071#ifndef MESA_VERBOSE
72int MESA_VERBOSE = 0
73/* | VERBOSE_PIPELINE */
74/* | VERBOSE_IMMEDIATE */
75/* | VERBOSE_VARRAY */
76/* | VERBOSE_TEXTURE */
77/* | VERBOSE_API */
78/* | VERBOSE_DRIVER */
79/* | VERBOSE_STATE */
80/* | VERBOSE_CULL */
81/* | VERBOSE_DISPLAY_LIST */
82;
83#endif
84
85#ifndef MESA_DEBUG_FLAGS
86int MESA_DEBUG_FLAGS = 0
87/* | DEBUG_ALWAYS_FLUSH */
88;
89#endif
Brian Paulb1394fa2000-09-26 20:53:53 +000090
91/**********************************************************************/
92/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
93/**********************************************************************/
94
95static GLboolean
96_mesa_DestroyContext(__GLcontext *gc)
97{
98 if (gc) {
99 _mesa_free_context_data(gc);
100 (*gc->imports.free)(gc, gc);
101 }
102 return GL_TRUE;
103}
104
105
106/* exported OpenGL SI interface */
107__GLcontext *
108__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
109{
110 GLcontext *ctx;
111
112 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
113 if (ctx == NULL) {
114 return NULL;
115 }
116 ctx->imports = *imports;
117
118 _mesa_initialize_visual(&ctx->Visual,
119 modes->rgbMode,
120 modes->doubleBufferMode,
121 modes->stereoMode,
122 modes->redBits,
123 modes->greenBits,
124 modes->blueBits,
125 modes->alphaBits,
126 modes->indexBits,
127 modes->depthBits,
128 modes->stencilBits,
129 modes->accumRedBits,
130 modes->accumGreenBits,
131 modes->accumBlueBits,
132 modes->accumAlphaBits,
133 0);
134
135 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->wscx, GL_FALSE);
136
137 ctx->exports.destroyContext = _mesa_DestroyContext;
138
139 return ctx;
140}
141
142
143/* exported OpenGL SI interface */
144void
145__glCoreNopDispatch(void)
146{
147#if 0
148 /* SI */
149 __gl_dispatch = __glNopDispatchState;
150#else
151 /* Mesa */
152 _glapi_set_dispatch(NULL);
153#endif
154}
155
156
jtgafb833d1999-08-19 00:55:39 +0000157/**********************************************************************/
158/***** Context and Thread management *****/
159/**********************************************************************/
160
161
jtgafb833d1999-08-19 00:55:39 +0000162
jtgafb833d1999-08-19 00:55:39 +0000163/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000164/***** GL Visual allocation/destruction *****/
165/**********************************************************************/
166
167
168/*
169 * Allocate a new GLvisual object.
170 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000171 * dbFlag - double buffering?
172 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000173 * depthBits - requested bits per depth buffer value
174 * Any value in [0, 32] is acceptable but the actual
175 * depth type will be GLushort or GLuint as needed.
176 * stencilBits - requested minimum bits per stencil buffer value
177 * accumBits - requested minimum bits per accum buffer component
178 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
179 * red/green/blue/alphaBits - number of bits per color component
180 * in frame buffer for RGB(A) mode.
181 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000182 * Return: pointer to new GLvisual or NULL if requested parameters can't
183 * be met.
184 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000185GLvisual *
186_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000187 GLboolean dbFlag,
188 GLboolean stereoFlag,
189 GLint redBits,
190 GLint greenBits,
191 GLint blueBits,
192 GLint alphaBits,
193 GLint indexBits,
194 GLint depthBits,
195 GLint stencilBits,
196 GLint accumRedBits,
197 GLint accumGreenBits,
198 GLint accumBlueBits,
199 GLint accumAlphaBits,
200 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000201{
Brian Paul178a1c52000-04-22 01:05:00 +0000202 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
203 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000204 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000205 redBits, greenBits, blueBits, alphaBits,
206 indexBits, depthBits, stencilBits,
207 accumRedBits, accumGreenBits,
208 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000209 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000210 FREE(vis);
211 return NULL;
212 }
213 }
214 return vis;
215}
216
217
218/*
219 * Initialize the fields of the given GLvisual.
220 * Input: see _mesa_create_visual() above.
221 * Return: GL_TRUE = success
222 * GL_FALSE = failure.
223 */
224GLboolean
225_mesa_initialize_visual( GLvisual *vis,
226 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000227 GLboolean dbFlag,
228 GLboolean stereoFlag,
229 GLint redBits,
230 GLint greenBits,
231 GLint blueBits,
232 GLint alphaBits,
233 GLint indexBits,
234 GLint depthBits,
235 GLint stencilBits,
236 GLint accumRedBits,
237 GLint accumGreenBits,
238 GLint accumBlueBits,
239 GLint accumAlphaBits,
240 GLint numSamples )
241{
242 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000243
Brian Pauled30dfa2000-03-03 17:47:39 +0000244 /* This is to catch bad values from device drivers not updated for
245 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
246 * bad value now (a 1-bit depth buffer!?!).
247 */
248 assert(depthBits == 0 || depthBits > 1);
249
250 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000251 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000252 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000253 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000254 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000255 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000256 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000257 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000258 }
259 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000260 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000261 }
262 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000263 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000264 }
265 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000266 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000267 }
268
269 vis->RGBAflag = rgbFlag;
270 vis->DBflag = dbFlag;
271 vis->StereoFlag = stereoFlag;
272 vis->RedBits = redBits;
273 vis->GreenBits = greenBits;
274 vis->BlueBits = blueBits;
Brian Paule70c6232000-05-04 13:53:55 +0000275 vis->AlphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000276
Brian Paulb371e0d2000-03-31 01:05:51 +0000277 vis->IndexBits = indexBits;
278 vis->DepthBits = depthBits;
279 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
280 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
281 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
282 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
283 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000284
Brian Pauled30dfa2000-03-03 17:47:39 +0000285 if (depthBits == 0) {
286 /* Special case. Even if we don't have a depth buffer we need
Brian Paul35324a62000-10-09 22:42:40 +0000287 * good values for DepthMax for Z vertex transformation purposes
288 * and for per-fragment fog computation.
Brian Pauled30dfa2000-03-03 17:47:39 +0000289 */
Brian Paul35324a62000-10-09 22:42:40 +0000290 vis->DepthMax = 1 << 16;
291 vis->DepthMaxF = (GLfloat) vis->DepthMax;
Brian Pauled30dfa2000-03-03 17:47:39 +0000292 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000293 else if (depthBits < 32) {
Brian Pauled30dfa2000-03-03 17:47:39 +0000294 vis->DepthMax = (1 << depthBits) - 1;
295 vis->DepthMaxF = (GLfloat) vis->DepthMax;
296 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000297 else {
298 /* Special case since shift values greater than or equal to the
299 * number of bits in the left hand expression's type are
300 * undefined.
301 */
302 vis->DepthMax = 0xffffffff;
303 vis->DepthMaxF = (GLfloat) vis->DepthMax;
304 }
Brian Pauld0d7d622000-10-21 00:02:47 +0000305 vis->MRD = 1; /* XXX temporary value */
Brian Pauled30dfa2000-03-03 17:47:39 +0000306
Brian Paul178a1c52000-04-22 01:05:00 +0000307 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000308}
309
310
Brian Paulb371e0d2000-03-31 01:05:51 +0000311void
312_mesa_destroy_visual( GLvisual *vis )
313{
314 FREE(vis);
315}
316
317
Brian Paul4d053dd2000-01-14 04:45:47 +0000318/**********************************************************************/
319/***** GL Framebuffer allocation/destruction *****/
320/**********************************************************************/
321
322
323/*
324 * Create a new framebuffer. A GLframebuffer is a struct which
325 * encapsulates the depth, stencil and accum buffers and related
326 * parameters.
327 * Input: visual - a GLvisual pointer
328 * softwareDepth - create/use a software depth buffer?
329 * softwareStencil - create/use a software stencil buffer?
330 * softwareAccum - create/use a software accum buffer?
331 * softwareAlpha - create/use a software alpha buffer?
332
333 * Return: pointer to new GLframebuffer struct or NULL if error.
334 */
Brian Paul178a1c52000-04-22 01:05:00 +0000335GLframebuffer *
Brian Paulb1394fa2000-09-26 20:53:53 +0000336_mesa_create_framebuffer( GLvisual *visual,
337 GLboolean softwareDepth,
338 GLboolean softwareStencil,
339 GLboolean softwareAccum,
340 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000341{
Brian Paul178a1c52000-04-22 01:05:00 +0000342 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
343 assert(visual);
344 if (buffer) {
345 _mesa_initialize_framebuffer(buffer, visual,
346 softwareDepth, softwareStencil,
347 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000348 }
Brian Paul178a1c52000-04-22 01:05:00 +0000349 return buffer;
350}
351
352
353/*
354 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000355 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000356 */
357void
358_mesa_initialize_framebuffer( GLframebuffer *buffer,
359 GLvisual *visual,
360 GLboolean softwareDepth,
361 GLboolean softwareStencil,
362 GLboolean softwareAccum,
363 GLboolean softwareAlpha )
364{
365 assert(buffer);
366 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000367
368 /* sanity checks */
369 if (softwareDepth ) {
370 assert(visual->DepthBits > 0);
371 }
372 if (softwareStencil) {
373 assert(visual->StencilBits > 0);
374 }
375 if (softwareAccum) {
376 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000377 assert(visual->AccumRedBits > 0);
378 assert(visual->AccumGreenBits > 0);
379 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000380 }
381 if (softwareAlpha) {
382 assert(visual->RGBAflag);
383 assert(visual->AlphaBits > 0);
384 }
385
386 buffer->Visual = visual;
387 buffer->UseSoftwareDepthBuffer = softwareDepth;
388 buffer->UseSoftwareStencilBuffer = softwareStencil;
389 buffer->UseSoftwareAccumBuffer = softwareAccum;
390 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000391}
392
393
Brian Paul4d053dd2000-01-14 04:45:47 +0000394/*
395 * Free a framebuffer struct and its buffers.
396 */
Brian Paul178a1c52000-04-22 01:05:00 +0000397void
Brian Paulb1394fa2000-09-26 20:53:53 +0000398_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000399{
400 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000401 if (buffer->DepthBuffer) {
402 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000403 }
404 if (buffer->Accum) {
405 FREE( buffer->Accum );
406 }
407 if (buffer->Stencil) {
408 FREE( buffer->Stencil );
409 }
410 if (buffer->FrontLeftAlpha) {
411 FREE( buffer->FrontLeftAlpha );
412 }
413 if (buffer->BackLeftAlpha) {
414 FREE( buffer->BackLeftAlpha );
415 }
416 if (buffer->FrontRightAlpha) {
417 FREE( buffer->FrontRightAlpha );
418 }
419 if (buffer->BackRightAlpha) {
420 FREE( buffer->BackRightAlpha );
421 }
422 FREE(buffer);
423 }
424}
425
426
427
428/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000429/***** Context allocation, initialization, destroying *****/
430/**********************************************************************/
431
432
Brian Paul9560f052000-01-31 23:11:39 +0000433_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
434
435
jtgafb833d1999-08-19 00:55:39 +0000436/*
437 * This function just calls all the various one-time-init functions in Mesa.
438 */
Brian Paul178a1c52000-04-22 01:05:00 +0000439static void
440one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000441{
442 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000443 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000444 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000445 /* do some implementation tests */
446 assert( sizeof(GLbyte) == 1 );
447 assert( sizeof(GLshort) >= 2 );
448 assert( sizeof(GLint) >= 4 );
449 assert( sizeof(GLubyte) == 1 );
450 assert( sizeof(GLushort) >= 2 );
451 assert( sizeof(GLuint) >= 4 );
452
jtgafb833d1999-08-19 00:55:39 +0000453 gl_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000454
455 _mesa_init_math();
456 _math_init();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000457
458 if (getenv("MESA_DEBUG")) {
459 _glapi_noop_enable_warnings(GL_TRUE);
460 }
461 else {
462 _glapi_noop_enable_warnings(GL_FALSE);
463 }
464
jtgafb833d1999-08-19 00:55:39 +0000465#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
466 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
467#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000468
469 alreadyCalled = GL_TRUE;
470 }
Brian Paul9560f052000-01-31 23:11:39 +0000471 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000472}
473
474
Brian Paul4d053dd2000-01-14 04:45:47 +0000475
jtgafb833d1999-08-19 00:55:39 +0000476/*
477 * Allocate and initialize a shared context state structure.
478 */
Brian Paul178a1c52000-04-22 01:05:00 +0000479static struct gl_shared_state *
480alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000481{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000482 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000483 struct gl_shared_state *ss;
484 GLboolean outOfMemory;
485
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000486 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000487 if (!ss)
488 return NULL;
489
Brian Paule4b684c2000-09-12 21:07:40 +0000490 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000491
Brian Paule4b684c2000-09-12 21:07:40 +0000492 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000493 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000494
495 /* Default Texture objects */
496 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000497 for (d = 1 ; d <= 3 ; d++) {
498 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
499 if (!ss->DefaultD[d]) {
500 outOfMemory = GL_TRUE;
501 break;
jtgafb833d1999-08-19 00:55:39 +0000502 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000503 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000504 }
505
Brian Paul413d6a22000-05-26 14:44:59 +0000506 ss->DefaultCubeMap = gl_alloc_texture_object(ss, 0, 6);
507 if (!ss->DefaultCubeMap) {
508 outOfMemory = GL_TRUE;
509 }
510 else {
511 ss->DefaultCubeMap->RefCount++;
512 }
513
jtgafb833d1999-08-19 00:55:39 +0000514 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
515 /* Ran out of memory at some point. Free everything and return NULL */
516 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000517 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000518 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000519 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000520 if (ss->DefaultD[1])
521 gl_free_texture_object(ss, ss->DefaultD[1]);
522 if (ss->DefaultD[2])
523 gl_free_texture_object(ss, ss->DefaultD[2]);
524 if (ss->DefaultD[3])
525 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paul413d6a22000-05-26 14:44:59 +0000526 if (ss->DefaultCubeMap)
527 gl_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000528 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000529 return NULL;
530 }
531 else {
532 return ss;
533 }
534}
535
536
537/*
538 * Deallocate a shared state context and all children structures.
539 */
Brian Paul178a1c52000-04-22 01:05:00 +0000540static void
541free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000542{
543 /* Free display lists */
544 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000545 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000546 if (list) {
547 gl_destroy_list(ctx, list);
548 }
549 else {
550 break;
551 }
552 }
Brian Paulbb797902000-01-24 16:19:54 +0000553 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000554
555 /* Free texture objects */
556 while (ss->TexObjectList)
557 {
558 if (ctx->Driver.DeleteTexture)
559 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
560 /* this function removes from linked list too! */
561 gl_free_texture_object(ss, ss->TexObjectList);
562 }
Brian Paulbb797902000-01-24 16:19:54 +0000563 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000564
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000565 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000566}
567
568
569
jtgafb833d1999-08-19 00:55:39 +0000570/*
571 * Initialize the nth light. Note that the defaults for light 0 are
572 * different than the other lights.
573 */
Brian Paul178a1c52000-04-22 01:05:00 +0000574static void
575init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000576{
577 make_empty_list( l );
578
579 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
580 if (n==0) {
581 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
582 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
583 }
584 else {
585 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
586 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
587 }
588 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
589 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
590 l->SpotExponent = 0.0;
591 gl_compute_spot_exp_table( l );
592 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000593 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000594 l->ConstantAttenuation = 1.0;
595 l->LinearAttenuation = 0.0;
596 l->QuadraticAttenuation = 0.0;
597 l->Enabled = GL_FALSE;
598}
599
600
601
Brian Paul178a1c52000-04-22 01:05:00 +0000602static void
603init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000604{
605 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
606 lm->LocalViewer = GL_FALSE;
607 lm->TwoSide = GL_FALSE;
608 lm->ColorControl = GL_SINGLE_COLOR;
609}
610
611
Brian Paul178a1c52000-04-22 01:05:00 +0000612static void
613init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000614{
615 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
616 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
617 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
618 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
619 m->Shininess = 0.0;
620 m->AmbientIndex = 0;
621 m->DiffuseIndex = 1;
622 m->SpecularIndex = 1;
623}
624
625
626
Brian Paul178a1c52000-04-22 01:05:00 +0000627static void
628init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000629{
630 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
631
632 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000633 texUnit->CombineModeRGB = GL_MODULATE;
634 texUnit->CombineModeA = GL_MODULATE;
635 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
636 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
637 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
638 texUnit->CombineSourceA[0] = GL_TEXTURE;
639 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
640 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
641 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
642 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
643 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
644 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
645 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
646 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
647 texUnit->CombineScaleShiftRGB = 0;
648 texUnit->CombineScaleShiftA = 0;
649
jtgafb833d1999-08-19 00:55:39 +0000650 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
651 texUnit->TexGenEnabled = 0;
652 texUnit->GenModeS = GL_EYE_LINEAR;
653 texUnit->GenModeT = GL_EYE_LINEAR;
654 texUnit->GenModeR = GL_EYE_LINEAR;
655 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000656 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
657 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
658 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
659 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000660
jtgafb833d1999-08-19 00:55:39 +0000661 /* Yes, these plane coefficients are correct! */
662 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
664 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
665 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
666 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
667 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
668 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
669 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
670
Brian Paul6e6d4c61999-10-09 20:17:07 +0000671 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
672 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
673 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
Brian Paul413d6a22000-05-26 14:44:59 +0000674 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000675}
676
677
Brian Paul178a1c52000-04-22 01:05:00 +0000678static void
679init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000680{
681 struct gl_client_array *cl;
682 GLuint i;
683
684 cl = &ctx->Fallback.Normal;
685 cl->Size = 3;
686 cl->Type = GL_FLOAT;
687 cl->Stride = 0;
688 cl->StrideB = 0;
689 cl->Ptr = (void *) ctx->Current.Normal;
690 cl->Enabled = 1;
691
692 cl = &ctx->Fallback.Color;
693 cl->Size = 4;
694 cl->Type = GL_UNSIGNED_BYTE;
695 cl->Stride = 0;
696 cl->StrideB = 0;
Brian Paul19300532000-10-29 19:02:23 +0000697 cl->Ptr = (void *) ctx->Current.Color;
jtgafb833d1999-08-19 00:55:39 +0000698 cl->Enabled = 1;
699
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000700 cl = &ctx->Fallback.SecondaryColor;
701 cl->Size = 3;
702 cl->Type = GL_UNSIGNED_BYTE;
703 cl->Stride = 0;
704 cl->StrideB = 0;
705 cl->Ptr = (void *) ctx->Current.SecondaryColor;
706 cl->Enabled = 1;
707
708 cl = &ctx->Fallback.FogCoord;
709 cl->Size = 1;
710 cl->Type = GL_FLOAT;
711 cl->Stride = 0;
712 cl->StrideB = 0;
713 cl->Ptr = (void *) &ctx->Current.FogCoord;
714 cl->Enabled = 1;
715
jtgafb833d1999-08-19 00:55:39 +0000716 cl = &ctx->Fallback.Index;
717 cl->Size = 1;
718 cl->Type = GL_UNSIGNED_INT;
719 cl->Stride = 0;
720 cl->StrideB = 0;
721 cl->Ptr = (void *) &ctx->Current.Index;
722 cl->Enabled = 1;
723
724 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
725 cl = &ctx->Fallback.TexCoord[i];
726 cl->Size = 4;
727 cl->Type = GL_FLOAT;
728 cl->Stride = 0;
729 cl->StrideB = 0;
730 cl->Ptr = (void *) ctx->Current.Texcoord[i];
731 cl->Enabled = 1;
732 }
733
734 cl = &ctx->Fallback.EdgeFlag;
735 cl->Size = 1;
736 cl->Type = GL_UNSIGNED_BYTE;
737 cl->Stride = 0;
738 cl->StrideB = 0;
739 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
740 cl->Enabled = 1;
741}
742
Brian Paul4d053dd2000-01-14 04:45:47 +0000743
jtgafb833d1999-08-19 00:55:39 +0000744/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000745static void
746init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000747{
748 map->Order = 1;
749 map->u1 = 0.0;
750 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000751 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000752 if (map->Points) {
753 GLint i;
754 for (i=0;i<n;i++)
755 map->Points[i] = initial[i];
756 }
jtgafb833d1999-08-19 00:55:39 +0000757}
758
759
760/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000761static void
762init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000763{
764 map->Uorder = 1;
765 map->Vorder = 1;
766 map->u1 = 0.0;
767 map->u2 = 1.0;
768 map->v1 = 0.0;
769 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000770 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000771 if (map->Points) {
772 GLint i;
773 for (i=0;i<n;i++)
774 map->Points[i] = initial[i];
775 }
jtgafb833d1999-08-19 00:55:39 +0000776}
777
778
jtgafb833d1999-08-19 00:55:39 +0000779/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000780 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000781 */
Brian Paul178a1c52000-04-22 01:05:00 +0000782static void
783init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000784{
785 GLuint i, j;
786
Brian Paul4d053dd2000-01-14 04:45:47 +0000787 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000788
Brian Paul539cce52000-02-03 19:40:07 +0000789 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000790 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
791 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000792 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000793 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
794 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000795 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
796 ctx->Const.MinPointSize = MIN_POINT_SIZE;
797 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
798 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
799 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
800 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
801 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
802 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
803 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
804 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
805 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
806 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000807 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000808 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
809 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000810 ctx->Const.NumCompressedTextureFormats = 0;
jtgafb833d1999-08-19 00:55:39 +0000811
Brian Paul4d053dd2000-01-14 04:45:47 +0000812 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000813 _math_matrix_ctr( &ctx->ModelView );
814 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000815
816 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000817 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000818 _math_matrix_ctr( &ctx->ModelViewStack[i] );
819 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000820 }
821
822 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000823 _math_matrix_ctr( &ctx->ProjectionMatrix );
824 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000825
826 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000827 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000828 _math_matrix_ctr( &ctx->ProjectionStack[i] );
829 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000830 }
831
Keith Whitwell23caf202000-11-16 21:05:34 +0000832 /* Derived ModelProject matrix */
833 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
834
Brian Paul4d053dd2000-01-14 04:45:47 +0000835 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000836 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000837 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000838 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000839 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000840 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000841 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000842 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000843 }
jtgafb833d1999-08-19 00:55:39 +0000844
Brian Paul250069d2000-04-08 18:57:45 +0000845 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000846 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000847 ctx->ColorStackDepth = 0;
848 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000849 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000850 }
851
Brian Paul4d053dd2000-01-14 04:45:47 +0000852 /* Accumulate buffer group */
853 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000854
Brian Paul4d053dd2000-01-14 04:45:47 +0000855 /* Color buffer group */
856 ctx->Color.IndexMask = 0xffffffff;
857 ctx->Color.ColorMask[0] = 0xff;
858 ctx->Color.ColorMask[1] = 0xff;
859 ctx->Color.ColorMask[2] = 0xff;
860 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000861 ctx->Color.ClearIndex = 0;
862 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
863 ctx->Color.DrawBuffer = GL_FRONT;
864 ctx->Color.AlphaEnabled = GL_FALSE;
865 ctx->Color.AlphaFunc = GL_ALWAYS;
866 ctx->Color.AlphaRef = 0;
867 ctx->Color.BlendEnabled = GL_FALSE;
868 ctx->Color.BlendSrcRGB = GL_ONE;
869 ctx->Color.BlendDstRGB = GL_ZERO;
870 ctx->Color.BlendSrcA = GL_ONE;
871 ctx->Color.BlendDstA = GL_ZERO;
872 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000873 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
874 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
875 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000876 ctx->Color.LogicOp = GL_COPY;
877 ctx->Color.DitherFlag = GL_TRUE;
878 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000879
Brian Paul4d053dd2000-01-14 04:45:47 +0000880 /* Current group */
Brian Paul19300532000-10-29 19:02:23 +0000881 ASSIGN_4V( ctx->Current.Color, CHAN_MAX, CHAN_MAX, CHAN_MAX, CHAN_MAX );
Brian Paul4d053dd2000-01-14 04:45:47 +0000882 ctx->Current.Index = 1;
883 for (i=0; i<MAX_TEXTURE_UNITS; i++)
884 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
885 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
886 ctx->Current.RasterDistance = 0.0;
887 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
888 ctx->Current.RasterIndex = 1;
889 for (i=0; i<MAX_TEXTURE_UNITS; i++)
890 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
891 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
892 ctx->Current.RasterPosValid = GL_TRUE;
893 ctx->Current.EdgeFlag = GL_TRUE;
894 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000895
Brian Paul4d053dd2000-01-14 04:45:47 +0000896 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000897
Brian Paul4d053dd2000-01-14 04:45:47 +0000898 /* Depth buffer group */
899 ctx->Depth.Test = GL_FALSE;
900 ctx->Depth.Clear = 1.0;
901 ctx->Depth.Func = GL_LESS;
902 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000903 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000904
Brian Paul4d053dd2000-01-14 04:45:47 +0000905 /* Evaluators group */
906 ctx->Eval.Map1Color4 = GL_FALSE;
907 ctx->Eval.Map1Index = GL_FALSE;
908 ctx->Eval.Map1Normal = GL_FALSE;
909 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
910 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
911 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
912 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
913 ctx->Eval.Map1Vertex3 = GL_FALSE;
914 ctx->Eval.Map1Vertex4 = GL_FALSE;
915 ctx->Eval.Map2Color4 = GL_FALSE;
916 ctx->Eval.Map2Index = GL_FALSE;
917 ctx->Eval.Map2Normal = GL_FALSE;
918 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
919 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
920 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
921 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
922 ctx->Eval.Map2Vertex3 = GL_FALSE;
923 ctx->Eval.Map2Vertex4 = GL_FALSE;
924 ctx->Eval.AutoNormal = GL_FALSE;
925 ctx->Eval.MapGrid1un = 1;
926 ctx->Eval.MapGrid1u1 = 0.0;
927 ctx->Eval.MapGrid1u2 = 1.0;
928 ctx->Eval.MapGrid2un = 1;
929 ctx->Eval.MapGrid2vn = 1;
930 ctx->Eval.MapGrid2u1 = 0.0;
931 ctx->Eval.MapGrid2u2 = 1.0;
932 ctx->Eval.MapGrid2v1 = 0.0;
933 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000934
Brian Paul4d053dd2000-01-14 04:45:47 +0000935 /* Evaluator data */
936 {
937 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
938 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
939 static GLfloat index[1] = { 1.0 };
940 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
941 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000942
Brian Paul4d053dd2000-01-14 04:45:47 +0000943 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
944 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
945 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
946 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
947 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
948 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
949 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
950 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
951 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000952
Brian Paul4d053dd2000-01-14 04:45:47 +0000953 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
954 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
955 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
956 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
957 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
958 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
959 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
960 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
961 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
962 }
jtgafb833d1999-08-19 00:55:39 +0000963
Brian Paul4d053dd2000-01-14 04:45:47 +0000964 /* Fog group */
965 ctx->Fog.Enabled = GL_FALSE;
966 ctx->Fog.Mode = GL_EXP;
967 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
968 ctx->Fog.Index = 0.0;
969 ctx->Fog.Density = 1.0;
970 ctx->Fog.Start = 0.0;
971 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000972 ctx->Fog.ColorSumEnabled = GL_FALSE;
973 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000974
Brian Paul4d053dd2000-01-14 04:45:47 +0000975 /* Hint group */
976 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
977 ctx->Hint.PointSmooth = GL_DONT_CARE;
978 ctx->Hint.LineSmooth = GL_DONT_CARE;
979 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
980 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000981 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000982 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000983 ctx->Hint.AllowDrawMem = GL_TRUE;
984 ctx->Hint.StrictLighting = GL_TRUE;
Brian Paul1207bf02000-05-23 20:10:49 +0000985 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
986 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000987
Brian Paul0771d152000-04-07 00:19:41 +0000988 /* Histogram group */
989 ctx->Histogram.Width = 0;
990 ctx->Histogram.Format = GL_RGBA;
991 ctx->Histogram.Sink = GL_FALSE;
992 ctx->Histogram.RedSize = 0xffffffff;
993 ctx->Histogram.GreenSize = 0xffffffff;
994 ctx->Histogram.BlueSize = 0xffffffff;
995 ctx->Histogram.AlphaSize = 0xffffffff;
996 ctx->Histogram.LuminanceSize = 0xffffffff;
997 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
998 ctx->Histogram.Count[i][0] = 0;
999 ctx->Histogram.Count[i][1] = 0;
1000 ctx->Histogram.Count[i][2] = 0;
1001 ctx->Histogram.Count[i][3] = 0;
1002 }
1003
1004 /* Min/Max group */
1005 ctx->MinMax.Format = GL_RGBA;
1006 ctx->MinMax.Sink = GL_FALSE;
1007 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
1008 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
1009 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
1010 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
1011
Brian Paul4d053dd2000-01-14 04:45:47 +00001012 /* Extensions */
1013 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +00001014
Brian Paul4d053dd2000-01-14 04:45:47 +00001015 /* Lighting group */
1016 for (i=0;i<MAX_LIGHTS;i++) {
1017 init_light( &ctx->Light.Light[i], i );
1018 }
1019 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001020
Brian Paul4d053dd2000-01-14 04:45:47 +00001021 init_lightmodel( &ctx->Light.Model );
1022 init_material( &ctx->Light.Material[0] );
1023 init_material( &ctx->Light.Material[1] );
1024 ctx->Light.ShadeModel = GL_SMOOTH;
1025 ctx->Light.Enabled = GL_FALSE;
1026 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1027 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
1028 ctx->Light.ColorMaterialBitmask
1029 = gl_material_bitmask( ctx,
1030 GL_FRONT_AND_BACK,
1031 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001032
Brian Paul4d053dd2000-01-14 04:45:47 +00001033 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001034
Brian Paul4d053dd2000-01-14 04:45:47 +00001035 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +00001036 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1037 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001038 for (i = 0 ; i < 10 ; i++) {
1039 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1040 s->shininess = -1;
1041 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001042 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +00001043 }
1044 for (i = 0 ; i < 4 ; i++) {
Keith Whitwell14940c42000-11-05 18:40:57 +00001045 ctx->_ShineTable[i] = ctx->_ShineTabList->prev;
1046 ctx->_ShineTable[i]->refcount++;
Brian Paul4d053dd2000-01-14 04:45:47 +00001047 }
jtgafb833d1999-08-19 00:55:39 +00001048
Brian Paul77d61af2000-06-28 04:20:21 +00001049 gl_compute_shine_table( ctx, 0, ctx->Light.Material[0].Shininess );
1050 gl_compute_shine_table( ctx, 2, ctx->Light.Material[0].Shininess * .5 );
1051 gl_compute_shine_table( ctx, 1, ctx->Light.Material[1].Shininess );
1052 gl_compute_shine_table( ctx, 3, ctx->Light.Material[1].Shininess * .5 );
1053
jtgafb833d1999-08-19 00:55:39 +00001054
Brian Paul4d053dd2000-01-14 04:45:47 +00001055 /* Line group */
1056 ctx->Line.SmoothFlag = GL_FALSE;
1057 ctx->Line.StippleFlag = GL_FALSE;
1058 ctx->Line.Width = 1.0;
1059 ctx->Line.StipplePattern = 0xffff;
1060 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001061
Brian Paul4d053dd2000-01-14 04:45:47 +00001062 /* Display List group */
1063 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001064
Brian Paul4d053dd2000-01-14 04:45:47 +00001065 /* Pixel group */
1066 ctx->Pixel.RedBias = 0.0;
1067 ctx->Pixel.RedScale = 1.0;
1068 ctx->Pixel.GreenBias = 0.0;
1069 ctx->Pixel.GreenScale = 1.0;
1070 ctx->Pixel.BlueBias = 0.0;
1071 ctx->Pixel.BlueScale = 1.0;
1072 ctx->Pixel.AlphaBias = 0.0;
1073 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001074 ctx->Pixel.DepthBias = 0.0;
1075 ctx->Pixel.DepthScale = 1.0;
1076 ctx->Pixel.IndexOffset = 0;
1077 ctx->Pixel.IndexShift = 0;
1078 ctx->Pixel.ZoomX = 1.0;
1079 ctx->Pixel.ZoomY = 1.0;
1080 ctx->Pixel.MapColorFlag = GL_FALSE;
1081 ctx->Pixel.MapStencilFlag = GL_FALSE;
1082 ctx->Pixel.MapStoSsize = 1;
1083 ctx->Pixel.MapItoIsize = 1;
1084 ctx->Pixel.MapItoRsize = 1;
1085 ctx->Pixel.MapItoGsize = 1;
1086 ctx->Pixel.MapItoBsize = 1;
1087 ctx->Pixel.MapItoAsize = 1;
1088 ctx->Pixel.MapRtoRsize = 1;
1089 ctx->Pixel.MapGtoGsize = 1;
1090 ctx->Pixel.MapBtoBsize = 1;
1091 ctx->Pixel.MapAtoAsize = 1;
1092 ctx->Pixel.MapStoS[0] = 0;
1093 ctx->Pixel.MapItoI[0] = 0;
1094 ctx->Pixel.MapItoR[0] = 0.0;
1095 ctx->Pixel.MapItoG[0] = 0.0;
1096 ctx->Pixel.MapItoB[0] = 0.0;
1097 ctx->Pixel.MapItoA[0] = 0.0;
1098 ctx->Pixel.MapItoR8[0] = 0;
1099 ctx->Pixel.MapItoG8[0] = 0;
1100 ctx->Pixel.MapItoB8[0] = 0;
1101 ctx->Pixel.MapItoA8[0] = 0;
1102 ctx->Pixel.MapRtoR[0] = 0.0;
1103 ctx->Pixel.MapGtoG[0] = 0.0;
1104 ctx->Pixel.MapBtoB[0] = 0.0;
1105 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001106 ctx->Pixel.HistogramEnabled = GL_FALSE;
1107 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1108 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1109 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1110 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001111 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1112 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1113 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1114 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001115 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1116 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1117 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1118 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001119 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1120 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1121 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001122 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1123 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1124 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1125 for (i = 0; i < 3; i++) {
1126 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1127 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1128 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1129 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1130 }
1131 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1132 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001133
Brian Paul4d053dd2000-01-14 04:45:47 +00001134 /* Point group */
1135 ctx->Point.SmoothFlag = GL_FALSE;
1136 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001137 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001138 ctx->Point.Params[0] = 1.0;
1139 ctx->Point.Params[1] = 0.0;
1140 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001141 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001142 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001143 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001144 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001145
Brian Paul4d053dd2000-01-14 04:45:47 +00001146 /* Polygon group */
1147 ctx->Polygon.CullFlag = GL_FALSE;
1148 ctx->Polygon.CullFaceMode = GL_BACK;
1149 ctx->Polygon.FrontFace = GL_CCW;
1150 ctx->Polygon.FrontBit = 0;
1151 ctx->Polygon.FrontMode = GL_FILL;
1152 ctx->Polygon.BackMode = GL_FILL;
Keith Whitwell14940c42000-11-05 18:40:57 +00001153 ctx->Polygon._Unfilled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001154 ctx->Polygon.SmoothFlag = GL_FALSE;
1155 ctx->Polygon.StippleFlag = GL_FALSE;
1156 ctx->Polygon.OffsetFactor = 0.0F;
1157 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001158 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001159 ctx->Polygon.OffsetPoint = GL_FALSE;
1160 ctx->Polygon.OffsetLine = GL_FALSE;
1161 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001162
Brian Paul4d053dd2000-01-14 04:45:47 +00001163 /* Polygon Stipple group */
1164 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001165
Brian Paul4d053dd2000-01-14 04:45:47 +00001166 /* Scissor group */
1167 ctx->Scissor.Enabled = GL_FALSE;
1168 ctx->Scissor.X = 0;
1169 ctx->Scissor.Y = 0;
1170 ctx->Scissor.Width = 0;
1171 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001172
Brian Paul4d053dd2000-01-14 04:45:47 +00001173 /* Stencil group */
1174 ctx->Stencil.Enabled = GL_FALSE;
1175 ctx->Stencil.Function = GL_ALWAYS;
1176 ctx->Stencil.FailFunc = GL_KEEP;
1177 ctx->Stencil.ZPassFunc = GL_KEEP;
1178 ctx->Stencil.ZFailFunc = GL_KEEP;
1179 ctx->Stencil.Ref = 0;
1180 ctx->Stencil.ValueMask = STENCIL_MAX;
1181 ctx->Stencil.Clear = 0;
1182 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001183
Brian Paul4d053dd2000-01-14 04:45:47 +00001184 /* Texture group */
1185 ctx->Texture.CurrentUnit = 0; /* multitexture */
1186 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001187 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001188 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1189 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001190 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001191 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001192
Brian Paul4d053dd2000-01-14 04:45:47 +00001193 /* Transformation group */
1194 ctx->Transform.MatrixMode = GL_MODELVIEW;
1195 ctx->Transform.Normalize = GL_FALSE;
1196 ctx->Transform.RescaleNormals = GL_FALSE;
1197 for (i=0;i<MAX_CLIP_PLANES;i++) {
1198 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1199 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1200 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001201 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001202
Brian Paul4d053dd2000-01-14 04:45:47 +00001203 /* Viewport group */
1204 ctx->Viewport.X = 0;
1205 ctx->Viewport.Y = 0;
1206 ctx->Viewport.Width = 0;
1207 ctx->Viewport.Height = 0;
1208 ctx->Viewport.Near = 0.0;
1209 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001210 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001211
1212#define Sz 10
1213#define Tz 14
Keith Whitwell14940c42000-11-05 18:40:57 +00001214 ctx->Viewport._WindowMap.m[Sz] = 0.5 * ctx->Visual.DepthMaxF;
1215 ctx->Viewport._WindowMap.m[Tz] = 0.5 * ctx->Visual.DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001216#undef Sz
1217#undef Tz
1218
Keith Whitwell14940c42000-11-05 18:40:57 +00001219 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1220 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001221
Brian Paul4d053dd2000-01-14 04:45:47 +00001222 /* Vertex arrays */
1223 ctx->Array.Vertex.Size = 4;
1224 ctx->Array.Vertex.Type = GL_FLOAT;
1225 ctx->Array.Vertex.Stride = 0;
1226 ctx->Array.Vertex.StrideB = 0;
1227 ctx->Array.Vertex.Ptr = NULL;
1228 ctx->Array.Vertex.Enabled = GL_FALSE;
1229 ctx->Array.Normal.Type = GL_FLOAT;
1230 ctx->Array.Normal.Stride = 0;
1231 ctx->Array.Normal.StrideB = 0;
1232 ctx->Array.Normal.Ptr = NULL;
1233 ctx->Array.Normal.Enabled = GL_FALSE;
1234 ctx->Array.Color.Size = 4;
1235 ctx->Array.Color.Type = GL_FLOAT;
1236 ctx->Array.Color.Stride = 0;
1237 ctx->Array.Color.StrideB = 0;
1238 ctx->Array.Color.Ptr = NULL;
1239 ctx->Array.Color.Enabled = GL_FALSE;
1240 ctx->Array.Index.Type = GL_FLOAT;
1241 ctx->Array.Index.Stride = 0;
1242 ctx->Array.Index.StrideB = 0;
1243 ctx->Array.Index.Ptr = NULL;
1244 ctx->Array.Index.Enabled = GL_FALSE;
1245 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1246 ctx->Array.TexCoord[i].Size = 4;
1247 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1248 ctx->Array.TexCoord[i].Stride = 0;
1249 ctx->Array.TexCoord[i].StrideB = 0;
1250 ctx->Array.TexCoord[i].Ptr = NULL;
1251 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1252 }
1253 ctx->Array.TexCoordInterleaveFactor = 1;
1254 ctx->Array.EdgeFlag.Stride = 0;
1255 ctx->Array.EdgeFlag.StrideB = 0;
1256 ctx->Array.EdgeFlag.Ptr = NULL;
1257 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1258 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1259
1260 /* Pixel transfer */
1261 ctx->Pack.Alignment = 4;
1262 ctx->Pack.RowLength = 0;
1263 ctx->Pack.ImageHeight = 0;
1264 ctx->Pack.SkipPixels = 0;
1265 ctx->Pack.SkipRows = 0;
1266 ctx->Pack.SkipImages = 0;
1267 ctx->Pack.SwapBytes = GL_FALSE;
1268 ctx->Pack.LsbFirst = GL_FALSE;
1269 ctx->Unpack.Alignment = 4;
1270 ctx->Unpack.RowLength = 0;
1271 ctx->Unpack.ImageHeight = 0;
1272 ctx->Unpack.SkipPixels = 0;
1273 ctx->Unpack.SkipRows = 0;
1274 ctx->Unpack.SkipImages = 0;
1275 ctx->Unpack.SwapBytes = GL_FALSE;
1276 ctx->Unpack.LsbFirst = GL_FALSE;
1277
1278 /* Feedback */
1279 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1280 ctx->Feedback.Buffer = NULL;
1281 ctx->Feedback.BufferSize = 0;
1282 ctx->Feedback.Count = 0;
1283
1284 /* Selection/picking */
1285 ctx->Select.Buffer = NULL;
1286 ctx->Select.BufferSize = 0;
1287 ctx->Select.BufferCount = 0;
1288 ctx->Select.Hits = 0;
1289 ctx->Select.NameStackDepth = 0;
1290
Brian Paul4d053dd2000-01-14 04:45:47 +00001291 /* Renderer and client attribute stacks */
1292 ctx->AttribStackDepth = 0;
1293 ctx->ClientAttribStackDepth = 0;
1294
Brian Paul13811372000-04-12 00:27:37 +00001295 /* Display list */
1296 ctx->CallDepth = 0;
1297 ctx->ExecuteFlag = GL_TRUE;
1298 ctx->CompileFlag = GL_FALSE;
1299 ctx->CurrentListPtr = NULL;
1300 ctx->CurrentBlock = NULL;
1301 ctx->CurrentListNum = 0;
1302 ctx->CurrentPos = 0;
1303
1304 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001305 _mesa_init_colortable(&ctx->ColorTable);
1306 _mesa_init_colortable(&ctx->ProxyColorTable);
1307 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1308 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1309 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1310 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001311
Brian Paul4d053dd2000-01-14 04:45:47 +00001312 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001313 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001314 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001315 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001316
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001317 ctx->_NeedNormals = 0;
1318 ctx->_NeedEyeCoords = 0;
1319 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001320
Brian Paul4d053dd2000-01-14 04:45:47 +00001321 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1322
1323 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001324 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001325 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001326
1327 /* For debug/development only */
1328 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1329 ctx->FirstTimeCurrent = GL_TRUE;
1330
1331 /* Dither disable */
1332 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1333 if (ctx->NoDither) {
1334 if (getenv("MESA_DEBUG")) {
1335 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001336 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001337 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001338 }
1339}
1340
1341
1342
1343
jtgafb833d1999-08-19 00:55:39 +00001344/*
1345 * Allocate the proxy textures. If we run out of memory part way through
1346 * the allocations clean up and return GL_FALSE.
1347 * Return: GL_TRUE=success, GL_FALSE=failure
1348 */
Brian Paul178a1c52000-04-22 01:05:00 +00001349static GLboolean
1350alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001351{
1352 GLboolean out_of_memory;
1353 GLint i;
1354
1355 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1356 if (!ctx->Texture.Proxy1D) {
1357 return GL_FALSE;
1358 }
1359
1360 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1361 if (!ctx->Texture.Proxy2D) {
1362 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1363 return GL_FALSE;
1364 }
1365
1366 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1367 if (!ctx->Texture.Proxy3D) {
1368 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1369 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1370 return GL_FALSE;
1371 }
1372
1373 out_of_memory = GL_FALSE;
1374 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001375 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1376 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1377 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001378 if (!ctx->Texture.Proxy1D->Image[i]
1379 || !ctx->Texture.Proxy2D->Image[i]
1380 || !ctx->Texture.Proxy3D->Image[i]) {
1381 out_of_memory = GL_TRUE;
1382 }
1383 }
1384 if (out_of_memory) {
1385 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1386 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001387 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001388 }
1389 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001390 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001391 }
1392 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001393 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001394 }
1395 }
1396 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1397 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1398 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1399 return GL_FALSE;
1400 }
1401 else {
1402 return GL_TRUE;
1403 }
1404}
1405
1406
jtgafb833d1999-08-19 00:55:39 +00001407/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001408 * Initialize a GLcontext struct. This includes allocating all the
1409 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001410 */
Brian Paul178a1c52000-04-22 01:05:00 +00001411GLboolean
1412_mesa_initialize_context( GLcontext *ctx,
1413 GLvisual *visual,
1414 GLcontext *share_list,
1415 void *driver_ctx,
1416 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001417{
Brian Paul5fb84d22000-05-24 15:04:45 +00001418 GLuint dispatchSize;
1419
jtgafb833d1999-08-19 00:55:39 +00001420 (void) direct; /* not used */
1421
jtgafb833d1999-08-19 00:55:39 +00001422 /* misc one-time initializations */
1423 one_time_init();
1424
Brian Paulb1394fa2000-09-26 20:53:53 +00001425 /**
1426 ** OpenGL SI stuff
1427 **/
1428 if (!ctx->imports.malloc) {
1429 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1430 }
1431 /* exports are setup by the device driver */
1432
jtgafb833d1999-08-19 00:55:39 +00001433 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001434 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001435 ctx->DrawBuffer = NULL;
1436 ctx->ReadBuffer = NULL;
Keith Whitwell724abeb2000-10-31 18:09:44 +00001437
jtgafb833d1999-08-19 00:55:39 +00001438 if (share_list) {
1439 /* share the group of display lists of another context */
1440 ctx->Shared = share_list->Shared;
1441 }
1442 else {
1443 /* allocate new group of display lists */
1444 ctx->Shared = alloc_shared_state();
1445 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001446 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001447 }
1448 }
Brian Paul9560f052000-01-31 23:11:39 +00001449 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001450 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001451 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001452
Brian Paul4d053dd2000-01-14 04:45:47 +00001453 init_attrib_groups( ctx );
1454
jtgafb833d1999-08-19 00:55:39 +00001455 if (visual->DBflag) {
1456 ctx->Color.DrawBuffer = GL_BACK;
1457 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1458 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1459 ctx->Pixel.ReadBuffer = GL_BACK;
1460 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1461 }
1462 else {
1463 ctx->Color.DrawBuffer = GL_FRONT;
1464 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1465 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1466 ctx->Pixel.ReadBuffer = GL_FRONT;
1467 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1468 }
1469
jtgafb833d1999-08-19 00:55:39 +00001470 if (!alloc_proxy_textures(ctx)) {
1471 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001472 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001473 }
jtgafb833d1999-08-19 00:55:39 +00001474
Brian Paulf59afc92000-05-23 23:23:00 +00001475 /* register the most recent extension functions with libGL */
1476 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1477 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1478 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1479 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1480 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1481 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1482 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1483 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1484
Brian Paul5fb84d22000-05-24 15:04:45 +00001485 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1486 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1487 * Mesa we do this to accomodate different versions of libGL and various
1488 * DRI drivers.
1489 */
1490 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1491 sizeof(struct _glapi_table) / sizeof(void *));
1492
Brian Paulfbd8f211999-11-11 01:22:25 +00001493 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001494 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1495 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001496 if (!ctx->Exec || !ctx->Save) {
1497 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001498 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001499 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001500 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001501 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1502 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001503 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001504
Brian Paul3b18a362000-09-26 15:27:20 +00001505#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +00001506 ctx->TraceCtx = CALLOC( sizeof(trace_context_t) );
1507#if 0
1508 /* Brian: do you want to have CreateContext fail here,
1509 or should we just trap in NewTrace (currently done)? */
1510 if (!(ctx->TraceCtx)) {
1511 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001512 FREE( ctx->Exec );
1513 FREE( ctx->Save );
1514 return GL_FALSE;
1515 }
1516#endif
1517 trInitContext(ctx->TraceCtx);
1518
1519 ctx->TraceDispatch = (struct _glapi_table *)
1520 CALLOC(dispatchSize * sizeof(void*));
1521#if 0
1522 if (!(ctx->TraceCtx)) {
1523 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001524 FREE( ctx->Exec );
1525 FREE( ctx->Save );
1526 FREE( ctx->TraceCtx );
1527 return GL_FALSE;
1528 }
1529#endif
1530 trInitDispatch(ctx->TraceDispatch);
1531#endif
1532
Brian Paul4d053dd2000-01-14 04:45:47 +00001533 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001534}
1535
jtgafb833d1999-08-19 00:55:39 +00001536
1537
1538/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001539 * Allocate and initialize a GLcontext structure.
1540 * Input: visual - a GLvisual pointer
1541 * sharelist - another context to share display lists with or NULL
1542 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001543 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001544 */
Brian Paul178a1c52000-04-22 01:05:00 +00001545GLcontext *
Brian Paulb1394fa2000-09-26 20:53:53 +00001546_mesa_create_context( GLvisual *visual,
1547 GLcontext *share_list,
1548 void *driver_ctx,
1549 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001550{
1551 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1552 if (!ctx) {
1553 return NULL;
1554 }
1555
Brian Paul178a1c52000-04-22 01:05:00 +00001556 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001557 return ctx;
1558 }
1559 else {
1560 FREE(ctx);
1561 return NULL;
1562 }
1563}
1564
1565
1566
1567/*
1568 * Free the data associated with the given context.
1569 * But don't free() the GLcontext struct itself!
1570 */
Brian Paul178a1c52000-04-22 01:05:00 +00001571void
Brian Paulb1394fa2000-09-26 20:53:53 +00001572_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001573{
Brian Paul4d053dd2000-01-14 04:45:47 +00001574 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001575 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001576
1577 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001578 if (ctx == _mesa_get_current_context()) {
1579 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001580 }
1581
Keith Whitwell23caf202000-11-16 21:05:34 +00001582 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001583 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001584 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001585 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001586 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001587 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001588 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001589 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001590 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001591 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001592 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001593 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001594 }
1595 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001596
Brian Paul9560f052000-01-31 23:11:39 +00001597 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001598 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001599 assert(ctx->Shared->RefCount >= 0);
1600 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1601 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001602 /* free shared state */
1603 free_shared_state( ctx, ctx->Shared );
1604 }
1605
Keith Whitwell14940c42000-11-05 18:40:57 +00001606 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001607 FREE( s );
1608 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001609 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001610
1611 /* Free proxy texture objects */
1612 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1613 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1614 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1615
1616 /* Free evaluator data */
1617 if (ctx->EvalMap.Map1Vertex3.Points)
1618 FREE( ctx->EvalMap.Map1Vertex3.Points );
1619 if (ctx->EvalMap.Map1Vertex4.Points)
1620 FREE( ctx->EvalMap.Map1Vertex4.Points );
1621 if (ctx->EvalMap.Map1Index.Points)
1622 FREE( ctx->EvalMap.Map1Index.Points );
1623 if (ctx->EvalMap.Map1Color4.Points)
1624 FREE( ctx->EvalMap.Map1Color4.Points );
1625 if (ctx->EvalMap.Map1Normal.Points)
1626 FREE( ctx->EvalMap.Map1Normal.Points );
1627 if (ctx->EvalMap.Map1Texture1.Points)
1628 FREE( ctx->EvalMap.Map1Texture1.Points );
1629 if (ctx->EvalMap.Map1Texture2.Points)
1630 FREE( ctx->EvalMap.Map1Texture2.Points );
1631 if (ctx->EvalMap.Map1Texture3.Points)
1632 FREE( ctx->EvalMap.Map1Texture3.Points );
1633 if (ctx->EvalMap.Map1Texture4.Points)
1634 FREE( ctx->EvalMap.Map1Texture4.Points );
1635
1636 if (ctx->EvalMap.Map2Vertex3.Points)
1637 FREE( ctx->EvalMap.Map2Vertex3.Points );
1638 if (ctx->EvalMap.Map2Vertex4.Points)
1639 FREE( ctx->EvalMap.Map2Vertex4.Points );
1640 if (ctx->EvalMap.Map2Index.Points)
1641 FREE( ctx->EvalMap.Map2Index.Points );
1642 if (ctx->EvalMap.Map2Color4.Points)
1643 FREE( ctx->EvalMap.Map2Color4.Points );
1644 if (ctx->EvalMap.Map2Normal.Points)
1645 FREE( ctx->EvalMap.Map2Normal.Points );
1646 if (ctx->EvalMap.Map2Texture1.Points)
1647 FREE( ctx->EvalMap.Map2Texture1.Points );
1648 if (ctx->EvalMap.Map2Texture2.Points)
1649 FREE( ctx->EvalMap.Map2Texture2.Points );
1650 if (ctx->EvalMap.Map2Texture3.Points)
1651 FREE( ctx->EvalMap.Map2Texture3.Points );
1652 if (ctx->EvalMap.Map2Texture4.Points)
1653 FREE( ctx->EvalMap.Map2Texture4.Points );
1654
Brian Paul4bdcfe52000-04-17 17:57:04 +00001655 _mesa_free_colortable_data( &ctx->ColorTable );
1656 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1657 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1658 _mesa_free_colortable_data( &ctx->Texture.Palette );
1659
Brian Paul4d053dd2000-01-14 04:45:47 +00001660 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001661
1662 FREE(ctx->Exec);
1663 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001664}
1665
1666
1667
1668/*
1669 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001670 */
Brian Paul178a1c52000-04-22 01:05:00 +00001671void
Brian Paulb1394fa2000-09-26 20:53:53 +00001672_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001673{
1674 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001675 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001676 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001677 }
1678}
1679
1680
1681
1682/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001683 * Called by the driver after both the context and driver are fully
1684 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001685 */
Brian Paul178a1c52000-04-22 01:05:00 +00001686void
Brian Paulb1394fa2000-09-26 20:53:53 +00001687_mesa_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001688{
Brian Paul00037781999-12-17 14:52:35 +00001689 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001690}
1691
1692
1693
1694/*
1695 * Copy attribute groups from one context to another.
1696 * Input: src - source context
1697 * dst - destination context
1698 * mask - bitwise OR of GL_*_BIT flags
1699 */
Brian Paul178a1c52000-04-22 01:05:00 +00001700void
Brian Paulb1394fa2000-09-26 20:53:53 +00001701_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001702{
1703 if (mask & GL_ACCUM_BUFFER_BIT) {
1704 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1705 }
1706 if (mask & GL_COLOR_BUFFER_BIT) {
1707 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1708 }
1709 if (mask & GL_CURRENT_BIT) {
1710 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1711 }
1712 if (mask & GL_DEPTH_BUFFER_BIT) {
1713 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1714 }
1715 if (mask & GL_ENABLE_BIT) {
1716 /* no op */
1717 }
1718 if (mask & GL_EVAL_BIT) {
1719 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1720 }
1721 if (mask & GL_FOG_BIT) {
1722 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1723 }
1724 if (mask & GL_HINT_BIT) {
1725 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1726 }
1727 if (mask & GL_LIGHTING_BIT) {
1728 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001729 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001730 }
1731 if (mask & GL_LINE_BIT) {
1732 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1733 }
1734 if (mask & GL_LIST_BIT) {
1735 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1736 }
1737 if (mask & GL_PIXEL_MODE_BIT) {
1738 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1739 }
1740 if (mask & GL_POINT_BIT) {
1741 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1742 }
1743 if (mask & GL_POLYGON_BIT) {
1744 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1745 }
1746 if (mask & GL_POLYGON_STIPPLE_BIT) {
1747 /* Use loop instead of MEMCPY due to problem with Portland Group's
1748 * C compiler. Reported by John Stone.
1749 */
1750 int i;
1751 for (i=0;i<32;i++) {
1752 dst->PolygonStipple[i] = src->PolygonStipple[i];
1753 }
1754 }
1755 if (mask & GL_SCISSOR_BIT) {
1756 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1757 }
1758 if (mask & GL_STENCIL_BUFFER_BIT) {
1759 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1760 }
1761 if (mask & GL_TEXTURE_BIT) {
1762 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1763 }
1764 if (mask & GL_TRANSFORM_BIT) {
1765 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1766 }
1767 if (mask & GL_VIEWPORT_BIT) {
1768 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1769 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001770 /* XXX FIXME: Call callbacks?
1771 */
1772 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001773}
1774
1775
jtgafb833d1999-08-19 00:55:39 +00001776/*
Brian Paul00037781999-12-17 14:52:35 +00001777 * Set the current context, binding the given frame buffer to the context.
1778 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001779void
1780_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001781{
Brian Paulb1394fa2000-09-26 20:53:53 +00001782 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001783}
1784
1785
Keith Whitwell23caf202000-11-16 21:05:34 +00001786static void print_info( void )
1787{
1788 fprintf(stderr, "Mesa GL_VERSION = %s\n",
1789 (char *) _mesa_GetString(GL_VERSION));
1790 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
1791 (char *) _mesa_GetString(GL_RENDERER));
1792 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
1793 (char *) _mesa_GetString(GL_VENDOR));
1794 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
1795 (char *) _mesa_GetString(GL_EXTENSIONS));
1796#if defined(THREADS)
1797 fprintf(stderr, "Mesa thread-safe: YES\n");
1798#else
1799 fprintf(stderr, "Mesa thread-safe: NO\n");
1800#endif
1801#if defined(USE_X86_ASM)
1802 fprintf(stderr, "Mesa x86-optimized: YES\n");
1803#else
1804 fprintf(stderr, "Mesa x86-optimized: NO\n");
1805#endif
1806}
1807
1808
Brian Paul00037781999-12-17 14:52:35 +00001809/*
1810 * Bind the given context to the given draw-buffer and read-buffer
1811 * and make it the current context for this thread.
1812 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001813void
1814_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1815 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001816{
Keith Whitwell23caf202000-11-16 21:05:34 +00001817 if (MESA_VERBOSE)
1818 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001819
1820 /* We call this function periodically (just here for now) in
1821 * order to detect when multithreading has begun.
1822 */
1823 _glapi_check_multithread();
1824
Brian Paulf9b97d92000-01-28 20:17:42 +00001825 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001826 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001827
1828
1829 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001830 _glapi_set_dispatch(NULL); /* none current */
1831 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001832 else {
1833 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001834
Keith Whitwell23caf202000-11-16 21:05:34 +00001835 if (drawBuffer && readBuffer) {
1836 /* TODO: check if newCtx and buffer's visual match??? */
1837 newCtx->DrawBuffer = drawBuffer;
1838 newCtx->ReadBuffer = readBuffer;
1839 newCtx->NewState |= _NEW_BUFFERS;
1840 /* gl_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001841 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001842
1843 if (newCtx->Driver.MakeCurrent)
1844 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1845
1846 /* We can use this to help debug user's problems. Tell them to set
1847 * the MESA_INFO env variable before running their app. Then the
1848 * first time each context is made current we'll print some useful
1849 * information.
1850 */
1851 if (newCtx->FirstTimeCurrent) {
1852 if (getenv("MESA_INFO")) {
1853 print_info();
1854 }
1855 newCtx->FirstTimeCurrent = GL_FALSE;
1856 }
Brian Paul00037781999-12-17 14:52:35 +00001857 }
1858}
1859
1860
1861
1862/*
1863 * Return current context handle for the calling thread.
1864 * This isn't the fastest way to get the current context.
1865 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1866 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001867GLcontext *
1868_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001869{
Brian Paulf9b97d92000-01-28 20:17:42 +00001870 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001871}
1872
1873
1874
1875/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001876 * This should be called by device drivers just before they do a
1877 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001878 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001879void
1880_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001881{
Keith Whitwell23caf202000-11-16 21:05:34 +00001882 FLUSH_TNL( ctx, FLUSH_STORED_VERTICES );
jtgafb833d1999-08-19 00:55:39 +00001883}
1884
1885
Brian Paul00037781999-12-17 14:52:35 +00001886
Brian Paulfbd8f211999-11-11 01:22:25 +00001887/*
1888 * Return pointer to this context's current API dispatch table.
1889 * It'll either be the immediate-mode execute dispatcher or the
1890 * display list compile dispatcher.
1891 */
1892struct _glapi_table *
1893_mesa_get_dispatch(GLcontext *ctx)
1894{
1895 return ctx->CurrentDispatch;
1896}
1897
1898
1899
jtgafb833d1999-08-19 00:55:39 +00001900/**********************************************************************/
1901/***** Miscellaneous functions *****/
1902/**********************************************************************/
1903
1904
1905/*
1906 * This function is called when the Mesa user has stumbled into a code
1907 * path which may not be implemented fully or correctly.
1908 */
1909void gl_problem( const GLcontext *ctx, const char *s )
1910{
1911 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paul413d6a22000-05-26 14:44:59 +00001912 fprintf( stderr, "Report to Mesa bug database at www.mesa3d.org\n" );
jtgafb833d1999-08-19 00:55:39 +00001913 (void) ctx;
1914}
1915
1916
1917
1918/*
1919 * This is called to inform the user that he or she has tried to do
1920 * something illogical or if there's likely a bug in their program
1921 * (like enabled depth testing without a depth buffer).
1922 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001923void
1924_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001925{
Brian Paulb1394fa2000-09-26 20:53:53 +00001926 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001927}
1928
1929
1930
Brian Paulfa9df402000-02-02 19:16:46 +00001931/*
1932 * Compile an error into current display list.
1933 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001934void
1935_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001936{
1937 if (ctx->CompileFlag)
1938 gl_save_error( ctx, error, s );
1939
1940 if (ctx->ExecuteFlag)
1941 gl_error( ctx, error, s );
1942}
1943
1944
Brian Paulfa9df402000-02-02 19:16:46 +00001945
jtgafb833d1999-08-19 00:55:39 +00001946/*
1947 * This is Mesa's error handler. Normally, all that's done is the updating
1948 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1949 * environment variable "MESA_DEBUG" is defined then a real error message
1950 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001951 * Input: ctx - the GL context
1952 * error - the error value
1953 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001954 */
Brian Paul7eb06032000-07-14 04:13:40 +00001955void
1956gl_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001957{
Brian Paul7eb06032000-07-14 04:13:40 +00001958 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001959 GLboolean debug;
1960
1961#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00001962 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00001963 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00001964 else
1965 debug = GL_TRUE;
1966#else
1967 if (debugEnv)
1968 debug = GL_TRUE;
1969 else
1970 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001971#endif
1972
1973 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00001974 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00001975 switch (error) {
1976 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00001977 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00001978 break;
1979 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00001980 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00001981 break;
1982 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00001983 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00001984 break;
1985 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00001986 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00001987 break;
1988 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001989 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001990 break;
1991 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001992 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001993 break;
1994 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00001995 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00001996 break;
Brian Paul86586aa2000-06-29 18:55:52 +00001997 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00001998 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00001999 break;
jtgafb833d1999-08-19 00:55:39 +00002000 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002001 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002002 break;
2003 }
Brian Paul7eb06032000-07-14 04:13:40 +00002004 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002005 }
2006
Brian Paul7eb06032000-07-14 04:13:40 +00002007 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002008 ctx->ErrorValue = error;
2009 }
2010
2011 /* Call device driver's error handler, if any. This is used on the Mac. */
2012 if (ctx->Driver.Error) {
2013 (*ctx->Driver.Error)( ctx );
2014 }
2015}
2016
2017
2018
Brian Paulfa9df402000-02-02 19:16:46 +00002019void
2020_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002021{
Brian Paulfa9df402000-02-02 19:16:46 +00002022 GET_CURRENT_CONTEXT(ctx);
2023 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
2024 if (ctx->Driver.Finish) {
2025 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002026 }
2027}
2028
2029
2030
Brian Paulfa9df402000-02-02 19:16:46 +00002031void
2032_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002033{
Brian Paulfa9df402000-02-02 19:16:46 +00002034 GET_CURRENT_CONTEXT(ctx);
2035 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
2036 if (ctx->Driver.Flush) {
2037 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002038 }
jtgafb833d1999-08-19 00:55:39 +00002039}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002040
2041
2042
2043const char *_mesa_prim_name[GL_POLYGON+2] = {
2044 "GL_POINTS",
2045 "GL_LINES",
2046 "GL_LINE_LOOP",
2047 "GL_LINE_STRIP",
2048 "GL_TRIANGLES",
2049 "GL_TRIANGLE_STRIP",
2050 "GL_TRIANGLE_FAN",
2051 "GL_QUADS",
2052 "GL_QUAD_STRIP",
2053 "GL_POLYGON",
2054 "culled primitive"
2055};
2056
Brian Paul1c56fdc2000-09-17 21:56:07 +00002057
2058GLenum gl_reduce_prim[GL_POLYGON+1] = {
2059 GL_POINTS,
2060 GL_LINES,
2061 GL_LINES,
2062 GL_LINES,
2063 GL_TRIANGLES,
2064 GL_TRIANGLES,
2065 GL_TRIANGLES,
2066 GL_TRIANGLES,
2067 GL_TRIANGLES,
2068 GL_TRIANGLES,
Gareth Hughesfc2427e2000-10-23 00:16:28 +00002069};