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