Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
/*
2
 * Mesa 3-D graphics library
3
 *
4
 * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included
14
 * in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
 * 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 "mtypes.h"
33
 
34
 
35
/**
36
 * Return the string for a glGetString(GL_SHADING_LANGUAGE_VERSION) query.
37
 */
38
static const GLubyte *
39
shading_language_version(struct gl_context *ctx)
40
{
41
   switch (ctx->API) {
42
   case API_OPENGL_COMPAT:
43
   case API_OPENGL_CORE:
44
      switch (ctx->Const.GLSLVersion) {
45
      case 110:
46
         return (const GLubyte *) "1.10";
47
      case 120:
48
         return (const GLubyte *) "1.20";
49
      case 130:
50
         return (const GLubyte *) "1.30";
51
      case 140:
52
         return (const GLubyte *) "1.40";
53
      case 150:
54
         return (const GLubyte *) "1.50";
55
      case 330:
56
         return (const GLubyte *) "3.30";
57
      case 400:
58
         return (const GLubyte *) "4.00";
59
      case 410:
60
         return (const GLubyte *) "4.10";
61
      case 420:
62
         return (const GLubyte *) "4.20";
63
      default:
64
         _mesa_problem(ctx,
65
                       "Invalid GLSL version in shading_language_version()");
66
         return (const GLubyte *) 0;
67
      }
68
      break;
69
 
70
   case API_OPENGLES2:
71
      return (ctx->Version < 30)
72
         ? (const GLubyte *) "OpenGL ES GLSL ES 1.0.16"
73
         : (const GLubyte *) "OpenGL ES GLSL ES 3.0";
74
 
75
   case API_OPENGLES:
76
      /* fall-through */
77
 
78
   default:
79
      _mesa_problem(ctx, "Unexpected API value in shading_language_version()");
80
      return (const GLubyte *) 0;
81
   }
82
}
83
 
84
 
85
/**
86
 * Query string-valued state.  The return value should _not_ be freed by
87
 * the caller.
88
 *
89
 * \param name  the state variable to query.
90
 *
91
 * \sa glGetString().
92
 *
93
 * Tries to get the string from dd_function_table::GetString, otherwise returns
94
 * the hardcoded strings.
95
 */
96
const GLubyte * GLAPIENTRY
97
_mesa_GetString( GLenum name )
98
{
99
   GET_CURRENT_CONTEXT(ctx);
100
   static const char *vendor = "Brian Paul";
101
   static const char *renderer = "Mesa";
102
 
103
   if (!ctx)
104
      return NULL;
105
 
106
   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
107
 
108
   /* this is a required driver function */
109
   assert(ctx->Driver.GetString);
110
   {
111
      /* Give the driver the chance to handle this query */
112
      const GLubyte *str = (*ctx->Driver.GetString)(ctx, name);
113
      if (str)
114
         return str;
115
   }
116
 
117
   switch (name) {
118
      case GL_VENDOR:
119
         return (const GLubyte *) vendor;
120
      case GL_RENDERER:
121
         return (const GLubyte *) renderer;
122
      case GL_VERSION:
123
         return (const GLubyte *) ctx->VersionString;
124
      case GL_EXTENSIONS:
125
         if (ctx->API == API_OPENGL_CORE) {
126
            _mesa_error(ctx, GL_INVALID_ENUM, "glGetString(GL_EXTENSIONS)");
127
            return (const GLubyte *) 0;
128
         }
129
         return (const GLubyte *) ctx->Extensions.String;
130
      case GL_SHADING_LANGUAGE_VERSION:
131
         if (ctx->API == API_OPENGLES)
132
            break;
133
	 return shading_language_version(ctx);
134
      case GL_PROGRAM_ERROR_STRING_ARB:
135
         if (ctx->API == API_OPENGL_COMPAT &&
136
             (ctx->Extensions.ARB_fragment_program ||
137
              ctx->Extensions.ARB_vertex_program)) {
138
            return (const GLubyte *) ctx->Program.ErrorString;
139
         }
140
         break;
141
      default:
142
         break;
143
   }
144
 
145
   _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
146
   return (const GLubyte *) 0;
147
}
148
 
149
 
150
/**
151
 * GL3
152
 */
153
const GLubyte * GLAPIENTRY
154
_mesa_GetStringi(GLenum name, GLuint index)
155
{
156
   GET_CURRENT_CONTEXT(ctx);
157
 
158
   if (!ctx)
159
      return NULL;
160
 
161
   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
162
 
163
   switch (name) {
164
   case GL_EXTENSIONS:
165
      if (index >= _mesa_get_extension_count(ctx)) {
166
         _mesa_error(ctx, GL_INVALID_VALUE, "glGetStringi(index=%u)", index);
167
         return (const GLubyte *) 0;
168
      }
169
      return _mesa_get_enabled_extension(ctx, index);
170
   default:
171
      _mesa_error( ctx, GL_INVALID_ENUM, "glGetString" );
172
      return (const GLubyte *) 0;
173
   }
174
}
175
 
176
 
177
 
178
/**
179
 * Return pointer-valued state, such as a vertex array pointer.
180
 *
181
 * \param pname  names state to be queried
182
 * \param params  returns the pointer value
183
 *
184
 * \sa glGetPointerv().
185
 *
186
 * Tries to get the specified pointer via dd_function_table::GetPointerv,
187
 * otherwise gets the specified pointer from the current context.
188
 */
189
void GLAPIENTRY
190
_mesa_GetPointerv( GLenum pname, GLvoid **params )
191
{
192
   GET_CURRENT_CONTEXT(ctx);
193
   const GLuint clientUnit = ctx->Array.ActiveTexture;
194
 
195
   if (!params)
196
      return;
197
 
198
   if (MESA_VERBOSE & VERBOSE_API)
199
      _mesa_debug(ctx, "glGetPointerv %s\n", _mesa_lookup_enum_by_nr(pname));
200
 
201
   switch (pname) {
202
      case GL_VERTEX_ARRAY_POINTER:
203
         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
204
            goto invalid_pname;
205
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Ptr;
206
         break;
207
      case GL_NORMAL_ARRAY_POINTER:
208
         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
209
            goto invalid_pname;
210
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Ptr;
211
         break;
212
      case GL_COLOR_ARRAY_POINTER:
213
         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
214
            goto invalid_pname;
215
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Ptr;
216
         break;
217
      case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT:
218
         if (ctx->API != API_OPENGL_COMPAT)
219
            goto invalid_pname;
220
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Ptr;
221
         break;
222
      case GL_FOG_COORDINATE_ARRAY_POINTER_EXT:
223
         if (ctx->API != API_OPENGL_COMPAT)
224
            goto invalid_pname;
225
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Ptr;
226
         break;
227
      case GL_INDEX_ARRAY_POINTER:
228
         if (ctx->API != API_OPENGL_COMPAT)
229
            goto invalid_pname;
230
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Ptr;
231
         break;
232
      case GL_TEXTURE_COORD_ARRAY_POINTER:
233
         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
234
            goto invalid_pname;
235
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(clientUnit)].Ptr;
236
         break;
237
      case GL_EDGE_FLAG_ARRAY_POINTER:
238
         if (ctx->API != API_OPENGL_COMPAT)
239
            goto invalid_pname;
240
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Ptr;
241
         break;
242
      case GL_FEEDBACK_BUFFER_POINTER:
243
         if (ctx->API != API_OPENGL_COMPAT)
244
            goto invalid_pname;
245
         *params = ctx->Feedback.Buffer;
246
         break;
247
      case GL_SELECTION_BUFFER_POINTER:
248
         if (ctx->API != API_OPENGL_COMPAT)
249
            goto invalid_pname;
250
         *params = ctx->Select.Buffer;
251
         break;
252
      case GL_POINT_SIZE_ARRAY_POINTER_OES:
253
         if (ctx->API != API_OPENGLES)
254
            goto invalid_pname;
255
         *params = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Ptr;
256
         break;
257
      case GL_DEBUG_CALLBACK_FUNCTION_ARB:
258
         if (!_mesa_is_desktop_gl(ctx))
259
            goto invalid_pname;
260
         *params = (GLvoid *) ctx->Debug.Callback;
261
         break;
262
      case GL_DEBUG_CALLBACK_USER_PARAM_ARB:
263
         if (!_mesa_is_desktop_gl(ctx))
264
            goto invalid_pname;
265
         *params = (GLvoid *) ctx->Debug.CallbackData;
266
         break;
267
      default:
268
         goto invalid_pname;
269
   }
270
 
271
   return;
272
 
273
invalid_pname:
274
   _mesa_error( ctx, GL_INVALID_ENUM, "glGetPointerv" );
275
   return;
276
}
277
 
278
 
279
/**
280
 * Returns the current GL error code, or GL_NO_ERROR.
281
 * \return current error code
282
 *
283
 * Returns __struct gl_contextRec::ErrorValue.
284
 */
285
GLenum GLAPIENTRY
286
_mesa_GetError( void )
287
{
288
   GET_CURRENT_CONTEXT(ctx);
289
   GLenum e = ctx->ErrorValue;
290
   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
291
 
292
   if (MESA_VERBOSE & VERBOSE_API)
293
      _mesa_debug(ctx, "glGetError <-- %s\n", _mesa_lookup_enum_by_nr(e));
294
 
295
   ctx->ErrorValue = (GLenum) GL_NO_ERROR;
296
   ctx->ErrorDebugCount = 0;
297
   return e;
298
}
299
 
300
/**
301
 * Returns an error code specified by GL_ARB_robustness, or GL_NO_ERROR.
302
 * \return current context status
303
 */
304
GLenum GLAPIENTRY
305
_mesa_GetGraphicsResetStatusARB( void )
306
{
307
   GET_CURRENT_CONTEXT(ctx);
308
   GLenum status = ctx->ResetStatus;
309
 
310
   if (MESA_VERBOSE & VERBOSE_API)
311
      _mesa_debug(ctx, "glGetGraphicsResetStatusARB"
312
                       "(always returns GL_NO_ERROR)\n");
313
 
314
   return status;
315
}