mesa: use the correct string for the ES GL_KHR_debug functions
[mesa.git] / src / mesa / main / getstring.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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.
23 */
24
25
26 #include <stdbool.h>
27 #include "glheader.h"
28 #include "context.h"
29 #include "get.h"
30 #include "enums.h"
31 #include "extensions.h"
32 #include "mtypes.h"
33
34
35 /**
36 * Return the string for a glGetString(GL_SHADING_LANGUAGE_VERSION) query.
37 */
38 static const GLubyte *
39 shading_language_version(struct gl_context *ctx)
40 {
41 switch (ctx->API) {
42 case API_OPENGL_COMPAT:
43 case API_OPENGL_CORE:
44 switch (ctx->Const.GLSLVersion) {
45 case 120:
46 return (const GLubyte *) "1.20";
47 case 130:
48 return (const GLubyte *) "1.30";
49 case 140:
50 return (const GLubyte *) "1.40";
51 case 150:
52 return (const GLubyte *) "1.50";
53 case 330:
54 return (const GLubyte *) "3.30";
55 case 400:
56 return (const GLubyte *) "4.00";
57 case 410:
58 return (const GLubyte *) "4.10";
59 case 420:
60 return (const GLubyte *) "4.20";
61 case 430:
62 return (const GLubyte *) "4.30";
63 case 440:
64 return (const GLubyte *) "4.40";
65 case 450:
66 return (const GLubyte *) "4.50";
67 default:
68 _mesa_problem(ctx,
69 "Invalid GLSL version in shading_language_version()");
70 return (const GLubyte *) 0;
71 }
72 break;
73
74 case API_OPENGLES2:
75 switch (ctx->Version) {
76 case 20:
77 return (const GLubyte *) "OpenGL ES GLSL ES 1.0.16";
78 case 30:
79 return (const GLubyte *) "OpenGL ES GLSL ES 3.00";
80 case 31:
81 return (const GLubyte *) "OpenGL ES GLSL ES 3.10";
82 default:
83 _mesa_problem(ctx,
84 "Invalid OpenGL ES version in shading_language_version()");
85 return (const GLubyte *) 0;
86 }
87 case API_OPENGLES:
88 /* fall-through */
89
90 default:
91 _mesa_problem(ctx, "Unexpected API value in shading_language_version()");
92 return (const GLubyte *) 0;
93 }
94 }
95
96
97 /**
98 * Query string-valued state. The return value should _not_ be freed by
99 * the caller.
100 *
101 * \param name the state variable to query.
102 *
103 * \sa glGetString().
104 *
105 * Tries to get the string from dd_function_table::GetString, otherwise returns
106 * the hardcoded strings.
107 */
108 const GLubyte * GLAPIENTRY
109 _mesa_GetString( GLenum name )
110 {
111 GET_CURRENT_CONTEXT(ctx);
112 static const char *vendor = "Brian Paul";
113 static const char *renderer = "Mesa";
114
115 if (!ctx)
116 return NULL;
117
118 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
119
120 /* this is a required driver function */
121 assert(ctx->Driver.GetString);
122 {
123 /* Give the driver the chance to handle this query */
124 const GLubyte *str = (*ctx->Driver.GetString)(ctx, name);
125 if (str)
126 return str;
127 }
128
129 switch (name) {
130 case GL_VENDOR:
131 return (const GLubyte *) vendor;
132 case GL_RENDERER:
133 return (const GLubyte *) renderer;
134 case GL_VERSION:
135 return (const GLubyte *) ctx->VersionString;
136 case GL_EXTENSIONS:
137 if (ctx->API == API_OPENGL_CORE) {
138 _mesa_error(ctx, GL_INVALID_ENUM, "glGetString(GL_EXTENSIONS)");
139 return (const GLubyte *) 0;
140 }
141 return (const GLubyte *) ctx->Extensions.String;
142 case GL_SHADING_LANGUAGE_VERSION:
143 if (ctx->API == API_OPENGLES)
144 break;
145 return shading_language_version(ctx);
146 case GL_PROGRAM_ERROR_STRING_ARB:
147 if (ctx->API == API_OPENGL_COMPAT &&
148 (ctx->Extensions.ARB_fragment_program ||
149 ctx->Extensions.ARB_vertex_program)) {
150 return (const GLubyte *) ctx->Program.ErrorString;
151 }
152 break;
153 default:
154 break;
155 }
156
157 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
158 return (const GLubyte *) 0;
159 }
160
161
162 /**
163 * GL3
164 */
165 const GLubyte * GLAPIENTRY
166 _mesa_GetStringi(GLenum name, GLuint index)
167 {
168 GET_CURRENT_CONTEXT(ctx);
169
170 if (!ctx)
171 return NULL;
172
173 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
174
175 switch (name) {
176 case GL_EXTENSIONS:
177 if (index >= _mesa_get_extension_count(ctx)) {
178 _mesa_error(ctx, GL_INVALID_VALUE, "glGetStringi(index=%u)", index);
179 return (const GLubyte *) 0;
180 }
181 return _mesa_get_enabled_extension(ctx, index);
182 default:
183 _mesa_error(ctx, GL_INVALID_ENUM, "glGetStringi");
184 return (const GLubyte *) 0;
185 }
186 }
187
188
189
190 /**
191 * Return pointer-valued state, such as a vertex array pointer.
192 *
193 * \param pname names state to be queried
194 * \param params returns the pointer value
195 *
196 * \sa glGetPointerv().
197 *
198 * Tries to get the specified pointer via dd_function_table::GetPointerv,
199 * otherwise gets the specified pointer from the current context.
200 */
201 void GLAPIENTRY
202 _mesa_GetPointerv( GLenum pname, GLvoid **params )
203 {
204 GET_CURRENT_CONTEXT(ctx);
205 const GLuint clientUnit = ctx->Array.ActiveTexture;
206 const char *callerstr;
207
208 if (_mesa_is_desktop_gl(ctx))
209 callerstr = "glGetPointerv";
210 else
211 callerstr = "glGetPointervKHR";
212
213 if (!params)
214 return;
215
216 if (MESA_VERBOSE & VERBOSE_API)
217 _mesa_debug(ctx, "%s %s\n", callerstr, _mesa_enum_to_string(pname));
218
219 switch (pname) {
220 case GL_VERTEX_ARRAY_POINTER:
221 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
222 goto invalid_pname;
223 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Ptr;
224 break;
225 case GL_NORMAL_ARRAY_POINTER:
226 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
227 goto invalid_pname;
228 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Ptr;
229 break;
230 case GL_COLOR_ARRAY_POINTER:
231 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
232 goto invalid_pname;
233 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Ptr;
234 break;
235 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT:
236 if (ctx->API != API_OPENGL_COMPAT)
237 goto invalid_pname;
238 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Ptr;
239 break;
240 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT:
241 if (ctx->API != API_OPENGL_COMPAT)
242 goto invalid_pname;
243 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Ptr;
244 break;
245 case GL_INDEX_ARRAY_POINTER:
246 if (ctx->API != API_OPENGL_COMPAT)
247 goto invalid_pname;
248 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Ptr;
249 break;
250 case GL_TEXTURE_COORD_ARRAY_POINTER:
251 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
252 goto invalid_pname;
253 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(clientUnit)].Ptr;
254 break;
255 case GL_EDGE_FLAG_ARRAY_POINTER:
256 if (ctx->API != API_OPENGL_COMPAT)
257 goto invalid_pname;
258 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Ptr;
259 break;
260 case GL_FEEDBACK_BUFFER_POINTER:
261 if (ctx->API != API_OPENGL_COMPAT)
262 goto invalid_pname;
263 *params = ctx->Feedback.Buffer;
264 break;
265 case GL_SELECTION_BUFFER_POINTER:
266 if (ctx->API != API_OPENGL_COMPAT)
267 goto invalid_pname;
268 *params = ctx->Select.Buffer;
269 break;
270 case GL_POINT_SIZE_ARRAY_POINTER_OES:
271 if (ctx->API != API_OPENGLES)
272 goto invalid_pname;
273 *params = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Ptr;
274 break;
275 case GL_DEBUG_CALLBACK_FUNCTION_ARB:
276 case GL_DEBUG_CALLBACK_USER_PARAM_ARB:
277 if (!_mesa_is_desktop_gl(ctx))
278 goto invalid_pname;
279 else
280 *params = _mesa_get_debug_state_ptr(ctx, pname);
281 break;
282 default:
283 goto invalid_pname;
284 }
285
286 return;
287
288 invalid_pname:
289 _mesa_error( ctx, GL_INVALID_ENUM, "%s", callerstr);
290 return;
291 }
292
293
294 /**
295 * Returns the current GL error code, or GL_NO_ERROR.
296 * \return current error code
297 *
298 * Returns __struct gl_contextRec::ErrorValue.
299 */
300 GLenum GLAPIENTRY
301 _mesa_GetError( void )
302 {
303 GET_CURRENT_CONTEXT(ctx);
304 GLenum e = ctx->ErrorValue;
305 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
306
307 if (MESA_VERBOSE & VERBOSE_API)
308 _mesa_debug(ctx, "glGetError <-- %s\n", _mesa_enum_to_string(e));
309
310 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
311 ctx->ErrorDebugCount = 0;
312 return e;
313 }
314
315 /**
316 * Returns an error code specified by GL_ARB_robustness, or GL_NO_ERROR.
317 * \return current context status
318 */
319 GLenum GLAPIENTRY
320 _mesa_GetGraphicsResetStatusARB( void )
321 {
322 GET_CURRENT_CONTEXT(ctx);
323 GLenum status = GL_NO_ERROR;
324
325 /* The ARB_robustness specification says:
326 *
327 * "If the reset notification behavior is NO_RESET_NOTIFICATION_ARB,
328 * then the implementation will never deliver notification of reset
329 * events, and GetGraphicsResetStatusARB will always return NO_ERROR."
330 */
331 if (ctx->Const.ResetStrategy == GL_NO_RESET_NOTIFICATION_ARB) {
332 if (MESA_VERBOSE & VERBOSE_API)
333 _mesa_debug(ctx,
334 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
335 "because reset notifictation was not requested at context "
336 "creation.\n");
337
338 return GL_NO_ERROR;
339 }
340
341 if (ctx->Driver.GetGraphicsResetStatus) {
342 /* Query the reset status of this context from the driver core.
343 */
344 status = ctx->Driver.GetGraphicsResetStatus(ctx);
345
346 mtx_lock(&ctx->Shared->Mutex);
347
348 /* If this context has not been affected by a GPU reset, check to see if
349 * some other context in the share group has been affected by a reset.
350 * If another context saw a reset but this context did not, assume that
351 * this context was not guilty.
352 */
353 if (status != GL_NO_ERROR) {
354 ctx->Shared->ShareGroupReset = true;
355 } else if (ctx->Shared->ShareGroupReset && !ctx->ShareGroupReset) {
356 status = GL_INNOCENT_CONTEXT_RESET_ARB;
357 }
358
359 ctx->ShareGroupReset = ctx->Shared->ShareGroupReset;
360 mtx_unlock(&ctx->Shared->Mutex);
361 }
362
363 if (!ctx->Driver.GetGraphicsResetStatus && (MESA_VERBOSE & VERBOSE_API))
364 _mesa_debug(ctx,
365 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
366 "because the driver doesn't track reset status.\n");
367
368 return status;
369 }