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