blob: 686d5535137db71ebe6afac47543183b5773a3ca [file] [log] [blame]
Brian Paul645ced22001-12-17 22:41:45 +00001/* $Id: context.c,v 1.151 2001/12/17 22:41:45 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 Paulb6bcae52001-01-23 23:39:36 +00007 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000032#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000034#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000035#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "dlist.h"
37#include "eval.h"
38#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000039#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000041#include "get.h"
Brian Paul9560f052000-01-31 23:11:39 +000042#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000044#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000045#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000046#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000047#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "mmath.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +000050#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000051#include "teximage.h"
52#include "texobj.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000053#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "varray.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +000055#include "vtxfmt.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000056#include "math/m_translate.h"
57#include "math/m_vertices.h"
58#include "math/m_matrix.h"
59#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +000060#include "math/mathmod.h"
jtgafb833d1999-08-19 00:55:39 +000061#endif
62
Brian Paul3b18a362000-09-26 15:27:20 +000063#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000064#include "Trace/tr_context.h"
65#include "Trace/tr_wrapper.h"
66#endif
67
davem69775355a2001-06-05 23:54:00 +000068#ifdef USE_SPARC_ASM
69#include "SPARC/sparc.h"
70#endif
jtgafb833d1999-08-19 00:55:39 +000071
Keith Whitwell23caf202000-11-16 21:05:34 +000072#ifndef MESA_VERBOSE
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000073int MESA_VERBOSE = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000074/* | VERBOSE_PIPELINE */
75/* | VERBOSE_IMMEDIATE */
76/* | VERBOSE_VARRAY */
77/* | VERBOSE_TEXTURE */
78/* | VERBOSE_API */
79/* | VERBOSE_DRIVER */
80/* | VERBOSE_STATE */
Keith Whitwell23caf202000-11-16 21:05:34 +000081/* | VERBOSE_DISPLAY_LIST */
82;
83#endif
84
85#ifndef MESA_DEBUG_FLAGS
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000086int MESA_DEBUG_FLAGS = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000087/* | DEBUG_ALWAYS_FLUSH */
88;
89#endif
Brian Paulb1394fa2000-09-26 20:53:53 +000090
Brian Paul86b84272001-12-14 02:50:01 +000091
92
Brian Paulb1394fa2000-09-26 20:53:53 +000093/**********************************************************************/
94/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
95/**********************************************************************/
96
97static GLboolean
98_mesa_DestroyContext(__GLcontext *gc)
99{
100 if (gc) {
101 _mesa_free_context_data(gc);
102 (*gc->imports.free)(gc, gc);
103 }
104 return GL_TRUE;
105}
106
107
108/* exported OpenGL SI interface */
109__GLcontext *
110__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
111{
112 GLcontext *ctx;
113
114 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
115 if (ctx == NULL) {
116 return NULL;
117 }
Jouk Jansen12e875c2001-10-18 08:04:57 +0000118 ctx->Driver.CurrentExecPrimitive=0;
Brian Paulb1394fa2000-09-26 20:53:53 +0000119 ctx->imports = *imports;
120
121 _mesa_initialize_visual(&ctx->Visual,
122 modes->rgbMode,
123 modes->doubleBufferMode,
124 modes->stereoMode,
125 modes->redBits,
126 modes->greenBits,
127 modes->blueBits,
128 modes->alphaBits,
129 modes->indexBits,
130 modes->depthBits,
131 modes->stencilBits,
132 modes->accumRedBits,
133 modes->accumGreenBits,
134 modes->accumBlueBits,
135 modes->accumAlphaBits,
136 0);
137
Keith Whitwellb980b2e2001-01-08 04:09:41 +0000138 /* KW: was imports->wscx */
139 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
Brian Paulb1394fa2000-09-26 20:53:53 +0000140
141 ctx->exports.destroyContext = _mesa_DestroyContext;
142
143 return ctx;
144}
145
146
147/* exported OpenGL SI interface */
148void
149__glCoreNopDispatch(void)
150{
151#if 0
152 /* SI */
153 __gl_dispatch = __glNopDispatchState;
154#else
155 /* Mesa */
156 _glapi_set_dispatch(NULL);
157#endif
158}
159
160
jtgafb833d1999-08-19 00:55:39 +0000161/**********************************************************************/
162/***** Context and Thread management *****/
163/**********************************************************************/
164
165
jtgafb833d1999-08-19 00:55:39 +0000166
jtgafb833d1999-08-19 00:55:39 +0000167/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000168/***** GL Visual allocation/destruction *****/
169/**********************************************************************/
170
171
172/*
173 * Allocate a new GLvisual object.
174 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000175 * dbFlag - double buffering?
176 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000177 * depthBits - requested bits per depth buffer value
178 * Any value in [0, 32] is acceptable but the actual
179 * depth type will be GLushort or GLuint as needed.
180 * stencilBits - requested minimum bits per stencil buffer value
181 * accumBits - requested minimum bits per accum buffer component
182 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
183 * red/green/blue/alphaBits - number of bits per color component
184 * in frame buffer for RGB(A) mode.
185 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000186 * Return: pointer to new GLvisual or NULL if requested parameters can't
187 * be met.
188 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000189GLvisual *
190_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000191 GLboolean dbFlag,
192 GLboolean stereoFlag,
193 GLint redBits,
194 GLint greenBits,
195 GLint blueBits,
196 GLint alphaBits,
197 GLint indexBits,
198 GLint depthBits,
199 GLint stencilBits,
200 GLint accumRedBits,
201 GLint accumGreenBits,
202 GLint accumBlueBits,
203 GLint accumAlphaBits,
204 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000205{
Brian Paul178a1c52000-04-22 01:05:00 +0000206 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
207 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000208 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000209 redBits, greenBits, blueBits, alphaBits,
210 indexBits, depthBits, stencilBits,
211 accumRedBits, accumGreenBits,
212 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000213 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000214 FREE(vis);
215 return NULL;
216 }
217 }
218 return vis;
219}
220
221
222/*
223 * Initialize the fields of the given GLvisual.
224 * Input: see _mesa_create_visual() above.
225 * Return: GL_TRUE = success
226 * GL_FALSE = failure.
227 */
228GLboolean
229_mesa_initialize_visual( GLvisual *vis,
230 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000231 GLboolean dbFlag,
232 GLboolean stereoFlag,
233 GLint redBits,
234 GLint greenBits,
235 GLint blueBits,
236 GLint alphaBits,
237 GLint indexBits,
238 GLint depthBits,
239 GLint stencilBits,
240 GLint accumRedBits,
241 GLint accumGreenBits,
242 GLint accumBlueBits,
243 GLint accumAlphaBits,
244 GLint numSamples )
245{
Brian Paulb6bcae52001-01-23 23:39:36 +0000246 (void) numSamples;
247
Brian Paul178a1c52000-04-22 01:05:00 +0000248 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000249
Brian Pauled30dfa2000-03-03 17:47:39 +0000250 /* This is to catch bad values from device drivers not updated for
251 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
252 * bad value now (a 1-bit depth buffer!?!).
253 */
254 assert(depthBits == 0 || depthBits > 1);
255
256 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000257 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000258 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000259 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000260 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000261 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000262 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000263 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000264 }
265 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000266 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000267 }
268 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000269 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000270 }
271 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000272 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000273 }
274
Brian Paulb6bcae52001-01-23 23:39:36 +0000275 vis->rgbMode = rgbFlag;
276 vis->doubleBufferMode = dbFlag;
277 vis->stereoMode = stereoFlag;
278 vis->redBits = redBits;
279 vis->greenBits = greenBits;
280 vis->blueBits = blueBits;
281 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000282
Brian Paulb6bcae52001-01-23 23:39:36 +0000283 vis->indexBits = indexBits;
284 vis->depthBits = depthBits;
285 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
286 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
287 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
288 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
289 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000290
Brian Paul178a1c52000-04-22 01:05:00 +0000291 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000292}
293
294
Brian Paulb371e0d2000-03-31 01:05:51 +0000295void
296_mesa_destroy_visual( GLvisual *vis )
297{
298 FREE(vis);
299}
300
301
Brian Paul4d053dd2000-01-14 04:45:47 +0000302/**********************************************************************/
303/***** GL Framebuffer allocation/destruction *****/
304/**********************************************************************/
305
306
307/*
308 * Create a new framebuffer. A GLframebuffer is a struct which
309 * encapsulates the depth, stencil and accum buffers and related
310 * parameters.
Brian Paulbe3602d2001-02-28 00:27:48 +0000311 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +0000312 * softwareDepth - create/use a software depth buffer?
313 * softwareStencil - create/use a software stencil buffer?
314 * softwareAccum - create/use a software accum buffer?
315 * softwareAlpha - create/use a software alpha buffer?
Brian Paul4d053dd2000-01-14 04:45:47 +0000316 * Return: pointer to new GLframebuffer struct or NULL if error.
317 */
Brian Paul178a1c52000-04-22 01:05:00 +0000318GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000319_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000320 GLboolean softwareDepth,
321 GLboolean softwareStencil,
322 GLboolean softwareAccum,
323 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000324{
Brian Paul178a1c52000-04-22 01:05:00 +0000325 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
326 assert(visual);
327 if (buffer) {
328 _mesa_initialize_framebuffer(buffer, visual,
329 softwareDepth, softwareStencil,
330 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000331 }
Brian Paul178a1c52000-04-22 01:05:00 +0000332 return buffer;
333}
334
335
336/*
337 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000338 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000339 */
340void
341_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000342 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000343 GLboolean softwareDepth,
344 GLboolean softwareStencil,
345 GLboolean softwareAccum,
346 GLboolean softwareAlpha )
347{
348 assert(buffer);
349 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000350
351 /* sanity checks */
352 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000353 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000354 }
355 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000356 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000357 }
358 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000359 assert(visual->rgbMode);
360 assert(visual->accumRedBits > 0);
361 assert(visual->accumGreenBits > 0);
362 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000363 }
364 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000365 assert(visual->rgbMode);
366 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000367 }
368
Brian Paul75978bd2001-04-27 21:17:20 +0000369 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000370 buffer->UseSoftwareDepthBuffer = softwareDepth;
371 buffer->UseSoftwareStencilBuffer = softwareStencil;
372 buffer->UseSoftwareAccumBuffer = softwareAccum;
373 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000374}
375
376
Brian Paul4d053dd2000-01-14 04:45:47 +0000377/*
378 * Free a framebuffer struct and its buffers.
379 */
Brian Paul178a1c52000-04-22 01:05:00 +0000380void
Brian Paulb1394fa2000-09-26 20:53:53 +0000381_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000382{
383 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000384 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000385 FREE(buffer);
386 }
387}
388
389
Brian Paul75978bd2001-04-27 21:17:20 +0000390/*
391 * Free the data hanging off of <buffer>, but not <buffer> itself.
392 */
393void
394_mesa_free_framebuffer_data( GLframebuffer *buffer )
395{
396 if (!buffer)
397 return;
398
399 if (buffer->DepthBuffer) {
400 FREE( buffer->DepthBuffer );
401 buffer->DepthBuffer = NULL;
402 }
403 if (buffer->Accum) {
404 FREE( buffer->Accum );
405 buffer->Accum = NULL;
406 }
407 if (buffer->Stencil) {
408 FREE( buffer->Stencil );
409 buffer->Stencil = NULL;
410 }
411 if (buffer->FrontLeftAlpha) {
412 FREE( buffer->FrontLeftAlpha );
413 buffer->FrontLeftAlpha = NULL;
414 }
415 if (buffer->BackLeftAlpha) {
416 FREE( buffer->BackLeftAlpha );
417 buffer->BackLeftAlpha = NULL;
418 }
419 if (buffer->FrontRightAlpha) {
420 FREE( buffer->FrontRightAlpha );
421 buffer->FrontRightAlpha = NULL;
422 }
423 if (buffer->BackRightAlpha) {
424 FREE( buffer->BackRightAlpha );
425 buffer->BackRightAlpha = NULL;
426 }
427}
428
429
Brian Paul4d053dd2000-01-14 04:45:47 +0000430
431/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000432/***** Context allocation, initialization, destroying *****/
433/**********************************************************************/
434
435
Brian Paul9560f052000-01-31 23:11:39 +0000436_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
437
438
jtgafb833d1999-08-19 00:55:39 +0000439/*
440 * This function just calls all the various one-time-init functions in Mesa.
441 */
Brian Paul178a1c52000-04-22 01:05:00 +0000442static void
443one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000444{
445 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000446 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000447 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000448 /* do some implementation tests */
449 assert( sizeof(GLbyte) == 1 );
450 assert( sizeof(GLshort) >= 2 );
451 assert( sizeof(GLint) >= 4 );
452 assert( sizeof(GLubyte) == 1 );
453 assert( sizeof(GLushort) >= 2 );
454 assert( sizeof(GLuint) >= 4 );
455
Brian Paul08836342001-03-03 20:33:27 +0000456 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000457
Keith Whitwell23caf202000-11-16 21:05:34 +0000458 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000459 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000460
davem69775355a2001-06-05 23:54:00 +0000461#ifdef USE_SPARC_ASM
462 _mesa_init_sparc_glapi_relocs();
463#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000464 if (getenv("MESA_DEBUG")) {
465 _glapi_noop_enable_warnings(GL_TRUE);
466 }
467 else {
468 _glapi_noop_enable_warnings(GL_FALSE);
469 }
470
jtgafb833d1999-08-19 00:55:39 +0000471#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
472 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
473#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000474
475 alreadyCalled = GL_TRUE;
476 }
Brian Paul9560f052000-01-31 23:11:39 +0000477 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000478}
479
480
Brian Paul86b84272001-12-14 02:50:01 +0000481static void
482init_matrix_stack( struct matrix_stack *stack,
483 GLuint maxDepth, GLuint dirtyFlag )
484{
485 GLuint i;
486
487 stack->Depth = 0;
488 stack->MaxDepth = maxDepth;
489 stack->DirtyFlag = dirtyFlag;
490 /* Top matrix */
491 _math_matrix_ctr( &stack->Top );
492 _math_matrix_alloc_inv( &stack->Top );
493 /* The stack */
494 stack->Stack = MALLOC(maxDepth * sizeof(GLmatrix));
495 for (i = 0; i < maxDepth; i++) {
496 _math_matrix_ctr(&stack->Stack[i]);
497 _math_matrix_alloc_inv(&stack->Stack[i]);
498 }
499}
500
501
502static void
503free_matrix_stack( struct matrix_stack *stack )
504{
505 GLuint i;
506 _math_matrix_dtr( &stack->Top );
507 for (i = 0; i < stack->MaxDepth; i++) {
508 _math_matrix_dtr(&stack->Stack[i]);
509 }
510}
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();
jtgafb833d1999-08-19 00:55:39 +0000530
531 /* Default Texture objects */
532 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000533
534 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
535 if (!ss->Default1D) {
536 outOfMemory = GL_TRUE;
537 }
jtgafb833d1999-08-19 00:55:39 +0000538
Brian Paula8523782000-11-19 23:10:25 +0000539 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
540 if (!ss->Default2D) {
541 outOfMemory = GL_TRUE;
542 }
Brian Paula8523782000-11-19 23:10:25 +0000543
544 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
545 if (!ss->Default3D) {
546 outOfMemory = GL_TRUE;
547 }
Brian Paula8523782000-11-19 23:10:25 +0000548
549 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000550 if (!ss->DefaultCubeMap) {
551 outOfMemory = GL_TRUE;
552 }
Brian Paul413d6a22000-05-26 14:44:59 +0000553
jtgafb833d1999-08-19 00:55:39 +0000554 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
555 /* Ran out of memory at some point. Free everything and return NULL */
556 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000557 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000558 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000559 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula8523782000-11-19 23:10:25 +0000560 if (ss->Default1D)
561 _mesa_free_texture_object(ss, ss->Default1D);
562 if (ss->Default2D)
563 _mesa_free_texture_object(ss, ss->Default2D);
564 if (ss->Default3D)
565 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000566 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000567 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000568 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000569 return NULL;
570 }
571 else {
572 return ss;
573 }
574}
575
576
577/*
578 * Deallocate a shared state context and all children structures.
579 */
Brian Paul178a1c52000-04-22 01:05:00 +0000580static void
581free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000582{
583 /* Free display lists */
584 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000585 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000586 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000587 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000588 }
589 else {
590 break;
591 }
592 }
Brian Paulbb797902000-01-24 16:19:54 +0000593 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000594
595 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000596 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000597 if (ctx->Driver.DeleteTexture)
598 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
599 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000600 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000601 }
Brian Paulbb797902000-01-24 16:19:54 +0000602 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000603
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000604 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000605}
606
607
608
jtgafb833d1999-08-19 00:55:39 +0000609/*
610 * Initialize the nth light. Note that the defaults for light 0 are
611 * different than the other lights.
612 */
Brian Paul178a1c52000-04-22 01:05:00 +0000613static void
614init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000615{
616 make_empty_list( l );
617
618 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
619 if (n==0) {
620 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
621 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
622 }
623 else {
624 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
625 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
626 }
627 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
628 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
629 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000630 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000631 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000632 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000633 l->ConstantAttenuation = 1.0;
634 l->LinearAttenuation = 0.0;
635 l->QuadraticAttenuation = 0.0;
636 l->Enabled = GL_FALSE;
637}
638
639
640
Brian Paul178a1c52000-04-22 01:05:00 +0000641static void
642init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000643{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000644 ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000645 lm->LocalViewer = GL_FALSE;
646 lm->TwoSide = GL_FALSE;
647 lm->ColorControl = GL_SINGLE_COLOR;
648}
649
650
Brian Paul178a1c52000-04-22 01:05:00 +0000651static void
652init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000653{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000654 ASSIGN_4V( m->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
655 ASSIGN_4V( m->Diffuse, 0.8F, 0.8F, 0.8F, 1.0F );
656 ASSIGN_4V( m->Specular, 0.0F, 0.0F, 0.0F, 1.0F );
657 ASSIGN_4V( m->Emission, 0.0F, 0.0F, 0.0F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000658 m->Shininess = 0.0;
659 m->AmbientIndex = 0;
660 m->DiffuseIndex = 1;
661 m->SpecularIndex = 1;
662}
663
664
665
Brian Paul178a1c52000-04-22 01:05:00 +0000666static void
667init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000668{
669 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
670
671 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000672 texUnit->CombineModeRGB = GL_MODULATE;
673 texUnit->CombineModeA = GL_MODULATE;
674 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
675 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
676 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
677 texUnit->CombineSourceA[0] = GL_TEXTURE;
678 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
679 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
680 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
681 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
682 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
683 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
684 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
685 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
686 texUnit->CombineScaleShiftRGB = 0;
687 texUnit->CombineScaleShiftA = 0;
688
jtgafb833d1999-08-19 00:55:39 +0000689 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
690 texUnit->TexGenEnabled = 0;
691 texUnit->GenModeS = GL_EYE_LINEAR;
692 texUnit->GenModeT = GL_EYE_LINEAR;
693 texUnit->GenModeR = GL_EYE_LINEAR;
694 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000695 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
696 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
697 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
698 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000699
jtgafb833d1999-08-19 00:55:39 +0000700 /* Yes, these plane coefficients are correct! */
701 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
702 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
703 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
704 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
705 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
706 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
707 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
708 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
709
Brian Paula8523782000-11-19 23:10:25 +0000710 texUnit->Current1D = ctx->Shared->Default1D;
711 texUnit->Current2D = ctx->Shared->Default2D;
712 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000713 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000714}
715
716
jtgafb833d1999-08-19 00:55:39 +0000717
Brian Paul4d053dd2000-01-14 04:45:47 +0000718
jtgafb833d1999-08-19 00:55:39 +0000719/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000720static void
721init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000722{
723 map->Order = 1;
724 map->u1 = 0.0;
725 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000726 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000727 if (map->Points) {
728 GLint i;
729 for (i=0;i<n;i++)
730 map->Points[i] = initial[i];
731 }
jtgafb833d1999-08-19 00:55:39 +0000732}
733
734
735/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000736static void
737init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000738{
739 map->Uorder = 1;
740 map->Vorder = 1;
741 map->u1 = 0.0;
742 map->u2 = 1.0;
743 map->v1 = 0.0;
744 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000745 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000746 if (map->Points) {
747 GLint i;
748 for (i=0;i<n;i++)
749 map->Points[i] = initial[i];
750 }
jtgafb833d1999-08-19 00:55:39 +0000751}
752
753
jtgafb833d1999-08-19 00:55:39 +0000754/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000755 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000756 */
Brian Paul178a1c52000-04-22 01:05:00 +0000757static void
758init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000759{
760 GLuint i, j;
761
Brian Paul4d053dd2000-01-14 04:45:47 +0000762 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000763
Brian Paulcd1cefa2001-06-13 14:56:14 +0000764 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
765 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
766
Brian Paul539cce52000-02-03 19:40:07 +0000767 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000768 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +0000769 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
770 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000771 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000772 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +0000773 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000774 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000775 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
776 ctx->Const.MinPointSize = MIN_POINT_SIZE;
777 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
778 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
779 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000780 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000781 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
782 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
783 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
784 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000785 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000786 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000787 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000788 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
789 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000790 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000791 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
792 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000793
Brian Paul4d053dd2000-01-14 04:45:47 +0000794 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000795 _math_matrix_ctr( &ctx->ModelView );
796 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000797
798 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000799 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000800 _math_matrix_ctr( &ctx->ModelViewStack[i] );
801 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000802 }
Brian Paul645ced22001-12-17 22:41:45 +0000803#if 0
Brian Paul86b84272001-12-14 02:50:01 +0000804 init_matrix_stack(&ctx->ModelviewStack, 32, _NEW_MODELVIEW);
805#endif
Brian Paul4d053dd2000-01-14 04:45:47 +0000806
807 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000808 _math_matrix_ctr( &ctx->ProjectionMatrix );
809 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000810
811 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000812 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000813 _math_matrix_ctr( &ctx->ProjectionStack[i] );
814 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000815 }
816
Keith Whitwell23caf202000-11-16 21:05:34 +0000817 /* Derived ModelProject matrix */
818 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
819
Brian Paul4d053dd2000-01-14 04:45:47 +0000820 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000821 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000822 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000823 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000824 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000825 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000826 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000827 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000828 }
jtgafb833d1999-08-19 00:55:39 +0000829
Brian Paul250069d2000-04-08 18:57:45 +0000830 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000831 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000832 ctx->ColorStackDepth = 0;
833 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000834 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000835 }
836
Brian Paul4d053dd2000-01-14 04:45:47 +0000837 /* Accumulate buffer group */
838 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000839
Brian Paul4d053dd2000-01-14 04:45:47 +0000840 /* Color buffer group */
841 ctx->Color.IndexMask = 0xffffffff;
842 ctx->Color.ColorMask[0] = 0xff;
843 ctx->Color.ColorMask[1] = 0xff;
844 ctx->Color.ColorMask[2] = 0xff;
845 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000846 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000847 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000848 ctx->Color.DrawBuffer = GL_FRONT;
849 ctx->Color.AlphaEnabled = GL_FALSE;
850 ctx->Color.AlphaFunc = GL_ALWAYS;
851 ctx->Color.AlphaRef = 0;
852 ctx->Color.BlendEnabled = GL_FALSE;
853 ctx->Color.BlendSrcRGB = GL_ONE;
854 ctx->Color.BlendDstRGB = GL_ZERO;
855 ctx->Color.BlendSrcA = GL_ONE;
856 ctx->Color.BlendDstA = GL_ZERO;
857 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000858 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
859 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
860 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000861 ctx->Color.LogicOp = GL_COPY;
862 ctx->Color.DitherFlag = GL_TRUE;
863 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000864
Brian Paul4d053dd2000-01-14 04:45:47 +0000865 /* Current group */
Brian Paul86b84272001-12-14 02:50:01 +0000866 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 0.0, 0.0, 0.0, 0.0 );
867 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 0.0 );
868 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
869 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 0.0 );
870 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 );
871 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
872 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_TEX0 + i], 0.0, 0.0, 0.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000873 ctx->Current.Index = 1;
Brian Paul86b84272001-12-14 02:50:01 +0000874 ctx->Current.EdgeFlag = GL_TRUE;
875
Brian Paul4d053dd2000-01-14 04:45:47 +0000876 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
877 ctx->Current.RasterDistance = 0.0;
878 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
879 ctx->Current.RasterIndex = 1;
880 for (i=0; i<MAX_TEXTURE_UNITS; i++)
881 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
882 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
883 ctx->Current.RasterPosValid = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000884
jtgafb833d1999-08-19 00:55:39 +0000885
Brian Paul4d053dd2000-01-14 04:45:47 +0000886 /* Depth buffer group */
887 ctx->Depth.Test = GL_FALSE;
888 ctx->Depth.Clear = 1.0;
889 ctx->Depth.Func = GL_LESS;
890 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000891 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000892
Brian Paul4d053dd2000-01-14 04:45:47 +0000893 /* Evaluators group */
894 ctx->Eval.Map1Color4 = GL_FALSE;
895 ctx->Eval.Map1Index = GL_FALSE;
896 ctx->Eval.Map1Normal = GL_FALSE;
897 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
898 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
899 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
900 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
901 ctx->Eval.Map1Vertex3 = GL_FALSE;
902 ctx->Eval.Map1Vertex4 = GL_FALSE;
903 ctx->Eval.Map2Color4 = GL_FALSE;
904 ctx->Eval.Map2Index = GL_FALSE;
905 ctx->Eval.Map2Normal = GL_FALSE;
906 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
907 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
908 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
909 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
910 ctx->Eval.Map2Vertex3 = GL_FALSE;
911 ctx->Eval.Map2Vertex4 = GL_FALSE;
912 ctx->Eval.AutoNormal = GL_FALSE;
913 ctx->Eval.MapGrid1un = 1;
914 ctx->Eval.MapGrid1u1 = 0.0;
915 ctx->Eval.MapGrid1u2 = 1.0;
916 ctx->Eval.MapGrid2un = 1;
917 ctx->Eval.MapGrid2vn = 1;
918 ctx->Eval.MapGrid2u1 = 0.0;
919 ctx->Eval.MapGrid2u2 = 1.0;
920 ctx->Eval.MapGrid2v1 = 0.0;
921 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000922
Brian Paul4d053dd2000-01-14 04:45:47 +0000923 /* Evaluator data */
924 {
925 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
926 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
927 static GLfloat index[1] = { 1.0 };
928 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
929 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000930
Brian Paul4d053dd2000-01-14 04:45:47 +0000931 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
932 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
933 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
934 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
935 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
936 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
937 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
938 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
939 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000940
Brian Paul4d053dd2000-01-14 04:45:47 +0000941 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
942 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
943 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
944 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
945 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
946 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
947 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
948 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
949 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
950 }
jtgafb833d1999-08-19 00:55:39 +0000951
Brian Paul4d053dd2000-01-14 04:45:47 +0000952 /* Fog group */
953 ctx->Fog.Enabled = GL_FALSE;
954 ctx->Fog.Mode = GL_EXP;
955 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
956 ctx->Fog.Index = 0.0;
957 ctx->Fog.Density = 1.0;
958 ctx->Fog.Start = 0.0;
959 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000960 ctx->Fog.ColorSumEnabled = GL_FALSE;
961 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000962
Brian Paul4d053dd2000-01-14 04:45:47 +0000963 /* Hint group */
964 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
965 ctx->Hint.PointSmooth = GL_DONT_CARE;
966 ctx->Hint.LineSmooth = GL_DONT_CARE;
967 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
968 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000969 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
970 ctx->Hint.TextureCompression = GL_DONT_CARE;
Brian Paul3893e632001-05-21 16:41:03 +0000971 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000972
Brian Paul0771d152000-04-07 00:19:41 +0000973 /* Histogram group */
974 ctx->Histogram.Width = 0;
975 ctx->Histogram.Format = GL_RGBA;
976 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000977 ctx->Histogram.RedSize = 0;
978 ctx->Histogram.GreenSize = 0;
979 ctx->Histogram.BlueSize = 0;
980 ctx->Histogram.AlphaSize = 0;
981 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000982 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
983 ctx->Histogram.Count[i][0] = 0;
984 ctx->Histogram.Count[i][1] = 0;
985 ctx->Histogram.Count[i][2] = 0;
986 ctx->Histogram.Count[i][3] = 0;
987 }
988
989 /* Min/Max group */
990 ctx->MinMax.Format = GL_RGBA;
991 ctx->MinMax.Sink = GL_FALSE;
992 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
993 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
994 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
995 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
996
Brian Paul4d053dd2000-01-14 04:45:47 +0000997 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000998 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000999
Brian Paul4d053dd2000-01-14 04:45:47 +00001000 /* Lighting group */
1001 for (i=0;i<MAX_LIGHTS;i++) {
1002 init_light( &ctx->Light.Light[i], i );
1003 }
1004 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001005
Brian Paul4d053dd2000-01-14 04:45:47 +00001006 init_lightmodel( &ctx->Light.Model );
1007 init_material( &ctx->Light.Material[0] );
1008 init_material( &ctx->Light.Material[1] );
1009 ctx->Light.ShadeModel = GL_SMOOTH;
1010 ctx->Light.Enabled = GL_FALSE;
1011 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1012 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +00001013 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
1014 GL_FRONT_AND_BACK,
1015 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001016
Brian Paul4d053dd2000-01-14 04:45:47 +00001017 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001018
Brian Paul4d053dd2000-01-14 04:45:47 +00001019 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +00001020 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1021 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001022 for (i = 0 ; i < 10 ; i++) {
1023 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1024 s->shininess = -1;
1025 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001026 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +00001027 }
Brian Paul77d61af2000-06-28 04:20:21 +00001028
jtgafb833d1999-08-19 00:55:39 +00001029
Brian Paul4d053dd2000-01-14 04:45:47 +00001030 /* Line group */
1031 ctx->Line.SmoothFlag = GL_FALSE;
1032 ctx->Line.StippleFlag = GL_FALSE;
1033 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +00001034 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001035 ctx->Line.StipplePattern = 0xffff;
1036 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001037
Brian Paul4d053dd2000-01-14 04:45:47 +00001038 /* Display List group */
1039 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001040
Brian Paul736fcbe2001-05-29 15:23:48 +00001041 /* Multisample */
1042 ctx->Multisample.Enabled = GL_FALSE;
1043 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
1044 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
1045 ctx->Multisample.SampleCoverage = GL_FALSE;
1046 ctx->Multisample.SampleCoverageValue = 1.0;
1047 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
1048
Brian Paul4d053dd2000-01-14 04:45:47 +00001049 /* Pixel group */
1050 ctx->Pixel.RedBias = 0.0;
1051 ctx->Pixel.RedScale = 1.0;
1052 ctx->Pixel.GreenBias = 0.0;
1053 ctx->Pixel.GreenScale = 1.0;
1054 ctx->Pixel.BlueBias = 0.0;
1055 ctx->Pixel.BlueScale = 1.0;
1056 ctx->Pixel.AlphaBias = 0.0;
1057 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001058 ctx->Pixel.DepthBias = 0.0;
1059 ctx->Pixel.DepthScale = 1.0;
1060 ctx->Pixel.IndexOffset = 0;
1061 ctx->Pixel.IndexShift = 0;
1062 ctx->Pixel.ZoomX = 1.0;
1063 ctx->Pixel.ZoomY = 1.0;
1064 ctx->Pixel.MapColorFlag = GL_FALSE;
1065 ctx->Pixel.MapStencilFlag = GL_FALSE;
1066 ctx->Pixel.MapStoSsize = 1;
1067 ctx->Pixel.MapItoIsize = 1;
1068 ctx->Pixel.MapItoRsize = 1;
1069 ctx->Pixel.MapItoGsize = 1;
1070 ctx->Pixel.MapItoBsize = 1;
1071 ctx->Pixel.MapItoAsize = 1;
1072 ctx->Pixel.MapRtoRsize = 1;
1073 ctx->Pixel.MapGtoGsize = 1;
1074 ctx->Pixel.MapBtoBsize = 1;
1075 ctx->Pixel.MapAtoAsize = 1;
1076 ctx->Pixel.MapStoS[0] = 0;
1077 ctx->Pixel.MapItoI[0] = 0;
1078 ctx->Pixel.MapItoR[0] = 0.0;
1079 ctx->Pixel.MapItoG[0] = 0.0;
1080 ctx->Pixel.MapItoB[0] = 0.0;
1081 ctx->Pixel.MapItoA[0] = 0.0;
1082 ctx->Pixel.MapItoR8[0] = 0;
1083 ctx->Pixel.MapItoG8[0] = 0;
1084 ctx->Pixel.MapItoB8[0] = 0;
1085 ctx->Pixel.MapItoA8[0] = 0;
1086 ctx->Pixel.MapRtoR[0] = 0.0;
1087 ctx->Pixel.MapGtoG[0] = 0.0;
1088 ctx->Pixel.MapBtoB[0] = 0.0;
1089 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001090 ctx->Pixel.HistogramEnabled = GL_FALSE;
1091 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1092 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1093 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1094 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001095 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1096 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1097 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1098 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001099 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1100 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1101 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1102 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001103 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1104 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1105 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001106 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1107 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1108 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1109 for (i = 0; i < 3; i++) {
1110 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1111 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1112 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1113 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1114 }
Brian Paul67adba12000-12-09 20:35:54 +00001115 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1116 ctx->Convolution1D.Filter[i] = 0.0;
1117 ctx->Convolution2D.Filter[i] = 0.0;
1118 ctx->Separable2D.Filter[i] = 0.0;
1119 }
Brian Paul82b02f02000-05-07 20:37:40 +00001120 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1121 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001122
Brian Paul4d053dd2000-01-14 04:45:47 +00001123 /* Point group */
1124 ctx->Point.SmoothFlag = GL_FALSE;
1125 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001126 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001127 ctx->Point.Params[0] = 1.0;
1128 ctx->Point.Params[1] = 0.0;
1129 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001130 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001131 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001132 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001134 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001135
Brian Paul4d053dd2000-01-14 04:45:47 +00001136 /* Polygon group */
1137 ctx->Polygon.CullFlag = GL_FALSE;
1138 ctx->Polygon.CullFaceMode = GL_BACK;
1139 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001140 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001141 ctx->Polygon.FrontMode = GL_FILL;
1142 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001143 ctx->Polygon.SmoothFlag = GL_FALSE;
1144 ctx->Polygon.StippleFlag = GL_FALSE;
1145 ctx->Polygon.OffsetFactor = 0.0F;
1146 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001147 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001148 ctx->Polygon.OffsetPoint = GL_FALSE;
1149 ctx->Polygon.OffsetLine = GL_FALSE;
1150 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001151
Brian Paul4d053dd2000-01-14 04:45:47 +00001152 /* Polygon Stipple group */
1153 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001154
Brian Paul4d053dd2000-01-14 04:45:47 +00001155 /* Scissor group */
1156 ctx->Scissor.Enabled = GL_FALSE;
1157 ctx->Scissor.X = 0;
1158 ctx->Scissor.Y = 0;
1159 ctx->Scissor.Width = 0;
1160 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001161
Brian Paul4d053dd2000-01-14 04:45:47 +00001162 /* Stencil group */
1163 ctx->Stencil.Enabled = GL_FALSE;
1164 ctx->Stencil.Function = GL_ALWAYS;
1165 ctx->Stencil.FailFunc = GL_KEEP;
1166 ctx->Stencil.ZPassFunc = GL_KEEP;
1167 ctx->Stencil.ZFailFunc = GL_KEEP;
1168 ctx->Stencil.Ref = 0;
1169 ctx->Stencil.ValueMask = STENCIL_MAX;
1170 ctx->Stencil.Clear = 0;
1171 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001172
Brian Paul4d053dd2000-01-14 04:45:47 +00001173 /* Texture group */
1174 ctx->Texture.CurrentUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001175 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001176 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1177 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001178 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001179 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001180
Brian Paul4d053dd2000-01-14 04:45:47 +00001181 /* Transformation group */
1182 ctx->Transform.MatrixMode = GL_MODELVIEW;
1183 ctx->Transform.Normalize = GL_FALSE;
1184 ctx->Transform.RescaleNormals = GL_FALSE;
Brian Paul8c2f6c52001-06-26 01:32:48 +00001185 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001186 for (i=0;i<MAX_CLIP_PLANES;i++) {
1187 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1188 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1189 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001190 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001191
Brian Paul4d053dd2000-01-14 04:45:47 +00001192 /* Viewport group */
1193 ctx->Viewport.X = 0;
1194 ctx->Viewport.Y = 0;
1195 ctx->Viewport.Width = 0;
1196 ctx->Viewport.Height = 0;
1197 ctx->Viewport.Near = 0.0;
1198 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001199 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001200
1201#define Sz 10
1202#define Tz 14
Brian Paulfde5e2c2001-09-15 18:02:49 +00001203 ctx->Viewport._WindowMap.m[Sz] = 0.5F * ctx->DepthMaxF;
1204 ctx->Viewport._WindowMap.m[Tz] = 0.5F * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001205#undef Sz
1206#undef Tz
1207
Keith Whitwell14940c42000-11-05 18:40:57 +00001208 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1209 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001210
Brian Paul4d053dd2000-01-14 04:45:47 +00001211 /* Vertex arrays */
1212 ctx->Array.Vertex.Size = 4;
1213 ctx->Array.Vertex.Type = GL_FLOAT;
1214 ctx->Array.Vertex.Stride = 0;
1215 ctx->Array.Vertex.StrideB = 0;
1216 ctx->Array.Vertex.Ptr = NULL;
1217 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001218 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001219 ctx->Array.Normal.Type = GL_FLOAT;
1220 ctx->Array.Normal.Stride = 0;
1221 ctx->Array.Normal.StrideB = 0;
1222 ctx->Array.Normal.Ptr = NULL;
1223 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001224 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001225 ctx->Array.Color.Size = 4;
1226 ctx->Array.Color.Type = GL_FLOAT;
1227 ctx->Array.Color.Stride = 0;
1228 ctx->Array.Color.StrideB = 0;
1229 ctx->Array.Color.Ptr = NULL;
1230 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001231 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1232 ctx->Array.SecondaryColor.Size = 4;
1233 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1234 ctx->Array.SecondaryColor.Stride = 0;
1235 ctx->Array.SecondaryColor.StrideB = 0;
1236 ctx->Array.SecondaryColor.Ptr = NULL;
1237 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1238 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1239 ctx->Array.FogCoord.Size = 1;
1240 ctx->Array.FogCoord.Type = GL_FLOAT;
1241 ctx->Array.FogCoord.Stride = 0;
1242 ctx->Array.FogCoord.StrideB = 0;
1243 ctx->Array.FogCoord.Ptr = NULL;
1244 ctx->Array.FogCoord.Enabled = GL_FALSE;
1245 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001246 ctx->Array.Index.Type = GL_FLOAT;
1247 ctx->Array.Index.Stride = 0;
1248 ctx->Array.Index.StrideB = 0;
1249 ctx->Array.Index.Ptr = NULL;
1250 ctx->Array.Index.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001251 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001252 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1253 ctx->Array.TexCoord[i].Size = 4;
1254 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1255 ctx->Array.TexCoord[i].Stride = 0;
1256 ctx->Array.TexCoord[i].StrideB = 0;
1257 ctx->Array.TexCoord[i].Ptr = NULL;
1258 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001259 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001260 }
1261 ctx->Array.TexCoordInterleaveFactor = 1;
1262 ctx->Array.EdgeFlag.Stride = 0;
1263 ctx->Array.EdgeFlag.StrideB = 0;
1264 ctx->Array.EdgeFlag.Ptr = NULL;
1265 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001266 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001267 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1268
1269 /* Pixel transfer */
1270 ctx->Pack.Alignment = 4;
1271 ctx->Pack.RowLength = 0;
1272 ctx->Pack.ImageHeight = 0;
1273 ctx->Pack.SkipPixels = 0;
1274 ctx->Pack.SkipRows = 0;
1275 ctx->Pack.SkipImages = 0;
1276 ctx->Pack.SwapBytes = GL_FALSE;
1277 ctx->Pack.LsbFirst = GL_FALSE;
1278 ctx->Unpack.Alignment = 4;
1279 ctx->Unpack.RowLength = 0;
1280 ctx->Unpack.ImageHeight = 0;
1281 ctx->Unpack.SkipPixels = 0;
1282 ctx->Unpack.SkipRows = 0;
1283 ctx->Unpack.SkipImages = 0;
1284 ctx->Unpack.SwapBytes = GL_FALSE;
1285 ctx->Unpack.LsbFirst = GL_FALSE;
1286
1287 /* Feedback */
1288 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1289 ctx->Feedback.Buffer = NULL;
1290 ctx->Feedback.BufferSize = 0;
1291 ctx->Feedback.Count = 0;
1292
1293 /* Selection/picking */
1294 ctx->Select.Buffer = NULL;
1295 ctx->Select.BufferSize = 0;
1296 ctx->Select.BufferCount = 0;
1297 ctx->Select.Hits = 0;
1298 ctx->Select.NameStackDepth = 0;
1299
Brian Paul4d053dd2000-01-14 04:45:47 +00001300 /* Renderer and client attribute stacks */
1301 ctx->AttribStackDepth = 0;
1302 ctx->ClientAttribStackDepth = 0;
1303
Brian Paul13811372000-04-12 00:27:37 +00001304 /* Display list */
1305 ctx->CallDepth = 0;
1306 ctx->ExecuteFlag = GL_TRUE;
1307 ctx->CompileFlag = GL_FALSE;
1308 ctx->CurrentListPtr = NULL;
1309 ctx->CurrentBlock = NULL;
1310 ctx->CurrentListNum = 0;
1311 ctx->CurrentPos = 0;
1312
1313 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001314 _mesa_init_colortable(&ctx->ColorTable);
1315 _mesa_init_colortable(&ctx->ProxyColorTable);
1316 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1317 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1318 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1319 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001320
Brian Paul86b84272001-12-14 02:50:01 +00001321 /* GL_NV_vertex_program */
1322 ctx->VertexProgram.Binding = 0;
1323 ctx->VertexProgram.HashTable = _mesa_NewHashTable();
1324 ctx->VertexProgram.Enabled = GL_FALSE;
1325 ctx->VertexProgram.PointSizeEnabled = GL_FALSE;
1326 ctx->VertexProgram.TwoSideEnabled = GL_FALSE;
1327 for (i = 0; i < VP_NUM_PROG_REGS / 4; i++) {
1328 ctx->VertexProgram.TrackMatrix[i] = GL_NONE;
1329 ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV;
1330 }
1331
Brian Paul4d053dd2000-01-14 04:45:47 +00001332 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001333 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001334 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001335 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001336
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001337 ctx->_NeedNormals = 0;
1338 ctx->_NeedEyeCoords = 0;
1339 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001340
Brian Paul4d053dd2000-01-14 04:45:47 +00001341 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1342
1343 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001344 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001345 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001346
1347 /* For debug/development only */
1348 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1349 ctx->FirstTimeCurrent = GL_TRUE;
1350
1351 /* Dither disable */
1352 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1353 if (ctx->NoDither) {
1354 if (getenv("MESA_DEBUG")) {
1355 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001356 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001357 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001358 }
1359}
1360
1361
1362
1363
jtgafb833d1999-08-19 00:55:39 +00001364/*
1365 * Allocate the proxy textures. If we run out of memory part way through
1366 * the allocations clean up and return GL_FALSE.
1367 * Return: GL_TRUE=success, GL_FALSE=failure
1368 */
Brian Paul178a1c52000-04-22 01:05:00 +00001369static GLboolean
1370alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001371{
1372 GLboolean out_of_memory;
1373 GLint i;
1374
Brian Paula8523782000-11-19 23:10:25 +00001375 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001376 if (!ctx->Texture.Proxy1D) {
1377 return GL_FALSE;
1378 }
1379
Brian Paula8523782000-11-19 23:10:25 +00001380 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001381 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001382 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001383 return GL_FALSE;
1384 }
1385
Brian Paula8523782000-11-19 23:10:25 +00001386 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001387 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001388 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1389 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1390 return GL_FALSE;
1391 }
1392
1393 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1394 if (!ctx->Texture.ProxyCubeMap) {
1395 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1396 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1397 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001398 return GL_FALSE;
1399 }
1400
1401 out_of_memory = GL_FALSE;
1402 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001403 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1404 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1405 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
Brian Paul172281d2001-07-26 20:02:10 +00001406 ctx->Texture.ProxyCubeMap->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001407 if (!ctx->Texture.Proxy1D->Image[i]
1408 || !ctx->Texture.Proxy2D->Image[i]
Brian Paul172281d2001-07-26 20:02:10 +00001409 || !ctx->Texture.Proxy3D->Image[i]
1410 || !ctx->Texture.ProxyCubeMap->Image[i]) {
jtgafb833d1999-08-19 00:55:39 +00001411 out_of_memory = GL_TRUE;
1412 }
1413 }
1414 if (out_of_memory) {
1415 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1416 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001417 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001418 }
1419 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001420 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001421 }
1422 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001423 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001424 }
Brian Paul172281d2001-07-26 20:02:10 +00001425 if (ctx->Texture.ProxyCubeMap->Image[i]) {
1426 _mesa_free_texture_image(ctx->Texture.ProxyCubeMap->Image[i]);
1427 }
jtgafb833d1999-08-19 00:55:39 +00001428 }
Brian Paula8523782000-11-19 23:10:25 +00001429 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1430 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1431 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
Brian Paul172281d2001-07-26 20:02:10 +00001432 _mesa_free_texture_object(NULL, ctx->Texture.ProxyCubeMap);
jtgafb833d1999-08-19 00:55:39 +00001433 return GL_FALSE;
1434 }
1435 else {
1436 return GL_TRUE;
1437 }
1438}
1439
1440
jtgafb833d1999-08-19 00:55:39 +00001441/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001442 * Initialize a GLcontext struct. This includes allocating all the
1443 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001444 */
Brian Paul178a1c52000-04-22 01:05:00 +00001445GLboolean
1446_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001447 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001448 GLcontext *share_list,
1449 void *driver_ctx,
1450 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001451{
Brian Paul5fb84d22000-05-24 15:04:45 +00001452 GLuint dispatchSize;
1453
jtgafb833d1999-08-19 00:55:39 +00001454 (void) direct; /* not used */
1455
jtgafb833d1999-08-19 00:55:39 +00001456 /* misc one-time initializations */
1457 one_time_init();
1458
Brian Paulb1394fa2000-09-26 20:53:53 +00001459 /**
1460 ** OpenGL SI stuff
1461 **/
1462 if (!ctx->imports.malloc) {
1463 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1464 }
1465 /* exports are setup by the device driver */
1466
jtgafb833d1999-08-19 00:55:39 +00001467 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001468 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001469 ctx->DrawBuffer = NULL;
1470 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001471
jtgafb833d1999-08-19 00:55:39 +00001472 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001473 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001474 ctx->Shared = share_list->Shared;
1475 }
1476 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001477 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001478 ctx->Shared = alloc_shared_state();
1479 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001480 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001481 }
1482 }
Brian Paul9560f052000-01-31 23:11:39 +00001483 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001484 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001485 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001486
Brian Paul5a2f32b2001-04-25 18:21:05 +00001487 /* Effectively bind the default textures to all texture units */
1488 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1489 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1490 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1491 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1492
Brian Paul4d053dd2000-01-14 04:45:47 +00001493 init_attrib_groups( ctx );
1494
Brian Paulb6bcae52001-01-23 23:39:36 +00001495 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001496 ctx->Color.DrawBuffer = GL_BACK;
1497 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1498 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1499 ctx->Pixel.ReadBuffer = GL_BACK;
1500 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1501 }
1502 else {
1503 ctx->Color.DrawBuffer = GL_FRONT;
1504 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1505 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1506 ctx->Pixel.ReadBuffer = GL_FRONT;
1507 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1508 }
1509
jtgafb833d1999-08-19 00:55:39 +00001510 if (!alloc_proxy_textures(ctx)) {
1511 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001512 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001513 }
jtgafb833d1999-08-19 00:55:39 +00001514
Brian Paulf59afc92000-05-23 23:23:00 +00001515 /* register the most recent extension functions with libGL */
1516 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1517 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1518 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1519 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1520 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1521 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1522 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1523 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1524
Brian Paul5fb84d22000-05-24 15:04:45 +00001525 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1526 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1527 * Mesa we do this to accomodate different versions of libGL and various
1528 * DRI drivers.
1529 */
1530 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1531 sizeof(struct _glapi_table) / sizeof(void *));
1532
Brian Paulfbd8f211999-11-11 01:22:25 +00001533 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001534 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1535 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001536 if (!ctx->Exec || !ctx->Save) {
1537 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001538 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001539 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001540 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001541 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1542 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001543 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001544
Keith Whitwellad2ac212000-11-24 10:25:05 +00001545 ctx->ExecPrefersFloat = GL_FALSE;
1546 ctx->SavePrefersFloat = GL_FALSE;
1547
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001548 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001549 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001550 ctx->TnlModule.Current = NULL;
1551 ctx->TnlModule.SwapCount = 0;
1552
Brian Paulb6bcae52001-01-23 23:39:36 +00001553 /* Z buffer stuff */
1554 if (ctx->Visual.depthBits == 0) {
1555 /* Special case. Even if we don't have a depth buffer we need
1556 * good values for DepthMax for Z vertex transformation purposes
1557 * and for per-fragment fog computation.
1558 */
1559 ctx->DepthMax = 1 << 16;
1560 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1561 }
1562 else if (ctx->Visual.depthBits < 32) {
1563 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1564 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1565 }
1566 else {
1567 /* Special case since shift values greater than or equal to the
1568 * number of bits in the left hand expression's type are undefined.
1569 */
1570 ctx->DepthMax = 0xffffffff;
1571 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1572 }
Brian Paulbc920f02001-05-07 16:32:51 +00001573 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001574
1575
Brian Paul3b18a362000-09-26 15:27:20 +00001576#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001577 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001578#if 0
1579 /* Brian: do you want to have CreateContext fail here,
1580 or should we just trap in NewTrace (currently done)? */
1581 if (!(ctx->TraceCtx)) {
1582 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001583 FREE( ctx->Exec );
1584 FREE( ctx->Save );
1585 return GL_FALSE;
1586 }
1587#endif
1588 trInitContext(ctx->TraceCtx);
1589
1590 ctx->TraceDispatch = (struct _glapi_table *)
1591 CALLOC(dispatchSize * sizeof(void*));
1592#if 0
1593 if (!(ctx->TraceCtx)) {
1594 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001595 FREE( ctx->Exec );
1596 FREE( ctx->Save );
1597 FREE( ctx->TraceCtx );
1598 return GL_FALSE;
1599 }
1600#endif
1601 trInitDispatch(ctx->TraceDispatch);
1602#endif
1603
Brian Paul4d053dd2000-01-14 04:45:47 +00001604 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001605}
1606
jtgafb833d1999-08-19 00:55:39 +00001607
1608
1609/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001610 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001611 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001612 * sharelist - another context to share display lists with or NULL
1613 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001614 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001615 */
Brian Paul178a1c52000-04-22 01:05:00 +00001616GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001617_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001618 GLcontext *share_list,
1619 void *driver_ctx,
1620 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001621{
1622 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1623 if (!ctx) {
1624 return NULL;
1625 }
Jouk Jansen12e875c2001-10-18 08:04:57 +00001626 ctx->Driver.CurrentExecPrimitive = 0;
Brian Paul178a1c52000-04-22 01:05:00 +00001627 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001628 return ctx;
1629 }
1630 else {
1631 FREE(ctx);
1632 return NULL;
1633 }
1634}
1635
1636
1637
1638/*
1639 * Free the data associated with the given context.
1640 * But don't free() the GLcontext struct itself!
1641 */
Brian Paul178a1c52000-04-22 01:05:00 +00001642void
Brian Paulb1394fa2000-09-26 20:53:53 +00001643_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001644{
Brian Paul4d053dd2000-01-14 04:45:47 +00001645 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001646 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001647
1648 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001649 if (ctx == _mesa_get_current_context()) {
1650 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001651 }
1652
Brian Paul645ced22001-12-17 22:41:45 +00001653#if 0
Brian Paul86b84272001-12-14 02:50:01 +00001654 free_matrix_stack(&ctx->ModelviewStack);
1655#endif
1656
Keith Whitwell23caf202000-11-16 21:05:34 +00001657 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001658 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001659 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001660 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001661 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001662 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001663 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001664 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001665 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001666 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001667 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001668 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001669 }
1670 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001671
Brian Paulfd284452001-07-19 15:54:34 +00001672 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
1673
1674 _math_matrix_dtr(&ctx->ColorMatrix);
1675 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
1676 _math_matrix_dtr(&ctx->ColorStack[j]);
1677 }
1678
Brian Paul9560f052000-01-31 23:11:39 +00001679 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001680 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001681 assert(ctx->Shared->RefCount >= 0);
1682 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1683 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001684 /* free shared state */
1685 free_shared_state( ctx, ctx->Shared );
1686 }
1687
Keith Whitwell14940c42000-11-05 18:40:57 +00001688 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001689 FREE( s );
1690 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001691 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001692
1693 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001694 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1695 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1696 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paulfd284452001-07-19 15:54:34 +00001697 _mesa_free_texture_object( NULL, ctx->Texture.ProxyCubeMap );
Brian Paul4d053dd2000-01-14 04:45:47 +00001698
1699 /* Free evaluator data */
1700 if (ctx->EvalMap.Map1Vertex3.Points)
1701 FREE( ctx->EvalMap.Map1Vertex3.Points );
1702 if (ctx->EvalMap.Map1Vertex4.Points)
1703 FREE( ctx->EvalMap.Map1Vertex4.Points );
1704 if (ctx->EvalMap.Map1Index.Points)
1705 FREE( ctx->EvalMap.Map1Index.Points );
1706 if (ctx->EvalMap.Map1Color4.Points)
1707 FREE( ctx->EvalMap.Map1Color4.Points );
1708 if (ctx->EvalMap.Map1Normal.Points)
1709 FREE( ctx->EvalMap.Map1Normal.Points );
1710 if (ctx->EvalMap.Map1Texture1.Points)
1711 FREE( ctx->EvalMap.Map1Texture1.Points );
1712 if (ctx->EvalMap.Map1Texture2.Points)
1713 FREE( ctx->EvalMap.Map1Texture2.Points );
1714 if (ctx->EvalMap.Map1Texture3.Points)
1715 FREE( ctx->EvalMap.Map1Texture3.Points );
1716 if (ctx->EvalMap.Map1Texture4.Points)
1717 FREE( ctx->EvalMap.Map1Texture4.Points );
1718
1719 if (ctx->EvalMap.Map2Vertex3.Points)
1720 FREE( ctx->EvalMap.Map2Vertex3.Points );
1721 if (ctx->EvalMap.Map2Vertex4.Points)
1722 FREE( ctx->EvalMap.Map2Vertex4.Points );
1723 if (ctx->EvalMap.Map2Index.Points)
1724 FREE( ctx->EvalMap.Map2Index.Points );
1725 if (ctx->EvalMap.Map2Color4.Points)
1726 FREE( ctx->EvalMap.Map2Color4.Points );
1727 if (ctx->EvalMap.Map2Normal.Points)
1728 FREE( ctx->EvalMap.Map2Normal.Points );
1729 if (ctx->EvalMap.Map2Texture1.Points)
1730 FREE( ctx->EvalMap.Map2Texture1.Points );
1731 if (ctx->EvalMap.Map2Texture2.Points)
1732 FREE( ctx->EvalMap.Map2Texture2.Points );
1733 if (ctx->EvalMap.Map2Texture3.Points)
1734 FREE( ctx->EvalMap.Map2Texture3.Points );
1735 if (ctx->EvalMap.Map2Texture4.Points)
1736 FREE( ctx->EvalMap.Map2Texture4.Points );
1737
Brian Paul4bdcfe52000-04-17 17:57:04 +00001738 _mesa_free_colortable_data( &ctx->ColorTable );
1739 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1740 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1741 _mesa_free_colortable_data( &ctx->Texture.Palette );
1742
Brian Paulfd284452001-07-19 15:54:34 +00001743 _math_matrix_dtr(&ctx->Viewport._WindowMap);
1744
Brian Paul69755402001-02-26 23:58:12 +00001745 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001746
Brian Paul86b84272001-12-14 02:50:01 +00001747 /* GL_NV_vertex_program */
1748 _mesa_DeleteHashTable(ctx->VertexProgram.HashTable);
1749
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001750 FREE(ctx->Exec);
1751 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001752}
1753
1754
1755
1756/*
1757 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001758 */
Brian Paul178a1c52000-04-22 01:05:00 +00001759void
Brian Paulb1394fa2000-09-26 20:53:53 +00001760_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001761{
1762 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001763 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001764 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001765 }
1766}
1767
1768
1769
1770/*
jtgafb833d1999-08-19 00:55:39 +00001771 * Copy attribute groups from one context to another.
1772 * Input: src - source context
1773 * dst - destination context
1774 * mask - bitwise OR of GL_*_BIT flags
1775 */
Brian Paul178a1c52000-04-22 01:05:00 +00001776void
Brian Paulb1394fa2000-09-26 20:53:53 +00001777_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001778{
1779 if (mask & GL_ACCUM_BUFFER_BIT) {
1780 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1781 }
1782 if (mask & GL_COLOR_BUFFER_BIT) {
1783 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1784 }
1785 if (mask & GL_CURRENT_BIT) {
1786 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1787 }
1788 if (mask & GL_DEPTH_BUFFER_BIT) {
1789 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1790 }
1791 if (mask & GL_ENABLE_BIT) {
1792 /* no op */
1793 }
1794 if (mask & GL_EVAL_BIT) {
1795 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1796 }
1797 if (mask & GL_FOG_BIT) {
1798 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1799 }
1800 if (mask & GL_HINT_BIT) {
1801 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1802 }
1803 if (mask & GL_LIGHTING_BIT) {
1804 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001805 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001806 }
1807 if (mask & GL_LINE_BIT) {
1808 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1809 }
1810 if (mask & GL_LIST_BIT) {
1811 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1812 }
1813 if (mask & GL_PIXEL_MODE_BIT) {
1814 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1815 }
1816 if (mask & GL_POINT_BIT) {
1817 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1818 }
1819 if (mask & GL_POLYGON_BIT) {
1820 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1821 }
1822 if (mask & GL_POLYGON_STIPPLE_BIT) {
1823 /* Use loop instead of MEMCPY due to problem with Portland Group's
1824 * C compiler. Reported by John Stone.
1825 */
1826 int i;
1827 for (i=0;i<32;i++) {
1828 dst->PolygonStipple[i] = src->PolygonStipple[i];
1829 }
1830 }
1831 if (mask & GL_SCISSOR_BIT) {
1832 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1833 }
1834 if (mask & GL_STENCIL_BUFFER_BIT) {
1835 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1836 }
1837 if (mask & GL_TEXTURE_BIT) {
1838 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1839 }
1840 if (mask & GL_TRANSFORM_BIT) {
1841 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1842 }
1843 if (mask & GL_VIEWPORT_BIT) {
1844 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1845 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001846 /* XXX FIXME: Call callbacks?
1847 */
1848 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001849}
1850
1851
jtgafb833d1999-08-19 00:55:39 +00001852/*
Brian Paul00037781999-12-17 14:52:35 +00001853 * Set the current context, binding the given frame buffer to the context.
1854 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001855void
1856_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001857{
Brian Paulb1394fa2000-09-26 20:53:53 +00001858 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001859}
1860
1861
Keith Whitwell23caf202000-11-16 21:05:34 +00001862static void print_info( void )
1863{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001864 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001865 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001866 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001867 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001868 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001869 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001870 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001871 (char *) _mesa_GetString(GL_EXTENSIONS));
1872#if defined(THREADS)
1873 fprintf(stderr, "Mesa thread-safe: YES\n");
1874#else
1875 fprintf(stderr, "Mesa thread-safe: NO\n");
1876#endif
1877#if defined(USE_X86_ASM)
1878 fprintf(stderr, "Mesa x86-optimized: YES\n");
1879#else
1880 fprintf(stderr, "Mesa x86-optimized: NO\n");
1881#endif
davem69e4f84b42001-06-05 03:58:20 +00001882#if defined(USE_SPARC_ASM)
1883 fprintf(stderr, "Mesa sparc-optimized: YES\n");
1884#else
1885 fprintf(stderr, "Mesa sparc-optimized: NO\n");
1886#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001887}
1888
1889
Brian Paul00037781999-12-17 14:52:35 +00001890/*
1891 * Bind the given context to the given draw-buffer and read-buffer
1892 * and make it the current context for this thread.
1893 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001894void
1895_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1896 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001897{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001898 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001899 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001900
Brian Paulbe3602d2001-02-28 00:27:48 +00001901 /* Check that the context's and framebuffer's visuals are compatible.
1902 * We could do a lot more checking here but this'll catch obvious
1903 * problems.
1904 */
1905 if (newCtx && drawBuffer && readBuffer) {
1906 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1907 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1908 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1909 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1910 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1911 return; /* incompatible */
1912 }
1913 }
1914
Brian Paul00037781999-12-17 14:52:35 +00001915 /* We call this function periodically (just here for now) in
1916 * order to detect when multithreading has begun.
1917 */
1918 _glapi_check_multithread();
1919
Brian Paulf9b97d92000-01-28 20:17:42 +00001920 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001921 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001922
1923
1924 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001925 _glapi_set_dispatch(NULL); /* none current */
1926 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001927 else {
1928 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001929
Keith Whitwell23caf202000-11-16 21:05:34 +00001930 if (drawBuffer && readBuffer) {
1931 /* TODO: check if newCtx and buffer's visual match??? */
1932 newCtx->DrawBuffer = drawBuffer;
1933 newCtx->ReadBuffer = readBuffer;
1934 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001935 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001936 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001937
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001938 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001939 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1940
1941 /* We can use this to help debug user's problems. Tell them to set
1942 * the MESA_INFO env variable before running their app. Then the
1943 * first time each context is made current we'll print some useful
1944 * information.
1945 */
1946 if (newCtx->FirstTimeCurrent) {
1947 if (getenv("MESA_INFO")) {
1948 print_info();
1949 }
1950 newCtx->FirstTimeCurrent = GL_FALSE;
1951 }
Brian Paul00037781999-12-17 14:52:35 +00001952 }
1953}
1954
1955
1956
1957/*
1958 * Return current context handle for the calling thread.
1959 * This isn't the fastest way to get the current context.
1960 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1961 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001962GLcontext *
1963_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001964{
Brian Paulf9b97d92000-01-28 20:17:42 +00001965 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001966}
1967
1968
1969
1970/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001971 * This should be called by device drivers just before they do a
1972 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001973 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001974void
1975_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001976{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001977 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001978}
1979
1980
Brian Paul00037781999-12-17 14:52:35 +00001981
Brian Paulfbd8f211999-11-11 01:22:25 +00001982/*
1983 * Return pointer to this context's current API dispatch table.
1984 * It'll either be the immediate-mode execute dispatcher or the
1985 * display list compile dispatcher.
1986 */
1987struct _glapi_table *
1988_mesa_get_dispatch(GLcontext *ctx)
1989{
1990 return ctx->CurrentDispatch;
1991}
1992
1993
1994
jtgafb833d1999-08-19 00:55:39 +00001995/**********************************************************************/
1996/***** Miscellaneous functions *****/
1997/**********************************************************************/
1998
1999
2000/*
2001 * This function is called when the Mesa user has stumbled into a code
2002 * path which may not be implemented fully or correctly.
2003 */
Brian Paul08836342001-03-03 20:33:27 +00002004void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00002005{
2006 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00002007#ifdef XF86DRI
2008 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
2009#else
2010 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
2011#endif
jtgafb833d1999-08-19 00:55:39 +00002012 (void) ctx;
2013}
2014
2015
2016
2017/*
2018 * This is called to inform the user that he or she has tried to do
2019 * something illogical or if there's likely a bug in their program
2020 * (like enabled depth testing without a depth buffer).
2021 */
Brian Paulb1394fa2000-09-26 20:53:53 +00002022void
2023_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00002024{
Brian Paulb1394fa2000-09-26 20:53:53 +00002025 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00002026}
2027
2028
2029
Brian Paulfa9df402000-02-02 19:16:46 +00002030/*
jtgafb833d1999-08-19 00:55:39 +00002031 * This is Mesa's error handler. Normally, all that's done is the updating
2032 * of the current error value. If Mesa is compiled with -DDEBUG or if the
2033 * environment variable "MESA_DEBUG" is defined then a real error message
2034 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00002035 * Input: ctx - the GL context
2036 * error - the error value
2037 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00002038 */
Brian Paul7eb06032000-07-14 04:13:40 +00002039void
Brian Paul08836342001-03-03 20:33:27 +00002040_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00002041{
Brian Paul7eb06032000-07-14 04:13:40 +00002042 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00002043 GLboolean debug;
2044
2045#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002046 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002047 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002048 else
2049 debug = GL_TRUE;
2050#else
2051 if (debugEnv)
2052 debug = GL_TRUE;
2053 else
2054 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002055#endif
2056
2057 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002058 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002059 switch (error) {
2060 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002061 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002062 break;
2063 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002064 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002065 break;
2066 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002067 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002068 break;
2069 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002070 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002071 break;
2072 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002073 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002074 break;
2075 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002076 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002077 break;
2078 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002079 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002080 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002081 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002082 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002083 break;
jtgafb833d1999-08-19 00:55:39 +00002084 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002085 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002086 break;
2087 }
Brian Paul7eb06032000-07-14 04:13:40 +00002088 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002089 }
2090
Brian Paul7eb06032000-07-14 04:13:40 +00002091 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002092 ctx->ErrorValue = error;
2093 }
2094
2095 /* Call device driver's error handler, if any. This is used on the Mac. */
2096 if (ctx->Driver.Error) {
2097 (*ctx->Driver.Error)( ctx );
2098 }
2099}
2100
2101
2102
Brian Paulfa9df402000-02-02 19:16:46 +00002103void
2104_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002105{
Brian Paulfa9df402000-02-02 19:16:46 +00002106 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002107 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002108 if (ctx->Driver.Finish) {
2109 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002110 }
2111}
2112
2113
2114
Brian Paulfa9df402000-02-02 19:16:46 +00002115void
2116_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002117{
Brian Paulfa9df402000-02-02 19:16:46 +00002118 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002119 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002120 if (ctx->Driver.Flush) {
2121 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002122 }
jtgafb833d1999-08-19 00:55:39 +00002123}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002124
2125
2126
Keith Whitwellcab974c2000-12-26 05:09:27 +00002127const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002128 "GL_POINTS",
2129 "GL_LINES",
2130 "GL_LINE_LOOP",
2131 "GL_LINE_STRIP",
2132 "GL_TRIANGLES",
2133 "GL_TRIANGLE_STRIP",
2134 "GL_TRIANGLE_FAN",
2135 "GL_QUADS",
2136 "GL_QUAD_STRIP",
2137 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002138 "outside begin/end",
2139 "inside unkown primitive",
2140 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002141};