Merge branch 'master' into drm-gem
[mesa.git] / src / mesa / main / getstring.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26
27 #include "glheader.h"
28 #include "colormac.h"
29 #include "context.h"
30 #include "get.h"
31 #include "version.h"
32 #include "enums.h"
33 #include "extensions.h"
34
35
36 /**
37 * Examine enabled GL extensions to determine GL version.
38 * \return version string
39 */
40 static const char *
41 compute_version(const GLcontext *ctx)
42 {
43 static const char *version_1_2 = "1.2 Mesa " MESA_VERSION_STRING;
44 static const char *version_1_3 = "1.3 Mesa " MESA_VERSION_STRING;
45 static const char *version_1_4 = "1.4 Mesa " MESA_VERSION_STRING;
46 static const char *version_1_5 = "1.5 Mesa " MESA_VERSION_STRING;
47 static const char *version_2_0 = "2.0 Mesa " MESA_VERSION_STRING;
48 static const char *version_2_1 = "2.1 Mesa " MESA_VERSION_STRING;
49
50 const GLboolean ver_1_3 = (ctx->Extensions.ARB_multisample &&
51 ctx->Extensions.ARB_multitexture &&
52 ctx->Extensions.ARB_texture_border_clamp &&
53 ctx->Extensions.ARB_texture_compression &&
54 ctx->Extensions.ARB_texture_cube_map &&
55 ctx->Extensions.EXT_texture_env_add &&
56 ctx->Extensions.ARB_texture_env_combine &&
57 ctx->Extensions.ARB_texture_env_dot3);
58 const GLboolean ver_1_4 = (ver_1_3 &&
59 ctx->Extensions.ARB_depth_texture &&
60 ctx->Extensions.ARB_shadow &&
61 ctx->Extensions.ARB_texture_env_crossbar &&
62 ctx->Extensions.ARB_texture_mirrored_repeat &&
63 ctx->Extensions.ARB_window_pos &&
64 ctx->Extensions.EXT_blend_color &&
65 ctx->Extensions.EXT_blend_func_separate &&
66 ctx->Extensions.EXT_blend_minmax &&
67 ctx->Extensions.EXT_blend_subtract &&
68 ctx->Extensions.EXT_fog_coord &&
69 ctx->Extensions.EXT_multi_draw_arrays &&
70 ctx->Extensions.EXT_point_parameters &&
71 ctx->Extensions.EXT_secondary_color &&
72 ctx->Extensions.EXT_stencil_wrap &&
73 ctx->Extensions.EXT_texture_lod_bias &&
74 ctx->Extensions.SGIS_generate_mipmap);
75 const GLboolean ver_1_5 = (ver_1_4 &&
76 ctx->Extensions.ARB_occlusion_query &&
77 ctx->Extensions.ARB_vertex_buffer_object &&
78 ctx->Extensions.EXT_shadow_funcs);
79 const GLboolean ver_2_0 = (ver_1_5 &&
80 ctx->Extensions.ARB_draw_buffers &&
81 ctx->Extensions.ARB_point_sprite &&
82 ctx->Extensions.ARB_shader_objects &&
83 ctx->Extensions.ARB_vertex_shader &&
84 ctx->Extensions.ARB_fragment_shader &&
85 ctx->Extensions.ARB_texture_non_power_of_two &&
86 ctx->Extensions.EXT_blend_equation_separate);
87 const GLboolean ver_2_1 = (ver_2_0 &&
88 ctx->Extensions.ARB_shading_language_120 &&
89 ctx->Extensions.EXT_pixel_buffer_object &&
90 ctx->Extensions.EXT_texture_sRGB);
91 if (ver_2_1)
92 return version_2_1;
93 if (ver_2_0)
94 return version_2_0;
95 if (ver_1_5)
96 return version_1_5;
97 if (ver_1_4)
98 return version_1_4;
99 if (ver_1_3)
100 return version_1_3;
101 return version_1_2;
102 }
103
104
105
106 /**
107 * Query string-valued state. The return value should _not_ be freed by
108 * the caller.
109 *
110 * \param name the state variable to query.
111 *
112 * \sa glGetString().
113 *
114 * Tries to get the string from dd_function_table::GetString, otherwise returns
115 * the hardcoded strings.
116 */
117 const GLubyte * GLAPIENTRY
118 _mesa_GetString( GLenum name )
119 {
120 GET_CURRENT_CONTEXT(ctx);
121 static const char *vendor = "Brian Paul";
122 static const char *renderer = "Mesa";
123
124 #if FEATURE_ARB_shading_language_120_foo /* support not complete! */
125 static const char *sl_version = "1.20";
126 #elif FEATURE_ARB_shading_language_100
127 static const char *sl_version = "1.10";
128 #endif
129
130 if (!ctx)
131 return NULL;
132
133 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
134
135 /* this is a required driver function */
136 assert(ctx->Driver.GetString);
137 {
138 /* Give the driver the chance to handle this query */
139 const GLubyte *str = (*ctx->Driver.GetString)(ctx, name);
140 if (str)
141 return str;
142 }
143
144 switch (name) {
145 case GL_VENDOR:
146 return (const GLubyte *) vendor;
147 case GL_RENDERER:
148 return (const GLubyte *) renderer;
149 case GL_VERSION:
150 return (const GLubyte *) compute_version(ctx);
151 case GL_EXTENSIONS:
152 if (!ctx->Extensions.String)
153 ctx->Extensions.String = _mesa_make_extension_string(ctx);
154 return (const GLubyte *) ctx->Extensions.String;
155 #if FEATURE_ARB_shading_language_100
156 case GL_SHADING_LANGUAGE_VERSION_ARB:
157 if (ctx->Extensions.ARB_shading_language_100)
158 return (const GLubyte *) sl_version;
159 goto error;
160 #endif
161 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program || \
162 FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
163 case GL_PROGRAM_ERROR_STRING_NV:
164 if (ctx->Extensions.NV_fragment_program ||
165 ctx->Extensions.ARB_fragment_program ||
166 ctx->Extensions.NV_vertex_program ||
167 ctx->Extensions.ARB_vertex_program) {
168 return (const GLubyte *) ctx->Program.ErrorString;
169 }
170 /* FALL-THROUGH */
171 #endif
172 #if FEATURE_ARB_shading_language_100
173 error:
174 #endif
175 default:
176 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
177 return (const GLubyte *) 0;
178 }
179 }
180
181
182 /**
183 * Return pointer-valued state, such as a vertex array pointer.
184 *
185 * \param pname names state to be queried
186 * \param params returns the pointer value
187 *
188 * \sa glGetPointerv().
189 *
190 * Tries to get the specified pointer via dd_function_table::GetPointerv,
191 * otherwise gets the specified pointer from the current context.
192 */
193 void GLAPIENTRY
194 _mesa_GetPointerv( GLenum pname, GLvoid **params )
195 {
196 GET_CURRENT_CONTEXT(ctx);
197 const GLuint clientUnit = ctx->Array.ActiveTexture;
198 ASSERT_OUTSIDE_BEGIN_END(ctx);
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 if (ctx->Driver.GetPointerv
207 && (*ctx->Driver.GetPointerv)(ctx, pname, params))
208 return;
209
210 switch (pname) {
211 case GL_VERTEX_ARRAY_POINTER:
212 *params = (GLvoid *) ctx->Array.ArrayObj->Vertex.Ptr;
213 break;
214 case GL_NORMAL_ARRAY_POINTER:
215 *params = (GLvoid *) ctx->Array.ArrayObj->Normal.Ptr;
216 break;
217 case GL_COLOR_ARRAY_POINTER:
218 *params = (GLvoid *) ctx->Array.ArrayObj->Color.Ptr;
219 break;
220 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT:
221 *params = (GLvoid *) ctx->Array.ArrayObj->SecondaryColor.Ptr;
222 break;
223 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT:
224 *params = (GLvoid *) ctx->Array.ArrayObj->FogCoord.Ptr;
225 break;
226 case GL_INDEX_ARRAY_POINTER:
227 *params = (GLvoid *) ctx->Array.ArrayObj->Index.Ptr;
228 break;
229 case GL_TEXTURE_COORD_ARRAY_POINTER:
230 *params = (GLvoid *) ctx->Array.ArrayObj->TexCoord[clientUnit].Ptr;
231 break;
232 case GL_EDGE_FLAG_ARRAY_POINTER:
233 *params = (GLvoid *) ctx->Array.ArrayObj->EdgeFlag.Ptr;
234 break;
235 case GL_FEEDBACK_BUFFER_POINTER:
236 *params = ctx->Feedback.Buffer;
237 break;
238 case GL_SELECTION_BUFFER_POINTER:
239 *params = ctx->Select.Buffer;
240 break;
241 #if FEATURE_MESA_program_debug
242 case GL_FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA:
243 if (!ctx->Extensions.MESA_program_debug) {
244 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
245 return;
246 }
247 *params = *(GLvoid **) &ctx->FragmentProgram.Callback;
248 break;
249 case GL_FRAGMENT_PROGRAM_CALLBACK_DATA_MESA:
250 if (!ctx->Extensions.MESA_program_debug) {
251 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
252 return;
253 }
254 *params = ctx->FragmentProgram.CallbackData;
255 break;
256 case GL_VERTEX_PROGRAM_CALLBACK_FUNC_MESA:
257 if (!ctx->Extensions.MESA_program_debug) {
258 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
259 return;
260 }
261 *params = *(GLvoid **) &ctx->VertexProgram.Callback;
262 break;
263 case GL_VERTEX_PROGRAM_CALLBACK_DATA_MESA:
264 if (!ctx->Extensions.MESA_program_debug) {
265 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
266 return;
267 }
268 *params = ctx->VertexProgram.CallbackData;
269 break;
270 #endif
271 default:
272 _mesa_error( ctx, GL_INVALID_ENUM, "glGetPointerv" );
273 return;
274 }
275 }
276
277
278 /**
279 * Returns the current GL error code, or GL_NO_ERROR.
280 * \return current error code
281 *
282 * Returns __GLcontextRec::ErrorValue.
283 */
284 GLenum GLAPIENTRY
285 _mesa_GetError( void )
286 {
287 GET_CURRENT_CONTEXT(ctx);
288 GLenum e = ctx->ErrorValue;
289 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
290
291 if (MESA_VERBOSE & VERBOSE_API)
292 _mesa_debug(ctx, "glGetError <-- %s\n", _mesa_lookup_enum_by_nr(e));
293
294 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
295 return e;
296 }