blob: c57f37c5791864675ba6ac63d58ce775248129f1 [file] [log] [blame]
Brian Pauld0d7d622000-10-21 00:02:47 +00001/* $Id: context.c,v 1.94 2000/10/21 00:02:47 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paule4b684c2000-09-12 21:07:40 +00005 * Version: 3.5
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paul54287052000-01-17 20:00:15 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000032#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000034#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000035#include "context.h"
36#include "cva.h"
jtgafb833d1999-08-19 00:55:39 +000037#include "dlist.h"
38#include "eval.h"
39#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000040#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000041#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000042#include "get.h"
Brian Paulf9b97d92000-01-28 20:17:42 +000043#include "glapinoop.h"
Brian Paul9560f052000-01-31 23:11:39 +000044#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000045#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000046#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000047#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "macros.h"
49#include "matrix.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000050#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000051#include "mmath.h"
52#include "pb.h"
53#include "pipeline.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "shade.h"
55#include "simple_list.h"
jtgafb833d1999-08-19 00:55:39 +000056#include "stages.h"
Brian Paulfa9df402000-02-02 19:16:46 +000057#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000058#include "translate.h"
59#include "teximage.h"
60#include "texobj.h"
jtgafb833d1999-08-19 00:55:39 +000061#include "texture.h"
62#include "types.h"
63#include "varray.h"
64#include "vb.h"
jtgafb833d1999-08-19 00:55:39 +000065#include "vbrender.h"
66#include "vbxform.h"
Keith Whitwell38756791999-08-29 10:26:31 +000067#include "vertices.h"
jtgafb833d1999-08-19 00:55:39 +000068#include "xform.h"
jtgafb833d1999-08-19 00:55:39 +000069#endif
70
Brian Paul3b18a362000-09-26 15:27:20 +000071#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000072#include "Trace/tr_context.h"
73#include "Trace/tr_wrapper.h"
74#endif
75
jtgafb833d1999-08-19 00:55:39 +000076
Brian Paulb1394fa2000-09-26 20:53:53 +000077
78/**********************************************************************/
79/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
80/**********************************************************************/
81
82static GLboolean
83_mesa_DestroyContext(__GLcontext *gc)
84{
85 if (gc) {
86 _mesa_free_context_data(gc);
87 (*gc->imports.free)(gc, gc);
88 }
89 return GL_TRUE;
90}
91
92
93/* exported OpenGL SI interface */
94__GLcontext *
95__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
96{
97 GLcontext *ctx;
98
99 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
100 if (ctx == NULL) {
101 return NULL;
102 }
103 ctx->imports = *imports;
104
105 _mesa_initialize_visual(&ctx->Visual,
106 modes->rgbMode,
107 modes->doubleBufferMode,
108 modes->stereoMode,
109 modes->redBits,
110 modes->greenBits,
111 modes->blueBits,
112 modes->alphaBits,
113 modes->indexBits,
114 modes->depthBits,
115 modes->stencilBits,
116 modes->accumRedBits,
117 modes->accumGreenBits,
118 modes->accumBlueBits,
119 modes->accumAlphaBits,
120 0);
121
122 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->wscx, GL_FALSE);
123
124 ctx->exports.destroyContext = _mesa_DestroyContext;
125
126 return ctx;
127}
128
129
130/* exported OpenGL SI interface */
131void
132__glCoreNopDispatch(void)
133{
134#if 0
135 /* SI */
136 __gl_dispatch = __glNopDispatchState;
137#else
138 /* Mesa */
139 _glapi_set_dispatch(NULL);
140#endif
141}
142
143
jtgafb833d1999-08-19 00:55:39 +0000144/**********************************************************************/
145/***** Context and Thread management *****/
146/**********************************************************************/
147
148
Brian Paul00037781999-12-17 14:52:35 +0000149#if !defined(THREADS)
jtgafb833d1999-08-19 00:55:39 +0000150
Brian Paul5666c632000-01-18 17:36:16 +0000151struct immediate *_mesa_CurrentInput = NULL;
jtgafb833d1999-08-19 00:55:39 +0000152
Brian Paul00037781999-12-17 14:52:35 +0000153#endif
jtgafb833d1999-08-19 00:55:39 +0000154
155
jtgafb833d1999-08-19 00:55:39 +0000156/**********************************************************************/
Brian Paul4d053dd2000-01-14 04:45:47 +0000157/***** GL Visual allocation/destruction *****/
158/**********************************************************************/
159
160
161/*
162 * Allocate a new GLvisual object.
163 * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
Brian Paul4d053dd2000-01-14 04:45:47 +0000164 * dbFlag - double buffering?
165 * stereoFlag - stereo buffer?
Brian Pauled30dfa2000-03-03 17:47:39 +0000166 * depthBits - requested bits per depth buffer value
167 * Any value in [0, 32] is acceptable but the actual
168 * depth type will be GLushort or GLuint as needed.
169 * stencilBits - requested minimum bits per stencil buffer value
170 * accumBits - requested minimum bits per accum buffer component
171 * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
172 * red/green/blue/alphaBits - number of bits per color component
173 * in frame buffer for RGB(A) mode.
174 * We always use 8 in core Mesa though.
Brian Paul4d053dd2000-01-14 04:45:47 +0000175 * Return: pointer to new GLvisual or NULL if requested parameters can't
176 * be met.
177 */
Brian Paulb371e0d2000-03-31 01:05:51 +0000178GLvisual *
179_mesa_create_visual( GLboolean rgbFlag,
Brian Paulb371e0d2000-03-31 01:05:51 +0000180 GLboolean dbFlag,
181 GLboolean stereoFlag,
182 GLint redBits,
183 GLint greenBits,
184 GLint blueBits,
185 GLint alphaBits,
186 GLint indexBits,
187 GLint depthBits,
188 GLint stencilBits,
189 GLint accumRedBits,
190 GLint accumGreenBits,
191 GLint accumBlueBits,
192 GLint accumAlphaBits,
193 GLint numSamples )
Brian Paul4d053dd2000-01-14 04:45:47 +0000194{
Brian Paul178a1c52000-04-22 01:05:00 +0000195 GLvisual *vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
196 if (vis) {
Brian Paule70c6232000-05-04 13:53:55 +0000197 if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000198 redBits, greenBits, blueBits, alphaBits,
199 indexBits, depthBits, stencilBits,
200 accumRedBits, accumGreenBits,
201 accumBlueBits, accumAlphaBits,
Brian Paulb1394fa2000-09-26 20:53:53 +0000202 numSamples)) {
Brian Paul178a1c52000-04-22 01:05:00 +0000203 FREE(vis);
204 return NULL;
205 }
206 }
207 return vis;
208}
209
210
211/*
212 * Initialize the fields of the given GLvisual.
213 * Input: see _mesa_create_visual() above.
214 * Return: GL_TRUE = success
215 * GL_FALSE = failure.
216 */
217GLboolean
218_mesa_initialize_visual( GLvisual *vis,
219 GLboolean rgbFlag,
Brian Paul178a1c52000-04-22 01:05:00 +0000220 GLboolean dbFlag,
221 GLboolean stereoFlag,
222 GLint redBits,
223 GLint greenBits,
224 GLint blueBits,
225 GLint alphaBits,
226 GLint indexBits,
227 GLint depthBits,
228 GLint stencilBits,
229 GLint accumRedBits,
230 GLint accumGreenBits,
231 GLint accumBlueBits,
232 GLint accumAlphaBits,
233 GLint numSamples )
234{
235 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000236
Brian Pauled30dfa2000-03-03 17:47:39 +0000237 /* This is to catch bad values from device drivers not updated for
238 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
239 * bad value now (a 1-bit depth buffer!?!).
240 */
241 assert(depthBits == 0 || depthBits > 1);
242
243 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000244 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000245 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000246 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000247 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000248 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000249 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000250 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000251 }
252 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000253 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000254 }
255 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000256 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000257 }
258 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000259 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000260 }
261
262 vis->RGBAflag = rgbFlag;
263 vis->DBflag = dbFlag;
264 vis->StereoFlag = stereoFlag;
265 vis->RedBits = redBits;
266 vis->GreenBits = greenBits;
267 vis->BlueBits = blueBits;
Brian Paule70c6232000-05-04 13:53:55 +0000268 vis->AlphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000269
Brian Paulb371e0d2000-03-31 01:05:51 +0000270 vis->IndexBits = indexBits;
271 vis->DepthBits = depthBits;
272 vis->AccumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
273 vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
274 vis->AccumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
275 vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
276 vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Paul4d053dd2000-01-14 04:45:47 +0000277
Brian Pauled30dfa2000-03-03 17:47:39 +0000278 if (depthBits == 0) {
279 /* Special case. Even if we don't have a depth buffer we need
Brian Paul35324a62000-10-09 22:42:40 +0000280 * good values for DepthMax for Z vertex transformation purposes
281 * and for per-fragment fog computation.
Brian Pauled30dfa2000-03-03 17:47:39 +0000282 */
Brian Paul35324a62000-10-09 22:42:40 +0000283 vis->DepthMax = 1 << 16;
284 vis->DepthMaxF = (GLfloat) vis->DepthMax;
Brian Pauled30dfa2000-03-03 17:47:39 +0000285 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000286 else if (depthBits < 32) {
Brian Pauled30dfa2000-03-03 17:47:39 +0000287 vis->DepthMax = (1 << depthBits) - 1;
288 vis->DepthMaxF = (GLfloat) vis->DepthMax;
289 }
Brian Paul3a94f5c2000-05-18 18:12:36 +0000290 else {
291 /* Special case since shift values greater than or equal to the
292 * number of bits in the left hand expression's type are
293 * undefined.
294 */
295 vis->DepthMax = 0xffffffff;
296 vis->DepthMaxF = (GLfloat) vis->DepthMax;
297 }
Brian Pauld0d7d622000-10-21 00:02:47 +0000298 vis->MRD = 1; /* XXX temporary value */
Brian Pauled30dfa2000-03-03 17:47:39 +0000299
Brian Paul178a1c52000-04-22 01:05:00 +0000300 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000301}
302
303
Brian Paulb371e0d2000-03-31 01:05:51 +0000304void
305_mesa_destroy_visual( GLvisual *vis )
306{
307 FREE(vis);
308}
309
310
Brian Paul4d053dd2000-01-14 04:45:47 +0000311/**********************************************************************/
312/***** GL Framebuffer allocation/destruction *****/
313/**********************************************************************/
314
315
316/*
317 * Create a new framebuffer. A GLframebuffer is a struct which
318 * encapsulates the depth, stencil and accum buffers and related
319 * parameters.
320 * Input: visual - a GLvisual pointer
321 * softwareDepth - create/use a software depth buffer?
322 * softwareStencil - create/use a software stencil buffer?
323 * softwareAccum - create/use a software accum buffer?
324 * softwareAlpha - create/use a software alpha buffer?
325
326 * Return: pointer to new GLframebuffer struct or NULL if error.
327 */
Brian Paul178a1c52000-04-22 01:05:00 +0000328GLframebuffer *
Brian Paulb1394fa2000-09-26 20:53:53 +0000329_mesa_create_framebuffer( GLvisual *visual,
330 GLboolean softwareDepth,
331 GLboolean softwareStencil,
332 GLboolean softwareAccum,
333 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000334{
Brian Paul178a1c52000-04-22 01:05:00 +0000335 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
336 assert(visual);
337 if (buffer) {
338 _mesa_initialize_framebuffer(buffer, visual,
339 softwareDepth, softwareStencil,
340 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000341 }
Brian Paul178a1c52000-04-22 01:05:00 +0000342 return buffer;
343}
344
345
346/*
347 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000348 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000349 */
350void
351_mesa_initialize_framebuffer( GLframebuffer *buffer,
352 GLvisual *visual,
353 GLboolean softwareDepth,
354 GLboolean softwareStencil,
355 GLboolean softwareAccum,
356 GLboolean softwareAlpha )
357{
358 assert(buffer);
359 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000360
361 /* sanity checks */
362 if (softwareDepth ) {
363 assert(visual->DepthBits > 0);
364 }
365 if (softwareStencil) {
366 assert(visual->StencilBits > 0);
367 }
368 if (softwareAccum) {
369 assert(visual->RGBAflag);
Brian Paulb371e0d2000-03-31 01:05:51 +0000370 assert(visual->AccumRedBits > 0);
371 assert(visual->AccumGreenBits > 0);
372 assert(visual->AccumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000373 }
374 if (softwareAlpha) {
375 assert(visual->RGBAflag);
376 assert(visual->AlphaBits > 0);
377 }
378
379 buffer->Visual = visual;
380 buffer->UseSoftwareDepthBuffer = softwareDepth;
381 buffer->UseSoftwareStencilBuffer = softwareStencil;
382 buffer->UseSoftwareAccumBuffer = softwareAccum;
383 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000384}
385
386
Brian Paul4d053dd2000-01-14 04:45:47 +0000387/*
388 * Free a framebuffer struct and its buffers.
389 */
Brian Paul178a1c52000-04-22 01:05:00 +0000390void
Brian Paulb1394fa2000-09-26 20:53:53 +0000391_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000392{
393 if (buffer) {
Brian Paul650cb742000-03-17 15:31:52 +0000394 if (buffer->DepthBuffer) {
395 FREE( buffer->DepthBuffer );
Brian Paul4d053dd2000-01-14 04:45:47 +0000396 }
397 if (buffer->Accum) {
398 FREE( buffer->Accum );
399 }
400 if (buffer->Stencil) {
401 FREE( buffer->Stencil );
402 }
403 if (buffer->FrontLeftAlpha) {
404 FREE( buffer->FrontLeftAlpha );
405 }
406 if (buffer->BackLeftAlpha) {
407 FREE( buffer->BackLeftAlpha );
408 }
409 if (buffer->FrontRightAlpha) {
410 FREE( buffer->FrontRightAlpha );
411 }
412 if (buffer->BackRightAlpha) {
413 FREE( buffer->BackRightAlpha );
414 }
415 FREE(buffer);
416 }
417}
418
419
420
421/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000422/***** Context allocation, initialization, destroying *****/
423/**********************************************************************/
424
425
Brian Paul9560f052000-01-31 23:11:39 +0000426_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
427
428
jtgafb833d1999-08-19 00:55:39 +0000429/*
430 * This function just calls all the various one-time-init functions in Mesa.
431 */
Brian Paul178a1c52000-04-22 01:05:00 +0000432static void
433one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000434{
435 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000436 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000437 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000438 /* do some implementation tests */
439 assert( sizeof(GLbyte) == 1 );
440 assert( sizeof(GLshort) >= 2 );
441 assert( sizeof(GLint) >= 4 );
442 assert( sizeof(GLubyte) == 1 );
443 assert( sizeof(GLushort) >= 2 );
444 assert( sizeof(GLuint) >= 4 );
445
jtgafb833d1999-08-19 00:55:39 +0000446 gl_init_clip();
447 gl_init_eval();
Brian Paul5829f0c2000-02-02 22:21:39 +0000448 _mesa_init_fog();
Brian Paul780c4e02000-03-22 23:20:12 +0000449 _mesa_init_math();
jtgafb833d1999-08-19 00:55:39 +0000450 gl_init_lists();
451 gl_init_shade();
452 gl_init_texture();
453 gl_init_transformation();
454 gl_init_translate();
455 gl_init_vbrender();
456 gl_init_vbxform();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000457
458 if (getenv("MESA_DEBUG")) {
459 _glapi_noop_enable_warnings(GL_TRUE);
460 }
461 else {
462 _glapi_noop_enable_warnings(GL_FALSE);
463 }
464
jtgafb833d1999-08-19 00:55:39 +0000465#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
466 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
467#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000468
469 alreadyCalled = GL_TRUE;
470 }
Brian Paul9560f052000-01-31 23:11:39 +0000471 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000472}
473
474
Brian Paul4d053dd2000-01-14 04:45:47 +0000475
jtgafb833d1999-08-19 00:55:39 +0000476/*
477 * Allocate and initialize a shared context state structure.
478 */
Brian Paul178a1c52000-04-22 01:05:00 +0000479static struct gl_shared_state *
480alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000481{
Brian Paul6e6d4c61999-10-09 20:17:07 +0000482 GLuint d;
jtgafb833d1999-08-19 00:55:39 +0000483 struct gl_shared_state *ss;
484 GLboolean outOfMemory;
485
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000486 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000487 if (!ss)
488 return NULL;
489
Brian Paule4b684c2000-09-12 21:07:40 +0000490 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000491
Brian Paule4b684c2000-09-12 21:07:40 +0000492 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000493 ss->TexObjects = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000494
495 /* Default Texture objects */
496 outOfMemory = GL_FALSE;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000497 for (d = 1 ; d <= 3 ; d++) {
498 ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
499 if (!ss->DefaultD[d]) {
500 outOfMemory = GL_TRUE;
501 break;
jtgafb833d1999-08-19 00:55:39 +0000502 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000503 ss->DefaultD[d]->RefCount++; /* don't free if not in use */
jtgafb833d1999-08-19 00:55:39 +0000504 }
505
Brian Paul413d6a22000-05-26 14:44:59 +0000506 ss->DefaultCubeMap = gl_alloc_texture_object(ss, 0, 6);
507 if (!ss->DefaultCubeMap) {
508 outOfMemory = GL_TRUE;
509 }
510 else {
511 ss->DefaultCubeMap->RefCount++;
512 }
513
jtgafb833d1999-08-19 00:55:39 +0000514 if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
515 /* Ran out of memory at some point. Free everything and return NULL */
516 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000517 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000518 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000519 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul6e6d4c61999-10-09 20:17:07 +0000520 if (ss->DefaultD[1])
521 gl_free_texture_object(ss, ss->DefaultD[1]);
522 if (ss->DefaultD[2])
523 gl_free_texture_object(ss, ss->DefaultD[2]);
524 if (ss->DefaultD[3])
525 gl_free_texture_object(ss, ss->DefaultD[3]);
Brian Paul413d6a22000-05-26 14:44:59 +0000526 if (ss->DefaultCubeMap)
527 gl_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000528 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000529 return NULL;
530 }
531 else {
532 return ss;
533 }
534}
535
536
537/*
538 * Deallocate a shared state context and all children structures.
539 */
Brian Paul178a1c52000-04-22 01:05:00 +0000540static void
541free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000542{
543 /* Free display lists */
544 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000545 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000546 if (list) {
547 gl_destroy_list(ctx, list);
548 }
549 else {
550 break;
551 }
552 }
Brian Paulbb797902000-01-24 16:19:54 +0000553 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000554
555 /* Free texture objects */
556 while (ss->TexObjectList)
557 {
558 if (ctx->Driver.DeleteTexture)
559 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
560 /* this function removes from linked list too! */
561 gl_free_texture_object(ss, ss->TexObjectList);
562 }
Brian Paulbb797902000-01-24 16:19:54 +0000563 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000564
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000565 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000566}
567
568
569
jtgafb833d1999-08-19 00:55:39 +0000570/*
571 * Initialize the nth light. Note that the defaults for light 0 are
572 * different than the other lights.
573 */
Brian Paul178a1c52000-04-22 01:05:00 +0000574static void
575init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000576{
577 make_empty_list( l );
578
579 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
580 if (n==0) {
581 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
582 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
583 }
584 else {
585 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
586 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
587 }
588 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
589 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
590 l->SpotExponent = 0.0;
591 gl_compute_spot_exp_table( l );
592 l->SpotCutoff = 180.0;
593 l->CosCutoff = 0.0; /* KW: -ve values not admitted */
594 l->ConstantAttenuation = 1.0;
595 l->LinearAttenuation = 0.0;
596 l->QuadraticAttenuation = 0.0;
597 l->Enabled = GL_FALSE;
598}
599
600
601
Brian Paul178a1c52000-04-22 01:05:00 +0000602static void
603init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000604{
605 ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
606 lm->LocalViewer = GL_FALSE;
607 lm->TwoSide = GL_FALSE;
608 lm->ColorControl = GL_SINGLE_COLOR;
609}
610
611
Brian Paul178a1c52000-04-22 01:05:00 +0000612static void
613init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000614{
615 ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
616 ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
617 ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
618 ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
619 m->Shininess = 0.0;
620 m->AmbientIndex = 0;
621 m->DiffuseIndex = 1;
622 m->SpecularIndex = 1;
623}
624
625
626
Brian Paul178a1c52000-04-22 01:05:00 +0000627static void
628init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000629{
630 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
631
632 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000633 texUnit->CombineModeRGB = GL_MODULATE;
634 texUnit->CombineModeA = GL_MODULATE;
635 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
636 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
637 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
638 texUnit->CombineSourceA[0] = GL_TEXTURE;
639 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
640 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
641 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
642 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
643 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
644 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
645 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
646 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
647 texUnit->CombineScaleShiftRGB = 0;
648 texUnit->CombineScaleShiftA = 0;
649
jtgafb833d1999-08-19 00:55:39 +0000650 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
651 texUnit->TexGenEnabled = 0;
652 texUnit->GenModeS = GL_EYE_LINEAR;
653 texUnit->GenModeT = GL_EYE_LINEAR;
654 texUnit->GenModeR = GL_EYE_LINEAR;
655 texUnit->GenModeQ = GL_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000656 texUnit->GenBitS = TEXGEN_EYE_LINEAR;
657 texUnit->GenBitT = TEXGEN_EYE_LINEAR;
658 texUnit->GenBitR = TEXGEN_EYE_LINEAR;
659 texUnit->GenBitQ = TEXGEN_EYE_LINEAR;
660
jtgafb833d1999-08-19 00:55:39 +0000661 /* Yes, these plane coefficients are correct! */
662 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
663 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
664 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
665 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
666 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
667 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
668 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
669 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
670
Brian Paul6e6d4c61999-10-09 20:17:07 +0000671 texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
672 texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
673 texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
Brian Paul413d6a22000-05-26 14:44:59 +0000674 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000675}
676
677
Brian Paul178a1c52000-04-22 01:05:00 +0000678static void
679init_fallback_arrays( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000680{
681 struct gl_client_array *cl;
682 GLuint i;
683
684 cl = &ctx->Fallback.Normal;
685 cl->Size = 3;
686 cl->Type = GL_FLOAT;
687 cl->Stride = 0;
688 cl->StrideB = 0;
689 cl->Ptr = (void *) ctx->Current.Normal;
690 cl->Enabled = 1;
691
692 cl = &ctx->Fallback.Color;
693 cl->Size = 4;
694 cl->Type = GL_UNSIGNED_BYTE;
695 cl->Stride = 0;
696 cl->StrideB = 0;
697 cl->Ptr = (void *) ctx->Current.ByteColor;
698 cl->Enabled = 1;
699
700 cl = &ctx->Fallback.Index;
701 cl->Size = 1;
702 cl->Type = GL_UNSIGNED_INT;
703 cl->Stride = 0;
704 cl->StrideB = 0;
705 cl->Ptr = (void *) &ctx->Current.Index;
706 cl->Enabled = 1;
707
708 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
709 cl = &ctx->Fallback.TexCoord[i];
710 cl->Size = 4;
711 cl->Type = GL_FLOAT;
712 cl->Stride = 0;
713 cl->StrideB = 0;
714 cl->Ptr = (void *) ctx->Current.Texcoord[i];
715 cl->Enabled = 1;
716 }
717
718 cl = &ctx->Fallback.EdgeFlag;
719 cl->Size = 1;
720 cl->Type = GL_UNSIGNED_BYTE;
721 cl->Stride = 0;
722 cl->StrideB = 0;
723 cl->Ptr = (void *) &ctx->Current.EdgeFlag;
724 cl->Enabled = 1;
725}
726
Brian Paul4d053dd2000-01-14 04:45:47 +0000727
jtgafb833d1999-08-19 00:55:39 +0000728/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000729static void
730init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000731{
732 map->Order = 1;
733 map->u1 = 0.0;
734 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000735 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000736 if (map->Points) {
737 GLint i;
738 for (i=0;i<n;i++)
739 map->Points[i] = initial[i];
740 }
jtgafb833d1999-08-19 00:55:39 +0000741}
742
743
744/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000745static void
746init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000747{
748 map->Uorder = 1;
749 map->Vorder = 1;
750 map->u1 = 0.0;
751 map->u2 = 1.0;
752 map->v1 = 0.0;
753 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000754 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000755 if (map->Points) {
756 GLint i;
757 for (i=0;i<n;i++)
758 map->Points[i] = initial[i];
759 }
jtgafb833d1999-08-19 00:55:39 +0000760}
761
762
jtgafb833d1999-08-19 00:55:39 +0000763/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000764 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000765 */
Brian Paul178a1c52000-04-22 01:05:00 +0000766static void
767init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000768{
769 GLuint i, j;
770
Brian Paul4d053dd2000-01-14 04:45:47 +0000771 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000772
Brian Paul539cce52000-02-03 19:40:07 +0000773 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000774 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
775 ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
Brian Paul86fc3702000-05-22 16:33:20 +0000776 ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
Brian Paul4d053dd2000-01-14 04:45:47 +0000777 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
778 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
Brian Paul539cce52000-02-03 19:40:07 +0000779 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
780 ctx->Const.MinPointSize = MIN_POINT_SIZE;
781 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
782 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
783 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
784 ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
785 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
786 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
787 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
788 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
789 ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
790 ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
Brian Paul4bdcfe52000-04-17 17:57:04 +0000791 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
Brian Paul82b02f02000-05-07 20:37:40 +0000792 ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
793 ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
Brian Paul1207bf02000-05-23 20:10:49 +0000794 ctx->Const.NumCompressedTextureFormats = 0;
jtgafb833d1999-08-19 00:55:39 +0000795
Brian Paul4d053dd2000-01-14 04:45:47 +0000796 /* Modelview matrix */
797 gl_matrix_ctr( &ctx->ModelView );
798 gl_matrix_alloc_inv( &ctx->ModelView );
799
800 ctx->ModelViewStackDepth = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000801 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000802 gl_matrix_ctr( &ctx->ModelViewStack[i] );
803 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
804 }
805
806 /* Projection matrix - need inv for user clipping in clip space*/
807 gl_matrix_ctr( &ctx->ProjectionMatrix );
808 gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
809
810 gl_matrix_ctr( &ctx->ModelProjectMatrix );
811 gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
812 ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
813
814 ctx->ProjectionStackDepth = 0;
815 ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
816 ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
817
Brian Paul7fc29c52000-03-06 17:03:03 +0000818 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000819 gl_matrix_ctr( &ctx->ProjectionStack[i] );
820 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
821 }
822
823 /* Texture matrix */
Brian Paul904ecb22000-06-27 23:38:45 +0000824 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000825 gl_matrix_ctr( &ctx->TextureMatrix[i] );
826 ctx->TextureStackDepth[i] = 0;
Brian Paul7fc29c52000-03-06 17:03:03 +0000827 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
Brian Paul904ecb22000-06-27 23:38:45 +0000828 gl_matrix_ctr( &ctx->TextureStack[i][j] );
Brian Paul4d053dd2000-01-14 04:45:47 +0000829 ctx->TextureStack[i][j].inv = 0;
jtgafb833d1999-08-19 00:55:39 +0000830 }
Brian Paul4d053dd2000-01-14 04:45:47 +0000831 }
jtgafb833d1999-08-19 00:55:39 +0000832
Brian Paul250069d2000-04-08 18:57:45 +0000833 /* Color matrix */
834 gl_matrix_ctr(&ctx->ColorMatrix);
835 ctx->ColorStackDepth = 0;
836 for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
837 gl_matrix_ctr(&ctx->ColorStack[j]);
838 }
839
Brian Paul4d053dd2000-01-14 04:45:47 +0000840 /* Accumulate buffer group */
841 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000842
Brian Paul4d053dd2000-01-14 04:45:47 +0000843 /* Color buffer group */
844 ctx->Color.IndexMask = 0xffffffff;
845 ctx->Color.ColorMask[0] = 0xff;
846 ctx->Color.ColorMask[1] = 0xff;
847 ctx->Color.ColorMask[2] = 0xff;
848 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000849 ctx->Color.ClearIndex = 0;
850 ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
851 ctx->Color.DrawBuffer = GL_FRONT;
852 ctx->Color.AlphaEnabled = GL_FALSE;
853 ctx->Color.AlphaFunc = GL_ALWAYS;
854 ctx->Color.AlphaRef = 0;
855 ctx->Color.BlendEnabled = GL_FALSE;
856 ctx->Color.BlendSrcRGB = GL_ONE;
857 ctx->Color.BlendDstRGB = GL_ZERO;
858 ctx->Color.BlendSrcA = GL_ONE;
859 ctx->Color.BlendDstA = GL_ZERO;
860 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
861 ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
862 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
863 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
864 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000865 ctx->Color.LogicOp = GL_COPY;
866 ctx->Color.DitherFlag = GL_TRUE;
867 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000868
Brian Paul4d053dd2000-01-14 04:45:47 +0000869 /* Current group */
870 ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
871 ctx->Current.Index = 1;
872 for (i=0; i<MAX_TEXTURE_UNITS; i++)
873 ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
874 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
875 ctx->Current.RasterDistance = 0.0;
876 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
877 ctx->Current.RasterIndex = 1;
878 for (i=0; i<MAX_TEXTURE_UNITS; i++)
879 ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
880 ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
881 ctx->Current.RasterPosValid = GL_TRUE;
882 ctx->Current.EdgeFlag = GL_TRUE;
883 ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
884 ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
jtgafb833d1999-08-19 00:55:39 +0000885
Brian Pauld4757302000-10-20 19:54:49 +0000886 ctx->Current.Flag = (VERT_NORM |
887 VERT_INDEX |
888 VERT_RGBA |
889 VERT_EDGE |
890 VERT_TEX0_1 |
891 VERT_TEX1_1 |
892 VERT_TEX2_1 | /* XXX fix for MAX_TEXTURE_UNITS > 3 */
893 VERT_MATERIAL);
jtgafb833d1999-08-19 00:55:39 +0000894
Brian Paul4d053dd2000-01-14 04:45:47 +0000895 init_fallback_arrays( ctx );
jtgafb833d1999-08-19 00:55:39 +0000896
Brian Paul4d053dd2000-01-14 04:45:47 +0000897 /* Depth buffer group */
898 ctx->Depth.Test = GL_FALSE;
899 ctx->Depth.Clear = 1.0;
900 ctx->Depth.Func = GL_LESS;
901 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000902 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000903
Brian Paul4d053dd2000-01-14 04:45:47 +0000904 /* Evaluators group */
905 ctx->Eval.Map1Color4 = GL_FALSE;
906 ctx->Eval.Map1Index = GL_FALSE;
907 ctx->Eval.Map1Normal = GL_FALSE;
908 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
909 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
910 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
911 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
912 ctx->Eval.Map1Vertex3 = GL_FALSE;
913 ctx->Eval.Map1Vertex4 = GL_FALSE;
914 ctx->Eval.Map2Color4 = GL_FALSE;
915 ctx->Eval.Map2Index = GL_FALSE;
916 ctx->Eval.Map2Normal = GL_FALSE;
917 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
918 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
919 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
920 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
921 ctx->Eval.Map2Vertex3 = GL_FALSE;
922 ctx->Eval.Map2Vertex4 = GL_FALSE;
923 ctx->Eval.AutoNormal = GL_FALSE;
924 ctx->Eval.MapGrid1un = 1;
925 ctx->Eval.MapGrid1u1 = 0.0;
926 ctx->Eval.MapGrid1u2 = 1.0;
927 ctx->Eval.MapGrid2un = 1;
928 ctx->Eval.MapGrid2vn = 1;
929 ctx->Eval.MapGrid2u1 = 0.0;
930 ctx->Eval.MapGrid2u2 = 1.0;
931 ctx->Eval.MapGrid2v1 = 0.0;
932 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000933
Brian Paul4d053dd2000-01-14 04:45:47 +0000934 /* Evaluator data */
935 {
936 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
937 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
938 static GLfloat index[1] = { 1.0 };
939 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
940 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000941
Brian Paul4d053dd2000-01-14 04:45:47 +0000942 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
943 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
944 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
945 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
946 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
947 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
948 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
949 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
950 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
jtgafb833d1999-08-19 00:55:39 +0000951
Brian Paul4d053dd2000-01-14 04:45:47 +0000952 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
953 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
954 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
955 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
956 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
957 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
958 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
959 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
960 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
961 }
jtgafb833d1999-08-19 00:55:39 +0000962
Brian Paul4d053dd2000-01-14 04:45:47 +0000963 /* Fog group */
964 ctx->Fog.Enabled = GL_FALSE;
965 ctx->Fog.Mode = GL_EXP;
966 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
967 ctx->Fog.Index = 0.0;
968 ctx->Fog.Density = 1.0;
969 ctx->Fog.Start = 0.0;
970 ctx->Fog.End = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000971
Brian Paul4d053dd2000-01-14 04:45:47 +0000972 /* Hint group */
973 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
974 ctx->Hint.PointSmooth = GL_DONT_CARE;
975 ctx->Hint.LineSmooth = GL_DONT_CARE;
976 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
977 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000978 ctx->Hint.AllowDrawWin = GL_TRUE;
Brian Paul8cce3142000-04-10 15:52:25 +0000979 ctx->Hint.AllowDrawFrg = GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000980 ctx->Hint.AllowDrawMem = GL_TRUE;
981 ctx->Hint.StrictLighting = GL_TRUE;
Brian Paul1207bf02000-05-23 20:10:49 +0000982 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
983 ctx->Hint.TextureCompression = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000984
Brian Paul0771d152000-04-07 00:19:41 +0000985 /* Histogram group */
986 ctx->Histogram.Width = 0;
987 ctx->Histogram.Format = GL_RGBA;
988 ctx->Histogram.Sink = GL_FALSE;
989 ctx->Histogram.RedSize = 0xffffffff;
990 ctx->Histogram.GreenSize = 0xffffffff;
991 ctx->Histogram.BlueSize = 0xffffffff;
992 ctx->Histogram.AlphaSize = 0xffffffff;
993 ctx->Histogram.LuminanceSize = 0xffffffff;
994 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
995 ctx->Histogram.Count[i][0] = 0;
996 ctx->Histogram.Count[i][1] = 0;
997 ctx->Histogram.Count[i][2] = 0;
998 ctx->Histogram.Count[i][3] = 0;
999 }
1000
1001 /* Min/Max group */
1002 ctx->MinMax.Format = GL_RGBA;
1003 ctx->MinMax.Sink = GL_FALSE;
1004 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
1005 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
1006 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
1007 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
1008
Brian Paul4d053dd2000-01-14 04:45:47 +00001009 /* Pipeline */
1010 gl_pipeline_init( ctx );
1011 gl_cva_init( ctx );
jtgafb833d1999-08-19 00:55:39 +00001012
Brian Paul4d053dd2000-01-14 04:45:47 +00001013 /* Extensions */
1014 gl_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +00001015
Brian Paul4d053dd2000-01-14 04:45:47 +00001016 ctx->AllowVertexCull = CLIP_CULLED_BIT;
jtgafb833d1999-08-19 00:55:39 +00001017
Brian Paul4d053dd2000-01-14 04:45:47 +00001018 /* Lighting group */
1019 for (i=0;i<MAX_LIGHTS;i++) {
1020 init_light( &ctx->Light.Light[i], i );
1021 }
1022 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +00001023
Brian Paul4d053dd2000-01-14 04:45:47 +00001024 init_lightmodel( &ctx->Light.Model );
1025 init_material( &ctx->Light.Material[0] );
1026 init_material( &ctx->Light.Material[1] );
1027 ctx->Light.ShadeModel = GL_SMOOTH;
1028 ctx->Light.Enabled = GL_FALSE;
1029 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
1030 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
1031 ctx->Light.ColorMaterialBitmask
1032 = gl_material_bitmask( ctx,
1033 GL_FRONT_AND_BACK,
1034 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001035
Brian Paul4d053dd2000-01-14 04:45:47 +00001036 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001037
Brian Paul4d053dd2000-01-14 04:45:47 +00001038 /* Lighting miscellaneous */
1039 ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1040 make_empty_list( ctx->ShineTabList );
1041 for (i = 0 ; i < 10 ; i++) {
1042 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1043 s->shininess = -1;
1044 s->refcount = 0;
1045 insert_at_tail( ctx->ShineTabList, s );
1046 }
1047 for (i = 0 ; i < 4 ; i++) {
1048 ctx->ShineTable[i] = ctx->ShineTabList->prev;
1049 ctx->ShineTable[i]->refcount++;
1050 }
jtgafb833d1999-08-19 00:55:39 +00001051
Brian Paul77d61af2000-06-28 04:20:21 +00001052 gl_compute_shine_table( ctx, 0, ctx->Light.Material[0].Shininess );
1053 gl_compute_shine_table( ctx, 2, ctx->Light.Material[0].Shininess * .5 );
1054 gl_compute_shine_table( ctx, 1, ctx->Light.Material[1].Shininess );
1055 gl_compute_shine_table( ctx, 3, ctx->Light.Material[1].Shininess * .5 );
1056
jtgafb833d1999-08-19 00:55:39 +00001057
Brian Paul4d053dd2000-01-14 04:45:47 +00001058 /* Line group */
1059 ctx->Line.SmoothFlag = GL_FALSE;
1060 ctx->Line.StippleFlag = GL_FALSE;
1061 ctx->Line.Width = 1.0;
1062 ctx->Line.StipplePattern = 0xffff;
1063 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001064
Brian Paul4d053dd2000-01-14 04:45:47 +00001065 /* Display List group */
1066 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001067
Brian Paul4d053dd2000-01-14 04:45:47 +00001068 /* Pixel group */
1069 ctx->Pixel.RedBias = 0.0;
1070 ctx->Pixel.RedScale = 1.0;
1071 ctx->Pixel.GreenBias = 0.0;
1072 ctx->Pixel.GreenScale = 1.0;
1073 ctx->Pixel.BlueBias = 0.0;
1074 ctx->Pixel.BlueScale = 1.0;
1075 ctx->Pixel.AlphaBias = 0.0;
1076 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001077 ctx->Pixel.DepthBias = 0.0;
1078 ctx->Pixel.DepthScale = 1.0;
1079 ctx->Pixel.IndexOffset = 0;
1080 ctx->Pixel.IndexShift = 0;
1081 ctx->Pixel.ZoomX = 1.0;
1082 ctx->Pixel.ZoomY = 1.0;
1083 ctx->Pixel.MapColorFlag = GL_FALSE;
1084 ctx->Pixel.MapStencilFlag = GL_FALSE;
1085 ctx->Pixel.MapStoSsize = 1;
1086 ctx->Pixel.MapItoIsize = 1;
1087 ctx->Pixel.MapItoRsize = 1;
1088 ctx->Pixel.MapItoGsize = 1;
1089 ctx->Pixel.MapItoBsize = 1;
1090 ctx->Pixel.MapItoAsize = 1;
1091 ctx->Pixel.MapRtoRsize = 1;
1092 ctx->Pixel.MapGtoGsize = 1;
1093 ctx->Pixel.MapBtoBsize = 1;
1094 ctx->Pixel.MapAtoAsize = 1;
1095 ctx->Pixel.MapStoS[0] = 0;
1096 ctx->Pixel.MapItoI[0] = 0;
1097 ctx->Pixel.MapItoR[0] = 0.0;
1098 ctx->Pixel.MapItoG[0] = 0.0;
1099 ctx->Pixel.MapItoB[0] = 0.0;
1100 ctx->Pixel.MapItoA[0] = 0.0;
1101 ctx->Pixel.MapItoR8[0] = 0;
1102 ctx->Pixel.MapItoG8[0] = 0;
1103 ctx->Pixel.MapItoB8[0] = 0;
1104 ctx->Pixel.MapItoA8[0] = 0;
1105 ctx->Pixel.MapRtoR[0] = 0.0;
1106 ctx->Pixel.MapGtoG[0] = 0.0;
1107 ctx->Pixel.MapBtoB[0] = 0.0;
1108 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001109 ctx->Pixel.HistogramEnabled = GL_FALSE;
1110 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1111 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1112 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1113 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001114 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1115 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1116 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1117 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001118 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1119 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1120 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1121 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001122 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1123 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1124 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001125 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1126 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1127 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1128 for (i = 0; i < 3; i++) {
1129 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1130 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1131 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1132 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1133 }
1134 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1135 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001136
Brian Paul4d053dd2000-01-14 04:45:47 +00001137 /* Point group */
1138 ctx->Point.SmoothFlag = GL_FALSE;
Brian Paula25f7e12000-06-27 04:29:22 +00001139 ctx->Point.UserSize = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001140 ctx->Point.Size = 1.0;
1141 ctx->Point.Params[0] = 1.0;
1142 ctx->Point.Params[1] = 0.0;
1143 ctx->Point.Params[2] = 0.0;
1144 ctx->Point.Attenuated = GL_FALSE;
1145 ctx->Point.MinSize = 0.0;
1146 ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
1147 ctx->Point.Threshold = 1.0;
jtgafb833d1999-08-19 00:55:39 +00001148
Brian Paul4d053dd2000-01-14 04:45:47 +00001149 /* Polygon group */
1150 ctx->Polygon.CullFlag = GL_FALSE;
1151 ctx->Polygon.CullFaceMode = GL_BACK;
1152 ctx->Polygon.FrontFace = GL_CCW;
1153 ctx->Polygon.FrontBit = 0;
1154 ctx->Polygon.FrontMode = GL_FILL;
1155 ctx->Polygon.BackMode = GL_FILL;
1156 ctx->Polygon.Unfilled = GL_FALSE;
1157 ctx->Polygon.SmoothFlag = GL_FALSE;
1158 ctx->Polygon.StippleFlag = GL_FALSE;
1159 ctx->Polygon.OffsetFactor = 0.0F;
1160 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001161 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001162 ctx->Polygon.OffsetPoint = GL_FALSE;
1163 ctx->Polygon.OffsetLine = GL_FALSE;
1164 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001165
Brian Paul4d053dd2000-01-14 04:45:47 +00001166 /* Polygon Stipple group */
1167 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001168
Brian Paul4d053dd2000-01-14 04:45:47 +00001169 /* Scissor group */
1170 ctx->Scissor.Enabled = GL_FALSE;
1171 ctx->Scissor.X = 0;
1172 ctx->Scissor.Y = 0;
1173 ctx->Scissor.Width = 0;
1174 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001175
Brian Paul4d053dd2000-01-14 04:45:47 +00001176 /* Stencil group */
1177 ctx->Stencil.Enabled = GL_FALSE;
1178 ctx->Stencil.Function = GL_ALWAYS;
1179 ctx->Stencil.FailFunc = GL_KEEP;
1180 ctx->Stencil.ZPassFunc = GL_KEEP;
1181 ctx->Stencil.ZFailFunc = GL_KEEP;
1182 ctx->Stencil.Ref = 0;
1183 ctx->Stencil.ValueMask = STENCIL_MAX;
1184 ctx->Stencil.Clear = 0;
1185 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001186
Brian Paul4d053dd2000-01-14 04:45:47 +00001187 /* Texture group */
1188 ctx->Texture.CurrentUnit = 0; /* multitexture */
1189 ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
Brian Paul23316032000-09-14 23:13:23 +00001190 ctx->Texture.ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001191 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1192 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001193 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001194 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001195
Brian Paul4d053dd2000-01-14 04:45:47 +00001196 /* Transformation group */
1197 ctx->Transform.MatrixMode = GL_MODELVIEW;
1198 ctx->Transform.Normalize = GL_FALSE;
1199 ctx->Transform.RescaleNormals = GL_FALSE;
1200 for (i=0;i<MAX_CLIP_PLANES;i++) {
1201 ctx->Transform.ClipEnabled[i] = GL_FALSE;
1202 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1203 }
1204 ctx->Transform.AnyClip = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001205
Brian Paul4d053dd2000-01-14 04:45:47 +00001206 /* Viewport group */
1207 ctx->Viewport.X = 0;
1208 ctx->Viewport.Y = 0;
1209 ctx->Viewport.Width = 0;
1210 ctx->Viewport.Height = 0;
1211 ctx->Viewport.Near = 0.0;
1212 ctx->Viewport.Far = 1.0;
1213 gl_matrix_ctr(&ctx->Viewport.WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001214
1215#define Sz 10
1216#define Tz 14
Brian Paulb1394fa2000-09-26 20:53:53 +00001217 ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual.DepthMaxF;
1218 ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual.DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001219#undef Sz
1220#undef Tz
1221
Brian Paul4d053dd2000-01-14 04:45:47 +00001222 ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1223 ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001224
Brian Paul4d053dd2000-01-14 04:45:47 +00001225 /* Vertex arrays */
1226 ctx->Array.Vertex.Size = 4;
1227 ctx->Array.Vertex.Type = GL_FLOAT;
1228 ctx->Array.Vertex.Stride = 0;
1229 ctx->Array.Vertex.StrideB = 0;
1230 ctx->Array.Vertex.Ptr = NULL;
1231 ctx->Array.Vertex.Enabled = GL_FALSE;
1232 ctx->Array.Normal.Type = GL_FLOAT;
1233 ctx->Array.Normal.Stride = 0;
1234 ctx->Array.Normal.StrideB = 0;
1235 ctx->Array.Normal.Ptr = NULL;
1236 ctx->Array.Normal.Enabled = GL_FALSE;
1237 ctx->Array.Color.Size = 4;
1238 ctx->Array.Color.Type = GL_FLOAT;
1239 ctx->Array.Color.Stride = 0;
1240 ctx->Array.Color.StrideB = 0;
1241 ctx->Array.Color.Ptr = NULL;
1242 ctx->Array.Color.Enabled = GL_FALSE;
1243 ctx->Array.Index.Type = GL_FLOAT;
1244 ctx->Array.Index.Stride = 0;
1245 ctx->Array.Index.StrideB = 0;
1246 ctx->Array.Index.Ptr = NULL;
1247 ctx->Array.Index.Enabled = GL_FALSE;
1248 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1249 ctx->Array.TexCoord[i].Size = 4;
1250 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1251 ctx->Array.TexCoord[i].Stride = 0;
1252 ctx->Array.TexCoord[i].StrideB = 0;
1253 ctx->Array.TexCoord[i].Ptr = NULL;
1254 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
1255 }
1256 ctx->Array.TexCoordInterleaveFactor = 1;
1257 ctx->Array.EdgeFlag.Stride = 0;
1258 ctx->Array.EdgeFlag.StrideB = 0;
1259 ctx->Array.EdgeFlag.Ptr = NULL;
1260 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
1261 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1262
1263 /* Pixel transfer */
1264 ctx->Pack.Alignment = 4;
1265 ctx->Pack.RowLength = 0;
1266 ctx->Pack.ImageHeight = 0;
1267 ctx->Pack.SkipPixels = 0;
1268 ctx->Pack.SkipRows = 0;
1269 ctx->Pack.SkipImages = 0;
1270 ctx->Pack.SwapBytes = GL_FALSE;
1271 ctx->Pack.LsbFirst = GL_FALSE;
1272 ctx->Unpack.Alignment = 4;
1273 ctx->Unpack.RowLength = 0;
1274 ctx->Unpack.ImageHeight = 0;
1275 ctx->Unpack.SkipPixels = 0;
1276 ctx->Unpack.SkipRows = 0;
1277 ctx->Unpack.SkipImages = 0;
1278 ctx->Unpack.SwapBytes = GL_FALSE;
1279 ctx->Unpack.LsbFirst = GL_FALSE;
1280
1281 /* Feedback */
1282 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1283 ctx->Feedback.Buffer = NULL;
1284 ctx->Feedback.BufferSize = 0;
1285 ctx->Feedback.Count = 0;
1286
1287 /* Selection/picking */
1288 ctx->Select.Buffer = NULL;
1289 ctx->Select.BufferSize = 0;
1290 ctx->Select.BufferCount = 0;
1291 ctx->Select.Hits = 0;
1292 ctx->Select.NameStackDepth = 0;
1293
1294 /* Optimized Accum buffer */
1295 ctx->IntegerAccumMode = GL_TRUE;
1296 ctx->IntegerAccumScaler = 0.0;
1297
1298 /* Renderer and client attribute stacks */
1299 ctx->AttribStackDepth = 0;
1300 ctx->ClientAttribStackDepth = 0;
1301
Brian Paul13811372000-04-12 00:27:37 +00001302 /* Display list */
1303 ctx->CallDepth = 0;
1304 ctx->ExecuteFlag = GL_TRUE;
1305 ctx->CompileFlag = GL_FALSE;
1306 ctx->CurrentListPtr = NULL;
1307 ctx->CurrentBlock = NULL;
1308 ctx->CurrentListNum = 0;
1309 ctx->CurrentPos = 0;
1310
1311 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001312 _mesa_init_colortable(&ctx->ColorTable);
1313 _mesa_init_colortable(&ctx->ProxyColorTable);
1314 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1315 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1316 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1317 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001318
Brian Paul4d053dd2000-01-14 04:45:47 +00001319 /* Miscellaneous */
1320 ctx->NewState = NEW_ALL;
1321 ctx->RenderMode = GL_RENDER;
1322 ctx->StippleCounter = 0;
1323 ctx->NeedNormals = GL_FALSE;
1324 ctx->DoViewportMapping = GL_TRUE;
Brian Paulfa4525e2000-08-21 14:22:24 +00001325 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001326
1327 ctx->NeedEyeCoords = GL_FALSE;
1328 ctx->NeedEyeNormals = GL_FALSE;
1329 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1330
Brian Paul4d053dd2000-01-14 04:45:47 +00001331 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1332
1333 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001334 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001335 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001336
1337 /* For debug/development only */
1338 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1339 ctx->FirstTimeCurrent = GL_TRUE;
1340
1341 /* Dither disable */
1342 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1343 if (ctx->NoDither) {
1344 if (getenv("MESA_DEBUG")) {
1345 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001346 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001347 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001348 }
1349}
1350
1351
1352
1353
jtgafb833d1999-08-19 00:55:39 +00001354/*
1355 * Allocate the proxy textures. If we run out of memory part way through
1356 * the allocations clean up and return GL_FALSE.
1357 * Return: GL_TRUE=success, GL_FALSE=failure
1358 */
Brian Paul178a1c52000-04-22 01:05:00 +00001359static GLboolean
1360alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001361{
1362 GLboolean out_of_memory;
1363 GLint i;
1364
1365 ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
1366 if (!ctx->Texture.Proxy1D) {
1367 return GL_FALSE;
1368 }
1369
1370 ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
1371 if (!ctx->Texture.Proxy2D) {
1372 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1373 return GL_FALSE;
1374 }
1375
1376 ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
1377 if (!ctx->Texture.Proxy3D) {
1378 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1379 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1380 return GL_FALSE;
1381 }
1382
1383 out_of_memory = GL_FALSE;
1384 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001385 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1386 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1387 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001388 if (!ctx->Texture.Proxy1D->Image[i]
1389 || !ctx->Texture.Proxy2D->Image[i]
1390 || !ctx->Texture.Proxy3D->Image[i]) {
1391 out_of_memory = GL_TRUE;
1392 }
1393 }
1394 if (out_of_memory) {
1395 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1396 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001397 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001398 }
1399 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001400 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001401 }
1402 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001403 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001404 }
1405 }
1406 gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
1407 gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
1408 gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
1409 return GL_FALSE;
1410 }
1411 else {
1412 return GL_TRUE;
1413 }
1414}
1415
1416
jtgafb833d1999-08-19 00:55:39 +00001417/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001418 * Initialize a GLcontext struct. This includes allocating all the
1419 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001420 */
Brian Paul178a1c52000-04-22 01:05:00 +00001421GLboolean
1422_mesa_initialize_context( GLcontext *ctx,
1423 GLvisual *visual,
1424 GLcontext *share_list,
1425 void *driver_ctx,
1426 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001427{
Brian Paul5fb84d22000-05-24 15:04:45 +00001428 GLuint dispatchSize;
1429
jtgafb833d1999-08-19 00:55:39 +00001430 (void) direct; /* not used */
1431
jtgafb833d1999-08-19 00:55:39 +00001432 /* misc one-time initializations */
1433 one_time_init();
1434
Brian Paulb1394fa2000-09-26 20:53:53 +00001435 /**
1436 ** OpenGL SI stuff
1437 **/
1438 if (!ctx->imports.malloc) {
1439 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1440 }
1441 /* exports are setup by the device driver */
1442
jtgafb833d1999-08-19 00:55:39 +00001443 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001444 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001445 ctx->DrawBuffer = NULL;
1446 ctx->ReadBuffer = NULL;
jtgafb833d1999-08-19 00:55:39 +00001447
1448 ctx->VB = gl_vb_create_for_immediate( ctx );
1449 if (!ctx->VB) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001450 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001451 }
1452 ctx->input = ctx->VB->IM;
1453
1454 ctx->PB = gl_alloc_pb();
1455 if (!ctx->PB) {
Brian Paul2d8db392000-06-27 22:10:00 +00001456 ALIGN_FREE( ctx->VB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001457 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001458 }
1459
1460 if (share_list) {
1461 /* share the group of display lists of another context */
1462 ctx->Shared = share_list->Shared;
1463 }
1464 else {
1465 /* allocate new group of display lists */
1466 ctx->Shared = alloc_shared_state();
1467 if (!ctx->Shared) {
Brian Paul2d8db392000-06-27 22:10:00 +00001468 ALIGN_FREE( ctx->VB );
1469 FREE( ctx->PB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001470 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001471 }
1472 }
Brian Paul9560f052000-01-31 23:11:39 +00001473 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001474 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001475 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001476
Brian Paul4d053dd2000-01-14 04:45:47 +00001477 init_attrib_groups( ctx );
1478
jtgafb833d1999-08-19 00:55:39 +00001479 gl_reset_vb( ctx->VB );
1480 gl_reset_input( ctx );
1481
jtgafb833d1999-08-19 00:55:39 +00001482 if (visual->DBflag) {
1483 ctx->Color.DrawBuffer = GL_BACK;
1484 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1485 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1486 ctx->Pixel.ReadBuffer = GL_BACK;
1487 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1488 }
1489 else {
1490 ctx->Color.DrawBuffer = GL_FRONT;
1491 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1492 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1493 ctx->Pixel.ReadBuffer = GL_FRONT;
1494 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1495 }
1496
jtgafb833d1999-08-19 00:55:39 +00001497 if (!alloc_proxy_textures(ctx)) {
1498 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001499 ALIGN_FREE( ctx->VB );
1500 FREE( ctx->PB );
Brian Paul4d053dd2000-01-14 04:45:47 +00001501 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001502 }
jtgafb833d1999-08-19 00:55:39 +00001503
Brian Paulf59afc92000-05-23 23:23:00 +00001504 /* register the most recent extension functions with libGL */
1505 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1506 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1507 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1508 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1509 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1510 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1511 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1512 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1513
Brian Paul5fb84d22000-05-24 15:04:45 +00001514 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1515 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1516 * Mesa we do this to accomodate different versions of libGL and various
1517 * DRI drivers.
1518 */
1519 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1520 sizeof(struct _glapi_table) / sizeof(void *));
1521
Brian Paulfbd8f211999-11-11 01:22:25 +00001522 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001523 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1524 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001525 if (!ctx->Exec || !ctx->Save) {
1526 free_shared_state(ctx, ctx->Shared);
Brian Paul2d8db392000-06-27 22:10:00 +00001527 ALIGN_FREE( ctx->VB );
1528 FREE( ctx->PB );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001529 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001530 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001531 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001532 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1533 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001534 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001535
Brian Paul3b18a362000-09-26 15:27:20 +00001536#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +00001537 ctx->TraceCtx = CALLOC( sizeof(trace_context_t) );
1538#if 0
1539 /* Brian: do you want to have CreateContext fail here,
1540 or should we just trap in NewTrace (currently done)? */
1541 if (!(ctx->TraceCtx)) {
1542 free_shared_state(ctx, ctx->Shared);
1543 ALIGN_FREE( ctx->VB );
1544 FREE( ctx->PB );
1545 FREE( ctx->Exec );
1546 FREE( ctx->Save );
1547 return GL_FALSE;
1548 }
1549#endif
1550 trInitContext(ctx->TraceCtx);
1551
1552 ctx->TraceDispatch = (struct _glapi_table *)
1553 CALLOC(dispatchSize * sizeof(void*));
1554#if 0
1555 if (!(ctx->TraceCtx)) {
1556 free_shared_state(ctx, ctx->Shared);
1557 ALIGN_FREE( ctx->VB );
1558 FREE( ctx->PB );
1559 FREE( ctx->Exec );
1560 FREE( ctx->Save );
1561 FREE( ctx->TraceCtx );
1562 return GL_FALSE;
1563 }
1564#endif
1565 trInitDispatch(ctx->TraceDispatch);
1566#endif
1567
Brian Paul4d053dd2000-01-14 04:45:47 +00001568 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001569}
1570
jtgafb833d1999-08-19 00:55:39 +00001571
1572
1573/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001574 * Allocate and initialize a GLcontext structure.
1575 * Input: visual - a GLvisual pointer
1576 * sharelist - another context to share display lists with or NULL
1577 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001578 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001579 */
Brian Paul178a1c52000-04-22 01:05:00 +00001580GLcontext *
Brian Paulb1394fa2000-09-26 20:53:53 +00001581_mesa_create_context( GLvisual *visual,
1582 GLcontext *share_list,
1583 void *driver_ctx,
1584 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001585{
1586 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1587 if (!ctx) {
1588 return NULL;
1589 }
1590
Brian Paul178a1c52000-04-22 01:05:00 +00001591 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001592 return ctx;
1593 }
1594 else {
1595 FREE(ctx);
1596 return NULL;
1597 }
1598}
1599
1600
1601
1602/*
1603 * Free the data associated with the given context.
1604 * But don't free() the GLcontext struct itself!
1605 */
Brian Paul178a1c52000-04-22 01:05:00 +00001606void
Brian Paulb1394fa2000-09-26 20:53:53 +00001607_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001608{
Brian Paul4d053dd2000-01-14 04:45:47 +00001609 struct gl_shine_tab *s, *tmps;
Brian Paul7fc29c52000-03-06 17:03:03 +00001610 GLuint i, j;
Brian Paul4d053dd2000-01-14 04:45:47 +00001611
1612 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001613 if (ctx == _mesa_get_current_context()) {
1614 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001615 }
1616
Brian Paul4d053dd2000-01-14 04:45:47 +00001617 gl_matrix_dtr( &ctx->ModelView );
Brian Paul7fc29c52000-03-06 17:03:03 +00001618 for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001619 gl_matrix_dtr( &ctx->ModelViewStack[i] );
1620 }
1621 gl_matrix_dtr( &ctx->ProjectionMatrix );
Brian Paul7fc29c52000-03-06 17:03:03 +00001622 for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001623 gl_matrix_dtr( &ctx->ProjectionStack[i] );
1624 }
Brian Paul7fc29c52000-03-06 17:03:03 +00001625 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1626 gl_matrix_dtr( &ctx->TextureMatrix[i] );
1627 for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
1628 gl_matrix_dtr( &ctx->TextureStack[i][j] );
1629 }
1630 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001631
1632 FREE( ctx->PB );
1633
Brian Paul4bdcfe52000-04-17 17:57:04 +00001634 if (ctx->input != ctx->VB->IM)
Brian Paul4d053dd2000-01-14 04:45:47 +00001635 gl_immediate_free( ctx->input );
1636
1637 gl_vb_free( ctx->VB );
1638
Brian Paul9560f052000-01-31 23:11:39 +00001639 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001640 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001641 assert(ctx->Shared->RefCount >= 0);
1642 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1643 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001644 /* free shared state */
1645 free_shared_state( ctx, ctx->Shared );
1646 }
1647
1648 foreach_s( s, tmps, ctx->ShineTabList ) {
1649 FREE( s );
1650 }
1651 FREE( ctx->ShineTabList );
1652
1653 /* Free proxy texture objects */
1654 gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
1655 gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
1656 gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
1657
1658 /* Free evaluator data */
1659 if (ctx->EvalMap.Map1Vertex3.Points)
1660 FREE( ctx->EvalMap.Map1Vertex3.Points );
1661 if (ctx->EvalMap.Map1Vertex4.Points)
1662 FREE( ctx->EvalMap.Map1Vertex4.Points );
1663 if (ctx->EvalMap.Map1Index.Points)
1664 FREE( ctx->EvalMap.Map1Index.Points );
1665 if (ctx->EvalMap.Map1Color4.Points)
1666 FREE( ctx->EvalMap.Map1Color4.Points );
1667 if (ctx->EvalMap.Map1Normal.Points)
1668 FREE( ctx->EvalMap.Map1Normal.Points );
1669 if (ctx->EvalMap.Map1Texture1.Points)
1670 FREE( ctx->EvalMap.Map1Texture1.Points );
1671 if (ctx->EvalMap.Map1Texture2.Points)
1672 FREE( ctx->EvalMap.Map1Texture2.Points );
1673 if (ctx->EvalMap.Map1Texture3.Points)
1674 FREE( ctx->EvalMap.Map1Texture3.Points );
1675 if (ctx->EvalMap.Map1Texture4.Points)
1676 FREE( ctx->EvalMap.Map1Texture4.Points );
1677
1678 if (ctx->EvalMap.Map2Vertex3.Points)
1679 FREE( ctx->EvalMap.Map2Vertex3.Points );
1680 if (ctx->EvalMap.Map2Vertex4.Points)
1681 FREE( ctx->EvalMap.Map2Vertex4.Points );
1682 if (ctx->EvalMap.Map2Index.Points)
1683 FREE( ctx->EvalMap.Map2Index.Points );
1684 if (ctx->EvalMap.Map2Color4.Points)
1685 FREE( ctx->EvalMap.Map2Color4.Points );
1686 if (ctx->EvalMap.Map2Normal.Points)
1687 FREE( ctx->EvalMap.Map2Normal.Points );
1688 if (ctx->EvalMap.Map2Texture1.Points)
1689 FREE( ctx->EvalMap.Map2Texture1.Points );
1690 if (ctx->EvalMap.Map2Texture2.Points)
1691 FREE( ctx->EvalMap.Map2Texture2.Points );
1692 if (ctx->EvalMap.Map2Texture3.Points)
1693 FREE( ctx->EvalMap.Map2Texture3.Points );
1694 if (ctx->EvalMap.Map2Texture4.Points)
1695 FREE( ctx->EvalMap.Map2Texture4.Points );
1696
Brian Paul4bdcfe52000-04-17 17:57:04 +00001697 _mesa_free_colortable_data( &ctx->ColorTable );
1698 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1699 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1700 _mesa_free_colortable_data( &ctx->Texture.Palette );
1701
Brian Paul4d053dd2000-01-14 04:45:47 +00001702 /* Free cache of immediate buffers. */
1703 while (ctx->nr_im_queued-- > 0) {
1704 struct immediate * next = ctx->freed_im_queue->next;
Brian Paul2d8db392000-06-27 22:10:00 +00001705 ALIGN_FREE( ctx->freed_im_queue );
Brian Paul4d053dd2000-01-14 04:45:47 +00001706 ctx->freed_im_queue = next;
1707 }
1708 gl_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001709
1710 FREE(ctx->Exec);
1711 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001712}
1713
1714
1715
1716/*
1717 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001718 */
Brian Paul178a1c52000-04-22 01:05:00 +00001719void
Brian Paulb1394fa2000-09-26 20:53:53 +00001720_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001721{
1722 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001723 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001724 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001725 }
1726}
1727
1728
1729
1730/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001731 * Called by the driver after both the context and driver are fully
1732 * initialized. Currently just reads the config file.
jtgafb833d1999-08-19 00:55:39 +00001733 */
Brian Paul178a1c52000-04-22 01:05:00 +00001734void
Brian Paulb1394fa2000-09-26 20:53:53 +00001735_mesa_context_initialize( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001736{
Brian Paul00037781999-12-17 14:52:35 +00001737 gl_read_config_file( ctx );
jtgafb833d1999-08-19 00:55:39 +00001738}
1739
1740
1741
1742/*
1743 * Copy attribute groups from one context to another.
1744 * Input: src - source context
1745 * dst - destination context
1746 * mask - bitwise OR of GL_*_BIT flags
1747 */
Brian Paul178a1c52000-04-22 01:05:00 +00001748void
Brian Paulb1394fa2000-09-26 20:53:53 +00001749_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001750{
1751 if (mask & GL_ACCUM_BUFFER_BIT) {
1752 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1753 }
1754 if (mask & GL_COLOR_BUFFER_BIT) {
1755 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1756 }
1757 if (mask & GL_CURRENT_BIT) {
1758 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1759 }
1760 if (mask & GL_DEPTH_BUFFER_BIT) {
1761 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1762 }
1763 if (mask & GL_ENABLE_BIT) {
1764 /* no op */
1765 }
1766 if (mask & GL_EVAL_BIT) {
1767 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1768 }
1769 if (mask & GL_FOG_BIT) {
1770 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1771 }
1772 if (mask & GL_HINT_BIT) {
1773 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1774 }
1775 if (mask & GL_LIGHTING_BIT) {
1776 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001777 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001778 }
1779 if (mask & GL_LINE_BIT) {
1780 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1781 }
1782 if (mask & GL_LIST_BIT) {
1783 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1784 }
1785 if (mask & GL_PIXEL_MODE_BIT) {
1786 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1787 }
1788 if (mask & GL_POINT_BIT) {
1789 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1790 }
1791 if (mask & GL_POLYGON_BIT) {
1792 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1793 }
1794 if (mask & GL_POLYGON_STIPPLE_BIT) {
1795 /* Use loop instead of MEMCPY due to problem with Portland Group's
1796 * C compiler. Reported by John Stone.
1797 */
1798 int i;
1799 for (i=0;i<32;i++) {
1800 dst->PolygonStipple[i] = src->PolygonStipple[i];
1801 }
1802 }
1803 if (mask & GL_SCISSOR_BIT) {
1804 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1805 }
1806 if (mask & GL_STENCIL_BUFFER_BIT) {
1807 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1808 }
1809 if (mask & GL_TEXTURE_BIT) {
1810 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1811 }
1812 if (mask & GL_TRANSFORM_BIT) {
1813 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1814 }
1815 if (mask & GL_VIEWPORT_BIT) {
1816 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1817 }
1818}
1819
1820
jtgafb833d1999-08-19 00:55:39 +00001821/*
Brian Paul00037781999-12-17 14:52:35 +00001822 * Set the current context, binding the given frame buffer to the context.
1823 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001824void
1825_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001826{
Brian Paulb1394fa2000-09-26 20:53:53 +00001827 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001828}
1829
1830
1831/*
1832 * Bind the given context to the given draw-buffer and read-buffer
1833 * and make it the current context for this thread.
1834 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001835void
1836_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1837 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001838{
1839#if 0
Brian Paulf9b97d92000-01-28 20:17:42 +00001840 GLcontext *oldCtx = gl_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001841
1842 /* Flush the old context
1843 */
1844 if (oldCtx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001845 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "_mesa_make_current");
Brian Paul00037781999-12-17 14:52:35 +00001846
1847 /* unbind frame buffers from context */
1848 if (oldCtx->DrawBuffer) {
1849 oldCtx->DrawBuffer = NULL;
1850 }
1851 if (oldCtx->ReadBuffer) {
1852 oldCtx->ReadBuffer = NULL;
1853 }
1854 }
1855#endif
1856
1857 /* We call this function periodically (just here for now) in
1858 * order to detect when multithreading has begun.
1859 */
1860 _glapi_check_multithread();
1861
Brian Paulf9b97d92000-01-28 20:17:42 +00001862 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001863 ASSERT(_mesa_get_current_context() == newCtx);
Brian Paul00037781999-12-17 14:52:35 +00001864 if (newCtx) {
1865 SET_IMMEDIATE(newCtx, newCtx->input);
1866 _glapi_set_dispatch(newCtx->CurrentDispatch);
1867 }
1868 else {
1869 _glapi_set_dispatch(NULL); /* none current */
1870 }
1871
Brian Paulb1394fa2000-09-26 20:53:53 +00001872 if (MESA_VERBOSE) fprintf(stderr, "_mesa_make_current()\n");
Brian Paul00037781999-12-17 14:52:35 +00001873
1874 if (newCtx && drawBuffer && readBuffer) {
1875 /* TODO: check if newCtx and buffer's visual match??? */
1876 newCtx->DrawBuffer = drawBuffer;
1877 newCtx->ReadBuffer = readBuffer;
1878 newCtx->NewState = NEW_ALL; /* just to be safe */
1879 gl_update_state( newCtx );
1880 }
1881
1882 /* We can use this to help debug user's problems. Tell the to set
1883 * the MESA_INFO env variable before running their app. Then the
1884 * first time each context is made current we'll print some useful
1885 * information.
1886 */
1887 if (newCtx && newCtx->FirstTimeCurrent) {
1888 if (getenv("MESA_INFO")) {
1889 fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
1890 fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
1891 fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
1892 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
Brian Paul09cb1481999-12-17 17:00:32 +00001893#if defined(THREADS)
1894 fprintf(stderr, "Mesa thread-safe: YES\n");
1895#else
1896 fprintf(stderr, "Mesa thread-safe: NO\n");
1897#endif
Brian Paul54287052000-01-17 20:00:15 +00001898#if defined(USE_X86_ASM)
1899 fprintf(stderr, "Mesa x86-optimized: YES\n");
1900#else
1901 fprintf(stderr, "Mesa x86-optimized: NO\n");
1902#endif
Brian Paul00037781999-12-17 14:52:35 +00001903 }
1904 newCtx->FirstTimeCurrent = GL_FALSE;
1905 }
1906}
1907
1908
1909
1910/*
1911 * Return current context handle for the calling thread.
1912 * This isn't the fastest way to get the current context.
1913 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1914 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001915GLcontext *
1916_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001917{
Brian Paulf9b97d92000-01-28 20:17:42 +00001918 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001919}
1920
1921
1922
1923/*
Brian Paulfbd8f211999-11-11 01:22:25 +00001924 * This should be called by device drivers just before they do a
1925 * swapbuffers. Any pending rendering commands will be executed.
jtgafb833d1999-08-19 00:55:39 +00001926 */
Brian Paulfbd8f211999-11-11 01:22:25 +00001927void
1928_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00001929{
Brian Paulfbd8f211999-11-11 01:22:25 +00001930 FLUSH_VB( ctx, "swap buffers" );
jtgafb833d1999-08-19 00:55:39 +00001931}
1932
1933
Brian Paul00037781999-12-17 14:52:35 +00001934
Brian Paulfbd8f211999-11-11 01:22:25 +00001935/*
1936 * Return pointer to this context's current API dispatch table.
1937 * It'll either be the immediate-mode execute dispatcher or the
1938 * display list compile dispatcher.
1939 */
1940struct _glapi_table *
1941_mesa_get_dispatch(GLcontext *ctx)
1942{
1943 return ctx->CurrentDispatch;
1944}
1945
1946
1947
jtgafb833d1999-08-19 00:55:39 +00001948/**********************************************************************/
1949/***** Miscellaneous functions *****/
1950/**********************************************************************/
1951
1952
1953/*
1954 * This function is called when the Mesa user has stumbled into a code
1955 * path which may not be implemented fully or correctly.
1956 */
1957void gl_problem( const GLcontext *ctx, const char *s )
1958{
1959 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paul413d6a22000-05-26 14:44:59 +00001960 fprintf( stderr, "Report to Mesa bug database at www.mesa3d.org\n" );
jtgafb833d1999-08-19 00:55:39 +00001961 (void) ctx;
1962}
1963
1964
1965
1966/*
1967 * This is called to inform the user that he or she has tried to do
1968 * something illogical or if there's likely a bug in their program
1969 * (like enabled depth testing without a depth buffer).
1970 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001971void
1972_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001973{
Brian Paulb1394fa2000-09-26 20:53:53 +00001974 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00001975}
1976
1977
1978
Brian Paulfa9df402000-02-02 19:16:46 +00001979/*
1980 * Compile an error into current display list.
1981 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001982void
1983_mesa_compile_error( GLcontext *ctx, GLenum error, const char *s )
jtgafb833d1999-08-19 00:55:39 +00001984{
1985 if (ctx->CompileFlag)
1986 gl_save_error( ctx, error, s );
1987
1988 if (ctx->ExecuteFlag)
1989 gl_error( ctx, error, s );
1990}
1991
1992
Brian Paulfa9df402000-02-02 19:16:46 +00001993
jtgafb833d1999-08-19 00:55:39 +00001994/*
1995 * This is Mesa's error handler. Normally, all that's done is the updating
1996 * of the current error value. If Mesa is compiled with -DDEBUG or if the
1997 * environment variable "MESA_DEBUG" is defined then a real error message
1998 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00001999 * Input: ctx - the GL context
2000 * error - the error value
2001 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00002002 */
Brian Paul7eb06032000-07-14 04:13:40 +00002003void
2004gl_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00002005{
Brian Paul7eb06032000-07-14 04:13:40 +00002006 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00002007 GLboolean debug;
2008
2009#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002010 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002011 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002012 else
2013 debug = GL_TRUE;
2014#else
2015 if (debugEnv)
2016 debug = GL_TRUE;
2017 else
2018 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002019#endif
2020
2021 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002022 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002023 switch (error) {
2024 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002025 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002026 break;
2027 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002028 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002029 break;
2030 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002031 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002032 break;
2033 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002034 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002035 break;
2036 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002037 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002038 break;
2039 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002040 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002041 break;
2042 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002043 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002044 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002045 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002046 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002047 break;
jtgafb833d1999-08-19 00:55:39 +00002048 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002049 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002050 break;
2051 }
Brian Paul7eb06032000-07-14 04:13:40 +00002052 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002053 }
2054
Brian Paul7eb06032000-07-14 04:13:40 +00002055 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002056 ctx->ErrorValue = error;
2057 }
2058
2059 /* Call device driver's error handler, if any. This is used on the Mac. */
2060 if (ctx->Driver.Error) {
2061 (*ctx->Driver.Error)( ctx );
2062 }
2063}
2064
2065
2066
Brian Paulfa9df402000-02-02 19:16:46 +00002067void
2068_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002069{
Brian Paulfa9df402000-02-02 19:16:46 +00002070 GET_CURRENT_CONTEXT(ctx);
2071 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
2072 if (ctx->Driver.Finish) {
2073 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002074 }
2075}
2076
2077
2078
Brian Paulfa9df402000-02-02 19:16:46 +00002079void
2080_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002081{
Brian Paulfa9df402000-02-02 19:16:46 +00002082 GET_CURRENT_CONTEXT(ctx);
2083 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
2084 if (ctx->Driver.Flush) {
2085 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002086 }
jtgafb833d1999-08-19 00:55:39 +00002087}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002088
2089
2090
2091const char *_mesa_prim_name[GL_POLYGON+2] = {
2092 "GL_POINTS",
2093 "GL_LINES",
2094 "GL_LINE_LOOP",
2095 "GL_LINE_STRIP",
2096 "GL_TRIANGLES",
2097 "GL_TRIANGLE_STRIP",
2098 "GL_TRIANGLE_FAN",
2099 "GL_QUADS",
2100 "GL_QUAD_STRIP",
2101 "GL_POLYGON",
2102 "culled primitive"
2103};
2104
Brian Paul1c56fdc2000-09-17 21:56:07 +00002105
2106GLenum gl_reduce_prim[GL_POLYGON+1] = {
2107 GL_POINTS,
2108 GL_LINES,
2109 GL_LINES,
2110 GL_LINES,
2111 GL_TRIANGLES,
2112 GL_TRIANGLES,
2113 GL_TRIANGLES,
2114 GL_TRIANGLES,
2115 GL_TRIANGLES,
2116 GL_TRIANGLES,
2117};