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