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