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