Fix typo in function name "shading_laguage_version".
[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
33 static const GLubyte *
34 shading_language_version(GLcontext *ctx)
35 {
36 switch (ctx->API) {
37 #if FEATURE_ARB_shading_language_100
38 case API_OPENGL:
39 if (ctx->Extensions.ARB_shading_language_120)
40 return (const GLubyte *) "1.20";
41 else if (ctx->Extensions.ARB_shading_language_100)
42 return (const GLubyte *) "1.10";
43 goto error;
44 #endif
45
46 case API_OPENGLES2:
47 return (const GLubyte *) "OpenGL ES GLSL ES 1.0.16";
48
49 case API_OPENGLES:
50 default:
51 error:
52 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
53 return (const GLubyte *) 0;
54 }
55 }
56
57
58 /**
59 * Query string-valued state. The return value should _not_ be freed by
60 * the caller.
61 *
62 * \param name the state variable to query.
63 *
64 * \sa glGetString().
65 *
66 * Tries to get the string from dd_function_table::GetString, otherwise returns
67 * the hardcoded strings.
68 */
69 const GLubyte * GLAPIENTRY
70 _mesa_GetString( GLenum name )
71 {
72 GET_CURRENT_CONTEXT(ctx);
73 static const char *vendor = "Brian Paul";
74 static const char *renderer = "Mesa";
75
76 if (!ctx)
77 return NULL;
78
79 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
80
81 /* this is a required driver function */
82 assert(ctx->Driver.GetString);
83 {
84 /* Give the driver the chance to handle this query */
85 const GLubyte *str = (*ctx->Driver.GetString)(ctx, name);
86 if (str)
87 return str;
88 }
89
90 switch (name) {
91 case GL_VENDOR:
92 return (const GLubyte *) vendor;
93 case GL_RENDERER:
94 return (const GLubyte *) renderer;
95 case GL_VERSION:
96 return (const GLubyte *) ctx->VersionString;
97 case GL_EXTENSIONS:
98 return (const GLubyte *) ctx->Extensions.String;
99 #if FEATURE_ARB_shading_language_100 || FEATURE_ES2
100 case GL_SHADING_LANGUAGE_VERSION:
101 return shading_language_version(ctx);
102 #endif
103 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program || \
104 FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
105 case GL_PROGRAM_ERROR_STRING_NV:
106 if (ctx->Extensions.NV_fragment_program ||
107 ctx->Extensions.ARB_fragment_program ||
108 ctx->Extensions.NV_vertex_program ||
109 ctx->Extensions.ARB_vertex_program) {
110 return (const GLubyte *) ctx->Program.ErrorString;
111 }
112 /* FALL-THROUGH */
113 #endif
114 default:
115 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
116 return (const GLubyte *) 0;
117 }
118 }
119
120
121 /**
122 * GL3
123 */
124 const GLubyte * GLAPIENTRY
125 _mesa_GetStringi(GLenum name, GLuint index)
126 {
127 GET_CURRENT_CONTEXT(ctx);
128
129 if (!ctx)
130 return NULL;
131
132 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
133
134 switch (name) {
135 case GL_EXTENSIONS:
136 if (index >= _mesa_get_extension_count(ctx)) {
137 _mesa_error(ctx, GL_INVALID_VALUE, "glGetStringi(index=%u)", index);
138 return (const GLubyte *) 0;
139 }
140 return _mesa_get_enabled_extension(ctx, index);
141 default:
142 _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
143 return (const GLubyte *) 0;
144 }
145 }
146
147
148
149 /**
150 * Return pointer-valued state, such as a vertex array pointer.
151 *
152 * \param pname names state to be queried
153 * \param params returns the pointer value
154 *
155 * \sa glGetPointerv().
156 *
157 * Tries to get the specified pointer via dd_function_table::GetPointerv,
158 * otherwise gets the specified pointer from the current context.
159 */
160 void GLAPIENTRY
161 _mesa_GetPointerv( GLenum pname, GLvoid **params )
162 {
163 GET_CURRENT_CONTEXT(ctx);
164 const GLuint clientUnit = ctx->Array.ActiveTexture;
165 ASSERT_OUTSIDE_BEGIN_END(ctx);
166
167 if (!params)
168 return;
169
170 if (MESA_VERBOSE & VERBOSE_API)
171 _mesa_debug(ctx, "glGetPointerv %s\n", _mesa_lookup_enum_by_nr(pname));
172
173 switch (pname) {
174 case GL_VERTEX_ARRAY_POINTER:
175 *params = (GLvoid *) ctx->Array.ArrayObj->Vertex.Ptr;
176 break;
177 case GL_NORMAL_ARRAY_POINTER:
178 *params = (GLvoid *) ctx->Array.ArrayObj->Normal.Ptr;
179 break;
180 case GL_COLOR_ARRAY_POINTER:
181 *params = (GLvoid *) ctx->Array.ArrayObj->Color.Ptr;
182 break;
183 case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT:
184 *params = (GLvoid *) ctx->Array.ArrayObj->SecondaryColor.Ptr;
185 break;
186 case GL_FOG_COORDINATE_ARRAY_POINTER_EXT:
187 *params = (GLvoid *) ctx->Array.ArrayObj->FogCoord.Ptr;
188 break;
189 case GL_INDEX_ARRAY_POINTER:
190 *params = (GLvoid *) ctx->Array.ArrayObj->Index.Ptr;
191 break;
192 case GL_TEXTURE_COORD_ARRAY_POINTER:
193 *params = (GLvoid *) ctx->Array.ArrayObj->TexCoord[clientUnit].Ptr;
194 break;
195 case GL_EDGE_FLAG_ARRAY_POINTER:
196 *params = (GLvoid *) ctx->Array.ArrayObj->EdgeFlag.Ptr;
197 break;
198 case GL_FEEDBACK_BUFFER_POINTER:
199 *params = ctx->Feedback.Buffer;
200 break;
201 case GL_SELECTION_BUFFER_POINTER:
202 *params = ctx->Select.Buffer;
203 break;
204 #if FEATURE_point_size_array
205 case GL_POINT_SIZE_ARRAY_POINTER_OES:
206 *params = (GLvoid *) ctx->Array.ArrayObj->PointSize.Ptr;
207 break;
208 #endif
209 default:
210 _mesa_error( ctx, GL_INVALID_ENUM, "glGetPointerv" );
211 return;
212 }
213 }
214
215
216 /**
217 * Returns the current GL error code, or GL_NO_ERROR.
218 * \return current error code
219 *
220 * Returns __GLcontextRec::ErrorValue.
221 */
222 GLenum GLAPIENTRY
223 _mesa_GetError( void )
224 {
225 GET_CURRENT_CONTEXT(ctx);
226 GLenum e = ctx->ErrorValue;
227 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
228
229 if (MESA_VERBOSE & VERBOSE_API)
230 _mesa_debug(ctx, "glGetError <-- %s\n", _mesa_lookup_enum_by_nr(e));
231
232 ctx->ErrorValue = (GLenum) GL_NO_ERROR;
233 ctx->ErrorDebugCount = 0;
234 return e;
235 }