blob: 9f31dac2014a14cc2d53c95929348b558a9b0e76 [file] [log] [blame]
Brian Paul178a1c52000-04-22 01:05:00 +00001/* $Id: context.c,v 1.61 2000/04/22 01:05:00 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
98 * alphaFlag - alloc software alpha buffers?
99 * dbFlag - double buffering?
100 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000101 * depthBits - requested bits per depth buffer value
102 * Any value in [0, 32] is acceptable but the actual
103 * depth type will be GLushort or GLuint as needed.
104 * stencilBits - requested minimum bits per stencil buffer value
105 * accumBits - requested minimum bits per accum buffer component
106 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
107 * red/green/blue/alphaBits - number of bits per color component
108 * in frame buffer for RGB(A) mode.
109 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000110 * Return: pointer to new GLvisual or NULL if requested parameters can't
111 * be met.
112 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000113GLvisual *
114_mesa_create_visual( GLboolean rgbFlag,
115 GLboolean alphaFlag,
116 GLboolean dbFlag,
117 GLboolean stereoFlag,
118 GLint redBits,
119 GLint greenBits,
120 GLint blueBits,
121 GLint alphaBits,
122 GLint indexBits,
123 GLint depthBits,
124 GLint stencilBits,
125 GLint accumRedBits,
126 GLint accumGreenBits,
127 GLint accumBlueBits,
128 GLint accumAlphaBits,
129 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000130{
Brian Paul178a1c52000-04-22 01:05:00 +0000131 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
132 if (vis) {
133 if (!_mesa_initialize_visual(vis, rgbFlag, alphaFlag, dbFlag, stereoFlag,
134 redBits, greenBits, blueBits, alphaBits,
135 indexBits, depthBits, stencilBits,
136 accumRedBits, accumGreenBits,
137 accumBlueBits, accumAlphaBits,
138 numSamples )) {
139 FREE(vis);
140 return NULL;
141 }
142 }
143 return vis;
144}
145
146
147/*
148 * Initialize the fields of the given GLvisual.
149 * Input: see _mesa_create_visual() above.
150 * Return: GL_TRUE = success
151 * GL_FALSE = failure.
152 */
153GLboolean
154_mesa_initialize_visual( GLvisual *vis,
155 GLboolean rgbFlag,
156 GLboolean alphaFlag,
157 GLboolean dbFlag,
158 GLboolean stereoFlag,
159 GLint redBits,
160 GLint greenBits,
161 GLint blueBits,
162 GLint alphaBits,
163 GLint indexBits,
164 GLint depthBits,
165 GLint stencilBits,
166 GLint accumRedBits,
167 GLint accumGreenBits,
168 GLint accumBlueBits,
169 GLint accumAlphaBits,
170 GLint numSamples )
171{
172 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000173
Brian Pauled30dfa2000-03-03 17:47:39 +0000174 /* This is to catch bad values from device drivers not updated for
175 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
176 * bad value now (a 1-bit depth buffer!?!).
177 */
178 assert(depthBits == 0 || depthBits > 1);
179
180 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000181 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000182 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000183 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000184 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000185 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000186 if (accumRedBits < 0 || accumRedBits > (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 (accumGreenBits < 0 || accumGreenBits > (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 (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000193 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000194 }
195 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000196 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000197 }
198
199 vis->RGBAflag = rgbFlag;
200 vis->DBflag = dbFlag;
201 vis->StereoFlag = stereoFlag;
202 vis->RedBits = redBits;
203 vis->GreenBits = greenBits;
204 vis->BlueBits = blueBits;
Brian Pauled30dfa2000-03-03 17:47:39 +0000205 vis->AlphaBits = alphaFlag ? (8 * sizeof(GLubyte)) : alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000206
Brian Paulb371e0d2000-03-31 01:05:51 +0000207 vis->IndexBits = indexBits;
208 vis->DepthBits = depthBits;
209 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
210 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
211 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
212 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
213 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000214
215 vis->SoftwareAlpha = alphaFlag;
216
Brian Pauled30dfa2000-03-03 17:47:39 +0000217 if (depthBits == 0) {
218 /* Special case. Even if we don't have a depth buffer we need
219 * good values for DepthMax for Z vertex transformation purposes.
220 */
221 vis->DepthMax = 1;
222 vis->DepthMaxF = 1.0F;
223 }
224 else {
225 vis->DepthMax = (1 << depthBits) - 1;
226 vis->DepthMaxF = (GLfloat) vis->DepthMax;
227 }
228
Brian Paul178a1c52000-04-22 01:05:00 +0000229 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000230}
231
232
Brian Paulb371e0d2000-03-31 01:05:51 +0000233/* This function should no longer be used. Use _mesa_create_visual() instead */
Brian Paul178a1c52000-04-22 01:05:00 +0000234GLvisual *
235gl_create_visual( GLboolean rgbFlag,
236 GLboolean alphaFlag,
237 GLboolean dbFlag,
238 GLboolean stereoFlag,
239 GLint depthBits,
240 GLint stencilBits,
241 GLint accumBits,
242 GLint indexBits,
243 GLint redBits,
244 GLint greenBits,
245 GLint blueBits,
246 GLint alphaBits )
Brian Paulb371e0d2000-03-31 01:05:51 +0000247{
248 return _mesa_create_visual(rgbFlag, alphaFlag, dbFlag, stereoFlag,
249 redBits, greenBits, blueBits, alphaBits,
250 indexBits, depthBits, stencilBits,
251 accumBits, accumBits, accumBits, accumBits, 0);
252}
Brian Paul4d053dd2000-01-14 04:45:47 +0000253
Brian Paulb371e0d2000-03-31 01:05:51 +0000254
255void
256_mesa_destroy_visual( GLvisual *vis )
257{
258 FREE(vis);
259}
260
261
262/* obsolete */
Brian Paul178a1c52000-04-22 01:05:00 +0000263void
264gl_destroy_visual( GLvisual *vis )
Brian Paul4d053dd2000-01-14 04:45:47 +0000265{
Brian Paulb371e0d2000-03-31 01:05:51 +0000266 _mesa_destroy_visual(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000267}
268
269
270
271/**********************************************************************/
272/***** GL Framebuffer allocation/destruction *****/
273/**********************************************************************/
274
275
276/*
277 * Create a new framebuffer. A GLframebuffer is a struct which
278 * encapsulates the depth, stencil and accum buffers and related
279 * parameters.
280 * Input: visual - a GLvisual pointer
281 * softwareDepth - create/use a software depth buffer?
282 * softwareStencil - create/use a software stencil buffer?
283 * softwareAccum - create/use a software accum buffer?
284 * softwareAlpha - create/use a software alpha buffer?
285
286 * Return: pointer to new GLframebuffer struct or NULL if error.
287 */
Brian Paul178a1c52000-04-22 01:05:00 +0000288GLframebuffer *
289gl_create_framebuffer( GLvisual *visual,
290 GLboolean softwareDepth,
291 GLboolean softwareStencil,
292 GLboolean softwareAccum,
293 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000294{
Brian Paul178a1c52000-04-22 01:05:00 +0000295 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
296 assert(visual);
297 if (buffer) {
298 _mesa_initialize_framebuffer(buffer, visual,
299 softwareDepth, softwareStencil,
300 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000301 }
Brian Paul178a1c52000-04-22 01:05:00 +0000302 return buffer;
303}
304
305
306/*
307 * Initialize a GLframebuffer object.
308 * Input: See gl_create_framebuffer() above.
309 */
310void
311_mesa_initialize_framebuffer( GLframebuffer *buffer,
312 GLvisual *visual,
313 GLboolean softwareDepth,
314 GLboolean softwareStencil,
315 GLboolean softwareAccum,
316 GLboolean softwareAlpha )
317{
318 assert(buffer);
319 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000320
321 /* sanity checks */
322 if (softwareDepth ) {
323 assert(visual->DepthBits > 0);
324 }
325 if (softwareStencil) {
326 assert(visual->StencilBits > 0);
327 }
328 if (softwareAccum) {
329 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000330 assert(visual->AccumRedBits > 0);
331 assert(visual->AccumGreenBits > 0);
332 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000333 }
334 if (softwareAlpha) {
335 assert(visual->RGBAflag);
336 assert(visual->AlphaBits > 0);
337 }
338
339 buffer->Visual = visual;
340 buffer->UseSoftwareDepthBuffer = softwareDepth;
341 buffer->UseSoftwareStencilBuffer = softwareStencil;
342 buffer->UseSoftwareAccumBuffer = softwareAccum;
343 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000344}
345
346
Brian Paul4d053dd2000-01-14 04:45:47 +0000347/*
348 * Free a framebuffer struct and its buffers.
349 */
Brian Paul178a1c52000-04-22 01:05:00 +0000350void
351gl_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000352{
353 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000354 if (buffer->DepthBuffer) {
355 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000356 }
357 if (buffer->Accum) {
358 FREE( buffer->Accum );
359 }
360 if (buffer->Stencil) {
361 FREE( buffer->Stencil );
362 }
363 if (buffer->FrontLeftAlpha) {
364 FREE( buffer->FrontLeftAlpha );
365 }
366 if (buffer->BackLeftAlpha) {
367 FREE( buffer->BackLeftAlpha );
368 }
369 if (buffer->FrontRightAlpha) {
370 FREE( buffer->FrontRightAlpha );
371 }
372 if (buffer->BackRightAlpha) {
373 FREE( buffer->BackRightAlpha );
374 }
375 FREE(buffer);
376 }
377}
378
379
380
381/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000382/***** Context allocation, initialization, destroying *****/
383/**********************************************************************/
384
385
Brian Paul9560f052000-01-31 23:11:39 +0000386_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
387
388
jtgafb833d1999-08-19 00:55:39 +0000389/*
390 * This function just calls all the various one-time-init functions in Mesa.
391 */
Brian Paul178a1c52000-04-22 01:05:00 +0000392static void
393one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000394{
395 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000396 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000397 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000398 /* do some implementation tests */
399 assert( sizeof(GLbyte) == 1 );
400 assert( sizeof(GLshort) >= 2 );
401 assert( sizeof(GLint) >= 4 );
402 assert( sizeof(GLubyte) == 1 );
403 assert( sizeof(GLushort) >= 2 );
404 assert( sizeof(GLuint) >= 4 );
405
jtgafb833d1999-08-19 00:55:39 +0000406 gl_init_clip();
407 gl_init_eval();
Brian Paul5829f0c2000-02-02 22:21:39 +0000408 _mesa_init_fog();
Brian Paul780c4e02000-03-22 23:20:12 +0000409 _mesa_init_math();
jtgafb833d1999-08-19 00:55:39 +0000410 gl_init_lists();
411 gl_init_shade();
412 gl_init_texture();
413 gl_init_transformation();
414 gl_init_translate();
415 gl_init_vbrender();
416 gl_init_vbxform();
Keith Whitwell38756791999-08-29 10:26:31 +0000417 gl_init_vertices();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000418
419 if (getenv("MESA_DEBUG")) {
420 _glapi_noop_enable_warnings(GL_TRUE);
421 }
422 else {
423 _glapi_noop_enable_warnings(GL_FALSE);
424 }
425
jtgafb833d1999-08-19 00:55:39 +0000426#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
427 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
428#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000429
430 alreadyCalled = GL_TRUE;
431 }
Brian Paul9560f052000-01-31 23:11:39 +0000432 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000433}
434
435
Brian Paul4d053dd2000-01-14 04:45:47 +0000436
jtgafb833d1999-08-19 00:55:39 +0000437/*
438 * Allocate and initialize a shared context state structure.
439 */
Brian Paul178a1c52000-04-22 01:05:00 +0000440static struct gl_shared_state *
441alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000442{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000443 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000444 struct gl_shared_state *ss;
445 GLboolean outOfMemory;
446
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000447 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000448 if (!ss)
449 return NULL;
450
Brian Paulbb797902000-01-24 16:19:54 +0000451 ss->DisplayList = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000452
Brian Paulbb797902000-01-24 16:19:54 +0000453 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000454
455 /* Default Texture objects */
456 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000457 for (d = 1 ; d <= 3 ; d++) {
458 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
459 if (!ss->DefaultD[d]) {
460 outOfMemory = GL_TRUE;
461 break;
jtgafb833d1999-08-19 00:55:39 +0000462 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000463 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000464 }
465
466 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
467 /* Ran out of memory at some point. Free everything and return NULL */
468 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000469 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000470 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000471 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000472 if (ss->DefaultD[1])
473 gl_free_texture_object(ss, ss->DefaultD[1]);
474 if (ss->DefaultD[2])
475 gl_free_texture_object(ss, ss->DefaultD[2]);
476 if (ss->DefaultD[3])
477 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000478 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000479 return NULL;
480 }
481 else {
482 return ss;
483 }
484}
485
486
487/*
488 * Deallocate a shared state context and all children structures.
489 */
Brian Paul178a1c52000-04-22 01:05:00 +0000490static void
491free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000492{
493 /* Free display lists */
494 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000495 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000496 if (list) {
497 gl_destroy_list(ctx, list);
498 }
499 else {
500 break;
501 }
502 }
Brian Paulbb797902000-01-24 16:19:54 +0000503 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000504
505 /* Free texture objects */
506 while (ss->TexObjectList)
507 {
508 if (ctx->Driver.DeleteTexture)
509 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
510 /* this function removes from linked list too! */
511 gl_free_texture_object(ss, ss->TexObjectList);
512 }
Brian Paulbb797902000-01-24 16:19:54 +0000513 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000514
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000515 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000516}
517
518
519
jtgafb833d1999-08-19 00:55:39 +0000520/*
521 * Initialize the nth light. Note that the defaults for light 0 are
522 * different than the other lights.
523 */
Brian Paul178a1c52000-04-22 01:05:00 +0000524static void
525init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000526{
527 make_empty_list( l );
528
529 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
530 if (n==0) {
531 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
532 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
533 }
534 else {
535 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
536 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
537 }
538 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
539 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
540 l->SpotExponent = 0.0;
541 gl_compute_spot_exp_table( l );
542 l->SpotCutoff = 180.0;
543 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
544 l->ConstantAttenuation = 1.0;
545 l->LinearAttenuation = 0.0;
546 l->QuadraticAttenuation = 0.0;
547 l->Enabled = GL_FALSE;
548}
549
550
551
Brian Paul178a1c52000-04-22 01:05:00 +0000552static void
553init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000554{
555 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
556 lm->LocalViewer = GL_FALSE;
557 lm->TwoSide = GL_FALSE;
558 lm->ColorControl = GL_SINGLE_COLOR;
559}
560
561
Brian Paul178a1c52000-04-22 01:05:00 +0000562static void
563init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000564{
565 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
566 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
567 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
568 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
569 m->Shininess = 0.0;
570 m->AmbientIndex = 0;
571 m->DiffuseIndex = 1;
572 m->SpecularIndex = 1;
573}
574
575
576
Brian Paul178a1c52000-04-22 01:05:00 +0000577static void
578init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000579{
580 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
581
582 texUnit->EnvMode = GL_MODULATE;
583 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
584 texUnit->TexGenEnabled = 0;
585 texUnit->GenModeS = GL_EYE_LINEAR;
586 texUnit->GenModeT = GL_EYE_LINEAR;
587 texUnit->GenModeR = GL_EYE_LINEAR;
588 texUnit->GenModeQ = GL_EYE_LINEAR;
589 /* Yes, these plane coefficients are correct! */
590 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
591 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
592 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
593 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
594 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
595 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
596 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
597 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
598
Brian Paul6e6d4c61999-10-09 20:17:07 +0000599 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
600 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
601 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
jtgafb833d1999-08-19 00:55:39 +0000602}
603
604
Brian Paul178a1c52000-04-22 01:05:00 +0000605static void
606init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000607{
608 struct gl_client_array *cl;
609 GLuint i;
610
611 cl = &ctx->Fallback.Normal;
612 cl->Size = 3;
613 cl->Type = GL_FLOAT;
614 cl->Stride = 0;
615 cl->StrideB = 0;
616 cl->Ptr = (void *) ctx->Current.Normal;
617 cl->Enabled = 1;
618
619 cl = &ctx->Fallback.Color;
620 cl->Size = 4;
621 cl->Type = GL_UNSIGNED_BYTE;
622 cl->Stride = 0;
623 cl->StrideB = 0;
624 cl->Ptr = (void *) ctx->Current.ByteColor;
625 cl->Enabled = 1;
626
627 cl = &ctx->Fallback.Index;
628 cl->Size = 1;
629 cl->Type = GL_UNSIGNED_INT;
630 cl->Stride = 0;
631 cl->StrideB = 0;
632 cl->Ptr = (void *) &ctx->Current.Index;
633 cl->Enabled = 1;
634
635 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
636 cl = &ctx->Fallback.TexCoord[i];
637 cl->Size = 4;
638 cl->Type = GL_FLOAT;
639 cl->Stride = 0;
640 cl->StrideB = 0;
641 cl->Ptr = (void *) ctx->Current.Texcoord[i];
642 cl->Enabled = 1;
643 }
644
645 cl = &ctx->Fallback.EdgeFlag;
646 cl->Size = 1;
647 cl->Type = GL_UNSIGNED_BYTE;
648 cl->Stride = 0;
649 cl->StrideB = 0;
650 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
651 cl->Enabled = 1;
652}
653
Brian Paul4d053dd2000-01-14 04:45:47 +0000654
jtgafb833d1999-08-19 00:55:39 +0000655/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000656static void
657init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000658{
659 map->Order = 1;
660 map->u1 = 0.0;
661 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000662 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000663 if (map->Points) {
664 GLint i;
665 for (i=0;i<n;i++)
666 map->Points[i] = initial[i];
667 }
jtgafb833d1999-08-19 00:55:39 +0000668}
669
670
671/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000672static void
673init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000674{
675 map->Uorder = 1;
676 map->Vorder = 1;
677 map->u1 = 0.0;
678 map->u2 = 1.0;
679 map->v1 = 0.0;
680 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000681 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000682 if (map->Points) {
683 GLint i;
684 for (i=0;i<n;i++)
685 map->Points[i] = initial[i];
686 }
jtgafb833d1999-08-19 00:55:39 +0000687}
688
689
jtgafb833d1999-08-19 00:55:39 +0000690/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000691 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000692 */
Brian Paul178a1c52000-04-22 01:05:00 +0000693static void
694init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000695{
696 GLuint i, j;
697
Brian Paul4d053dd2000-01-14 04:45:47 +0000698 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000699
Brian Paul539cce52000-02-03 19:40:07 +0000700 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000701 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
702 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
703 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
704 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000705 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
706 ctx->Const.MinPointSize = MIN_POINT_SIZE;
707 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
708 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
709 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
710 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
711 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
712 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
713 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
714 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
715 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
716 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000717 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
jtgafb833d1999-08-19 00:55:39 +0000718
Brian Paul4d053dd2000-01-14 04:45:47 +0000719 /* Modelview matrix */
720 gl_matrix_ctr( &ctx->ModelView );
721 gl_matrix_alloc_inv( &ctx->ModelView );
722
723 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000724 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000725 gl_matrix_ctr( &ctx->ModelViewStack[i] );
726 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
727 }
728
729 /* Projection matrix - need inv for user clipping in clip space*/
730 gl_matrix_ctr( &ctx->ProjectionMatrix );
731 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
732
733 gl_matrix_ctr( &ctx->ModelProjectMatrix );
734 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
735 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
736
737 ctx->ProjectionStackDepth = 0;
738 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
739 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
740
Brian Paul7fc29c52000-03-06 17:03:03 +0000741 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000742 gl_matrix_ctr( &ctx->ProjectionStack[i] );
743 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
744 }
745
746 /* Texture matrix */
747 for (i=0; i<MAX_TEXTURE_UNITS; i++) {
748 gl_matrix_ctr( &ctx->TextureMatrix[i] );
749 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000750 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000751 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000752 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000753 }
jtgafb833d1999-08-19 00:55:39 +0000754
Brian Paul250069d2000-04-08 18:57:45 +0000755 /* Color matrix */
756 gl_matrix_ctr(&ctx->ColorMatrix);
757 ctx->ColorStackDepth = 0;
758 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
759 gl_matrix_ctr(&ctx->ColorStack[j]);
760 }
761
Brian Paul4d053dd2000-01-14 04:45:47 +0000762 /* Accumulate buffer group */
763 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000764
Brian Paul4d053dd2000-01-14 04:45:47 +0000765 /* Color buffer group */
766 ctx->Color.IndexMask = 0xffffffff;
767 ctx->Color.ColorMask[0] = 0xff;
768 ctx->Color.ColorMask[1] = 0xff;
769 ctx->Color.ColorMask[2] = 0xff;
770 ctx->Color.ColorMask[3] = 0xff;
771 ctx->Color.SWmasking = GL_FALSE;
772 ctx->Color.ClearIndex = 0;
773 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
774 ctx->Color.DrawBuffer = GL_FRONT;
775 ctx->Color.AlphaEnabled = GL_FALSE;
776 ctx->Color.AlphaFunc = GL_ALWAYS;
777 ctx->Color.AlphaRef = 0;
778 ctx->Color.BlendEnabled = GL_FALSE;
779 ctx->Color.BlendSrcRGB = GL_ONE;
780 ctx->Color.BlendDstRGB = GL_ZERO;
781 ctx->Color.BlendSrcA = GL_ONE;
782 ctx->Color.BlendDstA = GL_ZERO;
783 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
784 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
785 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
786 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
787 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
788 ctx->Color.SWLogicOpEnabled = GL_FALSE;
789 ctx->Color.LogicOp = GL_COPY;
790 ctx->Color.DitherFlag = GL_TRUE;
791 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000792
Brian Paul4d053dd2000-01-14 04:45:47 +0000793 /* Current group */
794 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
795 ctx->Current.Index = 1;
796 for (i=0; i<MAX_TEXTURE_UNITS; i++)
797 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
798 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
799 ctx->Current.RasterDistance = 0.0;
800 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
801 ctx->Current.RasterIndex = 1;
802 for (i=0; i<MAX_TEXTURE_UNITS; i++)
803 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
804 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
805 ctx->Current.RasterPosValid = GL_TRUE;
806 ctx->Current.EdgeFlag = GL_TRUE;
807 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
808 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
jtgafb833d1999-08-19 00:55:39 +0000809
Brian Paul4d053dd2000-01-14 04:45:47 +0000810 ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
811 VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
jtgafb833d1999-08-19 00:55:39 +0000812
Brian Paul4d053dd2000-01-14 04:45:47 +0000813 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000814
Brian Paul4d053dd2000-01-14 04:45:47 +0000815 /* Depth buffer group */
816 ctx->Depth.Test = GL_FALSE;
817 ctx->Depth.Clear = 1.0;
818 ctx->Depth.Func = GL_LESS;
819 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000820 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000821
Brian Paul4d053dd2000-01-14 04:45:47 +0000822 /* Evaluators group */
823 ctx->Eval.Map1Color4 = GL_FALSE;
824 ctx->Eval.Map1Index = GL_FALSE;
825 ctx->Eval.Map1Normal = GL_FALSE;
826 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
827 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
828 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
829 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
830 ctx->Eval.Map1Vertex3 = GL_FALSE;
831 ctx->Eval.Map1Vertex4 = GL_FALSE;
832 ctx->Eval.Map2Color4 = GL_FALSE;
833 ctx->Eval.Map2Index = GL_FALSE;
834 ctx->Eval.Map2Normal = GL_FALSE;
835 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
836 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
837 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
838 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
839 ctx->Eval.Map2Vertex3 = GL_FALSE;
840 ctx->Eval.Map2Vertex4 = GL_FALSE;
841 ctx->Eval.AutoNormal = GL_FALSE;
842 ctx->Eval.MapGrid1un = 1;
843 ctx->Eval.MapGrid1u1 = 0.0;
844 ctx->Eval.MapGrid1u2 = 1.0;
845 ctx->Eval.MapGrid2un = 1;
846 ctx->Eval.MapGrid2vn = 1;
847 ctx->Eval.MapGrid2u1 = 0.0;
848 ctx->Eval.MapGrid2u2 = 1.0;
849 ctx->Eval.MapGrid2v1 = 0.0;
850 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000851
Brian Paul4d053dd2000-01-14 04:45:47 +0000852 /* Evaluator data */
853 {
854 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
855 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
856 static GLfloat index[1] = { 1.0 };
857 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
858 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000859
Brian Paul4d053dd2000-01-14 04:45:47 +0000860 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
861 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
862 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
863 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
864 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
865 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
866 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
867 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
868 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000869
Brian Paul4d053dd2000-01-14 04:45:47 +0000870 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
871 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
872 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
873 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
874 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
875 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
876 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
877 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
878 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
879 }
jtgafb833d1999-08-19 00:55:39 +0000880
Brian Paul4d053dd2000-01-14 04:45:47 +0000881 /* Fog group */
882 ctx->Fog.Enabled = GL_FALSE;
883 ctx->Fog.Mode = GL_EXP;
884 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
885 ctx->Fog.Index = 0.0;
886 ctx->Fog.Density = 1.0;
887 ctx->Fog.Start = 0.0;
888 ctx->Fog.End = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000889
Brian Paul4d053dd2000-01-14 04:45:47 +0000890 /* Hint group */
891 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
892 ctx->Hint.PointSmooth = GL_DONT_CARE;
893 ctx->Hint.LineSmooth = GL_DONT_CARE;
894 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
895 ctx->Hint.Fog = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000896
Brian Paul4d053dd2000-01-14 04:45:47 +0000897 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000898 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000899 ctx->Hint.AllowDrawMem = GL_TRUE;
900 ctx->Hint.StrictLighting = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000901
Brian Paul0771d152000-04-07 00:19:41 +0000902 /* Histogram group */
903 ctx->Histogram.Width = 0;
904 ctx->Histogram.Format = GL_RGBA;
905 ctx->Histogram.Sink = GL_FALSE;
906 ctx->Histogram.RedSize = 0xffffffff;
907 ctx->Histogram.GreenSize = 0xffffffff;
908 ctx->Histogram.BlueSize = 0xffffffff;
909 ctx->Histogram.AlphaSize = 0xffffffff;
910 ctx->Histogram.LuminanceSize = 0xffffffff;
911 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
912 ctx->Histogram.Count[i][0] = 0;
913 ctx->Histogram.Count[i][1] = 0;
914 ctx->Histogram.Count[i][2] = 0;
915 ctx->Histogram.Count[i][3] = 0;
916 }
917
918 /* Min/Max group */
919 ctx->MinMax.Format = GL_RGBA;
920 ctx->MinMax.Sink = GL_FALSE;
921 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
922 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
923 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
924 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
925
926
927
Brian Paul4d053dd2000-01-14 04:45:47 +0000928 /* Pipeline */
929 gl_pipeline_init( ctx );
930 gl_cva_init( ctx );
jtgafb833d1999-08-19 00:55:39 +0000931
Brian Paul4d053dd2000-01-14 04:45:47 +0000932 /* Extensions */
933 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000934
Brian Paul4d053dd2000-01-14 04:45:47 +0000935 ctx->AllowVertexCull = CLIP_CULLED_BIT;
jtgafb833d1999-08-19 00:55:39 +0000936
Brian Paul4d053dd2000-01-14 04:45:47 +0000937 /* Lighting group */
938 for (i=0;i<MAX_LIGHTS;i++) {
939 init_light( &ctx->Light.Light[i], i );
940 }
941 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000942
Brian Paul4d053dd2000-01-14 04:45:47 +0000943 init_lightmodel( &ctx->Light.Model );
944 init_material( &ctx->Light.Material[0] );
945 init_material( &ctx->Light.Material[1] );
946 ctx->Light.ShadeModel = GL_SMOOTH;
947 ctx->Light.Enabled = GL_FALSE;
948 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
949 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
950 ctx->Light.ColorMaterialBitmask
951 = gl_material_bitmask( ctx,
952 GL_FRONT_AND_BACK,
953 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +0000954
Brian Paul4d053dd2000-01-14 04:45:47 +0000955 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000956
Brian Paul4d053dd2000-01-14 04:45:47 +0000957 /* Lighting miscellaneous */
958 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
959 make_empty_list( ctx->ShineTabList );
960 for (i = 0 ; i < 10 ; i++) {
961 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
962 s->shininess = -1;
963 s->refcount = 0;
964 insert_at_tail( ctx->ShineTabList, s );
965 }
966 for (i = 0 ; i < 4 ; i++) {
967 ctx->ShineTable[i] = ctx->ShineTabList->prev;
968 ctx->ShineTable[i]->refcount++;
969 }
jtgafb833d1999-08-19 00:55:39 +0000970
jtgafb833d1999-08-19 00:55:39 +0000971
Brian Paul4d053dd2000-01-14 04:45:47 +0000972 /* Line group */
973 ctx->Line.SmoothFlag = GL_FALSE;
974 ctx->Line.StippleFlag = GL_FALSE;
975 ctx->Line.Width = 1.0;
976 ctx->Line.StipplePattern = 0xffff;
977 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +0000978
Brian Paul4d053dd2000-01-14 04:45:47 +0000979 /* Display List group */
980 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +0000981
Brian Paul4d053dd2000-01-14 04:45:47 +0000982 /* Pixel group */
983 ctx->Pixel.RedBias = 0.0;
984 ctx->Pixel.RedScale = 1.0;
985 ctx->Pixel.GreenBias = 0.0;
986 ctx->Pixel.GreenScale = 1.0;
987 ctx->Pixel.BlueBias = 0.0;
988 ctx->Pixel.BlueScale = 1.0;
989 ctx->Pixel.AlphaBias = 0.0;
990 ctx->Pixel.AlphaScale = 1.0;
991 ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
992 ctx->Pixel.DepthBias = 0.0;
993 ctx->Pixel.DepthScale = 1.0;
994 ctx->Pixel.IndexOffset = 0;
995 ctx->Pixel.IndexShift = 0;
996 ctx->Pixel.ZoomX = 1.0;
997 ctx->Pixel.ZoomY = 1.0;
998 ctx->Pixel.MapColorFlag = GL_FALSE;
999 ctx->Pixel.MapStencilFlag = GL_FALSE;
1000 ctx->Pixel.MapStoSsize = 1;
1001 ctx->Pixel.MapItoIsize = 1;
1002 ctx->Pixel.MapItoRsize = 1;
1003 ctx->Pixel.MapItoGsize = 1;
1004 ctx->Pixel.MapItoBsize = 1;
1005 ctx->Pixel.MapItoAsize = 1;
1006 ctx->Pixel.MapRtoRsize = 1;
1007 ctx->Pixel.MapGtoGsize = 1;
1008 ctx->Pixel.MapBtoBsize = 1;
1009 ctx->Pixel.MapAtoAsize = 1;
1010 ctx->Pixel.MapStoS[0] = 0;
1011 ctx->Pixel.MapItoI[0] = 0;
1012 ctx->Pixel.MapItoR[0] = 0.0;
1013 ctx->Pixel.MapItoG[0] = 0.0;
1014 ctx->Pixel.MapItoB[0] = 0.0;
1015 ctx->Pixel.MapItoA[0] = 0.0;
1016 ctx->Pixel.MapItoR8[0] = 0;
1017 ctx->Pixel.MapItoG8[0] = 0;
1018 ctx->Pixel.MapItoB8[0] = 0;
1019 ctx->Pixel.MapItoA8[0] = 0;
1020 ctx->Pixel.MapRtoR[0] = 0.0;
1021 ctx->Pixel.MapGtoG[0] = 0.0;
1022 ctx->Pixel.MapBtoB[0] = 0.0;
1023 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001024 ctx->Pixel.HistogramEnabled = GL_FALSE;
1025 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1026 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1027 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1028 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul250069d2000-04-08 18:57:45 +00001029 ctx->Pixel.PostColorMatrixRedBias = 0.0;
1030 ctx->Pixel.PostColorMatrixRedScale = 1.0;
1031 ctx->Pixel.PostColorMatrixGreenBias = 0.0;
1032 ctx->Pixel.PostColorMatrixGreenScale = 1.0;
1033 ctx->Pixel.PostColorMatrixBlueBias = 0.0;
1034 ctx->Pixel.PostColorMatrixBlueScale = 1.0;
1035 ctx->Pixel.PostColorMatrixAlphaBias = 0.0;
1036 ctx->Pixel.PostColorMatrixAlphaScale = 1.0;
Brian Paul4fe34b22000-04-11 15:07:48 +00001037 ctx->Pixel.ColorTableScale[0] = 1.0F;
1038 ctx->Pixel.ColorTableScale[1] = 1.0F;
1039 ctx->Pixel.ColorTableScale[2] = 1.0F;
1040 ctx->Pixel.ColorTableScale[3] = 1.0F;
1041 ctx->Pixel.ColorTableBias[0] = 0.0F;
1042 ctx->Pixel.ColorTableBias[1] = 0.0F;
1043 ctx->Pixel.ColorTableBias[2] = 0.0F;
1044 ctx->Pixel.ColorTableBias[3] = 0.0F;
1045 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1046 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1047 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001048
Brian Paul4d053dd2000-01-14 04:45:47 +00001049 /* Point group */
1050 ctx->Point.SmoothFlag = GL_FALSE;
1051 ctx->Point.Size = 1.0;
1052 ctx->Point.Params[0] = 1.0;
1053 ctx->Point.Params[1] = 0.0;
1054 ctx->Point.Params[2] = 0.0;
1055 ctx->Point.Attenuated = GL_FALSE;
1056 ctx->Point.MinSize = 0.0;
1057 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1058 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001059
Brian Paul4d053dd2000-01-14 04:45:47 +00001060 /* Polygon group */
1061 ctx->Polygon.CullFlag = GL_FALSE;
1062 ctx->Polygon.CullFaceMode = GL_BACK;
1063 ctx->Polygon.FrontFace = GL_CCW;
1064 ctx->Polygon.FrontBit = 0;
1065 ctx->Polygon.FrontMode = GL_FILL;
1066 ctx->Polygon.BackMode = GL_FILL;
1067 ctx->Polygon.Unfilled = GL_FALSE;
1068 ctx->Polygon.SmoothFlag = GL_FALSE;
1069 ctx->Polygon.StippleFlag = GL_FALSE;
1070 ctx->Polygon.OffsetFactor = 0.0F;
1071 ctx->Polygon.OffsetUnits = 0.0F;
1072 ctx->Polygon.OffsetPoint = GL_FALSE;
1073 ctx->Polygon.OffsetLine = GL_FALSE;
1074 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001075
Brian Paul4d053dd2000-01-14 04:45:47 +00001076 /* Polygon Stipple group */
1077 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001078
Brian Paul4d053dd2000-01-14 04:45:47 +00001079 /* Scissor group */
1080 ctx->Scissor.Enabled = GL_FALSE;
1081 ctx->Scissor.X = 0;
1082 ctx->Scissor.Y = 0;
1083 ctx->Scissor.Width = 0;
1084 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001085
Brian Paul4d053dd2000-01-14 04:45:47 +00001086 /* Stencil group */
1087 ctx->Stencil.Enabled = GL_FALSE;
1088 ctx->Stencil.Function = GL_ALWAYS;
1089 ctx->Stencil.FailFunc = GL_KEEP;
1090 ctx->Stencil.ZPassFunc = GL_KEEP;
1091 ctx->Stencil.ZFailFunc = GL_KEEP;
1092 ctx->Stencil.Ref = 0;
1093 ctx->Stencil.ValueMask = STENCIL_MAX;
1094 ctx->Stencil.Clear = 0;
1095 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001096
Brian Paul4d053dd2000-01-14 04:45:47 +00001097 /* Texture group */
1098 ctx->Texture.CurrentUnit = 0; /* multitexture */
1099 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
1100 ctx->Texture.Enabled = 0;
1101 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1102 init_texture_unit( ctx, i );
Brian Paul4bdcfe52000-04-17 17:57:04 +00001103 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001104
Brian Paul4d053dd2000-01-14 04:45:47 +00001105 /* Transformation group */
1106 ctx->Transform.MatrixMode = GL_MODELVIEW;
1107 ctx->Transform.Normalize = GL_FALSE;
1108 ctx->Transform.RescaleNormals = GL_FALSE;
1109 for (i=0;i<MAX_CLIP_PLANES;i++) {
1110 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1111 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1112 }
1113 ctx->Transform.AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001114
Brian Paul4d053dd2000-01-14 04:45:47 +00001115 /* Viewport group */
1116 ctx->Viewport.X = 0;
1117 ctx->Viewport.Y = 0;
1118 ctx->Viewport.Width = 0;
1119 ctx->Viewport.Height = 0;
1120 ctx->Viewport.Near = 0.0;
1121 ctx->Viewport.Far = 1.0;
1122 gl_matrix_ctr(&ctx->Viewport.WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001123
1124#define Sz 10
1125#define Tz 14
Brian Pauled30dfa2000-03-03 17:47:39 +00001126 ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual->DepthMaxF;
1127 ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001128#undef Sz
1129#undef Tz
1130
Brian Paul4d053dd2000-01-14 04:45:47 +00001131 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1132 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001133
Brian Paul4d053dd2000-01-14 04:45:47 +00001134 /* Vertex arrays */
1135 ctx->Array.Vertex.Size = 4;
1136 ctx->Array.Vertex.Type = GL_FLOAT;
1137 ctx->Array.Vertex.Stride = 0;
1138 ctx->Array.Vertex.StrideB = 0;
1139 ctx->Array.Vertex.Ptr = NULL;
1140 ctx->Array.Vertex.Enabled = GL_FALSE;
1141 ctx->Array.Normal.Type = GL_FLOAT;
1142 ctx->Array.Normal.Stride = 0;
1143 ctx->Array.Normal.StrideB = 0;
1144 ctx->Array.Normal.Ptr = NULL;
1145 ctx->Array.Normal.Enabled = GL_FALSE;
1146 ctx->Array.Color.Size = 4;
1147 ctx->Array.Color.Type = GL_FLOAT;
1148 ctx->Array.Color.Stride = 0;
1149 ctx->Array.Color.StrideB = 0;
1150 ctx->Array.Color.Ptr = NULL;
1151 ctx->Array.Color.Enabled = GL_FALSE;
1152 ctx->Array.Index.Type = GL_FLOAT;
1153 ctx->Array.Index.Stride = 0;
1154 ctx->Array.Index.StrideB = 0;
1155 ctx->Array.Index.Ptr = NULL;
1156 ctx->Array.Index.Enabled = GL_FALSE;
1157 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1158 ctx->Array.TexCoord[i].Size = 4;
1159 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1160 ctx->Array.TexCoord[i].Stride = 0;
1161 ctx->Array.TexCoord[i].StrideB = 0;
1162 ctx->Array.TexCoord[i].Ptr = NULL;
1163 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1164 }
1165 ctx->Array.TexCoordInterleaveFactor = 1;
1166 ctx->Array.EdgeFlag.Stride = 0;
1167 ctx->Array.EdgeFlag.StrideB = 0;
1168 ctx->Array.EdgeFlag.Ptr = NULL;
1169 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1170 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1171
1172 /* Pixel transfer */
1173 ctx->Pack.Alignment = 4;
1174 ctx->Pack.RowLength = 0;
1175 ctx->Pack.ImageHeight = 0;
1176 ctx->Pack.SkipPixels = 0;
1177 ctx->Pack.SkipRows = 0;
1178 ctx->Pack.SkipImages = 0;
1179 ctx->Pack.SwapBytes = GL_FALSE;
1180 ctx->Pack.LsbFirst = GL_FALSE;
1181 ctx->Unpack.Alignment = 4;
1182 ctx->Unpack.RowLength = 0;
1183 ctx->Unpack.ImageHeight = 0;
1184 ctx->Unpack.SkipPixels = 0;
1185 ctx->Unpack.SkipRows = 0;
1186 ctx->Unpack.SkipImages = 0;
1187 ctx->Unpack.SwapBytes = GL_FALSE;
1188 ctx->Unpack.LsbFirst = GL_FALSE;
1189
1190 /* Feedback */
1191 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1192 ctx->Feedback.Buffer = NULL;
1193 ctx->Feedback.BufferSize = 0;
1194 ctx->Feedback.Count = 0;
1195
1196 /* Selection/picking */
1197 ctx->Select.Buffer = NULL;
1198 ctx->Select.BufferSize = 0;
1199 ctx->Select.BufferCount = 0;
1200 ctx->Select.Hits = 0;
1201 ctx->Select.NameStackDepth = 0;
1202
1203 /* Optimized Accum buffer */
1204 ctx->IntegerAccumMode = GL_TRUE;
1205 ctx->IntegerAccumScaler = 0.0;
1206
1207 /* Renderer and client attribute stacks */
1208 ctx->AttribStackDepth = 0;
1209 ctx->ClientAttribStackDepth = 0;
1210
Brian Paul13811372000-04-12 00:27:37 +00001211 /* Display list */
1212 ctx->CallDepth = 0;
1213 ctx->ExecuteFlag = GL_TRUE;
1214 ctx->CompileFlag = GL_FALSE;
1215 ctx->CurrentListPtr = NULL;
1216 ctx->CurrentBlock = NULL;
1217 ctx->CurrentListNum = 0;
1218 ctx->CurrentPos = 0;
1219
1220 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001221 _mesa_init_colortable(&ctx->ColorTable);
1222 _mesa_init_colortable(&ctx->ProxyColorTable);
1223 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1224 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1225 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1226 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001227
Brian Paul4d053dd2000-01-14 04:45:47 +00001228 /* Miscellaneous */
1229 ctx->NewState = NEW_ALL;
1230 ctx->RenderMode = GL_RENDER;
1231 ctx->StippleCounter = 0;
1232 ctx->NeedNormals = GL_FALSE;
1233 ctx->DoViewportMapping = GL_TRUE;
1234
1235 ctx->NeedEyeCoords = GL_FALSE;
1236 ctx->NeedEyeNormals = GL_FALSE;
1237 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1238
Brian Paul4d053dd2000-01-14 04:45:47 +00001239 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1240
1241 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001242 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001243 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001244
1245 /* For debug/development only */
1246 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1247 ctx->FirstTimeCurrent = GL_TRUE;
1248
1249 /* Dither disable */
1250 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1251 if (ctx->NoDither) {
1252 if (getenv("MESA_DEBUG")) {
1253 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001254 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001255 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001256 }
1257}
1258
1259
1260
1261
jtgafb833d1999-08-19 00:55:39 +00001262/*
1263 * Allocate the proxy textures. If we run out of memory part way through
1264 * the allocations clean up and return GL_FALSE.
1265 * Return: GL_TRUE=success, GL_FALSE=failure
1266 */
Brian Paul178a1c52000-04-22 01:05:00 +00001267static GLboolean
1268alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001269{
1270 GLboolean out_of_memory;
1271 GLint i;
1272
1273 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1274 if (!ctx->Texture.Proxy1D) {
1275 return GL_FALSE;
1276 }
1277
1278 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1279 if (!ctx->Texture.Proxy2D) {
1280 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1281 return GL_FALSE;
1282 }
1283
1284 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1285 if (!ctx->Texture.Proxy3D) {
1286 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1287 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1288 return GL_FALSE;
1289 }
1290
1291 out_of_memory = GL_FALSE;
1292 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001293 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1294 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1295 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001296 if (!ctx->Texture.Proxy1D->Image[i]
1297 || !ctx->Texture.Proxy2D->Image[i]
1298 || !ctx->Texture.Proxy3D->Image[i]) {
1299 out_of_memory = GL_TRUE;
1300 }
1301 }
1302 if (out_of_memory) {
1303 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1304 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001305 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001306 }
1307 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001308 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001309 }
1310 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001311 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001312 }
1313 }
1314 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1315 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1316 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1317 return GL_FALSE;
1318 }
1319 else {
1320 return GL_TRUE;
1321 }
1322}
1323
1324
1325
jtgafb833d1999-08-19 00:55:39 +00001326/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001327 * Initialize a GLcontext struct.
jtgafb833d1999-08-19 00:55:39 +00001328 */
Brian Paul178a1c52000-04-22 01:05:00 +00001329GLboolean
1330_mesa_initialize_context( GLcontext *ctx,
1331 GLvisual *visual,
1332 GLcontext *share_list,
1333 void *driver_ctx,
1334 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001335{
jtgafb833d1999-08-19 00:55:39 +00001336 (void) direct; /* not used */
1337
jtgafb833d1999-08-19 00:55:39 +00001338 /* misc one-time initializations */
1339 one_time_init();
1340
jtgafb833d1999-08-19 00:55:39 +00001341 ctx->DriverCtx = driver_ctx;
1342 ctx->Visual = visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001343 ctx->DrawBuffer = NULL;
1344 ctx->ReadBuffer = NULL;
jtgafb833d1999-08-19 00:55:39 +00001345
1346 ctx->VB = gl_vb_create_for_immediate( ctx );
1347 if (!ctx->VB) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001348 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001349 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001350 }
1351 ctx->input = ctx->VB->IM;
1352
1353 ctx->PB = gl_alloc_pb();
1354 if (!ctx->PB) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001355 FREE( ctx->VB );
1356 FREE( ctx );
Brian Paul4d053dd2000-01-14 04:45:47 +00001357 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001358 }
1359
1360 if (share_list) {
1361 /* share the group of display lists of another context */
1362 ctx->Shared = share_list->Shared;
1363 }
1364 else {
1365 /* allocate new group of display lists */
1366 ctx->Shared = alloc_shared_state();
1367 if (!ctx->Shared) {
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001368 FREE(ctx->VB);
1369 FREE(ctx->PB);
1370 FREE(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001371 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001372 }
1373 }
Brian Paul9560f052000-01-31 23:11:39 +00001374 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001375 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001376 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001377
Brian Paul4d053dd2000-01-14 04:45:47 +00001378 init_attrib_groups( ctx );
1379
jtgafb833d1999-08-19 00:55:39 +00001380 gl_reset_vb( ctx->VB );
1381 gl_reset_input( ctx );
1382
jtgafb833d1999-08-19 00:55:39 +00001383 if (visual->DBflag) {
1384 ctx->Color.DrawBuffer = GL_BACK;
1385 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1386 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1387 ctx->Pixel.ReadBuffer = GL_BACK;
1388 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1389 }
1390 else {
1391 ctx->Color.DrawBuffer = GL_FRONT;
1392 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1393 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1394 ctx->Pixel.ReadBuffer = GL_FRONT;
1395 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1396 }
1397
jtgafb833d1999-08-19 00:55:39 +00001398 if (!alloc_proxy_textures(ctx)) {
1399 free_shared_state(ctx, ctx->Shared);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001400 FREE(ctx->VB);
1401 FREE(ctx->PB);
1402 FREE(ctx);
Brian Paul4d053dd2000-01-14 04:45:47 +00001403 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001404 }
jtgafb833d1999-08-19 00:55:39 +00001405
Brian Paulfbd8f211999-11-11 01:22:25 +00001406 /* setup API dispatch tables */
Brian Paul959f8022000-03-19 01:10:11 +00001407 ctx->Exec = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
1408 ctx->Save = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001409 if (!ctx->Exec || !ctx->Save) {
1410 free_shared_state(ctx, ctx->Shared);
1411 FREE(ctx->VB);
1412 FREE(ctx->PB);
1413 if (ctx->Exec)
1414 FREE(ctx->Exec);
1415 FREE(ctx);
1416 }
1417 _mesa_init_exec_table( ctx->Exec );
1418 _mesa_init_dlist_table( ctx->Save );
1419 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001420
Brian Paul4d053dd2000-01-14 04:45:47 +00001421 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001422}
1423
jtgafb833d1999-08-19 00:55:39 +00001424
1425
1426/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001427 * Allocate and initialize a GLcontext structure.
1428 * Input: visual - a GLvisual pointer
1429 * sharelist - another context to share display lists with or NULL
1430 * driver_ctx - pointer to device driver's context state struct
1431 * Return: pointer to a new gl_context struct or NULL if error.
1432 */
Brian Paul178a1c52000-04-22 01:05:00 +00001433GLcontext *
1434gl_create_context( GLvisual *visual,
1435 GLcontext *share_list,
1436 void *driver_ctx,
1437 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001438{
1439 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1440 if (!ctx) {
1441 return NULL;
1442 }
1443
Brian Paul178a1c52000-04-22 01:05:00 +00001444 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001445 return ctx;
1446 }
1447 else {
1448 FREE(ctx);
1449 return NULL;
1450 }
1451}
1452
1453
1454
1455/*
1456 * Free the data associated with the given context.
1457 * But don't free() the GLcontext struct itself!
1458 */
Brian Paul178a1c52000-04-22 01:05:00 +00001459void
1460gl_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001461{
Brian Paul4d053dd2000-01-14 04:45:47 +00001462 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001463 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001464
1465 /* if we're destroying the current context, unbind it first */
1466 if (ctx == gl_get_current_context()) {
1467 gl_make_current(NULL, NULL);
1468 }
1469
Brian Paul4d053dd2000-01-14 04:45:47 +00001470 gl_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001471 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001472 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1473 }
1474 gl_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001475 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001476 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1477 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001478 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1479 gl_matrix_dtr( &ctx->TextureMatrix[i] );
1480 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1481 gl_matrix_dtr( &ctx->TextureStack[i][j] );
1482 }
1483 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001484
1485 FREE( ctx->PB );
1486
Brian Paul4bdcfe52000-04-17 17:57:04 +00001487 if (ctx->input != ctx->VB->IM)
Brian Paul4d053dd2000-01-14 04:45:47 +00001488 gl_immediate_free( ctx->input );
1489
1490 gl_vb_free( ctx->VB );
1491
Brian Paul9560f052000-01-31 23:11:39 +00001492 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001493 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001494 assert(ctx->Shared->RefCount >= 0);
1495 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1496 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001497 /* free shared state */
1498 free_shared_state( ctx, ctx->Shared );
1499 }
1500
1501 foreach_s( s, tmps, ctx->ShineTabList ) {
1502 FREE( s );
1503 }
1504 FREE( ctx->ShineTabList );
1505
1506 /* Free proxy texture objects */
1507 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1508 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1509 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1510
1511 /* Free evaluator data */
1512 if (ctx->EvalMap.Map1Vertex3.Points)
1513 FREE( ctx->EvalMap.Map1Vertex3.Points );
1514 if (ctx->EvalMap.Map1Vertex4.Points)
1515 FREE( ctx->EvalMap.Map1Vertex4.Points );
1516 if (ctx->EvalMap.Map1Index.Points)
1517 FREE( ctx->EvalMap.Map1Index.Points );
1518 if (ctx->EvalMap.Map1Color4.Points)
1519 FREE( ctx->EvalMap.Map1Color4.Points );
1520 if (ctx->EvalMap.Map1Normal.Points)
1521 FREE( ctx->EvalMap.Map1Normal.Points );
1522 if (ctx->EvalMap.Map1Texture1.Points)
1523 FREE( ctx->EvalMap.Map1Texture1.Points );
1524 if (ctx->EvalMap.Map1Texture2.Points)
1525 FREE( ctx->EvalMap.Map1Texture2.Points );
1526 if (ctx->EvalMap.Map1Texture3.Points)
1527 FREE( ctx->EvalMap.Map1Texture3.Points );
1528 if (ctx->EvalMap.Map1Texture4.Points)
1529 FREE( ctx->EvalMap.Map1Texture4.Points );
1530
1531 if (ctx->EvalMap.Map2Vertex3.Points)
1532 FREE( ctx->EvalMap.Map2Vertex3.Points );
1533 if (ctx->EvalMap.Map2Vertex4.Points)
1534 FREE( ctx->EvalMap.Map2Vertex4.Points );
1535 if (ctx->EvalMap.Map2Index.Points)
1536 FREE( ctx->EvalMap.Map2Index.Points );
1537 if (ctx->EvalMap.Map2Color4.Points)
1538 FREE( ctx->EvalMap.Map2Color4.Points );
1539 if (ctx->EvalMap.Map2Normal.Points)
1540 FREE( ctx->EvalMap.Map2Normal.Points );
1541 if (ctx->EvalMap.Map2Texture1.Points)
1542 FREE( ctx->EvalMap.Map2Texture1.Points );
1543 if (ctx->EvalMap.Map2Texture2.Points)
1544 FREE( ctx->EvalMap.Map2Texture2.Points );
1545 if (ctx->EvalMap.Map2Texture3.Points)
1546 FREE( ctx->EvalMap.Map2Texture3.Points );
1547 if (ctx->EvalMap.Map2Texture4.Points)
1548 FREE( ctx->EvalMap.Map2Texture4.Points );
1549
Brian Paul4bdcfe52000-04-17 17:57:04 +00001550 _mesa_free_colortable_data( &ctx->ColorTable );
1551 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1552 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1553 _mesa_free_colortable_data( &ctx->Texture.Palette );
1554
Brian Paul4d053dd2000-01-14 04:45:47 +00001555 /* Free cache of immediate buffers. */
1556 while (ctx->nr_im_queued-- > 0) {
1557 struct immediate * next = ctx->freed_im_queue->next;
1558 FREE( ctx->freed_im_queue );
1559 ctx->freed_im_queue = next;
1560 }
1561 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001562
1563 FREE(ctx->Exec);
1564 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001565}
1566
1567
1568
1569/*
1570 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001571 */
Brian Paul178a1c52000-04-22 01:05:00 +00001572void
1573gl_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001574{
1575 if (ctx) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001576 gl_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001577 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001578 }
1579}
1580
1581
1582
1583/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001584 * Called by the driver after both the context and driver are fully
1585 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001586 */
Brian Paul178a1c52000-04-22 01:05:00 +00001587void
1588gl_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001589{
Brian Paul00037781999-12-17 14:52:35 +00001590 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001591}
1592
1593
1594
1595/*
1596 * Copy attribute groups from one context to another.
1597 * Input: src - source context
1598 * dst - destination context
1599 * mask - bitwise OR of GL_*_BIT flags
1600 */
Brian Paul178a1c52000-04-22 01:05:00 +00001601void
1602gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001603{
1604 if (mask & GL_ACCUM_BUFFER_BIT) {
1605 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1606 }
1607 if (mask & GL_COLOR_BUFFER_BIT) {
1608 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1609 }
1610 if (mask & GL_CURRENT_BIT) {
1611 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1612 }
1613 if (mask & GL_DEPTH_BUFFER_BIT) {
1614 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1615 }
1616 if (mask & GL_ENABLE_BIT) {
1617 /* no op */
1618 }
1619 if (mask & GL_EVAL_BIT) {
1620 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1621 }
1622 if (mask & GL_FOG_BIT) {
1623 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1624 }
1625 if (mask & GL_HINT_BIT) {
1626 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1627 }
1628 if (mask & GL_LIGHTING_BIT) {
1629 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001630 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001631 }
1632 if (mask & GL_LINE_BIT) {
1633 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1634 }
1635 if (mask & GL_LIST_BIT) {
1636 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1637 }
1638 if (mask & GL_PIXEL_MODE_BIT) {
1639 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1640 }
1641 if (mask & GL_POINT_BIT) {
1642 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1643 }
1644 if (mask & GL_POLYGON_BIT) {
1645 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1646 }
1647 if (mask & GL_POLYGON_STIPPLE_BIT) {
1648 /* Use loop instead of MEMCPY due to problem with Portland Group's
1649 * C compiler. Reported by John Stone.
1650 */
1651 int i;
1652 for (i=0;i<32;i++) {
1653 dst->PolygonStipple[i] = src->PolygonStipple[i];
1654 }
1655 }
1656 if (mask & GL_SCISSOR_BIT) {
1657 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1658 }
1659 if (mask & GL_STENCIL_BUFFER_BIT) {
1660 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1661 }
1662 if (mask & GL_TEXTURE_BIT) {
1663 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1664 }
1665 if (mask & GL_TRANSFORM_BIT) {
1666 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1667 }
1668 if (mask & GL_VIEWPORT_BIT) {
1669 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1670 }
1671}
1672
1673
jtgafb833d1999-08-19 00:55:39 +00001674/*
Brian Paul00037781999-12-17 14:52:35 +00001675 * Set the current context, binding the given frame buffer to the context.
1676 */
1677void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
1678{
1679 gl_make_current2( newCtx, buffer, buffer );
1680}
1681
1682
1683/*
1684 * Bind the given context to the given draw-buffer and read-buffer
1685 * and make it the current context for this thread.
1686 */
1687void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1688 GLframebuffer *readBuffer )
1689{
1690#if 0
Brian Paulf9b97d92000-01-28 20:17:42 +00001691 GLcontext *oldCtx = gl_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001692
1693 /* Flush the old context
1694 */
1695 if (oldCtx) {
1696 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
1697
1698 /* unbind frame buffers from context */
1699 if (oldCtx->DrawBuffer) {
1700 oldCtx->DrawBuffer = NULL;
1701 }
1702 if (oldCtx->ReadBuffer) {
1703 oldCtx->ReadBuffer = NULL;
1704 }
1705 }
1706#endif
1707
1708 /* We call this function periodically (just here for now) in
1709 * order to detect when multithreading has begun.
1710 */
1711 _glapi_check_multithread();
1712
Brian Paulf9b97d92000-01-28 20:17:42 +00001713 _glapi_set_context((void *) newCtx);
Brian Paul00037781999-12-17 14:52:35 +00001714 ASSERT(gl_get_current_context() == newCtx);
1715 if (newCtx) {
1716 SET_IMMEDIATE(newCtx, newCtx->input);
1717 _glapi_set_dispatch(newCtx->CurrentDispatch);
1718 }
1719 else {
1720 _glapi_set_dispatch(NULL); /* none current */
1721 }
1722
1723 if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
1724
1725 if (newCtx && drawBuffer && readBuffer) {
1726 /* TODO: check if newCtx and buffer's visual match??? */
1727 newCtx->DrawBuffer = drawBuffer;
1728 newCtx->ReadBuffer = readBuffer;
1729 newCtx->NewState = NEW_ALL; /* just to be safe */
1730 gl_update_state( newCtx );
1731 }
1732
1733 /* We can use this to help debug user's problems. Tell the to set
1734 * the MESA_INFO env variable before running their app. Then the
1735 * first time each context is made current we'll print some useful
1736 * information.
1737 */
1738 if (newCtx && newCtx->FirstTimeCurrent) {
1739 if (getenv("MESA_INFO")) {
1740 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1741 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1742 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1743 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
Brian Paul09cb1481999-12-17 17:00:32 +00001744#if defined(THREADS)
1745 fprintf(stderr, "Mesa thread-safe: YES\n");
1746#else
1747 fprintf(stderr, "Mesa thread-safe: NO\n");
1748#endif
Brian Paul54287052000-01-17 20:00:15 +00001749#if defined(USE_X86_ASM)
1750 fprintf(stderr, "Mesa x86-optimized: YES\n");
1751#else
1752 fprintf(stderr, "Mesa x86-optimized: NO\n");
1753#endif
Brian Paul00037781999-12-17 14:52:35 +00001754 }
1755 newCtx->FirstTimeCurrent = GL_FALSE;
1756 }
1757}
1758
1759
1760
1761/*
1762 * Return current context handle for the calling thread.
1763 * This isn't the fastest way to get the current context.
1764 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1765 */
1766GLcontext *gl_get_current_context( void )
1767{
Brian Paulf9b97d92000-01-28 20:17:42 +00001768 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001769}
1770
1771
1772
1773/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001774 * This should be called by device drivers just before they do a
1775 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001776 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001777void
1778_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001779{
Brian Paulfbd8f211999-11-11 01:22:25 +00001780 FLUSH_VB( ctx, "swap buffers" );
jtgafb833d1999-08-19 00:55:39 +00001781}
1782
1783
Brian Paul00037781999-12-17 14:52:35 +00001784
Brian Paulfbd8f211999-11-11 01:22:25 +00001785/*
1786 * Return pointer to this context's current API dispatch table.
1787 * It'll either be the immediate-mode execute dispatcher or the
1788 * display list compile dispatcher.
1789 */
1790struct _glapi_table *
1791_mesa_get_dispatch(GLcontext *ctx)
1792{
1793 return ctx->CurrentDispatch;
1794}
1795
1796
1797
jtgafb833d1999-08-19 00:55:39 +00001798/**********************************************************************/
1799/***** Miscellaneous functions *****/
1800/**********************************************************************/
1801
1802
1803/*
1804 * This function is called when the Mesa user has stumbled into a code
1805 * path which may not be implemented fully or correctly.
1806 */
1807void gl_problem( const GLcontext *ctx, const char *s )
1808{
1809 fprintf( stderr, "Mesa implementation error: %s\n", s );
1810 fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" );
1811 (void) ctx;
1812}
1813
1814
1815
1816/*
1817 * This is called to inform the user that he or she has tried to do
1818 * something illogical or if there's likely a bug in their program
1819 * (like enabled depth testing without a depth buffer).
1820 */
1821void gl_warning( const GLcontext *ctx, const char *s )
1822{
1823 GLboolean debug;
1824#ifdef DEBUG
1825 debug = GL_TRUE;
1826#else
1827 if (getenv("MESA_DEBUG")) {
1828 debug = GL_TRUE;
1829 }
1830 else {
1831 debug = GL_FALSE;
1832 }
1833#endif
1834 if (debug) {
1835 fprintf( stderr, "Mesa warning: %s\n", s );
1836 }
1837 (void) ctx;
1838}
1839
1840
1841
Brian Paulfa9df402000-02-02 19:16:46 +00001842/*
1843 * Compile an error into current display list.
1844 */
jtgafb833d1999-08-19 00:55:39 +00001845void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
1846{
1847 if (ctx->CompileFlag)
1848 gl_save_error( ctx, error, s );
1849
1850 if (ctx->ExecuteFlag)
1851 gl_error( ctx, error, s );
1852}
1853
1854
Brian Paulfa9df402000-02-02 19:16:46 +00001855
jtgafb833d1999-08-19 00:55:39 +00001856/*
1857 * This is Mesa's error handler. Normally, all that's done is the updating
1858 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1859 * environment variable "MESA_DEBUG" is defined then a real error message
1860 * is printed to stderr.
1861 * Input: error - the error value
1862 * s - a diagnostic string
1863 */
1864void gl_error( GLcontext *ctx, GLenum error, const char *s )
1865{
1866 GLboolean debug;
1867
1868#ifdef DEBUG
1869 debug = GL_TRUE;
1870#else
1871 if (getenv("MESA_DEBUG")) {
1872 debug = GL_TRUE;
1873 }
1874 else {
1875 debug = GL_FALSE;
1876 }
1877#endif
1878
1879 if (debug) {
1880 char errstr[1000];
1881
1882 switch (error) {
1883 case GL_NO_ERROR:
1884 strcpy( errstr, "GL_NO_ERROR" );
1885 break;
1886 case GL_INVALID_VALUE:
1887 strcpy( errstr, "GL_INVALID_VALUE" );
1888 break;
1889 case GL_INVALID_ENUM:
1890 strcpy( errstr, "GL_INVALID_ENUM" );
1891 break;
1892 case GL_INVALID_OPERATION:
1893 strcpy( errstr, "GL_INVALID_OPERATION" );
1894 break;
1895 case GL_STACK_OVERFLOW:
1896 strcpy( errstr, "GL_STACK_OVERFLOW" );
1897 break;
1898 case GL_STACK_UNDERFLOW:
1899 strcpy( errstr, "GL_STACK_UNDERFLOW" );
1900 break;
1901 case GL_OUT_OF_MEMORY:
1902 strcpy( errstr, "GL_OUT_OF_MEMORY" );
1903 break;
1904 default:
1905 strcpy( errstr, "unknown" );
1906 break;
1907 }
1908 fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
1909 }
1910
1911 if (ctx->ErrorValue==GL_NO_ERROR) {
1912 ctx->ErrorValue = error;
1913 }
1914
1915 /* Call device driver's error handler, if any. This is used on the Mac. */
1916 if (ctx->Driver.Error) {
1917 (*ctx->Driver.Error)( ctx );
1918 }
1919}
1920
1921
1922
Brian Paulfa9df402000-02-02 19:16:46 +00001923void
1924_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00001925{
Brian Paulfa9df402000-02-02 19:16:46 +00001926 GET_CURRENT_CONTEXT(ctx);
1927 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
1928 if (ctx->Driver.Finish) {
1929 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001930 }
1931}
1932
1933
1934
Brian Paulfa9df402000-02-02 19:16:46 +00001935void
1936_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00001937{
Brian Paulfa9df402000-02-02 19:16:46 +00001938 GET_CURRENT_CONTEXT(ctx);
1939 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
1940 if (ctx->Driver.Flush) {
1941 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00001942 }
jtgafb833d1999-08-19 00:55:39 +00001943}