Merge commit 'origin/gallium-0.1' into gallium-0.2
[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 "context.h"
29 #include "get.h"
30 #include "version.h"
31 #include "enums.h"
32 #include "extensions.h"
33
34
35 /**
36 * Examine enabled GL extensions to determine GL version.
37 * \return version string
38 */
39 static const char *
40 compute_version(const GLcontext *ctx)
41 {
42 static const char *version_1_2 = "1.2 Mesa " MESA_VERSION_STRING;
43 static const char *version_1_3 = "1.3 Mesa " MESA_VERSION_STRING;
44 static const char *version_1_4 = "1.4 Mesa " MESA_VERSION_STRING;
45 static const char *version_1_5 = "1.5 Mesa " MESA_VERSION_STRING;
46 static const char *version_2_0 = "2.0 Mesa " MESA_VERSION_STRING;
47 static const char *version_2_1 = "2.1 Mesa " MESA_VERSION_STRING;
48
49 const GLboolean ver_1_3 = (ctx->Extensions.ARB_multisample &&
50 ctx->Extensions.ARB_multitexture &&
51 ctx->Extensions.ARB_texture_border_clamp &&
52 ctx->Extensions.ARB_texture_compression &&
53 ctx->Extensions.ARB_texture_cube_map &&
54 ctx->Extensions.EXT_texture_env_add &&
55 ctx->Extensions.ARB_texture_env_combine &&
56 ctx->Extensions.ARB_texture_env_dot3);
57 const GLboolean ver_1_4 = (ver_1_3 &&
58 ctx->Extensions.ARB_depth_texture &&
59 ctx->Extensions.ARB_shadow &&
60 ctx->Extensions.ARB_texture_env_crossbar &&
61 ctx->Extensions.ARB_texture_mirrored_repeat &&
62 ctx->Extensions.ARB_window_pos &&
63 ctx->Extensions.EXT_blend_color &&
64 ctx->Extensions.EXT_blend_func_separate &&
65 ctx->Extensions.EXT_blend_minmax &&
66 ctx->Extensions.EXT_blend_subtract &&
67 ctx->Extensions.EXT_fog_coord &&
68 ctx->Extensions.EXT_multi_draw_arrays &&
69 ctx->Extensions.EXT_point_parameters &&
70 ctx->Extensions.EXT_secondary_color &&
71 ctx->Extensions.EXT_stencil_wrap &&
72 ctx->Extensions.EXT_texture_lod_bias &&
73 ctx->Extensions.SGIS_generate_mipmap);
74 const GLboolean ver_1_5 = (ver_1_4 &&
75 ctx->Extensions.ARB_occlusion_query &&
76 ctx->Extensions.ARB_vertex_buffer_object &&
77 ctx->Extensions.EXT_shadow_funcs);
78 const GLboolean ver_2_0 = (ver_1_5 &&
79 ctx->Extensions.ARB_draw_buffers &&
80 ctx->Extensions.ARB_point_sprite &&
81 ctx->Extensions.ARB_shader_objects &&
82 ctx->Extensions.ARB_vertex_shader &&
83 ctx->Extensions.ARB_fragment_shader &&
84 ctx->Extensions.ARB_texture_non_power_of_two &&
85 ctx->Extensions.EXT_blend_equation_separate);
86 const GLboolean ver_2_1 = (ver_2_0 &&
87 /*ctx->Extensions.ARB_shading_language_120 &&*/
88 ctx->Extensions.EXT_pixel_buffer_object &&
89 ctx->Extensions.EXT_texture_sRGB);
90 if (ver_2_1)
91 return version_2_1;
92 if (ver_2_0)
93 return version_2_0;
94 if (ver_1_5)
95 return version_1_5;
96 if (ver_1_4)
97 return version_1_4;
98 if (ver_1_3)
99 return version_1_3;
100 return version_1_2;
101 }
102
103
104
105 /**
106 * Query string-valued state. The return value should _not_ be freed by
107 * the caller.
108 *
109 * \param name the state variable to query.
110 *
111 * \sa glGetString().
112 *
113 * Tries to get the string from dd_function_table::GetString, otherwise returns
114 * the hardcoded strings.
115 */
116 const GLubyte * GLAPIENTRY
117 _mesa_GetString( GLenum name )
118 {
119 GET_CURRENT_CONTEXT(ctx);
120 static const char *vendor = "Brian Paul";
121 static const char *renderer = "Mesa";
122
123 if (!ctx)
124 return NULL;
125
126 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
127
128 /* this is a required driver function */
129 assert(ctx->Driver.GetString);
130 {
131 /* Give the driver the chance to handle this query */
132 const GLubyte *str = (*ctx->Driver.GetString)(ctx, name);
133 if (str)
134 return str;
135 }
136
137 switch (name) {
138 case GL_VENDOR:
139 return (const GLubyte *) vendor;
140 case GL_RENDERER:
141 return (const GLubyte *) renderer;
142 case GL_VERSION:
143 return (const GLubyte *) compute_version(ctx);
144 case GL_EXTENSIONS:
145 if (!ctx->Extensions.String)
146 ctx->Extensions.String = _mesa_make_extension_string(ctx);
147 return (const GLubyte *) ctx->Extensions.String;
148 #if FEATURE_ARB_shading_language_100
149 case GL_SHADING_LANGUAGE_VERSION_ARB:
150 if (ctx->Extensions.ARB_shading_language_120)
151 return (const GLubyte *) "1.20";
152 else if (ctx->Extensions.ARB_shading_language_100)
153 return (const GLubyte *) "1.10";
154 goto error;
155 #endif
156 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program || \
157 FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
158 case GL_PROGRAM_ERROR_STRING_NV:
159 if (ctx->Extensions.NV_fragment_program ||
160 ctx->Extensions.ARB_fragment_program ||
161 ctx->Extensions.NV_vertex_program ||
162 ctx->Extensions.ARB_vertex_program) {
163 return (const GLubyte *) ctx->Program.ErrorString;
164 }
165 /* FALL-THROUGH */
166 #endif
167 #if FEATURE_ARB_shading_language_100
168 error:
169 #endif
170 default:
171 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
172 return (const GLubyte *) 0;
173 }
174 }
175
176
177 /**
178 * Return pointer-valued state, such as a vertex array pointer.
179 *
180 * \param pname names state to be queried
181 * \param params returns the pointer value
182 *
183 * \sa glGetPointerv().
184 *
185 * Tries to get the specified pointer via dd_function_table::GetPointerv,
186 * otherwise gets the specified pointer from the current context.
187 */
188 void GLAPIENTRY
189 _mesa_GetPointerv( GLenum pname, GLvoid **params )
190 {
191 GET_CURRENT_CONTEXT(ctx);
192 const GLuint clientUnit = ctx->Array.ActiveTexture;
193 ASSERT_OUTSIDE_BEGIN_END(ctx);
194
195 if (!params)
196 return;
197
198 if (MESA_VERBOSE & VERBOSE_API)
199 _mesa_debug(ctx, "glGetPointerv %s\n", _mesa_lookup_enum_by_nr(pname));
200
201 if (ctx->Driver.GetPointerv
202 && (*ctx->Driver.GetPointerv)(ctx, pname, params))
203 return;
204
205 switch (pname) {
206 case GL_VERTEX_ARRAY_POINTER:
207 *params = (GLvoid *) ctx->Array.ArrayObj->Vertex.Ptr;
208 break;
209 case GL_NORMAL_ARRAY_POINTER:
210 *params = (GLvoid *) ctx->Array.ArrayObj->Normal.Ptr;
211 break;
212 case GL_COLOR_ARRAY_POINTER:
213 *params = (GLvoid *) ctx->Array.ArrayObj->Color.Ptr;
214 break;
215 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT:
216 *params = (GLvoid *) ctx->Array.ArrayObj->SecondaryColor.Ptr;
217 break;
218 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT:
219 *params = (GLvoid *) ctx->Array.ArrayObj->FogCoord.Ptr;
220 break;
221 case GL_INDEX_ARRAY_POINTER:
222 *params = (GLvoid *) ctx->Array.ArrayObj->Index.Ptr;
223 break;
224 case GL_TEXTURE_COORD_ARRAY_POINTER:
225 *params = (GLvoid *) ctx->Array.ArrayObj->TexCoord[clientUnit].Ptr;
226 break;
227 case GL_EDGE_FLAG_ARRAY_POINTER:
228 *params = (GLvoid *) ctx->Array.ArrayObj->EdgeFlag.Ptr;
229 break;
230 case GL_FEEDBACK_BUFFER_POINTER:
231 *params = ctx->Feedback.Buffer;
232 break;
233 case GL_SELECTION_BUFFER_POINTER:
234 *params = ctx->Select.Buffer;
235 break;
236 #if FEATURE_MESA_program_debug
237 case GL_FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA:
238 if (!ctx->Extensions.MESA_program_debug) {
239 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
240 return;
241 }
242 *params = *(GLvoid **) &ctx->FragmentProgram.Callback;
243 break;
244 case GL_FRAGMENT_PROGRAM_CALLBACK_DATA_MESA:
245 if (!ctx->Extensions.MESA_program_debug) {
246 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
247 return;
248 }
249 *params = ctx->FragmentProgram.CallbackData;
250 break;
251 case GL_VERTEX_PROGRAM_CALLBACK_FUNC_MESA:
252 if (!ctx->Extensions.MESA_program_debug) {
253 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
254 return;
255 }
256 *params = *(GLvoid **) &ctx->VertexProgram.Callback;
257 break;
258 case GL_VERTEX_PROGRAM_CALLBACK_DATA_MESA:
259 if (!ctx->Extensions.MESA_program_debug) {
260 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPointerv");
261 return;
262 }
263 *params = ctx->VertexProgram.CallbackData;
264 break;
265 #endif
266 default:
267 _mesa_error( ctx, GL_INVALID_ENUM, "glGetPointerv" );
268 return;
269 }
270 }
271
272
273 /**
274 * Returns the current GL error code, or GL_NO_ERROR.
275 * \return current error code
276 *
277 * Returns __GLcontextRec::ErrorValue.
278 */
279 GLenum GLAPIENTRY
280 _mesa_GetError( void )
281 {
282 GET_CURRENT_CONTEXT(ctx);
283 GLenum e = ctx->ErrorValue;
284 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
285
286 if (MESA_VERBOSE & VERBOSE_API)
287 _mesa_debug(ctx, "glGetError <-- %s\n", _mesa_lookup_enum_by_nr(e));
288
289 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
290 return e;
291 }