blob: 230af9c564fa86e7050c1fdb4b0d1bac3568555c [file] [log] [blame]
Brian Paul87c964d2001-11-06 15:53:00 +00001/* $Id: context.c,v 1.149 2001/11/06 15:53:00 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paule4b684c2000-09-12 21:07:40 +00005 * Version: 3.5
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian 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 Paul87c964d2001-11-06 15:53:00 +0000741 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000742 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000743 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
744 ctx->Const.MinPointSize = MIN_POINT_SIZE;
745 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
746 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
747 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000748 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000749 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
750 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
751 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
752 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000753 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000754 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000755 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000756 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
757 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000758 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000759 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
760 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000761
Brian Paul4d053dd2000-01-14 04:45:47 +0000762 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000763 _math_matrix_ctr( &ctx->ModelView );
764 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000765
766 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000767 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000768 _math_matrix_ctr( &ctx->ModelViewStack[i] );
769 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000770 }
771
772 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000773 _math_matrix_ctr( &ctx->ProjectionMatrix );
774 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000775
776 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000777 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000778 _math_matrix_ctr( &ctx->ProjectionStack[i] );
779 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000780 }
781
Keith Whitwell23caf202000-11-16 21:05:34 +0000782 /* Derived ModelProject matrix */
783 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
784
Brian Paul4d053dd2000-01-14 04:45:47 +0000785 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000786 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000787 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000788 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000789 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000790 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000791 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000792 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000793 }
jtgafb833d1999-08-19 00:55:39 +0000794
Brian Paul250069d2000-04-08 18:57:45 +0000795 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000796 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000797 ctx->ColorStackDepth = 0;
798 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000799 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000800 }
801
Brian Paul4d053dd2000-01-14 04:45:47 +0000802 /* Accumulate buffer group */
803 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000804
Brian Paul4d053dd2000-01-14 04:45:47 +0000805 /* Color buffer group */
806 ctx->Color.IndexMask = 0xffffffff;
807 ctx->Color.ColorMask[0] = 0xff;
808 ctx->Color.ColorMask[1] = 0xff;
809 ctx->Color.ColorMask[2] = 0xff;
810 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000811 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000812 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000813 ctx->Color.DrawBuffer = GL_FRONT;
814 ctx->Color.AlphaEnabled = GL_FALSE;
815 ctx->Color.AlphaFunc = GL_ALWAYS;
816 ctx->Color.AlphaRef = 0;
817 ctx->Color.BlendEnabled = GL_FALSE;
818 ctx->Color.BlendSrcRGB = GL_ONE;
819 ctx->Color.BlendDstRGB = GL_ZERO;
820 ctx->Color.BlendSrcA = GL_ONE;
821 ctx->Color.BlendDstA = GL_ZERO;
822 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000823 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
824 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
825 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000826 ctx->Color.LogicOp = GL_COPY;
827 ctx->Color.DitherFlag = GL_TRUE;
828 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000829
Brian Paul4d053dd2000-01-14 04:45:47 +0000830 /* Current group */
Keith Whitwell51c0c712001-04-28 08:39:17 +0000831 ASSIGN_4V( ctx->Current.Color, 1.0, 1.0, 1.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000832 ctx->Current.Index = 1;
833 for (i=0; i<MAX_TEXTURE_UNITS; i++)
834 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
835 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
836 ctx->Current.RasterDistance = 0.0;
837 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
838 ctx->Current.RasterIndex = 1;
839 for (i=0; i<MAX_TEXTURE_UNITS; i++)
840 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
841 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
842 ctx->Current.RasterPosValid = GL_TRUE;
843 ctx->Current.EdgeFlag = GL_TRUE;
844 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000845
jtgafb833d1999-08-19 00:55:39 +0000846
Brian Paul4d053dd2000-01-14 04:45:47 +0000847 /* Depth buffer group */
848 ctx->Depth.Test = GL_FALSE;
849 ctx->Depth.Clear = 1.0;
850 ctx->Depth.Func = GL_LESS;
851 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000852 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000853
Brian Paul4d053dd2000-01-14 04:45:47 +0000854 /* Evaluators group */
855 ctx->Eval.Map1Color4 = GL_FALSE;
856 ctx->Eval.Map1Index = GL_FALSE;
857 ctx->Eval.Map1Normal = GL_FALSE;
858 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
859 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
860 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
861 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
862 ctx->Eval.Map1Vertex3 = GL_FALSE;
863 ctx->Eval.Map1Vertex4 = GL_FALSE;
864 ctx->Eval.Map2Color4 = GL_FALSE;
865 ctx->Eval.Map2Index = GL_FALSE;
866 ctx->Eval.Map2Normal = GL_FALSE;
867 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
868 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
869 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
870 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
871 ctx->Eval.Map2Vertex3 = GL_FALSE;
872 ctx->Eval.Map2Vertex4 = GL_FALSE;
873 ctx->Eval.AutoNormal = GL_FALSE;
874 ctx->Eval.MapGrid1un = 1;
875 ctx->Eval.MapGrid1u1 = 0.0;
876 ctx->Eval.MapGrid1u2 = 1.0;
877 ctx->Eval.MapGrid2un = 1;
878 ctx->Eval.MapGrid2vn = 1;
879 ctx->Eval.MapGrid2u1 = 0.0;
880 ctx->Eval.MapGrid2u2 = 1.0;
881 ctx->Eval.MapGrid2v1 = 0.0;
882 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000883
Brian Paul4d053dd2000-01-14 04:45:47 +0000884 /* Evaluator data */
885 {
886 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
887 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
888 static GLfloat index[1] = { 1.0 };
889 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
890 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000891
Brian Paul4d053dd2000-01-14 04:45:47 +0000892 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
893 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
894 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
895 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
896 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
897 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
898 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
899 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
900 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000901
Brian Paul4d053dd2000-01-14 04:45:47 +0000902 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
903 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
904 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
905 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
906 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
907 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
908 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
909 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
910 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
911 }
jtgafb833d1999-08-19 00:55:39 +0000912
Brian Paul4d053dd2000-01-14 04:45:47 +0000913 /* Fog group */
914 ctx->Fog.Enabled = GL_FALSE;
915 ctx->Fog.Mode = GL_EXP;
916 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
917 ctx->Fog.Index = 0.0;
918 ctx->Fog.Density = 1.0;
919 ctx->Fog.Start = 0.0;
920 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000921 ctx->Fog.ColorSumEnabled = GL_FALSE;
922 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000923
Brian Paul4d053dd2000-01-14 04:45:47 +0000924 /* Hint group */
925 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
926 ctx->Hint.PointSmooth = GL_DONT_CARE;
927 ctx->Hint.LineSmooth = GL_DONT_CARE;
928 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
929 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000930 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
931 ctx->Hint.TextureCompression = GL_DONT_CARE;
Brian Paul3893e632001-05-21 16:41:03 +0000932 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000933
Brian Paul0771d152000-04-07 00:19:41 +0000934 /* Histogram group */
935 ctx->Histogram.Width = 0;
936 ctx->Histogram.Format = GL_RGBA;
937 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000938 ctx->Histogram.RedSize = 0;
939 ctx->Histogram.GreenSize = 0;
940 ctx->Histogram.BlueSize = 0;
941 ctx->Histogram.AlphaSize = 0;
942 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000943 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
944 ctx->Histogram.Count[i][0] = 0;
945 ctx->Histogram.Count[i][1] = 0;
946 ctx->Histogram.Count[i][2] = 0;
947 ctx->Histogram.Count[i][3] = 0;
948 }
949
950 /* Min/Max group */
951 ctx->MinMax.Format = GL_RGBA;
952 ctx->MinMax.Sink = GL_FALSE;
953 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
954 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
955 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
956 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
957
Brian Paul4d053dd2000-01-14 04:45:47 +0000958 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000959 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000960
Brian Paul4d053dd2000-01-14 04:45:47 +0000961 /* Lighting group */
962 for (i=0;i<MAX_LIGHTS;i++) {
963 init_light( &ctx->Light.Light[i], i );
964 }
965 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000966
Brian Paul4d053dd2000-01-14 04:45:47 +0000967 init_lightmodel( &ctx->Light.Model );
968 init_material( &ctx->Light.Material[0] );
969 init_material( &ctx->Light.Material[1] );
970 ctx->Light.ShadeModel = GL_SMOOTH;
971 ctx->Light.Enabled = GL_FALSE;
972 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
973 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +0000974 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
975 GL_FRONT_AND_BACK,
976 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000977
Brian Paul4d053dd2000-01-14 04:45:47 +0000978 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000979
Brian Paul4d053dd2000-01-14 04:45:47 +0000980 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +0000981 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
982 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +0000983 for (i = 0 ; i < 10 ; i++) {
984 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
985 s->shininess = -1;
986 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000987 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +0000988 }
Brian Paul77d61af2000-06-28 04:20:21 +0000989
jtgafb833d1999-08-19 00:55:39 +0000990
Brian Paul4d053dd2000-01-14 04:45:47 +0000991 /* Line group */
992 ctx->Line.SmoothFlag = GL_FALSE;
993 ctx->Line.StippleFlag = GL_FALSE;
994 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +0000995 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000996 ctx->Line.StipplePattern = 0xffff;
997 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000998
Brian Paul4d053dd2000-01-14 04:45:47 +0000999 /* Display List group */
1000 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001001
Brian Paul736fcbe2001-05-29 15:23:48 +00001002 /* Multisample */
1003 ctx->Multisample.Enabled = GL_FALSE;
1004 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
1005 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
1006 ctx->Multisample.SampleCoverage = GL_FALSE;
1007 ctx->Multisample.SampleCoverageValue = 1.0;
1008 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
1009
Brian Paul4d053dd2000-01-14 04:45:47 +00001010 /* Pixel group */
1011 ctx->Pixel.RedBias = 0.0;
1012 ctx->Pixel.RedScale = 1.0;
1013 ctx->Pixel.GreenBias = 0.0;
1014 ctx->Pixel.GreenScale = 1.0;
1015 ctx->Pixel.BlueBias = 0.0;
1016 ctx->Pixel.BlueScale = 1.0;
1017 ctx->Pixel.AlphaBias = 0.0;
1018 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001019 ctx->Pixel.DepthBias = 0.0;
1020 ctx->Pixel.DepthScale = 1.0;
1021 ctx->Pixel.IndexOffset = 0;
1022 ctx->Pixel.IndexShift = 0;
1023 ctx->Pixel.ZoomX = 1.0;
1024 ctx->Pixel.ZoomY = 1.0;
1025 ctx->Pixel.MapColorFlag = GL_FALSE;
1026 ctx->Pixel.MapStencilFlag = GL_FALSE;
1027 ctx->Pixel.MapStoSsize = 1;
1028 ctx->Pixel.MapItoIsize = 1;
1029 ctx->Pixel.MapItoRsize = 1;
1030 ctx->Pixel.MapItoGsize = 1;
1031 ctx->Pixel.MapItoBsize = 1;
1032 ctx->Pixel.MapItoAsize = 1;
1033 ctx->Pixel.MapRtoRsize = 1;
1034 ctx->Pixel.MapGtoGsize = 1;
1035 ctx->Pixel.MapBtoBsize = 1;
1036 ctx->Pixel.MapAtoAsize = 1;
1037 ctx->Pixel.MapStoS[0] = 0;
1038 ctx->Pixel.MapItoI[0] = 0;
1039 ctx->Pixel.MapItoR[0] = 0.0;
1040 ctx->Pixel.MapItoG[0] = 0.0;
1041 ctx->Pixel.MapItoB[0] = 0.0;
1042 ctx->Pixel.MapItoA[0] = 0.0;
1043 ctx->Pixel.MapItoR8[0] = 0;
1044 ctx->Pixel.MapItoG8[0] = 0;
1045 ctx->Pixel.MapItoB8[0] = 0;
1046 ctx->Pixel.MapItoA8[0] = 0;
1047 ctx->Pixel.MapRtoR[0] = 0.0;
1048 ctx->Pixel.MapGtoG[0] = 0.0;
1049 ctx->Pixel.MapBtoB[0] = 0.0;
1050 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001051 ctx->Pixel.HistogramEnabled = GL_FALSE;
1052 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1053 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1054 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1055 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001056 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1057 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1058 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1059 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001060 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1061 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1062 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1063 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001064 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1065 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1066 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001067 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1068 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1069 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1070 for (i = 0; i < 3; i++) {
1071 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1072 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1073 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1074 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1075 }
Brian Paul67adba12000-12-09 20:35:54 +00001076 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1077 ctx->Convolution1D.Filter[i] = 0.0;
1078 ctx->Convolution2D.Filter[i] = 0.0;
1079 ctx->Separable2D.Filter[i] = 0.0;
1080 }
Brian Paul82b02f02000-05-07 20:37:40 +00001081 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1082 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001083
Brian Paul4d053dd2000-01-14 04:45:47 +00001084 /* Point group */
1085 ctx->Point.SmoothFlag = GL_FALSE;
1086 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001087 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001088 ctx->Point.Params[0] = 1.0;
1089 ctx->Point.Params[1] = 0.0;
1090 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001091 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001092 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001093 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001094 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001095 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001096
Brian Paul4d053dd2000-01-14 04:45:47 +00001097 /* Polygon group */
1098 ctx->Polygon.CullFlag = GL_FALSE;
1099 ctx->Polygon.CullFaceMode = GL_BACK;
1100 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001101 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001102 ctx->Polygon.FrontMode = GL_FILL;
1103 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001104 ctx->Polygon.SmoothFlag = GL_FALSE;
1105 ctx->Polygon.StippleFlag = GL_FALSE;
1106 ctx->Polygon.OffsetFactor = 0.0F;
1107 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001108 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001109 ctx->Polygon.OffsetPoint = GL_FALSE;
1110 ctx->Polygon.OffsetLine = GL_FALSE;
1111 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001112
Brian Paul4d053dd2000-01-14 04:45:47 +00001113 /* Polygon Stipple group */
1114 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001115
Brian Paul4d053dd2000-01-14 04:45:47 +00001116 /* Scissor group */
1117 ctx->Scissor.Enabled = GL_FALSE;
1118 ctx->Scissor.X = 0;
1119 ctx->Scissor.Y = 0;
1120 ctx->Scissor.Width = 0;
1121 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001122
Brian Paul4d053dd2000-01-14 04:45:47 +00001123 /* Stencil group */
1124 ctx->Stencil.Enabled = GL_FALSE;
1125 ctx->Stencil.Function = GL_ALWAYS;
1126 ctx->Stencil.FailFunc = GL_KEEP;
1127 ctx->Stencil.ZPassFunc = GL_KEEP;
1128 ctx->Stencil.ZFailFunc = GL_KEEP;
1129 ctx->Stencil.Ref = 0;
1130 ctx->Stencil.ValueMask = STENCIL_MAX;
1131 ctx->Stencil.Clear = 0;
1132 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001133
Brian Paul4d053dd2000-01-14 04:45:47 +00001134 /* Texture group */
1135 ctx->Texture.CurrentUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001136 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001137 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1138 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001139 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001140 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001141
Brian Paul4d053dd2000-01-14 04:45:47 +00001142 /* Transformation group */
1143 ctx->Transform.MatrixMode = GL_MODELVIEW;
1144 ctx->Transform.Normalize = GL_FALSE;
1145 ctx->Transform.RescaleNormals = GL_FALSE;
Brian Paul8c2f6c52001-06-26 01:32:48 +00001146 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001147 for (i=0;i<MAX_CLIP_PLANES;i++) {
1148 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1149 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1150 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001151 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001152
Brian Paul4d053dd2000-01-14 04:45:47 +00001153 /* Viewport group */
1154 ctx->Viewport.X = 0;
1155 ctx->Viewport.Y = 0;
1156 ctx->Viewport.Width = 0;
1157 ctx->Viewport.Height = 0;
1158 ctx->Viewport.Near = 0.0;
1159 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001160 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001161
1162#define Sz 10
1163#define Tz 14
Brian Paulfde5e2c2001-09-15 18:02:49 +00001164 ctx->Viewport._WindowMap.m[Sz] = 0.5F * ctx->DepthMaxF;
1165 ctx->Viewport._WindowMap.m[Tz] = 0.5F * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001166#undef Sz
1167#undef Tz
1168
Keith Whitwell14940c42000-11-05 18:40:57 +00001169 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1170 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001171
Brian Paul4d053dd2000-01-14 04:45:47 +00001172 /* Vertex arrays */
1173 ctx->Array.Vertex.Size = 4;
1174 ctx->Array.Vertex.Type = GL_FLOAT;
1175 ctx->Array.Vertex.Stride = 0;
1176 ctx->Array.Vertex.StrideB = 0;
1177 ctx->Array.Vertex.Ptr = NULL;
1178 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001179 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001180 ctx->Array.Normal.Type = GL_FLOAT;
1181 ctx->Array.Normal.Stride = 0;
1182 ctx->Array.Normal.StrideB = 0;
1183 ctx->Array.Normal.Ptr = NULL;
1184 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001185 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001186 ctx->Array.Color.Size = 4;
1187 ctx->Array.Color.Type = GL_FLOAT;
1188 ctx->Array.Color.Stride = 0;
1189 ctx->Array.Color.StrideB = 0;
1190 ctx->Array.Color.Ptr = NULL;
1191 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001192 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1193 ctx->Array.SecondaryColor.Size = 4;
1194 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1195 ctx->Array.SecondaryColor.Stride = 0;
1196 ctx->Array.SecondaryColor.StrideB = 0;
1197 ctx->Array.SecondaryColor.Ptr = NULL;
1198 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1199 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1200 ctx->Array.FogCoord.Size = 1;
1201 ctx->Array.FogCoord.Type = GL_FLOAT;
1202 ctx->Array.FogCoord.Stride = 0;
1203 ctx->Array.FogCoord.StrideB = 0;
1204 ctx->Array.FogCoord.Ptr = NULL;
1205 ctx->Array.FogCoord.Enabled = GL_FALSE;
1206 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001207 ctx->Array.Index.Type = GL_FLOAT;
1208 ctx->Array.Index.Stride = 0;
1209 ctx->Array.Index.StrideB = 0;
1210 ctx->Array.Index.Ptr = NULL;
1211 ctx->Array.Index.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001212 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001213 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1214 ctx->Array.TexCoord[i].Size = 4;
1215 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1216 ctx->Array.TexCoord[i].Stride = 0;
1217 ctx->Array.TexCoord[i].StrideB = 0;
1218 ctx->Array.TexCoord[i].Ptr = NULL;
1219 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001220 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001221 }
1222 ctx->Array.TexCoordInterleaveFactor = 1;
1223 ctx->Array.EdgeFlag.Stride = 0;
1224 ctx->Array.EdgeFlag.StrideB = 0;
1225 ctx->Array.EdgeFlag.Ptr = NULL;
1226 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001227 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001228 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1229
1230 /* Pixel transfer */
1231 ctx->Pack.Alignment = 4;
1232 ctx->Pack.RowLength = 0;
1233 ctx->Pack.ImageHeight = 0;
1234 ctx->Pack.SkipPixels = 0;
1235 ctx->Pack.SkipRows = 0;
1236 ctx->Pack.SkipImages = 0;
1237 ctx->Pack.SwapBytes = GL_FALSE;
1238 ctx->Pack.LsbFirst = GL_FALSE;
1239 ctx->Unpack.Alignment = 4;
1240 ctx->Unpack.RowLength = 0;
1241 ctx->Unpack.ImageHeight = 0;
1242 ctx->Unpack.SkipPixels = 0;
1243 ctx->Unpack.SkipRows = 0;
1244 ctx->Unpack.SkipImages = 0;
1245 ctx->Unpack.SwapBytes = GL_FALSE;
1246 ctx->Unpack.LsbFirst = GL_FALSE;
1247
1248 /* Feedback */
1249 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1250 ctx->Feedback.Buffer = NULL;
1251 ctx->Feedback.BufferSize = 0;
1252 ctx->Feedback.Count = 0;
1253
1254 /* Selection/picking */
1255 ctx->Select.Buffer = NULL;
1256 ctx->Select.BufferSize = 0;
1257 ctx->Select.BufferCount = 0;
1258 ctx->Select.Hits = 0;
1259 ctx->Select.NameStackDepth = 0;
1260
Brian Paul4d053dd2000-01-14 04:45:47 +00001261 /* Renderer and client attribute stacks */
1262 ctx->AttribStackDepth = 0;
1263 ctx->ClientAttribStackDepth = 0;
1264
Brian Paul13811372000-04-12 00:27:37 +00001265 /* Display list */
1266 ctx->CallDepth = 0;
1267 ctx->ExecuteFlag = GL_TRUE;
1268 ctx->CompileFlag = GL_FALSE;
1269 ctx->CurrentListPtr = NULL;
1270 ctx->CurrentBlock = NULL;
1271 ctx->CurrentListNum = 0;
1272 ctx->CurrentPos = 0;
1273
1274 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001275 _mesa_init_colortable(&ctx->ColorTable);
1276 _mesa_init_colortable(&ctx->ProxyColorTable);
1277 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1278 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1279 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1280 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001281
Brian Paul4d053dd2000-01-14 04:45:47 +00001282 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001283 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001284 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001285 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001286
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001287 ctx->_NeedNormals = 0;
1288 ctx->_NeedEyeCoords = 0;
1289 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001290
Brian Paul4d053dd2000-01-14 04:45:47 +00001291 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1292
1293 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001294 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001295 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001296
1297 /* For debug/development only */
1298 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1299 ctx->FirstTimeCurrent = GL_TRUE;
1300
1301 /* Dither disable */
1302 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1303 if (ctx->NoDither) {
1304 if (getenv("MESA_DEBUG")) {
1305 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001306 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001307 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001308 }
1309}
1310
1311
1312
1313
jtgafb833d1999-08-19 00:55:39 +00001314/*
1315 * Allocate the proxy textures. If we run out of memory part way through
1316 * the allocations clean up and return GL_FALSE.
1317 * Return: GL_TRUE=success, GL_FALSE=failure
1318 */
Brian Paul178a1c52000-04-22 01:05:00 +00001319static GLboolean
1320alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001321{
1322 GLboolean out_of_memory;
1323 GLint i;
1324
Brian Paula8523782000-11-19 23:10:25 +00001325 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001326 if (!ctx->Texture.Proxy1D) {
1327 return GL_FALSE;
1328 }
1329
Brian Paula8523782000-11-19 23:10:25 +00001330 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001331 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001332 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001333 return GL_FALSE;
1334 }
1335
Brian Paula8523782000-11-19 23:10:25 +00001336 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001337 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001338 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1339 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1340 return GL_FALSE;
1341 }
1342
1343 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1344 if (!ctx->Texture.ProxyCubeMap) {
1345 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1346 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1347 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001348 return GL_FALSE;
1349 }
1350
1351 out_of_memory = GL_FALSE;
1352 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001353 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1354 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1355 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
Brian Paul172281d2001-07-26 20:02:10 +00001356 ctx->Texture.ProxyCubeMap->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001357 if (!ctx->Texture.Proxy1D->Image[i]
1358 || !ctx->Texture.Proxy2D->Image[i]
Brian Paul172281d2001-07-26 20:02:10 +00001359 || !ctx->Texture.Proxy3D->Image[i]
1360 || !ctx->Texture.ProxyCubeMap->Image[i]) {
jtgafb833d1999-08-19 00:55:39 +00001361 out_of_memory = GL_TRUE;
1362 }
1363 }
1364 if (out_of_memory) {
1365 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1366 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001367 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001368 }
1369 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001370 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001371 }
1372 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001373 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001374 }
Brian Paul172281d2001-07-26 20:02:10 +00001375 if (ctx->Texture.ProxyCubeMap->Image[i]) {
1376 _mesa_free_texture_image(ctx->Texture.ProxyCubeMap->Image[i]);
1377 }
jtgafb833d1999-08-19 00:55:39 +00001378 }
Brian Paula8523782000-11-19 23:10:25 +00001379 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1380 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1381 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
Brian Paul172281d2001-07-26 20:02:10 +00001382 _mesa_free_texture_object(NULL, ctx->Texture.ProxyCubeMap);
jtgafb833d1999-08-19 00:55:39 +00001383 return GL_FALSE;
1384 }
1385 else {
1386 return GL_TRUE;
1387 }
1388}
1389
1390
jtgafb833d1999-08-19 00:55:39 +00001391/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001392 * Initialize a GLcontext struct. This includes allocating all the
1393 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001394 */
Brian Paul178a1c52000-04-22 01:05:00 +00001395GLboolean
1396_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001397 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001398 GLcontext *share_list,
1399 void *driver_ctx,
1400 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001401{
Brian Paul5fb84d22000-05-24 15:04:45 +00001402 GLuint dispatchSize;
1403
jtgafb833d1999-08-19 00:55:39 +00001404 (void) direct; /* not used */
1405
jtgafb833d1999-08-19 00:55:39 +00001406 /* misc one-time initializations */
1407 one_time_init();
1408
Brian Paulb1394fa2000-09-26 20:53:53 +00001409 /**
1410 ** OpenGL SI stuff
1411 **/
1412 if (!ctx->imports.malloc) {
1413 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1414 }
1415 /* exports are setup by the device driver */
1416
jtgafb833d1999-08-19 00:55:39 +00001417 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001418 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001419 ctx->DrawBuffer = NULL;
1420 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001421
jtgafb833d1999-08-19 00:55:39 +00001422 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001423 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001424 ctx->Shared = share_list->Shared;
1425 }
1426 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001427 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001428 ctx->Shared = alloc_shared_state();
1429 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001430 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001431 }
1432 }
Brian Paul9560f052000-01-31 23:11:39 +00001433 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001434 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001435 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001436
Brian Paul5a2f32b2001-04-25 18:21:05 +00001437 /* Effectively bind the default textures to all texture units */
1438 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1439 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1440 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1441 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1442
Brian Paul4d053dd2000-01-14 04:45:47 +00001443 init_attrib_groups( ctx );
1444
Brian Paulb6bcae52001-01-23 23:39:36 +00001445 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001446 ctx->Color.DrawBuffer = GL_BACK;
1447 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1448 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1449 ctx->Pixel.ReadBuffer = GL_BACK;
1450 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1451 }
1452 else {
1453 ctx->Color.DrawBuffer = GL_FRONT;
1454 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1455 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1456 ctx->Pixel.ReadBuffer = GL_FRONT;
1457 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1458 }
1459
jtgafb833d1999-08-19 00:55:39 +00001460 if (!alloc_proxy_textures(ctx)) {
1461 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001462 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001463 }
jtgafb833d1999-08-19 00:55:39 +00001464
Brian Paulf59afc92000-05-23 23:23:00 +00001465 /* register the most recent extension functions with libGL */
1466 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1467 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1468 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1469 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1470 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1471 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1472 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1473 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1474
Brian Paul5fb84d22000-05-24 15:04:45 +00001475 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1476 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1477 * Mesa we do this to accomodate different versions of libGL and various
1478 * DRI drivers.
1479 */
1480 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1481 sizeof(struct _glapi_table) / sizeof(void *));
1482
Brian Paulfbd8f211999-11-11 01:22:25 +00001483 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001484 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1485 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001486 if (!ctx->Exec || !ctx->Save) {
1487 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001488 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001489 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001490 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001491 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1492 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001493 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001494
Keith Whitwellad2ac212000-11-24 10:25:05 +00001495 ctx->ExecPrefersFloat = GL_FALSE;
1496 ctx->SavePrefersFloat = GL_FALSE;
1497
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001498 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001499 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001500 ctx->TnlModule.Current = NULL;
1501 ctx->TnlModule.SwapCount = 0;
1502
Brian Paulb6bcae52001-01-23 23:39:36 +00001503 /* Z buffer stuff */
1504 if (ctx->Visual.depthBits == 0) {
1505 /* Special case. Even if we don't have a depth buffer we need
1506 * good values for DepthMax for Z vertex transformation purposes
1507 * and for per-fragment fog computation.
1508 */
1509 ctx->DepthMax = 1 << 16;
1510 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1511 }
1512 else if (ctx->Visual.depthBits < 32) {
1513 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1514 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1515 }
1516 else {
1517 /* Special case since shift values greater than or equal to the
1518 * number of bits in the left hand expression's type are undefined.
1519 */
1520 ctx->DepthMax = 0xffffffff;
1521 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1522 }
Brian Paulbc920f02001-05-07 16:32:51 +00001523 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001524
1525
Brian Paul3b18a362000-09-26 15:27:20 +00001526#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001527 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001528#if 0
1529 /* Brian: do you want to have CreateContext fail here,
1530 or should we just trap in NewTrace (currently done)? */
1531 if (!(ctx->TraceCtx)) {
1532 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001533 FREE( ctx->Exec );
1534 FREE( ctx->Save );
1535 return GL_FALSE;
1536 }
1537#endif
1538 trInitContext(ctx->TraceCtx);
1539
1540 ctx->TraceDispatch = (struct _glapi_table *)
1541 CALLOC(dispatchSize * sizeof(void*));
1542#if 0
1543 if (!(ctx->TraceCtx)) {
1544 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001545 FREE( ctx->Exec );
1546 FREE( ctx->Save );
1547 FREE( ctx->TraceCtx );
1548 return GL_FALSE;
1549 }
1550#endif
1551 trInitDispatch(ctx->TraceDispatch);
1552#endif
1553
Brian Paul4d053dd2000-01-14 04:45:47 +00001554 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001555}
1556
jtgafb833d1999-08-19 00:55:39 +00001557
1558
1559/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001560 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001561 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001562 * sharelist - another context to share display lists with or NULL
1563 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001564 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001565 */
Brian Paul178a1c52000-04-22 01:05:00 +00001566GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001567_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001568 GLcontext *share_list,
1569 void *driver_ctx,
1570 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001571{
1572 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1573 if (!ctx) {
1574 return NULL;
1575 }
Jouk Jansen12e875c2001-10-18 08:04:57 +00001576 ctx->Driver.CurrentExecPrimitive = 0;
Brian Paul178a1c52000-04-22 01:05:00 +00001577 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001578 return ctx;
1579 }
1580 else {
1581 FREE(ctx);
1582 return NULL;
1583 }
1584}
1585
1586
1587
1588/*
1589 * Free the data associated with the given context.
1590 * But don't free() the GLcontext struct itself!
1591 */
Brian Paul178a1c52000-04-22 01:05:00 +00001592void
Brian Paulb1394fa2000-09-26 20:53:53 +00001593_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001594{
Brian Paul4d053dd2000-01-14 04:45:47 +00001595 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001596 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001597
1598 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001599 if (ctx == _mesa_get_current_context()) {
1600 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001601 }
1602
Keith Whitwell23caf202000-11-16 21:05:34 +00001603 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001604 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001605 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001606 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001607 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001608 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001609 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001610 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001611 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001612 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001613 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001614 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001615 }
1616 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001617
Brian Paulfd284452001-07-19 15:54:34 +00001618 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
1619
1620 _math_matrix_dtr(&ctx->ColorMatrix);
1621 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
1622 _math_matrix_dtr(&ctx->ColorStack[j]);
1623 }
1624
Brian Paul9560f052000-01-31 23:11:39 +00001625 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001626 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001627 assert(ctx->Shared->RefCount >= 0);
1628 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1629 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001630 /* free shared state */
1631 free_shared_state( ctx, ctx->Shared );
1632 }
1633
Keith Whitwell14940c42000-11-05 18:40:57 +00001634 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001635 FREE( s );
1636 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001637 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001638
1639 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001640 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1641 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1642 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paulfd284452001-07-19 15:54:34 +00001643 _mesa_free_texture_object( NULL, ctx->Texture.ProxyCubeMap );
Brian Paul4d053dd2000-01-14 04:45:47 +00001644
1645 /* Free evaluator data */
1646 if (ctx->EvalMap.Map1Vertex3.Points)
1647 FREE( ctx->EvalMap.Map1Vertex3.Points );
1648 if (ctx->EvalMap.Map1Vertex4.Points)
1649 FREE( ctx->EvalMap.Map1Vertex4.Points );
1650 if (ctx->EvalMap.Map1Index.Points)
1651 FREE( ctx->EvalMap.Map1Index.Points );
1652 if (ctx->EvalMap.Map1Color4.Points)
1653 FREE( ctx->EvalMap.Map1Color4.Points );
1654 if (ctx->EvalMap.Map1Normal.Points)
1655 FREE( ctx->EvalMap.Map1Normal.Points );
1656 if (ctx->EvalMap.Map1Texture1.Points)
1657 FREE( ctx->EvalMap.Map1Texture1.Points );
1658 if (ctx->EvalMap.Map1Texture2.Points)
1659 FREE( ctx->EvalMap.Map1Texture2.Points );
1660 if (ctx->EvalMap.Map1Texture3.Points)
1661 FREE( ctx->EvalMap.Map1Texture3.Points );
1662 if (ctx->EvalMap.Map1Texture4.Points)
1663 FREE( ctx->EvalMap.Map1Texture4.Points );
1664
1665 if (ctx->EvalMap.Map2Vertex3.Points)
1666 FREE( ctx->EvalMap.Map2Vertex3.Points );
1667 if (ctx->EvalMap.Map2Vertex4.Points)
1668 FREE( ctx->EvalMap.Map2Vertex4.Points );
1669 if (ctx->EvalMap.Map2Index.Points)
1670 FREE( ctx->EvalMap.Map2Index.Points );
1671 if (ctx->EvalMap.Map2Color4.Points)
1672 FREE( ctx->EvalMap.Map2Color4.Points );
1673 if (ctx->EvalMap.Map2Normal.Points)
1674 FREE( ctx->EvalMap.Map2Normal.Points );
1675 if (ctx->EvalMap.Map2Texture1.Points)
1676 FREE( ctx->EvalMap.Map2Texture1.Points );
1677 if (ctx->EvalMap.Map2Texture2.Points)
1678 FREE( ctx->EvalMap.Map2Texture2.Points );
1679 if (ctx->EvalMap.Map2Texture3.Points)
1680 FREE( ctx->EvalMap.Map2Texture3.Points );
1681 if (ctx->EvalMap.Map2Texture4.Points)
1682 FREE( ctx->EvalMap.Map2Texture4.Points );
1683
Brian Paul4bdcfe52000-04-17 17:57:04 +00001684 _mesa_free_colortable_data( &ctx->ColorTable );
1685 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1686 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1687 _mesa_free_colortable_data( &ctx->Texture.Palette );
1688
Brian Paulfd284452001-07-19 15:54:34 +00001689 _math_matrix_dtr(&ctx->Viewport._WindowMap);
1690
Brian Paul69755402001-02-26 23:58:12 +00001691 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001692
1693 FREE(ctx->Exec);
1694 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001695}
1696
1697
1698
1699/*
1700 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001701 */
Brian Paul178a1c52000-04-22 01:05:00 +00001702void
Brian Paulb1394fa2000-09-26 20:53:53 +00001703_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001704{
1705 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001706 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001707 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001708 }
1709}
1710
1711
1712
1713/*
jtgafb833d1999-08-19 00:55:39 +00001714 * Copy attribute groups from one context to another.
1715 * Input: src - source context
1716 * dst - destination context
1717 * mask - bitwise OR of GL_*_BIT flags
1718 */
Brian Paul178a1c52000-04-22 01:05:00 +00001719void
Brian Paulb1394fa2000-09-26 20:53:53 +00001720_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001721{
1722 if (mask & GL_ACCUM_BUFFER_BIT) {
1723 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1724 }
1725 if (mask & GL_COLOR_BUFFER_BIT) {
1726 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1727 }
1728 if (mask & GL_CURRENT_BIT) {
1729 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1730 }
1731 if (mask & GL_DEPTH_BUFFER_BIT) {
1732 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1733 }
1734 if (mask & GL_ENABLE_BIT) {
1735 /* no op */
1736 }
1737 if (mask & GL_EVAL_BIT) {
1738 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1739 }
1740 if (mask & GL_FOG_BIT) {
1741 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1742 }
1743 if (mask & GL_HINT_BIT) {
1744 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1745 }
1746 if (mask & GL_LIGHTING_BIT) {
1747 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001748 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001749 }
1750 if (mask & GL_LINE_BIT) {
1751 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1752 }
1753 if (mask & GL_LIST_BIT) {
1754 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1755 }
1756 if (mask & GL_PIXEL_MODE_BIT) {
1757 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1758 }
1759 if (mask & GL_POINT_BIT) {
1760 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1761 }
1762 if (mask & GL_POLYGON_BIT) {
1763 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1764 }
1765 if (mask & GL_POLYGON_STIPPLE_BIT) {
1766 /* Use loop instead of MEMCPY due to problem with Portland Group's
1767 * C compiler. Reported by John Stone.
1768 */
1769 int i;
1770 for (i=0;i<32;i++) {
1771 dst->PolygonStipple[i] = src->PolygonStipple[i];
1772 }
1773 }
1774 if (mask & GL_SCISSOR_BIT) {
1775 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1776 }
1777 if (mask & GL_STENCIL_BUFFER_BIT) {
1778 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1779 }
1780 if (mask & GL_TEXTURE_BIT) {
1781 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1782 }
1783 if (mask & GL_TRANSFORM_BIT) {
1784 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1785 }
1786 if (mask & GL_VIEWPORT_BIT) {
1787 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1788 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001789 /* XXX FIXME: Call callbacks?
1790 */
1791 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001792}
1793
1794
jtgafb833d1999-08-19 00:55:39 +00001795/*
Brian Paul00037781999-12-17 14:52:35 +00001796 * Set the current context, binding the given frame buffer to the context.
1797 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001798void
1799_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001800{
Brian Paulb1394fa2000-09-26 20:53:53 +00001801 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001802}
1803
1804
Keith Whitwell23caf202000-11-16 21:05:34 +00001805static void print_info( void )
1806{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001807 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001808 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001809 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001810 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001811 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001812 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001813 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001814 (char *) _mesa_GetString(GL_EXTENSIONS));
1815#if defined(THREADS)
1816 fprintf(stderr, "Mesa thread-safe: YES\n");
1817#else
1818 fprintf(stderr, "Mesa thread-safe: NO\n");
1819#endif
1820#if defined(USE_X86_ASM)
1821 fprintf(stderr, "Mesa x86-optimized: YES\n");
1822#else
1823 fprintf(stderr, "Mesa x86-optimized: NO\n");
1824#endif
davem69e4f84b42001-06-05 03:58:20 +00001825#if defined(USE_SPARC_ASM)
1826 fprintf(stderr, "Mesa sparc-optimized: YES\n");
1827#else
1828 fprintf(stderr, "Mesa sparc-optimized: NO\n");
1829#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001830}
1831
1832
Brian Paul00037781999-12-17 14:52:35 +00001833/*
1834 * Bind the given context to the given draw-buffer and read-buffer
1835 * and make it the current context for this thread.
1836 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001837void
1838_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1839 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001840{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001841 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001842 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001843
Brian Paulbe3602d2001-02-28 00:27:48 +00001844 /* Check that the context's and framebuffer's visuals are compatible.
1845 * We could do a lot more checking here but this'll catch obvious
1846 * problems.
1847 */
1848 if (newCtx && drawBuffer && readBuffer) {
1849 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1850 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1851 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1852 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1853 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1854 return; /* incompatible */
1855 }
1856 }
1857
Brian Paul00037781999-12-17 14:52:35 +00001858 /* We call this function periodically (just here for now) in
1859 * order to detect when multithreading has begun.
1860 */
1861 _glapi_check_multithread();
1862
Brian Paulf9b97d92000-01-28 20:17:42 +00001863 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001864 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001865
1866
1867 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001868 _glapi_set_dispatch(NULL); /* none current */
1869 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001870 else {
1871 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001872
Keith Whitwell23caf202000-11-16 21:05:34 +00001873 if (drawBuffer && readBuffer) {
1874 /* TODO: check if newCtx and buffer's visual match??? */
1875 newCtx->DrawBuffer = drawBuffer;
1876 newCtx->ReadBuffer = readBuffer;
1877 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001878 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001879 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001880
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001881 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001882 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1883
1884 /* We can use this to help debug user's problems. Tell them to set
1885 * the MESA_INFO env variable before running their app. Then the
1886 * first time each context is made current we'll print some useful
1887 * information.
1888 */
1889 if (newCtx->FirstTimeCurrent) {
1890 if (getenv("MESA_INFO")) {
1891 print_info();
1892 }
1893 newCtx->FirstTimeCurrent = GL_FALSE;
1894 }
Brian Paul00037781999-12-17 14:52:35 +00001895 }
1896}
1897
1898
1899
1900/*
1901 * Return current context handle for the calling thread.
1902 * This isn't the fastest way to get the current context.
1903 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1904 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001905GLcontext *
1906_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001907{
Brian Paulf9b97d92000-01-28 20:17:42 +00001908 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001909}
1910
1911
1912
1913/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001914 * This should be called by device drivers just before they do a
1915 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001916 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001917void
1918_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001919{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001920 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001921}
1922
1923
Brian Paul00037781999-12-17 14:52:35 +00001924
Brian Paulfbd8f211999-11-11 01:22:25 +00001925/*
1926 * Return pointer to this context's current API dispatch table.
1927 * It'll either be the immediate-mode execute dispatcher or the
1928 * display list compile dispatcher.
1929 */
1930struct _glapi_table *
1931_mesa_get_dispatch(GLcontext *ctx)
1932{
1933 return ctx->CurrentDispatch;
1934}
1935
1936
1937
jtgafb833d1999-08-19 00:55:39 +00001938/**********************************************************************/
1939/***** Miscellaneous functions *****/
1940/**********************************************************************/
1941
1942
1943/*
1944 * This function is called when the Mesa user has stumbled into a code
1945 * path which may not be implemented fully or correctly.
1946 */
Brian Paul08836342001-03-03 20:33:27 +00001947void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001948{
1949 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00001950#ifdef XF86DRI
1951 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
1952#else
1953 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
1954#endif
jtgafb833d1999-08-19 00:55:39 +00001955 (void) ctx;
1956}
1957
1958
1959
1960/*
1961 * This is called to inform the user that he or she has tried to do
1962 * something illogical or if there's likely a bug in their program
1963 * (like enabled depth testing without a depth buffer).
1964 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001965void
1966_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001967{
Brian Paulb1394fa2000-09-26 20:53:53 +00001968 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001969}
1970
1971
1972
Brian Paulfa9df402000-02-02 19:16:46 +00001973/*
1974 * Compile an error into current display list.
1975 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001976void
1977_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001978{
1979 if (ctx->CompileFlag)
Brian Paul08836342001-03-03 20:33:27 +00001980 _mesa_save_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001981
1982 if (ctx->ExecuteFlag)
Brian Paul08836342001-03-03 20:33:27 +00001983 _mesa_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001984}
1985
1986
Brian Paulfa9df402000-02-02 19:16:46 +00001987
jtgafb833d1999-08-19 00:55:39 +00001988/*
1989 * This is Mesa's error handler. Normally, all that's done is the updating
1990 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1991 * environment variable "MESA_DEBUG" is defined then a real error message
1992 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001993 * Input: ctx - the GL context
1994 * error - the error value
1995 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001996 */
Brian Paul7eb06032000-07-14 04:13:40 +00001997void
Brian Paul08836342001-03-03 20:33:27 +00001998_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001999{
Brian Paul7eb06032000-07-14 04:13:40 +00002000 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00002001 GLboolean debug;
2002
2003#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002004 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002005 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002006 else
2007 debug = GL_TRUE;
2008#else
2009 if (debugEnv)
2010 debug = GL_TRUE;
2011 else
2012 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002013#endif
2014
2015 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002016 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002017 switch (error) {
2018 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002019 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002020 break;
2021 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002022 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002023 break;
2024 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002025 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002026 break;
2027 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002028 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002029 break;
2030 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002031 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002032 break;
2033 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002034 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002035 break;
2036 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002037 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002038 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002039 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002040 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002041 break;
jtgafb833d1999-08-19 00:55:39 +00002042 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002043 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002044 break;
2045 }
Brian Paul7eb06032000-07-14 04:13:40 +00002046 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002047 }
2048
Brian Paul7eb06032000-07-14 04:13:40 +00002049 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002050 ctx->ErrorValue = error;
2051 }
2052
2053 /* Call device driver's error handler, if any. This is used on the Mac. */
2054 if (ctx->Driver.Error) {
2055 (*ctx->Driver.Error)( ctx );
2056 }
2057}
2058
2059
2060
Brian Paulfa9df402000-02-02 19:16:46 +00002061void
2062_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002063{
Brian Paulfa9df402000-02-02 19:16:46 +00002064 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002065 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002066 if (ctx->Driver.Finish) {
2067 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002068 }
2069}
2070
2071
2072
Brian Paulfa9df402000-02-02 19:16:46 +00002073void
2074_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002075{
Brian Paulfa9df402000-02-02 19:16:46 +00002076 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002077 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002078 if (ctx->Driver.Flush) {
2079 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002080 }
jtgafb833d1999-08-19 00:55:39 +00002081}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002082
2083
2084
Keith Whitwellcab974c2000-12-26 05:09:27 +00002085const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002086 "GL_POINTS",
2087 "GL_LINES",
2088 "GL_LINE_LOOP",
2089 "GL_LINE_STRIP",
2090 "GL_TRIANGLES",
2091 "GL_TRIANGLE_STRIP",
2092 "GL_TRIANGLE_FAN",
2093 "GL_QUADS",
2094 "GL_QUAD_STRIP",
2095 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002096 "outside begin/end",
2097 "inside unkown primitive",
2098 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002099};