blob: 690071fee92dd7ac5a05ebb253c7ff7607a44790 [file] [log] [blame]
Jouk Jansen12e875c2001-10-18 08:04:57 +00001/* $Id: context.c,v 1.148 2001/10/18 08:04:57 joukj Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paule4b684c2000-09-12 21:07:40 +00005 * Version: 3.5
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paulb6bcae52001-01-23 23:39:36 +00007 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000032#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000034#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000035#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "dlist.h"
37#include "eval.h"
38#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000039#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000041#include "get.h"
Brian Paul9560f052000-01-31 23:11:39 +000042#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000044#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000045#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000046#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000047#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "mmath.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +000050#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000051#include "teximage.h"
52#include "texobj.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000053#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "varray.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +000055#include "vtxfmt.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000056
57#include "math/m_translate.h"
58#include "math/m_vertices.h"
59#include "math/m_matrix.h"
60#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +000061#include "math/mathmod.h"
jtgafb833d1999-08-19 00:55:39 +000062#endif
63
Brian Paul3b18a362000-09-26 15:27:20 +000064#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000065#include "Trace/tr_context.h"
66#include "Trace/tr_wrapper.h"
67#endif
68
davem69775355a2001-06-05 23:54:00 +000069#ifdef USE_SPARC_ASM
70#include "SPARC/sparc.h"
71#endif
jtgafb833d1999-08-19 00:55:39 +000072
Keith Whitwell23caf202000-11-16 21:05:34 +000073#ifndef MESA_VERBOSE
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000074int MESA_VERBOSE = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000075/* | VERBOSE_PIPELINE */
76/* | VERBOSE_IMMEDIATE */
77/* | VERBOSE_VARRAY */
78/* | VERBOSE_TEXTURE */
79/* | VERBOSE_API */
80/* | VERBOSE_DRIVER */
81/* | VERBOSE_STATE */
Keith Whitwell23caf202000-11-16 21:05:34 +000082/* | VERBOSE_DISPLAY_LIST */
83;
84#endif
85
86#ifndef MESA_DEBUG_FLAGS
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000087int MESA_DEBUG_FLAGS = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000088/* | DEBUG_ALWAYS_FLUSH */
89;
90#endif
Brian Paulb1394fa2000-09-26 20:53:53 +000091
92/**********************************************************************/
93/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
94/**********************************************************************/
95
96static GLboolean
97_mesa_DestroyContext(__GLcontext *gc)
98{
99 if (gc) {
100 _mesa_free_context_data(gc);
101 (*gc->imports.free)(gc, gc);
102 }
103 return GL_TRUE;
104}
105
106
107/* exported OpenGL SI interface */
108__GLcontext *
109__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
110{
111 GLcontext *ctx;
112
113 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
114 if (ctx == NULL) {
115 return NULL;
116 }
Jouk Jansen12e875c2001-10-18 08:04:57 +0000117 ctx->Driver.CurrentExecPrimitive=0;
Brian Paulb1394fa2000-09-26 20:53:53 +0000118 ctx->imports = *imports;
119
120 _mesa_initialize_visual(&ctx->Visual,
121 modes->rgbMode,
122 modes->doubleBufferMode,
123 modes->stereoMode,
124 modes->redBits,
125 modes->greenBits,
126 modes->blueBits,
127 modes->alphaBits,
128 modes->indexBits,
129 modes->depthBits,
130 modes->stencilBits,
131 modes->accumRedBits,
132 modes->accumGreenBits,
133 modes->accumBlueBits,
134 modes->accumAlphaBits,
135 0);
136
Keith Whitwellb980b2e2001-01-08 04:09:41 +0000137 /* KW: was imports->wscx */
138 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
Brian Paulb1394fa2000-09-26 20:53:53 +0000139
140 ctx->exports.destroyContext = _mesa_DestroyContext;
141
142 return ctx;
143}
144
145
146/* exported OpenGL SI interface */
147void
148__glCoreNopDispatch(void)
149{
150#if 0
151 /* SI */
152 __gl_dispatch = __glNopDispatchState;
153#else
154 /* Mesa */
155 _glapi_set_dispatch(NULL);
156#endif
157}
158
159
jtgafb833d1999-08-19 00:55:39 +0000160/**********************************************************************/
161/***** Context and Thread management *****/
162/**********************************************************************/
163
164
jtgafb833d1999-08-19 00:55:39 +0000165
jtgafb833d1999-08-19 00:55:39 +0000166/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000167/***** GL Visual allocation/destruction *****/
168/**********************************************************************/
169
170
171/*
172 * Allocate a new GLvisual object.
173 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000174 * dbFlag - double buffering?
175 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000176 * depthBits - requested bits per depth buffer value
177 * Any value in [0, 32] is acceptable but the actual
178 * depth type will be GLushort or GLuint as needed.
179 * stencilBits - requested minimum bits per stencil buffer value
180 * accumBits - requested minimum bits per accum buffer component
181 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
182 * red/green/blue/alphaBits - number of bits per color component
183 * in frame buffer for RGB(A) mode.
184 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000185 * Return: pointer to new GLvisual or NULL if requested parameters can't
186 * be met.
187 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000188GLvisual *
189_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000190 GLboolean dbFlag,
191 GLboolean stereoFlag,
192 GLint redBits,
193 GLint greenBits,
194 GLint blueBits,
195 GLint alphaBits,
196 GLint indexBits,
197 GLint depthBits,
198 GLint stencilBits,
199 GLint accumRedBits,
200 GLint accumGreenBits,
201 GLint accumBlueBits,
202 GLint accumAlphaBits,
203 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000204{
Brian Paul178a1c52000-04-22 01:05:00 +0000205 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
206 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000207 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000208 redBits, greenBits, blueBits, alphaBits,
209 indexBits, depthBits, stencilBits,
210 accumRedBits, accumGreenBits,
211 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000212 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000213 FREE(vis);
214 return NULL;
215 }
216 }
217 return vis;
218}
219
220
221/*
222 * Initialize the fields of the given GLvisual.
223 * Input: see _mesa_create_visual() above.
224 * Return: GL_TRUE = success
225 * GL_FALSE = failure.
226 */
227GLboolean
228_mesa_initialize_visual( GLvisual *vis,
229 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000230 GLboolean dbFlag,
231 GLboolean stereoFlag,
232 GLint redBits,
233 GLint greenBits,
234 GLint blueBits,
235 GLint alphaBits,
236 GLint indexBits,
237 GLint depthBits,
238 GLint stencilBits,
239 GLint accumRedBits,
240 GLint accumGreenBits,
241 GLint accumBlueBits,
242 GLint accumAlphaBits,
243 GLint numSamples )
244{
Brian Paulb6bcae52001-01-23 23:39:36 +0000245 (void) numSamples;
246
Brian Paul178a1c52000-04-22 01:05:00 +0000247 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000248
Brian Pauled30dfa2000-03-03 17:47:39 +0000249 /* This is to catch bad values from device drivers not updated for
250 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
251 * bad value now (a 1-bit depth buffer!?!).
252 */
253 assert(depthBits == 0 || depthBits > 1);
254
255 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000256 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000257 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000258 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000259 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000260 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000261 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000262 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000263 }
264 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000265 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000266 }
267 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000268 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000269 }
270 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000271 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000272 }
273
Brian Paulb6bcae52001-01-23 23:39:36 +0000274 vis->rgbMode = rgbFlag;
275 vis->doubleBufferMode = dbFlag;
276 vis->stereoMode = stereoFlag;
277 vis->redBits = redBits;
278 vis->greenBits = greenBits;
279 vis->blueBits = blueBits;
280 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000281
Brian Paulb6bcae52001-01-23 23:39:36 +0000282 vis->indexBits = indexBits;
283 vis->depthBits = depthBits;
284 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
285 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
286 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
287 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
288 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000289
Brian Paul178a1c52000-04-22 01:05:00 +0000290 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000291}
292
293
Brian Paulb371e0d2000-03-31 01:05:51 +0000294void
295_mesa_destroy_visual( GLvisual *vis )
296{
297 FREE(vis);
298}
299
300
Brian Paul4d053dd2000-01-14 04:45:47 +0000301/**********************************************************************/
302/***** GL Framebuffer allocation/destruction *****/
303/**********************************************************************/
304
305
306/*
307 * Create a new framebuffer. A GLframebuffer is a struct which
308 * encapsulates the depth, stencil and accum buffers and related
309 * parameters.
Brian Paulbe3602d2001-02-28 00:27:48 +0000310 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +0000311 * softwareDepth - create/use a software depth buffer?
312 * softwareStencil - create/use a software stencil buffer?
313 * softwareAccum - create/use a software accum buffer?
314 * softwareAlpha - create/use a software alpha buffer?
Brian Paul4d053dd2000-01-14 04:45:47 +0000315 * Return: pointer to new GLframebuffer struct or NULL if error.
316 */
Brian Paul178a1c52000-04-22 01:05:00 +0000317GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000318_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000319 GLboolean softwareDepth,
320 GLboolean softwareStencil,
321 GLboolean softwareAccum,
322 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000323{
Brian Paul178a1c52000-04-22 01:05:00 +0000324 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
325 assert(visual);
326 if (buffer) {
327 _mesa_initialize_framebuffer(buffer, visual,
328 softwareDepth, softwareStencil,
329 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000330 }
Brian Paul178a1c52000-04-22 01:05:00 +0000331 return buffer;
332}
333
334
335/*
336 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000337 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000338 */
339void
340_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000341 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000342 GLboolean softwareDepth,
343 GLboolean softwareStencil,
344 GLboolean softwareAccum,
345 GLboolean softwareAlpha )
346{
347 assert(buffer);
348 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000349
350 /* sanity checks */
351 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000352 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000353 }
354 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000355 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000356 }
357 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000358 assert(visual->rgbMode);
359 assert(visual->accumRedBits > 0);
360 assert(visual->accumGreenBits > 0);
361 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000362 }
363 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000364 assert(visual->rgbMode);
365 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000366 }
367
Brian Paul75978bd2001-04-27 21:17:20 +0000368 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000369 buffer->UseSoftwareDepthBuffer = softwareDepth;
370 buffer->UseSoftwareStencilBuffer = softwareStencil;
371 buffer->UseSoftwareAccumBuffer = softwareAccum;
372 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000373}
374
375
Brian Paul4d053dd2000-01-14 04:45:47 +0000376/*
377 * Free a framebuffer struct and its buffers.
378 */
Brian Paul178a1c52000-04-22 01:05:00 +0000379void
Brian Paulb1394fa2000-09-26 20:53:53 +0000380_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000381{
382 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000383 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000384 FREE(buffer);
385 }
386}
387
388
Brian Paul75978bd2001-04-27 21:17:20 +0000389/*
390 * Free the data hanging off of <buffer>, but not <buffer> itself.
391 */
392void
393_mesa_free_framebuffer_data( GLframebuffer *buffer )
394{
395 if (!buffer)
396 return;
397
398 if (buffer->DepthBuffer) {
399 FREE( buffer->DepthBuffer );
400 buffer->DepthBuffer = NULL;
401 }
402 if (buffer->Accum) {
403 FREE( buffer->Accum );
404 buffer->Accum = NULL;
405 }
406 if (buffer->Stencil) {
407 FREE( buffer->Stencil );
408 buffer->Stencil = NULL;
409 }
410 if (buffer->FrontLeftAlpha) {
411 FREE( buffer->FrontLeftAlpha );
412 buffer->FrontLeftAlpha = NULL;
413 }
414 if (buffer->BackLeftAlpha) {
415 FREE( buffer->BackLeftAlpha );
416 buffer->BackLeftAlpha = NULL;
417 }
418 if (buffer->FrontRightAlpha) {
419 FREE( buffer->FrontRightAlpha );
420 buffer->FrontRightAlpha = NULL;
421 }
422 if (buffer->BackRightAlpha) {
423 FREE( buffer->BackRightAlpha );
424 buffer->BackRightAlpha = NULL;
425 }
426}
427
428
Brian Paul4d053dd2000-01-14 04:45:47 +0000429
430/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000431/***** Context allocation, initialization, destroying *****/
432/**********************************************************************/
433
434
Brian Paul9560f052000-01-31 23:11:39 +0000435_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
436
437
jtgafb833d1999-08-19 00:55:39 +0000438/*
439 * This function just calls all the various one-time-init functions in Mesa.
440 */
Brian Paul178a1c52000-04-22 01:05:00 +0000441static void
442one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000443{
444 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000445 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000446 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000447 /* do some implementation tests */
448 assert( sizeof(GLbyte) == 1 );
449 assert( sizeof(GLshort) >= 2 );
450 assert( sizeof(GLint) >= 4 );
451 assert( sizeof(GLubyte) == 1 );
452 assert( sizeof(GLushort) >= 2 );
453 assert( sizeof(GLuint) >= 4 );
454
Brian Paul08836342001-03-03 20:33:27 +0000455 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000456
Keith Whitwell23caf202000-11-16 21:05:34 +0000457 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000458 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000459
davem69775355a2001-06-05 23:54:00 +0000460#ifdef USE_SPARC_ASM
461 _mesa_init_sparc_glapi_relocs();
462#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000463 if (getenv("MESA_DEBUG")) {
464 _glapi_noop_enable_warnings(GL_TRUE);
465 }
466 else {
467 _glapi_noop_enable_warnings(GL_FALSE);
468 }
469
jtgafb833d1999-08-19 00:55:39 +0000470#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
471 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
472#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000473
474 alreadyCalled = GL_TRUE;
475 }
Brian Paul9560f052000-01-31 23:11:39 +0000476 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000477}
478
479
Brian Paul4d053dd2000-01-14 04:45:47 +0000480
jtgafb833d1999-08-19 00:55:39 +0000481/*
482 * Allocate and initialize a shared context state structure.
483 */
Brian Paul178a1c52000-04-22 01:05:00 +0000484static struct gl_shared_state *
485alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000486{
jtgafb833d1999-08-19 00:55:39 +0000487 struct gl_shared_state *ss;
488 GLboolean outOfMemory;
489
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000490 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000491 if (!ss)
492 return NULL;
493
Brian Paule4b684c2000-09-12 21:07:40 +0000494 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000495
Brian Paule4b684c2000-09-12 21:07:40 +0000496 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000497 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000498
499 /* Default Texture objects */
500 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000501
502 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
503 if (!ss->Default1D) {
504 outOfMemory = GL_TRUE;
505 }
jtgafb833d1999-08-19 00:55:39 +0000506
Brian Paula8523782000-11-19 23:10:25 +0000507 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
508 if (!ss->Default2D) {
509 outOfMemory = GL_TRUE;
510 }
Brian Paula8523782000-11-19 23:10:25 +0000511
512 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
513 if (!ss->Default3D) {
514 outOfMemory = GL_TRUE;
515 }
Brian Paula8523782000-11-19 23:10:25 +0000516
517 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000518 if (!ss->DefaultCubeMap) {
519 outOfMemory = GL_TRUE;
520 }
Brian Paul413d6a22000-05-26 14:44:59 +0000521
jtgafb833d1999-08-19 00:55:39 +0000522 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
523 /* Ran out of memory at some point. Free everything and return NULL */
524 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000525 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000526 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000527 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula8523782000-11-19 23:10:25 +0000528 if (ss->Default1D)
529 _mesa_free_texture_object(ss, ss->Default1D);
530 if (ss->Default2D)
531 _mesa_free_texture_object(ss, ss->Default2D);
532 if (ss->Default3D)
533 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000534 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000535 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000536 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000537 return NULL;
538 }
539 else {
540 return ss;
541 }
542}
543
544
545/*
546 * Deallocate a shared state context and all children structures.
547 */
Brian Paul178a1c52000-04-22 01:05:00 +0000548static void
549free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000550{
551 /* Free display lists */
552 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000553 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000554 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000555 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000556 }
557 else {
558 break;
559 }
560 }
Brian Paulbb797902000-01-24 16:19:54 +0000561 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000562
563 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000564 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000565 if (ctx->Driver.DeleteTexture)
566 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
567 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000568 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000569 }
Brian Paulbb797902000-01-24 16:19:54 +0000570 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000571
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000572 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000573}
574
575
576
jtgafb833d1999-08-19 00:55:39 +0000577/*
578 * Initialize the nth light. Note that the defaults for light 0 are
579 * different than the other lights.
580 */
Brian Paul178a1c52000-04-22 01:05:00 +0000581static void
582init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000583{
584 make_empty_list( l );
585
586 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
587 if (n==0) {
588 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
589 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
590 }
591 else {
592 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
593 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
594 }
595 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
596 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
597 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000598 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000599 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000600 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000601 l->ConstantAttenuation = 1.0;
602 l->LinearAttenuation = 0.0;
603 l->QuadraticAttenuation = 0.0;
604 l->Enabled = GL_FALSE;
605}
606
607
608
Brian Paul178a1c52000-04-22 01:05:00 +0000609static void
610init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000611{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000612 ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000613 lm->LocalViewer = GL_FALSE;
614 lm->TwoSide = GL_FALSE;
615 lm->ColorControl = GL_SINGLE_COLOR;
616}
617
618
Brian Paul178a1c52000-04-22 01:05:00 +0000619static void
620init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000621{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000622 ASSIGN_4V( m->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
623 ASSIGN_4V( m->Diffuse, 0.8F, 0.8F, 0.8F, 1.0F );
624 ASSIGN_4V( m->Specular, 0.0F, 0.0F, 0.0F, 1.0F );
625 ASSIGN_4V( m->Emission, 0.0F, 0.0F, 0.0F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000626 m->Shininess = 0.0;
627 m->AmbientIndex = 0;
628 m->DiffuseIndex = 1;
629 m->SpecularIndex = 1;
630}
631
632
633
Brian Paul178a1c52000-04-22 01:05:00 +0000634static void
635init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000636{
637 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
638
639 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000640 texUnit->CombineModeRGB = GL_MODULATE;
641 texUnit->CombineModeA = GL_MODULATE;
642 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
643 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
644 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
645 texUnit->CombineSourceA[0] = GL_TEXTURE;
646 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
647 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
648 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
649 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
650 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
651 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
652 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
653 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
654 texUnit->CombineScaleShiftRGB = 0;
655 texUnit->CombineScaleShiftA = 0;
656
jtgafb833d1999-08-19 00:55:39 +0000657 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
658 texUnit->TexGenEnabled = 0;
659 texUnit->GenModeS = GL_EYE_LINEAR;
660 texUnit->GenModeT = GL_EYE_LINEAR;
661 texUnit->GenModeR = GL_EYE_LINEAR;
662 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000663 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
664 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
665 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
666 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000667
jtgafb833d1999-08-19 00:55:39 +0000668 /* Yes, these plane coefficients are correct! */
669 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
670 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
671 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
672 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
673 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
674 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
675 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
676 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
677
Brian Paula8523782000-11-19 23:10:25 +0000678 texUnit->Current1D = ctx->Shared->Default1D;
679 texUnit->Current2D = ctx->Shared->Default2D;
680 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000681 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000682}
683
684
jtgafb833d1999-08-19 00:55:39 +0000685
Brian Paul4d053dd2000-01-14 04:45:47 +0000686
jtgafb833d1999-08-19 00:55:39 +0000687/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000688static void
689init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000690{
691 map->Order = 1;
692 map->u1 = 0.0;
693 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000694 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000695 if (map->Points) {
696 GLint i;
697 for (i=0;i<n;i++)
698 map->Points[i] = initial[i];
699 }
jtgafb833d1999-08-19 00:55:39 +0000700}
701
702
703/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000704static void
705init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000706{
707 map->Uorder = 1;
708 map->Vorder = 1;
709 map->u1 = 0.0;
710 map->u2 = 1.0;
711 map->v1 = 0.0;
712 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000713 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000714 if (map->Points) {
715 GLint i;
716 for (i=0;i<n;i++)
717 map->Points[i] = initial[i];
718 }
jtgafb833d1999-08-19 00:55:39 +0000719}
720
721
jtgafb833d1999-08-19 00:55:39 +0000722/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000723 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000724 */
Brian Paul178a1c52000-04-22 01:05:00 +0000725static void
726init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000727{
728 GLuint i, j;
729
Brian Paul4d053dd2000-01-14 04:45:47 +0000730 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000731
Brian Paulcd1cefa2001-06-13 14:56:14 +0000732 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
733 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
734
Brian Paul539cce52000-02-03 19:40:07 +0000735 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000736 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +0000737 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
738 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000739 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000740 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul4d053dd2000-01-14 04:45:47 +0000741 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000742 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
743 ctx->Const.MinPointSize = MIN_POINT_SIZE;
744 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
745 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
746 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000747 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000748 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
749 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
750 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
751 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000752 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000753 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000754 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000755 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
756 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000757 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000758 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
759 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000760
Brian Paul4d053dd2000-01-14 04:45:47 +0000761 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000762 _math_matrix_ctr( &ctx->ModelView );
763 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000764
765 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000766 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000767 _math_matrix_ctr( &ctx->ModelViewStack[i] );
768 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000769 }
770
771 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000772 _math_matrix_ctr( &ctx->ProjectionMatrix );
773 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000774
775 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000776 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000777 _math_matrix_ctr( &ctx->ProjectionStack[i] );
778 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000779 }
780
Keith Whitwell23caf202000-11-16 21:05:34 +0000781 /* Derived ModelProject matrix */
782 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
783
Brian Paul4d053dd2000-01-14 04:45:47 +0000784 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000785 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000786 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000787 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000788 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000789 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000790 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000791 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000792 }
jtgafb833d1999-08-19 00:55:39 +0000793
Brian Paul250069d2000-04-08 18:57:45 +0000794 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000795 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000796 ctx->ColorStackDepth = 0;
797 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000798 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000799 }
800
Brian Paul4d053dd2000-01-14 04:45:47 +0000801 /* Accumulate buffer group */
802 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000803
Brian Paul4d053dd2000-01-14 04:45:47 +0000804 /* Color buffer group */
805 ctx->Color.IndexMask = 0xffffffff;
806 ctx->Color.ColorMask[0] = 0xff;
807 ctx->Color.ColorMask[1] = 0xff;
808 ctx->Color.ColorMask[2] = 0xff;
809 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000810 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000811 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000812 ctx->Color.DrawBuffer = GL_FRONT;
813 ctx->Color.AlphaEnabled = GL_FALSE;
814 ctx->Color.AlphaFunc = GL_ALWAYS;
815 ctx->Color.AlphaRef = 0;
816 ctx->Color.BlendEnabled = GL_FALSE;
817 ctx->Color.BlendSrcRGB = GL_ONE;
818 ctx->Color.BlendDstRGB = GL_ZERO;
819 ctx->Color.BlendSrcA = GL_ONE;
820 ctx->Color.BlendDstA = GL_ZERO;
821 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000822 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
823 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
824 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000825 ctx->Color.LogicOp = GL_COPY;
826 ctx->Color.DitherFlag = GL_TRUE;
827 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000828
Brian Paul4d053dd2000-01-14 04:45:47 +0000829 /* Current group */
Keith Whitwell51c0c712001-04-28 08:39:17 +0000830 ASSIGN_4V( ctx->Current.Color, 1.0, 1.0, 1.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000831 ctx->Current.Index = 1;
832 for (i=0; i<MAX_TEXTURE_UNITS; i++)
833 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
834 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
835 ctx->Current.RasterDistance = 0.0;
836 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
837 ctx->Current.RasterIndex = 1;
838 for (i=0; i<MAX_TEXTURE_UNITS; i++)
839 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
840 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
841 ctx->Current.RasterPosValid = GL_TRUE;
842 ctx->Current.EdgeFlag = GL_TRUE;
843 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000844
jtgafb833d1999-08-19 00:55:39 +0000845
Brian Paul4d053dd2000-01-14 04:45:47 +0000846 /* Depth buffer group */
847 ctx->Depth.Test = GL_FALSE;
848 ctx->Depth.Clear = 1.0;
849 ctx->Depth.Func = GL_LESS;
850 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000851 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000852
Brian Paul4d053dd2000-01-14 04:45:47 +0000853 /* Evaluators group */
854 ctx->Eval.Map1Color4 = GL_FALSE;
855 ctx->Eval.Map1Index = GL_FALSE;
856 ctx->Eval.Map1Normal = GL_FALSE;
857 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
858 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
859 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
860 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
861 ctx->Eval.Map1Vertex3 = GL_FALSE;
862 ctx->Eval.Map1Vertex4 = GL_FALSE;
863 ctx->Eval.Map2Color4 = GL_FALSE;
864 ctx->Eval.Map2Index = GL_FALSE;
865 ctx->Eval.Map2Normal = GL_FALSE;
866 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
867 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
868 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
869 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
870 ctx->Eval.Map2Vertex3 = GL_FALSE;
871 ctx->Eval.Map2Vertex4 = GL_FALSE;
872 ctx->Eval.AutoNormal = GL_FALSE;
873 ctx->Eval.MapGrid1un = 1;
874 ctx->Eval.MapGrid1u1 = 0.0;
875 ctx->Eval.MapGrid1u2 = 1.0;
876 ctx->Eval.MapGrid2un = 1;
877 ctx->Eval.MapGrid2vn = 1;
878 ctx->Eval.MapGrid2u1 = 0.0;
879 ctx->Eval.MapGrid2u2 = 1.0;
880 ctx->Eval.MapGrid2v1 = 0.0;
881 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000882
Brian Paul4d053dd2000-01-14 04:45:47 +0000883 /* Evaluator data */
884 {
885 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
886 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
887 static GLfloat index[1] = { 1.0 };
888 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
889 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000890
Brian Paul4d053dd2000-01-14 04:45:47 +0000891 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
892 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
893 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
894 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
895 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
896 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
897 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
898 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
899 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000900
Brian Paul4d053dd2000-01-14 04:45:47 +0000901 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
902 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
903 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
904 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
905 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
906 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
907 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
908 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
909 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
910 }
jtgafb833d1999-08-19 00:55:39 +0000911
Brian Paul4d053dd2000-01-14 04:45:47 +0000912 /* Fog group */
913 ctx->Fog.Enabled = GL_FALSE;
914 ctx->Fog.Mode = GL_EXP;
915 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
916 ctx->Fog.Index = 0.0;
917 ctx->Fog.Density = 1.0;
918 ctx->Fog.Start = 0.0;
919 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000920 ctx->Fog.ColorSumEnabled = GL_FALSE;
921 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000922
Brian Paul4d053dd2000-01-14 04:45:47 +0000923 /* Hint group */
924 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
925 ctx->Hint.PointSmooth = GL_DONT_CARE;
926 ctx->Hint.LineSmooth = GL_DONT_CARE;
927 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
928 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000929 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
930 ctx->Hint.TextureCompression = GL_DONT_CARE;
Brian Paul3893e632001-05-21 16:41:03 +0000931 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000932
Brian Paul0771d152000-04-07 00:19:41 +0000933 /* Histogram group */
934 ctx->Histogram.Width = 0;
935 ctx->Histogram.Format = GL_RGBA;
936 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000937 ctx->Histogram.RedSize = 0;
938 ctx->Histogram.GreenSize = 0;
939 ctx->Histogram.BlueSize = 0;
940 ctx->Histogram.AlphaSize = 0;
941 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000942 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
943 ctx->Histogram.Count[i][0] = 0;
944 ctx->Histogram.Count[i][1] = 0;
945 ctx->Histogram.Count[i][2] = 0;
946 ctx->Histogram.Count[i][3] = 0;
947 }
948
949 /* Min/Max group */
950 ctx->MinMax.Format = GL_RGBA;
951 ctx->MinMax.Sink = GL_FALSE;
952 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
953 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
954 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
955 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
956
Brian Paul4d053dd2000-01-14 04:45:47 +0000957 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000958 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000959
Brian Paul4d053dd2000-01-14 04:45:47 +0000960 /* Lighting group */
961 for (i=0;i<MAX_LIGHTS;i++) {
962 init_light( &ctx->Light.Light[i], i );
963 }
964 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000965
Brian Paul4d053dd2000-01-14 04:45:47 +0000966 init_lightmodel( &ctx->Light.Model );
967 init_material( &ctx->Light.Material[0] );
968 init_material( &ctx->Light.Material[1] );
969 ctx->Light.ShadeModel = GL_SMOOTH;
970 ctx->Light.Enabled = GL_FALSE;
971 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
972 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +0000973 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
974 GL_FRONT_AND_BACK,
975 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000976
Brian Paul4d053dd2000-01-14 04:45:47 +0000977 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000978
Brian Paul4d053dd2000-01-14 04:45:47 +0000979 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +0000980 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
981 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +0000982 for (i = 0 ; i < 10 ; i++) {
983 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
984 s->shininess = -1;
985 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000986 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +0000987 }
Brian Paul77d61af2000-06-28 04:20:21 +0000988
jtgafb833d1999-08-19 00:55:39 +0000989
Brian Paul4d053dd2000-01-14 04:45:47 +0000990 /* Line group */
991 ctx->Line.SmoothFlag = GL_FALSE;
992 ctx->Line.StippleFlag = GL_FALSE;
993 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +0000994 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000995 ctx->Line.StipplePattern = 0xffff;
996 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000997
Brian Paul4d053dd2000-01-14 04:45:47 +0000998 /* Display List group */
999 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001000
Brian Paul736fcbe2001-05-29 15:23:48 +00001001 /* Multisample */
1002 ctx->Multisample.Enabled = GL_FALSE;
1003 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
1004 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
1005 ctx->Multisample.SampleCoverage = GL_FALSE;
1006 ctx->Multisample.SampleCoverageValue = 1.0;
1007 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
1008
Brian Paul4d053dd2000-01-14 04:45:47 +00001009 /* Pixel group */
1010 ctx->Pixel.RedBias = 0.0;
1011 ctx->Pixel.RedScale = 1.0;
1012 ctx->Pixel.GreenBias = 0.0;
1013 ctx->Pixel.GreenScale = 1.0;
1014 ctx->Pixel.BlueBias = 0.0;
1015 ctx->Pixel.BlueScale = 1.0;
1016 ctx->Pixel.AlphaBias = 0.0;
1017 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001018 ctx->Pixel.DepthBias = 0.0;
1019 ctx->Pixel.DepthScale = 1.0;
1020 ctx->Pixel.IndexOffset = 0;
1021 ctx->Pixel.IndexShift = 0;
1022 ctx->Pixel.ZoomX = 1.0;
1023 ctx->Pixel.ZoomY = 1.0;
1024 ctx->Pixel.MapColorFlag = GL_FALSE;
1025 ctx->Pixel.MapStencilFlag = GL_FALSE;
1026 ctx->Pixel.MapStoSsize = 1;
1027 ctx->Pixel.MapItoIsize = 1;
1028 ctx->Pixel.MapItoRsize = 1;
1029 ctx->Pixel.MapItoGsize = 1;
1030 ctx->Pixel.MapItoBsize = 1;
1031 ctx->Pixel.MapItoAsize = 1;
1032 ctx->Pixel.MapRtoRsize = 1;
1033 ctx->Pixel.MapGtoGsize = 1;
1034 ctx->Pixel.MapBtoBsize = 1;
1035 ctx->Pixel.MapAtoAsize = 1;
1036 ctx->Pixel.MapStoS[0] = 0;
1037 ctx->Pixel.MapItoI[0] = 0;
1038 ctx->Pixel.MapItoR[0] = 0.0;
1039 ctx->Pixel.MapItoG[0] = 0.0;
1040 ctx->Pixel.MapItoB[0] = 0.0;
1041 ctx->Pixel.MapItoA[0] = 0.0;
1042 ctx->Pixel.MapItoR8[0] = 0;
1043 ctx->Pixel.MapItoG8[0] = 0;
1044 ctx->Pixel.MapItoB8[0] = 0;
1045 ctx->Pixel.MapItoA8[0] = 0;
1046 ctx->Pixel.MapRtoR[0] = 0.0;
1047 ctx->Pixel.MapGtoG[0] = 0.0;
1048 ctx->Pixel.MapBtoB[0] = 0.0;
1049 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001050 ctx->Pixel.HistogramEnabled = GL_FALSE;
1051 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1052 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1053 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1054 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001055 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1056 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1057 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1058 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001059 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1060 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1061 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1062 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001063 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1064 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1065 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001066 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1067 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1068 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1069 for (i = 0; i < 3; i++) {
1070 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1071 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1072 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1073 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1074 }
Brian Paul67adba12000-12-09 20:35:54 +00001075 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1076 ctx->Convolution1D.Filter[i] = 0.0;
1077 ctx->Convolution2D.Filter[i] = 0.0;
1078 ctx->Separable2D.Filter[i] = 0.0;
1079 }
Brian Paul82b02f02000-05-07 20:37:40 +00001080 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1081 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001082
Brian Paul4d053dd2000-01-14 04:45:47 +00001083 /* Point group */
1084 ctx->Point.SmoothFlag = GL_FALSE;
1085 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001086 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001087 ctx->Point.Params[0] = 1.0;
1088 ctx->Point.Params[1] = 0.0;
1089 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001090 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001091 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001092 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001093 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001094 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001095
Brian Paul4d053dd2000-01-14 04:45:47 +00001096 /* Polygon group */
1097 ctx->Polygon.CullFlag = GL_FALSE;
1098 ctx->Polygon.CullFaceMode = GL_BACK;
1099 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001100 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001101 ctx->Polygon.FrontMode = GL_FILL;
1102 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001103 ctx->Polygon.SmoothFlag = GL_FALSE;
1104 ctx->Polygon.StippleFlag = GL_FALSE;
1105 ctx->Polygon.OffsetFactor = 0.0F;
1106 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001107 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001108 ctx->Polygon.OffsetPoint = GL_FALSE;
1109 ctx->Polygon.OffsetLine = GL_FALSE;
1110 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001111
Brian Paul4d053dd2000-01-14 04:45:47 +00001112 /* Polygon Stipple group */
1113 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001114
Brian Paul4d053dd2000-01-14 04:45:47 +00001115 /* Scissor group */
1116 ctx->Scissor.Enabled = GL_FALSE;
1117 ctx->Scissor.X = 0;
1118 ctx->Scissor.Y = 0;
1119 ctx->Scissor.Width = 0;
1120 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001121
Brian Paul4d053dd2000-01-14 04:45:47 +00001122 /* Stencil group */
1123 ctx->Stencil.Enabled = GL_FALSE;
1124 ctx->Stencil.Function = GL_ALWAYS;
1125 ctx->Stencil.FailFunc = GL_KEEP;
1126 ctx->Stencil.ZPassFunc = GL_KEEP;
1127 ctx->Stencil.ZFailFunc = GL_KEEP;
1128 ctx->Stencil.Ref = 0;
1129 ctx->Stencil.ValueMask = STENCIL_MAX;
1130 ctx->Stencil.Clear = 0;
1131 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001132
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 /* Texture group */
1134 ctx->Texture.CurrentUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001135 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001136 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1137 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001138 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001139 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001140
Brian Paul4d053dd2000-01-14 04:45:47 +00001141 /* Transformation group */
1142 ctx->Transform.MatrixMode = GL_MODELVIEW;
1143 ctx->Transform.Normalize = GL_FALSE;
1144 ctx->Transform.RescaleNormals = GL_FALSE;
Brian Paul8c2f6c52001-06-26 01:32:48 +00001145 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001146 for (i=0;i<MAX_CLIP_PLANES;i++) {
1147 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1148 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1149 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001150 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001151
Brian Paul4d053dd2000-01-14 04:45:47 +00001152 /* Viewport group */
1153 ctx->Viewport.X = 0;
1154 ctx->Viewport.Y = 0;
1155 ctx->Viewport.Width = 0;
1156 ctx->Viewport.Height = 0;
1157 ctx->Viewport.Near = 0.0;
1158 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001159 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001160
1161#define Sz 10
1162#define Tz 14
Brian Paulfde5e2c2001-09-15 18:02:49 +00001163 ctx->Viewport._WindowMap.m[Sz] = 0.5F * ctx->DepthMaxF;
1164 ctx->Viewport._WindowMap.m[Tz] = 0.5F * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001165#undef Sz
1166#undef Tz
1167
Keith Whitwell14940c42000-11-05 18:40:57 +00001168 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1169 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001170
Brian Paul4d053dd2000-01-14 04:45:47 +00001171 /* Vertex arrays */
1172 ctx->Array.Vertex.Size = 4;
1173 ctx->Array.Vertex.Type = GL_FLOAT;
1174 ctx->Array.Vertex.Stride = 0;
1175 ctx->Array.Vertex.StrideB = 0;
1176 ctx->Array.Vertex.Ptr = NULL;
1177 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001178 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001179 ctx->Array.Normal.Type = GL_FLOAT;
1180 ctx->Array.Normal.Stride = 0;
1181 ctx->Array.Normal.StrideB = 0;
1182 ctx->Array.Normal.Ptr = NULL;
1183 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001184 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001185 ctx->Array.Color.Size = 4;
1186 ctx->Array.Color.Type = GL_FLOAT;
1187 ctx->Array.Color.Stride = 0;
1188 ctx->Array.Color.StrideB = 0;
1189 ctx->Array.Color.Ptr = NULL;
1190 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001191 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1192 ctx->Array.SecondaryColor.Size = 4;
1193 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1194 ctx->Array.SecondaryColor.Stride = 0;
1195 ctx->Array.SecondaryColor.StrideB = 0;
1196 ctx->Array.SecondaryColor.Ptr = NULL;
1197 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1198 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1199 ctx->Array.FogCoord.Size = 1;
1200 ctx->Array.FogCoord.Type = GL_FLOAT;
1201 ctx->Array.FogCoord.Stride = 0;
1202 ctx->Array.FogCoord.StrideB = 0;
1203 ctx->Array.FogCoord.Ptr = NULL;
1204 ctx->Array.FogCoord.Enabled = GL_FALSE;
1205 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001206 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;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001211 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001212 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1213 ctx->Array.TexCoord[i].Size = 4;
1214 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1215 ctx->Array.TexCoord[i].Stride = 0;
1216 ctx->Array.TexCoord[i].StrideB = 0;
1217 ctx->Array.TexCoord[i].Ptr = NULL;
1218 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001219 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001220 }
1221 ctx->Array.TexCoordInterleaveFactor = 1;
1222 ctx->Array.EdgeFlag.Stride = 0;
1223 ctx->Array.EdgeFlag.StrideB = 0;
1224 ctx->Array.EdgeFlag.Ptr = NULL;
1225 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001226 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001227 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1228
1229 /* Pixel transfer */
1230 ctx->Pack.Alignment = 4;
1231 ctx->Pack.RowLength = 0;
1232 ctx->Pack.ImageHeight = 0;
1233 ctx->Pack.SkipPixels = 0;
1234 ctx->Pack.SkipRows = 0;
1235 ctx->Pack.SkipImages = 0;
1236 ctx->Pack.SwapBytes = GL_FALSE;
1237 ctx->Pack.LsbFirst = GL_FALSE;
1238 ctx->Unpack.Alignment = 4;
1239 ctx->Unpack.RowLength = 0;
1240 ctx->Unpack.ImageHeight = 0;
1241 ctx->Unpack.SkipPixels = 0;
1242 ctx->Unpack.SkipRows = 0;
1243 ctx->Unpack.SkipImages = 0;
1244 ctx->Unpack.SwapBytes = GL_FALSE;
1245 ctx->Unpack.LsbFirst = GL_FALSE;
1246
1247 /* Feedback */
1248 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1249 ctx->Feedback.Buffer = NULL;
1250 ctx->Feedback.BufferSize = 0;
1251 ctx->Feedback.Count = 0;
1252
1253 /* Selection/picking */
1254 ctx->Select.Buffer = NULL;
1255 ctx->Select.BufferSize = 0;
1256 ctx->Select.BufferCount = 0;
1257 ctx->Select.Hits = 0;
1258 ctx->Select.NameStackDepth = 0;
1259
Brian Paul4d053dd2000-01-14 04:45:47 +00001260 /* Renderer and client attribute stacks */
1261 ctx->AttribStackDepth = 0;
1262 ctx->ClientAttribStackDepth = 0;
1263
Brian Paul13811372000-04-12 00:27:37 +00001264 /* Display list */
1265 ctx->CallDepth = 0;
1266 ctx->ExecuteFlag = GL_TRUE;
1267 ctx->CompileFlag = GL_FALSE;
1268 ctx->CurrentListPtr = NULL;
1269 ctx->CurrentBlock = NULL;
1270 ctx->CurrentListNum = 0;
1271 ctx->CurrentPos = 0;
1272
1273 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001274 _mesa_init_colortable(&ctx->ColorTable);
1275 _mesa_init_colortable(&ctx->ProxyColorTable);
1276 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1277 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1278 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1279 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001280
Brian Paul4d053dd2000-01-14 04:45:47 +00001281 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001282 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001283 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001284 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001285
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001286 ctx->_NeedNormals = 0;
1287 ctx->_NeedEyeCoords = 0;
1288 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001289
Brian Paul4d053dd2000-01-14 04:45:47 +00001290 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1291
1292 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001293 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001294 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001295
1296 /* For debug/development only */
1297 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1298 ctx->FirstTimeCurrent = GL_TRUE;
1299
1300 /* Dither disable */
1301 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1302 if (ctx->NoDither) {
1303 if (getenv("MESA_DEBUG")) {
1304 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001305 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001306 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001307 }
1308}
1309
1310
1311
1312
jtgafb833d1999-08-19 00:55:39 +00001313/*
1314 * Allocate the proxy textures. If we run out of memory part way through
1315 * the allocations clean up and return GL_FALSE.
1316 * Return: GL_TRUE=success, GL_FALSE=failure
1317 */
Brian Paul178a1c52000-04-22 01:05:00 +00001318static GLboolean
1319alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001320{
1321 GLboolean out_of_memory;
1322 GLint i;
1323
Brian Paula8523782000-11-19 23:10:25 +00001324 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001325 if (!ctx->Texture.Proxy1D) {
1326 return GL_FALSE;
1327 }
1328
Brian Paula8523782000-11-19 23:10:25 +00001329 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001330 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001331 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001332 return GL_FALSE;
1333 }
1334
Brian Paula8523782000-11-19 23:10:25 +00001335 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001336 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001337 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1338 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1339 return GL_FALSE;
1340 }
1341
1342 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1343 if (!ctx->Texture.ProxyCubeMap) {
1344 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1345 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1346 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001347 return GL_FALSE;
1348 }
1349
1350 out_of_memory = GL_FALSE;
1351 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001352 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1353 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1354 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
Brian Paul172281d2001-07-26 20:02:10 +00001355 ctx->Texture.ProxyCubeMap->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001356 if (!ctx->Texture.Proxy1D->Image[i]
1357 || !ctx->Texture.Proxy2D->Image[i]
Brian Paul172281d2001-07-26 20:02:10 +00001358 || !ctx->Texture.Proxy3D->Image[i]
1359 || !ctx->Texture.ProxyCubeMap->Image[i]) {
jtgafb833d1999-08-19 00:55:39 +00001360 out_of_memory = GL_TRUE;
1361 }
1362 }
1363 if (out_of_memory) {
1364 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1365 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001366 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001367 }
1368 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001369 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001370 }
1371 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001372 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001373 }
Brian Paul172281d2001-07-26 20:02:10 +00001374 if (ctx->Texture.ProxyCubeMap->Image[i]) {
1375 _mesa_free_texture_image(ctx->Texture.ProxyCubeMap->Image[i]);
1376 }
jtgafb833d1999-08-19 00:55:39 +00001377 }
Brian Paula8523782000-11-19 23:10:25 +00001378 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1379 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1380 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
Brian Paul172281d2001-07-26 20:02:10 +00001381 _mesa_free_texture_object(NULL, ctx->Texture.ProxyCubeMap);
jtgafb833d1999-08-19 00:55:39 +00001382 return GL_FALSE;
1383 }
1384 else {
1385 return GL_TRUE;
1386 }
1387}
1388
1389
jtgafb833d1999-08-19 00:55:39 +00001390/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001391 * Initialize a GLcontext struct. This includes allocating all the
1392 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001393 */
Brian Paul178a1c52000-04-22 01:05:00 +00001394GLboolean
1395_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001396 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001397 GLcontext *share_list,
1398 void *driver_ctx,
1399 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001400{
Brian Paul5fb84d22000-05-24 15:04:45 +00001401 GLuint dispatchSize;
1402
jtgafb833d1999-08-19 00:55:39 +00001403 (void) direct; /* not used */
1404
jtgafb833d1999-08-19 00:55:39 +00001405 /* misc one-time initializations */
1406 one_time_init();
1407
Brian Paulb1394fa2000-09-26 20:53:53 +00001408 /**
1409 ** OpenGL SI stuff
1410 **/
1411 if (!ctx->imports.malloc) {
1412 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1413 }
1414 /* exports are setup by the device driver */
1415
jtgafb833d1999-08-19 00:55:39 +00001416 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001417 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001418 ctx->DrawBuffer = NULL;
1419 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001420
jtgafb833d1999-08-19 00:55:39 +00001421 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001422 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001423 ctx->Shared = share_list->Shared;
1424 }
1425 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001426 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001427 ctx->Shared = alloc_shared_state();
1428 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001429 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001430 }
1431 }
Brian Paul9560f052000-01-31 23:11:39 +00001432 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001433 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001434 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001435
Brian Paul5a2f32b2001-04-25 18:21:05 +00001436 /* Effectively bind the default textures to all texture units */
1437 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1438 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1439 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1440 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1441
Brian Paul4d053dd2000-01-14 04:45:47 +00001442 init_attrib_groups( ctx );
1443
Brian Paulb6bcae52001-01-23 23:39:36 +00001444 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001445 ctx->Color.DrawBuffer = GL_BACK;
1446 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1447 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1448 ctx->Pixel.ReadBuffer = GL_BACK;
1449 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1450 }
1451 else {
1452 ctx->Color.DrawBuffer = GL_FRONT;
1453 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1454 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1455 ctx->Pixel.ReadBuffer = GL_FRONT;
1456 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1457 }
1458
jtgafb833d1999-08-19 00:55:39 +00001459 if (!alloc_proxy_textures(ctx)) {
1460 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001461 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001462 }
jtgafb833d1999-08-19 00:55:39 +00001463
Brian Paulf59afc92000-05-23 23:23:00 +00001464 /* register the most recent extension functions with libGL */
1465 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1466 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1467 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1468 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1469 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1470 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1471 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1472 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1473
Brian Paul5fb84d22000-05-24 15:04:45 +00001474 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1475 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1476 * Mesa we do this to accomodate different versions of libGL and various
1477 * DRI drivers.
1478 */
1479 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1480 sizeof(struct _glapi_table) / sizeof(void *));
1481
Brian Paulfbd8f211999-11-11 01:22:25 +00001482 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001483 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1484 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001485 if (!ctx->Exec || !ctx->Save) {
1486 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001487 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001488 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001489 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001490 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1491 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001492 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001493
Keith Whitwellad2ac212000-11-24 10:25:05 +00001494 ctx->ExecPrefersFloat = GL_FALSE;
1495 ctx->SavePrefersFloat = GL_FALSE;
1496
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001497 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001498 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001499 ctx->TnlModule.Current = NULL;
1500 ctx->TnlModule.SwapCount = 0;
1501
Brian Paulb6bcae52001-01-23 23:39:36 +00001502 /* Z buffer stuff */
1503 if (ctx->Visual.depthBits == 0) {
1504 /* Special case. Even if we don't have a depth buffer we need
1505 * good values for DepthMax for Z vertex transformation purposes
1506 * and for per-fragment fog computation.
1507 */
1508 ctx->DepthMax = 1 << 16;
1509 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1510 }
1511 else if (ctx->Visual.depthBits < 32) {
1512 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1513 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1514 }
1515 else {
1516 /* Special case since shift values greater than or equal to the
1517 * number of bits in the left hand expression's type are undefined.
1518 */
1519 ctx->DepthMax = 0xffffffff;
1520 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1521 }
Brian Paulbc920f02001-05-07 16:32:51 +00001522 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001523
1524
Brian Paul3b18a362000-09-26 15:27:20 +00001525#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001526 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001527#if 0
1528 /* Brian: do you want to have CreateContext fail here,
1529 or should we just trap in NewTrace (currently done)? */
1530 if (!(ctx->TraceCtx)) {
1531 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001532 FREE( ctx->Exec );
1533 FREE( ctx->Save );
1534 return GL_FALSE;
1535 }
1536#endif
1537 trInitContext(ctx->TraceCtx);
1538
1539 ctx->TraceDispatch = (struct _glapi_table *)
1540 CALLOC(dispatchSize * sizeof(void*));
1541#if 0
1542 if (!(ctx->TraceCtx)) {
1543 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001544 FREE( ctx->Exec );
1545 FREE( ctx->Save );
1546 FREE( ctx->TraceCtx );
1547 return GL_FALSE;
1548 }
1549#endif
1550 trInitDispatch(ctx->TraceDispatch);
1551#endif
1552
Brian Paul4d053dd2000-01-14 04:45:47 +00001553 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001554}
1555
jtgafb833d1999-08-19 00:55:39 +00001556
1557
1558/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001559 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001560 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001561 * sharelist - another context to share display lists with or NULL
1562 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001563 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001564 */
Brian Paul178a1c52000-04-22 01:05:00 +00001565GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001566_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001567 GLcontext *share_list,
1568 void *driver_ctx,
1569 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001570{
1571 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1572 if (!ctx) {
1573 return NULL;
1574 }
Jouk Jansen12e875c2001-10-18 08:04:57 +00001575 ctx->Driver.CurrentExecPrimitive = 0;
Brian Paul178a1c52000-04-22 01:05:00 +00001576 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001577 return ctx;
1578 }
1579 else {
1580 FREE(ctx);
1581 return NULL;
1582 }
1583}
1584
1585
1586
1587/*
1588 * Free the data associated with the given context.
1589 * But don't free() the GLcontext struct itself!
1590 */
Brian Paul178a1c52000-04-22 01:05:00 +00001591void
Brian Paulb1394fa2000-09-26 20:53:53 +00001592_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001593{
Brian Paul4d053dd2000-01-14 04:45:47 +00001594 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001595 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001596
1597 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001598 if (ctx == _mesa_get_current_context()) {
1599 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001600 }
1601
Keith Whitwell23caf202000-11-16 21:05:34 +00001602 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001603 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001604 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001605 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001606 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001607 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001608 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001609 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001610 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001611 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001612 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001613 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001614 }
1615 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001616
Brian Paulfd284452001-07-19 15:54:34 +00001617 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
1618
1619 _math_matrix_dtr(&ctx->ColorMatrix);
1620 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
1621 _math_matrix_dtr(&ctx->ColorStack[j]);
1622 }
1623
Brian Paul9560f052000-01-31 23:11:39 +00001624 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001625 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001626 assert(ctx->Shared->RefCount >= 0);
1627 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1628 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001629 /* free shared state */
1630 free_shared_state( ctx, ctx->Shared );
1631 }
1632
Keith Whitwell14940c42000-11-05 18:40:57 +00001633 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001634 FREE( s );
1635 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001636 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001637
1638 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001639 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1640 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1641 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paulfd284452001-07-19 15:54:34 +00001642 _mesa_free_texture_object( NULL, ctx->Texture.ProxyCubeMap );
Brian Paul4d053dd2000-01-14 04:45:47 +00001643
1644 /* Free evaluator data */
1645 if (ctx->EvalMap.Map1Vertex3.Points)
1646 FREE( ctx->EvalMap.Map1Vertex3.Points );
1647 if (ctx->EvalMap.Map1Vertex4.Points)
1648 FREE( ctx->EvalMap.Map1Vertex4.Points );
1649 if (ctx->EvalMap.Map1Index.Points)
1650 FREE( ctx->EvalMap.Map1Index.Points );
1651 if (ctx->EvalMap.Map1Color4.Points)
1652 FREE( ctx->EvalMap.Map1Color4.Points );
1653 if (ctx->EvalMap.Map1Normal.Points)
1654 FREE( ctx->EvalMap.Map1Normal.Points );
1655 if (ctx->EvalMap.Map1Texture1.Points)
1656 FREE( ctx->EvalMap.Map1Texture1.Points );
1657 if (ctx->EvalMap.Map1Texture2.Points)
1658 FREE( ctx->EvalMap.Map1Texture2.Points );
1659 if (ctx->EvalMap.Map1Texture3.Points)
1660 FREE( ctx->EvalMap.Map1Texture3.Points );
1661 if (ctx->EvalMap.Map1Texture4.Points)
1662 FREE( ctx->EvalMap.Map1Texture4.Points );
1663
1664 if (ctx->EvalMap.Map2Vertex3.Points)
1665 FREE( ctx->EvalMap.Map2Vertex3.Points );
1666 if (ctx->EvalMap.Map2Vertex4.Points)
1667 FREE( ctx->EvalMap.Map2Vertex4.Points );
1668 if (ctx->EvalMap.Map2Index.Points)
1669 FREE( ctx->EvalMap.Map2Index.Points );
1670 if (ctx->EvalMap.Map2Color4.Points)
1671 FREE( ctx->EvalMap.Map2Color4.Points );
1672 if (ctx->EvalMap.Map2Normal.Points)
1673 FREE( ctx->EvalMap.Map2Normal.Points );
1674 if (ctx->EvalMap.Map2Texture1.Points)
1675 FREE( ctx->EvalMap.Map2Texture1.Points );
1676 if (ctx->EvalMap.Map2Texture2.Points)
1677 FREE( ctx->EvalMap.Map2Texture2.Points );
1678 if (ctx->EvalMap.Map2Texture3.Points)
1679 FREE( ctx->EvalMap.Map2Texture3.Points );
1680 if (ctx->EvalMap.Map2Texture4.Points)
1681 FREE( ctx->EvalMap.Map2Texture4.Points );
1682
Brian Paul4bdcfe52000-04-17 17:57:04 +00001683 _mesa_free_colortable_data( &ctx->ColorTable );
1684 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1685 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1686 _mesa_free_colortable_data( &ctx->Texture.Palette );
1687
Brian Paulfd284452001-07-19 15:54:34 +00001688 _math_matrix_dtr(&ctx->Viewport._WindowMap);
1689
Brian Paul69755402001-02-26 23:58:12 +00001690 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001691
1692 FREE(ctx->Exec);
1693 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001694}
1695
1696
1697
1698/*
1699 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001700 */
Brian Paul178a1c52000-04-22 01:05:00 +00001701void
Brian Paulb1394fa2000-09-26 20:53:53 +00001702_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001703{
1704 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001705 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001706 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001707 }
1708}
1709
1710
1711
1712/*
jtgafb833d1999-08-19 00:55:39 +00001713 * Copy attribute groups from one context to another.
1714 * Input: src - source context
1715 * dst - destination context
1716 * mask - bitwise OR of GL_*_BIT flags
1717 */
Brian Paul178a1c52000-04-22 01:05:00 +00001718void
Brian Paulb1394fa2000-09-26 20:53:53 +00001719_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001720{
1721 if (mask & GL_ACCUM_BUFFER_BIT) {
1722 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1723 }
1724 if (mask & GL_COLOR_BUFFER_BIT) {
1725 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1726 }
1727 if (mask & GL_CURRENT_BIT) {
1728 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1729 }
1730 if (mask & GL_DEPTH_BUFFER_BIT) {
1731 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1732 }
1733 if (mask & GL_ENABLE_BIT) {
1734 /* no op */
1735 }
1736 if (mask & GL_EVAL_BIT) {
1737 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1738 }
1739 if (mask & GL_FOG_BIT) {
1740 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1741 }
1742 if (mask & GL_HINT_BIT) {
1743 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1744 }
1745 if (mask & GL_LIGHTING_BIT) {
1746 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001747 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001748 }
1749 if (mask & GL_LINE_BIT) {
1750 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1751 }
1752 if (mask & GL_LIST_BIT) {
1753 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1754 }
1755 if (mask & GL_PIXEL_MODE_BIT) {
1756 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1757 }
1758 if (mask & GL_POINT_BIT) {
1759 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1760 }
1761 if (mask & GL_POLYGON_BIT) {
1762 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1763 }
1764 if (mask & GL_POLYGON_STIPPLE_BIT) {
1765 /* Use loop instead of MEMCPY due to problem with Portland Group's
1766 * C compiler. Reported by John Stone.
1767 */
1768 int i;
1769 for (i=0;i<32;i++) {
1770 dst->PolygonStipple[i] = src->PolygonStipple[i];
1771 }
1772 }
1773 if (mask & GL_SCISSOR_BIT) {
1774 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1775 }
1776 if (mask & GL_STENCIL_BUFFER_BIT) {
1777 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1778 }
1779 if (mask & GL_TEXTURE_BIT) {
1780 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1781 }
1782 if (mask & GL_TRANSFORM_BIT) {
1783 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1784 }
1785 if (mask & GL_VIEWPORT_BIT) {
1786 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1787 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001788 /* XXX FIXME: Call callbacks?
1789 */
1790 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001791}
1792
1793
jtgafb833d1999-08-19 00:55:39 +00001794/*
Brian Paul00037781999-12-17 14:52:35 +00001795 * Set the current context, binding the given frame buffer to the context.
1796 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001797void
1798_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001799{
Brian Paulb1394fa2000-09-26 20:53:53 +00001800 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001801}
1802
1803
Keith Whitwell23caf202000-11-16 21:05:34 +00001804static void print_info( void )
1805{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001806 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001807 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001808 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001809 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001810 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001811 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001812 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001813 (char *) _mesa_GetString(GL_EXTENSIONS));
1814#if defined(THREADS)
1815 fprintf(stderr, "Mesa thread-safe: YES\n");
1816#else
1817 fprintf(stderr, "Mesa thread-safe: NO\n");
1818#endif
1819#if defined(USE_X86_ASM)
1820 fprintf(stderr, "Mesa x86-optimized: YES\n");
1821#else
1822 fprintf(stderr, "Mesa x86-optimized: NO\n");
1823#endif
davem69e4f84b42001-06-05 03:58:20 +00001824#if defined(USE_SPARC_ASM)
1825 fprintf(stderr, "Mesa sparc-optimized: YES\n");
1826#else
1827 fprintf(stderr, "Mesa sparc-optimized: NO\n");
1828#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001829}
1830
1831
Brian Paul00037781999-12-17 14:52:35 +00001832/*
1833 * Bind the given context to the given draw-buffer and read-buffer
1834 * and make it the current context for this thread.
1835 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001836void
1837_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1838 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001839{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001840 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001841 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001842
Brian Paulbe3602d2001-02-28 00:27:48 +00001843 /* Check that the context's and framebuffer's visuals are compatible.
1844 * We could do a lot more checking here but this'll catch obvious
1845 * problems.
1846 */
1847 if (newCtx && drawBuffer && readBuffer) {
1848 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1849 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1850 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1851 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1852 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1853 return; /* incompatible */
1854 }
1855 }
1856
Brian Paul00037781999-12-17 14:52:35 +00001857 /* We call this function periodically (just here for now) in
1858 * order to detect when multithreading has begun.
1859 */
1860 _glapi_check_multithread();
1861
Brian Paulf9b97d92000-01-28 20:17:42 +00001862 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001863 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001864
1865
1866 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001867 _glapi_set_dispatch(NULL); /* none current */
1868 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001869 else {
1870 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001871
Keith Whitwell23caf202000-11-16 21:05:34 +00001872 if (drawBuffer && readBuffer) {
1873 /* TODO: check if newCtx and buffer's visual match??? */
1874 newCtx->DrawBuffer = drawBuffer;
1875 newCtx->ReadBuffer = readBuffer;
1876 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001877 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001878 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001879
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001880 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001881 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1882
1883 /* We can use this to help debug user's problems. Tell them to set
1884 * the MESA_INFO env variable before running their app. Then the
1885 * first time each context is made current we'll print some useful
1886 * information.
1887 */
1888 if (newCtx->FirstTimeCurrent) {
1889 if (getenv("MESA_INFO")) {
1890 print_info();
1891 }
1892 newCtx->FirstTimeCurrent = GL_FALSE;
1893 }
Brian Paul00037781999-12-17 14:52:35 +00001894 }
1895}
1896
1897
1898
1899/*
1900 * Return current context handle for the calling thread.
1901 * This isn't the fastest way to get the current context.
1902 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1903 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001904GLcontext *
1905_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001906{
Brian Paulf9b97d92000-01-28 20:17:42 +00001907 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001908}
1909
1910
1911
1912/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001913 * This should be called by device drivers just before they do a
1914 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001915 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001916void
1917_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001918{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001919 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001920}
1921
1922
Brian Paul00037781999-12-17 14:52:35 +00001923
Brian Paulfbd8f211999-11-11 01:22:25 +00001924/*
1925 * Return pointer to this context's current API dispatch table.
1926 * It'll either be the immediate-mode execute dispatcher or the
1927 * display list compile dispatcher.
1928 */
1929struct _glapi_table *
1930_mesa_get_dispatch(GLcontext *ctx)
1931{
1932 return ctx->CurrentDispatch;
1933}
1934
1935
1936
jtgafb833d1999-08-19 00:55:39 +00001937/**********************************************************************/
1938/***** Miscellaneous functions *****/
1939/**********************************************************************/
1940
1941
1942/*
1943 * This function is called when the Mesa user has stumbled into a code
1944 * path which may not be implemented fully or correctly.
1945 */
Brian Paul08836342001-03-03 20:33:27 +00001946void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001947{
1948 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00001949#ifdef XF86DRI
1950 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
1951#else
1952 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
1953#endif
jtgafb833d1999-08-19 00:55:39 +00001954 (void) ctx;
1955}
1956
1957
1958
1959/*
1960 * This is called to inform the user that he or she has tried to do
1961 * something illogical or if there's likely a bug in their program
1962 * (like enabled depth testing without a depth buffer).
1963 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001964void
1965_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001966{
Brian Paulb1394fa2000-09-26 20:53:53 +00001967 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001968}
1969
1970
1971
Brian Paulfa9df402000-02-02 19:16:46 +00001972/*
1973 * Compile an error into current display list.
1974 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001975void
1976_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001977{
1978 if (ctx->CompileFlag)
Brian Paul08836342001-03-03 20:33:27 +00001979 _mesa_save_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001980
1981 if (ctx->ExecuteFlag)
Brian Paul08836342001-03-03 20:33:27 +00001982 _mesa_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001983}
1984
1985
Brian Paulfa9df402000-02-02 19:16:46 +00001986
jtgafb833d1999-08-19 00:55:39 +00001987/*
1988 * This is Mesa's error handler. Normally, all that's done is the updating
1989 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1990 * environment variable "MESA_DEBUG" is defined then a real error message
1991 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001992 * Input: ctx - the GL context
1993 * error - the error value
1994 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001995 */
Brian Paul7eb06032000-07-14 04:13:40 +00001996void
Brian Paul08836342001-03-03 20:33:27 +00001997_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001998{
Brian Paul7eb06032000-07-14 04:13:40 +00001999 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00002000 GLboolean debug;
2001
2002#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002003 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002004 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002005 else
2006 debug = GL_TRUE;
2007#else
2008 if (debugEnv)
2009 debug = GL_TRUE;
2010 else
2011 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002012#endif
2013
2014 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002015 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002016 switch (error) {
2017 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002018 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002019 break;
2020 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002021 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002022 break;
2023 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002024 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002025 break;
2026 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002027 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002028 break;
2029 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002030 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002031 break;
2032 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002033 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002034 break;
2035 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002036 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002037 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002038 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002039 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002040 break;
jtgafb833d1999-08-19 00:55:39 +00002041 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002042 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002043 break;
2044 }
Brian Paul7eb06032000-07-14 04:13:40 +00002045 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002046 }
2047
Brian Paul7eb06032000-07-14 04:13:40 +00002048 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002049 ctx->ErrorValue = error;
2050 }
2051
2052 /* Call device driver's error handler, if any. This is used on the Mac. */
2053 if (ctx->Driver.Error) {
2054 (*ctx->Driver.Error)( ctx );
2055 }
2056}
2057
2058
2059
Brian Paulfa9df402000-02-02 19:16:46 +00002060void
2061_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002062{
Brian Paulfa9df402000-02-02 19:16:46 +00002063 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002064 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002065 if (ctx->Driver.Finish) {
2066 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002067 }
2068}
2069
2070
2071
Brian Paulfa9df402000-02-02 19:16:46 +00002072void
2073_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002074{
Brian Paulfa9df402000-02-02 19:16:46 +00002075 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002076 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002077 if (ctx->Driver.Flush) {
2078 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002079 }
jtgafb833d1999-08-19 00:55:39 +00002080}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002081
2082
2083
Keith Whitwellcab974c2000-12-26 05:09:27 +00002084const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002085 "GL_POINTS",
2086 "GL_LINES",
2087 "GL_LINE_LOOP",
2088 "GL_LINE_STRIP",
2089 "GL_TRIANGLES",
2090 "GL_TRIANGLE_STRIP",
2091 "GL_TRIANGLE_FAN",
2092 "GL_QUADS",
2093 "GL_QUAD_STRIP",
2094 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002095 "outside begin/end",
2096 "inside unkown primitive",
2097 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002098};