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"
37 * Return the string for a glGetString(GL_SHADING_LANGUAGE_VERSION) query.
39 static const GLubyte
*
40 shading_language_version(struct gl_context
*ctx
)
43 case API_OPENGL_COMPAT
:
45 switch (ctx
->Const
.GLSLVersion
) {
47 return (const GLubyte
*) "1.20";
49 return (const GLubyte
*) "1.30";
51 return (const GLubyte
*) "1.40";
53 return (const GLubyte
*) "1.50";
55 return (const GLubyte
*) "3.30";
57 return (const GLubyte
*) "4.00";
59 return (const GLubyte
*) "4.10";
61 return (const GLubyte
*) "4.20";
63 return (const GLubyte
*) "4.30";
65 return (const GLubyte
*) "4.40";
67 return (const GLubyte
*) "4.50";
70 "Invalid GLSL version in shading_language_version()");
71 return (const GLubyte
*) 0;
76 switch (ctx
->Version
) {
78 return (const GLubyte
*) "OpenGL ES GLSL ES 1.0.16";
80 return (const GLubyte
*) "OpenGL ES GLSL ES 3.00";
82 return (const GLubyte
*) "OpenGL ES GLSL ES 3.10";
85 "Invalid OpenGL ES version in shading_language_version()");
86 return (const GLubyte
*) 0;
92 _mesa_problem(ctx
, "Unexpected API value in shading_language_version()");
93 return (const GLubyte
*) 0;
99 * Query string-valued state. The return value should _not_ be freed by
102 * \param name the state variable to query.
106 * Tries to get the string from dd_function_table::GetString, otherwise returns
107 * the hardcoded strings.
109 const GLubyte
* GLAPIENTRY
110 _mesa_GetString( GLenum name
)
112 GET_CURRENT_CONTEXT(ctx
);
113 static const char *vendor
= "Brian Paul";
114 static const char *renderer
= "Mesa";
119 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
121 /* this is a required driver function */
122 assert(ctx
->Driver
.GetString
);
124 /* Give the driver the chance to handle this query */
125 const GLubyte
*str
= ctx
->Driver
.GetString(ctx
, name
);
132 return (const GLubyte
*) vendor
;
134 return (const GLubyte
*) renderer
;
136 return (const GLubyte
*) ctx
->VersionString
;
138 if (ctx
->API
== API_OPENGL_CORE
) {
139 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetString(GL_EXTENSIONS)");
140 return (const GLubyte
*) 0;
142 return (const GLubyte
*) ctx
->Extensions
.String
;
143 case GL_SHADING_LANGUAGE_VERSION
:
144 if (ctx
->API
== API_OPENGLES
)
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
;
158 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetString" );
159 return (const GLubyte
*) 0;
166 const GLubyte
* GLAPIENTRY
167 _mesa_GetStringi(GLenum name
, GLuint index
)
169 GET_CURRENT_CONTEXT(ctx
);
174 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
178 if (index
>= _mesa_get_extension_count(ctx
)) {
179 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetStringi(index=%u)", index
);
180 return (const GLubyte
*) 0;
182 return _mesa_get_enabled_extension(ctx
, index
);
184 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetStringi");
185 return (const GLubyte
*) 0;
192 * Return pointer-valued state, such as a vertex array pointer.
194 * \param pname names state to be queried
195 * \param params returns the pointer value
197 * \sa glGetPointerv().
199 * Tries to get the specified pointer via dd_function_table::GetPointerv,
200 * otherwise gets the specified pointer from the current context.
203 _mesa_GetPointerv( GLenum pname
, GLvoid
**params
)
205 GET_CURRENT_CONTEXT(ctx
);
206 const GLuint clientUnit
= ctx
->Array
.ActiveTexture
;
207 const char *callerstr
;
209 if (_mesa_is_desktop_gl(ctx
))
210 callerstr
= "glGetPointerv";
212 callerstr
= "glGetPointervKHR";
217 if (MESA_VERBOSE
& VERBOSE_API
)
218 _mesa_debug(ctx
, "%s %s\n", callerstr
, _mesa_enum_to_string(pname
));
221 case GL_VERTEX_ARRAY_POINTER
:
222 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
224 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Ptr
;
226 case GL_NORMAL_ARRAY_POINTER
:
227 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
229 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Ptr
;
231 case GL_COLOR_ARRAY_POINTER
:
232 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
234 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Ptr
;
236 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT
:
237 if (ctx
->API
!= API_OPENGL_COMPAT
)
239 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Ptr
;
241 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT
:
242 if (ctx
->API
!= API_OPENGL_COMPAT
)
244 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Ptr
;
246 case GL_INDEX_ARRAY_POINTER
:
247 if (ctx
->API
!= API_OPENGL_COMPAT
)
249 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Ptr
;
251 case GL_TEXTURE_COORD_ARRAY_POINTER
:
252 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
254 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(clientUnit
)].Ptr
;
256 case GL_EDGE_FLAG_ARRAY_POINTER
:
257 if (ctx
->API
!= API_OPENGL_COMPAT
)
259 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Ptr
;
261 case GL_FEEDBACK_BUFFER_POINTER
:
262 if (ctx
->API
!= API_OPENGL_COMPAT
)
264 *params
= ctx
->Feedback
.Buffer
;
266 case GL_SELECTION_BUFFER_POINTER
:
267 if (ctx
->API
!= API_OPENGL_COMPAT
)
269 *params
= ctx
->Select
.Buffer
;
271 case GL_POINT_SIZE_ARRAY_POINTER_OES
:
272 if (ctx
->API
!= API_OPENGLES
)
274 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Ptr
;
276 case GL_DEBUG_CALLBACK_FUNCTION_ARB
:
277 case GL_DEBUG_CALLBACK_USER_PARAM_ARB
:
278 *params
= _mesa_get_debug_state_ptr(ctx
, pname
);
287 _mesa_error( ctx
, GL_INVALID_ENUM
, "%s", callerstr
);
293 * Returns the current GL error code, or GL_NO_ERROR.
294 * \return current error code
296 * Returns __struct gl_contextRec::ErrorValue.
299 _mesa_GetError( void )
301 GET_CURRENT_CONTEXT(ctx
);
302 GLenum e
= ctx
->ErrorValue
;
303 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
305 if (MESA_VERBOSE
& VERBOSE_API
)
306 _mesa_debug(ctx
, "glGetError <-- %s\n", _mesa_enum_to_string(e
));
308 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
309 ctx
->ErrorDebugCount
= 0;
314 * Returns an error code specified by GL_ARB_robustness, or GL_NO_ERROR.
315 * \return current context status
318 _mesa_GetGraphicsResetStatusARB( void )
320 GET_CURRENT_CONTEXT(ctx
);
321 GLenum status
= GL_NO_ERROR
;
323 /* The ARB_robustness specification says:
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."
329 if (ctx
->Const
.ResetStrategy
== GL_NO_RESET_NOTIFICATION_ARB
) {
330 if (MESA_VERBOSE
& VERBOSE_API
)
332 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
333 "because reset notifictation was not requested at context "
339 if (ctx
->Driver
.GetGraphicsResetStatus
) {
340 /* Query the reset status of this context from the driver core.
342 status
= ctx
->Driver
.GetGraphicsResetStatus(ctx
);
344 mtx_lock(&ctx
->Shared
->Mutex
);
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.
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
;
357 ctx
->ShareGroupReset
= ctx
->Shared
->ShareGroupReset
;
358 mtx_unlock(&ctx
->Shared
->Mutex
);
361 if (!ctx
->Driver
.GetGraphicsResetStatus
&& (MESA_VERBOSE
& VERBOSE_API
))
363 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
364 "because the driver doesn't track reset status.\n");