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