2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "debug_output.h"
32 #include "extensions.h"
36 #include "spirv_extensions.h"
39 * Return the string for a glGetString(GL_SHADING_LANGUAGE_VERSION) query.
41 static const GLubyte
*
42 shading_language_version(struct gl_context
*ctx
)
45 case API_OPENGL_COMPAT
:
47 switch (ctx
->Const
.GLSLVersion
) {
49 return (const GLubyte
*) "1.20";
51 return (const GLubyte
*) "1.30";
53 return (const GLubyte
*) "1.40";
55 return (const GLubyte
*) "1.50";
57 return (const GLubyte
*) "3.30";
59 return (const GLubyte
*) "4.00";
61 return (const GLubyte
*) "4.10";
63 return (const GLubyte
*) "4.20";
65 return (const GLubyte
*) "4.30";
67 return (const GLubyte
*) "4.40";
69 return (const GLubyte
*) "4.50";
71 return (const GLubyte
*) "4.60";
74 "Invalid GLSL version in shading_language_version()");
75 return (const GLubyte
*) 0;
80 switch (ctx
->Version
) {
82 return (const GLubyte
*) "OpenGL ES GLSL ES 1.0.16";
84 return (const GLubyte
*) "OpenGL ES GLSL ES 3.00";
86 return (const GLubyte
*) "OpenGL ES GLSL ES 3.10";
88 return (const GLubyte
*) "OpenGL ES GLSL ES 3.20";
91 "Invalid OpenGL ES version in shading_language_version()");
92 return (const GLubyte
*) 0;
98 _mesa_problem(ctx
, "Unexpected API value in shading_language_version()");
99 return (const GLubyte
*) 0;
105 * Query string-valued state. The return value should _not_ be freed by
108 * \param name the state variable to query.
112 * Tries to get the string from dd_function_table::GetString, otherwise returns
113 * the hardcoded strings.
115 const GLubyte
* GLAPIENTRY
116 _mesa_GetString( GLenum name
)
118 GET_CURRENT_CONTEXT(ctx
);
119 static const char *vendor
= "Brian Paul";
120 static const char *renderer
= "Mesa";
125 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
127 /* this is a required driver function */
128 assert(ctx
->Driver
.GetString
);
130 /* Give the driver the chance to handle this query */
131 const GLubyte
*str
= ctx
->Driver
.GetString(ctx
, name
);
138 return (const GLubyte
*) vendor
;
140 return (const GLubyte
*) renderer
;
142 return (const GLubyte
*) ctx
->VersionString
;
144 if (ctx
->API
== API_OPENGL_CORE
) {
145 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetString(GL_EXTENSIONS)");
146 return (const GLubyte
*) 0;
148 if (!ctx
->Extensions
.String
)
149 ctx
->Extensions
.String
= _mesa_make_extension_string(ctx
);
150 return (const GLubyte
*) ctx
->Extensions
.String
;
151 case GL_SHADING_LANGUAGE_VERSION
:
152 if (ctx
->API
== API_OPENGLES
)
154 return shading_language_version(ctx
);
155 case GL_PROGRAM_ERROR_STRING_ARB
:
156 if (ctx
->API
== API_OPENGL_COMPAT
&&
157 (ctx
->Extensions
.ARB_fragment_program
||
158 ctx
->Extensions
.ARB_vertex_program
)) {
159 return (const GLubyte
*) ctx
->Program
.ErrorString
;
166 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetString" );
167 return (const GLubyte
*) 0;
174 const GLubyte
* GLAPIENTRY
175 _mesa_GetStringi(GLenum name
, GLuint index
)
177 GET_CURRENT_CONTEXT(ctx
);
182 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
186 if (index
>= _mesa_get_extension_count(ctx
)) {
187 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetStringi(index=%u)", index
);
188 return (const GLubyte
*) 0;
190 return _mesa_get_enabled_extension(ctx
, index
);
191 case GL_SHADING_LANGUAGE_VERSION
:
195 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 43) {
196 _mesa_error(ctx
, GL_INVALID_ENUM
,
197 "glGetStringi(GL_SHADING_LANGUAGE_VERSION): "
198 "supported only in GL4.3 and later");
199 return (const GLubyte
*) 0;
201 num
= _mesa_get_shading_language_version(ctx
, index
, &version
);
203 _mesa_error(ctx
, GL_INVALID_VALUE
,
204 "glGetStringi(GL_SHADING_LANGUAGE_VERSION, index=%d)",
206 return (const GLubyte
*) 0;
208 return (const GLubyte
*) version
;
210 case GL_SPIR_V_EXTENSIONS
:
211 if (!ctx
->Extensions
.ARB_spirv_extensions
) {
212 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetStringi");
213 return (const GLubyte
*) 0;
216 if (index
>= _mesa_get_spirv_extension_count(ctx
)) {
217 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetStringi(index=%u)", index
);
218 return (const GLubyte
*) 0;
220 return _mesa_get_enabled_spirv_extension(ctx
, index
);
223 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetStringi");
224 return (const GLubyte
*) 0;
231 * Return pointer-valued state, such as a vertex array pointer.
233 * \param pname names state to be queried
234 * \param params returns the pointer value
236 * \sa glGetPointerv().
238 * Tries to get the specified pointer via dd_function_table::GetPointerv,
239 * otherwise gets the specified pointer from the current context.
242 _mesa_GetPointerv( GLenum pname
, GLvoid
**params
)
244 GET_CURRENT_CONTEXT(ctx
);
245 const GLuint clientUnit
= ctx
->Array
.ActiveTexture
;
246 const char *callerstr
;
248 if (_mesa_is_desktop_gl(ctx
))
249 callerstr
= "glGetPointerv";
251 callerstr
= "glGetPointervKHR";
256 if (MESA_VERBOSE
& VERBOSE_API
)
257 _mesa_debug(ctx
, "%s %s\n", callerstr
, _mesa_enum_to_string(pname
));
260 case GL_VERTEX_ARRAY_POINTER
:
261 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
263 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Ptr
;
265 case GL_NORMAL_ARRAY_POINTER
:
266 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
268 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Ptr
;
270 case GL_COLOR_ARRAY_POINTER
:
271 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
273 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Ptr
;
275 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT
:
276 if (ctx
->API
!= API_OPENGL_COMPAT
)
278 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Ptr
;
280 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT
:
281 if (ctx
->API
!= API_OPENGL_COMPAT
)
283 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Ptr
;
285 case GL_INDEX_ARRAY_POINTER
:
286 if (ctx
->API
!= API_OPENGL_COMPAT
)
288 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Ptr
;
290 case GL_TEXTURE_COORD_ARRAY_POINTER
:
291 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
293 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(clientUnit
)].Ptr
;
295 case GL_EDGE_FLAG_ARRAY_POINTER
:
296 if (ctx
->API
!= API_OPENGL_COMPAT
)
298 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Ptr
;
300 case GL_FEEDBACK_BUFFER_POINTER
:
301 if (ctx
->API
!= API_OPENGL_COMPAT
)
303 *params
= ctx
->Feedback
.Buffer
;
305 case GL_SELECTION_BUFFER_POINTER
:
306 if (ctx
->API
!= API_OPENGL_COMPAT
)
308 *params
= ctx
->Select
.Buffer
;
310 case GL_POINT_SIZE_ARRAY_POINTER_OES
:
311 if (ctx
->API
!= API_OPENGLES
)
313 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Ptr
;
315 case GL_DEBUG_CALLBACK_FUNCTION_ARB
:
316 case GL_DEBUG_CALLBACK_USER_PARAM_ARB
:
317 *params
= _mesa_get_debug_state_ptr(ctx
, pname
);
326 _mesa_error( ctx
, GL_INVALID_ENUM
, "%s", callerstr
);
332 * Returns the current GL error code, or GL_NO_ERROR.
333 * \return current error code
335 * Returns __struct gl_contextRec::ErrorValue.
338 _mesa_GetError( void )
340 GET_CURRENT_CONTEXT(ctx
);
341 GLenum e
= ctx
->ErrorValue
;
342 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
344 /* From Issue (3) of the KHR_no_error spec:
346 * "Should glGetError() always return NO_ERROR or have undefined
349 * RESOLVED: It should for all errors except OUT_OF_MEMORY."
351 if (_mesa_is_no_error_enabled(ctx
) && e
!= GL_OUT_OF_MEMORY
) {
355 if (MESA_VERBOSE
& VERBOSE_API
)
356 _mesa_debug(ctx
, "glGetError <-- %s\n", _mesa_enum_to_string(e
));
358 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
359 ctx
->ErrorDebugCount
= 0;