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";
84 return (const GLubyte
*) "OpenGL ES GLSL ES 3.20";
87 "Invalid OpenGL ES version in shading_language_version()");
88 return (const GLubyte
*) 0;
94 _mesa_problem(ctx
, "Unexpected API value in shading_language_version()");
95 return (const GLubyte
*) 0;
101 * Query string-valued state. The return value should _not_ be freed by
104 * \param name the state variable to query.
108 * Tries to get the string from dd_function_table::GetString, otherwise returns
109 * the hardcoded strings.
111 const GLubyte
* GLAPIENTRY
112 _mesa_GetString( GLenum name
)
114 GET_CURRENT_CONTEXT(ctx
);
115 static const char *vendor
= "Brian Paul";
116 static const char *renderer
= "Mesa";
121 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
123 /* this is a required driver function */
124 assert(ctx
->Driver
.GetString
);
126 /* Give the driver the chance to handle this query */
127 const GLubyte
*str
= ctx
->Driver
.GetString(ctx
, name
);
134 return (const GLubyte
*) vendor
;
136 return (const GLubyte
*) renderer
;
138 return (const GLubyte
*) ctx
->VersionString
;
140 if (ctx
->API
== API_OPENGL_CORE
) {
141 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetString(GL_EXTENSIONS)");
142 return (const GLubyte
*) 0;
144 return (const GLubyte
*) ctx
->Extensions
.String
;
145 case GL_SHADING_LANGUAGE_VERSION
:
146 if (ctx
->API
== API_OPENGLES
)
148 return shading_language_version(ctx
);
149 case GL_PROGRAM_ERROR_STRING_ARB
:
150 if (ctx
->API
== API_OPENGL_COMPAT
&&
151 (ctx
->Extensions
.ARB_fragment_program
||
152 ctx
->Extensions
.ARB_vertex_program
)) {
153 return (const GLubyte
*) ctx
->Program
.ErrorString
;
160 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetString" );
161 return (const GLubyte
*) 0;
168 const GLubyte
* GLAPIENTRY
169 _mesa_GetStringi(GLenum name
, GLuint index
)
171 GET_CURRENT_CONTEXT(ctx
);
176 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
180 if (index
>= _mesa_get_extension_count(ctx
)) {
181 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetStringi(index=%u)", index
);
182 return (const GLubyte
*) 0;
184 return _mesa_get_enabled_extension(ctx
, index
);
186 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetStringi");
187 return (const GLubyte
*) 0;
194 * Return pointer-valued state, such as a vertex array pointer.
196 * \param pname names state to be queried
197 * \param params returns the pointer value
199 * \sa glGetPointerv().
201 * Tries to get the specified pointer via dd_function_table::GetPointerv,
202 * otherwise gets the specified pointer from the current context.
205 _mesa_GetPointerv( GLenum pname
, GLvoid
**params
)
207 GET_CURRENT_CONTEXT(ctx
);
208 const GLuint clientUnit
= ctx
->Array
.ActiveTexture
;
209 const char *callerstr
;
211 if (_mesa_is_desktop_gl(ctx
))
212 callerstr
= "glGetPointerv";
214 callerstr
= "glGetPointervKHR";
219 if (MESA_VERBOSE
& VERBOSE_API
)
220 _mesa_debug(ctx
, "%s %s\n", callerstr
, _mesa_enum_to_string(pname
));
223 case GL_VERTEX_ARRAY_POINTER
:
224 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
226 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Ptr
;
228 case GL_NORMAL_ARRAY_POINTER
:
229 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
231 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Ptr
;
233 case GL_COLOR_ARRAY_POINTER
:
234 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
236 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Ptr
;
238 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT
:
239 if (ctx
->API
!= API_OPENGL_COMPAT
)
241 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Ptr
;
243 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT
:
244 if (ctx
->API
!= API_OPENGL_COMPAT
)
246 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Ptr
;
248 case GL_INDEX_ARRAY_POINTER
:
249 if (ctx
->API
!= API_OPENGL_COMPAT
)
251 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Ptr
;
253 case GL_TEXTURE_COORD_ARRAY_POINTER
:
254 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
256 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(clientUnit
)].Ptr
;
258 case GL_EDGE_FLAG_ARRAY_POINTER
:
259 if (ctx
->API
!= API_OPENGL_COMPAT
)
261 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Ptr
;
263 case GL_FEEDBACK_BUFFER_POINTER
:
264 if (ctx
->API
!= API_OPENGL_COMPAT
)
266 *params
= ctx
->Feedback
.Buffer
;
268 case GL_SELECTION_BUFFER_POINTER
:
269 if (ctx
->API
!= API_OPENGL_COMPAT
)
271 *params
= ctx
->Select
.Buffer
;
273 case GL_POINT_SIZE_ARRAY_POINTER_OES
:
274 if (ctx
->API
!= API_OPENGLES
)
276 *params
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Ptr
;
278 case GL_DEBUG_CALLBACK_FUNCTION_ARB
:
279 case GL_DEBUG_CALLBACK_USER_PARAM_ARB
:
280 *params
= _mesa_get_debug_state_ptr(ctx
, pname
);
289 _mesa_error( ctx
, GL_INVALID_ENUM
, "%s", callerstr
);
295 * Returns the current GL error code, or GL_NO_ERROR.
296 * \return current error code
298 * Returns __struct gl_contextRec::ErrorValue.
301 _mesa_GetError( void )
303 GET_CURRENT_CONTEXT(ctx
);
304 GLenum e
= ctx
->ErrorValue
;
305 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
307 /* From Issue (3) of the KHR_no_error spec:
309 * "Should glGetError() always return NO_ERROR or have undefined
312 * RESOLVED: It should for all errors except OUT_OF_MEMORY."
314 if (_mesa_is_no_error_enabled(ctx
) && e
!= GL_OUT_OF_MEMORY
) {
318 if (MESA_VERBOSE
& VERBOSE_API
)
319 _mesa_debug(ctx
, "glGetError <-- %s\n", _mesa_enum_to_string(e
));
321 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
322 ctx
->ErrorDebugCount
= 0;