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