blob: 170bb37e8c6fc57b434811b53f959772243ba3bf [file] [log] [blame]
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001/* $Id: context.c,v 1.108 2000/11/22 07:32:16 joukj 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 Paul54287052000-01-17 20:00:15 +00007 * Copyright (C) 1999-2000 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"
jtgafb833d1999-08-19 00:55:39 +000054#include "texture.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000055#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000056#include "varray.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"
62#include "math/math.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 */
80/* | VERBOSE_CULL */
81/* | 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
91/**********************************************************************/
92/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
93/**********************************************************************/
94
95static GLboolean
96_mesa_DestroyContext(__GLcontext *gc)
97{
98 if (gc) {
99 _mesa_free_context_data(gc);
100 (*gc->imports.free)(gc, gc);
101 }
102 return GL_TRUE;
103}
104
105
106/* exported OpenGL SI interface */
107__GLcontext *
108__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
109{
110 GLcontext *ctx;
111
112 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
113 if (ctx == NULL) {
114 return NULL;
115 }
116 ctx->imports = *imports;
117
118 _mesa_initialize_visual(&ctx->Visual,
119 modes->rgbMode,
120 modes->doubleBufferMode,
121 modes->stereoMode,
122 modes->redBits,
123 modes->greenBits,
124 modes->blueBits,
125 modes->alphaBits,
126 modes->indexBits,
127 modes->depthBits,
128 modes->stencilBits,
129 modes->accumRedBits,
130 modes->accumGreenBits,
131 modes->accumBlueBits,
132 modes->accumAlphaBits,
133 0);
134
135 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->wscx, GL_FALSE);
136
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{
242 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000243
Brian Pauled30dfa2000-03-03 17:47:39 +0000244 /* This is to catch bad values from device drivers not updated for
245 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
246 * bad value now (a 1-bit depth buffer!?!).
247 */
248 assert(depthBits == 0 || depthBits > 1);
249
250 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000251 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000252 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000253 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000254 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000255 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000256 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000257 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000258 }
259 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000260 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000261 }
262 if (accumBlueBits < 0 || accumBlueBits > (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 (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000266 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000267 }
268
269 vis->RGBAflag = rgbFlag;
270 vis->DBflag = dbFlag;
271 vis->StereoFlag = stereoFlag;
272 vis->RedBits = redBits;
273 vis->GreenBits = greenBits;
274 vis->BlueBits = blueBits;
Brian Paule70c6232000-05-04 13:53:55 +0000275 vis->AlphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000276
Brian Paulb371e0d2000-03-31 01:05:51 +0000277 vis->IndexBits = indexBits;
278 vis->DepthBits = depthBits;
279 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
280 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
281 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
282 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
283 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000284
Brian Pauled30dfa2000-03-03 17:47:39 +0000285 if (depthBits == 0) {
286 /* Special case. Even if we don't have a depth buffer we need
Brian Paul35324a62000-10-09 22:42:40 +0000287 * good values for DepthMax for Z vertex transformation purposes
288 * and for per-fragment fog computation.
Brian Pauled30dfa2000-03-03 17:47:39 +0000289 */
Brian Paul35324a62000-10-09 22:42:40 +0000290 vis->DepthMax = 1 << 16;
291 vis->DepthMaxF = (GLfloat) vis->DepthMax;
Brian Pauled30dfa2000-03-03 17:47:39 +0000292 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000293 else if (depthBits < 32) {
Brian Pauled30dfa2000-03-03 17:47:39 +0000294 vis->DepthMax = (1 << depthBits) - 1;
295 vis->DepthMaxF = (GLfloat) vis->DepthMax;
296 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000297 else {
298 /* Special case since shift values greater than or equal to the
299 * number of bits in the left hand expression's type are
300 * undefined.
301 */
302 vis->DepthMax = 0xffffffff;
303 vis->DepthMaxF = (GLfloat) vis->DepthMax;
304 }
Brian Pauld0d7d622000-10-21 00:02:47 +0000305 vis->MRD = 1; /* XXX temporary value */
Brian Pauled30dfa2000-03-03 17:47:39 +0000306
Brian Paul178a1c52000-04-22 01:05:00 +0000307 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000308}
309
310
Brian Paulb371e0d2000-03-31 01:05:51 +0000311void
312_mesa_destroy_visual( GLvisual *vis )
313{
314 FREE(vis);
315}
316
317
Brian Paul4d053dd2000-01-14 04:45:47 +0000318/**********************************************************************/
319/***** GL Framebuffer allocation/destruction *****/
320/**********************************************************************/
321
322
323/*
324 * Create a new framebuffer. A GLframebuffer is a struct which
325 * encapsulates the depth, stencil and accum buffers and related
326 * parameters.
327 * Input: visual - a GLvisual pointer
328 * softwareDepth - create/use a software depth buffer?
329 * softwareStencil - create/use a software stencil buffer?
330 * softwareAccum - create/use a software accum buffer?
331 * softwareAlpha - create/use a software alpha buffer?
332
333 * Return: pointer to new GLframebuffer struct or NULL if error.
334 */
Brian Paul178a1c52000-04-22 01:05:00 +0000335GLframebuffer *
Brian Paulb1394fa2000-09-26 20:53:53 +0000336_mesa_create_framebuffer( GLvisual *visual,
337 GLboolean softwareDepth,
338 GLboolean softwareStencil,
339 GLboolean softwareAccum,
340 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000341{
Brian Paul178a1c52000-04-22 01:05:00 +0000342 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
343 assert(visual);
344 if (buffer) {
345 _mesa_initialize_framebuffer(buffer, visual,
346 softwareDepth, softwareStencil,
347 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000348 }
Brian Paul178a1c52000-04-22 01:05:00 +0000349 return buffer;
350}
351
352
353/*
354 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000355 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000356 */
357void
358_mesa_initialize_framebuffer( GLframebuffer *buffer,
359 GLvisual *visual,
360 GLboolean softwareDepth,
361 GLboolean softwareStencil,
362 GLboolean softwareAccum,
363 GLboolean softwareAlpha )
364{
365 assert(buffer);
366 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000367
368 /* sanity checks */
369 if (softwareDepth ) {
370 assert(visual->DepthBits > 0);
371 }
372 if (softwareStencil) {
373 assert(visual->StencilBits > 0);
374 }
375 if (softwareAccum) {
376 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000377 assert(visual->AccumRedBits > 0);
378 assert(visual->AccumGreenBits > 0);
379 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000380 }
381 if (softwareAlpha) {
382 assert(visual->RGBAflag);
383 assert(visual->AlphaBits > 0);
384 }
385
386 buffer->Visual = visual;
387 buffer->UseSoftwareDepthBuffer = softwareDepth;
388 buffer->UseSoftwareStencilBuffer = softwareStencil;
389 buffer->UseSoftwareAccumBuffer = softwareAccum;
390 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000391}
392
393
Brian Paul4d053dd2000-01-14 04:45:47 +0000394/*
395 * Free a framebuffer struct and its buffers.
396 */
Brian Paul178a1c52000-04-22 01:05:00 +0000397void
Brian Paulb1394fa2000-09-26 20:53:53 +0000398_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000399{
400 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000401 if (buffer->DepthBuffer) {
402 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000403 }
404 if (buffer->Accum) {
405 FREE( buffer->Accum );
406 }
407 if (buffer->Stencil) {
408 FREE( buffer->Stencil );
409 }
410 if (buffer->FrontLeftAlpha) {
411 FREE( buffer->FrontLeftAlpha );
412 }
413 if (buffer->BackLeftAlpha) {
414 FREE( buffer->BackLeftAlpha );
415 }
416 if (buffer->FrontRightAlpha) {
417 FREE( buffer->FrontRightAlpha );
418 }
419 if (buffer->BackRightAlpha) {
420 FREE( buffer->BackRightAlpha );
421 }
422 FREE(buffer);
423 }
424}
425
426
427
428/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000429/***** Context allocation, initialization, destroying *****/
430/**********************************************************************/
431
432
Brian Paul9560f052000-01-31 23:11:39 +0000433_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
434
435
jtgafb833d1999-08-19 00:55:39 +0000436/*
437 * This function just calls all the various one-time-init functions in Mesa.
438 */
Brian Paul178a1c52000-04-22 01:05:00 +0000439static void
440one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000441{
442 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000443 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000444 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000445 /* do some implementation tests */
446 assert( sizeof(GLbyte) == 1 );
447 assert( sizeof(GLshort) >= 2 );
448 assert( sizeof(GLint) >= 4 );
449 assert( sizeof(GLubyte) == 1 );
450 assert( sizeof(GLushort) >= 2 );
451 assert( sizeof(GLuint) >= 4 );
452
jtgafb833d1999-08-19 00:55:39 +0000453 gl_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000454
455 _mesa_init_math();
456 _math_init();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000457
458 if (getenv("MESA_DEBUG")) {
459 _glapi_noop_enable_warnings(GL_TRUE);
460 }
461 else {
462 _glapi_noop_enable_warnings(GL_FALSE);
463 }
464
jtgafb833d1999-08-19 00:55:39 +0000465#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
466 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
467#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000468
469 alreadyCalled = GL_TRUE;
470 }
Brian Paul9560f052000-01-31 23:11:39 +0000471 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000472}
473
474
Brian Paul4d053dd2000-01-14 04:45:47 +0000475
jtgafb833d1999-08-19 00:55:39 +0000476/*
477 * Allocate and initialize a shared context state structure.
478 */
Brian Paul178a1c52000-04-22 01:05:00 +0000479static struct gl_shared_state *
480alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000481{
jtgafb833d1999-08-19 00:55:39 +0000482 struct gl_shared_state *ss;
483 GLboolean outOfMemory;
484
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000485 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000486 if (!ss)
487 return NULL;
488
Brian Paule4b684c2000-09-12 21:07:40 +0000489 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000490
Brian Paule4b684c2000-09-12 21:07:40 +0000491 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000492 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000493
494 /* Default Texture objects */
495 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000496
497 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
498 if (!ss->Default1D) {
499 outOfMemory = GL_TRUE;
500 }
501 else {
502 ss->Default1D->RefCount++;
jtgafb833d1999-08-19 00:55:39 +0000503 }
504
Brian Paula8523782000-11-19 23:10:25 +0000505 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
506 if (!ss->Default2D) {
507 outOfMemory = GL_TRUE;
508 }
509 else {
510 ss->Default2D->RefCount++;
511 }
512
513 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
514 if (!ss->Default3D) {
515 outOfMemory = GL_TRUE;
516 }
517 else {
518 ss->Default1D->RefCount++;
519 }
520
521 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000522 if (!ss->DefaultCubeMap) {
523 outOfMemory = GL_TRUE;
524 }
525 else {
526 ss->DefaultCubeMap->RefCount++;
527 }
528
jtgafb833d1999-08-19 00:55:39 +0000529 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
530 /* Ran out of memory at some point. Free everything and return NULL */
531 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000532 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000533 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000534 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paula8523782000-11-19 23:10:25 +0000535 if (ss->Default1D)
536 _mesa_free_texture_object(ss, ss->Default1D);
537 if (ss->Default2D)
538 _mesa_free_texture_object(ss, ss->Default2D);
539 if (ss->Default3D)
540 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000541 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000542 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000543 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000544 return NULL;
545 }
546 else {
547 return ss;
548 }
549}
550
551
552/*
553 * Deallocate a shared state context and all children structures.
554 */
Brian Paul178a1c52000-04-22 01:05:00 +0000555static void
556free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000557{
558 /* Free display lists */
559 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000560 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000561 if (list) {
562 gl_destroy_list(ctx, list);
563 }
564 else {
565 break;
566 }
567 }
Brian Paulbb797902000-01-24 16:19:54 +0000568 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000569
570 /* Free texture objects */
571 while (ss->TexObjectList)
572 {
573 if (ctx->Driver.DeleteTexture)
574 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
575 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000576 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000577 }
Brian Paulbb797902000-01-24 16:19:54 +0000578 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000579
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000580 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000581}
582
583
584
jtgafb833d1999-08-19 00:55:39 +0000585/*
586 * Initialize the nth light. Note that the defaults for light 0 are
587 * different than the other lights.
588 */
Brian Paul178a1c52000-04-22 01:05:00 +0000589static void
590init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000591{
592 make_empty_list( l );
593
594 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
595 if (n==0) {
596 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
597 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
598 }
599 else {
600 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
601 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
602 }
603 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
604 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
605 l->SpotExponent = 0.0;
606 gl_compute_spot_exp_table( l );
607 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000608 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000609 l->ConstantAttenuation = 1.0;
610 l->LinearAttenuation = 0.0;
611 l->QuadraticAttenuation = 0.0;
612 l->Enabled = GL_FALSE;
613}
614
615
616
Brian Paul178a1c52000-04-22 01:05:00 +0000617static void
618init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000619{
620 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
621 lm->LocalViewer = GL_FALSE;
622 lm->TwoSide = GL_FALSE;
623 lm->ColorControl = GL_SINGLE_COLOR;
624}
625
626
Brian Paul178a1c52000-04-22 01:05:00 +0000627static void
628init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000629{
630 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
631 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
632 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
633 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
634 m->Shininess = 0.0;
635 m->AmbientIndex = 0;
636 m->DiffuseIndex = 1;
637 m->SpecularIndex = 1;
638}
639
640
641
Brian Paul178a1c52000-04-22 01:05:00 +0000642static void
643init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000644{
645 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
646
647 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000648 texUnit->CombineModeRGB = GL_MODULATE;
649 texUnit->CombineModeA = GL_MODULATE;
650 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
651 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
652 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
653 texUnit->CombineSourceA[0] = GL_TEXTURE;
654 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
655 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
656 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
657 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
658 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
659 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
660 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
661 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
662 texUnit->CombineScaleShiftRGB = 0;
663 texUnit->CombineScaleShiftA = 0;
664
jtgafb833d1999-08-19 00:55:39 +0000665 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
666 texUnit->TexGenEnabled = 0;
667 texUnit->GenModeS = GL_EYE_LINEAR;
668 texUnit->GenModeT = GL_EYE_LINEAR;
669 texUnit->GenModeR = GL_EYE_LINEAR;
670 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000671 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
672 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
673 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
674 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000675
jtgafb833d1999-08-19 00:55:39 +0000676 /* Yes, these plane coefficients are correct! */
677 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
678 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
679 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
680 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
681 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
682 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
683 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
684 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
685
Brian Paula8523782000-11-19 23:10:25 +0000686 texUnit->Current1D = ctx->Shared->Default1D;
687 texUnit->Current2D = ctx->Shared->Default2D;
688 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000689 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000690}
691
692
Brian Paul178a1c52000-04-22 01:05:00 +0000693static void
694init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000695{
696 struct gl_client_array *cl;
697 GLuint i;
698
699 cl = &ctx->Fallback.Normal;
700 cl->Size = 3;
701 cl->Type = GL_FLOAT;
702 cl->Stride = 0;
703 cl->StrideB = 0;
704 cl->Ptr = (void *) ctx->Current.Normal;
705 cl->Enabled = 1;
706
707 cl = &ctx->Fallback.Color;
708 cl->Size = 4;
709 cl->Type = GL_UNSIGNED_BYTE;
710 cl->Stride = 0;
711 cl->StrideB = 0;
Brian Paul19300532000-10-29 19:02:23 +0000712 cl->Ptr = (void *) ctx->Current.Color;
jtgafb833d1999-08-19 00:55:39 +0000713 cl->Enabled = 1;
714
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000715 cl = &ctx->Fallback.SecondaryColor;
716 cl->Size = 3;
717 cl->Type = GL_UNSIGNED_BYTE;
718 cl->Stride = 0;
719 cl->StrideB = 0;
720 cl->Ptr = (void *) ctx->Current.SecondaryColor;
721 cl->Enabled = 1;
722
723 cl = &ctx->Fallback.FogCoord;
724 cl->Size = 1;
725 cl->Type = GL_FLOAT;
726 cl->Stride = 0;
727 cl->StrideB = 0;
728 cl->Ptr = (void *) &ctx->Current.FogCoord;
729 cl->Enabled = 1;
730
jtgafb833d1999-08-19 00:55:39 +0000731 cl = &ctx->Fallback.Index;
732 cl->Size = 1;
733 cl->Type = GL_UNSIGNED_INT;
734 cl->Stride = 0;
735 cl->StrideB = 0;
736 cl->Ptr = (void *) &ctx->Current.Index;
737 cl->Enabled = 1;
738
739 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
740 cl = &ctx->Fallback.TexCoord[i];
741 cl->Size = 4;
742 cl->Type = GL_FLOAT;
743 cl->Stride = 0;
744 cl->StrideB = 0;
745 cl->Ptr = (void *) ctx->Current.Texcoord[i];
746 cl->Enabled = 1;
747 }
748
749 cl = &ctx->Fallback.EdgeFlag;
750 cl->Size = 1;
751 cl->Type = GL_UNSIGNED_BYTE;
752 cl->Stride = 0;
753 cl->StrideB = 0;
754 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
755 cl->Enabled = 1;
756}
757
Brian Paul4d053dd2000-01-14 04:45:47 +0000758
jtgafb833d1999-08-19 00:55:39 +0000759/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000760static void
761init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000762{
763 map->Order = 1;
764 map->u1 = 0.0;
765 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000766 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000767 if (map->Points) {
768 GLint i;
769 for (i=0;i<n;i++)
770 map->Points[i] = initial[i];
771 }
jtgafb833d1999-08-19 00:55:39 +0000772}
773
774
775/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000776static void
777init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000778{
779 map->Uorder = 1;
780 map->Vorder = 1;
781 map->u1 = 0.0;
782 map->u2 = 1.0;
783 map->v1 = 0.0;
784 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000785 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000786 if (map->Points) {
787 GLint i;
788 for (i=0;i<n;i++)
789 map->Points[i] = initial[i];
790 }
jtgafb833d1999-08-19 00:55:39 +0000791}
792
793
jtgafb833d1999-08-19 00:55:39 +0000794/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000795 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000796 */
Brian Paul178a1c52000-04-22 01:05:00 +0000797static void
798init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000799{
800 GLuint i, j;
801
Brian Paul4d053dd2000-01-14 04:45:47 +0000802 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000803
Brian Paul539cce52000-02-03 19:40:07 +0000804 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000805 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
806 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000807 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000808 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
809 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000810 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
811 ctx->Const.MinPointSize = MIN_POINT_SIZE;
812 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
813 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
814 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
815 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
816 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
817 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
818 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
819 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
820 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
821 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000822 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000823 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
824 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000825 ctx->Const.NumCompressedTextureFormats = 0;
jtgafb833d1999-08-19 00:55:39 +0000826
Brian Paul4d053dd2000-01-14 04:45:47 +0000827 /* Modelview matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000828 _math_matrix_ctr( &ctx->ModelView );
829 _math_matrix_alloc_inv( &ctx->ModelView );
Brian Paul4d053dd2000-01-14 04:45:47 +0000830
831 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000832 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000833 _math_matrix_ctr( &ctx->ModelViewStack[i] );
834 _math_matrix_alloc_inv( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000835 }
836
837 /* Projection matrix - need inv for user clipping in clip space*/
Keith Whitwell23caf202000-11-16 21:05:34 +0000838 _math_matrix_ctr( &ctx->ProjectionMatrix );
839 _math_matrix_alloc_inv( &ctx->ProjectionMatrix );
Brian Paul4d053dd2000-01-14 04:45:47 +0000840
841 ctx->ProjectionStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000842 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000843 _math_matrix_ctr( &ctx->ProjectionStack[i] );
844 _math_matrix_alloc_inv( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000845 }
846
Keith Whitwell23caf202000-11-16 21:05:34 +0000847 /* Derived ModelProject matrix */
848 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
849
Brian Paul4d053dd2000-01-14 04:45:47 +0000850 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000851 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000852 _math_matrix_ctr( &ctx->TextureMatrix[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000853 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000854 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000855 _math_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000856 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000857 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000858 }
jtgafb833d1999-08-19 00:55:39 +0000859
Brian Paul250069d2000-04-08 18:57:45 +0000860 /* Color matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000861 _math_matrix_ctr(&ctx->ColorMatrix);
Brian Paul250069d2000-04-08 18:57:45 +0000862 ctx->ColorStackDepth = 0;
863 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000864 _math_matrix_ctr(&ctx->ColorStack[j]);
Brian Paul250069d2000-04-08 18:57:45 +0000865 }
866
Brian Paul4d053dd2000-01-14 04:45:47 +0000867 /* Accumulate buffer group */
868 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000869
Brian Paul4d053dd2000-01-14 04:45:47 +0000870 /* Color buffer group */
871 ctx->Color.IndexMask = 0xffffffff;
872 ctx->Color.ColorMask[0] = 0xff;
873 ctx->Color.ColorMask[1] = 0xff;
874 ctx->Color.ColorMask[2] = 0xff;
875 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000876 ctx->Color.ClearIndex = 0;
877 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
878 ctx->Color.DrawBuffer = GL_FRONT;
879 ctx->Color.AlphaEnabled = GL_FALSE;
880 ctx->Color.AlphaFunc = GL_ALWAYS;
881 ctx->Color.AlphaRef = 0;
882 ctx->Color.BlendEnabled = GL_FALSE;
883 ctx->Color.BlendSrcRGB = GL_ONE;
884 ctx->Color.BlendDstRGB = GL_ZERO;
885 ctx->Color.BlendSrcA = GL_ONE;
886 ctx->Color.BlendDstA = GL_ZERO;
887 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000888 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
889 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
890 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000891 ctx->Color.LogicOp = GL_COPY;
892 ctx->Color.DitherFlag = GL_TRUE;
893 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000894
Brian Paul4d053dd2000-01-14 04:45:47 +0000895 /* Current group */
Brian Paul19300532000-10-29 19:02:23 +0000896 ASSIGN_4V( ctx->Current.Color, CHAN_MAX, CHAN_MAX, CHAN_MAX, CHAN_MAX );
Brian Paul4d053dd2000-01-14 04:45:47 +0000897 ctx->Current.Index = 1;
898 for (i=0; i<MAX_TEXTURE_UNITS; i++)
899 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
900 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
901 ctx->Current.RasterDistance = 0.0;
902 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
903 ctx->Current.RasterIndex = 1;
904 for (i=0; i<MAX_TEXTURE_UNITS; i++)
905 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
906 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
907 ctx->Current.RasterPosValid = GL_TRUE;
908 ctx->Current.EdgeFlag = GL_TRUE;
909 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
jtgafb833d1999-08-19 00:55:39 +0000910
Brian Paul4d053dd2000-01-14 04:45:47 +0000911 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000912
Brian Paul4d053dd2000-01-14 04:45:47 +0000913 /* Depth buffer group */
914 ctx->Depth.Test = GL_FALSE;
915 ctx->Depth.Clear = 1.0;
916 ctx->Depth.Func = GL_LESS;
917 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000918 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000919
Brian Paul4d053dd2000-01-14 04:45:47 +0000920 /* Evaluators group */
921 ctx->Eval.Map1Color4 = GL_FALSE;
922 ctx->Eval.Map1Index = GL_FALSE;
923 ctx->Eval.Map1Normal = GL_FALSE;
924 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
925 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
926 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
927 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
928 ctx->Eval.Map1Vertex3 = GL_FALSE;
929 ctx->Eval.Map1Vertex4 = GL_FALSE;
930 ctx->Eval.Map2Color4 = GL_FALSE;
931 ctx->Eval.Map2Index = GL_FALSE;
932 ctx->Eval.Map2Normal = GL_FALSE;
933 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
934 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
935 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
936 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
937 ctx->Eval.Map2Vertex3 = GL_FALSE;
938 ctx->Eval.Map2Vertex4 = GL_FALSE;
939 ctx->Eval.AutoNormal = GL_FALSE;
940 ctx->Eval.MapGrid1un = 1;
941 ctx->Eval.MapGrid1u1 = 0.0;
942 ctx->Eval.MapGrid1u2 = 1.0;
943 ctx->Eval.MapGrid2un = 1;
944 ctx->Eval.MapGrid2vn = 1;
945 ctx->Eval.MapGrid2u1 = 0.0;
946 ctx->Eval.MapGrid2u2 = 1.0;
947 ctx->Eval.MapGrid2v1 = 0.0;
948 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000949
Brian Paul4d053dd2000-01-14 04:45:47 +0000950 /* Evaluator data */
951 {
952 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
953 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
954 static GLfloat index[1] = { 1.0 };
955 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
956 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000957
Brian Paul4d053dd2000-01-14 04:45:47 +0000958 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
959 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
960 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
961 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
962 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
963 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
964 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
965 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
966 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000967
Brian Paul4d053dd2000-01-14 04:45:47 +0000968 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
969 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
970 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
971 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
972 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
973 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
974 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
975 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
976 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
977 }
jtgafb833d1999-08-19 00:55:39 +0000978
Brian Paul4d053dd2000-01-14 04:45:47 +0000979 /* Fog group */
980 ctx->Fog.Enabled = GL_FALSE;
981 ctx->Fog.Mode = GL_EXP;
982 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
983 ctx->Fog.Index = 0.0;
984 ctx->Fog.Density = 1.0;
985 ctx->Fog.Start = 0.0;
986 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000987 ctx->Fog.ColorSumEnabled = GL_FALSE;
988 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000989
Brian Paul4d053dd2000-01-14 04:45:47 +0000990 /* Hint group */
991 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
992 ctx->Hint.PointSmooth = GL_DONT_CARE;
993 ctx->Hint.LineSmooth = GL_DONT_CARE;
994 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
995 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000996 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000997 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000998 ctx->Hint.AllowDrawMem = GL_TRUE;
999 ctx->Hint.StrictLighting = GL_TRUE;
Brian Paul1207bf02000-05-23 20:10:49 +00001000 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
1001 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +00001002
Brian Paul0771d152000-04-07 00:19:41 +00001003 /* Histogram group */
1004 ctx->Histogram.Width = 0;
1005 ctx->Histogram.Format = GL_RGBA;
1006 ctx->Histogram.Sink = GL_FALSE;
1007 ctx->Histogram.RedSize = 0xffffffff;
1008 ctx->Histogram.GreenSize = 0xffffffff;
1009 ctx->Histogram.BlueSize = 0xffffffff;
1010 ctx->Histogram.AlphaSize = 0xffffffff;
1011 ctx->Histogram.LuminanceSize = 0xffffffff;
1012 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
1013 ctx->Histogram.Count[i][0] = 0;
1014 ctx->Histogram.Count[i][1] = 0;
1015 ctx->Histogram.Count[i][2] = 0;
1016 ctx->Histogram.Count[i][3] = 0;
1017 }
1018
1019 /* Min/Max group */
1020 ctx->MinMax.Format = GL_RGBA;
1021 ctx->MinMax.Sink = GL_FALSE;
1022 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
1023 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
1024 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
1025 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
1026
Brian Paul4d053dd2000-01-14 04:45:47 +00001027 /* Extensions */
1028 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +00001029
Brian Paul4d053dd2000-01-14 04:45:47 +00001030 /* Lighting group */
1031 for (i=0;i<MAX_LIGHTS;i++) {
1032 init_light( &ctx->Light.Light[i], i );
1033 }
1034 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001035
Brian Paul4d053dd2000-01-14 04:45:47 +00001036 init_lightmodel( &ctx->Light.Model );
1037 init_material( &ctx->Light.Material[0] );
1038 init_material( &ctx->Light.Material[1] );
1039 ctx->Light.ShadeModel = GL_SMOOTH;
1040 ctx->Light.Enabled = GL_FALSE;
1041 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1042 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
1043 ctx->Light.ColorMaterialBitmask
1044 = gl_material_bitmask( ctx,
1045 GL_FRONT_AND_BACK,
1046 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001047
Brian Paul4d053dd2000-01-14 04:45:47 +00001048 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001049
Brian Paul4d053dd2000-01-14 04:45:47 +00001050 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +00001051 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1052 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001053 for (i = 0 ; i < 10 ; i++) {
1054 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1055 s->shininess = -1;
1056 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001057 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +00001058 }
1059 for (i = 0 ; i < 4 ; i++) {
Keith Whitwell14940c42000-11-05 18:40:57 +00001060 ctx->_ShineTable[i] = ctx->_ShineTabList->prev;
1061 ctx->_ShineTable[i]->refcount++;
Brian Paul4d053dd2000-01-14 04:45:47 +00001062 }
jtgafb833d1999-08-19 00:55:39 +00001063
Brian Paul77d61af2000-06-28 04:20:21 +00001064 gl_compute_shine_table( ctx, 0, ctx->Light.Material[0].Shininess );
1065 gl_compute_shine_table( ctx, 2, ctx->Light.Material[0].Shininess * .5 );
1066 gl_compute_shine_table( ctx, 1, ctx->Light.Material[1].Shininess );
1067 gl_compute_shine_table( ctx, 3, ctx->Light.Material[1].Shininess * .5 );
1068
jtgafb833d1999-08-19 00:55:39 +00001069
Brian Paul4d053dd2000-01-14 04:45:47 +00001070 /* Line group */
1071 ctx->Line.SmoothFlag = GL_FALSE;
1072 ctx->Line.StippleFlag = GL_FALSE;
1073 ctx->Line.Width = 1.0;
1074 ctx->Line.StipplePattern = 0xffff;
1075 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001076
Brian Paul4d053dd2000-01-14 04:45:47 +00001077 /* Display List group */
1078 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001079
Brian Paul4d053dd2000-01-14 04:45:47 +00001080 /* Pixel group */
1081 ctx->Pixel.RedBias = 0.0;
1082 ctx->Pixel.RedScale = 1.0;
1083 ctx->Pixel.GreenBias = 0.0;
1084 ctx->Pixel.GreenScale = 1.0;
1085 ctx->Pixel.BlueBias = 0.0;
1086 ctx->Pixel.BlueScale = 1.0;
1087 ctx->Pixel.AlphaBias = 0.0;
1088 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001089 ctx->Pixel.DepthBias = 0.0;
1090 ctx->Pixel.DepthScale = 1.0;
1091 ctx->Pixel.IndexOffset = 0;
1092 ctx->Pixel.IndexShift = 0;
1093 ctx->Pixel.ZoomX = 1.0;
1094 ctx->Pixel.ZoomY = 1.0;
1095 ctx->Pixel.MapColorFlag = GL_FALSE;
1096 ctx->Pixel.MapStencilFlag = GL_FALSE;
1097 ctx->Pixel.MapStoSsize = 1;
1098 ctx->Pixel.MapItoIsize = 1;
1099 ctx->Pixel.MapItoRsize = 1;
1100 ctx->Pixel.MapItoGsize = 1;
1101 ctx->Pixel.MapItoBsize = 1;
1102 ctx->Pixel.MapItoAsize = 1;
1103 ctx->Pixel.MapRtoRsize = 1;
1104 ctx->Pixel.MapGtoGsize = 1;
1105 ctx->Pixel.MapBtoBsize = 1;
1106 ctx->Pixel.MapAtoAsize = 1;
1107 ctx->Pixel.MapStoS[0] = 0;
1108 ctx->Pixel.MapItoI[0] = 0;
1109 ctx->Pixel.MapItoR[0] = 0.0;
1110 ctx->Pixel.MapItoG[0] = 0.0;
1111 ctx->Pixel.MapItoB[0] = 0.0;
1112 ctx->Pixel.MapItoA[0] = 0.0;
1113 ctx->Pixel.MapItoR8[0] = 0;
1114 ctx->Pixel.MapItoG8[0] = 0;
1115 ctx->Pixel.MapItoB8[0] = 0;
1116 ctx->Pixel.MapItoA8[0] = 0;
1117 ctx->Pixel.MapRtoR[0] = 0.0;
1118 ctx->Pixel.MapGtoG[0] = 0.0;
1119 ctx->Pixel.MapBtoB[0] = 0.0;
1120 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001121 ctx->Pixel.HistogramEnabled = GL_FALSE;
1122 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1123 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1124 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1125 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001126 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1127 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1128 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1129 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001130 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1131 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1132 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1133 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001134 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1135 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1136 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001137 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1138 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1139 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1140 for (i = 0; i < 3; i++) {
1141 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1142 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1143 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1144 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1145 }
1146 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1147 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001148
Brian Paul4d053dd2000-01-14 04:45:47 +00001149 /* Point group */
1150 ctx->Point.SmoothFlag = GL_FALSE;
1151 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001152 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001153 ctx->Point.Params[0] = 1.0;
1154 ctx->Point.Params[1] = 0.0;
1155 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001156 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001157 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001158 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001159 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001160
Brian Paul4d053dd2000-01-14 04:45:47 +00001161 /* Polygon group */
1162 ctx->Polygon.CullFlag = GL_FALSE;
1163 ctx->Polygon.CullFaceMode = GL_BACK;
1164 ctx->Polygon.FrontFace = GL_CCW;
1165 ctx->Polygon.FrontBit = 0;
1166 ctx->Polygon.FrontMode = GL_FILL;
1167 ctx->Polygon.BackMode = GL_FILL;
Keith Whitwell14940c42000-11-05 18:40:57 +00001168 ctx->Polygon._Unfilled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001169 ctx->Polygon.SmoothFlag = GL_FALSE;
1170 ctx->Polygon.StippleFlag = GL_FALSE;
1171 ctx->Polygon.OffsetFactor = 0.0F;
1172 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001173 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001174 ctx->Polygon.OffsetPoint = GL_FALSE;
1175 ctx->Polygon.OffsetLine = GL_FALSE;
1176 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001177
Brian Paul4d053dd2000-01-14 04:45:47 +00001178 /* Polygon Stipple group */
1179 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001180
Brian Paul4d053dd2000-01-14 04:45:47 +00001181 /* Scissor group */
1182 ctx->Scissor.Enabled = GL_FALSE;
1183 ctx->Scissor.X = 0;
1184 ctx->Scissor.Y = 0;
1185 ctx->Scissor.Width = 0;
1186 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001187
Brian Paul4d053dd2000-01-14 04:45:47 +00001188 /* Stencil group */
1189 ctx->Stencil.Enabled = GL_FALSE;
1190 ctx->Stencil.Function = GL_ALWAYS;
1191 ctx->Stencil.FailFunc = GL_KEEP;
1192 ctx->Stencil.ZPassFunc = GL_KEEP;
1193 ctx->Stencil.ZFailFunc = GL_KEEP;
1194 ctx->Stencil.Ref = 0;
1195 ctx->Stencil.ValueMask = STENCIL_MAX;
1196 ctx->Stencil.Clear = 0;
1197 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001198
Brian Paul4d053dd2000-01-14 04:45:47 +00001199 /* Texture group */
1200 ctx->Texture.CurrentUnit = 0; /* multitexture */
1201 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001202 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001203 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1204 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001205 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001206 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001207
Brian Paul4d053dd2000-01-14 04:45:47 +00001208 /* Transformation group */
1209 ctx->Transform.MatrixMode = GL_MODELVIEW;
1210 ctx->Transform.Normalize = GL_FALSE;
1211 ctx->Transform.RescaleNormals = GL_FALSE;
1212 for (i=0;i<MAX_CLIP_PLANES;i++) {
1213 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1214 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1215 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001216 ctx->Transform._AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001217
Brian Paul4d053dd2000-01-14 04:45:47 +00001218 /* Viewport group */
1219 ctx->Viewport.X = 0;
1220 ctx->Viewport.Y = 0;
1221 ctx->Viewport.Width = 0;
1222 ctx->Viewport.Height = 0;
1223 ctx->Viewport.Near = 0.0;
1224 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001225 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001226
1227#define Sz 10
1228#define Tz 14
Keith Whitwell14940c42000-11-05 18:40:57 +00001229 ctx->Viewport._WindowMap.m[Sz] = 0.5 * ctx->Visual.DepthMaxF;
1230 ctx->Viewport._WindowMap.m[Tz] = 0.5 * ctx->Visual.DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001231#undef Sz
1232#undef Tz
1233
Keith Whitwell14940c42000-11-05 18:40:57 +00001234 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1235 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001236
Brian Paul4d053dd2000-01-14 04:45:47 +00001237 /* Vertex arrays */
1238 ctx->Array.Vertex.Size = 4;
1239 ctx->Array.Vertex.Type = GL_FLOAT;
1240 ctx->Array.Vertex.Stride = 0;
1241 ctx->Array.Vertex.StrideB = 0;
1242 ctx->Array.Vertex.Ptr = NULL;
1243 ctx->Array.Vertex.Enabled = GL_FALSE;
1244 ctx->Array.Normal.Type = GL_FLOAT;
1245 ctx->Array.Normal.Stride = 0;
1246 ctx->Array.Normal.StrideB = 0;
1247 ctx->Array.Normal.Ptr = NULL;
1248 ctx->Array.Normal.Enabled = GL_FALSE;
1249 ctx->Array.Color.Size = 4;
1250 ctx->Array.Color.Type = GL_FLOAT;
1251 ctx->Array.Color.Stride = 0;
1252 ctx->Array.Color.StrideB = 0;
1253 ctx->Array.Color.Ptr = NULL;
1254 ctx->Array.Color.Enabled = GL_FALSE;
1255 ctx->Array.Index.Type = GL_FLOAT;
1256 ctx->Array.Index.Stride = 0;
1257 ctx->Array.Index.StrideB = 0;
1258 ctx->Array.Index.Ptr = NULL;
1259 ctx->Array.Index.Enabled = GL_FALSE;
1260 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1261 ctx->Array.TexCoord[i].Size = 4;
1262 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1263 ctx->Array.TexCoord[i].Stride = 0;
1264 ctx->Array.TexCoord[i].StrideB = 0;
1265 ctx->Array.TexCoord[i].Ptr = NULL;
1266 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1267 }
1268 ctx->Array.TexCoordInterleaveFactor = 1;
1269 ctx->Array.EdgeFlag.Stride = 0;
1270 ctx->Array.EdgeFlag.StrideB = 0;
1271 ctx->Array.EdgeFlag.Ptr = NULL;
1272 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1273 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1274
1275 /* Pixel transfer */
1276 ctx->Pack.Alignment = 4;
1277 ctx->Pack.RowLength = 0;
1278 ctx->Pack.ImageHeight = 0;
1279 ctx->Pack.SkipPixels = 0;
1280 ctx->Pack.SkipRows = 0;
1281 ctx->Pack.SkipImages = 0;
1282 ctx->Pack.SwapBytes = GL_FALSE;
1283 ctx->Pack.LsbFirst = GL_FALSE;
1284 ctx->Unpack.Alignment = 4;
1285 ctx->Unpack.RowLength = 0;
1286 ctx->Unpack.ImageHeight = 0;
1287 ctx->Unpack.SkipPixels = 0;
1288 ctx->Unpack.SkipRows = 0;
1289 ctx->Unpack.SkipImages = 0;
1290 ctx->Unpack.SwapBytes = GL_FALSE;
1291 ctx->Unpack.LsbFirst = GL_FALSE;
1292
1293 /* Feedback */
1294 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1295 ctx->Feedback.Buffer = NULL;
1296 ctx->Feedback.BufferSize = 0;
1297 ctx->Feedback.Count = 0;
1298
1299 /* Selection/picking */
1300 ctx->Select.Buffer = NULL;
1301 ctx->Select.BufferSize = 0;
1302 ctx->Select.BufferCount = 0;
1303 ctx->Select.Hits = 0;
1304 ctx->Select.NameStackDepth = 0;
1305
Brian Paul4d053dd2000-01-14 04:45:47 +00001306 /* Renderer and client attribute stacks */
1307 ctx->AttribStackDepth = 0;
1308 ctx->ClientAttribStackDepth = 0;
1309
Brian Paul13811372000-04-12 00:27:37 +00001310 /* Display list */
1311 ctx->CallDepth = 0;
1312 ctx->ExecuteFlag = GL_TRUE;
1313 ctx->CompileFlag = GL_FALSE;
1314 ctx->CurrentListPtr = NULL;
1315 ctx->CurrentBlock = NULL;
1316 ctx->CurrentListNum = 0;
1317 ctx->CurrentPos = 0;
1318
1319 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001320 _mesa_init_colortable(&ctx->ColorTable);
1321 _mesa_init_colortable(&ctx->ProxyColorTable);
1322 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1323 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1324 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1325 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001326
Brian Paul4d053dd2000-01-14 04:45:47 +00001327 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001328 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001329 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001330 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001331
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001332 ctx->_NeedNormals = 0;
1333 ctx->_NeedEyeCoords = 0;
1334 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001335
Brian Paul4d053dd2000-01-14 04:45:47 +00001336 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1337
1338 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001339 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001340 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001341
1342 /* For debug/development only */
1343 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1344 ctx->FirstTimeCurrent = GL_TRUE;
1345
1346 /* Dither disable */
1347 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1348 if (ctx->NoDither) {
1349 if (getenv("MESA_DEBUG")) {
1350 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001351 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001352 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001353 }
1354}
1355
1356
1357
1358
jtgafb833d1999-08-19 00:55:39 +00001359/*
1360 * Allocate the proxy textures. If we run out of memory part way through
1361 * the allocations clean up and return GL_FALSE.
1362 * Return: GL_TRUE=success, GL_FALSE=failure
1363 */
Brian Paul178a1c52000-04-22 01:05:00 +00001364static GLboolean
1365alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001366{
1367 GLboolean out_of_memory;
1368 GLint i;
1369
Brian Paula8523782000-11-19 23:10:25 +00001370 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001371 if (!ctx->Texture.Proxy1D) {
1372 return GL_FALSE;
1373 }
1374
Brian Paula8523782000-11-19 23:10:25 +00001375 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001376 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001377 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001378 return GL_FALSE;
1379 }
1380
Brian Paula8523782000-11-19 23:10:25 +00001381 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001382 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001383 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1384 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1385 return GL_FALSE;
1386 }
1387
1388 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1389 if (!ctx->Texture.ProxyCubeMap) {
1390 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1391 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1392 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001393 return GL_FALSE;
1394 }
1395
1396 out_of_memory = GL_FALSE;
1397 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001398 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1399 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1400 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001401 if (!ctx->Texture.Proxy1D->Image[i]
1402 || !ctx->Texture.Proxy2D->Image[i]
1403 || !ctx->Texture.Proxy3D->Image[i]) {
1404 out_of_memory = GL_TRUE;
1405 }
1406 }
1407 if (out_of_memory) {
1408 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1409 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001410 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001411 }
1412 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001413 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001414 }
1415 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001416 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001417 }
1418 }
Brian Paula8523782000-11-19 23:10:25 +00001419 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1420 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1421 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001422 return GL_FALSE;
1423 }
1424 else {
1425 return GL_TRUE;
1426 }
1427}
1428
1429
jtgafb833d1999-08-19 00:55:39 +00001430/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001431 * Initialize a GLcontext struct. This includes allocating all the
1432 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001433 */
Brian Paul178a1c52000-04-22 01:05:00 +00001434GLboolean
1435_mesa_initialize_context( GLcontext *ctx,
1436 GLvisual *visual,
1437 GLcontext *share_list,
1438 void *driver_ctx,
1439 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001440{
Brian Paul5fb84d22000-05-24 15:04:45 +00001441 GLuint dispatchSize;
1442
jtgafb833d1999-08-19 00:55:39 +00001443 (void) direct; /* not used */
1444
jtgafb833d1999-08-19 00:55:39 +00001445 /* misc one-time initializations */
1446 one_time_init();
1447
Brian Paulb1394fa2000-09-26 20:53:53 +00001448 /**
1449 ** OpenGL SI stuff
1450 **/
1451 if (!ctx->imports.malloc) {
1452 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1453 }
1454 /* exports are setup by the device driver */
1455
jtgafb833d1999-08-19 00:55:39 +00001456 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001457 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001458 ctx->DrawBuffer = NULL;
1459 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001460
jtgafb833d1999-08-19 00:55:39 +00001461 if (share_list) {
1462 /* share the group of display lists of another context */
1463 ctx->Shared = share_list->Shared;
1464 }
1465 else {
1466 /* allocate new group of display lists */
1467 ctx->Shared = alloc_shared_state();
1468 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001469 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001470 }
1471 }
Brian Paul9560f052000-01-31 23:11:39 +00001472 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001473 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001474 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001475
Brian Paul4d053dd2000-01-14 04:45:47 +00001476 init_attrib_groups( ctx );
1477
jtgafb833d1999-08-19 00:55:39 +00001478 if (visual->DBflag) {
1479 ctx->Color.DrawBuffer = GL_BACK;
1480 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1481 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1482 ctx->Pixel.ReadBuffer = GL_BACK;
1483 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1484 }
1485 else {
1486 ctx->Color.DrawBuffer = GL_FRONT;
1487 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1488 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1489 ctx->Pixel.ReadBuffer = GL_FRONT;
1490 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1491 }
1492
jtgafb833d1999-08-19 00:55:39 +00001493 if (!alloc_proxy_textures(ctx)) {
1494 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001495 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001496 }
jtgafb833d1999-08-19 00:55:39 +00001497
Brian Paulf59afc92000-05-23 23:23:00 +00001498 /* register the most recent extension functions with libGL */
1499 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1500 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1501 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1502 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1503 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1504 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1505 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1506 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1507
Brian Paul5fb84d22000-05-24 15:04:45 +00001508 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1509 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1510 * Mesa we do this to accomodate different versions of libGL and various
1511 * DRI drivers.
1512 */
1513 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1514 sizeof(struct _glapi_table) / sizeof(void *));
1515
Brian Paulfbd8f211999-11-11 01:22:25 +00001516 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001517 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1518 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001519 if (!ctx->Exec || !ctx->Save) {
1520 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001521 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001522 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001523 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001524 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1525 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001526 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001527
Brian Paul3b18a362000-09-26 15:27:20 +00001528#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +00001529 ctx->TraceCtx = CALLOC( sizeof(trace_context_t) );
1530#if 0
1531 /* Brian: do you want to have CreateContext fail here,
1532 or should we just trap in NewTrace (currently done)? */
1533 if (!(ctx->TraceCtx)) {
1534 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001535 FREE( ctx->Exec );
1536 FREE( ctx->Save );
1537 return GL_FALSE;
1538 }
1539#endif
1540 trInitContext(ctx->TraceCtx);
1541
1542 ctx->TraceDispatch = (struct _glapi_table *)
1543 CALLOC(dispatchSize * sizeof(void*));
1544#if 0
1545 if (!(ctx->TraceCtx)) {
1546 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001547 FREE( ctx->Exec );
1548 FREE( ctx->Save );
1549 FREE( ctx->TraceCtx );
1550 return GL_FALSE;
1551 }
1552#endif
1553 trInitDispatch(ctx->TraceDispatch);
1554#endif
1555
Brian Paul4d053dd2000-01-14 04:45:47 +00001556 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001557}
1558
jtgafb833d1999-08-19 00:55:39 +00001559
1560
1561/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001562 * Allocate and initialize a GLcontext structure.
1563 * Input: visual - a GLvisual pointer
1564 * sharelist - another context to share display lists with or NULL
1565 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001566 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001567 */
Brian Paul178a1c52000-04-22 01:05:00 +00001568GLcontext *
Brian Paulb1394fa2000-09-26 20:53:53 +00001569_mesa_create_context( GLvisual *visual,
1570 GLcontext *share_list,
1571 void *driver_ctx,
1572 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001573{
1574 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1575 if (!ctx) {
1576 return NULL;
1577 }
1578
Brian Paul178a1c52000-04-22 01:05:00 +00001579 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001580 return ctx;
1581 }
1582 else {
1583 FREE(ctx);
1584 return NULL;
1585 }
1586}
1587
1588
1589
1590/*
1591 * Free the data associated with the given context.
1592 * But don't free() the GLcontext struct itself!
1593 */
Brian Paul178a1c52000-04-22 01:05:00 +00001594void
Brian Paulb1394fa2000-09-26 20:53:53 +00001595_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001596{
Brian Paul4d053dd2000-01-14 04:45:47 +00001597 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001598 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001599
1600 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001601 if (ctx == _mesa_get_current_context()) {
1602 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001603 }
1604
Keith Whitwell23caf202000-11-16 21:05:34 +00001605 _math_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001606 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001607 _math_matrix_dtr( &ctx->ModelViewStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001608 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001609 _math_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001610 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001611 _math_matrix_dtr( &ctx->ProjectionStack[i] );
Brian Paul4d053dd2000-01-14 04:45:47 +00001612 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001613 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001614 _math_matrix_dtr( &ctx->TextureMatrix[i] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001615 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Keith Whitwell23caf202000-11-16 21:05:34 +00001616 _math_matrix_dtr( &ctx->TextureStack[i][j] );
Brian Paul7fc29c52000-03-06 17:03:03 +00001617 }
1618 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001619
Brian Paul9560f052000-01-31 23:11:39 +00001620 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001621 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001622 assert(ctx->Shared->RefCount >= 0);
1623 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1624 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001625 /* free shared state */
1626 free_shared_state( ctx, ctx->Shared );
1627 }
1628
Keith Whitwell14940c42000-11-05 18:40:57 +00001629 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001630 FREE( s );
1631 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001632 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001633
1634 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001635 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1636 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1637 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paul4d053dd2000-01-14 04:45:47 +00001638
1639 /* Free evaluator data */
1640 if (ctx->EvalMap.Map1Vertex3.Points)
1641 FREE( ctx->EvalMap.Map1Vertex3.Points );
1642 if (ctx->EvalMap.Map1Vertex4.Points)
1643 FREE( ctx->EvalMap.Map1Vertex4.Points );
1644 if (ctx->EvalMap.Map1Index.Points)
1645 FREE( ctx->EvalMap.Map1Index.Points );
1646 if (ctx->EvalMap.Map1Color4.Points)
1647 FREE( ctx->EvalMap.Map1Color4.Points );
1648 if (ctx->EvalMap.Map1Normal.Points)
1649 FREE( ctx->EvalMap.Map1Normal.Points );
1650 if (ctx->EvalMap.Map1Texture1.Points)
1651 FREE( ctx->EvalMap.Map1Texture1.Points );
1652 if (ctx->EvalMap.Map1Texture2.Points)
1653 FREE( ctx->EvalMap.Map1Texture2.Points );
1654 if (ctx->EvalMap.Map1Texture3.Points)
1655 FREE( ctx->EvalMap.Map1Texture3.Points );
1656 if (ctx->EvalMap.Map1Texture4.Points)
1657 FREE( ctx->EvalMap.Map1Texture4.Points );
1658
1659 if (ctx->EvalMap.Map2Vertex3.Points)
1660 FREE( ctx->EvalMap.Map2Vertex3.Points );
1661 if (ctx->EvalMap.Map2Vertex4.Points)
1662 FREE( ctx->EvalMap.Map2Vertex4.Points );
1663 if (ctx->EvalMap.Map2Index.Points)
1664 FREE( ctx->EvalMap.Map2Index.Points );
1665 if (ctx->EvalMap.Map2Color4.Points)
1666 FREE( ctx->EvalMap.Map2Color4.Points );
1667 if (ctx->EvalMap.Map2Normal.Points)
1668 FREE( ctx->EvalMap.Map2Normal.Points );
1669 if (ctx->EvalMap.Map2Texture1.Points)
1670 FREE( ctx->EvalMap.Map2Texture1.Points );
1671 if (ctx->EvalMap.Map2Texture2.Points)
1672 FREE( ctx->EvalMap.Map2Texture2.Points );
1673 if (ctx->EvalMap.Map2Texture3.Points)
1674 FREE( ctx->EvalMap.Map2Texture3.Points );
1675 if (ctx->EvalMap.Map2Texture4.Points)
1676 FREE( ctx->EvalMap.Map2Texture4.Points );
1677
Brian Paul4bdcfe52000-04-17 17:57:04 +00001678 _mesa_free_colortable_data( &ctx->ColorTable );
1679 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1680 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1681 _mesa_free_colortable_data( &ctx->Texture.Palette );
1682
Brian Paul4d053dd2000-01-14 04:45:47 +00001683 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001684
1685 FREE(ctx->Exec);
1686 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001687}
1688
1689
1690
1691/*
1692 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001693 */
Brian Paul178a1c52000-04-22 01:05:00 +00001694void
Brian Paulb1394fa2000-09-26 20:53:53 +00001695_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001696{
1697 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001698 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001699 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001700 }
1701}
1702
1703
1704
1705/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001706 * Called by the driver after both the context and driver are fully
1707 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001708 */
Brian Paul178a1c52000-04-22 01:05:00 +00001709void
Brian Paulb1394fa2000-09-26 20:53:53 +00001710_mesa_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001711{
Brian Paul00037781999-12-17 14:52:35 +00001712 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001713}
1714
1715
1716
1717/*
1718 * Copy attribute groups from one context to another.
1719 * Input: src - source context
1720 * dst - destination context
1721 * mask - bitwise OR of GL_*_BIT flags
1722 */
Brian Paul178a1c52000-04-22 01:05:00 +00001723void
Brian Paulb1394fa2000-09-26 20:53:53 +00001724_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001725{
1726 if (mask & GL_ACCUM_BUFFER_BIT) {
1727 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1728 }
1729 if (mask & GL_COLOR_BUFFER_BIT) {
1730 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1731 }
1732 if (mask & GL_CURRENT_BIT) {
1733 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1734 }
1735 if (mask & GL_DEPTH_BUFFER_BIT) {
1736 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1737 }
1738 if (mask & GL_ENABLE_BIT) {
1739 /* no op */
1740 }
1741 if (mask & GL_EVAL_BIT) {
1742 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1743 }
1744 if (mask & GL_FOG_BIT) {
1745 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1746 }
1747 if (mask & GL_HINT_BIT) {
1748 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1749 }
1750 if (mask & GL_LIGHTING_BIT) {
1751 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001752 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001753 }
1754 if (mask & GL_LINE_BIT) {
1755 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1756 }
1757 if (mask & GL_LIST_BIT) {
1758 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1759 }
1760 if (mask & GL_PIXEL_MODE_BIT) {
1761 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1762 }
1763 if (mask & GL_POINT_BIT) {
1764 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1765 }
1766 if (mask & GL_POLYGON_BIT) {
1767 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1768 }
1769 if (mask & GL_POLYGON_STIPPLE_BIT) {
1770 /* Use loop instead of MEMCPY due to problem with Portland Group's
1771 * C compiler. Reported by John Stone.
1772 */
1773 int i;
1774 for (i=0;i<32;i++) {
1775 dst->PolygonStipple[i] = src->PolygonStipple[i];
1776 }
1777 }
1778 if (mask & GL_SCISSOR_BIT) {
1779 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1780 }
1781 if (mask & GL_STENCIL_BUFFER_BIT) {
1782 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1783 }
1784 if (mask & GL_TEXTURE_BIT) {
1785 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1786 }
1787 if (mask & GL_TRANSFORM_BIT) {
1788 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1789 }
1790 if (mask & GL_VIEWPORT_BIT) {
1791 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1792 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001793 /* XXX FIXME: Call callbacks?
1794 */
1795 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001796}
1797
1798
jtgafb833d1999-08-19 00:55:39 +00001799/*
Brian Paul00037781999-12-17 14:52:35 +00001800 * Set the current context, binding the given frame buffer to the context.
1801 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001802void
1803_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001804{
Brian Paulb1394fa2000-09-26 20:53:53 +00001805 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001806}
1807
1808
Keith Whitwell23caf202000-11-16 21:05:34 +00001809static void print_info( void )
1810{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001811 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001812 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001813 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001814 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001815 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001816 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001817 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001818 (char *) _mesa_GetString(GL_EXTENSIONS));
1819#if defined(THREADS)
1820 fprintf(stderr, "Mesa thread-safe: YES\n");
1821#else
1822 fprintf(stderr, "Mesa thread-safe: NO\n");
1823#endif
1824#if defined(USE_X86_ASM)
1825 fprintf(stderr, "Mesa x86-optimized: YES\n");
1826#else
1827 fprintf(stderr, "Mesa x86-optimized: NO\n");
1828#endif
1829}
1830
1831
Brian Paul00037781999-12-17 14:52:35 +00001832/*
1833 * Bind the given context to the given draw-buffer and read-buffer
1834 * and make it the current context for this thread.
1835 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001836void
1837_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1838 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001839{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001840 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001841 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001842
1843 /* We call this function periodically (just here for now) in
1844 * order to detect when multithreading has begun.
1845 */
1846 _glapi_check_multithread();
1847
Brian Paulf9b97d92000-01-28 20:17:42 +00001848 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001849 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001850
1851
1852 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001853 _glapi_set_dispatch(NULL); /* none current */
1854 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001855 else {
1856 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001857
Keith Whitwell23caf202000-11-16 21:05:34 +00001858 if (drawBuffer && readBuffer) {
1859 /* TODO: check if newCtx and buffer's visual match??? */
1860 newCtx->DrawBuffer = drawBuffer;
1861 newCtx->ReadBuffer = readBuffer;
1862 newCtx->NewState |= _NEW_BUFFERS;
1863 /* gl_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001864 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001865
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001866 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001867 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1868
1869 /* We can use this to help debug user's problems. Tell them to set
1870 * the MESA_INFO env variable before running their app. Then the
1871 * first time each context is made current we'll print some useful
1872 * information.
1873 */
1874 if (newCtx->FirstTimeCurrent) {
1875 if (getenv("MESA_INFO")) {
1876 print_info();
1877 }
1878 newCtx->FirstTimeCurrent = GL_FALSE;
1879 }
Brian Paul00037781999-12-17 14:52:35 +00001880 }
1881}
1882
1883
1884
1885/*
1886 * Return current context handle for the calling thread.
1887 * This isn't the fastest way to get the current context.
1888 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1889 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001890GLcontext *
1891_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001892{
Brian Paulf9b97d92000-01-28 20:17:42 +00001893 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001894}
1895
1896
1897
1898/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001899 * This should be called by device drivers just before they do a
1900 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001901 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001902void
1903_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001904{
Keith Whitwell23caf202000-11-16 21:05:34 +00001905 FLUSH_TNL( ctx, FLUSH_STORED_VERTICES );
jtgafb833d1999-08-19 00:55:39 +00001906}
1907
1908
Brian Paul00037781999-12-17 14:52:35 +00001909
Brian Paulfbd8f211999-11-11 01:22:25 +00001910/*
1911 * Return pointer to this context's current API dispatch table.
1912 * It'll either be the immediate-mode execute dispatcher or the
1913 * display list compile dispatcher.
1914 */
1915struct _glapi_table *
1916_mesa_get_dispatch(GLcontext *ctx)
1917{
1918 return ctx->CurrentDispatch;
1919}
1920
1921
1922
jtgafb833d1999-08-19 00:55:39 +00001923/**********************************************************************/
1924/***** Miscellaneous functions *****/
1925/**********************************************************************/
1926
1927
1928/*
1929 * This function is called when the Mesa user has stumbled into a code
1930 * path which may not be implemented fully or correctly.
1931 */
1932void gl_problem( const GLcontext *ctx, const char *s )
1933{
1934 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paul413d6a22000-05-26 14:44:59 +00001935 fprintf( stderr, "Report to Mesa bug database at www.mesa3d.org\n" );
jtgafb833d1999-08-19 00:55:39 +00001936 (void) ctx;
1937}
1938
1939
1940
1941/*
1942 * This is called to inform the user that he or she has tried to do
1943 * something illogical or if there's likely a bug in their program
1944 * (like enabled depth testing without a depth buffer).
1945 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001946void
1947_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001948{
Brian Paulb1394fa2000-09-26 20:53:53 +00001949 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001950}
1951
1952
1953
Brian Paulfa9df402000-02-02 19:16:46 +00001954/*
1955 * Compile an error into current display list.
1956 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001957void
1958_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001959{
1960 if (ctx->CompileFlag)
1961 gl_save_error( ctx, error, s );
1962
1963 if (ctx->ExecuteFlag)
1964 gl_error( ctx, error, s );
1965}
1966
1967
Brian Paulfa9df402000-02-02 19:16:46 +00001968
jtgafb833d1999-08-19 00:55:39 +00001969/*
1970 * This is Mesa's error handler. Normally, all that's done is the updating
1971 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1972 * environment variable "MESA_DEBUG" is defined then a real error message
1973 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001974 * Input: ctx - the GL context
1975 * error - the error value
1976 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00001977 */
Brian Paul7eb06032000-07-14 04:13:40 +00001978void
1979gl_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00001980{
Brian Paul7eb06032000-07-14 04:13:40 +00001981 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00001982 GLboolean debug;
1983
1984#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00001985 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00001986 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00001987 else
1988 debug = GL_TRUE;
1989#else
1990 if (debugEnv)
1991 debug = GL_TRUE;
1992 else
1993 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001994#endif
1995
1996 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00001997 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00001998 switch (error) {
1999 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002000 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002001 break;
2002 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002003 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002004 break;
2005 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002006 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002007 break;
2008 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002009 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002010 break;
2011 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002012 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002013 break;
2014 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002015 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002016 break;
2017 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002018 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002019 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002020 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002021 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002022 break;
jtgafb833d1999-08-19 00:55:39 +00002023 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002024 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002025 break;
2026 }
Brian Paul7eb06032000-07-14 04:13:40 +00002027 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002028 }
2029
Brian Paul7eb06032000-07-14 04:13:40 +00002030 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002031 ctx->ErrorValue = error;
2032 }
2033
2034 /* Call device driver's error handler, if any. This is used on the Mac. */
2035 if (ctx->Driver.Error) {
2036 (*ctx->Driver.Error)( ctx );
2037 }
2038}
2039
2040
2041
Brian Paulfa9df402000-02-02 19:16:46 +00002042void
2043_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002044{
Brian Paulfa9df402000-02-02 19:16:46 +00002045 GET_CURRENT_CONTEXT(ctx);
2046 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
2047 if (ctx->Driver.Finish) {
2048 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002049 }
2050}
2051
2052
2053
Brian Paulfa9df402000-02-02 19:16:46 +00002054void
2055_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002056{
Brian Paulfa9df402000-02-02 19:16:46 +00002057 GET_CURRENT_CONTEXT(ctx);
2058 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
2059 if (ctx->Driver.Flush) {
2060 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002061 }
jtgafb833d1999-08-19 00:55:39 +00002062}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002063
2064
2065
2066const char *_mesa_prim_name[GL_POLYGON+2] = {
2067 "GL_POINTS",
2068 "GL_LINES",
2069 "GL_LINE_LOOP",
2070 "GL_LINE_STRIP",
2071 "GL_TRIANGLES",
2072 "GL_TRIANGLE_STRIP",
2073 "GL_TRIANGLE_FAN",
2074 "GL_QUADS",
2075 "GL_QUAD_STRIP",
2076 "GL_POLYGON",
2077 "culled primitive"
2078};
2079
Brian Paul1c56fdc2000-09-17 21:56:07 +00002080
2081GLenum gl_reduce_prim[GL_POLYGON+1] = {
2082 GL_POINTS,
2083 GL_LINES,
2084 GL_LINES,
2085 GL_LINES,
2086 GL_TRIANGLES,
2087 GL_TRIANGLES,
2088 GL_TRIANGLES,
2089 GL_TRIANGLES,
2090 GL_TRIANGLES,
2091 GL_TRIANGLES,
Gareth Hughesfc2427e2000-10-23 00:16:28 +00002092};