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