context.c revision 1463c08d
1/*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5 * Copyright (C) 2008  VMware, Inc.  All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * 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
81#include "accum.h"
82#include "api_exec.h"
83#include "arrayobj.h"
84#include "attrib.h"
85#include "bbox.h"
86#include "blend.h"
87#include "buffers.h"
88#include "bufferobj.h"
89#include "conservativeraster.h"
90#include "context.h"
91#include "cpuinfo.h"
92#include "debug.h"
93#include "debug_output.h"
94#include "depth.h"
95#include "dlist.h"
96#include "draw_validate.h"
97#include "eval.h"
98#include "extensions.h"
99#include "fbobject.h"
100#include "feedback.h"
101#include "fog.h"
102#include "formats.h"
103#include "framebuffer.h"
104#include "glthread.h"
105#include "hint.h"
106#include "hash.h"
107#include "light.h"
108#include "lines.h"
109#include "macros.h"
110#include "matrix.h"
111#include "multisample.h"
112#include "performance_monitor.h"
113#include "performance_query.h"
114#include "pipelineobj.h"
115#include "pixel.h"
116#include "pixelstore.h"
117#include "points.h"
118#include "polygon.h"
119#include "queryobj.h"
120#include "syncobj.h"
121#include "rastpos.h"
122#include "remap.h"
123#include "scissor.h"
124#include "shared.h"
125#include "shaderobj.h"
126#include "shaderimage.h"
127#include "state.h"
128#include "util/debug.h"
129#include "util/disk_cache.h"
130#include "util/strtod.h"
131#include "stencil.h"
132#include "shaderimage.h"
133#include "texcompress_s3tc.h"
134#include "texstate.h"
135#include "transformfeedback.h"
136#include "mtypes.h"
137#include "varray.h"
138#include "version.h"
139#include "viewport.h"
140#include "texturebindless.h"
141#include "program/program.h"
142#include "math/m_matrix.h"
143#include "main/dispatch.h" /* for _gloffset_COUNT */
144#include "macros.h"
145#include "git_sha1.h"
146
147#ifdef USE_SPARC_ASM
148#include "sparc/sparc.h"
149#endif
150
151#include "compiler/glsl_types.h"
152#include "compiler/glsl/builtin_functions.h"
153#include "compiler/glsl/glsl_parser_extras.h"
154#include <stdbool.h>
155#include "util/u_memory.h"
156
157
158#ifndef MESA_VERBOSE
159int MESA_VERBOSE = 0;
160#endif
161
162#ifndef MESA_DEBUG_FLAGS
163int MESA_DEBUG_FLAGS = 0;
164#endif
165
166
167/* ubyte -> float conversion */
168GLfloat _mesa_ubyte_to_float_color_tab[256];
169
170
171/**********************************************************************/
172/** \name GL Visual initialization                                    */
173/**********************************************************************/
174/*@{*/
175
176
177/**
178 * Makes some sanity checks and fills in the fields of the struct
179 * gl_config object with the given parameters.  If the caller needs to
180 * set additional fields, he should just probably init the whole
181 * gl_config object himself.
182 *
183 * \param dbFlag double buffering
184 * \param stereoFlag stereo buffer
185 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
186 * is acceptable but the actual depth type will be GLushort or GLuint as
187 * needed.
188 * \param stencilBits requested minimum bits per stencil buffer value
189 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number
190 * of bits per color component in accum buffer.
191 * \param redBits number of bits per color component in frame buffer for RGB(A)
192 * mode.  We always use 8 in core Mesa though.
193 * \param greenBits same as above.
194 * \param blueBits same as above.
195 * \param alphaBits same as above.
196 * \param numSamples number of samples per pixel.
197 *
198 * \return pointer to new struct gl_config or NULL if requested parameters
199 * can't be met.
200 *
201 * \return GL_TRUE on success, or GL_FALSE on failure.
202 */
203void
204_mesa_initialize_visual( struct gl_config *vis,
205                         GLboolean dbFlag,
206                         GLboolean stereoFlag,
207                         GLint redBits,
208                         GLint greenBits,
209                         GLint blueBits,
210                         GLint alphaBits,
211                         GLint depthBits,
212                         GLint stencilBits,
213                         GLint accumRedBits,
214                         GLint accumGreenBits,
215                         GLint accumBlueBits,
216                         GLint accumAlphaBits,
217                         GLuint numSamples )
218{
219   assert(vis);
220
221   vis->doubleBufferMode = dbFlag;
222   vis->stereoMode       = stereoFlag;
223
224   vis->redBits          = redBits;
225   vis->greenBits        = greenBits;
226   vis->blueBits         = blueBits;
227   vis->alphaBits        = alphaBits;
228   vis->rgbBits          = redBits + greenBits + blueBits + alphaBits;
229
230   vis->depthBits      = depthBits;
231   vis->stencilBits    = stencilBits;
232
233   vis->accumRedBits   = accumRedBits;
234   vis->accumGreenBits = accumGreenBits;
235   vis->accumBlueBits  = accumBlueBits;
236   vis->accumAlphaBits = accumAlphaBits;
237
238   vis->samples = numSamples;
239}
240
241
242/*@}*/
243
244
245/**********************************************************************/
246/** \name Context allocation, initialization, destroying
247 *
248 * The purpose of the most initialization functions here is to provide the
249 * default state values according to the OpenGL specification.
250 */
251/**********************************************************************/
252/*@{*/
253
254
255/**
256 * Calls all the various one-time-fini functions in Mesa
257 */
258
259static GLbitfield api_init_mask = 0x0;
260static void __attribute__((__destructor__))
261one_time_fini(void)
262{
263   if (api_init_mask) {
264      glsl_type_singleton_decref();
265      _mesa_locale_fini();
266   }
267}
268
269/**
270 * Calls all the various one-time-init functions in Mesa
271 */
272
273static void
274one_time_init(void)
275{
276   GLuint i;
277
278   STATIC_ASSERT(sizeof(GLbyte) == 1);
279   STATIC_ASSERT(sizeof(GLubyte) == 1);
280   STATIC_ASSERT(sizeof(GLshort) == 2);
281   STATIC_ASSERT(sizeof(GLushort) == 2);
282   STATIC_ASSERT(sizeof(GLint) == 4);
283   STATIC_ASSERT(sizeof(GLuint) == 4);
284
285   _mesa_locale_init();
286
287   _mesa_one_time_init_extension_overrides();
288
289   _mesa_get_cpu_features();
290
291   for (i = 0; i < 256; i++) {
292      _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
293   }
294
295   atexit(one_time_fini);
296
297#if defined(DEBUG)
298   if (MESA_VERBOSE != 0) {
299      _mesa_debug(NULL, "Mesa " PACKAGE_VERSION " DEBUG build" MESA_GIT_SHA1 "\n");
300   }
301#endif
302
303   /* Take a glsl type reference for the duration of libGL's life to avoid
304    * unecessary creation/destruction of glsl types.
305    */
306   glsl_type_singleton_init_or_ref();
307
308   _mesa_init_remap_table();
309}
310
311/**
312 * One-time initialization flag
313 *
314 * \sa Used by _mesa_initialize().
315 */
316static once_flag init_once = ONCE_FLAG_INIT;
317
318
319/**
320 * Calls all the various one-time-init functions in Mesa.
321 *
322 * While holding a global mutex lock, calls several initialization functions,
323 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
324 * defined.
325 *
326 * \sa _math_init().
327 */
328void
329_mesa_initialize(void)
330{
331   call_once(&init_once, one_time_init);
332}
333
334
335/**
336 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
337 */
338static void
339_mesa_init_current(struct gl_context *ctx)
340{
341   GLuint i;
342
343   /* Init all to (0,0,0,1) */
344   for (i = 0; i < ARRAY_SIZE(ctx->Current.Attrib); i++) {
345      ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
346   }
347
348   /* redo special cases: */
349   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
350   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
351   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
352   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
353   ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
354}
355
356
357/**
358 * Init vertex/fragment/geometry program limits.
359 * Important: drivers should override these with actual limits.
360 */
361static void
362init_program_limits(struct gl_constants *consts, gl_shader_stage stage,
363                    struct gl_program_constants *prog)
364{
365   prog->MaxInstructions = MAX_PROGRAM_INSTRUCTIONS;
366   prog->MaxAluInstructions = MAX_PROGRAM_INSTRUCTIONS;
367   prog->MaxTexInstructions = MAX_PROGRAM_INSTRUCTIONS;
368   prog->MaxTexIndirections = MAX_PROGRAM_INSTRUCTIONS;
369   prog->MaxTemps = MAX_PROGRAM_TEMPS;
370   prog->MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
371   prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
372   prog->MaxAddressOffset = MAX_PROGRAM_LOCAL_PARAMS;
373
374   switch (stage) {
375   case MESA_SHADER_VERTEX:
376      prog->MaxParameters = MAX_VERTEX_PROGRAM_PARAMS;
377      prog->MaxAttribs = MAX_VERTEX_GENERIC_ATTRIBS;
378      prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
379      prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
380      prog->MaxInputComponents = 0; /* value not used */
381      prog->MaxOutputComponents = 16 * 4; /* old limit not to break tnl and swrast */
382      break;
383   case MESA_SHADER_FRAGMENT:
384      prog->MaxParameters = MAX_FRAGMENT_PROGRAM_PARAMS;
385      prog->MaxAttribs = MAX_FRAGMENT_PROGRAM_INPUTS;
386      prog->MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
387      prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
388      prog->MaxInputComponents = 16 * 4; /* old limit not to break tnl and swrast */
389      prog->MaxOutputComponents = 0; /* value not used */
390      break;
391   case MESA_SHADER_TESS_CTRL:
392   case MESA_SHADER_TESS_EVAL:
393   case MESA_SHADER_GEOMETRY:
394      prog->MaxParameters = MAX_VERTEX_PROGRAM_PARAMS;
395      prog->MaxAttribs = MAX_VERTEX_GENERIC_ATTRIBS;
396      prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
397      prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
398      prog->MaxInputComponents = 16 * 4; /* old limit not to break tnl and swrast */
399      prog->MaxOutputComponents = 16 * 4; /* old limit not to break tnl and swrast */
400      break;
401   case MESA_SHADER_COMPUTE:
402      prog->MaxParameters = 0; /* not meaningful for compute shaders */
403      prog->MaxAttribs = 0; /* not meaningful for compute shaders */
404      prog->MaxAddressRegs = 0; /* not meaningful for compute shaders */
405      prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
406      prog->MaxInputComponents = 0; /* not meaningful for compute shaders */
407      prog->MaxOutputComponents = 0; /* not meaningful for compute shaders */
408      break;
409   default:
410      assert(0 && "Bad shader stage in init_program_limits()");
411   }
412
413   /* Set the native limits to zero.  This implies that there is no native
414    * support for shaders.  Let the drivers fill in the actual values.
415    */
416   prog->MaxNativeInstructions = 0;
417   prog->MaxNativeAluInstructions = 0;
418   prog->MaxNativeTexInstructions = 0;
419   prog->MaxNativeTexIndirections = 0;
420   prog->MaxNativeAttribs = 0;
421   prog->MaxNativeTemps = 0;
422   prog->MaxNativeAddressRegs = 0;
423   prog->MaxNativeParameters = 0;
424
425   /* Set GLSL datatype range/precision info assuming IEEE float values.
426    * Drivers should override these defaults as needed.
427    */
428   prog->MediumFloat.RangeMin = 127;
429   prog->MediumFloat.RangeMax = 127;
430   prog->MediumFloat.Precision = 23;
431   prog->LowFloat = prog->HighFloat = prog->MediumFloat;
432
433   /* Assume ints are stored as floats for now, since this is the least-common
434    * denominator.  The OpenGL ES spec implies (page 132) that the precision
435    * of integer types should be 0.  Practically speaking, IEEE
436    * single-precision floating point values can only store integers in the
437    * range [-0x01000000, 0x01000000] without loss of precision.
438    */
439   prog->MediumInt.RangeMin = 24;
440   prog->MediumInt.RangeMax = 24;
441   prog->MediumInt.Precision = 0;
442   prog->LowInt = prog->HighInt = prog->MediumInt;
443
444   prog->MaxUniformBlocks = 12;
445   prog->MaxCombinedUniformComponents = (prog->MaxUniformComponents +
446                                         consts->MaxUniformBlockSize / 4 *
447                                         prog->MaxUniformBlocks);
448
449   prog->MaxAtomicBuffers = 0;
450   prog->MaxAtomicCounters = 0;
451
452   prog->MaxShaderStorageBlocks = 8;
453}
454
455
456/**
457 * Initialize fields of gl_constants (aka ctx->Const.*).
458 * Use defaults from config.h.  The device drivers will often override
459 * some of these values (such as number of texture units).
460 */
461void
462_mesa_init_constants(struct gl_constants *consts, gl_api api)
463{
464   int i;
465   assert(consts);
466
467   /* Constants, may be overriden (usually only reduced) by device drivers */
468   consts->MaxTextureMbytes = MAX_TEXTURE_MBYTES;
469   consts->MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
470   consts->Max3DTextureLevels = MAX_TEXTURE_LEVELS;
471   consts->MaxCubeTextureLevels = MAX_TEXTURE_LEVELS;
472   consts->MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
473   consts->MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
474   consts->MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
475   consts->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
476   consts->MaxTextureUnits = MIN2(consts->MaxTextureCoordUnits,
477                                     consts->Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits);
478   consts->MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
479   consts->MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
480   consts->MaxTextureBufferSize = 65536;
481   consts->TextureBufferOffsetAlignment = 1;
482   consts->MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
483   consts->SubPixelBits = SUB_PIXEL_BITS;
484   consts->MinPointSize = MIN_POINT_SIZE;
485   consts->MaxPointSize = MAX_POINT_SIZE;
486   consts->MinPointSizeAA = MIN_POINT_SIZE;
487   consts->MaxPointSizeAA = MAX_POINT_SIZE;
488   consts->PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
489   consts->MinLineWidth = MIN_LINE_WIDTH;
490   consts->MaxLineWidth = MAX_LINE_WIDTH;
491   consts->MinLineWidthAA = MIN_LINE_WIDTH;
492   consts->MaxLineWidthAA = MAX_LINE_WIDTH;
493   consts->LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
494   consts->MaxClipPlanes = 6;
495   consts->MaxLights = MAX_LIGHTS;
496   consts->MaxShininess = 128.0;
497   consts->MaxSpotExponent = 128.0;
498   consts->MaxViewportWidth = 16384;
499   consts->MaxViewportHeight = 16384;
500   consts->MinMapBufferAlignment = 64;
501
502   /* Driver must override these values if ARB_viewport_array is supported. */
503   consts->MaxViewports = 1;
504   consts->ViewportSubpixelBits = 0;
505   consts->ViewportBounds.Min = 0;
506   consts->ViewportBounds.Max = 0;
507
508   /** GL_ARB_uniform_buffer_object */
509   consts->MaxCombinedUniformBlocks = 36;
510   consts->MaxUniformBufferBindings = 36;
511   consts->MaxUniformBlockSize = 16384;
512   consts->UniformBufferOffsetAlignment = 1;
513
514   /** GL_ARB_shader_storage_buffer_object */
515   consts->MaxCombinedShaderStorageBlocks = 8;
516   consts->MaxShaderStorageBufferBindings = 8;
517   consts->MaxShaderStorageBlockSize = 128 * 1024 * 1024; /* 2^27 */
518   consts->ShaderStorageBufferOffsetAlignment = 256;
519
520   /* GL_ARB_explicit_uniform_location, GL_MAX_UNIFORM_LOCATIONS */
521   consts->MaxUserAssignableUniformLocations =
522      4 * MESA_SHADER_STAGES * MAX_UNIFORMS;
523
524   for (i = 0; i < MESA_SHADER_STAGES; i++)
525      init_program_limits(consts, i, &consts->Program[i]);
526
527   consts->MaxProgramMatrices = MAX_PROGRAM_MATRICES;
528   consts->MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
529
530   /* Set the absolute minimum possible GLSL version.  API_OPENGL_CORE can
531    * mean an OpenGL 3.0 forward-compatible context, so that implies a minimum
532    * possible version of 1.30.  Otherwise, the minimum possible version 1.20.
533    * Since Mesa unconditionally advertises GL_ARB_shading_language_100 and
534    * GL_ARB_shader_objects, every driver has GLSL 1.20... even if they don't
535    * advertise any extensions to enable any shader stages (e.g.,
536    * GL_ARB_vertex_shader).
537    */
538   consts->GLSLVersion = api == API_OPENGL_CORE ? 130 : 120;
539   consts->GLSLVersionCompat = consts->GLSLVersion;
540
541   consts->GLSLLowerConstArrays = true;
542
543   /* Assume that if GLSL 1.30+ (or GLSL ES 3.00+) is supported that
544    * gl_VertexID is implemented using a native hardware register with OpenGL
545    * semantics.
546    */
547   consts->VertexID_is_zero_based = false;
548
549   /* GL_ARB_draw_buffers */
550   consts->MaxDrawBuffers = MAX_DRAW_BUFFERS;
551
552   consts->MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
553   consts->MaxRenderbufferSize = MAX_RENDERBUFFER_SIZE;
554
555   consts->Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
556   consts->MaxCombinedTextureImageUnits = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
557   consts->MaxVarying = 16; /* old limit not to break tnl and swrast */
558   consts->Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
559   consts->MaxGeometryOutputVertices = MAX_GEOMETRY_OUTPUT_VERTICES;
560   consts->MaxGeometryTotalOutputComponents = MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS;
561   consts->MaxGeometryShaderInvocations = MAX_GEOMETRY_SHADER_INVOCATIONS;
562
563#ifdef DEBUG
564   consts->GenerateTemporaryNames = true;
565#else
566   consts->GenerateTemporaryNames = false;
567#endif
568
569   /* GL_ARB_framebuffer_object */
570   consts->MaxSamples = 0;
571
572   /* GLSL default if NativeIntegers == FALSE */
573   consts->UniformBooleanTrue = FLOAT_AS_UNION(1.0f).u;
574
575   /* GL_ARB_sync */
576   consts->MaxServerWaitTimeout = 0x7fffffff7fffffffULL;
577
578   /* GL_EXT_provoking_vertex */
579   consts->QuadsFollowProvokingVertexConvention = GL_TRUE;
580
581   /** GL_ARB_viewport_array */
582   consts->LayerAndVPIndexProvokingVertex = GL_UNDEFINED_VERTEX;
583
584   /* GL_EXT_transform_feedback */
585   consts->MaxTransformFeedbackBuffers = MAX_FEEDBACK_BUFFERS;
586   consts->MaxTransformFeedbackSeparateComponents = 4 * MAX_FEEDBACK_ATTRIBS;
587   consts->MaxTransformFeedbackInterleavedComponents = 4 * MAX_FEEDBACK_ATTRIBS;
588   consts->MaxVertexStreams = 1;
589
590   /* GL 3.2  */
591   consts->ProfileMask = api == API_OPENGL_CORE
592                          ? GL_CONTEXT_CORE_PROFILE_BIT
593                          : GL_CONTEXT_COMPATIBILITY_PROFILE_BIT;
594
595   /* GL 4.4 */
596   consts->MaxVertexAttribStride = 2048;
597
598   /** GL_EXT_gpu_shader4 */
599   consts->MinProgramTexelOffset = -8;
600   consts->MaxProgramTexelOffset = 7;
601
602   /* GL_ARB_texture_gather */
603   consts->MinProgramTextureGatherOffset = -8;
604   consts->MaxProgramTextureGatherOffset = 7;
605
606   /* GL_ARB_robustness */
607   consts->ResetStrategy = GL_NO_RESET_NOTIFICATION_ARB;
608
609   /* GL_KHR_robustness */
610   consts->RobustAccess = GL_FALSE;
611
612   /* ES 3.0 or ARB_ES3_compatibility */
613   consts->MaxElementIndex = 0xffffffffu;
614
615   /* GL_ARB_texture_multisample */
616   consts->MaxColorTextureSamples = 1;
617   consts->MaxDepthTextureSamples = 1;
618   consts->MaxIntegerSamples = 1;
619
620   /* GL_ARB_shader_atomic_counters */
621   consts->MaxAtomicBufferBindings = MAX_COMBINED_ATOMIC_BUFFERS;
622   consts->MaxAtomicBufferSize = MAX_ATOMIC_COUNTERS * ATOMIC_COUNTER_SIZE;
623   consts->MaxCombinedAtomicBuffers = MAX_COMBINED_ATOMIC_BUFFERS;
624   consts->MaxCombinedAtomicCounters = MAX_ATOMIC_COUNTERS;
625
626   /* GL_ARB_vertex_attrib_binding */
627   consts->MaxVertexAttribRelativeOffset = 2047;
628   consts->MaxVertexAttribBindings = MAX_VERTEX_GENERIC_ATTRIBS;
629
630   /* GL_ARB_compute_shader */
631   consts->MaxComputeWorkGroupCount[0] = 65535;
632   consts->MaxComputeWorkGroupCount[1] = 65535;
633   consts->MaxComputeWorkGroupCount[2] = 65535;
634   consts->MaxComputeWorkGroupSize[0] = 1024;
635   consts->MaxComputeWorkGroupSize[1] = 1024;
636   consts->MaxComputeWorkGroupSize[2] = 64;
637   /* Enables compute support for GLES 3.1 if >= 128 */
638   consts->MaxComputeWorkGroupInvocations = 0;
639
640   /** GL_ARB_gpu_shader5 */
641   consts->MinFragmentInterpolationOffset = MIN_FRAGMENT_INTERPOLATION_OFFSET;
642   consts->MaxFragmentInterpolationOffset = MAX_FRAGMENT_INTERPOLATION_OFFSET;
643
644   /** GL_KHR_context_flush_control */
645   consts->ContextReleaseBehavior = GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;
646
647   /** GL_ARB_tessellation_shader */
648   consts->MaxTessGenLevel = MAX_TESS_GEN_LEVEL;
649   consts->MaxPatchVertices = MAX_PATCH_VERTICES;
650   consts->Program[MESA_SHADER_TESS_CTRL].MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
651   consts->Program[MESA_SHADER_TESS_EVAL].MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
652   consts->MaxTessPatchComponents = MAX_TESS_PATCH_COMPONENTS;
653   consts->MaxTessControlTotalOutputComponents = MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS;
654   consts->PrimitiveRestartForPatches = false;
655
656   /** GL_ARB_compute_variable_group_size */
657   consts->MaxComputeVariableGroupSize[0] = 512;
658   consts->MaxComputeVariableGroupSize[1] = 512;
659   consts->MaxComputeVariableGroupSize[2] = 64;
660   consts->MaxComputeVariableGroupInvocations = 512;
661
662   /** GL_NV_conservative_raster */
663   consts->MaxSubpixelPrecisionBiasBits = 0;
664
665   /** GL_NV_conservative_raster_dilate */
666   consts->ConservativeRasterDilateRange[0] = 0.0;
667   consts->ConservativeRasterDilateRange[1] = 0.0;
668   consts->ConservativeRasterDilateGranularity = 0.0;
669
670   consts->glBeginEndBufferSize = 512 * 1024;
671}
672
673
674/**
675 * Do some sanity checks on the limits/constants for the given context.
676 * Only called the first time a context is bound.
677 */
678static void
679check_context_limits(struct gl_context *ctx)
680{
681   (void) ctx;
682
683   /* check that we don't exceed the size of various bitfields */
684   assert(VARYING_SLOT_MAX <=
685          (8 * sizeof(ctx->VertexProgram._Current->info.outputs_written)));
686   assert(VARYING_SLOT_MAX <=
687          (8 * sizeof(ctx->FragmentProgram._Current->info.inputs_read)));
688
689   /* shader-related checks */
690   assert(ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
691   assert(ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
692
693   /* Texture unit checks */
694   assert(ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits > 0);
695   assert(ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
696   assert(ctx->Const.MaxTextureCoordUnits > 0);
697   assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
698   assert(ctx->Const.MaxTextureUnits > 0);
699   assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
700   assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
701   assert(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
702                                             ctx->Const.MaxTextureCoordUnits));
703   assert(ctx->Const.MaxCombinedTextureImageUnits > 0);
704   assert(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
705   assert(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
706   /* number of coord units cannot be greater than number of image units */
707   assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits);
708
709
710   /* Texture size checks */
711   assert(ctx->Const.MaxTextureSize <= (1 << (MAX_TEXTURE_LEVELS - 1)));
712   assert(ctx->Const.Max3DTextureLevels <= MAX_TEXTURE_LEVELS);
713   assert(ctx->Const.MaxCubeTextureLevels <= MAX_TEXTURE_LEVELS);
714   assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
715
716   /* Max texture size should be <= max viewport size (render to texture) */
717   assert(ctx->Const.MaxTextureSize <= ctx->Const.MaxViewportWidth);
718   assert(ctx->Const.MaxTextureSize <= ctx->Const.MaxViewportHeight);
719
720   assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
721
722   /* if this fails, add more enum values to gl_buffer_index */
723   assert(BUFFER_COLOR0 + MAX_DRAW_BUFFERS <= BUFFER_COUNT);
724
725   /* XXX probably add more tests */
726}
727
728
729/**
730 * Initialize the attribute groups in a GL context.
731 *
732 * \param ctx GL context.
733 *
734 * Initializes all the attributes, calling the respective <tt>init*</tt>
735 * functions for the more complex data structures.
736 */
737static GLboolean
738init_attrib_groups(struct gl_context *ctx)
739{
740   assert(ctx);
741
742   /* Constants */
743   _mesa_init_constants(&ctx->Const, ctx->API);
744
745   /* Extensions */
746   _mesa_init_extensions(&ctx->Extensions);
747
748   /* Attribute Groups */
749   _mesa_init_accum( ctx );
750   _mesa_init_attrib( ctx );
751   _mesa_init_bbox( ctx );
752   _mesa_init_buffer_objects( ctx );
753   _mesa_init_color( ctx );
754   _mesa_init_conservative_raster( ctx );
755   _mesa_init_current( ctx );
756   _mesa_init_depth( ctx );
757   _mesa_init_debug( ctx );
758   _mesa_init_debug_output( ctx );
759   _mesa_init_display_list( ctx );
760   _mesa_init_eval( ctx );
761   _mesa_init_feedback( ctx );
762   _mesa_init_fog( ctx );
763   _mesa_init_hint( ctx );
764   _mesa_init_image_units( ctx );
765   _mesa_init_line( ctx );
766   _mesa_init_lighting( ctx );
767   _mesa_init_matrix( ctx );
768   _mesa_init_multisample( ctx );
769   _mesa_init_performance_monitors( ctx );
770   _mesa_init_performance_queries( ctx );
771   _mesa_init_pipeline( ctx );
772   _mesa_init_pixel( ctx );
773   _mesa_init_pixelstore( ctx );
774   _mesa_init_point( ctx );
775   _mesa_init_polygon( ctx );
776   _mesa_init_program( ctx );
777   _mesa_init_queryobj( ctx );
778   _mesa_init_sync( ctx );
779   _mesa_init_rastpos( ctx );
780   _mesa_init_scissor( ctx );
781   _mesa_init_shader_state( ctx );
782   _mesa_init_stencil( ctx );
783   _mesa_init_transform( ctx );
784   _mesa_init_transform_feedback( ctx );
785   _mesa_init_varray( ctx );
786   _mesa_init_viewport( ctx );
787   _mesa_init_resident_handles( ctx );
788
789   if (!_mesa_init_texture( ctx ))
790      return GL_FALSE;
791
792   /* Miscellaneous */
793   ctx->TileRasterOrderIncreasingX = GL_TRUE;
794   ctx->TileRasterOrderIncreasingY = GL_TRUE;
795   ctx->NewState = _NEW_ALL;
796   ctx->NewDriverState = ~0;
797   ctx->ErrorValue = GL_NO_ERROR;
798   ctx->ShareGroupReset = false;
799   ctx->VertexProgram._VaryingInputs = VERT_BIT_ALL;
800   ctx->IntelBlackholeRender = env_var_as_boolean("INTEL_BLACKHOLE_DEFAULT", false);
801
802   return GL_TRUE;
803}
804
805
806/**
807 * Update default objects in a GL context with respect to shared state.
808 *
809 * \param ctx GL context.
810 *
811 * Removes references to old default objects, (texture objects, program
812 * objects, etc.) and changes to reference those from the current shared
813 * state.
814 */
815static GLboolean
816update_default_objects(struct gl_context *ctx)
817{
818   assert(ctx);
819
820   _mesa_update_default_objects_program(ctx);
821   _mesa_update_default_objects_texture(ctx);
822   _mesa_update_default_objects_buffer_objects(ctx);
823
824   return GL_TRUE;
825}
826
827
828/* XXX this is temporary and should be removed at some point in the
829 * future when there's a reasonable expectation that the libGL library
830 * contains the _glapi_new_nop_table() and _glapi_set_nop_handler()
831 * functions which were added in Mesa 10.6.
832 */
833#if !defined(_WIN32)
834/* Avoid libGL / driver ABI break */
835#define USE_GLAPI_NOP_FEATURES 0
836#else
837#define USE_GLAPI_NOP_FEATURES 1
838#endif
839
840
841/**
842 * This function is called by the glapi no-op functions.  For each OpenGL
843 * function/entrypoint there's a simple no-op function.  These "no-op"
844 * functions call this function.
845 *
846 * If there's a current OpenGL context for the calling thread, we record a
847 * GL_INVALID_OPERATION error.  This can happen either because the app's
848 * calling an unsupported extension function, or calling an illegal function
849 * (such as glClear between glBegin/glEnd).
850 *
851 * If there's no current OpenGL context for the calling thread, we can
852 * print a message to stderr.
853 *
854 * \param name  the name of the OpenGL function
855 */
856#if USE_GLAPI_NOP_FEATURES
857static void
858nop_handler(const char *name)
859{
860   GET_CURRENT_CONTEXT(ctx);
861   if (ctx) {
862      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid call)", name);
863   }
864#ifndef NDEBUG
865   else if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")) {
866      fprintf(stderr,
867              "GL User Error: gl%s called without a rendering context\n",
868              name);
869      fflush(stderr);
870   }
871#endif
872}
873#endif
874
875
876/**
877 * Special no-op glFlush, see below.
878 */
879#if defined(_WIN32)
880static void GLAPIENTRY
881nop_glFlush(void)
882{
883   /* don't record an error like we do in nop_handler() */
884}
885#endif
886
887
888#if !USE_GLAPI_NOP_FEATURES
889static int
890generic_nop(void)
891{
892   GET_CURRENT_CONTEXT(ctx);
893   _mesa_error(ctx, GL_INVALID_OPERATION,
894               "unsupported function called "
895               "(unsupported extension or deprecated function?)");
896   return 0;
897}
898#endif
899
900
901/**
902 * Create a new API dispatch table in which all entries point to the
903 * generic_nop() function.  This will not work on Windows because of
904 * the __stdcall convention which requires the callee to clean up the
905 * call stack.  That's impossible with one generic no-op function.
906 */
907struct _glapi_table *
908_mesa_new_nop_table(unsigned numEntries)
909{
910   struct _glapi_table *table;
911
912#if !USE_GLAPI_NOP_FEATURES
913   table = malloc(numEntries * sizeof(_glapi_proc));
914   if (table) {
915      _glapi_proc *entry = (_glapi_proc *) table;
916      unsigned i;
917      for (i = 0; i < numEntries; i++) {
918         entry[i] = (_glapi_proc) generic_nop;
919      }
920   }
921#else
922   table = _glapi_new_nop_table(numEntries);
923#endif
924   return table;
925}
926
927
928/**
929 * Allocate and initialize a new dispatch table.  The table will be
930 * populated with pointers to "no-op" functions.  In turn, the no-op
931 * functions will call nop_handler() above.
932 */
933struct _glapi_table *
934_mesa_alloc_dispatch_table(void)
935{
936   /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
937    * In practice, this'll be the same for stand-alone Mesa.  But for DRI
938    * Mesa we do this to accommodate different versions of libGL and various
939    * DRI drivers.
940    */
941   int numEntries = MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT);
942
943   struct _glapi_table *table = _mesa_new_nop_table(numEntries);
944
945#if defined(_WIN32)
946   if (table) {
947      /* This is a special case for Windows in the event that
948       * wglGetProcAddress is called between glBegin/End().
949       *
950       * The MS opengl32.dll library apparently calls glFlush from
951       * wglGetProcAddress().  If we're inside glBegin/End(), glFlush
952       * will dispatch to _mesa_generic_nop() and we'll generate a
953       * GL_INVALID_OPERATION error.
954       *
955       * The specific case which hits this is piglit's primitive-restart
956       * test which calls glPrimitiveRestartNV() inside glBegin/End.  The
957       * first time we call glPrimitiveRestartNV() Piglit's API dispatch
958       * code will try to resolve the function by calling wglGetProcAddress.
959       * This raises GL_INVALID_OPERATION and an assert(glGetError()==0)
960       * will fail causing the test to fail.  By suppressing the error, the
961       * assertion passes and the test continues.
962       */
963      SET_Flush(table, nop_glFlush);
964   }
965#endif
966
967#if USE_GLAPI_NOP_FEATURES
968   _glapi_set_nop_handler(nop_handler);
969#endif
970
971   return table;
972}
973
974/**
975 * Creates a minimal dispatch table for use within glBegin()/glEnd().
976 *
977 * This ensures that we generate GL_INVALID_OPERATION errors from most
978 * functions, since the set of functions that are valid within Begin/End is
979 * very small.
980 *
981 * From the GL 1.0 specification section 2.6.3, "GL Commands within
982 * Begin/End"
983 *
984 *     "The only GL commands that are allowed within any Begin/End pairs are
985 *      the commands for specifying vertex coordinates, vertex color, normal
986 *      coordinates, and texture coordinates (Vertex, Color, Index, Normal,
987 *      TexCoord), EvalCoord and EvalPoint commands (see section 5.1),
988 *      commands for specifying lighting material parameters (Material
989 *      commands see section 2.12.2), display list invocation commands
990 *      (CallList and CallLists see section 5.4), and the EdgeFlag
991 *      command. Executing Begin after Begin has already been executed but
992 *      before an End is issued generates the INVALID OPERATION error, as does
993 *      executing End without a previous corresponding Begin. Executing any
994 *      other GL command within Begin/End results in the error INVALID
995 *      OPERATION."
996 *
997 * The table entries for specifying vertex attributes are set up by
998 * install_vtxfmt(), and End() and dlists
999 * are set by install_vtxfmt() as well.
1000 */
1001static struct _glapi_table *
1002create_beginend_table(const struct gl_context *ctx)
1003{
1004   struct _glapi_table *table;
1005
1006   table = _mesa_alloc_dispatch_table();
1007   if (!table)
1008      return NULL;
1009
1010   /* Fill in functions which return a value, since they should return some
1011    * specific value even if they emit a GL_INVALID_OPERATION error from them
1012    * being called within glBegin()/glEnd().
1013    */
1014#define COPY_DISPATCH(func) SET_##func(table, GET_##func(ctx->Exec))
1015
1016   COPY_DISPATCH(GenLists);
1017   COPY_DISPATCH(IsProgram);
1018   COPY_DISPATCH(IsVertexArray);
1019   COPY_DISPATCH(IsBuffer);
1020   COPY_DISPATCH(IsEnabled);
1021   COPY_DISPATCH(IsEnabledi);
1022   COPY_DISPATCH(IsRenderbuffer);
1023   COPY_DISPATCH(IsFramebuffer);
1024   COPY_DISPATCH(CheckFramebufferStatus);
1025   COPY_DISPATCH(RenderMode);
1026   COPY_DISPATCH(GetString);
1027   COPY_DISPATCH(GetStringi);
1028   COPY_DISPATCH(GetPointerv);
1029   COPY_DISPATCH(IsQuery);
1030   COPY_DISPATCH(IsSampler);
1031   COPY_DISPATCH(IsSync);
1032   COPY_DISPATCH(IsTexture);
1033   COPY_DISPATCH(IsTransformFeedback);
1034   COPY_DISPATCH(DeleteQueries);
1035   COPY_DISPATCH(AreTexturesResident);
1036   COPY_DISPATCH(FenceSync);
1037   COPY_DISPATCH(ClientWaitSync);
1038   COPY_DISPATCH(MapBuffer);
1039   COPY_DISPATCH(UnmapBuffer);
1040   COPY_DISPATCH(MapBufferRange);
1041   COPY_DISPATCH(ObjectPurgeableAPPLE);
1042   COPY_DISPATCH(ObjectUnpurgeableAPPLE);
1043
1044   return table;
1045}
1046
1047void
1048_mesa_initialize_dispatch_tables(struct gl_context *ctx)
1049{
1050   /* Do the code-generated setup of the exec table in api_exec.c. */
1051   _mesa_initialize_exec_table(ctx);
1052
1053   if (ctx->Save)
1054      _mesa_initialize_save_table(ctx);
1055}
1056
1057/**
1058 * Initialize a struct gl_context struct (rendering context).
1059 *
1060 * This includes allocating all the other structs and arrays which hang off of
1061 * the context by pointers.
1062 * Note that the driver needs to pass in its dd_function_table here since
1063 * we need to at least call driverFunctions->NewTextureObject to create the
1064 * default texture objects.
1065 *
1066 * Called by _mesa_create_context().
1067 *
1068 * Performs the imports and exports callback tables initialization, and
1069 * miscellaneous one-time initializations. If no shared context is supplied one
1070 * is allocated, and increase its reference count.  Setups the GL API dispatch
1071 * tables.  Initialize the TNL module. Sets the maximum Z buffer depth.
1072 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1073 * for debug flags.
1074 *
1075 * \param ctx the context to initialize
1076 * \param api the GL API type to create the context for
1077 * \param visual describes the visual attributes for this context or NULL to
1078 *               create a configless context
1079 * \param share_list points to context to share textures, display lists,
1080 *        etc with, or NULL
1081 * \param driverFunctions table of device driver functions for this context
1082 *        to use
1083 */
1084GLboolean
1085_mesa_initialize_context(struct gl_context *ctx,
1086                         gl_api api,
1087                         const struct gl_config *visual,
1088                         struct gl_context *share_list,
1089                         const struct dd_function_table *driverFunctions)
1090{
1091   struct gl_shared_state *shared;
1092   int i;
1093
1094   assert(driverFunctions->NewTextureObject);
1095   assert(driverFunctions->FreeTextureImageBuffer);
1096
1097   ctx->API = api;
1098   ctx->DrawBuffer = NULL;
1099   ctx->ReadBuffer = NULL;
1100   ctx->WinSysDrawBuffer = NULL;
1101   ctx->WinSysReadBuffer = NULL;
1102
1103   if (visual) {
1104      ctx->Visual = *visual;
1105      ctx->HasConfig = GL_TRUE;
1106   }
1107   else {
1108      memset(&ctx->Visual, 0, sizeof ctx->Visual);
1109      ctx->HasConfig = GL_FALSE;
1110   }
1111
1112   _mesa_override_gl_version(ctx);
1113
1114   /* misc one-time initializations */
1115   _mesa_initialize();
1116
1117   /* Plug in driver functions and context pointer here.
1118    * This is important because when we call alloc_shared_state() below
1119    * we'll call ctx->Driver.NewTextureObject() to create the default
1120    * textures.
1121    */
1122   ctx->Driver = *driverFunctions;
1123
1124   if (share_list) {
1125      /* share state with another context */
1126      shared = share_list->Shared;
1127   }
1128   else {
1129      /* allocate new, unshared state */
1130      shared = _mesa_alloc_shared_state(ctx);
1131      if (!shared)
1132         return GL_FALSE;
1133   }
1134
1135   _mesa_reference_shared_state(ctx, &ctx->Shared, shared);
1136
1137   if (!init_attrib_groups( ctx ))
1138      goto fail;
1139
1140   /* KHR_no_error is likely to crash, overflow memory, etc if an application
1141    * has errors so don't enable it for setuid processes.
1142    */
1143   if (env_var_as_boolean("MESA_NO_ERROR", false)) {
1144#if !defined(_WIN32)
1145      if (!issetugid())
1146#endif
1147         ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
1148   }
1149
1150   /* setup the API dispatch tables with all nop functions */
1151   ctx->OutsideBeginEnd = _mesa_alloc_dispatch_table();
1152   if (!ctx->OutsideBeginEnd)
1153      goto fail;
1154   ctx->Exec = ctx->OutsideBeginEnd;
1155   ctx->CurrentClientDispatch = ctx->CurrentServerDispatch = ctx->OutsideBeginEnd;
1156
1157   ctx->FragmentProgram._MaintainTexEnvProgram
1158      = (getenv("MESA_TEX_PROG") != NULL);
1159
1160   ctx->VertexProgram._MaintainTnlProgram
1161      = (getenv("MESA_TNL_PROG") != NULL);
1162   if (ctx->VertexProgram._MaintainTnlProgram) {
1163      /* this is required... */
1164      ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
1165      _mesa_reset_vertex_processing_mode(ctx);
1166   }
1167
1168   /* Mesa core handles all the formats that mesa core knows about.
1169    * Drivers will want to override this list with just the formats
1170    * they can handle, and confirm that appropriate fallbacks exist in
1171    * _mesa_choose_tex_format().
1172    */
1173   memset(&ctx->TextureFormatSupported, GL_TRUE,
1174          sizeof(ctx->TextureFormatSupported));
1175
1176   switch (ctx->API) {
1177   case API_OPENGL_COMPAT:
1178      ctx->BeginEnd = create_beginend_table(ctx);
1179      ctx->Save = _mesa_alloc_dispatch_table();
1180      if (!ctx->BeginEnd || !ctx->Save)
1181         goto fail;
1182
1183      FALLTHROUGH;
1184   case API_OPENGL_CORE:
1185      break;
1186   case API_OPENGLES:
1187      /**
1188       * GL_OES_texture_cube_map says
1189       * "Initially all texture generation modes are set to REFLECTION_MAP_OES"
1190       */
1191      for (i = 0; i < ARRAY_SIZE(ctx->Texture.FixedFuncUnit); i++) {
1192         struct gl_fixedfunc_texture_unit *texUnit =
1193            &ctx->Texture.FixedFuncUnit[i];
1194
1195         texUnit->GenS.Mode = GL_REFLECTION_MAP_NV;
1196         texUnit->GenT.Mode = GL_REFLECTION_MAP_NV;
1197         texUnit->GenR.Mode = GL_REFLECTION_MAP_NV;
1198         texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV;
1199         texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV;
1200         texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV;
1201      }
1202      break;
1203   case API_OPENGLES2:
1204      ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
1205      ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
1206      _mesa_reset_vertex_processing_mode(ctx);
1207      break;
1208   }
1209
1210   ctx->FirstTimeCurrent = GL_TRUE;
1211
1212   return GL_TRUE;
1213
1214fail:
1215   _mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
1216   free(ctx->BeginEnd);
1217   free(ctx->OutsideBeginEnd);
1218   free(ctx->Save);
1219   return GL_FALSE;
1220}
1221
1222
1223/**
1224 * Free the data associated with the given context.
1225 *
1226 * But doesn't free the struct gl_context struct itself.
1227 *
1228 * \sa _mesa_initialize_context() and init_attrib_groups().
1229 */
1230void
1231_mesa_free_context_data(struct gl_context *ctx, bool destroy_debug_output)
1232{
1233   if (!_mesa_get_current_context()){
1234      /* No current context, but we may need one in order to delete
1235       * texture objs, etc.  So temporarily bind the context now.
1236       */
1237      _mesa_make_current(ctx, NULL, NULL);
1238   }
1239
1240   /* unreference WinSysDraw/Read buffers */
1241   _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL);
1242   _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL);
1243   _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL);
1244   _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL);
1245
1246   _mesa_reference_program(ctx, &ctx->VertexProgram.Current, NULL);
1247   _mesa_reference_program(ctx, &ctx->VertexProgram._Current, NULL);
1248   _mesa_reference_program(ctx, &ctx->VertexProgram._TnlProgram, NULL);
1249
1250   _mesa_reference_program(ctx, &ctx->TessCtrlProgram._Current, NULL);
1251   _mesa_reference_program(ctx, &ctx->TessEvalProgram._Current, NULL);
1252   _mesa_reference_program(ctx, &ctx->GeometryProgram._Current, NULL);
1253
1254   _mesa_reference_program(ctx, &ctx->FragmentProgram.Current, NULL);
1255   _mesa_reference_program(ctx, &ctx->FragmentProgram._Current, NULL);
1256   _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
1257
1258   _mesa_reference_program(ctx, &ctx->ComputeProgram._Current, NULL);
1259
1260   _mesa_reference_vao(ctx, &ctx->Array.VAO, NULL);
1261   _mesa_reference_vao(ctx, &ctx->Array.DefaultVAO, NULL);
1262   _mesa_reference_vao(ctx, &ctx->Array._EmptyVAO, NULL);
1263   _mesa_reference_vao(ctx, &ctx->Array._DrawVAO, NULL);
1264
1265   _mesa_free_attrib_data(ctx);
1266   _mesa_free_eval_data( ctx );
1267   _mesa_free_texture_data( ctx );
1268   _mesa_free_image_textures(ctx);
1269   _mesa_free_matrix_data( ctx );
1270   _mesa_free_pipeline_data(ctx);
1271   _mesa_free_program_data(ctx);
1272   _mesa_free_shader_state(ctx);
1273   _mesa_free_queryobj_data(ctx);
1274   _mesa_free_sync_data(ctx);
1275   _mesa_free_varray_data(ctx);
1276   _mesa_free_transform_feedback(ctx);
1277   _mesa_free_performance_monitors(ctx);
1278   _mesa_free_performance_queries(ctx);
1279   _mesa_free_resident_handles(ctx);
1280
1281   _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj, NULL);
1282   _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj, NULL);
1283   _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj, NULL);
1284   _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
1285
1286   /* This must be called after all buffers are unbound because global buffer
1287    * references that this context holds will be removed.
1288    */
1289   _mesa_free_buffer_objects(ctx);
1290
1291   /* free dispatch tables */
1292   free(ctx->BeginEnd);
1293   free(ctx->OutsideBeginEnd);
1294   free(ctx->Save);
1295   free(ctx->ContextLost);
1296   free(ctx->MarshalExec);
1297
1298   /* Shared context state (display lists, textures, etc) */
1299   _mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
1300
1301   if (destroy_debug_output)
1302      _mesa_destroy_debug_output(ctx);
1303
1304   free((void *)ctx->Extensions.String);
1305
1306   free(ctx->VersionString);
1307
1308   ralloc_free(ctx->SoftFP64);
1309
1310   /* unbind the context if it's currently bound */
1311   if (ctx == _mesa_get_current_context()) {
1312      _mesa_make_current(NULL, NULL, NULL);
1313   }
1314
1315   /* Do this after unbinding context to ensure any thread is finished. */
1316   if (ctx->shader_builtin_ref) {
1317      _mesa_glsl_builtin_functions_decref();
1318      ctx->shader_builtin_ref = false;
1319   }
1320
1321   free(ctx->Const.SpirVExtensions);
1322}
1323
1324
1325/**
1326 * Copy attribute groups from one context to another.
1327 *
1328 * \param src source context
1329 * \param dst destination context
1330 * \param mask bitwise OR of GL_*_BIT flags
1331 *
1332 * According to the bits specified in \p mask, copies the corresponding
1333 * attributes from \p src into \p dst.  For many of the attributes a simple \c
1334 * memcpy is not enough due to the existence of internal pointers in their data
1335 * structures.
1336 */
1337void
1338_mesa_copy_context( const struct gl_context *src, struct gl_context *dst,
1339                    GLuint mask )
1340{
1341   if (mask & GL_ACCUM_BUFFER_BIT) {
1342      /* OK to memcpy */
1343      dst->Accum = src->Accum;
1344   }
1345   if (mask & GL_COLOR_BUFFER_BIT) {
1346      /* OK to memcpy */
1347      dst->Color = src->Color;
1348   }
1349   if (mask & GL_CURRENT_BIT) {
1350      /* OK to memcpy */
1351      dst->Current = src->Current;
1352   }
1353   if (mask & GL_DEPTH_BUFFER_BIT) {
1354      /* OK to memcpy */
1355      dst->Depth = src->Depth;
1356   }
1357   if (mask & GL_ENABLE_BIT) {
1358      /* no op */
1359   }
1360   if (mask & GL_EVAL_BIT) {
1361      /* OK to memcpy */
1362      dst->Eval = src->Eval;
1363   }
1364   if (mask & GL_FOG_BIT) {
1365      /* OK to memcpy */
1366      dst->Fog = src->Fog;
1367   }
1368   if (mask & GL_HINT_BIT) {
1369      /* OK to memcpy */
1370      dst->Hint = src->Hint;
1371   }
1372   if (mask & GL_LIGHTING_BIT) {
1373      /* OK to memcpy */
1374      dst->Light = src->Light;
1375   }
1376   if (mask & GL_LINE_BIT) {
1377      /* OK to memcpy */
1378      dst->Line = src->Line;
1379   }
1380   if (mask & GL_LIST_BIT) {
1381      /* OK to memcpy */
1382      dst->List = src->List;
1383   }
1384   if (mask & GL_PIXEL_MODE_BIT) {
1385      /* OK to memcpy */
1386      dst->Pixel = src->Pixel;
1387   }
1388   if (mask & GL_POINT_BIT) {
1389      /* OK to memcpy */
1390      dst->Point = src->Point;
1391   }
1392   if (mask & GL_POLYGON_BIT) {
1393      /* OK to memcpy */
1394      dst->Polygon = src->Polygon;
1395   }
1396   if (mask & GL_POLYGON_STIPPLE_BIT) {
1397      /* Use loop instead of memcpy due to problem with Portland Group's
1398       * C compiler.  Reported by John Stone.
1399       */
1400      GLuint i;
1401      for (i = 0; i < 32; i++) {
1402         dst->PolygonStipple[i] = src->PolygonStipple[i];
1403      }
1404   }
1405   if (mask & GL_SCISSOR_BIT) {
1406      /* OK to memcpy */
1407      dst->Scissor = src->Scissor;
1408   }
1409   if (mask & GL_STENCIL_BUFFER_BIT) {
1410      /* OK to memcpy */
1411      dst->Stencil = src->Stencil;
1412   }
1413   if (mask & GL_TEXTURE_BIT) {
1414      /* Cannot memcpy because of pointers */
1415      _mesa_copy_texture_state(src, dst);
1416   }
1417   if (mask & GL_TRANSFORM_BIT) {
1418      /* OK to memcpy */
1419      dst->Transform = src->Transform;
1420   }
1421   if (mask & GL_VIEWPORT_BIT) {
1422      unsigned i;
1423      for (i = 0; i < src->Const.MaxViewports; i++) {
1424         /* OK to memcpy */
1425         dst->ViewportArray[i] = src->ViewportArray[i];
1426      }
1427   }
1428
1429   /* XXX FIXME:  Call callbacks?
1430    */
1431   dst->NewState = _NEW_ALL;
1432   dst->NewDriverState = ~0;
1433}
1434
1435
1436/**
1437 * Check if the given context can render into the given framebuffer
1438 * by checking visual attributes.
1439 *
1440 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1441 */
1442static GLboolean
1443check_compatible(const struct gl_context *ctx,
1444                 const struct gl_framebuffer *buffer)
1445{
1446   const struct gl_config *ctxvis = &ctx->Visual;
1447   const struct gl_config *bufvis = &buffer->Visual;
1448
1449   if (buffer == _mesa_get_incomplete_framebuffer())
1450      return GL_TRUE;
1451
1452#define check_component(foo)           \
1453   if (ctxvis->foo && bufvis->foo &&   \
1454       ctxvis->foo != bufvis->foo)     \
1455      return GL_FALSE
1456
1457   check_component(redShift);
1458   check_component(greenShift);
1459   check_component(blueShift);
1460   check_component(redBits);
1461   check_component(greenBits);
1462   check_component(blueBits);
1463   check_component(depthBits);
1464   check_component(stencilBits);
1465
1466#undef check_component
1467
1468   return GL_TRUE;
1469}
1470
1471
1472/**
1473 * Check if the viewport/scissor size has not yet been initialized.
1474 * Initialize the size if the given width and height are non-zero.
1475 */
1476static void
1477check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height)
1478{
1479   if (!ctx->ViewportInitialized && width > 0 && height > 0) {
1480      unsigned i;
1481
1482      /* Note: set flag here, before calling _mesa_set_viewport(), to prevent
1483       * potential infinite recursion.
1484       */
1485      ctx->ViewportInitialized = GL_TRUE;
1486
1487      /* Note: ctx->Const.MaxViewports may not have been set by the driver
1488       * yet, so just initialize all of them.
1489       */
1490      for (i = 0; i < MAX_VIEWPORTS; i++) {
1491         _mesa_set_viewport(ctx, i, 0, 0, width, height);
1492         _mesa_set_scissor(ctx, i, 0, 0, width, height);
1493      }
1494   }
1495}
1496
1497
1498static void
1499handle_first_current(struct gl_context *ctx)
1500{
1501   if (ctx->Version == 0 || !ctx->DrawBuffer) {
1502      /* probably in the process of tearing down the context */
1503      return;
1504   }
1505
1506   check_context_limits(ctx);
1507
1508   _mesa_update_vertex_processing_mode(ctx);
1509
1510   /* According to GL_MESA_configless_context the default value of
1511    * glDrawBuffers depends on the config of the first surface it is bound to.
1512    * For GLES it is always GL_BACK which has a magic interpretation.
1513    */
1514   if (!ctx->HasConfig && _mesa_is_desktop_gl(ctx)) {
1515      if (ctx->DrawBuffer != _mesa_get_incomplete_framebuffer()) {
1516         GLenum16 buffer;
1517
1518         if (ctx->DrawBuffer->Visual.doubleBufferMode)
1519            buffer = GL_BACK;
1520         else
1521            buffer = GL_FRONT;
1522
1523         _mesa_drawbuffers(ctx, ctx->DrawBuffer, 1, &buffer,
1524                           NULL /* destMask */);
1525      }
1526
1527      if (ctx->ReadBuffer != _mesa_get_incomplete_framebuffer()) {
1528         gl_buffer_index bufferIndex;
1529         GLenum buffer;
1530
1531         if (ctx->ReadBuffer->Visual.doubleBufferMode) {
1532            buffer = GL_BACK;
1533            bufferIndex = BUFFER_BACK_LEFT;
1534         }
1535         else {
1536            buffer = GL_FRONT;
1537            bufferIndex = BUFFER_FRONT_LEFT;
1538         }
1539
1540         _mesa_readbuffer(ctx, ctx->ReadBuffer, buffer, bufferIndex);
1541      }
1542   }
1543
1544   /* Determine if generic vertex attribute 0 aliases the conventional
1545    * glVertex position.
1546    */
1547   {
1548      const bool is_forward_compatible_context =
1549         ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
1550
1551      /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
1552       * 2.0.  Note that we cannot just check for API_OPENGL_COMPAT here because
1553       * that will erroneously allow this usage in a 3.0 forward-compatible
1554       * context too.
1555       */
1556      ctx->_AttribZeroAliasesVertex = (ctx->API == API_OPENGLES
1557                                       || (ctx->API == API_OPENGL_COMPAT
1558                                           && !is_forward_compatible_context));
1559   }
1560
1561   /* We can use this to help debug user's problems.  Tell them to set
1562    * the MESA_INFO env variable before running their app.  Then the
1563    * first time each context is made current we'll print some useful
1564    * information.
1565    */
1566   if (getenv("MESA_INFO")) {
1567      _mesa_print_info(ctx);
1568   }
1569}
1570
1571/**
1572 * Bind the given context to the given drawBuffer and readBuffer and
1573 * make it the current context for the calling thread.
1574 * We'll render into the drawBuffer and read pixels from the
1575 * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc).
1576 *
1577 * We check that the context's and framebuffer's visuals are compatible
1578 * and return immediately if they're not.
1579 *
1580 * \param newCtx  the new GL context. If NULL then there will be no current GL
1581 *                context.
1582 * \param drawBuffer  the drawing framebuffer
1583 * \param readBuffer  the reading framebuffer
1584 */
1585GLboolean
1586_mesa_make_current( struct gl_context *newCtx,
1587                    struct gl_framebuffer *drawBuffer,
1588                    struct gl_framebuffer *readBuffer )
1589{
1590   GET_CURRENT_CONTEXT(curCtx);
1591
1592   if (MESA_VERBOSE & VERBOSE_API)
1593      _mesa_debug(newCtx, "_mesa_make_current()\n");
1594
1595   /* Check that the context's and framebuffer's visuals are compatible.
1596    */
1597   if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
1598      if (!check_compatible(newCtx, drawBuffer)) {
1599         _mesa_warning(newCtx,
1600              "MakeCurrent: incompatible visuals for context and drawbuffer");
1601         return GL_FALSE;
1602      }
1603   }
1604   if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
1605      if (!check_compatible(newCtx, readBuffer)) {
1606         _mesa_warning(newCtx,
1607              "MakeCurrent: incompatible visuals for context and readbuffer");
1608         return GL_FALSE;
1609      }
1610   }
1611
1612   if (curCtx &&
1613       /* make sure this context is valid for flushing */
1614       curCtx != newCtx &&
1615       curCtx->Const.ContextReleaseBehavior ==
1616       GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH) {
1617      FLUSH_VERTICES(curCtx, 0, 0);
1618      if (curCtx->Driver.Flush)
1619         curCtx->Driver.Flush(curCtx, 0);
1620   }
1621
1622   /* Call this periodically to detect when the user has begun using
1623    * GL rendering from multiple threads.
1624    */
1625   _glapi_check_multithread();
1626
1627   if (!newCtx) {
1628      _glapi_set_dispatch(NULL);  /* none current */
1629      /* We need old ctx to correctly release Draw/ReadBuffer
1630       * and avoid a surface leak in st_renderbuffer_delete.
1631       * Therefore, first drop buffers then set new ctx to NULL.
1632       */
1633      if (curCtx) {
1634         _mesa_reference_framebuffer(&curCtx->WinSysDrawBuffer, NULL);
1635         _mesa_reference_framebuffer(&curCtx->WinSysReadBuffer, NULL);
1636      }
1637      _glapi_set_context(NULL);
1638      assert(_mesa_get_current_context() == NULL);
1639   }
1640   else {
1641      _glapi_set_context((void *) newCtx);
1642      assert(_mesa_get_current_context() == newCtx);
1643      _glapi_set_dispatch(newCtx->CurrentClientDispatch);
1644
1645      if (drawBuffer && readBuffer) {
1646         assert(_mesa_is_winsys_fbo(drawBuffer));
1647         assert(_mesa_is_winsys_fbo(readBuffer));
1648         _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
1649         _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
1650
1651         /*
1652          * Only set the context's Draw/ReadBuffer fields if they're NULL
1653          * or not bound to a user-created FBO.
1654          */
1655         if (!newCtx->DrawBuffer || _mesa_is_winsys_fbo(newCtx->DrawBuffer)) {
1656            _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
1657            /* Update the FBO's list of drawbuffers/renderbuffers.
1658             * For winsys FBOs this comes from the GL state (which may have
1659             * changed since the last time this FBO was bound).
1660             */
1661            _mesa_update_draw_buffers(newCtx);
1662            _mesa_update_allow_draw_out_of_order(newCtx);
1663            _mesa_update_valid_to_render_state(newCtx);
1664         }
1665         if (!newCtx->ReadBuffer || _mesa_is_winsys_fbo(newCtx->ReadBuffer)) {
1666            _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
1667            /* In _mesa_initialize_window_framebuffer, for single-buffered
1668             * visuals, the ColorReadBuffer is set to be GL_FRONT, even with
1669             * GLES contexts. When calling read_buffer, we verify we are reading
1670             * from GL_BACK in is_legal_es3_readbuffer_enum.  But the default is
1671             * incorrect, and certain dEQP tests check this.  So fix it here.
1672             */
1673            if (_mesa_is_gles(newCtx) &&
1674               !newCtx->ReadBuffer->Visual.doubleBufferMode)
1675               if (newCtx->ReadBuffer->ColorReadBuffer == GL_FRONT)
1676                  newCtx->ReadBuffer->ColorReadBuffer = GL_BACK;
1677         }
1678
1679         /* XXX only set this flag if we're really changing the draw/read
1680          * framebuffer bindings.
1681          */
1682         newCtx->NewState |= _NEW_BUFFERS;
1683
1684         check_init_viewport(newCtx, drawBuffer->Width, drawBuffer->Height);
1685      }
1686
1687      if (newCtx->FirstTimeCurrent) {
1688         handle_first_current(newCtx);
1689         newCtx->FirstTimeCurrent = GL_FALSE;
1690      }
1691   }
1692
1693   return GL_TRUE;
1694}
1695
1696
1697/**
1698 * Make context 'ctx' share the display lists, textures and programs
1699 * that are associated with 'ctxToShare'.
1700 * Any display lists, textures or programs associated with 'ctx' will
1701 * be deleted if nobody else is sharing them.
1702 */
1703GLboolean
1704_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare)
1705{
1706   if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
1707      struct gl_shared_state *oldShared = NULL;
1708
1709      /* save ref to old state to prevent it from being deleted immediately */
1710      _mesa_reference_shared_state(ctx, &oldShared, ctx->Shared);
1711
1712      /* update ctx's Shared pointer */
1713      _mesa_reference_shared_state(ctx, &ctx->Shared, ctxToShare->Shared);
1714
1715      update_default_objects(ctx);
1716
1717      /* release the old shared state */
1718      _mesa_reference_shared_state(ctx, &oldShared, NULL);
1719
1720      return GL_TRUE;
1721   }
1722   else {
1723      return GL_FALSE;
1724   }
1725}
1726
1727
1728
1729/**
1730 * \return pointer to the current GL context for this thread.
1731 *
1732 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1733 * context.  If you need speed, see the #GET_CURRENT_CONTEXT macro in
1734 * context.h.
1735 */
1736struct gl_context *
1737_mesa_get_current_context( void )
1738{
1739   return (struct gl_context *) _glapi_get_context();
1740}
1741
1742
1743/**
1744 * Get context's current API dispatch table.
1745 *
1746 * It'll either be the immediate-mode execute dispatcher, the display list
1747 * compile dispatcher, or the thread marshalling dispatcher.
1748 *
1749 * \param ctx GL context.
1750 *
1751 * \return pointer to dispatch_table.
1752 *
1753 * Simply returns __struct gl_contextRec::CurrentClientDispatch.
1754 */
1755struct _glapi_table *
1756_mesa_get_dispatch(struct gl_context *ctx)
1757{
1758   return ctx->CurrentClientDispatch;
1759}
1760
1761/*@}*/
1762
1763
1764/**********************************************************************/
1765/** \name Miscellaneous functions                                     */
1766/**********************************************************************/
1767/*@{*/
1768/**
1769 * Flush commands.
1770 */
1771void
1772_mesa_flush(struct gl_context *ctx)
1773{
1774   FLUSH_VERTICES(ctx, 0, 0);
1775   if (ctx->Driver.Flush) {
1776      bool async = !ctx->Shared->HasExternallySharedImages;
1777
1778      ctx->Driver.Flush(ctx, async ? PIPE_FLUSH_ASYNC : 0);
1779   }
1780}
1781
1782
1783
1784/**
1785 * Flush commands and wait for completion.
1786 *
1787 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1788 * dd_function_table::Finish driver callback, if not NULL.
1789 */
1790void GLAPIENTRY
1791_mesa_Finish(void)
1792{
1793   GET_CURRENT_CONTEXT(ctx);
1794   ASSERT_OUTSIDE_BEGIN_END(ctx);
1795
1796   FLUSH_VERTICES(ctx, 0, 0);
1797
1798   if (ctx->Driver.Finish) {
1799      ctx->Driver.Finish(ctx);
1800   }
1801}
1802
1803
1804/**
1805 * Execute glFlush().
1806 *
1807 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1808 * dd_function_table::Flush driver callback, if not NULL.
1809 */
1810void GLAPIENTRY
1811_mesa_Flush(void)
1812{
1813   GET_CURRENT_CONTEXT(ctx);
1814   ASSERT_OUTSIDE_BEGIN_END(ctx);
1815   _mesa_flush(ctx);
1816}
1817
1818
1819/*@}*/
1820