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