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