mesa: document sRGBDecode field
[mesa.git] / src / mesa / main / context.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.3
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file context.c
28 * Mesa context/visual/framebuffer management functions.
29 * \author Brian Paul
30 */
31
32 /**
33 * \mainpage Mesa Main Module
34 *
35 * \section MainIntroduction Introduction
36 *
37 * The Mesa Main module consists of all the files in the main/ directory.
38 * Among the features of this module are:
39 * <UL>
40 * <LI> Structures to represent most GL state </LI>
41 * <LI> State set/get functions </LI>
42 * <LI> Display lists </LI>
43 * <LI> Texture unit, object and image handling </LI>
44 * <LI> Matrix and attribute stacks </LI>
45 * </UL>
46 *
47 * Other modules are responsible for API dispatch, vertex transformation,
48 * point/line/triangle setup, rasterization, vertex array caching,
49 * vertex/fragment programs/shaders, etc.
50 *
51 *
52 * \section AboutDoxygen About Doxygen
53 *
54 * If you're viewing this information as Doxygen-generated HTML you'll
55 * see the documentation index at the top of this page.
56 *
57 * The first line lists the Mesa source code modules.
58 * The second line lists the indexes available for viewing the documentation
59 * for each module.
60 *
61 * Selecting the <b>Main page</b> link will display a summary of the module
62 * (this page).
63 *
64 * Selecting <b>Data Structures</b> will list all C structures.
65 *
66 * Selecting the <b>File List</b> link will list all the source files in
67 * the module.
68 * Selecting a filename will show a list of all functions defined in that file.
69 *
70 * Selecting the <b>Data Fields</b> link will display a list of all
71 * documented structure members.
72 *
73 * Selecting the <b>Globals</b> link will display a list
74 * of all functions, structures, global variables and macros in the module.
75 *
76 */
77
78
79 #include "glheader.h"
80 #include "mfeatures.h"
81 #include "imports.h"
82 #include "accum.h"
83 #include "api_exec.h"
84 #include "arrayobj.h"
85 #include "attrib.h"
86 #include "blend.h"
87 #include "buffers.h"
88 #include "bufferobj.h"
89 #include "context.h"
90 #include "cpuinfo.h"
91 #include "debug.h"
92 #include "depth.h"
93 #include "dlist.h"
94 #include "eval.h"
95 #include "extensions.h"
96 #include "fbobject.h"
97 #include "feedback.h"
98 #include "fog.h"
99 #include "formats.h"
100 #include "framebuffer.h"
101 #include "hint.h"
102 #include "hash.h"
103 #include "light.h"
104 #include "lines.h"
105 #include "macros.h"
106 #include "matrix.h"
107 #include "multisample.h"
108 #include "pixel.h"
109 #include "pixelstore.h"
110 #include "points.h"
111 #include "polygon.h"
112 #include "queryobj.h"
113 #include "syncobj.h"
114 #include "rastpos.h"
115 #include "remap.h"
116 #include "scissor.h"
117 #include "shared.h"
118 #include "shaderobj.h"
119 #include "simple_list.h"
120 #include "state.h"
121 #include "stencil.h"
122 #include "texcompress_s3tc.h"
123 #include "texstate.h"
124 #include "transformfeedback.h"
125 #include "mtypes.h"
126 #include "varray.h"
127 #include "version.h"
128 #include "viewport.h"
129 #include "vtxfmt.h"
130 #include "program/program.h"
131 #include "program/prog_print.h"
132 #if _HAVE_FULL_GL
133 #include "math/m_matrix.h"
134 #endif
135 #include "main/dispatch.h" /* for _gloffset_COUNT */
136
137 #ifdef USE_SPARC_ASM
138 #include "sparc/sparc.h"
139 #endif
140
141 #include "glsl_parser_extras.h"
142 #include <stdbool.h>
143
144
145 #ifndef MESA_VERBOSE
146 int MESA_VERBOSE = 0;
147 #endif
148
149 #ifndef MESA_DEBUG_FLAGS
150 int MESA_DEBUG_FLAGS = 0;
151 #endif
152
153
154 /* ubyte -> float conversion */
155 GLfloat _mesa_ubyte_to_float_color_tab[256];
156
157
158
159 /**
160 * Swap buffers notification callback.
161 *
162 * \param ctx GL context.
163 *
164 * Called by window system just before swapping buffers.
165 * We have to finish any pending rendering.
166 */
167 void
168 _mesa_notifySwapBuffers(struct gl_context *ctx)
169 {
170 if (MESA_VERBOSE & VERBOSE_SWAPBUFFERS)
171 _mesa_debug(ctx, "SwapBuffers\n");
172 FLUSH_CURRENT( ctx, 0 );
173 if (ctx->Driver.Flush) {
174 ctx->Driver.Flush(ctx);
175 }
176 }
177
178
179 /**********************************************************************/
180 /** \name GL Visual allocation/destruction */
181 /**********************************************************************/
182 /*@{*/
183
184 /**
185 * Allocates a struct gl_config structure and initializes it via
186 * _mesa_initialize_visual().
187 *
188 * \param dbFlag double buffering
189 * \param stereoFlag stereo buffer
190 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
191 * is acceptable but the actual depth type will be GLushort or GLuint as
192 * needed.
193 * \param stencilBits requested minimum bits per stencil buffer value
194 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
195 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
196 * \param redBits number of bits per color component in frame buffer for RGB(A)
197 * mode. We always use 8 in core Mesa though.
198 * \param greenBits same as above.
199 * \param blueBits same as above.
200 * \param alphaBits same as above.
201 * \param numSamples not really used.
202 *
203 * \return pointer to new struct gl_config or NULL if requested parameters can't be
204 * met.
205 *
206 * \note Need to add params for level and numAuxBuffers (at least)
207 */
208 struct gl_config *
209 _mesa_create_visual( GLboolean dbFlag,
210 GLboolean stereoFlag,
211 GLint redBits,
212 GLint greenBits,
213 GLint blueBits,
214 GLint alphaBits,
215 GLint depthBits,
216 GLint stencilBits,
217 GLint accumRedBits,
218 GLint accumGreenBits,
219 GLint accumBlueBits,
220 GLint accumAlphaBits,
221 GLint numSamples )
222 {
223 struct gl_config *vis = CALLOC_STRUCT(gl_config);
224 if (vis) {
225 if (!_mesa_initialize_visual(vis, dbFlag, stereoFlag,
226 redBits, greenBits, blueBits, alphaBits,
227 depthBits, stencilBits,
228 accumRedBits, accumGreenBits,
229 accumBlueBits, accumAlphaBits,
230 numSamples)) {
231 free(vis);
232 return NULL;
233 }
234 }
235 return vis;
236 }
237
238
239 /**
240 * Makes some sanity checks and fills in the fields of the struct
241 * gl_config object with the given parameters. If the caller needs to
242 * set additional fields, he should just probably init the whole
243 * gl_config object himself.
244 *
245 * \return GL_TRUE on success, or GL_FALSE on failure.
246 *
247 * \sa _mesa_create_visual() above for the parameter description.
248 */
249 GLboolean
250 _mesa_initialize_visual( struct gl_config *vis,
251 GLboolean dbFlag,
252 GLboolean stereoFlag,
253 GLint redBits,
254 GLint greenBits,
255 GLint blueBits,
256 GLint alphaBits,
257 GLint depthBits,
258 GLint stencilBits,
259 GLint accumRedBits,
260 GLint accumGreenBits,
261 GLint accumBlueBits,
262 GLint accumAlphaBits,
263 GLint numSamples )
264 {
265 assert(vis);
266
267 if (depthBits < 0 || depthBits > 32) {
268 return GL_FALSE;
269 }
270 if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
271 return GL_FALSE;
272 }
273 assert(accumRedBits >= 0);
274 assert(accumGreenBits >= 0);
275 assert(accumBlueBits >= 0);
276 assert(accumAlphaBits >= 0);
277
278 vis->rgbMode = GL_TRUE;
279 vis->doubleBufferMode = dbFlag;
280 vis->stereoMode = stereoFlag;
281
282 vis->redBits = redBits;
283 vis->greenBits = greenBits;
284 vis->blueBits = blueBits;
285 vis->alphaBits = alphaBits;
286 vis->rgbBits = redBits + greenBits + blueBits;
287
288 vis->indexBits = 0;
289 vis->depthBits = depthBits;
290 vis->stencilBits = stencilBits;
291
292 vis->accumRedBits = accumRedBits;
293 vis->accumGreenBits = accumGreenBits;
294 vis->accumBlueBits = accumBlueBits;
295 vis->accumAlphaBits = accumAlphaBits;
296
297 vis->haveAccumBuffer = accumRedBits > 0;
298 vis->haveDepthBuffer = depthBits > 0;
299 vis->haveStencilBuffer = stencilBits > 0;
300
301 vis->numAuxBuffers = 0;
302 vis->level = 0;
303 vis->sampleBuffers = numSamples > 0 ? 1 : 0;
304 vis->samples = numSamples;
305
306 return GL_TRUE;
307 }
308
309
310 /**
311 * Destroy a visual and free its memory.
312 *
313 * \param vis visual.
314 *
315 * Frees the visual structure.
316 */
317 void
318 _mesa_destroy_visual( struct gl_config *vis )
319 {
320 free(vis);
321 }
322
323 /*@}*/
324
325
326 /**********************************************************************/
327 /** \name Context allocation, initialization, destroying
328 *
329 * The purpose of the most initialization functions here is to provide the
330 * default state values according to the OpenGL specification.
331 */
332 /**********************************************************************/
333 /*@{*/
334
335
336 /**
337 * This is lame. gdb only seems to recognize enum types that are
338 * actually used somewhere. We want to be able to print/use enum
339 * values such as TEXTURE_2D_INDEX in gdb. But we don't actually use
340 * the gl_texture_index type anywhere. Thus, this lame function.
341 */
342 static void
343 dummy_enum_func(void)
344 {
345 gl_buffer_index bi = BUFFER_FRONT_LEFT;
346 gl_face_index fi = FACE_POS_X;
347 gl_frag_attrib fa = FRAG_ATTRIB_WPOS;
348 gl_frag_result fr = FRAG_RESULT_DEPTH;
349 gl_texture_index ti = TEXTURE_2D_ARRAY_INDEX;
350 gl_vert_attrib va = VERT_ATTRIB_POS;
351 gl_vert_result vr = VERT_RESULT_HPOS;
352 gl_geom_attrib ga = GEOM_ATTRIB_POSITION;
353 gl_geom_result gr = GEOM_RESULT_POS;
354
355 (void) bi;
356 (void) fi;
357 (void) fa;
358 (void) fr;
359 (void) ti;
360 (void) va;
361 (void) vr;
362 (void) ga;
363 (void) gr;
364 }
365
366
367 /**
368 * One-time initialization mutex lock.
369 *
370 * \sa Used by one_time_init().
371 */
372 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
373
374
375
376 /**
377 * Calls all the various one-time-init functions in Mesa.
378 *
379 * While holding a global mutex lock, calls several initialization functions,
380 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
381 * defined.
382 *
383 * \sa _math_init().
384 */
385 static void
386 one_time_init( struct gl_context *ctx )
387 {
388 static GLbitfield api_init_mask = 0x0;
389
390 _glthread_LOCK_MUTEX(OneTimeLock);
391
392 /* truly one-time init */
393 if (!api_init_mask) {
394 GLuint i;
395
396 /* do some implementation tests */
397 assert( sizeof(GLbyte) == 1 );
398 assert( sizeof(GLubyte) == 1 );
399 assert( sizeof(GLshort) == 2 );
400 assert( sizeof(GLushort) == 2 );
401 assert( sizeof(GLint) == 4 );
402 assert( sizeof(GLuint) == 4 );
403
404 _mesa_get_cpu_features();
405
406 _mesa_init_sqrt_table();
407
408 /* context dependence is never a one-time thing... */
409 _mesa_init_get_hash(ctx);
410
411 for (i = 0; i < 256; i++) {
412 _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
413 }
414
415 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
416 if (MESA_VERBOSE != 0) {
417 _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
418 MESA_VERSION_STRING, __DATE__, __TIME__);
419 }
420 #endif
421
422 #ifdef DEBUG
423 _mesa_test_formats();
424 #endif
425 }
426
427 /* per-API one-time init */
428 if (!(api_init_mask & (1 << ctx->API))) {
429 /*
430 * This is fine as ES does not use the remap table, but it may not be
431 * future-proof. We cannot always initialize the remap table because
432 * when an app is linked to libGLES*, there are not enough dynamic
433 * entries.
434 */
435 if (ctx->API == API_OPENGL)
436 _mesa_init_remap_table();
437 }
438
439 api_init_mask |= 1 << ctx->API;
440
441 _glthread_UNLOCK_MUTEX(OneTimeLock);
442
443 /* Hopefully atexit() is widely available. If not, we may need some
444 * #ifdef tests here.
445 */
446 atexit(_mesa_destroy_shader_compiler);
447
448 dummy_enum_func();
449 }
450
451
452 /**
453 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
454 */
455 static void
456 _mesa_init_current(struct gl_context *ctx)
457 {
458 GLuint i;
459
460 /* Init all to (0,0,0,1) */
461 for (i = 0; i < Elements(ctx->Current.Attrib); i++) {
462 ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
463 }
464
465 /* redo special cases: */
466 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
467 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
468 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
469 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
470 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
471 ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
472 }
473
474
475 /**
476 * Init vertex/fragment/geometry program limits.
477 * Important: drivers should override these with actual limits.
478 */
479 static void
480 init_program_limits(GLenum type, struct gl_program_constants *prog)
481 {
482 prog->MaxInstructions = MAX_PROGRAM_INSTRUCTIONS;
483 prog->MaxAluInstructions = MAX_PROGRAM_INSTRUCTIONS;
484 prog->MaxTexInstructions = MAX_PROGRAM_INSTRUCTIONS;
485 prog->MaxTexIndirections = MAX_PROGRAM_INSTRUCTIONS;
486 prog->MaxTemps = MAX_PROGRAM_TEMPS;
487 prog->MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
488 prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
489 prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
490
491 switch (type) {
492 case GL_VERTEX_PROGRAM_ARB:
493 prog->MaxParameters = MAX_VERTEX_PROGRAM_PARAMS;
494 prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
495 prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
496 break;
497 case GL_FRAGMENT_PROGRAM_ARB:
498 prog->MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
499 prog->MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
500 prog->MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
501 break;
502 case MESA_GEOMETRY_PROGRAM:
503 prog->MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
504 prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
505 prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
506
507 prog->MaxGeometryTextureImageUnits = MAX_GEOMETRY_TEXTURE_IMAGE_UNITS;
508 prog->MaxGeometryVaryingComponents = MAX_GEOMETRY_VARYING_COMPONENTS;
509 prog->MaxVertexVaryingComponents = MAX_VERTEX_VARYING_COMPONENTS;
510 prog->MaxGeometryUniformComponents = MAX_GEOMETRY_UNIFORM_COMPONENTS;
511 prog->MaxGeometryOutputVertices = MAX_GEOMETRY_OUTPUT_VERTICES;
512 prog->MaxGeometryTotalOutputComponents = MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS;
513 break;
514 default:
515 assert(0 && "Bad program type in init_program_limits()");
516 }
517
518 /* Set the native limits to zero. This implies that there is no native
519 * support for shaders. Let the drivers fill in the actual values.
520 */
521 prog->MaxNativeInstructions = 0;
522 prog->MaxNativeAluInstructions = 0;
523 prog->MaxNativeTexInstructions = 0;
524 prog->MaxNativeTexIndirections = 0;
525 prog->MaxNativeAttribs = 0;
526 prog->MaxNativeTemps = 0;
527 prog->MaxNativeAddressRegs = 0;
528 prog->MaxNativeParameters = 0;
529
530 /* Set GLSL datatype range/precision info assuming IEEE float values.
531 * Drivers should override these defaults as needed.
532 */
533 prog->MediumFloat.RangeMin = 127;
534 prog->MediumFloat.RangeMax = 127;
535 prog->MediumFloat.Precision = 23;
536 prog->LowFloat = prog->HighFloat = prog->MediumFloat;
537 /* assume ints are stored as floats for now */
538 prog->LowInt = prog->MediumInt = prog->HighInt = prog->MediumFloat;
539 }
540
541
542 /**
543 * Initialize fields of gl_constants (aka ctx->Const.*).
544 * Use defaults from config.h. The device drivers will often override
545 * some of these values (such as number of texture units).
546 */
547 static void
548 _mesa_init_constants(struct gl_context *ctx)
549 {
550 assert(ctx);
551
552 /* Constants, may be overriden (usually only reduced) by device drivers */
553 ctx->Const.MaxTextureMbytes = MAX_TEXTURE_MBYTES;
554 ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
555 ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
556 ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
557 ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
558 ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
559 ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
560 ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
561 ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
562 ctx->Const.MaxTextureImageUnits);
563 ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
564 ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
565 ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
566 ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
567 ctx->Const.MinPointSize = MIN_POINT_SIZE;
568 ctx->Const.MaxPointSize = MAX_POINT_SIZE;
569 ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
570 ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
571 ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
572 ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
573 ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
574 ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
575 ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
576 ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
577 ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
578 ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
579 ctx->Const.MaxLights = MAX_LIGHTS;
580 ctx->Const.MaxShininess = 128.0;
581 ctx->Const.MaxSpotExponent = 128.0;
582 ctx->Const.MaxViewportWidth = MAX_WIDTH;
583 ctx->Const.MaxViewportHeight = MAX_HEIGHT;
584 #if FEATURE_ARB_vertex_program
585 init_program_limits(GL_VERTEX_PROGRAM_ARB, &ctx->Const.VertexProgram);
586 #endif
587 #if FEATURE_ARB_fragment_program
588 init_program_limits(GL_FRAGMENT_PROGRAM_ARB, &ctx->Const.FragmentProgram);
589 #endif
590 #if FEATURE_ARB_geometry_shader4
591 init_program_limits(MESA_GEOMETRY_PROGRAM, &ctx->Const.GeometryProgram);
592 #endif
593 ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
594 ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
595
596 /* CheckArrayBounds is overriden by drivers/x11 for X server */
597 ctx->Const.CheckArrayBounds = GL_FALSE;
598
599 /* GL_ARB_draw_buffers */
600 ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
601
602 #if FEATURE_EXT_framebuffer_object
603 ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
604 ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
605 #endif
606
607 #if FEATURE_ARB_vertex_shader
608 ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
609 ctx->Const.MaxCombinedTextureImageUnits = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
610 ctx->Const.MaxVarying = MAX_VARYING;
611 #endif
612
613 /* Shading language version */
614 if (ctx->API == API_OPENGL) {
615 ctx->Const.GLSLVersion = 120;
616 }
617 else if (ctx->API == API_OPENGLES2) {
618 ctx->Const.GLSLVersion = 100;
619 }
620 else if (ctx->API == API_OPENGLES) {
621 ctx->Const.GLSLVersion = 0; /* GLSL not supported */
622 }
623
624 /* GL_ARB_framebuffer_object */
625 ctx->Const.MaxSamples = 0;
626
627 /* GL_ARB_sync */
628 ctx->Const.MaxServerWaitTimeout = (GLuint64) ~0;
629
630 /* GL_ATI_envmap_bumpmap */
631 ctx->Const.SupportedBumpUnits = SUPPORTED_ATI_BUMP_UNITS;
632
633 /* GL_EXT_provoking_vertex */
634 ctx->Const.QuadsFollowProvokingVertexConvention = GL_TRUE;
635
636 /* GL_EXT_transform_feedback */
637 ctx->Const.MaxTransformFeedbackSeparateAttribs = MAX_FEEDBACK_ATTRIBS;
638 ctx->Const.MaxTransformFeedbackSeparateComponents = 4 * MAX_FEEDBACK_ATTRIBS;
639 ctx->Const.MaxTransformFeedbackInterleavedComponents = 4 * MAX_FEEDBACK_ATTRIBS;
640
641 /* GL 3.2: hard-coded for now: */
642 ctx->Const.ProfileMask = GL_CONTEXT_COMPATIBILITY_PROFILE_BIT;
643
644 /** GL_EXT_gpu_shader4 */
645 ctx->Const.MinProgramTexelOffset = -8;
646 ctx->Const.MaxProgramTexelOffset = 7;
647 }
648
649
650 /**
651 * Do some sanity checks on the limits/constants for the given context.
652 * Only called the first time a context is bound.
653 */
654 static void
655 check_context_limits(struct gl_context *ctx)
656 {
657 /* check that we don't exceed the size of various bitfields */
658 assert(VERT_RESULT_MAX <=
659 (8 * sizeof(ctx->VertexProgram._Current->Base.OutputsWritten)));
660 assert(FRAG_ATTRIB_MAX <=
661 (8 * sizeof(ctx->FragmentProgram._Current->Base.InputsRead)));
662
663 assert(MAX_COMBINED_TEXTURE_IMAGE_UNITS <= 8 * sizeof(GLbitfield));
664
665 /* shader-related checks */
666 assert(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
667 assert(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
668
669 assert(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
670 assert(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
671 assert(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
672 assert(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
673
674 /* Texture unit checks */
675 assert(ctx->Const.MaxTextureImageUnits > 0);
676 assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
677 assert(ctx->Const.MaxTextureCoordUnits > 0);
678 assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
679 assert(ctx->Const.MaxTextureUnits > 0);
680 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
681 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
682 assert(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
683 ctx->Const.MaxTextureCoordUnits));
684 assert(ctx->Const.MaxCombinedTextureImageUnits > 0);
685 assert(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
686 assert(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
687 /* number of coord units cannot be greater than number of image units */
688 assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
689
690
691 /* Texture size checks */
692 assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
693 assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
694 assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
695 assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
696
697 /* make sure largest texture image is <= MAX_WIDTH in size */
698 assert((1 << (ctx->Const.MaxTextureLevels - 1)) <= MAX_WIDTH);
699 assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= MAX_WIDTH);
700 assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= MAX_WIDTH);
701
702 /* Texture level checks */
703 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
704 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
705
706 /* Max texture size should be <= max viewport size (render to texture) */
707 assert((1 << (MAX_TEXTURE_LEVELS - 1)) <= MAX_WIDTH);
708
709 assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
710 assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
711
712 assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
713
714 /* if this fails, add more enum values to gl_buffer_index */
715 assert(BUFFER_COLOR0 + MAX_DRAW_BUFFERS <= BUFFER_COUNT);
716
717 /* XXX probably add more tests */
718 }
719
720
721 /**
722 * Initialize the attribute groups in a GL context.
723 *
724 * \param ctx GL context.
725 *
726 * Initializes all the attributes, calling the respective <tt>init*</tt>
727 * functions for the more complex data structures.
728 */
729 static GLboolean
730 init_attrib_groups(struct gl_context *ctx)
731 {
732 assert(ctx);
733
734 /* Constants */
735 _mesa_init_constants( ctx );
736
737 /* Extensions */
738 _mesa_init_extensions( ctx );
739
740 /* Attribute Groups */
741 _mesa_init_accum( ctx );
742 _mesa_init_attrib( ctx );
743 _mesa_init_buffer_objects( ctx );
744 _mesa_init_color( ctx );
745 _mesa_init_current( ctx );
746 _mesa_init_depth( ctx );
747 _mesa_init_debug( ctx );
748 _mesa_init_display_list( ctx );
749 _mesa_init_eval( ctx );
750 _mesa_init_fbobjects( ctx );
751 _mesa_init_feedback( ctx );
752 _mesa_init_fog( ctx );
753 _mesa_init_hint( ctx );
754 _mesa_init_line( ctx );
755 _mesa_init_lighting( ctx );
756 _mesa_init_matrix( ctx );
757 _mesa_init_multisample( ctx );
758 _mesa_init_pixel( ctx );
759 _mesa_init_pixelstore( ctx );
760 _mesa_init_point( ctx );
761 _mesa_init_polygon( ctx );
762 _mesa_init_program( ctx );
763 _mesa_init_queryobj( ctx );
764 _mesa_init_sync( ctx );
765 _mesa_init_rastpos( ctx );
766 _mesa_init_scissor( ctx );
767 _mesa_init_shader_state( ctx );
768 _mesa_init_stencil( ctx );
769 _mesa_init_transform( ctx );
770 _mesa_init_transform_feedback( ctx );
771 _mesa_init_varray( ctx );
772 _mesa_init_viewport( ctx );
773
774 if (!_mesa_init_texture( ctx ))
775 return GL_FALSE;
776
777 _mesa_init_texture_s3tc( ctx );
778
779 /* Miscellaneous */
780 ctx->NewState = _NEW_ALL;
781 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
782 ctx->varying_vp_inputs = ~0;
783
784 return GL_TRUE;
785 }
786
787
788 /**
789 * Update default objects in a GL context with respect to shared state.
790 *
791 * \param ctx GL context.
792 *
793 * Removes references to old default objects, (texture objects, program
794 * objects, etc.) and changes to reference those from the current shared
795 * state.
796 */
797 static GLboolean
798 update_default_objects(struct gl_context *ctx)
799 {
800 assert(ctx);
801
802 _mesa_update_default_objects_program(ctx);
803 _mesa_update_default_objects_texture(ctx);
804 _mesa_update_default_objects_buffer_objects(ctx);
805
806 return GL_TRUE;
807 }
808
809
810 /**
811 * This is the default function we plug into all dispatch table slots
812 * This helps prevents a segfault when someone calls a GL function without
813 * first checking if the extension's supported.
814 */
815 static int
816 generic_nop(void)
817 {
818 _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
819 return 0;
820 }
821
822
823 /**
824 * Allocate and initialize a new dispatch table.
825 */
826 struct _glapi_table *
827 _mesa_alloc_dispatch_table(int size)
828 {
829 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
830 * In practice, this'll be the same for stand-alone Mesa. But for DRI
831 * Mesa we do this to accomodate different versions of libGL and various
832 * DRI drivers.
833 */
834 GLint numEntries = MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT);
835 struct _glapi_table *table;
836
837 /* should never happen, but just in case */
838 numEntries = MAX2(numEntries, size);
839
840 table = (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
841 if (table) {
842 _glapi_proc *entry = (_glapi_proc *) table;
843 GLint i;
844 for (i = 0; i < numEntries; i++) {
845 entry[i] = (_glapi_proc) generic_nop;
846 }
847 }
848 return table;
849 }
850
851
852 /**
853 * Initialize a struct gl_context struct (rendering context).
854 *
855 * This includes allocating all the other structs and arrays which hang off of
856 * the context by pointers.
857 * Note that the driver needs to pass in its dd_function_table here since
858 * we need to at least call driverFunctions->NewTextureObject to create the
859 * default texture objects.
860 *
861 * Called by _mesa_create_context().
862 *
863 * Performs the imports and exports callback tables initialization, and
864 * miscellaneous one-time initializations. If no shared context is supplied one
865 * is allocated, and increase its reference count. Setups the GL API dispatch
866 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
867 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
868 * for debug flags.
869 *
870 * \param ctx the context to initialize
871 * \param api the GL API type to create the context for
872 * \param visual describes the visual attributes for this context
873 * \param share_list points to context to share textures, display lists,
874 * etc with, or NULL
875 * \param driverFunctions table of device driver functions for this context
876 * to use
877 * \param driverContext pointer to driver-specific context data
878 */
879 GLboolean
880 _mesa_initialize_context_for_api(struct gl_context *ctx,
881 gl_api api,
882 const struct gl_config *visual,
883 struct gl_context *share_list,
884 const struct dd_function_table *driverFunctions,
885 void *driverContext)
886 {
887 struct gl_shared_state *shared;
888 int i;
889
890 /*ASSERT(driverContext);*/
891 assert(driverFunctions->NewTextureObject);
892 assert(driverFunctions->FreeTexImageData);
893
894 ctx->API = api;
895 ctx->Visual = *visual;
896 ctx->DrawBuffer = NULL;
897 ctx->ReadBuffer = NULL;
898 ctx->WinSysDrawBuffer = NULL;
899 ctx->WinSysReadBuffer = NULL;
900
901 /* misc one-time initializations */
902 one_time_init(ctx);
903
904 /* Plug in driver functions and context pointer here.
905 * This is important because when we call alloc_shared_state() below
906 * we'll call ctx->Driver.NewTextureObject() to create the default
907 * textures.
908 */
909 ctx->Driver = *driverFunctions;
910 ctx->DriverCtx = driverContext;
911
912 if (share_list) {
913 /* share state with another context */
914 shared = share_list->Shared;
915 }
916 else {
917 /* allocate new, unshared state */
918 shared = _mesa_alloc_shared_state(ctx);
919 if (!shared)
920 return GL_FALSE;
921 }
922
923 _glthread_LOCK_MUTEX(shared->Mutex);
924 ctx->Shared = shared;
925 shared->RefCount++;
926 _glthread_UNLOCK_MUTEX(shared->Mutex);
927
928 if (!init_attrib_groups( ctx )) {
929 _mesa_release_shared_state(ctx, ctx->Shared);
930 return GL_FALSE;
931 }
932
933 #if FEATURE_dispatch
934 /* setup the API dispatch tables */
935 switch (ctx->API) {
936 #if FEATURE_GL
937 case API_OPENGL:
938 ctx->Exec = _mesa_create_exec_table();
939 break;
940 #endif
941 #if FEATURE_ES1
942 case API_OPENGLES:
943 ctx->Exec = _mesa_create_exec_table_es1();
944 break;
945 #endif
946 #if FEATURE_ES2
947 case API_OPENGLES2:
948 ctx->Exec = _mesa_create_exec_table_es2();
949 break;
950 #endif
951 default:
952 _mesa_problem(ctx, "unknown or unsupported API");
953 break;
954 }
955
956 if (!ctx->Exec) {
957 _mesa_release_shared_state(ctx, ctx->Shared);
958 return GL_FALSE;
959 }
960 #endif
961 ctx->CurrentDispatch = ctx->Exec;
962
963 ctx->FragmentProgram._MaintainTexEnvProgram
964 = (_mesa_getenv("MESA_TEX_PROG") != NULL);
965
966 ctx->VertexProgram._MaintainTnlProgram
967 = (_mesa_getenv("MESA_TNL_PROG") != NULL);
968 if (ctx->VertexProgram._MaintainTnlProgram) {
969 /* this is required... */
970 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
971 }
972
973 /* Mesa core handles all the formats that mesa core knows about.
974 * Drivers will want to override this list with just the formats
975 * they can handle, and confirm that appropriate fallbacks exist in
976 * _mesa_choose_tex_format().
977 */
978 memset(&ctx->TextureFormatSupported, GL_TRUE,
979 sizeof(ctx->TextureFormatSupported));
980
981 switch (ctx->API) {
982 case API_OPENGL:
983 #if FEATURE_dlist
984 ctx->Save = _mesa_create_save_table();
985 if (!ctx->Save) {
986 _mesa_release_shared_state(ctx, ctx->Shared);
987 free(ctx->Exec);
988 return GL_FALSE;
989 }
990
991 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
992 #endif
993 break;
994 case API_OPENGLES:
995 /**
996 * GL_OES_texture_cube_map says
997 * "Initially all texture generation modes are set to REFLECTION_MAP_OES"
998 */
999 for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
1000 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
1001 texUnit->GenS.Mode = GL_REFLECTION_MAP_NV;
1002 texUnit->GenT.Mode = GL_REFLECTION_MAP_NV;
1003 texUnit->GenR.Mode = GL_REFLECTION_MAP_NV;
1004 texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV;
1005 texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV;
1006 texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV;
1007 }
1008 break;
1009 case API_OPENGLES2:
1010 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
1011 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
1012 ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */
1013 break;
1014 }
1015
1016 ctx->FirstTimeCurrent = GL_TRUE;
1017
1018 return GL_TRUE;
1019 }
1020
1021
1022 /**
1023 * Initialize an OpenGL context.
1024 */
1025 GLboolean
1026 _mesa_initialize_context(struct gl_context *ctx,
1027 const struct gl_config *visual,
1028 struct gl_context *share_list,
1029 const struct dd_function_table *driverFunctions,
1030 void *driverContext)
1031 {
1032 return _mesa_initialize_context_for_api(ctx,
1033 API_OPENGL,
1034 visual,
1035 share_list,
1036 driverFunctions,
1037 driverContext);
1038 }
1039
1040
1041 /**
1042 * Allocate and initialize a struct gl_context structure.
1043 * Note that the driver needs to pass in its dd_function_table here since
1044 * we need to at least call driverFunctions->NewTextureObject to initialize
1045 * the rendering context.
1046 *
1047 * \param api the GL API type to create the context for
1048 * \param visual a struct gl_config pointer (we copy the struct contents)
1049 * \param share_list another context to share display lists with or NULL
1050 * \param driverFunctions points to the dd_function_table into which the
1051 * driver has plugged in all its special functions.
1052 * \param driverContext points to the device driver's private context state
1053 *
1054 * \return pointer to a new __struct gl_contextRec or NULL if error.
1055 */
1056 struct gl_context *
1057 _mesa_create_context_for_api(gl_api api,
1058 const struct gl_config *visual,
1059 struct gl_context *share_list,
1060 const struct dd_function_table *driverFunctions,
1061 void *driverContext)
1062 {
1063 struct gl_context *ctx;
1064
1065 ASSERT(visual);
1066 /*ASSERT(driverContext);*/
1067
1068 ctx = (struct gl_context *) calloc(1, sizeof(struct gl_context));
1069 if (!ctx)
1070 return NULL;
1071
1072 if (_mesa_initialize_context_for_api(ctx, api, visual, share_list,
1073 driverFunctions, driverContext)) {
1074 return ctx;
1075 }
1076 else {
1077 free(ctx);
1078 return NULL;
1079 }
1080 }
1081
1082
1083 /**
1084 * Create an OpenGL context.
1085 */
1086 struct gl_context *
1087 _mesa_create_context(const struct gl_config *visual,
1088 struct gl_context *share_list,
1089 const struct dd_function_table *driverFunctions,
1090 void *driverContext)
1091 {
1092 return _mesa_create_context_for_api(API_OPENGL, visual,
1093 share_list,
1094 driverFunctions,
1095 driverContext);
1096 }
1097
1098
1099 /**
1100 * Free the data associated with the given context.
1101 *
1102 * But doesn't free the struct gl_context struct itself.
1103 *
1104 * \sa _mesa_initialize_context() and init_attrib_groups().
1105 */
1106 void
1107 _mesa_free_context_data( struct gl_context *ctx )
1108 {
1109 if (!_mesa_get_current_context()){
1110 /* No current context, but we may need one in order to delete
1111 * texture objs, etc. So temporarily bind the context now.
1112 */
1113 _mesa_make_current(ctx, NULL, NULL);
1114 }
1115
1116 /* unreference WinSysDraw/Read buffers */
1117 _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL);
1118 _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL);
1119 _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL);
1120 _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL);
1121
1122 _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
1123 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
1124 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
1125
1126 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
1127 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
1128 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
1129
1130 _mesa_free_attrib_data(ctx);
1131 _mesa_free_buffer_objects(ctx);
1132 _mesa_free_lighting_data( ctx );
1133 _mesa_free_eval_data( ctx );
1134 _mesa_free_texture_data( ctx );
1135 _mesa_free_matrix_data( ctx );
1136 _mesa_free_viewport_data( ctx );
1137 _mesa_free_program_data(ctx);
1138 _mesa_free_shader_state(ctx);
1139 _mesa_free_queryobj_data(ctx);
1140 _mesa_free_sync_data(ctx);
1141 _mesa_free_varray_data(ctx);
1142 _mesa_free_transform_feedback(ctx);
1143
1144 _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
1145
1146 #if FEATURE_ARB_pixel_buffer_object
1147 _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj, NULL);
1148 _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj, NULL);
1149 _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj, NULL);
1150 #endif
1151
1152 #if FEATURE_ARB_vertex_buffer_object
1153 _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
1154 _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, NULL);
1155 #endif
1156
1157 /* free dispatch tables */
1158 free(ctx->Exec);
1159 free(ctx->Save);
1160
1161 /* Shared context state (display lists, textures, etc) */
1162 _mesa_release_shared_state( ctx, ctx->Shared );
1163
1164 /* needs to be after freeing shared state */
1165 _mesa_free_display_list_data(ctx);
1166
1167 if (ctx->Extensions.String)
1168 free((void *) ctx->Extensions.String);
1169
1170 if (ctx->VersionString)
1171 free(ctx->VersionString);
1172
1173 /* unbind the context if it's currently bound */
1174 if (ctx == _mesa_get_current_context()) {
1175 _mesa_make_current(NULL, NULL, NULL);
1176 }
1177 }
1178
1179
1180 /**
1181 * Destroy a struct gl_context structure.
1182 *
1183 * \param ctx GL context.
1184 *
1185 * Calls _mesa_free_context_data() and frees the gl_context object itself.
1186 */
1187 void
1188 _mesa_destroy_context( struct gl_context *ctx )
1189 {
1190 if (ctx) {
1191 _mesa_free_context_data(ctx);
1192 free( (void *) ctx );
1193 }
1194 }
1195
1196
1197 #if _HAVE_FULL_GL
1198 /**
1199 * Copy attribute groups from one context to another.
1200 *
1201 * \param src source context
1202 * \param dst destination context
1203 * \param mask bitwise OR of GL_*_BIT flags
1204 *
1205 * According to the bits specified in \p mask, copies the corresponding
1206 * attributes from \p src into \p dst. For many of the attributes a simple \c
1207 * memcpy is not enough due to the existence of internal pointers in their data
1208 * structures.
1209 */
1210 void
1211 _mesa_copy_context( const struct gl_context *src, struct gl_context *dst, GLuint mask )
1212 {
1213 if (mask & GL_ACCUM_BUFFER_BIT) {
1214 /* OK to memcpy */
1215 dst->Accum = src->Accum;
1216 }
1217 if (mask & GL_COLOR_BUFFER_BIT) {
1218 /* OK to memcpy */
1219 dst->Color = src->Color;
1220 }
1221 if (mask & GL_CURRENT_BIT) {
1222 /* OK to memcpy */
1223 dst->Current = src->Current;
1224 }
1225 if (mask & GL_DEPTH_BUFFER_BIT) {
1226 /* OK to memcpy */
1227 dst->Depth = src->Depth;
1228 }
1229 if (mask & GL_ENABLE_BIT) {
1230 /* no op */
1231 }
1232 if (mask & GL_EVAL_BIT) {
1233 /* OK to memcpy */
1234 dst->Eval = src->Eval;
1235 }
1236 if (mask & GL_FOG_BIT) {
1237 /* OK to memcpy */
1238 dst->Fog = src->Fog;
1239 }
1240 if (mask & GL_HINT_BIT) {
1241 /* OK to memcpy */
1242 dst->Hint = src->Hint;
1243 }
1244 if (mask & GL_LIGHTING_BIT) {
1245 GLuint i;
1246 /* begin with memcpy */
1247 dst->Light = src->Light;
1248 /* fixup linked lists to prevent pointer insanity */
1249 make_empty_list( &(dst->Light.EnabledList) );
1250 for (i = 0; i < MAX_LIGHTS; i++) {
1251 if (dst->Light.Light[i].Enabled) {
1252 insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
1253 }
1254 }
1255 }
1256 if (mask & GL_LINE_BIT) {
1257 /* OK to memcpy */
1258 dst->Line = src->Line;
1259 }
1260 if (mask & GL_LIST_BIT) {
1261 /* OK to memcpy */
1262 dst->List = src->List;
1263 }
1264 if (mask & GL_PIXEL_MODE_BIT) {
1265 /* OK to memcpy */
1266 dst->Pixel = src->Pixel;
1267 }
1268 if (mask & GL_POINT_BIT) {
1269 /* OK to memcpy */
1270 dst->Point = src->Point;
1271 }
1272 if (mask & GL_POLYGON_BIT) {
1273 /* OK to memcpy */
1274 dst->Polygon = src->Polygon;
1275 }
1276 if (mask & GL_POLYGON_STIPPLE_BIT) {
1277 /* Use loop instead of memcpy due to problem with Portland Group's
1278 * C compiler. Reported by John Stone.
1279 */
1280 GLuint i;
1281 for (i = 0; i < 32; i++) {
1282 dst->PolygonStipple[i] = src->PolygonStipple[i];
1283 }
1284 }
1285 if (mask & GL_SCISSOR_BIT) {
1286 /* OK to memcpy */
1287 dst->Scissor = src->Scissor;
1288 }
1289 if (mask & GL_STENCIL_BUFFER_BIT) {
1290 /* OK to memcpy */
1291 dst->Stencil = src->Stencil;
1292 }
1293 if (mask & GL_TEXTURE_BIT) {
1294 /* Cannot memcpy because of pointers */
1295 _mesa_copy_texture_state(src, dst);
1296 }
1297 if (mask & GL_TRANSFORM_BIT) {
1298 /* OK to memcpy */
1299 dst->Transform = src->Transform;
1300 }
1301 if (mask & GL_VIEWPORT_BIT) {
1302 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1303 dst->Viewport.X = src->Viewport.X;
1304 dst->Viewport.Y = src->Viewport.Y;
1305 dst->Viewport.Width = src->Viewport.Width;
1306 dst->Viewport.Height = src->Viewport.Height;
1307 dst->Viewport.Near = src->Viewport.Near;
1308 dst->Viewport.Far = src->Viewport.Far;
1309 _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
1310 }
1311
1312 /* XXX FIXME: Call callbacks?
1313 */
1314 dst->NewState = _NEW_ALL;
1315 }
1316 #endif
1317
1318
1319 /**
1320 * Check if the given context can render into the given framebuffer
1321 * by checking visual attributes.
1322 *
1323 * Most of these tests could go away because Mesa is now pretty flexible
1324 * in terms of mixing rendering contexts with framebuffers. As long
1325 * as RGB vs. CI mode agree, we're probably good.
1326 *
1327 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1328 */
1329 static GLboolean
1330 check_compatible(const struct gl_context *ctx,
1331 const struct gl_framebuffer *buffer)
1332 {
1333 const struct gl_config *ctxvis = &ctx->Visual;
1334 const struct gl_config *bufvis = &buffer->Visual;
1335
1336 if (buffer == _mesa_get_incomplete_framebuffer())
1337 return GL_TRUE;
1338
1339 #if 0
1340 /* disabling this fixes the fgl_glxgears pbuffer demo */
1341 if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
1342 return GL_FALSE;
1343 #endif
1344 if (ctxvis->stereoMode && !bufvis->stereoMode)
1345 return GL_FALSE;
1346 if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
1347 return GL_FALSE;
1348 if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
1349 return GL_FALSE;
1350 if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
1351 return GL_FALSE;
1352 if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
1353 return GL_FALSE;
1354 if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
1355 return GL_FALSE;
1356 if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
1357 return GL_FALSE;
1358 #if 0
1359 /* disabled (see bug 11161) */
1360 if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
1361 return GL_FALSE;
1362 #endif
1363 if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
1364 return GL_FALSE;
1365
1366 return GL_TRUE;
1367 }
1368
1369
1370 /**
1371 * Do one-time initialization for the given framebuffer. Specifically,
1372 * ask the driver for the window's current size and update the framebuffer
1373 * object to match.
1374 * Really, the device driver should totally take care of this.
1375 */
1376 static void
1377 initialize_framebuffer_size(struct gl_context *ctx, struct gl_framebuffer *fb)
1378 {
1379 GLuint width, height;
1380 if (ctx->Driver.GetBufferSize) {
1381 ctx->Driver.GetBufferSize(fb, &width, &height);
1382 if (ctx->Driver.ResizeBuffers)
1383 ctx->Driver.ResizeBuffers(ctx, fb, width, height);
1384 fb->Initialized = GL_TRUE;
1385 }
1386 }
1387
1388
1389 /**
1390 * Check if the viewport/scissor size has not yet been initialized.
1391 * Initialize the size if the given width and height are non-zero.
1392 */
1393 void
1394 _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height)
1395 {
1396 if (!ctx->ViewportInitialized && width > 0 && height > 0) {
1397 /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
1398 * potential infinite recursion.
1399 */
1400 ctx->ViewportInitialized = GL_TRUE;
1401 _mesa_set_viewport(ctx, 0, 0, width, height);
1402 _mesa_set_scissor(ctx, 0, 0, width, height);
1403 }
1404 }
1405
1406
1407 /**
1408 * Bind the given context to the given drawBuffer and readBuffer and
1409 * make it the current context for the calling thread.
1410 * We'll render into the drawBuffer and read pixels from the
1411 * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
1412 *
1413 * We check that the context's and framebuffer's visuals are compatible
1414 * and return immediately if they're not.
1415 *
1416 * \param newCtx the new GL context. If NULL then there will be no current GL
1417 * context.
1418 * \param drawBuffer the drawing framebuffer
1419 * \param readBuffer the reading framebuffer
1420 */
1421 GLboolean
1422 _mesa_make_current( struct gl_context *newCtx,
1423 struct gl_framebuffer *drawBuffer,
1424 struct gl_framebuffer *readBuffer )
1425 {
1426 GET_CURRENT_CONTEXT(curCtx);
1427
1428 if (MESA_VERBOSE & VERBOSE_API)
1429 _mesa_debug(newCtx, "_mesa_make_current()\n");
1430
1431 /* Check that the context's and framebuffer's visuals are compatible.
1432 */
1433 if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
1434 if (!check_compatible(newCtx, drawBuffer)) {
1435 _mesa_warning(newCtx,
1436 "MakeCurrent: incompatible visuals for context and drawbuffer");
1437 return GL_FALSE;
1438 }
1439 }
1440 if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
1441 if (!check_compatible(newCtx, readBuffer)) {
1442 _mesa_warning(newCtx,
1443 "MakeCurrent: incompatible visuals for context and readbuffer");
1444 return GL_FALSE;
1445 }
1446 }
1447
1448 if (curCtx &&
1449 (curCtx->WinSysDrawBuffer || curCtx->WinSysReadBuffer) && /* make sure this context is valid for flushing */
1450 curCtx != newCtx)
1451 _mesa_flush(curCtx);
1452
1453 /* We used to call _glapi_check_multithread() here. Now do it in drivers */
1454 _glapi_set_context((void *) newCtx);
1455 ASSERT(_mesa_get_current_context() == newCtx);
1456
1457 if (!newCtx) {
1458 _glapi_set_dispatch(NULL); /* none current */
1459 }
1460 else {
1461 _glapi_set_dispatch(newCtx->CurrentDispatch);
1462
1463 if (drawBuffer && readBuffer) {
1464 /* TODO: check if newCtx and buffer's visual match??? */
1465
1466 ASSERT(drawBuffer->Name == 0);
1467 ASSERT(readBuffer->Name == 0);
1468 _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
1469 _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
1470
1471 /*
1472 * Only set the context's Draw/ReadBuffer fields if they're NULL
1473 * or not bound to a user-created FBO.
1474 */
1475 if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
1476 /* KW: merge conflict here, revisit.
1477 */
1478 /* fix up the fb fields - these will end up wrong otherwise
1479 * if the DRIdrawable changes, and everything relies on them.
1480 * This is a bit messy (same as needed in _mesa_BindFramebufferEXT)
1481 */
1482 unsigned int i;
1483 GLenum buffers[MAX_DRAW_BUFFERS];
1484
1485 _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
1486
1487 for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) {
1488 buffers[i] = newCtx->Color.DrawBuffer[i];
1489 }
1490
1491 _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers,
1492 buffers, NULL);
1493 }
1494 if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
1495 _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
1496 }
1497
1498 /* XXX only set this flag if we're really changing the draw/read
1499 * framebuffer bindings.
1500 */
1501 newCtx->NewState |= _NEW_BUFFERS;
1502
1503 #if 1
1504 /* We want to get rid of these lines: */
1505
1506 #if _HAVE_FULL_GL
1507 if (!drawBuffer->Initialized) {
1508 initialize_framebuffer_size(newCtx, drawBuffer);
1509 }
1510 if (readBuffer != drawBuffer && !readBuffer->Initialized) {
1511 initialize_framebuffer_size(newCtx, readBuffer);
1512 }
1513
1514 _mesa_resizebuffers(newCtx);
1515 #endif
1516
1517 #else
1518 /* We want the drawBuffer and readBuffer to be initialized by
1519 * the driver.
1520 * This generally means the Width and Height match the actual
1521 * window size and the renderbuffers (both hardware and software
1522 * based) are allocated to match. The later can generally be
1523 * done with a call to _mesa_resize_framebuffer().
1524 *
1525 * It's theoretically possible for a buffer to have zero width
1526 * or height, but for now, assert check that the driver did what's
1527 * expected of it.
1528 */
1529 ASSERT(drawBuffer->Width > 0);
1530 ASSERT(drawBuffer->Height > 0);
1531 #endif
1532
1533 if (drawBuffer) {
1534 _mesa_check_init_viewport(newCtx,
1535 drawBuffer->Width, drawBuffer->Height);
1536 }
1537 }
1538
1539 if (newCtx->FirstTimeCurrent) {
1540 _mesa_compute_version(newCtx);
1541
1542 newCtx->Extensions.String = _mesa_make_extension_string(newCtx);
1543
1544 check_context_limits(newCtx);
1545
1546 /* We can use this to help debug user's problems. Tell them to set
1547 * the MESA_INFO env variable before running their app. Then the
1548 * first time each context is made current we'll print some useful
1549 * information.
1550 */
1551 if (_mesa_getenv("MESA_INFO")) {
1552 _mesa_print_info();
1553 }
1554
1555 newCtx->FirstTimeCurrent = GL_FALSE;
1556 }
1557 }
1558
1559 return GL_TRUE;
1560 }
1561
1562
1563 /**
1564 * Make context 'ctx' share the display lists, textures and programs
1565 * that are associated with 'ctxToShare'.
1566 * Any display lists, textures or programs associated with 'ctx' will
1567 * be deleted if nobody else is sharing them.
1568 */
1569 GLboolean
1570 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare)
1571 {
1572 if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
1573 struct gl_shared_state *oldSharedState = ctx->Shared;
1574
1575 ctx->Shared = ctxToShare->Shared;
1576
1577 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1578 ctx->Shared->RefCount++;
1579 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1580
1581 update_default_objects(ctx);
1582
1583 _mesa_release_shared_state(ctx, oldSharedState);
1584
1585 return GL_TRUE;
1586 }
1587 else {
1588 return GL_FALSE;
1589 }
1590 }
1591
1592
1593
1594 /**
1595 * \return pointer to the current GL context for this thread.
1596 *
1597 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1598 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in
1599 * context.h.
1600 */
1601 struct gl_context *
1602 _mesa_get_current_context( void )
1603 {
1604 return (struct gl_context *) _glapi_get_context();
1605 }
1606
1607
1608 /**
1609 * Get context's current API dispatch table.
1610 *
1611 * It'll either be the immediate-mode execute dispatcher or the display list
1612 * compile dispatcher.
1613 *
1614 * \param ctx GL context.
1615 *
1616 * \return pointer to dispatch_table.
1617 *
1618 * Simply returns __struct gl_contextRec::CurrentDispatch.
1619 */
1620 struct _glapi_table *
1621 _mesa_get_dispatch(struct gl_context *ctx)
1622 {
1623 return ctx->CurrentDispatch;
1624 }
1625
1626 /*@}*/
1627
1628
1629 /**********************************************************************/
1630 /** \name Miscellaneous functions */
1631 /**********************************************************************/
1632 /*@{*/
1633
1634 /**
1635 * Record an error.
1636 *
1637 * \param ctx GL context.
1638 * \param error error code.
1639 *
1640 * Records the given error code and call the driver's dd_function_table::Error
1641 * function if defined.
1642 *
1643 * \sa
1644 * This is called via _mesa_error().
1645 */
1646 void
1647 _mesa_record_error(struct gl_context *ctx, GLenum error)
1648 {
1649 if (!ctx)
1650 return;
1651
1652 if (ctx->ErrorValue == GL_NO_ERROR) {
1653 ctx->ErrorValue = error;
1654 }
1655
1656 /* Call device driver's error handler, if any. This is used on the Mac. */
1657 if (ctx->Driver.Error) {
1658 ctx->Driver.Error(ctx);
1659 }
1660 }
1661
1662
1663 /**
1664 * Flush commands and wait for completion.
1665 */
1666 void
1667 _mesa_finish(struct gl_context *ctx)
1668 {
1669 FLUSH_CURRENT( ctx, 0 );
1670 if (ctx->Driver.Finish) {
1671 ctx->Driver.Finish(ctx);
1672 }
1673 }
1674
1675
1676 /**
1677 * Flush commands.
1678 */
1679 void
1680 _mesa_flush(struct gl_context *ctx)
1681 {
1682 FLUSH_CURRENT( ctx, 0 );
1683 if (ctx->Driver.Flush) {
1684 ctx->Driver.Flush(ctx);
1685 }
1686 }
1687
1688
1689
1690 /**
1691 * Execute glFinish().
1692 *
1693 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1694 * dd_function_table::Finish driver callback, if not NULL.
1695 */
1696 void GLAPIENTRY
1697 _mesa_Finish(void)
1698 {
1699 GET_CURRENT_CONTEXT(ctx);
1700 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1701 _mesa_finish(ctx);
1702 }
1703
1704
1705 /**
1706 * Execute glFlush().
1707 *
1708 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1709 * dd_function_table::Flush driver callback, if not NULL.
1710 */
1711 void GLAPIENTRY
1712 _mesa_Flush(void)
1713 {
1714 GET_CURRENT_CONTEXT(ctx);
1715 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1716 _mesa_flush(ctx);
1717 }
1718
1719
1720 /**
1721 * Set mvp_with_dp4 flag. If a driver has a preference for DP4 over
1722 * MUL/MAD, or vice versa, call this function to register that.
1723 * Otherwise we default to MUL/MAD.
1724 */
1725 void
1726 _mesa_set_mvp_with_dp4( struct gl_context *ctx,
1727 GLboolean flag )
1728 {
1729 ctx->mvp_with_dp4 = flag;
1730 }
1731
1732
1733
1734 /**
1735 * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
1736 * is called to see if it's valid to render. This involves checking that
1737 * the current shader is valid and the framebuffer is complete.
1738 * If an error is detected it'll be recorded here.
1739 * \return GL_TRUE if OK to render, GL_FALSE if not
1740 */
1741 GLboolean
1742 _mesa_valid_to_render(struct gl_context *ctx, const char *where)
1743 {
1744 bool vert_from_glsl_shader = false;
1745 bool geom_from_glsl_shader = false;
1746 bool frag_from_glsl_shader = false;
1747
1748 /* This depends on having up to date derived state (shaders) */
1749 if (ctx->NewState)
1750 _mesa_update_state(ctx);
1751
1752 if (ctx->Shader.CurrentVertexProgram) {
1753 vert_from_glsl_shader = true;
1754
1755 if (!ctx->Shader.CurrentVertexProgram->LinkStatus) {
1756 _mesa_error(ctx, GL_INVALID_OPERATION,
1757 "%s(shader not linked)", where);
1758 return GL_FALSE;
1759 }
1760 #if 0 /* not normally enabled */
1761 {
1762 char errMsg[100];
1763 if (!_mesa_validate_shader_program(ctx,
1764 ctx->Shader.CurrentVertexProgram,
1765 errMsg)) {
1766 _mesa_warning(ctx, "Shader program %u is invalid: %s",
1767 ctx->Shader.CurrentVertexProgram->Name, errMsg);
1768 }
1769 }
1770 #endif
1771 }
1772
1773 if (ctx->Shader.CurrentGeometryProgram) {
1774 geom_from_glsl_shader = true;
1775
1776 if (!ctx->Shader.CurrentGeometryProgram->LinkStatus) {
1777 _mesa_error(ctx, GL_INVALID_OPERATION,
1778 "%s(shader not linked)", where);
1779 return GL_FALSE;
1780 }
1781 #if 0 /* not normally enabled */
1782 {
1783 char errMsg[100];
1784 if (!_mesa_validate_shader_program(ctx,
1785 ctx->Shader.CurrentGeometryProgram,
1786 errMsg)) {
1787 _mesa_warning(ctx, "Shader program %u is invalid: %s",
1788 ctx->Shader.CurrentGeometryProgram->Name, errMsg);
1789 }
1790 }
1791 #endif
1792 }
1793
1794 if (ctx->Shader.CurrentFragmentProgram) {
1795 frag_from_glsl_shader = true;
1796
1797 if (!ctx->Shader.CurrentFragmentProgram->LinkStatus) {
1798 _mesa_error(ctx, GL_INVALID_OPERATION,
1799 "%s(shader not linked)", where);
1800 return GL_FALSE;
1801 }
1802 #if 0 /* not normally enabled */
1803 {
1804 char errMsg[100];
1805 if (!_mesa_validate_shader_program(ctx,
1806 ctx->Shader.CurrentFragmentProgram,
1807 errMsg)) {
1808 _mesa_warning(ctx, "Shader program %u is invalid: %s",
1809 ctx->Shader.CurrentFragmentProgram->Name, errMsg);
1810 }
1811 }
1812 #endif
1813 }
1814
1815 /* Any shader stages that are not supplied by the GLSL shader and have
1816 * assembly shaders enabled must now be validated.
1817 */
1818 if (!vert_from_glsl_shader
1819 && ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) {
1820 _mesa_error(ctx, GL_INVALID_OPERATION,
1821 "%s(vertex program not valid)", where);
1822 return GL_FALSE;
1823 }
1824
1825 /* FINISHME: If GL_NV_geometry_program4 is ever supported, the current
1826 * FINISHME: geometry program should validated here.
1827 */
1828 (void) geom_from_glsl_shader;
1829
1830 if (!frag_from_glsl_shader) {
1831 if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
1832 _mesa_error(ctx, GL_INVALID_OPERATION,
1833 "%s(fragment program not valid)", where);
1834 return GL_FALSE;
1835 }
1836
1837 /* If drawing to integer-valued color buffers, there must be an
1838 * active fragment shader (GL_EXT_texture_integer).
1839 */
1840 if (ctx->DrawBuffer && ctx->DrawBuffer->_IntegerColor) {
1841 _mesa_error(ctx, GL_INVALID_OPERATION,
1842 "%s(integer format but no fragment shader)", where);
1843 return GL_FALSE;
1844 }
1845 }
1846
1847 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
1848 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
1849 "%s(incomplete framebuffer)", where);
1850 return GL_FALSE;
1851 }
1852
1853 #ifdef DEBUG
1854 if (ctx->Shader.Flags & GLSL_LOG) {
1855 struct gl_shader_program *shProg[MESA_SHADER_TYPES];
1856 gl_shader_type i;
1857
1858 shProg[MESA_SHADER_VERTEX] = ctx->Shader.CurrentVertexProgram;
1859 shProg[MESA_SHADER_GEOMETRY] = ctx->Shader.CurrentGeometryProgram;
1860 shProg[MESA_SHADER_FRAGMENT] = ctx->Shader.CurrentFragmentProgram;
1861
1862 for (i = 0; i < MESA_SHADER_TYPES; i++) {
1863 struct gl_shader *sh;
1864
1865 if (shProg[i] == NULL || shProg[i]->_Used
1866 || shProg[i]->_LinkedShaders[i] == NULL)
1867 continue;
1868
1869 /* This is the first time this shader is being used.
1870 * Append shader's constants/uniforms to log file.
1871 *
1872 * The logic is a little odd here. We only want to log data for each
1873 * shader target that will actually be used, and we only want to log
1874 * it once. It's possible to have a program bound to the vertex
1875 * shader target that also supplied a fragment shader. If that
1876 * program isn't also bound to the fragment shader target we don't
1877 * want to log its fragment data.
1878 */
1879 sh = shProg[i]->_LinkedShaders[i];
1880 switch (sh->Type) {
1881 case GL_VERTEX_SHADER:
1882 _mesa_append_uniforms_to_file(sh, &shProg[i]->VertexProgram->Base);
1883 break;
1884
1885 case GL_GEOMETRY_SHADER_ARB:
1886 _mesa_append_uniforms_to_file(sh,
1887 &shProg[i]->GeometryProgram->Base);
1888 break;
1889
1890 case GL_FRAGMENT_SHADER:
1891 _mesa_append_uniforms_to_file(sh,
1892 &shProg[i]->FragmentProgram->Base);
1893 break;
1894 }
1895 }
1896
1897 for (i = 0; i < MESA_SHADER_TYPES; i++) {
1898 if (shProg[i] != NULL)
1899 shProg[i]->_Used = GL_TRUE;
1900 }
1901 }
1902 #endif
1903
1904 return GL_TRUE;
1905 }
1906
1907
1908 /*@}*/