blob: dbd1823f4ebc3a8d3416949120a0b0a27644e12b [file] [log] [blame]
Brian Paul7eb06032000-07-14 04:13:40 +00001/* $Id: context.c,v 1.78 2000/07/14 04:13:40 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paulfbd8f211999-11-11 01:22:25 +00005 * Version: 3.3
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"
jtgafb833d1999-08-19 00:55:39 +000032#include "accum.h"
33#include "alphabuf.h"
jtgafb833d1999-08-19 00:55:39 +000034#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000035#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "context.h"
37#include "cva.h"
38#include "depth.h"
39#include "dlist.h"
40#include "eval.h"
41#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000042#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000044#include "get.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000045#include "glapi.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000046#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000047#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "hash.h"
49#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000050#include "macros.h"
51#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000052#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000053#include "mmath.h"
54#include "pb.h"
55#include "pipeline.h"
jtgafb833d1999-08-19 00:55:39 +000056#include "shade.h"
57#include "simple_list.h"
58#include "stencil.h"
59#include "stages.h"
Brian Paulfa9df402000-02-02 19:16:46 +000060#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000061#include "translate.h"
62#include "teximage.h"
63#include "texobj.h"
64#include "texstate.h"
65#include "texture.h"
66#include "types.h"
67#include "varray.h"
68#include "vb.h"
69#include "vbcull.h"
jtgafb833d1999-08-19 00:55:39 +000070#include "vbrender.h"
71#include "vbxform.h"
Keith Whitwell38756791999-08-29 10:26:31 +000072#include "vertices.h"
jtgafb833d1999-08-19 00:55:39 +000073#include "xform.h"
jtgafb833d1999-08-19 00:55:39 +000074#endif
75
76
77
78/**********************************************************************/
79/***** Context and Thread management *****/
80/**********************************************************************/
81
82
Brian Paul00037781999-12-17 14:52:35 +000083#if !defined(THREADS)
jtgafb833d1999-08-19 00:55:39 +000084
Brian Paul5666c632000-01-18 17:36:16 +000085struct immediate *_mesa_CurrentInput = NULL;
jtgafb833d1999-08-19 00:55:39 +000086
Brian Paul00037781999-12-17 14:52:35 +000087#endif
jtgafb833d1999-08-19 00:55:39 +000088
89
jtgafb833d1999-08-19 00:55:39 +000090/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +000091/***** GL Visual allocation/destruction *****/
92/**********************************************************************/
93
94
95/*
96 * Allocate a new GLvisual object.
97 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +000098 * dbFlag - double buffering?
99 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000100 * depthBits - requested bits per depth buffer value
101 * Any value in [0, 32] is acceptable but the actual
102 * depth type will be GLushort or GLuint as needed.
103 * stencilBits - requested minimum bits per stencil buffer value
104 * accumBits - requested minimum bits per accum buffer component
105 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
106 * red/green/blue/alphaBits - number of bits per color component
107 * in frame buffer for RGB(A) mode.
108 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000109 * Return: pointer to new GLvisual or NULL if requested parameters can't
110 * be met.
111 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000112GLvisual *
113_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000114 GLboolean dbFlag,
115 GLboolean stereoFlag,
116 GLint redBits,
117 GLint greenBits,
118 GLint blueBits,
119 GLint alphaBits,
120 GLint indexBits,
121 GLint depthBits,
122 GLint stencilBits,
123 GLint accumRedBits,
124 GLint accumGreenBits,
125 GLint accumBlueBits,
126 GLint accumAlphaBits,
127 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000128{
Brian Paul178a1c52000-04-22 01:05:00 +0000129 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
130 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000131 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000132 redBits, greenBits, blueBits, alphaBits,
133 indexBits, depthBits, stencilBits,
134 accumRedBits, accumGreenBits,
135 accumBlueBits, accumAlphaBits,
136 numSamples )) {
137 FREE(vis);
138 return NULL;
139 }
140 }
141 return vis;
142}
143
144
145/*
146 * Initialize the fields of the given GLvisual.
147 * Input: see _mesa_create_visual() above.
148 * Return: GL_TRUE = success
149 * GL_FALSE = failure.
150 */
151GLboolean
152_mesa_initialize_visual( GLvisual *vis,
153 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000154 GLboolean dbFlag,
155 GLboolean stereoFlag,
156 GLint redBits,
157 GLint greenBits,
158 GLint blueBits,
159 GLint alphaBits,
160 GLint indexBits,
161 GLint depthBits,
162 GLint stencilBits,
163 GLint accumRedBits,
164 GLint accumGreenBits,
165 GLint accumBlueBits,
166 GLint accumAlphaBits,
167 GLint numSamples )
168{
169 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000170
Brian Pauled30dfa2000-03-03 17:47:39 +0000171 /* This is to catch bad values from device drivers not updated for
172 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
173 * bad value now (a 1-bit depth buffer!?!).
174 */
175 assert(depthBits == 0 || depthBits > 1);
176
177 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000178 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000179 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000180 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000181 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000182 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000183 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000184 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000185 }
186 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000187 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000188 }
189 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000190 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000191 }
192 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000193 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000194 }
195
196 vis->RGBAflag = rgbFlag;
197 vis->DBflag = dbFlag;
198 vis->StereoFlag = stereoFlag;
199 vis->RedBits = redBits;
200 vis->GreenBits = greenBits;
201 vis->BlueBits = blueBits;
Brian Paule70c6232000-05-04 13:53:55 +0000202 vis->AlphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000203
Brian Paulb371e0d2000-03-31 01:05:51 +0000204 vis->IndexBits = indexBits;
205 vis->DepthBits = depthBits;
206 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
207 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
208 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
209 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
210 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000211
Brian Pauled30dfa2000-03-03 17:47:39 +0000212 if (depthBits == 0) {
213 /* Special case. Even if we don't have a depth buffer we need
214 * good values for DepthMax for Z vertex transformation purposes.
215 */
216 vis->DepthMax = 1;
217 vis->DepthMaxF = 1.0F;
218 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000219 else if (depthBits < 32) {
Brian Pauled30dfa2000-03-03 17:47:39 +0000220 vis->DepthMax = (1 << depthBits) - 1;
221 vis->DepthMaxF = (GLfloat) vis->DepthMax;
222 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000223 else {
224 /* Special case since shift values greater than or equal to the
225 * number of bits in the left hand expression's type are
226 * undefined.
227 */
228 vis->DepthMax = 0xffffffff;
229 vis->DepthMaxF = (GLfloat) vis->DepthMax;
230 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000231
Brian Paul178a1c52000-04-22 01:05:00 +0000232 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000233}
234
235
Brian Paulb371e0d2000-03-31 01:05:51 +0000236/* This function should no longer be used. Use _mesa_create_visual() instead */
Brian Paul178a1c52000-04-22 01:05:00 +0000237GLvisual *
238gl_create_visual( GLboolean rgbFlag,
239 GLboolean alphaFlag,
240 GLboolean dbFlag,
241 GLboolean stereoFlag,
242 GLint depthBits,
243 GLint stencilBits,
244 GLint accumBits,
245 GLint indexBits,
246 GLint redBits,
247 GLint greenBits,
248 GLint blueBits,
249 GLint alphaBits )
Brian Paulb371e0d2000-03-31 01:05:51 +0000250{
Brian Paule70c6232000-05-04 13:53:55 +0000251 (void) alphaFlag;
252 return _mesa_create_visual(rgbFlag, dbFlag, stereoFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000253 redBits, greenBits, blueBits, alphaBits,
254 indexBits, depthBits, stencilBits,
255 accumBits, accumBits, accumBits, accumBits, 0);
256}
Brian Paul4d053dd2000-01-14 04:45:47 +0000257
Brian Paulb371e0d2000-03-31 01:05:51 +0000258
259void
260_mesa_destroy_visual( GLvisual *vis )
261{
262 FREE(vis);
263}
264
265
266/* obsolete */
Brian Paul178a1c52000-04-22 01:05:00 +0000267void
268gl_destroy_visual( GLvisual *vis )
Brian Paul4d053dd2000-01-14 04:45:47 +0000269{
Brian Paulb371e0d2000-03-31 01:05:51 +0000270 _mesa_destroy_visual(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000271}
272
273
274
275/**********************************************************************/
276/***** GL Framebuffer allocation/destruction *****/
277/**********************************************************************/
278
279
280/*
281 * Create a new framebuffer. A GLframebuffer is a struct which
282 * encapsulates the depth, stencil and accum buffers and related
283 * parameters.
284 * Input: visual - a GLvisual pointer
285 * softwareDepth - create/use a software depth buffer?
286 * softwareStencil - create/use a software stencil buffer?
287 * softwareAccum - create/use a software accum buffer?
288 * softwareAlpha - create/use a software alpha buffer?
289
290 * Return: pointer to new GLframebuffer struct or NULL if error.
291 */
Brian Paul178a1c52000-04-22 01:05:00 +0000292GLframebuffer *
293gl_create_framebuffer( GLvisual *visual,
294 GLboolean softwareDepth,
295 GLboolean softwareStencil,
296 GLboolean softwareAccum,
297 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000298{
Brian Paul178a1c52000-04-22 01:05:00 +0000299 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
300 assert(visual);
301 if (buffer) {
302 _mesa_initialize_framebuffer(buffer, visual,
303 softwareDepth, softwareStencil,
304 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000305 }
Brian Paul178a1c52000-04-22 01:05:00 +0000306 return buffer;
307}
308
309
310/*
311 * Initialize a GLframebuffer object.
312 * Input: See gl_create_framebuffer() above.
313 */
314void
315_mesa_initialize_framebuffer( GLframebuffer *buffer,
316 GLvisual *visual,
317 GLboolean softwareDepth,
318 GLboolean softwareStencil,
319 GLboolean softwareAccum,
320 GLboolean softwareAlpha )
321{
322 assert(buffer);
323 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000324
325 /* sanity checks */
326 if (softwareDepth ) {
327 assert(visual->DepthBits > 0);
328 }
329 if (softwareStencil) {
330 assert(visual->StencilBits > 0);
331 }
332 if (softwareAccum) {
333 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000334 assert(visual->AccumRedBits > 0);
335 assert(visual->AccumGreenBits > 0);
336 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000337 }
338 if (softwareAlpha) {
339 assert(visual->RGBAflag);
340 assert(visual->AlphaBits > 0);
341 }
342
343 buffer->Visual = visual;
344 buffer->UseSoftwareDepthBuffer = softwareDepth;
345 buffer->UseSoftwareStencilBuffer = softwareStencil;
346 buffer->UseSoftwareAccumBuffer = softwareAccum;
347 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000348}
349
350
Brian Paul4d053dd2000-01-14 04:45:47 +0000351/*
352 * Free a framebuffer struct and its buffers.
353 */
Brian Paul178a1c52000-04-22 01:05:00 +0000354void
355gl_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000356{
357 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000358 if (buffer->DepthBuffer) {
359 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000360 }
361 if (buffer->Accum) {
362 FREE( buffer->Accum );
363 }
364 if (buffer->Stencil) {
365 FREE( buffer->Stencil );
366 }
367 if (buffer->FrontLeftAlpha) {
368 FREE( buffer->FrontLeftAlpha );
369 }
370 if (buffer->BackLeftAlpha) {
371 FREE( buffer->BackLeftAlpha );
372 }
373 if (buffer->FrontRightAlpha) {
374 FREE( buffer->FrontRightAlpha );
375 }
376 if (buffer->BackRightAlpha) {
377 FREE( buffer->BackRightAlpha );
378 }
379 FREE(buffer);
380 }
381}
382
383
384
385/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000386/***** Context allocation, initialization, destroying *****/
387/**********************************************************************/
388
389
Brian Paul9560f052000-01-31 23:11:39 +0000390_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
391
392
jtgafb833d1999-08-19 00:55:39 +0000393/*
394 * This function just calls all the various one-time-init functions in Mesa.
395 */
Brian Paul178a1c52000-04-22 01:05:00 +0000396static void
397one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000398{
399 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000400 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000401 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000402 /* do some implementation tests */
403 assert( sizeof(GLbyte) == 1 );
404 assert( sizeof(GLshort) >= 2 );
405 assert( sizeof(GLint) >= 4 );
406 assert( sizeof(GLubyte) == 1 );
407 assert( sizeof(GLushort) >= 2 );
408 assert( sizeof(GLuint) >= 4 );
409
jtgafb833d1999-08-19 00:55:39 +0000410 gl_init_clip();
411 gl_init_eval();
Brian Paul5829f0c2000-02-02 22:21:39 +0000412 _mesa_init_fog();
Brian Paul780c4e02000-03-22 23:20:12 +0000413 _mesa_init_math();
jtgafb833d1999-08-19 00:55:39 +0000414 gl_init_lists();
415 gl_init_shade();
416 gl_init_texture();
417 gl_init_transformation();
418 gl_init_translate();
419 gl_init_vbrender();
420 gl_init_vbxform();
Keith Whitwell38756791999-08-29 10:26:31 +0000421 gl_init_vertices();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000422
423 if (getenv("MESA_DEBUG")) {
424 _glapi_noop_enable_warnings(GL_TRUE);
425 }
426 else {
427 _glapi_noop_enable_warnings(GL_FALSE);
428 }
429
jtgafb833d1999-08-19 00:55:39 +0000430#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
431 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
432#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000433
434 alreadyCalled = GL_TRUE;
435 }
Brian Paul9560f052000-01-31 23:11:39 +0000436 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000437}
438
439
Brian Paul4d053dd2000-01-14 04:45:47 +0000440
jtgafb833d1999-08-19 00:55:39 +0000441/*
442 * Allocate and initialize a shared context state structure.
443 */
Brian Paul178a1c52000-04-22 01:05:00 +0000444static struct gl_shared_state *
445alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000446{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000447 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000448 struct gl_shared_state *ss;
449 GLboolean outOfMemory;
450
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000451 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000452 if (!ss)
453 return NULL;
454
Brian Paulbb797902000-01-24 16:19:54 +0000455 ss->DisplayList = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000456
Brian Paulbb797902000-01-24 16:19:54 +0000457 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000458
459 /* Default Texture objects */
460 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000461 for (d = 1 ; d <= 3 ; d++) {
462 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
463 if (!ss->DefaultD[d]) {
464 outOfMemory = GL_TRUE;
465 break;
jtgafb833d1999-08-19 00:55:39 +0000466 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000467 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000468 }
469
Brian Paul413d6a22000-05-26 14:44:59 +0000470 ss->DefaultCubeMap = gl_alloc_texture_object(ss, 0, 6);
471 if (!ss->DefaultCubeMap) {
472 outOfMemory = GL_TRUE;
473 }
474 else {
475 ss->DefaultCubeMap->RefCount++;
476 }
477
jtgafb833d1999-08-19 00:55:39 +0000478 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
479 /* Ran out of memory at some point. Free everything and return NULL */
480 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000481 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000482 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000483 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000484 if (ss->DefaultD[1])
485 gl_free_texture_object(ss, ss->DefaultD[1]);
486 if (ss->DefaultD[2])
487 gl_free_texture_object(ss, ss->DefaultD[2]);
488 if (ss->DefaultD[3])
489 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paul413d6a22000-05-26 14:44:59 +0000490 if (ss->DefaultCubeMap)
491 gl_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000492 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000493 return NULL;
494 }
495 else {
496 return ss;
497 }
498}
499
500
501/*
502 * Deallocate a shared state context and all children structures.
503 */
Brian Paul178a1c52000-04-22 01:05:00 +0000504static void
505free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000506{
507 /* Free display lists */
508 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000509 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000510 if (list) {
511 gl_destroy_list(ctx, list);
512 }
513 else {
514 break;
515 }
516 }
Brian Paulbb797902000-01-24 16:19:54 +0000517 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000518
519 /* Free texture objects */
520 while (ss->TexObjectList)
521 {
522 if (ctx->Driver.DeleteTexture)
523 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
524 /* this function removes from linked list too! */
525 gl_free_texture_object(ss, ss->TexObjectList);
526 }
Brian Paulbb797902000-01-24 16:19:54 +0000527 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000528
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000529 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000530}
531
532
533
jtgafb833d1999-08-19 00:55:39 +0000534/*
535 * Initialize the nth light. Note that the defaults for light 0 are
536 * different than the other lights.
537 */
Brian Paul178a1c52000-04-22 01:05:00 +0000538static void
539init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000540{
541 make_empty_list( l );
542
543 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
544 if (n==0) {
545 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
546 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
547 }
548 else {
549 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
550 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
551 }
552 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
553 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
554 l->SpotExponent = 0.0;
555 gl_compute_spot_exp_table( l );
556 l->SpotCutoff = 180.0;
557 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
558 l->ConstantAttenuation = 1.0;
559 l->LinearAttenuation = 0.0;
560 l->QuadraticAttenuation = 0.0;
561 l->Enabled = GL_FALSE;
562}
563
564
565
Brian Paul178a1c52000-04-22 01:05:00 +0000566static void
567init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000568{
569 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
570 lm->LocalViewer = GL_FALSE;
571 lm->TwoSide = GL_FALSE;
572 lm->ColorControl = GL_SINGLE_COLOR;
573}
574
575
Brian Paul178a1c52000-04-22 01:05:00 +0000576static void
577init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000578{
579 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
580 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
581 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
582 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
583 m->Shininess = 0.0;
584 m->AmbientIndex = 0;
585 m->DiffuseIndex = 1;
586 m->SpecularIndex = 1;
587}
588
589
590
Brian Paul178a1c52000-04-22 01:05:00 +0000591static void
592init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000593{
594 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
595
596 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000597 texUnit->CombineModeRGB = GL_MODULATE;
598 texUnit->CombineModeA = GL_MODULATE;
599 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
600 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
601 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
602 texUnit->CombineSourceA[0] = GL_TEXTURE;
603 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
604 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
605 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
606 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
607 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
608 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
609 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
610 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
611 texUnit->CombineScaleShiftRGB = 0;
612 texUnit->CombineScaleShiftA = 0;
613
jtgafb833d1999-08-19 00:55:39 +0000614 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
615 texUnit->TexGenEnabled = 0;
616 texUnit->GenModeS = GL_EYE_LINEAR;
617 texUnit->GenModeT = GL_EYE_LINEAR;
618 texUnit->GenModeR = GL_EYE_LINEAR;
619 texUnit->GenModeQ = GL_EYE_LINEAR;
620 /* Yes, these plane coefficients are correct! */
621 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
622 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
623 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
624 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
625 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
626 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
627 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
628 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
629
Brian Paul6e6d4c61999-10-09 20:17:07 +0000630 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
631 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
632 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
Brian Paul413d6a22000-05-26 14:44:59 +0000633 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000634}
635
636
Brian Paul178a1c52000-04-22 01:05:00 +0000637static void
638init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000639{
640 struct gl_client_array *cl;
641 GLuint i;
642
643 cl = &ctx->Fallback.Normal;
644 cl->Size = 3;
645 cl->Type = GL_FLOAT;
646 cl->Stride = 0;
647 cl->StrideB = 0;
648 cl->Ptr = (void *) ctx->Current.Normal;
649 cl->Enabled = 1;
650
651 cl = &ctx->Fallback.Color;
652 cl->Size = 4;
653 cl->Type = GL_UNSIGNED_BYTE;
654 cl->Stride = 0;
655 cl->StrideB = 0;
656 cl->Ptr = (void *) ctx->Current.ByteColor;
657 cl->Enabled = 1;
658
659 cl = &ctx->Fallback.Index;
660 cl->Size = 1;
661 cl->Type = GL_UNSIGNED_INT;
662 cl->Stride = 0;
663 cl->StrideB = 0;
664 cl->Ptr = (void *) &ctx->Current.Index;
665 cl->Enabled = 1;
666
667 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
668 cl = &ctx->Fallback.TexCoord[i];
669 cl->Size = 4;
670 cl->Type = GL_FLOAT;
671 cl->Stride = 0;
672 cl->StrideB = 0;
673 cl->Ptr = (void *) ctx->Current.Texcoord[i];
674 cl->Enabled = 1;
675 }
676
677 cl = &ctx->Fallback.EdgeFlag;
678 cl->Size = 1;
679 cl->Type = GL_UNSIGNED_BYTE;
680 cl->Stride = 0;
681 cl->StrideB = 0;
682 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
683 cl->Enabled = 1;
684}
685
Brian Paul4d053dd2000-01-14 04:45:47 +0000686
jtgafb833d1999-08-19 00:55:39 +0000687/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000688static void
689init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000690{
691 map->Order = 1;
692 map->u1 = 0.0;
693 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000694 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000695 if (map->Points) {
696 GLint i;
697 for (i=0;i<n;i++)
698 map->Points[i] = initial[i];
699 }
jtgafb833d1999-08-19 00:55:39 +0000700}
701
702
703/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000704static void
705init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000706{
707 map->Uorder = 1;
708 map->Vorder = 1;
709 map->u1 = 0.0;
710 map->u2 = 1.0;
711 map->v1 = 0.0;
712 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000713 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000714 if (map->Points) {
715 GLint i;
716 for (i=0;i<n;i++)
717 map->Points[i] = initial[i];
718 }
jtgafb833d1999-08-19 00:55:39 +0000719}
720
721
jtgafb833d1999-08-19 00:55:39 +0000722/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000723 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000724 */
Brian Paul178a1c52000-04-22 01:05:00 +0000725static void
726init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000727{
728 GLuint i, j;
729
Brian Paul4d053dd2000-01-14 04:45:47 +0000730 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000731
Brian Paul539cce52000-02-03 19:40:07 +0000732 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000733 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
734 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000735 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000736 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
737 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000738 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
739 ctx->Const.MinPointSize = MIN_POINT_SIZE;
740 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
741 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
742 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
743 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
744 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
745 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
746 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
747 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
748 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
749 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000750 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000751 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
752 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000753 ctx->Const.NumCompressedTextureFormats = 0;
jtgafb833d1999-08-19 00:55:39 +0000754
Brian Paul4d053dd2000-01-14 04:45:47 +0000755 /* Modelview matrix */
756 gl_matrix_ctr( &ctx->ModelView );
757 gl_matrix_alloc_inv( &ctx->ModelView );
758
759 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000760 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000761 gl_matrix_ctr( &ctx->ModelViewStack[i] );
762 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
763 }
764
765 /* Projection matrix - need inv for user clipping in clip space*/
766 gl_matrix_ctr( &ctx->ProjectionMatrix );
767 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
768
769 gl_matrix_ctr( &ctx->ModelProjectMatrix );
770 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
771 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
772
773 ctx->ProjectionStackDepth = 0;
774 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
775 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
776
Brian Paul7fc29c52000-03-06 17:03:03 +0000777 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000778 gl_matrix_ctr( &ctx->ProjectionStack[i] );
779 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
780 }
781
782 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000783 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000784 gl_matrix_ctr( &ctx->TextureMatrix[i] );
785 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000786 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Brian Paul904ecb22000-06-27 23:38:45 +0000787 gl_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000788 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000789 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000790 }
jtgafb833d1999-08-19 00:55:39 +0000791
Brian Paul250069d2000-04-08 18:57:45 +0000792 /* Color matrix */
793 gl_matrix_ctr(&ctx->ColorMatrix);
794 ctx->ColorStackDepth = 0;
795 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
796 gl_matrix_ctr(&ctx->ColorStack[j]);
797 }
798
Brian Paul4d053dd2000-01-14 04:45:47 +0000799 /* Accumulate buffer group */
800 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000801
Brian Paul4d053dd2000-01-14 04:45:47 +0000802 /* Color buffer group */
803 ctx->Color.IndexMask = 0xffffffff;
804 ctx->Color.ColorMask[0] = 0xff;
805 ctx->Color.ColorMask[1] = 0xff;
806 ctx->Color.ColorMask[2] = 0xff;
807 ctx->Color.ColorMask[3] = 0xff;
808 ctx->Color.SWmasking = GL_FALSE;
809 ctx->Color.ClearIndex = 0;
810 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
811 ctx->Color.DrawBuffer = GL_FRONT;
812 ctx->Color.AlphaEnabled = GL_FALSE;
813 ctx->Color.AlphaFunc = GL_ALWAYS;
814 ctx->Color.AlphaRef = 0;
815 ctx->Color.BlendEnabled = GL_FALSE;
816 ctx->Color.BlendSrcRGB = GL_ONE;
817 ctx->Color.BlendDstRGB = GL_ZERO;
818 ctx->Color.BlendSrcA = GL_ONE;
819 ctx->Color.BlendDstA = GL_ZERO;
820 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
821 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
822 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
823 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
824 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
825 ctx->Color.SWLogicOpEnabled = GL_FALSE;
826 ctx->Color.LogicOp = GL_COPY;
827 ctx->Color.DitherFlag = GL_TRUE;
828 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000829
Brian Paul4d053dd2000-01-14 04:45:47 +0000830 /* Current group */
831 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
832 ctx->Current.Index = 1;
833 for (i=0; i<MAX_TEXTURE_UNITS; i++)
834 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
835 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
836 ctx->Current.RasterDistance = 0.0;
837 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
838 ctx->Current.RasterIndex = 1;
839 for (i=0; i<MAX_TEXTURE_UNITS; i++)
840 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
841 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
842 ctx->Current.RasterPosValid = GL_TRUE;
843 ctx->Current.EdgeFlag = GL_TRUE;
844 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
845 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
jtgafb833d1999-08-19 00:55:39 +0000846
Brian Paul4d053dd2000-01-14 04:45:47 +0000847 ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
848 VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
jtgafb833d1999-08-19 00:55:39 +0000849
Brian Paul4d053dd2000-01-14 04:45:47 +0000850 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000851
Brian Paul4d053dd2000-01-14 04:45:47 +0000852 /* Depth buffer group */
853 ctx->Depth.Test = GL_FALSE;
854 ctx->Depth.Clear = 1.0;
855 ctx->Depth.Func = GL_LESS;
856 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000857 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000858
Brian Paul4d053dd2000-01-14 04:45:47 +0000859 /* Evaluators group */
860 ctx->Eval.Map1Color4 = GL_FALSE;
861 ctx->Eval.Map1Index = GL_FALSE;
862 ctx->Eval.Map1Normal = GL_FALSE;
863 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
864 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
865 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
866 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
867 ctx->Eval.Map1Vertex3 = GL_FALSE;
868 ctx->Eval.Map1Vertex4 = GL_FALSE;
869 ctx->Eval.Map2Color4 = GL_FALSE;
870 ctx->Eval.Map2Index = GL_FALSE;
871 ctx->Eval.Map2Normal = GL_FALSE;
872 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
873 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
874 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
875 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
876 ctx->Eval.Map2Vertex3 = GL_FALSE;
877 ctx->Eval.Map2Vertex4 = GL_FALSE;
878 ctx->Eval.AutoNormal = GL_FALSE;
879 ctx->Eval.MapGrid1un = 1;
880 ctx->Eval.MapGrid1u1 = 0.0;
881 ctx->Eval.MapGrid1u2 = 1.0;
882 ctx->Eval.MapGrid2un = 1;
883 ctx->Eval.MapGrid2vn = 1;
884 ctx->Eval.MapGrid2u1 = 0.0;
885 ctx->Eval.MapGrid2u2 = 1.0;
886 ctx->Eval.MapGrid2v1 = 0.0;
887 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000888
Brian Paul4d053dd2000-01-14 04:45:47 +0000889 /* Evaluator data */
890 {
891 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
892 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
893 static GLfloat index[1] = { 1.0 };
894 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
895 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000896
Brian Paul4d053dd2000-01-14 04:45:47 +0000897 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
898 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
899 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
900 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
901 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
902 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
903 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
904 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
905 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000906
Brian Paul4d053dd2000-01-14 04:45:47 +0000907 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
908 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
909 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
910 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
911 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
912 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
913 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
914 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
915 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
916 }
jtgafb833d1999-08-19 00:55:39 +0000917
Brian Paul4d053dd2000-01-14 04:45:47 +0000918 /* Fog group */
919 ctx->Fog.Enabled = GL_FALSE;
920 ctx->Fog.Mode = GL_EXP;
921 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
922 ctx->Fog.Index = 0.0;
923 ctx->Fog.Density = 1.0;
924 ctx->Fog.Start = 0.0;
925 ctx->Fog.End = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000926
Brian Paul4d053dd2000-01-14 04:45:47 +0000927 /* Hint group */
928 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
929 ctx->Hint.PointSmooth = GL_DONT_CARE;
930 ctx->Hint.LineSmooth = GL_DONT_CARE;
931 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
932 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000933 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000934 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000935 ctx->Hint.AllowDrawMem = GL_TRUE;
936 ctx->Hint.StrictLighting = GL_TRUE;
Brian Paul1207bf02000-05-23 20:10:49 +0000937 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
938 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000939
Brian Paul0771d152000-04-07 00:19:41 +0000940 /* Histogram group */
941 ctx->Histogram.Width = 0;
942 ctx->Histogram.Format = GL_RGBA;
943 ctx->Histogram.Sink = GL_FALSE;
944 ctx->Histogram.RedSize = 0xffffffff;
945 ctx->Histogram.GreenSize = 0xffffffff;
946 ctx->Histogram.BlueSize = 0xffffffff;
947 ctx->Histogram.AlphaSize = 0xffffffff;
948 ctx->Histogram.LuminanceSize = 0xffffffff;
949 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
950 ctx->Histogram.Count[i][0] = 0;
951 ctx->Histogram.Count[i][1] = 0;
952 ctx->Histogram.Count[i][2] = 0;
953 ctx->Histogram.Count[i][3] = 0;
954 }
955
956 /* Min/Max group */
957 ctx->MinMax.Format = GL_RGBA;
958 ctx->MinMax.Sink = GL_FALSE;
959 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
960 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
961 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
962 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
963
964
965
Brian Paul4d053dd2000-01-14 04:45:47 +0000966 /* Pipeline */
967 gl_pipeline_init( ctx );
968 gl_cva_init( ctx );
jtgafb833d1999-08-19 00:55:39 +0000969
Brian Paul4d053dd2000-01-14 04:45:47 +0000970 /* Extensions */
971 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000972
Brian Paul4d053dd2000-01-14 04:45:47 +0000973 ctx->AllowVertexCull = CLIP_CULLED_BIT;
jtgafb833d1999-08-19 00:55:39 +0000974
Brian Paul4d053dd2000-01-14 04:45:47 +0000975 /* Lighting group */
976 for (i=0;i<MAX_LIGHTS;i++) {
977 init_light( &ctx->Light.Light[i], i );
978 }
979 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000980
Brian Paul4d053dd2000-01-14 04:45:47 +0000981 init_lightmodel( &ctx->Light.Model );
982 init_material( &ctx->Light.Material[0] );
983 init_material( &ctx->Light.Material[1] );
984 ctx->Light.ShadeModel = GL_SMOOTH;
985 ctx->Light.Enabled = GL_FALSE;
986 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
987 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
988 ctx->Light.ColorMaterialBitmask
989 = gl_material_bitmask( ctx,
990 GL_FRONT_AND_BACK,
991 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000992
Brian Paul4d053dd2000-01-14 04:45:47 +0000993 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000994
Brian Paul4d053dd2000-01-14 04:45:47 +0000995 /* Lighting miscellaneous */
996 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
997 make_empty_list( ctx->ShineTabList );
998 for (i = 0 ; i < 10 ; i++) {
999 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1000 s->shininess = -1;
1001 s->refcount = 0;
1002 insert_at_tail( ctx->ShineTabList, s );
1003 }
1004 for (i = 0 ; i < 4 ; i++) {
1005 ctx->ShineTable[i] = ctx->ShineTabList->prev;
1006 ctx->ShineTable[i]->refcount++;
1007 }
jtgafb833d1999-08-19 00:55:39 +00001008
Brian Paul77d61af2000-06-28 04:20:21 +00001009 gl_compute_shine_table( ctx, 0, ctx->Light.Material[0].Shininess );
1010 gl_compute_shine_table( ctx, 2, ctx->Light.Material[0].Shininess * .5 );
1011 gl_compute_shine_table( ctx, 1, ctx->Light.Material[1].Shininess );
1012 gl_compute_shine_table( ctx, 3, ctx->Light.Material[1].Shininess * .5 );
1013
jtgafb833d1999-08-19 00:55:39 +00001014
Brian Paul4d053dd2000-01-14 04:45:47 +00001015 /* Line group */
1016 ctx->Line.SmoothFlag = GL_FALSE;
1017 ctx->Line.StippleFlag = GL_FALSE;
1018 ctx->Line.Width = 1.0;
1019 ctx->Line.StipplePattern = 0xffff;
1020 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001021
Brian Paul4d053dd2000-01-14 04:45:47 +00001022 /* Display List group */
1023 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001024
Brian Paul4d053dd2000-01-14 04:45:47 +00001025 /* Pixel group */
1026 ctx->Pixel.RedBias = 0.0;
1027 ctx->Pixel.RedScale = 1.0;
1028 ctx->Pixel.GreenBias = 0.0;
1029 ctx->Pixel.GreenScale = 1.0;
1030 ctx->Pixel.BlueBias = 0.0;
1031 ctx->Pixel.BlueScale = 1.0;
1032 ctx->Pixel.AlphaBias = 0.0;
1033 ctx->Pixel.AlphaScale = 1.0;
1034 ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
1035 ctx->Pixel.DepthBias = 0.0;
1036 ctx->Pixel.DepthScale = 1.0;
1037 ctx->Pixel.IndexOffset = 0;
1038 ctx->Pixel.IndexShift = 0;
1039 ctx->Pixel.ZoomX = 1.0;
1040 ctx->Pixel.ZoomY = 1.0;
1041 ctx->Pixel.MapColorFlag = GL_FALSE;
1042 ctx->Pixel.MapStencilFlag = GL_FALSE;
1043 ctx->Pixel.MapStoSsize = 1;
1044 ctx->Pixel.MapItoIsize = 1;
1045 ctx->Pixel.MapItoRsize = 1;
1046 ctx->Pixel.MapItoGsize = 1;
1047 ctx->Pixel.MapItoBsize = 1;
1048 ctx->Pixel.MapItoAsize = 1;
1049 ctx->Pixel.MapRtoRsize = 1;
1050 ctx->Pixel.MapGtoGsize = 1;
1051 ctx->Pixel.MapBtoBsize = 1;
1052 ctx->Pixel.MapAtoAsize = 1;
1053 ctx->Pixel.MapStoS[0] = 0;
1054 ctx->Pixel.MapItoI[0] = 0;
1055 ctx->Pixel.MapItoR[0] = 0.0;
1056 ctx->Pixel.MapItoG[0] = 0.0;
1057 ctx->Pixel.MapItoB[0] = 0.0;
1058 ctx->Pixel.MapItoA[0] = 0.0;
1059 ctx->Pixel.MapItoR8[0] = 0;
1060 ctx->Pixel.MapItoG8[0] = 0;
1061 ctx->Pixel.MapItoB8[0] = 0;
1062 ctx->Pixel.MapItoA8[0] = 0;
1063 ctx->Pixel.MapRtoR[0] = 0.0;
1064 ctx->Pixel.MapGtoG[0] = 0.0;
1065 ctx->Pixel.MapBtoB[0] = 0.0;
1066 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001067 ctx->Pixel.HistogramEnabled = GL_FALSE;
1068 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1069 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1070 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1071 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001072 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1073 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1074 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1075 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001076 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1077 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1078 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1079 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001080 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1081 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1082 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001083 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1084 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1085 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1086 for (i = 0; i < 3; i++) {
1087 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1088 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1089 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1090 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1091 }
1092 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1093 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001094
Brian Paul4d053dd2000-01-14 04:45:47 +00001095 /* Point group */
1096 ctx->Point.SmoothFlag = GL_FALSE;
Brian Paula25f7e12000-06-27 04:29:22 +00001097 ctx->Point.UserSize = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001098 ctx->Point.Size = 1.0;
1099 ctx->Point.Params[0] = 1.0;
1100 ctx->Point.Params[1] = 0.0;
1101 ctx->Point.Params[2] = 0.0;
1102 ctx->Point.Attenuated = GL_FALSE;
1103 ctx->Point.MinSize = 0.0;
1104 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1105 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001106
Brian Paul4d053dd2000-01-14 04:45:47 +00001107 /* Polygon group */
1108 ctx->Polygon.CullFlag = GL_FALSE;
1109 ctx->Polygon.CullFaceMode = GL_BACK;
1110 ctx->Polygon.FrontFace = GL_CCW;
1111 ctx->Polygon.FrontBit = 0;
1112 ctx->Polygon.FrontMode = GL_FILL;
1113 ctx->Polygon.BackMode = GL_FILL;
1114 ctx->Polygon.Unfilled = GL_FALSE;
1115 ctx->Polygon.SmoothFlag = GL_FALSE;
1116 ctx->Polygon.StippleFlag = GL_FALSE;
1117 ctx->Polygon.OffsetFactor = 0.0F;
1118 ctx->Polygon.OffsetUnits = 0.0F;
1119 ctx->Polygon.OffsetPoint = GL_FALSE;
1120 ctx->Polygon.OffsetLine = GL_FALSE;
1121 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001122
Brian Paul4d053dd2000-01-14 04:45:47 +00001123 /* Polygon Stipple group */
1124 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001125
Brian Paul4d053dd2000-01-14 04:45:47 +00001126 /* Scissor group */
1127 ctx->Scissor.Enabled = GL_FALSE;
1128 ctx->Scissor.X = 0;
1129 ctx->Scissor.Y = 0;
1130 ctx->Scissor.Width = 0;
1131 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001132
Brian Paul4d053dd2000-01-14 04:45:47 +00001133 /* Stencil group */
1134 ctx->Stencil.Enabled = GL_FALSE;
1135 ctx->Stencil.Function = GL_ALWAYS;
1136 ctx->Stencil.FailFunc = GL_KEEP;
1137 ctx->Stencil.ZPassFunc = GL_KEEP;
1138 ctx->Stencil.ZFailFunc = GL_KEEP;
1139 ctx->Stencil.Ref = 0;
1140 ctx->Stencil.ValueMask = STENCIL_MAX;
1141 ctx->Stencil.Clear = 0;
1142 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001143
Brian Paul4d053dd2000-01-14 04:45:47 +00001144 /* Texture group */
1145 ctx->Texture.CurrentUnit = 0; /* multitexture */
1146 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
1147 ctx->Texture.Enabled = 0;
1148 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1149 init_texture_unit( ctx, i );
Brian Paul4bdcfe52000-04-17 17:57:04 +00001150 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001151
Brian Paul4d053dd2000-01-14 04:45:47 +00001152 /* Transformation group */
1153 ctx->Transform.MatrixMode = GL_MODELVIEW;
1154 ctx->Transform.Normalize = GL_FALSE;
1155 ctx->Transform.RescaleNormals = GL_FALSE;
1156 for (i=0;i<MAX_CLIP_PLANES;i++) {
1157 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1158 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1159 }
1160 ctx->Transform.AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001161
Brian Paul4d053dd2000-01-14 04:45:47 +00001162 /* Viewport group */
1163 ctx->Viewport.X = 0;
1164 ctx->Viewport.Y = 0;
1165 ctx->Viewport.Width = 0;
1166 ctx->Viewport.Height = 0;
1167 ctx->Viewport.Near = 0.0;
1168 ctx->Viewport.Far = 1.0;
1169 gl_matrix_ctr(&ctx->Viewport.WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001170
1171#define Sz 10
1172#define Tz 14
Brian Pauled30dfa2000-03-03 17:47:39 +00001173 ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual->DepthMaxF;
1174 ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001175#undef Sz
1176#undef Tz
1177
Brian Paul4d053dd2000-01-14 04:45:47 +00001178 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1179 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001180
Brian Paul4d053dd2000-01-14 04:45:47 +00001181 /* Vertex arrays */
1182 ctx->Array.Vertex.Size = 4;
1183 ctx->Array.Vertex.Type = GL_FLOAT;
1184 ctx->Array.Vertex.Stride = 0;
1185 ctx->Array.Vertex.StrideB = 0;
1186 ctx->Array.Vertex.Ptr = NULL;
1187 ctx->Array.Vertex.Enabled = GL_FALSE;
1188 ctx->Array.Normal.Type = GL_FLOAT;
1189 ctx->Array.Normal.Stride = 0;
1190 ctx->Array.Normal.StrideB = 0;
1191 ctx->Array.Normal.Ptr = NULL;
1192 ctx->Array.Normal.Enabled = GL_FALSE;
1193 ctx->Array.Color.Size = 4;
1194 ctx->Array.Color.Type = GL_FLOAT;
1195 ctx->Array.Color.Stride = 0;
1196 ctx->Array.Color.StrideB = 0;
1197 ctx->Array.Color.Ptr = NULL;
1198 ctx->Array.Color.Enabled = GL_FALSE;
1199 ctx->Array.Index.Type = GL_FLOAT;
1200 ctx->Array.Index.Stride = 0;
1201 ctx->Array.Index.StrideB = 0;
1202 ctx->Array.Index.Ptr = NULL;
1203 ctx->Array.Index.Enabled = GL_FALSE;
1204 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1205 ctx->Array.TexCoord[i].Size = 4;
1206 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1207 ctx->Array.TexCoord[i].Stride = 0;
1208 ctx->Array.TexCoord[i].StrideB = 0;
1209 ctx->Array.TexCoord[i].Ptr = NULL;
1210 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1211 }
1212 ctx->Array.TexCoordInterleaveFactor = 1;
1213 ctx->Array.EdgeFlag.Stride = 0;
1214 ctx->Array.EdgeFlag.StrideB = 0;
1215 ctx->Array.EdgeFlag.Ptr = NULL;
1216 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1217 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1218
1219 /* Pixel transfer */
1220 ctx->Pack.Alignment = 4;
1221 ctx->Pack.RowLength = 0;
1222 ctx->Pack.ImageHeight = 0;
1223 ctx->Pack.SkipPixels = 0;
1224 ctx->Pack.SkipRows = 0;
1225 ctx->Pack.SkipImages = 0;
1226 ctx->Pack.SwapBytes = GL_FALSE;
1227 ctx->Pack.LsbFirst = GL_FALSE;
1228 ctx->Unpack.Alignment = 4;
1229 ctx->Unpack.RowLength = 0;
1230 ctx->Unpack.ImageHeight = 0;
1231 ctx->Unpack.SkipPixels = 0;
1232 ctx->Unpack.SkipRows = 0;
1233 ctx->Unpack.SkipImages = 0;
1234 ctx->Unpack.SwapBytes = GL_FALSE;
1235 ctx->Unpack.LsbFirst = GL_FALSE;
1236
1237 /* Feedback */
1238 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1239 ctx->Feedback.Buffer = NULL;
1240 ctx->Feedback.BufferSize = 0;
1241 ctx->Feedback.Count = 0;
1242
1243 /* Selection/picking */
1244 ctx->Select.Buffer = NULL;
1245 ctx->Select.BufferSize = 0;
1246 ctx->Select.BufferCount = 0;
1247 ctx->Select.Hits = 0;
1248 ctx->Select.NameStackDepth = 0;
1249
1250 /* Optimized Accum buffer */
1251 ctx->IntegerAccumMode = GL_TRUE;
1252 ctx->IntegerAccumScaler = 0.0;
1253
1254 /* Renderer and client attribute stacks */
1255 ctx->AttribStackDepth = 0;
1256 ctx->ClientAttribStackDepth = 0;
1257
Brian Paul13811372000-04-12 00:27:37 +00001258 /* Display list */
1259 ctx->CallDepth = 0;
1260 ctx->ExecuteFlag = GL_TRUE;
1261 ctx->CompileFlag = GL_FALSE;
1262 ctx->CurrentListPtr = NULL;
1263 ctx->CurrentBlock = NULL;
1264 ctx->CurrentListNum = 0;
1265 ctx->CurrentPos = 0;
1266
1267 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001268 _mesa_init_colortable(&ctx->ColorTable);
1269 _mesa_init_colortable(&ctx->ProxyColorTable);
1270 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1271 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1272 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1273 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001274
Brian Paul4d053dd2000-01-14 04:45:47 +00001275 /* Miscellaneous */
1276 ctx->NewState = NEW_ALL;
1277 ctx->RenderMode = GL_RENDER;
1278 ctx->StippleCounter = 0;
1279 ctx->NeedNormals = GL_FALSE;
1280 ctx->DoViewportMapping = GL_TRUE;
1281
1282 ctx->NeedEyeCoords = GL_FALSE;
1283 ctx->NeedEyeNormals = GL_FALSE;
1284 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1285
Brian Paul4d053dd2000-01-14 04:45:47 +00001286 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1287
1288 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001289 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001290 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001291
1292 /* For debug/development only */
1293 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1294 ctx->FirstTimeCurrent = GL_TRUE;
1295
1296 /* Dither disable */
1297 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1298 if (ctx->NoDither) {
1299 if (getenv("MESA_DEBUG")) {
1300 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001301 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001302 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001303 }
1304}
1305
1306
1307
1308
jtgafb833d1999-08-19 00:55:39 +00001309/*
1310 * Allocate the proxy textures. If we run out of memory part way through
1311 * the allocations clean up and return GL_FALSE.
1312 * Return: GL_TRUE=success, GL_FALSE=failure
1313 */
Brian Paul178a1c52000-04-22 01:05:00 +00001314static GLboolean
1315alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001316{
1317 GLboolean out_of_memory;
1318 GLint i;
1319
1320 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1321 if (!ctx->Texture.Proxy1D) {
1322 return GL_FALSE;
1323 }
1324
1325 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1326 if (!ctx->Texture.Proxy2D) {
1327 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1328 return GL_FALSE;
1329 }
1330
1331 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1332 if (!ctx->Texture.Proxy3D) {
1333 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1334 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1335 return GL_FALSE;
1336 }
1337
1338 out_of_memory = GL_FALSE;
1339 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001340 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1341 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1342 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001343 if (!ctx->Texture.Proxy1D->Image[i]
1344 || !ctx->Texture.Proxy2D->Image[i]
1345 || !ctx->Texture.Proxy3D->Image[i]) {
1346 out_of_memory = GL_TRUE;
1347 }
1348 }
1349 if (out_of_memory) {
1350 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1351 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001352 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001353 }
1354 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001355 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001356 }
1357 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001358 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001359 }
1360 }
1361 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1362 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1363 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1364 return GL_FALSE;
1365 }
1366 else {
1367 return GL_TRUE;
1368 }
1369}
1370
1371
1372
jtgafb833d1999-08-19 00:55:39 +00001373/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001374 * Initialize a GLcontext struct.
jtgafb833d1999-08-19 00:55:39 +00001375 */
Brian Paul178a1c52000-04-22 01:05:00 +00001376GLboolean
1377_mesa_initialize_context( GLcontext *ctx,
1378 GLvisual *visual,
1379 GLcontext *share_list,
1380 void *driver_ctx,
1381 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001382{
Brian Paul5fb84d22000-05-24 15:04:45 +00001383 GLuint dispatchSize;
1384
jtgafb833d1999-08-19 00:55:39 +00001385 (void) direct; /* not used */
1386
jtgafb833d1999-08-19 00:55:39 +00001387 /* misc one-time initializations */
1388 one_time_init();
1389
jtgafb833d1999-08-19 00:55:39 +00001390 ctx->DriverCtx = driver_ctx;
1391 ctx->Visual = visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001392 ctx->DrawBuffer = NULL;
1393 ctx->ReadBuffer = NULL;
jtgafb833d1999-08-19 00:55:39 +00001394
1395 ctx->VB = gl_vb_create_for_immediate( ctx );
1396 if (!ctx->VB) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001397 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001398 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001399 }
1400 ctx->input = ctx->VB->IM;
1401
1402 ctx->PB = gl_alloc_pb();
1403 if (!ctx->PB) {
Brian Paul2d8db392000-06-27 22:10:00 +00001404 ALIGN_FREE( ctx->VB );
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001405 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001406 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001407 }
1408
1409 if (share_list) {
1410 /* share the group of display lists of another context */
1411 ctx->Shared = share_list->Shared;
1412 }
1413 else {
1414 /* allocate new group of display lists */
1415 ctx->Shared = alloc_shared_state();
1416 if (!ctx->Shared) {
Brian Paul2d8db392000-06-27 22:10:00 +00001417 ALIGN_FREE( ctx->VB );
1418 FREE( ctx->PB );
1419 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001420 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001421 }
1422 }
Brian Paul9560f052000-01-31 23:11:39 +00001423 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001424 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001425 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001426
Brian Paul4d053dd2000-01-14 04:45:47 +00001427 init_attrib_groups( ctx );
1428
jtgafb833d1999-08-19 00:55:39 +00001429 gl_reset_vb( ctx->VB );
1430 gl_reset_input( ctx );
1431
jtgafb833d1999-08-19 00:55:39 +00001432 if (visual->DBflag) {
1433 ctx->Color.DrawBuffer = GL_BACK;
1434 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1435 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1436 ctx->Pixel.ReadBuffer = GL_BACK;
1437 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1438 }
1439 else {
1440 ctx->Color.DrawBuffer = GL_FRONT;
1441 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1442 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1443 ctx->Pixel.ReadBuffer = GL_FRONT;
1444 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1445 }
1446
jtgafb833d1999-08-19 00:55:39 +00001447 if (!alloc_proxy_textures(ctx)) {
1448 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001449 ALIGN_FREE( ctx->VB );
1450 FREE( ctx->PB );
1451 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001452 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001453 }
jtgafb833d1999-08-19 00:55:39 +00001454
Brian Paulf59afc92000-05-23 23:23:00 +00001455 /* register the most recent extension functions with libGL */
1456 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1457 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1458 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1459 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1460 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1461 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1462 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1463 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1464
Brian Paul5fb84d22000-05-24 15:04:45 +00001465 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1466 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1467 * Mesa we do this to accomodate different versions of libGL and various
1468 * DRI drivers.
1469 */
1470 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1471 sizeof(struct _glapi_table) / sizeof(void *));
1472
Brian Paulfbd8f211999-11-11 01:22:25 +00001473 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001474 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1475 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001476 if (!ctx->Exec || !ctx->Save) {
1477 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001478 ALIGN_FREE( ctx->VB );
1479 FREE( ctx->PB );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001480 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001481 FREE( ctx->Exec );
1482 FREE( ctx );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001483 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001484 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1485 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001486 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001487
Brian Paul4d053dd2000-01-14 04:45:47 +00001488 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001489}
1490
jtgafb833d1999-08-19 00:55:39 +00001491
1492
1493/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001494 * Allocate and initialize a GLcontext structure.
1495 * Input: visual - a GLvisual pointer
1496 * sharelist - another context to share display lists with or NULL
1497 * driver_ctx - pointer to device driver's context state struct
1498 * Return: pointer to a new gl_context struct or NULL if error.
1499 */
Brian Paul178a1c52000-04-22 01:05:00 +00001500GLcontext *
1501gl_create_context( GLvisual *visual,
1502 GLcontext *share_list,
1503 void *driver_ctx,
1504 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001505{
1506 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1507 if (!ctx) {
1508 return NULL;
1509 }
1510
Brian Paul178a1c52000-04-22 01:05:00 +00001511 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001512 return ctx;
1513 }
1514 else {
1515 FREE(ctx);
1516 return NULL;
1517 }
1518}
1519
1520
1521
1522/*
1523 * Free the data associated with the given context.
1524 * But don't free() the GLcontext struct itself!
1525 */
Brian Paul178a1c52000-04-22 01:05:00 +00001526void
1527gl_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001528{
Brian Paul4d053dd2000-01-14 04:45:47 +00001529 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001530 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001531
1532 /* if we're destroying the current context, unbind it first */
1533 if (ctx == gl_get_current_context()) {
1534 gl_make_current(NULL, NULL);
1535 }
1536
Brian Paul4d053dd2000-01-14 04:45:47 +00001537 gl_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001538 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001539 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1540 }
1541 gl_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001542 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001543 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1544 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001545 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1546 gl_matrix_dtr( &ctx->TextureMatrix[i] );
1547 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1548 gl_matrix_dtr( &ctx->TextureStack[i][j] );
1549 }
1550 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001551
1552 FREE( ctx->PB );
1553
Brian Paul4bdcfe52000-04-17 17:57:04 +00001554 if (ctx->input != ctx->VB->IM)
Brian Paul4d053dd2000-01-14 04:45:47 +00001555 gl_immediate_free( ctx->input );
1556
1557 gl_vb_free( ctx->VB );
1558
Brian Paul9560f052000-01-31 23:11:39 +00001559 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001560 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001561 assert(ctx->Shared->RefCount >= 0);
1562 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1563 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001564 /* free shared state */
1565 free_shared_state( ctx, ctx->Shared );
1566 }
1567
1568 foreach_s( s, tmps, ctx->ShineTabList ) {
1569 FREE( s );
1570 }
1571 FREE( ctx->ShineTabList );
1572
1573 /* Free proxy texture objects */
1574 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1575 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1576 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1577
1578 /* Free evaluator data */
1579 if (ctx->EvalMap.Map1Vertex3.Points)
1580 FREE( ctx->EvalMap.Map1Vertex3.Points );
1581 if (ctx->EvalMap.Map1Vertex4.Points)
1582 FREE( ctx->EvalMap.Map1Vertex4.Points );
1583 if (ctx->EvalMap.Map1Index.Points)
1584 FREE( ctx->EvalMap.Map1Index.Points );
1585 if (ctx->EvalMap.Map1Color4.Points)
1586 FREE( ctx->EvalMap.Map1Color4.Points );
1587 if (ctx->EvalMap.Map1Normal.Points)
1588 FREE( ctx->EvalMap.Map1Normal.Points );
1589 if (ctx->EvalMap.Map1Texture1.Points)
1590 FREE( ctx->EvalMap.Map1Texture1.Points );
1591 if (ctx->EvalMap.Map1Texture2.Points)
1592 FREE( ctx->EvalMap.Map1Texture2.Points );
1593 if (ctx->EvalMap.Map1Texture3.Points)
1594 FREE( ctx->EvalMap.Map1Texture3.Points );
1595 if (ctx->EvalMap.Map1Texture4.Points)
1596 FREE( ctx->EvalMap.Map1Texture4.Points );
1597
1598 if (ctx->EvalMap.Map2Vertex3.Points)
1599 FREE( ctx->EvalMap.Map2Vertex3.Points );
1600 if (ctx->EvalMap.Map2Vertex4.Points)
1601 FREE( ctx->EvalMap.Map2Vertex4.Points );
1602 if (ctx->EvalMap.Map2Index.Points)
1603 FREE( ctx->EvalMap.Map2Index.Points );
1604 if (ctx->EvalMap.Map2Color4.Points)
1605 FREE( ctx->EvalMap.Map2Color4.Points );
1606 if (ctx->EvalMap.Map2Normal.Points)
1607 FREE( ctx->EvalMap.Map2Normal.Points );
1608 if (ctx->EvalMap.Map2Texture1.Points)
1609 FREE( ctx->EvalMap.Map2Texture1.Points );
1610 if (ctx->EvalMap.Map2Texture2.Points)
1611 FREE( ctx->EvalMap.Map2Texture2.Points );
1612 if (ctx->EvalMap.Map2Texture3.Points)
1613 FREE( ctx->EvalMap.Map2Texture3.Points );
1614 if (ctx->EvalMap.Map2Texture4.Points)
1615 FREE( ctx->EvalMap.Map2Texture4.Points );
1616
Brian Paul4bdcfe52000-04-17 17:57:04 +00001617 _mesa_free_colortable_data( &ctx->ColorTable );
1618 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1619 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1620 _mesa_free_colortable_data( &ctx->Texture.Palette );
1621
Brian Paul4d053dd2000-01-14 04:45:47 +00001622 /* Free cache of immediate buffers. */
1623 while (ctx->nr_im_queued-- > 0) {
1624 struct immediate * next = ctx->freed_im_queue->next;
Brian Paul2d8db392000-06-27 22:10:00 +00001625 ALIGN_FREE( ctx->freed_im_queue );
Brian Paul4d053dd2000-01-14 04:45:47 +00001626 ctx->freed_im_queue = next;
1627 }
1628 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001629
1630 FREE(ctx->Exec);
1631 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001632}
1633
1634
1635
1636/*
1637 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001638 */
Brian Paul178a1c52000-04-22 01:05:00 +00001639void
1640gl_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001641{
1642 if (ctx) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001643 gl_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001644 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001645 }
1646}
1647
1648
1649
1650/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001651 * Called by the driver after both the context and driver are fully
1652 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001653 */
Brian Paul178a1c52000-04-22 01:05:00 +00001654void
1655gl_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001656{
Brian Paul00037781999-12-17 14:52:35 +00001657 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001658}
1659
1660
1661
1662/*
1663 * Copy attribute groups from one context to another.
1664 * Input: src - source context
1665 * dst - destination context
1666 * mask - bitwise OR of GL_*_BIT flags
1667 */
Brian Paul178a1c52000-04-22 01:05:00 +00001668void
1669gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001670{
1671 if (mask & GL_ACCUM_BUFFER_BIT) {
1672 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1673 }
1674 if (mask & GL_COLOR_BUFFER_BIT) {
1675 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1676 }
1677 if (mask & GL_CURRENT_BIT) {
1678 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1679 }
1680 if (mask & GL_DEPTH_BUFFER_BIT) {
1681 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1682 }
1683 if (mask & GL_ENABLE_BIT) {
1684 /* no op */
1685 }
1686 if (mask & GL_EVAL_BIT) {
1687 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1688 }
1689 if (mask & GL_FOG_BIT) {
1690 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1691 }
1692 if (mask & GL_HINT_BIT) {
1693 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1694 }
1695 if (mask & GL_LIGHTING_BIT) {
1696 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001697 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001698 }
1699 if (mask & GL_LINE_BIT) {
1700 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1701 }
1702 if (mask & GL_LIST_BIT) {
1703 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1704 }
1705 if (mask & GL_PIXEL_MODE_BIT) {
1706 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1707 }
1708 if (mask & GL_POINT_BIT) {
1709 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1710 }
1711 if (mask & GL_POLYGON_BIT) {
1712 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1713 }
1714 if (mask & GL_POLYGON_STIPPLE_BIT) {
1715 /* Use loop instead of MEMCPY due to problem with Portland Group's
1716 * C compiler. Reported by John Stone.
1717 */
1718 int i;
1719 for (i=0;i<32;i++) {
1720 dst->PolygonStipple[i] = src->PolygonStipple[i];
1721 }
1722 }
1723 if (mask & GL_SCISSOR_BIT) {
1724 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1725 }
1726 if (mask & GL_STENCIL_BUFFER_BIT) {
1727 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1728 }
1729 if (mask & GL_TEXTURE_BIT) {
1730 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1731 }
1732 if (mask & GL_TRANSFORM_BIT) {
1733 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1734 }
1735 if (mask & GL_VIEWPORT_BIT) {
1736 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1737 }
1738}
1739
1740
jtgafb833d1999-08-19 00:55:39 +00001741/*
Brian Paul00037781999-12-17 14:52:35 +00001742 * Set the current context, binding the given frame buffer to the context.
1743 */
1744void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1745{
1746 gl_make_current2( newCtx, buffer, buffer );
1747}
1748
1749
1750/*
1751 * Bind the given context to the given draw-buffer and read-buffer
1752 * and make it the current context for this thread.
1753 */
1754void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1755 GLframebuffer *readBuffer )
1756{
1757#if 0
Brian Paulf9b97d92000-01-28 20:17:42 +00001758 GLcontext *oldCtx = gl_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001759
1760 /* Flush the old context
1761 */
1762 if (oldCtx) {
1763 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
1764
1765 /* unbind frame buffers from context */
1766 if (oldCtx->DrawBuffer) {
1767 oldCtx->DrawBuffer = NULL;
1768 }
1769 if (oldCtx->ReadBuffer) {
1770 oldCtx->ReadBuffer = NULL;
1771 }
1772 }
1773#endif
1774
1775 /* We call this function periodically (just here for now) in
1776 * order to detect when multithreading has begun.
1777 */
1778 _glapi_check_multithread();
1779
Brian Paulf9b97d92000-01-28 20:17:42 +00001780 _glapi_set_context((void *) newCtx);
Brian Paul00037781999-12-17 14:52:35 +00001781 ASSERT(gl_get_current_context() == newCtx);
1782 if (newCtx) {
1783 SET_IMMEDIATE(newCtx, newCtx->input);
1784 _glapi_set_dispatch(newCtx->CurrentDispatch);
1785 }
1786 else {
1787 _glapi_set_dispatch(NULL); /* none current */
1788 }
1789
1790 if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
1791
1792 if (newCtx && drawBuffer && readBuffer) {
1793 /* TODO: check if newCtx and buffer's visual match??? */
1794 newCtx->DrawBuffer = drawBuffer;
1795 newCtx->ReadBuffer = readBuffer;
1796 newCtx->NewState = NEW_ALL; /* just to be safe */
1797 gl_update_state( newCtx );
1798 }
1799
1800 /* We can use this to help debug user's problems. Tell the to set
1801 * the MESA_INFO env variable before running their app. Then the
1802 * first time each context is made current we'll print some useful
1803 * information.
1804 */
1805 if (newCtx && newCtx->FirstTimeCurrent) {
1806 if (getenv("MESA_INFO")) {
1807 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1808 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1809 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1810 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
Brian Paul09cb1481999-12-17 17:00:32 +00001811#if defined(THREADS)
1812 fprintf(stderr, "Mesa thread-safe: YES\n");
1813#else
1814 fprintf(stderr, "Mesa thread-safe: NO\n");
1815#endif
Brian Paul54287052000-01-17 20:00:15 +00001816#if defined(USE_X86_ASM)
1817 fprintf(stderr, "Mesa x86-optimized: YES\n");
1818#else
1819 fprintf(stderr, "Mesa x86-optimized: NO\n");
1820#endif
Brian Paul00037781999-12-17 14:52:35 +00001821 }
1822 newCtx->FirstTimeCurrent = GL_FALSE;
1823 }
1824}
1825
1826
1827
1828/*
1829 * Return current context handle for the calling thread.
1830 * This isn't the fastest way to get the current context.
1831 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1832 */
1833GLcontext *gl_get_current_context( void )
1834{
Brian Paulf9b97d92000-01-28 20:17:42 +00001835 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001836}
1837
1838
1839
1840/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001841 * This should be called by device drivers just before they do a
1842 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001843 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001844void
1845_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001846{
Brian Paulfbd8f211999-11-11 01:22:25 +00001847 FLUSH_VB( ctx, "swap buffers" );
jtgafb833d1999-08-19 00:55:39 +00001848}
1849
1850
Brian Paul00037781999-12-17 14:52:35 +00001851
Brian Paulfbd8f211999-11-11 01:22:25 +00001852/*
1853 * Return pointer to this context's current API dispatch table.
1854 * It'll either be the immediate-mode execute dispatcher or the
1855 * display list compile dispatcher.
1856 */
1857struct _glapi_table *
1858_mesa_get_dispatch(GLcontext *ctx)
1859{
1860 return ctx->CurrentDispatch;
1861}
1862
1863
1864
jtgafb833d1999-08-19 00:55:39 +00001865/**********************************************************************/
1866/***** Miscellaneous functions *****/
1867/**********************************************************************/
1868
1869
1870/*
1871 * This function is called when the Mesa user has stumbled into a code
1872 * path which may not be implemented fully or correctly.
1873 */
1874void gl_problem( const GLcontext *ctx, const char *s )
1875{
1876 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paul413d6a22000-05-26 14:44:59 +00001877 fprintf( stderr, "Report to Mesa bug database at www.mesa3d.org\n" );
jtgafb833d1999-08-19 00:55:39 +00001878 (void) ctx;
1879}
1880
1881
1882
1883/*
1884 * This is called to inform the user that he or she has tried to do
1885 * something illogical or if there's likely a bug in their program
1886 * (like enabled depth testing without a depth buffer).
1887 */
1888void gl_warning( const GLcontext *ctx, const char *s )
1889{
1890 GLboolean debug;
1891#ifdef DEBUG
1892 debug = GL_TRUE;
1893#else
1894 if (getenv("MESA_DEBUG")) {
1895 debug = GL_TRUE;
1896 }
1897 else {
1898 debug = GL_FALSE;
1899 }
1900#endif
1901 if (debug) {
1902 fprintf( stderr, "Mesa warning: %s\n", s );
1903 }
1904 (void) ctx;
1905}
1906
1907
1908
Brian Paulfa9df402000-02-02 19:16:46 +00001909/*
1910 * Compile an error into current display list.
1911 */
jtgafb833d1999-08-19 00:55:39 +00001912void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
1913{
1914 if (ctx->CompileFlag)
1915 gl_save_error( ctx, error, s );
1916
1917 if (ctx->ExecuteFlag)
1918 gl_error( ctx, error, s );
1919}
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
1933gl_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);
2000 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
2001 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);
2012 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
2013 if (ctx->Driver.Flush) {
2014 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002015 }
jtgafb833d1999-08-19 00:55:39 +00002016}