mesa: remove outdated version lines in comments
[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
27 #include "glheader.h"
28 #include "context.h"
29 #include "get.h"
30 #include "enums.h"
31 #include "extensions.h"
32 #include "mtypes.h"
33
34
35 /**
36 * Return the string for a glGetString(GL_SHADING_LANGUAGE_VERSION) query.
37 */
38 static const GLubyte *
39 shading_language_version(struct gl_context *ctx)
40 {
41 switch (ctx->API) {
42 case API_OPENGL_COMPAT:
43 case API_OPENGL_CORE:
44 if (!ctx->Extensions.ARB_shader_objects) {
45 _mesa_error(ctx, GL_INVALID_ENUM, "glGetString");
46 return (const GLubyte *) 0;
47 }
48
49 switch (ctx->Const.GLSLVersion) {
50 case 110:
51 return (const GLubyte *) "1.10";
52 case 120:
53 return (const GLubyte *) "1.20";
54 case 130:
55 return (const GLubyte *) "1.30";
56 case 140:
57 return (const GLubyte *) "1.40";
58 case 150:
59 return (const GLubyte *) "1.50";
60 case 330:
61 return (const GLubyte *) "3.30";
62 case 400:
63 return (const GLubyte *) "4.00";
64 case 410:
65 return (const GLubyte *) "4.10";
66 case 420:
67 return (const GLubyte *) "4.20";
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 return (ctx->Version < 30)
77 ? (const GLubyte *) "OpenGL ES GLSL ES 1.0.16"
78 : (const GLubyte *) "OpenGL ES GLSL ES 3.0";
79
80 case API_OPENGLES:
81 /* fall-through */
82
83 default:
84 _mesa_problem(ctx, "Unexpected API value in shading_language_version()");
85 return (const GLubyte *) 0;
86 }
87 }
88
89
90 /**
91 * Query string-valued state. The return value should _not_ be freed by
92 * the caller.
93 *
94 * \param name the state variable to query.
95 *
96 * \sa glGetString().
97 *
98 * Tries to get the string from dd_function_table::GetString, otherwise returns
99 * the hardcoded strings.
100 */
101 const GLubyte * GLAPIENTRY
102 _mesa_GetString( GLenum name )
103 {
104 GET_CURRENT_CONTEXT(ctx);
105 static const char *vendor = "Brian Paul";
106 static const char *renderer = "Mesa";
107
108 if (!ctx)
109 return NULL;
110
111 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
112
113 /* this is a required driver function */
114 assert(ctx->Driver.GetString);
115 {
116 /* Give the driver the chance to handle this query */
117 const GLubyte *str = (*ctx->Driver.GetString)(ctx, name);
118 if (str)
119 return str;
120 }
121
122 switch (name) {
123 case GL_VENDOR:
124 return (const GLubyte *) vendor;
125 case GL_RENDERER:
126 return (const GLubyte *) renderer;
127 case GL_VERSION:
128 return (const GLubyte *) ctx->VersionString;
129 case GL_EXTENSIONS:
130 if (ctx->API == API_OPENGL_CORE) {
131 _mesa_error(ctx, GL_INVALID_ENUM, "glGetString(GL_EXTENSIONS)");
132 return (const GLubyte *) 0;
133 }
134 return (const GLubyte *) ctx->Extensions.String;
135 case GL_SHADING_LANGUAGE_VERSION:
136 if (ctx->API == API_OPENGLES)
137 break;
138 return shading_language_version(ctx);
139 case GL_PROGRAM_ERROR_STRING_ARB:
140 if (ctx->API == API_OPENGL_COMPAT &&
141 (ctx->Extensions.ARB_fragment_program ||
142 ctx->Extensions.ARB_vertex_program)) {
143 return (const GLubyte *) ctx->Program.ErrorString;
144 }
145 break;
146 default:
147 break;
148 }
149
150 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
151 return (const GLubyte *) 0;
152 }
153
154
155 /**
156 * GL3
157 */
158 const GLubyte * GLAPIENTRY
159 _mesa_GetStringi(GLenum name, GLuint index)
160 {
161 GET_CURRENT_CONTEXT(ctx);
162
163 if (!ctx)
164 return NULL;
165
166 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
167
168 switch (name) {
169 case GL_EXTENSIONS:
170 if (index >= _mesa_get_extension_count(ctx)) {
171 _mesa_error(ctx, GL_INVALID_VALUE, "glGetStringi(index=%u)", index);
172 return (const GLubyte *) 0;
173 }
174 return _mesa_get_enabled_extension(ctx, index);
175 default:
176 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
177 return (const GLubyte *) 0;
178 }
179 }
180
181
182
183 /**
184 * Return pointer-valued state, such as a vertex array pointer.
185 *
186 * \param pname names state to be queried
187 * \param params returns the pointer value
188 *
189 * \sa glGetPointerv().
190 *
191 * Tries to get the specified pointer via dd_function_table::GetPointerv,
192 * otherwise gets the specified pointer from the current context.
193 */
194 void GLAPIENTRY
195 _mesa_GetPointerv( GLenum pname, GLvoid **params )
196 {
197 GET_CURRENT_CONTEXT(ctx);
198 const GLuint clientUnit = ctx->Array.ActiveTexture;
199
200 if (!params)
201 return;
202
203 if (MESA_VERBOSE & VERBOSE_API)
204 _mesa_debug(ctx, "glGetPointerv %s\n", _mesa_lookup_enum_by_nr(pname));
205
206 switch (pname) {
207 case GL_VERTEX_ARRAY_POINTER:
208 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
209 goto invalid_pname;
210 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Ptr;
211 break;
212 case GL_NORMAL_ARRAY_POINTER:
213 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
214 goto invalid_pname;
215 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Ptr;
216 break;
217 case GL_COLOR_ARRAY_POINTER:
218 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
219 goto invalid_pname;
220 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Ptr;
221 break;
222 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT:
223 if (ctx->API != API_OPENGL_COMPAT)
224 goto invalid_pname;
225 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Ptr;
226 break;
227 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT:
228 if (ctx->API != API_OPENGL_COMPAT)
229 goto invalid_pname;
230 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Ptr;
231 break;
232 case GL_INDEX_ARRAY_POINTER:
233 if (ctx->API != API_OPENGL_COMPAT)
234 goto invalid_pname;
235 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Ptr;
236 break;
237 case GL_TEXTURE_COORD_ARRAY_POINTER:
238 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
239 goto invalid_pname;
240 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(clientUnit)].Ptr;
241 break;
242 case GL_EDGE_FLAG_ARRAY_POINTER:
243 if (ctx->API != API_OPENGL_COMPAT)
244 goto invalid_pname;
245 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Ptr;
246 break;
247 case GL_FEEDBACK_BUFFER_POINTER:
248 if (ctx->API != API_OPENGL_COMPAT)
249 goto invalid_pname;
250 *params = ctx->Feedback.Buffer;
251 break;
252 case GL_SELECTION_BUFFER_POINTER:
253 if (ctx->API != API_OPENGL_COMPAT)
254 goto invalid_pname;
255 *params = ctx->Select.Buffer;
256 break;
257 case GL_POINT_SIZE_ARRAY_POINTER_OES:
258 if (ctx->API != API_OPENGLES)
259 goto invalid_pname;
260 *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Ptr;
261 break;
262 case GL_DEBUG_CALLBACK_FUNCTION_ARB:
263 if (!_mesa_is_desktop_gl(ctx))
264 goto invalid_pname;
265 *params = (GLvoid *) ctx->Debug.Callback;
266 break;
267 case GL_DEBUG_CALLBACK_USER_PARAM_ARB:
268 if (!_mesa_is_desktop_gl(ctx))
269 goto invalid_pname;
270 *params = ctx->Debug.CallbackData;
271 break;
272 default:
273 goto invalid_pname;
274 }
275
276 return;
277
278 invalid_pname:
279 _mesa_error( ctx, GL_INVALID_ENUM, "glGetPointerv" );
280 return;
281 }
282
283
284 /**
285 * Returns the current GL error code, or GL_NO_ERROR.
286 * \return current error code
287 *
288 * Returns __struct gl_contextRec::ErrorValue.
289 */
290 GLenum GLAPIENTRY
291 _mesa_GetError( void )
292 {
293 GET_CURRENT_CONTEXT(ctx);
294 GLenum e = ctx->ErrorValue;
295 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
296
297 if (MESA_VERBOSE & VERBOSE_API)
298 _mesa_debug(ctx, "glGetError <-- %s\n", _mesa_lookup_enum_by_nr(e));
299
300 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
301 ctx->ErrorDebugCount = 0;
302 return e;
303 }
304
305 /**
306 * Returns an error code specified by GL_ARB_robustness, or GL_NO_ERROR.
307 * \return current context status
308 */
309 GLenum GLAPIENTRY
310 _mesa_GetGraphicsResetStatusARB( void )
311 {
312 GET_CURRENT_CONTEXT(ctx);
313 GLenum status = ctx->ResetStatus;
314
315 if (MESA_VERBOSE & VERBOSE_API)
316 _mesa_debug(ctx, "glGetGraphicsResetStatusARB"
317 "(always returns GL_NO_ERROR)\n");
318
319 return status;
320 }