blob: 013a16b95be75ad4f820c20de95ebb4430759bf0 [file] [log] [blame]
Gareth Hughes2c3d34c2001-03-18 08:53:49 +00001/* $Id: context.c,v 1.129 2001/03/18 08:53:49 gareth Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paule4b684c2000-09-12 21:07:40 +00005 * Version: 3.5
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paulb6bcae52001-01-23 23:39:36 +00007 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000032#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000034#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000035#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "dlist.h"
37#include "eval.h"
38#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000039#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000041#include "get.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000042#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000043#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000044#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000045#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000046#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000047#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000048#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "mmath.h"
jtgafb833d1999-08-19 00:55:39 +000050#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +000051#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000052#include "teximage.h"
53#include "texobj.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000054#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000055#include "varray.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +000056#include "vtxfmt.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000057
58#include "math/m_translate.h"
59#include "math/m_vertices.h"
60#include "math/m_matrix.h"
61#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +000062#include "math/mathmod.h"
jtgafb833d1999-08-19 00:55:39 +000063#endif
64
Brian Paul3b18a362000-09-26 15:27:20 +000065#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000066#include "Trace/tr_context.h"
67#include "Trace/tr_wrapper.h"
68#endif
69
jtgafb833d1999-08-19 00:55:39 +000070
Keith Whitwell23caf202000-11-16 21:05:34 +000071#ifndef MESA_VERBOSE
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000072int MESA_VERBOSE = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000073/* | VERBOSE_PIPELINE */
74/* | VERBOSE_IMMEDIATE */
75/* | VERBOSE_VARRAY */
76/* | VERBOSE_TEXTURE */
77/* | VERBOSE_API */
78/* | VERBOSE_DRIVER */
79/* | VERBOSE_STATE */
Keith Whitwell23caf202000-11-16 21:05:34 +000080/* | VERBOSE_DISPLAY_LIST */
81;
82#endif
83
84#ifndef MESA_DEBUG_FLAGS
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000085int MESA_DEBUG_FLAGS = 0
Keith Whitwell23caf202000-11-16 21:05:34 +000086/* | DEBUG_ALWAYS_FLUSH */
87;
88#endif
Brian Paulb1394fa2000-09-26 20:53:53 +000089
90/**********************************************************************/
91/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
92/**********************************************************************/
93
94static GLboolean
95_mesa_DestroyContext(__GLcontext *gc)
96{
97 if (gc) {
98 _mesa_free_context_data(gc);
99 (*gc->imports.free)(gc, gc);
100 }
101 return GL_TRUE;
102}
103
104
105/* exported OpenGL SI interface */
106__GLcontext *
107__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
108{
109 GLcontext *ctx;
110
111 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
112 if (ctx == NULL) {
113 return NULL;
114 }
115 ctx->imports = *imports;
116
117 _mesa_initialize_visual(&ctx->Visual,
118 modes->rgbMode,
119 modes->doubleBufferMode,
120 modes->stereoMode,
121 modes->redBits,
122 modes->greenBits,
123 modes->blueBits,
124 modes->alphaBits,
125 modes->indexBits,
126 modes->depthBits,
127 modes->stencilBits,
128 modes->accumRedBits,
129 modes->accumGreenBits,
130 modes->accumBlueBits,
131 modes->accumAlphaBits,
132 0);
133
Keith Whitwellb980b2e2001-01-08 04:09:41 +0000134 /* KW: was imports->wscx */
135 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
Brian Paulb1394fa2000-09-26 20:53:53 +0000136
137 ctx->exports.destroyContext = _mesa_DestroyContext;
138
139 return ctx;
140}
141
142
143/* exported OpenGL SI interface */
144void
145__glCoreNopDispatch(void)
146{
147#if 0
148 /* SI */
149 __gl_dispatch = __glNopDispatchState;
150#else
151 /* Mesa */
152 _glapi_set_dispatch(NULL);
153#endif
154}
155
156
jtgafb833d1999-08-19 00:55:39 +0000157/**********************************************************************/
158/***** Context and Thread management *****/
159/**********************************************************************/
160
161
jtgafb833d1999-08-19 00:55:39 +0000162
jtgafb833d1999-08-19 00:55:39 +0000163/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000164/***** GL Visual allocation/destruction *****/
165/**********************************************************************/
166
167
168/*
169 * Allocate a new GLvisual object.
170 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000171 * dbFlag - double buffering?
172 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000173 * depthBits - requested bits per depth buffer value
174 * Any value in [0, 32] is acceptable but the actual
175 * depth type will be GLushort or GLuint as needed.
176 * stencilBits - requested minimum bits per stencil buffer value
177 * accumBits - requested minimum bits per accum buffer component
178 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
179 * red/green/blue/alphaBits - number of bits per color component
180 * in frame buffer for RGB(A) mode.
181 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000182 * Return: pointer to new GLvisual or NULL if requested parameters can't
183 * be met.
184 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000185GLvisual *
186_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000187 GLboolean dbFlag,
188 GLboolean stereoFlag,
189 GLint redBits,
190 GLint greenBits,
191 GLint blueBits,
192 GLint alphaBits,
193 GLint indexBits,
194 GLint depthBits,
195 GLint stencilBits,
196 GLint accumRedBits,
197 GLint accumGreenBits,
198 GLint accumBlueBits,
199 GLint accumAlphaBits,
200 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000201{
Brian Paul178a1c52000-04-22 01:05:00 +0000202 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
203 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000204 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000205 redBits, greenBits, blueBits, alphaBits,
206 indexBits, depthBits, stencilBits,
207 accumRedBits, accumGreenBits,
208 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000209 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000210 FREE(vis);
211 return NULL;
212 }
213 }
214 return vis;
215}
216
217
218/*
219 * Initialize the fields of the given GLvisual.
220 * Input: see _mesa_create_visual() above.
221 * Return: GL_TRUE = success
222 * GL_FALSE = failure.
223 */
224GLboolean
225_mesa_initialize_visual( GLvisual *vis,
226 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000227 GLboolean dbFlag,
228 GLboolean stereoFlag,
229 GLint redBits,
230 GLint greenBits,
231 GLint blueBits,
232 GLint alphaBits,
233 GLint indexBits,
234 GLint depthBits,
235 GLint stencilBits,
236 GLint accumRedBits,
237 GLint accumGreenBits,
238 GLint accumBlueBits,
239 GLint accumAlphaBits,
240 GLint numSamples )
241{
Brian Paulb6bcae52001-01-23 23:39:36 +0000242 (void) numSamples;
243
Brian Paul178a1c52000-04-22 01:05:00 +0000244 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000245
Brian Pauled30dfa2000-03-03 17:47:39 +0000246 /* This is to catch bad values from device drivers not updated for
247 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
248 * bad value now (a 1-bit depth buffer!?!).
249 */
250 assert(depthBits == 0 || depthBits > 1);
251
252 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000253 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000254 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000255 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000256 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000257 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000258 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000259 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000260 }
261 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000262 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000263 }
264 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000265 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000266 }
267 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000268 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000269 }
270
Brian Paulb6bcae52001-01-23 23:39:36 +0000271 vis->rgbMode = rgbFlag;
272 vis->doubleBufferMode = dbFlag;
273 vis->stereoMode = stereoFlag;
274 vis->redBits = redBits;
275 vis->greenBits = greenBits;
276 vis->blueBits = blueBits;
277 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000278
Brian Paulb6bcae52001-01-23 23:39:36 +0000279 vis->indexBits = indexBits;
280 vis->depthBits = depthBits;
281 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
282 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
283 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
284 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
285 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000286
Brian Paul178a1c52000-04-22 01:05:00 +0000287 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000288}
289
290
Brian Paulb371e0d2000-03-31 01:05:51 +0000291void
292_mesa_destroy_visual( GLvisual *vis )
293{
294 FREE(vis);
295}
296
297
Brian Paul4d053dd2000-01-14 04:45:47 +0000298/**********************************************************************/
299/***** GL Framebuffer allocation/destruction *****/
300/**********************************************************************/
301
302
303/*
304 * Create a new framebuffer. A GLframebuffer is a struct which
305 * encapsulates the depth, stencil and accum buffers and related
306 * parameters.
Brian Paulbe3602d2001-02-28 00:27:48 +0000307 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +0000308 * softwareDepth - create/use a software depth buffer?
309 * softwareStencil - create/use a software stencil buffer?
310 * softwareAccum - create/use a software accum buffer?
311 * softwareAlpha - create/use a software alpha buffer?
Brian Paul4d053dd2000-01-14 04:45:47 +0000312 * Return: pointer to new GLframebuffer struct or NULL if error.
313 */
Brian Paul178a1c52000-04-22 01:05:00 +0000314GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000315_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000316 GLboolean softwareDepth,
317 GLboolean softwareStencil,
318 GLboolean softwareAccum,
319 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000320{
Brian Paul178a1c52000-04-22 01:05:00 +0000321 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
322 assert(visual);
323 if (buffer) {
324 _mesa_initialize_framebuffer(buffer, visual,
325 softwareDepth, softwareStencil,
326 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000327 }
Brian Paul178a1c52000-04-22 01:05:00 +0000328 return buffer;
329}
330
331
332/*
333 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000334 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000335 */
336void
337_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000338 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000339 GLboolean softwareDepth,
340 GLboolean softwareStencil,
341 GLboolean softwareAccum,
342 GLboolean softwareAlpha )
343{
344 assert(buffer);
345 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000346
347 /* sanity checks */
348 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000349 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000350 }
351 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000352 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000353 }
354 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000355 assert(visual->rgbMode);
356 assert(visual->accumRedBits > 0);
357 assert(visual->accumGreenBits > 0);
358 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000359 }
360 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000361 assert(visual->rgbMode);
362 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000363 }
364
Brian Paulbe3602d2001-02-28 00:27:48 +0000365 buffer->Visual = *visual; /* XXX copy instead? */
Brian Paul4d053dd2000-01-14 04:45:47 +0000366 buffer->UseSoftwareDepthBuffer = softwareDepth;
367 buffer->UseSoftwareStencilBuffer = softwareStencil;
368 buffer->UseSoftwareAccumBuffer = softwareAccum;
369 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000370}
371
372
Brian Paul4d053dd2000-01-14 04:45:47 +0000373/*
374 * Free a framebuffer struct and its buffers.
375 */
Brian Paul178a1c52000-04-22 01:05:00 +0000376void
Brian Paulb1394fa2000-09-26 20:53:53 +0000377_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000378{
379 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000380 if (buffer->DepthBuffer) {
381 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000382 }
383 if (buffer->Accum) {
384 FREE( buffer->Accum );
385 }
386 if (buffer->Stencil) {
387 FREE( buffer->Stencil );
388 }
389 if (buffer->FrontLeftAlpha) {
390 FREE( buffer->FrontLeftAlpha );
391 }
392 if (buffer->BackLeftAlpha) {
393 FREE( buffer->BackLeftAlpha );
394 }
395 if (buffer->FrontRightAlpha) {
396 FREE( buffer->FrontRightAlpha );
397 }
398 if (buffer->BackRightAlpha) {
399 FREE( buffer->BackRightAlpha );
400 }
401 FREE(buffer);
402 }
403}
404
405
406
407/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000408/***** Context allocation, initialization, destroying *****/
409/**********************************************************************/
410
411
Brian Paul9560f052000-01-31 23:11:39 +0000412_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
413
414
jtgafb833d1999-08-19 00:55:39 +0000415/*
416 * This function just calls all the various one-time-init functions in Mesa.
417 */
Brian Paul178a1c52000-04-22 01:05:00 +0000418static void
419one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000420{
421 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000422 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000423 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000424 /* do some implementation tests */
425 assert( sizeof(GLbyte) == 1 );
426 assert( sizeof(GLshort) >= 2 );
427 assert( sizeof(GLint) >= 4 );
428 assert( sizeof(GLubyte) == 1 );
429 assert( sizeof(GLushort) >= 2 );
430 assert( sizeof(GLuint) >= 4 );
431
Brian Paul08836342001-03-03 20:33:27 +0000432 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000433
Keith Whitwell23caf202000-11-16 21:05:34 +0000434 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000435 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000436
437 if (getenv("MESA_DEBUG")) {
438 _glapi_noop_enable_warnings(GL_TRUE);
439 }
440 else {
441 _glapi_noop_enable_warnings(GL_FALSE);
442 }
443
jtgafb833d1999-08-19 00:55:39 +0000444#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
445 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
446#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000447
448 alreadyCalled = GL_TRUE;
449 }
Brian Paul9560f052000-01-31 23:11:39 +0000450 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000451}
452
453
Brian Paul4d053dd2000-01-14 04:45:47 +0000454
jtgafb833d1999-08-19 00:55:39 +0000455/*
456 * Allocate and initialize a shared context state structure.
457 */
Brian Paul178a1c52000-04-22 01:05:00 +0000458static struct gl_shared_state *
459alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000460{
jtgafb833d1999-08-19 00:55:39 +0000461 struct gl_shared_state *ss;
462 GLboolean outOfMemory;
463
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000464 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000465 if (!ss)
466 return NULL;
467
Brian Paule4b684c2000-09-12 21:07:40 +0000468 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000469
Brian Paule4b684c2000-09-12 21:07:40 +0000470 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000471 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000472
473 /* Default Texture objects */
474 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000475
476 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
477 if (!ss->Default1D) {
478 outOfMemory = GL_TRUE;
479 }
480 else {
481 ss->Default1D->RefCount++;
jtgafb833d1999-08-19 00:55:39 +0000482 }
483
Brian Paula8523782000-11-19 23:10:25 +0000484 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
485 if (!ss->Default2D) {
486 outOfMemory = GL_TRUE;
487 }
488 else {
489 ss->Default2D->RefCount++;
490 }
491
492 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
493 if (!ss->Default3D) {
494 outOfMemory = GL_TRUE;
495 }
496 else {
497 ss->Default1D->RefCount++;
498 }
499
500 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000501 if (!ss->DefaultCubeMap) {
502 outOfMemory = GL_TRUE;
503 }
504 else {
505 ss->DefaultCubeMap->RefCount++;
506 }
507
jtgafb833d1999-08-19 00:55:39 +0000508 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
509 /* Ran out of memory at some point. Free everything and return NULL */
510 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000511 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000512 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000513 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula8523782000-11-19 23:10:25 +0000514 if (ss->Default1D)
515 _mesa_free_texture_object(ss, ss->Default1D);
516 if (ss->Default2D)
517 _mesa_free_texture_object(ss, ss->Default2D);
518 if (ss->Default3D)
519 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000520 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000521 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000522 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000523 return NULL;
524 }
525 else {
526 return ss;
527 }
528}
529
530
531/*
532 * Deallocate a shared state context and all children structures.
533 */
Brian Paul178a1c52000-04-22 01:05:00 +0000534static void
535free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000536{
537 /* Free display lists */
538 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000539 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000540 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000541 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000542 }
543 else {
544 break;
545 }
546 }
Brian Paulbb797902000-01-24 16:19:54 +0000547 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000548
549 /* Free texture objects */
550 while (ss->TexObjectList)
551 {
552 if (ctx->Driver.DeleteTexture)
553 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
554 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000555 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000556 }
Brian Paulbb797902000-01-24 16:19:54 +0000557 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000558
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000559 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000560}
561
562
563
jtgafb833d1999-08-19 00:55:39 +0000564/*
565 * Initialize the nth light. Note that the defaults for light 0 are
566 * different than the other lights.
567 */
Brian Paul178a1c52000-04-22 01:05:00 +0000568static void
569init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000570{
571 make_empty_list( l );
572
573 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
574 if (n==0) {
575 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
576 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
577 }
578 else {
579 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
580 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
581 }
582 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
583 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
584 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000585 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000586 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000587 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000588 l->ConstantAttenuation = 1.0;
589 l->LinearAttenuation = 0.0;
590 l->QuadraticAttenuation = 0.0;
591 l->Enabled = GL_FALSE;
592}
593
594
595
Brian Paul178a1c52000-04-22 01:05:00 +0000596static void
597init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000598{
599 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
600 lm->LocalViewer = GL_FALSE;
601 lm->TwoSide = GL_FALSE;
602 lm->ColorControl = GL_SINGLE_COLOR;
603}
604
605
Brian Paul178a1c52000-04-22 01:05:00 +0000606static void
607init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000608{
609 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
610 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
611 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
612 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
613 m->Shininess = 0.0;
614 m->AmbientIndex = 0;
615 m->DiffuseIndex = 1;
616 m->SpecularIndex = 1;
617}
618
619
620
Brian Paul178a1c52000-04-22 01:05:00 +0000621static void
622init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000623{
624 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
625
626 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000627 texUnit->CombineModeRGB = GL_MODULATE;
628 texUnit->CombineModeA = GL_MODULATE;
629 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
630 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
631 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
632 texUnit->CombineSourceA[0] = GL_TEXTURE;
633 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
634 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
635 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
636 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
637 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
638 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
639 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
640 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
641 texUnit->CombineScaleShiftRGB = 0;
642 texUnit->CombineScaleShiftA = 0;
643
jtgafb833d1999-08-19 00:55:39 +0000644 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
645 texUnit->TexGenEnabled = 0;
646 texUnit->GenModeS = GL_EYE_LINEAR;
647 texUnit->GenModeT = GL_EYE_LINEAR;
648 texUnit->GenModeR = GL_EYE_LINEAR;
649 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000650 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
651 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
652 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
653 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000654
jtgafb833d1999-08-19 00:55:39 +0000655 /* Yes, these plane coefficients are correct! */
656 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
657 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
658 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
659 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
660 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
661 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
662 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
664
Brian Paula8523782000-11-19 23:10:25 +0000665 texUnit->Current1D = ctx->Shared->Default1D;
666 texUnit->Current2D = ctx->Shared->Default2D;
667 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000668 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000669}
670
671
jtgafb833d1999-08-19 00:55:39 +0000672
Brian Paul4d053dd2000-01-14 04:45:47 +0000673
jtgafb833d1999-08-19 00:55:39 +0000674/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000675static void
676init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000677{
678 map->Order = 1;
679 map->u1 = 0.0;
680 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000681 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000682 if (map->Points) {
683 GLint i;
684 for (i=0;i<n;i++)
685 map->Points[i] = initial[i];
686 }
jtgafb833d1999-08-19 00:55:39 +0000687}
688
689
690/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000691static void
692init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000693{
694 map->Uorder = 1;
695 map->Vorder = 1;
696 map->u1 = 0.0;
697 map->u2 = 1.0;
698 map->v1 = 0.0;
699 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000700 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000701 if (map->Points) {
702 GLint i;
703 for (i=0;i<n;i++)
704 map->Points[i] = initial[i];
705 }
jtgafb833d1999-08-19 00:55:39 +0000706}
707
708
jtgafb833d1999-08-19 00:55:39 +0000709/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000710 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000711 */
Brian Paul178a1c52000-04-22 01:05:00 +0000712static void
713init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000714{
715 GLuint i, j;
716
Brian Paul4d053dd2000-01-14 04:45:47 +0000717 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000718
Brian Paul539cce52000-02-03 19:40:07 +0000719 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000720 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
721 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000722 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000723 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000724 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul4d053dd2000-01-14 04:45:47 +0000725 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000726 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
727 ctx->Const.MinPointSize = MIN_POINT_SIZE;
728 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
729 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
730 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
731 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
732 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
733 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
734 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
735 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
736 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
737 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000738 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000739 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
740 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000741 ctx->Const.NumCompressedTextureFormats = 0;
Brian Paula8644322000-11-27 18:22:13 +0000742 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
743 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000744
Brian Paul4d053dd2000-01-14 04:45:47 +0000745 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000746 _math_matrix_ctr( &ctx->ModelView );
747 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000748
749 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000750 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000751 _math_matrix_ctr( &ctx->ModelViewStack[i] );
752 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000753 }
754
755 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000756 _math_matrix_ctr( &ctx->ProjectionMatrix );
757 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000758
759 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000760 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000761 _math_matrix_ctr( &ctx->ProjectionStack[i] );
762 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000763 }
764
Keith Whitwell23caf202000-11-16 21:05:34 +0000765 /* Derived ModelProject matrix */
766 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
767
Brian Paul4d053dd2000-01-14 04:45:47 +0000768 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000769 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000770 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000771 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000772 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000773 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000774 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000775 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000776 }
jtgafb833d1999-08-19 00:55:39 +0000777
Brian Paul250069d2000-04-08 18:57:45 +0000778 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000779 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000780 ctx->ColorStackDepth = 0;
781 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000782 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000783 }
784
Brian Paul4d053dd2000-01-14 04:45:47 +0000785 /* Accumulate buffer group */
786 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000787
Brian Paul4d053dd2000-01-14 04:45:47 +0000788 /* Color buffer group */
789 ctx->Color.IndexMask = 0xffffffff;
790 ctx->Color.ColorMask[0] = 0xff;
791 ctx->Color.ColorMask[1] = 0xff;
792 ctx->Color.ColorMask[2] = 0xff;
793 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000794 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000795 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000796 ctx->Color.DrawBuffer = GL_FRONT;
797 ctx->Color.AlphaEnabled = GL_FALSE;
798 ctx->Color.AlphaFunc = GL_ALWAYS;
799 ctx->Color.AlphaRef = 0;
800 ctx->Color.BlendEnabled = GL_FALSE;
801 ctx->Color.BlendSrcRGB = GL_ONE;
802 ctx->Color.BlendDstRGB = GL_ZERO;
803 ctx->Color.BlendSrcA = GL_ONE;
804 ctx->Color.BlendDstA = GL_ZERO;
805 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000806 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
807 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
808 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000809 ctx->Color.LogicOp = GL_COPY;
810 ctx->Color.DitherFlag = GL_TRUE;
811 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000812
Brian Paul4d053dd2000-01-14 04:45:47 +0000813 /* Current group */
Brian Paul19300532000-10-29 19:02:23 +0000814 ASSIGN_4V( ctx->Current.Color, CHAN_MAX, CHAN_MAX, CHAN_MAX, CHAN_MAX );
Brian Paul4d053dd2000-01-14 04:45:47 +0000815 ctx->Current.Index = 1;
816 for (i=0; i<MAX_TEXTURE_UNITS; i++)
817 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
818 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
819 ctx->Current.RasterDistance = 0.0;
820 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
821 ctx->Current.RasterIndex = 1;
822 for (i=0; i<MAX_TEXTURE_UNITS; i++)
823 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
824 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
825 ctx->Current.RasterPosValid = GL_TRUE;
826 ctx->Current.EdgeFlag = GL_TRUE;
827 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000828
jtgafb833d1999-08-19 00:55:39 +0000829
Brian Paul4d053dd2000-01-14 04:45:47 +0000830 /* Depth buffer group */
831 ctx->Depth.Test = GL_FALSE;
832 ctx->Depth.Clear = 1.0;
833 ctx->Depth.Func = GL_LESS;
834 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000835 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000836
Brian Paul4d053dd2000-01-14 04:45:47 +0000837 /* Evaluators group */
838 ctx->Eval.Map1Color4 = GL_FALSE;
839 ctx->Eval.Map1Index = GL_FALSE;
840 ctx->Eval.Map1Normal = GL_FALSE;
841 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
842 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
843 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
844 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
845 ctx->Eval.Map1Vertex3 = GL_FALSE;
846 ctx->Eval.Map1Vertex4 = GL_FALSE;
847 ctx->Eval.Map2Color4 = GL_FALSE;
848 ctx->Eval.Map2Index = GL_FALSE;
849 ctx->Eval.Map2Normal = GL_FALSE;
850 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
851 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
852 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
853 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
854 ctx->Eval.Map2Vertex3 = GL_FALSE;
855 ctx->Eval.Map2Vertex4 = GL_FALSE;
856 ctx->Eval.AutoNormal = GL_FALSE;
857 ctx->Eval.MapGrid1un = 1;
858 ctx->Eval.MapGrid1u1 = 0.0;
859 ctx->Eval.MapGrid1u2 = 1.0;
860 ctx->Eval.MapGrid2un = 1;
861 ctx->Eval.MapGrid2vn = 1;
862 ctx->Eval.MapGrid2u1 = 0.0;
863 ctx->Eval.MapGrid2u2 = 1.0;
864 ctx->Eval.MapGrid2v1 = 0.0;
865 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000866
Brian Paul4d053dd2000-01-14 04:45:47 +0000867 /* Evaluator data */
868 {
869 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
870 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
871 static GLfloat index[1] = { 1.0 };
872 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
873 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000874
Brian Paul4d053dd2000-01-14 04:45:47 +0000875 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
876 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
877 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
878 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
879 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
880 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
881 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
882 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
883 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000884
Brian Paul4d053dd2000-01-14 04:45:47 +0000885 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
886 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
887 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
888 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
889 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
890 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
891 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
892 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
893 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
894 }
jtgafb833d1999-08-19 00:55:39 +0000895
Brian Paul4d053dd2000-01-14 04:45:47 +0000896 /* Fog group */
897 ctx->Fog.Enabled = GL_FALSE;
898 ctx->Fog.Mode = GL_EXP;
899 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
900 ctx->Fog.Index = 0.0;
901 ctx->Fog.Density = 1.0;
902 ctx->Fog.Start = 0.0;
903 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000904 ctx->Fog.ColorSumEnabled = GL_FALSE;
905 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000906
Brian Paul4d053dd2000-01-14 04:45:47 +0000907 /* Hint group */
908 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
909 ctx->Hint.PointSmooth = GL_DONT_CARE;
910 ctx->Hint.LineSmooth = GL_DONT_CARE;
911 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
912 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000913 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
914 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000915
Brian Paul0771d152000-04-07 00:19:41 +0000916 /* Histogram group */
917 ctx->Histogram.Width = 0;
918 ctx->Histogram.Format = GL_RGBA;
919 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000920 ctx->Histogram.RedSize = 0;
921 ctx->Histogram.GreenSize = 0;
922 ctx->Histogram.BlueSize = 0;
923 ctx->Histogram.AlphaSize = 0;
924 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000925 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
926 ctx->Histogram.Count[i][0] = 0;
927 ctx->Histogram.Count[i][1] = 0;
928 ctx->Histogram.Count[i][2] = 0;
929 ctx->Histogram.Count[i][3] = 0;
930 }
931
932 /* Min/Max group */
933 ctx->MinMax.Format = GL_RGBA;
934 ctx->MinMax.Sink = GL_FALSE;
935 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
936 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
937 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
938 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
939
Brian Paul4d053dd2000-01-14 04:45:47 +0000940 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000941 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000942
Brian Paul4d053dd2000-01-14 04:45:47 +0000943 /* Lighting group */
944 for (i=0;i<MAX_LIGHTS;i++) {
945 init_light( &ctx->Light.Light[i], i );
946 }
947 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000948
Brian Paul4d053dd2000-01-14 04:45:47 +0000949 init_lightmodel( &ctx->Light.Model );
950 init_material( &ctx->Light.Material[0] );
951 init_material( &ctx->Light.Material[1] );
952 ctx->Light.ShadeModel = GL_SMOOTH;
953 ctx->Light.Enabled = GL_FALSE;
954 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
955 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +0000956 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
957 GL_FRONT_AND_BACK,
958 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000959
Brian Paul4d053dd2000-01-14 04:45:47 +0000960 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000961
Brian Paul4d053dd2000-01-14 04:45:47 +0000962 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +0000963 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
964 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +0000965 for (i = 0 ; i < 10 ; i++) {
966 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
967 s->shininess = -1;
968 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000969 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +0000970 }
Brian Paul77d61af2000-06-28 04:20:21 +0000971
jtgafb833d1999-08-19 00:55:39 +0000972
Brian Paul4d053dd2000-01-14 04:45:47 +0000973 /* Line group */
974 ctx->Line.SmoothFlag = GL_FALSE;
975 ctx->Line.StippleFlag = GL_FALSE;
976 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +0000977 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000978 ctx->Line.StipplePattern = 0xffff;
979 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000980
Brian Paul4d053dd2000-01-14 04:45:47 +0000981 /* Display List group */
982 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +0000983
Brian Paul4d053dd2000-01-14 04:45:47 +0000984 /* Pixel group */
985 ctx->Pixel.RedBias = 0.0;
986 ctx->Pixel.RedScale = 1.0;
987 ctx->Pixel.GreenBias = 0.0;
988 ctx->Pixel.GreenScale = 1.0;
989 ctx->Pixel.BlueBias = 0.0;
990 ctx->Pixel.BlueScale = 1.0;
991 ctx->Pixel.AlphaBias = 0.0;
992 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000993 ctx->Pixel.DepthBias = 0.0;
994 ctx->Pixel.DepthScale = 1.0;
995 ctx->Pixel.IndexOffset = 0;
996 ctx->Pixel.IndexShift = 0;
997 ctx->Pixel.ZoomX = 1.0;
998 ctx->Pixel.ZoomY = 1.0;
999 ctx->Pixel.MapColorFlag = GL_FALSE;
1000 ctx->Pixel.MapStencilFlag = GL_FALSE;
1001 ctx->Pixel.MapStoSsize = 1;
1002 ctx->Pixel.MapItoIsize = 1;
1003 ctx->Pixel.MapItoRsize = 1;
1004 ctx->Pixel.MapItoGsize = 1;
1005 ctx->Pixel.MapItoBsize = 1;
1006 ctx->Pixel.MapItoAsize = 1;
1007 ctx->Pixel.MapRtoRsize = 1;
1008 ctx->Pixel.MapGtoGsize = 1;
1009 ctx->Pixel.MapBtoBsize = 1;
1010 ctx->Pixel.MapAtoAsize = 1;
1011 ctx->Pixel.MapStoS[0] = 0;
1012 ctx->Pixel.MapItoI[0] = 0;
1013 ctx->Pixel.MapItoR[0] = 0.0;
1014 ctx->Pixel.MapItoG[0] = 0.0;
1015 ctx->Pixel.MapItoB[0] = 0.0;
1016 ctx->Pixel.MapItoA[0] = 0.0;
1017 ctx->Pixel.MapItoR8[0] = 0;
1018 ctx->Pixel.MapItoG8[0] = 0;
1019 ctx->Pixel.MapItoB8[0] = 0;
1020 ctx->Pixel.MapItoA8[0] = 0;
1021 ctx->Pixel.MapRtoR[0] = 0.0;
1022 ctx->Pixel.MapGtoG[0] = 0.0;
1023 ctx->Pixel.MapBtoB[0] = 0.0;
1024 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001025 ctx->Pixel.HistogramEnabled = GL_FALSE;
1026 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1027 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1028 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1029 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001030 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1031 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1032 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1033 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001034 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1035 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1036 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1037 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001038 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1039 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1040 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001041 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1042 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1043 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1044 for (i = 0; i < 3; i++) {
1045 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1046 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1047 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1048 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1049 }
Brian Paul67adba12000-12-09 20:35:54 +00001050 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1051 ctx->Convolution1D.Filter[i] = 0.0;
1052 ctx->Convolution2D.Filter[i] = 0.0;
1053 ctx->Separable2D.Filter[i] = 0.0;
1054 }
Brian Paul82b02f02000-05-07 20:37:40 +00001055 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1056 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001057
Brian Paul4d053dd2000-01-14 04:45:47 +00001058 /* Point group */
1059 ctx->Point.SmoothFlag = GL_FALSE;
1060 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001061 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001062 ctx->Point.Params[0] = 1.0;
1063 ctx->Point.Params[1] = 0.0;
1064 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001065 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001066 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001067 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001068 ctx->Point.Threshold = 1.0;
Brian Paul06d05af2000-12-08 00:20:15 +00001069 ctx->Point.SpriteMode = GL_FALSE; /* GL_MESA_sprite_point */
jtgafb833d1999-08-19 00:55:39 +00001070
Brian Paul4d053dd2000-01-14 04:45:47 +00001071 /* Polygon group */
1072 ctx->Polygon.CullFlag = GL_FALSE;
1073 ctx->Polygon.CullFaceMode = GL_BACK;
1074 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001075 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001076 ctx->Polygon.FrontMode = GL_FILL;
1077 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001078 ctx->Polygon.SmoothFlag = GL_FALSE;
1079 ctx->Polygon.StippleFlag = GL_FALSE;
1080 ctx->Polygon.OffsetFactor = 0.0F;
1081 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001082 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001083 ctx->Polygon.OffsetPoint = GL_FALSE;
1084 ctx->Polygon.OffsetLine = GL_FALSE;
1085 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001086
Brian Paul4d053dd2000-01-14 04:45:47 +00001087 /* Polygon Stipple group */
1088 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001089
Brian Paul4d053dd2000-01-14 04:45:47 +00001090 /* Scissor group */
1091 ctx->Scissor.Enabled = GL_FALSE;
1092 ctx->Scissor.X = 0;
1093 ctx->Scissor.Y = 0;
1094 ctx->Scissor.Width = 0;
1095 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001096
Brian Paul4d053dd2000-01-14 04:45:47 +00001097 /* Stencil group */
1098 ctx->Stencil.Enabled = GL_FALSE;
1099 ctx->Stencil.Function = GL_ALWAYS;
1100 ctx->Stencil.FailFunc = GL_KEEP;
1101 ctx->Stencil.ZPassFunc = GL_KEEP;
1102 ctx->Stencil.ZFailFunc = GL_KEEP;
1103 ctx->Stencil.Ref = 0;
1104 ctx->Stencil.ValueMask = STENCIL_MAX;
1105 ctx->Stencil.Clear = 0;
1106 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001107
Brian Paul4d053dd2000-01-14 04:45:47 +00001108 /* Texture group */
1109 ctx->Texture.CurrentUnit = 0; /* multitexture */
1110 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001111 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001112 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1113 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001114 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001115 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001116
Brian Paul4d053dd2000-01-14 04:45:47 +00001117 /* Transformation group */
1118 ctx->Transform.MatrixMode = GL_MODELVIEW;
1119 ctx->Transform.Normalize = GL_FALSE;
1120 ctx->Transform.RescaleNormals = GL_FALSE;
1121 for (i=0;i<MAX_CLIP_PLANES;i++) {
1122 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1123 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1124 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001125 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001126
Brian Paul4d053dd2000-01-14 04:45:47 +00001127 /* Viewport group */
1128 ctx->Viewport.X = 0;
1129 ctx->Viewport.Y = 0;
1130 ctx->Viewport.Width = 0;
1131 ctx->Viewport.Height = 0;
1132 ctx->Viewport.Near = 0.0;
1133 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001134 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001135
1136#define Sz 10
1137#define Tz 14
Brian Paulb6bcae52001-01-23 23:39:36 +00001138 ctx->Viewport._WindowMap.m[Sz] = 0.5 * ctx->DepthMaxF;
1139 ctx->Viewport._WindowMap.m[Tz] = 0.5 * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001140#undef Sz
1141#undef Tz
1142
Keith Whitwell14940c42000-11-05 18:40:57 +00001143 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1144 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001145
Brian Paul4d053dd2000-01-14 04:45:47 +00001146 /* Vertex arrays */
1147 ctx->Array.Vertex.Size = 4;
1148 ctx->Array.Vertex.Type = GL_FLOAT;
1149 ctx->Array.Vertex.Stride = 0;
1150 ctx->Array.Vertex.StrideB = 0;
1151 ctx->Array.Vertex.Ptr = NULL;
1152 ctx->Array.Vertex.Enabled = GL_FALSE;
1153 ctx->Array.Normal.Type = GL_FLOAT;
1154 ctx->Array.Normal.Stride = 0;
1155 ctx->Array.Normal.StrideB = 0;
1156 ctx->Array.Normal.Ptr = NULL;
1157 ctx->Array.Normal.Enabled = GL_FALSE;
1158 ctx->Array.Color.Size = 4;
1159 ctx->Array.Color.Type = GL_FLOAT;
1160 ctx->Array.Color.Stride = 0;
1161 ctx->Array.Color.StrideB = 0;
1162 ctx->Array.Color.Ptr = NULL;
1163 ctx->Array.Color.Enabled = GL_FALSE;
1164 ctx->Array.Index.Type = GL_FLOAT;
1165 ctx->Array.Index.Stride = 0;
1166 ctx->Array.Index.StrideB = 0;
1167 ctx->Array.Index.Ptr = NULL;
1168 ctx->Array.Index.Enabled = GL_FALSE;
1169 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1170 ctx->Array.TexCoord[i].Size = 4;
1171 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1172 ctx->Array.TexCoord[i].Stride = 0;
1173 ctx->Array.TexCoord[i].StrideB = 0;
1174 ctx->Array.TexCoord[i].Ptr = NULL;
1175 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1176 }
1177 ctx->Array.TexCoordInterleaveFactor = 1;
1178 ctx->Array.EdgeFlag.Stride = 0;
1179 ctx->Array.EdgeFlag.StrideB = 0;
1180 ctx->Array.EdgeFlag.Ptr = NULL;
1181 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1182 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1183
1184 /* Pixel transfer */
1185 ctx->Pack.Alignment = 4;
1186 ctx->Pack.RowLength = 0;
1187 ctx->Pack.ImageHeight = 0;
1188 ctx->Pack.SkipPixels = 0;
1189 ctx->Pack.SkipRows = 0;
1190 ctx->Pack.SkipImages = 0;
1191 ctx->Pack.SwapBytes = GL_FALSE;
1192 ctx->Pack.LsbFirst = GL_FALSE;
1193 ctx->Unpack.Alignment = 4;
1194 ctx->Unpack.RowLength = 0;
1195 ctx->Unpack.ImageHeight = 0;
1196 ctx->Unpack.SkipPixels = 0;
1197 ctx->Unpack.SkipRows = 0;
1198 ctx->Unpack.SkipImages = 0;
1199 ctx->Unpack.SwapBytes = GL_FALSE;
1200 ctx->Unpack.LsbFirst = GL_FALSE;
1201
1202 /* Feedback */
1203 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1204 ctx->Feedback.Buffer = NULL;
1205 ctx->Feedback.BufferSize = 0;
1206 ctx->Feedback.Count = 0;
1207
1208 /* Selection/picking */
1209 ctx->Select.Buffer = NULL;
1210 ctx->Select.BufferSize = 0;
1211 ctx->Select.BufferCount = 0;
1212 ctx->Select.Hits = 0;
1213 ctx->Select.NameStackDepth = 0;
1214
Brian Paul4d053dd2000-01-14 04:45:47 +00001215 /* Renderer and client attribute stacks */
1216 ctx->AttribStackDepth = 0;
1217 ctx->ClientAttribStackDepth = 0;
1218
Brian Paul13811372000-04-12 00:27:37 +00001219 /* Display list */
1220 ctx->CallDepth = 0;
1221 ctx->ExecuteFlag = GL_TRUE;
1222 ctx->CompileFlag = GL_FALSE;
1223 ctx->CurrentListPtr = NULL;
1224 ctx->CurrentBlock = NULL;
1225 ctx->CurrentListNum = 0;
1226 ctx->CurrentPos = 0;
1227
1228 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001229 _mesa_init_colortable(&ctx->ColorTable);
1230 _mesa_init_colortable(&ctx->ProxyColorTable);
1231 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1232 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1233 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1234 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001235
Brian Paul4d053dd2000-01-14 04:45:47 +00001236 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001237 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001238 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001239 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001240
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001241 ctx->_NeedNormals = 0;
1242 ctx->_NeedEyeCoords = 0;
1243 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001244
Brian Paul4d053dd2000-01-14 04:45:47 +00001245 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1246
1247 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001248 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001249 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001250
1251 /* For debug/development only */
1252 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1253 ctx->FirstTimeCurrent = GL_TRUE;
1254
1255 /* Dither disable */
1256 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1257 if (ctx->NoDither) {
1258 if (getenv("MESA_DEBUG")) {
1259 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001260 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001261 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001262 }
1263}
1264
1265
1266
1267
jtgafb833d1999-08-19 00:55:39 +00001268/*
1269 * Allocate the proxy textures. If we run out of memory part way through
1270 * the allocations clean up and return GL_FALSE.
1271 * Return: GL_TRUE=success, GL_FALSE=failure
1272 */
Brian Paul178a1c52000-04-22 01:05:00 +00001273static GLboolean
1274alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001275{
1276 GLboolean out_of_memory;
1277 GLint i;
1278
Brian Paula8523782000-11-19 23:10:25 +00001279 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001280 if (!ctx->Texture.Proxy1D) {
1281 return GL_FALSE;
1282 }
1283
Brian Paula8523782000-11-19 23:10:25 +00001284 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001285 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001286 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001287 return GL_FALSE;
1288 }
1289
Brian Paula8523782000-11-19 23:10:25 +00001290 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001291 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001292 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1293 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1294 return GL_FALSE;
1295 }
1296
1297 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1298 if (!ctx->Texture.ProxyCubeMap) {
1299 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1300 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1301 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001302 return GL_FALSE;
1303 }
1304
1305 out_of_memory = GL_FALSE;
1306 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001307 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1308 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1309 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001310 if (!ctx->Texture.Proxy1D->Image[i]
1311 || !ctx->Texture.Proxy2D->Image[i]
1312 || !ctx->Texture.Proxy3D->Image[i]) {
1313 out_of_memory = GL_TRUE;
1314 }
1315 }
1316 if (out_of_memory) {
1317 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1318 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001319 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001320 }
1321 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001322 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001323 }
1324 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001325 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001326 }
1327 }
Brian Paula8523782000-11-19 23:10:25 +00001328 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1329 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1330 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001331 return GL_FALSE;
1332 }
1333 else {
1334 return GL_TRUE;
1335 }
1336}
1337
1338
jtgafb833d1999-08-19 00:55:39 +00001339/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001340 * Initialize a GLcontext struct. This includes allocating all the
1341 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001342 */
Brian Paul178a1c52000-04-22 01:05:00 +00001343GLboolean
1344_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001345 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001346 GLcontext *share_list,
1347 void *driver_ctx,
1348 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001349{
Brian Paul5fb84d22000-05-24 15:04:45 +00001350 GLuint dispatchSize;
1351
jtgafb833d1999-08-19 00:55:39 +00001352 (void) direct; /* not used */
1353
jtgafb833d1999-08-19 00:55:39 +00001354 /* misc one-time initializations */
1355 one_time_init();
1356
Brian Paulb1394fa2000-09-26 20:53:53 +00001357 /**
1358 ** OpenGL SI stuff
1359 **/
1360 if (!ctx->imports.malloc) {
1361 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1362 }
1363 /* exports are setup by the device driver */
1364
jtgafb833d1999-08-19 00:55:39 +00001365 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001366 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001367 ctx->DrawBuffer = NULL;
1368 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001369
jtgafb833d1999-08-19 00:55:39 +00001370 if (share_list) {
1371 /* share the group of display lists of another context */
1372 ctx->Shared = share_list->Shared;
1373 }
1374 else {
1375 /* allocate new group of display lists */
1376 ctx->Shared = alloc_shared_state();
1377 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001378 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001379 }
1380 }
Brian Paul9560f052000-01-31 23:11:39 +00001381 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001382 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001383 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001384
Brian Paul4d053dd2000-01-14 04:45:47 +00001385 init_attrib_groups( ctx );
1386
Brian Paulb6bcae52001-01-23 23:39:36 +00001387 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001388 ctx->Color.DrawBuffer = GL_BACK;
1389 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1390 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1391 ctx->Pixel.ReadBuffer = GL_BACK;
1392 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1393 }
1394 else {
1395 ctx->Color.DrawBuffer = GL_FRONT;
1396 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1397 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1398 ctx->Pixel.ReadBuffer = GL_FRONT;
1399 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1400 }
1401
jtgafb833d1999-08-19 00:55:39 +00001402 if (!alloc_proxy_textures(ctx)) {
1403 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001404 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001405 }
jtgafb833d1999-08-19 00:55:39 +00001406
Brian Paulf59afc92000-05-23 23:23:00 +00001407 /* register the most recent extension functions with libGL */
1408 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1409 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1410 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1411 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1412 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1413 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1414 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1415 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1416
Brian Paul5fb84d22000-05-24 15:04:45 +00001417 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1418 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1419 * Mesa we do this to accomodate different versions of libGL and various
1420 * DRI drivers.
1421 */
1422 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1423 sizeof(struct _glapi_table) / sizeof(void *));
1424
Brian Paulfbd8f211999-11-11 01:22:25 +00001425 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001426 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1427 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001428 if (!ctx->Exec || !ctx->Save) {
1429 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001430 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001431 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001432 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001433 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1434 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001435 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001436
Keith Whitwellad2ac212000-11-24 10:25:05 +00001437 ctx->ExecPrefersFloat = GL_FALSE;
1438 ctx->SavePrefersFloat = GL_FALSE;
1439
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001440 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001441 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001442 ctx->TnlModule.Current = NULL;
1443 ctx->TnlModule.SwapCount = 0;
1444
Brian Paulb6bcae52001-01-23 23:39:36 +00001445 /* Z buffer stuff */
1446 if (ctx->Visual.depthBits == 0) {
1447 /* Special case. Even if we don't have a depth buffer we need
1448 * good values for DepthMax for Z vertex transformation purposes
1449 * and for per-fragment fog computation.
1450 */
1451 ctx->DepthMax = 1 << 16;
1452 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1453 }
1454 else if (ctx->Visual.depthBits < 32) {
1455 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1456 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1457 }
1458 else {
1459 /* Special case since shift values greater than or equal to the
1460 * number of bits in the left hand expression's type are undefined.
1461 */
1462 ctx->DepthMax = 0xffffffff;
1463 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1464 }
1465 ctx->MRD = 2.0; /* XXX temporary value */
1466
1467
Brian Paul3b18a362000-09-26 15:27:20 +00001468#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +00001469 ctx->TraceCtx = CALLOC( sizeof(trace_context_t) );
1470#if 0
1471 /* Brian: do you want to have CreateContext fail here,
1472 or should we just trap in NewTrace (currently done)? */
1473 if (!(ctx->TraceCtx)) {
1474 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001475 FREE( ctx->Exec );
1476 FREE( ctx->Save );
1477 return GL_FALSE;
1478 }
1479#endif
1480 trInitContext(ctx->TraceCtx);
1481
1482 ctx->TraceDispatch = (struct _glapi_table *)
1483 CALLOC(dispatchSize * sizeof(void*));
1484#if 0
1485 if (!(ctx->TraceCtx)) {
1486 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001487 FREE( ctx->Exec );
1488 FREE( ctx->Save );
1489 FREE( ctx->TraceCtx );
1490 return GL_FALSE;
1491 }
1492#endif
1493 trInitDispatch(ctx->TraceDispatch);
1494#endif
1495
Brian Paul4d053dd2000-01-14 04:45:47 +00001496 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001497}
1498
jtgafb833d1999-08-19 00:55:39 +00001499
1500
1501/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001502 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001503 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001504 * sharelist - another context to share display lists with or NULL
1505 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001506 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001507 */
Brian Paul178a1c52000-04-22 01:05:00 +00001508GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001509_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001510 GLcontext *share_list,
1511 void *driver_ctx,
1512 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001513{
1514 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1515 if (!ctx) {
1516 return NULL;
1517 }
1518
Brian Paul178a1c52000-04-22 01:05:00 +00001519 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001520 return ctx;
1521 }
1522 else {
1523 FREE(ctx);
1524 return NULL;
1525 }
1526}
1527
1528
1529
1530/*
1531 * Free the data associated with the given context.
1532 * But don't free() the GLcontext struct itself!
1533 */
Brian Paul178a1c52000-04-22 01:05:00 +00001534void
Brian Paulb1394fa2000-09-26 20:53:53 +00001535_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001536{
Brian Paul4d053dd2000-01-14 04:45:47 +00001537 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001538 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001539
1540 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001541 if (ctx == _mesa_get_current_context()) {
1542 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001543 }
1544
Keith Whitwell23caf202000-11-16 21:05:34 +00001545 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001546 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001547 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001548 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001549 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001550 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001551 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001552 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001553 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001554 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001555 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001556 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001557 }
1558 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001559
Brian Paul9560f052000-01-31 23:11:39 +00001560 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001561 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001562 assert(ctx->Shared->RefCount >= 0);
1563 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1564 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001565 /* free shared state */
1566 free_shared_state( ctx, ctx->Shared );
1567 }
1568
Keith Whitwell14940c42000-11-05 18:40:57 +00001569 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001570 FREE( s );
1571 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001572 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001573
1574 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001575 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1576 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1577 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paul4d053dd2000-01-14 04:45:47 +00001578
1579 /* Free evaluator data */
1580 if (ctx->EvalMap.Map1Vertex3.Points)
1581 FREE( ctx->EvalMap.Map1Vertex3.Points );
1582 if (ctx->EvalMap.Map1Vertex4.Points)
1583 FREE( ctx->EvalMap.Map1Vertex4.Points );
1584 if (ctx->EvalMap.Map1Index.Points)
1585 FREE( ctx->EvalMap.Map1Index.Points );
1586 if (ctx->EvalMap.Map1Color4.Points)
1587 FREE( ctx->EvalMap.Map1Color4.Points );
1588 if (ctx->EvalMap.Map1Normal.Points)
1589 FREE( ctx->EvalMap.Map1Normal.Points );
1590 if (ctx->EvalMap.Map1Texture1.Points)
1591 FREE( ctx->EvalMap.Map1Texture1.Points );
1592 if (ctx->EvalMap.Map1Texture2.Points)
1593 FREE( ctx->EvalMap.Map1Texture2.Points );
1594 if (ctx->EvalMap.Map1Texture3.Points)
1595 FREE( ctx->EvalMap.Map1Texture3.Points );
1596 if (ctx->EvalMap.Map1Texture4.Points)
1597 FREE( ctx->EvalMap.Map1Texture4.Points );
1598
1599 if (ctx->EvalMap.Map2Vertex3.Points)
1600 FREE( ctx->EvalMap.Map2Vertex3.Points );
1601 if (ctx->EvalMap.Map2Vertex4.Points)
1602 FREE( ctx->EvalMap.Map2Vertex4.Points );
1603 if (ctx->EvalMap.Map2Index.Points)
1604 FREE( ctx->EvalMap.Map2Index.Points );
1605 if (ctx->EvalMap.Map2Color4.Points)
1606 FREE( ctx->EvalMap.Map2Color4.Points );
1607 if (ctx->EvalMap.Map2Normal.Points)
1608 FREE( ctx->EvalMap.Map2Normal.Points );
1609 if (ctx->EvalMap.Map2Texture1.Points)
1610 FREE( ctx->EvalMap.Map2Texture1.Points );
1611 if (ctx->EvalMap.Map2Texture2.Points)
1612 FREE( ctx->EvalMap.Map2Texture2.Points );
1613 if (ctx->EvalMap.Map2Texture3.Points)
1614 FREE( ctx->EvalMap.Map2Texture3.Points );
1615 if (ctx->EvalMap.Map2Texture4.Points)
1616 FREE( ctx->EvalMap.Map2Texture4.Points );
1617
Brian Paul4bdcfe52000-04-17 17:57:04 +00001618 _mesa_free_colortable_data( &ctx->ColorTable );
1619 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1620 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1621 _mesa_free_colortable_data( &ctx->Texture.Palette );
1622
Brian Paul69755402001-02-26 23:58:12 +00001623 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001624
1625 FREE(ctx->Exec);
1626 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001627}
1628
1629
1630
1631/*
1632 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001633 */
Brian Paul178a1c52000-04-22 01:05:00 +00001634void
Brian Paulb1394fa2000-09-26 20:53:53 +00001635_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001636{
1637 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001638 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001639 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001640 }
1641}
1642
1643
1644
1645/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001646 * Called by the driver after both the context and driver are fully
1647 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001648 */
Brian Paul178a1c52000-04-22 01:05:00 +00001649void
Brian Paulb1394fa2000-09-26 20:53:53 +00001650_mesa_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001651{
Brian Paul08836342001-03-03 20:33:27 +00001652 _mesa_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001653}
1654
1655
1656
1657/*
1658 * Copy attribute groups from one context to another.
1659 * Input: src - source context
1660 * dst - destination context
1661 * mask - bitwise OR of GL_*_BIT flags
1662 */
Brian Paul178a1c52000-04-22 01:05:00 +00001663void
Brian Paulb1394fa2000-09-26 20:53:53 +00001664_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001665{
1666 if (mask & GL_ACCUM_BUFFER_BIT) {
1667 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1668 }
1669 if (mask & GL_COLOR_BUFFER_BIT) {
1670 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1671 }
1672 if (mask & GL_CURRENT_BIT) {
1673 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1674 }
1675 if (mask & GL_DEPTH_BUFFER_BIT) {
1676 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1677 }
1678 if (mask & GL_ENABLE_BIT) {
1679 /* no op */
1680 }
1681 if (mask & GL_EVAL_BIT) {
1682 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1683 }
1684 if (mask & GL_FOG_BIT) {
1685 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1686 }
1687 if (mask & GL_HINT_BIT) {
1688 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1689 }
1690 if (mask & GL_LIGHTING_BIT) {
1691 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001692 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001693 }
1694 if (mask & GL_LINE_BIT) {
1695 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1696 }
1697 if (mask & GL_LIST_BIT) {
1698 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1699 }
1700 if (mask & GL_PIXEL_MODE_BIT) {
1701 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1702 }
1703 if (mask & GL_POINT_BIT) {
1704 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1705 }
1706 if (mask & GL_POLYGON_BIT) {
1707 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1708 }
1709 if (mask & GL_POLYGON_STIPPLE_BIT) {
1710 /* Use loop instead of MEMCPY due to problem with Portland Group's
1711 * C compiler. Reported by John Stone.
1712 */
1713 int i;
1714 for (i=0;i<32;i++) {
1715 dst->PolygonStipple[i] = src->PolygonStipple[i];
1716 }
1717 }
1718 if (mask & GL_SCISSOR_BIT) {
1719 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1720 }
1721 if (mask & GL_STENCIL_BUFFER_BIT) {
1722 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1723 }
1724 if (mask & GL_TEXTURE_BIT) {
1725 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1726 }
1727 if (mask & GL_TRANSFORM_BIT) {
1728 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1729 }
1730 if (mask & GL_VIEWPORT_BIT) {
1731 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1732 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001733 /* XXX FIXME: Call callbacks?
1734 */
1735 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001736}
1737
1738
jtgafb833d1999-08-19 00:55:39 +00001739/*
Brian Paul00037781999-12-17 14:52:35 +00001740 * Set the current context, binding the given frame buffer to the context.
1741 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001742void
1743_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001744{
Brian Paulb1394fa2000-09-26 20:53:53 +00001745 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001746}
1747
1748
Keith Whitwell23caf202000-11-16 21:05:34 +00001749static void print_info( void )
1750{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001751 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001752 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001753 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001754 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001755 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001756 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001757 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001758 (char *) _mesa_GetString(GL_EXTENSIONS));
1759#if defined(THREADS)
1760 fprintf(stderr, "Mesa thread-safe: YES\n");
1761#else
1762 fprintf(stderr, "Mesa thread-safe: NO\n");
1763#endif
1764#if defined(USE_X86_ASM)
1765 fprintf(stderr, "Mesa x86-optimized: YES\n");
1766#else
1767 fprintf(stderr, "Mesa x86-optimized: NO\n");
1768#endif
1769}
1770
1771
Brian Paul00037781999-12-17 14:52:35 +00001772/*
1773 * Bind the given context to the given draw-buffer and read-buffer
1774 * and make it the current context for this thread.
1775 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001776void
1777_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1778 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001779{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001780 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001781 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001782
Brian Paulbe3602d2001-02-28 00:27:48 +00001783 /* Check that the context's and framebuffer's visuals are compatible.
1784 * We could do a lot more checking here but this'll catch obvious
1785 * problems.
1786 */
1787 if (newCtx && drawBuffer && readBuffer) {
1788 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1789 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1790 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1791 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1792 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1793 return; /* incompatible */
1794 }
1795 }
1796
Brian Paul00037781999-12-17 14:52:35 +00001797 /* We call this function periodically (just here for now) in
1798 * order to detect when multithreading has begun.
1799 */
1800 _glapi_check_multithread();
1801
Brian Paulf9b97d92000-01-28 20:17:42 +00001802 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001803 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001804
1805
1806 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001807 _glapi_set_dispatch(NULL); /* none current */
1808 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001809 else {
1810 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001811
Keith Whitwell23caf202000-11-16 21:05:34 +00001812 if (drawBuffer && readBuffer) {
1813 /* TODO: check if newCtx and buffer's visual match??? */
1814 newCtx->DrawBuffer = drawBuffer;
1815 newCtx->ReadBuffer = readBuffer;
1816 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001817 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001818 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001819
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001820 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001821 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1822
1823 /* We can use this to help debug user's problems. Tell them to set
1824 * the MESA_INFO env variable before running their app. Then the
1825 * first time each context is made current we'll print some useful
1826 * information.
1827 */
1828 if (newCtx->FirstTimeCurrent) {
1829 if (getenv("MESA_INFO")) {
1830 print_info();
1831 }
1832 newCtx->FirstTimeCurrent = GL_FALSE;
1833 }
Brian Paul00037781999-12-17 14:52:35 +00001834 }
1835}
1836
1837
1838
1839/*
1840 * Return current context handle for the calling thread.
1841 * This isn't the fastest way to get the current context.
1842 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1843 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001844GLcontext *
1845_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001846{
Brian Paulf9b97d92000-01-28 20:17:42 +00001847 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001848}
1849
1850
1851
1852/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001853 * This should be called by device drivers just before they do a
1854 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001855 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001856void
1857_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001858{
Keith Whitwellcab974c2000-12-26 05:09:27 +00001859 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00001860}
1861
1862
Brian Paul00037781999-12-17 14:52:35 +00001863
Brian Paulfbd8f211999-11-11 01:22:25 +00001864/*
1865 * Return pointer to this context's current API dispatch table.
1866 * It'll either be the immediate-mode execute dispatcher or the
1867 * display list compile dispatcher.
1868 */
1869struct _glapi_table *
1870_mesa_get_dispatch(GLcontext *ctx)
1871{
1872 return ctx->CurrentDispatch;
1873}
1874
1875
1876
jtgafb833d1999-08-19 00:55:39 +00001877/**********************************************************************/
1878/***** Miscellaneous functions *****/
1879/**********************************************************************/
1880
1881
1882/*
1883 * This function is called when the Mesa user has stumbled into a code
1884 * path which may not be implemented fully or correctly.
1885 */
Brian Paul08836342001-03-03 20:33:27 +00001886void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001887{
1888 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paul413d6a22000-05-26 14:44:59 +00001889 fprintf( stderr, "Report to Mesa bug database at www.mesa3d.org\n" );
jtgafb833d1999-08-19 00:55:39 +00001890 (void) ctx;
1891}
1892
1893
1894
1895/*
1896 * This is called to inform the user that he or she has tried to do
1897 * something illogical or if there's likely a bug in their program
1898 * (like enabled depth testing without a depth buffer).
1899 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001900void
1901_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001902{
Brian Paulb1394fa2000-09-26 20:53:53 +00001903 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001904}
1905
1906
1907
Brian Paulfa9df402000-02-02 19:16:46 +00001908/*
1909 * Compile an error into current display list.
1910 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001911void
1912_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001913{
1914 if (ctx->CompileFlag)
Brian Paul08836342001-03-03 20:33:27 +00001915 _mesa_save_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001916
1917 if (ctx->ExecuteFlag)
Brian Paul08836342001-03-03 20:33:27 +00001918 _mesa_error( ctx, error, s );
jtgafb833d1999-08-19 00:55:39 +00001919}
1920
1921
Brian Paulfa9df402000-02-02 19:16:46 +00001922
jtgafb833d1999-08-19 00:55:39 +00001923/*
1924 * This is Mesa's error handler. Normally, all that's done is the updating
1925 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1926 * environment variable "MESA_DEBUG" is defined then a real error message
1927 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001928 * Input: ctx - the GL context
1929 * error - the error value
1930 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001931 */
Brian Paul7eb06032000-07-14 04:13:40 +00001932void
Brian Paul08836342001-03-03 20:33:27 +00001933_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001934{
Brian Paul7eb06032000-07-14 04:13:40 +00001935 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001936 GLboolean debug;
1937
1938#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00001939 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00001940 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00001941 else
1942 debug = GL_TRUE;
1943#else
1944 if (debugEnv)
1945 debug = GL_TRUE;
1946 else
1947 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001948#endif
1949
1950 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00001951 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00001952 switch (error) {
1953 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00001954 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00001955 break;
1956 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00001957 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00001958 break;
1959 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00001960 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00001961 break;
1962 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00001963 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00001964 break;
1965 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001966 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001967 break;
1968 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00001969 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00001970 break;
1971 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00001972 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00001973 break;
Brian Paul86586aa2000-06-29 18:55:52 +00001974 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00001975 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00001976 break;
jtgafb833d1999-08-19 00:55:39 +00001977 default:
Brian Paul7eb06032000-07-14 04:13:40 +00001978 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00001979 break;
1980 }
Brian Paul7eb06032000-07-14 04:13:40 +00001981 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00001982 }
1983
Brian Paul7eb06032000-07-14 04:13:40 +00001984 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00001985 ctx->ErrorValue = error;
1986 }
1987
1988 /* Call device driver's error handler, if any. This is used on the Mac. */
1989 if (ctx->Driver.Error) {
1990 (*ctx->Driver.Error)( ctx );
1991 }
1992}
1993
1994
1995
Brian Paulfa9df402000-02-02 19:16:46 +00001996void
1997_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00001998{
Brian Paulfa9df402000-02-02 19:16:46 +00001999 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002000 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002001 if (ctx->Driver.Finish) {
2002 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002003 }
2004}
2005
2006
2007
Brian Paulfa9df402000-02-02 19:16:46 +00002008void
2009_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002010{
Brian Paulfa9df402000-02-02 19:16:46 +00002011 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002012 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002013 if (ctx->Driver.Flush) {
2014 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002015 }
jtgafb833d1999-08-19 00:55:39 +00002016}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002017
2018
2019
Keith Whitwellcab974c2000-12-26 05:09:27 +00002020const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002021 "GL_POINTS",
2022 "GL_LINES",
2023 "GL_LINE_LOOP",
2024 "GL_LINE_STRIP",
2025 "GL_TRIANGLES",
2026 "GL_TRIANGLE_STRIP",
2027 "GL_TRIANGLE_FAN",
2028 "GL_QUADS",
2029 "GL_QUAD_STRIP",
2030 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002031 "outside begin/end",
2032 "inside unkown primitive",
2033 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002034};
2035
Brian Paul1c56fdc2000-09-17 21:56:07 +00002036
2037GLenum gl_reduce_prim[GL_POLYGON+1] = {
2038 GL_POINTS,
2039 GL_LINES,
2040 GL_LINES,
2041 GL_LINES,
2042 GL_TRIANGLES,
2043 GL_TRIANGLES,
2044 GL_TRIANGLES,
2045 GL_TRIANGLES,
2046 GL_TRIANGLES,
2047 GL_TRIANGLES,
Gareth Hughesfc2427e2000-10-23 00:16:28 +00002048};