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