blob: 969b320a440244a3bfd91d4bfc787558a4660f60 [file] [log] [blame]
Keith Whitwell0a79baf2002-04-09 14:58:03 +00001/* $Id: context.c,v 1.159 2002/04/09 14:58:03 keithw Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul86b84272001-12-14 02:50:01 +00005 * Version: 4.1
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paulbc42c192002-01-05 21:53:20 +00007 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000032#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000034#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000035#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "dlist.h"
37#include "eval.h"
38#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000039#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000041#include "get.h"
Brian Paul9560f052000-01-31 23:11:39 +000042#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000044#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000045#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000046#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000047#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "mmath.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +000050#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000051#include "teximage.h"
52#include "texobj.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000053#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "varray.h"
Brian Paul30f51ae2001-12-18 04:06:44 +000055#include "vpstate.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +000056#include "vtxfmt.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000057#include "math/m_translate.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000058#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) {
Brian Paulaeb44342002-03-19 16:47:04 +0000400 MESA_PBUFFER_FREE( buffer->DepthBuffer );
Brian Paul75978bd2001-04-27 21:17:20 +0000401 buffer->DepthBuffer = NULL;
402 }
403 if (buffer->Accum) {
Brian Paulaeb44342002-03-19 16:47:04 +0000404 MESA_PBUFFER_FREE( buffer->Accum );
Brian Paul75978bd2001-04-27 21:17:20 +0000405 buffer->Accum = NULL;
406 }
407 if (buffer->Stencil) {
Brian Paulaeb44342002-03-19 16:47:04 +0000408 MESA_PBUFFER_FREE( buffer->Stencil );
Brian Paul75978bd2001-04-27 21:17:20 +0000409 buffer->Stencil = NULL;
410 }
411 if (buffer->FrontLeftAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000412 MESA_PBUFFER_FREE( buffer->FrontLeftAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000413 buffer->FrontLeftAlpha = NULL;
414 }
415 if (buffer->BackLeftAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000416 MESA_PBUFFER_FREE( buffer->BackLeftAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000417 buffer->BackLeftAlpha = NULL;
418 }
419 if (buffer->FrontRightAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000420 MESA_PBUFFER_FREE( buffer->FrontRightAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000421 buffer->FrontRightAlpha = NULL;
422 }
423 if (buffer->BackRightAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000424 MESA_PBUFFER_FREE( buffer->BackRightAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000425 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;
Brian Paul86b84272001-12-14 02:50:01 +0000490 /* The stack */
Brian Paul30f51ae2001-12-18 04:06:44 +0000491 stack->Stack = CALLOC(maxDepth * sizeof(GLmatrix));
Brian Paul86b84272001-12-14 02:50:01 +0000492 for (i = 0; i < maxDepth; i++) {
493 _math_matrix_ctr(&stack->Stack[i]);
494 _math_matrix_alloc_inv(&stack->Stack[i]);
495 }
Brian Paul30f51ae2001-12-18 04:06:44 +0000496 stack->Top = stack->Stack;
Brian Paul86b84272001-12-14 02:50:01 +0000497}
498
499
500static void
501free_matrix_stack( struct matrix_stack *stack )
502{
503 GLuint i;
Brian Paul86b84272001-12-14 02:50:01 +0000504 for (i = 0; i < stack->MaxDepth; i++) {
505 _math_matrix_dtr(&stack->Stack[i]);
506 }
Brian Paulc4afba32002-02-05 23:21:45 +0000507 FREE(stack->Stack);
Brian Paul30f51ae2001-12-18 04:06:44 +0000508 stack->Stack = stack->Top = NULL;
Brian Paul86b84272001-12-14 02:50:01 +0000509}
510
Brian Paul4d053dd2000-01-14 04:45:47 +0000511
jtgafb833d1999-08-19 00:55:39 +0000512/*
513 * Allocate and initialize a shared context state structure.
514 */
Brian Paul178a1c52000-04-22 01:05:00 +0000515static struct gl_shared_state *
516alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000517{
jtgafb833d1999-08-19 00:55:39 +0000518 struct gl_shared_state *ss;
519 GLboolean outOfMemory;
520
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000521 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000522 if (!ss)
523 return NULL;
524
Brian Paule4b684c2000-09-12 21:07:40 +0000525 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000526
Brian Paule4b684c2000-09-12 21:07:40 +0000527 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000528 ss->TexObjects = _mesa_NewHashTable();
Brian Paul30f51ae2001-12-18 04:06:44 +0000529 ss->VertexPrograms = _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
Brian Paul30f51ae2001-12-18 04:06:44 +0000554 if (!ss->DisplayList || !ss->TexObjects || !ss->VertexPrograms
555 || outOfMemory) {
jtgafb833d1999-08-19 00:55:39 +0000556 /* Ran out of memory at some point. Free everything and return NULL */
557 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000558 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000559 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000560 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul30f51ae2001-12-18 04:06:44 +0000561 if (ss->VertexPrograms)
562 _mesa_DeleteHashTable(ss->VertexPrograms);
Brian Paula8523782000-11-19 23:10:25 +0000563 if (ss->Default1D)
564 _mesa_free_texture_object(ss, ss->Default1D);
565 if (ss->Default2D)
566 _mesa_free_texture_object(ss, ss->Default2D);
567 if (ss->Default3D)
568 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000569 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000570 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000571 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000572 return NULL;
573 }
574 else {
575 return ss;
576 }
577}
578
579
580/*
581 * Deallocate a shared state context and all children structures.
582 */
Brian Paul178a1c52000-04-22 01:05:00 +0000583static void
584free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000585{
586 /* Free display lists */
587 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000588 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000589 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000590 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000591 }
592 else {
593 break;
594 }
595 }
Brian Paulbb797902000-01-24 16:19:54 +0000596 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000597
598 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000599 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000600 if (ctx->Driver.DeleteTexture)
601 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
602 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000603 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000604 }
Brian Paulbb797902000-01-24 16:19:54 +0000605 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000606
Brian Paul30f51ae2001-12-18 04:06:44 +0000607 /* Free vertex programs */
608 while (1) {
609 GLuint prog = _mesa_HashFirstEntry(ss->VertexPrograms);
610 if (prog) {
611 _mesa_delete_program(ctx, prog);
612 }
613 else {
614 break;
615 }
616 }
617 _mesa_DeleteHashTable(ss->VertexPrograms);
618
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000619 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000620}
621
622
623
jtgafb833d1999-08-19 00:55:39 +0000624/*
625 * Initialize the nth light. Note that the defaults for light 0 are
626 * different than the other lights.
627 */
Brian Paul178a1c52000-04-22 01:05:00 +0000628static void
629init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000630{
631 make_empty_list( l );
632
633 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
634 if (n==0) {
635 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
636 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
637 }
638 else {
639 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
640 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
641 }
642 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
643 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
644 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000645 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000646 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000647 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000648 l->ConstantAttenuation = 1.0;
649 l->LinearAttenuation = 0.0;
650 l->QuadraticAttenuation = 0.0;
651 l->Enabled = GL_FALSE;
652}
653
654
655
Brian Paul178a1c52000-04-22 01:05:00 +0000656static void
657init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000658{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000659 ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000660 lm->LocalViewer = GL_FALSE;
661 lm->TwoSide = GL_FALSE;
662 lm->ColorControl = GL_SINGLE_COLOR;
663}
664
665
Brian Paul178a1c52000-04-22 01:05:00 +0000666static void
667init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000668{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000669 ASSIGN_4V( m->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
670 ASSIGN_4V( m->Diffuse, 0.8F, 0.8F, 0.8F, 1.0F );
671 ASSIGN_4V( m->Specular, 0.0F, 0.0F, 0.0F, 1.0F );
672 ASSIGN_4V( m->Emission, 0.0F, 0.0F, 0.0F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000673 m->Shininess = 0.0;
674 m->AmbientIndex = 0;
675 m->DiffuseIndex = 1;
676 m->SpecularIndex = 1;
677}
678
679
680
Brian Paul178a1c52000-04-22 01:05:00 +0000681static void
682init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000683{
684 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
685
686 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000687 texUnit->CombineModeRGB = GL_MODULATE;
688 texUnit->CombineModeA = GL_MODULATE;
689 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
690 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
691 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
692 texUnit->CombineSourceA[0] = GL_TEXTURE;
693 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
694 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
695 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
696 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
697 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
698 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
699 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
700 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
701 texUnit->CombineScaleShiftRGB = 0;
702 texUnit->CombineScaleShiftA = 0;
703
jtgafb833d1999-08-19 00:55:39 +0000704 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
705 texUnit->TexGenEnabled = 0;
706 texUnit->GenModeS = GL_EYE_LINEAR;
707 texUnit->GenModeT = GL_EYE_LINEAR;
708 texUnit->GenModeR = GL_EYE_LINEAR;
709 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000710 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
711 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
712 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
713 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000714
jtgafb833d1999-08-19 00:55:39 +0000715 /* Yes, these plane coefficients are correct! */
716 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
717 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
718 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
719 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
720 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
721 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
722 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
723 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
724
Brian Paula8523782000-11-19 23:10:25 +0000725 texUnit->Current1D = ctx->Shared->Default1D;
726 texUnit->Current2D = ctx->Shared->Default2D;
727 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000728 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000729}
730
731
jtgafb833d1999-08-19 00:55:39 +0000732
Brian Paul4d053dd2000-01-14 04:45:47 +0000733
jtgafb833d1999-08-19 00:55:39 +0000734/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000735static void
736init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000737{
738 map->Order = 1;
739 map->u1 = 0.0;
740 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000741 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000742 if (map->Points) {
743 GLint i;
744 for (i=0;i<n;i++)
745 map->Points[i] = initial[i];
746 }
jtgafb833d1999-08-19 00:55:39 +0000747}
748
749
750/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000751static void
752init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000753{
754 map->Uorder = 1;
755 map->Vorder = 1;
756 map->u1 = 0.0;
757 map->u2 = 1.0;
758 map->v1 = 0.0;
759 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000760 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000761 if (map->Points) {
762 GLint i;
763 for (i=0;i<n;i++)
764 map->Points[i] = initial[i];
765 }
jtgafb833d1999-08-19 00:55:39 +0000766}
767
768
jtgafb833d1999-08-19 00:55:39 +0000769/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000770 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000771 */
Brian Paul178a1c52000-04-22 01:05:00 +0000772static void
773init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000774{
Brian Paul30f51ae2001-12-18 04:06:44 +0000775 GLuint i;
jtgafb833d1999-08-19 00:55:39 +0000776
Brian Paul4d053dd2000-01-14 04:45:47 +0000777 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000778
Brian Paulcd1cefa2001-06-13 14:56:14 +0000779 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
780 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
781
Brian Paul539cce52000-02-03 19:40:07 +0000782 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000783 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +0000784 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
785 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000786 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000787 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +0000788 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000789 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000790 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
791 ctx->Const.MinPointSize = MIN_POINT_SIZE;
792 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
793 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
794 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000795 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000796 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
797 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
798 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
799 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000800 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000801 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000802 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000803 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
804 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000805 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000806 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
807 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000808
Brian Paul30f51ae2001-12-18 04:06:44 +0000809 /* Initialize matrix stacks */
810 init_matrix_stack(&ctx->ModelviewMatrixStack, MAX_MODELVIEW_STACK_DEPTH,
811 _NEW_MODELVIEW);
812 init_matrix_stack(&ctx->ProjectionMatrixStack, MAX_PROJECTION_STACK_DEPTH,
813 _NEW_PROJECTION);
814 init_matrix_stack(&ctx->ColorMatrixStack, MAX_COLOR_STACK_DEPTH,
815 _NEW_COLOR_MATRIX);
816 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
817 init_matrix_stack(&ctx->TextureMatrixStack[i], MAX_TEXTURE_STACK_DEPTH,
818 _NEW_TEXTURE_MATRIX);
819 for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
820 init_matrix_stack(&ctx->ProgramMatrixStack[i], MAX_PROGRAM_STACK_DEPTH,
821 _NEW_TRACK_MATRIX);
822 ctx->CurrentStack = &ctx->ModelviewMatrixStack;
Brian Paul4d053dd2000-01-14 04:45:47 +0000823
Brian Paul30f51ae2001-12-18 04:06:44 +0000824 /* Init combined Modelview*Projection matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000825 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
826
Brian Paul4d053dd2000-01-14 04:45:47 +0000827 /* Accumulate buffer group */
828 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000829
Brian Paul4d053dd2000-01-14 04:45:47 +0000830 /* Color buffer group */
831 ctx->Color.IndexMask = 0xffffffff;
832 ctx->Color.ColorMask[0] = 0xff;
833 ctx->Color.ColorMask[1] = 0xff;
834 ctx->Color.ColorMask[2] = 0xff;
835 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000836 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000837 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000838 ctx->Color.DrawBuffer = GL_FRONT;
839 ctx->Color.AlphaEnabled = GL_FALSE;
840 ctx->Color.AlphaFunc = GL_ALWAYS;
841 ctx->Color.AlphaRef = 0;
842 ctx->Color.BlendEnabled = GL_FALSE;
843 ctx->Color.BlendSrcRGB = GL_ONE;
844 ctx->Color.BlendDstRGB = GL_ZERO;
845 ctx->Color.BlendSrcA = GL_ONE;
846 ctx->Color.BlendDstA = GL_ZERO;
847 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000848 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
849 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
850 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000851 ctx->Color.LogicOp = GL_COPY;
852 ctx->Color.DitherFlag = GL_TRUE;
853 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000854
Brian Paul4d053dd2000-01-14 04:45:47 +0000855 /* Current group */
Brian Paul86b84272001-12-14 02:50:01 +0000856 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 0.0, 0.0, 0.0, 0.0 );
857 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 0.0 );
858 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
859 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 0.0 );
860 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 );
861 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
862 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_TEX0 + i], 0.0, 0.0, 0.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000863 ctx->Current.Index = 1;
Brian Paul86b84272001-12-14 02:50:01 +0000864 ctx->Current.EdgeFlag = GL_TRUE;
865
Brian Paul4d053dd2000-01-14 04:45:47 +0000866 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
867 ctx->Current.RasterDistance = 0.0;
868 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
869 ctx->Current.RasterIndex = 1;
870 for (i=0; i<MAX_TEXTURE_UNITS; i++)
871 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
872 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
873 ctx->Current.RasterPosValid = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000874
jtgafb833d1999-08-19 00:55:39 +0000875
Brian Paul4d053dd2000-01-14 04:45:47 +0000876 /* Depth buffer group */
877 ctx->Depth.Test = GL_FALSE;
878 ctx->Depth.Clear = 1.0;
879 ctx->Depth.Func = GL_LESS;
880 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000881 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000882
Brian Paul4d053dd2000-01-14 04:45:47 +0000883 /* Evaluators group */
884 ctx->Eval.Map1Color4 = GL_FALSE;
885 ctx->Eval.Map1Index = GL_FALSE;
886 ctx->Eval.Map1Normal = GL_FALSE;
887 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
888 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
889 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
890 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
891 ctx->Eval.Map1Vertex3 = GL_FALSE;
892 ctx->Eval.Map1Vertex4 = GL_FALSE;
Brian Paulbc42c192002-01-05 21:53:20 +0000893 MEMSET(ctx->Eval.Map1Attrib, 0, sizeof(ctx->Eval.Map1Attrib));
Brian Paul4d053dd2000-01-14 04:45:47 +0000894 ctx->Eval.Map2Color4 = GL_FALSE;
895 ctx->Eval.Map2Index = GL_FALSE;
896 ctx->Eval.Map2Normal = GL_FALSE;
897 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
898 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
899 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
900 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
901 ctx->Eval.Map2Vertex3 = GL_FALSE;
902 ctx->Eval.Map2Vertex4 = GL_FALSE;
Brian Paulbc42c192002-01-05 21:53:20 +0000903 MEMSET(ctx->Eval.Map2Attrib, 0, sizeof(ctx->Eval.Map2Attrib));
Brian Paul4d053dd2000-01-14 04:45:47 +0000904 ctx->Eval.AutoNormal = GL_FALSE;
905 ctx->Eval.MapGrid1un = 1;
906 ctx->Eval.MapGrid1u1 = 0.0;
907 ctx->Eval.MapGrid1u2 = 1.0;
908 ctx->Eval.MapGrid2un = 1;
909 ctx->Eval.MapGrid2vn = 1;
910 ctx->Eval.MapGrid2u1 = 0.0;
911 ctx->Eval.MapGrid2u2 = 1.0;
912 ctx->Eval.MapGrid2v1 = 0.0;
913 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000914
Brian Paul4d053dd2000-01-14 04:45:47 +0000915 /* Evaluator data */
916 {
917 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
918 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
919 static GLfloat index[1] = { 1.0 };
920 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
921 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
Brian Paulbc42c192002-01-05 21:53:20 +0000922 static GLfloat attrib[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000923
Brian Paul4d053dd2000-01-14 04:45:47 +0000924 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
925 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
926 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
927 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
928 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
929 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
930 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
931 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
932 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
Brian Paulbc42c192002-01-05 21:53:20 +0000933 for (i = 0; i < 16; i++)
934 init_1d_map( ctx->EvalMap.Map1Attrib + i, 4, attrib );
jtgafb833d1999-08-19 00:55:39 +0000935
Brian Paul4d053dd2000-01-14 04:45:47 +0000936 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
937 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
938 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
939 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
940 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
941 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
942 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
943 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
944 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
Brian Paulbc42c192002-01-05 21:53:20 +0000945 for (i = 0; i < 16; i++)
946 init_2d_map( ctx->EvalMap.Map2Attrib + i, 4, attrib );
Brian Paul4d053dd2000-01-14 04:45:47 +0000947 }
jtgafb833d1999-08-19 00:55:39 +0000948
Brian Paul4d053dd2000-01-14 04:45:47 +0000949 /* Fog group */
950 ctx->Fog.Enabled = GL_FALSE;
951 ctx->Fog.Mode = GL_EXP;
952 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
953 ctx->Fog.Index = 0.0;
954 ctx->Fog.Density = 1.0;
955 ctx->Fog.Start = 0.0;
956 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000957 ctx->Fog.ColorSumEnabled = GL_FALSE;
958 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000959
Brian Paul4d053dd2000-01-14 04:45:47 +0000960 /* Hint group */
961 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
962 ctx->Hint.PointSmooth = GL_DONT_CARE;
963 ctx->Hint.LineSmooth = GL_DONT_CARE;
964 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
965 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000966 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
967 ctx->Hint.TextureCompression = GL_DONT_CARE;
Brian Paul3893e632001-05-21 16:41:03 +0000968 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000969
Brian Paul0771d152000-04-07 00:19:41 +0000970 /* Histogram group */
971 ctx->Histogram.Width = 0;
972 ctx->Histogram.Format = GL_RGBA;
973 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000974 ctx->Histogram.RedSize = 0;
975 ctx->Histogram.GreenSize = 0;
976 ctx->Histogram.BlueSize = 0;
977 ctx->Histogram.AlphaSize = 0;
978 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000979 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
980 ctx->Histogram.Count[i][0] = 0;
981 ctx->Histogram.Count[i][1] = 0;
982 ctx->Histogram.Count[i][2] = 0;
983 ctx->Histogram.Count[i][3] = 0;
984 }
985
986 /* Min/Max group */
987 ctx->MinMax.Format = GL_RGBA;
988 ctx->MinMax.Sink = GL_FALSE;
989 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
990 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
991 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
992 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
993
Brian Paul4d053dd2000-01-14 04:45:47 +0000994 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000995 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000996
Brian Paul4d053dd2000-01-14 04:45:47 +0000997 /* Lighting group */
998 for (i=0;i<MAX_LIGHTS;i++) {
999 init_light( &ctx->Light.Light[i], i );
1000 }
1001 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001002
Brian Paul4d053dd2000-01-14 04:45:47 +00001003 init_lightmodel( &ctx->Light.Model );
1004 init_material( &ctx->Light.Material[0] );
1005 init_material( &ctx->Light.Material[1] );
1006 ctx->Light.ShadeModel = GL_SMOOTH;
1007 ctx->Light.Enabled = GL_FALSE;
1008 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1009 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +00001010 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
1011 GL_FRONT_AND_BACK,
1012 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001013
Brian Paul4d053dd2000-01-14 04:45:47 +00001014 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001015
Brian Paul4d053dd2000-01-14 04:45:47 +00001016 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +00001017 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1018 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001019 for (i = 0 ; i < 10 ; i++) {
1020 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1021 s->shininess = -1;
1022 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001023 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +00001024 }
Brian Paul77d61af2000-06-28 04:20:21 +00001025
jtgafb833d1999-08-19 00:55:39 +00001026
Brian Paul4d053dd2000-01-14 04:45:47 +00001027 /* Line group */
1028 ctx->Line.SmoothFlag = GL_FALSE;
1029 ctx->Line.StippleFlag = GL_FALSE;
1030 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +00001031 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001032 ctx->Line.StipplePattern = 0xffff;
1033 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001034
Brian Paul4d053dd2000-01-14 04:45:47 +00001035 /* Display List group */
1036 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001037
Brian Paul736fcbe2001-05-29 15:23:48 +00001038 /* Multisample */
1039 ctx->Multisample.Enabled = GL_FALSE;
1040 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
1041 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
1042 ctx->Multisample.SampleCoverage = GL_FALSE;
1043 ctx->Multisample.SampleCoverageValue = 1.0;
1044 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
1045
Brian Paul4d053dd2000-01-14 04:45:47 +00001046 /* Pixel group */
1047 ctx->Pixel.RedBias = 0.0;
1048 ctx->Pixel.RedScale = 1.0;
1049 ctx->Pixel.GreenBias = 0.0;
1050 ctx->Pixel.GreenScale = 1.0;
1051 ctx->Pixel.BlueBias = 0.0;
1052 ctx->Pixel.BlueScale = 1.0;
1053 ctx->Pixel.AlphaBias = 0.0;
1054 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001055 ctx->Pixel.DepthBias = 0.0;
1056 ctx->Pixel.DepthScale = 1.0;
1057 ctx->Pixel.IndexOffset = 0;
1058 ctx->Pixel.IndexShift = 0;
1059 ctx->Pixel.ZoomX = 1.0;
1060 ctx->Pixel.ZoomY = 1.0;
1061 ctx->Pixel.MapColorFlag = GL_FALSE;
1062 ctx->Pixel.MapStencilFlag = GL_FALSE;
1063 ctx->Pixel.MapStoSsize = 1;
1064 ctx->Pixel.MapItoIsize = 1;
1065 ctx->Pixel.MapItoRsize = 1;
1066 ctx->Pixel.MapItoGsize = 1;
1067 ctx->Pixel.MapItoBsize = 1;
1068 ctx->Pixel.MapItoAsize = 1;
1069 ctx->Pixel.MapRtoRsize = 1;
1070 ctx->Pixel.MapGtoGsize = 1;
1071 ctx->Pixel.MapBtoBsize = 1;
1072 ctx->Pixel.MapAtoAsize = 1;
1073 ctx->Pixel.MapStoS[0] = 0;
1074 ctx->Pixel.MapItoI[0] = 0;
1075 ctx->Pixel.MapItoR[0] = 0.0;
1076 ctx->Pixel.MapItoG[0] = 0.0;
1077 ctx->Pixel.MapItoB[0] = 0.0;
1078 ctx->Pixel.MapItoA[0] = 0.0;
1079 ctx->Pixel.MapItoR8[0] = 0;
1080 ctx->Pixel.MapItoG8[0] = 0;
1081 ctx->Pixel.MapItoB8[0] = 0;
1082 ctx->Pixel.MapItoA8[0] = 0;
1083 ctx->Pixel.MapRtoR[0] = 0.0;
1084 ctx->Pixel.MapGtoG[0] = 0.0;
1085 ctx->Pixel.MapBtoB[0] = 0.0;
1086 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001087 ctx->Pixel.HistogramEnabled = GL_FALSE;
1088 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1089 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1090 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1091 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001092 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1093 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1094 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1095 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001096 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1097 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1098 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1099 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001100 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1101 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1102 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001103 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1104 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1105 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1106 for (i = 0; i < 3; i++) {
1107 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1108 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1109 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1110 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1111 }
Brian Paul67adba12000-12-09 20:35:54 +00001112 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1113 ctx->Convolution1D.Filter[i] = 0.0;
1114 ctx->Convolution2D.Filter[i] = 0.0;
1115 ctx->Separable2D.Filter[i] = 0.0;
1116 }
Brian Paul82b02f02000-05-07 20:37:40 +00001117 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1118 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001119
Brian Paul4d053dd2000-01-14 04:45:47 +00001120 /* Point group */
1121 ctx->Point.SmoothFlag = GL_FALSE;
1122 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001123 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001124 ctx->Point.Params[0] = 1.0;
1125 ctx->Point.Params[1] = 0.0;
1126 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001127 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001128 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001129 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001130 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001131 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001132
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 /* Polygon group */
1134 ctx->Polygon.CullFlag = GL_FALSE;
1135 ctx->Polygon.CullFaceMode = GL_BACK;
1136 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001137 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001138 ctx->Polygon.FrontMode = GL_FILL;
1139 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001140 ctx->Polygon.SmoothFlag = GL_FALSE;
1141 ctx->Polygon.StippleFlag = GL_FALSE;
1142 ctx->Polygon.OffsetFactor = 0.0F;
1143 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001144 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001145 ctx->Polygon.OffsetPoint = GL_FALSE;
1146 ctx->Polygon.OffsetLine = GL_FALSE;
1147 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001148
Brian Paul4d053dd2000-01-14 04:45:47 +00001149 /* Polygon Stipple group */
1150 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001151
Brian Paul4d053dd2000-01-14 04:45:47 +00001152 /* Scissor group */
1153 ctx->Scissor.Enabled = GL_FALSE;
1154 ctx->Scissor.X = 0;
1155 ctx->Scissor.Y = 0;
1156 ctx->Scissor.Width = 0;
1157 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001158
Brian Paul4d053dd2000-01-14 04:45:47 +00001159 /* Stencil group */
1160 ctx->Stencil.Enabled = GL_FALSE;
1161 ctx->Stencil.Function = GL_ALWAYS;
1162 ctx->Stencil.FailFunc = GL_KEEP;
1163 ctx->Stencil.ZPassFunc = GL_KEEP;
1164 ctx->Stencil.ZFailFunc = GL_KEEP;
1165 ctx->Stencil.Ref = 0;
1166 ctx->Stencil.ValueMask = STENCIL_MAX;
1167 ctx->Stencil.Clear = 0;
1168 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001169
Brian Paul4d053dd2000-01-14 04:45:47 +00001170 /* Texture group */
1171 ctx->Texture.CurrentUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001172 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001173 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1174 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001175 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001176 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001177
Brian Paul4d053dd2000-01-14 04:45:47 +00001178 /* Transformation group */
1179 ctx->Transform.MatrixMode = GL_MODELVIEW;
1180 ctx->Transform.Normalize = GL_FALSE;
1181 ctx->Transform.RescaleNormals = GL_FALSE;
Brian Paul8c2f6c52001-06-26 01:32:48 +00001182 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001183 for (i=0;i<MAX_CLIP_PLANES;i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001184 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1185 }
Brian Paul103bc0f2002-03-29 17:27:59 +00001186 ctx->Transform.ClipPlanesEnabled = 0;
jtgafb833d1999-08-19 00:55:39 +00001187
Brian Paul4d053dd2000-01-14 04:45:47 +00001188 /* Viewport group */
1189 ctx->Viewport.X = 0;
1190 ctx->Viewport.Y = 0;
1191 ctx->Viewport.Width = 0;
1192 ctx->Viewport.Height = 0;
1193 ctx->Viewport.Near = 0.0;
1194 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001195 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001196
1197#define Sz 10
1198#define Tz 14
Brian Paulfde5e2c2001-09-15 18:02:49 +00001199 ctx->Viewport._WindowMap.m[Sz] = 0.5F * ctx->DepthMaxF;
1200 ctx->Viewport._WindowMap.m[Tz] = 0.5F * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001201#undef Sz
1202#undef Tz
1203
Keith Whitwell14940c42000-11-05 18:40:57 +00001204 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1205 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001206
Brian Paul4d053dd2000-01-14 04:45:47 +00001207 /* Vertex arrays */
1208 ctx->Array.Vertex.Size = 4;
1209 ctx->Array.Vertex.Type = GL_FLOAT;
1210 ctx->Array.Vertex.Stride = 0;
1211 ctx->Array.Vertex.StrideB = 0;
1212 ctx->Array.Vertex.Ptr = NULL;
1213 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001214 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001215 ctx->Array.Normal.Type = GL_FLOAT;
1216 ctx->Array.Normal.Stride = 0;
1217 ctx->Array.Normal.StrideB = 0;
1218 ctx->Array.Normal.Ptr = NULL;
1219 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001220 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001221 ctx->Array.Color.Size = 4;
1222 ctx->Array.Color.Type = GL_FLOAT;
1223 ctx->Array.Color.Stride = 0;
1224 ctx->Array.Color.StrideB = 0;
1225 ctx->Array.Color.Ptr = NULL;
1226 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001227 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1228 ctx->Array.SecondaryColor.Size = 4;
1229 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1230 ctx->Array.SecondaryColor.Stride = 0;
1231 ctx->Array.SecondaryColor.StrideB = 0;
1232 ctx->Array.SecondaryColor.Ptr = NULL;
1233 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1234 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1235 ctx->Array.FogCoord.Size = 1;
1236 ctx->Array.FogCoord.Type = GL_FLOAT;
1237 ctx->Array.FogCoord.Stride = 0;
1238 ctx->Array.FogCoord.StrideB = 0;
1239 ctx->Array.FogCoord.Ptr = NULL;
1240 ctx->Array.FogCoord.Enabled = GL_FALSE;
1241 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001242 ctx->Array.Index.Type = GL_FLOAT;
1243 ctx->Array.Index.Stride = 0;
1244 ctx->Array.Index.StrideB = 0;
1245 ctx->Array.Index.Ptr = NULL;
1246 ctx->Array.Index.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001247 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001248 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1249 ctx->Array.TexCoord[i].Size = 4;
1250 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1251 ctx->Array.TexCoord[i].Stride = 0;
1252 ctx->Array.TexCoord[i].StrideB = 0;
1253 ctx->Array.TexCoord[i].Ptr = NULL;
1254 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001255 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001256 }
1257 ctx->Array.TexCoordInterleaveFactor = 1;
1258 ctx->Array.EdgeFlag.Stride = 0;
1259 ctx->Array.EdgeFlag.StrideB = 0;
1260 ctx->Array.EdgeFlag.Ptr = NULL;
1261 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001262 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001263 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1264
1265 /* Pixel transfer */
1266 ctx->Pack.Alignment = 4;
1267 ctx->Pack.RowLength = 0;
1268 ctx->Pack.ImageHeight = 0;
1269 ctx->Pack.SkipPixels = 0;
1270 ctx->Pack.SkipRows = 0;
1271 ctx->Pack.SkipImages = 0;
1272 ctx->Pack.SwapBytes = GL_FALSE;
1273 ctx->Pack.LsbFirst = GL_FALSE;
1274 ctx->Unpack.Alignment = 4;
1275 ctx->Unpack.RowLength = 0;
1276 ctx->Unpack.ImageHeight = 0;
1277 ctx->Unpack.SkipPixels = 0;
1278 ctx->Unpack.SkipRows = 0;
1279 ctx->Unpack.SkipImages = 0;
1280 ctx->Unpack.SwapBytes = GL_FALSE;
1281 ctx->Unpack.LsbFirst = GL_FALSE;
1282
1283 /* Feedback */
1284 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1285 ctx->Feedback.Buffer = NULL;
1286 ctx->Feedback.BufferSize = 0;
1287 ctx->Feedback.Count = 0;
1288
1289 /* Selection/picking */
1290 ctx->Select.Buffer = NULL;
1291 ctx->Select.BufferSize = 0;
1292 ctx->Select.BufferCount = 0;
1293 ctx->Select.Hits = 0;
1294 ctx->Select.NameStackDepth = 0;
1295
Brian Paul4d053dd2000-01-14 04:45:47 +00001296 /* Renderer and client attribute stacks */
1297 ctx->AttribStackDepth = 0;
1298 ctx->ClientAttribStackDepth = 0;
1299
Brian Paul13811372000-04-12 00:27:37 +00001300 /* Display list */
1301 ctx->CallDepth = 0;
1302 ctx->ExecuteFlag = GL_TRUE;
1303 ctx->CompileFlag = GL_FALSE;
1304 ctx->CurrentListPtr = NULL;
1305 ctx->CurrentBlock = NULL;
1306 ctx->CurrentListNum = 0;
1307 ctx->CurrentPos = 0;
1308
1309 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001310 _mesa_init_colortable(&ctx->ColorTable);
1311 _mesa_init_colortable(&ctx->ProxyColorTable);
1312 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1313 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1314 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1315 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001316
Brian Paul86b84272001-12-14 02:50:01 +00001317 /* GL_NV_vertex_program */
Brian Paul30f51ae2001-12-18 04:06:44 +00001318 ctx->VertexProgram.Current = NULL;
1319 ctx->VertexProgram.CurrentID = 0;
Brian Paul86b84272001-12-14 02:50:01 +00001320 ctx->VertexProgram.Enabled = GL_FALSE;
1321 ctx->VertexProgram.PointSizeEnabled = GL_FALSE;
1322 ctx->VertexProgram.TwoSideEnabled = GL_FALSE;
1323 for (i = 0; i < VP_NUM_PROG_REGS / 4; i++) {
1324 ctx->VertexProgram.TrackMatrix[i] = GL_NONE;
1325 ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV;
1326 }
1327
Brian Paul4d053dd2000-01-14 04:45:47 +00001328 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001329 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001330 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001331 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001332
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001333 ctx->_NeedNormals = 0;
1334 ctx->_NeedEyeCoords = 0;
1335 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001336
Brian Paul4d053dd2000-01-14 04:45:47 +00001337 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1338
1339 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001340 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001341 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001342
1343 /* For debug/development only */
1344 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1345 ctx->FirstTimeCurrent = GL_TRUE;
1346
1347 /* Dither disable */
1348 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1349 if (ctx->NoDither) {
1350 if (getenv("MESA_DEBUG")) {
1351 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001352 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001353 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001354 }
1355}
1356
1357
1358
1359
jtgafb833d1999-08-19 00:55:39 +00001360/*
1361 * Allocate the proxy textures. If we run out of memory part way through
1362 * the allocations clean up and return GL_FALSE.
1363 * Return: GL_TRUE=success, GL_FALSE=failure
1364 */
Brian Paul178a1c52000-04-22 01:05:00 +00001365static GLboolean
1366alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001367{
1368 GLboolean out_of_memory;
1369 GLint i;
1370
Brian Paula8523782000-11-19 23:10:25 +00001371 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001372 if (!ctx->Texture.Proxy1D) {
1373 return GL_FALSE;
1374 }
1375
Brian Paula8523782000-11-19 23:10:25 +00001376 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001377 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001378 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001379 return GL_FALSE;
1380 }
1381
Brian Paula8523782000-11-19 23:10:25 +00001382 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001383 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001384 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1385 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1386 return GL_FALSE;
1387 }
1388
1389 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1390 if (!ctx->Texture.ProxyCubeMap) {
1391 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1392 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1393 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001394 return GL_FALSE;
1395 }
1396
1397 out_of_memory = GL_FALSE;
1398 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001399 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1400 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1401 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
Brian Paul172281d2001-07-26 20:02:10 +00001402 ctx->Texture.ProxyCubeMap->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001403 if (!ctx->Texture.Proxy1D->Image[i]
1404 || !ctx->Texture.Proxy2D->Image[i]
Brian Paul172281d2001-07-26 20:02:10 +00001405 || !ctx->Texture.Proxy3D->Image[i]
1406 || !ctx->Texture.ProxyCubeMap->Image[i]) {
jtgafb833d1999-08-19 00:55:39 +00001407 out_of_memory = GL_TRUE;
1408 }
1409 }
1410 if (out_of_memory) {
1411 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1412 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001413 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001414 }
1415 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001416 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001417 }
1418 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001419 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001420 }
Brian Paul172281d2001-07-26 20:02:10 +00001421 if (ctx->Texture.ProxyCubeMap->Image[i]) {
1422 _mesa_free_texture_image(ctx->Texture.ProxyCubeMap->Image[i]);
1423 }
jtgafb833d1999-08-19 00:55:39 +00001424 }
Brian Paula8523782000-11-19 23:10:25 +00001425 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1426 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1427 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
Brian Paul172281d2001-07-26 20:02:10 +00001428 _mesa_free_texture_object(NULL, ctx->Texture.ProxyCubeMap);
jtgafb833d1999-08-19 00:55:39 +00001429 return GL_FALSE;
1430 }
1431 else {
1432 return GL_TRUE;
1433 }
1434}
1435
1436
jtgafb833d1999-08-19 00:55:39 +00001437/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001438 * Initialize a GLcontext struct. This includes allocating all the
1439 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001440 */
Brian Paul178a1c52000-04-22 01:05:00 +00001441GLboolean
1442_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001443 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001444 GLcontext *share_list,
1445 void *driver_ctx,
1446 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001447{
Brian Paul5fb84d22000-05-24 15:04:45 +00001448 GLuint dispatchSize;
1449
jtgafb833d1999-08-19 00:55:39 +00001450 (void) direct; /* not used */
1451
jtgafb833d1999-08-19 00:55:39 +00001452 /* misc one-time initializations */
1453 one_time_init();
1454
Brian Paulb1394fa2000-09-26 20:53:53 +00001455 /**
1456 ** OpenGL SI stuff
1457 **/
1458 if (!ctx->imports.malloc) {
1459 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1460 }
1461 /* exports are setup by the device driver */
1462
jtgafb833d1999-08-19 00:55:39 +00001463 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001464 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001465 ctx->DrawBuffer = NULL;
1466 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001467
jtgafb833d1999-08-19 00:55:39 +00001468 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001469 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001470 ctx->Shared = share_list->Shared;
1471 }
1472 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001473 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001474 ctx->Shared = alloc_shared_state();
1475 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001476 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001477 }
1478 }
Brian Paul9560f052000-01-31 23:11:39 +00001479 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001480 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001481 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001482
Brian Paul5a2f32b2001-04-25 18:21:05 +00001483 /* Effectively bind the default textures to all texture units */
1484 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1485 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1486 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1487 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1488
Brian Paul4d053dd2000-01-14 04:45:47 +00001489 init_attrib_groups( ctx );
1490
Brian Paulb6bcae52001-01-23 23:39:36 +00001491 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001492 ctx->Color.DrawBuffer = GL_BACK;
1493 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1494 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1495 ctx->Pixel.ReadBuffer = GL_BACK;
1496 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1497 }
1498 else {
1499 ctx->Color.DrawBuffer = GL_FRONT;
1500 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1501 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1502 ctx->Pixel.ReadBuffer = GL_FRONT;
1503 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1504 }
1505
jtgafb833d1999-08-19 00:55:39 +00001506 if (!alloc_proxy_textures(ctx)) {
1507 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001508 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001509 }
jtgafb833d1999-08-19 00:55:39 +00001510
Brian Paulf59afc92000-05-23 23:23:00 +00001511 /* register the most recent extension functions with libGL */
1512 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1513 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1514 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1515 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1516 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1517 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1518 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1519 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1520
Brian Paul5fb84d22000-05-24 15:04:45 +00001521 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1522 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1523 * Mesa we do this to accomodate different versions of libGL and various
1524 * DRI drivers.
1525 */
1526 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1527 sizeof(struct _glapi_table) / sizeof(void *));
1528
Brian Paulfbd8f211999-11-11 01:22:25 +00001529 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001530 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1531 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001532 if (!ctx->Exec || !ctx->Save) {
1533 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001534 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001535 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001536 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001537 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1538 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001539 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001540
Keith Whitwellad2ac212000-11-24 10:25:05 +00001541 ctx->ExecPrefersFloat = GL_FALSE;
1542 ctx->SavePrefersFloat = GL_FALSE;
1543
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001544 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001545 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001546 ctx->TnlModule.Current = NULL;
1547 ctx->TnlModule.SwapCount = 0;
1548
Brian Paulb6bcae52001-01-23 23:39:36 +00001549 /* Z buffer stuff */
1550 if (ctx->Visual.depthBits == 0) {
1551 /* Special case. Even if we don't have a depth buffer we need
1552 * good values for DepthMax for Z vertex transformation purposes
1553 * and for per-fragment fog computation.
1554 */
1555 ctx->DepthMax = 1 << 16;
1556 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1557 }
1558 else if (ctx->Visual.depthBits < 32) {
1559 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1560 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1561 }
1562 else {
1563 /* Special case since shift values greater than or equal to the
1564 * number of bits in the left hand expression's type are undefined.
1565 */
1566 ctx->DepthMax = 0xffffffff;
1567 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1568 }
Brian Paulbc920f02001-05-07 16:32:51 +00001569 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001570
1571
Brian Paul3b18a362000-09-26 15:27:20 +00001572#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001573 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001574#if 0
1575 /* Brian: do you want to have CreateContext fail here,
1576 or should we just trap in NewTrace (currently done)? */
1577 if (!(ctx->TraceCtx)) {
1578 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001579 FREE( ctx->Exec );
1580 FREE( ctx->Save );
1581 return GL_FALSE;
1582 }
1583#endif
1584 trInitContext(ctx->TraceCtx);
1585
1586 ctx->TraceDispatch = (struct _glapi_table *)
1587 CALLOC(dispatchSize * sizeof(void*));
1588#if 0
1589 if (!(ctx->TraceCtx)) {
1590 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001591 FREE( ctx->Exec );
1592 FREE( ctx->Save );
1593 FREE( ctx->TraceCtx );
1594 return GL_FALSE;
1595 }
1596#endif
1597 trInitDispatch(ctx->TraceDispatch);
1598#endif
1599
Brian Paul4d053dd2000-01-14 04:45:47 +00001600 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001601}
1602
jtgafb833d1999-08-19 00:55:39 +00001603
1604
1605/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001606 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001607 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001608 * sharelist - another context to share display lists with or NULL
1609 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001610 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001611 */
Brian Paul178a1c52000-04-22 01:05:00 +00001612GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001613_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001614 GLcontext *share_list,
1615 void *driver_ctx,
1616 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001617{
1618 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1619 if (!ctx) {
1620 return NULL;
1621 }
Jouk Jansen12e875c2001-10-18 08:04:57 +00001622 ctx->Driver.CurrentExecPrimitive = 0;
Brian Paul178a1c52000-04-22 01:05:00 +00001623 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001624 return ctx;
1625 }
1626 else {
1627 FREE(ctx);
1628 return NULL;
1629 }
1630}
1631
1632
1633
1634/*
1635 * Free the data associated with the given context.
1636 * But don't free() the GLcontext struct itself!
1637 */
Brian Paul178a1c52000-04-22 01:05:00 +00001638void
Brian Paulb1394fa2000-09-26 20:53:53 +00001639_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001640{
Brian Paul4d053dd2000-01-14 04:45:47 +00001641 struct gl_shine_tab *s, *tmps;
Brian Paul30f51ae2001-12-18 04:06:44 +00001642 GLuint i;
Brian Paul4d053dd2000-01-14 04:45:47 +00001643
1644 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001645 if (ctx == _mesa_get_current_context()) {
1646 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001647 }
1648
Brian Paul30f51ae2001-12-18 04:06:44 +00001649 /*
1650 * Free transformation matrix stacks
1651 */
1652 free_matrix_stack(&ctx->ModelviewMatrixStack);
1653 free_matrix_stack(&ctx->ProjectionMatrixStack);
1654 free_matrix_stack(&ctx->ColorMatrixStack);
1655 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
1656 free_matrix_stack(&ctx->TextureMatrixStack[i]);
1657 for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
1658 free_matrix_stack(&ctx->ProgramMatrixStack[i]);
1659 /* combined Modelview*Projection matrix */
Brian Paulfd284452001-07-19 15:54:34 +00001660 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
1661
Brian Paul30f51ae2001-12-18 04:06:44 +00001662
1663 if (ctx->VertexProgram.Current) {
1664 ctx->VertexProgram.Current->RefCount--;
1665 if (ctx->VertexProgram.Current->RefCount <= 0)
1666 _mesa_delete_program(ctx, ctx->VertexProgram.CurrentID);
Brian Paulfd284452001-07-19 15:54:34 +00001667 }
1668
Brian Paul30f51ae2001-12-18 04:06:44 +00001669 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001670 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001671 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001672 assert(ctx->Shared->RefCount >= 0);
1673 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1674 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001675 /* free shared state */
1676 free_shared_state( ctx, ctx->Shared );
1677 }
1678
Brian Paul30f51ae2001-12-18 04:06:44 +00001679 /* Free lighting shininess exponentiation table */
Keith Whitwell14940c42000-11-05 18:40:57 +00001680 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001681 FREE( s );
1682 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001683 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001684
1685 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001686 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1687 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1688 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paulfd284452001-07-19 15:54:34 +00001689 _mesa_free_texture_object( NULL, ctx->Texture.ProxyCubeMap );
Brian Paul4d053dd2000-01-14 04:45:47 +00001690
1691 /* Free evaluator data */
1692 if (ctx->EvalMap.Map1Vertex3.Points)
1693 FREE( ctx->EvalMap.Map1Vertex3.Points );
1694 if (ctx->EvalMap.Map1Vertex4.Points)
1695 FREE( ctx->EvalMap.Map1Vertex4.Points );
1696 if (ctx->EvalMap.Map1Index.Points)
1697 FREE( ctx->EvalMap.Map1Index.Points );
1698 if (ctx->EvalMap.Map1Color4.Points)
1699 FREE( ctx->EvalMap.Map1Color4.Points );
1700 if (ctx->EvalMap.Map1Normal.Points)
1701 FREE( ctx->EvalMap.Map1Normal.Points );
1702 if (ctx->EvalMap.Map1Texture1.Points)
1703 FREE( ctx->EvalMap.Map1Texture1.Points );
1704 if (ctx->EvalMap.Map1Texture2.Points)
1705 FREE( ctx->EvalMap.Map1Texture2.Points );
1706 if (ctx->EvalMap.Map1Texture3.Points)
1707 FREE( ctx->EvalMap.Map1Texture3.Points );
1708 if (ctx->EvalMap.Map1Texture4.Points)
1709 FREE( ctx->EvalMap.Map1Texture4.Points );
Brian Paulc4afba32002-02-05 23:21:45 +00001710 for (i = 0; i < 16; i++)
1711 FREE((ctx->EvalMap.Map1Attrib[i].Points));
Brian Paul4d053dd2000-01-14 04:45:47 +00001712
1713 if (ctx->EvalMap.Map2Vertex3.Points)
1714 FREE( ctx->EvalMap.Map2Vertex3.Points );
1715 if (ctx->EvalMap.Map2Vertex4.Points)
1716 FREE( ctx->EvalMap.Map2Vertex4.Points );
1717 if (ctx->EvalMap.Map2Index.Points)
1718 FREE( ctx->EvalMap.Map2Index.Points );
1719 if (ctx->EvalMap.Map2Color4.Points)
1720 FREE( ctx->EvalMap.Map2Color4.Points );
1721 if (ctx->EvalMap.Map2Normal.Points)
1722 FREE( ctx->EvalMap.Map2Normal.Points );
1723 if (ctx->EvalMap.Map2Texture1.Points)
1724 FREE( ctx->EvalMap.Map2Texture1.Points );
1725 if (ctx->EvalMap.Map2Texture2.Points)
1726 FREE( ctx->EvalMap.Map2Texture2.Points );
1727 if (ctx->EvalMap.Map2Texture3.Points)
1728 FREE( ctx->EvalMap.Map2Texture3.Points );
1729 if (ctx->EvalMap.Map2Texture4.Points)
1730 FREE( ctx->EvalMap.Map2Texture4.Points );
Brian Paulc4afba32002-02-05 23:21:45 +00001731 for (i = 0; i < 16; i++)
1732 FREE((ctx->EvalMap.Map2Attrib[i].Points));
Brian Paul4d053dd2000-01-14 04:45:47 +00001733
Brian Paul4bdcfe52000-04-17 17:57:04 +00001734 _mesa_free_colortable_data( &ctx->ColorTable );
1735 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1736 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1737 _mesa_free_colortable_data( &ctx->Texture.Palette );
1738
Brian Paulfd284452001-07-19 15:54:34 +00001739 _math_matrix_dtr(&ctx->Viewport._WindowMap);
1740
Brian Paul69755402001-02-26 23:58:12 +00001741 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001742
1743 FREE(ctx->Exec);
1744 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001745}
1746
1747
1748
1749/*
1750 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001751 */
Brian Paul178a1c52000-04-22 01:05:00 +00001752void
Brian Paulb1394fa2000-09-26 20:53:53 +00001753_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001754{
1755 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001756 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001757 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001758 }
1759}
1760
1761
1762
1763/*
jtgafb833d1999-08-19 00:55:39 +00001764 * Copy attribute groups from one context to another.
1765 * Input: src - source context
1766 * dst - destination context
1767 * mask - bitwise OR of GL_*_BIT flags
1768 */
Brian Paul178a1c52000-04-22 01:05:00 +00001769void
Brian Paulb1394fa2000-09-26 20:53:53 +00001770_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001771{
1772 if (mask & GL_ACCUM_BUFFER_BIT) {
1773 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1774 }
1775 if (mask & GL_COLOR_BUFFER_BIT) {
1776 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1777 }
1778 if (mask & GL_CURRENT_BIT) {
1779 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1780 }
1781 if (mask & GL_DEPTH_BUFFER_BIT) {
1782 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1783 }
1784 if (mask & GL_ENABLE_BIT) {
1785 /* no op */
1786 }
1787 if (mask & GL_EVAL_BIT) {
1788 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1789 }
1790 if (mask & GL_FOG_BIT) {
1791 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1792 }
1793 if (mask & GL_HINT_BIT) {
1794 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1795 }
1796 if (mask & GL_LIGHTING_BIT) {
1797 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001798 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001799 }
1800 if (mask & GL_LINE_BIT) {
1801 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1802 }
1803 if (mask & GL_LIST_BIT) {
1804 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1805 }
1806 if (mask & GL_PIXEL_MODE_BIT) {
1807 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1808 }
1809 if (mask & GL_POINT_BIT) {
1810 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1811 }
1812 if (mask & GL_POLYGON_BIT) {
1813 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1814 }
1815 if (mask & GL_POLYGON_STIPPLE_BIT) {
1816 /* Use loop instead of MEMCPY due to problem with Portland Group's
1817 * C compiler. Reported by John Stone.
1818 */
1819 int i;
1820 for (i=0;i<32;i++) {
1821 dst->PolygonStipple[i] = src->PolygonStipple[i];
1822 }
1823 }
1824 if (mask & GL_SCISSOR_BIT) {
1825 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1826 }
1827 if (mask & GL_STENCIL_BUFFER_BIT) {
1828 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1829 }
1830 if (mask & GL_TEXTURE_BIT) {
1831 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1832 }
1833 if (mask & GL_TRANSFORM_BIT) {
1834 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1835 }
1836 if (mask & GL_VIEWPORT_BIT) {
1837 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1838 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001839 /* XXX FIXME: Call callbacks?
1840 */
1841 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001842}
1843
1844
jtgafb833d1999-08-19 00:55:39 +00001845/*
Brian Paul00037781999-12-17 14:52:35 +00001846 * Set the current context, binding the given frame buffer to the context.
1847 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001848void
1849_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001850{
Brian Paulb1394fa2000-09-26 20:53:53 +00001851 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001852}
1853
1854
Keith Whitwell23caf202000-11-16 21:05:34 +00001855static void print_info( void )
1856{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001857 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001858 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001859 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001860 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001861 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001862 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001863 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001864 (char *) _mesa_GetString(GL_EXTENSIONS));
1865#if defined(THREADS)
1866 fprintf(stderr, "Mesa thread-safe: YES\n");
1867#else
1868 fprintf(stderr, "Mesa thread-safe: NO\n");
1869#endif
1870#if defined(USE_X86_ASM)
1871 fprintf(stderr, "Mesa x86-optimized: YES\n");
1872#else
1873 fprintf(stderr, "Mesa x86-optimized: NO\n");
1874#endif
davem69e4f84b42001-06-05 03:58:20 +00001875#if defined(USE_SPARC_ASM)
1876 fprintf(stderr, "Mesa sparc-optimized: YES\n");
1877#else
1878 fprintf(stderr, "Mesa sparc-optimized: NO\n");
1879#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001880}
1881
1882
Brian Paul00037781999-12-17 14:52:35 +00001883/*
1884 * Bind the given context to the given draw-buffer and read-buffer
1885 * and make it the current context for this thread.
1886 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001887void
1888_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1889 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001890{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001891 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001892 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001893
Brian Paulbe3602d2001-02-28 00:27:48 +00001894 /* Check that the context's and framebuffer's visuals are compatible.
1895 * We could do a lot more checking here but this'll catch obvious
1896 * problems.
1897 */
1898 if (newCtx && drawBuffer && readBuffer) {
1899 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1900 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1901 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1902 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1903 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1904 return; /* incompatible */
1905 }
1906 }
1907
Brian Paul00037781999-12-17 14:52:35 +00001908 /* We call this function periodically (just here for now) in
1909 * order to detect when multithreading has begun.
1910 */
1911 _glapi_check_multithread();
1912
Brian Paulf9b97d92000-01-28 20:17:42 +00001913 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001914 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001915
1916
1917 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001918 _glapi_set_dispatch(NULL); /* none current */
1919 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001920 else {
1921 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001922
Keith Whitwell23caf202000-11-16 21:05:34 +00001923 if (drawBuffer && readBuffer) {
1924 /* TODO: check if newCtx and buffer's visual match??? */
1925 newCtx->DrawBuffer = drawBuffer;
1926 newCtx->ReadBuffer = readBuffer;
1927 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001928 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001929 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001930
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001931 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001932 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1933
1934 /* We can use this to help debug user's problems. Tell them to set
1935 * the MESA_INFO env variable before running their app. Then the
1936 * first time each context is made current we'll print some useful
1937 * information.
1938 */
1939 if (newCtx->FirstTimeCurrent) {
1940 if (getenv("MESA_INFO")) {
1941 print_info();
1942 }
1943 newCtx->FirstTimeCurrent = GL_FALSE;
1944 }
Brian Paul00037781999-12-17 14:52:35 +00001945 }
1946}
1947
1948
1949
1950/*
1951 * Return current context handle for the calling thread.
1952 * This isn't the fastest way to get the current context.
1953 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1954 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001955GLcontext *
1956_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001957{
Brian Paulf9b97d92000-01-28 20:17:42 +00001958 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001959}
1960
1961
1962
1963/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001964 * This should be called by device drivers just before they do a
1965 * swapbuffers. Any pending rendering commands will be executed.
Brian Paul9a888bd2002-03-13 04:33:32 +00001966 * XXX we should really rename this function to _mesa_flush() or something.
jtgafb833d1999-08-19 00:55:39 +00001967 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001968void
1969_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001970{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001971 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001972}
1973
1974
Brian Paul00037781999-12-17 14:52:35 +00001975
Brian Paulfbd8f211999-11-11 01:22:25 +00001976/*
1977 * Return pointer to this context's current API dispatch table.
1978 * It'll either be the immediate-mode execute dispatcher or the
1979 * display list compile dispatcher.
1980 */
1981struct _glapi_table *
1982_mesa_get_dispatch(GLcontext *ctx)
1983{
1984 return ctx->CurrentDispatch;
1985}
1986
1987
1988
jtgafb833d1999-08-19 00:55:39 +00001989/**********************************************************************/
1990/***** Miscellaneous functions *****/
1991/**********************************************************************/
1992
1993
1994/*
1995 * This function is called when the Mesa user has stumbled into a code
1996 * path which may not be implemented fully or correctly.
1997 */
Brian Paul08836342001-03-03 20:33:27 +00001998void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001999{
2000 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00002001#ifdef XF86DRI
2002 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
2003#else
2004 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
2005#endif
jtgafb833d1999-08-19 00:55:39 +00002006 (void) ctx;
2007}
2008
2009
2010
2011/*
2012 * This is called to inform the user that he or she has tried to do
2013 * something illogical or if there's likely a bug in their program
2014 * (like enabled depth testing without a depth buffer).
2015 */
Brian Paulb1394fa2000-09-26 20:53:53 +00002016void
2017_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00002018{
Brian Paulb1394fa2000-09-26 20:53:53 +00002019 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00002020}
2021
2022
2023
Brian Paulfa9df402000-02-02 19:16:46 +00002024/*
jtgafb833d1999-08-19 00:55:39 +00002025 * This is Mesa's error handler. Normally, all that's done is the updating
2026 * of the current error value. If Mesa is compiled with -DDEBUG or if the
2027 * environment variable "MESA_DEBUG" is defined then a real error message
2028 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00002029 * Input: ctx - the GL context
2030 * error - the error value
2031 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00002032 */
Brian Paul7eb06032000-07-14 04:13:40 +00002033void
Brian Paul08836342001-03-03 20:33:27 +00002034_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00002035{
Brian Paul7eb06032000-07-14 04:13:40 +00002036 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00002037 GLboolean debug;
2038
2039#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002040 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002041 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002042 else
2043 debug = GL_TRUE;
2044#else
2045 if (debugEnv)
2046 debug = GL_TRUE;
2047 else
2048 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002049#endif
2050
2051 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002052 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002053 switch (error) {
2054 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002055 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002056 break;
2057 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002058 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002059 break;
2060 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002061 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002062 break;
2063 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002064 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002065 break;
2066 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002067 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002068 break;
2069 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002070 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002071 break;
2072 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002073 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002074 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002075 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002076 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002077 break;
jtgafb833d1999-08-19 00:55:39 +00002078 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002079 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002080 break;
2081 }
Brian Paul7eb06032000-07-14 04:13:40 +00002082 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002083 }
2084
Brian Paul18a285a2002-03-16 00:53:15 +00002085 if (!ctx)
2086 return;
2087
Brian Paul7eb06032000-07-14 04:13:40 +00002088 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002089 ctx->ErrorValue = error;
2090 }
2091
2092 /* Call device driver's error handler, if any. This is used on the Mac. */
2093 if (ctx->Driver.Error) {
2094 (*ctx->Driver.Error)( ctx );
2095 }
2096}
2097
2098
2099
Brian Paulfa9df402000-02-02 19:16:46 +00002100void
2101_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002102{
Brian Paulfa9df402000-02-02 19:16:46 +00002103 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002105 if (ctx->Driver.Finish) {
2106 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002107 }
2108}
2109
2110
2111
Brian Paulfa9df402000-02-02 19:16:46 +00002112void
2113_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002114{
Brian Paulfa9df402000-02-02 19:16:46 +00002115 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002116 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002117 if (ctx->Driver.Flush) {
2118 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002119 }
jtgafb833d1999-08-19 00:55:39 +00002120}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002121
2122
2123
Keith Whitwellcab974c2000-12-26 05:09:27 +00002124const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002125 "GL_POINTS",
2126 "GL_LINES",
2127 "GL_LINE_LOOP",
2128 "GL_LINE_STRIP",
2129 "GL_TRIANGLES",
2130 "GL_TRIANGLE_STRIP",
2131 "GL_TRIANGLE_FAN",
2132 "GL_QUADS",
2133 "GL_QUAD_STRIP",
2134 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002135 "outside begin/end",
2136 "inside unkown primitive",
2137 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002138};