blob: 420bfa46914f3b1e8e196f579f225891ea18240a [file] [log] [blame]
Brian Paul6c408b42002-05-27 17:04:52 +00001/* $Id: context.c,v 1.163 2002/05/27 17:04:52 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul86b84272001-12-14 02:50:01 +00005 * Version: 4.1
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Paulbc42c192002-01-05 21:53:20 +00007 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
jtgafb833d1999-08-19 00:55:39 +000028#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000032#include "buffers.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "clip.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000034#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000035#include "context.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "dlist.h"
37#include "eval.h"
38#include "enums.h"
Brian Paul585a68c1999-09-11 11:31:34 +000039#include "extensions.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "fog.h"
Brian Paulb7a43041999-11-30 20:34:51 +000041#include "get.h"
Brian Paul9560f052000-01-31 23:11:39 +000042#include "glthread.h"
jtgafb833d1999-08-19 00:55:39 +000043#include "hash.h"
Brian Paulb1394fa2000-09-26 20:53:53 +000044#include "imports.h"
jtgafb833d1999-08-19 00:55:39 +000045#include "light.h"
jtgafb833d1999-08-19 00:55:39 +000046#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000047#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000048#include "mmath.h"
jtgafb833d1999-08-19 00:55:39 +000049#include "simple_list.h"
Brian Paulfa9df402000-02-02 19:16:46 +000050#include "state.h"
jtgafb833d1999-08-19 00:55:39 +000051#include "teximage.h"
52#include "texobj.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000053#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000054#include "varray.h"
Brian Paul30f51ae2001-12-18 04:06:44 +000055#include "vpstate.h"
Gareth Hughesd4eb6652001-03-12 01:32:20 +000056#include "vtxfmt.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000057#include "math/m_translate.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000058#include "math/m_matrix.h"
59#include "math/m_xform.h"
Keith Whitwellf4b02d12001-01-05 05:31:42 +000060#include "math/mathmod.h"
jtgafb833d1999-08-19 00:55:39 +000061#endif
62
Brian Paul3b18a362000-09-26 15:27:20 +000063#if defined(MESA_TRACE)
Brian Paul45f36342000-09-05 20:28:06 +000064#include "Trace/tr_context.h"
65#include "Trace/tr_wrapper.h"
66#endif
67
davem69775355a2001-06-05 23:54:00 +000068#ifdef USE_SPARC_ASM
69#include "SPARC/sparc.h"
70#endif
jtgafb833d1999-08-19 00:55:39 +000071
Keith Whitwell23caf202000-11-16 21:05:34 +000072#ifndef MESA_VERBOSE
Keith Whitwell306d3fc2002-04-09 16:56:50 +000073int MESA_VERBOSE = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +000074#endif
75
76#ifndef MESA_DEBUG_FLAGS
Keith Whitwell306d3fc2002-04-09 16:56:50 +000077int MESA_DEBUG_FLAGS = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +000078#endif
Brian Paulb1394fa2000-09-26 20:53:53 +000079
Brian Paul86b84272001-12-14 02:50:01 +000080
81
Brian Paulb1394fa2000-09-26 20:53:53 +000082/**********************************************************************/
83/***** OpenGL SI-style interface (new in Mesa 3.5) *****/
84/**********************************************************************/
85
86static GLboolean
87_mesa_DestroyContext(__GLcontext *gc)
88{
89 if (gc) {
90 _mesa_free_context_data(gc);
91 (*gc->imports.free)(gc, gc);
92 }
93 return GL_TRUE;
94}
95
96
97/* exported OpenGL SI interface */
98__GLcontext *
99__glCoreCreateContext(__GLimports *imports, __GLcontextModes *modes)
100{
101 GLcontext *ctx;
102
103 ctx = (GLcontext *) (*imports->calloc)(0, 1, sizeof(GLcontext));
104 if (ctx == NULL) {
105 return NULL;
106 }
Jouk Jansen12e875c2001-10-18 08:04:57 +0000107 ctx->Driver.CurrentExecPrimitive=0;
Brian Paulb1394fa2000-09-26 20:53:53 +0000108 ctx->imports = *imports;
109
110 _mesa_initialize_visual(&ctx->Visual,
111 modes->rgbMode,
112 modes->doubleBufferMode,
113 modes->stereoMode,
114 modes->redBits,
115 modes->greenBits,
116 modes->blueBits,
117 modes->alphaBits,
118 modes->indexBits,
119 modes->depthBits,
120 modes->stencilBits,
121 modes->accumRedBits,
122 modes->accumGreenBits,
123 modes->accumBlueBits,
124 modes->accumAlphaBits,
125 0);
126
Keith Whitwellb980b2e2001-01-08 04:09:41 +0000127 /* KW: was imports->wscx */
128 _mesa_initialize_context(ctx, &ctx->Visual, NULL, imports->other, GL_FALSE);
Brian Paulb1394fa2000-09-26 20:53:53 +0000129
130 ctx->exports.destroyContext = _mesa_DestroyContext;
131
132 return ctx;
133}
134
135
136/* exported OpenGL SI interface */
137void
138__glCoreNopDispatch(void)
139{
140#if 0
141 /* SI */
142 __gl_dispatch = __glNopDispatchState;
143#else
144 /* Mesa */
145 _glapi_set_dispatch(NULL);
146#endif
147}
148
149
jtgafb833d1999-08-19 00:55:39 +0000150/**********************************************************************/
151/***** Context and Thread management *****/
152/**********************************************************************/
153
154
jtgafb833d1999-08-19 00:55:39 +0000155
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{
Brian Paulb6bcae52001-01-23 23:39:36 +0000235 (void) numSamples;
236
Brian Paul178a1c52000-04-22 01:05:00 +0000237 assert(vis);
Brian Paul4d053dd2000-01-14 04:45:47 +0000238
Brian Pauled30dfa2000-03-03 17:47:39 +0000239 /* This is to catch bad values from device drivers not updated for
240 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
241 * bad value now (a 1-bit depth buffer!?!).
242 */
243 assert(depthBits == 0 || depthBits > 1);
244
245 if (depthBits < 0 || depthBits > 32) {
Brian Paul178a1c52000-04-22 01:05:00 +0000246 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000247 }
Brian Pauled30dfa2000-03-03 17:47:39 +0000248 if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000249 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000250 }
Brian Paulb371e0d2000-03-31 01:05:51 +0000251 if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000252 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000253 }
254 if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000255 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000256 }
257 if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000258 return GL_FALSE;
Brian Paulb371e0d2000-03-31 01:05:51 +0000259 }
260 if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
Brian Paul178a1c52000-04-22 01:05:00 +0000261 return GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000262 }
263
Brian Paulb6bcae52001-01-23 23:39:36 +0000264 vis->rgbMode = rgbFlag;
265 vis->doubleBufferMode = dbFlag;
266 vis->stereoMode = stereoFlag;
267 vis->redBits = redBits;
268 vis->greenBits = greenBits;
269 vis->blueBits = blueBits;
270 vis->alphaBits = alphaBits;
Brian Paul4d053dd2000-01-14 04:45:47 +0000271
Brian Paulb6bcae52001-01-23 23:39:36 +0000272 vis->indexBits = indexBits;
273 vis->depthBits = depthBits;
274 vis->accumRedBits = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
275 vis->accumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
276 vis->accumBlueBits = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
277 vis->accumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
278 vis->stencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
Brian Pauled30dfa2000-03-03 17:47:39 +0000279
Brian Paul178a1c52000-04-22 01:05:00 +0000280 return GL_TRUE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000281}
282
283
Brian Paulb371e0d2000-03-31 01:05:51 +0000284void
285_mesa_destroy_visual( GLvisual *vis )
286{
287 FREE(vis);
288}
289
290
Brian Paul4d053dd2000-01-14 04:45:47 +0000291/**********************************************************************/
292/***** GL Framebuffer allocation/destruction *****/
293/**********************************************************************/
294
295
296/*
297 * Create a new framebuffer. A GLframebuffer is a struct which
298 * encapsulates the depth, stencil and accum buffers and related
299 * parameters.
Brian Paulbe3602d2001-02-28 00:27:48 +0000300 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +0000301 * softwareDepth - create/use a software depth buffer?
302 * softwareStencil - create/use a software stencil buffer?
303 * softwareAccum - create/use a software accum buffer?
304 * softwareAlpha - create/use a software alpha buffer?
Brian Paul4d053dd2000-01-14 04:45:47 +0000305 * Return: pointer to new GLframebuffer struct or NULL if error.
306 */
Brian Paul178a1c52000-04-22 01:05:00 +0000307GLframebuffer *
Brian Paulbe3602d2001-02-28 00:27:48 +0000308_mesa_create_framebuffer( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +0000309 GLboolean softwareDepth,
310 GLboolean softwareStencil,
311 GLboolean softwareAccum,
312 GLboolean softwareAlpha )
Brian Paul4d053dd2000-01-14 04:45:47 +0000313{
Brian Paul178a1c52000-04-22 01:05:00 +0000314 GLframebuffer *buffer = CALLOC_STRUCT(gl_frame_buffer);
315 assert(visual);
316 if (buffer) {
317 _mesa_initialize_framebuffer(buffer, visual,
318 softwareDepth, softwareStencil,
319 softwareAccum, softwareAlpha );
Brian Paul4d053dd2000-01-14 04:45:47 +0000320 }
Brian Paul178a1c52000-04-22 01:05:00 +0000321 return buffer;
322}
323
324
325/*
326 * Initialize a GLframebuffer object.
Brian Paulb1394fa2000-09-26 20:53:53 +0000327 * Input: See _mesa_create_framebuffer() above.
Brian Paul178a1c52000-04-22 01:05:00 +0000328 */
329void
330_mesa_initialize_framebuffer( GLframebuffer *buffer,
Brian Paulbe3602d2001-02-28 00:27:48 +0000331 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +0000332 GLboolean softwareDepth,
333 GLboolean softwareStencil,
334 GLboolean softwareAccum,
335 GLboolean softwareAlpha )
336{
337 assert(buffer);
338 assert(visual);
Brian Paul4d053dd2000-01-14 04:45:47 +0000339
340 /* sanity checks */
341 if (softwareDepth ) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000342 assert(visual->depthBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000343 }
344 if (softwareStencil) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000345 assert(visual->stencilBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000346 }
347 if (softwareAccum) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000348 assert(visual->rgbMode);
349 assert(visual->accumRedBits > 0);
350 assert(visual->accumGreenBits > 0);
351 assert(visual->accumBlueBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000352 }
353 if (softwareAlpha) {
Brian Paulb6bcae52001-01-23 23:39:36 +0000354 assert(visual->rgbMode);
355 assert(visual->alphaBits > 0);
Brian Paul4d053dd2000-01-14 04:45:47 +0000356 }
357
Brian Paul75978bd2001-04-27 21:17:20 +0000358 buffer->Visual = *visual;
Brian Paul4d053dd2000-01-14 04:45:47 +0000359 buffer->UseSoftwareDepthBuffer = softwareDepth;
360 buffer->UseSoftwareStencilBuffer = softwareStencil;
361 buffer->UseSoftwareAccumBuffer = softwareAccum;
362 buffer->UseSoftwareAlphaBuffers = softwareAlpha;
Brian Paul4d053dd2000-01-14 04:45:47 +0000363}
364
365
Brian Paul4d053dd2000-01-14 04:45:47 +0000366/*
367 * Free a framebuffer struct and its buffers.
368 */
Brian Paul178a1c52000-04-22 01:05:00 +0000369void
Brian Paulb1394fa2000-09-26 20:53:53 +0000370_mesa_destroy_framebuffer( GLframebuffer *buffer )
Brian Paul4d053dd2000-01-14 04:45:47 +0000371{
372 if (buffer) {
Brian Paul75978bd2001-04-27 21:17:20 +0000373 _mesa_free_framebuffer_data(buffer);
Brian Paul4d053dd2000-01-14 04:45:47 +0000374 FREE(buffer);
375 }
376}
377
378
Brian Paul75978bd2001-04-27 21:17:20 +0000379/*
380 * Free the data hanging off of <buffer>, but not <buffer> itself.
381 */
382void
383_mesa_free_framebuffer_data( GLframebuffer *buffer )
384{
385 if (!buffer)
386 return;
387
388 if (buffer->DepthBuffer) {
Brian Paulaeb44342002-03-19 16:47:04 +0000389 MESA_PBUFFER_FREE( buffer->DepthBuffer );
Brian Paul75978bd2001-04-27 21:17:20 +0000390 buffer->DepthBuffer = NULL;
391 }
392 if (buffer->Accum) {
Brian Paulaeb44342002-03-19 16:47:04 +0000393 MESA_PBUFFER_FREE( buffer->Accum );
Brian Paul75978bd2001-04-27 21:17:20 +0000394 buffer->Accum = NULL;
395 }
396 if (buffer->Stencil) {
Brian Paulaeb44342002-03-19 16:47:04 +0000397 MESA_PBUFFER_FREE( buffer->Stencil );
Brian Paul75978bd2001-04-27 21:17:20 +0000398 buffer->Stencil = NULL;
399 }
400 if (buffer->FrontLeftAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000401 MESA_PBUFFER_FREE( buffer->FrontLeftAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000402 buffer->FrontLeftAlpha = NULL;
403 }
404 if (buffer->BackLeftAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000405 MESA_PBUFFER_FREE( buffer->BackLeftAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000406 buffer->BackLeftAlpha = NULL;
407 }
408 if (buffer->FrontRightAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000409 MESA_PBUFFER_FREE( buffer->FrontRightAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000410 buffer->FrontRightAlpha = NULL;
411 }
412 if (buffer->BackRightAlpha) {
Brian Paulaeb44342002-03-19 16:47:04 +0000413 MESA_PBUFFER_FREE( buffer->BackRightAlpha );
Brian Paul75978bd2001-04-27 21:17:20 +0000414 buffer->BackRightAlpha = NULL;
415 }
416}
417
418
Brian Paul4d053dd2000-01-14 04:45:47 +0000419
420/**********************************************************************/
jtgafb833d1999-08-19 00:55:39 +0000421/***** Context allocation, initialization, destroying *****/
422/**********************************************************************/
423
424
Brian Paul9560f052000-01-31 23:11:39 +0000425_glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
426
427
jtgafb833d1999-08-19 00:55:39 +0000428/*
429 * This function just calls all the various one-time-init functions in Mesa.
430 */
Brian Paul178a1c52000-04-22 01:05:00 +0000431static void
432one_time_init( void )
jtgafb833d1999-08-19 00:55:39 +0000433{
434 static GLboolean alreadyCalled = GL_FALSE;
Brian Paul9560f052000-01-31 23:11:39 +0000435 _glthread_LOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000436 if (!alreadyCalled) {
Brian Paul4d053dd2000-01-14 04:45:47 +0000437 /* do some implementation tests */
438 assert( sizeof(GLbyte) == 1 );
439 assert( sizeof(GLshort) >= 2 );
440 assert( sizeof(GLint) >= 4 );
441 assert( sizeof(GLubyte) == 1 );
442 assert( sizeof(GLushort) >= 2 );
443 assert( sizeof(GLuint) >= 4 );
444
Brian Paul08836342001-03-03 20:33:27 +0000445 _mesa_init_lists();
Keith Whitwell23caf202000-11-16 21:05:34 +0000446
Keith Whitwell23caf202000-11-16 21:05:34 +0000447 _math_init();
Brian Paul69755402001-02-26 23:58:12 +0000448 _mesa_init_math();
Brian Paul68ee4bc2000-01-28 19:02:22 +0000449
davem69775355a2001-06-05 23:54:00 +0000450#ifdef USE_SPARC_ASM
451 _mesa_init_sparc_glapi_relocs();
452#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000453 if (getenv("MESA_DEBUG")) {
454 _glapi_noop_enable_warnings(GL_TRUE);
455 }
456 else {
457 _glapi_noop_enable_warnings(GL_FALSE);
458 }
459
jtgafb833d1999-08-19 00:55:39 +0000460#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
461 fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
462#endif
Brian Paul68ee4bc2000-01-28 19:02:22 +0000463
464 alreadyCalled = GL_TRUE;
465 }
Brian Paul9560f052000-01-31 23:11:39 +0000466 _glthread_UNLOCK_MUTEX(OneTimeLock);
jtgafb833d1999-08-19 00:55:39 +0000467}
468
469
Brian Paul86b84272001-12-14 02:50:01 +0000470static void
471init_matrix_stack( struct matrix_stack *stack,
472 GLuint maxDepth, GLuint dirtyFlag )
473{
474 GLuint i;
475
476 stack->Depth = 0;
477 stack->MaxDepth = maxDepth;
478 stack->DirtyFlag = dirtyFlag;
Brian Paul86b84272001-12-14 02:50:01 +0000479 /* The stack */
Brian Pauldb07de02002-04-19 00:23:08 +0000480 stack->Stack = (GLmatrix *) CALLOC(maxDepth * sizeof(GLmatrix));
Brian Paul86b84272001-12-14 02:50:01 +0000481 for (i = 0; i < maxDepth; i++) {
482 _math_matrix_ctr(&stack->Stack[i]);
483 _math_matrix_alloc_inv(&stack->Stack[i]);
484 }
Brian Paul30f51ae2001-12-18 04:06:44 +0000485 stack->Top = stack->Stack;
Brian Paul86b84272001-12-14 02:50:01 +0000486}
487
488
489static void
490free_matrix_stack( struct matrix_stack *stack )
491{
492 GLuint i;
Brian Paul86b84272001-12-14 02:50:01 +0000493 for (i = 0; i < stack->MaxDepth; i++) {
494 _math_matrix_dtr(&stack->Stack[i]);
495 }
Brian Paulc4afba32002-02-05 23:21:45 +0000496 FREE(stack->Stack);
Brian Paul30f51ae2001-12-18 04:06:44 +0000497 stack->Stack = stack->Top = NULL;
Brian Paul86b84272001-12-14 02:50:01 +0000498}
499
Brian Paul4d053dd2000-01-14 04:45:47 +0000500
jtgafb833d1999-08-19 00:55:39 +0000501/*
502 * Allocate and initialize a shared context state structure.
503 */
Brian Paul178a1c52000-04-22 01:05:00 +0000504static struct gl_shared_state *
505alloc_shared_state( void )
jtgafb833d1999-08-19 00:55:39 +0000506{
jtgafb833d1999-08-19 00:55:39 +0000507 struct gl_shared_state *ss;
508 GLboolean outOfMemory;
509
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000510 ss = CALLOC_STRUCT(gl_shared_state);
jtgafb833d1999-08-19 00:55:39 +0000511 if (!ss)
512 return NULL;
513
Brian Paule4b684c2000-09-12 21:07:40 +0000514 _glthread_INIT_MUTEX(ss->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000515
Brian Paule4b684c2000-09-12 21:07:40 +0000516 ss->DisplayList = _mesa_NewHashTable();
Brian Paulbb797902000-01-24 16:19:54 +0000517 ss->TexObjects = _mesa_NewHashTable();
Brian Paul30f51ae2001-12-18 04:06:44 +0000518 ss->VertexPrograms = _mesa_NewHashTable();
jtgafb833d1999-08-19 00:55:39 +0000519
520 /* Default Texture objects */
521 outOfMemory = GL_FALSE;
Brian Paula8523782000-11-19 23:10:25 +0000522
523 ss->Default1D = _mesa_alloc_texture_object(ss, 0, 1);
524 if (!ss->Default1D) {
525 outOfMemory = GL_TRUE;
526 }
jtgafb833d1999-08-19 00:55:39 +0000527
Brian Paula8523782000-11-19 23:10:25 +0000528 ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2);
529 if (!ss->Default2D) {
530 outOfMemory = GL_TRUE;
531 }
Brian Paula8523782000-11-19 23:10:25 +0000532
533 ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3);
534 if (!ss->Default3D) {
535 outOfMemory = GL_TRUE;
536 }
Brian Paula8523782000-11-19 23:10:25 +0000537
538 ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6);
Brian Paul413d6a22000-05-26 14:44:59 +0000539 if (!ss->DefaultCubeMap) {
540 outOfMemory = GL_TRUE;
541 }
Brian Paul413d6a22000-05-26 14:44:59 +0000542
Brian Paul30f51ae2001-12-18 04:06:44 +0000543 if (!ss->DisplayList || !ss->TexObjects || !ss->VertexPrograms
544 || outOfMemory) {
jtgafb833d1999-08-19 00:55:39 +0000545 /* Ran out of memory at some point. Free everything and return NULL */
546 if (ss->DisplayList)
Brian Paulbb797902000-01-24 16:19:54 +0000547 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000548 if (ss->TexObjects)
Brian Paulbb797902000-01-24 16:19:54 +0000549 _mesa_DeleteHashTable(ss->TexObjects);
Brian Paul30f51ae2001-12-18 04:06:44 +0000550 if (ss->VertexPrograms)
551 _mesa_DeleteHashTable(ss->VertexPrograms);
Brian Paula8523782000-11-19 23:10:25 +0000552 if (ss->Default1D)
553 _mesa_free_texture_object(ss, ss->Default1D);
554 if (ss->Default2D)
555 _mesa_free_texture_object(ss, ss->Default2D);
556 if (ss->Default3D)
557 _mesa_free_texture_object(ss, ss->Default3D);
Brian Paul413d6a22000-05-26 14:44:59 +0000558 if (ss->DefaultCubeMap)
Brian Paula8523782000-11-19 23:10:25 +0000559 _mesa_free_texture_object(ss, ss->DefaultCubeMap);
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000560 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000561 return NULL;
562 }
563 else {
564 return ss;
565 }
566}
567
568
569/*
570 * Deallocate a shared state context and all children structures.
571 */
Brian Paul178a1c52000-04-22 01:05:00 +0000572static void
573free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
jtgafb833d1999-08-19 00:55:39 +0000574{
575 /* Free display lists */
576 while (1) {
Brian Paulbb797902000-01-24 16:19:54 +0000577 GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000578 if (list) {
Brian Paul08836342001-03-03 20:33:27 +0000579 _mesa_destroy_list(ctx, list);
jtgafb833d1999-08-19 00:55:39 +0000580 }
581 else {
582 break;
583 }
584 }
Brian Paulbb797902000-01-24 16:19:54 +0000585 _mesa_DeleteHashTable(ss->DisplayList);
jtgafb833d1999-08-19 00:55:39 +0000586
587 /* Free texture objects */
Brian Paul5a2f32b2001-04-25 18:21:05 +0000588 while (ss->TexObjectList) {
jtgafb833d1999-08-19 00:55:39 +0000589 if (ctx->Driver.DeleteTexture)
590 (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
591 /* this function removes from linked list too! */
Brian Paula8523782000-11-19 23:10:25 +0000592 _mesa_free_texture_object(ss, ss->TexObjectList);
jtgafb833d1999-08-19 00:55:39 +0000593 }
Brian Paulbb797902000-01-24 16:19:54 +0000594 _mesa_DeleteHashTable(ss->TexObjects);
jtgafb833d1999-08-19 00:55:39 +0000595
Brian Paul30f51ae2001-12-18 04:06:44 +0000596 /* Free vertex programs */
597 while (1) {
598 GLuint prog = _mesa_HashFirstEntry(ss->VertexPrograms);
599 if (prog) {
600 _mesa_delete_program(ctx, prog);
601 }
602 else {
603 break;
604 }
605 }
606 _mesa_DeleteHashTable(ss->VertexPrograms);
607
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000608 FREE(ss);
jtgafb833d1999-08-19 00:55:39 +0000609}
610
611
612
jtgafb833d1999-08-19 00:55:39 +0000613/*
614 * Initialize the nth light. Note that the defaults for light 0 are
615 * different than the other lights.
616 */
Brian Paul178a1c52000-04-22 01:05:00 +0000617static void
618init_light( struct gl_light *l, GLuint n )
jtgafb833d1999-08-19 00:55:39 +0000619{
620 make_empty_list( l );
621
622 ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
623 if (n==0) {
624 ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
625 ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
626 }
627 else {
628 ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
629 ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
630 }
631 ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
632 ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
633 l->SpotExponent = 0.0;
Brian Paul08836342001-03-03 20:33:27 +0000634 _mesa_invalidate_spot_exp_table( l );
jtgafb833d1999-08-19 00:55:39 +0000635 l->SpotCutoff = 180.0;
Keith Whitwell14940c42000-11-05 18:40:57 +0000636 l->_CosCutoff = 0.0; /* KW: -ve values not admitted */
jtgafb833d1999-08-19 00:55:39 +0000637 l->ConstantAttenuation = 1.0;
638 l->LinearAttenuation = 0.0;
639 l->QuadraticAttenuation = 0.0;
640 l->Enabled = GL_FALSE;
641}
642
643
644
Brian Paul178a1c52000-04-22 01:05:00 +0000645static void
646init_lightmodel( struct gl_lightmodel *lm )
jtgafb833d1999-08-19 00:55:39 +0000647{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000648 ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000649 lm->LocalViewer = GL_FALSE;
650 lm->TwoSide = GL_FALSE;
651 lm->ColorControl = GL_SINGLE_COLOR;
652}
653
654
Brian Paul178a1c52000-04-22 01:05:00 +0000655static void
656init_material( struct gl_material *m )
jtgafb833d1999-08-19 00:55:39 +0000657{
Brian Paulfde5e2c2001-09-15 18:02:49 +0000658 ASSIGN_4V( m->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
659 ASSIGN_4V( m->Diffuse, 0.8F, 0.8F, 0.8F, 1.0F );
660 ASSIGN_4V( m->Specular, 0.0F, 0.0F, 0.0F, 1.0F );
661 ASSIGN_4V( m->Emission, 0.0F, 0.0F, 0.0F, 1.0F );
jtgafb833d1999-08-19 00:55:39 +0000662 m->Shininess = 0.0;
663 m->AmbientIndex = 0;
664 m->DiffuseIndex = 1;
665 m->SpecularIndex = 1;
666}
667
668
669
Brian Paul178a1c52000-04-22 01:05:00 +0000670static void
671init_texture_unit( GLcontext *ctx, GLuint unit )
jtgafb833d1999-08-19 00:55:39 +0000672{
673 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
674
675 texUnit->EnvMode = GL_MODULATE;
Brian Paul24507ff2000-06-27 21:42:13 +0000676 texUnit->CombineModeRGB = GL_MODULATE;
677 texUnit->CombineModeA = GL_MODULATE;
678 texUnit->CombineSourceRGB[0] = GL_TEXTURE;
679 texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT;
680 texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT;
681 texUnit->CombineSourceA[0] = GL_TEXTURE;
682 texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT;
683 texUnit->CombineSourceA[2] = GL_CONSTANT_EXT;
684 texUnit->CombineOperandRGB[0] = GL_SRC_COLOR;
685 texUnit->CombineOperandRGB[1] = GL_SRC_COLOR;
686 texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA;
687 texUnit->CombineOperandA[0] = GL_SRC_ALPHA;
688 texUnit->CombineOperandA[1] = GL_SRC_ALPHA;
689 texUnit->CombineOperandA[2] = GL_SRC_ALPHA;
690 texUnit->CombineScaleShiftRGB = 0;
691 texUnit->CombineScaleShiftA = 0;
692
jtgafb833d1999-08-19 00:55:39 +0000693 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
694 texUnit->TexGenEnabled = 0;
695 texUnit->GenModeS = GL_EYE_LINEAR;
696 texUnit->GenModeT = GL_EYE_LINEAR;
697 texUnit->GenModeR = GL_EYE_LINEAR;
698 texUnit->GenModeQ = GL_EYE_LINEAR;
Keith Whitwell14940c42000-11-05 18:40:57 +0000699 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
700 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
701 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
702 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
Brian Paul26f3b052000-07-19 20:58:59 +0000703
jtgafb833d1999-08-19 00:55:39 +0000704 /* Yes, these plane coefficients are correct! */
705 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
706 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
707 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
708 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
709 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
710 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
711 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
712 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
713
Brian Paula8523782000-11-19 23:10:25 +0000714 texUnit->Current1D = ctx->Shared->Default1D;
715 texUnit->Current2D = ctx->Shared->Default2D;
716 texUnit->Current3D = ctx->Shared->Default3D;
Brian Paul413d6a22000-05-26 14:44:59 +0000717 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
jtgafb833d1999-08-19 00:55:39 +0000718}
719
720
jtgafb833d1999-08-19 00:55:39 +0000721
Brian Paul4d053dd2000-01-14 04:45:47 +0000722
jtgafb833d1999-08-19 00:55:39 +0000723/* Initialize a 1-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000724static void
725init_1d_map( struct gl_1d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000726{
727 map->Order = 1;
728 map->u1 = 0.0;
729 map->u2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000730 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000731 if (map->Points) {
732 GLint i;
733 for (i=0;i<n;i++)
734 map->Points[i] = initial[i];
735 }
jtgafb833d1999-08-19 00:55:39 +0000736}
737
738
739/* Initialize a 2-D evaluator map */
Brian Paul178a1c52000-04-22 01:05:00 +0000740static void
741init_2d_map( struct gl_2d_map *map, int n, const float *initial )
jtgafb833d1999-08-19 00:55:39 +0000742{
743 map->Uorder = 1;
744 map->Vorder = 1;
745 map->u1 = 0.0;
746 map->u2 = 1.0;
747 map->v1 = 0.0;
748 map->v2 = 1.0;
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000749 map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
jtgafb833d1999-08-19 00:55:39 +0000750 if (map->Points) {
751 GLint i;
752 for (i=0;i<n;i++)
753 map->Points[i] = initial[i];
754 }
jtgafb833d1999-08-19 00:55:39 +0000755}
756
757
jtgafb833d1999-08-19 00:55:39 +0000758/*
Brian Paul4d053dd2000-01-14 04:45:47 +0000759 * Initialize the attribute groups in a GLcontext.
jtgafb833d1999-08-19 00:55:39 +0000760 */
Brian Paul178a1c52000-04-22 01:05:00 +0000761static void
762init_attrib_groups( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +0000763{
Brian Paul30f51ae2001-12-18 04:06:44 +0000764 GLuint i;
jtgafb833d1999-08-19 00:55:39 +0000765
Brian Paul4d053dd2000-01-14 04:45:47 +0000766 assert(ctx);
jtgafb833d1999-08-19 00:55:39 +0000767
Brian Paulcd1cefa2001-06-13 14:56:14 +0000768 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
769 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
770
Brian Paul539cce52000-02-03 19:40:07 +0000771 /* Constants, may be overriden by device drivers */
Brian Paul4d053dd2000-01-14 04:45:47 +0000772 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
Brian Paulcd1cefa2001-06-13 14:56:14 +0000773 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
774 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000775 ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000776 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
Brian Paul87c964d2001-11-06 15:53:00 +0000777 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
Brian Paul4d053dd2000-01-14 04:45:47 +0000778 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;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000784 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000785 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;
Brian Paulfde5e2c2001-09-15 18:02:49 +0000789 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
Brian Paul539cce52000-02-03 19:40:07 +0000790 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;
Brian Paula8644322000-11-27 18:22:13 +0000795 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
796 ctx->Const.MaxLights = MAX_LIGHTS;
jtgafb833d1999-08-19 00:55:39 +0000797
Brian Paul30f51ae2001-12-18 04:06:44 +0000798 /* Initialize matrix stacks */
799 init_matrix_stack(&ctx->ModelviewMatrixStack, MAX_MODELVIEW_STACK_DEPTH,
800 _NEW_MODELVIEW);
801 init_matrix_stack(&ctx->ProjectionMatrixStack, MAX_PROJECTION_STACK_DEPTH,
802 _NEW_PROJECTION);
803 init_matrix_stack(&ctx->ColorMatrixStack, MAX_COLOR_STACK_DEPTH,
804 _NEW_COLOR_MATRIX);
805 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
806 init_matrix_stack(&ctx->TextureMatrixStack[i], MAX_TEXTURE_STACK_DEPTH,
807 _NEW_TEXTURE_MATRIX);
808 for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
809 init_matrix_stack(&ctx->ProgramMatrixStack[i], MAX_PROGRAM_STACK_DEPTH,
810 _NEW_TRACK_MATRIX);
811 ctx->CurrentStack = &ctx->ModelviewMatrixStack;
Brian Paul4d053dd2000-01-14 04:45:47 +0000812
Brian Paul30f51ae2001-12-18 04:06:44 +0000813 /* Init combined Modelview*Projection matrix */
Keith Whitwell23caf202000-11-16 21:05:34 +0000814 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
815
Brian Paul4d053dd2000-01-14 04:45:47 +0000816 /* Accumulate buffer group */
817 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000818
Brian Paul4d053dd2000-01-14 04:45:47 +0000819 /* Color buffer group */
820 ctx->Color.IndexMask = 0xffffffff;
821 ctx->Color.ColorMask[0] = 0xff;
822 ctx->Color.ColorMask[1] = 0xff;
823 ctx->Color.ColorMask[2] = 0xff;
824 ctx->Color.ColorMask[3] = 0xff;
Brian Paul4d053dd2000-01-14 04:45:47 +0000825 ctx->Color.ClearIndex = 0;
Brian Paul74b493a2001-01-24 00:04:58 +0000826 ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000827 ctx->Color.DrawBuffer = GL_FRONT;
828 ctx->Color.AlphaEnabled = GL_FALSE;
829 ctx->Color.AlphaFunc = GL_ALWAYS;
830 ctx->Color.AlphaRef = 0;
831 ctx->Color.BlendEnabled = GL_FALSE;
832 ctx->Color.BlendSrcRGB = GL_ONE;
833 ctx->Color.BlendDstRGB = GL_ZERO;
834 ctx->Color.BlendSrcA = GL_ONE;
835 ctx->Color.BlendDstA = GL_ZERO;
836 ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
Brian Paul4d053dd2000-01-14 04:45:47 +0000837 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
838 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
839 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +0000840 ctx->Color.LogicOp = GL_COPY;
841 ctx->Color.DitherFlag = GL_TRUE;
842 ctx->Color.MultiDrawBuffer = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000843
Brian Paul4d053dd2000-01-14 04:45:47 +0000844 /* Current group */
Brian Paul86b84272001-12-14 02:50:01 +0000845 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 0.0, 0.0, 0.0, 0.0 );
846 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 0.0 );
847 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
848 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 0.0 );
849 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_FOG], 0.0, 0.0, 0.0, 0.0 );
850 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
851 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_TEX0 + i], 0.0, 0.0, 0.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000852 ctx->Current.Index = 1;
Brian Paul86b84272001-12-14 02:50:01 +0000853 ctx->Current.EdgeFlag = GL_TRUE;
854
Brian Paul4d053dd2000-01-14 04:45:47 +0000855 ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
856 ctx->Current.RasterDistance = 0.0;
857 ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
858 ctx->Current.RasterIndex = 1;
859 for (i=0; i<MAX_TEXTURE_UNITS; i++)
Brian Paul002483e2002-05-09 21:54:16 +0000860 ASSIGN_4V( ctx->Current.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 );
Brian Paul4d053dd2000-01-14 04:45:47 +0000861 ctx->Current.RasterPosValid = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000862
jtgafb833d1999-08-19 00:55:39 +0000863
Brian Paul4d053dd2000-01-14 04:45:47 +0000864 /* Depth buffer group */
865 ctx->Depth.Test = GL_FALSE;
866 ctx->Depth.Clear = 1.0;
867 ctx->Depth.Func = GL_LESS;
868 ctx->Depth.Mask = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +0000869 ctx->Depth.OcclusionTest = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000870
Brian Paul4d053dd2000-01-14 04:45:47 +0000871 /* Evaluators group */
872 ctx->Eval.Map1Color4 = GL_FALSE;
873 ctx->Eval.Map1Index = GL_FALSE;
874 ctx->Eval.Map1Normal = GL_FALSE;
875 ctx->Eval.Map1TextureCoord1 = GL_FALSE;
876 ctx->Eval.Map1TextureCoord2 = GL_FALSE;
877 ctx->Eval.Map1TextureCoord3 = GL_FALSE;
878 ctx->Eval.Map1TextureCoord4 = GL_FALSE;
879 ctx->Eval.Map1Vertex3 = GL_FALSE;
880 ctx->Eval.Map1Vertex4 = GL_FALSE;
Brian Paulbc42c192002-01-05 21:53:20 +0000881 MEMSET(ctx->Eval.Map1Attrib, 0, sizeof(ctx->Eval.Map1Attrib));
Brian Paul4d053dd2000-01-14 04:45:47 +0000882 ctx->Eval.Map2Color4 = GL_FALSE;
883 ctx->Eval.Map2Index = GL_FALSE;
884 ctx->Eval.Map2Normal = GL_FALSE;
885 ctx->Eval.Map2TextureCoord1 = GL_FALSE;
886 ctx->Eval.Map2TextureCoord2 = GL_FALSE;
887 ctx->Eval.Map2TextureCoord3 = GL_FALSE;
888 ctx->Eval.Map2TextureCoord4 = GL_FALSE;
889 ctx->Eval.Map2Vertex3 = GL_FALSE;
890 ctx->Eval.Map2Vertex4 = GL_FALSE;
Brian Paulbc42c192002-01-05 21:53:20 +0000891 MEMSET(ctx->Eval.Map2Attrib, 0, sizeof(ctx->Eval.Map2Attrib));
Brian Paul4d053dd2000-01-14 04:45:47 +0000892 ctx->Eval.AutoNormal = GL_FALSE;
893 ctx->Eval.MapGrid1un = 1;
894 ctx->Eval.MapGrid1u1 = 0.0;
895 ctx->Eval.MapGrid1u2 = 1.0;
896 ctx->Eval.MapGrid2un = 1;
897 ctx->Eval.MapGrid2vn = 1;
898 ctx->Eval.MapGrid2u1 = 0.0;
899 ctx->Eval.MapGrid2u2 = 1.0;
900 ctx->Eval.MapGrid2v1 = 0.0;
901 ctx->Eval.MapGrid2v2 = 1.0;
jtgafb833d1999-08-19 00:55:39 +0000902
Brian Paul4d053dd2000-01-14 04:45:47 +0000903 /* Evaluator data */
904 {
905 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
906 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
907 static GLfloat index[1] = { 1.0 };
908 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
909 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
Brian Paulbc42c192002-01-05 21:53:20 +0000910 static GLfloat attrib[4] = { 0.0, 0.0, 0.0, 1.0 };
jtgafb833d1999-08-19 00:55:39 +0000911
Brian Paul4d053dd2000-01-14 04:45:47 +0000912 init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
913 init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
914 init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
915 init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
916 init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
917 init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
918 init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
919 init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
920 init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
Brian Paulbc42c192002-01-05 21:53:20 +0000921 for (i = 0; i < 16; i++)
922 init_1d_map( ctx->EvalMap.Map1Attrib + i, 4, attrib );
jtgafb833d1999-08-19 00:55:39 +0000923
Brian Paul4d053dd2000-01-14 04:45:47 +0000924 init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
925 init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
926 init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
927 init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
928 init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
929 init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
930 init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
931 init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
932 init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
Brian Paulbc42c192002-01-05 21:53:20 +0000933 for (i = 0; i < 16; i++)
934 init_2d_map( ctx->EvalMap.Map2Attrib + i, 4, attrib );
Brian Paul4d053dd2000-01-14 04:45:47 +0000935 }
jtgafb833d1999-08-19 00:55:39 +0000936
Brian Paul4d053dd2000-01-14 04:45:47 +0000937 /* Fog group */
938 ctx->Fog.Enabled = GL_FALSE;
939 ctx->Fog.Mode = GL_EXP;
940 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
941 ctx->Fog.Index = 0.0;
942 ctx->Fog.Density = 1.0;
943 ctx->Fog.Start = 0.0;
944 ctx->Fog.End = 1.0;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000945 ctx->Fog.ColorSumEnabled = GL_FALSE;
946 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
jtgafb833d1999-08-19 00:55:39 +0000947
Brian Paul4d053dd2000-01-14 04:45:47 +0000948 /* Hint group */
949 ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
950 ctx->Hint.PointSmooth = GL_DONT_CARE;
951 ctx->Hint.LineSmooth = GL_DONT_CARE;
952 ctx->Hint.PolygonSmooth = GL_DONT_CARE;
953 ctx->Hint.Fog = GL_DONT_CARE;
Brian Paul1207bf02000-05-23 20:10:49 +0000954 ctx->Hint.ClipVolumeClipping = GL_DONT_CARE;
955 ctx->Hint.TextureCompression = GL_DONT_CARE;
Brian Paul3893e632001-05-21 16:41:03 +0000956 ctx->Hint.GenerateMipmap = GL_DONT_CARE;
jtgafb833d1999-08-19 00:55:39 +0000957
Brian Paul0771d152000-04-07 00:19:41 +0000958 /* Histogram group */
959 ctx->Histogram.Width = 0;
960 ctx->Histogram.Format = GL_RGBA;
961 ctx->Histogram.Sink = GL_FALSE;
Brian Paule75d2422001-02-17 18:41:01 +0000962 ctx->Histogram.RedSize = 0;
963 ctx->Histogram.GreenSize = 0;
964 ctx->Histogram.BlueSize = 0;
965 ctx->Histogram.AlphaSize = 0;
966 ctx->Histogram.LuminanceSize = 0;
Brian Paul0771d152000-04-07 00:19:41 +0000967 for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
968 ctx->Histogram.Count[i][0] = 0;
969 ctx->Histogram.Count[i][1] = 0;
970 ctx->Histogram.Count[i][2] = 0;
971 ctx->Histogram.Count[i][3] = 0;
972 }
973
974 /* Min/Max group */
975 ctx->MinMax.Format = GL_RGBA;
976 ctx->MinMax.Sink = GL_FALSE;
977 ctx->MinMax.Min[RCOMP] = 1000; ctx->MinMax.Max[RCOMP] = -1000;
978 ctx->MinMax.Min[GCOMP] = 1000; ctx->MinMax.Max[GCOMP] = -1000;
979 ctx->MinMax.Min[BCOMP] = 1000; ctx->MinMax.Max[BCOMP] = -1000;
980 ctx->MinMax.Min[ACOMP] = 1000; ctx->MinMax.Max[ACOMP] = -1000;
981
Brian Paul4d053dd2000-01-14 04:45:47 +0000982 /* Extensions */
Brian Paul69755402001-02-26 23:58:12 +0000983 _mesa_extensions_ctr( ctx );
jtgafb833d1999-08-19 00:55:39 +0000984
Brian Paul4d053dd2000-01-14 04:45:47 +0000985 /* Lighting group */
986 for (i=0;i<MAX_LIGHTS;i++) {
987 init_light( &ctx->Light.Light[i], i );
988 }
989 make_empty_list( &ctx->Light.EnabledList );
jtgafb833d1999-08-19 00:55:39 +0000990
Brian Paul4d053dd2000-01-14 04:45:47 +0000991 init_lightmodel( &ctx->Light.Model );
992 init_material( &ctx->Light.Material[0] );
993 init_material( &ctx->Light.Material[1] );
994 ctx->Light.ShadeModel = GL_SMOOTH;
995 ctx->Light.Enabled = GL_FALSE;
996 ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
997 ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
Brian Paul08836342001-03-03 20:33:27 +0000998 ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
999 GL_FRONT_AND_BACK,
1000 GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
jtgafb833d1999-08-19 00:55:39 +00001001
Brian Paul4d053dd2000-01-14 04:45:47 +00001002 ctx->Light.ColorMaterialEnabled = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001003
Brian Paul4d053dd2000-01-14 04:45:47 +00001004 /* Lighting miscellaneous */
Keith Whitwell14940c42000-11-05 18:40:57 +00001005 ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
1006 make_empty_list( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001007 for (i = 0 ; i < 10 ; i++) {
1008 struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
1009 s->shininess = -1;
1010 s->refcount = 0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001011 insert_at_tail( ctx->_ShineTabList, s );
Brian Paul4d053dd2000-01-14 04:45:47 +00001012 }
Brian Paul77d61af2000-06-28 04:20:21 +00001013
jtgafb833d1999-08-19 00:55:39 +00001014
Brian Paul4d053dd2000-01-14 04:45:47 +00001015 /* Line group */
1016 ctx->Line.SmoothFlag = GL_FALSE;
1017 ctx->Line.StippleFlag = GL_FALSE;
1018 ctx->Line.Width = 1.0;
Keith Whitwellbed4c5b2001-02-27 16:14:35 +00001019 ctx->Line._Width = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001020 ctx->Line.StipplePattern = 0xffff;
1021 ctx->Line.StippleFactor = 1;
jtgafb833d1999-08-19 00:55:39 +00001022
Brian Paul4d053dd2000-01-14 04:45:47 +00001023 /* Display List group */
1024 ctx->List.ListBase = 0;
jtgafb833d1999-08-19 00:55:39 +00001025
Brian Paul736fcbe2001-05-29 15:23:48 +00001026 /* Multisample */
1027 ctx->Multisample.Enabled = GL_FALSE;
1028 ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
1029 ctx->Multisample.SampleAlphaToOne = GL_FALSE;
1030 ctx->Multisample.SampleCoverage = GL_FALSE;
1031 ctx->Multisample.SampleCoverageValue = 1.0;
1032 ctx->Multisample.SampleCoverageInvert = GL_FALSE;
1033
Brian Paul4d053dd2000-01-14 04:45:47 +00001034 /* Pixel group */
1035 ctx->Pixel.RedBias = 0.0;
1036 ctx->Pixel.RedScale = 1.0;
1037 ctx->Pixel.GreenBias = 0.0;
1038 ctx->Pixel.GreenScale = 1.0;
1039 ctx->Pixel.BlueBias = 0.0;
1040 ctx->Pixel.BlueScale = 1.0;
1041 ctx->Pixel.AlphaBias = 0.0;
1042 ctx->Pixel.AlphaScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001043 ctx->Pixel.DepthBias = 0.0;
1044 ctx->Pixel.DepthScale = 1.0;
1045 ctx->Pixel.IndexOffset = 0;
1046 ctx->Pixel.IndexShift = 0;
1047 ctx->Pixel.ZoomX = 1.0;
1048 ctx->Pixel.ZoomY = 1.0;
1049 ctx->Pixel.MapColorFlag = GL_FALSE;
1050 ctx->Pixel.MapStencilFlag = GL_FALSE;
1051 ctx->Pixel.MapStoSsize = 1;
1052 ctx->Pixel.MapItoIsize = 1;
1053 ctx->Pixel.MapItoRsize = 1;
1054 ctx->Pixel.MapItoGsize = 1;
1055 ctx->Pixel.MapItoBsize = 1;
1056 ctx->Pixel.MapItoAsize = 1;
1057 ctx->Pixel.MapRtoRsize = 1;
1058 ctx->Pixel.MapGtoGsize = 1;
1059 ctx->Pixel.MapBtoBsize = 1;
1060 ctx->Pixel.MapAtoAsize = 1;
1061 ctx->Pixel.MapStoS[0] = 0;
1062 ctx->Pixel.MapItoI[0] = 0;
1063 ctx->Pixel.MapItoR[0] = 0.0;
1064 ctx->Pixel.MapItoG[0] = 0.0;
1065 ctx->Pixel.MapItoB[0] = 0.0;
1066 ctx->Pixel.MapItoA[0] = 0.0;
1067 ctx->Pixel.MapItoR8[0] = 0;
1068 ctx->Pixel.MapItoG8[0] = 0;
1069 ctx->Pixel.MapItoB8[0] = 0;
1070 ctx->Pixel.MapItoA8[0] = 0;
1071 ctx->Pixel.MapRtoR[0] = 0.0;
1072 ctx->Pixel.MapGtoG[0] = 0.0;
1073 ctx->Pixel.MapBtoB[0] = 0.0;
1074 ctx->Pixel.MapAtoA[0] = 0.0;
Brian Paul2b2e9252000-04-07 16:27:26 +00001075 ctx->Pixel.HistogramEnabled = GL_FALSE;
1076 ctx->Pixel.MinMaxEnabled = GL_FALSE;
1077 ctx->Pixel.PixelTextureEnabled = GL_FALSE;
1078 ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
1079 ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
Brian Paul82b02f02000-05-07 20:37:40 +00001080 ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
1081 ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
1082 ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
1083 ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
Brian Paul6c50e162000-06-30 22:11:04 +00001084 ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
1085 ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
1086 ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
1087 ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
Brian Paul4fe34b22000-04-11 15:07:48 +00001088 ctx->Pixel.ColorTableEnabled = GL_FALSE;
1089 ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
1090 ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
Brian Paul82b02f02000-05-07 20:37:40 +00001091 ctx->Pixel.Convolution1DEnabled = GL_FALSE;
1092 ctx->Pixel.Convolution2DEnabled = GL_FALSE;
1093 ctx->Pixel.Separable2DEnabled = GL_FALSE;
1094 for (i = 0; i < 3; i++) {
1095 ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
1096 ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
1097 ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
1098 ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
1099 }
Brian Paul67adba12000-12-09 20:35:54 +00001100 for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
1101 ctx->Convolution1D.Filter[i] = 0.0;
1102 ctx->Convolution2D.Filter[i] = 0.0;
1103 ctx->Separable2D.Filter[i] = 0.0;
1104 }
Brian Paul82b02f02000-05-07 20:37:40 +00001105 ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
1106 ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
jtgafb833d1999-08-19 00:55:39 +00001107
Brian Paul4d053dd2000-01-14 04:45:47 +00001108 /* Point group */
1109 ctx->Point.SmoothFlag = GL_FALSE;
1110 ctx->Point.Size = 1.0;
Brian Paul24a32622000-11-15 16:38:40 +00001111 ctx->Point._Size = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001112 ctx->Point.Params[0] = 1.0;
1113 ctx->Point.Params[1] = 0.0;
1114 ctx->Point.Params[2] = 0.0;
Keith Whitwell14940c42000-11-05 18:40:57 +00001115 ctx->Point._Attenuated = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001116 ctx->Point.MinSize = 0.0;
Brian Paul24a32622000-11-15 16:38:40 +00001117 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
Brian Paul4d053dd2000-01-14 04:45:47 +00001118 ctx->Point.Threshold = 1.0;
Brian Paul6c408b42002-05-27 17:04:52 +00001119 ctx->Point.PointSprite = GL_FALSE; /* GL_NV_point_sprite */
1120 ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite */
1121 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1122 ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_NV_point_sprite */
1123 }
jtgafb833d1999-08-19 00:55:39 +00001124
Brian Paul4d053dd2000-01-14 04:45:47 +00001125 /* Polygon group */
1126 ctx->Polygon.CullFlag = GL_FALSE;
1127 ctx->Polygon.CullFaceMode = GL_BACK;
1128 ctx->Polygon.FrontFace = GL_CCW;
Keith Whitwellcab974c2000-12-26 05:09:27 +00001129 ctx->Polygon._FrontBit = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001130 ctx->Polygon.FrontMode = GL_FILL;
1131 ctx->Polygon.BackMode = GL_FILL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001132 ctx->Polygon.SmoothFlag = GL_FALSE;
1133 ctx->Polygon.StippleFlag = GL_FALSE;
1134 ctx->Polygon.OffsetFactor = 0.0F;
1135 ctx->Polygon.OffsetUnits = 0.0F;
Brian Pauld0d7d622000-10-21 00:02:47 +00001136 ctx->Polygon.OffsetMRD = 0.0F;
Brian Paul4d053dd2000-01-14 04:45:47 +00001137 ctx->Polygon.OffsetPoint = GL_FALSE;
1138 ctx->Polygon.OffsetLine = GL_FALSE;
1139 ctx->Polygon.OffsetFill = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001140
Brian Paul4d053dd2000-01-14 04:45:47 +00001141 /* Polygon Stipple group */
1142 MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
jtgafb833d1999-08-19 00:55:39 +00001143
Brian Paul4d053dd2000-01-14 04:45:47 +00001144 /* Scissor group */
1145 ctx->Scissor.Enabled = GL_FALSE;
1146 ctx->Scissor.X = 0;
1147 ctx->Scissor.Y = 0;
1148 ctx->Scissor.Width = 0;
1149 ctx->Scissor.Height = 0;
jtgafb833d1999-08-19 00:55:39 +00001150
Brian Paul4d053dd2000-01-14 04:45:47 +00001151 /* Stencil group */
1152 ctx->Stencil.Enabled = GL_FALSE;
1153 ctx->Stencil.Function = GL_ALWAYS;
1154 ctx->Stencil.FailFunc = GL_KEEP;
1155 ctx->Stencil.ZPassFunc = GL_KEEP;
1156 ctx->Stencil.ZFailFunc = GL_KEEP;
1157 ctx->Stencil.Ref = 0;
1158 ctx->Stencil.ValueMask = STENCIL_MAX;
1159 ctx->Stencil.Clear = 0;
1160 ctx->Stencil.WriteMask = STENCIL_MAX;
jtgafb833d1999-08-19 00:55:39 +00001161
Brian Paul4d053dd2000-01-14 04:45:47 +00001162 /* Texture group */
1163 ctx->Texture.CurrentUnit = 0; /* multitexture */
Keith Whitwell14940c42000-11-05 18:40:57 +00001164 ctx->Texture._ReallyEnabled = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001165 for (i=0; i<MAX_TEXTURE_UNITS; i++)
1166 init_texture_unit( ctx, i );
Brian Paul23316032000-09-14 23:13:23 +00001167 ctx->Texture.SharedPalette = GL_FALSE;
Brian Paul4bdcfe52000-04-17 17:57:04 +00001168 _mesa_init_colortable(&ctx->Texture.Palette);
jtgafb833d1999-08-19 00:55:39 +00001169
Brian Paul4d053dd2000-01-14 04:45:47 +00001170 /* Transformation group */
1171 ctx->Transform.MatrixMode = GL_MODELVIEW;
1172 ctx->Transform.Normalize = GL_FALSE;
1173 ctx->Transform.RescaleNormals = GL_FALSE;
Brian Paul8c2f6c52001-06-26 01:32:48 +00001174 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001175 for (i=0;i<MAX_CLIP_PLANES;i++) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001176 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
1177 }
Brian Paul103bc0f2002-03-29 17:27:59 +00001178 ctx->Transform.ClipPlanesEnabled = 0;
jtgafb833d1999-08-19 00:55:39 +00001179
Brian Paul4d053dd2000-01-14 04:45:47 +00001180 /* Viewport group */
1181 ctx->Viewport.X = 0;
1182 ctx->Viewport.Y = 0;
1183 ctx->Viewport.Width = 0;
1184 ctx->Viewport.Height = 0;
1185 ctx->Viewport.Near = 0.0;
1186 ctx->Viewport.Far = 1.0;
Keith Whitwell23caf202000-11-16 21:05:34 +00001187 _math_matrix_ctr(&ctx->Viewport._WindowMap);
jtgafb833d1999-08-19 00:55:39 +00001188
1189#define Sz 10
1190#define Tz 14
Brian Paulfde5e2c2001-09-15 18:02:49 +00001191 ctx->Viewport._WindowMap.m[Sz] = 0.5F * ctx->DepthMaxF;
1192 ctx->Viewport._WindowMap.m[Tz] = 0.5F * ctx->DepthMaxF;
jtgafb833d1999-08-19 00:55:39 +00001193#undef Sz
1194#undef Tz
1195
Keith Whitwell14940c42000-11-05 18:40:57 +00001196 ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
1197 ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
jtgafb833d1999-08-19 00:55:39 +00001198
Brian Paul4d053dd2000-01-14 04:45:47 +00001199 /* Vertex arrays */
1200 ctx->Array.Vertex.Size = 4;
1201 ctx->Array.Vertex.Type = GL_FLOAT;
1202 ctx->Array.Vertex.Stride = 0;
1203 ctx->Array.Vertex.StrideB = 0;
1204 ctx->Array.Vertex.Ptr = NULL;
1205 ctx->Array.Vertex.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001206 ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001207 ctx->Array.Normal.Type = GL_FLOAT;
1208 ctx->Array.Normal.Stride = 0;
1209 ctx->Array.Normal.StrideB = 0;
1210 ctx->Array.Normal.Ptr = NULL;
1211 ctx->Array.Normal.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001212 ctx->Array.Normal.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001213 ctx->Array.Color.Size = 4;
1214 ctx->Array.Color.Type = GL_FLOAT;
1215 ctx->Array.Color.Stride = 0;
1216 ctx->Array.Color.StrideB = 0;
1217 ctx->Array.Color.Ptr = NULL;
1218 ctx->Array.Color.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001219 ctx->Array.Color.Flags = CA_CLIENT_DATA;
1220 ctx->Array.SecondaryColor.Size = 4;
1221 ctx->Array.SecondaryColor.Type = GL_FLOAT;
1222 ctx->Array.SecondaryColor.Stride = 0;
1223 ctx->Array.SecondaryColor.StrideB = 0;
1224 ctx->Array.SecondaryColor.Ptr = NULL;
1225 ctx->Array.SecondaryColor.Enabled = GL_FALSE;
1226 ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
1227 ctx->Array.FogCoord.Size = 1;
1228 ctx->Array.FogCoord.Type = GL_FLOAT;
1229 ctx->Array.FogCoord.Stride = 0;
1230 ctx->Array.FogCoord.StrideB = 0;
1231 ctx->Array.FogCoord.Ptr = NULL;
1232 ctx->Array.FogCoord.Enabled = GL_FALSE;
1233 ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001234 ctx->Array.Index.Type = GL_FLOAT;
1235 ctx->Array.Index.Stride = 0;
1236 ctx->Array.Index.StrideB = 0;
1237 ctx->Array.Index.Ptr = NULL;
1238 ctx->Array.Index.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001239 ctx->Array.Index.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001240 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1241 ctx->Array.TexCoord[i].Size = 4;
1242 ctx->Array.TexCoord[i].Type = GL_FLOAT;
1243 ctx->Array.TexCoord[i].Stride = 0;
1244 ctx->Array.TexCoord[i].StrideB = 0;
1245 ctx->Array.TexCoord[i].Ptr = NULL;
1246 ctx->Array.TexCoord[i].Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001247 ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001248 }
1249 ctx->Array.TexCoordInterleaveFactor = 1;
1250 ctx->Array.EdgeFlag.Stride = 0;
1251 ctx->Array.EdgeFlag.StrideB = 0;
1252 ctx->Array.EdgeFlag.Ptr = NULL;
1253 ctx->Array.EdgeFlag.Enabled = GL_FALSE;
Keith Whitwell51c0c712001-04-28 08:39:17 +00001254 ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
Brian Paul4d053dd2000-01-14 04:45:47 +00001255 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1256
1257 /* Pixel transfer */
1258 ctx->Pack.Alignment = 4;
1259 ctx->Pack.RowLength = 0;
1260 ctx->Pack.ImageHeight = 0;
1261 ctx->Pack.SkipPixels = 0;
1262 ctx->Pack.SkipRows = 0;
1263 ctx->Pack.SkipImages = 0;
1264 ctx->Pack.SwapBytes = GL_FALSE;
1265 ctx->Pack.LsbFirst = GL_FALSE;
1266 ctx->Unpack.Alignment = 4;
1267 ctx->Unpack.RowLength = 0;
1268 ctx->Unpack.ImageHeight = 0;
1269 ctx->Unpack.SkipPixels = 0;
1270 ctx->Unpack.SkipRows = 0;
1271 ctx->Unpack.SkipImages = 0;
1272 ctx->Unpack.SwapBytes = GL_FALSE;
1273 ctx->Unpack.LsbFirst = GL_FALSE;
1274
1275 /* Feedback */
1276 ctx->Feedback.Type = GL_2D; /* TODO: verify */
1277 ctx->Feedback.Buffer = NULL;
1278 ctx->Feedback.BufferSize = 0;
1279 ctx->Feedback.Count = 0;
1280
1281 /* Selection/picking */
1282 ctx->Select.Buffer = NULL;
1283 ctx->Select.BufferSize = 0;
1284 ctx->Select.BufferCount = 0;
1285 ctx->Select.Hits = 0;
1286 ctx->Select.NameStackDepth = 0;
1287
Brian Paul4d053dd2000-01-14 04:45:47 +00001288 /* Renderer and client attribute stacks */
1289 ctx->AttribStackDepth = 0;
1290 ctx->ClientAttribStackDepth = 0;
1291
Brian Paul13811372000-04-12 00:27:37 +00001292 /* Display list */
1293 ctx->CallDepth = 0;
1294 ctx->ExecuteFlag = GL_TRUE;
1295 ctx->CompileFlag = GL_FALSE;
1296 ctx->CurrentListPtr = NULL;
1297 ctx->CurrentBlock = NULL;
1298 ctx->CurrentListNum = 0;
1299 ctx->CurrentPos = 0;
1300
1301 /* Color tables */
Brian Paul4bdcfe52000-04-17 17:57:04 +00001302 _mesa_init_colortable(&ctx->ColorTable);
1303 _mesa_init_colortable(&ctx->ProxyColorTable);
1304 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1305 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1306 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1307 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
Brian Paul13811372000-04-12 00:27:37 +00001308
Brian Paul86b84272001-12-14 02:50:01 +00001309 /* GL_NV_vertex_program */
Brian Paul30f51ae2001-12-18 04:06:44 +00001310 ctx->VertexProgram.Current = NULL;
1311 ctx->VertexProgram.CurrentID = 0;
Brian Paul86b84272001-12-14 02:50:01 +00001312 ctx->VertexProgram.Enabled = GL_FALSE;
1313 ctx->VertexProgram.PointSizeEnabled = GL_FALSE;
1314 ctx->VertexProgram.TwoSideEnabled = GL_FALSE;
1315 for (i = 0; i < VP_NUM_PROG_REGS / 4; i++) {
1316 ctx->VertexProgram.TrackMatrix[i] = GL_NONE;
1317 ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV;
1318 }
1319
Brian Paul4d053dd2000-01-14 04:45:47 +00001320 /* Miscellaneous */
Keith Whitwella96308c2000-10-30 13:31:59 +00001321 ctx->NewState = _NEW_ALL;
Brian Paul4d053dd2000-01-14 04:45:47 +00001322 ctx->RenderMode = GL_RENDER;
Keith Whitwell14940c42000-11-05 18:40:57 +00001323 ctx->_ImageTransferState = 0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001324
Keith Whitwell1e1aac02000-11-13 20:02:56 +00001325 ctx->_NeedNormals = 0;
1326 ctx->_NeedEyeCoords = 0;
1327 ctx->_ModelViewInvScale = 1.0;
Brian Paul4d053dd2000-01-14 04:45:47 +00001328
Brian Paul4d053dd2000-01-14 04:45:47 +00001329 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
1330
1331 ctx->CatchSignals = GL_TRUE;
Brian Paul1b2ff692000-03-11 23:23:26 +00001332 ctx->OcclusionResult = GL_FALSE;
Brian Paul7e67fb42000-04-04 15:14:10 +00001333 ctx->OcclusionResultSaved = GL_FALSE;
Brian Paul4d053dd2000-01-14 04:45:47 +00001334
1335 /* For debug/development only */
1336 ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
1337 ctx->FirstTimeCurrent = GL_TRUE;
1338
1339 /* Dither disable */
1340 ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
1341 if (ctx->NoDither) {
1342 if (getenv("MESA_DEBUG")) {
1343 fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
jtgafb833d1999-08-19 00:55:39 +00001344 }
Brian Paul4d053dd2000-01-14 04:45:47 +00001345 ctx->Color.DitherFlag = GL_FALSE;
Brian Paul00037781999-12-17 14:52:35 +00001346 }
1347}
1348
1349
1350
1351
jtgafb833d1999-08-19 00:55:39 +00001352/*
1353 * Allocate the proxy textures. If we run out of memory part way through
1354 * the allocations clean up and return GL_FALSE.
1355 * Return: GL_TRUE=success, GL_FALSE=failure
1356 */
Brian Paul178a1c52000-04-22 01:05:00 +00001357static GLboolean
1358alloc_proxy_textures( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001359{
1360 GLboolean out_of_memory;
1361 GLint i;
1362
Brian Paula8523782000-11-19 23:10:25 +00001363 ctx->Texture.Proxy1D = _mesa_alloc_texture_object(NULL, 0, 1);
jtgafb833d1999-08-19 00:55:39 +00001364 if (!ctx->Texture.Proxy1D) {
1365 return GL_FALSE;
1366 }
1367
Brian Paula8523782000-11-19 23:10:25 +00001368 ctx->Texture.Proxy2D = _mesa_alloc_texture_object(NULL, 0, 2);
jtgafb833d1999-08-19 00:55:39 +00001369 if (!ctx->Texture.Proxy2D) {
Brian Paula8523782000-11-19 23:10:25 +00001370 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
jtgafb833d1999-08-19 00:55:39 +00001371 return GL_FALSE;
1372 }
1373
Brian Paula8523782000-11-19 23:10:25 +00001374 ctx->Texture.Proxy3D = _mesa_alloc_texture_object(NULL, 0, 3);
jtgafb833d1999-08-19 00:55:39 +00001375 if (!ctx->Texture.Proxy3D) {
Brian Paula8523782000-11-19 23:10:25 +00001376 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1377 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1378 return GL_FALSE;
1379 }
1380
1381 ctx->Texture.ProxyCubeMap = _mesa_alloc_texture_object(NULL, 0, 6);
1382 if (!ctx->Texture.ProxyCubeMap) {
1383 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1384 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1385 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
jtgafb833d1999-08-19 00:55:39 +00001386 return GL_FALSE;
1387 }
1388
1389 out_of_memory = GL_FALSE;
1390 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
Brian Paul021a5252000-03-27 17:54:17 +00001391 ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
1392 ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
1393 ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
Brian Paul172281d2001-07-26 20:02:10 +00001394 ctx->Texture.ProxyCubeMap->Image[i] = _mesa_alloc_texture_image();
jtgafb833d1999-08-19 00:55:39 +00001395 if (!ctx->Texture.Proxy1D->Image[i]
1396 || !ctx->Texture.Proxy2D->Image[i]
Brian Paul172281d2001-07-26 20:02:10 +00001397 || !ctx->Texture.Proxy3D->Image[i]
1398 || !ctx->Texture.ProxyCubeMap->Image[i]) {
jtgafb833d1999-08-19 00:55:39 +00001399 out_of_memory = GL_TRUE;
1400 }
1401 }
1402 if (out_of_memory) {
1403 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
1404 if (ctx->Texture.Proxy1D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001405 _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001406 }
1407 if (ctx->Texture.Proxy2D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001408 _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001409 }
1410 if (ctx->Texture.Proxy3D->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +00001411 _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
jtgafb833d1999-08-19 00:55:39 +00001412 }
Brian Paul172281d2001-07-26 20:02:10 +00001413 if (ctx->Texture.ProxyCubeMap->Image[i]) {
1414 _mesa_free_texture_image(ctx->Texture.ProxyCubeMap->Image[i]);
1415 }
jtgafb833d1999-08-19 00:55:39 +00001416 }
Brian Paula8523782000-11-19 23:10:25 +00001417 _mesa_free_texture_object(NULL, ctx->Texture.Proxy1D);
1418 _mesa_free_texture_object(NULL, ctx->Texture.Proxy2D);
1419 _mesa_free_texture_object(NULL, ctx->Texture.Proxy3D);
Brian Paul172281d2001-07-26 20:02:10 +00001420 _mesa_free_texture_object(NULL, ctx->Texture.ProxyCubeMap);
jtgafb833d1999-08-19 00:55:39 +00001421 return GL_FALSE;
1422 }
1423 else {
1424 return GL_TRUE;
1425 }
1426}
1427
1428
Keith Whitwell306d3fc2002-04-09 16:56:50 +00001429static void add_debug_flags( const char *debug )
1430{
1431#ifdef MESA_DEBUG
1432 if (strstr(debug, "varray"))
1433 MESA_VERBOSE |= VERBOSE_VARRAY;
1434
1435 if (strstr(debug, "tex"))
1436 MESA_VERBOSE |= VERBOSE_TEXTURE;
1437
1438 if (strstr(debug, "imm"))
1439 MESA_VERBOSE |= VERBOSE_IMMEDIATE;
1440
1441 if (strstr(debug, "pipe"))
1442 MESA_VERBOSE |= VERBOSE_PIPELINE;
1443
1444 if (strstr(debug, "driver"))
1445 MESA_VERBOSE |= VERBOSE_DRIVER;
1446
1447 if (strstr(debug, "state"))
1448 MESA_VERBOSE |= VERBOSE_STATE;
1449
1450 if (strstr(debug, "api"))
1451 MESA_VERBOSE |= VERBOSE_API;
1452
1453 if (strstr(debug, "list"))
1454 MESA_VERBOSE |= VERBOSE_DISPLAY_LIST;
1455
1456 if (strstr(debug, "lighting"))
1457 MESA_VERBOSE |= VERBOSE_LIGHTING;
1458
1459 /* Debug flag:
1460 */
1461 if (strstr(debug, "flush"))
1462 MESA_DEBUG_FLAGS |= DEBUG_ALWAYS_FLUSH;
1463#endif
1464}
1465
1466
jtgafb833d1999-08-19 00:55:39 +00001467/*
Brian Paul8aee2a32000-08-29 18:57:58 +00001468 * Initialize a GLcontext struct. This includes allocating all the
1469 * other structs and arrays which hang off of the context by pointers.
jtgafb833d1999-08-19 00:55:39 +00001470 */
Brian Paul178a1c52000-04-22 01:05:00 +00001471GLboolean
1472_mesa_initialize_context( GLcontext *ctx,
Brian Paulbe3602d2001-02-28 00:27:48 +00001473 const GLvisual *visual,
Brian Paul178a1c52000-04-22 01:05:00 +00001474 GLcontext *share_list,
1475 void *driver_ctx,
1476 GLboolean direct )
jtgafb833d1999-08-19 00:55:39 +00001477{
Brian Paul5fb84d22000-05-24 15:04:45 +00001478 GLuint dispatchSize;
1479
jtgafb833d1999-08-19 00:55:39 +00001480 (void) direct; /* not used */
1481
jtgafb833d1999-08-19 00:55:39 +00001482 /* misc one-time initializations */
1483 one_time_init();
1484
Brian Paulb1394fa2000-09-26 20:53:53 +00001485 /**
1486 ** OpenGL SI stuff
1487 **/
1488 if (!ctx->imports.malloc) {
1489 _mesa_InitDefaultImports(&ctx->imports, driver_ctx, NULL);
1490 }
1491 /* exports are setup by the device driver */
1492
jtgafb833d1999-08-19 00:55:39 +00001493 ctx->DriverCtx = driver_ctx;
Brian Paulb1394fa2000-09-26 20:53:53 +00001494 ctx->Visual = *visual;
Brian Paul3f02f901999-11-24 18:48:30 +00001495 ctx->DrawBuffer = NULL;
1496 ctx->ReadBuffer = NULL;
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001497
jtgafb833d1999-08-19 00:55:39 +00001498 if (share_list) {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001499 /* share state with another context */
jtgafb833d1999-08-19 00:55:39 +00001500 ctx->Shared = share_list->Shared;
1501 }
1502 else {
Brian Paul5a2f32b2001-04-25 18:21:05 +00001503 /* allocate new, unshared state */
jtgafb833d1999-08-19 00:55:39 +00001504 ctx->Shared = alloc_shared_state();
1505 if (!ctx->Shared) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001506 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001507 }
1508 }
Brian Paul9560f052000-01-31 23:11:39 +00001509 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001510 ctx->Shared->RefCount++;
Brian Paul9560f052000-01-31 23:11:39 +00001511 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +00001512
Brian Paul5a2f32b2001-04-25 18:21:05 +00001513 /* Effectively bind the default textures to all texture units */
1514 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
1515 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
1516 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
1517 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
1518
Brian Paul4d053dd2000-01-14 04:45:47 +00001519 init_attrib_groups( ctx );
1520
Brian Paulb6bcae52001-01-23 23:39:36 +00001521 if (visual->doubleBufferMode) {
jtgafb833d1999-08-19 00:55:39 +00001522 ctx->Color.DrawBuffer = GL_BACK;
1523 ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
1524 ctx->Color.DrawDestMask = BACK_LEFT_BIT;
1525 ctx->Pixel.ReadBuffer = GL_BACK;
1526 ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
1527 }
1528 else {
1529 ctx->Color.DrawBuffer = GL_FRONT;
1530 ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
1531 ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
1532 ctx->Pixel.ReadBuffer = GL_FRONT;
1533 ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
1534 }
1535
jtgafb833d1999-08-19 00:55:39 +00001536 if (!alloc_proxy_textures(ctx)) {
1537 free_shared_state(ctx, ctx->Shared);
Brian Paul4d053dd2000-01-14 04:45:47 +00001538 return GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00001539 }
jtgafb833d1999-08-19 00:55:39 +00001540
Brian Paulf59afc92000-05-23 23:23:00 +00001541 /* register the most recent extension functions with libGL */
1542 _glapi_add_entrypoint("glTbufferMask3DFX", 553);
1543 _glapi_add_entrypoint("glCompressedTexImage3DARB", 554);
1544 _glapi_add_entrypoint("glCompressedTexImage2DARB", 555);
1545 _glapi_add_entrypoint("glCompressedTexImage1DARB", 556);
1546 _glapi_add_entrypoint("glCompressedTexSubImage3DARB", 557);
1547 _glapi_add_entrypoint("glCompressedTexSubImage2DARB", 558);
1548 _glapi_add_entrypoint("glCompressedTexSubImage1DARB", 559);
1549 _glapi_add_entrypoint("glGetCompressedTexImageARB", 560);
1550
Brian Paul5fb84d22000-05-24 15:04:45 +00001551 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1552 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1553 * Mesa we do this to accomodate different versions of libGL and various
1554 * DRI drivers.
1555 */
1556 dispatchSize = MAX2(_glapi_get_dispatch_table_size(),
1557 sizeof(struct _glapi_table) / sizeof(void *));
1558
Brian Paulfbd8f211999-11-11 01:22:25 +00001559 /* setup API dispatch tables */
Brian Paul5fb84d22000-05-24 15:04:45 +00001560 ctx->Exec = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
1561 ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*));
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001562 if (!ctx->Exec || !ctx->Save) {
1563 free_shared_state(ctx, ctx->Shared);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001564 if (ctx->Exec)
Brian Paul2d8db392000-06-27 22:10:00 +00001565 FREE( ctx->Exec );
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001566 }
Brian Paul5fb84d22000-05-24 15:04:45 +00001567 _mesa_init_exec_table(ctx->Exec, dispatchSize);
1568 _mesa_init_dlist_table(ctx->Save, dispatchSize);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001569 ctx->CurrentDispatch = ctx->Exec;
jtgafb833d1999-08-19 00:55:39 +00001570
Keith Whitwellad2ac212000-11-24 10:25:05 +00001571 ctx->ExecPrefersFloat = GL_FALSE;
1572 ctx->SavePrefersFloat = GL_FALSE;
1573
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001574 /* Neutral tnl module stuff */
Gareth Hughesde6a2e02001-03-11 23:49:20 +00001575 _mesa_init_exec_vtxfmt( ctx );
Gareth Hughesd8aa0262001-03-11 18:49:11 +00001576 ctx->TnlModule.Current = NULL;
1577 ctx->TnlModule.SwapCount = 0;
1578
Brian Paulb6bcae52001-01-23 23:39:36 +00001579 /* Z buffer stuff */
1580 if (ctx->Visual.depthBits == 0) {
1581 /* Special case. Even if we don't have a depth buffer we need
1582 * good values for DepthMax for Z vertex transformation purposes
1583 * and for per-fragment fog computation.
1584 */
1585 ctx->DepthMax = 1 << 16;
1586 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1587 }
1588 else if (ctx->Visual.depthBits < 32) {
1589 ctx->DepthMax = (1 << ctx->Visual.depthBits) - 1;
1590 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1591 }
1592 else {
1593 /* Special case since shift values greater than or equal to the
1594 * number of bits in the left hand expression's type are undefined.
1595 */
1596 ctx->DepthMax = 0xffffffff;
1597 ctx->DepthMaxF = (GLfloat) ctx->DepthMax;
1598 }
Brian Paulbc920f02001-05-07 16:32:51 +00001599 ctx->MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */
Brian Paulb6bcae52001-01-23 23:39:36 +00001600
1601
Brian Paul3b18a362000-09-26 15:27:20 +00001602#if defined(MESA_TRACE)
Brian Paul9e351d52001-05-03 14:11:18 +00001603 ctx->TraceCtx = (trace_context_t *) CALLOC( sizeof(trace_context_t) );
Brian Paul45f36342000-09-05 20:28:06 +00001604#if 0
1605 /* Brian: do you want to have CreateContext fail here,
1606 or should we just trap in NewTrace (currently done)? */
1607 if (!(ctx->TraceCtx)) {
1608 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001609 FREE( ctx->Exec );
1610 FREE( ctx->Save );
1611 return GL_FALSE;
1612 }
1613#endif
1614 trInitContext(ctx->TraceCtx);
1615
1616 ctx->TraceDispatch = (struct _glapi_table *)
1617 CALLOC(dispatchSize * sizeof(void*));
1618#if 0
1619 if (!(ctx->TraceCtx)) {
1620 free_shared_state(ctx, ctx->Shared);
Brian Paul45f36342000-09-05 20:28:06 +00001621 FREE( ctx->Exec );
1622 FREE( ctx->Save );
1623 FREE( ctx->TraceCtx );
1624 return GL_FALSE;
1625 }
1626#endif
1627 trInitDispatch(ctx->TraceDispatch);
1628#endif
1629
Keith Whitwell306d3fc2002-04-09 16:56:50 +00001630
1631 if (getenv("MESA_DEBUG"))
1632 add_debug_flags(getenv("MESA_DEBUG"));
1633
1634 if (getenv("MESA_VERBOSE"))
1635 add_debug_flags(getenv("MESA_VERBOSE"));
1636
Brian Paul4d053dd2000-01-14 04:45:47 +00001637 return GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +00001638}
1639
jtgafb833d1999-08-19 00:55:39 +00001640
1641
1642/*
Brian Paul4d053dd2000-01-14 04:45:47 +00001643 * Allocate and initialize a GLcontext structure.
Brian Paulbe3602d2001-02-28 00:27:48 +00001644 * Input: visual - a GLvisual pointer (we copy the struct contents)
Brian Paul4d053dd2000-01-14 04:45:47 +00001645 * sharelist - another context to share display lists with or NULL
1646 * driver_ctx - pointer to device driver's context state struct
Brian Paulb1394fa2000-09-26 20:53:53 +00001647 * Return: pointer to a new __GLcontextRec or NULL if error.
Brian Paul4d053dd2000-01-14 04:45:47 +00001648 */
Brian Paul178a1c52000-04-22 01:05:00 +00001649GLcontext *
Brian Paulbe3602d2001-02-28 00:27:48 +00001650_mesa_create_context( const GLvisual *visual,
Brian Paulb1394fa2000-09-26 20:53:53 +00001651 GLcontext *share_list,
1652 void *driver_ctx,
1653 GLboolean direct )
Brian Paul4d053dd2000-01-14 04:45:47 +00001654{
1655 GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
1656 if (!ctx) {
1657 return NULL;
1658 }
Jouk Jansen12e875c2001-10-18 08:04:57 +00001659 ctx->Driver.CurrentExecPrimitive = 0;
Brian Paul178a1c52000-04-22 01:05:00 +00001660 if (_mesa_initialize_context(ctx, visual, share_list, driver_ctx, direct)) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001661 return ctx;
1662 }
1663 else {
1664 FREE(ctx);
1665 return NULL;
1666 }
1667}
1668
1669
1670
1671/*
1672 * Free the data associated with the given context.
1673 * But don't free() the GLcontext struct itself!
1674 */
Brian Paul178a1c52000-04-22 01:05:00 +00001675void
Brian Paulb1394fa2000-09-26 20:53:53 +00001676_mesa_free_context_data( GLcontext *ctx )
Brian Paul4d053dd2000-01-14 04:45:47 +00001677{
Brian Paul4d053dd2000-01-14 04:45:47 +00001678 struct gl_shine_tab *s, *tmps;
Brian Paul30f51ae2001-12-18 04:06:44 +00001679 GLuint i;
Brian Paul4d053dd2000-01-14 04:45:47 +00001680
1681 /* if we're destroying the current context, unbind it first */
Brian Paulb1394fa2000-09-26 20:53:53 +00001682 if (ctx == _mesa_get_current_context()) {
1683 _mesa_make_current(NULL, NULL);
Brian Paul4d053dd2000-01-14 04:45:47 +00001684 }
1685
Brian Paul30f51ae2001-12-18 04:06:44 +00001686 /*
1687 * Free transformation matrix stacks
1688 */
1689 free_matrix_stack(&ctx->ModelviewMatrixStack);
1690 free_matrix_stack(&ctx->ProjectionMatrixStack);
1691 free_matrix_stack(&ctx->ColorMatrixStack);
1692 for (i = 0; i < MAX_TEXTURE_UNITS; i++)
1693 free_matrix_stack(&ctx->TextureMatrixStack[i]);
1694 for (i = 0; i < MAX_PROGRAM_MATRICES; i++)
1695 free_matrix_stack(&ctx->ProgramMatrixStack[i]);
1696 /* combined Modelview*Projection matrix */
Brian Paulfd284452001-07-19 15:54:34 +00001697 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
1698
Brian Paul30f51ae2001-12-18 04:06:44 +00001699
1700 if (ctx->VertexProgram.Current) {
1701 ctx->VertexProgram.Current->RefCount--;
1702 if (ctx->VertexProgram.Current->RefCount <= 0)
1703 _mesa_delete_program(ctx, ctx->VertexProgram.CurrentID);
Brian Paulfd284452001-07-19 15:54:34 +00001704 }
1705
Brian Paul30f51ae2001-12-18 04:06:44 +00001706 /* Shared context state (display lists, textures, etc) */
Brian Paul9560f052000-01-31 23:11:39 +00001707 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul4d053dd2000-01-14 04:45:47 +00001708 ctx->Shared->RefCount--;
Brian Paul9560f052000-01-31 23:11:39 +00001709 assert(ctx->Shared->RefCount >= 0);
1710 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1711 if (ctx->Shared->RefCount == 0) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001712 /* free shared state */
1713 free_shared_state( ctx, ctx->Shared );
1714 }
1715
Brian Paul30f51ae2001-12-18 04:06:44 +00001716 /* Free lighting shininess exponentiation table */
Keith Whitwell14940c42000-11-05 18:40:57 +00001717 foreach_s( s, tmps, ctx->_ShineTabList ) {
Brian Paul4d053dd2000-01-14 04:45:47 +00001718 FREE( s );
1719 }
Keith Whitwell14940c42000-11-05 18:40:57 +00001720 FREE( ctx->_ShineTabList );
Brian Paul4d053dd2000-01-14 04:45:47 +00001721
1722 /* Free proxy texture objects */
Brian Paula8523782000-11-19 23:10:25 +00001723 _mesa_free_texture_object( NULL, ctx->Texture.Proxy1D );
1724 _mesa_free_texture_object( NULL, ctx->Texture.Proxy2D );
1725 _mesa_free_texture_object( NULL, ctx->Texture.Proxy3D );
Brian Paulfd284452001-07-19 15:54:34 +00001726 _mesa_free_texture_object( NULL, ctx->Texture.ProxyCubeMap );
Brian Paul4d053dd2000-01-14 04:45:47 +00001727
1728 /* Free evaluator data */
1729 if (ctx->EvalMap.Map1Vertex3.Points)
1730 FREE( ctx->EvalMap.Map1Vertex3.Points );
1731 if (ctx->EvalMap.Map1Vertex4.Points)
1732 FREE( ctx->EvalMap.Map1Vertex4.Points );
1733 if (ctx->EvalMap.Map1Index.Points)
1734 FREE( ctx->EvalMap.Map1Index.Points );
1735 if (ctx->EvalMap.Map1Color4.Points)
1736 FREE( ctx->EvalMap.Map1Color4.Points );
1737 if (ctx->EvalMap.Map1Normal.Points)
1738 FREE( ctx->EvalMap.Map1Normal.Points );
1739 if (ctx->EvalMap.Map1Texture1.Points)
1740 FREE( ctx->EvalMap.Map1Texture1.Points );
1741 if (ctx->EvalMap.Map1Texture2.Points)
1742 FREE( ctx->EvalMap.Map1Texture2.Points );
1743 if (ctx->EvalMap.Map1Texture3.Points)
1744 FREE( ctx->EvalMap.Map1Texture3.Points );
1745 if (ctx->EvalMap.Map1Texture4.Points)
1746 FREE( ctx->EvalMap.Map1Texture4.Points );
Brian Paulc4afba32002-02-05 23:21:45 +00001747 for (i = 0; i < 16; i++)
1748 FREE((ctx->EvalMap.Map1Attrib[i].Points));
Brian Paul4d053dd2000-01-14 04:45:47 +00001749
1750 if (ctx->EvalMap.Map2Vertex3.Points)
1751 FREE( ctx->EvalMap.Map2Vertex3.Points );
1752 if (ctx->EvalMap.Map2Vertex4.Points)
1753 FREE( ctx->EvalMap.Map2Vertex4.Points );
1754 if (ctx->EvalMap.Map2Index.Points)
1755 FREE( ctx->EvalMap.Map2Index.Points );
1756 if (ctx->EvalMap.Map2Color4.Points)
1757 FREE( ctx->EvalMap.Map2Color4.Points );
1758 if (ctx->EvalMap.Map2Normal.Points)
1759 FREE( ctx->EvalMap.Map2Normal.Points );
1760 if (ctx->EvalMap.Map2Texture1.Points)
1761 FREE( ctx->EvalMap.Map2Texture1.Points );
1762 if (ctx->EvalMap.Map2Texture2.Points)
1763 FREE( ctx->EvalMap.Map2Texture2.Points );
1764 if (ctx->EvalMap.Map2Texture3.Points)
1765 FREE( ctx->EvalMap.Map2Texture3.Points );
1766 if (ctx->EvalMap.Map2Texture4.Points)
1767 FREE( ctx->EvalMap.Map2Texture4.Points );
Brian Paulc4afba32002-02-05 23:21:45 +00001768 for (i = 0; i < 16; i++)
1769 FREE((ctx->EvalMap.Map2Attrib[i].Points));
Brian Paul4d053dd2000-01-14 04:45:47 +00001770
Brian Paul4bdcfe52000-04-17 17:57:04 +00001771 _mesa_free_colortable_data( &ctx->ColorTable );
1772 _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
1773 _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
1774 _mesa_free_colortable_data( &ctx->Texture.Palette );
1775
Brian Paulfd284452001-07-19 15:54:34 +00001776 _math_matrix_dtr(&ctx->Viewport._WindowMap);
1777
Brian Paul69755402001-02-26 23:58:12 +00001778 _mesa_extensions_dtr(ctx);
Brian Paul3ab6bbe2000-02-12 17:26:15 +00001779
1780 FREE(ctx->Exec);
1781 FREE(ctx->Save);
Brian Paul4d053dd2000-01-14 04:45:47 +00001782}
1783
1784
1785
1786/*
1787 * Destroy a GLcontext structure.
jtgafb833d1999-08-19 00:55:39 +00001788 */
Brian Paul178a1c52000-04-22 01:05:00 +00001789void
Brian Paulb1394fa2000-09-26 20:53:53 +00001790_mesa_destroy_context( GLcontext *ctx )
jtgafb833d1999-08-19 00:55:39 +00001791{
1792 if (ctx) {
Brian Paulb1394fa2000-09-26 20:53:53 +00001793 _mesa_free_context_data(ctx);
Brian Paulbd5cdaf1999-10-13 18:42:49 +00001794 FREE( (void *) ctx );
jtgafb833d1999-08-19 00:55:39 +00001795 }
1796}
1797
1798
1799
1800/*
jtgafb833d1999-08-19 00:55:39 +00001801 * Copy attribute groups from one context to another.
1802 * Input: src - source context
1803 * dst - destination context
1804 * mask - bitwise OR of GL_*_BIT flags
1805 */
Brian Paul178a1c52000-04-22 01:05:00 +00001806void
Brian Paulb1394fa2000-09-26 20:53:53 +00001807_mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
jtgafb833d1999-08-19 00:55:39 +00001808{
1809 if (mask & GL_ACCUM_BUFFER_BIT) {
1810 MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
1811 }
1812 if (mask & GL_COLOR_BUFFER_BIT) {
1813 MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
1814 }
1815 if (mask & GL_CURRENT_BIT) {
1816 MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
1817 }
1818 if (mask & GL_DEPTH_BUFFER_BIT) {
1819 MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
1820 }
1821 if (mask & GL_ENABLE_BIT) {
1822 /* no op */
1823 }
1824 if (mask & GL_EVAL_BIT) {
1825 MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
1826 }
1827 if (mask & GL_FOG_BIT) {
1828 MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
1829 }
1830 if (mask & GL_HINT_BIT) {
1831 MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
1832 }
1833 if (mask & GL_LIGHTING_BIT) {
1834 MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
Brian Paul00037781999-12-17 14:52:35 +00001835 /* gl_reinit_light_attrib( &dst->Light ); */
jtgafb833d1999-08-19 00:55:39 +00001836 }
1837 if (mask & GL_LINE_BIT) {
1838 MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
1839 }
1840 if (mask & GL_LIST_BIT) {
1841 MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
1842 }
1843 if (mask & GL_PIXEL_MODE_BIT) {
1844 MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
1845 }
1846 if (mask & GL_POINT_BIT) {
1847 MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
1848 }
1849 if (mask & GL_POLYGON_BIT) {
1850 MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
1851 }
1852 if (mask & GL_POLYGON_STIPPLE_BIT) {
1853 /* Use loop instead of MEMCPY due to problem with Portland Group's
1854 * C compiler. Reported by John Stone.
1855 */
1856 int i;
1857 for (i=0;i<32;i++) {
1858 dst->PolygonStipple[i] = src->PolygonStipple[i];
1859 }
1860 }
1861 if (mask & GL_SCISSOR_BIT) {
1862 MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
1863 }
1864 if (mask & GL_STENCIL_BUFFER_BIT) {
1865 MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
1866 }
1867 if (mask & GL_TEXTURE_BIT) {
1868 MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
1869 }
1870 if (mask & GL_TRANSFORM_BIT) {
1871 MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
1872 }
1873 if (mask & GL_VIEWPORT_BIT) {
1874 MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
1875 }
Keith Whitwella96308c2000-10-30 13:31:59 +00001876 /* XXX FIXME: Call callbacks?
1877 */
1878 dst->NewState = _NEW_ALL;
jtgafb833d1999-08-19 00:55:39 +00001879}
1880
1881
jtgafb833d1999-08-19 00:55:39 +00001882/*
Brian Paul00037781999-12-17 14:52:35 +00001883 * Set the current context, binding the given frame buffer to the context.
1884 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001885void
1886_mesa_make_current( GLcontext *newCtx, GLframebuffer *buffer )
Brian Paul00037781999-12-17 14:52:35 +00001887{
Brian Paulb1394fa2000-09-26 20:53:53 +00001888 _mesa_make_current2( newCtx, buffer, buffer );
Brian Paul00037781999-12-17 14:52:35 +00001889}
1890
1891
Keith Whitwell23caf202000-11-16 21:05:34 +00001892static void print_info( void )
1893{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001894 fprintf(stderr, "Mesa GL_VERSION = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001895 (char *) _mesa_GetString(GL_VERSION));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001896 fprintf(stderr, "Mesa GL_RENDERER = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001897 (char *) _mesa_GetString(GL_RENDERER));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001898 fprintf(stderr, "Mesa GL_VENDOR = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001899 (char *) _mesa_GetString(GL_VENDOR));
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001900 fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
Keith Whitwell23caf202000-11-16 21:05:34 +00001901 (char *) _mesa_GetString(GL_EXTENSIONS));
1902#if defined(THREADS)
1903 fprintf(stderr, "Mesa thread-safe: YES\n");
1904#else
1905 fprintf(stderr, "Mesa thread-safe: NO\n");
1906#endif
1907#if defined(USE_X86_ASM)
1908 fprintf(stderr, "Mesa x86-optimized: YES\n");
1909#else
1910 fprintf(stderr, "Mesa x86-optimized: NO\n");
1911#endif
davem69e4f84b42001-06-05 03:58:20 +00001912#if defined(USE_SPARC_ASM)
1913 fprintf(stderr, "Mesa sparc-optimized: YES\n");
1914#else
1915 fprintf(stderr, "Mesa sparc-optimized: NO\n");
1916#endif
Keith Whitwell23caf202000-11-16 21:05:34 +00001917}
1918
1919
Brian Paul00037781999-12-17 14:52:35 +00001920/*
1921 * Bind the given context to the given draw-buffer and read-buffer
1922 * and make it the current context for this thread.
1923 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001924void
1925_mesa_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
1926 GLframebuffer *readBuffer )
Brian Paul00037781999-12-17 14:52:35 +00001927{
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001928 if (MESA_VERBOSE)
Keith Whitwell23caf202000-11-16 21:05:34 +00001929 fprintf(stderr, "_mesa_make_current2()\n");
Brian Paul00037781999-12-17 14:52:35 +00001930
Brian Paulbe3602d2001-02-28 00:27:48 +00001931 /* Check that the context's and framebuffer's visuals are compatible.
1932 * We could do a lot more checking here but this'll catch obvious
1933 * problems.
1934 */
1935 if (newCtx && drawBuffer && readBuffer) {
1936 if (newCtx->Visual.rgbMode != drawBuffer->Visual.rgbMode ||
1937 newCtx->Visual.redBits != drawBuffer->Visual.redBits ||
1938 newCtx->Visual.depthBits != drawBuffer->Visual.depthBits ||
1939 newCtx->Visual.stencilBits != drawBuffer->Visual.stencilBits ||
1940 newCtx->Visual.accumRedBits != drawBuffer->Visual.accumRedBits) {
1941 return; /* incompatible */
1942 }
1943 }
1944
Brian Paul00037781999-12-17 14:52:35 +00001945 /* We call this function periodically (just here for now) in
1946 * order to detect when multithreading has begun.
1947 */
1948 _glapi_check_multithread();
1949
Brian Paulf9b97d92000-01-28 20:17:42 +00001950 _glapi_set_context((void *) newCtx);
Brian Paulb1394fa2000-09-26 20:53:53 +00001951 ASSERT(_mesa_get_current_context() == newCtx);
Keith Whitwell23caf202000-11-16 21:05:34 +00001952
1953
1954 if (!newCtx) {
Brian Paul00037781999-12-17 14:52:35 +00001955 _glapi_set_dispatch(NULL); /* none current */
1956 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001957 else {
1958 _glapi_set_dispatch(newCtx->CurrentDispatch);
Brian Paul00037781999-12-17 14:52:35 +00001959
Keith Whitwell23caf202000-11-16 21:05:34 +00001960 if (drawBuffer && readBuffer) {
1961 /* TODO: check if newCtx and buffer's visual match??? */
1962 newCtx->DrawBuffer = drawBuffer;
1963 newCtx->ReadBuffer = readBuffer;
1964 newCtx->NewState |= _NEW_BUFFERS;
Brian Paul08836342001-03-03 20:33:27 +00001965 /* _mesa_update_state( newCtx ); */
Brian Paul00037781999-12-17 14:52:35 +00001966 }
Keith Whitwell23caf202000-11-16 21:05:34 +00001967
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00001968 if (newCtx->Driver.MakeCurrent)
Keith Whitwell23caf202000-11-16 21:05:34 +00001969 newCtx->Driver.MakeCurrent( newCtx, drawBuffer, readBuffer );
1970
1971 /* We can use this to help debug user's problems. Tell them to set
1972 * the MESA_INFO env variable before running their app. Then the
1973 * first time each context is made current we'll print some useful
1974 * information.
1975 */
1976 if (newCtx->FirstTimeCurrent) {
1977 if (getenv("MESA_INFO")) {
1978 print_info();
1979 }
1980 newCtx->FirstTimeCurrent = GL_FALSE;
1981 }
Brian Paul00037781999-12-17 14:52:35 +00001982 }
1983}
1984
1985
1986
1987/*
1988 * Return current context handle for the calling thread.
1989 * This isn't the fastest way to get the current context.
1990 * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
1991 */
Brian Paulb1394fa2000-09-26 20:53:53 +00001992GLcontext *
1993_mesa_get_current_context( void )
Brian Paul00037781999-12-17 14:52:35 +00001994{
Brian Paulf9b97d92000-01-28 20:17:42 +00001995 return (GLcontext *) _glapi_get_context();
Brian Paul00037781999-12-17 14:52:35 +00001996}
1997
1998
1999
2000/*
Brian Paulfbd8f211999-11-11 01:22:25 +00002001 * This should be called by device drivers just before they do a
2002 * swapbuffers. Any pending rendering commands will be executed.
Brian Paul9a888bd2002-03-13 04:33:32 +00002003 * XXX we should really rename this function to _mesa_flush() or something.
jtgafb833d1999-08-19 00:55:39 +00002004 */
Brian Paulfbd8f211999-11-11 01:22:25 +00002005void
2006_mesa_swapbuffers(GLcontext *ctx)
jtgafb833d1999-08-19 00:55:39 +00002007{
Keith Whitwellcab974c2000-12-26 05:09:27 +00002008 FLUSH_VERTICES( ctx, 0 );
jtgafb833d1999-08-19 00:55:39 +00002009}
2010
2011
Brian Paul00037781999-12-17 14:52:35 +00002012
Brian Paulfbd8f211999-11-11 01:22:25 +00002013/*
2014 * Return pointer to this context's current API dispatch table.
2015 * It'll either be the immediate-mode execute dispatcher or the
2016 * display list compile dispatcher.
2017 */
2018struct _glapi_table *
2019_mesa_get_dispatch(GLcontext *ctx)
2020{
2021 return ctx->CurrentDispatch;
2022}
2023
2024
2025
jtgafb833d1999-08-19 00:55:39 +00002026/**********************************************************************/
2027/***** Miscellaneous functions *****/
2028/**********************************************************************/
2029
2030
2031/*
2032 * This function is called when the Mesa user has stumbled into a code
2033 * path which may not be implemented fully or correctly.
2034 */
Brian Paul08836342001-03-03 20:33:27 +00002035void _mesa_problem( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00002036{
2037 fprintf( stderr, "Mesa implementation error: %s\n", s );
Brian Paulbb0830d2001-04-04 13:38:51 +00002038#ifdef XF86DRI
2039 fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
2040#else
2041 fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
2042#endif
jtgafb833d1999-08-19 00:55:39 +00002043 (void) ctx;
2044}
2045
2046
2047
2048/*
2049 * This is called to inform the user that he or she has tried to do
2050 * something illogical or if there's likely a bug in their program
2051 * (like enabled depth testing without a depth buffer).
2052 */
Brian Paulb1394fa2000-09-26 20:53:53 +00002053void
2054_mesa_warning( const GLcontext *ctx, const char *s )
jtgafb833d1999-08-19 00:55:39 +00002055{
Brian Paulb1394fa2000-09-26 20:53:53 +00002056 (*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
jtgafb833d1999-08-19 00:55:39 +00002057}
2058
2059
2060
Brian Paulfa9df402000-02-02 19:16:46 +00002061/*
jtgafb833d1999-08-19 00:55:39 +00002062 * This is Mesa's error handler. Normally, all that's done is the updating
2063 * of the current error value. If Mesa is compiled with -DDEBUG or if the
2064 * environment variable "MESA_DEBUG" is defined then a real error message
2065 * is printed to stderr.
Brian Paul7eb06032000-07-14 04:13:40 +00002066 * Input: ctx - the GL context
2067 * error - the error value
2068 * where - usually the name of function where error was detected
jtgafb833d1999-08-19 00:55:39 +00002069 */
Brian Paul7eb06032000-07-14 04:13:40 +00002070void
Brian Paul08836342001-03-03 20:33:27 +00002071_mesa_error( GLcontext *ctx, GLenum error, const char *where )
jtgafb833d1999-08-19 00:55:39 +00002072{
Brian Paul7eb06032000-07-14 04:13:40 +00002073 const char *debugEnv = getenv("MESA_DEBUG");
jtgafb833d1999-08-19 00:55:39 +00002074 GLboolean debug;
2075
2076#ifdef DEBUG
Brian Paul7eb06032000-07-14 04:13:40 +00002077 if (debugEnv && strstr(debugEnv, "silent"))
jtgafb833d1999-08-19 00:55:39 +00002078 debug = GL_FALSE;
Brian Paul7eb06032000-07-14 04:13:40 +00002079 else
2080 debug = GL_TRUE;
2081#else
2082 if (debugEnv)
2083 debug = GL_TRUE;
2084 else
2085 debug = GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +00002086#endif
2087
2088 if (debug) {
Brian Paul7eb06032000-07-14 04:13:40 +00002089 const char *errstr;
jtgafb833d1999-08-19 00:55:39 +00002090 switch (error) {
2091 case GL_NO_ERROR:
Brian Paul7eb06032000-07-14 04:13:40 +00002092 errstr = "GL_NO_ERROR";
jtgafb833d1999-08-19 00:55:39 +00002093 break;
2094 case GL_INVALID_VALUE:
Brian Paul7eb06032000-07-14 04:13:40 +00002095 errstr = "GL_INVALID_VALUE";
jtgafb833d1999-08-19 00:55:39 +00002096 break;
2097 case GL_INVALID_ENUM:
Brian Paul7eb06032000-07-14 04:13:40 +00002098 errstr = "GL_INVALID_ENUM";
jtgafb833d1999-08-19 00:55:39 +00002099 break;
2100 case GL_INVALID_OPERATION:
Brian Paul7eb06032000-07-14 04:13:40 +00002101 errstr = "GL_INVALID_OPERATION";
jtgafb833d1999-08-19 00:55:39 +00002102 break;
2103 case GL_STACK_OVERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002104 errstr = "GL_STACK_OVERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002105 break;
2106 case GL_STACK_UNDERFLOW:
Brian Paul7eb06032000-07-14 04:13:40 +00002107 errstr = "GL_STACK_UNDERFLOW";
jtgafb833d1999-08-19 00:55:39 +00002108 break;
2109 case GL_OUT_OF_MEMORY:
Brian Paul7eb06032000-07-14 04:13:40 +00002110 errstr = "GL_OUT_OF_MEMORY";
jtgafb833d1999-08-19 00:55:39 +00002111 break;
Brian Paul86586aa2000-06-29 18:55:52 +00002112 case GL_TABLE_TOO_LARGE:
Brian Paul7eb06032000-07-14 04:13:40 +00002113 errstr = "GL_TABLE_TOO_LARGE";
Brian Paul86586aa2000-06-29 18:55:52 +00002114 break;
jtgafb833d1999-08-19 00:55:39 +00002115 default:
Brian Paul7eb06032000-07-14 04:13:40 +00002116 errstr = "unknown";
jtgafb833d1999-08-19 00:55:39 +00002117 break;
2118 }
Brian Paul7eb06032000-07-14 04:13:40 +00002119 fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
jtgafb833d1999-08-19 00:55:39 +00002120 }
2121
Brian Paul18a285a2002-03-16 00:53:15 +00002122 if (!ctx)
2123 return;
2124
Brian Paul7eb06032000-07-14 04:13:40 +00002125 if (ctx->ErrorValue == GL_NO_ERROR) {
jtgafb833d1999-08-19 00:55:39 +00002126 ctx->ErrorValue = error;
2127 }
2128
2129 /* Call device driver's error handler, if any. This is used on the Mac. */
2130 if (ctx->Driver.Error) {
2131 (*ctx->Driver.Error)( ctx );
2132 }
2133}
2134
2135
2136
Brian Paulfa9df402000-02-02 19:16:46 +00002137void
2138_mesa_Finish( void )
jtgafb833d1999-08-19 00:55:39 +00002139{
Brian Paulfa9df402000-02-02 19:16:46 +00002140 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002141 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002142 if (ctx->Driver.Finish) {
2143 (*ctx->Driver.Finish)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002144 }
2145}
2146
2147
2148
Brian Paulfa9df402000-02-02 19:16:46 +00002149void
2150_mesa_Flush( void )
jtgafb833d1999-08-19 00:55:39 +00002151{
Brian Paulfa9df402000-02-02 19:16:46 +00002152 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +00002153 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
Brian Paulfa9df402000-02-02 19:16:46 +00002154 if (ctx->Driver.Flush) {
2155 (*ctx->Driver.Flush)( ctx );
jtgafb833d1999-08-19 00:55:39 +00002156 }
jtgafb833d1999-08-19 00:55:39 +00002157}
Brian Paul48c6a6e2000-09-08 21:28:04 +00002158
2159
2160
Keith Whitwellcab974c2000-12-26 05:09:27 +00002161const char *_mesa_prim_name[GL_POLYGON+4] = {
Brian Paul48c6a6e2000-09-08 21:28:04 +00002162 "GL_POINTS",
2163 "GL_LINES",
2164 "GL_LINE_LOOP",
2165 "GL_LINE_STRIP",
2166 "GL_TRIANGLES",
2167 "GL_TRIANGLE_STRIP",
2168 "GL_TRIANGLE_FAN",
2169 "GL_QUADS",
2170 "GL_QUAD_STRIP",
2171 "GL_POLYGON",
Keith Whitwellcab974c2000-12-26 05:09:27 +00002172 "outside begin/end",
2173 "inside unkown primitive",
2174 "unknown state"
Brian Paul48c6a6e2000-09-08 21:28:04 +00002175};