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