blob: d498b92d54b0b27e69849a8fd88d80d914ae0171 [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"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000026bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000028 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000029 {
30 return false;
31 }
32
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000033 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000034 {
35 return true;
36 }
37
38 if (level == 0)
39 {
40 return true;
41 }
42
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000043 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000044 {
45 return true;
46 }
47
48 return false;
49}
50
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000051bool validCompressedImageSize(GLsizei width, GLsizei height)
52{
53 if (width != 1 && width != 2 && width % 4 != 0)
54 {
55 return false;
56 }
57
58 if (height != 1 && height != 2 && height % 4 != 0)
59 {
60 return false;
61 }
62
63 return true;
64}
65
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066// Verify that format/type are one of the combinations from table 3.4.
67bool checkTextureFormatType(GLenum format, GLenum type)
68{
69 // validate <format> by itself (used as secondary key below)
70 switch (format)
71 {
72 case GL_RGBA:
73 case GL_BGRA_EXT:
74 case GL_RGB:
75 case GL_ALPHA:
76 case GL_LUMINANCE:
77 case GL_LUMINANCE_ALPHA:
78 case GL_DEPTH_COMPONENT:
79 case GL_DEPTH_STENCIL_OES:
80 break;
81 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000082 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000083 }
84
85 // invalid <type> -> sets INVALID_ENUM
86 // invalid <format>+<type> combination -> sets INVALID_OPERATION
87 switch (type)
88 {
89 case GL_UNSIGNED_BYTE:
90 switch (format)
91 {
92 case GL_RGBA:
93 case GL_BGRA_EXT:
94 case GL_RGB:
95 case GL_ALPHA:
96 case GL_LUMINANCE:
97 case GL_LUMINANCE_ALPHA:
98 return true;
99 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000100 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000101 }
102
103 case GL_FLOAT:
104 case GL_HALF_FLOAT_OES:
105 switch (format)
106 {
107 case GL_RGBA:
108 case GL_RGB:
109 case GL_ALPHA:
110 case GL_LUMINANCE:
111 case GL_LUMINANCE_ALPHA:
112 return true;
113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000114 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000115 }
116
117 case GL_UNSIGNED_SHORT_4_4_4_4:
118 case GL_UNSIGNED_SHORT_5_5_5_1:
119 switch (format)
120 {
121 case GL_RGBA:
122 return true;
123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000124 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000125 }
126
127 case GL_UNSIGNED_SHORT_5_6_5:
128 switch (format)
129 {
130 case GL_RGB:
131 return true;
132 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000134 }
135
136 case GL_UNSIGNED_SHORT:
137 case GL_UNSIGNED_INT:
138 switch (format)
139 {
140 case GL_DEPTH_COMPONENT:
141 return true;
142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000143 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000144 }
145
146 case GL_UNSIGNED_INT_24_8_OES:
147 switch (format)
148 {
149 case GL_DEPTH_STENCIL_OES:
150 return true;
151 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000152 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000153 }
154
155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000156 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000157 }
158}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000160bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000161 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000162 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000163{
164 if (!texture)
165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000166 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000167 }
168
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000169 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000172 }
173
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000174 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000175 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000176 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000177 if (internalformat != texture->getInternalFormat(level))
178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000179 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000180 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000181 }
182
183 if (compressed)
184 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000185 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
186 (height % 4 != 0 && height != texture->getHeight(0)))
187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000188 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000189 }
190 }
191
192 if (xoffset + width > texture->getWidth(level) ||
193 yoffset + height > texture->getHeight(level))
194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
198 return true;
199}
200
201bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000202 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000203 gl::TextureCubeMap *texture)
204{
205 if (!texture)
206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000207 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000208 }
209
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000210 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000213 }
214
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000215 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000216 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000217 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000218 if (internalformat != texture->getInternalFormat(target, level))
219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000220 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000221 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000222 }
223
224 if (compressed)
225 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000226 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
227 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000229 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000230 }
231 }
232
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000233 if (xoffset + width > texture->getWidth(target, level) ||
234 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000236 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000237 }
238
239 return true;
240}
241
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000242bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
243 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
244 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
245{
246 if (!validImageSize(context, level, width, height, 1))
247 {
248 return gl::error(GL_INVALID_VALUE, false);
249 }
250
251 if (isCompressed && !validCompressedImageSize(width, height))
252 {
253 return gl::error(GL_INVALID_OPERATION, false);
254 }
255
256 if (level < 0 || xoffset < 0 ||
257 std::numeric_limits<GLsizei>::max() - xoffset < width ||
258 std::numeric_limits<GLsizei>::max() - yoffset < height)
259 {
260 return gl::error(GL_INVALID_VALUE, false);
261 }
262
263 if (!isSubImage && !isCompressed && internalformat != GLint(format))
264 {
265 return gl::error(GL_INVALID_OPERATION, false);
266 }
267
268 gl::Texture *texture = NULL;
269 bool textureCompressed = false;
270 GLenum textureInternalFormat = GL_NONE;
271 GLint textureLevelWidth = 0;
272 GLint textureLevelHeight = 0;
273 switch (target)
274 {
275 case GL_TEXTURE_2D:
276 {
277 if (width > (context->getMaximum2DTextureDimension() >> level) ||
278 height > (context->getMaximum2DTextureDimension() >> level))
279 {
280 return gl::error(GL_INVALID_VALUE, false);
281 }
282
283 gl::Texture2D *tex2d = context->getTexture2D();
284 if (tex2d)
285 {
286 textureCompressed = tex2d->isCompressed(level);
287 textureInternalFormat = tex2d->getInternalFormat(level);
288 textureLevelWidth = tex2d->getWidth(level);
289 textureLevelHeight = tex2d->getHeight(level);
290 texture = tex2d;
291 }
292
293 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
294 level, format, type, tex2d))
295 {
296 return false;
297 }
298
299 texture = tex2d;
300 }
301 break;
302
303 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
304 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
305 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
309 {
310 if (!isSubImage && width != height)
311 {
312 return gl::error(GL_INVALID_VALUE, false);
313 }
314
315 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
316 height > (context->getMaximumCubeTextureDimension() >> level))
317 {
318 return gl::error(GL_INVALID_VALUE, false);
319 }
320
321 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
322 if (texCube)
323 {
324 textureCompressed = texCube->isCompressed(target, level);
325 textureInternalFormat = texCube->getInternalFormat(target, level);
326 textureLevelWidth = texCube->getWidth(target, level);
327 textureLevelHeight = texCube->getHeight(target, level);
328 texture = texCube;
329 }
330
331 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
332 target, level, format, type, texCube))
333 {
334 return false;
335 }
336 }
337 break;
338
339 default:
340 return gl::error(GL_INVALID_ENUM, false);
341 }
342
343 if (!texture)
344 {
345 return gl::error(GL_INVALID_OPERATION, false);
346 }
347
348 if (!isSubImage && texture->isImmutable())
349 {
350 return gl::error(GL_INVALID_OPERATION, false);
351 }
352
353 // Verify zero border
354 if (border != 0)
355 {
356 return gl::error(GL_INVALID_VALUE, false);
357 }
358
359 // Verify texture is not requesting more mip levels than are available.
360 if (level > context->getMaximumTextureLevel())
361 {
362 return gl::error(GL_INVALID_VALUE, false);
363 }
364
365 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
366 if (isCompressed)
367 {
368 switch (actualInternalFormat)
369 {
370 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
371 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
372 if (!context->supportsDXT1Textures())
373 {
374 return gl::error(GL_INVALID_ENUM, false);
375 }
376 break;
377 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
378 if (!context->supportsDXT3Textures())
379 {
380 return gl::error(GL_INVALID_ENUM, false);
381 }
382 break;
383 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
384 if (!context->supportsDXT5Textures())
385 {
386 return gl::error(GL_INVALID_ENUM, false);
387 }
388 break;
389 default:
390 return gl::error(GL_INVALID_ENUM, false);
391 }
392 }
393 else
394 {
395 // validate <type> by itself (used as secondary key below)
396 switch (type)
397 {
398 case GL_UNSIGNED_BYTE:
399 case GL_UNSIGNED_SHORT_5_6_5:
400 case GL_UNSIGNED_SHORT_4_4_4_4:
401 case GL_UNSIGNED_SHORT_5_5_5_1:
402 case GL_UNSIGNED_SHORT:
403 case GL_UNSIGNED_INT:
404 case GL_UNSIGNED_INT_24_8_OES:
405 case GL_HALF_FLOAT_OES:
406 case GL_FLOAT:
407 break;
408 default:
409 return gl::error(GL_INVALID_ENUM, false);
410 }
411
412 // validate <format> + <type> combinations
413 // - invalid <format> -> sets INVALID_ENUM
414 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
415 switch (format)
416 {
417 case GL_ALPHA:
418 case GL_LUMINANCE:
419 case GL_LUMINANCE_ALPHA:
420 switch (type)
421 {
422 case GL_UNSIGNED_BYTE:
423 case GL_FLOAT:
424 case GL_HALF_FLOAT_OES:
425 break;
426 default:
427 return gl::error(GL_INVALID_OPERATION, false);
428 }
429 break;
430 case GL_RGB:
431 switch (type)
432 {
433 case GL_UNSIGNED_BYTE:
434 case GL_UNSIGNED_SHORT_5_6_5:
435 case GL_FLOAT:
436 case GL_HALF_FLOAT_OES:
437 break;
438 default:
439 return gl::error(GL_INVALID_OPERATION, false);
440 }
441 break;
442 case GL_RGBA:
443 switch (type)
444 {
445 case GL_UNSIGNED_BYTE:
446 case GL_UNSIGNED_SHORT_4_4_4_4:
447 case GL_UNSIGNED_SHORT_5_5_5_1:
448 case GL_FLOAT:
449 case GL_HALF_FLOAT_OES:
450 break;
451 default:
452 return gl::error(GL_INVALID_OPERATION, false);
453 }
454 break;
455 case GL_BGRA_EXT:
456 switch (type)
457 {
458 case GL_UNSIGNED_BYTE:
459 break;
460 default:
461 return gl::error(GL_INVALID_OPERATION, false);
462 }
463 break;
464 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
465 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
466 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
467 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
468 break;
469 case GL_DEPTH_COMPONENT:
470 switch (type)
471 {
472 case GL_UNSIGNED_SHORT:
473 case GL_UNSIGNED_INT:
474 break;
475 default:
476 return gl::error(GL_INVALID_OPERATION, false);
477 }
478 break;
479 case GL_DEPTH_STENCIL_OES:
480 switch (type)
481 {
482 case GL_UNSIGNED_INT_24_8_OES:
483 break;
484 default:
485 return gl::error(GL_INVALID_OPERATION, false);
486 }
487 break;
488 default:
489 return gl::error(GL_INVALID_ENUM, false);
490 }
491
492 switch (format)
493 {
494 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
495 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
496 if (context->supportsDXT1Textures())
497 {
498 return gl::error(GL_INVALID_OPERATION, false);
499 }
500 else
501 {
502 return gl::error(GL_INVALID_ENUM, false);
503 }
504 break;
505 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
506 if (context->supportsDXT3Textures())
507 {
508 return gl::error(GL_INVALID_OPERATION, false);
509 }
510 else
511 {
512 return gl::error(GL_INVALID_ENUM, false);
513 }
514 break;
515 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
516 if (context->supportsDXT5Textures())
517 {
518 return gl::error(GL_INVALID_OPERATION, false);
519 }
520 else
521 {
522 return gl::error(GL_INVALID_ENUM, false);
523 }
524 break;
525 case GL_DEPTH_COMPONENT:
526 case GL_DEPTH_STENCIL_OES:
527 if (!context->supportsDepthTextures())
528 {
529 return gl::error(GL_INVALID_VALUE, false);
530 }
531 if (target != GL_TEXTURE_2D)
532 {
533 return gl::error(GL_INVALID_OPERATION, false);
534 }
535 // OES_depth_texture supports loading depth data and multiple levels,
536 // but ANGLE_depth_texture does not
537 if (pixels != NULL || level != 0)
538 {
539 return gl::error(GL_INVALID_OPERATION, false);
540 }
541 break;
542 default:
543 break;
544 }
545
546 if (type == GL_FLOAT)
547 {
548 if (!context->supportsFloat32Textures())
549 {
550 return gl::error(GL_INVALID_ENUM, false);
551 }
552 }
553 else if (type == GL_HALF_FLOAT_OES)
554 {
555 if (!context->supportsFloat16Textures())
556 {
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559 }
560 }
561
562 return true;
563}
564
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000565bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
566 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
567 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000568{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000569 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000570 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000571 {
572 return gl::error(GL_INVALID_VALUE, false);
573 }
574
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000575 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000576 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000577 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000578 }
579
580 // Verify zero border
581 if (border != 0)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 // Validate dimensions based on Context limits and validate the texture
587 if (level > context->getMaximumTextureLevel())
588 {
589 return gl::error(GL_INVALID_VALUE, false);
590 }
591
592 gl::Texture *texture = NULL;
593 bool textureCompressed = false;
594 GLenum textureInternalFormat = GL_NONE;
595 GLint textureLevelWidth = 0;
596 GLint textureLevelHeight = 0;
597 GLint textureLevelDepth = 0;
598 switch (target)
599 {
600 case GL_TEXTURE_2D:
601 {
602 if (width > (context->getMaximum2DTextureDimension() >> level) ||
603 height > (context->getMaximum2DTextureDimension() >> level))
604 {
605 return gl::error(GL_INVALID_VALUE, false);
606 }
607
608 gl::Texture2D *texture2d = context->getTexture2D();
609 if (texture2d)
610 {
611 textureCompressed = texture2d->isCompressed(level);
612 textureInternalFormat = texture2d->getInternalFormat(level);
613 textureLevelWidth = texture2d->getWidth(level);
614 textureLevelHeight = texture2d->getHeight(level);
615 textureLevelDepth = 1;
616 texture = texture2d;
617 }
618 }
619 break;
620
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
627 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000628 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000629 {
630 return gl::error(GL_INVALID_VALUE, false);
631 }
632
633 if (width > (context->getMaximumCubeTextureDimension() >> level))
634 {
635 return gl::error(GL_INVALID_VALUE, false);
636 }
637
638 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
639 if (textureCube)
640 {
641 textureCompressed = textureCube->isCompressed(target, level);
642 textureInternalFormat = textureCube->getInternalFormat(target, level);
643 textureLevelWidth = textureCube->getWidth(target, level);
644 textureLevelHeight = textureCube->getHeight(target, level);
645 textureLevelDepth = 1;
646 texture = textureCube;
647 }
648 }
649 break;
650
651 case GL_TEXTURE_3D:
652 {
653 if (width > (context->getMaximum3DTextureDimension() >> level) ||
654 height > (context->getMaximum3DTextureDimension() >> level) ||
655 depth > (context->getMaximum3DTextureDimension() >> level))
656 {
657 return gl::error(GL_INVALID_VALUE, false);
658 }
659
660 gl::Texture3D *texture3d = context->getTexture3D();
661 if (texture3d)
662 {
663 textureCompressed = texture3d->isCompressed(level);
664 textureInternalFormat = texture3d->getInternalFormat(level);
665 textureLevelWidth = texture3d->getWidth(level);
666 textureLevelHeight = texture3d->getHeight(level);
667 textureLevelDepth = texture3d->getDepth(level);
668 texture = texture3d;
669 }
670 }
671 break;
672
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000673 case GL_TEXTURE_2D_ARRAY:
674 {
675 if (width > (context->getMaximum2DTextureDimension() >> level) ||
676 height > (context->getMaximum2DTextureDimension() >> level) ||
677 depth > (context->getMaximum2DArrayTextureLayers() >> level))
678 {
679 return gl::error(GL_INVALID_VALUE, false);
680 }
681
682 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
683 if (texture2darray)
684 {
685 textureCompressed = texture2darray->isCompressed(level);
686 textureInternalFormat = texture2darray->getInternalFormat(level);
687 textureLevelWidth = texture2darray->getWidth(level);
688 textureLevelHeight = texture2darray->getHeight(level);
689 textureLevelDepth = texture2darray->getDepth(level);
690 texture = texture2darray;
691 }
692 }
693 break;
694
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000695 default:
696 return gl::error(GL_INVALID_ENUM, false);
697 }
698
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000699 if (!texture)
700 {
701 return gl::error(GL_INVALID_OPERATION, false);
702 }
703
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000704 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000705 {
706 return gl::error(GL_INVALID_OPERATION, false);
707 }
708
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000709 // Validate texture formats
710 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
711 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000712 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000713 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000714 {
715 return gl::error(GL_INVALID_ENUM, false);
716 }
717
718 if (target == GL_TEXTURE_3D)
719 {
720 return gl::error(GL_INVALID_OPERATION, false);
721 }
722 }
723 else
724 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000725 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
726 !gl::IsValidFormat(format, context->getClientVersion()) ||
727 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000728 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000729 return gl::error(GL_INVALID_ENUM, false);
730 }
731
732 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
733 {
734 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000735 }
736
737 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
738 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000739 {
740 return gl::error(GL_INVALID_OPERATION, false);
741 }
742 }
743
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000744 // Validate sub image parameters
745 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000746 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000747 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000748 {
749 return gl::error(GL_INVALID_OPERATION, false);
750 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000751
752 if (format != GL_NONE)
753 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000754 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000755 if (internalformat != textureInternalFormat)
756 {
757 return gl::error(GL_INVALID_OPERATION, false);
758 }
759 }
760
761 if (isCompressed)
762 {
763 if ((width % 4 != 0 && width != textureLevelWidth) ||
764 (height % 4 != 0 && height != textureLevelHeight))
765 {
766 return gl::error(GL_INVALID_OPERATION, false);
767 }
768 }
769
770 if (width == 0 || height == 0 || depth == 0)
771 {
772 return false;
773 }
774
775 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
776 {
777 return gl::error(GL_INVALID_VALUE, false);
778 }
779
780 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
781 std::numeric_limits<GLsizei>::max() - yoffset < height ||
782 std::numeric_limits<GLsizei>::max() - zoffset < depth)
783 {
784 return gl::error(GL_INVALID_VALUE, false);
785 }
786
787 if (xoffset + width > textureLevelWidth ||
788 yoffset + height > textureLevelHeight ||
789 zoffset + depth > textureLevelDepth)
790 {
791 return gl::error(GL_INVALID_VALUE, false);
792 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000793 }
794
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000795 return true;
796}
797
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000798
799bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
800 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
801 GLint border)
802{
803 if (!gl::IsInternalTextureTarget(target))
804 {
805 return gl::error(GL_INVALID_ENUM, false);
806 }
807
808 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
809 {
810 return gl::error(GL_INVALID_VALUE, false);
811 }
812
813 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
814 {
815 return gl::error(GL_INVALID_VALUE, false);
816 }
817
818 if (width == 0 || height == 0)
819 {
820 return false;
821 }
822
823 // Verify zero border
824 if (border != 0)
825 {
826 return gl::error(GL_INVALID_VALUE, false);
827 }
828
829 // Validate dimensions based on Context limits and validate the texture
830 if (level > context->getMaximumTextureLevel())
831 {
832 return gl::error(GL_INVALID_VALUE, false);
833 }
834
835 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
836
837 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
838 {
839 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
840 }
841
842 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
843 {
844 return gl::error(GL_INVALID_OPERATION, false);
845 }
846
847 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
848 gl::Texture *texture = NULL;
849 GLenum textureFormat = GL_RGBA;
850
851 switch (target)
852 {
853 case GL_TEXTURE_2D:
854 {
855 if (width > (context->getMaximum2DTextureDimension() >> level) ||
856 height > (context->getMaximum2DTextureDimension() >> level))
857 {
858 return gl::error(GL_INVALID_VALUE, false);
859 }
860
861 gl::Texture2D *tex2d = context->getTexture2D();
862 if (tex2d)
863 {
864 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
865 {
866 return false; // error already registered by validateSubImageParams
867 }
868 texture = tex2d;
869 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
870 }
871 }
872 break;
873
874 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
875 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
876 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
878 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
879 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
880 {
881 if (!isSubImage && width != height)
882 {
883 return gl::error(GL_INVALID_VALUE, false);
884 }
885
886 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
887 height > (context->getMaximumCubeTextureDimension() >> level))
888 {
889 return gl::error(GL_INVALID_VALUE, false);
890 }
891
892 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
893 if (texcube)
894 {
895 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
896 {
897 return false; // error already registered by validateSubImageParams
898 }
899 texture = texcube;
900 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
901 }
902 }
903 break;
904
905 default:
906 return gl::error(GL_INVALID_ENUM, false);
907 }
908
909 if (!texture)
910 {
911 return gl::error(GL_INVALID_OPERATION, false);
912 }
913
914 if (texture->isImmutable() && !isSubImage)
915 {
916 return gl::error(GL_INVALID_OPERATION, false);
917 }
918
919
920 // [OpenGL ES 2.0.24] table 3.9
921 if (isSubImage)
922 {
923 switch (textureFormat)
924 {
925 case GL_ALPHA:
926 if (colorbufferFormat != GL_ALPHA8_EXT &&
927 colorbufferFormat != GL_RGBA4 &&
928 colorbufferFormat != GL_RGB5_A1 &&
929 colorbufferFormat != GL_RGBA8_OES)
930 {
931 return gl::error(GL_INVALID_OPERATION, false);
932 }
933 break;
934 case GL_LUMINANCE:
935 case GL_RGB:
936 if (colorbufferFormat != GL_RGB565 &&
937 colorbufferFormat != GL_RGB8_OES &&
938 colorbufferFormat != GL_RGBA4 &&
939 colorbufferFormat != GL_RGB5_A1 &&
940 colorbufferFormat != GL_RGBA8_OES)
941 {
942 return gl::error(GL_INVALID_OPERATION, false);
943 }
944 break;
945 case GL_LUMINANCE_ALPHA:
946 case GL_RGBA:
947 if (colorbufferFormat != GL_RGBA4 &&
948 colorbufferFormat != GL_RGB5_A1 &&
949 colorbufferFormat != GL_RGBA8_OES)
950 {
951 return gl::error(GL_INVALID_OPERATION, false);
952 }
953 break;
954 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
956 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
957 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
958 return gl::error(GL_INVALID_OPERATION, false);
959 case GL_DEPTH_COMPONENT:
960 case GL_DEPTH_STENCIL_OES:
961 return gl::error(GL_INVALID_OPERATION, false);
962 default:
963 return gl::error(GL_INVALID_OPERATION, false);
964 }
965 }
966 else
967 {
968 switch (internalformat)
969 {
970 case GL_ALPHA:
971 if (colorbufferFormat != GL_ALPHA8_EXT &&
972 colorbufferFormat != GL_RGBA4 &&
973 colorbufferFormat != GL_RGB5_A1 &&
974 colorbufferFormat != GL_BGRA8_EXT &&
975 colorbufferFormat != GL_RGBA8_OES)
976 {
977 return gl::error(GL_INVALID_OPERATION, false);
978 }
979 break;
980 case GL_LUMINANCE:
981 case GL_RGB:
982 if (colorbufferFormat != GL_RGB565 &&
983 colorbufferFormat != GL_RGB8_OES &&
984 colorbufferFormat != GL_RGBA4 &&
985 colorbufferFormat != GL_RGB5_A1 &&
986 colorbufferFormat != GL_BGRA8_EXT &&
987 colorbufferFormat != GL_RGBA8_OES)
988 {
989 return gl::error(GL_INVALID_OPERATION, false);
990 }
991 break;
992 case GL_LUMINANCE_ALPHA:
993 case GL_RGBA:
994 if (colorbufferFormat != GL_RGBA4 &&
995 colorbufferFormat != GL_RGB5_A1 &&
996 colorbufferFormat != GL_BGRA8_EXT &&
997 colorbufferFormat != GL_RGBA8_OES)
998 {
999 return gl::error(GL_INVALID_OPERATION, false);
1000 }
1001 break;
1002 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1003 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1004 if (context->supportsDXT1Textures())
1005 {
1006 return gl::error(GL_INVALID_OPERATION, false);
1007 }
1008 else
1009 {
1010 return gl::error(GL_INVALID_ENUM, false);
1011 }
1012 break;
1013 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1014 if (context->supportsDXT3Textures())
1015 {
1016 return gl::error(GL_INVALID_OPERATION, false);
1017 }
1018 else
1019 {
1020 return gl::error(GL_INVALID_ENUM, false);
1021 }
1022 break;
1023 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1024 if (context->supportsDXT5Textures())
1025 {
1026 return gl::error(GL_INVALID_OPERATION, false);
1027 }
1028 else
1029 {
1030 return gl::error(GL_INVALID_ENUM, false);
1031 }
1032 break;
1033 case GL_DEPTH_COMPONENT:
1034 case GL_DEPTH_COMPONENT16:
1035 case GL_DEPTH_COMPONENT32_OES:
1036 case GL_DEPTH_STENCIL_OES:
1037 case GL_DEPTH24_STENCIL8_OES:
1038 if (context->supportsDepthTextures())
1039 {
1040 return gl::error(GL_INVALID_OPERATION, false);
1041 }
1042 else
1043 {
1044 return gl::error(GL_INVALID_ENUM, false);
1045 }
1046 default:
1047 return gl::error(GL_INVALID_ENUM, false);
1048 }
1049 }
1050
1051 return true;
1052}
1053
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001054bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1055 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1056 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001057{
1058 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001059 {
1060 return gl::error(GL_INVALID_VALUE, false);
1061 }
1062
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001063 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1064 {
1065 return gl::error(GL_INVALID_VALUE, false);
1066 }
1067
1068 if (width == 0 || height == 0)
1069 {
1070 return false;
1071 }
1072
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001073 if (border != 0)
1074 {
1075 return gl::error(GL_INVALID_VALUE, false);
1076 }
1077
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001078 if (level > context->getMaximumTextureLevel())
1079 {
1080 return gl::error(GL_INVALID_VALUE, false);
1081 }
1082
1083 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1084
1085 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1086 {
1087 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1088 }
1089
1090 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1091 {
1092 return gl::error(GL_INVALID_OPERATION, false);
1093 }
1094
1095 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001096 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001097 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001098 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001099 bool textureCompressed = false;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001100 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001101 GLint textureLevelWidth = 0;
1102 GLint textureLevelHeight = 0;
1103 GLint textureLevelDepth = 0;
1104 switch (target)
1105 {
1106 case GL_TEXTURE_2D:
1107 {
1108 gl::Texture2D *texture2d = context->getTexture2D();
1109 if (texture2d)
1110 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001111 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001112 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001113 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001114 textureLevelWidth = texture2d->getWidth(level);
1115 textureLevelHeight = texture2d->getHeight(level);
1116 textureLevelDepth = 1;
1117 texture = texture2d;
1118 }
1119 }
1120 break;
1121
1122 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1124 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1126 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1127 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1128 {
1129 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1130 if (textureCube)
1131 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001132 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001133 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001134 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001135 textureLevelWidth = textureCube->getWidth(target, level);
1136 textureLevelHeight = textureCube->getHeight(target, level);
1137 textureLevelDepth = 1;
1138 texture = textureCube;
1139 }
1140 }
1141 break;
1142
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001143 case GL_TEXTURE_2D_ARRAY:
1144 {
1145 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1146 if (texture2dArray)
1147 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001148 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001149 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001150 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001151 textureLevelWidth = texture2dArray->getWidth(level);
1152 textureLevelHeight = texture2dArray->getHeight(level);
1153 textureLevelDepth = texture2dArray->getDepth(level);
1154 texture = texture2dArray;
1155 }
1156 }
1157 break;
1158
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001159 case GL_TEXTURE_3D:
1160 {
1161 gl::Texture3D *texture3d = context->getTexture3D();
1162 if (texture3d)
1163 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001164 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001165 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001166 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001167 textureLevelWidth = texture3d->getWidth(level);
1168 textureLevelHeight = texture3d->getHeight(level);
1169 textureLevelDepth = texture3d->getDepth(level);
1170 texture = texture3d;
1171 }
1172 }
1173 break;
1174
1175 default:
1176 return gl::error(GL_INVALID_ENUM, false);
1177 }
1178
1179 if (!texture)
1180 {
1181 return gl::error(GL_INVALID_OPERATION, false);
1182 }
1183
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001184 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001185 {
1186 return gl::error(GL_INVALID_OPERATION, false);
1187 }
1188
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001189 if (textureIsDepth)
1190 {
1191 return gl::error(GL_INVALID_OPERATION, false);
1192 }
1193
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001194 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001195 {
1196 if ((width % 4 != 0 && width != textureLevelWidth) ||
1197 (height % 4 != 0 && height != textureLevelHeight))
1198 {
1199 return gl::error(GL_INVALID_OPERATION, false);
1200 }
1201 }
1202
Geoff Langa4d13322013-06-05 14:57:51 -04001203 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001204 {
Geoff Langa4d13322013-06-05 14:57:51 -04001205 if (xoffset + width > textureLevelWidth ||
1206 yoffset + height > textureLevelHeight ||
1207 zoffset >= textureLevelDepth)
1208 {
1209 return gl::error(GL_INVALID_VALUE, false);
1210 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001211
Geoff Langa4d13322013-06-05 14:57:51 -04001212 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1213 context->getClientVersion()))
1214 {
1215 return gl::error(GL_INVALID_OPERATION, false);
1216 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001217 }
1218
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001219 return true;
1220}
1221
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001222bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1223 GLsizei width, GLsizei height)
1224{
1225 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1226 {
1227 return gl::error(GL_INVALID_ENUM, false);
1228 }
1229
1230 if (width < 1 || height < 1 || levels < 1)
1231 {
1232 return gl::error(GL_INVALID_VALUE, false);
1233 }
1234
1235 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1236 {
1237 return gl::error(GL_INVALID_VALUE, false);
1238 }
1239
1240 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1241 {
1242 return gl::error(GL_INVALID_OPERATION, false);
1243 }
1244
1245 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1246 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1247
1248 if (format == GL_NONE || type == GL_NONE)
1249 {
1250 return gl::error(GL_INVALID_ENUM, false);
1251 }
1252
1253 switch (target)
1254 {
1255 case GL_TEXTURE_2D:
1256 if (width > context->getMaximum2DTextureDimension() ||
1257 height > context->getMaximum2DTextureDimension())
1258 {
1259 return gl::error(GL_INVALID_VALUE, false);
1260 }
1261 break;
1262 case GL_TEXTURE_CUBE_MAP:
1263 if (width > context->getMaximumCubeTextureDimension() ||
1264 height > context->getMaximumCubeTextureDimension())
1265 {
1266 return gl::error(GL_INVALID_VALUE, false);
1267 }
1268 break;
1269 default:
1270 return gl::error(GL_INVALID_ENUM, false);
1271 }
1272
1273 if (levels != 1 && !context->supportsNonPower2Texture())
1274 {
1275 if (!gl::isPow2(width) || !gl::isPow2(height))
1276 {
1277 return gl::error(GL_INVALID_OPERATION, false);
1278 }
1279 }
1280
1281 switch (internalformat)
1282 {
1283 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1284 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1285 if (!context->supportsDXT1Textures())
1286 {
1287 return gl::error(GL_INVALID_ENUM, false);
1288 }
1289 break;
1290 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1291 if (!context->supportsDXT3Textures())
1292 {
1293 return gl::error(GL_INVALID_ENUM, false);
1294 }
1295 break;
1296 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1297 if (!context->supportsDXT5Textures())
1298 {
1299 return gl::error(GL_INVALID_ENUM, false);
1300 }
1301 break;
1302 case GL_RGBA32F_EXT:
1303 case GL_RGB32F_EXT:
1304 case GL_ALPHA32F_EXT:
1305 case GL_LUMINANCE32F_EXT:
1306 case GL_LUMINANCE_ALPHA32F_EXT:
1307 if (!context->supportsFloat32Textures())
1308 {
1309 return gl::error(GL_INVALID_ENUM, false);
1310 }
1311 break;
1312 case GL_RGBA16F_EXT:
1313 case GL_RGB16F_EXT:
1314 case GL_ALPHA16F_EXT:
1315 case GL_LUMINANCE16F_EXT:
1316 case GL_LUMINANCE_ALPHA16F_EXT:
1317 if (!context->supportsFloat16Textures())
1318 {
1319 return gl::error(GL_INVALID_ENUM, false);
1320 }
1321 break;
1322 case GL_DEPTH_COMPONENT16:
1323 case GL_DEPTH_COMPONENT32_OES:
1324 case GL_DEPTH24_STENCIL8_OES:
1325 if (!context->supportsDepthTextures())
1326 {
1327 return gl::error(GL_INVALID_ENUM, false);
1328 }
1329 if (target != GL_TEXTURE_2D)
1330 {
1331 return gl::error(GL_INVALID_OPERATION, false);
1332 }
1333 // ANGLE_depth_texture only supports 1-level textures
1334 if (levels != 1)
1335 {
1336 return gl::error(GL_INVALID_OPERATION, false);
1337 }
1338 break;
1339 default:
1340 break;
1341 }
1342
1343 gl::Texture *texture = NULL;
1344 switch(target)
1345 {
1346 case GL_TEXTURE_2D:
1347 texture = context->getTexture2D();
1348 break;
1349 case GL_TEXTURE_CUBE_MAP:
1350 texture = context->getTextureCubeMap();
1351 break;
1352 default:
1353 UNREACHABLE();
1354 }
1355
1356 if (!texture || texture->id() == 0)
1357 {
1358 return gl::error(GL_INVALID_OPERATION, false);
1359 }
1360
1361 if (texture->isImmutable())
1362 {
1363 return gl::error(GL_INVALID_OPERATION, false);
1364 }
1365
1366 return true;
1367}
1368
1369bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1370 GLsizei width, GLsizei height, GLsizei depth)
1371{
1372 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1373 {
1374 return gl::error(GL_INVALID_VALUE, false);
1375 }
1376
1377 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1378 {
1379 return gl::error(GL_INVALID_OPERATION, false);
1380 }
1381
1382 gl::Texture *texture = NULL;
1383 switch (target)
1384 {
1385 case GL_TEXTURE_2D:
1386 {
1387 texture = context->getTexture2D();
1388
1389 if (width > (context->getMaximum2DTextureDimension()) ||
1390 height > (context->getMaximum2DTextureDimension()))
1391 {
1392 return gl::error(GL_INVALID_VALUE, false);
1393 }
1394 }
1395 break;
1396
1397 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1399 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1401 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1402 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1403 {
1404 texture = context->getTextureCubeMap();
1405
1406 if (width != height)
1407 {
1408 return gl::error(GL_INVALID_VALUE, false);
1409 }
1410
1411 if (width > (context->getMaximumCubeTextureDimension()))
1412 {
1413 return gl::error(GL_INVALID_VALUE, false);
1414 }
1415 }
1416 break;
1417
1418 case GL_TEXTURE_3D:
1419 {
1420 texture = context->getTexture3D();
1421
1422 if (width > (context->getMaximum3DTextureDimension()) ||
1423 height > (context->getMaximum3DTextureDimension()) ||
1424 depth > (context->getMaximum3DTextureDimension()))
1425 {
1426 return gl::error(GL_INVALID_VALUE, false);
1427 }
1428 }
1429 break;
1430
1431 case GL_TEXTURE_2D_ARRAY:
1432 {
1433 texture = context->getTexture2DArray();
1434
1435 if (width > (context->getMaximum2DTextureDimension()) ||
1436 height > (context->getMaximum2DTextureDimension()) ||
1437 depth > (context->getMaximum2DArrayTextureLayers()))
1438 {
1439 return gl::error(GL_INVALID_VALUE, false);
1440 }
1441 }
1442 break;
1443
1444 default:
1445 return gl::error(GL_INVALID_ENUM, false);
1446 }
1447
1448 if (!texture || texture->id() == 0)
1449 {
1450 return gl::error(GL_INVALID_OPERATION, false);
1451 }
1452
1453 if (texture->isImmutable())
1454 {
1455 return gl::error(GL_INVALID_OPERATION, false);
1456 }
1457
1458 if (!gl::IsValidInternalFormat(internalformat, context))
1459 {
1460 return gl::error(GL_INVALID_ENUM, false);
1461 }
1462
1463 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1464 {
1465 return gl::error(GL_INVALID_ENUM, false);
1466 }
1467
1468 return true;
1469}
1470
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001471bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1472 GLenum internalformat, GLsizei width, GLsizei height,
1473 bool angleExtension)
1474{
1475 switch (target)
1476 {
1477 case GL_RENDERBUFFER:
1478 break;
1479 default:
1480 return gl::error(GL_INVALID_ENUM, false);
1481 }
1482
1483 if (width < 0 || height < 0 || samples < 0)
1484 {
1485 return gl::error(GL_INVALID_VALUE, false);
1486 }
1487
1488 if (!gl::IsValidInternalFormat(internalformat, context))
1489 {
1490 return gl::error(GL_INVALID_ENUM, false);
1491 }
1492
1493 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1494 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1495 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1496 // internal format must be sized and not an integer format if samples is greater than zero.
1497 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1498 {
1499 return gl::error(GL_INVALID_ENUM, false);
1500 }
1501
1502 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1503 {
1504 return gl::error(GL_INVALID_OPERATION, false);
1505 }
1506
1507 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1508 !gl::IsDepthRenderingSupported(internalformat, context) &&
1509 !gl::IsStencilRenderingSupported(internalformat, context))
1510 {
1511 return gl::error(GL_INVALID_ENUM, false);
1512 }
1513
1514 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1515 {
1516 return gl::error(GL_INVALID_VALUE, false);
1517 }
1518
1519 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1520 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1521 // states that samples must be less than or equal to the maximum samples for the specified
1522 // internal format.
1523 if (angleExtension)
1524 {
1525 if (samples > context->getMaxSupportedSamples())
1526 {
1527 return gl::error(GL_INVALID_VALUE, false);
1528 }
1529 }
1530 else
1531 {
1532 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1533 {
1534 return gl::error(GL_INVALID_VALUE, false);
1535 }
1536 }
1537
1538 GLuint handle = context->getRenderbufferHandle();
1539 if (handle == 0)
1540 {
1541 return gl::error(GL_INVALID_OPERATION, false);
1542 }
1543
1544 return true;
1545}
1546
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001547// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001548bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001549{
1550 switch (format)
1551 {
1552 case GL_RGBA:
1553 switch (type)
1554 {
1555 case GL_UNSIGNED_BYTE:
1556 break;
1557 default:
1558 return false;
1559 }
1560 break;
1561 case GL_BGRA_EXT:
1562 switch (type)
1563 {
1564 case GL_UNSIGNED_BYTE:
1565 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1566 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1567 break;
1568 default:
1569 return false;
1570 }
1571 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001572 default:
1573 return false;
1574 }
1575 return true;
1576}
1577
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001578bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1579{
1580 switch (format)
1581 {
1582 case GL_RGBA:
1583 switch (type)
1584 {
1585 case GL_UNSIGNED_BYTE:
1586 break;
1587 case GL_UNSIGNED_INT_2_10_10_10_REV:
1588 if (internalFormat != GL_RGB10_A2)
1589 {
1590 return false;
1591 }
1592 break;
1593 default:
1594 return false;
1595 }
1596 break;
1597 case GL_RGBA_INTEGER:
1598 switch (type)
1599 {
1600 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001601 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1602 {
1603 return false;
1604 }
1605 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001606 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001607 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1608 {
1609 return false;
1610 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001611 break;
1612 default:
1613 return false;
1614 }
1615 break;
1616 case GL_BGRA_EXT:
1617 switch (type)
1618 {
1619 case GL_UNSIGNED_BYTE:
1620 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1621 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1622 break;
1623 default:
1624 return false;
1625 }
1626 break;
1627 default:
1628 return false;
1629 }
1630 return true;
1631}
1632
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001633bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1634 const GLenum* attachments)
1635{
1636 bool defaultFramebuffer = false;
1637
1638 switch (target)
1639 {
1640 case GL_DRAW_FRAMEBUFFER:
1641 case GL_FRAMEBUFFER:
1642 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1643 break;
1644 case GL_READ_FRAMEBUFFER:
1645 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1646 break;
1647 default:
1648 return gl::error(GL_INVALID_ENUM, false);
1649 }
1650
1651 for (int i = 0; i < numAttachments; ++i)
1652 {
1653 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1654 {
1655 if (defaultFramebuffer)
1656 {
1657 return gl::error(GL_INVALID_ENUM, false);
1658 }
1659
1660 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1661 {
1662 return gl::error(GL_INVALID_OPERATION, false);
1663 }
1664 }
1665 else
1666 {
1667 switch (attachments[i])
1668 {
1669 case GL_DEPTH_ATTACHMENT:
1670 case GL_STENCIL_ATTACHMENT:
1671 case GL_DEPTH_STENCIL_ATTACHMENT:
1672 if (defaultFramebuffer)
1673 {
1674 return gl::error(GL_INVALID_ENUM, false);
1675 }
1676 break;
1677 case GL_COLOR:
1678 case GL_DEPTH:
1679 case GL_STENCIL:
1680 if (!defaultFramebuffer)
1681 {
1682 return gl::error(GL_INVALID_ENUM, false);
1683 }
1684 break;
1685 default:
1686 return gl::error(GL_INVALID_ENUM, false);
1687 }
1688 }
1689 }
1690
1691 return true;
1692}
1693
Geoff Lang758d5b22013-06-11 11:42:50 -04001694bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1695 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1696 GLenum filter, bool fromAngleExtension)
1697{
1698 switch (filter)
1699 {
1700 case GL_NEAREST:
1701 break;
1702 case GL_LINEAR:
1703 if (fromAngleExtension)
1704 {
1705 return gl::error(GL_INVALID_ENUM, false);
1706 }
1707 break;
1708 default:
1709 return gl::error(GL_INVALID_ENUM, false);
1710 }
1711
1712 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1713 {
1714 return gl::error(GL_INVALID_VALUE, false);
1715 }
1716
1717 if (mask == 0)
1718 {
1719 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1720 // buffers are copied.
1721 return false;
1722 }
1723
1724 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
1725 {
1726 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
1727 return gl::error(GL_INVALID_OPERATION, false);
1728 }
1729
1730 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
1731 // color buffer, leaving only nearest being unfiltered from above
1732 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
1733 {
1734 return gl::error(GL_INVALID_OPERATION, false);
1735 }
1736
1737 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
1738 {
1739 if (fromAngleExtension)
1740 {
1741 ERR("Blits with the same source and destination framebuffer are not supported by this "
1742 "implementation.");
1743 }
1744 return gl::error(GL_INVALID_OPERATION, false);
1745 }
1746
1747 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
1748 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
1749 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
1750 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1751 {
1752 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1753 }
1754
1755 if (drawFramebuffer->getSamples() != 0)
1756 {
1757 return gl::error(GL_INVALID_OPERATION, false);
1758 }
1759
1760 gl::Rectangle sourceClippedRect, destClippedRect;
1761 bool partialCopy;
1762 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
1763 &sourceClippedRect, &destClippedRect, &partialCopy))
1764 {
1765 return gl::error(GL_INVALID_OPERATION, false);
1766 }
1767
1768 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
1769
1770 GLuint clientVersion = context->getClientVersion();
1771
1772 if (mask & GL_COLOR_BUFFER_BIT)
1773 {
1774 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
1775 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
1776
1777 if (readColorBuffer && drawColorBuffer)
1778 {
1779 GLint readInternalFormat = readColorBuffer->getActualFormat();
1780 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
1781
1782 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
1783 {
1784 if (drawFramebuffer->isEnabledColorAttachment(i))
1785 {
1786 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
1787
1788 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
1789 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
1790 {
1791 return gl::error(GL_INVALID_OPERATION, false);
1792 }
1793
1794 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
1795 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1796 {
1797 return gl::error(GL_INVALID_OPERATION, false);
1798 }
1799
1800 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
1801 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1802 {
1803 return gl::error(GL_INVALID_OPERATION, false);
1804 }
1805
1806 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
1807 {
1808 return gl::error(GL_INVALID_OPERATION, false);
1809 }
1810 }
1811 }
1812
1813 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
1814 {
1815 return gl::error(GL_INVALID_OPERATION, false);
1816 }
1817
1818 if (fromAngleExtension)
1819 {
1820 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
1821 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
1822 {
1823 return gl::error(GL_INVALID_OPERATION, false);
1824 }
1825
1826 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
1827 {
1828 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
1829 {
1830 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
1831 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
1832 {
1833 return gl::error(GL_INVALID_OPERATION, false);
1834 }
1835
1836 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
1837 {
1838 return gl::error(GL_INVALID_OPERATION, false);
1839 }
1840 }
1841 }
1842
1843 if (partialCopy && readFramebuffer->getSamples() != 0)
1844 {
1845 return gl::error(GL_INVALID_OPERATION, false);
1846 }
1847 }
1848 }
1849 }
1850
1851 if (mask & GL_DEPTH_BUFFER_BIT)
1852 {
1853 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
1854 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
1855
1856 if (readDepthBuffer && drawDepthBuffer)
1857 {
1858 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
1859 {
1860 return gl::error(GL_INVALID_OPERATION, false);
1861 }
1862
1863 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
1864 {
1865 return gl::error(GL_INVALID_OPERATION, false);
1866 }
1867
1868 if (fromAngleExtension)
1869 {
1870 if (partialCopy)
1871 {
1872 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1873 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1874 }
1875
1876 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
1877 {
1878 return gl::error(GL_INVALID_OPERATION, false);
1879 }
1880 }
1881 }
1882 }
1883
1884 if (mask & GL_STENCIL_BUFFER_BIT)
1885 {
1886 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
1887 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
1888
1889 if (fromAngleExtension && partialCopy)
1890 {
1891 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1892 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1893 }
1894
1895 if (readStencilBuffer && drawStencilBuffer)
1896 {
1897 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
1898 {
1899 return gl::error(GL_INVALID_OPERATION, false);
1900 }
1901
1902 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
1903 {
1904 return gl::error(GL_INVALID_OPERATION, false);
1905 }
1906
1907 if (fromAngleExtension)
1908 {
1909 if (partialCopy)
1910 {
1911 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1912 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1913 }
1914
1915 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
1916 {
1917 return gl::error(GL_INVALID_OPERATION, false);
1918 }
1919 }
1920 }
1921 }
1922
1923 return true;
1924}
1925
Jamie Madillaff71502013-07-02 11:57:05 -04001926bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
1927{
1928 switch (pname)
1929 {
1930 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1931 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1932 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1933 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1934 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1935 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1936 case GL_CURRENT_VERTEX_ATTRIB:
1937 return true;
1938
1939 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
1940 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
1941 // the same constant.
1942 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
1943 return true;
1944
Jamie Madill30855b32013-07-02 11:57:06 -04001945 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1946 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
1947
Jamie Madillaff71502013-07-02 11:57:05 -04001948 default:
1949 return gl::error(GL_INVALID_ENUM, false);
1950 }
1951}
1952
Jamie Madill478fdb22013-07-19 16:36:59 -04001953bool validateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
1954{
1955 switch (pname)
1956 {
1957 case GL_TEXTURE_WRAP_R:
1958 case GL_TEXTURE_SWIZZLE_R:
1959 case GL_TEXTURE_SWIZZLE_G:
1960 case GL_TEXTURE_SWIZZLE_B:
1961 case GL_TEXTURE_SWIZZLE_A:
1962 case GL_TEXTURE_BASE_LEVEL:
1963 case GL_TEXTURE_MAX_LEVEL:
1964 case GL_TEXTURE_COMPARE_MODE:
1965 case GL_TEXTURE_COMPARE_FUNC:
1966 case GL_TEXTURE_MIN_LOD:
1967 case GL_TEXTURE_MAX_LOD:
1968 if (context->getClientVersion() < 3)
1969 {
1970 return gl::error(GL_INVALID_ENUM, false);
1971 }
1972 break;
1973
1974 default: break;
1975 }
1976
1977 switch (pname)
1978 {
1979 case GL_TEXTURE_WRAP_S:
1980 case GL_TEXTURE_WRAP_T:
1981 case GL_TEXTURE_WRAP_R:
1982 switch (param)
1983 {
1984 case GL_REPEAT:
1985 case GL_CLAMP_TO_EDGE:
1986 case GL_MIRRORED_REPEAT:
1987 return true;
1988 default:
1989 return gl::error(GL_INVALID_ENUM, false);
1990 }
1991
1992 case GL_TEXTURE_MIN_FILTER:
1993 switch (param)
1994 {
1995 case GL_NEAREST:
1996 case GL_LINEAR:
1997 case GL_NEAREST_MIPMAP_NEAREST:
1998 case GL_LINEAR_MIPMAP_NEAREST:
1999 case GL_NEAREST_MIPMAP_LINEAR:
2000 case GL_LINEAR_MIPMAP_LINEAR:
2001 return true;
2002 default:
2003 return gl::error(GL_INVALID_ENUM, false);
2004 }
2005 break;
2006
2007 case GL_TEXTURE_MAG_FILTER:
2008 switch (param)
2009 {
2010 case GL_NEAREST:
2011 case GL_LINEAR:
2012 return true;
2013 default:
2014 return gl::error(GL_INVALID_ENUM, false);
2015 }
2016 break;
2017
2018 case GL_TEXTURE_USAGE_ANGLE:
2019 switch (param)
2020 {
2021 case GL_NONE:
2022 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
2023 return true;
2024 default:
2025 return gl::error(GL_INVALID_ENUM, false);
2026 }
2027 break;
2028
2029 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2030 if (!context->supportsTextureFilterAnisotropy())
2031 {
2032 return gl::error(GL_INVALID_ENUM, false);
2033 }
2034
2035 // we assume the parameter passed to this validation method is truncated, not rounded
2036 if (param < 1)
2037 {
2038 return gl::error(GL_INVALID_VALUE, false);
2039 }
2040 return true;
2041
2042 case GL_TEXTURE_MIN_LOD:
2043 case GL_TEXTURE_MAX_LOD:
2044 // any value is permissible
2045 return true;
2046
2047 case GL_TEXTURE_COMPARE_MODE:
2048 switch (param)
2049 {
2050 case GL_NONE:
2051 case GL_COMPARE_REF_TO_TEXTURE:
2052 return true;
2053 default:
2054 return gl::error(GL_INVALID_ENUM, false);
2055 }
2056 break;
2057
2058 case GL_TEXTURE_COMPARE_FUNC:
2059 switch (param)
2060 {
2061 case GL_LEQUAL:
2062 case GL_GEQUAL:
2063 case GL_LESS:
2064 case GL_GREATER:
2065 case GL_EQUAL:
2066 case GL_NOTEQUAL:
2067 case GL_ALWAYS:
2068 case GL_NEVER:
2069 return true;
2070 default:
2071 return gl::error(GL_INVALID_ENUM, false);
2072 }
2073 break;
2074
2075 case GL_TEXTURE_SWIZZLE_R:
2076 case GL_TEXTURE_SWIZZLE_G:
2077 case GL_TEXTURE_SWIZZLE_B:
2078 case GL_TEXTURE_SWIZZLE_A:
2079 case GL_TEXTURE_BASE_LEVEL:
2080 case GL_TEXTURE_MAX_LEVEL:
2081 UNIMPLEMENTED();
2082 return true;
2083
2084 default:
2085 return gl::error(GL_INVALID_ENUM, false);
2086 }
2087}
2088
2089
2090
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002091extern "C"
2092{
2093
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002094// OpenGL ES 2.0 functions
2095
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002096void __stdcall glActiveTexture(GLenum texture)
2097{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002098 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002099
2100 try
2101 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002102 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002103
2104 if (context)
2105 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002106 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002108 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002109 }
2110
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002111 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002112 }
2113 }
2114 catch(std::bad_alloc&)
2115 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002116 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002117 }
2118}
2119
2120void __stdcall glAttachShader(GLuint program, GLuint shader)
2121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002122 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
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 gl::Program *programObject = context->getProgram(program);
2131 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002132
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002133 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002134 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002135 if (context->getShader(program))
2136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002137 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002138 }
2139 else
2140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002141 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002142 }
2143 }
2144
2145 if (!shaderObject)
2146 {
2147 if (context->getProgram(shader))
2148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002149 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002150 }
2151 else
2152 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002153 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002154 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002155 }
2156
2157 if (!programObject->attachShader(shaderObject))
2158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002159 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002160 }
2161 }
2162 }
2163 catch(std::bad_alloc&)
2164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002165 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166 }
2167}
2168
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002169void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2170{
2171 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2172
2173 try
2174 {
2175 switch (target)
2176 {
2177 case GL_ANY_SAMPLES_PASSED_EXT:
2178 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2179 break;
2180 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002181 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002182 }
2183
2184 if (id == 0)
2185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002186 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002187 }
2188
2189 gl::Context *context = gl::getNonLostContext();
2190
2191 if (context)
2192 {
2193 context->beginQuery(target, id);
2194 }
2195 }
2196 catch(std::bad_alloc&)
2197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002198 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002199 }
2200}
2201
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002202void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002203{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002204 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002205
2206 try
2207 {
2208 if (index >= gl::MAX_VERTEX_ATTRIBS)
2209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002210 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002211 }
2212
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002213 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002214
2215 if (context)
2216 {
2217 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002218
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002219 if (!programObject)
2220 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002221 if (context->getShader(program))
2222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002223 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002224 }
2225 else
2226 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002227 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002228 }
2229 }
2230
2231 if (strncmp(name, "gl_", 3) == 0)
2232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002233 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002234 }
2235
2236 programObject->bindAttributeLocation(index, name);
2237 }
2238 }
2239 catch(std::bad_alloc&)
2240 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002241 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002242 }
2243}
2244
2245void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2246{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002247 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002248
2249 try
2250 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002251 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002252
2253 if (context)
2254 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002255 // Check ES3 specific targets
2256 switch (target)
2257 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002258 case GL_COPY_READ_BUFFER:
2259 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002260 case GL_PIXEL_PACK_BUFFER:
2261 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002262 case GL_UNIFORM_BUFFER:
2263 case GL_TRANSFORM_FEEDBACK_BUFFER:
2264 if (context->getClientVersion() < 3)
2265 {
2266 return gl::error(GL_INVALID_ENUM);
2267 }
2268 }
2269
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002270 switch (target)
2271 {
2272 case GL_ARRAY_BUFFER:
2273 context->bindArrayBuffer(buffer);
2274 return;
2275 case GL_ELEMENT_ARRAY_BUFFER:
2276 context->bindElementArrayBuffer(buffer);
2277 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002278 case GL_COPY_READ_BUFFER:
2279 context->bindCopyReadBuffer(buffer);
2280 return;
2281 case GL_COPY_WRITE_BUFFER:
2282 context->bindCopyWriteBuffer(buffer);
2283 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002284 case GL_PIXEL_PACK_BUFFER:
2285 context->bindPixelPackBuffer(buffer);
2286 return;
2287 case GL_PIXEL_UNPACK_BUFFER:
2288 context->bindPixelUnpackBuffer(buffer);
2289 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002290 case GL_UNIFORM_BUFFER:
2291 context->bindGenericUniformBuffer(buffer);
2292 return;
2293 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002294 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002295 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002296 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002297 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002298 }
2299 }
2300 }
2301 catch(std::bad_alloc&)
2302 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002303 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002304 }
2305}
2306
2307void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002309 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002310
2311 try
2312 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002313 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002316 }
2317
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002318 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002319
2320 if (context)
2321 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002322 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2323 {
2324 context->bindReadFramebuffer(framebuffer);
2325 }
2326
2327 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2328 {
2329 context->bindDrawFramebuffer(framebuffer);
2330 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002331 }
2332 }
2333 catch(std::bad_alloc&)
2334 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002335 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002336 }
2337}
2338
2339void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2340{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002341 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342
2343 try
2344 {
2345 if (target != GL_RENDERBUFFER)
2346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002347 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002348 }
2349
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002350 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002351
2352 if (context)
2353 {
2354 context->bindRenderbuffer(renderbuffer);
2355 }
2356 }
2357 catch(std::bad_alloc&)
2358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002359 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002360 }
2361}
2362
2363void __stdcall glBindTexture(GLenum target, GLuint texture)
2364{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002365 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002366
2367 try
2368 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002369 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002370
2371 if (context)
2372 {
2373 gl::Texture *textureObject = context->getTexture(texture);
2374
2375 if (textureObject && textureObject->getTarget() != target && texture != 0)
2376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002377 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002378 }
2379
2380 switch (target)
2381 {
2382 case GL_TEXTURE_2D:
2383 context->bindTexture2D(texture);
2384 return;
2385 case GL_TEXTURE_CUBE_MAP:
2386 context->bindTextureCubeMap(texture);
2387 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002388 case GL_TEXTURE_3D:
2389 if (context->getClientVersion() < 3)
2390 {
2391 return gl::error(GL_INVALID_ENUM);
2392 }
2393 context->bindTexture3D(texture);
2394 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002395 case GL_TEXTURE_2D_ARRAY:
2396 if (context->getClientVersion() < 3)
2397 {
2398 return gl::error(GL_INVALID_ENUM);
2399 }
2400 context->bindTexture2DArray(texture);
2401 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002402 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002403 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002404 }
2405 }
2406 }
2407 catch(std::bad_alloc&)
2408 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002409 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002410 }
2411}
2412
2413void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2414{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002415 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002416 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417
2418 try
2419 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002420 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002421
2422 if (context)
2423 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002424 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002425 }
2426 }
2427 catch(std::bad_alloc&)
2428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002429 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002430 }
2431}
2432
2433void __stdcall glBlendEquation(GLenum mode)
2434{
2435 glBlendEquationSeparate(mode, mode);
2436}
2437
2438void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2439{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002440 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441
2442 try
2443 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002444 gl::Context *context = gl::getNonLostContext();
2445
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002446 switch (modeRGB)
2447 {
2448 case GL_FUNC_ADD:
2449 case GL_FUNC_SUBTRACT:
2450 case GL_FUNC_REVERSE_SUBTRACT:
2451 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002452
2453 case GL_MIN:
2454 case GL_MAX:
2455 if (context && context->getClientVersion() < 3)
2456 {
2457 return gl::error(GL_INVALID_ENUM);
2458 }
2459 break;
2460
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002461 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002462 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 }
2464
2465 switch (modeAlpha)
2466 {
2467 case GL_FUNC_ADD:
2468 case GL_FUNC_SUBTRACT:
2469 case GL_FUNC_REVERSE_SUBTRACT:
2470 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002471
2472 case GL_MIN:
2473 case GL_MAX:
2474 if (context && context->getClientVersion() < 3)
2475 {
2476 return gl::error(GL_INVALID_ENUM);
2477 }
2478 break;
2479
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002481 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002482 }
2483
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002484 if (context)
2485 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002486 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002487 }
2488 }
2489 catch(std::bad_alloc&)
2490 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002491 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002492 }
2493}
2494
2495void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2496{
2497 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2498}
2499
2500void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2501{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002502 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 +00002503 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002504
2505 try
2506 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002507 gl::Context *context = gl::getNonLostContext();
2508
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002509 switch (srcRGB)
2510 {
2511 case GL_ZERO:
2512 case GL_ONE:
2513 case GL_SRC_COLOR:
2514 case GL_ONE_MINUS_SRC_COLOR:
2515 case GL_DST_COLOR:
2516 case GL_ONE_MINUS_DST_COLOR:
2517 case GL_SRC_ALPHA:
2518 case GL_ONE_MINUS_SRC_ALPHA:
2519 case GL_DST_ALPHA:
2520 case GL_ONE_MINUS_DST_ALPHA:
2521 case GL_CONSTANT_COLOR:
2522 case GL_ONE_MINUS_CONSTANT_COLOR:
2523 case GL_CONSTANT_ALPHA:
2524 case GL_ONE_MINUS_CONSTANT_ALPHA:
2525 case GL_SRC_ALPHA_SATURATE:
2526 break;
2527 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002528 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529 }
2530
2531 switch (dstRGB)
2532 {
2533 case GL_ZERO:
2534 case GL_ONE:
2535 case GL_SRC_COLOR:
2536 case GL_ONE_MINUS_SRC_COLOR:
2537 case GL_DST_COLOR:
2538 case GL_ONE_MINUS_DST_COLOR:
2539 case GL_SRC_ALPHA:
2540 case GL_ONE_MINUS_SRC_ALPHA:
2541 case GL_DST_ALPHA:
2542 case GL_ONE_MINUS_DST_ALPHA:
2543 case GL_CONSTANT_COLOR:
2544 case GL_ONE_MINUS_CONSTANT_COLOR:
2545 case GL_CONSTANT_ALPHA:
2546 case GL_ONE_MINUS_CONSTANT_ALPHA:
2547 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002548
2549 case GL_SRC_ALPHA_SATURATE:
2550 if (!context || context->getClientVersion() < 3)
2551 {
2552 return gl::error(GL_INVALID_ENUM);
2553 }
2554 break;
2555
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002556 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002557 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002558 }
2559
2560 switch (srcAlpha)
2561 {
2562 case GL_ZERO:
2563 case GL_ONE:
2564 case GL_SRC_COLOR:
2565 case GL_ONE_MINUS_SRC_COLOR:
2566 case GL_DST_COLOR:
2567 case GL_ONE_MINUS_DST_COLOR:
2568 case GL_SRC_ALPHA:
2569 case GL_ONE_MINUS_SRC_ALPHA:
2570 case GL_DST_ALPHA:
2571 case GL_ONE_MINUS_DST_ALPHA:
2572 case GL_CONSTANT_COLOR:
2573 case GL_ONE_MINUS_CONSTANT_COLOR:
2574 case GL_CONSTANT_ALPHA:
2575 case GL_ONE_MINUS_CONSTANT_ALPHA:
2576 case GL_SRC_ALPHA_SATURATE:
2577 break;
2578 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002579 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002580 }
2581
2582 switch (dstAlpha)
2583 {
2584 case GL_ZERO:
2585 case GL_ONE:
2586 case GL_SRC_COLOR:
2587 case GL_ONE_MINUS_SRC_COLOR:
2588 case GL_DST_COLOR:
2589 case GL_ONE_MINUS_DST_COLOR:
2590 case GL_SRC_ALPHA:
2591 case GL_ONE_MINUS_SRC_ALPHA:
2592 case GL_DST_ALPHA:
2593 case GL_ONE_MINUS_DST_ALPHA:
2594 case GL_CONSTANT_COLOR:
2595 case GL_ONE_MINUS_CONSTANT_COLOR:
2596 case GL_CONSTANT_ALPHA:
2597 case GL_ONE_MINUS_CONSTANT_ALPHA:
2598 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002599
2600 case GL_SRC_ALPHA_SATURATE:
2601 if (!context || context->getClientVersion() < 3)
2602 {
2603 return gl::error(GL_INVALID_ENUM);
2604 }
2605 break;
2606
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002607 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002608 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002609 }
2610
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002611 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2612 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2613
2614 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2615 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2616
2617 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002618 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002619 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 +00002620 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002621 }
2622
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002623 if (context)
2624 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002625 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002626 }
2627 }
2628 catch(std::bad_alloc&)
2629 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002630 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002631 }
2632}
2633
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002634void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002635{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002636 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 +00002637 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002638
2639 try
2640 {
2641 if (size < 0)
2642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002643 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002644 }
2645
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002646 gl::Context *context = gl::getNonLostContext();
2647
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002648 switch (usage)
2649 {
2650 case GL_STREAM_DRAW:
2651 case GL_STATIC_DRAW:
2652 case GL_DYNAMIC_DRAW:
2653 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002654
2655 case GL_STREAM_READ:
2656 case GL_STREAM_COPY:
2657 case GL_STATIC_READ:
2658 case GL_STATIC_COPY:
2659 case GL_DYNAMIC_READ:
2660 case GL_DYNAMIC_COPY:
2661 if (context && context->getClientVersion() < 3)
2662 {
2663 return gl::error(GL_INVALID_ENUM);
2664 }
2665 break;
2666
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002667 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002668 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002669 }
2670
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002671 if (context)
2672 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002673 // Check ES3 specific targets
2674 switch (target)
2675 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002676 case GL_COPY_READ_BUFFER:
2677 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002678 case GL_PIXEL_PACK_BUFFER:
2679 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002680 case GL_UNIFORM_BUFFER:
2681 case GL_TRANSFORM_FEEDBACK_BUFFER:
2682 if (context->getClientVersion() < 3)
2683 {
2684 return gl::error(GL_INVALID_ENUM);
2685 }
2686 }
2687
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002688 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002689
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690 switch (target)
2691 {
2692 case GL_ARRAY_BUFFER:
2693 buffer = context->getArrayBuffer();
2694 break;
2695 case GL_ELEMENT_ARRAY_BUFFER:
2696 buffer = context->getElementArrayBuffer();
2697 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002698 case GL_COPY_READ_BUFFER:
2699 buffer = context->getCopyReadBuffer();
2700 break;
2701 case GL_COPY_WRITE_BUFFER:
2702 buffer = context->getCopyWriteBuffer();
2703 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002704 case GL_PIXEL_PACK_BUFFER:
2705 buffer = context->getPixelPackBuffer();
2706 break;
2707 case GL_PIXEL_UNPACK_BUFFER:
2708 buffer = context->getPixelUnpackBuffer();
2709 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002710 case GL_TRANSFORM_FEEDBACK_BUFFER:
2711 buffer = context->getGenericTransformFeedbackBuffer();
2712 break;
2713 case GL_UNIFORM_BUFFER:
2714 buffer = context->getGenericUniformBuffer();
2715 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002716 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002717 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002718 }
2719
2720 if (!buffer)
2721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002722 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002723 }
2724
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002725 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726 }
2727 }
2728 catch(std::bad_alloc&)
2729 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002730 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002731 }
2732}
2733
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002734void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002736 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 +00002737 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002738
2739 try
2740 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002741 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002743 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002744 }
2745
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002746 if (data == NULL)
2747 {
2748 return;
2749 }
2750
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002751 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002752
2753 if (context)
2754 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002755 // Check ES3 specific targets
2756 switch (target)
2757 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002758 case GL_COPY_READ_BUFFER:
2759 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002760 case GL_PIXEL_PACK_BUFFER:
2761 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002762 case GL_UNIFORM_BUFFER:
2763 case GL_TRANSFORM_FEEDBACK_BUFFER:
2764 if (context->getClientVersion() < 3)
2765 {
2766 return gl::error(GL_INVALID_ENUM);
2767 }
2768 }
2769
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002770 gl::Buffer *buffer;
2771
2772 switch (target)
2773 {
2774 case GL_ARRAY_BUFFER:
2775 buffer = context->getArrayBuffer();
2776 break;
2777 case GL_ELEMENT_ARRAY_BUFFER:
2778 buffer = context->getElementArrayBuffer();
2779 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002780 case GL_COPY_READ_BUFFER:
2781 buffer = context->getCopyReadBuffer();
2782 break;
2783 case GL_COPY_WRITE_BUFFER:
2784 buffer = context->getCopyWriteBuffer();
2785 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002786 case GL_PIXEL_PACK_BUFFER:
2787 buffer = context->getPixelPackBuffer();
2788 break;
2789 case GL_PIXEL_UNPACK_BUFFER:
2790 buffer = context->getPixelUnpackBuffer();
2791 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002792 case GL_TRANSFORM_FEEDBACK_BUFFER:
2793 buffer = context->getGenericTransformFeedbackBuffer();
2794 break;
2795 case GL_UNIFORM_BUFFER:
2796 buffer = context->getGenericUniformBuffer();
2797 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002798 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002799 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002800 }
2801
2802 if (!buffer)
2803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002804 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002805 }
2806
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002807 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002808 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002809 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002810 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002811
2812 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002813 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002814 }
2815 catch(std::bad_alloc&)
2816 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002817 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002818 }
2819}
2820
2821GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2822{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002823 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002824
2825 try
2826 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002827 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002828 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002829 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002830 }
2831
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002832 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002833
2834 if (context)
2835 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002836 gl::Framebuffer *framebuffer = NULL;
2837 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2838 {
2839 framebuffer = context->getReadFramebuffer();
2840 }
2841 else
2842 {
2843 framebuffer = context->getDrawFramebuffer();
2844 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002845
2846 return framebuffer->completeness();
2847 }
2848 }
2849 catch(std::bad_alloc&)
2850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002851 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002852 }
2853
2854 return 0;
2855}
2856
2857void __stdcall glClear(GLbitfield mask)
2858{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002859 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002860
2861 try
2862 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002863 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002864
2865 if (context)
2866 {
2867 context->clear(mask);
2868 }
2869 }
2870 catch(std::bad_alloc&)
2871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002872 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002873 }
2874}
2875
2876void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2877{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002878 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002879 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002880
2881 try
2882 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002883 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002884
2885 if (context)
2886 {
2887 context->setClearColor(red, green, blue, alpha);
2888 }
2889 }
2890 catch(std::bad_alloc&)
2891 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002892 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002893 }
2894}
2895
2896void __stdcall glClearDepthf(GLclampf depth)
2897{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002898 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002899
2900 try
2901 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002903
2904 if (context)
2905 {
2906 context->setClearDepth(depth);
2907 }
2908 }
2909 catch(std::bad_alloc&)
2910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002911 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002912 }
2913}
2914
2915void __stdcall glClearStencil(GLint s)
2916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002917 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002918
2919 try
2920 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002921 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002922
2923 if (context)
2924 {
2925 context->setClearStencil(s);
2926 }
2927 }
2928 catch(std::bad_alloc&)
2929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002930 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002931 }
2932}
2933
2934void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2935{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002936 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002937 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002938
2939 try
2940 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002941 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002942
2943 if (context)
2944 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002945 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002946 }
2947 }
2948 catch(std::bad_alloc&)
2949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002951 }
2952}
2953
2954void __stdcall glCompileShader(GLuint shader)
2955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002956 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002957
2958 try
2959 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002961
2962 if (context)
2963 {
2964 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002965
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002966 if (!shaderObject)
2967 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002968 if (context->getProgram(shader))
2969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002970 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002971 }
2972 else
2973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002974 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002975 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002976 }
2977
2978 shaderObject->compile();
2979 }
2980 }
2981 catch(std::bad_alloc&)
2982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002983 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002984 }
2985}
2986
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002987void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2988 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002989{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002990 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002991 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002992 target, level, internalformat, width, height, border, imageSize, data);
2993
2994 try
2995 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002996 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002997
2998 if (context)
2999 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003000 if (context->getClientVersion() < 3 &&
3001 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3002 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3003 {
3004 return;
3005 }
3006
3007 if (context->getClientVersion() >= 3 &&
3008 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3009 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3010 {
3011 return;
3012 }
3013
3014 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003016 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003017 }
3018
3019 switch (target)
3020 {
3021 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003022 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003023 gl::Texture2D *texture = context->getTexture2D();
3024 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003025 }
3026 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003027
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003028 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3029 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3030 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3031 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3032 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3033 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003034 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003035 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3036 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003037 }
3038 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003039
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003040 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003041 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003042 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003043 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003044 }
3045 catch(std::bad_alloc&)
3046 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003047 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003048 }
3049}
3050
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003051void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3052 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003053{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003054 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003055 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003056 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003057 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3058
3059 try
3060 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003061 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003062
3063 if (context)
3064 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003065 if (context->getClientVersion() < 3 &&
3066 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3067 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3068 {
3069 return;
3070 }
3071
3072 if (context->getClientVersion() >= 3 &&
3073 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3074 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3075 {
3076 return;
3077 }
3078
3079 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003080 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003081 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003082 }
3083
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003084 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003085 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003086 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003087 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003088 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003089 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003090 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003091 break;
3092
3093 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3094 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3095 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3096 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3097 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3098 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003099 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003100 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003101 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003102 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003103 break;
3104
3105 default:
3106 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003107 }
3108 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003109 }
3110 catch(std::bad_alloc&)
3111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003112 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003113 }
3114}
3115
3116void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3117{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003118 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003119 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003120 target, level, internalformat, x, y, width, height, border);
3121
3122 try
3123 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003124 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003125
3126 if (context)
3127 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003128 if (context->getClientVersion() < 3 &&
3129 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3130 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003131 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003132 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003133 }
3134
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003135 if (context->getClientVersion() >= 3 &&
3136 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3137 0, 0, 0, x, y, width, height, border))
3138 {
3139 return;
3140 }
3141
3142 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3143
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003144 switch (target)
3145 {
3146 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003147 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003148 gl::Texture2D *texture = context->getTexture2D();
3149 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003150 }
3151 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003152
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003153 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3154 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3155 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3156 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3157 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3158 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003159 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003160 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3161 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003162 }
3163 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003164
3165 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003166 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003167 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003168 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003169 }
3170 catch(std::bad_alloc&)
3171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003172 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003173 }
3174}
3175
3176void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3177{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003178 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003179 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003180 target, level, xoffset, yoffset, x, y, width, height);
3181
3182 try
3183 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003184 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003185
3186 if (context)
3187 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003188 if (context->getClientVersion() < 3 &&
3189 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3190 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003191 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003192 return;
3193 }
3194
3195 if (context->getClientVersion() >= 3 &&
3196 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3197 xoffset, yoffset, 0, x, y, width, height, 0))
3198 {
3199 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003200 }
3201
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003202 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003203
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003204 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003205 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003206 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003207 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003208 gl::Texture2D *texture = context->getTexture2D();
3209 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003210 }
3211 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003212
3213 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3214 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3215 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3216 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3217 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3218 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003219 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003220 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3221 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003222 }
3223 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003224
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003225 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003226 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003227 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003228 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003230
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003231 catch(std::bad_alloc&)
3232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003233 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003234 }
3235}
3236
3237GLuint __stdcall glCreateProgram(void)
3238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003239 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003240
3241 try
3242 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003244
3245 if (context)
3246 {
3247 return context->createProgram();
3248 }
3249 }
3250 catch(std::bad_alloc&)
3251 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003252 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253 }
3254
3255 return 0;
3256}
3257
3258GLuint __stdcall glCreateShader(GLenum type)
3259{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003260 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003261
3262 try
3263 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003264 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003265
3266 if (context)
3267 {
3268 switch (type)
3269 {
3270 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003271 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003272 return context->createShader(type);
3273 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003274 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003275 }
3276 }
3277 }
3278 catch(std::bad_alloc&)
3279 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003280 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281 }
3282
3283 return 0;
3284}
3285
3286void __stdcall glCullFace(GLenum mode)
3287{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003288 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003289
3290 try
3291 {
3292 switch (mode)
3293 {
3294 case GL_FRONT:
3295 case GL_BACK:
3296 case GL_FRONT_AND_BACK:
3297 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003298 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003299
3300 if (context)
3301 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003302 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003303 }
3304 }
3305 break;
3306 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003307 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003308 }
3309 }
3310 catch(std::bad_alloc&)
3311 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003312 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003313 }
3314}
3315
3316void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3317{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003318 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003319
3320 try
3321 {
3322 if (n < 0)
3323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003324 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325 }
3326
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003327 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 if (context)
3330 {
3331 for (int i = 0; i < n; i++)
3332 {
3333 context->deleteBuffer(buffers[i]);
3334 }
3335 }
3336 }
3337 catch(std::bad_alloc&)
3338 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003339 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003340 }
3341}
3342
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003343void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003345 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003346
3347 try
3348 {
3349 if (n < 0)
3350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003351 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003352 }
3353
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003354 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003355
3356 if (context)
3357 {
3358 for (int i = 0; i < n; i++)
3359 {
3360 context->deleteFence(fences[i]);
3361 }
3362 }
3363 }
3364 catch(std::bad_alloc&)
3365 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003366 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003367 }
3368}
3369
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3371{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003372 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003373
3374 try
3375 {
3376 if (n < 0)
3377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003378 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379 }
3380
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003381 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003382
3383 if (context)
3384 {
3385 for (int i = 0; i < n; i++)
3386 {
3387 if (framebuffers[i] != 0)
3388 {
3389 context->deleteFramebuffer(framebuffers[i]);
3390 }
3391 }
3392 }
3393 }
3394 catch(std::bad_alloc&)
3395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003396 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397 }
3398}
3399
3400void __stdcall glDeleteProgram(GLuint program)
3401{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003402 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003403
3404 try
3405 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003406 if (program == 0)
3407 {
3408 return;
3409 }
3410
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003411 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412
3413 if (context)
3414 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003415 if (!context->getProgram(program))
3416 {
3417 if(context->getShader(program))
3418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003419 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003420 }
3421 else
3422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003423 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003424 }
3425 }
3426
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427 context->deleteProgram(program);
3428 }
3429 }
3430 catch(std::bad_alloc&)
3431 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003432 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003433 }
3434}
3435
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003436void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3437{
3438 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3439
3440 try
3441 {
3442 if (n < 0)
3443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003444 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003445 }
3446
3447 gl::Context *context = gl::getNonLostContext();
3448
3449 if (context)
3450 {
3451 for (int i = 0; i < n; i++)
3452 {
3453 context->deleteQuery(ids[i]);
3454 }
3455 }
3456 }
3457 catch(std::bad_alloc&)
3458 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003459 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003460 }
3461}
3462
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3464{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003465 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466
3467 try
3468 {
3469 if (n < 0)
3470 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003471 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 }
3473
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003475
3476 if (context)
3477 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003478 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003479 {
3480 context->deleteRenderbuffer(renderbuffers[i]);
3481 }
3482 }
3483 }
3484 catch(std::bad_alloc&)
3485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003487 }
3488}
3489
3490void __stdcall glDeleteShader(GLuint shader)
3491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003492 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003493
3494 try
3495 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003496 if (shader == 0)
3497 {
3498 return;
3499 }
3500
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003501 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502
3503 if (context)
3504 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003505 if (!context->getShader(shader))
3506 {
3507 if(context->getProgram(shader))
3508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003509 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003510 }
3511 else
3512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003513 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003514 }
3515 }
3516
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003517 context->deleteShader(shader);
3518 }
3519 }
3520 catch(std::bad_alloc&)
3521 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003522 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003523 }
3524}
3525
3526void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3527{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003528 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003529
3530 try
3531 {
3532 if (n < 0)
3533 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003534 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003535 }
3536
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003537 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003538
3539 if (context)
3540 {
3541 for (int i = 0; i < n; i++)
3542 {
3543 if (textures[i] != 0)
3544 {
3545 context->deleteTexture(textures[i]);
3546 }
3547 }
3548 }
3549 }
3550 catch(std::bad_alloc&)
3551 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003552 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003553 }
3554}
3555
3556void __stdcall glDepthFunc(GLenum func)
3557{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003558 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559
3560 try
3561 {
3562 switch (func)
3563 {
3564 case GL_NEVER:
3565 case GL_ALWAYS:
3566 case GL_LESS:
3567 case GL_LEQUAL:
3568 case GL_EQUAL:
3569 case GL_GREATER:
3570 case GL_GEQUAL:
3571 case GL_NOTEQUAL:
3572 break;
3573 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003574 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003575 }
3576
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003577 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003578
3579 if (context)
3580 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003581 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582 }
3583 }
3584 catch(std::bad_alloc&)
3585 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003586 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003587 }
3588}
3589
3590void __stdcall glDepthMask(GLboolean flag)
3591{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003592 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003593
3594 try
3595 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003596 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003597
3598 if (context)
3599 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003600 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003601 }
3602 }
3603 catch(std::bad_alloc&)
3604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 }
3607}
3608
3609void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003611 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612
3613 try
3614 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003615 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003616
3617 if (context)
3618 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003619 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003620 }
3621 }
3622 catch(std::bad_alloc&)
3623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003624 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625 }
3626}
3627
3628void __stdcall glDetachShader(GLuint program, GLuint shader)
3629{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003630 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003631
3632 try
3633 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003634 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003635
3636 if (context)
3637 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003638
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003639 gl::Program *programObject = context->getProgram(program);
3640 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003641
3642 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003643 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003644 gl::Shader *shaderByProgramHandle;
3645 shaderByProgramHandle = context->getShader(program);
3646 if (!shaderByProgramHandle)
3647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003648 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003649 }
3650 else
3651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003652 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003653 }
3654 }
3655
3656 if (!shaderObject)
3657 {
3658 gl::Program *programByShaderHandle = context->getProgram(shader);
3659 if (!programByShaderHandle)
3660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003661 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003662 }
3663 else
3664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003665 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003666 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003667 }
3668
3669 if (!programObject->detachShader(shaderObject))
3670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003672 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673 }
3674 }
3675 catch(std::bad_alloc&)
3676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003677 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003678 }
3679}
3680
3681void __stdcall glDisable(GLenum cap)
3682{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003683 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003684
3685 try
3686 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003687 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003688
3689 if (context)
3690 {
3691 switch (cap)
3692 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003693 case GL_CULL_FACE: context->setCullFace(false); break;
3694 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3695 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3696 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3697 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3698 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3699 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3700 case GL_BLEND: context->setBlend(false); break;
3701 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003702
3703 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3704 case GL_RASTERIZER_DISCARD:
3705 if (context->getClientVersion() < 3)
3706 {
3707 return gl::error(GL_INVALID_ENUM);
3708 }
3709 UNIMPLEMENTED();
3710 break;
3711
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003713 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003714 }
3715 }
3716 }
3717 catch(std::bad_alloc&)
3718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003719 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003720 }
3721}
3722
3723void __stdcall glDisableVertexAttribArray(GLuint index)
3724{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003725 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003726
3727 try
3728 {
3729 if (index >= gl::MAX_VERTEX_ATTRIBS)
3730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003731 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003732 }
3733
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003734 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003735
3736 if (context)
3737 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003738 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003739 }
3740 }
3741 catch(std::bad_alloc&)
3742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003744 }
3745}
3746
3747void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3748{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003749 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003750
3751 try
3752 {
3753 if (count < 0 || first < 0)
3754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003755 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003756 }
3757
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003758 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759
3760 if (context)
3761 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003762 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003763 }
3764 }
3765 catch(std::bad_alloc&)
3766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003767 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003768 }
3769}
3770
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003771void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3772{
3773 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3774
3775 try
3776 {
3777 if (count < 0 || first < 0 || primcount < 0)
3778 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003779 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003780 }
3781
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003782 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003783 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003784 gl::Context *context = gl::getNonLostContext();
3785
3786 if (context)
3787 {
3788 context->drawArrays(mode, first, count, primcount);
3789 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003790 }
3791 }
3792 catch(std::bad_alloc&)
3793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003794 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003795 }
3796}
3797
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003798void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003799{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003800 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 +00003801 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003802
3803 try
3804 {
3805 if (count < 0)
3806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003807 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003808 }
3809
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003810 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003811
3812 if (context)
3813 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003814 switch (type)
3815 {
3816 case GL_UNSIGNED_BYTE:
3817 case GL_UNSIGNED_SHORT:
3818 break;
3819 case GL_UNSIGNED_INT:
3820 if (!context->supports32bitIndices())
3821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003822 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003823 }
3824 break;
3825 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003826 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003827 }
3828
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003829 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003830 }
3831 }
3832 catch(std::bad_alloc&)
3833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003834 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003835 }
3836}
3837
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003838void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3839{
3840 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3841 mode, count, type, indices, primcount);
3842
3843 try
3844 {
3845 if (count < 0 || primcount < 0)
3846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003847 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003848 }
3849
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003850 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003851 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003852 gl::Context *context = gl::getNonLostContext();
3853
3854 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003855 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003856 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003857 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003858 case GL_UNSIGNED_BYTE:
3859 case GL_UNSIGNED_SHORT:
3860 break;
3861 case GL_UNSIGNED_INT:
3862 if (!context->supports32bitIndices())
3863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003864 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003865 }
3866 break;
3867 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003868 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003869 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003870
3871 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003872 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003873 }
3874 }
3875 catch(std::bad_alloc&)
3876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003877 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003878 }
3879}
3880
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003881void __stdcall glEnable(GLenum cap)
3882{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003883 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003884
3885 try
3886 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003887 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003888
3889 if (context)
3890 {
3891 switch (cap)
3892 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003893 case GL_CULL_FACE: context->setCullFace(true); break;
3894 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3895 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3896 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3897 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3898 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3899 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3900 case GL_BLEND: context->setBlend(true); break;
3901 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003904 }
3905 }
3906 }
3907 catch(std::bad_alloc&)
3908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003910 }
3911}
3912
3913void __stdcall glEnableVertexAttribArray(GLuint index)
3914{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003915 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003916
3917 try
3918 {
3919 if (index >= gl::MAX_VERTEX_ATTRIBS)
3920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003921 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003922 }
3923
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003924 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003925
3926 if (context)
3927 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003928 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003929 }
3930 }
3931 catch(std::bad_alloc&)
3932 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003933 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003934 }
3935}
3936
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003937void __stdcall glEndQueryEXT(GLenum target)
3938{
3939 EVENT("GLenum target = 0x%X)", target);
3940
3941 try
3942 {
3943 switch (target)
3944 {
3945 case GL_ANY_SAMPLES_PASSED_EXT:
3946 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3947 break;
3948 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003949 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003950 }
3951
3952 gl::Context *context = gl::getNonLostContext();
3953
3954 if (context)
3955 {
3956 context->endQuery(target);
3957 }
3958 }
3959 catch(std::bad_alloc&)
3960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003961 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003962 }
3963}
3964
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003965void __stdcall glFinishFenceNV(GLuint fence)
3966{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003967 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003968
3969 try
3970 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003971 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003972
3973 if (context)
3974 {
3975 gl::Fence* fenceObject = context->getFence(fence);
3976
3977 if (fenceObject == NULL)
3978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003979 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003980 }
3981
3982 fenceObject->finishFence();
3983 }
3984 }
3985 catch(std::bad_alloc&)
3986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003987 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003988 }
3989}
3990
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003991void __stdcall glFinish(void)
3992{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003993 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003994
3995 try
3996 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003997 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003998
3999 if (context)
4000 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004001 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004002 }
4003 }
4004 catch(std::bad_alloc&)
4005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004006 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004007 }
4008}
4009
4010void __stdcall glFlush(void)
4011{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004012 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004013
4014 try
4015 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004016 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004017
4018 if (context)
4019 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004020 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004021 }
4022 }
4023 catch(std::bad_alloc&)
4024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004025 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 }
4027}
4028
4029void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4030{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004031 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004032 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004033
4034 try
4035 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004036 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004037 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004039 return gl::error(GL_INVALID_ENUM);
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.com4f39fd92010-03-08 20:26:45 +00004043
4044 if (context)
4045 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004046 gl::Framebuffer *framebuffer = NULL;
4047 GLuint framebufferHandle = 0;
4048 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4049 {
4050 framebuffer = context->getReadFramebuffer();
4051 framebufferHandle = context->getReadFramebufferHandle();
4052 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004053 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004054 {
4055 framebuffer = context->getDrawFramebuffer();
4056 framebufferHandle = context->getDrawFramebufferHandle();
4057 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004058
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004059 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004060 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004061 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004062 }
4063
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004064 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004066 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4067
4068 if (colorAttachment >= context->getMaximumRenderTargets())
4069 {
4070 return gl::error(GL_INVALID_VALUE);
4071 }
4072
4073 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
4074 }
4075 else
4076 {
4077 switch (attachment)
4078 {
4079 case GL_DEPTH_ATTACHMENT:
4080 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
4081 break;
4082 case GL_STENCIL_ATTACHMENT:
4083 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
4084 break;
4085 default:
4086 return gl::error(GL_INVALID_ENUM);
4087 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004088 }
4089 }
4090 }
4091 catch(std::bad_alloc&)
4092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004093 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004094 }
4095}
4096
4097void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4098{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004099 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004100 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004101
4102 try
4103 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004104 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004106 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004107 }
4108
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004109 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004110
4111 if (context)
4112 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004113 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
4114 {
4115 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4116
4117 if (colorAttachment >= context->getMaximumRenderTargets())
4118 {
4119 return gl::error(GL_INVALID_VALUE);
4120 }
4121 }
4122 else
4123 {
4124 switch (attachment)
4125 {
4126 case GL_DEPTH_ATTACHMENT:
4127 case GL_STENCIL_ATTACHMENT:
4128 break;
4129 default:
4130 return gl::error(GL_INVALID_ENUM);
4131 }
4132 }
4133
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004134 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004135 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004136 textarget = GL_NONE;
4137 }
4138 else
4139 {
4140 gl::Texture *tex = context->getTexture(texture);
4141
4142 if (tex == NULL)
4143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004144 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004145 }
4146
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004147 switch (textarget)
4148 {
4149 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004150 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004151 if (tex->getTarget() != GL_TEXTURE_2D)
4152 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004153 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004154 }
4155 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004156 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004158 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004159 }
4160 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004161 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004162
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004163 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004164 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004165 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004166 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004167 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004168 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004169 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004170 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004172 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004173 }
4174 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004175 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004176 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004177 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004178 }
4179 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004180 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004181
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004182 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004183 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004184 }
4185
4186 if (level != 0)
4187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004188 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004189 }
4190 }
4191
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004192 gl::Framebuffer *framebuffer = NULL;
4193 GLuint framebufferHandle = 0;
4194 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4195 {
4196 framebuffer = context->getReadFramebuffer();
4197 framebufferHandle = context->getReadFramebufferHandle();
4198 }
4199 else
4200 {
4201 framebuffer = context->getDrawFramebuffer();
4202 framebufferHandle = context->getDrawFramebufferHandle();
4203 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004204
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004205 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004207 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004208 }
4209
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004210 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004211 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004212 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4213
4214 if (colorAttachment >= context->getMaximumRenderTargets())
4215 {
4216 return gl::error(GL_INVALID_VALUE);
4217 }
4218
4219 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4220 }
4221 else
4222 {
4223 switch (attachment)
4224 {
4225 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4226 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4227 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004228 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004229 }
4230 }
4231 catch(std::bad_alloc&)
4232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004233 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004234 }
4235}
4236
4237void __stdcall glFrontFace(GLenum mode)
4238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004239 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004240
4241 try
4242 {
4243 switch (mode)
4244 {
4245 case GL_CW:
4246 case GL_CCW:
4247 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004248 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004249
4250 if (context)
4251 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004252 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004253 }
4254 }
4255 break;
4256 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004257 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
4259 }
4260 catch(std::bad_alloc&)
4261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004262 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004263 }
4264}
4265
4266void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4267{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004268 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004269
4270 try
4271 {
4272 if (n < 0)
4273 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004274 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004275 }
4276
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004277 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004278
4279 if (context)
4280 {
4281 for (int i = 0; i < n; i++)
4282 {
4283 buffers[i] = context->createBuffer();
4284 }
4285 }
4286 }
4287 catch(std::bad_alloc&)
4288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004289 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004290 }
4291}
4292
4293void __stdcall glGenerateMipmap(GLenum target)
4294{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004295 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004296
4297 try
4298 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004300
4301 if (context)
4302 {
Geoff Langae4852a2013-06-05 15:00:34 -04004303 gl::Texture *texture = NULL;
4304 GLint internalFormat = GL_NONE;
4305 bool isCompressed = false;
4306 bool isDepth = false;
4307
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004308 switch (target)
4309 {
4310 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004311 {
4312 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004313 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004314 {
Geoff Langae4852a2013-06-05 15:00:34 -04004315 internalFormat = tex2d->getInternalFormat(0);
4316 isCompressed = tex2d->isCompressed(0);
4317 isDepth = tex2d->isDepth(0);
4318 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004319 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004320 break;
4321 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004322
4323 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004324 {
4325 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004326 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004327 {
Geoff Langae4852a2013-06-05 15:00:34 -04004328 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4329 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4330 isDepth = false;
4331 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004332 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004333 break;
4334 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004335
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004336 case GL_TEXTURE_3D:
4337 {
4338 if (context->getClientVersion() < 3)
4339 {
4340 return gl::error(GL_INVALID_ENUM);
4341 }
4342
4343 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004344 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004345 {
Geoff Langae4852a2013-06-05 15:00:34 -04004346 internalFormat = tex3D->getInternalFormat(0);
4347 isCompressed = tex3D->isCompressed(0);
4348 isDepth = tex3D->isDepth(0);
4349 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004350 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004351 break;
4352 }
4353
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004354 case GL_TEXTURE_2D_ARRAY:
4355 {
4356 if (context->getClientVersion() < 3)
4357 {
4358 return gl::error(GL_INVALID_ENUM);
4359 }
4360
4361 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004362 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004363 {
Geoff Langae4852a2013-06-05 15:00:34 -04004364 internalFormat = tex2darr->getInternalFormat(0);
4365 isCompressed = tex2darr->isCompressed(0);
4366 isDepth = tex2darr->isDepth(0);
4367 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004368 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004369 break;
4370 }
4371
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004372 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004373 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004374 }
Geoff Langae4852a2013-06-05 15:00:34 -04004375
4376 if (!texture)
4377 {
4378 return gl::error(GL_INVALID_OPERATION);
4379 }
4380
4381 // Internally, all texture formats are sized so checking if the format
4382 // is color renderable and filterable will not fail.
4383 if (isDepth || isCompressed ||
4384 !gl::IsColorRenderingSupported(internalFormat, context) ||
4385 !gl::IsTextureFilteringSupported(internalFormat, context))
4386 {
4387 return gl::error(GL_INVALID_OPERATION);
4388 }
4389
4390 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004391 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004392 }
4393 catch(std::bad_alloc&)
4394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004395 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004396 }
4397}
4398
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004399void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4400{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004401 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004402
4403 try
4404 {
4405 if (n < 0)
4406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004407 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004408 }
4409
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004410 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004411
4412 if (context)
4413 {
4414 for (int i = 0; i < n; i++)
4415 {
4416 fences[i] = context->createFence();
4417 }
4418 }
4419 }
4420 catch(std::bad_alloc&)
4421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004422 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004423 }
4424}
4425
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004426void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004428 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004429
4430 try
4431 {
4432 if (n < 0)
4433 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004434 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004435 }
4436
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004437 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438
4439 if (context)
4440 {
4441 for (int i = 0; i < n; i++)
4442 {
4443 framebuffers[i] = context->createFramebuffer();
4444 }
4445 }
4446 }
4447 catch(std::bad_alloc&)
4448 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004449 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450 }
4451}
4452
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004453void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4454{
4455 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4456
4457 try
4458 {
4459 if (n < 0)
4460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004461 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004462 }
4463
4464 gl::Context *context = gl::getNonLostContext();
4465
4466 if (context)
4467 {
4468 for (int i = 0; i < n; i++)
4469 {
4470 ids[i] = context->createQuery();
4471 }
4472 }
4473 }
4474 catch(std::bad_alloc&)
4475 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004476 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004477 }
4478}
4479
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4481{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004482 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483
4484 try
4485 {
4486 if (n < 0)
4487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004488 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004489 }
4490
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004491 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492
4493 if (context)
4494 {
4495 for (int i = 0; i < n; i++)
4496 {
4497 renderbuffers[i] = context->createRenderbuffer();
4498 }
4499 }
4500 }
4501 catch(std::bad_alloc&)
4502 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004503 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004504 }
4505}
4506
4507void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4508{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004509 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004510
4511 try
4512 {
4513 if (n < 0)
4514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004515 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004516 }
4517
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004518 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004519
4520 if (context)
4521 {
4522 for (int i = 0; i < n; i++)
4523 {
4524 textures[i] = context->createTexture();
4525 }
4526 }
4527 }
4528 catch(std::bad_alloc&)
4529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004531 }
4532}
4533
daniel@transgaming.com85423182010-04-22 13:35:27 +00004534void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004535{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004536 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004537 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004538 program, index, bufsize, length, size, type, name);
4539
4540 try
4541 {
4542 if (bufsize < 0)
4543 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004544 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004545 }
4546
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004547 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004548
4549 if (context)
4550 {
4551 gl::Program *programObject = context->getProgram(program);
4552
4553 if (!programObject)
4554 {
4555 if (context->getShader(program))
4556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004557 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004558 }
4559 else
4560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004561 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004562 }
4563 }
4564
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004565 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004567 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004568 }
4569
4570 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4571 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004572 }
4573 catch(std::bad_alloc&)
4574 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004575 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004576 }
4577}
4578
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004579void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004580{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004581 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004582 "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 +00004583 program, index, bufsize, length, size, type, name);
4584
4585 try
4586 {
4587 if (bufsize < 0)
4588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004589 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004590 }
4591
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004592 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004593
4594 if (context)
4595 {
4596 gl::Program *programObject = context->getProgram(program);
4597
4598 if (!programObject)
4599 {
4600 if (context->getShader(program))
4601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004602 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004603 }
4604 else
4605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004606 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004607 }
4608 }
4609
4610 if (index >= (GLuint)programObject->getActiveUniformCount())
4611 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004612 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004613 }
4614
4615 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4616 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004617 }
4618 catch(std::bad_alloc&)
4619 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004620 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004621 }
4622}
4623
4624void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4625{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004626 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 +00004627 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004628
4629 try
4630 {
4631 if (maxcount < 0)
4632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 }
4635
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004637
4638 if (context)
4639 {
4640 gl::Program *programObject = context->getProgram(program);
4641
4642 if (!programObject)
4643 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004644 if (context->getShader(program))
4645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004646 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004647 }
4648 else
4649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004650 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004651 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004652 }
4653
4654 return programObject->getAttachedShaders(maxcount, count, shaders);
4655 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004656 }
4657 catch(std::bad_alloc&)
4658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004659 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660 }
4661}
4662
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004663int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004665 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004666
4667 try
4668 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004669 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670
4671 if (context)
4672 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004673
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674 gl::Program *programObject = context->getProgram(program);
4675
4676 if (!programObject)
4677 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004678 if (context->getShader(program))
4679 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004680 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004681 }
4682 else
4683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004684 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004685 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004686 }
4687
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004688 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004689 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004691 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004692 }
4693
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004694 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004695 }
4696 }
4697 catch(std::bad_alloc&)
4698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004699 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004700 }
4701
4702 return -1;
4703}
4704
4705void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4706{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004707 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004708
4709 try
4710 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004711 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004712
4713 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004714 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004715 if (!(context->getBooleanv(pname, params)))
4716 {
4717 GLenum nativeType;
4718 unsigned int numParams = 0;
4719 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004720 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004721
4722 if (numParams == 0)
4723 return; // it is known that the pname is valid, but there are no parameters to return
4724
4725 if (nativeType == GL_FLOAT)
4726 {
4727 GLfloat *floatParams = NULL;
4728 floatParams = new GLfloat[numParams];
4729
4730 context->getFloatv(pname, floatParams);
4731
4732 for (unsigned int i = 0; i < numParams; ++i)
4733 {
4734 if (floatParams[i] == 0.0f)
4735 params[i] = GL_FALSE;
4736 else
4737 params[i] = GL_TRUE;
4738 }
4739
4740 delete [] floatParams;
4741 }
4742 else if (nativeType == GL_INT)
4743 {
4744 GLint *intParams = NULL;
4745 intParams = new GLint[numParams];
4746
4747 context->getIntegerv(pname, intParams);
4748
4749 for (unsigned int i = 0; i < numParams; ++i)
4750 {
4751 if (intParams[i] == 0)
4752 params[i] = GL_FALSE;
4753 else
4754 params[i] = GL_TRUE;
4755 }
4756
4757 delete [] intParams;
4758 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004759 else if (nativeType == GL_INT_64_ANGLEX)
4760 {
4761 GLint64 *int64Params = NULL;
4762 int64Params = new GLint64[numParams];
4763
4764 context->getInteger64v(pname, int64Params);
4765
4766 for (unsigned int i = 0; i < numParams; ++i)
4767 {
4768 if (int64Params[i] == 0)
4769 params[i] = GL_FALSE;
4770 else
4771 params[i] = GL_TRUE;
4772 }
4773
4774 delete [] int64Params;
4775 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004776 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004777 }
4778 }
4779 catch(std::bad_alloc&)
4780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004781 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004782 }
4783}
4784
4785void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4786{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004787 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 +00004788
4789 try
4790 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004791 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004792
4793 if (context)
4794 {
4795 gl::Buffer *buffer;
4796
4797 switch (target)
4798 {
4799 case GL_ARRAY_BUFFER:
4800 buffer = context->getArrayBuffer();
4801 break;
4802 case GL_ELEMENT_ARRAY_BUFFER:
4803 buffer = context->getElementArrayBuffer();
4804 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004805 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004806 }
4807
4808 if (!buffer)
4809 {
4810 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004811 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004812 }
4813
4814 switch (pname)
4815 {
4816 case GL_BUFFER_USAGE:
4817 *params = buffer->usage();
4818 break;
4819 case GL_BUFFER_SIZE:
4820 *params = buffer->size();
4821 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004822 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004823 }
4824 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004825 }
4826 catch(std::bad_alloc&)
4827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004828 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004829 }
4830}
4831
4832GLenum __stdcall glGetError(void)
4833{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004834 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004835
4836 gl::Context *context = gl::getContext();
4837
4838 if (context)
4839 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004840 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004841 }
4842
4843 return GL_NO_ERROR;
4844}
4845
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004846void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4847{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004848 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004849
4850 try
4851 {
4852
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004853 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004854
4855 if (context)
4856 {
4857 gl::Fence *fenceObject = context->getFence(fence);
4858
4859 if (fenceObject == NULL)
4860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004861 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004862 }
4863
4864 fenceObject->getFenceiv(pname, params);
4865 }
4866 }
4867 catch(std::bad_alloc&)
4868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004869 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004870 }
4871}
4872
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004873void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004875 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004876
4877 try
4878 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004879 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004880
4881 if (context)
4882 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004883 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004884 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004885 GLenum nativeType;
4886 unsigned int numParams = 0;
4887 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004888 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004889
4890 if (numParams == 0)
4891 return; // it is known that the pname is valid, but that there are no parameters to return.
4892
4893 if (nativeType == GL_BOOL)
4894 {
4895 GLboolean *boolParams = NULL;
4896 boolParams = new GLboolean[numParams];
4897
4898 context->getBooleanv(pname, boolParams);
4899
4900 for (unsigned int i = 0; i < numParams; ++i)
4901 {
4902 if (boolParams[i] == GL_FALSE)
4903 params[i] = 0.0f;
4904 else
4905 params[i] = 1.0f;
4906 }
4907
4908 delete [] boolParams;
4909 }
4910 else if (nativeType == GL_INT)
4911 {
4912 GLint *intParams = NULL;
4913 intParams = new GLint[numParams];
4914
4915 context->getIntegerv(pname, intParams);
4916
4917 for (unsigned int i = 0; i < numParams; ++i)
4918 {
Jamie Madill71fbd602013-07-19 16:36:55 -04004919 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004920 }
4921
4922 delete [] intParams;
4923 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004924 else if (nativeType == GL_INT_64_ANGLEX)
4925 {
4926 GLint64 *int64Params = NULL;
4927 int64Params = new GLint64[numParams];
4928
4929 context->getInteger64v(pname, int64Params);
4930
4931 for (unsigned int i = 0; i < numParams; ++i)
4932 {
4933 params[i] = static_cast<GLfloat>(int64Params[i]);
4934 }
4935
4936 delete [] int64Params;
4937 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004938 }
4939 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004940 }
4941 catch(std::bad_alloc&)
4942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004943 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004944 }
4945}
4946
4947void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4948{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004949 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 +00004950 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004951
4952 try
4953 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004954 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004955
4956 if (context)
4957 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004958 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004960 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004961 }
4962
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004963 gl::Framebuffer *framebuffer = NULL;
4964 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4965 {
4966 if(context->getReadFramebufferHandle() == 0)
4967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004968 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004969 }
4970
4971 framebuffer = context->getReadFramebuffer();
4972 }
4973 else
4974 {
4975 if (context->getDrawFramebufferHandle() == 0)
4976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004977 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004978 }
4979
4980 framebuffer = context->getDrawFramebuffer();
4981 }
4982
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004983 GLenum attachmentType;
4984 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004985
4986 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004987 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004988 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4989
4990 if (colorAttachment >= context->getMaximumRenderTargets())
4991 {
4992 return gl::error(GL_INVALID_ENUM);
4993 }
4994
4995 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4996 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4997 }
4998 else
4999 {
5000 switch (attachment)
5001 {
5002 case GL_DEPTH_ATTACHMENT:
5003 attachmentType = framebuffer->getDepthbufferType();
5004 attachmentHandle = framebuffer->getDepthbufferHandle();
5005 break;
5006 case GL_STENCIL_ATTACHMENT:
5007 attachmentType = framebuffer->getStencilbufferType();
5008 attachmentHandle = framebuffer->getStencilbufferHandle();
5009 break;
5010 default: return gl::error(GL_INVALID_ENUM);
5011 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005012 }
5013
5014 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005015 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005016 {
5017 attachmentObjectType = attachmentType;
5018 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00005019 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005020 {
5021 attachmentObjectType = GL_TEXTURE;
5022 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005023 else
5024 {
5025 UNREACHABLE();
5026 return;
5027 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005028
5029 switch (pname)
5030 {
5031 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5032 *params = attachmentObjectType;
5033 break;
5034 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5035 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5036 {
5037 *params = attachmentHandle;
5038 }
5039 else
5040 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005041 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005042 }
5043 break;
5044 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5045 if (attachmentObjectType == GL_TEXTURE)
5046 {
5047 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
5048 }
5049 else
5050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005051 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005052 }
5053 break;
5054 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5055 if (attachmentObjectType == GL_TEXTURE)
5056 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005057 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005058 {
5059 *params = attachmentType;
5060 }
5061 else
5062 {
5063 *params = 0;
5064 }
5065 }
5066 else
5067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005068 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005069 }
5070 break;
5071 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005072 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005073 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005074 }
5075 }
5076 catch(std::bad_alloc&)
5077 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005078 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005079 }
5080}
5081
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005082GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5083{
5084 EVENT("()");
5085
5086 try
5087 {
5088 gl::Context *context = gl::getContext();
5089
5090 if (context)
5091 {
5092 return context->getResetStatus();
5093 }
5094
5095 return GL_NO_ERROR;
5096 }
5097 catch(std::bad_alloc&)
5098 {
5099 return GL_OUT_OF_MEMORY;
5100 }
5101}
5102
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005103void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5104{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005105 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005106
5107 try
5108 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005109 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005110
5111 if (context)
5112 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005113 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005114 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005115 GLenum nativeType;
5116 unsigned int numParams = 0;
5117 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005118 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005119
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005120 if (numParams == 0)
5121 return; // it is known that pname is valid, but there are no parameters to return
5122
5123 if (nativeType == GL_BOOL)
5124 {
5125 GLboolean *boolParams = NULL;
5126 boolParams = new GLboolean[numParams];
5127
5128 context->getBooleanv(pname, boolParams);
5129
5130 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005131 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005132 if (boolParams[i] == GL_FALSE)
5133 params[i] = 0;
5134 else
5135 params[i] = 1;
5136 }
5137
5138 delete [] boolParams;
5139 }
5140 else if (nativeType == GL_FLOAT)
5141 {
5142 GLfloat *floatParams = NULL;
5143 floatParams = new GLfloat[numParams];
5144
5145 context->getFloatv(pname, floatParams);
5146
5147 for (unsigned int i = 0; i < numParams; ++i)
5148 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005149 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
daniel@transgaming.comc1641352010-04-26 15:33:36 +00005150 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 +00005151 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005152 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005153 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005154 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005155 {
Jamie Madillaf496912013-07-19 16:36:54 -04005156 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005157 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005158 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005159
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005160 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005161 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005162 else if (nativeType == GL_INT_64_ANGLEX)
5163 {
5164 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5165 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5166 GLint64 *int64Params = NULL;
5167 int64Params = new GLint64[numParams];
5168
5169 context->getInteger64v(pname, int64Params);
5170
5171 for (unsigned int i = 0; i < numParams; ++i)
5172 {
5173 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5174 params[i] = static_cast<GLint>(clampedValue);
5175 }
5176
5177 delete [] int64Params;
5178 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005179 }
5180 }
5181 }
5182 catch(std::bad_alloc&)
5183 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005184 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005185 }
5186}
5187
5188void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5189{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005190 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005191
5192 try
5193 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005194 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005195
5196 if (context)
5197 {
5198 gl::Program *programObject = context->getProgram(program);
5199
5200 if (!programObject)
5201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005202 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005203 }
5204
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005205 if (context->getClientVersion() < 3)
5206 {
5207 switch (pname)
5208 {
5209 case GL_ACTIVE_UNIFORM_BLOCKS:
5210 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5211 return gl::error(GL_INVALID_ENUM);
5212 }
5213 }
5214
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005215 switch (pname)
5216 {
5217 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005218 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005219 return;
5220 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005221 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005222 return;
5223 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005224 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005225 return;
5226 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005227 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005228 return;
5229 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005230 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005231 return;
5232 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005233 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234 return;
5235 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005236 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005237 return;
5238 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005239 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005240 return;
5241 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005242 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005243 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005244 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005245 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005246 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005247 case GL_ACTIVE_UNIFORM_BLOCKS:
5248 *params = programObject->getActiveUniformBlockCount();
5249 return;
5250 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5251 *params = programObject->getActiveUniformBlockMaxLength();
5252 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005253 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005254 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005255 }
5256 }
5257 }
5258 catch(std::bad_alloc&)
5259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005260 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 }
5262}
5263
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005264void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005265{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005266 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 +00005267 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005268
5269 try
5270 {
5271 if (bufsize < 0)
5272 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005273 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005274 }
5275
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005276 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005277
5278 if (context)
5279 {
5280 gl::Program *programObject = context->getProgram(program);
5281
5282 if (!programObject)
5283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005284 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005285 }
5286
5287 programObject->getInfoLog(bufsize, length, infolog);
5288 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005289 }
5290 catch(std::bad_alloc&)
5291 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005292 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005293 }
5294}
5295
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005296void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5297{
5298 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5299
5300 try
5301 {
5302 switch (pname)
5303 {
5304 case GL_CURRENT_QUERY_EXT:
5305 break;
5306 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005307 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005308 }
5309
5310 gl::Context *context = gl::getNonLostContext();
5311
5312 if (context)
5313 {
5314 params[0] = context->getActiveQuery(target);
5315 }
5316 }
5317 catch(std::bad_alloc&)
5318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005319 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005320 }
5321}
5322
5323void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5324{
5325 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5326
5327 try
5328 {
5329 switch (pname)
5330 {
5331 case GL_QUERY_RESULT_EXT:
5332 case GL_QUERY_RESULT_AVAILABLE_EXT:
5333 break;
5334 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005335 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005336 }
5337 gl::Context *context = gl::getNonLostContext();
5338
5339 if (context)
5340 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005341 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5342
5343 if (!queryObject)
5344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005345 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005346 }
5347
5348 if (context->getActiveQuery(queryObject->getType()) == id)
5349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005350 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005351 }
5352
5353 switch(pname)
5354 {
5355 case GL_QUERY_RESULT_EXT:
5356 params[0] = queryObject->getResult();
5357 break;
5358 case GL_QUERY_RESULT_AVAILABLE_EXT:
5359 params[0] = queryObject->isResultAvailable();
5360 break;
5361 default:
5362 ASSERT(false);
5363 }
5364 }
5365 }
5366 catch(std::bad_alloc&)
5367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005368 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005369 }
5370}
5371
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005372void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5373{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005374 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 +00005375
5376 try
5377 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005378 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005379
5380 if (context)
5381 {
5382 if (target != GL_RENDERBUFFER)
5383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005384 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005385 }
5386
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005387 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005388 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005389 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005390 }
5391
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005392 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005393
5394 switch (pname)
5395 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005396 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5397 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5398 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5399 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5400 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5401 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5402 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5403 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5404 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005405 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005406 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005407 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005408 *params = renderbuffer->getSamples();
5409 }
5410 else
5411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005412 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005413 }
5414 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005415 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005416 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005417 }
5418 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005419 }
5420 catch(std::bad_alloc&)
5421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005422 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005423 }
5424}
5425
5426void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005428 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429
5430 try
5431 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005432 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005433
5434 if (context)
5435 {
5436 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005437
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005438 if (!shaderObject)
5439 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005440 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005441 }
5442
5443 switch (pname)
5444 {
5445 case GL_SHADER_TYPE:
5446 *params = shaderObject->getType();
5447 return;
5448 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005449 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005450 return;
5451 case GL_COMPILE_STATUS:
5452 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5453 return;
5454 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005455 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005456 return;
5457 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005458 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005459 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005460 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5461 *params = shaderObject->getTranslatedSourceLength();
5462 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005463 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005464 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005465 }
5466 }
5467 }
5468 catch(std::bad_alloc&)
5469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005470 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005471 }
5472}
5473
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005474void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005476 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 +00005477 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005478
5479 try
5480 {
5481 if (bufsize < 0)
5482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005483 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005484 }
5485
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005486 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005487
5488 if (context)
5489 {
5490 gl::Shader *shaderObject = context->getShader(shader);
5491
5492 if (!shaderObject)
5493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005494 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005495 }
5496
5497 shaderObject->getInfoLog(bufsize, length, infolog);
5498 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005499 }
5500 catch(std::bad_alloc&)
5501 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005502 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005503 }
5504}
5505
5506void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5507{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005508 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 +00005509 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005510
5511 try
5512 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005513 switch (shadertype)
5514 {
5515 case GL_VERTEX_SHADER:
5516 case GL_FRAGMENT_SHADER:
5517 break;
5518 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005519 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005520 }
5521
5522 switch (precisiontype)
5523 {
5524 case GL_LOW_FLOAT:
5525 case GL_MEDIUM_FLOAT:
5526 case GL_HIGH_FLOAT:
5527 // Assume IEEE 754 precision
5528 range[0] = 127;
5529 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005530 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005531 break;
5532 case GL_LOW_INT:
5533 case GL_MEDIUM_INT:
5534 case GL_HIGH_INT:
5535 // Some (most) hardware only supports single-precision floating-point numbers,
5536 // which can accurately represent integers up to +/-16777216
5537 range[0] = 24;
5538 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005539 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005540 break;
5541 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005542 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005543 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005544 }
5545 catch(std::bad_alloc&)
5546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005547 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005548 }
5549}
5550
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005551void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005552{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005553 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 +00005554 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005555
5556 try
5557 {
5558 if (bufsize < 0)
5559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005560 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005561 }
5562
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005563 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005564
5565 if (context)
5566 {
5567 gl::Shader *shaderObject = context->getShader(shader);
5568
5569 if (!shaderObject)
5570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005571 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005572 }
5573
5574 shaderObject->getSource(bufsize, length, source);
5575 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005576 }
5577 catch(std::bad_alloc&)
5578 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005579 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005580 }
5581}
5582
zmo@google.coma574f782011-10-03 21:45:23 +00005583void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5584{
5585 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5586 shader, bufsize, length, source);
5587
5588 try
5589 {
5590 if (bufsize < 0)
5591 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005592 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005593 }
5594
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005595 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005596
5597 if (context)
5598 {
5599 gl::Shader *shaderObject = context->getShader(shader);
5600
5601 if (!shaderObject)
5602 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005603 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005604 }
5605
5606 shaderObject->getTranslatedSource(bufsize, length, source);
5607 }
5608 }
5609 catch(std::bad_alloc&)
5610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005611 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005612 }
5613}
5614
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005615const GLubyte* __stdcall glGetString(GLenum name)
5616{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005617 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005618
5619 try
5620 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005621 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005622
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005623 switch (name)
5624 {
5625 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005626 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005627 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005628 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005629 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005630 if (context->getClientVersion() == 2)
5631 {
5632 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5633 }
5634 else
5635 {
5636 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5637 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005638 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005639 if (context->getClientVersion() == 2)
5640 {
5641 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5642 }
5643 else
5644 {
5645 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5646 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005647 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005648 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005649 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005650 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005651 }
5652 }
5653 catch(std::bad_alloc&)
5654 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005655 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005657}
5658
5659void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5660{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005661 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 +00005662
5663 try
5664 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005665 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005666
5667 if (context)
5668 {
5669 gl::Texture *texture;
5670
5671 switch (target)
5672 {
5673 case GL_TEXTURE_2D:
5674 texture = context->getTexture2D();
5675 break;
5676 case GL_TEXTURE_CUBE_MAP:
5677 texture = context->getTextureCubeMap();
5678 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005679 case GL_TEXTURE_3D:
5680 if (context->getClientVersion() < 3)
5681 {
5682 return gl::error(GL_INVALID_ENUM);
5683 }
5684 texture = context->getTexture3D();
5685 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005686 case GL_TEXTURE_2D_ARRAY:
5687 if (context->getClientVersion() < 3)
5688 {
5689 return gl::error(GL_INVALID_ENUM);
5690 }
5691 texture = context->getTexture2DArray();
5692 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005693 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005694 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005695 }
5696
5697 switch (pname)
5698 {
5699 case GL_TEXTURE_MAG_FILTER:
5700 *params = (GLfloat)texture->getMagFilter();
5701 break;
5702 case GL_TEXTURE_MIN_FILTER:
5703 *params = (GLfloat)texture->getMinFilter();
5704 break;
5705 case GL_TEXTURE_WRAP_S:
5706 *params = (GLfloat)texture->getWrapS();
5707 break;
5708 case GL_TEXTURE_WRAP_T:
5709 *params = (GLfloat)texture->getWrapT();
5710 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005711 case GL_TEXTURE_WRAP_R:
5712 if (context->getClientVersion() < 3)
5713 {
5714 return gl::error(GL_INVALID_ENUM);
5715 }
5716 *params = (GLfloat)texture->getWrapR();
5717 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005718 case GL_TEXTURE_IMMUTABLE_FORMAT:
5719 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005720 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5721 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005722 case GL_TEXTURE_IMMUTABLE_LEVELS:
5723 if (context->getClientVersion() < 3)
5724 {
5725 return gl::error(GL_INVALID_ENUM);
5726 }
5727 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5728 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005729 case GL_TEXTURE_USAGE_ANGLE:
5730 *params = (GLfloat)texture->getUsage();
5731 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005732 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5733 if (!context->supportsTextureFilterAnisotropy())
5734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005735 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005736 }
5737 *params = (GLfloat)texture->getMaxAnisotropy();
5738 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005739 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005740 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005741 }
5742 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005743 }
5744 catch(std::bad_alloc&)
5745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005747 }
5748}
5749
5750void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5751{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005752 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 +00005753
5754 try
5755 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005756 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005757
5758 if (context)
5759 {
5760 gl::Texture *texture;
5761
5762 switch (target)
5763 {
5764 case GL_TEXTURE_2D:
5765 texture = context->getTexture2D();
5766 break;
5767 case GL_TEXTURE_CUBE_MAP:
5768 texture = context->getTextureCubeMap();
5769 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005770 case GL_TEXTURE_3D:
5771 if (context->getClientVersion() < 3)
5772 {
5773 return gl::error(GL_INVALID_ENUM);
5774 }
5775 texture = context->getTexture3D();
5776 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005777 case GL_TEXTURE_2D_ARRAY:
5778 if (context->getClientVersion() < 3)
5779 {
5780 return gl::error(GL_INVALID_ENUM);
5781 }
5782 texture = context->getTexture2DArray();
5783 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005784 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005785 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005786 }
5787
5788 switch (pname)
5789 {
5790 case GL_TEXTURE_MAG_FILTER:
5791 *params = texture->getMagFilter();
5792 break;
5793 case GL_TEXTURE_MIN_FILTER:
5794 *params = texture->getMinFilter();
5795 break;
5796 case GL_TEXTURE_WRAP_S:
5797 *params = texture->getWrapS();
5798 break;
5799 case GL_TEXTURE_WRAP_T:
5800 *params = texture->getWrapT();
5801 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005802 case GL_TEXTURE_WRAP_R:
5803 if (context->getClientVersion() < 3)
5804 {
5805 return gl::error(GL_INVALID_ENUM);
5806 }
5807 *params = texture->getWrapR();
5808 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005809 case GL_TEXTURE_IMMUTABLE_FORMAT:
5810 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005811 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5812 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005813 case GL_TEXTURE_IMMUTABLE_LEVELS:
5814 if (context->getClientVersion() < 3)
5815 {
5816 return gl::error(GL_INVALID_ENUM);
5817 }
5818 *params = texture->isImmutable() ? texture->levelCount() : 0;
5819 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005820 case GL_TEXTURE_USAGE_ANGLE:
5821 *params = texture->getUsage();
5822 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005823 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5824 if (!context->supportsTextureFilterAnisotropy())
5825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005826 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005827 }
5828 *params = (GLint)texture->getMaxAnisotropy();
5829 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005830
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005831 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005832 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005833 }
5834 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005835 }
5836 catch(std::bad_alloc&)
5837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005838 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005839 }
5840}
5841
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005842void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5843{
5844 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5845 program, location, bufSize, params);
5846
5847 try
5848 {
5849 if (bufSize < 0)
5850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005851 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005852 }
5853
5854 gl::Context *context = gl::getNonLostContext();
5855
5856 if (context)
5857 {
5858 if (program == 0)
5859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005860 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005861 }
5862
5863 gl::Program *programObject = context->getProgram(program);
5864
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005865 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005867 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005868 }
5869
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005870 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5871 if (!programBinary)
5872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005873 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005874 }
5875
5876 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005878 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005879 }
5880 }
5881 }
5882 catch(std::bad_alloc&)
5883 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005884 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005885 }
5886}
5887
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005888void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5889{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005890 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005891
5892 try
5893 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005894 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005895
5896 if (context)
5897 {
5898 if (program == 0)
5899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005900 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005901 }
5902
5903 gl::Program *programObject = context->getProgram(program);
5904
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005905 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005906 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005907 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005908 }
5909
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005910 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5911 if (!programBinary)
5912 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005913 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005914 }
5915
5916 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005917 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005918 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005919 }
5920 }
5921 }
5922 catch(std::bad_alloc&)
5923 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005924 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005925 }
5926}
5927
5928void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5929{
5930 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5931 program, location, bufSize, params);
5932
5933 try
5934 {
5935 if (bufSize < 0)
5936 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005937 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005938 }
5939
5940 gl::Context *context = gl::getNonLostContext();
5941
5942 if (context)
5943 {
5944 if (program == 0)
5945 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005946 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005947 }
5948
5949 gl::Program *programObject = context->getProgram(program);
5950
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005951 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005953 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005954 }
5955
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005956 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5957 if (!programBinary)
5958 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005959 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005960 }
5961
5962 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005963 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005964 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005965 }
5966 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005967 }
5968 catch(std::bad_alloc&)
5969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005970 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005971 }
5972}
5973
5974void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5975{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005976 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005977
5978 try
5979 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005980 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005981
5982 if (context)
5983 {
5984 if (program == 0)
5985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005986 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005987 }
5988
5989 gl::Program *programObject = context->getProgram(program);
5990
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005991 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005993 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005994 }
5995
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005996 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5997 if (!programBinary)
5998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005999 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006000 }
6001
6002 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006004 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006005 }
6006 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006007 }
6008 catch(std::bad_alloc&)
6009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006010 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006011 }
6012}
6013
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006014int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006016 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006017
6018 try
6019 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006020 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006021
6022 if (strstr(name, "gl_") == name)
6023 {
6024 return -1;
6025 }
6026
6027 if (context)
6028 {
6029 gl::Program *programObject = context->getProgram(program);
6030
6031 if (!programObject)
6032 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006033 if (context->getShader(program))
6034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006035 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006036 }
6037 else
6038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006039 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006040 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006041 }
6042
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006043 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006044 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006046 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006047 }
6048
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006049 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006050 }
6051 }
6052 catch(std::bad_alloc&)
6053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006054 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006055 }
6056
6057 return -1;
6058}
6059
6060void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6061{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006062 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006063
6064 try
6065 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006066 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006067
daniel@transgaming.come0078962010-04-15 20:45:08 +00006068 if (context)
6069 {
6070 if (index >= gl::MAX_VERTEX_ATTRIBS)
6071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006073 }
6074
daniel@transgaming.com83921382011-01-08 05:46:00 +00006075 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006076
Jamie Madillaff71502013-07-02 11:57:05 -04006077 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006078 {
Jamie Madillaff71502013-07-02 11:57:05 -04006079 return;
6080 }
6081
6082 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6083 {
6084 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6085 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006086 {
Jamie Madillaff71502013-07-02 11:57:05 -04006087 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006088 }
Jamie Madillaff71502013-07-02 11:57:05 -04006089 }
6090 else
6091 {
6092 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006093 }
6094 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006095 }
6096 catch(std::bad_alloc&)
6097 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006098 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006099 }
6100}
6101
6102void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6103{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006104 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006105
6106 try
6107 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006108 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006109
daniel@transgaming.come0078962010-04-15 20:45:08 +00006110 if (context)
6111 {
6112 if (index >= gl::MAX_VERTEX_ATTRIBS)
6113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006114 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006115 }
6116
daniel@transgaming.com83921382011-01-08 05:46:00 +00006117 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006118
Jamie Madillaff71502013-07-02 11:57:05 -04006119 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006120 {
Jamie Madillaff71502013-07-02 11:57:05 -04006121 return;
6122 }
6123
6124 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6125 {
6126 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6127 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006128 {
Jamie Madillaff71502013-07-02 11:57:05 -04006129 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006130 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006131 }
Jamie Madillaff71502013-07-02 11:57:05 -04006132 }
6133 else
6134 {
6135 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006136 }
6137 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006138 }
6139 catch(std::bad_alloc&)
6140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006141 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006142 }
6143}
6144
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006145void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006147 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006148
6149 try
6150 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006151 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006152
daniel@transgaming.come0078962010-04-15 20:45:08 +00006153 if (context)
6154 {
6155 if (index >= gl::MAX_VERTEX_ATTRIBS)
6156 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006157 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006158 }
6159
6160 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006162 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006163 }
6164
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006165 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006166 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006167 }
6168 catch(std::bad_alloc&)
6169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006170 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006171 }
6172}
6173
6174void __stdcall glHint(GLenum target, GLenum mode)
6175{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006176 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006177
6178 try
6179 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006180 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006181 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006182 case GL_FASTEST:
6183 case GL_NICEST:
6184 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006185 break;
6186 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006187 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006188 }
6189
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006190 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006191 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006192 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006193 case GL_GENERATE_MIPMAP_HINT:
6194 if (context) context->setGenerateMipmapHint(mode);
6195 break;
6196 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6197 if (context) context->setFragmentShaderDerivativeHint(mode);
6198 break;
6199 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006200 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006201 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006202 }
6203 catch(std::bad_alloc&)
6204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006205 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006206 }
6207}
6208
6209GLboolean __stdcall glIsBuffer(GLuint buffer)
6210{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006211 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006212
6213 try
6214 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006215 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006216
6217 if (context && buffer)
6218 {
6219 gl::Buffer *bufferObject = context->getBuffer(buffer);
6220
6221 if (bufferObject)
6222 {
6223 return GL_TRUE;
6224 }
6225 }
6226 }
6227 catch(std::bad_alloc&)
6228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006229 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006230 }
6231
6232 return GL_FALSE;
6233}
6234
6235GLboolean __stdcall glIsEnabled(GLenum cap)
6236{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006237 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006238
6239 try
6240 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006241 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006242
6243 if (context)
6244 {
6245 switch (cap)
6246 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006247 case GL_CULL_FACE: return context->isCullFaceEnabled();
6248 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6249 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6250 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6251 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6252 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6253 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6254 case GL_BLEND: return context->isBlendEnabled();
6255 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006256 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006257 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006258 }
6259 }
6260 }
6261 catch(std::bad_alloc&)
6262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006263 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006264 }
6265
6266 return false;
6267}
6268
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006269GLboolean __stdcall glIsFenceNV(GLuint fence)
6270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006271 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006272
6273 try
6274 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006275 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006276
6277 if (context)
6278 {
6279 gl::Fence *fenceObject = context->getFence(fence);
6280
6281 if (fenceObject == NULL)
6282 {
6283 return GL_FALSE;
6284 }
6285
6286 return fenceObject->isFence();
6287 }
6288 }
6289 catch(std::bad_alloc&)
6290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006291 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006292 }
6293
6294 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006295}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006296
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006297GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006299 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006300
6301 try
6302 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006303 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006304
6305 if (context && framebuffer)
6306 {
6307 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6308
6309 if (framebufferObject)
6310 {
6311 return GL_TRUE;
6312 }
6313 }
6314 }
6315 catch(std::bad_alloc&)
6316 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006317 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006318 }
6319
6320 return GL_FALSE;
6321}
6322
6323GLboolean __stdcall glIsProgram(GLuint program)
6324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006325 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006326
6327 try
6328 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006329 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006330
6331 if (context && program)
6332 {
6333 gl::Program *programObject = context->getProgram(program);
6334
6335 if (programObject)
6336 {
6337 return GL_TRUE;
6338 }
6339 }
6340 }
6341 catch(std::bad_alloc&)
6342 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006343 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006344 }
6345
6346 return GL_FALSE;
6347}
6348
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006349GLboolean __stdcall glIsQueryEXT(GLuint id)
6350{
6351 EVENT("(GLuint id = %d)", id);
6352
6353 try
6354 {
6355 if (id == 0)
6356 {
6357 return GL_FALSE;
6358 }
6359
6360 gl::Context *context = gl::getNonLostContext();
6361
6362 if (context)
6363 {
6364 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6365
6366 if (queryObject)
6367 {
6368 return GL_TRUE;
6369 }
6370 }
6371 }
6372 catch(std::bad_alloc&)
6373 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006374 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006375 }
6376
6377 return GL_FALSE;
6378}
6379
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006380GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006382 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006383
6384 try
6385 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006386 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006387
6388 if (context && renderbuffer)
6389 {
6390 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6391
6392 if (renderbufferObject)
6393 {
6394 return GL_TRUE;
6395 }
6396 }
6397 }
6398 catch(std::bad_alloc&)
6399 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006400 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006401 }
6402
6403 return GL_FALSE;
6404}
6405
6406GLboolean __stdcall glIsShader(GLuint shader)
6407{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006408 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006409
6410 try
6411 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006412 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006413
6414 if (context && shader)
6415 {
6416 gl::Shader *shaderObject = context->getShader(shader);
6417
6418 if (shaderObject)
6419 {
6420 return GL_TRUE;
6421 }
6422 }
6423 }
6424 catch(std::bad_alloc&)
6425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006426 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006427 }
6428
6429 return GL_FALSE;
6430}
6431
6432GLboolean __stdcall glIsTexture(GLuint texture)
6433{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006434 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006435
6436 try
6437 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006439
6440 if (context && texture)
6441 {
6442 gl::Texture *textureObject = context->getTexture(texture);
6443
6444 if (textureObject)
6445 {
6446 return GL_TRUE;
6447 }
6448 }
6449 }
6450 catch(std::bad_alloc&)
6451 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006452 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006453 }
6454
6455 return GL_FALSE;
6456}
6457
6458void __stdcall glLineWidth(GLfloat width)
6459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006460 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006461
6462 try
6463 {
6464 if (width <= 0.0f)
6465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006466 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006467 }
6468
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006469 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006470
6471 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006472 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006473 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006474 }
6475 }
6476 catch(std::bad_alloc&)
6477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006478 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006479 }
6480}
6481
6482void __stdcall glLinkProgram(GLuint program)
6483{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006484 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006485
6486 try
6487 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006488 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006489
6490 if (context)
6491 {
6492 gl::Program *programObject = context->getProgram(program);
6493
6494 if (!programObject)
6495 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006496 if (context->getShader(program))
6497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006498 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006499 }
6500 else
6501 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006502 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006503 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006504 }
6505
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006506 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006507 }
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.com4f39fd92010-03-08 20:26:45 +00006512 }
6513}
6514
6515void __stdcall glPixelStorei(GLenum pname, GLint param)
6516{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006517 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006518
6519 try
6520 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006521 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006522
6523 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006524 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006525 switch (pname)
6526 {
6527 case GL_UNPACK_ALIGNMENT:
6528 if (param != 1 && param != 2 && param != 4 && param != 8)
6529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006530 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006531 }
6532
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006533 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006534 break;
6535
6536 case GL_PACK_ALIGNMENT:
6537 if (param != 1 && param != 2 && param != 4 && param != 8)
6538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006539 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006540 }
6541
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006542 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006543 break;
6544
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006545 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6546 context->setPackReverseRowOrder(param != 0);
6547 break;
6548
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006549 case GL_UNPACK_IMAGE_HEIGHT:
6550 case GL_UNPACK_SKIP_IMAGES:
6551 case GL_UNPACK_ROW_LENGTH:
6552 case GL_UNPACK_SKIP_ROWS:
6553 case GL_UNPACK_SKIP_PIXELS:
6554 case GL_PACK_ROW_LENGTH:
6555 case GL_PACK_SKIP_ROWS:
6556 case GL_PACK_SKIP_PIXELS:
6557 if (context->getClientVersion() < 3)
6558 {
6559 return gl::error(GL_INVALID_ENUM);
6560 }
6561 UNIMPLEMENTED();
6562 break;
6563
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006564 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006565 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006566 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006567 }
6568 }
6569 catch(std::bad_alloc&)
6570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006571 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006572 }
6573}
6574
6575void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6576{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006577 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006578
6579 try
6580 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006581 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006582
6583 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006584 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006585 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006586 }
6587 }
6588 catch(std::bad_alloc&)
6589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006590 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006591 }
6592}
6593
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006594void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6595 GLenum format, GLenum type, GLsizei bufSize,
6596 GLvoid *data)
6597{
6598 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6599 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6600 x, y, width, height, format, type, bufSize, data);
6601
6602 try
6603 {
6604 if (width < 0 || height < 0 || bufSize < 0)
6605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006606 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006607 }
6608
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006609 gl::Context *context = gl::getNonLostContext();
6610
6611 if (context)
6612 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006613 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006614 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006615
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006616 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6617 // and attempting to read back if that's the case is an error. The error will be registered
6618 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006619 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006620 return;
6621
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006622 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6623 validES3ReadFormatType(currentInternalFormat, format, type);
6624
6625 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006626 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006627 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006628 }
6629
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006630 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6631 }
6632 }
6633 catch(std::bad_alloc&)
6634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006635 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006636 }
6637}
6638
6639void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6640 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006642 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006643 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006644 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006645
6646 try
6647 {
6648 if (width < 0 || height < 0)
6649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006650 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006651 }
6652
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006653 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006654
6655 if (context)
6656 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006657 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006658 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006659
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006660 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6661 // and attempting to read back if that's the case is an error. The error will be registered
6662 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006663 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006664 return;
6665
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006666 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6667 validES3ReadFormatType(currentInternalFormat, format, type);
6668
6669 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006672 }
6673
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006674 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006675 }
6676 }
6677 catch(std::bad_alloc&)
6678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006679 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006680 }
6681}
6682
6683void __stdcall glReleaseShaderCompiler(void)
6684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006685 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006686
6687 try
6688 {
6689 gl::Shader::releaseCompiler();
6690 }
6691 catch(std::bad_alloc&)
6692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006693 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006694 }
6695}
6696
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006697void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006698{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006699 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 +00006700 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006701
6702 try
6703 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006704 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006705
6706 if (context)
6707 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006708 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6709 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006710 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006711 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006712 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006713
6714 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006715 }
6716 }
6717 catch(std::bad_alloc&)
6718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006719 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006720 }
6721}
6722
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006723void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6724{
6725 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6726}
6727
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006728void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6729{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006730 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006731
6732 try
6733 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006734 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006735
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006736 if (context)
6737 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006738 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006739 }
6740 }
6741 catch(std::bad_alloc&)
6742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006744 }
6745}
6746
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006747void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6748{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006749 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006750
6751 try
6752 {
6753 if (condition != GL_ALL_COMPLETED_NV)
6754 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006755 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006756 }
6757
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006758 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006759
6760 if (context)
6761 {
6762 gl::Fence *fenceObject = context->getFence(fence);
6763
6764 if (fenceObject == NULL)
6765 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006766 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006767 }
6768
6769 fenceObject->setFence(condition);
6770 }
6771 }
6772 catch(std::bad_alloc&)
6773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006774 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006775 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006776}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006777
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006778void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006780 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 +00006781
6782 try
6783 {
6784 if (width < 0 || height < 0)
6785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006787 }
6788
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006789 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006790
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006791 if (context)
6792 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006793 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006794 }
6795 }
6796 catch(std::bad_alloc&)
6797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006798 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006799 }
6800}
6801
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006802void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006803{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006804 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006805 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006806 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006807
6808 try
6809 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006810 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006811 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006812 }
6813 catch(std::bad_alloc&)
6814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006815 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006816 }
6817}
6818
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006819void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006820{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006821 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 +00006822 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006823
6824 try
6825 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006826 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006828 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006829 }
6830
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006832
6833 if (context)
6834 {
6835 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006836
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006837 if (!shaderObject)
6838 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006839 if (context->getProgram(shader))
6840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006841 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006842 }
6843 else
6844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006845 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006846 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006847 }
6848
6849 shaderObject->setSource(count, string, length);
6850 }
6851 }
6852 catch(std::bad_alloc&)
6853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006854 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006855 }
6856}
6857
6858void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6859{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006860 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006861}
6862
6863void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006865 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 +00006866
6867 try
6868 {
6869 switch (face)
6870 {
6871 case GL_FRONT:
6872 case GL_BACK:
6873 case GL_FRONT_AND_BACK:
6874 break;
6875 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006876 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006877 }
6878
6879 switch (func)
6880 {
6881 case GL_NEVER:
6882 case GL_ALWAYS:
6883 case GL_LESS:
6884 case GL_LEQUAL:
6885 case GL_EQUAL:
6886 case GL_GEQUAL:
6887 case GL_GREATER:
6888 case GL_NOTEQUAL:
6889 break;
6890 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006891 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006892 }
6893
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006894 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006895
6896 if (context)
6897 {
6898 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6899 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006900 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006901 }
6902
6903 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6904 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006905 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006906 }
6907 }
6908 }
6909 catch(std::bad_alloc&)
6910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006911 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006912 }
6913}
6914
6915void __stdcall glStencilMask(GLuint mask)
6916{
6917 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6918}
6919
6920void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006922 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006923
6924 try
6925 {
6926 switch (face)
6927 {
6928 case GL_FRONT:
6929 case GL_BACK:
6930 case GL_FRONT_AND_BACK:
6931 break;
6932 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006933 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006934 }
6935
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006936 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006937
6938 if (context)
6939 {
6940 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6941 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006942 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006943 }
6944
6945 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6946 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006947 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006948 }
6949 }
6950 }
6951 catch(std::bad_alloc&)
6952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006953 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006954 }
6955}
6956
6957void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6958{
6959 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6960}
6961
6962void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6963{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006964 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 +00006965 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006966
6967 try
6968 {
6969 switch (face)
6970 {
6971 case GL_FRONT:
6972 case GL_BACK:
6973 case GL_FRONT_AND_BACK:
6974 break;
6975 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006976 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006977 }
6978
6979 switch (fail)
6980 {
6981 case GL_ZERO:
6982 case GL_KEEP:
6983 case GL_REPLACE:
6984 case GL_INCR:
6985 case GL_DECR:
6986 case GL_INVERT:
6987 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006988 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006989 break;
6990 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006991 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006992 }
6993
6994 switch (zfail)
6995 {
6996 case GL_ZERO:
6997 case GL_KEEP:
6998 case GL_REPLACE:
6999 case GL_INCR:
7000 case GL_DECR:
7001 case GL_INVERT:
7002 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007003 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007004 break;
7005 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007006 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007007 }
7008
7009 switch (zpass)
7010 {
7011 case GL_ZERO:
7012 case GL_KEEP:
7013 case GL_REPLACE:
7014 case GL_INCR:
7015 case GL_DECR:
7016 case GL_INVERT:
7017 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007018 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007019 break;
7020 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007021 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007022 }
7023
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007024 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007025
7026 if (context)
7027 {
7028 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7029 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007030 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007031 }
7032
7033 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7034 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007035 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007036 }
7037 }
7038 }
7039 catch(std::bad_alloc&)
7040 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007041 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007042 }
7043}
7044
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007045GLboolean __stdcall glTestFenceNV(GLuint fence)
7046{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007047 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007048
7049 try
7050 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007051 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007052
7053 if (context)
7054 {
7055 gl::Fence *fenceObject = context->getFence(fence);
7056
7057 if (fenceObject == NULL)
7058 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007059 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007060 }
7061
7062 return fenceObject->testFence();
7063 }
7064 }
7065 catch(std::bad_alloc&)
7066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007067 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007068 }
7069
7070 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007071}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007072
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007073void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7074 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007076 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 +00007077 "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 +00007078 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007079
7080 try
7081 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007082 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007083
7084 if (context)
7085 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007086 if (context->getClientVersion() < 3 &&
7087 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7088 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007089 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007090 return;
7091 }
7092
7093 if (context->getClientVersion() >= 3 &&
7094 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7095 0, 0, 0, width, height, 1, border, format, type))
7096 {
7097 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007098 }
7099
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007100 switch (target)
7101 {
7102 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007103 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007104 gl::Texture2D *texture = context->getTexture2D();
7105 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007106 }
7107 break;
7108 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007109 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007110 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007111 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007112 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007113 break;
7114 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7115 {
7116 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7117 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7118 }
7119 break;
7120 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7121 {
7122 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7123 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7124 }
7125 break;
7126 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7127 {
7128 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7129 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7130 }
7131 break;
7132 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7133 {
7134 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7135 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7136 }
7137 break;
7138 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7139 {
7140 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7141 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7142 }
7143 break;
7144 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007145 }
7146 }
7147 }
7148 catch(std::bad_alloc&)
7149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007150 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007151 }
7152}
7153
7154void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7155{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007156 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7157
7158 try
7159 {
7160 gl::Context *context = gl::getNonLostContext();
7161
7162 if (context)
7163 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007164 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7165 {
7166 return;
7167 }
7168
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007169 gl::Texture *texture;
7170
7171 switch (target)
7172 {
7173 case GL_TEXTURE_2D:
7174 texture = context->getTexture2D();
7175 break;
7176 case GL_TEXTURE_CUBE_MAP:
7177 texture = context->getTextureCubeMap();
7178 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007179 case GL_TEXTURE_3D:
7180 if (context->getClientVersion() < 3)
7181 {
7182 return gl::error(GL_INVALID_ENUM);
7183 }
7184 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007185 case GL_TEXTURE_2D_ARRAY:
7186 if (context->getClientVersion() < 3)
7187 {
7188 return gl::error(GL_INVALID_ENUM);
7189 }
7190 texture = context->getTexture2DArray();
7191 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007192 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007193 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007194 }
7195
7196 switch (pname)
7197 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007198 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7199 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7200 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7201 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7202 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7203 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7204 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7205 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7206 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007207
Jamie Madill478fdb22013-07-19 16:36:59 -04007208 case GL_TEXTURE_SWIZZLE_R:
7209 case GL_TEXTURE_SWIZZLE_G:
7210 case GL_TEXTURE_SWIZZLE_B:
7211 case GL_TEXTURE_SWIZZLE_A:
7212 case GL_TEXTURE_BASE_LEVEL:
7213 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007214 case GL_TEXTURE_MIN_LOD:
7215 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007216 UNIMPLEMENTED();
7217 break;
7218
Jamie Madill478fdb22013-07-19 16:36:59 -04007219 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007220 }
7221 }
7222 }
7223 catch(std::bad_alloc&)
7224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007225 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007226 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007227}
7228
7229void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7230{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007231 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007232}
7233
7234void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7235{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007236 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007237
7238 try
7239 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007240 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007241
7242 if (context)
7243 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007244 if (!validateTexParamParameters(context, pname, param))
7245 {
7246 return;
7247 }
7248
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007249 gl::Texture *texture;
7250
7251 switch (target)
7252 {
7253 case GL_TEXTURE_2D:
7254 texture = context->getTexture2D();
7255 break;
7256 case GL_TEXTURE_CUBE_MAP:
7257 texture = context->getTextureCubeMap();
7258 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007259 case GL_TEXTURE_3D:
7260 if (context->getClientVersion() < 3)
7261 {
7262 return gl::error(GL_INVALID_ENUM);
7263 }
7264 texture = context->getTexture3D();
7265 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007266 case GL_TEXTURE_2D_ARRAY:
7267 if (context->getClientVersion() < 3)
7268 {
7269 return gl::error(GL_INVALID_ENUM);
7270 }
7271 texture = context->getTexture2DArray();
7272 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007273 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007274 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007275 }
7276
7277 switch (pname)
7278 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007279 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7280 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7281 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7282 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7283 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7284 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7285 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7286 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7287 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007288
7289 case GL_TEXTURE_SWIZZLE_R:
7290 case GL_TEXTURE_SWIZZLE_G:
7291 case GL_TEXTURE_SWIZZLE_B:
7292 case GL_TEXTURE_SWIZZLE_A:
7293 case GL_TEXTURE_BASE_LEVEL:
7294 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007295 case GL_TEXTURE_MIN_LOD:
7296 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007297 UNIMPLEMENTED();
7298 break;
7299
Jamie Madill478fdb22013-07-19 16:36:59 -04007300 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007301 }
7302 }
7303 }
7304 catch(std::bad_alloc&)
7305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007306 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007307 }
7308}
7309
7310void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7311{
7312 glTexParameteri(target, pname, *params);
7313}
7314
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007315void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7316{
7317 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7318 target, levels, internalformat, width, height);
7319
7320 try
7321 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007322 gl::Context *context = gl::getNonLostContext();
7323
7324 if (context)
7325 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007326 if (context->getClientVersion() < 3 &&
7327 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007328 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007329 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007330 }
7331
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007332 if (context->getClientVersion() >= 3 &&
7333 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007334 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007335 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007336 }
7337
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007338 switch (target)
7339 {
7340 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007341 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007342 gl::Texture2D *texture2d = context->getTexture2D();
7343 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007344 }
7345 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007346
7347 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7348 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7349 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7350 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7351 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7352 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007353 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007354 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7355 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007356 }
7357 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007358
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007359 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007360 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007361 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007362 }
7363 }
7364 catch(std::bad_alloc&)
7365 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007366 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007367 }
7368}
7369
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007370void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7371 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007372{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007373 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007374 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007375 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007376 target, level, xoffset, yoffset, width, height, format, type, pixels);
7377
7378 try
7379 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007380 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007381
7382 if (context)
7383 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007384 if (context->getClientVersion() < 3 &&
7385 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7386 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007387 {
7388 return;
7389 }
7390
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007391 if (context->getClientVersion() >= 3 &&
7392 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7393 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007394 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007395 return;
7396 }
7397
7398 switch (target)
7399 {
7400 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007401 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007402 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007403 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007404 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007405 break;
7406
7407 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7408 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7409 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7410 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7411 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7412 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007413 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007414 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007415 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007416 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007417 break;
7418
7419 default:
7420 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007421 }
7422 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007423 }
7424 catch(std::bad_alloc&)
7425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007426 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007427 }
7428}
7429
7430void __stdcall glUniform1f(GLint location, GLfloat x)
7431{
7432 glUniform1fv(location, 1, &x);
7433}
7434
7435void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7436{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007437 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007438
7439 try
7440 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007441 if (count < 0)
7442 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007443 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007444 }
7445
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007446 if (location == -1)
7447 {
7448 return;
7449 }
7450
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007451 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007452
7453 if (context)
7454 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007455 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007456 if (!programBinary)
7457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007458 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007459 }
7460
7461 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007463 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007464 }
7465 }
7466 }
7467 catch(std::bad_alloc&)
7468 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007469 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007470 }
7471}
7472
7473void __stdcall glUniform1i(GLint location, GLint x)
7474{
7475 glUniform1iv(location, 1, &x);
7476}
7477
7478void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7479{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007480 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007481
7482 try
7483 {
7484 if (count < 0)
7485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007486 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007487 }
7488
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007489 if (location == -1)
7490 {
7491 return;
7492 }
7493
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007494 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007495
7496 if (context)
7497 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007498 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007499 if (!programBinary)
7500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007501 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007502 }
7503
7504 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007505 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007506 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007507 }
7508 }
7509 }
7510 catch(std::bad_alloc&)
7511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007512 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007513 }
7514}
7515
7516void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7517{
7518 GLfloat xy[2] = {x, y};
7519
7520 glUniform2fv(location, 1, (GLfloat*)&xy);
7521}
7522
7523void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7524{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007525 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007526
7527 try
7528 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007529 if (count < 0)
7530 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007531 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007532 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007533
7534 if (location == -1)
7535 {
7536 return;
7537 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007538
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007539 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007540
7541 if (context)
7542 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007543 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007544 if (!programBinary)
7545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007546 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007547 }
7548
7549 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007550 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007551 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007552 }
7553 }
7554 }
7555 catch(std::bad_alloc&)
7556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007557 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007558 }
7559}
7560
7561void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7562{
7563 GLint xy[4] = {x, y};
7564
7565 glUniform2iv(location, 1, (GLint*)&xy);
7566}
7567
7568void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007570 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007571
7572 try
7573 {
7574 if (count < 0)
7575 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007576 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007577 }
7578
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007579 if (location == -1)
7580 {
7581 return;
7582 }
7583
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007584 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007585
7586 if (context)
7587 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007588 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007589 if (!programBinary)
7590 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007591 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007592 }
7593
7594 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007596 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007597 }
7598 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007599 }
7600 catch(std::bad_alloc&)
7601 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007602 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007603 }
7604}
7605
7606void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7607{
7608 GLfloat xyz[3] = {x, y, z};
7609
7610 glUniform3fv(location, 1, (GLfloat*)&xyz);
7611}
7612
7613void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7614{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007615 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007616
7617 try
7618 {
7619 if (count < 0)
7620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007621 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007622 }
7623
7624 if (location == -1)
7625 {
7626 return;
7627 }
7628
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007629 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007630
7631 if (context)
7632 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007633 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007634 if (!programBinary)
7635 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007636 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007637 }
7638
7639 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007641 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007642 }
7643 }
7644 }
7645 catch(std::bad_alloc&)
7646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007647 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007648 }
7649}
7650
7651void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7652{
7653 GLint xyz[3] = {x, y, z};
7654
7655 glUniform3iv(location, 1, (GLint*)&xyz);
7656}
7657
7658void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7659{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007660 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007661
7662 try
7663 {
7664 if (count < 0)
7665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007666 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007667 }
7668
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007669 if (location == -1)
7670 {
7671 return;
7672 }
7673
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007674 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007675
7676 if (context)
7677 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007678 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007679 if (!programBinary)
7680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007681 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007682 }
7683
7684 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007686 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007687 }
7688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007689 }
7690 catch(std::bad_alloc&)
7691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007692 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007693 }
7694}
7695
7696void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7697{
7698 GLfloat xyzw[4] = {x, y, z, w};
7699
7700 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7701}
7702
7703void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007705 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007706
7707 try
7708 {
7709 if (count < 0)
7710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007711 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007712 }
7713
7714 if (location == -1)
7715 {
7716 return;
7717 }
7718
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007719 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007720
7721 if (context)
7722 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007723 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007724 if (!programBinary)
7725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007726 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007727 }
7728
7729 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007731 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007732 }
7733 }
7734 }
7735 catch(std::bad_alloc&)
7736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007737 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007738 }
7739}
7740
7741void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7742{
7743 GLint xyzw[4] = {x, y, z, w};
7744
7745 glUniform4iv(location, 1, (GLint*)&xyzw);
7746}
7747
7748void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7749{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007750 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007751
7752 try
7753 {
7754 if (count < 0)
7755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007756 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007757 }
7758
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007759 if (location == -1)
7760 {
7761 return;
7762 }
7763
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007764 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007765
7766 if (context)
7767 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007768 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007769 if (!programBinary)
7770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007771 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007772 }
7773
7774 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007775 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007776 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007777 }
7778 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007779 }
7780 catch(std::bad_alloc&)
7781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007782 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007783 }
7784}
7785
7786void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7787{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007788 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007789 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007790
7791 try
7792 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007793 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007795 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007796 }
7797
7798 if (location == -1)
7799 {
7800 return;
7801 }
7802
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007803 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007804
7805 if (context)
7806 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007807 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7808 {
7809 return gl::error(GL_INVALID_VALUE);
7810 }
7811
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007812 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007813 if (!programBinary)
7814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007815 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007816 }
7817
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007818 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007820 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007821 }
7822 }
7823 }
7824 catch(std::bad_alloc&)
7825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007826 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007827 }
7828}
7829
7830void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7831{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007832 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007833 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007834
7835 try
7836 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007837 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007839 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007840 }
7841
7842 if (location == -1)
7843 {
7844 return;
7845 }
7846
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007847 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007848
7849 if (context)
7850 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007851 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7852 {
7853 return gl::error(GL_INVALID_VALUE);
7854 }
7855
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007856 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007857 if (!programBinary)
7858 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007859 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007860 }
7861
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007862 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007864 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007865 }
7866 }
7867 }
7868 catch(std::bad_alloc&)
7869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007870 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007871 }
7872}
7873
7874void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7875{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007876 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007877 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007878
7879 try
7880 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007881 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007883 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007884 }
7885
7886 if (location == -1)
7887 {
7888 return;
7889 }
7890
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007891 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007892
7893 if (context)
7894 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007895 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7896 {
7897 return gl::error(GL_INVALID_VALUE);
7898 }
7899
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007900 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007901 if (!programBinary)
7902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007903 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007904 }
7905
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007906 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007908 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007909 }
7910 }
7911 }
7912 catch(std::bad_alloc&)
7913 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007914 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007915 }
7916}
7917
7918void __stdcall glUseProgram(GLuint program)
7919{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007920 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007921
7922 try
7923 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007924 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007925
7926 if (context)
7927 {
7928 gl::Program *programObject = context->getProgram(program);
7929
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007930 if (!programObject && program != 0)
7931 {
7932 if (context->getShader(program))
7933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007934 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007935 }
7936 else
7937 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007938 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007939 }
7940 }
7941
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007942 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007944 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007945 }
7946
7947 context->useProgram(program);
7948 }
7949 }
7950 catch(std::bad_alloc&)
7951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007952 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007953 }
7954}
7955
7956void __stdcall glValidateProgram(GLuint program)
7957{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007958 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007959
7960 try
7961 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007962 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007963
7964 if (context)
7965 {
7966 gl::Program *programObject = context->getProgram(program);
7967
7968 if (!programObject)
7969 {
7970 if (context->getShader(program))
7971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007972 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007973 }
7974 else
7975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007976 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007977 }
7978 }
7979
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007980 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007981 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007982 }
7983 catch(std::bad_alloc&)
7984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007985 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007986 }
7987}
7988
7989void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7990{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007991 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007992
7993 try
7994 {
7995 if (index >= gl::MAX_VERTEX_ATTRIBS)
7996 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007997 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007998 }
7999
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008000 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008001
8002 if (context)
8003 {
8004 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008005 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008006 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008007 }
8008 catch(std::bad_alloc&)
8009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008010 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008011 }
8012}
8013
8014void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
8015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008016 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008017
8018 try
8019 {
8020 if (index >= gl::MAX_VERTEX_ATTRIBS)
8021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008022 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008023 }
8024
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008025 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008026
8027 if (context)
8028 {
8029 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008030 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008031 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008032 }
8033 catch(std::bad_alloc&)
8034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008035 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008036 }
8037}
8038
8039void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8040{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008041 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008042
8043 try
8044 {
8045 if (index >= gl::MAX_VERTEX_ATTRIBS)
8046 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008047 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008048 }
8049
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008050 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008051
8052 if (context)
8053 {
8054 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008055 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008056 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008057 }
8058 catch(std::bad_alloc&)
8059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008060 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008061 }
8062}
8063
8064void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8065{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008066 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008067
8068 try
8069 {
8070 if (index >= gl::MAX_VERTEX_ATTRIBS)
8071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008073 }
8074
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008075 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008076
8077 if (context)
8078 {
8079 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008080 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008081 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008082 }
8083 catch(std::bad_alloc&)
8084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008085 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008086 }
8087}
8088
8089void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8090{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008091 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 +00008092
8093 try
8094 {
8095 if (index >= gl::MAX_VERTEX_ATTRIBS)
8096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008097 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008098 }
8099
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008101
8102 if (context)
8103 {
8104 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008105 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008106 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008107 }
8108 catch(std::bad_alloc&)
8109 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008110 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008111 }
8112}
8113
8114void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8115{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008116 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008117
8118 try
8119 {
8120 if (index >= gl::MAX_VERTEX_ATTRIBS)
8121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008122 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008123 }
8124
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008125 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008126
8127 if (context)
8128 {
8129 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008130 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008131 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008132 }
8133 catch(std::bad_alloc&)
8134 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008135 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008136 }
8137}
8138
8139void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8140{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008141 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 +00008142
8143 try
8144 {
8145 if (index >= gl::MAX_VERTEX_ATTRIBS)
8146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008147 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008148 }
8149
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008150 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008151
8152 if (context)
8153 {
8154 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008155 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008156 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008157 }
8158 catch(std::bad_alloc&)
8159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008160 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008161 }
8162}
8163
8164void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8165{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008166 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008167
8168 try
8169 {
8170 if (index >= gl::MAX_VERTEX_ATTRIBS)
8171 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008172 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008173 }
8174
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008175 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008176
8177 if (context)
8178 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008179 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008180 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008181 }
8182 catch(std::bad_alloc&)
8183 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008184 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008185 }
8186}
8187
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008188void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8189{
8190 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8191
8192 try
8193 {
8194 if (index >= gl::MAX_VERTEX_ATTRIBS)
8195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008196 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008197 }
8198
8199 gl::Context *context = gl::getNonLostContext();
8200
8201 if (context)
8202 {
8203 context->setVertexAttribDivisor(index, divisor);
8204 }
8205 }
8206 catch(std::bad_alloc&)
8207 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008208 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008209 }
8210}
8211
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008212void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008213{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008214 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008215 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008216 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008217
8218 try
8219 {
8220 if (index >= gl::MAX_VERTEX_ATTRIBS)
8221 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008222 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008223 }
8224
8225 if (size < 1 || size > 4)
8226 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008227 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008228 }
8229
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008230 gl::Context *context = gl::getNonLostContext();
8231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008232 switch (type)
8233 {
8234 case GL_BYTE:
8235 case GL_UNSIGNED_BYTE:
8236 case GL_SHORT:
8237 case GL_UNSIGNED_SHORT:
8238 case GL_FIXED:
8239 case GL_FLOAT:
8240 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008241 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008242 case GL_INT:
8243 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008244 case GL_INT_2_10_10_10_REV:
8245 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008246 if (context && context->getClientVersion() < 3)
8247 {
8248 return gl::error(GL_INVALID_ENUM);
8249 }
8250 else
8251 {
8252 break;
8253 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008254 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008255 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008256 }
8257
8258 if (stride < 0)
8259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008260 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008261 }
8262
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008263 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8264 {
8265 return gl::error(GL_INVALID_OPERATION);
8266 }
8267
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008268 if (context)
8269 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008270 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8271 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8272 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8273 // and the pointer argument is not NULL.
8274 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8275 {
8276 return gl::error(GL_INVALID_OPERATION);
8277 }
8278
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008279 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8280 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008281 }
8282 }
8283 catch(std::bad_alloc&)
8284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008285 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008286 }
8287}
8288
8289void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8290{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008291 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 +00008292
8293 try
8294 {
8295 if (width < 0 || height < 0)
8296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008297 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008298 }
8299
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008300 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008301
8302 if (context)
8303 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008304 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008305 }
8306 }
8307 catch(std::bad_alloc&)
8308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008309 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008310 }
8311}
8312
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008313// OpenGL ES 3.0 functions
8314
8315void __stdcall glReadBuffer(GLenum mode)
8316{
8317 EVENT("(GLenum mode = 0x%X)", mode);
8318
8319 try
8320 {
8321 gl::Context *context = gl::getNonLostContext();
8322
8323 if (context)
8324 {
8325 if (context->getClientVersion() < 3)
8326 {
8327 return gl::error(GL_INVALID_OPERATION);
8328 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008329
Jamie Madill54133512013-06-21 09:33:07 -04008330 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008331 UNIMPLEMENTED();
8332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008333 }
8334 catch(std::bad_alloc&)
8335 {
8336 return gl::error(GL_OUT_OF_MEMORY);
8337 }
8338}
8339
8340void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8341{
8342 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8343 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8344
8345 try
8346 {
8347 gl::Context *context = gl::getNonLostContext();
8348
8349 if (context)
8350 {
8351 if (context->getClientVersion() < 3)
8352 {
8353 return gl::error(GL_INVALID_OPERATION);
8354 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008355
Jamie Madill54133512013-06-21 09:33:07 -04008356 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008357 UNIMPLEMENTED();
8358 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008359 }
8360 catch(std::bad_alloc&)
8361 {
8362 return gl::error(GL_OUT_OF_MEMORY);
8363 }
8364}
8365
8366void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8367{
8368 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8369 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8370 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8371 target, level, internalformat, width, height, depth, border, format, type, pixels);
8372
8373 try
8374 {
8375 gl::Context *context = gl::getNonLostContext();
8376
8377 if (context)
8378 {
8379 if (context->getClientVersion() < 3)
8380 {
8381 return gl::error(GL_INVALID_OPERATION);
8382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008383
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008384 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008385 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008386 0, 0, 0, width, height, depth, border, format, type))
8387 {
8388 return;
8389 }
8390
8391 switch(target)
8392 {
8393 case GL_TEXTURE_3D:
8394 {
8395 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008396 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008397 }
8398 break;
8399
8400 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008401 {
8402 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008403 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008404 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008405 break;
8406
8407 default:
8408 return gl::error(GL_INVALID_ENUM);
8409 }
8410 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008411 }
8412 catch(std::bad_alloc&)
8413 {
8414 return gl::error(GL_OUT_OF_MEMORY);
8415 }
8416}
8417
8418void __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)
8419{
8420 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8421 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8422 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8423 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8424
8425 try
8426 {
8427 gl::Context *context = gl::getNonLostContext();
8428
8429 if (context)
8430 {
8431 if (context->getClientVersion() < 3)
8432 {
8433 return gl::error(GL_INVALID_OPERATION);
8434 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008435
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008436 if (!pixels)
8437 {
8438 return gl::error(GL_INVALID_VALUE);
8439 }
8440
8441 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008442 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008443 xoffset, yoffset, zoffset, width, height, depth, 0,
8444 format, type))
8445 {
8446 return;
8447 }
8448
8449 switch(target)
8450 {
8451 case GL_TEXTURE_3D:
8452 {
8453 gl::Texture3D *texture = context->getTexture3D();
8454 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8455 }
8456 break;
8457
8458 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008459 {
8460 gl::Texture2DArray *texture = context->getTexture2DArray();
8461 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8462 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008463 break;
8464
8465 default:
8466 return gl::error(GL_INVALID_ENUM);
8467 }
8468 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008469 }
8470 catch(std::bad_alloc&)
8471 {
8472 return gl::error(GL_OUT_OF_MEMORY);
8473 }
8474}
8475
8476void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8477{
8478 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8479 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8480 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8481
8482 try
8483 {
8484 gl::Context *context = gl::getNonLostContext();
8485
8486 if (context)
8487 {
8488 if (context->getClientVersion() < 3)
8489 {
8490 return gl::error(GL_INVALID_OPERATION);
8491 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008492
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008493 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8494 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008495 {
8496 return;
8497 }
8498
8499 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8500 gl::Texture *texture = NULL;
8501 switch (target)
8502 {
8503 case GL_TEXTURE_3D:
8504 texture = context->getTexture3D();
8505 break;
8506
8507 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008508 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008509 break;
8510
8511 default:
8512 return gl::error(GL_INVALID_ENUM);
8513 }
8514
8515 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8516 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008517 }
8518 catch(std::bad_alloc&)
8519 {
8520 return gl::error(GL_OUT_OF_MEMORY);
8521 }
8522}
8523
8524void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8525{
8526 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8527 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8528 "const GLvoid* data = 0x%0.8p)",
8529 target, level, internalformat, width, height, depth, border, imageSize, data);
8530
8531 try
8532 {
8533 gl::Context *context = gl::getNonLostContext();
8534
8535 if (context)
8536 {
8537 if (context->getClientVersion() < 3)
8538 {
8539 return gl::error(GL_INVALID_OPERATION);
8540 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008541
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008542 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008543 {
8544 return gl::error(GL_INVALID_VALUE);
8545 }
8546
8547 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008548 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8549 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008550 {
8551 return;
8552 }
8553
8554 switch(target)
8555 {
8556 case GL_TEXTURE_3D:
8557 {
8558 gl::Texture3D *texture = context->getTexture3D();
8559 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8560 }
8561 break;
8562
8563 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008564 {
8565 gl::Texture2DArray *texture = context->getTexture2DArray();
8566 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8567 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008568 break;
8569
8570 default:
8571 return gl::error(GL_INVALID_ENUM);
8572 }
8573 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008574 }
8575 catch(std::bad_alloc&)
8576 {
8577 return gl::error(GL_OUT_OF_MEMORY);
8578 }
8579}
8580
8581void __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)
8582{
8583 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8584 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8585 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8586 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8587
8588 try
8589 {
8590 gl::Context *context = gl::getNonLostContext();
8591
8592 if (context)
8593 {
8594 if (context->getClientVersion() < 3)
8595 {
8596 return gl::error(GL_INVALID_OPERATION);
8597 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008598
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008599 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008600 {
8601 return gl::error(GL_INVALID_VALUE);
8602 }
8603
8604 if (!data)
8605 {
8606 return gl::error(GL_INVALID_VALUE);
8607 }
8608
8609 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008610 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8611 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008612 {
8613 return;
8614 }
8615
8616 switch(target)
8617 {
8618 case GL_TEXTURE_3D:
8619 {
8620 gl::Texture3D *texture = context->getTexture3D();
8621 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8622 format, imageSize, data);
8623 }
8624 break;
8625
8626 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008627 {
8628 gl::Texture2DArray *texture = context->getTexture2DArray();
8629 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8630 format, imageSize, data);
8631 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008632 break;
8633
8634 default:
8635 return gl::error(GL_INVALID_ENUM);
8636 }
8637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008638 }
8639 catch(std::bad_alloc&)
8640 {
8641 return gl::error(GL_OUT_OF_MEMORY);
8642 }
8643}
8644
8645void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8646{
8647 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8648
8649 try
8650 {
8651 gl::Context *context = gl::getNonLostContext();
8652
8653 if (context)
8654 {
8655 if (context->getClientVersion() < 3)
8656 {
8657 return gl::error(GL_INVALID_OPERATION);
8658 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008659
Jamie Madill54133512013-06-21 09:33:07 -04008660 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008661 UNIMPLEMENTED();
8662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008663 }
8664 catch(std::bad_alloc&)
8665 {
8666 return gl::error(GL_OUT_OF_MEMORY);
8667 }
8668}
8669
8670void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8671{
8672 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8673
8674 try
8675 {
8676 gl::Context *context = gl::getNonLostContext();
8677
8678 if (context)
8679 {
8680 if (context->getClientVersion() < 3)
8681 {
8682 return gl::error(GL_INVALID_OPERATION);
8683 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008684
Jamie Madill54133512013-06-21 09:33:07 -04008685 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008686 UNIMPLEMENTED();
8687 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008688 }
8689 catch(std::bad_alloc&)
8690 {
8691 return gl::error(GL_OUT_OF_MEMORY);
8692 }
8693}
8694
8695GLboolean __stdcall glIsQuery(GLuint id)
8696{
8697 EVENT("(GLuint id = %u)", id);
8698
8699 try
8700 {
8701 gl::Context *context = gl::getNonLostContext();
8702
8703 if (context)
8704 {
8705 if (context->getClientVersion() < 3)
8706 {
8707 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8708 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008709
Jamie Madill54133512013-06-21 09:33:07 -04008710 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008711 UNIMPLEMENTED();
8712 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008713 }
8714 catch(std::bad_alloc&)
8715 {
8716 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8717 }
8718
8719 return GL_FALSE;
8720}
8721
8722void __stdcall glBeginQuery(GLenum target, GLuint id)
8723{
8724 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8725
8726 try
8727 {
8728 gl::Context *context = gl::getNonLostContext();
8729
8730 if (context)
8731 {
8732 if (context->getClientVersion() < 3)
8733 {
8734 return gl::error(GL_INVALID_OPERATION);
8735 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008736
Jamie Madill54133512013-06-21 09:33:07 -04008737 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008738 UNIMPLEMENTED();
8739 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008740 }
8741 catch(std::bad_alloc&)
8742 {
8743 return gl::error(GL_OUT_OF_MEMORY);
8744 }
8745}
8746
8747void __stdcall glEndQuery(GLenum target)
8748{
8749 EVENT("(GLenum target = 0x%X)", target);
8750
8751 try
8752 {
8753 gl::Context *context = gl::getNonLostContext();
8754
8755 if (context)
8756 {
8757 if (context->getClientVersion() < 3)
8758 {
8759 return gl::error(GL_INVALID_OPERATION);
8760 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008761
Jamie Madill54133512013-06-21 09:33:07 -04008762 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008763 UNIMPLEMENTED();
8764 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008765 }
8766 catch(std::bad_alloc&)
8767 {
8768 return gl::error(GL_OUT_OF_MEMORY);
8769 }
8770}
8771
8772void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8773{
8774 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8775
8776 try
8777 {
8778 gl::Context *context = gl::getNonLostContext();
8779
8780 if (context)
8781 {
8782 if (context->getClientVersion() < 3)
8783 {
8784 return gl::error(GL_INVALID_OPERATION);
8785 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008786
Jamie Madill54133512013-06-21 09:33:07 -04008787 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008788 UNIMPLEMENTED();
8789 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008790 }
8791 catch(std::bad_alloc&)
8792 {
8793 return gl::error(GL_OUT_OF_MEMORY);
8794 }
8795}
8796
8797void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8798{
8799 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8800
8801 try
8802 {
8803 gl::Context *context = gl::getNonLostContext();
8804
8805 if (context)
8806 {
8807 if (context->getClientVersion() < 3)
8808 {
8809 return gl::error(GL_INVALID_OPERATION);
8810 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008811
Jamie Madill54133512013-06-21 09:33:07 -04008812 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008813 UNIMPLEMENTED();
8814 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008815 }
8816 catch(std::bad_alloc&)
8817 {
8818 return gl::error(GL_OUT_OF_MEMORY);
8819 }
8820}
8821
8822GLboolean __stdcall glUnmapBuffer(GLenum target)
8823{
8824 EVENT("(GLenum target = 0x%X)", target);
8825
8826 try
8827 {
8828 gl::Context *context = gl::getNonLostContext();
8829
8830 if (context)
8831 {
8832 if (context->getClientVersion() < 3)
8833 {
8834 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8835 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008836
Jamie Madill54133512013-06-21 09:33:07 -04008837 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008838 UNIMPLEMENTED();
8839 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008840 }
8841 catch(std::bad_alloc&)
8842 {
8843 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8844 }
8845
8846 return GL_FALSE;
8847}
8848
8849void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8850{
8851 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8852
8853 try
8854 {
8855 gl::Context *context = gl::getNonLostContext();
8856
8857 if (context)
8858 {
8859 if (context->getClientVersion() < 3)
8860 {
8861 return gl::error(GL_INVALID_OPERATION);
8862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008863
Jamie Madill54133512013-06-21 09:33:07 -04008864 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008865 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008866 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008867 }
8868 catch(std::bad_alloc&)
8869 {
8870 return gl::error(GL_OUT_OF_MEMORY);
8871 }
8872}
8873
8874void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8875{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008876 try
8877 {
8878 gl::Context *context = gl::getNonLostContext();
8879
8880 if (context)
8881 {
8882 if (context->getClientVersion() < 3)
8883 {
8884 return gl::error(GL_INVALID_OPERATION);
8885 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008886
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008887 glDrawBuffersEXT(n, bufs);
8888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008889 }
8890 catch(std::bad_alloc&)
8891 {
8892 return gl::error(GL_OUT_OF_MEMORY);
8893 }
8894}
8895
8896void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8897{
8898 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8899 location, count, transpose, value);
8900
8901 try
8902 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008903 if (count < 0)
8904 {
8905 return gl::error(GL_INVALID_VALUE);
8906 }
8907
8908 if (location == -1)
8909 {
8910 return;
8911 }
8912
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008913 gl::Context *context = gl::getNonLostContext();
8914
8915 if (context)
8916 {
8917 if (context->getClientVersion() < 3)
8918 {
8919 return gl::error(GL_INVALID_OPERATION);
8920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008921
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008922 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8923 if (!programBinary)
8924 {
8925 return gl::error(GL_INVALID_OPERATION);
8926 }
8927
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008928 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008929 {
8930 return gl::error(GL_INVALID_OPERATION);
8931 }
8932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008933 }
8934 catch(std::bad_alloc&)
8935 {
8936 return gl::error(GL_OUT_OF_MEMORY);
8937 }
8938}
8939
8940void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8941{
8942 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8943 location, count, transpose, value);
8944
8945 try
8946 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008947 if (count < 0)
8948 {
8949 return gl::error(GL_INVALID_VALUE);
8950 }
8951
8952 if (location == -1)
8953 {
8954 return;
8955 }
8956
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008957 gl::Context *context = gl::getNonLostContext();
8958
8959 if (context)
8960 {
8961 if (context->getClientVersion() < 3)
8962 {
8963 return gl::error(GL_INVALID_OPERATION);
8964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008965
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008966 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8967 if (!programBinary)
8968 {
8969 return gl::error(GL_INVALID_OPERATION);
8970 }
8971
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008972 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008973 {
8974 return gl::error(GL_INVALID_OPERATION);
8975 }
8976 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008977 }
8978 catch(std::bad_alloc&)
8979 {
8980 return gl::error(GL_OUT_OF_MEMORY);
8981 }
8982}
8983
8984void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8985{
8986 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8987 location, count, transpose, value);
8988
8989 try
8990 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008991 if (count < 0)
8992 {
8993 return gl::error(GL_INVALID_VALUE);
8994 }
8995
8996 if (location == -1)
8997 {
8998 return;
8999 }
9000
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009001 gl::Context *context = gl::getNonLostContext();
9002
9003 if (context)
9004 {
9005 if (context->getClientVersion() < 3)
9006 {
9007 return gl::error(GL_INVALID_OPERATION);
9008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009009
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009010 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9011 if (!programBinary)
9012 {
9013 return gl::error(GL_INVALID_OPERATION);
9014 }
9015
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009016 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009017 {
9018 return gl::error(GL_INVALID_OPERATION);
9019 }
9020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009021 }
9022 catch(std::bad_alloc&)
9023 {
9024 return gl::error(GL_OUT_OF_MEMORY);
9025 }
9026}
9027
9028void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9029{
9030 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9031 location, count, transpose, value);
9032
9033 try
9034 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009035 if (count < 0)
9036 {
9037 return gl::error(GL_INVALID_VALUE);
9038 }
9039
9040 if (location == -1)
9041 {
9042 return;
9043 }
9044
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009045 gl::Context *context = gl::getNonLostContext();
9046
9047 if (context)
9048 {
9049 if (context->getClientVersion() < 3)
9050 {
9051 return gl::error(GL_INVALID_OPERATION);
9052 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009053
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009054 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9055 if (!programBinary)
9056 {
9057 return gl::error(GL_INVALID_OPERATION);
9058 }
9059
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009060 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009061 {
9062 return gl::error(GL_INVALID_OPERATION);
9063 }
9064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009065 }
9066 catch(std::bad_alloc&)
9067 {
9068 return gl::error(GL_OUT_OF_MEMORY);
9069 }
9070}
9071
9072void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9073{
9074 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9075 location, count, transpose, value);
9076
9077 try
9078 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009079 if (count < 0)
9080 {
9081 return gl::error(GL_INVALID_VALUE);
9082 }
9083
9084 if (location == -1)
9085 {
9086 return;
9087 }
9088
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009089 gl::Context *context = gl::getNonLostContext();
9090
9091 if (context)
9092 {
9093 if (context->getClientVersion() < 3)
9094 {
9095 return gl::error(GL_INVALID_OPERATION);
9096 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009097
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009098 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9099 if (!programBinary)
9100 {
9101 return gl::error(GL_INVALID_OPERATION);
9102 }
9103
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009104 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009105 {
9106 return gl::error(GL_INVALID_OPERATION);
9107 }
9108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009109 }
9110 catch(std::bad_alloc&)
9111 {
9112 return gl::error(GL_OUT_OF_MEMORY);
9113 }
9114}
9115
9116void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9117{
9118 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9119 location, count, transpose, value);
9120
9121 try
9122 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009123 if (count < 0)
9124 {
9125 return gl::error(GL_INVALID_VALUE);
9126 }
9127
9128 if (location == -1)
9129 {
9130 return;
9131 }
9132
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009133 gl::Context *context = gl::getNonLostContext();
9134
9135 if (context)
9136 {
9137 if (context->getClientVersion() < 3)
9138 {
9139 return gl::error(GL_INVALID_OPERATION);
9140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009141
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009142 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9143 if (!programBinary)
9144 {
9145 return gl::error(GL_INVALID_OPERATION);
9146 }
9147
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009148 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009149 {
9150 return gl::error(GL_INVALID_OPERATION);
9151 }
9152 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009153 }
9154 catch(std::bad_alloc&)
9155 {
9156 return gl::error(GL_OUT_OF_MEMORY);
9157 }
9158}
9159
9160void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9161{
9162 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9163 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9164 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9165
9166 try
9167 {
9168 gl::Context *context = gl::getNonLostContext();
9169
9170 if (context)
9171 {
9172 if (context->getClientVersion() < 3)
9173 {
9174 return gl::error(GL_INVALID_OPERATION);
9175 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009176
Geoff Lang758d5b22013-06-11 11:42:50 -04009177 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9178 dstX0, dstY0, dstX1, dstY1, mask, filter,
9179 false))
9180 {
9181 return;
9182 }
9183
9184 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9185 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009186 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009187 }
9188 catch(std::bad_alloc&)
9189 {
9190 return gl::error(GL_OUT_OF_MEMORY);
9191 }
9192}
9193
9194void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9195{
9196 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9197 target, samples, internalformat, width, height);
9198
9199 try
9200 {
9201 gl::Context *context = gl::getNonLostContext();
9202
9203 if (context)
9204 {
9205 if (context->getClientVersion() < 3)
9206 {
9207 return gl::error(GL_INVALID_OPERATION);
9208 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009209
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009210 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9211 width, height, false))
9212 {
9213 return;
9214 }
9215
9216 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009218 }
9219 catch(std::bad_alloc&)
9220 {
9221 return gl::error(GL_OUT_OF_MEMORY);
9222 }
9223}
9224
9225void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9226{
9227 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9228 target, attachment, texture, level, layer);
9229
9230 try
9231 {
9232 gl::Context *context = gl::getNonLostContext();
9233
9234 if (context)
9235 {
9236 if (context->getClientVersion() < 3)
9237 {
9238 return gl::error(GL_INVALID_OPERATION);
9239 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009240
Jamie Madill54133512013-06-21 09:33:07 -04009241 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009242 UNIMPLEMENTED();
9243 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009244 }
9245 catch(std::bad_alloc&)
9246 {
9247 return gl::error(GL_OUT_OF_MEMORY);
9248 }
9249}
9250
9251GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9252{
9253 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9254 target, offset, length, access);
9255
9256 try
9257 {
9258 gl::Context *context = gl::getNonLostContext();
9259
9260 if (context)
9261 {
9262 if (context->getClientVersion() < 3)
9263 {
9264 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9265 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009266
Jamie Madill54133512013-06-21 09:33:07 -04009267 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009268 UNIMPLEMENTED();
9269 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009270 }
9271 catch(std::bad_alloc&)
9272 {
9273 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9274 }
9275
9276 return NULL;
9277}
9278
9279void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9280{
9281 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9282
9283 try
9284 {
9285 gl::Context *context = gl::getNonLostContext();
9286
9287 if (context)
9288 {
9289 if (context->getClientVersion() < 3)
9290 {
9291 return gl::error(GL_INVALID_OPERATION);
9292 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009293
Jamie Madill54133512013-06-21 09:33:07 -04009294 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009295 UNIMPLEMENTED();
9296 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009297 }
9298 catch(std::bad_alloc&)
9299 {
9300 return gl::error(GL_OUT_OF_MEMORY);
9301 }
9302}
9303
9304void __stdcall glBindVertexArray(GLuint array)
9305{
9306 EVENT("(GLuint array = %u)", array);
9307
9308 try
9309 {
9310 gl::Context *context = gl::getNonLostContext();
9311
9312 if (context)
9313 {
9314 if (context->getClientVersion() < 3)
9315 {
9316 return gl::error(GL_INVALID_OPERATION);
9317 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009318
Jamie Madilld1028542013-07-02 11:57:04 -04009319 gl::VertexArray *vao = context->getVertexArray(array);
9320
9321 if (!vao)
9322 {
9323 // The default VAO should always exist
9324 ASSERT(array != 0);
9325 return gl::error(GL_INVALID_OPERATION);
9326 }
9327
9328 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009329 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009330 }
9331 catch(std::bad_alloc&)
9332 {
9333 return gl::error(GL_OUT_OF_MEMORY);
9334 }
9335}
9336
9337void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9338{
9339 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9340
9341 try
9342 {
9343 gl::Context *context = gl::getNonLostContext();
9344
9345 if (context)
9346 {
9347 if (context->getClientVersion() < 3)
9348 {
9349 return gl::error(GL_INVALID_OPERATION);
9350 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009351
Jamie Madilld1028542013-07-02 11:57:04 -04009352 if (n < 0)
9353 {
9354 return gl::error(GL_INVALID_VALUE);
9355 }
9356
9357 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9358 {
9359 if (arrays[arrayIndex] != 0)
9360 {
9361 context->deleteVertexArray(arrays[arrayIndex]);
9362 }
9363 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009365 }
9366 catch(std::bad_alloc&)
9367 {
9368 return gl::error(GL_OUT_OF_MEMORY);
9369 }
9370}
9371
9372void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9373{
9374 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9375
9376 try
9377 {
9378 gl::Context *context = gl::getNonLostContext();
9379
9380 if (context)
9381 {
9382 if (context->getClientVersion() < 3)
9383 {
9384 return gl::error(GL_INVALID_OPERATION);
9385 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009386
Jamie Madilld1028542013-07-02 11:57:04 -04009387 if (n < 0)
9388 {
9389 return gl::error(GL_INVALID_VALUE);
9390 }
9391
9392 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9393 {
9394 arrays[arrayIndex] = context->createVertexArray();
9395 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009396 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009397 }
9398 catch(std::bad_alloc&)
9399 {
9400 return gl::error(GL_OUT_OF_MEMORY);
9401 }
9402}
9403
9404GLboolean __stdcall glIsVertexArray(GLuint array)
9405{
9406 EVENT("(GLuint array = %u)", array);
9407
9408 try
9409 {
9410 gl::Context *context = gl::getNonLostContext();
9411
9412 if (context)
9413 {
9414 if (context->getClientVersion() < 3)
9415 {
9416 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9417 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009418
Jamie Madilld1028542013-07-02 11:57:04 -04009419 if (array == 0)
9420 {
9421 return GL_FALSE;
9422 }
9423
9424 gl::VertexArray *vao = context->getVertexArray(array);
9425
9426 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009427 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009428 }
9429 catch(std::bad_alloc&)
9430 {
9431 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9432 }
9433
9434 return GL_FALSE;
9435}
9436
9437void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9438{
9439 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9440 target, index, data);
9441
9442 try
9443 {
9444 gl::Context *context = gl::getNonLostContext();
9445
9446 if (context)
9447 {
9448 if (context->getClientVersion() < 3)
9449 {
9450 return gl::error(GL_INVALID_OPERATION);
9451 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009452
Jamie Madill54133512013-06-21 09:33:07 -04009453 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009454 UNIMPLEMENTED();
9455 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009456 }
9457 catch(std::bad_alloc&)
9458 {
9459 return gl::error(GL_OUT_OF_MEMORY);
9460 }
9461}
9462
9463void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9464{
9465 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9466
9467 try
9468 {
9469 gl::Context *context = gl::getNonLostContext();
9470
9471 if (context)
9472 {
9473 if (context->getClientVersion() < 3)
9474 {
9475 return gl::error(GL_INVALID_OPERATION);
9476 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009477
Jamie Madill54133512013-06-21 09:33:07 -04009478 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009479 UNIMPLEMENTED();
9480 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009481 }
9482 catch(std::bad_alloc&)
9483 {
9484 return gl::error(GL_OUT_OF_MEMORY);
9485 }
9486}
9487
9488void __stdcall glEndTransformFeedback(void)
9489{
9490 EVENT("(void)");
9491
9492 try
9493 {
9494 gl::Context *context = gl::getNonLostContext();
9495
9496 if (context)
9497 {
9498 if (context->getClientVersion() < 3)
9499 {
9500 return gl::error(GL_INVALID_OPERATION);
9501 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009502
Jamie Madill54133512013-06-21 09:33:07 -04009503 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009504 UNIMPLEMENTED();
9505 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009506 }
9507 catch(std::bad_alloc&)
9508 {
9509 return gl::error(GL_OUT_OF_MEMORY);
9510 }
9511}
9512
9513void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9514{
9515 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9516 target, index, buffer, offset, size);
9517
9518 try
9519 {
9520 gl::Context *context = gl::getNonLostContext();
9521
9522 if (context)
9523 {
9524 if (context->getClientVersion() < 3)
9525 {
9526 return gl::error(GL_INVALID_OPERATION);
9527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009528
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009529 switch (target)
9530 {
9531 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009532 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009533 {
9534 return gl::error(GL_INVALID_VALUE);
9535 }
9536 break;
9537
9538 case GL_UNIFORM_BUFFER:
9539 if (index >= context->getMaximumCombinedUniformBufferBindings())
9540 {
9541 return gl::error(GL_INVALID_VALUE);
9542 }
9543 break;
9544
9545 default:
9546 return gl::error(GL_INVALID_ENUM);
9547 }
9548
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009549 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009550 {
9551 return gl::error(GL_INVALID_VALUE);
9552 }
9553
9554 switch (target)
9555 {
9556 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009557
9558 // size and offset must be a multiple of 4
9559 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9560 {
9561 return gl::error(GL_INVALID_VALUE);
9562 }
9563
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009564 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9565 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009566 break;
9567
9568 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009569
9570 // it is an error to bind an offset not a multiple of the alignment
9571 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9572 {
9573 return gl::error(GL_INVALID_VALUE);
9574 }
9575
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009576 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9577 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009578 break;
9579
9580 default:
9581 UNREACHABLE();
9582 }
9583 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009584 }
9585 catch(std::bad_alloc&)
9586 {
9587 return gl::error(GL_OUT_OF_MEMORY);
9588 }
9589}
9590
9591void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9592{
9593 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9594 target, index, buffer);
9595
9596 try
9597 {
9598 gl::Context *context = gl::getNonLostContext();
9599
9600 if (context)
9601 {
9602 if (context->getClientVersion() < 3)
9603 {
9604 return gl::error(GL_INVALID_OPERATION);
9605 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009606
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009607 switch (target)
9608 {
9609 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009610 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009611 {
9612 return gl::error(GL_INVALID_VALUE);
9613 }
9614 break;
9615
9616 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009617 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009618 {
9619 return gl::error(GL_INVALID_VALUE);
9620 }
9621 break;
9622
9623 default:
9624 return gl::error(GL_INVALID_ENUM);
9625 }
9626
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009627 switch (target)
9628 {
9629 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009630 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009631 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009632 break;
9633
9634 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009635 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009636 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009637 break;
9638
9639 default:
9640 UNREACHABLE();
9641 }
9642 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009643 }
9644 catch(std::bad_alloc&)
9645 {
9646 return gl::error(GL_OUT_OF_MEMORY);
9647 }
9648}
9649
9650void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9651{
9652 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9653 program, count, varyings, bufferMode);
9654
9655 try
9656 {
9657 gl::Context *context = gl::getNonLostContext();
9658
9659 if (context)
9660 {
9661 if (context->getClientVersion() < 3)
9662 {
9663 return gl::error(GL_INVALID_OPERATION);
9664 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009665
Jamie Madill54133512013-06-21 09:33:07 -04009666 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009667 UNIMPLEMENTED();
9668 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009669 }
9670 catch(std::bad_alloc&)
9671 {
9672 return gl::error(GL_OUT_OF_MEMORY);
9673 }
9674}
9675
9676void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9677{
9678 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9679 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9680 program, index, bufSize, length, size, type, name);
9681
9682 try
9683 {
9684 gl::Context *context = gl::getNonLostContext();
9685
9686 if (context)
9687 {
9688 if (context->getClientVersion() < 3)
9689 {
9690 return gl::error(GL_INVALID_OPERATION);
9691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009692
Jamie Madill54133512013-06-21 09:33:07 -04009693 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009694 UNIMPLEMENTED();
9695 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009696 }
9697 catch(std::bad_alloc&)
9698 {
9699 return gl::error(GL_OUT_OF_MEMORY);
9700 }
9701}
9702
9703void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9704{
9705 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9706 index, size, type, stride, pointer);
9707
9708 try
9709 {
9710 gl::Context *context = gl::getNonLostContext();
9711
9712 if (context)
9713 {
9714 if (context->getClientVersion() < 3)
9715 {
9716 return gl::error(GL_INVALID_OPERATION);
9717 }
9718 }
9719
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009720 if (index >= gl::MAX_VERTEX_ATTRIBS)
9721 {
9722 return gl::error(GL_INVALID_VALUE);
9723 }
9724
9725 if (size < 1 || size > 4)
9726 {
9727 return gl::error(GL_INVALID_VALUE);
9728 }
9729
9730 switch (type)
9731 {
9732 case GL_BYTE:
9733 case GL_UNSIGNED_BYTE:
9734 case GL_SHORT:
9735 case GL_UNSIGNED_SHORT:
9736 case GL_INT:
9737 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009738 case GL_INT_2_10_10_10_REV:
9739 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009740 break;
9741 default:
9742 return gl::error(GL_INVALID_ENUM);
9743 }
9744
9745 if (stride < 0)
9746 {
9747 return gl::error(GL_INVALID_VALUE);
9748 }
9749
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009750 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9751 {
9752 return gl::error(GL_INVALID_OPERATION);
9753 }
9754
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009755 if (context)
9756 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009757 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9758 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9759 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9760 // and the pointer argument is not NULL.
9761 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9762 {
9763 return gl::error(GL_INVALID_OPERATION);
9764 }
9765
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009766 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9767 stride, pointer);
9768 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009769 }
9770 catch(std::bad_alloc&)
9771 {
9772 return gl::error(GL_OUT_OF_MEMORY);
9773 }
9774}
9775
9776void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9777{
9778 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9779 index, pname, params);
9780
9781 try
9782 {
9783 gl::Context *context = gl::getNonLostContext();
9784
9785 if (context)
9786 {
9787 if (context->getClientVersion() < 3)
9788 {
9789 return gl::error(GL_INVALID_OPERATION);
9790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009791
Jamie Madilla7d05862013-07-02 11:57:06 -04009792 if (index >= gl::MAX_VERTEX_ATTRIBS)
9793 {
9794 return gl::error(GL_INVALID_VALUE);
9795 }
9796
9797 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9798
9799 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9800 {
9801 return;
9802 }
9803
9804 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9805 {
9806 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9807 for (int i = 0; i < 4; ++i)
9808 {
9809 params[i] = currentValueData.IntValues[i];
9810 }
9811 }
9812 else
9813 {
9814 *params = attribState.querySingleParameter<GLint>(pname);
9815 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009816 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009817 }
9818 catch(std::bad_alloc&)
9819 {
9820 return gl::error(GL_OUT_OF_MEMORY);
9821 }
9822}
9823
9824void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9825{
9826 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9827 index, pname, params);
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 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009839
Jamie Madilla7d05862013-07-02 11:57:06 -04009840 if (index >= gl::MAX_VERTEX_ATTRIBS)
9841 {
9842 return gl::error(GL_INVALID_VALUE);
9843 }
9844
9845 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9846
9847 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9848 {
9849 return;
9850 }
9851
9852 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9853 {
9854 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9855 for (int i = 0; i < 4; ++i)
9856 {
9857 params[i] = currentValueData.UnsignedIntValues[i];
9858 }
9859 }
9860 else
9861 {
9862 *params = attribState.querySingleParameter<GLuint>(pname);
9863 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009865 }
9866 catch(std::bad_alloc&)
9867 {
9868 return gl::error(GL_OUT_OF_MEMORY);
9869 }
9870}
9871
9872void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9873{
9874 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9875 index, x, y, z, w);
9876
9877 try
9878 {
9879 gl::Context *context = gl::getNonLostContext();
9880
9881 if (context)
9882 {
9883 if (context->getClientVersion() < 3)
9884 {
9885 return gl::error(GL_INVALID_OPERATION);
9886 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009887
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009888 if (index >= gl::MAX_VERTEX_ATTRIBS)
9889 {
9890 return gl::error(GL_INVALID_VALUE);
9891 }
9892
9893 GLint vals[4] = { x, y, z, w };
9894 context->setVertexAttribi(index, vals);
9895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009896 }
9897 catch(std::bad_alloc&)
9898 {
9899 return gl::error(GL_OUT_OF_MEMORY);
9900 }
9901}
9902
9903void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9904{
9905 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9906 index, x, y, z, w);
9907
9908 try
9909 {
9910 gl::Context *context = gl::getNonLostContext();
9911
9912 if (context)
9913 {
9914 if (context->getClientVersion() < 3)
9915 {
9916 return gl::error(GL_INVALID_OPERATION);
9917 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009918
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009919 if (index >= gl::MAX_VERTEX_ATTRIBS)
9920 {
9921 return gl::error(GL_INVALID_VALUE);
9922 }
9923
9924 GLuint vals[4] = { x, y, z, w };
9925 context->setVertexAttribu(index, vals);
9926 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009927 }
9928 catch(std::bad_alloc&)
9929 {
9930 return gl::error(GL_OUT_OF_MEMORY);
9931 }
9932}
9933
9934void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9935{
9936 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9937
9938 try
9939 {
9940 gl::Context *context = gl::getNonLostContext();
9941
9942 if (context)
9943 {
9944 if (context->getClientVersion() < 3)
9945 {
9946 return gl::error(GL_INVALID_OPERATION);
9947 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009948
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009949 if (index >= gl::MAX_VERTEX_ATTRIBS)
9950 {
9951 return gl::error(GL_INVALID_VALUE);
9952 }
9953
9954 context->setVertexAttribi(index, v);
9955 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009956 }
9957 catch(std::bad_alloc&)
9958 {
9959 return gl::error(GL_OUT_OF_MEMORY);
9960 }
9961}
9962
9963void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9964{
9965 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9966
9967 try
9968 {
9969 gl::Context *context = gl::getNonLostContext();
9970
9971 if (context)
9972 {
9973 if (context->getClientVersion() < 3)
9974 {
9975 return gl::error(GL_INVALID_OPERATION);
9976 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009977
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009978 if (index >= gl::MAX_VERTEX_ATTRIBS)
9979 {
9980 return gl::error(GL_INVALID_VALUE);
9981 }
9982
9983 context->setVertexAttribu(index, v);
9984 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009985 }
9986 catch(std::bad_alloc&)
9987 {
9988 return gl::error(GL_OUT_OF_MEMORY);
9989 }
9990}
9991
9992void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9993{
9994 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9995 program, location, params);
9996
9997 try
9998 {
9999 gl::Context *context = gl::getNonLostContext();
10000
10001 if (context)
10002 {
10003 if (context->getClientVersion() < 3)
10004 {
10005 return gl::error(GL_INVALID_OPERATION);
10006 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010007
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +000010008 if (program == 0)
10009 {
10010 return gl::error(GL_INVALID_VALUE);
10011 }
10012
10013 gl::Program *programObject = context->getProgram(program);
10014
10015 if (!programObject || !programObject->isLinked())
10016 {
10017 return gl::error(GL_INVALID_OPERATION);
10018 }
10019
10020 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10021 if (!programBinary)
10022 {
10023 return gl::error(GL_INVALID_OPERATION);
10024 }
10025
10026 if (!programBinary->getUniformuiv(location, NULL, params))
10027 {
10028 return gl::error(GL_INVALID_OPERATION);
10029 }
10030 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010031 }
10032 catch(std::bad_alloc&)
10033 {
10034 return gl::error(GL_OUT_OF_MEMORY);
10035 }
10036}
10037
10038GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10039{
10040 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10041 program, name);
10042
10043 try
10044 {
10045 gl::Context *context = gl::getNonLostContext();
10046
10047 if (context)
10048 {
10049 if (context->getClientVersion() < 3)
10050 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010051 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010052 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010053
Jamie Madilld1e78c92013-06-20 11:55:50 -040010054 if (program == 0)
10055 {
10056 return gl::error(GL_INVALID_VALUE, -1);
10057 }
10058
10059 gl::Program *programObject = context->getProgram(program);
10060
10061 if (!programObject || !programObject->isLinked())
10062 {
10063 return gl::error(GL_INVALID_OPERATION, -1);
10064 }
10065
10066 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10067 if (!programBinary)
10068 {
10069 return gl::error(GL_INVALID_OPERATION, -1);
10070 }
10071
10072 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010073 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010074 }
10075 catch(std::bad_alloc&)
10076 {
10077 return gl::error(GL_OUT_OF_MEMORY, 0);
10078 }
10079
10080 return 0;
10081}
10082
10083void __stdcall glUniform1ui(GLint location, GLuint v0)
10084{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010085 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010086}
10087
10088void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10089{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010090 const GLuint xy[] = { v0, v1 };
10091 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010092}
10093
10094void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10095{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010096 const GLuint xyz[] = { v0, v1, v2 };
10097 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010098}
10099
10100void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10101{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010102 const GLuint xyzw[] = { v0, v1, v2, v3 };
10103 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010104}
10105
10106void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10107{
10108 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10109 location, count, value);
10110
10111 try
10112 {
10113 gl::Context *context = gl::getNonLostContext();
10114
10115 if (context)
10116 {
10117 if (context->getClientVersion() < 3)
10118 {
10119 return gl::error(GL_INVALID_OPERATION);
10120 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010121
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010122 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10123 if (!programBinary)
10124 {
10125 return gl::error(GL_INVALID_OPERATION);
10126 }
10127
10128 if (!programBinary->setUniform1uiv(location, count, value))
10129 {
10130 return gl::error(GL_INVALID_OPERATION);
10131 }
10132 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010133 }
10134 catch(std::bad_alloc&)
10135 {
10136 return gl::error(GL_OUT_OF_MEMORY);
10137 }
10138}
10139
10140void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10141{
10142 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10143 location, count, value);
10144
10145 try
10146 {
10147 gl::Context *context = gl::getNonLostContext();
10148
10149 if (context)
10150 {
10151 if (context->getClientVersion() < 3)
10152 {
10153 return gl::error(GL_INVALID_OPERATION);
10154 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010155
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010156 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10157 if (!programBinary)
10158 {
10159 return gl::error(GL_INVALID_OPERATION);
10160 }
10161
10162 if (!programBinary->setUniform2uiv(location, count, value))
10163 {
10164 return gl::error(GL_INVALID_OPERATION);
10165 }
10166 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010167 }
10168 catch(std::bad_alloc&)
10169 {
10170 return gl::error(GL_OUT_OF_MEMORY);
10171 }
10172}
10173
10174void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10175{
10176 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10177 location, count, value);
10178
10179 try
10180 {
10181 gl::Context *context = gl::getNonLostContext();
10182
10183 if (context)
10184 {
10185 if (context->getClientVersion() < 3)
10186 {
10187 return gl::error(GL_INVALID_OPERATION);
10188 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010189
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010190 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10191 if (!programBinary)
10192 {
10193 return gl::error(GL_INVALID_OPERATION);
10194 }
10195
10196 if (!programBinary->setUniform3uiv(location, count, value))
10197 {
10198 return gl::error(GL_INVALID_OPERATION);
10199 }
10200 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010201 }
10202 catch(std::bad_alloc&)
10203 {
10204 return gl::error(GL_OUT_OF_MEMORY);
10205 }
10206}
10207
10208void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10209{
10210 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10211 location, count, value);
10212
10213 try
10214 {
10215 gl::Context *context = gl::getNonLostContext();
10216
10217 if (context)
10218 {
10219 if (context->getClientVersion() < 3)
10220 {
10221 return gl::error(GL_INVALID_OPERATION);
10222 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010223
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010224 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10225 if (!programBinary)
10226 {
10227 return gl::error(GL_INVALID_OPERATION);
10228 }
10229
10230 if (!programBinary->setUniform4uiv(location, count, value))
10231 {
10232 return gl::error(GL_INVALID_OPERATION);
10233 }
10234 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010235 }
10236 catch(std::bad_alloc&)
10237 {
10238 return gl::error(GL_OUT_OF_MEMORY);
10239 }
10240}
10241
10242void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10243{
10244 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10245 buffer, drawbuffer, value);
10246
10247 try
10248 {
10249 gl::Context *context = gl::getNonLostContext();
10250
10251 if (context)
10252 {
10253 if (context->getClientVersion() < 3)
10254 {
10255 return gl::error(GL_INVALID_OPERATION);
10256 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010257
Jamie Madill54133512013-06-21 09:33:07 -040010258 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010259 UNIMPLEMENTED();
10260 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010261 }
10262 catch(std::bad_alloc&)
10263 {
10264 return gl::error(GL_OUT_OF_MEMORY);
10265 }
10266}
10267
10268void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10269{
10270 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10271 buffer, drawbuffer, value);
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 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010283
Jamie Madill54133512013-06-21 09:33:07 -040010284 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010285 UNIMPLEMENTED();
10286 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010287 }
10288 catch(std::bad_alloc&)
10289 {
10290 return gl::error(GL_OUT_OF_MEMORY);
10291 }
10292}
10293
10294void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10295{
10296 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10297 buffer, drawbuffer, value);
10298
10299 try
10300 {
10301 gl::Context *context = gl::getNonLostContext();
10302
10303 if (context)
10304 {
10305 if (context->getClientVersion() < 3)
10306 {
10307 return gl::error(GL_INVALID_OPERATION);
10308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010309
Jamie Madill54133512013-06-21 09:33:07 -040010310 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010311 UNIMPLEMENTED();
10312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010313 }
10314 catch(std::bad_alloc&)
10315 {
10316 return gl::error(GL_OUT_OF_MEMORY);
10317 }
10318}
10319
10320void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10321{
10322 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10323 buffer, drawbuffer, depth, stencil);
10324
10325 try
10326 {
10327 gl::Context *context = gl::getNonLostContext();
10328
10329 if (context)
10330 {
10331 if (context->getClientVersion() < 3)
10332 {
10333 return gl::error(GL_INVALID_OPERATION);
10334 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010335
Jamie Madill54133512013-06-21 09:33:07 -040010336 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010337 UNIMPLEMENTED();
10338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010339 }
10340 catch(std::bad_alloc&)
10341 {
10342 return gl::error(GL_OUT_OF_MEMORY);
10343 }
10344}
10345
10346const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10347{
10348 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10349
10350 try
10351 {
10352 gl::Context *context = gl::getNonLostContext();
10353
10354 if (context)
10355 {
10356 if (context->getClientVersion() < 3)
10357 {
10358 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10359 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010360
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010361 if (name != GL_EXTENSIONS)
10362 {
10363 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10364 }
10365
10366 if (index >= context->getNumExtensions())
10367 {
10368 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10369 }
10370
10371 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10372 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010373 }
10374 catch(std::bad_alloc&)
10375 {
10376 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10377 }
10378
10379 return NULL;
10380}
10381
10382void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10383{
10384 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10385 readTarget, writeTarget, readOffset, writeOffset, size);
10386
10387 try
10388 {
10389 gl::Context *context = gl::getNonLostContext();
10390
10391 if (context)
10392 {
10393 if (context->getClientVersion() < 3)
10394 {
10395 return gl::error(GL_INVALID_OPERATION);
10396 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010397
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010398 gl::Buffer *readBuffer = NULL;
10399 switch (readTarget)
10400 {
10401 case GL_ARRAY_BUFFER:
10402 readBuffer = context->getArrayBuffer();
10403 break;
10404 case GL_COPY_READ_BUFFER:
10405 readBuffer = context->getCopyReadBuffer();
10406 break;
10407 case GL_COPY_WRITE_BUFFER:
10408 readBuffer = context->getCopyWriteBuffer();
10409 break;
10410 case GL_ELEMENT_ARRAY_BUFFER:
10411 readBuffer = context->getElementArrayBuffer();
10412 break;
10413 case GL_PIXEL_PACK_BUFFER:
10414 readBuffer = context->getPixelPackBuffer();
10415 break;
10416 case GL_PIXEL_UNPACK_BUFFER:
10417 readBuffer = context->getPixelUnpackBuffer();
10418 break;
10419 case GL_TRANSFORM_FEEDBACK_BUFFER:
10420 readBuffer = context->getGenericTransformFeedbackBuffer();
10421 break;
10422 case GL_UNIFORM_BUFFER:
10423 readBuffer = context->getGenericUniformBuffer();
10424 break;
10425 default:
10426 return gl::error(GL_INVALID_ENUM);
10427 }
10428
10429 gl::Buffer *writeBuffer = NULL;
10430 switch (writeTarget)
10431 {
10432 case GL_ARRAY_BUFFER:
10433 writeBuffer = context->getArrayBuffer();
10434 break;
10435 case GL_COPY_READ_BUFFER:
10436 writeBuffer = context->getCopyReadBuffer();
10437 break;
10438 case GL_COPY_WRITE_BUFFER:
10439 writeBuffer = context->getCopyWriteBuffer();
10440 break;
10441 case GL_ELEMENT_ARRAY_BUFFER:
10442 writeBuffer = context->getElementArrayBuffer();
10443 break;
10444 case GL_PIXEL_PACK_BUFFER:
10445 writeBuffer = context->getPixelPackBuffer();
10446 break;
10447 case GL_PIXEL_UNPACK_BUFFER:
10448 writeBuffer = context->getPixelUnpackBuffer();
10449 break;
10450 case GL_TRANSFORM_FEEDBACK_BUFFER:
10451 writeBuffer = context->getGenericTransformFeedbackBuffer();
10452 break;
10453 case GL_UNIFORM_BUFFER:
10454 writeBuffer = context->getGenericUniformBuffer();
10455 break;
10456 default:
10457 return gl::error(GL_INVALID_ENUM);
10458 }
10459
10460 if (!readBuffer || !writeBuffer)
10461 {
10462 return gl::error(GL_INVALID_OPERATION);
10463 }
10464
10465 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10466 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10467 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10468 {
10469 return gl::error(GL_INVALID_VALUE);
10470 }
10471
10472 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10473 {
10474 return gl::error(GL_INVALID_VALUE);
10475 }
10476
10477 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10478
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010479 // if size is zero, the copy is a successful no-op
10480 if (size > 0)
10481 {
10482 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10483 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010484 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010485 }
10486 catch(std::bad_alloc&)
10487 {
10488 return gl::error(GL_OUT_OF_MEMORY);
10489 }
10490}
10491
10492void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10493{
10494 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10495 program, uniformCount, uniformNames, uniformIndices);
10496
10497 try
10498 {
10499 gl::Context *context = gl::getNonLostContext();
10500
10501 if (context)
10502 {
10503 if (context->getClientVersion() < 3)
10504 {
10505 return gl::error(GL_INVALID_OPERATION);
10506 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010507
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010508 if (uniformCount < 0)
10509 {
10510 return gl::error(GL_INVALID_VALUE);
10511 }
10512
10513 gl::Program *programObject = context->getProgram(program);
10514
10515 if (!programObject)
10516 {
10517 if (context->getShader(program))
10518 {
10519 return gl::error(GL_INVALID_OPERATION);
10520 }
10521 else
10522 {
10523 return gl::error(GL_INVALID_VALUE);
10524 }
10525 }
10526
10527 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10528 if (!programObject->isLinked() || !programBinary)
10529 {
10530 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10531 {
10532 uniformIndices[uniformId] = GL_INVALID_INDEX;
10533 }
10534 }
10535 else
10536 {
10537 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10538 {
10539 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10540 }
10541 }
10542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010543 }
10544 catch(std::bad_alloc&)
10545 {
10546 return gl::error(GL_OUT_OF_MEMORY);
10547 }
10548}
10549
10550void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10551{
10552 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10553 program, uniformCount, uniformIndices, pname, params);
10554
10555 try
10556 {
10557 gl::Context *context = gl::getNonLostContext();
10558
10559 if (context)
10560 {
10561 if (context->getClientVersion() < 3)
10562 {
10563 return gl::error(GL_INVALID_OPERATION);
10564 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010565
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010566 if (uniformCount < 0)
10567 {
10568 return gl::error(GL_INVALID_VALUE);
10569 }
10570
10571 gl::Program *programObject = context->getProgram(program);
10572
10573 if (!programObject)
10574 {
10575 if (context->getShader(program))
10576 {
10577 return gl::error(GL_INVALID_OPERATION);
10578 }
10579 else
10580 {
10581 return gl::error(GL_INVALID_VALUE);
10582 }
10583 }
10584
10585 switch (pname)
10586 {
10587 case GL_UNIFORM_TYPE:
10588 case GL_UNIFORM_SIZE:
10589 case GL_UNIFORM_NAME_LENGTH:
10590 case GL_UNIFORM_BLOCK_INDEX:
10591 case GL_UNIFORM_OFFSET:
10592 case GL_UNIFORM_ARRAY_STRIDE:
10593 case GL_UNIFORM_MATRIX_STRIDE:
10594 case GL_UNIFORM_IS_ROW_MAJOR:
10595 break;
10596 default:
10597 return gl::error(GL_INVALID_ENUM);
10598 }
10599
10600 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10601
10602 if (!programBinary && uniformCount > 0)
10603 {
10604 return gl::error(GL_INVALID_VALUE);
10605 }
10606
10607 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10608 {
10609 const GLuint index = uniformIndices[uniformId];
10610
10611 if (index >= (GLuint)programBinary->getActiveUniformCount())
10612 {
10613 return gl::error(GL_INVALID_VALUE);
10614 }
10615 }
10616
10617 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10618 {
10619 const GLuint index = uniformIndices[uniformId];
10620 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10621 }
10622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010623 }
10624 catch(std::bad_alloc&)
10625 {
10626 return gl::error(GL_OUT_OF_MEMORY);
10627 }
10628}
10629
10630GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10631{
10632 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10633
10634 try
10635 {
10636 gl::Context *context = gl::getNonLostContext();
10637
10638 if (context)
10639 {
10640 if (context->getClientVersion() < 3)
10641 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010642 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010643 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010644
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010645 gl::Program *programObject = context->getProgram(program);
10646
10647 if (!programObject)
10648 {
10649 if (context->getShader(program))
10650 {
10651 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10652 }
10653 else
10654 {
10655 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10656 }
10657 }
10658
10659 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10660 if (!programBinary)
10661 {
10662 return GL_INVALID_INDEX;
10663 }
10664
10665 return programBinary->getUniformBlockIndex(uniformBlockName);
10666 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010667 }
10668 catch(std::bad_alloc&)
10669 {
10670 return gl::error(GL_OUT_OF_MEMORY, 0);
10671 }
10672
10673 return 0;
10674}
10675
10676void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10677{
10678 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10679 program, uniformBlockIndex, pname, params);
10680
10681 try
10682 {
10683 gl::Context *context = gl::getNonLostContext();
10684
10685 if (context)
10686 {
10687 if (context->getClientVersion() < 3)
10688 {
10689 return gl::error(GL_INVALID_OPERATION);
10690 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010691 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010692
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010693 if (!programObject)
10694 {
10695 if (context->getShader(program))
10696 {
10697 return gl::error(GL_INVALID_OPERATION);
10698 }
10699 else
10700 {
10701 return gl::error(GL_INVALID_VALUE);
10702 }
10703 }
10704
10705 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10706
10707 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10708 {
10709 return gl::error(GL_INVALID_VALUE);
10710 }
10711
10712 switch (pname)
10713 {
10714 case GL_UNIFORM_BLOCK_BINDING:
10715 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10716 break;
10717
10718 case GL_UNIFORM_BLOCK_DATA_SIZE:
10719 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10720 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10721 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10722 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10723 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10724 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10725 break;
10726
10727 default:
10728 return gl::error(GL_INVALID_ENUM);
10729 }
10730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010731 }
10732 catch(std::bad_alloc&)
10733 {
10734 return gl::error(GL_OUT_OF_MEMORY);
10735 }
10736}
10737
10738void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10739{
10740 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10741 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10742
10743 try
10744 {
10745 gl::Context *context = gl::getNonLostContext();
10746
10747 if (context)
10748 {
10749 if (context->getClientVersion() < 3)
10750 {
10751 return gl::error(GL_INVALID_OPERATION);
10752 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010753
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010754 gl::Program *programObject = context->getProgram(program);
10755
10756 if (!programObject)
10757 {
10758 if (context->getShader(program))
10759 {
10760 return gl::error(GL_INVALID_OPERATION);
10761 }
10762 else
10763 {
10764 return gl::error(GL_INVALID_VALUE);
10765 }
10766 }
10767
10768 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10769
10770 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10771 {
10772 return gl::error(GL_INVALID_VALUE);
10773 }
10774
10775 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10776 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010777 }
10778 catch(std::bad_alloc&)
10779 {
10780 return gl::error(GL_OUT_OF_MEMORY);
10781 }
10782}
10783
10784void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10785{
10786 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10787 program, uniformBlockIndex, uniformBlockBinding);
10788
10789 try
10790 {
10791 gl::Context *context = gl::getNonLostContext();
10792
10793 if (context)
10794 {
10795 if (context->getClientVersion() < 3)
10796 {
10797 return gl::error(GL_INVALID_OPERATION);
10798 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010799
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010800 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10801 {
10802 return gl::error(GL_INVALID_VALUE);
10803 }
10804
10805 gl::Program *programObject = context->getProgram(program);
10806
10807 if (!programObject)
10808 {
10809 if (context->getShader(program))
10810 {
10811 return gl::error(GL_INVALID_OPERATION);
10812 }
10813 else
10814 {
10815 return gl::error(GL_INVALID_VALUE);
10816 }
10817 }
10818
10819 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10820
10821 // if never linked, there won't be any uniform blocks
10822 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10823 {
10824 return gl::error(GL_INVALID_VALUE);
10825 }
10826
10827 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10828 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010829 }
10830 catch(std::bad_alloc&)
10831 {
10832 return gl::error(GL_OUT_OF_MEMORY);
10833 }
10834}
10835
10836void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10837{
10838 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10839 mode, first, count, instanceCount);
10840
10841 try
10842 {
10843 gl::Context *context = gl::getNonLostContext();
10844
10845 if (context)
10846 {
10847 if (context->getClientVersion() < 3)
10848 {
10849 return gl::error(GL_INVALID_OPERATION);
10850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010851
Jamie Madill54133512013-06-21 09:33:07 -040010852 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010853 UNIMPLEMENTED();
10854 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010855 }
10856 catch(std::bad_alloc&)
10857 {
10858 return gl::error(GL_OUT_OF_MEMORY);
10859 }
10860}
10861
10862void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10863{
10864 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10865 mode, count, type, indices, instanceCount);
10866
10867 try
10868 {
10869 gl::Context *context = gl::getNonLostContext();
10870
10871 if (context)
10872 {
10873 if (context->getClientVersion() < 3)
10874 {
10875 return gl::error(GL_INVALID_OPERATION);
10876 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010877
Jamie Madill54133512013-06-21 09:33:07 -040010878 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010879 UNIMPLEMENTED();
10880 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010881 }
10882 catch(std::bad_alloc&)
10883 {
10884 return gl::error(GL_OUT_OF_MEMORY);
10885 }
10886}
10887
10888GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10889{
10890 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10891
10892 try
10893 {
10894 gl::Context *context = gl::getNonLostContext();
10895
10896 if (context)
10897 {
10898 if (context->getClientVersion() < 3)
10899 {
10900 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10901 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010902
Jamie Madill54133512013-06-21 09:33:07 -040010903 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010904 UNIMPLEMENTED();
10905 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010906 }
10907 catch(std::bad_alloc&)
10908 {
10909 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10910 }
10911
10912 return NULL;
10913}
10914
10915GLboolean __stdcall glIsSync(GLsync sync)
10916{
10917 EVENT("(GLsync sync = 0x%0.8p)", sync);
10918
10919 try
10920 {
10921 gl::Context *context = gl::getNonLostContext();
10922
10923 if (context)
10924 {
10925 if (context->getClientVersion() < 3)
10926 {
10927 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10928 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010929
Jamie Madill54133512013-06-21 09:33:07 -040010930 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010931 UNIMPLEMENTED();
10932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010933 }
10934 catch(std::bad_alloc&)
10935 {
10936 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10937 }
10938
10939 return GL_FALSE;
10940}
10941
10942void __stdcall glDeleteSync(GLsync sync)
10943{
10944 EVENT("(GLsync sync = 0x%0.8p)", sync);
10945
10946 try
10947 {
10948 gl::Context *context = gl::getNonLostContext();
10949
10950 if (context)
10951 {
10952 if (context->getClientVersion() < 3)
10953 {
10954 return gl::error(GL_INVALID_OPERATION);
10955 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010956
Jamie Madill54133512013-06-21 09:33:07 -040010957 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010958 UNIMPLEMENTED();
10959 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010960 }
10961 catch(std::bad_alloc&)
10962 {
10963 return gl::error(GL_OUT_OF_MEMORY);
10964 }
10965}
10966
10967GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10968{
10969 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10970 sync, flags, timeout);
10971
10972 try
10973 {
10974 gl::Context *context = gl::getNonLostContext();
10975
10976 if (context)
10977 {
10978 if (context->getClientVersion() < 3)
10979 {
10980 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10981 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010982
Jamie Madill54133512013-06-21 09:33:07 -040010983 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010984 UNIMPLEMENTED();
10985 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010986 }
10987 catch(std::bad_alloc&)
10988 {
10989 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10990 }
10991
10992 return GL_FALSE;
10993}
10994
10995void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10996{
10997 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10998 sync, flags, timeout);
10999
11000 try
11001 {
11002 gl::Context *context = gl::getNonLostContext();
11003
11004 if (context)
11005 {
11006 if (context->getClientVersion() < 3)
11007 {
11008 return gl::error(GL_INVALID_OPERATION);
11009 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011010
Jamie Madill54133512013-06-21 09:33:07 -040011011 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011012 UNIMPLEMENTED();
11013 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011014 }
11015 catch(std::bad_alloc&)
11016 {
11017 return gl::error(GL_OUT_OF_MEMORY);
11018 }
11019}
11020
11021void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
11022{
11023 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11024 pname, params);
11025
11026 try
11027 {
11028 gl::Context *context = gl::getNonLostContext();
11029
11030 if (context)
11031 {
11032 if (context->getClientVersion() < 3)
11033 {
11034 return gl::error(GL_INVALID_OPERATION);
11035 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011036
Jamie Madill71fbd602013-07-19 16:36:55 -040011037 if (!(context->getInteger64v(pname, params)))
11038 {
11039 GLenum nativeType;
11040 unsigned int numParams = 0;
11041 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11042 return gl::error(GL_INVALID_ENUM);
11043
11044 if (numParams == 0)
11045 return; // it is known that the pname is valid, but that there are no parameters to return.
11046
11047 if (nativeType == GL_BOOL)
11048 {
11049 GLboolean *boolParams = NULL;
11050 boolParams = new GLboolean[numParams];
11051
11052 context->getBooleanv(pname, boolParams);
11053
11054 for (unsigned int i = 0; i < numParams; ++i)
11055 {
11056 if (boolParams[i] == GL_FALSE)
11057 params[i] = 0;
11058 else
11059 params[i] = 1;
11060 }
11061
11062 delete [] boolParams;
11063 }
11064 else if (nativeType == GL_INT)
11065 {
11066 GLint *intParams = NULL;
11067 intParams = new GLint[numParams];
11068
11069 context->getIntegerv(pname, intParams);
11070
11071 for (unsigned int i = 0; i < numParams; ++i)
11072 {
11073 params[i] = static_cast<GLint64>(intParams[i]);
11074 }
11075
11076 delete [] intParams;
11077 }
11078 else if (nativeType == GL_FLOAT)
11079 {
11080 GLfloat *floatParams = NULL;
11081 floatParams = new GLfloat[numParams];
11082
11083 context->getFloatv(pname, floatParams);
11084
11085 for (unsigned int i = 0; i < numParams; ++i)
11086 {
11087 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11088 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11089 {
11090 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11091 }
11092 else
11093 {
11094 params[i] = gl::iround<GLint64>(floatParams[i]);
11095 }
11096 }
11097
11098 delete [] floatParams;
11099 }
11100 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011101 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011102 }
11103 catch(std::bad_alloc&)
11104 {
11105 return gl::error(GL_OUT_OF_MEMORY);
11106 }
11107}
11108
11109void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11110{
11111 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11112 sync, pname, bufSize, length, values);
11113
11114 try
11115 {
11116 gl::Context *context = gl::getNonLostContext();
11117
11118 if (context)
11119 {
11120 if (context->getClientVersion() < 3)
11121 {
11122 return gl::error(GL_INVALID_OPERATION);
11123 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011124
Jamie Madill54133512013-06-21 09:33:07 -040011125 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011126 UNIMPLEMENTED();
11127 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011128 }
11129 catch(std::bad_alloc&)
11130 {
11131 return gl::error(GL_OUT_OF_MEMORY);
11132 }
11133}
11134
11135void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11136{
11137 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11138 target, index, data);
11139
11140 try
11141 {
11142 gl::Context *context = gl::getNonLostContext();
11143
11144 if (context)
11145 {
11146 if (context->getClientVersion() < 3)
11147 {
11148 return gl::error(GL_INVALID_OPERATION);
11149 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011150
Jamie Madill54133512013-06-21 09:33:07 -040011151 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011152 UNIMPLEMENTED();
11153 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011154 }
11155 catch(std::bad_alloc&)
11156 {
11157 return gl::error(GL_OUT_OF_MEMORY);
11158 }
11159}
11160
11161void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11162{
11163 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11164 target, pname, params);
11165
11166 try
11167 {
11168 gl::Context *context = gl::getNonLostContext();
11169
11170 if (context)
11171 {
11172 if (context->getClientVersion() < 3)
11173 {
11174 return gl::error(GL_INVALID_OPERATION);
11175 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011176
Jamie Madill54133512013-06-21 09:33:07 -040011177 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011178 UNIMPLEMENTED();
11179 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011180 }
11181 catch(std::bad_alloc&)
11182 {
11183 return gl::error(GL_OUT_OF_MEMORY);
11184 }
11185}
11186
11187void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11188{
11189 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11190
11191 try
11192 {
11193 gl::Context *context = gl::getNonLostContext();
11194
11195 if (context)
11196 {
11197 if (context->getClientVersion() < 3)
11198 {
11199 return gl::error(GL_INVALID_OPERATION);
11200 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011201
Jamie Madill54133512013-06-21 09:33:07 -040011202 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011203 UNIMPLEMENTED();
11204 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011205 }
11206 catch(std::bad_alloc&)
11207 {
11208 return gl::error(GL_OUT_OF_MEMORY);
11209 }
11210}
11211
11212void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11213{
11214 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11215
11216 try
11217 {
11218 gl::Context *context = gl::getNonLostContext();
11219
11220 if (context)
11221 {
11222 if (context->getClientVersion() < 3)
11223 {
11224 return gl::error(GL_INVALID_OPERATION);
11225 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011226
Jamie Madill54133512013-06-21 09:33:07 -040011227 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011228 UNIMPLEMENTED();
11229 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011230 }
11231 catch(std::bad_alloc&)
11232 {
11233 return gl::error(GL_OUT_OF_MEMORY);
11234 }
11235}
11236
11237GLboolean __stdcall glIsSampler(GLuint sampler)
11238{
11239 EVENT("(GLuint sampler = %u)", sampler);
11240
11241 try
11242 {
11243 gl::Context *context = gl::getNonLostContext();
11244
11245 if (context)
11246 {
11247 if (context->getClientVersion() < 3)
11248 {
11249 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11250 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011251
Jamie Madill54133512013-06-21 09:33:07 -040011252 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011253 UNIMPLEMENTED();
11254 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011255 }
11256 catch(std::bad_alloc&)
11257 {
11258 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11259 }
11260
11261 return GL_FALSE;
11262}
11263
11264void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11265{
11266 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11267
11268 try
11269 {
11270 gl::Context *context = gl::getNonLostContext();
11271
11272 if (context)
11273 {
11274 if (context->getClientVersion() < 3)
11275 {
11276 return gl::error(GL_INVALID_OPERATION);
11277 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011278
Jamie Madill54133512013-06-21 09:33:07 -040011279 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011280 UNIMPLEMENTED();
11281 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011282 }
11283 catch(std::bad_alloc&)
11284 {
11285 return gl::error(GL_OUT_OF_MEMORY);
11286 }
11287}
11288
11289void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11290{
11291 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11292
11293 try
11294 {
11295 gl::Context *context = gl::getNonLostContext();
11296
11297 if (context)
11298 {
11299 if (context->getClientVersion() < 3)
11300 {
11301 return gl::error(GL_INVALID_OPERATION);
11302 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011303
Jamie Madill54133512013-06-21 09:33:07 -040011304 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011305 UNIMPLEMENTED();
11306 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011307 }
11308 catch(std::bad_alloc&)
11309 {
11310 return gl::error(GL_OUT_OF_MEMORY);
11311 }
11312}
11313
11314void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11315{
11316 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11317 sampler, pname, param);
11318
11319 try
11320 {
11321 gl::Context *context = gl::getNonLostContext();
11322
11323 if (context)
11324 {
11325 if (context->getClientVersion() < 3)
11326 {
11327 return gl::error(GL_INVALID_OPERATION);
11328 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011329
Jamie Madill54133512013-06-21 09:33:07 -040011330 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011331 UNIMPLEMENTED();
11332 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011333 }
11334 catch(std::bad_alloc&)
11335 {
11336 return gl::error(GL_OUT_OF_MEMORY);
11337 }
11338}
11339
11340void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11341{
11342 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11343
11344 try
11345 {
11346 gl::Context *context = gl::getNonLostContext();
11347
11348 if (context)
11349 {
11350 if (context->getClientVersion() < 3)
11351 {
11352 return gl::error(GL_INVALID_OPERATION);
11353 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011354
Jamie Madill54133512013-06-21 09:33:07 -040011355 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011356 UNIMPLEMENTED();
11357 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011358 }
11359 catch(std::bad_alloc&)
11360 {
11361 return gl::error(GL_OUT_OF_MEMORY);
11362 }
11363}
11364
11365void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11366{
11367 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11368
11369 try
11370 {
11371 gl::Context *context = gl::getNonLostContext();
11372
11373 if (context)
11374 {
11375 if (context->getClientVersion() < 3)
11376 {
11377 return gl::error(GL_INVALID_OPERATION);
11378 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011379
Jamie Madill54133512013-06-21 09:33:07 -040011380 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011381 UNIMPLEMENTED();
11382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011383 }
11384 catch(std::bad_alloc&)
11385 {
11386 return gl::error(GL_OUT_OF_MEMORY);
11387 }
11388}
11389
11390void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11391{
11392 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11393
11394 try
11395 {
11396 gl::Context *context = gl::getNonLostContext();
11397
11398 if (context)
11399 {
11400 if (context->getClientVersion() < 3)
11401 {
11402 return gl::error(GL_INVALID_OPERATION);
11403 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011404
Jamie Madill54133512013-06-21 09:33:07 -040011405 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011406 UNIMPLEMENTED();
11407 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011408 }
11409 catch(std::bad_alloc&)
11410 {
11411 return gl::error(GL_OUT_OF_MEMORY);
11412 }
11413}
11414
11415void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11416{
11417 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11418
11419 try
11420 {
11421 gl::Context *context = gl::getNonLostContext();
11422
11423 if (context)
11424 {
11425 if (context->getClientVersion() < 3)
11426 {
11427 return gl::error(GL_INVALID_OPERATION);
11428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011429
Jamie Madill54133512013-06-21 09:33:07 -040011430 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011431 UNIMPLEMENTED();
11432 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011433 }
11434 catch(std::bad_alloc&)
11435 {
11436 return gl::error(GL_OUT_OF_MEMORY);
11437 }
11438}
11439
11440void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11441{
11442 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11443
11444 try
11445 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011446 if (index >= gl::MAX_VERTEX_ATTRIBS)
11447 {
11448 return gl::error(GL_INVALID_VALUE);
11449 }
11450
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011451 gl::Context *context = gl::getNonLostContext();
11452
11453 if (context)
11454 {
11455 if (context->getClientVersion() < 3)
11456 {
11457 return gl::error(GL_INVALID_OPERATION);
11458 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011459
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011460 context->setVertexAttribDivisor(index, divisor);
11461 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011462 }
11463 catch(std::bad_alloc&)
11464 {
11465 return gl::error(GL_OUT_OF_MEMORY);
11466 }
11467}
11468
11469void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11470{
11471 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11472
11473 try
11474 {
11475 gl::Context *context = gl::getNonLostContext();
11476
11477 if (context)
11478 {
11479 if (context->getClientVersion() < 3)
11480 {
11481 return gl::error(GL_INVALID_OPERATION);
11482 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011483
Jamie Madill54133512013-06-21 09:33:07 -040011484 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011485 UNIMPLEMENTED();
11486 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011487 }
11488 catch(std::bad_alloc&)
11489 {
11490 return gl::error(GL_OUT_OF_MEMORY);
11491 }
11492}
11493
11494void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11495{
11496 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11497
11498 try
11499 {
11500 gl::Context *context = gl::getNonLostContext();
11501
11502 if (context)
11503 {
11504 if (context->getClientVersion() < 3)
11505 {
11506 return gl::error(GL_INVALID_OPERATION);
11507 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011508
Jamie Madill54133512013-06-21 09:33:07 -040011509 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011510 UNIMPLEMENTED();
11511 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011512 }
11513 catch(std::bad_alloc&)
11514 {
11515 return gl::error(GL_OUT_OF_MEMORY);
11516 }
11517}
11518
11519void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11520{
11521 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11522
11523 try
11524 {
11525 gl::Context *context = gl::getNonLostContext();
11526
11527 if (context)
11528 {
11529 if (context->getClientVersion() < 3)
11530 {
11531 return gl::error(GL_INVALID_OPERATION);
11532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011533
Jamie Madill54133512013-06-21 09:33:07 -040011534 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011535 UNIMPLEMENTED();
11536 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011537 }
11538 catch(std::bad_alloc&)
11539 {
11540 return gl::error(GL_OUT_OF_MEMORY);
11541 }
11542}
11543
11544GLboolean __stdcall glIsTransformFeedback(GLuint id)
11545{
11546 EVENT("(GLuint id = %u)", id);
11547
11548 try
11549 {
11550 gl::Context *context = gl::getNonLostContext();
11551
11552 if (context)
11553 {
11554 if (context->getClientVersion() < 3)
11555 {
11556 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11557 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011558
Jamie Madill54133512013-06-21 09:33:07 -040011559 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011560 UNIMPLEMENTED();
11561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011562 }
11563 catch(std::bad_alloc&)
11564 {
11565 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11566 }
11567
11568 return GL_FALSE;
11569}
11570
11571void __stdcall glPauseTransformFeedback(void)
11572{
11573 EVENT("(void)");
11574
11575 try
11576 {
11577 gl::Context *context = gl::getNonLostContext();
11578
11579 if (context)
11580 {
11581 if (context->getClientVersion() < 3)
11582 {
11583 return gl::error(GL_INVALID_OPERATION);
11584 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011585
Jamie Madill54133512013-06-21 09:33:07 -040011586 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011587 UNIMPLEMENTED();
11588 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011589 }
11590 catch(std::bad_alloc&)
11591 {
11592 return gl::error(GL_OUT_OF_MEMORY);
11593 }
11594}
11595
11596void __stdcall glResumeTransformFeedback(void)
11597{
11598 EVENT("(void)");
11599
11600 try
11601 {
11602 gl::Context *context = gl::getNonLostContext();
11603
11604 if (context)
11605 {
11606 if (context->getClientVersion() < 3)
11607 {
11608 return gl::error(GL_INVALID_OPERATION);
11609 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011610
Jamie Madill54133512013-06-21 09:33:07 -040011611 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011612 UNIMPLEMENTED();
11613 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011614 }
11615 catch(std::bad_alloc&)
11616 {
11617 return gl::error(GL_OUT_OF_MEMORY);
11618 }
11619}
11620
11621void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11622{
11623 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11624 program, bufSize, length, binaryFormat, binary);
11625
11626 try
11627 {
11628 gl::Context *context = gl::getNonLostContext();
11629
11630 if (context)
11631 {
11632 if (context->getClientVersion() < 3)
11633 {
11634 return gl::error(GL_INVALID_OPERATION);
11635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011636
Jamie Madill54133512013-06-21 09:33:07 -040011637 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011638 UNIMPLEMENTED();
11639 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011640 }
11641 catch(std::bad_alloc&)
11642 {
11643 return gl::error(GL_OUT_OF_MEMORY);
11644 }
11645}
11646
11647void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11648{
11649 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11650 program, binaryFormat, binary, length);
11651
11652 try
11653 {
11654 gl::Context *context = gl::getNonLostContext();
11655
11656 if (context)
11657 {
11658 if (context->getClientVersion() < 3)
11659 {
11660 return gl::error(GL_INVALID_OPERATION);
11661 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011662
Jamie Madill54133512013-06-21 09:33:07 -040011663 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011664 UNIMPLEMENTED();
11665 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011666 }
11667 catch(std::bad_alloc&)
11668 {
11669 return gl::error(GL_OUT_OF_MEMORY);
11670 }
11671}
11672
11673void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11674{
11675 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11676 program, pname, value);
11677
11678 try
11679 {
11680 gl::Context *context = gl::getNonLostContext();
11681
11682 if (context)
11683 {
11684 if (context->getClientVersion() < 3)
11685 {
11686 return gl::error(GL_INVALID_OPERATION);
11687 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011688
Jamie Madill54133512013-06-21 09:33:07 -040011689 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011690 UNIMPLEMENTED();
11691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011692 }
11693 catch(std::bad_alloc&)
11694 {
11695 return gl::error(GL_OUT_OF_MEMORY);
11696 }
11697}
11698
11699void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11700{
11701 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11702 target, numAttachments, attachments);
11703
11704 try
11705 {
11706 gl::Context *context = gl::getNonLostContext();
11707
11708 if (context)
11709 {
11710 if (context->getClientVersion() < 3)
11711 {
11712 return gl::error(GL_INVALID_OPERATION);
11713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011714
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011715 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11716 {
11717 return;
11718 }
11719
11720 int maxDimension = context->getMaximumRenderbufferDimension();
11721 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11722 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011723 }
11724 catch(std::bad_alloc&)
11725 {
11726 return gl::error(GL_OUT_OF_MEMORY);
11727 }
11728}
11729
11730void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11731{
11732 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11733 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11734 target, numAttachments, attachments, x, y, width, height);
11735
11736 try
11737 {
11738 gl::Context *context = gl::getNonLostContext();
11739
11740 if (context)
11741 {
11742 if (context->getClientVersion() < 3)
11743 {
11744 return gl::error(GL_INVALID_OPERATION);
11745 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011746
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011747 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11748 {
11749 return;
11750 }
11751
11752 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11753 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011754 }
11755 catch(std::bad_alloc&)
11756 {
11757 return gl::error(GL_OUT_OF_MEMORY);
11758 }
11759}
11760
11761void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11762{
11763 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11764 target, levels, internalformat, width, height);
11765
11766 try
11767 {
11768 gl::Context *context = gl::getNonLostContext();
11769
11770 if (context)
11771 {
11772 if (context->getClientVersion() < 3)
11773 {
11774 return gl::error(GL_INVALID_OPERATION);
11775 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011776
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011777 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11778 {
11779 return;
11780 }
11781
11782 switch (target)
11783 {
11784 case GL_TEXTURE_2D:
11785 {
11786 gl::Texture2D *texture2d = context->getTexture2D();
11787 texture2d->storage(levels, internalformat, width, height);
11788 }
11789 break;
11790
11791 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11792 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11793 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11797 {
11798 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11799 textureCube->storage(levels, internalformat, width);
11800 }
11801 break;
11802
11803 default:
11804 return gl::error(GL_INVALID_ENUM);
11805 }
11806 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011807 }
11808 catch(std::bad_alloc&)
11809 {
11810 return gl::error(GL_OUT_OF_MEMORY);
11811 }
11812}
11813
11814void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11815{
11816 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11817 "GLsizei height = %d, GLsizei depth = %d)",
11818 target, levels, internalformat, width, height, depth);
11819
11820 try
11821 {
11822 gl::Context *context = gl::getNonLostContext();
11823
11824 if (context)
11825 {
11826 if (context->getClientVersion() < 3)
11827 {
11828 return gl::error(GL_INVALID_OPERATION);
11829 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011830
11831 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11832 {
11833 return;
11834 }
11835
11836 switch (target)
11837 {
11838 case GL_TEXTURE_3D:
11839 {
11840 gl::Texture3D *texture3d = context->getTexture3D();
11841 texture3d->storage(levels, internalformat, width, height, depth);
11842 }
11843 break;
11844
11845 case GL_TEXTURE_2D_ARRAY:
11846 {
11847 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11848 texture2darray->storage(levels, internalformat, width, height, depth);
11849 }
11850 break;
11851
11852 default:
11853 return gl::error(GL_INVALID_ENUM);
11854 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011856 }
11857 catch(std::bad_alloc&)
11858 {
11859 return gl::error(GL_OUT_OF_MEMORY);
11860 }
11861}
11862
11863void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11864{
11865 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11866 "GLint* params = 0x%0.8p)",
11867 target, internalformat, pname, bufSize, params);
11868
11869 try
11870 {
11871 gl::Context *context = gl::getNonLostContext();
11872
11873 if (context)
11874 {
11875 if (context->getClientVersion() < 3)
11876 {
11877 return gl::error(GL_INVALID_OPERATION);
11878 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011879
Shannon Woods809d2502013-07-08 10:32:18 -040011880 if (!gl::IsColorRenderingSupported(internalformat, context) &&
11881 !gl::IsDepthRenderingSupported(internalformat, context) &&
11882 !gl::IsStencilRenderingSupported(internalformat, context))
11883 {
11884 return gl::error(GL_INVALID_ENUM);
11885 }
11886
11887 if (target != GL_RENDERBUFFER)
11888 {
11889 return gl::error(GL_INVALID_ENUM);
11890 }
11891
11892 if (bufSize < 0)
11893 {
11894 return gl::error(GL_INVALID_VALUE);
11895 }
11896
11897 switch (pname)
11898 {
11899 case GL_NUM_SAMPLE_COUNTS:
11900 if (bufSize != 0)
11901 *params = context->getNumSampleCounts(internalformat);
11902 break;
11903 case GL_SAMPLES:
11904 context->getSampleCounts(internalformat, bufSize, params);
11905 break;
11906 default:
11907 return gl::error(GL_INVALID_ENUM);
11908 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011909 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011910 }
11911 catch(std::bad_alloc&)
11912 {
11913 return gl::error(GL_OUT_OF_MEMORY);
11914 }
11915}
11916
11917// Extension functions
11918
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011919void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11920 GLbitfield mask, GLenum filter)
11921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011922 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011923 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11924 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11925 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11926
11927 try
11928 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011930
11931 if (context)
11932 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011933 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11934 dstX0, dstY0, dstX1, dstY1, mask, filter,
11935 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011936 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011937 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011938 }
11939
Geoff Lang758d5b22013-06-11 11:42:50 -040011940 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11941 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011942 }
11943 }
11944 catch(std::bad_alloc&)
11945 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011946 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011947 }
11948}
11949
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011950void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11951 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011952{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011953 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011954 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011955 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011956 target, level, internalformat, width, height, depth, border, format, type, pixels);
11957
11958 try
11959 {
11960 UNIMPLEMENTED(); // FIXME
11961 }
11962 catch(std::bad_alloc&)
11963 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011964 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011965 }
11966}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011967
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011968void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11969 GLenum *binaryFormat, void *binary)
11970{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011971 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 +000011972 program, bufSize, length, binaryFormat, binary);
11973
11974 try
11975 {
11976 gl::Context *context = gl::getNonLostContext();
11977
11978 if (context)
11979 {
11980 gl::Program *programObject = context->getProgram(program);
11981
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011982 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011983 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011984 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011985 }
11986
11987 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11988
11989 if (!programBinary)
11990 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011991 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011992 }
11993
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011994 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011996 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011997 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011998
11999 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012000 }
12001 }
12002 catch(std::bad_alloc&)
12003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012004 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012005 }
12006}
12007
12008void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
12009 const void *binary, GLint length)
12010{
12011 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
12012 program, binaryFormat, binary, length);
12013
12014 try
12015 {
12016 gl::Context *context = gl::getNonLostContext();
12017
12018 if (context)
12019 {
12020 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012022 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012023 }
12024
12025 gl::Program *programObject = context->getProgram(program);
12026
12027 if (!programObject)
12028 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012029 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012030 }
12031
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012032 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012033 }
12034 }
12035 catch(std::bad_alloc&)
12036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012037 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012038 }
12039}
12040
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012041void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12042{
12043 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12044
12045 try
12046 {
12047 gl::Context *context = gl::getNonLostContext();
12048
12049 if (context)
12050 {
12051 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12052 {
12053 return gl::error(GL_INVALID_VALUE);
12054 }
12055
12056 if (context->getDrawFramebufferHandle() == 0)
12057 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012058 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012059 {
12060 return gl::error(GL_INVALID_OPERATION);
12061 }
12062
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012063 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012064 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012065 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012066 }
12067 }
12068 else
12069 {
12070 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12071 {
12072 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12073 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12074 {
12075 return gl::error(GL_INVALID_OPERATION);
12076 }
12077 }
12078 }
12079
12080 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12081
12082 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12083 {
12084 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12085 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012086
12087 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12088 {
12089 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12090 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012091 }
12092 }
12093 catch (std::bad_alloc&)
12094 {
12095 return gl::error(GL_OUT_OF_MEMORY);
12096 }
12097}
12098
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012099__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12100{
12101 struct Extension
12102 {
12103 const char *name;
12104 __eglMustCastToProperFunctionPointerType address;
12105 };
12106
12107 static const Extension glExtensions[] =
12108 {
12109 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012110 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012111 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012112 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12113 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12114 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12115 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12116 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12117 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12118 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012119 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012120 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012121 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12122 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12123 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12124 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012125 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12126 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12127 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12128 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12129 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12130 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12131 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012132 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012133 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12134 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12135 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012136 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12137 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012138
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012139 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012140 {
12141 if (strcmp(procname, glExtensions[ext].name) == 0)
12142 {
12143 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12144 }
12145 }
12146
12147 return NULL;
12148}
12149
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012150// Non-public functions used by EGL
12151
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012152bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012153{
12154 EVENT("(egl::Surface* surface = 0x%0.8p)",
12155 surface);
12156
12157 try
12158 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012159 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012160
12161 if (context)
12162 {
12163 gl::Texture2D *textureObject = context->getTexture2D();
12164
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012165 if (textureObject->isImmutable())
12166 {
12167 return false;
12168 }
12169
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012170 if (textureObject)
12171 {
12172 textureObject->bindTexImage(surface);
12173 }
12174 }
12175 }
12176 catch(std::bad_alloc&)
12177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012178 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012179 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012180
12181 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012182}
12183
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012184}