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";
69 return (const GLubyte
*) "4.60";
72 "Invalid GLSL version in shading_language_version()");
73 return (const GLubyte
*) 0;
78 switch (ctx
->Version
) {
80 return (const GLubyte
*) "OpenGL ES GLSL ES 1.0.16";
82 return (const GLubyte
*) "OpenGL ES GLSL ES 3.00";
84 return (const GLubyte
*) "OpenGL ES GLSL ES 3.10";
86 return (const GLubyte
*) "OpenGL ES GLSL ES 3.20";
89 "Invalid OpenGL ES version in shading_language_version()");
90 return (const GLubyte
*) 0;
96 _mesa_problem(ctx
, "Unexpected API value in shading_language_version()");
97 return (const GLubyte
*) 0;
103 * Query string-valued state. The return value should _not_ be freed by
106 * \param name the state variable to query.
110 * Tries to get the string from dd_function_table::GetString, otherwise returns
111 * the hardcoded strings.
113 const GLubyte
* GLAPIENTRY
114 _mesa_GetString( GLenum name
)
116 GET_CURRENT_CONTEXT(ctx
);
117 static const char *vendor
= "Brian Paul";
118 static const char *renderer
= "Mesa";
123 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
125 /* this is a required driver function */
126 assert(ctx
->Driver
.GetString
);
128 /* Give the driver the chance to handle this query */
129 const GLubyte
*str
= ctx
->Driver
.GetString(ctx
, name
);
136 return (const GLubyte
*) vendor
;
138 return (const GLubyte
*) renderer
;
140 return (const GLubyte
*) ctx
->VersionString
;
142 if (ctx
->API
== API_OPENGL_CORE
) {
143 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetString(GL_EXTENSIONS)");
144 return (const GLubyte
*) 0;
146 return (const GLubyte
*) ctx
->Extensions
.String
;
147 case GL_SHADING_LANGUAGE_VERSION
:
148 if (ctx
->API
== API_OPENGLES
)
150 return shading_language_version(ctx
);
151 case GL_PROGRAM_ERROR_STRING_ARB
:
152 if (ctx
->API
== API_OPENGL_COMPAT
&&
153 (ctx
->Extensions
.ARB_fragment_program
||
154 ctx
->Extensions
.ARB_vertex_program
)) {
155 return (const GLubyte
*) ctx
->Program
.ErrorString
;
162 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetString" );
163 return (const GLubyte
*) 0;
170 const GLubyte
* GLAPIENTRY
171 _mesa_GetStringi(GLenum name
, GLuint index
)
173 GET_CURRENT_CONTEXT(ctx
);
178 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
182 if (index
>= _mesa_get_extension_count(ctx
)) {
183 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetStringi(index=%u)", index
);
184 return (const GLubyte
*) 0;
186 return _mesa_get_enabled_extension(ctx
, index
);
188 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetStringi");
189 return (const GLubyte
*) 0;
196 * Return pointer-valued state, such as a vertex array pointer.
198 * \param pname names state to be queried
199 * \param params returns the pointer value
201 * \sa glGetPointerv().
203 * Tries to get the specified pointer via dd_function_table::GetPointerv,
204 * otherwise gets the specified pointer from the current context.
207 _mesa_GetPointerv( GLenum pname
, GLvoid
**params
)
209 GET_CURRENT_CONTEXT(ctx
);
210 const GLuint clientUnit
= ctx
->Array
.ActiveTexture
;
211 const char *callerstr
;
213 if (_mesa_is_desktop_gl(ctx
))
214 callerstr
= "glGetPointerv";
216 callerstr
= "glGetPointervKHR";
221 if (MESA_VERBOSE
& VERBOSE_API
)
222 _mesa_debug(ctx
, "%s %s\n", callerstr
, _mesa_enum_to_string(pname
));
225 case GL_VERTEX_ARRAY_POINTER
:
226 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
228 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Ptr
;
230 case GL_NORMAL_ARRAY_POINTER
:
231 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
233 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Ptr
;
235 case GL_COLOR_ARRAY_POINTER
:
236 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
238 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Ptr
;
240 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT
:
241 if (ctx
->API
!= API_OPENGL_COMPAT
)
243 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Ptr
;
245 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT
:
246 if (ctx
->API
!= API_OPENGL_COMPAT
)
248 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Ptr
;
250 case GL_INDEX_ARRAY_POINTER
:
251 if (ctx
->API
!= API_OPENGL_COMPAT
)
253 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Ptr
;
255 case GL_TEXTURE_COORD_ARRAY_POINTER
:
256 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
258 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(clientUnit
)].Ptr
;
260 case GL_EDGE_FLAG_ARRAY_POINTER
:
261 if (ctx
->API
!= API_OPENGL_COMPAT
)
263 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Ptr
;
265 case GL_FEEDBACK_BUFFER_POINTER
:
266 if (ctx
->API
!= API_OPENGL_COMPAT
)
268 *params
= ctx
->Feedback
.Buffer
;
270 case GL_SELECTION_BUFFER_POINTER
:
271 if (ctx
->API
!= API_OPENGL_COMPAT
)
273 *params
= ctx
->Select
.Buffer
;
275 case GL_POINT_SIZE_ARRAY_POINTER_OES
:
276 if (ctx
->API
!= API_OPENGLES
)
278 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Ptr
;
280 case GL_DEBUG_CALLBACK_FUNCTION_ARB
:
281 case GL_DEBUG_CALLBACK_USER_PARAM_ARB
:
282 *params
= _mesa_get_debug_state_ptr(ctx
, pname
);
291 _mesa_error( ctx
, GL_INVALID_ENUM
, "%s", callerstr
);
297 * Returns the current GL error code, or GL_NO_ERROR.
298 * \return current error code
300 * Returns __struct gl_contextRec::ErrorValue.
303 _mesa_GetError( void )
305 GET_CURRENT_CONTEXT(ctx
);
306 GLenum e
= ctx
->ErrorValue
;
307 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
309 /* From Issue (3) of the KHR_no_error spec:
311 * "Should glGetError() always return NO_ERROR or have undefined
314 * RESOLVED: It should for all errors except OUT_OF_MEMORY."
316 if (_mesa_is_no_error_enabled(ctx
) && e
!= GL_OUT_OF_MEMORY
) {
320 if (MESA_VERBOSE
& VERBOSE_API
)
321 _mesa_debug(ctx
, "glGetError <-- %s\n", _mesa_enum_to_string(e
));
323 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
324 ctx
->ErrorDebugCount
= 0;