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