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