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.
31 #include "extensions.h"
36 * Return the string for a glGetString(GL_SHADING_LANGUAGE_VERSION) query.
38 static const GLubyte
*
39 shading_language_version(struct gl_context
*ctx
)
42 case API_OPENGL_COMPAT
:
44 switch (ctx
->Const
.GLSLVersion
) {
46 return (const GLubyte
*) "1.20";
48 return (const GLubyte
*) "1.30";
50 return (const GLubyte
*) "1.40";
52 return (const GLubyte
*) "1.50";
54 return (const GLubyte
*) "3.30";
56 return (const GLubyte
*) "4.00";
58 return (const GLubyte
*) "4.10";
60 return (const GLubyte
*) "4.20";
62 return (const GLubyte
*) "4.30";
64 return (const GLubyte
*) "4.40";
66 return (const GLubyte
*) "4.50";
69 "Invalid GLSL version in shading_language_version()");
70 return (const GLubyte
*) 0;
75 switch (ctx
->Version
) {
77 return (const GLubyte
*) "OpenGL ES GLSL ES 1.0.16";
79 return (const GLubyte
*) "OpenGL ES GLSL ES 3.00";
81 return (const GLubyte
*) "OpenGL ES GLSL ES 3.10";
84 "Invalid OpenGL ES version in shading_language_version()");
85 return (const GLubyte
*) 0;
91 _mesa_problem(ctx
, "Unexpected API value in shading_language_version()");
92 return (const GLubyte
*) 0;
98 * Query string-valued state. The return value should _not_ be freed by
101 * \param name the state variable to query.
105 * Tries to get the string from dd_function_table::GetString, otherwise returns
106 * the hardcoded strings.
108 const GLubyte
* GLAPIENTRY
109 _mesa_GetString( GLenum name
)
111 GET_CURRENT_CONTEXT(ctx
);
112 static const char *vendor
= "Brian Paul";
113 static const char *renderer
= "Mesa";
118 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
120 /* this is a required driver function */
121 assert(ctx
->Driver
.GetString
);
123 /* Give the driver the chance to handle this query */
124 const GLubyte
*str
= (*ctx
->Driver
.GetString
)(ctx
, name
);
131 return (const GLubyte
*) vendor
;
133 return (const GLubyte
*) renderer
;
135 return (const GLubyte
*) ctx
->VersionString
;
137 if (ctx
->API
== API_OPENGL_CORE
) {
138 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetString(GL_EXTENSIONS)");
139 return (const GLubyte
*) 0;
141 return (const GLubyte
*) ctx
->Extensions
.String
;
142 case GL_SHADING_LANGUAGE_VERSION
:
143 if (ctx
->API
== API_OPENGLES
)
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
;
157 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetString" );
158 return (const GLubyte
*) 0;
165 const GLubyte
* GLAPIENTRY
166 _mesa_GetStringi(GLenum name
, GLuint index
)
168 GET_CURRENT_CONTEXT(ctx
);
173 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
177 if (index
>= _mesa_get_extension_count(ctx
)) {
178 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetStringi(index=%u)", index
);
179 return (const GLubyte
*) 0;
181 return _mesa_get_enabled_extension(ctx
, index
);
183 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetStringi");
184 return (const GLubyte
*) 0;
191 * Return pointer-valued state, such as a vertex array pointer.
193 * \param pname names state to be queried
194 * \param params returns the pointer value
196 * \sa glGetPointerv().
198 * Tries to get the specified pointer via dd_function_table::GetPointerv,
199 * otherwise gets the specified pointer from the current context.
202 _mesa_GetPointerv( GLenum pname
, GLvoid
**params
)
204 GET_CURRENT_CONTEXT(ctx
);
205 const GLuint clientUnit
= ctx
->Array
.ActiveTexture
;
210 if (MESA_VERBOSE
& VERBOSE_API
)
211 _mesa_debug(ctx
, "glGetPointerv %s\n", _mesa_lookup_enum_by_nr(pname
));
214 case GL_VERTEX_ARRAY_POINTER
:
215 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
217 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Ptr
;
219 case GL_NORMAL_ARRAY_POINTER
:
220 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
222 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Ptr
;
224 case GL_COLOR_ARRAY_POINTER
:
225 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
227 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Ptr
;
229 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT
:
230 if (ctx
->API
!= API_OPENGL_COMPAT
)
232 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Ptr
;
234 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT
:
235 if (ctx
->API
!= API_OPENGL_COMPAT
)
237 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Ptr
;
239 case GL_INDEX_ARRAY_POINTER
:
240 if (ctx
->API
!= API_OPENGL_COMPAT
)
242 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Ptr
;
244 case GL_TEXTURE_COORD_ARRAY_POINTER
:
245 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
247 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(clientUnit
)].Ptr
;
249 case GL_EDGE_FLAG_ARRAY_POINTER
:
250 if (ctx
->API
!= API_OPENGL_COMPAT
)
252 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Ptr
;
254 case GL_FEEDBACK_BUFFER_POINTER
:
255 if (ctx
->API
!= API_OPENGL_COMPAT
)
257 *params
= ctx
->Feedback
.Buffer
;
259 case GL_SELECTION_BUFFER_POINTER
:
260 if (ctx
->API
!= API_OPENGL_COMPAT
)
262 *params
= ctx
->Select
.Buffer
;
264 case GL_POINT_SIZE_ARRAY_POINTER_OES
:
265 if (ctx
->API
!= API_OPENGLES
)
267 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Ptr
;
269 case GL_DEBUG_CALLBACK_FUNCTION_ARB
:
270 case GL_DEBUG_CALLBACK_USER_PARAM_ARB
:
271 if (!_mesa_is_desktop_gl(ctx
))
274 *params
= _mesa_get_debug_state_ptr(ctx
, pname
);
283 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetPointerv" );
289 * Returns the current GL error code, or GL_NO_ERROR.
290 * \return current error code
292 * Returns __struct gl_contextRec::ErrorValue.
295 _mesa_GetError( void )
297 GET_CURRENT_CONTEXT(ctx
);
298 GLenum e
= ctx
->ErrorValue
;
299 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
301 if (MESA_VERBOSE
& VERBOSE_API
)
302 _mesa_debug(ctx
, "glGetError <-- %s\n", _mesa_lookup_enum_by_nr(e
));
304 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
305 ctx
->ErrorDebugCount
= 0;
310 * Returns an error code specified by GL_ARB_robustness, or GL_NO_ERROR.
311 * \return current context status
314 _mesa_GetGraphicsResetStatusARB( void )
316 GET_CURRENT_CONTEXT(ctx
);
317 GLenum status
= GL_NO_ERROR
;
319 /* The ARB_robustness specification says:
321 * "If the reset notification behavior is NO_RESET_NOTIFICATION_ARB,
322 * then the implementation will never deliver notification of reset
323 * events, and GetGraphicsResetStatusARB will always return NO_ERROR."
325 if (ctx
->Const
.ResetStrategy
== GL_NO_RESET_NOTIFICATION_ARB
) {
326 if (MESA_VERBOSE
& VERBOSE_API
)
328 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
329 "because reset notifictation was not requested at context "
335 if (ctx
->Driver
.GetGraphicsResetStatus
) {
336 /* Query the reset status of this context from the driver core.
338 status
= ctx
->Driver
.GetGraphicsResetStatus(ctx
);
340 mtx_lock(&ctx
->Shared
->Mutex
);
342 /* If this context has not been affected by a GPU reset, check to see if
343 * some other context in the share group has been affected by a reset.
344 * If another context saw a reset but this context did not, assume that
345 * this context was not guilty.
347 if (status
!= GL_NO_ERROR
) {
348 ctx
->Shared
->ShareGroupReset
= true;
349 } else if (ctx
->Shared
->ShareGroupReset
&& !ctx
->ShareGroupReset
) {
350 status
= GL_INNOCENT_CONTEXT_RESET_ARB
;
353 ctx
->ShareGroupReset
= ctx
->Shared
->ShareGroupReset
;
354 mtx_unlock(&ctx
->Shared
->Mutex
);
357 if (!ctx
->Driver
.GetGraphicsResetStatus
&& (MESA_VERBOSE
& VERBOSE_API
))
359 "glGetGraphicsResetStatusARB always returns GL_NO_ERROR "
360 "because the driver doesn't track reset status.\n");