blob: 55d581cf9fa28ea2955b74299c0973bb4e0453db [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000013#include "libGLESv2/utilities.h"
14#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000015#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000016#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000017#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000018#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000019#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000021#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000022#include "libGLESv2/Context.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000023
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000024bool validImageSize(GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000025{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000026 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027 {
28 return false;
29 }
30
31 if (gl::getContext() && gl::getContext()->supportsNonPower2Texture())
32 {
33 return true;
34 }
35
36 if (level == 0)
37 {
38 return true;
39 }
40
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000041 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000042 {
43 return true;
44 }
45
46 return false;
47}
48
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000049// Verify that format/type are one of the combinations from table 3.4.
50bool checkTextureFormatType(GLenum format, GLenum type)
51{
52 // validate <format> by itself (used as secondary key below)
53 switch (format)
54 {
55 case GL_RGBA:
56 case GL_BGRA_EXT:
57 case GL_RGB:
58 case GL_ALPHA:
59 case GL_LUMINANCE:
60 case GL_LUMINANCE_ALPHA:
61 case GL_DEPTH_COMPONENT:
62 case GL_DEPTH_STENCIL_OES:
63 break;
64 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000065 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066 }
67
68 // invalid <type> -> sets INVALID_ENUM
69 // invalid <format>+<type> combination -> sets INVALID_OPERATION
70 switch (type)
71 {
72 case GL_UNSIGNED_BYTE:
73 switch (format)
74 {
75 case GL_RGBA:
76 case GL_BGRA_EXT:
77 case GL_RGB:
78 case GL_ALPHA:
79 case GL_LUMINANCE:
80 case GL_LUMINANCE_ALPHA:
81 return true;
82 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000083 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000084 }
85
86 case GL_FLOAT:
87 case GL_HALF_FLOAT_OES:
88 switch (format)
89 {
90 case GL_RGBA:
91 case GL_RGB:
92 case GL_ALPHA:
93 case GL_LUMINANCE:
94 case GL_LUMINANCE_ALPHA:
95 return true;
96 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000097 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000098 }
99
100 case GL_UNSIGNED_SHORT_4_4_4_4:
101 case GL_UNSIGNED_SHORT_5_5_5_1:
102 switch (format)
103 {
104 case GL_RGBA:
105 return true;
106 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000107 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000108 }
109
110 case GL_UNSIGNED_SHORT_5_6_5:
111 switch (format)
112 {
113 case GL_RGB:
114 return true;
115 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000116 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000117 }
118
119 case GL_UNSIGNED_SHORT:
120 case GL_UNSIGNED_INT:
121 switch (format)
122 {
123 case GL_DEPTH_COMPONENT:
124 return true;
125 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000126 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000127 }
128
129 case GL_UNSIGNED_INT_24_8_OES:
130 switch (format)
131 {
132 case GL_DEPTH_STENCIL_OES:
133 return true;
134 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000135 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000136 }
137
138 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000139 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000140 }
141}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000142
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000143bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000144 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000145 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000146{
147 if (!texture)
148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000149 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000150 }
151
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000152 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000154 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000155 }
156
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000157 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000158 {
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
160 if (internalformat != texture->getInternalFormat(level))
161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000162 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000163 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000164 }
165
166 if (compressed)
167 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000168 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
169 (height % 4 != 0 && height != texture->getHeight(0)))
170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000172 }
173 }
174
175 if (xoffset + width > texture->getWidth(level) ||
176 yoffset + height > texture->getHeight(level))
177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000178 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000179 }
180
181 return true;
182}
183
184bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000185 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000186 gl::TextureCubeMap *texture)
187{
188 if (!texture)
189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000190 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000191 }
192
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000193 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000198 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000199 {
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000200 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
201 if (internalformat != texture->getInternalFormat(target, level))
202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000203 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000204 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000205 }
206
207 if (compressed)
208 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000209 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
210 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000213 }
214 }
215
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000216 if (xoffset + width > texture->getWidth(target, level) ||
217 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000219 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000220 }
221
222 return true;
223}
224
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000225bool validateES3TexImageFormat(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
226 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
227 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000228{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000229 // Validate image size
230 if (level < 0 || width < 0 || height < 0 || depth < 0 )
231 {
232 return gl::error(GL_INVALID_VALUE, false);
233 }
234
235 if (isCompressed)
236 {
237 if (width != 1 && width != 2 && width % 4 != 0)
238 {
239 return gl::error(GL_INVALID_OPERATION, false);
240 }
241
242 if (height != 1 && height != 2 && height % 4 != 0)
243 {
244 return gl::error(GL_INVALID_OPERATION, false);
245 }
246 }
247
248 // Verify zero border
249 if (border != 0)
250 {
251 return gl::error(GL_INVALID_VALUE, false);
252 }
253
254 // Validate dimensions based on Context limits and validate the texture
255 if (level > context->getMaximumTextureLevel())
256 {
257 return gl::error(GL_INVALID_VALUE, false);
258 }
259
260 gl::Texture *texture = NULL;
261 bool textureCompressed = false;
262 GLenum textureInternalFormat = GL_NONE;
263 GLint textureLevelWidth = 0;
264 GLint textureLevelHeight = 0;
265 GLint textureLevelDepth = 0;
266 switch (target)
267 {
268 case GL_TEXTURE_2D:
269 {
270 if (width > (context->getMaximum2DTextureDimension() >> level) ||
271 height > (context->getMaximum2DTextureDimension() >> level))
272 {
273 return gl::error(GL_INVALID_VALUE, false);
274 }
275
276 gl::Texture2D *texture2d = context->getTexture2D();
277 if (texture2d)
278 {
279 textureCompressed = texture2d->isCompressed(level);
280 textureInternalFormat = texture2d->getInternalFormat(level);
281 textureLevelWidth = texture2d->getWidth(level);
282 textureLevelHeight = texture2d->getHeight(level);
283 textureLevelDepth = 1;
284 texture = texture2d;
285 }
286 }
287 break;
288
289 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
290 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
291 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
292 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
293 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
294 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
295 {
296 if (width != height)
297 {
298 return gl::error(GL_INVALID_VALUE, false);
299 }
300
301 if (width > (context->getMaximumCubeTextureDimension() >> level))
302 {
303 return gl::error(GL_INVALID_VALUE, false);
304 }
305
306 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
307 if (textureCube)
308 {
309 textureCompressed = textureCube->isCompressed(target, level);
310 textureInternalFormat = textureCube->getInternalFormat(target, level);
311 textureLevelWidth = textureCube->getWidth(target, level);
312 textureLevelHeight = textureCube->getHeight(target, level);
313 textureLevelDepth = 1;
314 texture = textureCube;
315 }
316 }
317 break;
318
319 case GL_TEXTURE_3D:
320 {
321 if (width > (context->getMaximum3DTextureDimension() >> level) ||
322 height > (context->getMaximum3DTextureDimension() >> level) ||
323 depth > (context->getMaximum3DTextureDimension() >> level))
324 {
325 return gl::error(GL_INVALID_VALUE, false);
326 }
327
328 gl::Texture3D *texture3d = context->getTexture3D();
329 if (texture3d)
330 {
331 textureCompressed = texture3d->isCompressed(level);
332 textureInternalFormat = texture3d->getInternalFormat(level);
333 textureLevelWidth = texture3d->getWidth(level);
334 textureLevelHeight = texture3d->getHeight(level);
335 textureLevelDepth = texture3d->getDepth(level);
336 texture = texture3d;
337 }
338 }
339 break;
340
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000341 case GL_TEXTURE_2D_ARRAY:
342 {
343 if (width > (context->getMaximum2DTextureDimension() >> level) ||
344 height > (context->getMaximum2DTextureDimension() >> level) ||
345 depth > (context->getMaximum2DArrayTextureLayers() >> level))
346 {
347 return gl::error(GL_INVALID_VALUE, false);
348 }
349
350 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
351 if (texture2darray)
352 {
353 textureCompressed = texture2darray->isCompressed(level);
354 textureInternalFormat = texture2darray->getInternalFormat(level);
355 textureLevelWidth = texture2darray->getWidth(level);
356 textureLevelHeight = texture2darray->getHeight(level);
357 textureLevelDepth = texture2darray->getDepth(level);
358 texture = texture2darray;
359 }
360 }
361 break;
362
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000363 default:
364 return gl::error(GL_INVALID_ENUM, false);
365 }
366
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000367 if (!texture)
368 {
369 return gl::error(GL_INVALID_OPERATION, false);
370 }
371
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000372 if (texture->isImmutable())
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000373 {
374 return gl::error(GL_INVALID_OPERATION, false);
375 }
376
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000377 // Validate texture formats
378 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
379 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000380 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000381 if (!gl::IsValidES3CompressedFormat(actualInternalFormat))
382 {
383 return gl::error(GL_INVALID_ENUM, false);
384 }
385
386 if (target == GL_TEXTURE_3D)
387 {
388 return gl::error(GL_INVALID_OPERATION, false);
389 }
390 }
391 else
392 {
393 GLenum err;
394 if (!gl::IsValidES3FormatCombination(actualInternalFormat, format, type, &err))
395 {
396 return gl::error(err, false);
397 }
398
399 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
400 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000401 {
402 return gl::error(GL_INVALID_OPERATION, false);
403 }
404 }
405
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000406 // Validate sub image parameters
407 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000408 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000409 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000410 {
411 return gl::error(GL_INVALID_OPERATION, false);
412 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000413
414 if (format != GL_NONE)
415 {
416 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
417 if (internalformat != textureInternalFormat)
418 {
419 return gl::error(GL_INVALID_OPERATION, false);
420 }
421 }
422
423 if (isCompressed)
424 {
425 if ((width % 4 != 0 && width != textureLevelWidth) ||
426 (height % 4 != 0 && height != textureLevelHeight))
427 {
428 return gl::error(GL_INVALID_OPERATION, false);
429 }
430 }
431
432 if (width == 0 || height == 0 || depth == 0)
433 {
434 return false;
435 }
436
437 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
438 {
439 return gl::error(GL_INVALID_VALUE, false);
440 }
441
442 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
443 std::numeric_limits<GLsizei>::max() - yoffset < height ||
444 std::numeric_limits<GLsizei>::max() - zoffset < depth)
445 {
446 return gl::error(GL_INVALID_VALUE, false);
447 }
448
449 if (xoffset + width > textureLevelWidth ||
450 yoffset + height > textureLevelHeight ||
451 zoffset + depth > textureLevelDepth)
452 {
453 return gl::error(GL_INVALID_VALUE, false);
454 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000455 }
456
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000457 return true;
458}
459
460bool validateCopyTexImageParameters(gl::Context *context, GLenum target, bool isCompressed, GLint level,
461 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
462 GLsizei width, GLsizei height)
463{
464 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000465 {
466 return gl::error(GL_INVALID_VALUE, false);
467 }
468
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000469 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
470 {
471 return gl::error(GL_INVALID_VALUE, false);
472 }
473
474 if (width == 0 || height == 0)
475 {
476 return false;
477 }
478
479 if (level > context->getMaximumTextureLevel())
480 {
481 return gl::error(GL_INVALID_VALUE, false);
482 }
483
484 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
485
486 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
487 {
488 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
489 }
490
491 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
492 {
493 return gl::error(GL_INVALID_OPERATION, false);
494 }
495
496 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
497 GLenum colorbufferFormat = source->getInternalFormat();
498 gl::Texture *texture = NULL;
499 GLenum textureFormat = GL_RGBA;
500 bool textureCompressed = false;
501 GLint textureLevelWidth = 0;
502 GLint textureLevelHeight = 0;
503 GLint textureLevelDepth = 0;
504 switch (target)
505 {
506 case GL_TEXTURE_2D:
507 {
508 gl::Texture2D *texture2d = context->getTexture2D();
509 if (texture2d)
510 {
511 textureFormat = gl::ExtractFormat(texture2d->getInternalFormat(level));
512 textureCompressed = texture2d->isCompressed(level);
513 textureLevelWidth = texture2d->getWidth(level);
514 textureLevelHeight = texture2d->getHeight(level);
515 textureLevelDepth = 1;
516 texture = texture2d;
517 }
518 }
519 break;
520
521 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
522 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
523 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
524 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
525 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
526 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
527 {
528 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
529 if (textureCube)
530 {
531 textureFormat = gl::ExtractFormat(textureCube->getInternalFormat(target, level));
532 textureCompressed = textureCube->isCompressed(target, level);
533 textureLevelWidth = textureCube->getWidth(target, level);
534 textureLevelHeight = textureCube->getHeight(target, level);
535 textureLevelDepth = 1;
536 texture = textureCube;
537 }
538 }
539 break;
540
541 case GL_TEXTURE_3D:
542 {
543 gl::Texture3D *texture3d = context->getTexture3D();
544 if (texture3d)
545 {
546 textureFormat = gl::ExtractFormat(texture3d->getInternalFormat(level));
547 textureCompressed = texture3d->isCompressed(level);
548 textureLevelWidth = texture3d->getWidth(level);
549 textureLevelHeight = texture3d->getHeight(level);
550 textureLevelDepth = texture3d->getDepth(level);
551 texture = texture3d;
552 }
553 }
554 break;
555
556 default:
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559
560 if (!texture)
561 {
562 return gl::error(GL_INVALID_OPERATION, false);
563 }
564
565 if (isCompressed != textureCompressed)
566 {
567 return gl::error(GL_INVALID_OPERATION, false);
568 }
569
570 if (isCompressed)
571 {
572 if ((width % 4 != 0 && width != textureLevelWidth) ||
573 (height % 4 != 0 && height != textureLevelHeight))
574 {
575 return gl::error(GL_INVALID_OPERATION, false);
576 }
577 }
578
579 if (xoffset + width > textureLevelWidth ||
580 yoffset + height > textureLevelHeight ||
581 zoffset >= textureLevelDepth)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 if (!gl::IsValidES3CopyTexImageCombination(textureFormat, colorbufferFormat))
587 {
588 return gl::error(GL_INVALID_OPERATION, false);
589 }
590
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000591 return true;
592}
593
daniel@transgaming.comb7915a52011-11-12 03:14:20 +0000594// check for combinations of format and type that are valid for ReadPixels
595bool validReadFormatType(GLenum format, GLenum type)
596{
597 switch (format)
598 {
599 case GL_RGBA:
600 switch (type)
601 {
602 case GL_UNSIGNED_BYTE:
603 break;
604 default:
605 return false;
606 }
607 break;
608 case GL_BGRA_EXT:
609 switch (type)
610 {
611 case GL_UNSIGNED_BYTE:
612 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
613 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
614 break;
615 default:
616 return false;
617 }
618 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +0000619 default:
620 return false;
621 }
622 return true;
623}
624
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625extern "C"
626{
627
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000628// OpenGL ES 2.0 functions
629
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000630void __stdcall glActiveTexture(GLenum texture)
631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000632 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
634 try
635 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000637
638 if (context)
639 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +0000640 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
641 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000642 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +0000643 }
644
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000645 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646 }
647 }
648 catch(std::bad_alloc&)
649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000650 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651 }
652}
653
654void __stdcall glAttachShader(GLuint program, GLuint shader)
655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000656 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000657
658 try
659 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000660 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000661
662 if (context)
663 {
664 gl::Program *programObject = context->getProgram(program);
665 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +0000666
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000667 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000668 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000669 if (context->getShader(program))
670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000672 }
673 else
674 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000675 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000676 }
677 }
678
679 if (!shaderObject)
680 {
681 if (context->getProgram(shader))
682 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000683 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000684 }
685 else
686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000687 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689 }
690
691 if (!programObject->attachShader(shaderObject))
692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000693 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000694 }
695 }
696 }
697 catch(std::bad_alloc&)
698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000699 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000700 }
701}
702
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000703void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
704{
705 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
706
707 try
708 {
709 switch (target)
710 {
711 case GL_ANY_SAMPLES_PASSED_EXT:
712 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
713 break;
714 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000715 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000716 }
717
718 if (id == 0)
719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000720 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000721 }
722
723 gl::Context *context = gl::getNonLostContext();
724
725 if (context)
726 {
727 context->beginQuery(target, id);
728 }
729 }
730 catch(std::bad_alloc&)
731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000732 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000733 }
734}
735
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000736void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000737{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000738 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000739
740 try
741 {
742 if (index >= gl::MAX_VERTEX_ATTRIBS)
743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000744 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000745 }
746
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000747 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000748
749 if (context)
750 {
751 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +0000752
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000753 if (!programObject)
754 {
daniel@transgaming.com98079832010-04-13 03:26:29 +0000755 if (context->getShader(program))
756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000757 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +0000758 }
759 else
760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000761 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +0000762 }
763 }
764
765 if (strncmp(name, "gl_", 3) == 0)
766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000767 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000768 }
769
770 programObject->bindAttributeLocation(index, name);
771 }
772 }
773 catch(std::bad_alloc&)
774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000775 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000776 }
777}
778
779void __stdcall glBindBuffer(GLenum target, GLuint buffer)
780{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000781 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000782
783 try
784 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000785 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000786
787 if (context)
788 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000789 // Check ES3 specific targets
790 switch (target)
791 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000792 case GL_COPY_READ_BUFFER:
793 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000794 case GL_PIXEL_PACK_BUFFER:
795 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000796 case GL_UNIFORM_BUFFER:
797 case GL_TRANSFORM_FEEDBACK_BUFFER:
798 if (context->getClientVersion() < 3)
799 {
800 return gl::error(GL_INVALID_ENUM);
801 }
802 }
803
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000804 switch (target)
805 {
806 case GL_ARRAY_BUFFER:
807 context->bindArrayBuffer(buffer);
808 return;
809 case GL_ELEMENT_ARRAY_BUFFER:
810 context->bindElementArrayBuffer(buffer);
811 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000812 case GL_COPY_READ_BUFFER:
813 context->bindCopyReadBuffer(buffer);
814 return;
815 case GL_COPY_WRITE_BUFFER:
816 context->bindCopyWriteBuffer(buffer);
817 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000818 case GL_PIXEL_PACK_BUFFER:
819 context->bindPixelPackBuffer(buffer);
820 return;
821 case GL_PIXEL_UNPACK_BUFFER:
822 context->bindPixelUnpackBuffer(buffer);
823 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000824 case GL_UNIFORM_BUFFER:
825 context->bindGenericUniformBuffer(buffer);
826 return;
827 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +0000828 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000829 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000830 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000831 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000832 }
833 }
834 }
835 catch(std::bad_alloc&)
836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000837 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000838 }
839}
840
841void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
842{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000843 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000844
845 try
846 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000847 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000849 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000850 }
851
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000852 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000853
854 if (context)
855 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000856 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
857 {
858 context->bindReadFramebuffer(framebuffer);
859 }
860
861 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
862 {
863 context->bindDrawFramebuffer(framebuffer);
864 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000865 }
866 }
867 catch(std::bad_alloc&)
868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000869 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000870 }
871}
872
873void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000875 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000876
877 try
878 {
879 if (target != GL_RENDERBUFFER)
880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000881 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000882 }
883
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000884 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000885
886 if (context)
887 {
888 context->bindRenderbuffer(renderbuffer);
889 }
890 }
891 catch(std::bad_alloc&)
892 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000893 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000894 }
895}
896
897void __stdcall glBindTexture(GLenum target, GLuint texture)
898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000899 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000900
901 try
902 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000903 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000904
905 if (context)
906 {
907 gl::Texture *textureObject = context->getTexture(texture);
908
909 if (textureObject && textureObject->getTarget() != target && texture != 0)
910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000911 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000912 }
913
914 switch (target)
915 {
916 case GL_TEXTURE_2D:
917 context->bindTexture2D(texture);
918 return;
919 case GL_TEXTURE_CUBE_MAP:
920 context->bindTextureCubeMap(texture);
921 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +0000922 case GL_TEXTURE_3D:
923 if (context->getClientVersion() < 3)
924 {
925 return gl::error(GL_INVALID_ENUM);
926 }
927 context->bindTexture3D(texture);
928 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000929 case GL_TEXTURE_2D_ARRAY:
930 if (context->getClientVersion() < 3)
931 {
932 return gl::error(GL_INVALID_ENUM);
933 }
934 context->bindTexture2DArray(texture);
935 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000936 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000937 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000938 }
939 }
940 }
941 catch(std::bad_alloc&)
942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000943 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000944 }
945}
946
947void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
948{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000949 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000950 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000951
952 try
953 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000954 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000955
956 if (context)
957 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000958 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000959 }
960 }
961 catch(std::bad_alloc&)
962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000963 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000964 }
965}
966
967void __stdcall glBlendEquation(GLenum mode)
968{
969 glBlendEquationSeparate(mode, mode);
970}
971
972void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
973{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000974 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975
976 try
977 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000978 gl::Context *context = gl::getNonLostContext();
979
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000980 switch (modeRGB)
981 {
982 case GL_FUNC_ADD:
983 case GL_FUNC_SUBTRACT:
984 case GL_FUNC_REVERSE_SUBTRACT:
985 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000986
987 case GL_MIN:
988 case GL_MAX:
989 if (context && context->getClientVersion() < 3)
990 {
991 return gl::error(GL_INVALID_ENUM);
992 }
993 break;
994
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000995 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000996 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997 }
998
999 switch (modeAlpha)
1000 {
1001 case GL_FUNC_ADD:
1002 case GL_FUNC_SUBTRACT:
1003 case GL_FUNC_REVERSE_SUBTRACT:
1004 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001005
1006 case GL_MIN:
1007 case GL_MAX:
1008 if (context && context->getClientVersion() < 3)
1009 {
1010 return gl::error(GL_INVALID_ENUM);
1011 }
1012 break;
1013
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001014 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001015 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016 }
1017
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001018 if (context)
1019 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001020 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021 }
1022 }
1023 catch(std::bad_alloc&)
1024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001025 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001026 }
1027}
1028
1029void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
1030{
1031 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
1032}
1033
1034void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
1035{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001036 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001037 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001038
1039 try
1040 {
1041 switch (srcRGB)
1042 {
1043 case GL_ZERO:
1044 case GL_ONE:
1045 case GL_SRC_COLOR:
1046 case GL_ONE_MINUS_SRC_COLOR:
1047 case GL_DST_COLOR:
1048 case GL_ONE_MINUS_DST_COLOR:
1049 case GL_SRC_ALPHA:
1050 case GL_ONE_MINUS_SRC_ALPHA:
1051 case GL_DST_ALPHA:
1052 case GL_ONE_MINUS_DST_ALPHA:
1053 case GL_CONSTANT_COLOR:
1054 case GL_ONE_MINUS_CONSTANT_COLOR:
1055 case GL_CONSTANT_ALPHA:
1056 case GL_ONE_MINUS_CONSTANT_ALPHA:
1057 case GL_SRC_ALPHA_SATURATE:
1058 break;
1059 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001060 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001061 }
1062
1063 switch (dstRGB)
1064 {
1065 case GL_ZERO:
1066 case GL_ONE:
1067 case GL_SRC_COLOR:
1068 case GL_ONE_MINUS_SRC_COLOR:
1069 case GL_DST_COLOR:
1070 case GL_ONE_MINUS_DST_COLOR:
1071 case GL_SRC_ALPHA:
1072 case GL_ONE_MINUS_SRC_ALPHA:
1073 case GL_DST_ALPHA:
1074 case GL_ONE_MINUS_DST_ALPHA:
1075 case GL_CONSTANT_COLOR:
1076 case GL_ONE_MINUS_CONSTANT_COLOR:
1077 case GL_CONSTANT_ALPHA:
1078 case GL_ONE_MINUS_CONSTANT_ALPHA:
1079 break;
1080 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001081 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001082 }
1083
1084 switch (srcAlpha)
1085 {
1086 case GL_ZERO:
1087 case GL_ONE:
1088 case GL_SRC_COLOR:
1089 case GL_ONE_MINUS_SRC_COLOR:
1090 case GL_DST_COLOR:
1091 case GL_ONE_MINUS_DST_COLOR:
1092 case GL_SRC_ALPHA:
1093 case GL_ONE_MINUS_SRC_ALPHA:
1094 case GL_DST_ALPHA:
1095 case GL_ONE_MINUS_DST_ALPHA:
1096 case GL_CONSTANT_COLOR:
1097 case GL_ONE_MINUS_CONSTANT_COLOR:
1098 case GL_CONSTANT_ALPHA:
1099 case GL_ONE_MINUS_CONSTANT_ALPHA:
1100 case GL_SRC_ALPHA_SATURATE:
1101 break;
1102 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001103 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001104 }
1105
1106 switch (dstAlpha)
1107 {
1108 case GL_ZERO:
1109 case GL_ONE:
1110 case GL_SRC_COLOR:
1111 case GL_ONE_MINUS_SRC_COLOR:
1112 case GL_DST_COLOR:
1113 case GL_ONE_MINUS_DST_COLOR:
1114 case GL_SRC_ALPHA:
1115 case GL_ONE_MINUS_SRC_ALPHA:
1116 case GL_DST_ALPHA:
1117 case GL_ONE_MINUS_DST_ALPHA:
1118 case GL_CONSTANT_COLOR:
1119 case GL_ONE_MINUS_CONSTANT_COLOR:
1120 case GL_CONSTANT_ALPHA:
1121 case GL_ONE_MINUS_CONSTANT_ALPHA:
1122 break;
1123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001124 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001125 }
1126
daniel@transgaming.comfe453652010-03-16 06:23:28 +00001127 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
1128 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
1129
1130 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
1131 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
1132
1133 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001134 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00001135 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001136 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001137 }
1138
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001140
1141 if (context)
1142 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001143 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001144 }
1145 }
1146 catch(std::bad_alloc&)
1147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001148 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149 }
1150}
1151
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001152void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001153{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001154 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001155 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001156
1157 try
1158 {
1159 if (size < 0)
1160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001161 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001162 }
1163
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00001164 gl::Context *context = gl::getNonLostContext();
1165
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001166 switch (usage)
1167 {
1168 case GL_STREAM_DRAW:
1169 case GL_STATIC_DRAW:
1170 case GL_DYNAMIC_DRAW:
1171 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00001172
1173 case GL_STREAM_READ:
1174 case GL_STREAM_COPY:
1175 case GL_STATIC_READ:
1176 case GL_STATIC_COPY:
1177 case GL_DYNAMIC_READ:
1178 case GL_DYNAMIC_COPY:
1179 if (context && context->getClientVersion() < 3)
1180 {
1181 return gl::error(GL_INVALID_ENUM);
1182 }
1183 break;
1184
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001185 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001186 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001187 }
1188
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001189 if (context)
1190 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001191 // Check ES3 specific targets
1192 switch (target)
1193 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001194 case GL_COPY_READ_BUFFER:
1195 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001196 case GL_PIXEL_PACK_BUFFER:
1197 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001198 case GL_UNIFORM_BUFFER:
1199 case GL_TRANSFORM_FEEDBACK_BUFFER:
1200 if (context->getClientVersion() < 3)
1201 {
1202 return gl::error(GL_INVALID_ENUM);
1203 }
1204 }
1205
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001207
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001208 switch (target)
1209 {
1210 case GL_ARRAY_BUFFER:
1211 buffer = context->getArrayBuffer();
1212 break;
1213 case GL_ELEMENT_ARRAY_BUFFER:
1214 buffer = context->getElementArrayBuffer();
1215 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001216 case GL_COPY_READ_BUFFER:
1217 buffer = context->getCopyReadBuffer();
1218 break;
1219 case GL_COPY_WRITE_BUFFER:
1220 buffer = context->getCopyWriteBuffer();
1221 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001222 case GL_PIXEL_PACK_BUFFER:
1223 buffer = context->getPixelPackBuffer();
1224 break;
1225 case GL_PIXEL_UNPACK_BUFFER:
1226 buffer = context->getPixelUnpackBuffer();
1227 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001228 case GL_TRANSFORM_FEEDBACK_BUFFER:
1229 buffer = context->getGenericTransformFeedbackBuffer();
1230 break;
1231 case GL_UNIFORM_BUFFER:
1232 buffer = context->getGenericUniformBuffer();
1233 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001234 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001235 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001236 }
1237
1238 if (!buffer)
1239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001240 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001241 }
1242
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001243 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001244 }
1245 }
1246 catch(std::bad_alloc&)
1247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001248 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001249 }
1250}
1251
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001252void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001253{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001254 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001255 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001256
1257 try
1258 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001259 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001260 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001261 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001262 }
1263
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00001264 if (data == NULL)
1265 {
1266 return;
1267 }
1268
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001269 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001270
1271 if (context)
1272 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001273 // Check ES3 specific targets
1274 switch (target)
1275 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001276 case GL_COPY_READ_BUFFER:
1277 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001278 case GL_PIXEL_PACK_BUFFER:
1279 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001280 case GL_UNIFORM_BUFFER:
1281 case GL_TRANSFORM_FEEDBACK_BUFFER:
1282 if (context->getClientVersion() < 3)
1283 {
1284 return gl::error(GL_INVALID_ENUM);
1285 }
1286 }
1287
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001288 gl::Buffer *buffer;
1289
1290 switch (target)
1291 {
1292 case GL_ARRAY_BUFFER:
1293 buffer = context->getArrayBuffer();
1294 break;
1295 case GL_ELEMENT_ARRAY_BUFFER:
1296 buffer = context->getElementArrayBuffer();
1297 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001298 case GL_COPY_READ_BUFFER:
1299 buffer = context->getCopyReadBuffer();
1300 break;
1301 case GL_COPY_WRITE_BUFFER:
1302 buffer = context->getCopyWriteBuffer();
1303 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001304 case GL_PIXEL_PACK_BUFFER:
1305 buffer = context->getPixelPackBuffer();
1306 break;
1307 case GL_PIXEL_UNPACK_BUFFER:
1308 buffer = context->getPixelUnpackBuffer();
1309 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001310 case GL_TRANSFORM_FEEDBACK_BUFFER:
1311 buffer = context->getGenericTransformFeedbackBuffer();
1312 break;
1313 case GL_UNIFORM_BUFFER:
1314 buffer = context->getGenericUniformBuffer();
1315 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001316 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001317 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001318 }
1319
1320 if (!buffer)
1321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001322 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001323 }
1324
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001325 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001327 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001328 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001329
1330 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001331 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001332 }
1333 catch(std::bad_alloc&)
1334 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001335 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001336 }
1337}
1338
1339GLenum __stdcall glCheckFramebufferStatus(GLenum target)
1340{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001341 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001342
1343 try
1344 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001345 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001347 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001348 }
1349
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001350 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001351
1352 if (context)
1353 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001354 gl::Framebuffer *framebuffer = NULL;
1355 if (target == GL_READ_FRAMEBUFFER_ANGLE)
1356 {
1357 framebuffer = context->getReadFramebuffer();
1358 }
1359 else
1360 {
1361 framebuffer = context->getDrawFramebuffer();
1362 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001363
1364 return framebuffer->completeness();
1365 }
1366 }
1367 catch(std::bad_alloc&)
1368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001369 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001370 }
1371
1372 return 0;
1373}
1374
1375void __stdcall glClear(GLbitfield mask)
1376{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001377 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001378
1379 try
1380 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001381 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001382
1383 if (context)
1384 {
1385 context->clear(mask);
1386 }
1387 }
1388 catch(std::bad_alloc&)
1389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001390 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001391 }
1392}
1393
1394void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1395{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001396 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001397 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001398
1399 try
1400 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001401 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001402
1403 if (context)
1404 {
1405 context->setClearColor(red, green, blue, alpha);
1406 }
1407 }
1408 catch(std::bad_alloc&)
1409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001410 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001411 }
1412}
1413
1414void __stdcall glClearDepthf(GLclampf depth)
1415{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001416 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001417
1418 try
1419 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001420 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001421
1422 if (context)
1423 {
1424 context->setClearDepth(depth);
1425 }
1426 }
1427 catch(std::bad_alloc&)
1428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001429 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001430 }
1431}
1432
1433void __stdcall glClearStencil(GLint s)
1434{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001435 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001436
1437 try
1438 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001440
1441 if (context)
1442 {
1443 context->setClearStencil(s);
1444 }
1445 }
1446 catch(std::bad_alloc&)
1447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001449 }
1450}
1451
1452void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
1453{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001454 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001455 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001456
1457 try
1458 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001459 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001460
1461 if (context)
1462 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00001463 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001464 }
1465 }
1466 catch(std::bad_alloc&)
1467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001469 }
1470}
1471
1472void __stdcall glCompileShader(GLuint shader)
1473{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001474 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001475
1476 try
1477 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001478 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001479
1480 if (context)
1481 {
1482 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001483
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001484 if (!shaderObject)
1485 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001486 if (context->getProgram(shader))
1487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001488 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001489 }
1490 else
1491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001492 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001493 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001494 }
1495
1496 shaderObject->compile();
1497 }
1498 }
1499 catch(std::bad_alloc&)
1500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001501 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001502 }
1503}
1504
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001505void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
1506 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001507{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001508 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001509 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001510 target, level, internalformat, width, height, border, imageSize, data);
1511
1512 try
1513 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001514 if (!validImageSize(level, width, height, 1) || border != 0 || imageSize < 0)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001515 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001516 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001517 }
1518
daniel@transgaming.com01868132010-08-24 19:21:17 +00001519 switch (internalformat)
1520 {
1521 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1522 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001523 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1524 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00001525 break;
1526 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001527 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001528 }
1529
1530 if (border != 0)
1531 {
shannon.woods@transgaming.com0efef902013-02-28 23:21:09 +00001532 return gl::error(GL_INVALID_OPERATION);
1533 }
1534
1535 if (width != 1 && width != 2 && width % 4 != 0)
1536 {
1537 return gl::error(GL_INVALID_OPERATION);
1538 }
1539
1540 if (height != 1 && height != 2 && height % 4 != 0)
1541 {
1542 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001543 }
1544
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001545 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001546
1547 if (context)
1548 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001549 if (level > context->getMaximumTextureLevel())
1550 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001551 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001552 }
1553
1554 switch (target)
1555 {
1556 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00001557 if (width > (context->getMaximum2DTextureDimension() >> level) ||
1558 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001560 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001561 }
1562 break;
1563 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1564 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1565 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1566 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1567 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1568 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1569 if (width != height)
1570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001571 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001572 }
1573
1574 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
1575 height > (context->getMaximumCubeTextureDimension() >> level))
1576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001577 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001578 }
1579 break;
1580 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001581 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001582 }
1583
gman@chromium.org50c526d2011-08-10 05:19:44 +00001584 switch (internalformat) {
1585 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1586 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1587 if (!context->supportsDXT1Textures())
1588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001589 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001590 }
1591 break;
1592 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1593 if (!context->supportsDXT3Textures())
1594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001595 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001596 }
1597 break;
1598 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1599 if (!context->supportsDXT5Textures())
1600 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001601 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001602 }
1603 break;
1604 default: UNREACHABLE();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001605 }
1606
1607 if (imageSize != gl::ComputeCompressedSize(width, height, internalformat))
1608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001609 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001610 }
1611
1612 if (target == GL_TEXTURE_2D)
1613 {
1614 gl::Texture2D *texture = context->getTexture2D();
1615
1616 if (!texture)
1617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001618 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001619 }
1620
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001621 if (texture->isImmutable())
1622 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001623 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001624 }
1625
daniel@transgaming.com01868132010-08-24 19:21:17 +00001626 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
1627 }
1628 else
1629 {
1630 gl::TextureCubeMap *texture = context->getTextureCubeMap();
1631
1632 if (!texture)
1633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001634 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001635 }
1636
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001637 if (texture->isImmutable())
1638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001639 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001640 }
1641
daniel@transgaming.com01868132010-08-24 19:21:17 +00001642 switch (target)
1643 {
1644 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1645 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1646 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1647 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1648 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1649 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1650 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
1651 break;
1652 default: UNREACHABLE();
1653 }
1654 }
1655 }
1656
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001657 }
1658 catch(std::bad_alloc&)
1659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001660 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001661 }
1662}
1663
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001664void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1665 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001666{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001667 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001668 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001669 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001670 target, level, xoffset, yoffset, width, height, format, imageSize, data);
1671
1672 try
1673 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00001674 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.com41430492010-03-11 20:36:18 +00001675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001676 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001677 }
1678
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001679 if (xoffset < 0 || yoffset < 0 || !validImageSize(level, width, height, 1) || imageSize < 0)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001681 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001682 }
1683
daniel@transgaming.com01868132010-08-24 19:21:17 +00001684 switch (format)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001685 {
daniel@transgaming.com01868132010-08-24 19:21:17 +00001686 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1687 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001688 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1689 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00001690 break;
1691 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001692 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001693 }
1694
daniel@transgaming.com01868132010-08-24 19:21:17 +00001695 if (width == 0 || height == 0 || data == NULL)
1696 {
1697 return;
1698 }
1699
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001700 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001701
1702 if (context)
1703 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001704 if (level > context->getMaximumTextureLevel())
1705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001707 }
1708
gman@chromium.org50c526d2011-08-10 05:19:44 +00001709 switch (format) {
1710 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1711 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1712 if (!context->supportsDXT1Textures())
1713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001714 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001715 }
1716 break;
1717 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1718 if (!context->supportsDXT3Textures())
1719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001720 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001721 }
1722 break;
1723 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1724 if (!context->supportsDXT5Textures())
1725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001726 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001727 }
1728 break;
1729 default: UNREACHABLE();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001730 }
1731
1732 if (imageSize != gl::ComputeCompressedSize(width, height, format))
1733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001734 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001735 }
1736
1737 if (xoffset % 4 != 0 || yoffset % 4 != 0)
1738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001739 return gl::error(GL_INVALID_OPERATION); // we wait to check the offsets until this point, because the multiple-of-four restriction
gman@chromium.org50c526d2011-08-10 05:19:44 +00001740 // does not exist unless DXT textures are supported.
daniel@transgaming.com01868132010-08-24 19:21:17 +00001741 }
1742
1743 if (target == GL_TEXTURE_2D)
1744 {
1745 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001746 if (validateSubImageParams2D(true, width, height, xoffset, yoffset, level, format, GL_NONE, texture))
daniel@transgaming.com01868132010-08-24 19:21:17 +00001747 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00001748 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001749 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00001750 }
1751 else if (gl::IsCubemapTextureTarget(target))
1752 {
1753 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001754 if (validateSubImageParamsCube(true, width, height, xoffset, yoffset, target, level, format, GL_NONE, texture))
daniel@transgaming.com01868132010-08-24 19:21:17 +00001755 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00001756 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001757 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00001758 }
1759 else
1760 {
1761 UNREACHABLE();
1762 }
1763 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001764 }
1765 catch(std::bad_alloc&)
1766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001767 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001768 }
1769}
1770
1771void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
1772{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001773 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001774 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001775 target, level, internalformat, x, y, width, height, border);
1776
1777 try
1778 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001779 if (!validImageSize(level, width, height, 1))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001781 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001782 }
1783
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001784 if (border != 0)
1785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001787 }
1788
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001789 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001790
1791 if (context)
1792 {
daniel@transgaming.com32b11442011-11-19 02:42:48 +00001793 if (level > context->getMaximumTextureLevel())
1794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001795 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com32b11442011-11-19 02:42:48 +00001796 }
1797
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001798 switch (target)
1799 {
1800 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00001801 if (width > (context->getMaximum2DTextureDimension() >> level) ||
1802 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001804 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001805 }
1806 break;
1807 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1808 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1809 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1810 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1811 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1812 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1813 if (width != height)
1814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001815 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001816 }
1817
1818 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
1819 height > (context->getMaximumCubeTextureDimension() >> level))
1820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001821 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001822 }
1823 break;
1824 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001825 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001826 }
1827
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001828 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001829
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001830 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001832 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001833 }
1834
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001835 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001837 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001838 }
1839
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001840 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001841 GLenum colorbufferFormat = source->getInternalFormat();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001842
1843 // [OpenGL ES 2.0.24] table 3.9
1844 switch (internalformat)
1845 {
1846 case GL_ALPHA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001847 if (colorbufferFormat != GL_ALPHA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001848 colorbufferFormat != GL_RGBA4 &&
1849 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001850 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001851 colorbufferFormat != GL_RGBA8_OES)
1852 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001853 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001854 }
1855 break;
1856 case GL_LUMINANCE:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001857 case GL_RGB:
1858 if (colorbufferFormat != GL_RGB565 &&
1859 colorbufferFormat != GL_RGB8_OES &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001860 colorbufferFormat != GL_RGBA4 &&
1861 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001862 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001863 colorbufferFormat != GL_RGBA8_OES)
1864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001865 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001866 }
1867 break;
1868 case GL_LUMINANCE_ALPHA:
1869 case GL_RGBA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001870 if (colorbufferFormat != GL_RGBA4 &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001871 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001872 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001873 colorbufferFormat != GL_RGBA8_OES)
1874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001875 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001876 }
1877 break;
1878 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1879 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001880 if (context->supportsDXT1Textures())
1881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001882 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001883 }
1884 else
1885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001886 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001887 }
1888 break;
1889 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1890 if (context->supportsDXT3Textures())
1891 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001892 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001893 }
1894 else
1895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001896 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001897 }
1898 break;
1899 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1900 if (context->supportsDXT5Textures())
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001901 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001902 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001903 }
1904 else
1905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001906 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001907 }
1908 break;
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001909 case GL_DEPTH_COMPONENT:
1910 case GL_DEPTH_COMPONENT16:
1911 case GL_DEPTH_COMPONENT32_OES:
1912 case GL_DEPTH_STENCIL_OES:
1913 case GL_DEPTH24_STENCIL8_OES:
1914 if (context->supportsDepthTextures())
1915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001916 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001917 }
1918 else
1919 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001920 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001921 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001922 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001923 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001924 }
1925
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001926 if (target == GL_TEXTURE_2D)
1927 {
1928 gl::Texture2D *texture = context->getTexture2D();
1929
1930 if (!texture)
1931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001932 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001933 }
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00001934
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001935 if (texture->isImmutable())
1936 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001937 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001938 }
1939
apatrick@chromium.orgb31f5322011-01-19 19:02:52 +00001940 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001941 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00001942 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001943 {
1944 gl::TextureCubeMap *texture = context->getTextureCubeMap();
1945
1946 if (!texture)
1947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001948 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001949 }
1950
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001951 if (texture->isImmutable())
1952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001953 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001954 }
1955
apatrick@chromium.orgb31f5322011-01-19 19:02:52 +00001956 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001957 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001958 else UNREACHABLE();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001959 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001960 }
1961 catch(std::bad_alloc&)
1962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001963 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001964 }
1965}
1966
1967void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1968{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001969 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001970 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001971 target, level, xoffset, yoffset, x, y, width, height);
1972
1973 try
1974 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00001975 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001977 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001978 }
1979
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001980 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001982 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001983 }
1984
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001985 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001987 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001988 }
1989
1990 if (width == 0 || height == 0)
1991 {
1992 return;
1993 }
1994
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001995 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001996
1997 if (context)
1998 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001999 if (level > context->getMaximumTextureLevel())
2000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002001 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002002 }
2003
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002004 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002005
daniel@transgaming.combbc57792010-07-28 19:21:05 +00002006 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
2007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002008 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.combbc57792010-07-28 19:21:05 +00002009 }
2010
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002011 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00002012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002013 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00002014 }
2015
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002016 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00002017 GLenum colorbufferFormat = source->getInternalFormat();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002018 gl::Texture *texture = NULL;
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002019 GLenum textureFormat = GL_RGBA;
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002020
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002021 if (target == GL_TEXTURE_2D)
2022 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002023 gl::Texture2D *tex2d = context->getTexture2D();
2024
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002025 if (!validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002026 {
2027 return; // error already registered by validateSubImageParams
2028 }
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002029 textureFormat = gl::ExtractFormat(tex2d->getInternalFormat(level));
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002030 texture = tex2d;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002031 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00002032 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002033 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002034 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
2035
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002036 if (!validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002037 {
2038 return; // error already registered by validateSubImageParams
2039 }
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002040 textureFormat = gl::ExtractFormat(texcube->getInternalFormat(target, level));
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002041 texture = texcube;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002042 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002043 else UNREACHABLE();
2044
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002045 // [OpenGL ES 2.0.24] table 3.9
2046 switch (textureFormat)
2047 {
2048 case GL_ALPHA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002049 if (colorbufferFormat != GL_ALPHA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002050 colorbufferFormat != GL_RGBA4 &&
2051 colorbufferFormat != GL_RGB5_A1 &&
2052 colorbufferFormat != GL_RGBA8_OES)
2053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002054 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002055 }
2056 break;
2057 case GL_LUMINANCE:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002058 case GL_RGB:
2059 if (colorbufferFormat != GL_RGB565 &&
2060 colorbufferFormat != GL_RGB8_OES &&
2061 colorbufferFormat != GL_RGBA4 &&
2062 colorbufferFormat != GL_RGB5_A1 &&
2063 colorbufferFormat != GL_RGBA8_OES)
2064 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002065 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002066 }
2067 break;
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002068 case GL_LUMINANCE_ALPHA:
2069 case GL_RGBA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002070 if (colorbufferFormat != GL_RGBA4 &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002071 colorbufferFormat != GL_RGB5_A1 &&
2072 colorbufferFormat != GL_RGBA8_OES)
2073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002074 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002075 }
2076 break;
2077 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2078 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00002079 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
2080 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002081 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00002082 case GL_DEPTH_COMPONENT:
2083 case GL_DEPTH_STENCIL_OES:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002084 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002085 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002086 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002087 }
2088
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +00002089 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002091 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002092
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002093 catch(std::bad_alloc&)
2094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002096 }
2097}
2098
2099GLuint __stdcall glCreateProgram(void)
2100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002101 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002102
2103 try
2104 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002106
2107 if (context)
2108 {
2109 return context->createProgram();
2110 }
2111 }
2112 catch(std::bad_alloc&)
2113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002114 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002115 }
2116
2117 return 0;
2118}
2119
2120GLuint __stdcall glCreateShader(GLenum type)
2121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002122 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002123
2124 try
2125 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002126 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002127
2128 if (context)
2129 {
2130 switch (type)
2131 {
2132 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002133 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002134 return context->createShader(type);
2135 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002136 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002137 }
2138 }
2139 }
2140 catch(std::bad_alloc&)
2141 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002142 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002143 }
2144
2145 return 0;
2146}
2147
2148void __stdcall glCullFace(GLenum mode)
2149{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002150 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151
2152 try
2153 {
2154 switch (mode)
2155 {
2156 case GL_FRONT:
2157 case GL_BACK:
2158 case GL_FRONT_AND_BACK:
2159 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002160 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002161
2162 if (context)
2163 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002164 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002165 }
2166 }
2167 break;
2168 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002169 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002170 }
2171 }
2172 catch(std::bad_alloc&)
2173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002174 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002175 }
2176}
2177
2178void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
2179{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002180 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002181
2182 try
2183 {
2184 if (n < 0)
2185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002186 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002187 }
2188
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002190
2191 if (context)
2192 {
2193 for (int i = 0; i < n; i++)
2194 {
2195 context->deleteBuffer(buffers[i]);
2196 }
2197 }
2198 }
2199 catch(std::bad_alloc&)
2200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002201 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002202 }
2203}
2204
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002205void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
2206{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002207 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002208
2209 try
2210 {
2211 if (n < 0)
2212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002213 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002214 }
2215
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002216 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002217
2218 if (context)
2219 {
2220 for (int i = 0; i < n; i++)
2221 {
2222 context->deleteFence(fences[i]);
2223 }
2224 }
2225 }
2226 catch(std::bad_alloc&)
2227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002228 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002229 }
2230}
2231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002232void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
2233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002234 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002235
2236 try
2237 {
2238 if (n < 0)
2239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002240 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002241 }
2242
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002244
2245 if (context)
2246 {
2247 for (int i = 0; i < n; i++)
2248 {
2249 if (framebuffers[i] != 0)
2250 {
2251 context->deleteFramebuffer(framebuffers[i]);
2252 }
2253 }
2254 }
2255 }
2256 catch(std::bad_alloc&)
2257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002258 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002259 }
2260}
2261
2262void __stdcall glDeleteProgram(GLuint program)
2263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002264 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002265
2266 try
2267 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002268 if (program == 0)
2269 {
2270 return;
2271 }
2272
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002273 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002274
2275 if (context)
2276 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002277 if (!context->getProgram(program))
2278 {
2279 if(context->getShader(program))
2280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002281 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002282 }
2283 else
2284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002285 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002286 }
2287 }
2288
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002289 context->deleteProgram(program);
2290 }
2291 }
2292 catch(std::bad_alloc&)
2293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002295 }
2296}
2297
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002298void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
2299{
2300 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
2301
2302 try
2303 {
2304 if (n < 0)
2305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002307 }
2308
2309 gl::Context *context = gl::getNonLostContext();
2310
2311 if (context)
2312 {
2313 for (int i = 0; i < n; i++)
2314 {
2315 context->deleteQuery(ids[i]);
2316 }
2317 }
2318 }
2319 catch(std::bad_alloc&)
2320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002322 }
2323}
2324
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002325void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
2326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002327 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002328
2329 try
2330 {
2331 if (n < 0)
2332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002334 }
2335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337
2338 if (context)
2339 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00002340 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002341 {
2342 context->deleteRenderbuffer(renderbuffers[i]);
2343 }
2344 }
2345 }
2346 catch(std::bad_alloc&)
2347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349 }
2350}
2351
2352void __stdcall glDeleteShader(GLuint shader)
2353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002354 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002355
2356 try
2357 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002358 if (shader == 0)
2359 {
2360 return;
2361 }
2362
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002364
2365 if (context)
2366 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002367 if (!context->getShader(shader))
2368 {
2369 if(context->getProgram(shader))
2370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002371 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002372 }
2373 else
2374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002375 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002376 }
2377 }
2378
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002379 context->deleteShader(shader);
2380 }
2381 }
2382 catch(std::bad_alloc&)
2383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002384 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002385 }
2386}
2387
2388void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
2389{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002390 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002391
2392 try
2393 {
2394 if (n < 0)
2395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002396 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002397 }
2398
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002400
2401 if (context)
2402 {
2403 for (int i = 0; i < n; i++)
2404 {
2405 if (textures[i] != 0)
2406 {
2407 context->deleteTexture(textures[i]);
2408 }
2409 }
2410 }
2411 }
2412 catch(std::bad_alloc&)
2413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002415 }
2416}
2417
2418void __stdcall glDepthFunc(GLenum func)
2419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002420 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002421
2422 try
2423 {
2424 switch (func)
2425 {
2426 case GL_NEVER:
2427 case GL_ALWAYS:
2428 case GL_LESS:
2429 case GL_LEQUAL:
2430 case GL_EQUAL:
2431 case GL_GREATER:
2432 case GL_GEQUAL:
2433 case GL_NOTEQUAL:
2434 break;
2435 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002436 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002437 }
2438
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002440
2441 if (context)
2442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002443 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002444 }
2445 }
2446 catch(std::bad_alloc&)
2447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 }
2450}
2451
2452void __stdcall glDepthMask(GLboolean flag)
2453{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002454 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002455
2456 try
2457 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002459
2460 if (context)
2461 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002462 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 }
2464 }
2465 catch(std::bad_alloc&)
2466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002467 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468 }
2469}
2470
2471void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
2472{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002473 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002474
2475 try
2476 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002477 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002478
2479 if (context)
2480 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002481 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002482 }
2483 }
2484 catch(std::bad_alloc&)
2485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002487 }
2488}
2489
2490void __stdcall glDetachShader(GLuint program, GLuint shader)
2491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002492 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493
2494 try
2495 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002496 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002497
2498 if (context)
2499 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002500
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002501 gl::Program *programObject = context->getProgram(program);
2502 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002503
2504 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002505 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002506 gl::Shader *shaderByProgramHandle;
2507 shaderByProgramHandle = context->getShader(program);
2508 if (!shaderByProgramHandle)
2509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002511 }
2512 else
2513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002515 }
2516 }
2517
2518 if (!shaderObject)
2519 {
2520 gl::Program *programByShaderHandle = context->getProgram(shader);
2521 if (!programByShaderHandle)
2522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002523 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002524 }
2525 else
2526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002527 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002528 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529 }
2530
2531 if (!programObject->detachShader(shaderObject))
2532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002533 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002535 }
2536 }
2537 catch(std::bad_alloc&)
2538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002539 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002540 }
2541}
2542
2543void __stdcall glDisable(GLenum cap)
2544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002545 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002546
2547 try
2548 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002549 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550
2551 if (context)
2552 {
2553 switch (cap)
2554 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002555 case GL_CULL_FACE: context->setCullFace(false); break;
2556 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
2557 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
2558 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
2559 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
2560 case GL_STENCIL_TEST: context->setStencilTest(false); break;
2561 case GL_DEPTH_TEST: context->setDepthTest(false); break;
2562 case GL_BLEND: context->setBlend(false); break;
2563 case GL_DITHER: context->setDither(false); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002564 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002565 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002566 }
2567 }
2568 }
2569 catch(std::bad_alloc&)
2570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002571 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002572 }
2573}
2574
2575void __stdcall glDisableVertexAttribArray(GLuint index)
2576{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002577 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578
2579 try
2580 {
2581 if (index >= gl::MAX_VERTEX_ATTRIBS)
2582 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002583 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002584 }
2585
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002586 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002587
2588 if (context)
2589 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002590 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002591 }
2592 }
2593 catch(std::bad_alloc&)
2594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002595 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002596 }
2597}
2598
2599void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
2600{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002601 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002602
2603 try
2604 {
2605 if (count < 0 || first < 0)
2606 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002607 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002608 }
2609
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002610 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002611
2612 if (context)
2613 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002614 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002615 }
2616 }
2617 catch(std::bad_alloc&)
2618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002619 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002620 }
2621}
2622
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002623void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
2624{
2625 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
2626
2627 try
2628 {
2629 if (count < 0 || first < 0 || primcount < 0)
2630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002631 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002632 }
2633
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002634 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002635 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002636 gl::Context *context = gl::getNonLostContext();
2637
2638 if (context)
2639 {
2640 context->drawArrays(mode, first, count, primcount);
2641 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002642 }
2643 }
2644 catch(std::bad_alloc&)
2645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002646 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002647 }
2648}
2649
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002650void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002651{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002652 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002653 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002654
2655 try
2656 {
2657 if (count < 0)
2658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002659 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002660 }
2661
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002662 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002663
2664 if (context)
2665 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002666 switch (type)
2667 {
2668 case GL_UNSIGNED_BYTE:
2669 case GL_UNSIGNED_SHORT:
2670 break;
2671 case GL_UNSIGNED_INT:
2672 if (!context->supports32bitIndices())
2673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002674 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00002675 }
2676 break;
2677 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002678 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00002679 }
2680
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002681 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002682 }
2683 }
2684 catch(std::bad_alloc&)
2685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002686 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002687 }
2688}
2689
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002690void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
2691{
2692 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
2693 mode, count, type, indices, primcount);
2694
2695 try
2696 {
2697 if (count < 0 || primcount < 0)
2698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002699 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002700 }
2701
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002702 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002703 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002704 gl::Context *context = gl::getNonLostContext();
2705
2706 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002707 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002708 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002709 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002710 case GL_UNSIGNED_BYTE:
2711 case GL_UNSIGNED_SHORT:
2712 break;
2713 case GL_UNSIGNED_INT:
2714 if (!context->supports32bitIndices())
2715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002716 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002717 }
2718 break;
2719 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002720 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002721 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002722
2723 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002724 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002725 }
2726 }
2727 catch(std::bad_alloc&)
2728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002729 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002730 }
2731}
2732
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002733void __stdcall glEnable(GLenum cap)
2734{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002735 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002736
2737 try
2738 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002739 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002740
2741 if (context)
2742 {
2743 switch (cap)
2744 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002745 case GL_CULL_FACE: context->setCullFace(true); break;
2746 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
2747 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
2748 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
2749 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
2750 case GL_STENCIL_TEST: context->setStencilTest(true); break;
2751 case GL_DEPTH_TEST: context->setDepthTest(true); break;
2752 case GL_BLEND: context->setBlend(true); break;
2753 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002754 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002755 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002756 }
2757 }
2758 }
2759 catch(std::bad_alloc&)
2760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002761 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762 }
2763}
2764
2765void __stdcall glEnableVertexAttribArray(GLuint index)
2766{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002767 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002768
2769 try
2770 {
2771 if (index >= gl::MAX_VERTEX_ATTRIBS)
2772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002773 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774 }
2775
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002776 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777
2778 if (context)
2779 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002780 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781 }
2782 }
2783 catch(std::bad_alloc&)
2784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002785 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002786 }
2787}
2788
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002789void __stdcall glEndQueryEXT(GLenum target)
2790{
2791 EVENT("GLenum target = 0x%X)", target);
2792
2793 try
2794 {
2795 switch (target)
2796 {
2797 case GL_ANY_SAMPLES_PASSED_EXT:
2798 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2799 break;
2800 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002801 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002802 }
2803
2804 gl::Context *context = gl::getNonLostContext();
2805
2806 if (context)
2807 {
2808 context->endQuery(target);
2809 }
2810 }
2811 catch(std::bad_alloc&)
2812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002813 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002814 }
2815}
2816
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002817void __stdcall glFinishFenceNV(GLuint fence)
2818{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002819 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002820
2821 try
2822 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002823 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002824
2825 if (context)
2826 {
2827 gl::Fence* fenceObject = context->getFence(fence);
2828
2829 if (fenceObject == NULL)
2830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002831 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002832 }
2833
2834 fenceObject->finishFence();
2835 }
2836 }
2837 catch(std::bad_alloc&)
2838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002839 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002840 }
2841}
2842
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843void __stdcall glFinish(void)
2844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002845 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002846
2847 try
2848 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002849 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002850
2851 if (context)
2852 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00002853 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002854 }
2855 }
2856 catch(std::bad_alloc&)
2857 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002858 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002859 }
2860}
2861
2862void __stdcall glFlush(void)
2863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002864 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002865
2866 try
2867 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002868 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002869
2870 if (context)
2871 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00002872 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002873 }
2874 }
2875 catch(std::bad_alloc&)
2876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002877 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002878 }
2879}
2880
2881void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
2882{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002883 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002884 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002885
2886 try
2887 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002888 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002889 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002891 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002892 }
2893
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002894 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002895
2896 if (context)
2897 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002898 gl::Framebuffer *framebuffer = NULL;
2899 GLuint framebufferHandle = 0;
2900 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2901 {
2902 framebuffer = context->getReadFramebuffer();
2903 framebufferHandle = context->getReadFramebufferHandle();
2904 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002905 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002906 {
2907 framebuffer = context->getDrawFramebuffer();
2908 framebufferHandle = context->getDrawFramebufferHandle();
2909 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002910
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002911 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002912 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002913 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002914 }
2915
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002916 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002917 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002918 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
2919
2920 if (colorAttachment >= context->getMaximumRenderTargets())
2921 {
2922 return gl::error(GL_INVALID_VALUE);
2923 }
2924
2925 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
2926 }
2927 else
2928 {
2929 switch (attachment)
2930 {
2931 case GL_DEPTH_ATTACHMENT:
2932 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
2933 break;
2934 case GL_STENCIL_ATTACHMENT:
2935 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
2936 break;
2937 default:
2938 return gl::error(GL_INVALID_ENUM);
2939 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002940 }
2941 }
2942 }
2943 catch(std::bad_alloc&)
2944 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002945 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002946 }
2947}
2948
2949void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
2950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002951 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002952 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002953
2954 try
2955 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002956 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002958 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002959 }
2960
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002962
2963 if (context)
2964 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002965 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2966 {
2967 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
2968
2969 if (colorAttachment >= context->getMaximumRenderTargets())
2970 {
2971 return gl::error(GL_INVALID_VALUE);
2972 }
2973 }
2974 else
2975 {
2976 switch (attachment)
2977 {
2978 case GL_DEPTH_ATTACHMENT:
2979 case GL_STENCIL_ATTACHMENT:
2980 break;
2981 default:
2982 return gl::error(GL_INVALID_ENUM);
2983 }
2984 }
2985
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002986 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002987 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002988 textarget = GL_NONE;
2989 }
2990 else
2991 {
2992 gl::Texture *tex = context->getTexture(texture);
2993
2994 if (tex == NULL)
2995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002996 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002997 }
2998
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002999 switch (textarget)
3000 {
3001 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003002 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003003 if (tex->getTarget() != GL_TEXTURE_2D)
3004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003005 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003006 }
3007 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003008 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003010 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003011 }
3012 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003013 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003014
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003015 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003016 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003017 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003019 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003021 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003022 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
3023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003024 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003025 }
3026 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003027 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003028 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003029 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003030 }
3031 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003032 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003033
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003034 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003035 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003036 }
3037
3038 if (level != 0)
3039 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003040 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003041 }
3042 }
3043
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003044 gl::Framebuffer *framebuffer = NULL;
3045 GLuint framebufferHandle = 0;
3046 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3047 {
3048 framebuffer = context->getReadFramebuffer();
3049 framebufferHandle = context->getReadFramebufferHandle();
3050 }
3051 else
3052 {
3053 framebuffer = context->getDrawFramebuffer();
3054 framebufferHandle = context->getDrawFramebufferHandle();
3055 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003056
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003057 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003058 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003059 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003060 }
3061
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003062 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003063 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003064 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3065
3066 if (colorAttachment >= context->getMaximumRenderTargets())
3067 {
3068 return gl::error(GL_INVALID_VALUE);
3069 }
3070
3071 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
3072 }
3073 else
3074 {
3075 switch (attachment)
3076 {
3077 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
3078 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
3079 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003080 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003081 }
3082 }
3083 catch(std::bad_alloc&)
3084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003085 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003086 }
3087}
3088
3089void __stdcall glFrontFace(GLenum mode)
3090{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003091 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003092
3093 try
3094 {
3095 switch (mode)
3096 {
3097 case GL_CW:
3098 case GL_CCW:
3099 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003101
3102 if (context)
3103 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003104 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003105 }
3106 }
3107 break;
3108 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003109 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003110 }
3111 }
3112 catch(std::bad_alloc&)
3113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
3116}
3117
3118void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
3119{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003120 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003121
3122 try
3123 {
3124 if (n < 0)
3125 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003126 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003127 }
3128
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003129 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003130
3131 if (context)
3132 {
3133 for (int i = 0; i < n; i++)
3134 {
3135 buffers[i] = context->createBuffer();
3136 }
3137 }
3138 }
3139 catch(std::bad_alloc&)
3140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003141 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 }
3143}
3144
3145void __stdcall glGenerateMipmap(GLenum target)
3146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003147 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148
3149 try
3150 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003151 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003152
3153 if (context)
3154 {
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003155 switch (target)
3156 {
3157 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003158 {
3159 gl::Texture2D *tex2d = context->getTexture2D();
3160
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003161 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003163 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003164 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003165 if (tex2d->isDepth(0))
3166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003167 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003168 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003169
3170 tex2d->generateMipmaps();
3171 break;
3172 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003173
3174 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003175 {
3176 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
3177
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003178 if (texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003180 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003181 }
3182
3183 texcube->generateMipmaps();
3184 break;
3185 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003186
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00003187 case GL_TEXTURE_3D:
3188 {
3189 if (context->getClientVersion() < 3)
3190 {
3191 return gl::error(GL_INVALID_ENUM);
3192 }
3193
3194 gl::Texture3D *tex3D = context->getTexture3D();
3195 if (tex3D->isCompressed(0))
3196 {
3197 return gl::error(GL_INVALID_OPERATION);
3198 }
3199
3200 tex3D->generateMipmaps();
3201 break;
3202 }
3203
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00003204 case GL_TEXTURE_2D_ARRAY:
3205 {
3206 if (context->getClientVersion() < 3)
3207 {
3208 return gl::error(GL_INVALID_ENUM);
3209 }
3210
3211 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
3212 if (tex2darr->isCompressed(0))
3213 {
3214 return gl::error(GL_INVALID_OPERATION);
3215 }
3216
3217 tex2darr->generateMipmaps();
3218 break;
3219 }
3220
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003221 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003222 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003223 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003224 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003225 }
3226 catch(std::bad_alloc&)
3227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003228 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229 }
3230}
3231
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003232void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
3233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003234 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003235
3236 try
3237 {
3238 if (n < 0)
3239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003240 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003241 }
3242
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003243 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003244
3245 if (context)
3246 {
3247 for (int i = 0; i < n; i++)
3248 {
3249 fences[i] = context->createFence();
3250 }
3251 }
3252 }
3253 catch(std::bad_alloc&)
3254 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003255 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003256 }
3257}
3258
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
3260{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003261 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003262
3263 try
3264 {
3265 if (n < 0)
3266 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003267 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
3269
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003270 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003271
3272 if (context)
3273 {
3274 for (int i = 0; i < n; i++)
3275 {
3276 framebuffers[i] = context->createFramebuffer();
3277 }
3278 }
3279 }
3280 catch(std::bad_alloc&)
3281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003282 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283 }
3284}
3285
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003286void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
3287{
3288 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
3289
3290 try
3291 {
3292 if (n < 0)
3293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003294 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003295 }
3296
3297 gl::Context *context = gl::getNonLostContext();
3298
3299 if (context)
3300 {
3301 for (int i = 0; i < n; i++)
3302 {
3303 ids[i] = context->createQuery();
3304 }
3305 }
3306 }
3307 catch(std::bad_alloc&)
3308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003309 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003310 }
3311}
3312
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003313void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
3314{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003315 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003316
3317 try
3318 {
3319 if (n < 0)
3320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003321 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003322 }
3323
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003324 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325
3326 if (context)
3327 {
3328 for (int i = 0; i < n; i++)
3329 {
3330 renderbuffers[i] = context->createRenderbuffer();
3331 }
3332 }
3333 }
3334 catch(std::bad_alloc&)
3335 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003336 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337 }
3338}
3339
3340void __stdcall glGenTextures(GLsizei n, GLuint* textures)
3341{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003342 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003343
3344 try
3345 {
3346 if (n < 0)
3347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003348 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003349 }
3350
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003351 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003352
3353 if (context)
3354 {
3355 for (int i = 0; i < n; i++)
3356 {
3357 textures[i] = context->createTexture();
3358 }
3359 }
3360 }
3361 catch(std::bad_alloc&)
3362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003363 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364 }
3365}
3366
daniel@transgaming.com85423182010-04-22 13:35:27 +00003367void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003369 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00003370 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003371 program, index, bufsize, length, size, type, name);
3372
3373 try
3374 {
3375 if (bufsize < 0)
3376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003377 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003378 }
3379
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003380 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00003381
3382 if (context)
3383 {
3384 gl::Program *programObject = context->getProgram(program);
3385
3386 if (!programObject)
3387 {
3388 if (context->getShader(program))
3389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003390 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003391 }
3392 else
3393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003394 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003395 }
3396 }
3397
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003398 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00003399 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003400 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003401 }
3402
3403 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
3404 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003405 }
3406 catch(std::bad_alloc&)
3407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003408 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003409 }
3410}
3411
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003412void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003413{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003414 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003415 "GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003416 program, index, bufsize, length, size, type, name);
3417
3418 try
3419 {
3420 if (bufsize < 0)
3421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003422 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 }
3424
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003425 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003426
3427 if (context)
3428 {
3429 gl::Program *programObject = context->getProgram(program);
3430
3431 if (!programObject)
3432 {
3433 if (context->getShader(program))
3434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003435 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003436 }
3437 else
3438 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003439 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003440 }
3441 }
3442
3443 if (index >= (GLuint)programObject->getActiveUniformCount())
3444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003445 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003446 }
3447
3448 programObject->getActiveUniform(index, bufsize, length, size, type, name);
3449 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003450 }
3451 catch(std::bad_alloc&)
3452 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003453 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003454 }
3455}
3456
3457void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
3458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003459 EVENT("(GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003460 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003461
3462 try
3463 {
3464 if (maxcount < 0)
3465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003466 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003467 }
3468
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003469 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00003470
3471 if (context)
3472 {
3473 gl::Program *programObject = context->getProgram(program);
3474
3475 if (!programObject)
3476 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003477 if (context->getShader(program))
3478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003479 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003480 }
3481 else
3482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003483 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003484 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00003485 }
3486
3487 return programObject->getAttachedShaders(maxcount, count, shaders);
3488 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003489 }
3490 catch(std::bad_alloc&)
3491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003492 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003493 }
3494}
3495
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003496int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003498 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003499
3500 try
3501 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003502 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003503
3504 if (context)
3505 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003506
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003507 gl::Program *programObject = context->getProgram(program);
3508
3509 if (!programObject)
3510 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003511 if (context->getShader(program))
3512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003513 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003514 }
3515 else
3516 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003517 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003518 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003519 }
3520
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00003521 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00003522 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00003523 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003524 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00003525 }
3526
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00003527 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003528 }
3529 }
3530 catch(std::bad_alloc&)
3531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003532 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003533 }
3534
3535 return -1;
3536}
3537
3538void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
3539{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003540 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003541
3542 try
3543 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003544 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003545
3546 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003547 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003548 if (!(context->getBooleanv(pname, params)))
3549 {
3550 GLenum nativeType;
3551 unsigned int numParams = 0;
3552 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003553 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003554
3555 if (numParams == 0)
3556 return; // it is known that the pname is valid, but there are no parameters to return
3557
3558 if (nativeType == GL_FLOAT)
3559 {
3560 GLfloat *floatParams = NULL;
3561 floatParams = new GLfloat[numParams];
3562
3563 context->getFloatv(pname, floatParams);
3564
3565 for (unsigned int i = 0; i < numParams; ++i)
3566 {
3567 if (floatParams[i] == 0.0f)
3568 params[i] = GL_FALSE;
3569 else
3570 params[i] = GL_TRUE;
3571 }
3572
3573 delete [] floatParams;
3574 }
3575 else if (nativeType == GL_INT)
3576 {
3577 GLint *intParams = NULL;
3578 intParams = new GLint[numParams];
3579
3580 context->getIntegerv(pname, intParams);
3581
3582 for (unsigned int i = 0; i < numParams; ++i)
3583 {
3584 if (intParams[i] == 0)
3585 params[i] = GL_FALSE;
3586 else
3587 params[i] = GL_TRUE;
3588 }
3589
3590 delete [] intParams;
3591 }
3592 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003593 }
3594 }
3595 catch(std::bad_alloc&)
3596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003597 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598 }
3599}
3600
3601void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
3602{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003603 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003604
3605 try
3606 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003607 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003608
3609 if (context)
3610 {
3611 gl::Buffer *buffer;
3612
3613 switch (target)
3614 {
3615 case GL_ARRAY_BUFFER:
3616 buffer = context->getArrayBuffer();
3617 break;
3618 case GL_ELEMENT_ARRAY_BUFFER:
3619 buffer = context->getElementArrayBuffer();
3620 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003621 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003622 }
3623
3624 if (!buffer)
3625 {
3626 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003627 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003628 }
3629
3630 switch (pname)
3631 {
3632 case GL_BUFFER_USAGE:
3633 *params = buffer->usage();
3634 break;
3635 case GL_BUFFER_SIZE:
3636 *params = buffer->size();
3637 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003638 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003639 }
3640 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003641 }
3642 catch(std::bad_alloc&)
3643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003644 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003645 }
3646}
3647
3648GLenum __stdcall glGetError(void)
3649{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003650 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651
3652 gl::Context *context = gl::getContext();
3653
3654 if (context)
3655 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00003656 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003657 }
3658
3659 return GL_NO_ERROR;
3660}
3661
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003662void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
3663{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003664 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003665
3666 try
3667 {
3668
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003669 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003670
3671 if (context)
3672 {
3673 gl::Fence *fenceObject = context->getFence(fence);
3674
3675 if (fenceObject == NULL)
3676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003677 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003678 }
3679
3680 fenceObject->getFenceiv(pname, params);
3681 }
3682 }
3683 catch(std::bad_alloc&)
3684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003685 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003686 }
3687}
3688
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003689void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
3690{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003691 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003692
3693 try
3694 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003695 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003696
3697 if (context)
3698 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003699 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003700 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003701 GLenum nativeType;
3702 unsigned int numParams = 0;
3703 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003704 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003705
3706 if (numParams == 0)
3707 return; // it is known that the pname is valid, but that there are no parameters to return.
3708
3709 if (nativeType == GL_BOOL)
3710 {
3711 GLboolean *boolParams = NULL;
3712 boolParams = new GLboolean[numParams];
3713
3714 context->getBooleanv(pname, boolParams);
3715
3716 for (unsigned int i = 0; i < numParams; ++i)
3717 {
3718 if (boolParams[i] == GL_FALSE)
3719 params[i] = 0.0f;
3720 else
3721 params[i] = 1.0f;
3722 }
3723
3724 delete [] boolParams;
3725 }
3726 else if (nativeType == GL_INT)
3727 {
3728 GLint *intParams = NULL;
3729 intParams = new GLint[numParams];
3730
3731 context->getIntegerv(pname, intParams);
3732
3733 for (unsigned int i = 0; i < numParams; ++i)
3734 {
3735 params[i] = (GLfloat)intParams[i];
3736 }
3737
3738 delete [] intParams;
3739 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003740 }
3741 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003742 }
3743 catch(std::bad_alloc&)
3744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003745 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746 }
3747}
3748
3749void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
3750{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003751 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003752 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003753
3754 try
3755 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003756 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003757
3758 if (context)
3759 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003760 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003762 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003763 }
3764
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003765 gl::Framebuffer *framebuffer = NULL;
3766 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3767 {
3768 if(context->getReadFramebufferHandle() == 0)
3769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003770 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003771 }
3772
3773 framebuffer = context->getReadFramebuffer();
3774 }
3775 else
3776 {
3777 if (context->getDrawFramebufferHandle() == 0)
3778 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003779 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003780 }
3781
3782 framebuffer = context->getDrawFramebuffer();
3783 }
3784
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003785 GLenum attachmentType;
3786 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003787
3788 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003789 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003790 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3791
3792 if (colorAttachment >= context->getMaximumRenderTargets())
3793 {
3794 return gl::error(GL_INVALID_ENUM);
3795 }
3796
3797 attachmentType = framebuffer->getColorbufferType(colorAttachment);
3798 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
3799 }
3800 else
3801 {
3802 switch (attachment)
3803 {
3804 case GL_DEPTH_ATTACHMENT:
3805 attachmentType = framebuffer->getDepthbufferType();
3806 attachmentHandle = framebuffer->getDepthbufferHandle();
3807 break;
3808 case GL_STENCIL_ATTACHMENT:
3809 attachmentType = framebuffer->getStencilbufferType();
3810 attachmentHandle = framebuffer->getStencilbufferHandle();
3811 break;
3812 default: return gl::error(GL_INVALID_ENUM);
3813 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003814 }
3815
3816 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003817 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003818 {
3819 attachmentObjectType = attachmentType;
3820 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00003821 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003822 {
3823 attachmentObjectType = GL_TEXTURE;
3824 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00003825 else
3826 {
3827 UNREACHABLE();
3828 return;
3829 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003830
3831 switch (pname)
3832 {
3833 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
3834 *params = attachmentObjectType;
3835 break;
3836 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
3837 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
3838 {
3839 *params = attachmentHandle;
3840 }
3841 else
3842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003843 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003844 }
3845 break;
3846 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
3847 if (attachmentObjectType == GL_TEXTURE)
3848 {
3849 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
3850 }
3851 else
3852 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003853 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003854 }
3855 break;
3856 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
3857 if (attachmentObjectType == GL_TEXTURE)
3858 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00003859 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003860 {
3861 *params = attachmentType;
3862 }
3863 else
3864 {
3865 *params = 0;
3866 }
3867 }
3868 else
3869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003870 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003871 }
3872 break;
3873 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003874 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003875 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003876 }
3877 }
3878 catch(std::bad_alloc&)
3879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003880 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003881 }
3882}
3883
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00003884GLenum __stdcall glGetGraphicsResetStatusEXT(void)
3885{
3886 EVENT("()");
3887
3888 try
3889 {
3890 gl::Context *context = gl::getContext();
3891
3892 if (context)
3893 {
3894 return context->getResetStatus();
3895 }
3896
3897 return GL_NO_ERROR;
3898 }
3899 catch(std::bad_alloc&)
3900 {
3901 return GL_OUT_OF_MEMORY;
3902 }
3903}
3904
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003905void __stdcall glGetIntegerv(GLenum pname, GLint* params)
3906{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003907 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003908
3909 try
3910 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003911 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003912
3913 if (context)
3914 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003915 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003916 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003917 GLenum nativeType;
3918 unsigned int numParams = 0;
3919 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003920 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003921
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003922 if (numParams == 0)
3923 return; // it is known that pname is valid, but there are no parameters to return
3924
3925 if (nativeType == GL_BOOL)
3926 {
3927 GLboolean *boolParams = NULL;
3928 boolParams = new GLboolean[numParams];
3929
3930 context->getBooleanv(pname, boolParams);
3931
3932 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003933 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003934 if (boolParams[i] == GL_FALSE)
3935 params[i] = 0;
3936 else
3937 params[i] = 1;
3938 }
3939
3940 delete [] boolParams;
3941 }
3942 else if (nativeType == GL_FLOAT)
3943 {
3944 GLfloat *floatParams = NULL;
3945 floatParams = new GLfloat[numParams];
3946
3947 context->getFloatv(pname, floatParams);
3948
3949 for (unsigned int i = 0; i < numParams; ++i)
3950 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00003951 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003952 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003953 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003954 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003955 else
3956 params[i] = (GLint)(floatParams[i] > 0.0f ? floor(floatParams[i] + 0.5) : ceil(floatParams[i] - 0.5));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003958
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003959 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003960 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003961 }
3962 }
3963 }
3964 catch(std::bad_alloc&)
3965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003966 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967 }
3968}
3969
3970void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
3971{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003972 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003973
3974 try
3975 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003976 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003977
3978 if (context)
3979 {
3980 gl::Program *programObject = context->getProgram(program);
3981
3982 if (!programObject)
3983 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003984 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003985 }
3986
3987 switch (pname)
3988 {
3989 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003990 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003991 return;
3992 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00003993 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003994 return;
3995 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00003996 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003997 return;
3998 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003999 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004000 return;
4001 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004002 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004003 return;
4004 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004005 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004006 return;
4007 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00004008 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004009 return;
4010 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004011 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004012 return;
4013 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004014 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004015 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004016 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00004017 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004018 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004019 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004020 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004021 }
4022 }
4023 }
4024 catch(std::bad_alloc&)
4025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004026 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004027 }
4028}
4029
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004030void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004032 EVENT("(GLuint program = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004033 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004034
4035 try
4036 {
4037 if (bufsize < 0)
4038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004039 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004040 }
4041
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004042 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004043
4044 if (context)
4045 {
4046 gl::Program *programObject = context->getProgram(program);
4047
4048 if (!programObject)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004051 }
4052
4053 programObject->getInfoLog(bufsize, length, infolog);
4054 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004055 }
4056 catch(std::bad_alloc&)
4057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004058 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004059 }
4060}
4061
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004062void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
4063{
4064 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
4065
4066 try
4067 {
4068 switch (pname)
4069 {
4070 case GL_CURRENT_QUERY_EXT:
4071 break;
4072 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004073 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004074 }
4075
4076 gl::Context *context = gl::getNonLostContext();
4077
4078 if (context)
4079 {
4080 params[0] = context->getActiveQuery(target);
4081 }
4082 }
4083 catch(std::bad_alloc&)
4084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004085 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004086 }
4087}
4088
4089void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
4090{
4091 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
4092
4093 try
4094 {
4095 switch (pname)
4096 {
4097 case GL_QUERY_RESULT_EXT:
4098 case GL_QUERY_RESULT_AVAILABLE_EXT:
4099 break;
4100 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004101 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004102 }
4103 gl::Context *context = gl::getNonLostContext();
4104
4105 if (context)
4106 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004107 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
4108
4109 if (!queryObject)
4110 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004111 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004112 }
4113
4114 if (context->getActiveQuery(queryObject->getType()) == id)
4115 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004116 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004117 }
4118
4119 switch(pname)
4120 {
4121 case GL_QUERY_RESULT_EXT:
4122 params[0] = queryObject->getResult();
4123 break;
4124 case GL_QUERY_RESULT_AVAILABLE_EXT:
4125 params[0] = queryObject->isResultAvailable();
4126 break;
4127 default:
4128 ASSERT(false);
4129 }
4130 }
4131 }
4132 catch(std::bad_alloc&)
4133 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004134 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004135 }
4136}
4137
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004138void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
4139{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004140 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004141
4142 try
4143 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004144 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004145
4146 if (context)
4147 {
4148 if (target != GL_RENDERBUFFER)
4149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004151 }
4152
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004153 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004155 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004156 }
4157
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004158 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004159
4160 switch (pname)
4161 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004162 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
4163 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
4164 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
4165 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
4166 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
4167 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
4168 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
4169 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
4170 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004171 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004172 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004173 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004174 *params = renderbuffer->getSamples();
4175 }
4176 else
4177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004178 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004179 }
4180 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004181 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004182 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004183 }
4184 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004185 }
4186 catch(std::bad_alloc&)
4187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004188 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189 }
4190}
4191
4192void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
4193{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004194 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004195
4196 try
4197 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004198 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004199
4200 if (context)
4201 {
4202 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00004203
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204 if (!shaderObject)
4205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004206 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004207 }
4208
4209 switch (pname)
4210 {
4211 case GL_SHADER_TYPE:
4212 *params = shaderObject->getType();
4213 return;
4214 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004215 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004216 return;
4217 case GL_COMPILE_STATUS:
4218 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
4219 return;
4220 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004221 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004222 return;
4223 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004224 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225 return;
zmo@google.coma574f782011-10-03 21:45:23 +00004226 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
4227 *params = shaderObject->getTranslatedSourceLength();
4228 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004229 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004230 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004231 }
4232 }
4233 }
4234 catch(std::bad_alloc&)
4235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004236 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237 }
4238}
4239
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004240void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004241{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004242 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004243 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004244
4245 try
4246 {
4247 if (bufsize < 0)
4248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004249 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004250 }
4251
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004252 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004253
4254 if (context)
4255 {
4256 gl::Shader *shaderObject = context->getShader(shader);
4257
4258 if (!shaderObject)
4259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004260 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004261 }
4262
4263 shaderObject->getInfoLog(bufsize, length, infolog);
4264 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004265 }
4266 catch(std::bad_alloc&)
4267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004268 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004269 }
4270}
4271
4272void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
4273{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004274 EVENT("(GLenum shadertype = 0x%X, GLenum precisiontype = 0x%X, GLint* range = 0x%0.8p, GLint* precision = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004275 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004276
4277 try
4278 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004279 switch (shadertype)
4280 {
4281 case GL_VERTEX_SHADER:
4282 case GL_FRAGMENT_SHADER:
4283 break;
4284 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004285 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004286 }
4287
4288 switch (precisiontype)
4289 {
4290 case GL_LOW_FLOAT:
4291 case GL_MEDIUM_FLOAT:
4292 case GL_HIGH_FLOAT:
4293 // Assume IEEE 754 precision
4294 range[0] = 127;
4295 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004296 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004297 break;
4298 case GL_LOW_INT:
4299 case GL_MEDIUM_INT:
4300 case GL_HIGH_INT:
4301 // Some (most) hardware only supports single-precision floating-point numbers,
4302 // which can accurately represent integers up to +/-16777216
4303 range[0] = 24;
4304 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004305 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004306 break;
4307 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004308 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004309 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004310 }
4311 catch(std::bad_alloc&)
4312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004313 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004314 }
4315}
4316
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004317void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004319 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004320 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004321
4322 try
4323 {
4324 if (bufsize < 0)
4325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004326 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004327 }
4328
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004329 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004330
4331 if (context)
4332 {
4333 gl::Shader *shaderObject = context->getShader(shader);
4334
4335 if (!shaderObject)
4336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004337 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004338 }
4339
4340 shaderObject->getSource(bufsize, length, source);
4341 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342 }
4343 catch(std::bad_alloc&)
4344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004345 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004346 }
4347}
4348
zmo@google.coma574f782011-10-03 21:45:23 +00004349void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
4350{
4351 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
4352 shader, bufsize, length, source);
4353
4354 try
4355 {
4356 if (bufsize < 0)
4357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004358 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00004359 }
4360
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004361 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00004362
4363 if (context)
4364 {
4365 gl::Shader *shaderObject = context->getShader(shader);
4366
4367 if (!shaderObject)
4368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004369 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00004370 }
4371
4372 shaderObject->getTranslatedSource(bufsize, length, source);
4373 }
4374 }
4375 catch(std::bad_alloc&)
4376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004377 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00004378 }
4379}
4380
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381const GLubyte* __stdcall glGetString(GLenum name)
4382{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004383 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004384
4385 try
4386 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004387 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00004388
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004389 switch (name)
4390 {
4391 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00004392 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004393 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00004394 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004395 case GL_VERSION:
daniel@transgaming.com1825d8e2012-08-27 16:25:29 +00004396 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004397 case GL_SHADING_LANGUAGE_VERSION:
daniel@transgaming.com1825d8e2012-08-27 16:25:29 +00004398 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004399 case GL_EXTENSIONS:
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00004400 return (GLubyte*)((context != NULL) ? context->getExtensionString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004401 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004402 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004403 }
4404 }
4405 catch(std::bad_alloc&)
4406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004407 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004408 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004409}
4410
4411void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
4412{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004413 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004414
4415 try
4416 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004417 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004418
4419 if (context)
4420 {
4421 gl::Texture *texture;
4422
4423 switch (target)
4424 {
4425 case GL_TEXTURE_2D:
4426 texture = context->getTexture2D();
4427 break;
4428 case GL_TEXTURE_CUBE_MAP:
4429 texture = context->getTextureCubeMap();
4430 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00004431 case GL_TEXTURE_3D:
4432 if (context->getClientVersion() < 3)
4433 {
4434 return gl::error(GL_INVALID_ENUM);
4435 }
4436 texture = context->getTexture3D();
4437 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004438 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004439 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004440 }
4441
4442 switch (pname)
4443 {
4444 case GL_TEXTURE_MAG_FILTER:
4445 *params = (GLfloat)texture->getMagFilter();
4446 break;
4447 case GL_TEXTURE_MIN_FILTER:
4448 *params = (GLfloat)texture->getMinFilter();
4449 break;
4450 case GL_TEXTURE_WRAP_S:
4451 *params = (GLfloat)texture->getWrapS();
4452 break;
4453 case GL_TEXTURE_WRAP_T:
4454 *params = (GLfloat)texture->getWrapT();
4455 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00004456 case GL_TEXTURE_WRAP_R:
4457 if (context->getClientVersion() < 3)
4458 {
4459 return gl::error(GL_INVALID_ENUM);
4460 }
4461 *params = (GLfloat)texture->getWrapR();
4462 break;
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00004463 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
4464 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
4465 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00004466 case GL_TEXTURE_USAGE_ANGLE:
4467 *params = (GLfloat)texture->getUsage();
4468 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004469 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4470 if (!context->supportsTextureFilterAnisotropy())
4471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004472 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004473 }
4474 *params = (GLfloat)texture->getMaxAnisotropy();
4475 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004476 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004477 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004478 }
4479 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480 }
4481 catch(std::bad_alloc&)
4482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004483 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004484 }
4485}
4486
4487void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
4488{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004489 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490
4491 try
4492 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004494
4495 if (context)
4496 {
4497 gl::Texture *texture;
4498
4499 switch (target)
4500 {
4501 case GL_TEXTURE_2D:
4502 texture = context->getTexture2D();
4503 break;
4504 case GL_TEXTURE_CUBE_MAP:
4505 texture = context->getTextureCubeMap();
4506 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00004507 case GL_TEXTURE_3D:
4508 if (context->getClientVersion() < 3)
4509 {
4510 return gl::error(GL_INVALID_ENUM);
4511 }
4512 texture = context->getTexture3D();
4513 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004514 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004515 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004516 }
4517
4518 switch (pname)
4519 {
4520 case GL_TEXTURE_MAG_FILTER:
4521 *params = texture->getMagFilter();
4522 break;
4523 case GL_TEXTURE_MIN_FILTER:
4524 *params = texture->getMinFilter();
4525 break;
4526 case GL_TEXTURE_WRAP_S:
4527 *params = texture->getWrapS();
4528 break;
4529 case GL_TEXTURE_WRAP_T:
4530 *params = texture->getWrapT();
4531 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00004532 case GL_TEXTURE_WRAP_R:
4533 if (context->getClientVersion() < 3)
4534 {
4535 return gl::error(GL_INVALID_ENUM);
4536 }
4537 *params = texture->getWrapR();
4538 break;
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00004539 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
4540 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
4541 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00004542 case GL_TEXTURE_USAGE_ANGLE:
4543 *params = texture->getUsage();
4544 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004545 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4546 if (!context->supportsTextureFilterAnisotropy())
4547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004548 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004549 }
4550 *params = (GLint)texture->getMaxAnisotropy();
4551 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004552 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004553 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004554 }
4555 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004556 }
4557 catch(std::bad_alloc&)
4558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004559 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004560 }
4561}
4562
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004563void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
4564{
4565 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
4566 program, location, bufSize, params);
4567
4568 try
4569 {
4570 if (bufSize < 0)
4571 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004572 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004573 }
4574
4575 gl::Context *context = gl::getNonLostContext();
4576
4577 if (context)
4578 {
4579 if (program == 0)
4580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004581 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004582 }
4583
4584 gl::Program *programObject = context->getProgram(program);
4585
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004586 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004588 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004589 }
4590
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004591 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4592 if (!programBinary)
4593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004594 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004595 }
4596
4597 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004598 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004599 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004600 }
4601 }
4602 }
4603 catch(std::bad_alloc&)
4604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004606 }
4607}
4608
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004609void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
4610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004611 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004612
4613 try
4614 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004615 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004616
4617 if (context)
4618 {
4619 if (program == 0)
4620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004621 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004622 }
4623
4624 gl::Program *programObject = context->getProgram(program);
4625
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004626 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004628 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004629 }
4630
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004631 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4632 if (!programBinary)
4633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004634 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004635 }
4636
4637 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004639 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004640 }
4641 }
4642 }
4643 catch(std::bad_alloc&)
4644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004645 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004646 }
4647}
4648
4649void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
4650{
4651 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
4652 program, location, bufSize, params);
4653
4654 try
4655 {
4656 if (bufSize < 0)
4657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004658 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004659 }
4660
4661 gl::Context *context = gl::getNonLostContext();
4662
4663 if (context)
4664 {
4665 if (program == 0)
4666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004667 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004668 }
4669
4670 gl::Program *programObject = context->getProgram(program);
4671
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004672 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004674 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004675 }
4676
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004677 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4678 if (!programBinary)
4679 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004680 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004681 }
4682
4683 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004685 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004686 }
4687 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688 }
4689 catch(std::bad_alloc&)
4690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004691 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004692 }
4693}
4694
4695void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
4696{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004697 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004698
4699 try
4700 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004701 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004702
4703 if (context)
4704 {
4705 if (program == 0)
4706 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004707 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004708 }
4709
4710 gl::Program *programObject = context->getProgram(program);
4711
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004712 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004714 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004715 }
4716
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004717 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4718 if (!programBinary)
4719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004720 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004721 }
4722
4723 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004724 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004725 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004726 }
4727 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004728 }
4729 catch(std::bad_alloc&)
4730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004731 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004732 }
4733}
4734
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004735int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004736{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004737 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004738
4739 try
4740 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004741 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004742
4743 if (strstr(name, "gl_") == name)
4744 {
4745 return -1;
4746 }
4747
4748 if (context)
4749 {
4750 gl::Program *programObject = context->getProgram(program);
4751
4752 if (!programObject)
4753 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004754 if (context->getShader(program))
4755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004756 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004757 }
4758 else
4759 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004760 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004761 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004762 }
4763
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004764 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004765 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004767 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004768 }
4769
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004770 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004771 }
4772 }
4773 catch(std::bad_alloc&)
4774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004775 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004776 }
4777
4778 return -1;
4779}
4780
4781void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
4782{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004783 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004784
4785 try
4786 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004787 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004788
daniel@transgaming.come0078962010-04-15 20:45:08 +00004789 if (context)
4790 {
4791 if (index >= gl::MAX_VERTEX_ATTRIBS)
4792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004793 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004794 }
4795
daniel@transgaming.com83921382011-01-08 05:46:00 +00004796 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004797
daniel@transgaming.come0078962010-04-15 20:45:08 +00004798 switch (pname)
4799 {
4800 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00004801 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004802 break;
4803 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004804 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004805 break;
4806 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004807 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004808 break;
4809 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004810 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004811 break;
4812 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004813 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004814 break;
4815 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00004816 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00004817 break;
4818 case GL_CURRENT_VERTEX_ATTRIB:
4819 for (int i = 0; i < 4; ++i)
4820 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00004821 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00004822 }
4823 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00004824 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
4825 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
4826 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004827 *params = (GLfloat)attribState.mDivisor;
4828 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004829 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004830 }
4831 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004832 }
4833 catch(std::bad_alloc&)
4834 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004835 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004836 }
4837}
4838
4839void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
4840{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004841 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004842
4843 try
4844 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004845 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004846
daniel@transgaming.come0078962010-04-15 20:45:08 +00004847 if (context)
4848 {
4849 if (index >= gl::MAX_VERTEX_ATTRIBS)
4850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004851 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004852 }
4853
daniel@transgaming.com83921382011-01-08 05:46:00 +00004854 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004855
daniel@transgaming.come0078962010-04-15 20:45:08 +00004856 switch (pname)
4857 {
4858 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00004859 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004860 break;
4861 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004862 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004863 break;
4864 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004865 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004866 break;
4867 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004868 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004869 break;
4870 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004871 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004872 break;
4873 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00004874 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00004875 break;
4876 case GL_CURRENT_VERTEX_ATTRIB:
4877 for (int i = 0; i < 4; ++i)
4878 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00004879 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00004880 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
4881 }
4882 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00004883 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
4884 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
4885 // the same constant.
4886 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004887 *params = (GLint)attribState.mDivisor;
4888 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004889 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004890 }
4891 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004892 }
4893 catch(std::bad_alloc&)
4894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004895 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004896 }
4897}
4898
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004899void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004900{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004901 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004902
4903 try
4904 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004905 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004906
daniel@transgaming.come0078962010-04-15 20:45:08 +00004907 if (context)
4908 {
4909 if (index >= gl::MAX_VERTEX_ATTRIBS)
4910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004911 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004912 }
4913
4914 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
4915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004916 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004917 }
4918
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004919 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00004920 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004921 }
4922 catch(std::bad_alloc&)
4923 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004924 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004925 }
4926}
4927
4928void __stdcall glHint(GLenum target, GLenum mode)
4929{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004930 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004931
4932 try
4933 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004934 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004935 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004936 case GL_FASTEST:
4937 case GL_NICEST:
4938 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004939 break;
4940 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004941 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004942 }
4943
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004944 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004945 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004946 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004947 case GL_GENERATE_MIPMAP_HINT:
4948 if (context) context->setGenerateMipmapHint(mode);
4949 break;
4950 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
4951 if (context) context->setFragmentShaderDerivativeHint(mode);
4952 break;
4953 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004954 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004955 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004956 }
4957 catch(std::bad_alloc&)
4958 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004959 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004960 }
4961}
4962
4963GLboolean __stdcall glIsBuffer(GLuint buffer)
4964{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004965 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004966
4967 try
4968 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004969 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004970
4971 if (context && buffer)
4972 {
4973 gl::Buffer *bufferObject = context->getBuffer(buffer);
4974
4975 if (bufferObject)
4976 {
4977 return GL_TRUE;
4978 }
4979 }
4980 }
4981 catch(std::bad_alloc&)
4982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004983 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004984 }
4985
4986 return GL_FALSE;
4987}
4988
4989GLboolean __stdcall glIsEnabled(GLenum cap)
4990{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004991 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004992
4993 try
4994 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004995 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004996
4997 if (context)
4998 {
4999 switch (cap)
5000 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005001 case GL_CULL_FACE: return context->isCullFaceEnabled();
5002 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
5003 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
5004 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
5005 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
5006 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
5007 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
5008 case GL_BLEND: return context->isBlendEnabled();
5009 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005010 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005011 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005012 }
5013 }
5014 }
5015 catch(std::bad_alloc&)
5016 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005017 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005018 }
5019
5020 return false;
5021}
5022
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005023GLboolean __stdcall glIsFenceNV(GLuint fence)
5024{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005025 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005026
5027 try
5028 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005029 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005030
5031 if (context)
5032 {
5033 gl::Fence *fenceObject = context->getFence(fence);
5034
5035 if (fenceObject == NULL)
5036 {
5037 return GL_FALSE;
5038 }
5039
5040 return fenceObject->isFence();
5041 }
5042 }
5043 catch(std::bad_alloc&)
5044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005045 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005046 }
5047
5048 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005049}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005050
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005051GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
5052{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005053 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005054
5055 try
5056 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005057 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005058
5059 if (context && framebuffer)
5060 {
5061 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
5062
5063 if (framebufferObject)
5064 {
5065 return GL_TRUE;
5066 }
5067 }
5068 }
5069 catch(std::bad_alloc&)
5070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005071 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005072 }
5073
5074 return GL_FALSE;
5075}
5076
5077GLboolean __stdcall glIsProgram(GLuint program)
5078{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005079 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005080
5081 try
5082 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005083 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005084
5085 if (context && program)
5086 {
5087 gl::Program *programObject = context->getProgram(program);
5088
5089 if (programObject)
5090 {
5091 return GL_TRUE;
5092 }
5093 }
5094 }
5095 catch(std::bad_alloc&)
5096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005097 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005098 }
5099
5100 return GL_FALSE;
5101}
5102
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005103GLboolean __stdcall glIsQueryEXT(GLuint id)
5104{
5105 EVENT("(GLuint id = %d)", id);
5106
5107 try
5108 {
5109 if (id == 0)
5110 {
5111 return GL_FALSE;
5112 }
5113
5114 gl::Context *context = gl::getNonLostContext();
5115
5116 if (context)
5117 {
5118 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5119
5120 if (queryObject)
5121 {
5122 return GL_TRUE;
5123 }
5124 }
5125 }
5126 catch(std::bad_alloc&)
5127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005128 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005129 }
5130
5131 return GL_FALSE;
5132}
5133
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005134GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
5135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005136 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005137
5138 try
5139 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005140 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005141
5142 if (context && renderbuffer)
5143 {
5144 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
5145
5146 if (renderbufferObject)
5147 {
5148 return GL_TRUE;
5149 }
5150 }
5151 }
5152 catch(std::bad_alloc&)
5153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005154 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005155 }
5156
5157 return GL_FALSE;
5158}
5159
5160GLboolean __stdcall glIsShader(GLuint shader)
5161{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005162 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005163
5164 try
5165 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005166 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005167
5168 if (context && shader)
5169 {
5170 gl::Shader *shaderObject = context->getShader(shader);
5171
5172 if (shaderObject)
5173 {
5174 return GL_TRUE;
5175 }
5176 }
5177 }
5178 catch(std::bad_alloc&)
5179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005180 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005181 }
5182
5183 return GL_FALSE;
5184}
5185
5186GLboolean __stdcall glIsTexture(GLuint texture)
5187{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005188 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005189
5190 try
5191 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005192 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005193
5194 if (context && texture)
5195 {
5196 gl::Texture *textureObject = context->getTexture(texture);
5197
5198 if (textureObject)
5199 {
5200 return GL_TRUE;
5201 }
5202 }
5203 }
5204 catch(std::bad_alloc&)
5205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005206 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005207 }
5208
5209 return GL_FALSE;
5210}
5211
5212void __stdcall glLineWidth(GLfloat width)
5213{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005214 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005215
5216 try
5217 {
5218 if (width <= 0.0f)
5219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005220 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005221 }
5222
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005223 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005224
5225 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005226 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005227 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005228 }
5229 }
5230 catch(std::bad_alloc&)
5231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005232 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005233 }
5234}
5235
5236void __stdcall glLinkProgram(GLuint program)
5237{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005238 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005239
5240 try
5241 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005242 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005243
5244 if (context)
5245 {
5246 gl::Program *programObject = context->getProgram(program);
5247
5248 if (!programObject)
5249 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005250 if (context->getShader(program))
5251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005252 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005253 }
5254 else
5255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005256 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005257 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005258 }
5259
daniel@transgaming.com95d29422012-07-24 18:36:10 +00005260 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 }
5262 }
5263 catch(std::bad_alloc&)
5264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005265 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005266 }
5267}
5268
5269void __stdcall glPixelStorei(GLenum pname, GLint param)
5270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005271 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005272
5273 try
5274 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005275 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005276
5277 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005278 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005279 switch (pname)
5280 {
5281 case GL_UNPACK_ALIGNMENT:
5282 if (param != 1 && param != 2 && param != 4 && param != 8)
5283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005284 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005285 }
5286
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005287 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005288 break;
5289
5290 case GL_PACK_ALIGNMENT:
5291 if (param != 1 && param != 2 && param != 4 && param != 8)
5292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005293 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005294 }
5295
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005296 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005297 break;
5298
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00005299 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
5300 context->setPackReverseRowOrder(param != 0);
5301 break;
5302
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005303 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005304 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005305 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005306 }
5307 }
5308 catch(std::bad_alloc&)
5309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005310 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005311 }
5312}
5313
5314void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
5315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005316 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005317
5318 try
5319 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005320 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00005321
5322 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005323 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005324 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005325 }
5326 }
5327 catch(std::bad_alloc&)
5328 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005329 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005330 }
5331}
5332
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005333void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
5334 GLenum format, GLenum type, GLsizei bufSize,
5335 GLvoid *data)
5336{
5337 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
5338 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
5339 x, y, width, height, format, type, bufSize, data);
5340
5341 try
5342 {
5343 if (width < 0 || height < 0 || bufSize < 0)
5344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005345 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005346 }
5347
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005348 gl::Context *context = gl::getNonLostContext();
5349
5350 if (context)
5351 {
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005352 GLenum currentFormat, currentType;
5353
5354 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
5355 // and attempting to read back if that's the case is an error. The error will be registered
5356 // by getCurrentReadFormat.
5357 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
5358 return;
5359
5360 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
5361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005362 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005363 }
5364
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005365 context->readPixels(x, y, width, height, format, type, &bufSize, data);
5366 }
5367 }
5368 catch(std::bad_alloc&)
5369 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005370 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005371 }
5372}
5373
5374void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
5375 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005376{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005377 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005378 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005379 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005380
5381 try
5382 {
5383 if (width < 0 || height < 0)
5384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005385 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005386 }
5387
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005388 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005389
5390 if (context)
5391 {
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005392 GLenum currentFormat, currentType;
5393
5394 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
5395 // and attempting to read back if that's the case is an error. The error will be registered
5396 // by getCurrentReadFormat.
5397 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
5398 return;
5399
5400 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
5401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005402 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005403 }
5404
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005405 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005406 }
5407 }
5408 catch(std::bad_alloc&)
5409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005410 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005411 }
5412}
5413
5414void __stdcall glReleaseShaderCompiler(void)
5415{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005416 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005417
5418 try
5419 {
5420 gl::Shader::releaseCompiler();
5421 }
5422 catch(std::bad_alloc&)
5423 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005424 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005425 }
5426}
5427
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005428void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005430 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005431 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005432
5433 try
5434 {
5435 switch (target)
5436 {
5437 case GL_RENDERBUFFER:
5438 break;
5439 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005440 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005441 }
5442
daniel@transgaming.comedc19182010-10-15 17:57:55 +00005443 if (!gl::IsColorRenderable(internalformat) && !gl::IsDepthRenderable(internalformat) && !gl::IsStencilRenderable(internalformat))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005445 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005446 }
5447
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005448 if (width < 0 || height < 0 || samples < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005450 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005451 }
5452
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005453 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005454
5455 if (context)
5456 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005457 if (width > context->getMaximumRenderbufferDimension() ||
5458 height > context->getMaximumRenderbufferDimension() ||
5459 samples > context->getMaxSupportedSamples())
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005461 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005462 }
5463
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005464 GLuint handle = context->getRenderbufferHandle();
5465 if (handle == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005467 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005468 }
5469
5470 switch (internalformat)
5471 {
5472 case GL_DEPTH_COMPONENT16:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005473 case GL_RGBA4:
5474 case GL_RGB5_A1:
5475 case GL_RGB565:
daniel@transgaming.com63977542010-08-24 19:21:02 +00005476 case GL_RGB8_OES:
5477 case GL_RGBA8_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005478 case GL_STENCIL_INDEX8:
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00005479 case GL_DEPTH24_STENCIL8_OES:
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00005480 break;
5481 case GL_SRGB8_ALPHA8:
5482 case GL_RGB10_A2:
5483 case GL_RG8:
5484 case GL_R8:
5485 if (context->getClientVersion() < 3)
5486 {
5487 return gl::error(GL_INVALID_ENUM);
5488 }
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00005489 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005490 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005491 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005492 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00005493
5494 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005495 }
5496 }
5497 catch(std::bad_alloc&)
5498 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005499 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005500 }
5501}
5502
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005503void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
5504{
5505 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
5506}
5507
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005508void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
5509{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005510 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005511
5512 try
5513 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005514 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005515
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005516 if (context)
5517 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00005518 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005519 }
5520 }
5521 catch(std::bad_alloc&)
5522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005523 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005524 }
5525}
5526
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005527void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
5528{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005529 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005530
5531 try
5532 {
5533 if (condition != GL_ALL_COMPLETED_NV)
5534 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005535 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005536 }
5537
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005538 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005539
5540 if (context)
5541 {
5542 gl::Fence *fenceObject = context->getFence(fence);
5543
5544 if (fenceObject == NULL)
5545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005546 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005547 }
5548
5549 fenceObject->setFence(condition);
5550 }
5551 }
5552 catch(std::bad_alloc&)
5553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005554 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005555 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005556}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005557
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005558void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
5559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005560 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005561
5562 try
5563 {
5564 if (width < 0 || height < 0)
5565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005567 }
5568
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005569 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005570
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005571 if (context)
5572 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005573 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005574 }
5575 }
5576 catch(std::bad_alloc&)
5577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005578 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005579 }
5580}
5581
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005582void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005584 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005585 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005586 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005587
5588 try
5589 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00005590 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005591 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005592 }
5593 catch(std::bad_alloc&)
5594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005595 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005596 }
5597}
5598
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00005599void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005600{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005601 EVENT("(GLuint shader = %d, GLsizei count = %d, const GLchar** string = 0x%0.8p, const GLint* length = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005602 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005603
5604 try
5605 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005606 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005608 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005609 }
5610
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005611 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005612
5613 if (context)
5614 {
5615 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005616
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005617 if (!shaderObject)
5618 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005619 if (context->getProgram(shader))
5620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005621 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005622 }
5623 else
5624 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005625 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005626 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005627 }
5628
5629 shaderObject->setSource(count, string, length);
5630 }
5631 }
5632 catch(std::bad_alloc&)
5633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005634 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005635 }
5636}
5637
5638void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
5639{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005640 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005641}
5642
5643void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
5644{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005645 EVENT("(GLenum face = 0x%X, GLenum func = 0x%X, GLint ref = %d, GLuint mask = %d)", face, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005646
5647 try
5648 {
5649 switch (face)
5650 {
5651 case GL_FRONT:
5652 case GL_BACK:
5653 case GL_FRONT_AND_BACK:
5654 break;
5655 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005656 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005657 }
5658
5659 switch (func)
5660 {
5661 case GL_NEVER:
5662 case GL_ALWAYS:
5663 case GL_LESS:
5664 case GL_LEQUAL:
5665 case GL_EQUAL:
5666 case GL_GEQUAL:
5667 case GL_GREATER:
5668 case GL_NOTEQUAL:
5669 break;
5670 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005671 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005672 }
5673
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005674 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005675
5676 if (context)
5677 {
5678 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5679 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005680 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005681 }
5682
5683 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5684 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005685 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005686 }
5687 }
5688 }
5689 catch(std::bad_alloc&)
5690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005691 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005692 }
5693}
5694
5695void __stdcall glStencilMask(GLuint mask)
5696{
5697 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5698}
5699
5700void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
5701{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005702 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005703
5704 try
5705 {
5706 switch (face)
5707 {
5708 case GL_FRONT:
5709 case GL_BACK:
5710 case GL_FRONT_AND_BACK:
5711 break;
5712 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005713 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005714 }
5715
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005716 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005717
5718 if (context)
5719 {
5720 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5721 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005722 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005723 }
5724
5725 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5726 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005727 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005728 }
5729 }
5730 }
5731 catch(std::bad_alloc&)
5732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005733 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005734 }
5735}
5736
5737void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5738{
5739 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5740}
5741
5742void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
5743{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005744 EVENT("(GLenum face = 0x%X, GLenum fail = 0x%X, GLenum zfail = 0x%X, GLenum zpas = 0x%Xs)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005745 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005746
5747 try
5748 {
5749 switch (face)
5750 {
5751 case GL_FRONT:
5752 case GL_BACK:
5753 case GL_FRONT_AND_BACK:
5754 break;
5755 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005756 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005757 }
5758
5759 switch (fail)
5760 {
5761 case GL_ZERO:
5762 case GL_KEEP:
5763 case GL_REPLACE:
5764 case GL_INCR:
5765 case GL_DECR:
5766 case GL_INVERT:
5767 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005768 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005769 break;
5770 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005771 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005772 }
5773
5774 switch (zfail)
5775 {
5776 case GL_ZERO:
5777 case GL_KEEP:
5778 case GL_REPLACE:
5779 case GL_INCR:
5780 case GL_DECR:
5781 case GL_INVERT:
5782 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005783 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005784 break;
5785 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005786 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005787 }
5788
5789 switch (zpass)
5790 {
5791 case GL_ZERO:
5792 case GL_KEEP:
5793 case GL_REPLACE:
5794 case GL_INCR:
5795 case GL_DECR:
5796 case GL_INVERT:
5797 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005798 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005799 break;
5800 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005801 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005802 }
5803
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005804 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005805
5806 if (context)
5807 {
5808 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5809 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005810 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005811 }
5812
5813 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5814 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005815 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005816 }
5817 }
5818 }
5819 catch(std::bad_alloc&)
5820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005821 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005822 }
5823}
5824
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005825GLboolean __stdcall glTestFenceNV(GLuint fence)
5826{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005827 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005828
5829 try
5830 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005831 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005832
5833 if (context)
5834 {
5835 gl::Fence *fenceObject = context->getFence(fence);
5836
5837 if (fenceObject == NULL)
5838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005839 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005840 }
5841
5842 return fenceObject->testFence();
5843 }
5844 }
5845 catch(std::bad_alloc&)
5846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005847 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005848 }
5849
5850 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005851}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005852
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005853void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
5854 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005855{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005856 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005857 "GLint border = %d, GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005858 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005859
5860 try
5861 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00005862 if (!validImageSize(level, width, height, 1))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005864 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005865 }
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005866
apatrick@chromium.orge057c5d2012-01-26 19:18:24 +00005867 if (internalformat != GLint(format))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005869 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005870 }
5871
daniel@transgaming.com6377e362012-06-05 19:49:55 +00005872 // validate <type> by itself (used as secondary key below)
5873 switch (type)
5874 {
5875 case GL_UNSIGNED_BYTE:
5876 case GL_UNSIGNED_SHORT_5_6_5:
5877 case GL_UNSIGNED_SHORT_4_4_4_4:
5878 case GL_UNSIGNED_SHORT_5_5_5_1:
5879 case GL_UNSIGNED_SHORT:
5880 case GL_UNSIGNED_INT:
5881 case GL_UNSIGNED_INT_24_8_OES:
5882 case GL_HALF_FLOAT_OES:
5883 case GL_FLOAT:
5884 break;
5885 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005886 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6377e362012-06-05 19:49:55 +00005887 }
5888
5889 // validate <format> + <type> combinations
5890 // - invalid <format> -> sets INVALID_ENUM
5891 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00005892 switch (format)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005893 {
5894 case GL_ALPHA:
5895 case GL_LUMINANCE:
5896 case GL_LUMINANCE_ALPHA:
5897 switch (type)
5898 {
5899 case GL_UNSIGNED_BYTE:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005900 case GL_FLOAT:
5901 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005902 break;
5903 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005904 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005905 }
5906 break;
5907 case GL_RGB:
5908 switch (type)
5909 {
5910 case GL_UNSIGNED_BYTE:
5911 case GL_UNSIGNED_SHORT_5_6_5:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005912 case GL_FLOAT:
5913 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005914 break;
5915 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005916 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005917 }
5918 break;
5919 case GL_RGBA:
5920 switch (type)
5921 {
5922 case GL_UNSIGNED_BYTE:
5923 case GL_UNSIGNED_SHORT_4_4_4_4:
5924 case GL_UNSIGNED_SHORT_5_5_5_1:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005925 case GL_FLOAT:
5926 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005927 break;
5928 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005929 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005930 }
5931 break;
daniel@transgaming.coma9198d92010-08-08 04:49:56 +00005932 case GL_BGRA_EXT:
5933 switch (type)
5934 {
5935 case GL_UNSIGNED_BYTE:
5936 break;
5937 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005938 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma9198d92010-08-08 04:49:56 +00005939 }
5940 break;
daniel@transgaming.com01868132010-08-24 19:21:17 +00005941 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
5942 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00005943 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
5944 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00005945 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005946 case GL_DEPTH_COMPONENT:
5947 switch (type)
5948 {
5949 case GL_UNSIGNED_SHORT:
5950 case GL_UNSIGNED_INT:
5951 break;
5952 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005953 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005954 }
5955 break;
5956 case GL_DEPTH_STENCIL_OES:
5957 switch (type)
5958 {
5959 case GL_UNSIGNED_INT_24_8_OES:
5960 break;
5961 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005962 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005963 }
5964 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005965 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005966 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005967 }
5968
5969 if (border != 0)
5970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005971 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005972 }
5973
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005974 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005975
5976 if (context)
5977 {
daniel@transgaming.com32b11442011-11-19 02:42:48 +00005978 if (level > context->getMaximumTextureLevel())
5979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com32b11442011-11-19 02:42:48 +00005981 }
5982
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005983 switch (target)
5984 {
5985 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00005986 if (width > (context->getMaximum2DTextureDimension() >> level) ||
5987 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005989 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005990 }
5991 break;
5992 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
5993 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
5994 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
5995 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
5996 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
5997 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
5998 if (width != height)
5999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006000 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006001 }
6002
6003 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
6004 height > (context->getMaximumCubeTextureDimension() >> level))
6005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006006 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006007 }
6008 break;
6009 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006010 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006011 }
6012
gman@chromium.org50c526d2011-08-10 05:19:44 +00006013 switch (format) {
6014 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
6015 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
6016 if (context->supportsDXT1Textures())
daniel@transgaming.com01868132010-08-24 19:21:17 +00006017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006018 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00006019 }
6020 else
6021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006022 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00006023 }
gman@chromium.org50c526d2011-08-10 05:19:44 +00006024 break;
6025 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
6026 if (context->supportsDXT3Textures())
6027 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006028 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006029 }
6030 else
6031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006032 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006033 }
6034 break;
6035 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
6036 if (context->supportsDXT5Textures())
6037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006038 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006039 }
6040 else
6041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006042 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006043 }
6044 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006045 case GL_DEPTH_COMPONENT:
6046 case GL_DEPTH_STENCIL_OES:
6047 if (!context->supportsDepthTextures())
6048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006049 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006050 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006051 if (target != GL_TEXTURE_2D)
6052 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006053 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006054 }
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006055 // OES_depth_texture supports loading depth data and multiple levels,
6056 // but ANGLE_depth_texture does not
6057 if (pixels != NULL || level != 0)
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006058 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006059 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006060 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006061 break;
gman@chromium.org50c526d2011-08-10 05:19:44 +00006062 default:
6063 break;
daniel@transgaming.com01868132010-08-24 19:21:17 +00006064 }
6065
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006066 if (type == GL_FLOAT)
6067 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006068 if (!context->supportsFloat32Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006070 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006071 }
6072 }
6073 else if (type == GL_HALF_FLOAT_OES)
6074 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006075 if (!context->supportsFloat16Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006076 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006077 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006078 }
6079 }
6080
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006081 if (target == GL_TEXTURE_2D)
6082 {
6083 gl::Texture2D *texture = context->getTexture2D();
6084
6085 if (!texture)
6086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006087 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006088 }
6089
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006090 if (texture->isImmutable())
6091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006092 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006093 }
6094
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006095 texture->setImage(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006096 }
6097 else
6098 {
6099 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6100
6101 if (!texture)
6102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006103 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006104 }
6105
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006106 if (texture->isImmutable())
6107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006108 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006109 }
6110
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006111 switch (target)
6112 {
6113 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006114 texture->setImagePosX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006115 break;
6116 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006117 texture->setImageNegX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006118 break;
6119 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006120 texture->setImagePosY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006121 break;
6122 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006123 texture->setImageNegY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006124 break;
6125 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006126 texture->setImagePosZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006127 break;
6128 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006129 texture->setImageNegZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006130 break;
6131 default: UNREACHABLE();
6132 }
6133 }
6134 }
6135 }
6136 catch(std::bad_alloc&)
6137 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006138 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006139 }
6140}
6141
6142void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6143{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006144 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6145
6146 try
6147 {
6148 gl::Context *context = gl::getNonLostContext();
6149
6150 if (context)
6151 {
6152 gl::Texture *texture;
6153
6154 switch (target)
6155 {
6156 case GL_TEXTURE_2D:
6157 texture = context->getTexture2D();
6158 break;
6159 case GL_TEXTURE_CUBE_MAP:
6160 texture = context->getTextureCubeMap();
6161 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006162 case GL_TEXTURE_3D:
6163 if (context->getClientVersion() < 3)
6164 {
6165 return gl::error(GL_INVALID_ENUM);
6166 }
6167 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006168 case GL_TEXTURE_2D_ARRAY:
6169 if (context->getClientVersion() < 3)
6170 {
6171 return gl::error(GL_INVALID_ENUM);
6172 }
6173 texture = context->getTexture2DArray();
6174 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006175 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006176 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006177 }
6178
6179 switch (pname)
6180 {
6181 case GL_TEXTURE_WRAP_S:
6182 if (!texture->setWrapS((GLenum)param))
6183 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006184 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006185 }
6186 break;
6187 case GL_TEXTURE_WRAP_T:
6188 if (!texture->setWrapT((GLenum)param))
6189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006190 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006191 }
6192 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006193 case GL_TEXTURE_WRAP_R:
6194 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6195 {
6196 return gl::error(GL_INVALID_ENUM);
6197 }
6198 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006199 case GL_TEXTURE_MIN_FILTER:
6200 if (!texture->setMinFilter((GLenum)param))
6201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006202 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006203 }
6204 break;
6205 case GL_TEXTURE_MAG_FILTER:
6206 if (!texture->setMagFilter((GLenum)param))
6207 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006208 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006209 }
6210 break;
6211 case GL_TEXTURE_USAGE_ANGLE:
6212 if (!texture->setUsage((GLenum)param))
6213 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006214 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006215 }
6216 break;
6217 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6218 if (!context->supportsTextureFilterAnisotropy())
6219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006221 }
6222 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6223 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006224 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006225 }
6226 break;
6227 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006228 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006229 }
6230 }
6231 }
6232 catch(std::bad_alloc&)
6233 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006234 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006235 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006236}
6237
6238void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
6239{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006240 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006241}
6242
6243void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
6244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006245 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006246
6247 try
6248 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006249 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006250
6251 if (context)
6252 {
6253 gl::Texture *texture;
6254
6255 switch (target)
6256 {
6257 case GL_TEXTURE_2D:
6258 texture = context->getTexture2D();
6259 break;
6260 case GL_TEXTURE_CUBE_MAP:
6261 texture = context->getTextureCubeMap();
6262 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006263 case GL_TEXTURE_3D:
6264 if (context->getClientVersion() < 3)
6265 {
6266 return gl::error(GL_INVALID_ENUM);
6267 }
6268 texture = context->getTexture3D();
6269 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006270 case GL_TEXTURE_2D_ARRAY:
6271 if (context->getClientVersion() < 3)
6272 {
6273 return gl::error(GL_INVALID_ENUM);
6274 }
6275 texture = context->getTexture2DArray();
6276 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006277 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006278 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006279 }
6280
6281 switch (pname)
6282 {
6283 case GL_TEXTURE_WRAP_S:
6284 if (!texture->setWrapS((GLenum)param))
6285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006286 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006287 }
6288 break;
6289 case GL_TEXTURE_WRAP_T:
6290 if (!texture->setWrapT((GLenum)param))
6291 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006292 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006293 }
6294 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006295 case GL_TEXTURE_WRAP_R:
6296 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6297 {
6298 return gl::error(GL_INVALID_ENUM);
6299 }
6300 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006301 case GL_TEXTURE_MIN_FILTER:
6302 if (!texture->setMinFilter((GLenum)param))
6303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006304 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006305 }
6306 break;
6307 case GL_TEXTURE_MAG_FILTER:
6308 if (!texture->setMagFilter((GLenum)param))
6309 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006310 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006311 }
6312 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006313 case GL_TEXTURE_USAGE_ANGLE:
6314 if (!texture->setUsage((GLenum)param))
6315 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006316 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006317 }
6318 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006319 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6320 if (!context->supportsTextureFilterAnisotropy())
6321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006322 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006323 }
6324 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006326 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006327 }
6328 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006329 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006330 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006331 }
6332 }
6333 }
6334 catch(std::bad_alloc&)
6335 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006336 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006337 }
6338}
6339
6340void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
6341{
6342 glTexParameteri(target, pname, *params);
6343}
6344
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006345void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
6346{
6347 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
6348 target, levels, internalformat, width, height);
6349
6350 try
6351 {
6352 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
6353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006354 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006355 }
6356
6357 if (width < 1 || height < 1 || levels < 1)
6358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006359 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006360 }
6361
6362 if (target == GL_TEXTURE_CUBE_MAP && width != height)
6363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006364 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006365 }
6366
daniel@transgaming.com45b888a2011-11-16 03:56:39 +00006367 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006369 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006370 }
6371
6372 GLenum format = gl::ExtractFormat(internalformat);
6373 GLenum type = gl::ExtractType(internalformat);
6374
6375 if (format == GL_NONE || type == GL_NONE)
6376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006377 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006378 }
6379
6380 gl::Context *context = gl::getNonLostContext();
6381
6382 if (context)
6383 {
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006384 switch (target)
6385 {
6386 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00006387 if (width > context->getMaximum2DTextureDimension() ||
6388 height > context->getMaximum2DTextureDimension())
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006390 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006391 }
6392 break;
6393 case GL_TEXTURE_CUBE_MAP:
6394 if (width > context->getMaximumCubeTextureDimension() ||
6395 height > context->getMaximumCubeTextureDimension())
6396 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006397 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006398 }
6399 break;
6400 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006401 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006402 }
6403
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006404 if (levels != 1 && !context->supportsNonPower2Texture())
6405 {
6406 if (!gl::isPow2(width) || !gl::isPow2(height))
6407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006408 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006409 }
6410 }
6411
daniel@transgaming.come1077362011-11-11 04:16:50 +00006412 switch (internalformat)
6413 {
6414 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
6415 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
6416 if (!context->supportsDXT1Textures())
6417 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006418 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006419 }
6420 break;
6421 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
6422 if (!context->supportsDXT3Textures())
6423 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006424 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006425 }
6426 break;
6427 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
6428 if (!context->supportsDXT5Textures())
6429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006430 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006431 }
6432 break;
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006433 case GL_RGBA32F_EXT:
6434 case GL_RGB32F_EXT:
6435 case GL_ALPHA32F_EXT:
6436 case GL_LUMINANCE32F_EXT:
6437 case GL_LUMINANCE_ALPHA32F_EXT:
6438 if (!context->supportsFloat32Textures())
6439 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006440 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006441 }
6442 break;
6443 case GL_RGBA16F_EXT:
6444 case GL_RGB16F_EXT:
6445 case GL_ALPHA16F_EXT:
6446 case GL_LUMINANCE16F_EXT:
6447 case GL_LUMINANCE_ALPHA16F_EXT:
6448 if (!context->supportsFloat16Textures())
6449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006450 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006451 }
6452 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006453 case GL_DEPTH_COMPONENT16:
6454 case GL_DEPTH_COMPONENT32_OES:
6455 case GL_DEPTH24_STENCIL8_OES:
6456 if (!context->supportsDepthTextures())
6457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006458 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006459 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006460 if (target != GL_TEXTURE_2D)
6461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006462 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006463 }
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006464 // ANGLE_depth_texture only supports 1-level textures
6465 if (levels != 1)
6466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006467 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006468 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006469 break;
6470 default:
6471 break;
daniel@transgaming.come1077362011-11-11 04:16:50 +00006472 }
6473
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006474 if (target == GL_TEXTURE_2D)
6475 {
6476 gl::Texture2D *texture = context->getTexture2D();
6477
6478 if (!texture || texture->id() == 0)
6479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006480 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006481 }
6482
6483 if (texture->isImmutable())
6484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006485 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006486 }
6487
6488 texture->storage(levels, internalformat, width, height);
6489 }
6490 else if (target == GL_TEXTURE_CUBE_MAP)
6491 {
6492 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6493
6494 if (!texture || texture->id() == 0)
6495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006496 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006497 }
6498
6499 if (texture->isImmutable())
6500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006501 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006502 }
6503
6504 texture->storage(levels, internalformat, width);
6505 }
6506 else UNREACHABLE();
6507 }
6508 }
6509 catch(std::bad_alloc&)
6510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006511 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006512 }
6513}
6514
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006515void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
6516 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006517{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006518 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006519 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006520 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006521 target, level, xoffset, yoffset, width, height, format, type, pixels);
6522
6523 try
6524 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00006525 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006527 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006528 }
6529
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006530 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006532 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006533 }
6534
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006535 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
6536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006537 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006538 }
6539
daniel@transgaming.com8833dd22012-06-05 19:49:58 +00006540 if (!checkTextureFormatType(format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006541 {
daniel@transgaming.com8833dd22012-06-05 19:49:58 +00006542 return; // error is set by helper function
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006543 }
6544
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006545 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006546
6547 if (context)
6548 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006549 if (level > context->getMaximumTextureLevel())
6550 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006551 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006552 }
6553
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006554 if (format == GL_FLOAT)
6555 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006556 if (!context->supportsFloat32Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006557 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006558 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006559 }
6560 }
6561 else if (format == GL_HALF_FLOAT_OES)
6562 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006563 if (!context->supportsFloat16Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006565 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006566 }
6567 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006568 else if (gl::IsDepthTexture(format))
6569 {
6570 if (!context->supportsDepthTextures())
6571 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006572 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006573 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006574 if (target != GL_TEXTURE_2D)
6575 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006576 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006577 }
6578 // OES_depth_texture supports loading depth data, but ANGLE_depth_texture does not
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006579 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006580 }
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006581
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00006582 if (width == 0 || height == 0 || pixels == NULL)
6583 {
6584 return;
6585 }
6586
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006587 if (target == GL_TEXTURE_2D)
6588 {
6589 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00006590 if (validateSubImageParams2D(false, width, height, xoffset, yoffset, level, format, type, texture))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006591 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006592 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006593 }
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006594 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00006595 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006596 {
6597 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00006598 if (validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, format, type, texture))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006599 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006600 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006601 }
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006602 }
6603 else
6604 {
6605 UNREACHABLE();
6606 }
6607 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006608 }
6609 catch(std::bad_alloc&)
6610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006611 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006612 }
6613}
6614
6615void __stdcall glUniform1f(GLint location, GLfloat x)
6616{
6617 glUniform1fv(location, 1, &x);
6618}
6619
6620void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
6621{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006622 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006623
6624 try
6625 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006626 if (count < 0)
6627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006628 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006629 }
6630
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006631 if (location == -1)
6632 {
6633 return;
6634 }
6635
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006637
6638 if (context)
6639 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006640 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006641 if (!programBinary)
6642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006643 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006644 }
6645
6646 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006648 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006649 }
6650 }
6651 }
6652 catch(std::bad_alloc&)
6653 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006654 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006655 }
6656}
6657
6658void __stdcall glUniform1i(GLint location, GLint x)
6659{
6660 glUniform1iv(location, 1, &x);
6661}
6662
6663void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
6664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006665 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006666
6667 try
6668 {
6669 if (count < 0)
6670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006672 }
6673
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006674 if (location == -1)
6675 {
6676 return;
6677 }
6678
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006679 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006680
6681 if (context)
6682 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006683 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006684 if (!programBinary)
6685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006686 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006687 }
6688
6689 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006692 }
6693 }
6694 }
6695 catch(std::bad_alloc&)
6696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006697 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006698 }
6699}
6700
6701void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
6702{
6703 GLfloat xy[2] = {x, y};
6704
6705 glUniform2fv(location, 1, (GLfloat*)&xy);
6706}
6707
6708void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
6709{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006710 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006711
6712 try
6713 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006714 if (count < 0)
6715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006716 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006718
6719 if (location == -1)
6720 {
6721 return;
6722 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006723
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006724 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006725
6726 if (context)
6727 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006728 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006729 if (!programBinary)
6730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006731 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006732 }
6733
6734 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006736 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006737 }
6738 }
6739 }
6740 catch(std::bad_alloc&)
6741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006742 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006743 }
6744}
6745
6746void __stdcall glUniform2i(GLint location, GLint x, GLint y)
6747{
6748 GLint xy[4] = {x, y};
6749
6750 glUniform2iv(location, 1, (GLint*)&xy);
6751}
6752
6753void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
6754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006755 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006756
6757 try
6758 {
6759 if (count < 0)
6760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006761 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006762 }
6763
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006764 if (location == -1)
6765 {
6766 return;
6767 }
6768
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006769 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006770
6771 if (context)
6772 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006773 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006774 if (!programBinary)
6775 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006776 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006777 }
6778
6779 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006781 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006782 }
6783 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006784 }
6785 catch(std::bad_alloc&)
6786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006787 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006788 }
6789}
6790
6791void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6792{
6793 GLfloat xyz[3] = {x, y, z};
6794
6795 glUniform3fv(location, 1, (GLfloat*)&xyz);
6796}
6797
6798void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
6799{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006800 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006801
6802 try
6803 {
6804 if (count < 0)
6805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006806 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006807 }
6808
6809 if (location == -1)
6810 {
6811 return;
6812 }
6813
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006814 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006815
6816 if (context)
6817 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006818 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006819 if (!programBinary)
6820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006821 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006822 }
6823
6824 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006826 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006827 }
6828 }
6829 }
6830 catch(std::bad_alloc&)
6831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006832 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006833 }
6834}
6835
6836void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
6837{
6838 GLint xyz[3] = {x, y, z};
6839
6840 glUniform3iv(location, 1, (GLint*)&xyz);
6841}
6842
6843void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
6844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006845 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006846
6847 try
6848 {
6849 if (count < 0)
6850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006851 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006852 }
6853
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006854 if (location == -1)
6855 {
6856 return;
6857 }
6858
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006859 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006860
6861 if (context)
6862 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006863 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006864 if (!programBinary)
6865 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006866 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006867 }
6868
6869 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006870 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006871 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006872 }
6873 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006874 }
6875 catch(std::bad_alloc&)
6876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006877 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006878 }
6879}
6880
6881void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6882{
6883 GLfloat xyzw[4] = {x, y, z, w};
6884
6885 glUniform4fv(location, 1, (GLfloat*)&xyzw);
6886}
6887
6888void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
6889{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006890 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006891
6892 try
6893 {
6894 if (count < 0)
6895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006896 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006897 }
6898
6899 if (location == -1)
6900 {
6901 return;
6902 }
6903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006905
6906 if (context)
6907 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006908 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006909 if (!programBinary)
6910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006911 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006912 }
6913
6914 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006916 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006917 }
6918 }
6919 }
6920 catch(std::bad_alloc&)
6921 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006922 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006923 }
6924}
6925
6926void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6927{
6928 GLint xyzw[4] = {x, y, z, w};
6929
6930 glUniform4iv(location, 1, (GLint*)&xyzw);
6931}
6932
6933void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
6934{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006935 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006936
6937 try
6938 {
6939 if (count < 0)
6940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006941 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006942 }
6943
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006944 if (location == -1)
6945 {
6946 return;
6947 }
6948
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006949 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006950
6951 if (context)
6952 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006953 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006954 if (!programBinary)
6955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006956 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006957 }
6958
6959 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006961 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006962 }
6963 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006964 }
6965 catch(std::bad_alloc&)
6966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006967 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006968 }
6969}
6970
6971void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
6972{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006973 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006974 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006975
6976 try
6977 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006978 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006981 }
6982
6983 if (location == -1)
6984 {
6985 return;
6986 }
6987
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006988 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006989
6990 if (context)
6991 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006992 if (transpose != GL_FALSE && context->getClientVersion() < 3)
6993 {
6994 return gl::error(GL_INVALID_VALUE);
6995 }
6996
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006997 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006998 if (!programBinary)
6999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007000 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007001 }
7002
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007003 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007005 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007006 }
7007 }
7008 }
7009 catch(std::bad_alloc&)
7010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007011 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007012 }
7013}
7014
7015void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7016{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007017 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007018 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007019
7020 try
7021 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007022 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007024 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007025 }
7026
7027 if (location == -1)
7028 {
7029 return;
7030 }
7031
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007032 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007033
7034 if (context)
7035 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007036 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7037 {
7038 return gl::error(GL_INVALID_VALUE);
7039 }
7040
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007041 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007042 if (!programBinary)
7043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007044 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007045 }
7046
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007047 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007049 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007050 }
7051 }
7052 }
7053 catch(std::bad_alloc&)
7054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007055 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007056 }
7057}
7058
7059void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7060{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007061 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007062 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007063
7064 try
7065 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007066 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007068 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007069 }
7070
7071 if (location == -1)
7072 {
7073 return;
7074 }
7075
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007076 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007077
7078 if (context)
7079 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007080 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7081 {
7082 return gl::error(GL_INVALID_VALUE);
7083 }
7084
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007085 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007086 if (!programBinary)
7087 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007088 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007089 }
7090
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007091 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007093 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007094 }
7095 }
7096 }
7097 catch(std::bad_alloc&)
7098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007099 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007100 }
7101}
7102
7103void __stdcall glUseProgram(GLuint program)
7104{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007105 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007106
7107 try
7108 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007109 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007110
7111 if (context)
7112 {
7113 gl::Program *programObject = context->getProgram(program);
7114
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007115 if (!programObject && program != 0)
7116 {
7117 if (context->getShader(program))
7118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007119 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007120 }
7121 else
7122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007123 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007124 }
7125 }
7126
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007127 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007128 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007129 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007130 }
7131
7132 context->useProgram(program);
7133 }
7134 }
7135 catch(std::bad_alloc&)
7136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007137 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138 }
7139}
7140
7141void __stdcall glValidateProgram(GLuint program)
7142{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007143 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007144
7145 try
7146 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007147 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007148
7149 if (context)
7150 {
7151 gl::Program *programObject = context->getProgram(program);
7152
7153 if (!programObject)
7154 {
7155 if (context->getShader(program))
7156 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007157 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007158 }
7159 else
7160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007161 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007162 }
7163 }
7164
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007165 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007166 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007167 }
7168 catch(std::bad_alloc&)
7169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007170 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007171 }
7172}
7173
7174void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7175{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007176 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007177
7178 try
7179 {
7180 if (index >= gl::MAX_VERTEX_ATTRIBS)
7181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007182 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007183 }
7184
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007185 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007186
7187 if (context)
7188 {
7189 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007190 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007191 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007192 }
7193 catch(std::bad_alloc&)
7194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007195 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007196 }
7197}
7198
7199void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007201 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007202
7203 try
7204 {
7205 if (index >= gl::MAX_VERTEX_ATTRIBS)
7206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007207 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007208 }
7209
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007210 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007211
7212 if (context)
7213 {
7214 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007215 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007217 }
7218 catch(std::bad_alloc&)
7219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007220 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007221 }
7222}
7223
7224void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7225{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007226 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007227
7228 try
7229 {
7230 if (index >= gl::MAX_VERTEX_ATTRIBS)
7231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007233 }
7234
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007235 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007236
7237 if (context)
7238 {
7239 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007240 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007241 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007242 }
7243 catch(std::bad_alloc&)
7244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007245 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007246 }
7247}
7248
7249void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7250{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007251 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007252
7253 try
7254 {
7255 if (index >= gl::MAX_VERTEX_ATTRIBS)
7256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007257 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007258 }
7259
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007260 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007261
7262 if (context)
7263 {
7264 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007265 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007266 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007267 }
7268 catch(std::bad_alloc&)
7269 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007270 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007271 }
7272}
7273
7274void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7275{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007276 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", index, x, y, z);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007277
7278 try
7279 {
7280 if (index >= gl::MAX_VERTEX_ATTRIBS)
7281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007283 }
7284
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007285 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007286
7287 if (context)
7288 {
7289 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007290 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007291 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007292 }
7293 catch(std::bad_alloc&)
7294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007295 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007296 }
7297}
7298
7299void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7300{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007301 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007302
7303 try
7304 {
7305 if (index >= gl::MAX_VERTEX_ATTRIBS)
7306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007307 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007308 }
7309
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007311
7312 if (context)
7313 {
7314 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007315 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007317 }
7318 catch(std::bad_alloc&)
7319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007320 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007321 }
7322}
7323
7324void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7325{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007326 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f, GLfloat w = %f)", index, x, y, z, w);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007327
7328 try
7329 {
7330 if (index >= gl::MAX_VERTEX_ATTRIBS)
7331 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007332 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007333 }
7334
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007336
7337 if (context)
7338 {
7339 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007340 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007341 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007342 }
7343 catch(std::bad_alloc&)
7344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007345 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007346 }
7347}
7348
7349void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
7350{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007351 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007352
7353 try
7354 {
7355 if (index >= gl::MAX_VERTEX_ATTRIBS)
7356 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007357 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007358 }
7359
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007360 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007361
7362 if (context)
7363 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007364 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007365 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007366 }
7367 catch(std::bad_alloc&)
7368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007369 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007370 }
7371}
7372
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007373void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
7374{
7375 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
7376
7377 try
7378 {
7379 if (index >= gl::MAX_VERTEX_ATTRIBS)
7380 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007381 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007382 }
7383
7384 gl::Context *context = gl::getNonLostContext();
7385
7386 if (context)
7387 {
7388 context->setVertexAttribDivisor(index, divisor);
7389 }
7390 }
7391 catch(std::bad_alloc&)
7392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007394 }
7395}
7396
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007397void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007399 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007400 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007401 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007402
7403 try
7404 {
7405 if (index >= gl::MAX_VERTEX_ATTRIBS)
7406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007407 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007408 }
7409
7410 if (size < 1 || size > 4)
7411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007412 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007413 }
7414
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007415 gl::Context *context = gl::getNonLostContext();
7416
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007417 switch (type)
7418 {
7419 case GL_BYTE:
7420 case GL_UNSIGNED_BYTE:
7421 case GL_SHORT:
7422 case GL_UNSIGNED_SHORT:
7423 case GL_FIXED:
7424 case GL_FLOAT:
7425 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007426 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007427 case GL_INT:
7428 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007429 case GL_INT_2_10_10_10_REV:
7430 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007431 if (context && context->getClientVersion() < 3)
7432 {
7433 return gl::error(GL_INVALID_ENUM);
7434 }
7435 else
7436 {
7437 break;
7438 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007439 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007440 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007441 }
7442
7443 if (stride < 0)
7444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007445 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007446 }
7447
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007448 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
7449 {
7450 return gl::error(GL_INVALID_OPERATION);
7451 }
7452
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007453 if (context)
7454 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00007455 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
7456 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007457 }
7458 }
7459 catch(std::bad_alloc&)
7460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007461 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007462 }
7463}
7464
7465void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
7466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007467 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007468
7469 try
7470 {
7471 if (width < 0 || height < 0)
7472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007473 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007474 }
7475
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007476 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007477
7478 if (context)
7479 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007480 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007481 }
7482 }
7483 catch(std::bad_alloc&)
7484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007485 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007486 }
7487}
7488
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007489// OpenGL ES 3.0 functions
7490
7491void __stdcall glReadBuffer(GLenum mode)
7492{
7493 EVENT("(GLenum mode = 0x%X)", mode);
7494
7495 try
7496 {
7497 gl::Context *context = gl::getNonLostContext();
7498
7499 if (context)
7500 {
7501 if (context->getClientVersion() < 3)
7502 {
7503 return gl::error(GL_INVALID_OPERATION);
7504 }
7505 }
7506
7507 UNIMPLEMENTED();
7508 }
7509 catch(std::bad_alloc&)
7510 {
7511 return gl::error(GL_OUT_OF_MEMORY);
7512 }
7513}
7514
7515void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
7516{
7517 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
7518 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
7519
7520 try
7521 {
7522 gl::Context *context = gl::getNonLostContext();
7523
7524 if (context)
7525 {
7526 if (context->getClientVersion() < 3)
7527 {
7528 return gl::error(GL_INVALID_OPERATION);
7529 }
7530 }
7531
7532 UNIMPLEMENTED();
7533 }
7534 catch(std::bad_alloc&)
7535 {
7536 return gl::error(GL_OUT_OF_MEMORY);
7537 }
7538}
7539
7540void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
7541{
7542 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7543 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
7544 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7545 target, level, internalformat, width, height, depth, border, format, type, pixels);
7546
7547 try
7548 {
7549 gl::Context *context = gl::getNonLostContext();
7550
7551 if (context)
7552 {
7553 if (context->getClientVersion() < 3)
7554 {
7555 return gl::error(GL_INVALID_OPERATION);
7556 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007557
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007558 // validateES3TexImageFormat sets the error code if there is an error
7559 if (!validateES3TexImageFormat(context, target, level, internalformat, false, false,
7560 0, 0, 0, width, height, depth, border, format, type))
7561 {
7562 return;
7563 }
7564
7565 switch(target)
7566 {
7567 case GL_TEXTURE_3D:
7568 {
7569 gl::Texture3D *texture = context->getTexture3D();
7570 texture->setImage(level, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7571 }
7572 break;
7573
7574 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007575 {
7576 gl::Texture2DArray *texture = context->getTexture2DArray();
7577 texture->setImage(level, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7578 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007579 break;
7580
7581 default:
7582 return gl::error(GL_INVALID_ENUM);
7583 }
7584 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007585 }
7586 catch(std::bad_alloc&)
7587 {
7588 return gl::error(GL_OUT_OF_MEMORY);
7589 }
7590}
7591
7592void __stdcall glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels)
7593{
7594 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7595 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7596 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7597 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
7598
7599 try
7600 {
7601 gl::Context *context = gl::getNonLostContext();
7602
7603 if (context)
7604 {
7605 if (context->getClientVersion() < 3)
7606 {
7607 return gl::error(GL_INVALID_OPERATION);
7608 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007609
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007610 if (!pixels)
7611 {
7612 return gl::error(GL_INVALID_VALUE);
7613 }
7614
7615 // validateES3TexImageFormat sets the error code if there is an error
7616 if (!validateES3TexImageFormat(context, target, level, GL_NONE, false, true,
7617 xoffset, yoffset, zoffset, width, height, depth, 0,
7618 format, type))
7619 {
7620 return;
7621 }
7622
7623 switch(target)
7624 {
7625 case GL_TEXTURE_3D:
7626 {
7627 gl::Texture3D *texture = context->getTexture3D();
7628 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7629 }
7630 break;
7631
7632 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007633 {
7634 gl::Texture2DArray *texture = context->getTexture2DArray();
7635 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7636 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007637 break;
7638
7639 default:
7640 return gl::error(GL_INVALID_ENUM);
7641 }
7642 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007643 }
7644 catch(std::bad_alloc&)
7645 {
7646 return gl::error(GL_OUT_OF_MEMORY);
7647 }
7648}
7649
7650void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
7651{
7652 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7653 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7654 target, level, xoffset, yoffset, zoffset, x, y, width, height);
7655
7656 try
7657 {
7658 gl::Context *context = gl::getNonLostContext();
7659
7660 if (context)
7661 {
7662 if (context->getClientVersion() < 3)
7663 {
7664 return gl::error(GL_INVALID_OPERATION);
7665 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007666
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007667 if (!validateCopyTexImageParameters(context, target, false, level, xoffset, yoffset, zoffset,
7668 x, y, width, height))
7669 {
7670 return;
7671 }
7672
7673 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
7674 gl::Texture *texture = NULL;
7675 switch (target)
7676 {
7677 case GL_TEXTURE_3D:
7678 texture = context->getTexture3D();
7679 break;
7680
7681 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007682 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007683 break;
7684
7685 default:
7686 return gl::error(GL_INVALID_ENUM);
7687 }
7688
7689 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
7690 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007691 }
7692 catch(std::bad_alloc&)
7693 {
7694 return gl::error(GL_OUT_OF_MEMORY);
7695 }
7696}
7697
7698void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
7699{
7700 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7701 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
7702 "const GLvoid* data = 0x%0.8p)",
7703 target, level, internalformat, width, height, depth, border, imageSize, data);
7704
7705 try
7706 {
7707 gl::Context *context = gl::getNonLostContext();
7708
7709 if (context)
7710 {
7711 if (context->getClientVersion() < 3)
7712 {
7713 return gl::error(GL_INVALID_OPERATION);
7714 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007715
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007716 if (imageSize < 0 || imageSize != gl::ComputeCompressedSize(width, height, internalformat))
7717 {
7718 return gl::error(GL_INVALID_VALUE);
7719 }
7720
7721 // validateES3TexImageFormat sets the error code if there is an error
7722 if (!validateES3TexImageFormat(context, target, level, internalformat, true, false,
7723 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
7724 {
7725 return;
7726 }
7727
7728 switch(target)
7729 {
7730 case GL_TEXTURE_3D:
7731 {
7732 gl::Texture3D *texture = context->getTexture3D();
7733 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
7734 }
7735 break;
7736
7737 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007738 {
7739 gl::Texture2DArray *texture = context->getTexture2DArray();
7740 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
7741 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007742 break;
7743
7744 default:
7745 return gl::error(GL_INVALID_ENUM);
7746 }
7747 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007748 }
7749 catch(std::bad_alloc&)
7750 {
7751 return gl::error(GL_OUT_OF_MEMORY);
7752 }
7753}
7754
7755void __stdcall glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
7756{
7757 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7758 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7759 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
7760 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
7761
7762 try
7763 {
7764 gl::Context *context = gl::getNonLostContext();
7765
7766 if (context)
7767 {
7768 if (context->getClientVersion() < 3)
7769 {
7770 return gl::error(GL_INVALID_OPERATION);
7771 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007772
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007773 if (imageSize < 0 || imageSize != gl::ComputeCompressedSize(width, height, format))
7774 {
7775 return gl::error(GL_INVALID_VALUE);
7776 }
7777
7778 if (!data)
7779 {
7780 return gl::error(GL_INVALID_VALUE);
7781 }
7782
7783 // validateES3TexImageFormat sets the error code if there is an error
7784 if (!validateES3TexImageFormat(context, target, level, GL_NONE, true, true,
7785 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
7786 {
7787 return;
7788 }
7789
7790 switch(target)
7791 {
7792 case GL_TEXTURE_3D:
7793 {
7794 gl::Texture3D *texture = context->getTexture3D();
7795 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
7796 format, imageSize, data);
7797 }
7798 break;
7799
7800 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007801 {
7802 gl::Texture2DArray *texture = context->getTexture2DArray();
7803 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
7804 format, imageSize, data);
7805 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007806 break;
7807
7808 default:
7809 return gl::error(GL_INVALID_ENUM);
7810 }
7811 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007812 }
7813 catch(std::bad_alloc&)
7814 {
7815 return gl::error(GL_OUT_OF_MEMORY);
7816 }
7817}
7818
7819void __stdcall glGenQueries(GLsizei n, GLuint* ids)
7820{
7821 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7822
7823 try
7824 {
7825 gl::Context *context = gl::getNonLostContext();
7826
7827 if (context)
7828 {
7829 if (context->getClientVersion() < 3)
7830 {
7831 return gl::error(GL_INVALID_OPERATION);
7832 }
7833 }
7834
7835 UNIMPLEMENTED();
7836 }
7837 catch(std::bad_alloc&)
7838 {
7839 return gl::error(GL_OUT_OF_MEMORY);
7840 }
7841}
7842
7843void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
7844{
7845 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7846
7847 try
7848 {
7849 gl::Context *context = gl::getNonLostContext();
7850
7851 if (context)
7852 {
7853 if (context->getClientVersion() < 3)
7854 {
7855 return gl::error(GL_INVALID_OPERATION);
7856 }
7857 }
7858
7859 UNIMPLEMENTED();
7860 }
7861 catch(std::bad_alloc&)
7862 {
7863 return gl::error(GL_OUT_OF_MEMORY);
7864 }
7865}
7866
7867GLboolean __stdcall glIsQuery(GLuint id)
7868{
7869 EVENT("(GLuint id = %u)", id);
7870
7871 try
7872 {
7873 gl::Context *context = gl::getNonLostContext();
7874
7875 if (context)
7876 {
7877 if (context->getClientVersion() < 3)
7878 {
7879 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
7880 }
7881 }
7882
7883 UNIMPLEMENTED();
7884 }
7885 catch(std::bad_alloc&)
7886 {
7887 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
7888 }
7889
7890 return GL_FALSE;
7891}
7892
7893void __stdcall glBeginQuery(GLenum target, GLuint id)
7894{
7895 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7896
7897 try
7898 {
7899 gl::Context *context = gl::getNonLostContext();
7900
7901 if (context)
7902 {
7903 if (context->getClientVersion() < 3)
7904 {
7905 return gl::error(GL_INVALID_OPERATION);
7906 }
7907 }
7908
7909 UNIMPLEMENTED();
7910 }
7911 catch(std::bad_alloc&)
7912 {
7913 return gl::error(GL_OUT_OF_MEMORY);
7914 }
7915}
7916
7917void __stdcall glEndQuery(GLenum target)
7918{
7919 EVENT("(GLenum target = 0x%X)", target);
7920
7921 try
7922 {
7923 gl::Context *context = gl::getNonLostContext();
7924
7925 if (context)
7926 {
7927 if (context->getClientVersion() < 3)
7928 {
7929 return gl::error(GL_INVALID_OPERATION);
7930 }
7931 }
7932
7933 UNIMPLEMENTED();
7934 }
7935 catch(std::bad_alloc&)
7936 {
7937 return gl::error(GL_OUT_OF_MEMORY);
7938 }
7939}
7940
7941void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
7942{
7943 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
7944
7945 try
7946 {
7947 gl::Context *context = gl::getNonLostContext();
7948
7949 if (context)
7950 {
7951 if (context->getClientVersion() < 3)
7952 {
7953 return gl::error(GL_INVALID_OPERATION);
7954 }
7955 }
7956
7957 UNIMPLEMENTED();
7958 }
7959 catch(std::bad_alloc&)
7960 {
7961 return gl::error(GL_OUT_OF_MEMORY);
7962 }
7963}
7964
7965void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
7966{
7967 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
7968
7969 try
7970 {
7971 gl::Context *context = gl::getNonLostContext();
7972
7973 if (context)
7974 {
7975 if (context->getClientVersion() < 3)
7976 {
7977 return gl::error(GL_INVALID_OPERATION);
7978 }
7979 }
7980
7981 UNIMPLEMENTED();
7982 }
7983 catch(std::bad_alloc&)
7984 {
7985 return gl::error(GL_OUT_OF_MEMORY);
7986 }
7987}
7988
7989GLboolean __stdcall glUnmapBuffer(GLenum target)
7990{
7991 EVENT("(GLenum target = 0x%X)", target);
7992
7993 try
7994 {
7995 gl::Context *context = gl::getNonLostContext();
7996
7997 if (context)
7998 {
7999 if (context->getClientVersion() < 3)
8000 {
8001 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8002 }
8003 }
8004
8005 UNIMPLEMENTED();
8006 }
8007 catch(std::bad_alloc&)
8008 {
8009 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8010 }
8011
8012 return GL_FALSE;
8013}
8014
8015void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8016{
8017 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8018
8019 try
8020 {
8021 gl::Context *context = gl::getNonLostContext();
8022
8023 if (context)
8024 {
8025 if (context->getClientVersion() < 3)
8026 {
8027 return gl::error(GL_INVALID_OPERATION);
8028 }
8029 }
8030
8031 UNIMPLEMENTED();
8032 }
8033 catch(std::bad_alloc&)
8034 {
8035 return gl::error(GL_OUT_OF_MEMORY);
8036 }
8037}
8038
8039void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8040{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008041 try
8042 {
8043 gl::Context *context = gl::getNonLostContext();
8044
8045 if (context)
8046 {
8047 if (context->getClientVersion() < 3)
8048 {
8049 return gl::error(GL_INVALID_OPERATION);
8050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008051
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008052 glDrawBuffersEXT(n, bufs);
8053 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008054 }
8055 catch(std::bad_alloc&)
8056 {
8057 return gl::error(GL_OUT_OF_MEMORY);
8058 }
8059}
8060
8061void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8062{
8063 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8064 location, count, transpose, value);
8065
8066 try
8067 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008068 if (count < 0)
8069 {
8070 return gl::error(GL_INVALID_VALUE);
8071 }
8072
8073 if (location == -1)
8074 {
8075 return;
8076 }
8077
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008078 gl::Context *context = gl::getNonLostContext();
8079
8080 if (context)
8081 {
8082 if (context->getClientVersion() < 3)
8083 {
8084 return gl::error(GL_INVALID_OPERATION);
8085 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008086
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008087 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8088 if (!programBinary)
8089 {
8090 return gl::error(GL_INVALID_OPERATION);
8091 }
8092
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008093 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008094 {
8095 return gl::error(GL_INVALID_OPERATION);
8096 }
8097 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008098 }
8099 catch(std::bad_alloc&)
8100 {
8101 return gl::error(GL_OUT_OF_MEMORY);
8102 }
8103}
8104
8105void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8106{
8107 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8108 location, count, transpose, value);
8109
8110 try
8111 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008112 if (count < 0)
8113 {
8114 return gl::error(GL_INVALID_VALUE);
8115 }
8116
8117 if (location == -1)
8118 {
8119 return;
8120 }
8121
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008122 gl::Context *context = gl::getNonLostContext();
8123
8124 if (context)
8125 {
8126 if (context->getClientVersion() < 3)
8127 {
8128 return gl::error(GL_INVALID_OPERATION);
8129 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008130
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008131 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8132 if (!programBinary)
8133 {
8134 return gl::error(GL_INVALID_OPERATION);
8135 }
8136
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008137 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008138 {
8139 return gl::error(GL_INVALID_OPERATION);
8140 }
8141 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008142 }
8143 catch(std::bad_alloc&)
8144 {
8145 return gl::error(GL_OUT_OF_MEMORY);
8146 }
8147}
8148
8149void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8150{
8151 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8152 location, count, transpose, value);
8153
8154 try
8155 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008156 if (count < 0)
8157 {
8158 return gl::error(GL_INVALID_VALUE);
8159 }
8160
8161 if (location == -1)
8162 {
8163 return;
8164 }
8165
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008166 gl::Context *context = gl::getNonLostContext();
8167
8168 if (context)
8169 {
8170 if (context->getClientVersion() < 3)
8171 {
8172 return gl::error(GL_INVALID_OPERATION);
8173 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008174
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008175 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8176 if (!programBinary)
8177 {
8178 return gl::error(GL_INVALID_OPERATION);
8179 }
8180
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008181 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008182 {
8183 return gl::error(GL_INVALID_OPERATION);
8184 }
8185 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008186 }
8187 catch(std::bad_alloc&)
8188 {
8189 return gl::error(GL_OUT_OF_MEMORY);
8190 }
8191}
8192
8193void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8194{
8195 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8196 location, count, transpose, value);
8197
8198 try
8199 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008200 if (count < 0)
8201 {
8202 return gl::error(GL_INVALID_VALUE);
8203 }
8204
8205 if (location == -1)
8206 {
8207 return;
8208 }
8209
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008210 gl::Context *context = gl::getNonLostContext();
8211
8212 if (context)
8213 {
8214 if (context->getClientVersion() < 3)
8215 {
8216 return gl::error(GL_INVALID_OPERATION);
8217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008218
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008219 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8220 if (!programBinary)
8221 {
8222 return gl::error(GL_INVALID_OPERATION);
8223 }
8224
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008225 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008226 {
8227 return gl::error(GL_INVALID_OPERATION);
8228 }
8229 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008230 }
8231 catch(std::bad_alloc&)
8232 {
8233 return gl::error(GL_OUT_OF_MEMORY);
8234 }
8235}
8236
8237void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8238{
8239 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8240 location, count, transpose, value);
8241
8242 try
8243 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008244 if (count < 0)
8245 {
8246 return gl::error(GL_INVALID_VALUE);
8247 }
8248
8249 if (location == -1)
8250 {
8251 return;
8252 }
8253
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008254 gl::Context *context = gl::getNonLostContext();
8255
8256 if (context)
8257 {
8258 if (context->getClientVersion() < 3)
8259 {
8260 return gl::error(GL_INVALID_OPERATION);
8261 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008262
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008263 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8264 if (!programBinary)
8265 {
8266 return gl::error(GL_INVALID_OPERATION);
8267 }
8268
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008269 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008270 {
8271 return gl::error(GL_INVALID_OPERATION);
8272 }
8273 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008274 }
8275 catch(std::bad_alloc&)
8276 {
8277 return gl::error(GL_OUT_OF_MEMORY);
8278 }
8279}
8280
8281void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8282{
8283 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8284 location, count, transpose, value);
8285
8286 try
8287 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008288 if (count < 0)
8289 {
8290 return gl::error(GL_INVALID_VALUE);
8291 }
8292
8293 if (location == -1)
8294 {
8295 return;
8296 }
8297
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008298 gl::Context *context = gl::getNonLostContext();
8299
8300 if (context)
8301 {
8302 if (context->getClientVersion() < 3)
8303 {
8304 return gl::error(GL_INVALID_OPERATION);
8305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008306
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008307 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8308 if (!programBinary)
8309 {
8310 return gl::error(GL_INVALID_OPERATION);
8311 }
8312
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008313 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008314 {
8315 return gl::error(GL_INVALID_OPERATION);
8316 }
8317 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008318 }
8319 catch(std::bad_alloc&)
8320 {
8321 return gl::error(GL_OUT_OF_MEMORY);
8322 }
8323}
8324
8325void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
8326{
8327 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
8328 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8329 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8330
8331 try
8332 {
8333 gl::Context *context = gl::getNonLostContext();
8334
8335 if (context)
8336 {
8337 if (context->getClientVersion() < 3)
8338 {
8339 return gl::error(GL_INVALID_OPERATION);
8340 }
8341 }
8342
8343 UNIMPLEMENTED();
8344 }
8345 catch(std::bad_alloc&)
8346 {
8347 return gl::error(GL_OUT_OF_MEMORY);
8348 }
8349}
8350
8351void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
8352{
8353 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8354 target, samples, internalformat, width, height);
8355
8356 try
8357 {
8358 gl::Context *context = gl::getNonLostContext();
8359
8360 if (context)
8361 {
8362 if (context->getClientVersion() < 3)
8363 {
8364 return gl::error(GL_INVALID_OPERATION);
8365 }
8366 }
8367
8368 UNIMPLEMENTED();
8369 }
8370 catch(std::bad_alloc&)
8371 {
8372 return gl::error(GL_OUT_OF_MEMORY);
8373 }
8374}
8375
8376void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
8377{
8378 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
8379 target, attachment, texture, level, layer);
8380
8381 try
8382 {
8383 gl::Context *context = gl::getNonLostContext();
8384
8385 if (context)
8386 {
8387 if (context->getClientVersion() < 3)
8388 {
8389 return gl::error(GL_INVALID_OPERATION);
8390 }
8391 }
8392
8393 UNIMPLEMENTED();
8394 }
8395 catch(std::bad_alloc&)
8396 {
8397 return gl::error(GL_OUT_OF_MEMORY);
8398 }
8399}
8400
8401GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8402{
8403 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8404 target, offset, length, access);
8405
8406 try
8407 {
8408 gl::Context *context = gl::getNonLostContext();
8409
8410 if (context)
8411 {
8412 if (context->getClientVersion() < 3)
8413 {
8414 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8415 }
8416 }
8417
8418 UNIMPLEMENTED();
8419 }
8420 catch(std::bad_alloc&)
8421 {
8422 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
8423 }
8424
8425 return NULL;
8426}
8427
8428void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
8429{
8430 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8431
8432 try
8433 {
8434 gl::Context *context = gl::getNonLostContext();
8435
8436 if (context)
8437 {
8438 if (context->getClientVersion() < 3)
8439 {
8440 return gl::error(GL_INVALID_OPERATION);
8441 }
8442 }
8443
8444 UNIMPLEMENTED();
8445 }
8446 catch(std::bad_alloc&)
8447 {
8448 return gl::error(GL_OUT_OF_MEMORY);
8449 }
8450}
8451
8452void __stdcall glBindVertexArray(GLuint array)
8453{
8454 EVENT("(GLuint array = %u)", array);
8455
8456 try
8457 {
8458 gl::Context *context = gl::getNonLostContext();
8459
8460 if (context)
8461 {
8462 if (context->getClientVersion() < 3)
8463 {
8464 return gl::error(GL_INVALID_OPERATION);
8465 }
8466 }
8467
8468 UNIMPLEMENTED();
8469 }
8470 catch(std::bad_alloc&)
8471 {
8472 return gl::error(GL_OUT_OF_MEMORY);
8473 }
8474}
8475
8476void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
8477{
8478 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
8479
8480 try
8481 {
8482 gl::Context *context = gl::getNonLostContext();
8483
8484 if (context)
8485 {
8486 if (context->getClientVersion() < 3)
8487 {
8488 return gl::error(GL_INVALID_OPERATION);
8489 }
8490 }
8491
8492 UNIMPLEMENTED();
8493 }
8494 catch(std::bad_alloc&)
8495 {
8496 return gl::error(GL_OUT_OF_MEMORY);
8497 }
8498}
8499
8500void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
8501{
8502 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
8503
8504 try
8505 {
8506 gl::Context *context = gl::getNonLostContext();
8507
8508 if (context)
8509 {
8510 if (context->getClientVersion() < 3)
8511 {
8512 return gl::error(GL_INVALID_OPERATION);
8513 }
8514 }
8515
8516 UNIMPLEMENTED();
8517 }
8518 catch(std::bad_alloc&)
8519 {
8520 return gl::error(GL_OUT_OF_MEMORY);
8521 }
8522}
8523
8524GLboolean __stdcall glIsVertexArray(GLuint array)
8525{
8526 EVENT("(GLuint array = %u)", array);
8527
8528 try
8529 {
8530 gl::Context *context = gl::getNonLostContext();
8531
8532 if (context)
8533 {
8534 if (context->getClientVersion() < 3)
8535 {
8536 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8537 }
8538 }
8539
8540 UNIMPLEMENTED();
8541 }
8542 catch(std::bad_alloc&)
8543 {
8544 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8545 }
8546
8547 return GL_FALSE;
8548}
8549
8550void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
8551{
8552 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
8553 target, index, data);
8554
8555 try
8556 {
8557 gl::Context *context = gl::getNonLostContext();
8558
8559 if (context)
8560 {
8561 if (context->getClientVersion() < 3)
8562 {
8563 return gl::error(GL_INVALID_OPERATION);
8564 }
8565 }
8566
8567 UNIMPLEMENTED();
8568 }
8569 catch(std::bad_alloc&)
8570 {
8571 return gl::error(GL_OUT_OF_MEMORY);
8572 }
8573}
8574
8575void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
8576{
8577 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
8578
8579 try
8580 {
8581 gl::Context *context = gl::getNonLostContext();
8582
8583 if (context)
8584 {
8585 if (context->getClientVersion() < 3)
8586 {
8587 return gl::error(GL_INVALID_OPERATION);
8588 }
8589 }
8590
8591 UNIMPLEMENTED();
8592 }
8593 catch(std::bad_alloc&)
8594 {
8595 return gl::error(GL_OUT_OF_MEMORY);
8596 }
8597}
8598
8599void __stdcall glEndTransformFeedback(void)
8600{
8601 EVENT("(void)");
8602
8603 try
8604 {
8605 gl::Context *context = gl::getNonLostContext();
8606
8607 if (context)
8608 {
8609 if (context->getClientVersion() < 3)
8610 {
8611 return gl::error(GL_INVALID_OPERATION);
8612 }
8613 }
8614
8615 UNIMPLEMENTED();
8616 }
8617 catch(std::bad_alloc&)
8618 {
8619 return gl::error(GL_OUT_OF_MEMORY);
8620 }
8621}
8622
8623void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
8624{
8625 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
8626 target, index, buffer, offset, size);
8627
8628 try
8629 {
8630 gl::Context *context = gl::getNonLostContext();
8631
8632 if (context)
8633 {
8634 if (context->getClientVersion() < 3)
8635 {
8636 return gl::error(GL_INVALID_OPERATION);
8637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008638
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008639 switch (target)
8640 {
8641 case GL_TRANSFORM_FEEDBACK_BUFFER:
8642 if (index > context->getMaxTransformFeedbackBufferBindings())
8643 {
8644 return gl::error(GL_INVALID_VALUE);
8645 }
8646 break;
8647
8648 case GL_UNIFORM_BUFFER:
8649 if (index >= context->getMaximumCombinedUniformBufferBindings())
8650 {
8651 return gl::error(GL_INVALID_VALUE);
8652 }
8653 break;
8654
8655 default:
8656 return gl::error(GL_INVALID_ENUM);
8657 }
8658
8659 gl::Buffer *bufferObject = context->getBuffer(buffer);
8660 if (!bufferObject)
8661 {
8662 // Buffer index must not have been valid
8663 return gl::error(GL_INVALID_VALUE);
8664 }
8665
8666 if (size <= 0 || static_cast<unsigned int>(offset + size) > bufferObject->size())
8667 {
8668 return gl::error(GL_INVALID_VALUE);
8669 }
8670
8671 switch (target)
8672 {
8673 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008674 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
8675 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008676 break;
8677
8678 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00008679
8680 // it is an error to bind an offset not a multiple of the alignment
8681 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
8682 {
8683 return gl::error(GL_INVALID_VALUE);
8684 }
8685
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008686 context->bindIndexedUniformBuffer(buffer, index, offset, size);
8687 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008688 break;
8689
8690 default:
8691 UNREACHABLE();
8692 }
8693 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008694 }
8695 catch(std::bad_alloc&)
8696 {
8697 return gl::error(GL_OUT_OF_MEMORY);
8698 }
8699}
8700
8701void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
8702{
8703 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
8704 target, index, buffer);
8705
8706 try
8707 {
8708 gl::Context *context = gl::getNonLostContext();
8709
8710 if (context)
8711 {
8712 if (context->getClientVersion() < 3)
8713 {
8714 return gl::error(GL_INVALID_OPERATION);
8715 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008716
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008717 switch (target)
8718 {
8719 case GL_TRANSFORM_FEEDBACK_BUFFER:
8720 if (index > context->getMaxTransformFeedbackBufferBindings())
8721 {
8722 return gl::error(GL_INVALID_VALUE);
8723 }
8724 break;
8725
8726 case GL_UNIFORM_BUFFER:
8727 if (index > context->getMaximumCombinedUniformBufferBindings())
8728 {
8729 return gl::error(GL_INVALID_VALUE);
8730 }
8731 break;
8732
8733 default:
8734 return gl::error(GL_INVALID_ENUM);
8735 }
8736
8737 gl::Buffer *bufferObject = context->getBuffer(buffer);
8738 if (!bufferObject)
8739 {
8740 // Buffer index must not have been valid
8741 return gl::error(GL_INVALID_VALUE);
8742 }
8743
8744 switch (target)
8745 {
8746 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00008747 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008748 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008749 break;
8750
8751 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00008752 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008753 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008754 break;
8755
8756 default:
8757 UNREACHABLE();
8758 }
8759 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008760 }
8761 catch(std::bad_alloc&)
8762 {
8763 return gl::error(GL_OUT_OF_MEMORY);
8764 }
8765}
8766
8767void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
8768{
8769 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
8770 program, count, varyings, bufferMode);
8771
8772 try
8773 {
8774 gl::Context *context = gl::getNonLostContext();
8775
8776 if (context)
8777 {
8778 if (context->getClientVersion() < 3)
8779 {
8780 return gl::error(GL_INVALID_OPERATION);
8781 }
8782 }
8783
8784 UNIMPLEMENTED();
8785 }
8786 catch(std::bad_alloc&)
8787 {
8788 return gl::error(GL_OUT_OF_MEMORY);
8789 }
8790}
8791
8792void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
8793{
8794 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
8795 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
8796 program, index, bufSize, length, size, type, name);
8797
8798 try
8799 {
8800 gl::Context *context = gl::getNonLostContext();
8801
8802 if (context)
8803 {
8804 if (context->getClientVersion() < 3)
8805 {
8806 return gl::error(GL_INVALID_OPERATION);
8807 }
8808 }
8809
8810 UNIMPLEMENTED();
8811 }
8812 catch(std::bad_alloc&)
8813 {
8814 return gl::error(GL_OUT_OF_MEMORY);
8815 }
8816}
8817
8818void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
8819{
8820 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
8821 index, size, type, stride, pointer);
8822
8823 try
8824 {
8825 gl::Context *context = gl::getNonLostContext();
8826
8827 if (context)
8828 {
8829 if (context->getClientVersion() < 3)
8830 {
8831 return gl::error(GL_INVALID_OPERATION);
8832 }
8833 }
8834
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008835 if (index >= gl::MAX_VERTEX_ATTRIBS)
8836 {
8837 return gl::error(GL_INVALID_VALUE);
8838 }
8839
8840 if (size < 1 || size > 4)
8841 {
8842 return gl::error(GL_INVALID_VALUE);
8843 }
8844
8845 switch (type)
8846 {
8847 case GL_BYTE:
8848 case GL_UNSIGNED_BYTE:
8849 case GL_SHORT:
8850 case GL_UNSIGNED_SHORT:
8851 case GL_INT:
8852 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008853 case GL_INT_2_10_10_10_REV:
8854 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008855 break;
8856 default:
8857 return gl::error(GL_INVALID_ENUM);
8858 }
8859
8860 if (stride < 0)
8861 {
8862 return gl::error(GL_INVALID_VALUE);
8863 }
8864
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008865 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8866 {
8867 return gl::error(GL_INVALID_OPERATION);
8868 }
8869
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008870 if (context)
8871 {
8872 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
8873 stride, pointer);
8874 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008875 }
8876 catch(std::bad_alloc&)
8877 {
8878 return gl::error(GL_OUT_OF_MEMORY);
8879 }
8880}
8881
8882void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
8883{
8884 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
8885 index, pname, params);
8886
8887 try
8888 {
8889 gl::Context *context = gl::getNonLostContext();
8890
8891 if (context)
8892 {
8893 if (context->getClientVersion() < 3)
8894 {
8895 return gl::error(GL_INVALID_OPERATION);
8896 }
8897 }
8898
8899 UNIMPLEMENTED();
8900 }
8901 catch(std::bad_alloc&)
8902 {
8903 return gl::error(GL_OUT_OF_MEMORY);
8904 }
8905}
8906
8907void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
8908{
8909 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
8910 index, pname, params);
8911
8912 try
8913 {
8914 gl::Context *context = gl::getNonLostContext();
8915
8916 if (context)
8917 {
8918 if (context->getClientVersion() < 3)
8919 {
8920 return gl::error(GL_INVALID_OPERATION);
8921 }
8922 }
8923
8924 UNIMPLEMENTED();
8925 }
8926 catch(std::bad_alloc&)
8927 {
8928 return gl::error(GL_OUT_OF_MEMORY);
8929 }
8930}
8931
8932void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
8933{
8934 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
8935 index, x, y, z, w);
8936
8937 try
8938 {
8939 gl::Context *context = gl::getNonLostContext();
8940
8941 if (context)
8942 {
8943 if (context->getClientVersion() < 3)
8944 {
8945 return gl::error(GL_INVALID_OPERATION);
8946 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008947
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008948 if (index >= gl::MAX_VERTEX_ATTRIBS)
8949 {
8950 return gl::error(GL_INVALID_VALUE);
8951 }
8952
8953 GLint vals[4] = { x, y, z, w };
8954 context->setVertexAttribi(index, vals);
8955 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008956 }
8957 catch(std::bad_alloc&)
8958 {
8959 return gl::error(GL_OUT_OF_MEMORY);
8960 }
8961}
8962
8963void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
8964{
8965 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
8966 index, x, y, z, w);
8967
8968 try
8969 {
8970 gl::Context *context = gl::getNonLostContext();
8971
8972 if (context)
8973 {
8974 if (context->getClientVersion() < 3)
8975 {
8976 return gl::error(GL_INVALID_OPERATION);
8977 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008978
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008979 if (index >= gl::MAX_VERTEX_ATTRIBS)
8980 {
8981 return gl::error(GL_INVALID_VALUE);
8982 }
8983
8984 GLuint vals[4] = { x, y, z, w };
8985 context->setVertexAttribu(index, vals);
8986 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008987 }
8988 catch(std::bad_alloc&)
8989 {
8990 return gl::error(GL_OUT_OF_MEMORY);
8991 }
8992}
8993
8994void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
8995{
8996 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
8997
8998 try
8999 {
9000 gl::Context *context = gl::getNonLostContext();
9001
9002 if (context)
9003 {
9004 if (context->getClientVersion() < 3)
9005 {
9006 return gl::error(GL_INVALID_OPERATION);
9007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009008
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009009 if (index >= gl::MAX_VERTEX_ATTRIBS)
9010 {
9011 return gl::error(GL_INVALID_VALUE);
9012 }
9013
9014 context->setVertexAttribi(index, v);
9015 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009016 }
9017 catch(std::bad_alloc&)
9018 {
9019 return gl::error(GL_OUT_OF_MEMORY);
9020 }
9021}
9022
9023void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9024{
9025 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9026
9027 try
9028 {
9029 gl::Context *context = gl::getNonLostContext();
9030
9031 if (context)
9032 {
9033 if (context->getClientVersion() < 3)
9034 {
9035 return gl::error(GL_INVALID_OPERATION);
9036 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009037
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009038 if (index >= gl::MAX_VERTEX_ATTRIBS)
9039 {
9040 return gl::error(GL_INVALID_VALUE);
9041 }
9042
9043 context->setVertexAttribu(index, v);
9044 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009045 }
9046 catch(std::bad_alloc&)
9047 {
9048 return gl::error(GL_OUT_OF_MEMORY);
9049 }
9050}
9051
9052void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9053{
9054 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9055 program, location, params);
9056
9057 try
9058 {
9059 gl::Context *context = gl::getNonLostContext();
9060
9061 if (context)
9062 {
9063 if (context->getClientVersion() < 3)
9064 {
9065 return gl::error(GL_INVALID_OPERATION);
9066 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009067
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009068 if (program == 0)
9069 {
9070 return gl::error(GL_INVALID_VALUE);
9071 }
9072
9073 gl::Program *programObject = context->getProgram(program);
9074
9075 if (!programObject || !programObject->isLinked())
9076 {
9077 return gl::error(GL_INVALID_OPERATION);
9078 }
9079
9080 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9081 if (!programBinary)
9082 {
9083 return gl::error(GL_INVALID_OPERATION);
9084 }
9085
9086 if (!programBinary->getUniformuiv(location, NULL, params))
9087 {
9088 return gl::error(GL_INVALID_OPERATION);
9089 }
9090 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009091 }
9092 catch(std::bad_alloc&)
9093 {
9094 return gl::error(GL_OUT_OF_MEMORY);
9095 }
9096}
9097
9098GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9099{
9100 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9101 program, name);
9102
9103 try
9104 {
9105 gl::Context *context = gl::getNonLostContext();
9106
9107 if (context)
9108 {
9109 if (context->getClientVersion() < 3)
9110 {
9111 return gl::error(GL_INVALID_OPERATION, 0);
9112 }
9113 }
9114
9115 UNIMPLEMENTED();
9116 }
9117 catch(std::bad_alloc&)
9118 {
9119 return gl::error(GL_OUT_OF_MEMORY, 0);
9120 }
9121
9122 return 0;
9123}
9124
9125void __stdcall glUniform1ui(GLint location, GLuint v0)
9126{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009127 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009128}
9129
9130void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9131{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009132 const GLuint xy[] = { v0, v1 };
9133 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009134}
9135
9136void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9137{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009138 const GLuint xyz[] = { v0, v1, v2 };
9139 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009140}
9141
9142void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9143{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009144 const GLuint xyzw[] = { v0, v1, v2, v3 };
9145 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009146}
9147
9148void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9149{
9150 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9151 location, count, value);
9152
9153 try
9154 {
9155 gl::Context *context = gl::getNonLostContext();
9156
9157 if (context)
9158 {
9159 if (context->getClientVersion() < 3)
9160 {
9161 return gl::error(GL_INVALID_OPERATION);
9162 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009163
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009164 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9165 if (!programBinary)
9166 {
9167 return gl::error(GL_INVALID_OPERATION);
9168 }
9169
9170 if (!programBinary->setUniform1uiv(location, count, value))
9171 {
9172 return gl::error(GL_INVALID_OPERATION);
9173 }
9174 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009175 }
9176 catch(std::bad_alloc&)
9177 {
9178 return gl::error(GL_OUT_OF_MEMORY);
9179 }
9180}
9181
9182void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9183{
9184 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9185 location, count, value);
9186
9187 try
9188 {
9189 gl::Context *context = gl::getNonLostContext();
9190
9191 if (context)
9192 {
9193 if (context->getClientVersion() < 3)
9194 {
9195 return gl::error(GL_INVALID_OPERATION);
9196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009197
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009198 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9199 if (!programBinary)
9200 {
9201 return gl::error(GL_INVALID_OPERATION);
9202 }
9203
9204 if (!programBinary->setUniform2uiv(location, count, value))
9205 {
9206 return gl::error(GL_INVALID_OPERATION);
9207 }
9208 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009209 }
9210 catch(std::bad_alloc&)
9211 {
9212 return gl::error(GL_OUT_OF_MEMORY);
9213 }
9214}
9215
9216void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9217{
9218 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9219 location, count, value);
9220
9221 try
9222 {
9223 gl::Context *context = gl::getNonLostContext();
9224
9225 if (context)
9226 {
9227 if (context->getClientVersion() < 3)
9228 {
9229 return gl::error(GL_INVALID_OPERATION);
9230 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009231
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009232 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9233 if (!programBinary)
9234 {
9235 return gl::error(GL_INVALID_OPERATION);
9236 }
9237
9238 if (!programBinary->setUniform3uiv(location, count, value))
9239 {
9240 return gl::error(GL_INVALID_OPERATION);
9241 }
9242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009243 }
9244 catch(std::bad_alloc&)
9245 {
9246 return gl::error(GL_OUT_OF_MEMORY);
9247 }
9248}
9249
9250void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9251{
9252 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9253 location, count, value);
9254
9255 try
9256 {
9257 gl::Context *context = gl::getNonLostContext();
9258
9259 if (context)
9260 {
9261 if (context->getClientVersion() < 3)
9262 {
9263 return gl::error(GL_INVALID_OPERATION);
9264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009265
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009266 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9267 if (!programBinary)
9268 {
9269 return gl::error(GL_INVALID_OPERATION);
9270 }
9271
9272 if (!programBinary->setUniform4uiv(location, count, value))
9273 {
9274 return gl::error(GL_INVALID_OPERATION);
9275 }
9276 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009277 }
9278 catch(std::bad_alloc&)
9279 {
9280 return gl::error(GL_OUT_OF_MEMORY);
9281 }
9282}
9283
9284void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9285{
9286 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9287 buffer, drawbuffer, value);
9288
9289 try
9290 {
9291 gl::Context *context = gl::getNonLostContext();
9292
9293 if (context)
9294 {
9295 if (context->getClientVersion() < 3)
9296 {
9297 return gl::error(GL_INVALID_OPERATION);
9298 }
9299 }
9300
9301 UNIMPLEMENTED();
9302 }
9303 catch(std::bad_alloc&)
9304 {
9305 return gl::error(GL_OUT_OF_MEMORY);
9306 }
9307}
9308
9309void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
9310{
9311 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
9312 buffer, drawbuffer, value);
9313
9314 try
9315 {
9316 gl::Context *context = gl::getNonLostContext();
9317
9318 if (context)
9319 {
9320 if (context->getClientVersion() < 3)
9321 {
9322 return gl::error(GL_INVALID_OPERATION);
9323 }
9324 }
9325
9326 UNIMPLEMENTED();
9327 }
9328 catch(std::bad_alloc&)
9329 {
9330 return gl::error(GL_OUT_OF_MEMORY);
9331 }
9332}
9333
9334void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
9335{
9336 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
9337 buffer, drawbuffer, value);
9338
9339 try
9340 {
9341 gl::Context *context = gl::getNonLostContext();
9342
9343 if (context)
9344 {
9345 if (context->getClientVersion() < 3)
9346 {
9347 return gl::error(GL_INVALID_OPERATION);
9348 }
9349 }
9350
9351 UNIMPLEMENTED();
9352 }
9353 catch(std::bad_alloc&)
9354 {
9355 return gl::error(GL_OUT_OF_MEMORY);
9356 }
9357}
9358
9359void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
9360{
9361 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
9362 buffer, drawbuffer, depth, stencil);
9363
9364 try
9365 {
9366 gl::Context *context = gl::getNonLostContext();
9367
9368 if (context)
9369 {
9370 if (context->getClientVersion() < 3)
9371 {
9372 return gl::error(GL_INVALID_OPERATION);
9373 }
9374 }
9375
9376 UNIMPLEMENTED();
9377 }
9378 catch(std::bad_alloc&)
9379 {
9380 return gl::error(GL_OUT_OF_MEMORY);
9381 }
9382}
9383
9384const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
9385{
9386 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
9387
9388 try
9389 {
9390 gl::Context *context = gl::getNonLostContext();
9391
9392 if (context)
9393 {
9394 if (context->getClientVersion() < 3)
9395 {
9396 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
9397 }
9398 }
9399
9400 UNIMPLEMENTED();
9401 }
9402 catch(std::bad_alloc&)
9403 {
9404 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
9405 }
9406
9407 return NULL;
9408}
9409
9410void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
9411{
9412 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
9413 readTarget, writeTarget, readOffset, writeOffset, size);
9414
9415 try
9416 {
9417 gl::Context *context = gl::getNonLostContext();
9418
9419 if (context)
9420 {
9421 if (context->getClientVersion() < 3)
9422 {
9423 return gl::error(GL_INVALID_OPERATION);
9424 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009425
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009426 gl::Buffer *readBuffer = NULL;
9427 switch (readTarget)
9428 {
9429 case GL_ARRAY_BUFFER:
9430 readBuffer = context->getArrayBuffer();
9431 break;
9432 case GL_COPY_READ_BUFFER:
9433 readBuffer = context->getCopyReadBuffer();
9434 break;
9435 case GL_COPY_WRITE_BUFFER:
9436 readBuffer = context->getCopyWriteBuffer();
9437 break;
9438 case GL_ELEMENT_ARRAY_BUFFER:
9439 readBuffer = context->getElementArrayBuffer();
9440 break;
9441 case GL_PIXEL_PACK_BUFFER:
9442 readBuffer = context->getPixelPackBuffer();
9443 break;
9444 case GL_PIXEL_UNPACK_BUFFER:
9445 readBuffer = context->getPixelUnpackBuffer();
9446 break;
9447 case GL_TRANSFORM_FEEDBACK_BUFFER:
9448 readBuffer = context->getGenericTransformFeedbackBuffer();
9449 break;
9450 case GL_UNIFORM_BUFFER:
9451 readBuffer = context->getGenericUniformBuffer();
9452 break;
9453 default:
9454 return gl::error(GL_INVALID_ENUM);
9455 }
9456
9457 gl::Buffer *writeBuffer = NULL;
9458 switch (writeTarget)
9459 {
9460 case GL_ARRAY_BUFFER:
9461 writeBuffer = context->getArrayBuffer();
9462 break;
9463 case GL_COPY_READ_BUFFER:
9464 writeBuffer = context->getCopyReadBuffer();
9465 break;
9466 case GL_COPY_WRITE_BUFFER:
9467 writeBuffer = context->getCopyWriteBuffer();
9468 break;
9469 case GL_ELEMENT_ARRAY_BUFFER:
9470 writeBuffer = context->getElementArrayBuffer();
9471 break;
9472 case GL_PIXEL_PACK_BUFFER:
9473 writeBuffer = context->getPixelPackBuffer();
9474 break;
9475 case GL_PIXEL_UNPACK_BUFFER:
9476 writeBuffer = context->getPixelUnpackBuffer();
9477 break;
9478 case GL_TRANSFORM_FEEDBACK_BUFFER:
9479 writeBuffer = context->getGenericTransformFeedbackBuffer();
9480 break;
9481 case GL_UNIFORM_BUFFER:
9482 writeBuffer = context->getGenericUniformBuffer();
9483 break;
9484 default:
9485 return gl::error(GL_INVALID_ENUM);
9486 }
9487
9488 if (!readBuffer || !writeBuffer)
9489 {
9490 return gl::error(GL_INVALID_OPERATION);
9491 }
9492
9493 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
9494 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
9495 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
9496 {
9497 return gl::error(GL_INVALID_VALUE);
9498 }
9499
9500 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
9501 {
9502 return gl::error(GL_INVALID_VALUE);
9503 }
9504
9505 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
9506
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +00009507 // if size is zero, the copy is a successful no-op
9508 if (size > 0)
9509 {
9510 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
9511 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009512 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009513 }
9514 catch(std::bad_alloc&)
9515 {
9516 return gl::error(GL_OUT_OF_MEMORY);
9517 }
9518}
9519
9520void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
9521{
9522 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
9523 program, uniformCount, uniformNames, uniformIndices);
9524
9525 try
9526 {
9527 gl::Context *context = gl::getNonLostContext();
9528
9529 if (context)
9530 {
9531 if (context->getClientVersion() < 3)
9532 {
9533 return gl::error(GL_INVALID_OPERATION);
9534 }
9535 }
9536
9537 UNIMPLEMENTED();
9538 }
9539 catch(std::bad_alloc&)
9540 {
9541 return gl::error(GL_OUT_OF_MEMORY);
9542 }
9543}
9544
9545void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
9546{
9547 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9548 program, uniformCount, uniformIndices, pname, params);
9549
9550 try
9551 {
9552 gl::Context *context = gl::getNonLostContext();
9553
9554 if (context)
9555 {
9556 if (context->getClientVersion() < 3)
9557 {
9558 return gl::error(GL_INVALID_OPERATION);
9559 }
9560 }
9561
9562 UNIMPLEMENTED();
9563 }
9564 catch(std::bad_alloc&)
9565 {
9566 return gl::error(GL_OUT_OF_MEMORY);
9567 }
9568}
9569
9570GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
9571{
9572 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
9573
9574 try
9575 {
9576 gl::Context *context = gl::getNonLostContext();
9577
9578 if (context)
9579 {
9580 if (context->getClientVersion() < 3)
9581 {
9582 return gl::error(GL_INVALID_OPERATION, 0);
9583 }
9584 }
9585
9586 UNIMPLEMENTED();
9587 }
9588 catch(std::bad_alloc&)
9589 {
9590 return gl::error(GL_OUT_OF_MEMORY, 0);
9591 }
9592
9593 return 0;
9594}
9595
9596void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
9597{
9598 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9599 program, uniformBlockIndex, pname, params);
9600
9601 try
9602 {
9603 gl::Context *context = gl::getNonLostContext();
9604
9605 if (context)
9606 {
9607 if (context->getClientVersion() < 3)
9608 {
9609 return gl::error(GL_INVALID_OPERATION);
9610 }
9611 }
9612
9613 UNIMPLEMENTED();
9614 }
9615 catch(std::bad_alloc&)
9616 {
9617 return gl::error(GL_OUT_OF_MEMORY);
9618 }
9619}
9620
9621void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
9622{
9623 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
9624 program, uniformBlockIndex, bufSize, length, uniformBlockName);
9625
9626 try
9627 {
9628 gl::Context *context = gl::getNonLostContext();
9629
9630 if (context)
9631 {
9632 if (context->getClientVersion() < 3)
9633 {
9634 return gl::error(GL_INVALID_OPERATION);
9635 }
9636 }
9637
9638 UNIMPLEMENTED();
9639 }
9640 catch(std::bad_alloc&)
9641 {
9642 return gl::error(GL_OUT_OF_MEMORY);
9643 }
9644}
9645
9646void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
9647{
9648 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
9649 program, uniformBlockIndex, uniformBlockBinding);
9650
9651 try
9652 {
9653 gl::Context *context = gl::getNonLostContext();
9654
9655 if (context)
9656 {
9657 if (context->getClientVersion() < 3)
9658 {
9659 return gl::error(GL_INVALID_OPERATION);
9660 }
9661 }
9662
9663 UNIMPLEMENTED();
9664 }
9665 catch(std::bad_alloc&)
9666 {
9667 return gl::error(GL_OUT_OF_MEMORY);
9668 }
9669}
9670
9671void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
9672{
9673 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
9674 mode, first, count, instanceCount);
9675
9676 try
9677 {
9678 gl::Context *context = gl::getNonLostContext();
9679
9680 if (context)
9681 {
9682 if (context->getClientVersion() < 3)
9683 {
9684 return gl::error(GL_INVALID_OPERATION);
9685 }
9686 }
9687
9688 UNIMPLEMENTED();
9689 }
9690 catch(std::bad_alloc&)
9691 {
9692 return gl::error(GL_OUT_OF_MEMORY);
9693 }
9694}
9695
9696void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
9697{
9698 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
9699 mode, count, type, indices, instanceCount);
9700
9701 try
9702 {
9703 gl::Context *context = gl::getNonLostContext();
9704
9705 if (context)
9706 {
9707 if (context->getClientVersion() < 3)
9708 {
9709 return gl::error(GL_INVALID_OPERATION);
9710 }
9711 }
9712
9713 UNIMPLEMENTED();
9714 }
9715 catch(std::bad_alloc&)
9716 {
9717 return gl::error(GL_OUT_OF_MEMORY);
9718 }
9719}
9720
9721GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
9722{
9723 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
9724
9725 try
9726 {
9727 gl::Context *context = gl::getNonLostContext();
9728
9729 if (context)
9730 {
9731 if (context->getClientVersion() < 3)
9732 {
9733 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
9734 }
9735 }
9736
9737 UNIMPLEMENTED();
9738 }
9739 catch(std::bad_alloc&)
9740 {
9741 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
9742 }
9743
9744 return NULL;
9745}
9746
9747GLboolean __stdcall glIsSync(GLsync sync)
9748{
9749 EVENT("(GLsync sync = 0x%0.8p)", sync);
9750
9751 try
9752 {
9753 gl::Context *context = gl::getNonLostContext();
9754
9755 if (context)
9756 {
9757 if (context->getClientVersion() < 3)
9758 {
9759 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9760 }
9761 }
9762
9763 UNIMPLEMENTED();
9764 }
9765 catch(std::bad_alloc&)
9766 {
9767 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9768 }
9769
9770 return GL_FALSE;
9771}
9772
9773void __stdcall glDeleteSync(GLsync sync)
9774{
9775 EVENT("(GLsync sync = 0x%0.8p)", sync);
9776
9777 try
9778 {
9779 gl::Context *context = gl::getNonLostContext();
9780
9781 if (context)
9782 {
9783 if (context->getClientVersion() < 3)
9784 {
9785 return gl::error(GL_INVALID_OPERATION);
9786 }
9787 }
9788
9789 UNIMPLEMENTED();
9790 }
9791 catch(std::bad_alloc&)
9792 {
9793 return gl::error(GL_OUT_OF_MEMORY);
9794 }
9795}
9796
9797GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
9798{
9799 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
9800 sync, flags, timeout);
9801
9802 try
9803 {
9804 gl::Context *context = gl::getNonLostContext();
9805
9806 if (context)
9807 {
9808 if (context->getClientVersion() < 3)
9809 {
9810 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9811 }
9812 }
9813
9814 UNIMPLEMENTED();
9815 }
9816 catch(std::bad_alloc&)
9817 {
9818 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9819 }
9820
9821 return GL_FALSE;
9822}
9823
9824void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
9825{
9826 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
9827 sync, flags, timeout);
9828
9829 try
9830 {
9831 gl::Context *context = gl::getNonLostContext();
9832
9833 if (context)
9834 {
9835 if (context->getClientVersion() < 3)
9836 {
9837 return gl::error(GL_INVALID_OPERATION);
9838 }
9839 }
9840
9841 UNIMPLEMENTED();
9842 }
9843 catch(std::bad_alloc&)
9844 {
9845 return gl::error(GL_OUT_OF_MEMORY);
9846 }
9847}
9848
9849void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
9850{
9851 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
9852 pname, params);
9853
9854 try
9855 {
9856 gl::Context *context = gl::getNonLostContext();
9857
9858 if (context)
9859 {
9860 if (context->getClientVersion() < 3)
9861 {
9862 return gl::error(GL_INVALID_OPERATION);
9863 }
9864 }
9865
9866 UNIMPLEMENTED();
9867 }
9868 catch(std::bad_alloc&)
9869 {
9870 return gl::error(GL_OUT_OF_MEMORY);
9871 }
9872}
9873
9874void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
9875{
9876 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
9877 sync, pname, bufSize, length, values);
9878
9879 try
9880 {
9881 gl::Context *context = gl::getNonLostContext();
9882
9883 if (context)
9884 {
9885 if (context->getClientVersion() < 3)
9886 {
9887 return gl::error(GL_INVALID_OPERATION);
9888 }
9889 }
9890
9891 UNIMPLEMENTED();
9892 }
9893 catch(std::bad_alloc&)
9894 {
9895 return gl::error(GL_OUT_OF_MEMORY);
9896 }
9897}
9898
9899void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
9900{
9901 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
9902 target, index, data);
9903
9904 try
9905 {
9906 gl::Context *context = gl::getNonLostContext();
9907
9908 if (context)
9909 {
9910 if (context->getClientVersion() < 3)
9911 {
9912 return gl::error(GL_INVALID_OPERATION);
9913 }
9914 }
9915
9916 UNIMPLEMENTED();
9917 }
9918 catch(std::bad_alloc&)
9919 {
9920 return gl::error(GL_OUT_OF_MEMORY);
9921 }
9922}
9923
9924void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
9925{
9926 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
9927 target, pname, params);
9928
9929 try
9930 {
9931 gl::Context *context = gl::getNonLostContext();
9932
9933 if (context)
9934 {
9935 if (context->getClientVersion() < 3)
9936 {
9937 return gl::error(GL_INVALID_OPERATION);
9938 }
9939 }
9940
9941 UNIMPLEMENTED();
9942 }
9943 catch(std::bad_alloc&)
9944 {
9945 return gl::error(GL_OUT_OF_MEMORY);
9946 }
9947}
9948
9949void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
9950{
9951 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
9952
9953 try
9954 {
9955 gl::Context *context = gl::getNonLostContext();
9956
9957 if (context)
9958 {
9959 if (context->getClientVersion() < 3)
9960 {
9961 return gl::error(GL_INVALID_OPERATION);
9962 }
9963 }
9964
9965 UNIMPLEMENTED();
9966 }
9967 catch(std::bad_alloc&)
9968 {
9969 return gl::error(GL_OUT_OF_MEMORY);
9970 }
9971}
9972
9973void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
9974{
9975 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
9976
9977 try
9978 {
9979 gl::Context *context = gl::getNonLostContext();
9980
9981 if (context)
9982 {
9983 if (context->getClientVersion() < 3)
9984 {
9985 return gl::error(GL_INVALID_OPERATION);
9986 }
9987 }
9988
9989 UNIMPLEMENTED();
9990 }
9991 catch(std::bad_alloc&)
9992 {
9993 return gl::error(GL_OUT_OF_MEMORY);
9994 }
9995}
9996
9997GLboolean __stdcall glIsSampler(GLuint sampler)
9998{
9999 EVENT("(GLuint sampler = %u)", sampler);
10000
10001 try
10002 {
10003 gl::Context *context = gl::getNonLostContext();
10004
10005 if (context)
10006 {
10007 if (context->getClientVersion() < 3)
10008 {
10009 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10010 }
10011 }
10012
10013 UNIMPLEMENTED();
10014 }
10015 catch(std::bad_alloc&)
10016 {
10017 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10018 }
10019
10020 return GL_FALSE;
10021}
10022
10023void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10024{
10025 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10026
10027 try
10028 {
10029 gl::Context *context = gl::getNonLostContext();
10030
10031 if (context)
10032 {
10033 if (context->getClientVersion() < 3)
10034 {
10035 return gl::error(GL_INVALID_OPERATION);
10036 }
10037 }
10038
10039 UNIMPLEMENTED();
10040 }
10041 catch(std::bad_alloc&)
10042 {
10043 return gl::error(GL_OUT_OF_MEMORY);
10044 }
10045}
10046
10047void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10048{
10049 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10050
10051 try
10052 {
10053 gl::Context *context = gl::getNonLostContext();
10054
10055 if (context)
10056 {
10057 if (context->getClientVersion() < 3)
10058 {
10059 return gl::error(GL_INVALID_OPERATION);
10060 }
10061 }
10062
10063 UNIMPLEMENTED();
10064 }
10065 catch(std::bad_alloc&)
10066 {
10067 return gl::error(GL_OUT_OF_MEMORY);
10068 }
10069}
10070
10071void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10072{
10073 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10074 sampler, pname, param);
10075
10076 try
10077 {
10078 gl::Context *context = gl::getNonLostContext();
10079
10080 if (context)
10081 {
10082 if (context->getClientVersion() < 3)
10083 {
10084 return gl::error(GL_INVALID_OPERATION);
10085 }
10086 }
10087
10088 UNIMPLEMENTED();
10089 }
10090 catch(std::bad_alloc&)
10091 {
10092 return gl::error(GL_OUT_OF_MEMORY);
10093 }
10094}
10095
10096void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10097{
10098 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10099
10100 try
10101 {
10102 gl::Context *context = gl::getNonLostContext();
10103
10104 if (context)
10105 {
10106 if (context->getClientVersion() < 3)
10107 {
10108 return gl::error(GL_INVALID_OPERATION);
10109 }
10110 }
10111
10112 UNIMPLEMENTED();
10113 }
10114 catch(std::bad_alloc&)
10115 {
10116 return gl::error(GL_OUT_OF_MEMORY);
10117 }
10118}
10119
10120void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
10121{
10122 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
10123
10124 try
10125 {
10126 gl::Context *context = gl::getNonLostContext();
10127
10128 if (context)
10129 {
10130 if (context->getClientVersion() < 3)
10131 {
10132 return gl::error(GL_INVALID_OPERATION);
10133 }
10134 }
10135
10136 UNIMPLEMENTED();
10137 }
10138 catch(std::bad_alloc&)
10139 {
10140 return gl::error(GL_OUT_OF_MEMORY);
10141 }
10142}
10143
10144void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
10145{
10146 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
10147
10148 try
10149 {
10150 gl::Context *context = gl::getNonLostContext();
10151
10152 if (context)
10153 {
10154 if (context->getClientVersion() < 3)
10155 {
10156 return gl::error(GL_INVALID_OPERATION);
10157 }
10158 }
10159
10160 UNIMPLEMENTED();
10161 }
10162 catch(std::bad_alloc&)
10163 {
10164 return gl::error(GL_OUT_OF_MEMORY);
10165 }
10166}
10167
10168void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
10169{
10170 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
10171
10172 try
10173 {
10174 gl::Context *context = gl::getNonLostContext();
10175
10176 if (context)
10177 {
10178 if (context->getClientVersion() < 3)
10179 {
10180 return gl::error(GL_INVALID_OPERATION);
10181 }
10182 }
10183
10184 UNIMPLEMENTED();
10185 }
10186 catch(std::bad_alloc&)
10187 {
10188 return gl::error(GL_OUT_OF_MEMORY);
10189 }
10190}
10191
10192void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
10193{
10194 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
10195
10196 try
10197 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010198 if (index >= gl::MAX_VERTEX_ATTRIBS)
10199 {
10200 return gl::error(GL_INVALID_VALUE);
10201 }
10202
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010203 gl::Context *context = gl::getNonLostContext();
10204
10205 if (context)
10206 {
10207 if (context->getClientVersion() < 3)
10208 {
10209 return gl::error(GL_INVALID_OPERATION);
10210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010211
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010212 context->setVertexAttribDivisor(index, divisor);
10213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010214 }
10215 catch(std::bad_alloc&)
10216 {
10217 return gl::error(GL_OUT_OF_MEMORY);
10218 }
10219}
10220
10221void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
10222{
10223 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
10224
10225 try
10226 {
10227 gl::Context *context = gl::getNonLostContext();
10228
10229 if (context)
10230 {
10231 if (context->getClientVersion() < 3)
10232 {
10233 return gl::error(GL_INVALID_OPERATION);
10234 }
10235 }
10236
10237 UNIMPLEMENTED();
10238 }
10239 catch(std::bad_alloc&)
10240 {
10241 return gl::error(GL_OUT_OF_MEMORY);
10242 }
10243}
10244
10245void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
10246{
10247 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
10248
10249 try
10250 {
10251 gl::Context *context = gl::getNonLostContext();
10252
10253 if (context)
10254 {
10255 if (context->getClientVersion() < 3)
10256 {
10257 return gl::error(GL_INVALID_OPERATION);
10258 }
10259 }
10260
10261 UNIMPLEMENTED();
10262 }
10263 catch(std::bad_alloc&)
10264 {
10265 return gl::error(GL_OUT_OF_MEMORY);
10266 }
10267}
10268
10269void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
10270{
10271 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
10272
10273 try
10274 {
10275 gl::Context *context = gl::getNonLostContext();
10276
10277 if (context)
10278 {
10279 if (context->getClientVersion() < 3)
10280 {
10281 return gl::error(GL_INVALID_OPERATION);
10282 }
10283 }
10284
10285 UNIMPLEMENTED();
10286 }
10287 catch(std::bad_alloc&)
10288 {
10289 return gl::error(GL_OUT_OF_MEMORY);
10290 }
10291}
10292
10293GLboolean __stdcall glIsTransformFeedback(GLuint id)
10294{
10295 EVENT("(GLuint id = %u)", id);
10296
10297 try
10298 {
10299 gl::Context *context = gl::getNonLostContext();
10300
10301 if (context)
10302 {
10303 if (context->getClientVersion() < 3)
10304 {
10305 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10306 }
10307 }
10308
10309 UNIMPLEMENTED();
10310 }
10311 catch(std::bad_alloc&)
10312 {
10313 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10314 }
10315
10316 return GL_FALSE;
10317}
10318
10319void __stdcall glPauseTransformFeedback(void)
10320{
10321 EVENT("(void)");
10322
10323 try
10324 {
10325 gl::Context *context = gl::getNonLostContext();
10326
10327 if (context)
10328 {
10329 if (context->getClientVersion() < 3)
10330 {
10331 return gl::error(GL_INVALID_OPERATION);
10332 }
10333 }
10334
10335 UNIMPLEMENTED();
10336 }
10337 catch(std::bad_alloc&)
10338 {
10339 return gl::error(GL_OUT_OF_MEMORY);
10340 }
10341}
10342
10343void __stdcall glResumeTransformFeedback(void)
10344{
10345 EVENT("(void)");
10346
10347 try
10348 {
10349 gl::Context *context = gl::getNonLostContext();
10350
10351 if (context)
10352 {
10353 if (context->getClientVersion() < 3)
10354 {
10355 return gl::error(GL_INVALID_OPERATION);
10356 }
10357 }
10358
10359 UNIMPLEMENTED();
10360 }
10361 catch(std::bad_alloc&)
10362 {
10363 return gl::error(GL_OUT_OF_MEMORY);
10364 }
10365}
10366
10367void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
10368{
10369 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
10370 program, bufSize, length, binaryFormat, binary);
10371
10372 try
10373 {
10374 gl::Context *context = gl::getNonLostContext();
10375
10376 if (context)
10377 {
10378 if (context->getClientVersion() < 3)
10379 {
10380 return gl::error(GL_INVALID_OPERATION);
10381 }
10382 }
10383
10384 UNIMPLEMENTED();
10385 }
10386 catch(std::bad_alloc&)
10387 {
10388 return gl::error(GL_OUT_OF_MEMORY);
10389 }
10390}
10391
10392void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
10393{
10394 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
10395 program, binaryFormat, binary, length);
10396
10397 try
10398 {
10399 gl::Context *context = gl::getNonLostContext();
10400
10401 if (context)
10402 {
10403 if (context->getClientVersion() < 3)
10404 {
10405 return gl::error(GL_INVALID_OPERATION);
10406 }
10407 }
10408
10409 UNIMPLEMENTED();
10410 }
10411 catch(std::bad_alloc&)
10412 {
10413 return gl::error(GL_OUT_OF_MEMORY);
10414 }
10415}
10416
10417void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
10418{
10419 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
10420 program, pname, value);
10421
10422 try
10423 {
10424 gl::Context *context = gl::getNonLostContext();
10425
10426 if (context)
10427 {
10428 if (context->getClientVersion() < 3)
10429 {
10430 return gl::error(GL_INVALID_OPERATION);
10431 }
10432 }
10433
10434 UNIMPLEMENTED();
10435 }
10436 catch(std::bad_alloc&)
10437 {
10438 return gl::error(GL_OUT_OF_MEMORY);
10439 }
10440}
10441
10442void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
10443{
10444 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
10445 target, numAttachments, attachments);
10446
10447 try
10448 {
10449 gl::Context *context = gl::getNonLostContext();
10450
10451 if (context)
10452 {
10453 if (context->getClientVersion() < 3)
10454 {
10455 return gl::error(GL_INVALID_OPERATION);
10456 }
10457 }
10458
10459 UNIMPLEMENTED();
10460 }
10461 catch(std::bad_alloc&)
10462 {
10463 return gl::error(GL_OUT_OF_MEMORY);
10464 }
10465}
10466
10467void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
10468{
10469 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
10470 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
10471 target, numAttachments, attachments, x, y, width, height);
10472
10473 try
10474 {
10475 gl::Context *context = gl::getNonLostContext();
10476
10477 if (context)
10478 {
10479 if (context->getClientVersion() < 3)
10480 {
10481 return gl::error(GL_INVALID_OPERATION);
10482 }
10483 }
10484
10485 UNIMPLEMENTED();
10486 }
10487 catch(std::bad_alloc&)
10488 {
10489 return gl::error(GL_OUT_OF_MEMORY);
10490 }
10491}
10492
10493void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
10494{
10495 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
10496 target, levels, internalformat, width, height);
10497
10498 try
10499 {
10500 gl::Context *context = gl::getNonLostContext();
10501
10502 if (context)
10503 {
10504 if (context->getClientVersion() < 3)
10505 {
10506 return gl::error(GL_INVALID_OPERATION);
10507 }
10508 }
10509
10510 UNIMPLEMENTED();
10511 }
10512 catch(std::bad_alloc&)
10513 {
10514 return gl::error(GL_OUT_OF_MEMORY);
10515 }
10516}
10517
10518void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
10519{
10520 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
10521 "GLsizei height = %d, GLsizei depth = %d)",
10522 target, levels, internalformat, width, height, depth);
10523
10524 try
10525 {
10526 gl::Context *context = gl::getNonLostContext();
10527
10528 if (context)
10529 {
10530 if (context->getClientVersion() < 3)
10531 {
10532 return gl::error(GL_INVALID_OPERATION);
10533 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000010534 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010535 }
10536 catch(std::bad_alloc&)
10537 {
10538 return gl::error(GL_OUT_OF_MEMORY);
10539 }
10540}
10541
10542void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
10543{
10544 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
10545 "GLint* params = 0x%0.8p)",
10546 target, internalformat, pname, bufSize, params);
10547
10548 try
10549 {
10550 gl::Context *context = gl::getNonLostContext();
10551
10552 if (context)
10553 {
10554 if (context->getClientVersion() < 3)
10555 {
10556 return gl::error(GL_INVALID_OPERATION);
10557 }
10558 }
10559
10560 UNIMPLEMENTED();
10561 }
10562 catch(std::bad_alloc&)
10563 {
10564 return gl::error(GL_OUT_OF_MEMORY);
10565 }
10566}
10567
10568// Extension functions
10569
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010570void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
10571 GLbitfield mask, GLenum filter)
10572{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000010573 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010574 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
10575 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
10576 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
10577
10578 try
10579 {
10580 switch (filter)
10581 {
10582 case GL_NEAREST:
10583 break;
10584 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010585 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010586 }
10587
10588 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
10589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010590 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010591 }
10592
10593 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
10594 {
10595 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010596 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010597 }
10598
daniel@transgaming.com9d788502011-11-09 17:46:55 +000010599 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010600
10601 if (context)
10602 {
10603 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
10604 {
10605 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010606 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010607 }
10608
10609 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
10610 }
10611 }
10612 catch(std::bad_alloc&)
10613 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010614 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010615 }
10616}
10617
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000010618void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
10619 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010620{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000010621 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000010622 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000010623 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010624 target, level, internalformat, width, height, depth, border, format, type, pixels);
10625
10626 try
10627 {
10628 UNIMPLEMENTED(); // FIXME
10629 }
10630 catch(std::bad_alloc&)
10631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010632 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010633 }
10634}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010635
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010636void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
10637 GLenum *binaryFormat, void *binary)
10638{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010639 EVENT("(GLenum program = 0x%X, bufSize = %d, length = 0x%0.8p, binaryFormat = 0x%0.8p, binary = 0x%0.8p)",
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010640 program, bufSize, length, binaryFormat, binary);
10641
10642 try
10643 {
10644 gl::Context *context = gl::getNonLostContext();
10645
10646 if (context)
10647 {
10648 gl::Program *programObject = context->getProgram(program);
10649
daniel@transgaming.com716056c2012-07-24 18:38:59 +000010650 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010652 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010653 }
10654
10655 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10656
10657 if (!programBinary)
10658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010659 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010660 }
10661
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010662 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010664 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010665 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010666
10667 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010668 }
10669 }
10670 catch(std::bad_alloc&)
10671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010672 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010673 }
10674}
10675
10676void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
10677 const void *binary, GLint length)
10678{
10679 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
10680 program, binaryFormat, binary, length);
10681
10682 try
10683 {
10684 gl::Context *context = gl::getNonLostContext();
10685
10686 if (context)
10687 {
10688 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
10689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010690 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010691 }
10692
10693 gl::Program *programObject = context->getProgram(program);
10694
10695 if (!programObject)
10696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010697 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010698 }
10699
daniel@transgaming.com95d29422012-07-24 18:36:10 +000010700 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010701 }
10702 }
10703 catch(std::bad_alloc&)
10704 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010705 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010706 }
10707}
10708
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010709void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
10710{
10711 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
10712
10713 try
10714 {
10715 gl::Context *context = gl::getNonLostContext();
10716
10717 if (context)
10718 {
10719 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
10720 {
10721 return gl::error(GL_INVALID_VALUE);
10722 }
10723
10724 if (context->getDrawFramebufferHandle() == 0)
10725 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010726 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010727 {
10728 return gl::error(GL_INVALID_OPERATION);
10729 }
10730
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010731 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010732 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010733 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010734 }
10735 }
10736 else
10737 {
10738 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
10739 {
10740 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
10741 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
10742 {
10743 return gl::error(GL_INVALID_OPERATION);
10744 }
10745 }
10746 }
10747
10748 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
10749
10750 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
10751 {
10752 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
10753 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010754
10755 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
10756 {
10757 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
10758 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010759 }
10760 }
10761 catch (std::bad_alloc&)
10762 {
10763 return gl::error(GL_OUT_OF_MEMORY);
10764 }
10765}
10766
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010767__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
10768{
10769 struct Extension
10770 {
10771 const char *name;
10772 __eglMustCastToProperFunctionPointerType address;
10773 };
10774
10775 static const Extension glExtensions[] =
10776 {
10777 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000010778 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000010779 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000010780 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
10781 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
10782 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
10783 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
10784 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
10785 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
10786 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000010787 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000010788 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000010789 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
10790 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
10791 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
10792 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000010793 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
10794 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
10795 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
10796 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
10797 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
10798 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
10799 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000010800 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000010801 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
10802 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
10803 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010804 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
10805 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010806
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000010807 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010808 {
10809 if (strcmp(procname, glExtensions[ext].name) == 0)
10810 {
10811 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
10812 }
10813 }
10814
10815 return NULL;
10816}
10817
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000010818// Non-public functions used by EGL
10819
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010820bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010821{
10822 EVENT("(egl::Surface* surface = 0x%0.8p)",
10823 surface);
10824
10825 try
10826 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000010827 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010828
10829 if (context)
10830 {
10831 gl::Texture2D *textureObject = context->getTexture2D();
10832
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010833 if (textureObject->isImmutable())
10834 {
10835 return false;
10836 }
10837
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010838 if (textureObject)
10839 {
10840 textureObject->bindTexImage(surface);
10841 }
10842 }
10843 }
10844 catch(std::bad_alloc&)
10845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010846 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010847 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010848
10849 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010850}
10851
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010852}