blob: 18477f32771c924da8b9a0bc26073e56e2f3ed1e [file] [log] [blame]
Brian Paul9a888bd2002-03-13 04:33:32 +00001/* $Id: context.c,v 1.155 2002/03/13 04:33:32 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul86b84272001-12-14 02:50:01 +00005 * Version: 4.1
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paulbc42c192002-01-05 21:53:20 +00007 * Copyright (C) 1999-2002 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"
Brian Paul30f51ae2001-12-18 04:06:44 +000055#include "vpstate.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +000056#include "vtxfmt.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000057#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
Brian Paul86b84272001-12-14 02:50:01 +000092
93
Brian Paulb1394fa2000-09-26 20:53:53 +000094/**********************************************************************/
95/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
96/**********************************************************************/
97
98static GLboolean
99_mesa_DestroyContext(__GLcontext *gc)
100{
101 if (gc) {
102 _mesa_free_context_data(gc);
103 (*gc->imports.free)(gc, gc);
104 }
105 return GL_TRUE;
106}
107
108
109/* exported OpenGL SI interface */
110__GLcontext *
111__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
112{
113 GLcontext *ctx;
114
115 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
116 if (ctx == NULL) {
117 return NULL;
118 }
Jouk Jansen12e875c2001-10-18 08:04:57 +0000119 ctx->Driver.CurrentExecPrimitive=0;
Brian Paulb1394fa2000-09-26 20:53:53 +0000120 ctx->imports = *imports;
121
122 _mesa_initialize_visual(&ctx->Visual,
123 modes->rgbMode,
124 modes->doubleBufferMode,
125 modes->stereoMode,
126 modes->redBits,
127 modes->greenBits,
128 modes->blueBits,
129 modes->alphaBits,
130 modes->indexBits,
131 modes->depthBits,
132 modes->stencilBits,
133 modes->accumRedBits,
134 modes->accumGreenBits,
135 modes->accumBlueBits,
136 modes->accumAlphaBits,
137 0);
138
Keith Whitwellb980b2e2001-01-08 04:09:41 +0000139 /* KW: was imports->wscx */
140 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
Brian Paulb1394fa2000-09-26 20:53:53 +0000141
142 ctx->exports.destroyContext = _mesa_DestroyContext;
143
144 return ctx;
145}
146
147
148/* exported OpenGL SI interface */
149void
150__glCoreNopDispatch(void)
151{
152#if 0
153 /* SI */
154 __gl_dispatch = __glNopDispatchState;
155#else
156 /* Mesa */
157 _glapi_set_dispatch(NULL);
158#endif
159}
160
161
jtgafb833d1999-08-19 00:55:39 +0000162/**********************************************************************/
163/***** Context and Thread management *****/
164/**********************************************************************/
165
166
jtgafb833d1999-08-19 00:55:39 +0000167
jtgafb833d1999-08-19 00:55:39 +0000168/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000169/***** GL Visual allocation/destruction *****/
170/**********************************************************************/
171
172
173/*
174 * Allocate a new GLvisual object.
175 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000176 * dbFlag - double buffering?
177 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000178 * depthBits - requested bits per depth buffer value
179 * Any value in [0, 32] is acceptable but the actual
180 * depth type will be GLushort or GLuint as needed.
181 * stencilBits - requested minimum bits per stencil buffer value
182 * accumBits - requested minimum bits per accum buffer component
183 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
184 * red/green/blue/alphaBits - number of bits per color component
185 * in frame buffer for RGB(A) mode.
186 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000187 * Return: pointer to new GLvisual or NULL if requested parameters can't
188 * be met.
189 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000190GLvisual *
191_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000192 GLboolean dbFlag,
193 GLboolean stereoFlag,
194 GLint redBits,
195 GLint greenBits,
196 GLint blueBits,
197 GLint alphaBits,
198 GLint indexBits,
199 GLint depthBits,
200 GLint stencilBits,
201 GLint accumRedBits,
202 GLint accumGreenBits,
203 GLint accumBlueBits,
204 GLint accumAlphaBits,
205 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000206{
Brian Paul178a1c52000-04-22 01:05:00 +0000207 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
208 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000209 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000210 redBits, greenBits, blueBits, alphaBits,
211 indexBits, depthBits, stencilBits,
212 accumRedBits, accumGreenBits,
213 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000214 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000215 FREE(vis);
216 return NULL;
217 }
218 }
219 return vis;
220}
221
222
223/*
224 * Initialize the fields of the given GLvisual.
225 * Input: see _mesa_create_visual() above.
226 * Return: GL_TRUE = success
227 * GL_FALSE = failure.
228 */
229GLboolean
230_mesa_initialize_visual( GLvisual *vis,
231 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000232 GLboolean dbFlag,
233 GLboolean stereoFlag,
234 GLint redBits,
235 GLint greenBits,
236 GLint blueBits,
237 GLint alphaBits,
238 GLint indexBits,
239 GLint depthBits,
240 GLint stencilBits,
241 GLint accumRedBits,
242 GLint accumGreenBits,
243 GLint accumBlueBits,
244 GLint accumAlphaBits,
245 GLint numSamples )
246{
Brian Paulb6bcae52001-01-23 23:39:36 +0000247 (void) numSamples;
248
Brian Paul178a1c52000-04-22 01:05:00 +0000249 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000250
Brian Pauled30dfa2000-03-03 17:47:39 +0000251 /* This is to catch bad values from device drivers not updated for
252 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
253 * bad value now (a 1-bit depth buffer!?!).
254 */
255 assert(depthBits == 0 || depthBits > 1);
256
257 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000258 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000259 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000260 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000261 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000262 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000263 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000264 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000265 }
266 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000267 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000268 }
269 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000270 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000271 }
272 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000273 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000274 }
275
Brian Paulb6bcae52001-01-23 23:39:36 +0000276 vis->rgbMode = rgbFlag;
277 vis->doubleBufferMode = dbFlag;
278 vis->stereoMode = stereoFlag;
279 vis->redBits = redBits;
280 vis->greenBits = greenBits;
281 vis->blueBits = blueBits;
282 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000283
Brian Paulb6bcae52001-01-23 23:39:36 +0000284 vis->indexBits = indexBits;
285 vis->depthBits = depthBits;
286 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
287 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
288 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
289 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
290 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000291
Brian Paul178a1c52000-04-22 01:05:00 +0000292 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000293}
294
295
Brian Paulb371e0d2000-03-31 01:05:51 +0000296void
297_mesa_destroy_visual( GLvisual *vis )
298{
299 FREE(vis);
300}
301
302
Brian Paul4d053dd2000-01-14 04:45:47 +0000303/**********************************************************************/
304/***** GL Framebuffer allocation/destruction *****/
305/**********************************************************************/
306
307
308/*
309 * Create a new framebuffer. A GLframebuffer is a struct which
310 * encapsulates the depth, stencil and accum buffers and related
311 * parameters.
Brian Paulbe3602d2001-02-28 00:27:48 +0000312 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +0000313 * softwareDepth - create/use a software depth buffer?
314 * softwareStencil - create/use a software stencil buffer?
315 * softwareAccum - create/use a software accum buffer?
316 * softwareAlpha - create/use a software alpha buffer?
Brian Paul4d053dd2000-01-14 04:45:47 +0000317 * Return: pointer to new GLframebuffer struct or NULL if error.
318 */
Brian Paul178a1c52000-04-22 01:05:00 +0000319GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000320_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000321 GLboolean softwareDepth,
322 GLboolean softwareStencil,
323 GLboolean softwareAccum,
324 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000325{
Brian Paul178a1c52000-04-22 01:05:00 +0000326 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
327 assert(visual);
328 if (buffer) {
329 _mesa_initialize_framebuffer(buffer, visual,
330 softwareDepth, softwareStencil,
331 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000332 }
Brian Paul178a1c52000-04-22 01:05:00 +0000333 return buffer;
334}
335
336
337/*
338 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000339 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000340 */
341void
342_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000343 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000344 GLboolean softwareDepth,
345 GLboolean softwareStencil,
346 GLboolean softwareAccum,
347 GLboolean softwareAlpha )
348{
349 assert(buffer);
350 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000351
352 /* sanity checks */
353 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000354 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000355 }
356 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000357 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000358 }
359 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000360 assert(visual->rgbMode);
361 assert(visual->accumRedBits > 0);
362 assert(visual->accumGreenBits > 0);
363 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000364 }
365 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000366 assert(visual->rgbMode);
367 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000368 }
369
Brian Paul75978bd2001-04-27 21:17:20 +0000370 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000371 buffer->UseSoftwareDepthBuffer = softwareDepth;
372 buffer->UseSoftwareStencilBuffer = softwareStencil;
373 buffer->UseSoftwareAccumBuffer = softwareAccum;
374 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000375}
376
377
Brian Paul4d053dd2000-01-14 04:45:47 +0000378/*
379 * Free a framebuffer struct and its buffers.
380 */
Brian Paul178a1c52000-04-22 01:05:00 +0000381void
Brian Paulb1394fa2000-09-26 20:53:53 +0000382_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000383{
384 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000385 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000386 FREE(buffer);
387 }
388}
389
390
Brian Paul75978bd2001-04-27 21:17:20 +0000391/*
392 * Free the data hanging off of <buffer>, but not <buffer> itself.
393 */
394void
395_mesa_free_framebuffer_data( GLframebuffer *buffer )
396{
397 if (!buffer)
398 return;
399
400 if (buffer->DepthBuffer) {
401 FREE( buffer->DepthBuffer );
402 buffer->DepthBuffer = NULL;
403 }
404 if (buffer->Accum) {
405 FREE( buffer->Accum );
406 buffer->Accum = NULL;
407 }
408 if (buffer->Stencil) {
409 FREE( buffer->Stencil );
410 buffer->Stencil = NULL;
411 }
412 if (buffer->FrontLeftAlpha) {
413 FREE( buffer->FrontLeftAlpha );
414 buffer->FrontLeftAlpha = NULL;
415 }
416 if (buffer->BackLeftAlpha) {
417 FREE( buffer->BackLeftAlpha );
418 buffer->BackLeftAlpha = NULL;
419 }
420 if (buffer->FrontRightAlpha) {
421 FREE( buffer->FrontRightAlpha );
422 buffer->FrontRightAlpha = NULL;
423 }
424 if (buffer->BackRightAlpha) {
425 FREE( buffer->BackRightAlpha );
426 buffer->BackRightAlpha = NULL;
427 }
428}
429
430
Brian Paul4d053dd2000-01-14 04:45:47 +0000431
432/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000433/***** Context allocation, initialization, destroying *****/
434/**********************************************************************/
435
436
Brian Paul9560f052000-01-31 23:11:39 +0000437_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
438
439
jtgafb833d1999-08-19 00:55:39 +0000440/*
441 * This function just calls all the various one-time-init functions in Mesa.
442 */
Brian Paul178a1c52000-04-22 01:05:00 +0000443static void
444one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000445{
446 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000447 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000448 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000449 /* do some implementation tests */
450 assert( sizeof(GLbyte) == 1 );
451 assert( sizeof(GLshort) >= 2 );
452 assert( sizeof(GLint) >= 4 );
453 assert( sizeof(GLubyte) == 1 );
454 assert( sizeof(GLushort) >= 2 );
455 assert( sizeof(GLuint) >= 4 );
456
Brian Paul08836342001-03-03 20:33:27 +0000457 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000458
Keith Whitwell23caf202000-11-16 21:05:34 +0000459 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000460 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000461
davem69775355a2001-06-05 23:54:00 +0000462#ifdef USE_SPARC_ASM
463 _mesa_init_sparc_glapi_relocs();
464#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000465 if (getenv("MESA_DEBUG")) {
466 _glapi_noop_enable_warnings(GL_TRUE);
467 }
468 else {
469 _glapi_noop_enable_warnings(GL_FALSE);
470 }
471
jtgafb833d1999-08-19 00:55:39 +0000472#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
473 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
474#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000475
476 alreadyCalled = GL_TRUE;
477 }
Brian Paul9560f052000-01-31 23:11:39 +0000478 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000479}
480
481
Brian Paul86b84272001-12-14 02:50:01 +0000482static void
483init_matrix_stack( struct matrix_stack *stack,
484 GLuint maxDepth, GLuint dirtyFlag )
485{
486 GLuint i;
487
488 stack->Depth = 0;
489 stack->MaxDepth = maxDepth;
490 stack->DirtyFlag = dirtyFlag;
Brian Paul86b84272001-12-14 02:50:01 +0000491 /* The stack */
Brian Paul30f51ae2001-12-18 04:06:44 +0000492 stack->Stack = CALLOC(maxDepth * sizeof(GLmatrix));
Brian Paul86b84272001-12-14 02:50:01 +0000493 for (i = 0; i < maxDepth; i++) {
494 _math_matrix_ctr(&stack->Stack[i]);
495 _math_matrix_alloc_inv(&stack->Stack[i]);
496 }
Brian Paul30f51ae2001-12-18 04:06:44 +0000497 stack->Top = stack->Stack;
Brian Paul86b84272001-12-14 02:50:01 +0000498}
499
500
501static void
502free_matrix_stack( struct matrix_stack *stack )
503{
504 GLuint i;
Brian Paul86b84272001-12-14 02:50:01 +0000505 for (i = 0; i < stack->MaxDepth; i++) {
506 _math_matrix_dtr(&stack->Stack[i]);
507 }
Brian Paulc4afba32002-02-05 23:21:45 +0000508 FREE(stack->Stack);
Brian Paul30f51ae2001-12-18 04:06:44 +0000509 stack->Stack = stack->Top = NULL;
Brian Paul86b84272001-12-14 02:50:01 +0000510}
511
Brian Paul4d053dd2000-01-14 04:45:47 +0000512
jtgafb833d1999-08-19 00:55:39 +0000513/*
514 * Allocate and initialize a shared context state structure.
515 */
Brian Paul178a1c52000-04-22 01:05:00 +0000516static struct gl_shared_state *
517alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000518{
jtgafb833d1999-08-19 00:55:39 +0000519 struct gl_shared_state *ss;
520 GLboolean outOfMemory;
521
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000522 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000523 if (!ss)
524 return NULL;
525
Brian Paule4b684c2000-09-12 21:07:40 +0000526 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000527
Brian Paule4b684c2000-09-12 21:07:40 +0000528 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000529 ss->TexObjects = _mesa_NewHashTable();
Brian Paul30f51ae2001-12-18 04:06:44 +0000530 ss->VertexPrograms = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000531
532 /* Default Texture objects */
533 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000534
535 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
536 if (!ss->Default1D) {
537 outOfMemory = GL_TRUE;
538 }
jtgafb833d1999-08-19 00:55:39 +0000539
Brian Paula8523782000-11-19 23:10:25 +0000540 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
541 if (!ss->Default2D) {
542 outOfMemory = GL_TRUE;
543 }
Brian Paula8523782000-11-19 23:10:25 +0000544
545 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
546 if (!ss->Default3D) {
547 outOfMemory = GL_TRUE;
548 }
Brian Paula8523782000-11-19 23:10:25 +0000549
550 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000551 if (!ss->DefaultCubeMap) {
552 outOfMemory = GL_TRUE;
553 }
Brian Paul413d6a22000-05-26 14:44:59 +0000554
Brian Paul30f51ae2001-12-18 04:06:44 +0000555 if (!ss->DisplayList || !ss->TexObjects || !ss->VertexPrograms
556 || outOfMemory) {
jtgafb833d1999-08-19 00:55:39 +0000557 /* Ran out of memory at some point. Free everything and return NULL */
558 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000559 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000560 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000561 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul30f51ae2001-12-18 04:06:44 +0000562 if (ss->VertexPrograms)
563 _mesa_DeleteHashTable(ss->VertexPrograms);
Brian Paula8523782000-11-19 23:10:25 +0000564 if (ss->Default1D)
565 _mesa_free_texture_object(ss, ss->Default1D);
566 if (ss->Default2D)
567 _mesa_free_texture_object(ss, ss->Default2D);
568 if (ss->Default3D)
569 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000570 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000571 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000572 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000573 return NULL;
574 }
575 else {
576 return ss;
577 }
578}
579
580
581/*
582 * Deallocate a shared state context and all children structures.
583 */
Brian Paul178a1c52000-04-22 01:05:00 +0000584static void
585free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000586{
587 /* Free display lists */
588 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000589 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000590 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000591 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000592 }
593 else {
594 break;
595 }
596 }
Brian Paulbb797902000-01-24 16:19:54 +0000597 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000598
599 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000600 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000601 if (ctx->Driver.DeleteTexture)
602 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
603 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000604 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000605 }
Brian Paulbb797902000-01-24 16:19:54 +0000606 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000607
Brian Paul30f51ae2001-12-18 04:06:44 +0000608 /* Free vertex programs */
609 while (1) {
610 GLuint prog = _mesa_HashFirstEntry(ss->VertexPrograms);
611 if (prog) {
612 _mesa_delete_program(ctx, prog);
613 }
614 else {
615 break;
616 }
617 }
618 _mesa_DeleteHashTable(ss->VertexPrograms);
619
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000620 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000621}
622
623
624
jtgafb833d1999-08-19 00:55:39 +0000625/*
626 * Initialize the nth light. Note that the defaults for light 0 are
627 * different than the other lights.
628 */
Brian Paul178a1c52000-04-22 01:05:00 +0000629static void
630init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000631{
632 make_empty_list( l );
633
634 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
635 if (n==0) {
636 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
637 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
638 }
639 else {
640 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
641 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
642 }
643 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
644 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
645 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000646 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000647 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000648 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000649 l->ConstantAttenuation = 1.0;
650 l->LinearAttenuation = 0.0;
651 l->QuadraticAttenuation = 0.0;
652 l->Enabled = GL_FALSE;
653}
654
655
656
Brian Paul178a1c52000-04-22 01:05:00 +0000657static void
658init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000659{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000660 ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000661 lm->LocalViewer = GL_FALSE;
662 lm->TwoSide = GL_FALSE;
663 lm->ColorControl = GL_SINGLE_COLOR;
664}
665
666
Brian Paul178a1c52000-04-22 01:05:00 +0000667static void
668init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000669{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000670 ASSIGN_4V( m->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
671 ASSIGN_4V( m->Diffuse, 0.8F, 0.8F, 0.8F, 1.0F );
672 ASSIGN_4V( m->Specular, 0.0F, 0.0F, 0.0F, 1.0F );
673 ASSIGN_4V( m->Emission, 0.0F, 0.0F, 0.0F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000674 m->Shininess = 0.0;
675 m->AmbientIndex = 0;
676 m->DiffuseIndex = 1;
677 m->SpecularIndex = 1;
678}
679
680
681
Brian Paul178a1c52000-04-22 01:05:00 +0000682static void
683init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000684{
685 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
686
687 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000688 texUnit->CombineModeRGB = GL_MODULATE;
689 texUnit->CombineModeA = GL_MODULATE;
690 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
691 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
692 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
693 texUnit->CombineSourceA[0] = GL_TEXTURE;
694 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
695 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
696 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
697 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
698 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
699 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
700 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
701 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
702 texUnit->CombineScaleShiftRGB = 0;
703 texUnit->CombineScaleShiftA = 0;
704
jtgafb833d1999-08-19 00:55:39 +0000705 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
706 texUnit->TexGenEnabled = 0;
707 texUnit->GenModeS = GL_EYE_LINEAR;
708 texUnit->GenModeT = GL_EYE_LINEAR;
709 texUnit->GenModeR = GL_EYE_LINEAR;
710 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000711 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
712 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
713 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
714 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000715
jtgafb833d1999-08-19 00:55:39 +0000716 /* Yes, these plane coefficients are correct! */
717 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
718 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
719 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
720 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
721 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
722 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
723 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
724 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
725
Brian Paula8523782000-11-19 23:10:25 +0000726 texUnit->Current1D = ctx->Shared->Default1D;
727 texUnit->Current2D = ctx->Shared->Default2D;
728 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000729 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000730}
731
732
jtgafb833d1999-08-19 00:55:39 +0000733
Brian Paul4d053dd2000-01-14 04:45:47 +0000734
jtgafb833d1999-08-19 00:55:39 +0000735/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000736static void
737init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000738{
739 map->Order = 1;
740 map->u1 = 0.0;
741 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000742 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000743 if (map->Points) {
744 GLint i;
745 for (i=0;i<n;i++)
746 map->Points[i] = initial[i];
747 }
jtgafb833d1999-08-19 00:55:39 +0000748}
749
750
751/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000752static void
753init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000754{
755 map->Uorder = 1;
756 map->Vorder = 1;
757 map->u1 = 0.0;
758 map->u2 = 1.0;
759 map->v1 = 0.0;
760 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000761 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000762 if (map->Points) {
763 GLint i;
764 for (i=0;i<n;i++)
765 map->Points[i] = initial[i];
766 }
jtgafb833d1999-08-19 00:55:39 +0000767}
768
769
jtgafb833d1999-08-19 00:55:39 +0000770/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000771 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000772 */
Brian Paul178a1c52000-04-22 01:05:00 +0000773static void
774init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000775{
Brian Paul30f51ae2001-12-18 04:06:44 +0000776 GLuint i;
jtgafb833d1999-08-19 00:55:39 +0000777
Brian Paul4d053dd2000-01-14 04:45:47 +0000778 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000779
Brian Paulcd1cefa2001-06-13 14:56:14 +0000780 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
781 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
782
Brian Paul539cce52000-02-03 19:40:07 +0000783 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000784 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +0000785 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
786 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000787 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000788 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +0000789 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000790 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000791 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
792 ctx->Const.MinPointSize = MIN_POINT_SIZE;
793 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
794 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
795 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000796 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000797 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
798 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
799 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
800 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000801 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000802 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000803 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000804 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
805 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000806 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000807 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
808 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000809
Brian Paul30f51ae2001-12-18 04:06:44 +0000810 /* Initialize matrix stacks */
811 init_matrix_stack(&ctx->ModelviewMatrixStack, MAX_MODELVIEW_STACK_DEPTH,
812 _NEW_MODELVIEW);
813 init_matrix_stack(&ctx->ProjectionMatrixStack, MAX_PROJECTION_STACK_DEPTH,
814 _NEW_PROJECTION);
815 init_matrix_stack(&ctx->ColorMatrixStack, MAX_COLOR_STACK_DEPTH,
816 _NEW_COLOR_MATRIX);
817 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
818 init_matrix_stack(&ctx->TextureMatrixStack[i], MAX_TEXTURE_STACK_DEPTH,
819 _NEW_TEXTURE_MATRIX);
820 for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
821 init_matrix_stack(&ctx->ProgramMatrixStack[i], MAX_PROGRAM_STACK_DEPTH,
822 _NEW_TRACK_MATRIX);
823 ctx->CurrentStack = &ctx->ModelviewMatrixStack;
Brian Paul4d053dd2000-01-14 04:45:47 +0000824
Brian Paul30f51ae2001-12-18 04:06:44 +0000825 /* Init combined Modelview*Projection matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000826 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
827
Brian Paul4d053dd2000-01-14 04:45:47 +0000828 /* Accumulate buffer group */
829 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000830
Brian Paul4d053dd2000-01-14 04:45:47 +0000831 /* Color buffer group */
832 ctx->Color.IndexMask = 0xffffffff;
833 ctx->Color.ColorMask[0] = 0xff;
834 ctx->Color.ColorMask[1] = 0xff;
835 ctx->Color.ColorMask[2] = 0xff;
836 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000837 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000838 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000839 ctx->Color.DrawBuffer = GL_FRONT;
840 ctx->Color.AlphaEnabled = GL_FALSE;
841 ctx->Color.AlphaFunc = GL_ALWAYS;
842 ctx->Color.AlphaRef = 0;
843 ctx->Color.BlendEnabled = GL_FALSE;
844 ctx->Color.BlendSrcRGB = GL_ONE;
845 ctx->Color.BlendDstRGB = GL_ZERO;
846 ctx->Color.BlendSrcA = GL_ONE;
847 ctx->Color.BlendDstA = GL_ZERO;
848 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000849 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
850 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
851 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000852 ctx->Color.LogicOp = GL_COPY;
853 ctx->Color.DitherFlag = GL_TRUE;
854 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000855
Brian Paul4d053dd2000-01-14 04:45:47 +0000856 /* Current group */
Brian Paul86b84272001-12-14 02:50:01 +0000857 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 0.0, 0.0, 0.0, 0.0 );
858 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 0.0 );
859 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
860 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 0.0 );
861 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 );
862 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
863 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_TEX0 + i], 0.0, 0.0, 0.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000864 ctx->Current.Index = 1;
Brian Paul86b84272001-12-14 02:50:01 +0000865 ctx->Current.EdgeFlag = GL_TRUE;
866
Brian Paul4d053dd2000-01-14 04:45:47 +0000867 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
868 ctx->Current.RasterDistance = 0.0;
869 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
870 ctx->Current.RasterIndex = 1;
871 for (i=0; i<MAX_TEXTURE_UNITS; i++)
872 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
873 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
874 ctx->Current.RasterPosValid = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000875
jtgafb833d1999-08-19 00:55:39 +0000876
Brian Paul4d053dd2000-01-14 04:45:47 +0000877 /* Depth buffer group */
878 ctx->Depth.Test = GL_FALSE;
879 ctx->Depth.Clear = 1.0;
880 ctx->Depth.Func = GL_LESS;
881 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000882 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000883
Brian Paul4d053dd2000-01-14 04:45:47 +0000884 /* Evaluators group */
885 ctx->Eval.Map1Color4 = GL_FALSE;
886 ctx->Eval.Map1Index = GL_FALSE;
887 ctx->Eval.Map1Normal = GL_FALSE;
888 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
889 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
890 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
891 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
892 ctx->Eval.Map1Vertex3 = GL_FALSE;
893 ctx->Eval.Map1Vertex4 = GL_FALSE;
Brian Paulbc42c192002-01-05 21:53:20 +0000894 MEMSET(ctx->Eval.Map1Attrib, 0, sizeof(ctx->Eval.Map1Attrib));
Brian Paul4d053dd2000-01-14 04:45:47 +0000895 ctx->Eval.Map2Color4 = GL_FALSE;
896 ctx->Eval.Map2Index = GL_FALSE;
897 ctx->Eval.Map2Normal = GL_FALSE;
898 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
899 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
900 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
901 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
902 ctx->Eval.Map2Vertex3 = GL_FALSE;
903 ctx->Eval.Map2Vertex4 = GL_FALSE;
Brian Paulbc42c192002-01-05 21:53:20 +0000904 MEMSET(ctx->Eval.Map2Attrib, 0, sizeof(ctx->Eval.Map2Attrib));
Brian Paul4d053dd2000-01-14 04:45:47 +0000905 ctx->Eval.AutoNormal = GL_FALSE;
906 ctx->Eval.MapGrid1un = 1;
907 ctx->Eval.MapGrid1u1 = 0.0;
908 ctx->Eval.MapGrid1u2 = 1.0;
909 ctx->Eval.MapGrid2un = 1;
910 ctx->Eval.MapGrid2vn = 1;
911 ctx->Eval.MapGrid2u1 = 0.0;
912 ctx->Eval.MapGrid2u2 = 1.0;
913 ctx->Eval.MapGrid2v1 = 0.0;
914 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000915
Brian Paul4d053dd2000-01-14 04:45:47 +0000916 /* Evaluator data */
917 {
918 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
919 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
920 static GLfloat index[1] = { 1.0 };
921 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
922 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
Brian Paulbc42c192002-01-05 21:53:20 +0000923 static GLfloat attrib[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000924
Brian Paul4d053dd2000-01-14 04:45:47 +0000925 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
926 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
927 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
928 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
929 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
930 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
931 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
932 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
933 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
Brian Paulbc42c192002-01-05 21:53:20 +0000934 for (i = 0; i < 16; i++)
935 init_1d_map( ctx->EvalMap.Map1Attrib + i, 4, attrib );
jtgafb833d1999-08-19 00:55:39 +0000936
Brian Paul4d053dd2000-01-14 04:45:47 +0000937 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
938 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
939 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
940 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
941 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
942 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
943 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
944 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
945 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
Brian Paulbc42c192002-01-05 21:53:20 +0000946 for (i = 0; i < 16; i++)
947 init_2d_map( ctx->EvalMap.Map2Attrib + i, 4, attrib );
Brian Paul4d053dd2000-01-14 04:45:47 +0000948 }
jtgafb833d1999-08-19 00:55:39 +0000949
Brian Paul4d053dd2000-01-14 04:45:47 +0000950 /* Fog group */
951 ctx->Fog.Enabled = GL_FALSE;
952 ctx->Fog.Mode = GL_EXP;
953 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
954 ctx->Fog.Index = 0.0;
955 ctx->Fog.Density = 1.0;
956 ctx->Fog.Start = 0.0;
957 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000958 ctx->Fog.ColorSumEnabled = GL_FALSE;
959 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000960
Brian Paul4d053dd2000-01-14 04:45:47 +0000961 /* Hint group */
962 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
963 ctx->Hint.PointSmooth = GL_DONT_CARE;
964 ctx->Hint.LineSmooth = GL_DONT_CARE;
965 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
966 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000967 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
968 ctx->Hint.TextureCompression = GL_DONT_CARE;
Brian Paul3893e632001-05-21 16:41:03 +0000969 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000970
Brian Paul0771d152000-04-07 00:19:41 +0000971 /* Histogram group */
972 ctx->Histogram.Width = 0;
973 ctx->Histogram.Format = GL_RGBA;
974 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000975 ctx->Histogram.RedSize = 0;
976 ctx->Histogram.GreenSize = 0;
977 ctx->Histogram.BlueSize = 0;
978 ctx->Histogram.AlphaSize = 0;
979 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000980 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
981 ctx->Histogram.Count[i][0] = 0;
982 ctx->Histogram.Count[i][1] = 0;
983 ctx->Histogram.Count[i][2] = 0;
984 ctx->Histogram.Count[i][3] = 0;
985 }
986
987 /* Min/Max group */
988 ctx->MinMax.Format = GL_RGBA;
989 ctx->MinMax.Sink = GL_FALSE;
990 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
991 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
992 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
993 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
994
Brian Paul4d053dd2000-01-14 04:45:47 +0000995 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000996 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000997
Brian Paul4d053dd2000-01-14 04:45:47 +0000998 /* Lighting group */
999 for (i=0;i<MAX_LIGHTS;i++) {
1000 init_light( &ctx->Light.Light[i], i );
1001 }
1002 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001003
Brian Paul4d053dd2000-01-14 04:45:47 +00001004 init_lightmodel( &ctx->Light.Model );
1005 init_material( &ctx->Light.Material[0] );
1006 init_material( &ctx->Light.Material[1] );
1007 ctx->Light.ShadeModel = GL_SMOOTH;
1008 ctx->Light.Enabled = GL_FALSE;
1009 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1010 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +00001011 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
1012 GL_FRONT_AND_BACK,
1013 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001014
Brian Paul4d053dd2000-01-14 04:45:47 +00001015 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001016
Brian Paul4d053dd2000-01-14 04:45:47 +00001017 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +00001018 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1019 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001020 for (i = 0 ; i < 10 ; i++) {
1021 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1022 s->shininess = -1;
1023 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001024 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +00001025 }
Brian Paul77d61af2000-06-28 04:20:21 +00001026
jtgafb833d1999-08-19 00:55:39 +00001027
Brian Paul4d053dd2000-01-14 04:45:47 +00001028 /* Line group */
1029 ctx->Line.SmoothFlag = GL_FALSE;
1030 ctx->Line.StippleFlag = GL_FALSE;
1031 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +00001032 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001033 ctx->Line.StipplePattern = 0xffff;
1034 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001035
Brian Paul4d053dd2000-01-14 04:45:47 +00001036 /* Display List group */
1037 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001038
Brian Paul736fcbe2001-05-29 15:23:48 +00001039 /* Multisample */
1040 ctx->Multisample.Enabled = GL_FALSE;
1041 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
1042 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
1043 ctx->Multisample.SampleCoverage = GL_FALSE;
1044 ctx->Multisample.SampleCoverageValue = 1.0;
1045 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
1046
Brian Paul4d053dd2000-01-14 04:45:47 +00001047 /* Pixel group */
1048 ctx->Pixel.RedBias = 0.0;
1049 ctx->Pixel.RedScale = 1.0;
1050 ctx->Pixel.GreenBias = 0.0;
1051 ctx->Pixel.GreenScale = 1.0;
1052 ctx->Pixel.BlueBias = 0.0;
1053 ctx->Pixel.BlueScale = 1.0;
1054 ctx->Pixel.AlphaBias = 0.0;
1055 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001056 ctx->Pixel.DepthBias = 0.0;
1057 ctx->Pixel.DepthScale = 1.0;
1058 ctx->Pixel.IndexOffset = 0;
1059 ctx->Pixel.IndexShift = 0;
1060 ctx->Pixel.ZoomX = 1.0;
1061 ctx->Pixel.ZoomY = 1.0;
1062 ctx->Pixel.MapColorFlag = GL_FALSE;
1063 ctx->Pixel.MapStencilFlag = GL_FALSE;
1064 ctx->Pixel.MapStoSsize = 1;
1065 ctx->Pixel.MapItoIsize = 1;
1066 ctx->Pixel.MapItoRsize = 1;
1067 ctx->Pixel.MapItoGsize = 1;
1068 ctx->Pixel.MapItoBsize = 1;
1069 ctx->Pixel.MapItoAsize = 1;
1070 ctx->Pixel.MapRtoRsize = 1;
1071 ctx->Pixel.MapGtoGsize = 1;
1072 ctx->Pixel.MapBtoBsize = 1;
1073 ctx->Pixel.MapAtoAsize = 1;
1074 ctx->Pixel.MapStoS[0] = 0;
1075 ctx->Pixel.MapItoI[0] = 0;
1076 ctx->Pixel.MapItoR[0] = 0.0;
1077 ctx->Pixel.MapItoG[0] = 0.0;
1078 ctx->Pixel.MapItoB[0] = 0.0;
1079 ctx->Pixel.MapItoA[0] = 0.0;
1080 ctx->Pixel.MapItoR8[0] = 0;
1081 ctx->Pixel.MapItoG8[0] = 0;
1082 ctx->Pixel.MapItoB8[0] = 0;
1083 ctx->Pixel.MapItoA8[0] = 0;
1084 ctx->Pixel.MapRtoR[0] = 0.0;
1085 ctx->Pixel.MapGtoG[0] = 0.0;
1086 ctx->Pixel.MapBtoB[0] = 0.0;
1087 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001088 ctx->Pixel.HistogramEnabled = GL_FALSE;
1089 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1090 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1091 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1092 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001093 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1094 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1095 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1096 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001097 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1098 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1099 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1100 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001101 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1102 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1103 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001104 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1105 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1106 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1107 for (i = 0; i < 3; i++) {
1108 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1109 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1110 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1111 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1112 }
Brian Paul67adba12000-12-09 20:35:54 +00001113 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1114 ctx->Convolution1D.Filter[i] = 0.0;
1115 ctx->Convolution2D.Filter[i] = 0.0;
1116 ctx->Separable2D.Filter[i] = 0.0;
1117 }
Brian Paul82b02f02000-05-07 20:37:40 +00001118 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1119 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001120
Brian Paul4d053dd2000-01-14 04:45:47 +00001121 /* Point group */
1122 ctx->Point.SmoothFlag = GL_FALSE;
1123 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001124 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001125 ctx->Point.Params[0] = 1.0;
1126 ctx->Point.Params[1] = 0.0;
1127 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001128 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001129 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001130 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001131 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001132 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001133
Brian Paul4d053dd2000-01-14 04:45:47 +00001134 /* Polygon group */
1135 ctx->Polygon.CullFlag = GL_FALSE;
1136 ctx->Polygon.CullFaceMode = GL_BACK;
1137 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001138 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001139 ctx->Polygon.FrontMode = GL_FILL;
1140 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001141 ctx->Polygon.SmoothFlag = GL_FALSE;
1142 ctx->Polygon.StippleFlag = GL_FALSE;
1143 ctx->Polygon.OffsetFactor = 0.0F;
1144 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001145 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001146 ctx->Polygon.OffsetPoint = GL_FALSE;
1147 ctx->Polygon.OffsetLine = GL_FALSE;
1148 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001149
Brian Paul4d053dd2000-01-14 04:45:47 +00001150 /* Polygon Stipple group */
1151 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001152
Brian Paul4d053dd2000-01-14 04:45:47 +00001153 /* Scissor group */
1154 ctx->Scissor.Enabled = GL_FALSE;
1155 ctx->Scissor.X = 0;
1156 ctx->Scissor.Y = 0;
1157 ctx->Scissor.Width = 0;
1158 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001159
Brian Paul4d053dd2000-01-14 04:45:47 +00001160 /* Stencil group */
1161 ctx->Stencil.Enabled = GL_FALSE;
1162 ctx->Stencil.Function = GL_ALWAYS;
1163 ctx->Stencil.FailFunc = GL_KEEP;
1164 ctx->Stencil.ZPassFunc = GL_KEEP;
1165 ctx->Stencil.ZFailFunc = GL_KEEP;
1166 ctx->Stencil.Ref = 0;
1167 ctx->Stencil.ValueMask = STENCIL_MAX;
1168 ctx->Stencil.Clear = 0;
1169 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001170
Brian Paul4d053dd2000-01-14 04:45:47 +00001171 /* Texture group */
1172 ctx->Texture.CurrentUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001173 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001174 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1175 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001176 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001177 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001178
Brian Paul4d053dd2000-01-14 04:45:47 +00001179 /* Transformation group */
1180 ctx->Transform.MatrixMode = GL_MODELVIEW;
1181 ctx->Transform.Normalize = GL_FALSE;
1182 ctx->Transform.RescaleNormals = GL_FALSE;
Brian Paul8c2f6c52001-06-26 01:32:48 +00001183 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001184 for (i=0;i<MAX_CLIP_PLANES;i++) {
1185 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1186 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1187 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001188 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001189
Brian Paul4d053dd2000-01-14 04:45:47 +00001190 /* Viewport group */
1191 ctx->Viewport.X = 0;
1192 ctx->Viewport.Y = 0;
1193 ctx->Viewport.Width = 0;
1194 ctx->Viewport.Height = 0;
1195 ctx->Viewport.Near = 0.0;
1196 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001197 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001198
1199#define Sz 10
1200#define Tz 14
Brian Paulfde5e2c2001-09-15 18:02:49 +00001201 ctx->Viewport._WindowMap.m[Sz] = 0.5F * ctx->DepthMaxF;
1202 ctx->Viewport._WindowMap.m[Tz] = 0.5F * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001203#undef Sz
1204#undef Tz
1205
Keith Whitwell14940c42000-11-05 18:40:57 +00001206 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1207 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001208
Brian Paul4d053dd2000-01-14 04:45:47 +00001209 /* Vertex arrays */
1210 ctx->Array.Vertex.Size = 4;
1211 ctx->Array.Vertex.Type = GL_FLOAT;
1212 ctx->Array.Vertex.Stride = 0;
1213 ctx->Array.Vertex.StrideB = 0;
1214 ctx->Array.Vertex.Ptr = NULL;
1215 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001216 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001217 ctx->Array.Normal.Type = GL_FLOAT;
1218 ctx->Array.Normal.Stride = 0;
1219 ctx->Array.Normal.StrideB = 0;
1220 ctx->Array.Normal.Ptr = NULL;
1221 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001222 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001223 ctx->Array.Color.Size = 4;
1224 ctx->Array.Color.Type = GL_FLOAT;
1225 ctx->Array.Color.Stride = 0;
1226 ctx->Array.Color.StrideB = 0;
1227 ctx->Array.Color.Ptr = NULL;
1228 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001229 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1230 ctx->Array.SecondaryColor.Size = 4;
1231 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1232 ctx->Array.SecondaryColor.Stride = 0;
1233 ctx->Array.SecondaryColor.StrideB = 0;
1234 ctx->Array.SecondaryColor.Ptr = NULL;
1235 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1236 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1237 ctx->Array.FogCoord.Size = 1;
1238 ctx->Array.FogCoord.Type = GL_FLOAT;
1239 ctx->Array.FogCoord.Stride = 0;
1240 ctx->Array.FogCoord.StrideB = 0;
1241 ctx->Array.FogCoord.Ptr = NULL;
1242 ctx->Array.FogCoord.Enabled = GL_FALSE;
1243 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001244 ctx->Array.Index.Type = GL_FLOAT;
1245 ctx->Array.Index.Stride = 0;
1246 ctx->Array.Index.StrideB = 0;
1247 ctx->Array.Index.Ptr = NULL;
1248 ctx->Array.Index.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001249 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001250 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1251 ctx->Array.TexCoord[i].Size = 4;
1252 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1253 ctx->Array.TexCoord[i].Stride = 0;
1254 ctx->Array.TexCoord[i].StrideB = 0;
1255 ctx->Array.TexCoord[i].Ptr = NULL;
1256 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001257 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001258 }
1259 ctx->Array.TexCoordInterleaveFactor = 1;
1260 ctx->Array.EdgeFlag.Stride = 0;
1261 ctx->Array.EdgeFlag.StrideB = 0;
1262 ctx->Array.EdgeFlag.Ptr = NULL;
1263 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001264 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001265 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1266
1267 /* Pixel transfer */
1268 ctx->Pack.Alignment = 4;
1269 ctx->Pack.RowLength = 0;
1270 ctx->Pack.ImageHeight = 0;
1271 ctx->Pack.SkipPixels = 0;
1272 ctx->Pack.SkipRows = 0;
1273 ctx->Pack.SkipImages = 0;
1274 ctx->Pack.SwapBytes = GL_FALSE;
1275 ctx->Pack.LsbFirst = GL_FALSE;
1276 ctx->Unpack.Alignment = 4;
1277 ctx->Unpack.RowLength = 0;
1278 ctx->Unpack.ImageHeight = 0;
1279 ctx->Unpack.SkipPixels = 0;
1280 ctx->Unpack.SkipRows = 0;
1281 ctx->Unpack.SkipImages = 0;
1282 ctx->Unpack.SwapBytes = GL_FALSE;
1283 ctx->Unpack.LsbFirst = GL_FALSE;
1284
1285 /* Feedback */
1286 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1287 ctx->Feedback.Buffer = NULL;
1288 ctx->Feedback.BufferSize = 0;
1289 ctx->Feedback.Count = 0;
1290
1291 /* Selection/picking */
1292 ctx->Select.Buffer = NULL;
1293 ctx->Select.BufferSize = 0;
1294 ctx->Select.BufferCount = 0;
1295 ctx->Select.Hits = 0;
1296 ctx->Select.NameStackDepth = 0;
1297
Brian Paul4d053dd2000-01-14 04:45:47 +00001298 /* Renderer and client attribute stacks */
1299 ctx->AttribStackDepth = 0;
1300 ctx->ClientAttribStackDepth = 0;
1301
Brian Paul13811372000-04-12 00:27:37 +00001302 /* Display list */
1303 ctx->CallDepth = 0;
1304 ctx->ExecuteFlag = GL_TRUE;
1305 ctx->CompileFlag = GL_FALSE;
1306 ctx->CurrentListPtr = NULL;
1307 ctx->CurrentBlock = NULL;
1308 ctx->CurrentListNum = 0;
1309 ctx->CurrentPos = 0;
1310
1311 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001312 _mesa_init_colortable(&ctx->ColorTable);
1313 _mesa_init_colortable(&ctx->ProxyColorTable);
1314 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1315 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1316 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1317 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001318
Brian Paul86b84272001-12-14 02:50:01 +00001319 /* GL_NV_vertex_program */
Brian Paul30f51ae2001-12-18 04:06:44 +00001320 ctx->VertexProgram.Current = NULL;
1321 ctx->VertexProgram.CurrentID = 0;
Brian Paul86b84272001-12-14 02:50:01 +00001322 ctx->VertexProgram.Enabled = GL_FALSE;
1323 ctx->VertexProgram.PointSizeEnabled = GL_FALSE;
1324 ctx->VertexProgram.TwoSideEnabled = GL_FALSE;
1325 for (i = 0; i < VP_NUM_PROG_REGS / 4; i++) {
1326 ctx->VertexProgram.TrackMatrix[i] = GL_NONE;
1327 ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV;
1328 }
1329
Brian Paul4d053dd2000-01-14 04:45:47 +00001330 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001331 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001332 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001333 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001334
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001335 ctx->_NeedNormals = 0;
1336 ctx->_NeedEyeCoords = 0;
1337 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001338
Brian Paul4d053dd2000-01-14 04:45:47 +00001339 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1340
1341 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001342 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001343 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001344
1345 /* For debug/development only */
1346 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1347 ctx->FirstTimeCurrent = GL_TRUE;
1348
1349 /* Dither disable */
1350 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1351 if (ctx->NoDither) {
1352 if (getenv("MESA_DEBUG")) {
1353 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001354 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001355 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001356 }
1357}
1358
1359
1360
1361
jtgafb833d1999-08-19 00:55:39 +00001362/*
1363 * Allocate the proxy textures. If we run out of memory part way through
1364 * the allocations clean up and return GL_FALSE.
1365 * Return: GL_TRUE=success, GL_FALSE=failure
1366 */
Brian Paul178a1c52000-04-22 01:05:00 +00001367static GLboolean
1368alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001369{
1370 GLboolean out_of_memory;
1371 GLint i;
1372
Brian Paula8523782000-11-19 23:10:25 +00001373 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001374 if (!ctx->Texture.Proxy1D) {
1375 return GL_FALSE;
1376 }
1377
Brian Paula8523782000-11-19 23:10:25 +00001378 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001379 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001380 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001381 return GL_FALSE;
1382 }
1383
Brian Paula8523782000-11-19 23:10:25 +00001384 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001385 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001386 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1387 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1388 return GL_FALSE;
1389 }
1390
1391 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1392 if (!ctx->Texture.ProxyCubeMap) {
1393 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1394 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1395 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001396 return GL_FALSE;
1397 }
1398
1399 out_of_memory = GL_FALSE;
1400 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001401 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1402 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1403 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
Brian Paul172281d2001-07-26 20:02:10 +00001404 ctx->Texture.ProxyCubeMap->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001405 if (!ctx->Texture.Proxy1D->Image[i]
1406 || !ctx->Texture.Proxy2D->Image[i]
Brian Paul172281d2001-07-26 20:02:10 +00001407 || !ctx->Texture.Proxy3D->Image[i]
1408 || !ctx->Texture.ProxyCubeMap->Image[i]) {
jtgafb833d1999-08-19 00:55:39 +00001409 out_of_memory = GL_TRUE;
1410 }
1411 }
1412 if (out_of_memory) {
1413 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1414 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001415 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001416 }
1417 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001418 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001419 }
1420 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001421 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001422 }
Brian Paul172281d2001-07-26 20:02:10 +00001423 if (ctx->Texture.ProxyCubeMap->Image[i]) {
1424 _mesa_free_texture_image(ctx->Texture.ProxyCubeMap->Image[i]);
1425 }
jtgafb833d1999-08-19 00:55:39 +00001426 }
Brian Paula8523782000-11-19 23:10:25 +00001427 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1428 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1429 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
Brian Paul172281d2001-07-26 20:02:10 +00001430 _mesa_free_texture_object(NULL, ctx->Texture.ProxyCubeMap);
jtgafb833d1999-08-19 00:55:39 +00001431 return GL_FALSE;
1432 }
1433 else {
1434 return GL_TRUE;
1435 }
1436}
1437
1438
jtgafb833d1999-08-19 00:55:39 +00001439/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001440 * Initialize a GLcontext struct. This includes allocating all the
1441 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001442 */
Brian Paul178a1c52000-04-22 01:05:00 +00001443GLboolean
1444_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001445 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001446 GLcontext *share_list,
1447 void *driver_ctx,
1448 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001449{
Brian Paul5fb84d22000-05-24 15:04:45 +00001450 GLuint dispatchSize;
1451
jtgafb833d1999-08-19 00:55:39 +00001452 (void) direct; /* not used */
1453
jtgafb833d1999-08-19 00:55:39 +00001454 /* misc one-time initializations */
1455 one_time_init();
1456
Brian Paulb1394fa2000-09-26 20:53:53 +00001457 /**
1458 ** OpenGL SI stuff
1459 **/
1460 if (!ctx->imports.malloc) {
1461 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1462 }
1463 /* exports are setup by the device driver */
1464
jtgafb833d1999-08-19 00:55:39 +00001465 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001466 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001467 ctx->DrawBuffer = NULL;
1468 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001469
jtgafb833d1999-08-19 00:55:39 +00001470 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001471 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001472 ctx->Shared = share_list->Shared;
1473 }
1474 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001475 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001476 ctx->Shared = alloc_shared_state();
1477 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001478 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001479 }
1480 }
Brian Paul9560f052000-01-31 23:11:39 +00001481 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001482 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001483 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001484
Brian Paul5a2f32b2001-04-25 18:21:05 +00001485 /* Effectively bind the default textures to all texture units */
1486 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1487 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1488 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1489 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1490
Brian Paul4d053dd2000-01-14 04:45:47 +00001491 init_attrib_groups( ctx );
1492
Brian Paulb6bcae52001-01-23 23:39:36 +00001493 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001494 ctx->Color.DrawBuffer = GL_BACK;
1495 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1496 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1497 ctx->Pixel.ReadBuffer = GL_BACK;
1498 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1499 }
1500 else {
1501 ctx->Color.DrawBuffer = GL_FRONT;
1502 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1503 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1504 ctx->Pixel.ReadBuffer = GL_FRONT;
1505 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1506 }
1507
jtgafb833d1999-08-19 00:55:39 +00001508 if (!alloc_proxy_textures(ctx)) {
1509 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001510 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001511 }
jtgafb833d1999-08-19 00:55:39 +00001512
Brian Paulf59afc92000-05-23 23:23:00 +00001513 /* register the most recent extension functions with libGL */
1514 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1515 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1516 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1517 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1518 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1519 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1520 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1521 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1522
Brian Paul5fb84d22000-05-24 15:04:45 +00001523 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1524 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1525 * Mesa we do this to accomodate different versions of libGL and various
1526 * DRI drivers.
1527 */
1528 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1529 sizeof(struct _glapi_table) / sizeof(void *));
1530
Brian Paulfbd8f211999-11-11 01:22:25 +00001531 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001532 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1533 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001534 if (!ctx->Exec || !ctx->Save) {
1535 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001536 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001537 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001538 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001539 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1540 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001541 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001542
Keith Whitwellad2ac212000-11-24 10:25:05 +00001543 ctx->ExecPrefersFloat = GL_FALSE;
1544 ctx->SavePrefersFloat = GL_FALSE;
1545
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001546 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001547 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001548 ctx->TnlModule.Current = NULL;
1549 ctx->TnlModule.SwapCount = 0;
1550
Brian Paulb6bcae52001-01-23 23:39:36 +00001551 /* Z buffer stuff */
1552 if (ctx->Visual.depthBits == 0) {
1553 /* Special case. Even if we don't have a depth buffer we need
1554 * good values for DepthMax for Z vertex transformation purposes
1555 * and for per-fragment fog computation.
1556 */
1557 ctx->DepthMax = 1 << 16;
1558 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1559 }
1560 else if (ctx->Visual.depthBits < 32) {
1561 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1562 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1563 }
1564 else {
1565 /* Special case since shift values greater than or equal to the
1566 * number of bits in the left hand expression's type are undefined.
1567 */
1568 ctx->DepthMax = 0xffffffff;
1569 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1570 }
Brian Paulbc920f02001-05-07 16:32:51 +00001571 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001572
1573
Brian Paul3b18a362000-09-26 15:27:20 +00001574#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001575 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001576#if 0
1577 /* Brian: do you want to have CreateContext fail here,
1578 or should we just trap in NewTrace (currently done)? */
1579 if (!(ctx->TraceCtx)) {
1580 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001581 FREE( ctx->Exec );
1582 FREE( ctx->Save );
1583 return GL_FALSE;
1584 }
1585#endif
1586 trInitContext(ctx->TraceCtx);
1587
1588 ctx->TraceDispatch = (struct _glapi_table *)
1589 CALLOC(dispatchSize * sizeof(void*));
1590#if 0
1591 if (!(ctx->TraceCtx)) {
1592 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001593 FREE( ctx->Exec );
1594 FREE( ctx->Save );
1595 FREE( ctx->TraceCtx );
1596 return GL_FALSE;
1597 }
1598#endif
1599 trInitDispatch(ctx->TraceDispatch);
1600#endif
1601
Brian Paul4d053dd2000-01-14 04:45:47 +00001602 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001603}
1604
jtgafb833d1999-08-19 00:55:39 +00001605
1606
1607/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001608 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001609 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001610 * sharelist - another context to share display lists with or NULL
1611 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001612 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001613 */
Brian Paul178a1c52000-04-22 01:05:00 +00001614GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001615_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001616 GLcontext *share_list,
1617 void *driver_ctx,
1618 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001619{
1620 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1621 if (!ctx) {
1622 return NULL;
1623 }
Jouk Jansen12e875c2001-10-18 08:04:57 +00001624 ctx->Driver.CurrentExecPrimitive = 0;
Brian Paul178a1c52000-04-22 01:05:00 +00001625 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001626 return ctx;
1627 }
1628 else {
1629 FREE(ctx);
1630 return NULL;
1631 }
1632}
1633
1634
1635
1636/*
1637 * Free the data associated with the given context.
1638 * But don't free() the GLcontext struct itself!
1639 */
Brian Paul178a1c52000-04-22 01:05:00 +00001640void
Brian Paulb1394fa2000-09-26 20:53:53 +00001641_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001642{
Brian Paul4d053dd2000-01-14 04:45:47 +00001643 struct gl_shine_tab *s, *tmps;
Brian Paul30f51ae2001-12-18 04:06:44 +00001644 GLuint i;
Brian Paul4d053dd2000-01-14 04:45:47 +00001645
1646 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001647 if (ctx == _mesa_get_current_context()) {
1648 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001649 }
1650
Brian Paul30f51ae2001-12-18 04:06:44 +00001651 /*
1652 * Free transformation matrix stacks
1653 */
1654 free_matrix_stack(&ctx->ModelviewMatrixStack);
1655 free_matrix_stack(&ctx->ProjectionMatrixStack);
1656 free_matrix_stack(&ctx->ColorMatrixStack);
1657 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
1658 free_matrix_stack(&ctx->TextureMatrixStack[i]);
1659 for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
1660 free_matrix_stack(&ctx->ProgramMatrixStack[i]);
1661 /* combined Modelview*Projection matrix */
Brian Paulfd284452001-07-19 15:54:34 +00001662 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
1663
Brian Paul30f51ae2001-12-18 04:06:44 +00001664
1665 if (ctx->VertexProgram.Current) {
1666 ctx->VertexProgram.Current->RefCount--;
1667 if (ctx->VertexProgram.Current->RefCount <= 0)
1668 _mesa_delete_program(ctx, ctx->VertexProgram.CurrentID);
Brian Paulfd284452001-07-19 15:54:34 +00001669 }
1670
Brian Paul30f51ae2001-12-18 04:06:44 +00001671 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001672 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001673 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001674 assert(ctx->Shared->RefCount >= 0);
1675 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1676 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001677 /* free shared state */
1678 free_shared_state( ctx, ctx->Shared );
1679 }
1680
Brian Paul30f51ae2001-12-18 04:06:44 +00001681 /* Free lighting shininess exponentiation table */
Keith Whitwell14940c42000-11-05 18:40:57 +00001682 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001683 FREE( s );
1684 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001685 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001686
1687 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001688 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1689 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1690 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paulfd284452001-07-19 15:54:34 +00001691 _mesa_free_texture_object( NULL, ctx->Texture.ProxyCubeMap );
Brian Paul4d053dd2000-01-14 04:45:47 +00001692
1693 /* Free evaluator data */
1694 if (ctx->EvalMap.Map1Vertex3.Points)
1695 FREE( ctx->EvalMap.Map1Vertex3.Points );
1696 if (ctx->EvalMap.Map1Vertex4.Points)
1697 FREE( ctx->EvalMap.Map1Vertex4.Points );
1698 if (ctx->EvalMap.Map1Index.Points)
1699 FREE( ctx->EvalMap.Map1Index.Points );
1700 if (ctx->EvalMap.Map1Color4.Points)
1701 FREE( ctx->EvalMap.Map1Color4.Points );
1702 if (ctx->EvalMap.Map1Normal.Points)
1703 FREE( ctx->EvalMap.Map1Normal.Points );
1704 if (ctx->EvalMap.Map1Texture1.Points)
1705 FREE( ctx->EvalMap.Map1Texture1.Points );
1706 if (ctx->EvalMap.Map1Texture2.Points)
1707 FREE( ctx->EvalMap.Map1Texture2.Points );
1708 if (ctx->EvalMap.Map1Texture3.Points)
1709 FREE( ctx->EvalMap.Map1Texture3.Points );
1710 if (ctx->EvalMap.Map1Texture4.Points)
1711 FREE( ctx->EvalMap.Map1Texture4.Points );
Brian Paulc4afba32002-02-05 23:21:45 +00001712 for (i = 0; i < 16; i++)
1713 FREE((ctx->EvalMap.Map1Attrib[i].Points));
Brian Paul4d053dd2000-01-14 04:45:47 +00001714
1715 if (ctx->EvalMap.Map2Vertex3.Points)
1716 FREE( ctx->EvalMap.Map2Vertex3.Points );
1717 if (ctx->EvalMap.Map2Vertex4.Points)
1718 FREE( ctx->EvalMap.Map2Vertex4.Points );
1719 if (ctx->EvalMap.Map2Index.Points)
1720 FREE( ctx->EvalMap.Map2Index.Points );
1721 if (ctx->EvalMap.Map2Color4.Points)
1722 FREE( ctx->EvalMap.Map2Color4.Points );
1723 if (ctx->EvalMap.Map2Normal.Points)
1724 FREE( ctx->EvalMap.Map2Normal.Points );
1725 if (ctx->EvalMap.Map2Texture1.Points)
1726 FREE( ctx->EvalMap.Map2Texture1.Points );
1727 if (ctx->EvalMap.Map2Texture2.Points)
1728 FREE( ctx->EvalMap.Map2Texture2.Points );
1729 if (ctx->EvalMap.Map2Texture3.Points)
1730 FREE( ctx->EvalMap.Map2Texture3.Points );
1731 if (ctx->EvalMap.Map2Texture4.Points)
1732 FREE( ctx->EvalMap.Map2Texture4.Points );
Brian Paulc4afba32002-02-05 23:21:45 +00001733 for (i = 0; i < 16; i++)
1734 FREE((ctx->EvalMap.Map2Attrib[i].Points));
Brian Paul4d053dd2000-01-14 04:45:47 +00001735
Brian Paul4bdcfe52000-04-17 17:57:04 +00001736 _mesa_free_colortable_data( &ctx->ColorTable );
1737 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1738 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1739 _mesa_free_colortable_data( &ctx->Texture.Palette );
1740
Brian Paulfd284452001-07-19 15:54:34 +00001741 _math_matrix_dtr(&ctx->Viewport._WindowMap);
1742
Brian Paul69755402001-02-26 23:58:12 +00001743 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001744
1745 FREE(ctx->Exec);
1746 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001747}
1748
1749
1750
1751/*
1752 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001753 */
Brian Paul178a1c52000-04-22 01:05:00 +00001754void
Brian Paulb1394fa2000-09-26 20:53:53 +00001755_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001756{
1757 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001758 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001759 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001760 }
1761}
1762
1763
1764
1765/*
jtgafb833d1999-08-19 00:55:39 +00001766 * Copy attribute groups from one context to another.
1767 * Input: src - source context
1768 * dst - destination context
1769 * mask - bitwise OR of GL_*_BIT flags
1770 */
Brian Paul178a1c52000-04-22 01:05:00 +00001771void
Brian Paulb1394fa2000-09-26 20:53:53 +00001772_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001773{
1774 if (mask & GL_ACCUM_BUFFER_BIT) {
1775 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1776 }
1777 if (mask & GL_COLOR_BUFFER_BIT) {
1778 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1779 }
1780 if (mask & GL_CURRENT_BIT) {
1781 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1782 }
1783 if (mask & GL_DEPTH_BUFFER_BIT) {
1784 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1785 }
1786 if (mask & GL_ENABLE_BIT) {
1787 /* no op */
1788 }
1789 if (mask & GL_EVAL_BIT) {
1790 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1791 }
1792 if (mask & GL_FOG_BIT) {
1793 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1794 }
1795 if (mask & GL_HINT_BIT) {
1796 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1797 }
1798 if (mask & GL_LIGHTING_BIT) {
1799 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001800 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001801 }
1802 if (mask & GL_LINE_BIT) {
1803 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1804 }
1805 if (mask & GL_LIST_BIT) {
1806 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1807 }
1808 if (mask & GL_PIXEL_MODE_BIT) {
1809 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1810 }
1811 if (mask & GL_POINT_BIT) {
1812 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1813 }
1814 if (mask & GL_POLYGON_BIT) {
1815 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1816 }
1817 if (mask & GL_POLYGON_STIPPLE_BIT) {
1818 /* Use loop instead of MEMCPY due to problem with Portland Group's
1819 * C compiler. Reported by John Stone.
1820 */
1821 int i;
1822 for (i=0;i<32;i++) {
1823 dst->PolygonStipple[i] = src->PolygonStipple[i];
1824 }
1825 }
1826 if (mask & GL_SCISSOR_BIT) {
1827 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1828 }
1829 if (mask & GL_STENCIL_BUFFER_BIT) {
1830 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1831 }
1832 if (mask & GL_TEXTURE_BIT) {
1833 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1834 }
1835 if (mask & GL_TRANSFORM_BIT) {
1836 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1837 }
1838 if (mask & GL_VIEWPORT_BIT) {
1839 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1840 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001841 /* XXX FIXME: Call callbacks?
1842 */
1843 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001844}
1845
1846
jtgafb833d1999-08-19 00:55:39 +00001847/*
Brian Paul00037781999-12-17 14:52:35 +00001848 * Set the current context, binding the given frame buffer to the context.
1849 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001850void
1851_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001852{
Brian Paulb1394fa2000-09-26 20:53:53 +00001853 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001854}
1855
1856
Keith Whitwell23caf202000-11-16 21:05:34 +00001857static void print_info( void )
1858{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001859 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001860 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001861 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001862 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001863 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001864 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001865 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001866 (char *) _mesa_GetString(GL_EXTENSIONS));
1867#if defined(THREADS)
1868 fprintf(stderr, "Mesa thread-safe: YES\n");
1869#else
1870 fprintf(stderr, "Mesa thread-safe: NO\n");
1871#endif
1872#if defined(USE_X86_ASM)
1873 fprintf(stderr, "Mesa x86-optimized: YES\n");
1874#else
1875 fprintf(stderr, "Mesa x86-optimized: NO\n");
1876#endif
davem69e4f84b42001-06-05 03:58:20 +00001877#if defined(USE_SPARC_ASM)
1878 fprintf(stderr, "Mesa sparc-optimized: YES\n");
1879#else
1880 fprintf(stderr, "Mesa sparc-optimized: NO\n");
1881#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001882}
1883
1884
Brian Paul00037781999-12-17 14:52:35 +00001885/*
1886 * Bind the given context to the given draw-buffer and read-buffer
1887 * and make it the current context for this thread.
1888 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001889void
1890_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1891 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001892{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001893 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001894 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001895
Brian Paulbe3602d2001-02-28 00:27:48 +00001896 /* Check that the context's and framebuffer's visuals are compatible.
1897 * We could do a lot more checking here but this'll catch obvious
1898 * problems.
1899 */
1900 if (newCtx && drawBuffer && readBuffer) {
1901 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1902 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1903 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1904 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1905 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1906 return; /* incompatible */
1907 }
1908 }
1909
Brian Paul00037781999-12-17 14:52:35 +00001910 /* We call this function periodically (just here for now) in
1911 * order to detect when multithreading has begun.
1912 */
1913 _glapi_check_multithread();
1914
Brian Paulf9b97d92000-01-28 20:17:42 +00001915 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001916 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001917
1918
1919 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001920 _glapi_set_dispatch(NULL); /* none current */
1921 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001922 else {
1923 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001924
Keith Whitwell23caf202000-11-16 21:05:34 +00001925 if (drawBuffer && readBuffer) {
1926 /* TODO: check if newCtx and buffer's visual match??? */
1927 newCtx->DrawBuffer = drawBuffer;
1928 newCtx->ReadBuffer = readBuffer;
1929 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001930 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001931 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001932
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001933 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001934 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1935
1936 /* We can use this to help debug user's problems. Tell them to set
1937 * the MESA_INFO env variable before running their app. Then the
1938 * first time each context is made current we'll print some useful
1939 * information.
1940 */
1941 if (newCtx->FirstTimeCurrent) {
1942 if (getenv("MESA_INFO")) {
1943 print_info();
1944 }
1945 newCtx->FirstTimeCurrent = GL_FALSE;
1946 }
Brian Paul00037781999-12-17 14:52:35 +00001947 }
1948}
1949
1950
1951
1952/*
1953 * Return current context handle for the calling thread.
1954 * This isn't the fastest way to get the current context.
1955 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1956 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001957GLcontext *
1958_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001959{
Brian Paulf9b97d92000-01-28 20:17:42 +00001960 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001961}
1962
1963
1964
1965/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001966 * This should be called by device drivers just before they do a
1967 * swapbuffers. Any pending rendering commands will be executed.
Brian Paul9a888bd2002-03-13 04:33:32 +00001968 * XXX we should really rename this function to _mesa_flush() or something.
jtgafb833d1999-08-19 00:55:39 +00001969 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001970void
1971_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001972{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001973 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001974}
1975
1976
Brian Paul00037781999-12-17 14:52:35 +00001977
Brian Paulfbd8f211999-11-11 01:22:25 +00001978/*
1979 * Return pointer to this context's current API dispatch table.
1980 * It'll either be the immediate-mode execute dispatcher or the
1981 * display list compile dispatcher.
1982 */
1983struct _glapi_table *
1984_mesa_get_dispatch(GLcontext *ctx)
1985{
1986 return ctx->CurrentDispatch;
1987}
1988
1989
1990
jtgafb833d1999-08-19 00:55:39 +00001991/**********************************************************************/
1992/***** Miscellaneous functions *****/
1993/**********************************************************************/
1994
1995
1996/*
1997 * This function is called when the Mesa user has stumbled into a code
1998 * path which may not be implemented fully or correctly.
1999 */
Brian Paul08836342001-03-03 20:33:27 +00002000void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00002001{
2002 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00002003#ifdef XF86DRI
2004 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
2005#else
2006 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
2007#endif
jtgafb833d1999-08-19 00:55:39 +00002008 (void) ctx;
2009}
2010
2011
2012
2013/*
2014 * This is called to inform the user that he or she has tried to do
2015 * something illogical or if there's likely a bug in their program
2016 * (like enabled depth testing without a depth buffer).
2017 */
Brian Paulb1394fa2000-09-26 20:53:53 +00002018void
2019_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00002020{
Brian Paulb1394fa2000-09-26 20:53:53 +00002021 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00002022}
2023
2024
2025
Brian Paulfa9df402000-02-02 19:16:46 +00002026/*
jtgafb833d1999-08-19 00:55:39 +00002027 * This is Mesa's error handler. Normally, all that's done is the updating
2028 * of the current error value. If Mesa is compiled with -DDEBUG or if the
2029 * environment variable "MESA_DEBUG" is defined then a real error message
2030 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00002031 * Input: ctx - the GL context
2032 * error - the error value
2033 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00002034 */
Brian Paul7eb06032000-07-14 04:13:40 +00002035void
Brian Paul08836342001-03-03 20:33:27 +00002036_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00002037{
Brian Paul7eb06032000-07-14 04:13:40 +00002038 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00002039 GLboolean debug;
2040
2041#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002042 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002043 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002044 else
2045 debug = GL_TRUE;
2046#else
2047 if (debugEnv)
2048 debug = GL_TRUE;
2049 else
2050 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002051#endif
2052
2053 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002054 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002055 switch (error) {
2056 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002057 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002058 break;
2059 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002060 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002061 break;
2062 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002063 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002064 break;
2065 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002066 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002067 break;
2068 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002069 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002070 break;
2071 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002072 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002073 break;
2074 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002075 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002076 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002077 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002078 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002079 break;
jtgafb833d1999-08-19 00:55:39 +00002080 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002081 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002082 break;
2083 }
Brian Paul7eb06032000-07-14 04:13:40 +00002084 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002085 }
2086
Brian Paul7eb06032000-07-14 04:13:40 +00002087 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002088 ctx->ErrorValue = error;
2089 }
2090
2091 /* Call device driver's error handler, if any. This is used on the Mac. */
2092 if (ctx->Driver.Error) {
2093 (*ctx->Driver.Error)( ctx );
2094 }
2095}
2096
2097
2098
Brian Paulfa9df402000-02-02 19:16:46 +00002099void
2100_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002101{
Brian Paulfa9df402000-02-02 19:16:46 +00002102 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002103 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002104 if (ctx->Driver.Finish) {
2105 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002106 }
2107}
2108
2109
2110
Brian Paulfa9df402000-02-02 19:16:46 +00002111void
2112_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002113{
Brian Paulfa9df402000-02-02 19:16:46 +00002114 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002115 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002116 if (ctx->Driver.Flush) {
2117 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002118 }
jtgafb833d1999-08-19 00:55:39 +00002119}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002120
2121
2122
Keith Whitwellcab974c2000-12-26 05:09:27 +00002123const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002124 "GL_POINTS",
2125 "GL_LINES",
2126 "GL_LINE_LOOP",
2127 "GL_LINE_STRIP",
2128 "GL_TRIANGLES",
2129 "GL_TRIANGLE_STRIP",
2130 "GL_TRIANGLE_FAN",
2131 "GL_QUADS",
2132 "GL_QUAD_STRIP",
2133 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002134 "outside begin/end",
2135 "inside unkown primitive",
2136 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002137};