blob: b12cb1ea55f424891980c57f063146d23e23c8c2 [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
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001953extern "C"
1954{
1955
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001956// OpenGL ES 2.0 functions
1957
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001958void __stdcall glActiveTexture(GLenum texture)
1959{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001960 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961
1962 try
1963 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001964 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001965
1966 if (context)
1967 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001968 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
1969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001970 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00001971 }
1972
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001973 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001974 }
1975 }
1976 catch(std::bad_alloc&)
1977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001978 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979 }
1980}
1981
1982void __stdcall glAttachShader(GLuint program, GLuint shader)
1983{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001984 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001985
1986 try
1987 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001988 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001989
1990 if (context)
1991 {
1992 gl::Program *programObject = context->getProgram(program);
1993 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001994
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001995 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001996 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00001997 if (context->getShader(program))
1998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001999 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002000 }
2001 else
2002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002003 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002004 }
2005 }
2006
2007 if (!shaderObject)
2008 {
2009 if (context->getProgram(shader))
2010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002011 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002012 }
2013 else
2014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002015 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002016 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002017 }
2018
2019 if (!programObject->attachShader(shaderObject))
2020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002021 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002022 }
2023 }
2024 }
2025 catch(std::bad_alloc&)
2026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002027 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002028 }
2029}
2030
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002031void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2032{
2033 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2034
2035 try
2036 {
2037 switch (target)
2038 {
2039 case GL_ANY_SAMPLES_PASSED_EXT:
2040 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2041 break;
2042 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002043 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002044 }
2045
2046 if (id == 0)
2047 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002048 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002049 }
2050
2051 gl::Context *context = gl::getNonLostContext();
2052
2053 if (context)
2054 {
2055 context->beginQuery(target, id);
2056 }
2057 }
2058 catch(std::bad_alloc&)
2059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002060 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002061 }
2062}
2063
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002064void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002065{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002066 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002067
2068 try
2069 {
2070 if (index >= gl::MAX_VERTEX_ATTRIBS)
2071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002072 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002073 }
2074
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002075 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002076
2077 if (context)
2078 {
2079 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002080
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002081 if (!programObject)
2082 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002083 if (context->getShader(program))
2084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002085 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002086 }
2087 else
2088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002089 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002090 }
2091 }
2092
2093 if (strncmp(name, "gl_", 3) == 0)
2094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002095 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002096 }
2097
2098 programObject->bindAttributeLocation(index, name);
2099 }
2100 }
2101 catch(std::bad_alloc&)
2102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002103 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002104 }
2105}
2106
2107void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2108{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002109 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002110
2111 try
2112 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002113 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002114
2115 if (context)
2116 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002117 // Check ES3 specific targets
2118 switch (target)
2119 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002120 case GL_COPY_READ_BUFFER:
2121 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002122 case GL_PIXEL_PACK_BUFFER:
2123 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002124 case GL_UNIFORM_BUFFER:
2125 case GL_TRANSFORM_FEEDBACK_BUFFER:
2126 if (context->getClientVersion() < 3)
2127 {
2128 return gl::error(GL_INVALID_ENUM);
2129 }
2130 }
2131
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002132 switch (target)
2133 {
2134 case GL_ARRAY_BUFFER:
2135 context->bindArrayBuffer(buffer);
2136 return;
2137 case GL_ELEMENT_ARRAY_BUFFER:
2138 context->bindElementArrayBuffer(buffer);
2139 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002140 case GL_COPY_READ_BUFFER:
2141 context->bindCopyReadBuffer(buffer);
2142 return;
2143 case GL_COPY_WRITE_BUFFER:
2144 context->bindCopyWriteBuffer(buffer);
2145 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002146 case GL_PIXEL_PACK_BUFFER:
2147 context->bindPixelPackBuffer(buffer);
2148 return;
2149 case GL_PIXEL_UNPACK_BUFFER:
2150 context->bindPixelUnpackBuffer(buffer);
2151 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002152 case GL_UNIFORM_BUFFER:
2153 context->bindGenericUniformBuffer(buffer);
2154 return;
2155 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002156 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002157 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002158 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002159 return gl::error(GL_INVALID_ENUM);
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
2169void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002171 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002172
2173 try
2174 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002175 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002176 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002177 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002178 }
2179
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002180 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002181
2182 if (context)
2183 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002184 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2185 {
2186 context->bindReadFramebuffer(framebuffer);
2187 }
2188
2189 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2190 {
2191 context->bindDrawFramebuffer(framebuffer);
2192 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002193 }
2194 }
2195 catch(std::bad_alloc&)
2196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002197 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002198 }
2199}
2200
2201void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2202{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002203 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002204
2205 try
2206 {
2207 if (target != GL_RENDERBUFFER)
2208 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002209 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002210 }
2211
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002212 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002213
2214 if (context)
2215 {
2216 context->bindRenderbuffer(renderbuffer);
2217 }
2218 }
2219 catch(std::bad_alloc&)
2220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002221 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002222 }
2223}
2224
2225void __stdcall glBindTexture(GLenum target, GLuint texture)
2226{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002227 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002228
2229 try
2230 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002231 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002232
2233 if (context)
2234 {
2235 gl::Texture *textureObject = context->getTexture(texture);
2236
2237 if (textureObject && textureObject->getTarget() != target && texture != 0)
2238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002239 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002240 }
2241
2242 switch (target)
2243 {
2244 case GL_TEXTURE_2D:
2245 context->bindTexture2D(texture);
2246 return;
2247 case GL_TEXTURE_CUBE_MAP:
2248 context->bindTextureCubeMap(texture);
2249 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002250 case GL_TEXTURE_3D:
2251 if (context->getClientVersion() < 3)
2252 {
2253 return gl::error(GL_INVALID_ENUM);
2254 }
2255 context->bindTexture3D(texture);
2256 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002257 case GL_TEXTURE_2D_ARRAY:
2258 if (context->getClientVersion() < 3)
2259 {
2260 return gl::error(GL_INVALID_ENUM);
2261 }
2262 context->bindTexture2DArray(texture);
2263 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002264 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002266 }
2267 }
2268 }
2269 catch(std::bad_alloc&)
2270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002271 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002272 }
2273}
2274
2275void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2276{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002277 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002278 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002279
2280 try
2281 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002282 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002283
2284 if (context)
2285 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002286 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287 }
2288 }
2289 catch(std::bad_alloc&)
2290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002291 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002292 }
2293}
2294
2295void __stdcall glBlendEquation(GLenum mode)
2296{
2297 glBlendEquationSeparate(mode, mode);
2298}
2299
2300void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002302 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002303
2304 try
2305 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002306 gl::Context *context = gl::getNonLostContext();
2307
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002308 switch (modeRGB)
2309 {
2310 case GL_FUNC_ADD:
2311 case GL_FUNC_SUBTRACT:
2312 case GL_FUNC_REVERSE_SUBTRACT:
2313 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002314
2315 case GL_MIN:
2316 case GL_MAX:
2317 if (context && context->getClientVersion() < 3)
2318 {
2319 return gl::error(GL_INVALID_ENUM);
2320 }
2321 break;
2322
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002323 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002324 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002325 }
2326
2327 switch (modeAlpha)
2328 {
2329 case GL_FUNC_ADD:
2330 case GL_FUNC_SUBTRACT:
2331 case GL_FUNC_REVERSE_SUBTRACT:
2332 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002333
2334 case GL_MIN:
2335 case GL_MAX:
2336 if (context && context->getClientVersion() < 3)
2337 {
2338 return gl::error(GL_INVALID_ENUM);
2339 }
2340 break;
2341
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002343 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002344 }
2345
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002346 if (context)
2347 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002348 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349 }
2350 }
2351 catch(std::bad_alloc&)
2352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002353 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002354 }
2355}
2356
2357void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2358{
2359 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2360}
2361
2362void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002364 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 +00002365 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002366
2367 try
2368 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002369 gl::Context *context = gl::getNonLostContext();
2370
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002371 switch (srcRGB)
2372 {
2373 case GL_ZERO:
2374 case GL_ONE:
2375 case GL_SRC_COLOR:
2376 case GL_ONE_MINUS_SRC_COLOR:
2377 case GL_DST_COLOR:
2378 case GL_ONE_MINUS_DST_COLOR:
2379 case GL_SRC_ALPHA:
2380 case GL_ONE_MINUS_SRC_ALPHA:
2381 case GL_DST_ALPHA:
2382 case GL_ONE_MINUS_DST_ALPHA:
2383 case GL_CONSTANT_COLOR:
2384 case GL_ONE_MINUS_CONSTANT_COLOR:
2385 case GL_CONSTANT_ALPHA:
2386 case GL_ONE_MINUS_CONSTANT_ALPHA:
2387 case GL_SRC_ALPHA_SATURATE:
2388 break;
2389 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002390 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002391 }
2392
2393 switch (dstRGB)
2394 {
2395 case GL_ZERO:
2396 case GL_ONE:
2397 case GL_SRC_COLOR:
2398 case GL_ONE_MINUS_SRC_COLOR:
2399 case GL_DST_COLOR:
2400 case GL_ONE_MINUS_DST_COLOR:
2401 case GL_SRC_ALPHA:
2402 case GL_ONE_MINUS_SRC_ALPHA:
2403 case GL_DST_ALPHA:
2404 case GL_ONE_MINUS_DST_ALPHA:
2405 case GL_CONSTANT_COLOR:
2406 case GL_ONE_MINUS_CONSTANT_COLOR:
2407 case GL_CONSTANT_ALPHA:
2408 case GL_ONE_MINUS_CONSTANT_ALPHA:
2409 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002410
2411 case GL_SRC_ALPHA_SATURATE:
2412 if (!context || context->getClientVersion() < 3)
2413 {
2414 return gl::error(GL_INVALID_ENUM);
2415 }
2416 break;
2417
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002418 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002419 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002420 }
2421
2422 switch (srcAlpha)
2423 {
2424 case GL_ZERO:
2425 case GL_ONE:
2426 case GL_SRC_COLOR:
2427 case GL_ONE_MINUS_SRC_COLOR:
2428 case GL_DST_COLOR:
2429 case GL_ONE_MINUS_DST_COLOR:
2430 case GL_SRC_ALPHA:
2431 case GL_ONE_MINUS_SRC_ALPHA:
2432 case GL_DST_ALPHA:
2433 case GL_ONE_MINUS_DST_ALPHA:
2434 case GL_CONSTANT_COLOR:
2435 case GL_ONE_MINUS_CONSTANT_COLOR:
2436 case GL_CONSTANT_ALPHA:
2437 case GL_ONE_MINUS_CONSTANT_ALPHA:
2438 case GL_SRC_ALPHA_SATURATE:
2439 break;
2440 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002441 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442 }
2443
2444 switch (dstAlpha)
2445 {
2446 case GL_ZERO:
2447 case GL_ONE:
2448 case GL_SRC_COLOR:
2449 case GL_ONE_MINUS_SRC_COLOR:
2450 case GL_DST_COLOR:
2451 case GL_ONE_MINUS_DST_COLOR:
2452 case GL_SRC_ALPHA:
2453 case GL_ONE_MINUS_SRC_ALPHA:
2454 case GL_DST_ALPHA:
2455 case GL_ONE_MINUS_DST_ALPHA:
2456 case GL_CONSTANT_COLOR:
2457 case GL_ONE_MINUS_CONSTANT_COLOR:
2458 case GL_CONSTANT_ALPHA:
2459 case GL_ONE_MINUS_CONSTANT_ALPHA:
2460 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002461
2462 case GL_SRC_ALPHA_SATURATE:
2463 if (!context || context->getClientVersion() < 3)
2464 {
2465 return gl::error(GL_INVALID_ENUM);
2466 }
2467 break;
2468
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002470 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002471 }
2472
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002473 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2474 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2475
2476 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2477 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2478
2479 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002481 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 +00002482 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 }
2484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002485 if (context)
2486 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002487 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002488 }
2489 }
2490 catch(std::bad_alloc&)
2491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002492 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493 }
2494}
2495
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002496void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002497{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002498 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 +00002499 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500
2501 try
2502 {
2503 if (size < 0)
2504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002505 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002506 }
2507
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002508 gl::Context *context = gl::getNonLostContext();
2509
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002510 switch (usage)
2511 {
2512 case GL_STREAM_DRAW:
2513 case GL_STATIC_DRAW:
2514 case GL_DYNAMIC_DRAW:
2515 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002516
2517 case GL_STREAM_READ:
2518 case GL_STREAM_COPY:
2519 case GL_STATIC_READ:
2520 case GL_STATIC_COPY:
2521 case GL_DYNAMIC_READ:
2522 case GL_DYNAMIC_COPY:
2523 if (context && context->getClientVersion() < 3)
2524 {
2525 return gl::error(GL_INVALID_ENUM);
2526 }
2527 break;
2528
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002530 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531 }
2532
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002533 if (context)
2534 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002535 // Check ES3 specific targets
2536 switch (target)
2537 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002538 case GL_COPY_READ_BUFFER:
2539 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002540 case GL_PIXEL_PACK_BUFFER:
2541 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002542 case GL_UNIFORM_BUFFER:
2543 case GL_TRANSFORM_FEEDBACK_BUFFER:
2544 if (context->getClientVersion() < 3)
2545 {
2546 return gl::error(GL_INVALID_ENUM);
2547 }
2548 }
2549
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002551
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002552 switch (target)
2553 {
2554 case GL_ARRAY_BUFFER:
2555 buffer = context->getArrayBuffer();
2556 break;
2557 case GL_ELEMENT_ARRAY_BUFFER:
2558 buffer = context->getElementArrayBuffer();
2559 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002560 case GL_COPY_READ_BUFFER:
2561 buffer = context->getCopyReadBuffer();
2562 break;
2563 case GL_COPY_WRITE_BUFFER:
2564 buffer = context->getCopyWriteBuffer();
2565 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002566 case GL_PIXEL_PACK_BUFFER:
2567 buffer = context->getPixelPackBuffer();
2568 break;
2569 case GL_PIXEL_UNPACK_BUFFER:
2570 buffer = context->getPixelUnpackBuffer();
2571 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002572 case GL_TRANSFORM_FEEDBACK_BUFFER:
2573 buffer = context->getGenericTransformFeedbackBuffer();
2574 break;
2575 case GL_UNIFORM_BUFFER:
2576 buffer = context->getGenericUniformBuffer();
2577 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578 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 if (!buffer)
2583 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002584 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 }
2586
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002587 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002588 }
2589 }
2590 catch(std::bad_alloc&)
2591 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002592 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002593 }
2594}
2595
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002596void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002598 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 +00002599 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002600
2601 try
2602 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002603 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002605 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002606 }
2607
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002608 if (data == NULL)
2609 {
2610 return;
2611 }
2612
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002613 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002614
2615 if (context)
2616 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002617 // Check ES3 specific targets
2618 switch (target)
2619 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002620 case GL_COPY_READ_BUFFER:
2621 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002622 case GL_PIXEL_PACK_BUFFER:
2623 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002624 case GL_UNIFORM_BUFFER:
2625 case GL_TRANSFORM_FEEDBACK_BUFFER:
2626 if (context->getClientVersion() < 3)
2627 {
2628 return gl::error(GL_INVALID_ENUM);
2629 }
2630 }
2631
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002632 gl::Buffer *buffer;
2633
2634 switch (target)
2635 {
2636 case GL_ARRAY_BUFFER:
2637 buffer = context->getArrayBuffer();
2638 break;
2639 case GL_ELEMENT_ARRAY_BUFFER:
2640 buffer = context->getElementArrayBuffer();
2641 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002642 case GL_COPY_READ_BUFFER:
2643 buffer = context->getCopyReadBuffer();
2644 break;
2645 case GL_COPY_WRITE_BUFFER:
2646 buffer = context->getCopyWriteBuffer();
2647 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002648 case GL_PIXEL_PACK_BUFFER:
2649 buffer = context->getPixelPackBuffer();
2650 break;
2651 case GL_PIXEL_UNPACK_BUFFER:
2652 buffer = context->getPixelUnpackBuffer();
2653 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002654 case GL_TRANSFORM_FEEDBACK_BUFFER:
2655 buffer = context->getGenericTransformFeedbackBuffer();
2656 break;
2657 case GL_UNIFORM_BUFFER:
2658 buffer = context->getGenericUniformBuffer();
2659 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002660 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002661 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002662 }
2663
2664 if (!buffer)
2665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002666 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002667 }
2668
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002669 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002672 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002673
2674 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002675 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002676 }
2677 catch(std::bad_alloc&)
2678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002679 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680 }
2681}
2682
2683GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002685 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002686
2687 try
2688 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002689 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002691 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002692 }
2693
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002694 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002695
2696 if (context)
2697 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002698 gl::Framebuffer *framebuffer = NULL;
2699 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2700 {
2701 framebuffer = context->getReadFramebuffer();
2702 }
2703 else
2704 {
2705 framebuffer = context->getDrawFramebuffer();
2706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002707
2708 return framebuffer->completeness();
2709 }
2710 }
2711 catch(std::bad_alloc&)
2712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002713 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002714 }
2715
2716 return 0;
2717}
2718
2719void __stdcall glClear(GLbitfield mask)
2720{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002721 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002722
2723 try
2724 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002725 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002726
2727 if (context)
2728 {
2729 context->clear(mask);
2730 }
2731 }
2732 catch(std::bad_alloc&)
2733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002734 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735 }
2736}
2737
2738void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2739{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002740 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002741 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002742
2743 try
2744 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002745 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002746
2747 if (context)
2748 {
2749 context->setClearColor(red, green, blue, alpha);
2750 }
2751 }
2752 catch(std::bad_alloc&)
2753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002754 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755 }
2756}
2757
2758void __stdcall glClearDepthf(GLclampf depth)
2759{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002760 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761
2762 try
2763 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002764 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765
2766 if (context)
2767 {
2768 context->setClearDepth(depth);
2769 }
2770 }
2771 catch(std::bad_alloc&)
2772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002773 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774 }
2775}
2776
2777void __stdcall glClearStencil(GLint s)
2778{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002779 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002780
2781 try
2782 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002783 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002784
2785 if (context)
2786 {
2787 context->setClearStencil(s);
2788 }
2789 }
2790 catch(std::bad_alloc&)
2791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002792 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002793 }
2794}
2795
2796void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2797{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002798 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002799 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002800
2801 try
2802 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002803 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002804
2805 if (context)
2806 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002807 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002808 }
2809 }
2810 catch(std::bad_alloc&)
2811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002812 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002813 }
2814}
2815
2816void __stdcall glCompileShader(GLuint shader)
2817{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002818 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002819
2820 try
2821 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002822 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823
2824 if (context)
2825 {
2826 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002827
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002828 if (!shaderObject)
2829 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002830 if (context->getProgram(shader))
2831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002832 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002833 }
2834 else
2835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002836 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00002837 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002838 }
2839
2840 shaderObject->compile();
2841 }
2842 }
2843 catch(std::bad_alloc&)
2844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002845 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002846 }
2847}
2848
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002849void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
2850 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002852 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002853 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002854 target, level, internalformat, width, height, border, imageSize, data);
2855
2856 try
2857 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002858 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002859
2860 if (context)
2861 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002862 if (context->getClientVersion() < 3 &&
2863 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
2864 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
2865 {
2866 return;
2867 }
2868
2869 if (context->getClientVersion() >= 3 &&
2870 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
2871 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2872 {
2873 return;
2874 }
2875
2876 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002878 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002879 }
2880
2881 switch (target)
2882 {
2883 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002884 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002885 gl::Texture2D *texture = context->getTexture2D();
2886 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002887 }
2888 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002889
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002890 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2891 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2892 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2893 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2894 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2895 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002896 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002897 gl::TextureCubeMap *texture = context->getTextureCubeMap();
2898 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002899 }
2900 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002901
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002902 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002904 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00002905 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002906 }
2907 catch(std::bad_alloc&)
2908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002910 }
2911}
2912
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002913void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
2914 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002915{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002916 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002917 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002918 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002919 target, level, xoffset, yoffset, width, height, format, imageSize, data);
2920
2921 try
2922 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002923 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00002924
2925 if (context)
2926 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002927 if (context->getClientVersion() < 3 &&
2928 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
2929 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
2930 {
2931 return;
2932 }
2933
2934 if (context->getClientVersion() >= 3 &&
2935 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
2936 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
2937 {
2938 return;
2939 }
2940
2941 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002943 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002944 }
2945
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002946 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00002947 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002948 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002949 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002950 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002951 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002952 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002953 break;
2954
2955 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2956 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2957 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2958 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2959 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00002961 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002962 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00002963 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002964 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002965 break;
2966
2967 default:
2968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00002969 }
2970 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002971 }
2972 catch(std::bad_alloc&)
2973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002974 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002975 }
2976}
2977
2978void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
2979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002980 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002981 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002982 target, level, internalformat, x, y, width, height, border);
2983
2984 try
2985 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002986 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002987
2988 if (context)
2989 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002990 if (context->getClientVersion() < 3 &&
2991 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
2992 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002993 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002994 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00002995 }
2996
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00002997 if (context->getClientVersion() >= 3 &&
2998 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
2999 0, 0, 0, x, y, width, height, border))
3000 {
3001 return;
3002 }
3003
3004 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3005
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003006 switch (target)
3007 {
3008 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003009 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003010 gl::Texture2D *texture = context->getTexture2D();
3011 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003012 }
3013 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003014
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003015 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3016 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3017 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3019 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003021 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003022 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3023 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003024 }
3025 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003026
3027 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003028 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003029 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031 }
3032 catch(std::bad_alloc&)
3033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003034 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003035 }
3036}
3037
3038void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003040 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003041 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003042 target, level, xoffset, yoffset, x, y, width, height);
3043
3044 try
3045 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003046 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003047
3048 if (context)
3049 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003050 if (context->getClientVersion() < 3 &&
3051 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3052 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003053 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003054 return;
3055 }
3056
3057 if (context->getClientVersion() >= 3 &&
3058 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3059 xoffset, yoffset, 0, x, y, width, height, 0))
3060 {
3061 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003062 }
3063
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003064 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003065
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003066 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003067 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003068 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003069 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003070 gl::Texture2D *texture = context->getTexture2D();
3071 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003072 }
3073 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003074
3075 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3076 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3077 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3078 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3079 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3080 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003081 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003082 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3083 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003084 }
3085 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003086
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003087 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003088 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003089 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003091 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003092
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003093 catch(std::bad_alloc&)
3094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096 }
3097}
3098
3099GLuint __stdcall glCreateProgram(void)
3100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003101 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003102
3103 try
3104 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003106
3107 if (context)
3108 {
3109 return context->createProgram();
3110 }
3111 }
3112 catch(std::bad_alloc&)
3113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
3116
3117 return 0;
3118}
3119
3120GLuint __stdcall glCreateShader(GLenum type)
3121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003122 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003123
3124 try
3125 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003126 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003127
3128 if (context)
3129 {
3130 switch (type)
3131 {
3132 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003133 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003134 return context->createShader(type);
3135 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003136 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003137 }
3138 }
3139 }
3140 catch(std::bad_alloc&)
3141 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003142 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143 }
3144
3145 return 0;
3146}
3147
3148void __stdcall glCullFace(GLenum mode)
3149{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003150 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003151
3152 try
3153 {
3154 switch (mode)
3155 {
3156 case GL_FRONT:
3157 case GL_BACK:
3158 case GL_FRONT_AND_BACK:
3159 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003160 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003161
3162 if (context)
3163 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003164 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003165 }
3166 }
3167 break;
3168 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003169 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003170 }
3171 }
3172 catch(std::bad_alloc&)
3173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003174 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003175 }
3176}
3177
3178void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3179{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003180 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003181
3182 try
3183 {
3184 if (n < 0)
3185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003186 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187 }
3188
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003190
3191 if (context)
3192 {
3193 for (int i = 0; i < n; i++)
3194 {
3195 context->deleteBuffer(buffers[i]);
3196 }
3197 }
3198 }
3199 catch(std::bad_alloc&)
3200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003201 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003202 }
3203}
3204
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003205void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3206{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003207 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003208
3209 try
3210 {
3211 if (n < 0)
3212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003213 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003214 }
3215
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003216 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003217
3218 if (context)
3219 {
3220 for (int i = 0; i < n; i++)
3221 {
3222 context->deleteFence(fences[i]);
3223 }
3224 }
3225 }
3226 catch(std::bad_alloc&)
3227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003228 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003229 }
3230}
3231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003234 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003235
3236 try
3237 {
3238 if (n < 0)
3239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003240 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003241 }
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 for (int i = 0; i < n; i++)
3248 {
3249 if (framebuffers[i] != 0)
3250 {
3251 context->deleteFramebuffer(framebuffers[i]);
3252 }
3253 }
3254 }
3255 }
3256 catch(std::bad_alloc&)
3257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003258 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003259 }
3260}
3261
3262void __stdcall glDeleteProgram(GLuint program)
3263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003264 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003265
3266 try
3267 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003268 if (program == 0)
3269 {
3270 return;
3271 }
3272
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003273 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003274
3275 if (context)
3276 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003277 if (!context->getProgram(program))
3278 {
3279 if(context->getShader(program))
3280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003281 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003282 }
3283 else
3284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003285 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003286 }
3287 }
3288
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003289 context->deleteProgram(program);
3290 }
3291 }
3292 catch(std::bad_alloc&)
3293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003295 }
3296}
3297
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003298void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3299{
3300 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3301
3302 try
3303 {
3304 if (n < 0)
3305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003307 }
3308
3309 gl::Context *context = gl::getNonLostContext();
3310
3311 if (context)
3312 {
3313 for (int i = 0; i < n; i++)
3314 {
3315 context->deleteQuery(ids[i]);
3316 }
3317 }
3318 }
3319 catch(std::bad_alloc&)
3320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003322 }
3323}
3324
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 try
3330 {
3331 if (n < 0)
3332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334 }
3335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003337
3338 if (context)
3339 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003340 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003341 {
3342 context->deleteRenderbuffer(renderbuffers[i]);
3343 }
3344 }
3345 }
3346 catch(std::bad_alloc&)
3347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003349 }
3350}
3351
3352void __stdcall glDeleteShader(GLuint shader)
3353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003354 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003355
3356 try
3357 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003358 if (shader == 0)
3359 {
3360 return;
3361 }
3362
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364
3365 if (context)
3366 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003367 if (!context->getShader(shader))
3368 {
3369 if(context->getProgram(shader))
3370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003371 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003372 }
3373 else
3374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003375 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003376 }
3377 }
3378
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379 context->deleteShader(shader);
3380 }
3381 }
3382 catch(std::bad_alloc&)
3383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003384 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003385 }
3386}
3387
3388void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3389{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003390 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003391
3392 try
3393 {
3394 if (n < 0)
3395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003396 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003397 }
3398
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003400
3401 if (context)
3402 {
3403 for (int i = 0; i < n; i++)
3404 {
3405 if (textures[i] != 0)
3406 {
3407 context->deleteTexture(textures[i]);
3408 }
3409 }
3410 }
3411 }
3412 catch(std::bad_alloc&)
3413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416}
3417
3418void __stdcall glDepthFunc(GLenum func)
3419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003420 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421
3422 try
3423 {
3424 switch (func)
3425 {
3426 case GL_NEVER:
3427 case GL_ALWAYS:
3428 case GL_LESS:
3429 case GL_LEQUAL:
3430 case GL_EQUAL:
3431 case GL_GREATER:
3432 case GL_GEQUAL:
3433 case GL_NOTEQUAL:
3434 break;
3435 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003436 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437 }
3438
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003440
3441 if (context)
3442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003443 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003444 }
3445 }
3446 catch(std::bad_alloc&)
3447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003449 }
3450}
3451
3452void __stdcall glDepthMask(GLboolean flag)
3453{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003454 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003455
3456 try
3457 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459
3460 if (context)
3461 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003462 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463 }
3464 }
3465 catch(std::bad_alloc&)
3466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003467 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468 }
3469}
3470
3471void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3472{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003473 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474
3475 try
3476 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003477 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003478
3479 if (context)
3480 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003481 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482 }
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 glDetachShader(GLuint program, GLuint shader)
3491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003492 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003493
3494 try
3495 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003496 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003497
3498 if (context)
3499 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003500
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003501 gl::Program *programObject = context->getProgram(program);
3502 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003503
3504 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003505 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003506 gl::Shader *shaderByProgramHandle;
3507 shaderByProgramHandle = context->getShader(program);
3508 if (!shaderByProgramHandle)
3509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003511 }
3512 else
3513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003515 }
3516 }
3517
3518 if (!shaderObject)
3519 {
3520 gl::Program *programByShaderHandle = context->getProgram(shader);
3521 if (!programByShaderHandle)
3522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003523 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003524 }
3525 else
3526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003527 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003528 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003529 }
3530
3531 if (!programObject->detachShader(shaderObject))
3532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003533 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003535 }
3536 }
3537 catch(std::bad_alloc&)
3538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003539 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003540 }
3541}
3542
3543void __stdcall glDisable(GLenum cap)
3544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003545 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546
3547 try
3548 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003549 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003550
3551 if (context)
3552 {
3553 switch (cap)
3554 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003555 case GL_CULL_FACE: context->setCullFace(false); break;
3556 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3557 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3558 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3559 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3560 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3561 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3562 case GL_BLEND: context->setBlend(false); break;
3563 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003564
3565 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3566 case GL_RASTERIZER_DISCARD:
3567 if (context->getClientVersion() < 3)
3568 {
3569 return gl::error(GL_INVALID_ENUM);
3570 }
3571 UNIMPLEMENTED();
3572 break;
3573
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003575 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003576 }
3577 }
3578 }
3579 catch(std::bad_alloc&)
3580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003581 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582 }
3583}
3584
3585void __stdcall glDisableVertexAttribArray(GLuint index)
3586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003587 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003588
3589 try
3590 {
3591 if (index >= gl::MAX_VERTEX_ATTRIBS)
3592 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003593 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003594 }
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.com83921382011-01-08 05:46:00 +00003600 context->setEnableVertexAttribArray(index, 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 glDrawArrays(GLenum mode, GLint first, GLsizei count)
3610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003611 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612
3613 try
3614 {
3615 if (count < 0 || first < 0)
3616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003617 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618 }
3619
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003620 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621
3622 if (context)
3623 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003624 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625 }
3626 }
3627 catch(std::bad_alloc&)
3628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003629 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003630 }
3631}
3632
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003633void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3634{
3635 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3636
3637 try
3638 {
3639 if (count < 0 || first < 0 || primcount < 0)
3640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003641 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003642 }
3643
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003644 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003645 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003646 gl::Context *context = gl::getNonLostContext();
3647
3648 if (context)
3649 {
3650 context->drawArrays(mode, first, count, primcount);
3651 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003652 }
3653 }
3654 catch(std::bad_alloc&)
3655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003656 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003657 }
3658}
3659
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003660void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003662 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 +00003663 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664
3665 try
3666 {
3667 if (count < 0)
3668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003669 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670 }
3671
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003673
3674 if (context)
3675 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003676 switch (type)
3677 {
3678 case GL_UNSIGNED_BYTE:
3679 case GL_UNSIGNED_SHORT:
3680 break;
3681 case GL_UNSIGNED_INT:
3682 if (!context->supports32bitIndices())
3683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003684 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003685 }
3686 break;
3687 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003688 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003689 }
3690
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003691 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003692 }
3693 }
3694 catch(std::bad_alloc&)
3695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003696 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697 }
3698}
3699
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003700void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3701{
3702 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3703 mode, count, type, indices, primcount);
3704
3705 try
3706 {
3707 if (count < 0 || primcount < 0)
3708 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003709 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003710 }
3711
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003712 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003713 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003714 gl::Context *context = gl::getNonLostContext();
3715
3716 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003717 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003718 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003719 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003720 case GL_UNSIGNED_BYTE:
3721 case GL_UNSIGNED_SHORT:
3722 break;
3723 case GL_UNSIGNED_INT:
3724 if (!context->supports32bitIndices())
3725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003726 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003727 }
3728 break;
3729 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003730 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003731 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003732
3733 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003734 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003735 }
3736 }
3737 catch(std::bad_alloc&)
3738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003739 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003740 }
3741}
3742
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003743void __stdcall glEnable(GLenum cap)
3744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003745 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003746
3747 try
3748 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003749 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003750
3751 if (context)
3752 {
3753 switch (cap)
3754 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003755 case GL_CULL_FACE: context->setCullFace(true); break;
3756 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3757 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3758 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3759 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3760 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3761 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3762 case GL_BLEND: context->setBlend(true); break;
3763 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003764 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003765 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003766 }
3767 }
3768 }
3769 catch(std::bad_alloc&)
3770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003771 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772 }
3773}
3774
3775void __stdcall glEnableVertexAttribArray(GLuint index)
3776{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003777 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778
3779 try
3780 {
3781 if (index >= gl::MAX_VERTEX_ATTRIBS)
3782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003783 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003784 }
3785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003786 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003787
3788 if (context)
3789 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003790 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003791 }
3792 }
3793 catch(std::bad_alloc&)
3794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003795 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003796 }
3797}
3798
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003799void __stdcall glEndQueryEXT(GLenum target)
3800{
3801 EVENT("GLenum target = 0x%X)", target);
3802
3803 try
3804 {
3805 switch (target)
3806 {
3807 case GL_ANY_SAMPLES_PASSED_EXT:
3808 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3809 break;
3810 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003811 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003812 }
3813
3814 gl::Context *context = gl::getNonLostContext();
3815
3816 if (context)
3817 {
3818 context->endQuery(target);
3819 }
3820 }
3821 catch(std::bad_alloc&)
3822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003823 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003824 }
3825}
3826
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003827void __stdcall glFinishFenceNV(GLuint fence)
3828{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003829 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003830
3831 try
3832 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003833 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003834
3835 if (context)
3836 {
3837 gl::Fence* fenceObject = context->getFence(fence);
3838
3839 if (fenceObject == NULL)
3840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003841 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003842 }
3843
3844 fenceObject->finishFence();
3845 }
3846 }
3847 catch(std::bad_alloc&)
3848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003849 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003850 }
3851}
3852
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853void __stdcall glFinish(void)
3854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003855 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003856
3857 try
3858 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003859 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003860
3861 if (context)
3862 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003863 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003864 }
3865 }
3866 catch(std::bad_alloc&)
3867 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003868 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869 }
3870}
3871
3872void __stdcall glFlush(void)
3873{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003874 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003875
3876 try
3877 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003878 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003879
3880 if (context)
3881 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00003882 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003883 }
3884 }
3885 catch(std::bad_alloc&)
3886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003887 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003888 }
3889}
3890
3891void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
3892{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003893 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003894 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003895
3896 try
3897 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003898 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003899 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003901 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902 }
3903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003905
3906 if (context)
3907 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003908 gl::Framebuffer *framebuffer = NULL;
3909 GLuint framebufferHandle = 0;
3910 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3911 {
3912 framebuffer = context->getReadFramebuffer();
3913 framebufferHandle = context->getReadFramebufferHandle();
3914 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003915 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003916 {
3917 framebuffer = context->getDrawFramebuffer();
3918 framebufferHandle = context->getDrawFramebufferHandle();
3919 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00003921 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003923 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003924 }
3925
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003926 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003928 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3929
3930 if (colorAttachment >= context->getMaximumRenderTargets())
3931 {
3932 return gl::error(GL_INVALID_VALUE);
3933 }
3934
3935 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
3936 }
3937 else
3938 {
3939 switch (attachment)
3940 {
3941 case GL_DEPTH_ATTACHMENT:
3942 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
3943 break;
3944 case GL_STENCIL_ATTACHMENT:
3945 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
3946 break;
3947 default:
3948 return gl::error(GL_INVALID_ENUM);
3949 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003950 }
3951 }
3952 }
3953 catch(std::bad_alloc&)
3954 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003955 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956 }
3957}
3958
3959void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
3960{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003961 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003962 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003963
3964 try
3965 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003966 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003968 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003969 }
3970
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003971 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003972
3973 if (context)
3974 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003975 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
3976 {
3977 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3978
3979 if (colorAttachment >= context->getMaximumRenderTargets())
3980 {
3981 return gl::error(GL_INVALID_VALUE);
3982 }
3983 }
3984 else
3985 {
3986 switch (attachment)
3987 {
3988 case GL_DEPTH_ATTACHMENT:
3989 case GL_STENCIL_ATTACHMENT:
3990 break;
3991 default:
3992 return gl::error(GL_INVALID_ENUM);
3993 }
3994 }
3995
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003996 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003997 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003998 textarget = GL_NONE;
3999 }
4000 else
4001 {
4002 gl::Texture *tex = context->getTexture(texture);
4003
4004 if (tex == NULL)
4005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004006 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004007 }
4008
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004009 switch (textarget)
4010 {
4011 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004012 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004013 if (tex->getTarget() != GL_TEXTURE_2D)
4014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004015 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004016 }
4017 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004018 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004020 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004021 }
4022 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004023 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004024
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004025 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004027 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004028 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004029 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004030 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004031 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004032 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004034 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004035 }
4036 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004037 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004039 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004040 }
4041 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004042 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004043
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004044 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004045 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047
4048 if (level != 0)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051 }
4052 }
4053
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004054 gl::Framebuffer *framebuffer = NULL;
4055 GLuint framebufferHandle = 0;
4056 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4057 {
4058 framebuffer = context->getReadFramebuffer();
4059 framebufferHandle = context->getReadFramebufferHandle();
4060 }
4061 else
4062 {
4063 framebuffer = context->getDrawFramebuffer();
4064 framebufferHandle = context->getDrawFramebufferHandle();
4065 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004066
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004067 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004072 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004073 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004074 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4075
4076 if (colorAttachment >= context->getMaximumRenderTargets())
4077 {
4078 return gl::error(GL_INVALID_VALUE);
4079 }
4080
4081 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4082 }
4083 else
4084 {
4085 switch (attachment)
4086 {
4087 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4088 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4089 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004091 }
4092 }
4093 catch(std::bad_alloc&)
4094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004096 }
4097}
4098
4099void __stdcall glFrontFace(GLenum mode)
4100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004101 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
4103 try
4104 {
4105 switch (mode)
4106 {
4107 case GL_CW:
4108 case GL_CCW:
4109 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004110 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004111
4112 if (context)
4113 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004114 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004115 }
4116 }
4117 break;
4118 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004119 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004120 }
4121 }
4122 catch(std::bad_alloc&)
4123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004124 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125 }
4126}
4127
4128void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4129{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004130 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004131
4132 try
4133 {
4134 if (n < 0)
4135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004136 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004137 }
4138
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004140
4141 if (context)
4142 {
4143 for (int i = 0; i < n; i++)
4144 {
4145 buffers[i] = context->createBuffer();
4146 }
4147 }
4148 }
4149 catch(std::bad_alloc&)
4150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004151 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004152 }
4153}
4154
4155void __stdcall glGenerateMipmap(GLenum target)
4156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004157 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004158
4159 try
4160 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004161 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004162
4163 if (context)
4164 {
Geoff Langae4852a2013-06-05 15:00:34 -04004165 gl::Texture *texture = NULL;
4166 GLint internalFormat = GL_NONE;
4167 bool isCompressed = false;
4168 bool isDepth = false;
4169
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004170 switch (target)
4171 {
4172 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004173 {
4174 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004175 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004176 {
Geoff Langae4852a2013-06-05 15:00:34 -04004177 internalFormat = tex2d->getInternalFormat(0);
4178 isCompressed = tex2d->isCompressed(0);
4179 isDepth = tex2d->isDepth(0);
4180 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004181 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004182 break;
4183 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004184
4185 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004186 {
4187 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004188 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004189 {
Geoff Langae4852a2013-06-05 15:00:34 -04004190 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4191 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4192 isDepth = false;
4193 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004194 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004195 break;
4196 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004197
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004198 case GL_TEXTURE_3D:
4199 {
4200 if (context->getClientVersion() < 3)
4201 {
4202 return gl::error(GL_INVALID_ENUM);
4203 }
4204
4205 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004206 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004207 {
Geoff Langae4852a2013-06-05 15:00:34 -04004208 internalFormat = tex3D->getInternalFormat(0);
4209 isCompressed = tex3D->isCompressed(0);
4210 isDepth = tex3D->isDepth(0);
4211 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004212 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004213 break;
4214 }
4215
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004216 case GL_TEXTURE_2D_ARRAY:
4217 {
4218 if (context->getClientVersion() < 3)
4219 {
4220 return gl::error(GL_INVALID_ENUM);
4221 }
4222
4223 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004224 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004225 {
Geoff Langae4852a2013-06-05 15:00:34 -04004226 internalFormat = tex2darr->getInternalFormat(0);
4227 isCompressed = tex2darr->isCompressed(0);
4228 isDepth = tex2darr->isDepth(0);
4229 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004230 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004231 break;
4232 }
4233
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004234 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004235 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004236 }
Geoff Langae4852a2013-06-05 15:00:34 -04004237
4238 if (!texture)
4239 {
4240 return gl::error(GL_INVALID_OPERATION);
4241 }
4242
4243 // Internally, all texture formats are sized so checking if the format
4244 // is color renderable and filterable will not fail.
4245 if (isDepth || isCompressed ||
4246 !gl::IsColorRenderingSupported(internalFormat, context) ||
4247 !gl::IsTextureFilteringSupported(internalFormat, context))
4248 {
4249 return gl::error(GL_INVALID_OPERATION);
4250 }
4251
4252 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004253 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004254 }
4255 catch(std::bad_alloc&)
4256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004257 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
4259}
4260
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004261void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4262{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004263 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004264
4265 try
4266 {
4267 if (n < 0)
4268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004269 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004270 }
4271
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004272 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004273
4274 if (context)
4275 {
4276 for (int i = 0; i < n; i++)
4277 {
4278 fences[i] = context->createFence();
4279 }
4280 }
4281 }
4282 catch(std::bad_alloc&)
4283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004284 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004285 }
4286}
4287
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004290 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291
4292 try
4293 {
4294 if (n < 0)
4295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004296 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297 }
4298
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004300
4301 if (context)
4302 {
4303 for (int i = 0; i < n; i++)
4304 {
4305 framebuffers[i] = context->createFramebuffer();
4306 }
4307 }
4308 }
4309 catch(std::bad_alloc&)
4310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004311 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004312 }
4313}
4314
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004315void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4316{
4317 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4318
4319 try
4320 {
4321 if (n < 0)
4322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004323 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004324 }
4325
4326 gl::Context *context = gl::getNonLostContext();
4327
4328 if (context)
4329 {
4330 for (int i = 0; i < n; i++)
4331 {
4332 ids[i] = context->createQuery();
4333 }
4334 }
4335 }
4336 catch(std::bad_alloc&)
4337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004338 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004339 }
4340}
4341
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004344 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345
4346 try
4347 {
4348 if (n < 0)
4349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004350 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004351 }
4352
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004353 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354
4355 if (context)
4356 {
4357 for (int i = 0; i < n; i++)
4358 {
4359 renderbuffers[i] = context->createRenderbuffer();
4360 }
4361 }
4362 }
4363 catch(std::bad_alloc&)
4364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004365 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004366 }
4367}
4368
4369void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4370{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004371 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004372
4373 try
4374 {
4375 if (n < 0)
4376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004377 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378 }
4379
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004380 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381
4382 if (context)
4383 {
4384 for (int i = 0; i < n; i++)
4385 {
4386 textures[i] = context->createTexture();
4387 }
4388 }
4389 }
4390 catch(std::bad_alloc&)
4391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004392 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004393 }
4394}
4395
daniel@transgaming.com85423182010-04-22 13:35:27 +00004396void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004398 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004399 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004400 program, index, bufsize, length, size, type, name);
4401
4402 try
4403 {
4404 if (bufsize < 0)
4405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004406 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004407 }
4408
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004409 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004410
4411 if (context)
4412 {
4413 gl::Program *programObject = context->getProgram(program);
4414
4415 if (!programObject)
4416 {
4417 if (context->getShader(program))
4418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004419 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004420 }
4421 else
4422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004423 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004424 }
4425 }
4426
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004427 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004429 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004430 }
4431
4432 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4433 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004434 }
4435 catch(std::bad_alloc&)
4436 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004437 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004438 }
4439}
4440
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004441void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004442{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004443 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004444 "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 +00004445 program, index, bufsize, length, size, type, name);
4446
4447 try
4448 {
4449 if (bufsize < 0)
4450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004451 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 }
4453
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004454 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004455
4456 if (context)
4457 {
4458 gl::Program *programObject = context->getProgram(program);
4459
4460 if (!programObject)
4461 {
4462 if (context->getShader(program))
4463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004464 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004465 }
4466 else
4467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004468 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004469 }
4470 }
4471
4472 if (index >= (GLuint)programObject->getActiveUniformCount())
4473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004474 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004475 }
4476
4477 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4478 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479 }
4480 catch(std::bad_alloc&)
4481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004482 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483 }
4484}
4485
4486void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4487{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004488 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 +00004489 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490
4491 try
4492 {
4493 if (maxcount < 0)
4494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004495 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004496 }
4497
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004499
4500 if (context)
4501 {
4502 gl::Program *programObject = context->getProgram(program);
4503
4504 if (!programObject)
4505 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004506 if (context->getShader(program))
4507 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004508 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004509 }
4510 else
4511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004513 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004514 }
4515
4516 return programObject->getAttachedShaders(maxcount, count, shaders);
4517 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004518 }
4519 catch(std::bad_alloc&)
4520 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004521 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004522 }
4523}
4524
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004525int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004527 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004528
4529 try
4530 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004531 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004532
4533 if (context)
4534 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004535
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004536 gl::Program *programObject = context->getProgram(program);
4537
4538 if (!programObject)
4539 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004540 if (context->getShader(program))
4541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004542 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004543 }
4544 else
4545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004546 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004547 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004548 }
4549
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004550 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004551 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004552 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004553 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004554 }
4555
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004556 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004557 }
4558 }
4559 catch(std::bad_alloc&)
4560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004561 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 }
4563
4564 return -1;
4565}
4566
4567void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4568{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004569 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570
4571 try
4572 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004573 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004574
4575 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004576 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004577 if (!(context->getBooleanv(pname, params)))
4578 {
4579 GLenum nativeType;
4580 unsigned int numParams = 0;
4581 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004582 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004583
4584 if (numParams == 0)
4585 return; // it is known that the pname is valid, but there are no parameters to return
4586
4587 if (nativeType == GL_FLOAT)
4588 {
4589 GLfloat *floatParams = NULL;
4590 floatParams = new GLfloat[numParams];
4591
4592 context->getFloatv(pname, floatParams);
4593
4594 for (unsigned int i = 0; i < numParams; ++i)
4595 {
4596 if (floatParams[i] == 0.0f)
4597 params[i] = GL_FALSE;
4598 else
4599 params[i] = GL_TRUE;
4600 }
4601
4602 delete [] floatParams;
4603 }
4604 else if (nativeType == GL_INT)
4605 {
4606 GLint *intParams = NULL;
4607 intParams = new GLint[numParams];
4608
4609 context->getIntegerv(pname, intParams);
4610
4611 for (unsigned int i = 0; i < numParams; ++i)
4612 {
4613 if (intParams[i] == 0)
4614 params[i] = GL_FALSE;
4615 else
4616 params[i] = GL_TRUE;
4617 }
4618
4619 delete [] intParams;
4620 }
4621 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004622 }
4623 }
4624 catch(std::bad_alloc&)
4625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627 }
4628}
4629
4630void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 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 +00004633
4634 try
4635 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004637
4638 if (context)
4639 {
4640 gl::Buffer *buffer;
4641
4642 switch (target)
4643 {
4644 case GL_ARRAY_BUFFER:
4645 buffer = context->getArrayBuffer();
4646 break;
4647 case GL_ELEMENT_ARRAY_BUFFER:
4648 buffer = context->getElementArrayBuffer();
4649 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004650 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004651 }
4652
4653 if (!buffer)
4654 {
4655 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004656 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004657 }
4658
4659 switch (pname)
4660 {
4661 case GL_BUFFER_USAGE:
4662 *params = buffer->usage();
4663 break;
4664 case GL_BUFFER_SIZE:
4665 *params = buffer->size();
4666 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004667 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004668 }
4669 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670 }
4671 catch(std::bad_alloc&)
4672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674 }
4675}
4676
4677GLenum __stdcall glGetError(void)
4678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004679 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004680
4681 gl::Context *context = gl::getContext();
4682
4683 if (context)
4684 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004685 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004686 }
4687
4688 return GL_NO_ERROR;
4689}
4690
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004691void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004693 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004694
4695 try
4696 {
4697
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004698 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004699
4700 if (context)
4701 {
4702 gl::Fence *fenceObject = context->getFence(fence);
4703
4704 if (fenceObject == NULL)
4705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004706 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004707 }
4708
4709 fenceObject->getFenceiv(pname, params);
4710 }
4711 }
4712 catch(std::bad_alloc&)
4713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004714 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004715 }
4716}
4717
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4719{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004720 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721
4722 try
4723 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004724 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004725
4726 if (context)
4727 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004728 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004729 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004730 GLenum nativeType;
4731 unsigned int numParams = 0;
4732 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004733 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004734
4735 if (numParams == 0)
4736 return; // it is known that the pname is valid, but that there are no parameters to return.
4737
4738 if (nativeType == GL_BOOL)
4739 {
4740 GLboolean *boolParams = NULL;
4741 boolParams = new GLboolean[numParams];
4742
4743 context->getBooleanv(pname, boolParams);
4744
4745 for (unsigned int i = 0; i < numParams; ++i)
4746 {
4747 if (boolParams[i] == GL_FALSE)
4748 params[i] = 0.0f;
4749 else
4750 params[i] = 1.0f;
4751 }
4752
4753 delete [] boolParams;
4754 }
4755 else if (nativeType == GL_INT)
4756 {
4757 GLint *intParams = NULL;
4758 intParams = new GLint[numParams];
4759
4760 context->getIntegerv(pname, intParams);
4761
4762 for (unsigned int i = 0; i < numParams; ++i)
4763 {
4764 params[i] = (GLfloat)intParams[i];
4765 }
4766
4767 delete [] intParams;
4768 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004769 }
4770 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004771 }
4772 catch(std::bad_alloc&)
4773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004774 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004775 }
4776}
4777
4778void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
4779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004780 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 +00004781 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004782
4783 try
4784 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004785 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004786
4787 if (context)
4788 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004789 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004790 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004791 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004792 }
4793
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004794 gl::Framebuffer *framebuffer = NULL;
4795 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4796 {
4797 if(context->getReadFramebufferHandle() == 0)
4798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004799 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004800 }
4801
4802 framebuffer = context->getReadFramebuffer();
4803 }
4804 else
4805 {
4806 if (context->getDrawFramebufferHandle() == 0)
4807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004808 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004809 }
4810
4811 framebuffer = context->getDrawFramebuffer();
4812 }
4813
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004814 GLenum attachmentType;
4815 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004816
4817 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004818 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004819 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4820
4821 if (colorAttachment >= context->getMaximumRenderTargets())
4822 {
4823 return gl::error(GL_INVALID_ENUM);
4824 }
4825
4826 attachmentType = framebuffer->getColorbufferType(colorAttachment);
4827 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
4828 }
4829 else
4830 {
4831 switch (attachment)
4832 {
4833 case GL_DEPTH_ATTACHMENT:
4834 attachmentType = framebuffer->getDepthbufferType();
4835 attachmentHandle = framebuffer->getDepthbufferHandle();
4836 break;
4837 case GL_STENCIL_ATTACHMENT:
4838 attachmentType = framebuffer->getStencilbufferType();
4839 attachmentHandle = framebuffer->getStencilbufferHandle();
4840 break;
4841 default: return gl::error(GL_INVALID_ENUM);
4842 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004843 }
4844
4845 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004846 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004847 {
4848 attachmentObjectType = attachmentType;
4849 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00004850 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004851 {
4852 attachmentObjectType = GL_TEXTURE;
4853 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00004854 else
4855 {
4856 UNREACHABLE();
4857 return;
4858 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004859
4860 switch (pname)
4861 {
4862 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
4863 *params = attachmentObjectType;
4864 break;
4865 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
4866 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
4867 {
4868 *params = attachmentHandle;
4869 }
4870 else
4871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004872 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004873 }
4874 break;
4875 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
4876 if (attachmentObjectType == GL_TEXTURE)
4877 {
4878 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
4879 }
4880 else
4881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004882 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004883 }
4884 break;
4885 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
4886 if (attachmentObjectType == GL_TEXTURE)
4887 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00004888 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004889 {
4890 *params = attachmentType;
4891 }
4892 else
4893 {
4894 *params = 0;
4895 }
4896 }
4897 else
4898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004899 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004900 }
4901 break;
4902 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00004904 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004905 }
4906 }
4907 catch(std::bad_alloc&)
4908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004910 }
4911}
4912
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00004913GLenum __stdcall glGetGraphicsResetStatusEXT(void)
4914{
4915 EVENT("()");
4916
4917 try
4918 {
4919 gl::Context *context = gl::getContext();
4920
4921 if (context)
4922 {
4923 return context->getResetStatus();
4924 }
4925
4926 return GL_NO_ERROR;
4927 }
4928 catch(std::bad_alloc&)
4929 {
4930 return GL_OUT_OF_MEMORY;
4931 }
4932}
4933
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004934void __stdcall glGetIntegerv(GLenum pname, GLint* params)
4935{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004936 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004937
4938 try
4939 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004940 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004941
4942 if (context)
4943 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004944 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004945 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004946 GLenum nativeType;
4947 unsigned int numParams = 0;
4948 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004949 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004950
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004951 if (numParams == 0)
4952 return; // it is known that pname is valid, but there are no parameters to return
4953
4954 if (nativeType == GL_BOOL)
4955 {
4956 GLboolean *boolParams = NULL;
4957 boolParams = new GLboolean[numParams];
4958
4959 context->getBooleanv(pname, boolParams);
4960
4961 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004962 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004963 if (boolParams[i] == GL_FALSE)
4964 params[i] = 0;
4965 else
4966 params[i] = 1;
4967 }
4968
4969 delete [] boolParams;
4970 }
4971 else if (nativeType == GL_FLOAT)
4972 {
4973 GLfloat *floatParams = NULL;
4974 floatParams = new GLfloat[numParams];
4975
4976 context->getFloatv(pname, floatParams);
4977
4978 for (unsigned int i = 0; i < numParams; ++i)
4979 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00004980 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 +00004981 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004982 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004983 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004984 else
4985 params[i] = (GLint)(floatParams[i] > 0.0f ? floor(floatParams[i] + 0.5) : ceil(floatParams[i] - 0.5));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004986 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004987
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004988 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004989 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004990 }
4991 }
4992 }
4993 catch(std::bad_alloc&)
4994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004995 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004996 }
4997}
4998
4999void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5000{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005001 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005002
5003 try
5004 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005005 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005006
5007 if (context)
5008 {
5009 gl::Program *programObject = context->getProgram(program);
5010
5011 if (!programObject)
5012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005013 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005014 }
5015
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005016 if (context->getClientVersion() < 3)
5017 {
5018 switch (pname)
5019 {
5020 case GL_ACTIVE_UNIFORM_BLOCKS:
5021 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5022 return gl::error(GL_INVALID_ENUM);
5023 }
5024 }
5025
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005026 switch (pname)
5027 {
5028 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005029 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005030 return;
5031 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005032 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005033 return;
5034 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005035 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005036 return;
5037 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005038 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005039 return;
5040 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005041 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005042 return;
5043 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005044 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005045 return;
5046 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005047 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005048 return;
5049 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005050 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005051 return;
5052 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005053 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005054 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005055 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005056 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005057 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005058 case GL_ACTIVE_UNIFORM_BLOCKS:
5059 *params = programObject->getActiveUniformBlockCount();
5060 return;
5061 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5062 *params = programObject->getActiveUniformBlockMaxLength();
5063 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005064 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005065 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005066 }
5067 }
5068 }
5069 catch(std::bad_alloc&)
5070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005071 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005072 }
5073}
5074
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005075void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005076{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005077 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 +00005078 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005079
5080 try
5081 {
5082 if (bufsize < 0)
5083 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005084 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005085 }
5086
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005087 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005088
5089 if (context)
5090 {
5091 gl::Program *programObject = context->getProgram(program);
5092
5093 if (!programObject)
5094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005095 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005096 }
5097
5098 programObject->getInfoLog(bufsize, length, infolog);
5099 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005100 }
5101 catch(std::bad_alloc&)
5102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005103 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005104 }
5105}
5106
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005107void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5108{
5109 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5110
5111 try
5112 {
5113 switch (pname)
5114 {
5115 case GL_CURRENT_QUERY_EXT:
5116 break;
5117 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005118 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005119 }
5120
5121 gl::Context *context = gl::getNonLostContext();
5122
5123 if (context)
5124 {
5125 params[0] = context->getActiveQuery(target);
5126 }
5127 }
5128 catch(std::bad_alloc&)
5129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005130 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005131 }
5132}
5133
5134void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5135{
5136 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5137
5138 try
5139 {
5140 switch (pname)
5141 {
5142 case GL_QUERY_RESULT_EXT:
5143 case GL_QUERY_RESULT_AVAILABLE_EXT:
5144 break;
5145 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005146 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005147 }
5148 gl::Context *context = gl::getNonLostContext();
5149
5150 if (context)
5151 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005152 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5153
5154 if (!queryObject)
5155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005156 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005157 }
5158
5159 if (context->getActiveQuery(queryObject->getType()) == id)
5160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005161 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005162 }
5163
5164 switch(pname)
5165 {
5166 case GL_QUERY_RESULT_EXT:
5167 params[0] = queryObject->getResult();
5168 break;
5169 case GL_QUERY_RESULT_AVAILABLE_EXT:
5170 params[0] = queryObject->isResultAvailable();
5171 break;
5172 default:
5173 ASSERT(false);
5174 }
5175 }
5176 }
5177 catch(std::bad_alloc&)
5178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005179 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005180 }
5181}
5182
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005183void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5184{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005185 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 +00005186
5187 try
5188 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005190
5191 if (context)
5192 {
5193 if (target != GL_RENDERBUFFER)
5194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005195 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005196 }
5197
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005198 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005199 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005200 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005201 }
5202
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005203 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005204
5205 switch (pname)
5206 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005207 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5208 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5209 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5210 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5211 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5212 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5213 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5214 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5215 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005216 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005217 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005218 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005219 *params = renderbuffer->getSamples();
5220 }
5221 else
5222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005223 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005224 }
5225 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005226 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005228 }
5229 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005230 }
5231 catch(std::bad_alloc&)
5232 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005233 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234 }
5235}
5236
5237void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5238{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005239 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005240
5241 try
5242 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005244
5245 if (context)
5246 {
5247 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005248
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005249 if (!shaderObject)
5250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005251 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005252 }
5253
5254 switch (pname)
5255 {
5256 case GL_SHADER_TYPE:
5257 *params = shaderObject->getType();
5258 return;
5259 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005260 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 return;
5262 case GL_COMPILE_STATUS:
5263 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5264 return;
5265 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005266 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005267 return;
5268 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005269 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005270 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005271 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5272 *params = shaderObject->getTranslatedSourceLength();
5273 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005274 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005275 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005276 }
5277 }
5278 }
5279 catch(std::bad_alloc&)
5280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005281 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005282 }
5283}
5284
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005285void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005286{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005287 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 +00005288 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005289
5290 try
5291 {
5292 if (bufsize < 0)
5293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005294 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005295 }
5296
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005297 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005298
5299 if (context)
5300 {
5301 gl::Shader *shaderObject = context->getShader(shader);
5302
5303 if (!shaderObject)
5304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005305 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005306 }
5307
5308 shaderObject->getInfoLog(bufsize, length, infolog);
5309 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005310 }
5311 catch(std::bad_alloc&)
5312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005313 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005314 }
5315}
5316
5317void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005319 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 +00005320 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005321
5322 try
5323 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005324 switch (shadertype)
5325 {
5326 case GL_VERTEX_SHADER:
5327 case GL_FRAGMENT_SHADER:
5328 break;
5329 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005330 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005331 }
5332
5333 switch (precisiontype)
5334 {
5335 case GL_LOW_FLOAT:
5336 case GL_MEDIUM_FLOAT:
5337 case GL_HIGH_FLOAT:
5338 // Assume IEEE 754 precision
5339 range[0] = 127;
5340 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005341 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005342 break;
5343 case GL_LOW_INT:
5344 case GL_MEDIUM_INT:
5345 case GL_HIGH_INT:
5346 // Some (most) hardware only supports single-precision floating-point numbers,
5347 // which can accurately represent integers up to +/-16777216
5348 range[0] = 24;
5349 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005350 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005351 break;
5352 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005353 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005354 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005355 }
5356 catch(std::bad_alloc&)
5357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005358 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005359 }
5360}
5361
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005362void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005363{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005364 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 +00005365 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005366
5367 try
5368 {
5369 if (bufsize < 0)
5370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005371 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005372 }
5373
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005374 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005375
5376 if (context)
5377 {
5378 gl::Shader *shaderObject = context->getShader(shader);
5379
5380 if (!shaderObject)
5381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005382 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005383 }
5384
5385 shaderObject->getSource(bufsize, length, source);
5386 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005387 }
5388 catch(std::bad_alloc&)
5389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005390 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005391 }
5392}
5393
zmo@google.coma574f782011-10-03 21:45:23 +00005394void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5395{
5396 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5397 shader, bufsize, length, source);
5398
5399 try
5400 {
5401 if (bufsize < 0)
5402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005403 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005404 }
5405
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005406 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005407
5408 if (context)
5409 {
5410 gl::Shader *shaderObject = context->getShader(shader);
5411
5412 if (!shaderObject)
5413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005414 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005415 }
5416
5417 shaderObject->getTranslatedSource(bufsize, length, source);
5418 }
5419 }
5420 catch(std::bad_alloc&)
5421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005422 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005423 }
5424}
5425
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005426const GLubyte* __stdcall glGetString(GLenum name)
5427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005428 EVENT("(GLenum name = 0x%X)", name);
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.com3e4c6002010-05-05 18:50:13 +00005433
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005434 switch (name)
5435 {
5436 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005437 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005438 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005439 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005440 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005441 if (context->getClientVersion() == 2)
5442 {
5443 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5444 }
5445 else
5446 {
5447 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5448 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005449 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005450 if (context->getClientVersion() == 2)
5451 {
5452 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5453 }
5454 else
5455 {
5456 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5457 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005458 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005459 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005460 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005461 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005462 }
5463 }
5464 catch(std::bad_alloc&)
5465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005466 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005467 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005468}
5469
5470void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5471{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005472 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 +00005473
5474 try
5475 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005476 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005477
5478 if (context)
5479 {
5480 gl::Texture *texture;
5481
5482 switch (target)
5483 {
5484 case GL_TEXTURE_2D:
5485 texture = context->getTexture2D();
5486 break;
5487 case GL_TEXTURE_CUBE_MAP:
5488 texture = context->getTextureCubeMap();
5489 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005490 case GL_TEXTURE_3D:
5491 if (context->getClientVersion() < 3)
5492 {
5493 return gl::error(GL_INVALID_ENUM);
5494 }
5495 texture = context->getTexture3D();
5496 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005497 case GL_TEXTURE_2D_ARRAY:
5498 if (context->getClientVersion() < 3)
5499 {
5500 return gl::error(GL_INVALID_ENUM);
5501 }
5502 texture = context->getTexture2DArray();
5503 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005504 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005505 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005506 }
5507
5508 switch (pname)
5509 {
5510 case GL_TEXTURE_MAG_FILTER:
5511 *params = (GLfloat)texture->getMagFilter();
5512 break;
5513 case GL_TEXTURE_MIN_FILTER:
5514 *params = (GLfloat)texture->getMinFilter();
5515 break;
5516 case GL_TEXTURE_WRAP_S:
5517 *params = (GLfloat)texture->getWrapS();
5518 break;
5519 case GL_TEXTURE_WRAP_T:
5520 *params = (GLfloat)texture->getWrapT();
5521 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005522 case GL_TEXTURE_WRAP_R:
5523 if (context->getClientVersion() < 3)
5524 {
5525 return gl::error(GL_INVALID_ENUM);
5526 }
5527 *params = (GLfloat)texture->getWrapR();
5528 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005529 case GL_TEXTURE_IMMUTABLE_FORMAT:
5530 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005531 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5532 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005533 case GL_TEXTURE_IMMUTABLE_LEVELS:
5534 if (context->getClientVersion() < 3)
5535 {
5536 return gl::error(GL_INVALID_ENUM);
5537 }
5538 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5539 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005540 case GL_TEXTURE_USAGE_ANGLE:
5541 *params = (GLfloat)texture->getUsage();
5542 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005543 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5544 if (!context->supportsTextureFilterAnisotropy())
5545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005546 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005547 }
5548 *params = (GLfloat)texture->getMaxAnisotropy();
5549 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005550 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005551 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005552 }
5553 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005554 }
5555 catch(std::bad_alloc&)
5556 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005557 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005558 }
5559}
5560
5561void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5562{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005563 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 +00005564
5565 try
5566 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005567 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005568
5569 if (context)
5570 {
5571 gl::Texture *texture;
5572
5573 switch (target)
5574 {
5575 case GL_TEXTURE_2D:
5576 texture = context->getTexture2D();
5577 break;
5578 case GL_TEXTURE_CUBE_MAP:
5579 texture = context->getTextureCubeMap();
5580 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00005581 case GL_TEXTURE_3D:
5582 if (context->getClientVersion() < 3)
5583 {
5584 return gl::error(GL_INVALID_ENUM);
5585 }
5586 texture = context->getTexture3D();
5587 break;
shannonwoods@chromium.org0c611d12013-05-30 00:15:05 +00005588 case GL_TEXTURE_2D_ARRAY:
5589 if (context->getClientVersion() < 3)
5590 {
5591 return gl::error(GL_INVALID_ENUM);
5592 }
5593 texture = context->getTexture2DArray();
5594 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005595 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005596 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005597 }
5598
5599 switch (pname)
5600 {
5601 case GL_TEXTURE_MAG_FILTER:
5602 *params = texture->getMagFilter();
5603 break;
5604 case GL_TEXTURE_MIN_FILTER:
5605 *params = texture->getMinFilter();
5606 break;
5607 case GL_TEXTURE_WRAP_S:
5608 *params = texture->getWrapS();
5609 break;
5610 case GL_TEXTURE_WRAP_T:
5611 *params = texture->getWrapT();
5612 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005613 case GL_TEXTURE_WRAP_R:
5614 if (context->getClientVersion() < 3)
5615 {
5616 return gl::error(GL_INVALID_ENUM);
5617 }
5618 *params = texture->getWrapR();
5619 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005620 case GL_TEXTURE_IMMUTABLE_FORMAT:
5621 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005622 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5623 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005624 case GL_TEXTURE_IMMUTABLE_LEVELS:
5625 if (context->getClientVersion() < 3)
5626 {
5627 return gl::error(GL_INVALID_ENUM);
5628 }
5629 *params = texture->isImmutable() ? texture->levelCount() : 0;
5630 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005631 case GL_TEXTURE_USAGE_ANGLE:
5632 *params = texture->getUsage();
5633 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005634 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5635 if (!context->supportsTextureFilterAnisotropy())
5636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005637 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005638 }
5639 *params = (GLint)texture->getMaxAnisotropy();
5640 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005641
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005642 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005643 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005644 }
5645 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005646 }
5647 catch(std::bad_alloc&)
5648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005649 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005650 }
5651}
5652
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005653void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5654{
5655 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5656 program, location, bufSize, params);
5657
5658 try
5659 {
5660 if (bufSize < 0)
5661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005662 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005663 }
5664
5665 gl::Context *context = gl::getNonLostContext();
5666
5667 if (context)
5668 {
5669 if (program == 0)
5670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005671 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005672 }
5673
5674 gl::Program *programObject = context->getProgram(program);
5675
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005676 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005678 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005679 }
5680
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005681 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5682 if (!programBinary)
5683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005684 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005685 }
5686
5687 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005688 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005689 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005690 }
5691 }
5692 }
5693 catch(std::bad_alloc&)
5694 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005695 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005696 }
5697}
5698
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005699void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5700{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005701 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005702
5703 try
5704 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005705 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005706
5707 if (context)
5708 {
5709 if (program == 0)
5710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005711 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005712 }
5713
5714 gl::Program *programObject = context->getProgram(program);
5715
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005716 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005718 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005719 }
5720
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005721 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5722 if (!programBinary)
5723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005724 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005725 }
5726
5727 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005729 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005730 }
5731 }
5732 }
5733 catch(std::bad_alloc&)
5734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005735 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005736 }
5737}
5738
5739void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5740{
5741 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5742 program, location, bufSize, params);
5743
5744 try
5745 {
5746 if (bufSize < 0)
5747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005748 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005749 }
5750
5751 gl::Context *context = gl::getNonLostContext();
5752
5753 if (context)
5754 {
5755 if (program == 0)
5756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005757 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005758 }
5759
5760 gl::Program *programObject = context->getProgram(program);
5761
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005762 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005764 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005765 }
5766
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005767 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5768 if (!programBinary)
5769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005770 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005771 }
5772
5773 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005775 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005776 }
5777 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005778 }
5779 catch(std::bad_alloc&)
5780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005781 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005782 }
5783}
5784
5785void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5786{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005787 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005788
5789 try
5790 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005791 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005792
5793 if (context)
5794 {
5795 if (program == 0)
5796 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005797 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005798 }
5799
5800 gl::Program *programObject = context->getProgram(program);
5801
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005802 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005804 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005805 }
5806
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005807 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5808 if (!programBinary)
5809 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005810 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005811 }
5812
5813 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005815 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005816 }
5817 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005818 }
5819 catch(std::bad_alloc&)
5820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005821 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005822 }
5823}
5824
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005825int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005826{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005827 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005828
5829 try
5830 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005832
5833 if (strstr(name, "gl_") == name)
5834 {
5835 return -1;
5836 }
5837
5838 if (context)
5839 {
5840 gl::Program *programObject = context->getProgram(program);
5841
5842 if (!programObject)
5843 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005844 if (context->getShader(program))
5845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005846 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005847 }
5848 else
5849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005850 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00005851 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005852 }
5853
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005854 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005855 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005857 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005858 }
5859
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005860 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005861 }
5862 }
5863 catch(std::bad_alloc&)
5864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005865 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005866 }
5867
5868 return -1;
5869}
5870
5871void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
5872{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005873 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005874
5875 try
5876 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005877 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005878
daniel@transgaming.come0078962010-04-15 20:45:08 +00005879 if (context)
5880 {
5881 if (index >= gl::MAX_VERTEX_ATTRIBS)
5882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005883 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005884 }
5885
daniel@transgaming.com83921382011-01-08 05:46:00 +00005886 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005887
Jamie Madillaff71502013-07-02 11:57:05 -04005888 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005889 {
Jamie Madillaff71502013-07-02 11:57:05 -04005890 return;
5891 }
5892
5893 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5894 {
5895 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5896 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005897 {
Jamie Madillaff71502013-07-02 11:57:05 -04005898 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00005899 }
Jamie Madillaff71502013-07-02 11:57:05 -04005900 }
5901 else
5902 {
5903 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005904 }
5905 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005906 }
5907 catch(std::bad_alloc&)
5908 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005909 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005910 }
5911}
5912
5913void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5914{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005915 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005916
5917 try
5918 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005919 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005920
daniel@transgaming.come0078962010-04-15 20:45:08 +00005921 if (context)
5922 {
5923 if (index >= gl::MAX_VERTEX_ATTRIBS)
5924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005925 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005926 }
5927
daniel@transgaming.com83921382011-01-08 05:46:00 +00005928 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005929
Jamie Madillaff71502013-07-02 11:57:05 -04005930 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00005931 {
Jamie Madillaff71502013-07-02 11:57:05 -04005932 return;
5933 }
5934
5935 if (pname == GL_CURRENT_VERTEX_ATTRIB)
5936 {
5937 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5938 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00005939 {
Jamie Madillaff71502013-07-02 11:57:05 -04005940 float currentValue = currentValueData.FloatValues[i];
5941 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005942 }
Jamie Madillaff71502013-07-02 11:57:05 -04005943 }
5944 else
5945 {
5946 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005947 }
5948 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005949 }
5950 catch(std::bad_alloc&)
5951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005952 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005953 }
5954}
5955
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005956void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005957{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005958 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005959
5960 try
5961 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005962 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005963
daniel@transgaming.come0078962010-04-15 20:45:08 +00005964 if (context)
5965 {
5966 if (index >= gl::MAX_VERTEX_ATTRIBS)
5967 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005968 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005969 }
5970
5971 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5972 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005973 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005974 }
5975
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005976 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005977 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005978 }
5979 catch(std::bad_alloc&)
5980 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005981 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005982 }
5983}
5984
5985void __stdcall glHint(GLenum target, GLenum mode)
5986{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005987 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005988
5989 try
5990 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005991 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005992 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00005993 case GL_FASTEST:
5994 case GL_NICEST:
5995 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005996 break;
5997 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005998 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00005999 }
6000
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006001 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006002 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006003 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006004 case GL_GENERATE_MIPMAP_HINT:
6005 if (context) context->setGenerateMipmapHint(mode);
6006 break;
6007 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6008 if (context) context->setFragmentShaderDerivativeHint(mode);
6009 break;
6010 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006011 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006012 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006013 }
6014 catch(std::bad_alloc&)
6015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006016 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006017 }
6018}
6019
6020GLboolean __stdcall glIsBuffer(GLuint buffer)
6021{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006022 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006023
6024 try
6025 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006026 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006027
6028 if (context && buffer)
6029 {
6030 gl::Buffer *bufferObject = context->getBuffer(buffer);
6031
6032 if (bufferObject)
6033 {
6034 return GL_TRUE;
6035 }
6036 }
6037 }
6038 catch(std::bad_alloc&)
6039 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006040 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006041 }
6042
6043 return GL_FALSE;
6044}
6045
6046GLboolean __stdcall glIsEnabled(GLenum cap)
6047{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006048 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006049
6050 try
6051 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006052 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006053
6054 if (context)
6055 {
6056 switch (cap)
6057 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006058 case GL_CULL_FACE: return context->isCullFaceEnabled();
6059 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6060 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6061 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6062 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6063 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6064 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6065 case GL_BLEND: return context->isBlendEnabled();
6066 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006067 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006068 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006069 }
6070 }
6071 }
6072 catch(std::bad_alloc&)
6073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006074 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006075 }
6076
6077 return false;
6078}
6079
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006080GLboolean __stdcall glIsFenceNV(GLuint fence)
6081{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006082 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006083
6084 try
6085 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006086 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006087
6088 if (context)
6089 {
6090 gl::Fence *fenceObject = context->getFence(fence);
6091
6092 if (fenceObject == NULL)
6093 {
6094 return GL_FALSE;
6095 }
6096
6097 return fenceObject->isFence();
6098 }
6099 }
6100 catch(std::bad_alloc&)
6101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006102 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006103 }
6104
6105 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006106}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006107
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006108GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6109{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006110 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006111
6112 try
6113 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006114 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006115
6116 if (context && framebuffer)
6117 {
6118 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6119
6120 if (framebufferObject)
6121 {
6122 return GL_TRUE;
6123 }
6124 }
6125 }
6126 catch(std::bad_alloc&)
6127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006128 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006129 }
6130
6131 return GL_FALSE;
6132}
6133
6134GLboolean __stdcall glIsProgram(GLuint program)
6135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006136 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006137
6138 try
6139 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006140 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006141
6142 if (context && program)
6143 {
6144 gl::Program *programObject = context->getProgram(program);
6145
6146 if (programObject)
6147 {
6148 return GL_TRUE;
6149 }
6150 }
6151 }
6152 catch(std::bad_alloc&)
6153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006154 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006155 }
6156
6157 return GL_FALSE;
6158}
6159
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006160GLboolean __stdcall glIsQueryEXT(GLuint id)
6161{
6162 EVENT("(GLuint id = %d)", id);
6163
6164 try
6165 {
6166 if (id == 0)
6167 {
6168 return GL_FALSE;
6169 }
6170
6171 gl::Context *context = gl::getNonLostContext();
6172
6173 if (context)
6174 {
6175 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6176
6177 if (queryObject)
6178 {
6179 return GL_TRUE;
6180 }
6181 }
6182 }
6183 catch(std::bad_alloc&)
6184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006185 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006186 }
6187
6188 return GL_FALSE;
6189}
6190
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006191GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6192{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006193 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006194
6195 try
6196 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006197 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006198
6199 if (context && renderbuffer)
6200 {
6201 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6202
6203 if (renderbufferObject)
6204 {
6205 return GL_TRUE;
6206 }
6207 }
6208 }
6209 catch(std::bad_alloc&)
6210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006211 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006212 }
6213
6214 return GL_FALSE;
6215}
6216
6217GLboolean __stdcall glIsShader(GLuint shader)
6218{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006219 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006220
6221 try
6222 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006223 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006224
6225 if (context && shader)
6226 {
6227 gl::Shader *shaderObject = context->getShader(shader);
6228
6229 if (shaderObject)
6230 {
6231 return GL_TRUE;
6232 }
6233 }
6234 }
6235 catch(std::bad_alloc&)
6236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006237 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006238 }
6239
6240 return GL_FALSE;
6241}
6242
6243GLboolean __stdcall glIsTexture(GLuint texture)
6244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006245 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006246
6247 try
6248 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006249 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006250
6251 if (context && texture)
6252 {
6253 gl::Texture *textureObject = context->getTexture(texture);
6254
6255 if (textureObject)
6256 {
6257 return GL_TRUE;
6258 }
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, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006264 }
6265
6266 return GL_FALSE;
6267}
6268
6269void __stdcall glLineWidth(GLfloat width)
6270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006271 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006272
6273 try
6274 {
6275 if (width <= 0.0f)
6276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006278 }
6279
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006280 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006281
6282 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006283 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006284 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006285 }
6286 }
6287 catch(std::bad_alloc&)
6288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006289 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 }
6291}
6292
6293void __stdcall glLinkProgram(GLuint program)
6294{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006295 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006296
6297 try
6298 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006299 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006300
6301 if (context)
6302 {
6303 gl::Program *programObject = context->getProgram(program);
6304
6305 if (!programObject)
6306 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006307 if (context->getShader(program))
6308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006309 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006310 }
6311 else
6312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006313 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006314 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006315 }
6316
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006317 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006318 }
6319 }
6320 catch(std::bad_alloc&)
6321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006322 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006323 }
6324}
6325
6326void __stdcall glPixelStorei(GLenum pname, GLint param)
6327{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006328 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006329
6330 try
6331 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006332 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006333
6334 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006335 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006336 switch (pname)
6337 {
6338 case GL_UNPACK_ALIGNMENT:
6339 if (param != 1 && param != 2 && param != 4 && param != 8)
6340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006341 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006342 }
6343
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006344 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006345 break;
6346
6347 case GL_PACK_ALIGNMENT:
6348 if (param != 1 && param != 2 && param != 4 && param != 8)
6349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006350 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006351 }
6352
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006353 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006354 break;
6355
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006356 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6357 context->setPackReverseRowOrder(param != 0);
6358 break;
6359
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006360 case GL_UNPACK_IMAGE_HEIGHT:
6361 case GL_UNPACK_SKIP_IMAGES:
6362 case GL_UNPACK_ROW_LENGTH:
6363 case GL_UNPACK_SKIP_ROWS:
6364 case GL_UNPACK_SKIP_PIXELS:
6365 case GL_PACK_ROW_LENGTH:
6366 case GL_PACK_SKIP_ROWS:
6367 case GL_PACK_SKIP_PIXELS:
6368 if (context->getClientVersion() < 3)
6369 {
6370 return gl::error(GL_INVALID_ENUM);
6371 }
6372 UNIMPLEMENTED();
6373 break;
6374
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006375 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006376 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006377 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006378 }
6379 }
6380 catch(std::bad_alloc&)
6381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006382 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006383 }
6384}
6385
6386void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6387{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006388 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006389
6390 try
6391 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006392 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006393
6394 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006395 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006396 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006397 }
6398 }
6399 catch(std::bad_alloc&)
6400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006401 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006402 }
6403}
6404
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006405void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6406 GLenum format, GLenum type, GLsizei bufSize,
6407 GLvoid *data)
6408{
6409 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6410 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6411 x, y, width, height, format, type, bufSize, data);
6412
6413 try
6414 {
6415 if (width < 0 || height < 0 || bufSize < 0)
6416 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006417 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006418 }
6419
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006420 gl::Context *context = gl::getNonLostContext();
6421
6422 if (context)
6423 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006424 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006425 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006426
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006427 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6428 // and attempting to read back if that's the case is an error. The error will be registered
6429 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006430 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006431 return;
6432
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006433 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6434 validES3ReadFormatType(currentInternalFormat, format, type);
6435
6436 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006437 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006438 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006439 }
6440
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006441 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6442 }
6443 }
6444 catch(std::bad_alloc&)
6445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006446 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006447 }
6448}
6449
6450void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6451 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006452{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006453 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006454 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006455 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006456
6457 try
6458 {
6459 if (width < 0 || height < 0)
6460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006461 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006462 }
6463
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006464 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006465
6466 if (context)
6467 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006468 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006469 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006470
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006471 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6472 // and attempting to read back if that's the case is an error. The error will be registered
6473 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006474 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006475 return;
6476
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006477 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6478 validES3ReadFormatType(currentInternalFormat, format, type);
6479
6480 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006482 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006483 }
6484
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006485 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006486 }
6487 }
6488 catch(std::bad_alloc&)
6489 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006490 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006491 }
6492}
6493
6494void __stdcall glReleaseShaderCompiler(void)
6495{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006496 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006497
6498 try
6499 {
6500 gl::Shader::releaseCompiler();
6501 }
6502 catch(std::bad_alloc&)
6503 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006504 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006505 }
6506}
6507
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006508void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006509{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006510 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 +00006511 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006512
6513 try
6514 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006515 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006516
6517 if (context)
6518 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006519 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6520 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006521 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006522 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006523 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006524
6525 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006526 }
6527 }
6528 catch(std::bad_alloc&)
6529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006531 }
6532}
6533
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006534void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6535{
6536 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6537}
6538
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006539void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6540{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006541 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006542
6543 try
6544 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006545 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006546
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006547 if (context)
6548 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006549 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006550 }
6551 }
6552 catch(std::bad_alloc&)
6553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006555 }
6556}
6557
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006558void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006560 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006561
6562 try
6563 {
6564 if (condition != GL_ALL_COMPLETED_NV)
6565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006566 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006567 }
6568
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006569 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006570
6571 if (context)
6572 {
6573 gl::Fence *fenceObject = context->getFence(fence);
6574
6575 if (fenceObject == NULL)
6576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006577 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006578 }
6579
6580 fenceObject->setFence(condition);
6581 }
6582 }
6583 catch(std::bad_alloc&)
6584 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006585 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006586 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006587}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006588
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006589void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6590{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006591 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 +00006592
6593 try
6594 {
6595 if (width < 0 || height < 0)
6596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006597 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006598 }
6599
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006600 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006601
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006602 if (context)
6603 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006604 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006605 }
6606 }
6607 catch(std::bad_alloc&)
6608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006609 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006610 }
6611}
6612
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006613void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006614{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006615 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006616 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006617 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006618
6619 try
6620 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006621 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006622 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006623 }
6624 catch(std::bad_alloc&)
6625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006627 }
6628}
6629
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006630void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006632 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 +00006633 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006634
6635 try
6636 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006637 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006639 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006640 }
6641
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006642 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006643
6644 if (context)
6645 {
6646 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006647
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006648 if (!shaderObject)
6649 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006650 if (context->getProgram(shader))
6651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006652 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006653 }
6654 else
6655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006656 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006657 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006658 }
6659
6660 shaderObject->setSource(count, string, length);
6661 }
6662 }
6663 catch(std::bad_alloc&)
6664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006665 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006666 }
6667}
6668
6669void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6670{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006671 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006672}
6673
6674void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006676 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 +00006677
6678 try
6679 {
6680 switch (face)
6681 {
6682 case GL_FRONT:
6683 case GL_BACK:
6684 case GL_FRONT_AND_BACK:
6685 break;
6686 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006687 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006688 }
6689
6690 switch (func)
6691 {
6692 case GL_NEVER:
6693 case GL_ALWAYS:
6694 case GL_LESS:
6695 case GL_LEQUAL:
6696 case GL_EQUAL:
6697 case GL_GEQUAL:
6698 case GL_GREATER:
6699 case GL_NOTEQUAL:
6700 break;
6701 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006702 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006703 }
6704
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006705 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006706
6707 if (context)
6708 {
6709 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6710 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006711 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006712 }
6713
6714 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6715 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006716 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717 }
6718 }
6719 }
6720 catch(std::bad_alloc&)
6721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006722 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006723 }
6724}
6725
6726void __stdcall glStencilMask(GLuint mask)
6727{
6728 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6729}
6730
6731void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6732{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006733 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006734
6735 try
6736 {
6737 switch (face)
6738 {
6739 case GL_FRONT:
6740 case GL_BACK:
6741 case GL_FRONT_AND_BACK:
6742 break;
6743 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006744 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006745 }
6746
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006747 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006748
6749 if (context)
6750 {
6751 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6752 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006753 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006754 }
6755
6756 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6757 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006758 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006759 }
6760 }
6761 }
6762 catch(std::bad_alloc&)
6763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006764 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006765 }
6766}
6767
6768void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6769{
6770 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6771}
6772
6773void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006775 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 +00006776 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006777
6778 try
6779 {
6780 switch (face)
6781 {
6782 case GL_FRONT:
6783 case GL_BACK:
6784 case GL_FRONT_AND_BACK:
6785 break;
6786 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006787 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006788 }
6789
6790 switch (fail)
6791 {
6792 case GL_ZERO:
6793 case GL_KEEP:
6794 case GL_REPLACE:
6795 case GL_INCR:
6796 case GL_DECR:
6797 case GL_INVERT:
6798 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006799 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006800 break;
6801 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006802 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006803 }
6804
6805 switch (zfail)
6806 {
6807 case GL_ZERO:
6808 case GL_KEEP:
6809 case GL_REPLACE:
6810 case GL_INCR:
6811 case GL_DECR:
6812 case GL_INVERT:
6813 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006814 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006815 break;
6816 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006817 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006818 }
6819
6820 switch (zpass)
6821 {
6822 case GL_ZERO:
6823 case GL_KEEP:
6824 case GL_REPLACE:
6825 case GL_INCR:
6826 case GL_DECR:
6827 case GL_INVERT:
6828 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006829 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006830 break;
6831 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006832 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006833 }
6834
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006835 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006836
6837 if (context)
6838 {
6839 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6840 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006841 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006842 }
6843
6844 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6845 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006846 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006847 }
6848 }
6849 }
6850 catch(std::bad_alloc&)
6851 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006852 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006853 }
6854}
6855
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006856GLboolean __stdcall glTestFenceNV(GLuint fence)
6857{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006858 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006859
6860 try
6861 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006862 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006863
6864 if (context)
6865 {
6866 gl::Fence *fenceObject = context->getFence(fence);
6867
6868 if (fenceObject == NULL)
6869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006870 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006871 }
6872
6873 return fenceObject->testFence();
6874 }
6875 }
6876 catch(std::bad_alloc&)
6877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006878 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006879 }
6880
6881 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006882}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006883
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006884void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6885 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006886{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006887 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 +00006888 "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 +00006889 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006890
6891 try
6892 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006893 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006894
6895 if (context)
6896 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006897 if (context->getClientVersion() < 3 &&
6898 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6899 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006900 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006901 return;
6902 }
6903
6904 if (context->getClientVersion() >= 3 &&
6905 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6906 0, 0, 0, width, height, 1, border, format, type))
6907 {
6908 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006909 }
6910
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006911 switch (target)
6912 {
6913 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006914 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006915 gl::Texture2D *texture = context->getTexture2D();
6916 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006917 }
6918 break;
6919 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006920 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006921 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006922 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006923 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006924 break;
6925 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6926 {
6927 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6928 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6929 }
6930 break;
6931 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6932 {
6933 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6934 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6935 }
6936 break;
6937 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6938 {
6939 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6940 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6941 }
6942 break;
6943 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6944 {
6945 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6946 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6947 }
6948 break;
6949 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6950 {
6951 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6952 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6953 }
6954 break;
6955 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006956 }
6957 }
6958 }
6959 catch(std::bad_alloc&)
6960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006961 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006962 }
6963}
6964
6965void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6966{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006967 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6968
6969 try
6970 {
6971 gl::Context *context = gl::getNonLostContext();
6972
6973 if (context)
6974 {
6975 gl::Texture *texture;
6976
6977 switch (target)
6978 {
6979 case GL_TEXTURE_2D:
6980 texture = context->getTexture2D();
6981 break;
6982 case GL_TEXTURE_CUBE_MAP:
6983 texture = context->getTextureCubeMap();
6984 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006985 case GL_TEXTURE_3D:
6986 if (context->getClientVersion() < 3)
6987 {
6988 return gl::error(GL_INVALID_ENUM);
6989 }
6990 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006991 case GL_TEXTURE_2D_ARRAY:
6992 if (context->getClientVersion() < 3)
6993 {
6994 return gl::error(GL_INVALID_ENUM);
6995 }
6996 texture = context->getTexture2DArray();
6997 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006998 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006999 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007000 }
7001
7002 switch (pname)
7003 {
7004 case GL_TEXTURE_WRAP_S:
7005 if (!texture->setWrapS((GLenum)param))
7006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007007 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007008 }
7009 break;
7010 case GL_TEXTURE_WRAP_T:
7011 if (!texture->setWrapT((GLenum)param))
7012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007013 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007014 }
7015 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007016 case GL_TEXTURE_WRAP_R:
7017 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7018 {
7019 return gl::error(GL_INVALID_ENUM);
7020 }
7021 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007022 case GL_TEXTURE_MIN_FILTER:
7023 if (!texture->setMinFilter((GLenum)param))
7024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007025 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007026 }
7027 break;
7028 case GL_TEXTURE_MAG_FILTER:
7029 if (!texture->setMagFilter((GLenum)param))
7030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007032 }
7033 break;
7034 case GL_TEXTURE_USAGE_ANGLE:
7035 if (!texture->setUsage((GLenum)param))
7036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007037 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007038 }
7039 break;
7040 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7041 if (!context->supportsTextureFilterAnisotropy())
7042 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007043 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007044 }
7045 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7046 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007047 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007048 }
7049 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007050
7051 case GL_TEXTURE_MIN_LOD:
7052 case GL_TEXTURE_MAX_LOD:
7053 if (context->getClientVersion() < 3)
7054 {
7055 return gl::error(GL_INVALID_ENUM);
7056 }
7057 UNIMPLEMENTED();
7058 break;
7059
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007060 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007061 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007062 }
7063 }
7064 }
7065 catch(std::bad_alloc&)
7066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007067 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007068 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007069}
7070
7071void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7072{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007073 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007074}
7075
7076void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7077{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007078 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
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 {
7086 gl::Texture *texture;
7087
7088 switch (target)
7089 {
7090 case GL_TEXTURE_2D:
7091 texture = context->getTexture2D();
7092 break;
7093 case GL_TEXTURE_CUBE_MAP:
7094 texture = context->getTextureCubeMap();
7095 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007096 case GL_TEXTURE_3D:
7097 if (context->getClientVersion() < 3)
7098 {
7099 return gl::error(GL_INVALID_ENUM);
7100 }
7101 texture = context->getTexture3D();
7102 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007103 case GL_TEXTURE_2D_ARRAY:
7104 if (context->getClientVersion() < 3)
7105 {
7106 return gl::error(GL_INVALID_ENUM);
7107 }
7108 texture = context->getTexture2DArray();
7109 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007110 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007111 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007112 }
7113
7114 switch (pname)
7115 {
7116 case GL_TEXTURE_WRAP_S:
7117 if (!texture->setWrapS((GLenum)param))
7118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007119 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007120 }
7121 break;
7122 case GL_TEXTURE_WRAP_T:
7123 if (!texture->setWrapT((GLenum)param))
7124 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007125 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007126 }
7127 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007128 case GL_TEXTURE_WRAP_R:
7129 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7130 {
7131 return gl::error(GL_INVALID_ENUM);
7132 }
7133 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007134 case GL_TEXTURE_MIN_FILTER:
7135 if (!texture->setMinFilter((GLenum)param))
7136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138 }
7139 break;
7140 case GL_TEXTURE_MAG_FILTER:
7141 if (!texture->setMagFilter((GLenum)param))
7142 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007143 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007144 }
7145 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007146 case GL_TEXTURE_USAGE_ANGLE:
7147 if (!texture->setUsage((GLenum)param))
7148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007149 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007150 }
7151 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007152 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7153 if (!context->supportsTextureFilterAnisotropy())
7154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007155 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007156 }
7157 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007159 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007160 }
7161 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007162
7163 case GL_TEXTURE_SWIZZLE_R:
7164 case GL_TEXTURE_SWIZZLE_G:
7165 case GL_TEXTURE_SWIZZLE_B:
7166 case GL_TEXTURE_SWIZZLE_A:
7167 case GL_TEXTURE_BASE_LEVEL:
7168 case GL_TEXTURE_MAX_LEVEL:
7169 case GL_TEXTURE_COMPARE_MODE:
7170 case GL_TEXTURE_COMPARE_FUNC:
7171 if (context->getClientVersion() < 3)
7172 {
7173 return gl::error(GL_INVALID_ENUM);
7174 }
7175 UNIMPLEMENTED();
7176 break;
7177
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007178 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007179 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007180 }
7181 }
7182 }
7183 catch(std::bad_alloc&)
7184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007185 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007186 }
7187}
7188
7189void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7190{
7191 glTexParameteri(target, pname, *params);
7192}
7193
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007194void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7195{
7196 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7197 target, levels, internalformat, width, height);
7198
7199 try
7200 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007201 gl::Context *context = gl::getNonLostContext();
7202
7203 if (context)
7204 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007205 if (context->getClientVersion() < 3 &&
7206 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007207 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007208 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007209 }
7210
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007211 if (context->getClientVersion() >= 3 &&
7212 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007213 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007214 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007215 }
7216
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007217 switch (target)
7218 {
7219 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007220 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007221 gl::Texture2D *texture2d = context->getTexture2D();
7222 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007223 }
7224 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007225
7226 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7227 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7228 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7229 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7230 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7231 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007232 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007233 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7234 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007235 }
7236 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007237
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007238 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007239 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007240 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007241 }
7242 }
7243 catch(std::bad_alloc&)
7244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007245 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007246 }
7247}
7248
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007249void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7250 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007251{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007252 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007253 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007254 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007255 target, level, xoffset, yoffset, width, height, format, type, pixels);
7256
7257 try
7258 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007260
7261 if (context)
7262 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007263 if (context->getClientVersion() < 3 &&
7264 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7265 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007266 {
7267 return;
7268 }
7269
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007270 if (context->getClientVersion() >= 3 &&
7271 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7272 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007273 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007274 return;
7275 }
7276
7277 switch (target)
7278 {
7279 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007280 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007281 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007282 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007283 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007284 break;
7285
7286 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7287 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7288 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7289 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7290 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7291 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007292 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007293 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007294 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007295 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007296 break;
7297
7298 default:
7299 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007300 }
7301 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007302 }
7303 catch(std::bad_alloc&)
7304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007305 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007306 }
7307}
7308
7309void __stdcall glUniform1f(GLint location, GLfloat x)
7310{
7311 glUniform1fv(location, 1, &x);
7312}
7313
7314void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7315{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007316 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007317
7318 try
7319 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007320 if (count < 0)
7321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007322 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007323 }
7324
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007325 if (location == -1)
7326 {
7327 return;
7328 }
7329
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007330 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007331
7332 if (context)
7333 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007334 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007335 if (!programBinary)
7336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007337 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007338 }
7339
7340 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007342 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007343 }
7344 }
7345 }
7346 catch(std::bad_alloc&)
7347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007349 }
7350}
7351
7352void __stdcall glUniform1i(GLint location, GLint x)
7353{
7354 glUniform1iv(location, 1, &x);
7355}
7356
7357void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007359 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007360
7361 try
7362 {
7363 if (count < 0)
7364 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007365 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007366 }
7367
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007368 if (location == -1)
7369 {
7370 return;
7371 }
7372
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007373 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007374
7375 if (context)
7376 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007377 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007378 if (!programBinary)
7379 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007380 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007381 }
7382
7383 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007385 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007386 }
7387 }
7388 }
7389 catch(std::bad_alloc&)
7390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007391 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007392 }
7393}
7394
7395void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7396{
7397 GLfloat xy[2] = {x, y};
7398
7399 glUniform2fv(location, 1, (GLfloat*)&xy);
7400}
7401
7402void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007404 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007405
7406 try
7407 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007408 if (count < 0)
7409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007410 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007411 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007412
7413 if (location == -1)
7414 {
7415 return;
7416 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007417
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007418 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007419
7420 if (context)
7421 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007422 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007423 if (!programBinary)
7424 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007425 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007426 }
7427
7428 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007430 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007431 }
7432 }
7433 }
7434 catch(std::bad_alloc&)
7435 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007436 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007437 }
7438}
7439
7440void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7441{
7442 GLint xy[4] = {x, y};
7443
7444 glUniform2iv(location, 1, (GLint*)&xy);
7445}
7446
7447void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7448{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007449 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007450
7451 try
7452 {
7453 if (count < 0)
7454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007455 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007456 }
7457
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007458 if (location == -1)
7459 {
7460 return;
7461 }
7462
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007463 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007464
7465 if (context)
7466 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007467 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007468 if (!programBinary)
7469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007470 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007471 }
7472
7473 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007475 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007476 }
7477 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007478 }
7479 catch(std::bad_alloc&)
7480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007481 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007482 }
7483}
7484
7485void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7486{
7487 GLfloat xyz[3] = {x, y, z};
7488
7489 glUniform3fv(location, 1, (GLfloat*)&xyz);
7490}
7491
7492void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7493{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007494 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007495
7496 try
7497 {
7498 if (count < 0)
7499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007500 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007501 }
7502
7503 if (location == -1)
7504 {
7505 return;
7506 }
7507
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007508 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007509
7510 if (context)
7511 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007512 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007513 if (!programBinary)
7514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007515 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007516 }
7517
7518 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007520 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007521 }
7522 }
7523 }
7524 catch(std::bad_alloc&)
7525 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007526 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007527 }
7528}
7529
7530void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7531{
7532 GLint xyz[3] = {x, y, z};
7533
7534 glUniform3iv(location, 1, (GLint*)&xyz);
7535}
7536
7537void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7538{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007539 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007540
7541 try
7542 {
7543 if (count < 0)
7544 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007545 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007546 }
7547
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007548 if (location == -1)
7549 {
7550 return;
7551 }
7552
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007553 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007554
7555 if (context)
7556 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007557 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007558 if (!programBinary)
7559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007560 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007561 }
7562
7563 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007565 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007566 }
7567 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007568 }
7569 catch(std::bad_alloc&)
7570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007571 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007572 }
7573}
7574
7575void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7576{
7577 GLfloat xyzw[4] = {x, y, z, w};
7578
7579 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7580}
7581
7582void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007584 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007585
7586 try
7587 {
7588 if (count < 0)
7589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007590 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007591 }
7592
7593 if (location == -1)
7594 {
7595 return;
7596 }
7597
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007599
7600 if (context)
7601 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007602 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007603 if (!programBinary)
7604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007605 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007606 }
7607
7608 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007609 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007610 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007611 }
7612 }
7613 }
7614 catch(std::bad_alloc&)
7615 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007616 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007617 }
7618}
7619
7620void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7621{
7622 GLint xyzw[4] = {x, y, z, w};
7623
7624 glUniform4iv(location, 1, (GLint*)&xyzw);
7625}
7626
7627void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007629 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007630
7631 try
7632 {
7633 if (count < 0)
7634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007635 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007636 }
7637
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007638 if (location == -1)
7639 {
7640 return;
7641 }
7642
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007643 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007644
7645 if (context)
7646 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007647 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007648 if (!programBinary)
7649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007650 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007651 }
7652
7653 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007654 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007655 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007656 }
7657 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007658 }
7659 catch(std::bad_alloc&)
7660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007661 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007662 }
7663}
7664
7665void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7666{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007667 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007668 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007669
7670 try
7671 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007672 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007674 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007675 }
7676
7677 if (location == -1)
7678 {
7679 return;
7680 }
7681
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007682 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007683
7684 if (context)
7685 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007686 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7687 {
7688 return gl::error(GL_INVALID_VALUE);
7689 }
7690
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007691 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007692 if (!programBinary)
7693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007694 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007695 }
7696
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007697 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007699 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007700 }
7701 }
7702 }
7703 catch(std::bad_alloc&)
7704 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007705 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007706 }
7707}
7708
7709void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7710{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007711 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007712 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007713
7714 try
7715 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007716 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007718 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007719 }
7720
7721 if (location == -1)
7722 {
7723 return;
7724 }
7725
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007726 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007727
7728 if (context)
7729 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007730 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7731 {
7732 return gl::error(GL_INVALID_VALUE);
7733 }
7734
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007735 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007736 if (!programBinary)
7737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007738 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007739 }
7740
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007741 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007743 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007744 }
7745 }
7746 }
7747 catch(std::bad_alloc&)
7748 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007749 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007750 }
7751}
7752
7753void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7754{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007755 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007756 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007757
7758 try
7759 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007760 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007762 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007763 }
7764
7765 if (location == -1)
7766 {
7767 return;
7768 }
7769
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007770 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007771
7772 if (context)
7773 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007774 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7775 {
7776 return gl::error(GL_INVALID_VALUE);
7777 }
7778
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007779 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007780 if (!programBinary)
7781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007782 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007783 }
7784
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007785 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007787 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007788 }
7789 }
7790 }
7791 catch(std::bad_alloc&)
7792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007793 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007794 }
7795}
7796
7797void __stdcall glUseProgram(GLuint program)
7798{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007799 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007800
7801 try
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 {
7807 gl::Program *programObject = context->getProgram(program);
7808
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007809 if (!programObject && program != 0)
7810 {
7811 if (context->getShader(program))
7812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007813 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007814 }
7815 else
7816 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007817 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007818 }
7819 }
7820
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007821 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007823 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007824 }
7825
7826 context->useProgram(program);
7827 }
7828 }
7829 catch(std::bad_alloc&)
7830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007831 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007832 }
7833}
7834
7835void __stdcall glValidateProgram(GLuint program)
7836{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007837 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007838
7839 try
7840 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007841 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007842
7843 if (context)
7844 {
7845 gl::Program *programObject = context->getProgram(program);
7846
7847 if (!programObject)
7848 {
7849 if (context->getShader(program))
7850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007851 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007852 }
7853 else
7854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007855 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007856 }
7857 }
7858
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007859 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007860 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007861 }
7862 catch(std::bad_alloc&)
7863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007864 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007865 }
7866}
7867
7868void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7869{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007870 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007871
7872 try
7873 {
7874 if (index >= gl::MAX_VERTEX_ATTRIBS)
7875 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007876 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007877 }
7878
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007879 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007880
7881 if (context)
7882 {
7883 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007884 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007885 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007886 }
7887 catch(std::bad_alloc&)
7888 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007889 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007890 }
7891}
7892
7893void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7894{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007895 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007896
7897 try
7898 {
7899 if (index >= gl::MAX_VERTEX_ATTRIBS)
7900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007901 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007902 }
7903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007905
7906 if (context)
7907 {
7908 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007909 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007910 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007911 }
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 glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7919{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007920 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007921
7922 try
7923 {
7924 if (index >= gl::MAX_VERTEX_ATTRIBS)
7925 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007926 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007927 }
7928
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007930
7931 if (context)
7932 {
7933 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007934 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007935 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007936 }
7937 catch(std::bad_alloc&)
7938 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007939 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007940 }
7941}
7942
7943void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7944{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007945 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007946
7947 try
7948 {
7949 if (index >= gl::MAX_VERTEX_ATTRIBS)
7950 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007951 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007952 }
7953
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007954 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007955
7956 if (context)
7957 {
7958 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007959 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007960 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007961 }
7962 catch(std::bad_alloc&)
7963 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007964 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007965 }
7966}
7967
7968void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7969{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007970 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 +00007971
7972 try
7973 {
7974 if (index >= gl::MAX_VERTEX_ATTRIBS)
7975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007976 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007977 }
7978
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007979 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007980
7981 if (context)
7982 {
7983 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007984 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007985 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007986 }
7987 catch(std::bad_alloc&)
7988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007990 }
7991}
7992
7993void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007995 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007996
7997 try
7998 {
7999 if (index >= gl::MAX_VERTEX_ATTRIBS)
8000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008001 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008002 }
8003
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008004 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008005
8006 if (context)
8007 {
8008 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008009 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008010 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008011 }
8012 catch(std::bad_alloc&)
8013 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008014 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008015 }
8016}
8017
8018void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8019{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008020 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 +00008021
8022 try
8023 {
8024 if (index >= gl::MAX_VERTEX_ATTRIBS)
8025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008026 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008027 }
8028
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008029 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008030
8031 if (context)
8032 {
8033 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008034 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008035 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008036 }
8037 catch(std::bad_alloc&)
8038 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008039 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008040 }
8041}
8042
8043void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8044{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008045 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008046
8047 try
8048 {
8049 if (index >= gl::MAX_VERTEX_ATTRIBS)
8050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008051 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008052 }
8053
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008054 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008055
8056 if (context)
8057 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008058 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008059 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008060 }
8061 catch(std::bad_alloc&)
8062 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008063 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008064 }
8065}
8066
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008067void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8068{
8069 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8070
8071 try
8072 {
8073 if (index >= gl::MAX_VERTEX_ATTRIBS)
8074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008075 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008076 }
8077
8078 gl::Context *context = gl::getNonLostContext();
8079
8080 if (context)
8081 {
8082 context->setVertexAttribDivisor(index, divisor);
8083 }
8084 }
8085 catch(std::bad_alloc&)
8086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008087 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008088 }
8089}
8090
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008091void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008092{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008093 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008094 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008095 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008096
8097 try
8098 {
8099 if (index >= gl::MAX_VERTEX_ATTRIBS)
8100 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008101 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008102 }
8103
8104 if (size < 1 || size > 4)
8105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008106 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008107 }
8108
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008109 gl::Context *context = gl::getNonLostContext();
8110
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008111 switch (type)
8112 {
8113 case GL_BYTE:
8114 case GL_UNSIGNED_BYTE:
8115 case GL_SHORT:
8116 case GL_UNSIGNED_SHORT:
8117 case GL_FIXED:
8118 case GL_FLOAT:
8119 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008120 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008121 case GL_INT:
8122 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008123 case GL_INT_2_10_10_10_REV:
8124 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008125 if (context && context->getClientVersion() < 3)
8126 {
8127 return gl::error(GL_INVALID_ENUM);
8128 }
8129 else
8130 {
8131 break;
8132 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008133 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008134 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008135 }
8136
8137 if (stride < 0)
8138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008139 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008140 }
8141
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008142 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8143 {
8144 return gl::error(GL_INVALID_OPERATION);
8145 }
8146
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008147 if (context)
8148 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008149 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8150 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8151 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8152 // and the pointer argument is not NULL.
8153 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8154 {
8155 return gl::error(GL_INVALID_OPERATION);
8156 }
8157
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008158 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8159 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008160 }
8161 }
8162 catch(std::bad_alloc&)
8163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008164 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008165 }
8166}
8167
8168void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8169{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008170 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 +00008171
8172 try
8173 {
8174 if (width < 0 || height < 0)
8175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008176 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008177 }
8178
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008179 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008180
8181 if (context)
8182 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008183 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008184 }
8185 }
8186 catch(std::bad_alloc&)
8187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008188 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008189 }
8190}
8191
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008192// OpenGL ES 3.0 functions
8193
8194void __stdcall glReadBuffer(GLenum mode)
8195{
8196 EVENT("(GLenum mode = 0x%X)", mode);
8197
8198 try
8199 {
8200 gl::Context *context = gl::getNonLostContext();
8201
8202 if (context)
8203 {
8204 if (context->getClientVersion() < 3)
8205 {
8206 return gl::error(GL_INVALID_OPERATION);
8207 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008208
Jamie Madill54133512013-06-21 09:33:07 -04008209 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008210 UNIMPLEMENTED();
8211 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008212 }
8213 catch(std::bad_alloc&)
8214 {
8215 return gl::error(GL_OUT_OF_MEMORY);
8216 }
8217}
8218
8219void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8220{
8221 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8222 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8223
8224 try
8225 {
8226 gl::Context *context = gl::getNonLostContext();
8227
8228 if (context)
8229 {
8230 if (context->getClientVersion() < 3)
8231 {
8232 return gl::error(GL_INVALID_OPERATION);
8233 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008234
Jamie Madill54133512013-06-21 09:33:07 -04008235 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008236 UNIMPLEMENTED();
8237 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008238 }
8239 catch(std::bad_alloc&)
8240 {
8241 return gl::error(GL_OUT_OF_MEMORY);
8242 }
8243}
8244
8245void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8246{
8247 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8248 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8249 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8250 target, level, internalformat, width, height, depth, border, format, type, pixels);
8251
8252 try
8253 {
8254 gl::Context *context = gl::getNonLostContext();
8255
8256 if (context)
8257 {
8258 if (context->getClientVersion() < 3)
8259 {
8260 return gl::error(GL_INVALID_OPERATION);
8261 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008262
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008263 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008264 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008265 0, 0, 0, width, height, depth, border, format, type))
8266 {
8267 return;
8268 }
8269
8270 switch(target)
8271 {
8272 case GL_TEXTURE_3D:
8273 {
8274 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008275 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008276 }
8277 break;
8278
8279 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008280 {
8281 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008282 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008283 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008284 break;
8285
8286 default:
8287 return gl::error(GL_INVALID_ENUM);
8288 }
8289 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008290 }
8291 catch(std::bad_alloc&)
8292 {
8293 return gl::error(GL_OUT_OF_MEMORY);
8294 }
8295}
8296
8297void __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)
8298{
8299 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8300 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8301 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8302 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8303
8304 try
8305 {
8306 gl::Context *context = gl::getNonLostContext();
8307
8308 if (context)
8309 {
8310 if (context->getClientVersion() < 3)
8311 {
8312 return gl::error(GL_INVALID_OPERATION);
8313 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008314
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008315 if (!pixels)
8316 {
8317 return gl::error(GL_INVALID_VALUE);
8318 }
8319
8320 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008321 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008322 xoffset, yoffset, zoffset, width, height, depth, 0,
8323 format, type))
8324 {
8325 return;
8326 }
8327
8328 switch(target)
8329 {
8330 case GL_TEXTURE_3D:
8331 {
8332 gl::Texture3D *texture = context->getTexture3D();
8333 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8334 }
8335 break;
8336
8337 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008338 {
8339 gl::Texture2DArray *texture = context->getTexture2DArray();
8340 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8341 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008342 break;
8343
8344 default:
8345 return gl::error(GL_INVALID_ENUM);
8346 }
8347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008348 }
8349 catch(std::bad_alloc&)
8350 {
8351 return gl::error(GL_OUT_OF_MEMORY);
8352 }
8353}
8354
8355void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8356{
8357 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8358 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8359 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8360
8361 try
8362 {
8363 gl::Context *context = gl::getNonLostContext();
8364
8365 if (context)
8366 {
8367 if (context->getClientVersion() < 3)
8368 {
8369 return gl::error(GL_INVALID_OPERATION);
8370 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008371
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008372 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8373 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008374 {
8375 return;
8376 }
8377
8378 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8379 gl::Texture *texture = NULL;
8380 switch (target)
8381 {
8382 case GL_TEXTURE_3D:
8383 texture = context->getTexture3D();
8384 break;
8385
8386 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008387 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008388 break;
8389
8390 default:
8391 return gl::error(GL_INVALID_ENUM);
8392 }
8393
8394 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8395 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008396 }
8397 catch(std::bad_alloc&)
8398 {
8399 return gl::error(GL_OUT_OF_MEMORY);
8400 }
8401}
8402
8403void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8404{
8405 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8406 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8407 "const GLvoid* data = 0x%0.8p)",
8408 target, level, internalformat, width, height, depth, border, imageSize, data);
8409
8410 try
8411 {
8412 gl::Context *context = gl::getNonLostContext();
8413
8414 if (context)
8415 {
8416 if (context->getClientVersion() < 3)
8417 {
8418 return gl::error(GL_INVALID_OPERATION);
8419 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008420
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008421 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 +00008422 {
8423 return gl::error(GL_INVALID_VALUE);
8424 }
8425
8426 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008427 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8428 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008429 {
8430 return;
8431 }
8432
8433 switch(target)
8434 {
8435 case GL_TEXTURE_3D:
8436 {
8437 gl::Texture3D *texture = context->getTexture3D();
8438 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8439 }
8440 break;
8441
8442 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008443 {
8444 gl::Texture2DArray *texture = context->getTexture2DArray();
8445 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8446 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008447 break;
8448
8449 default:
8450 return gl::error(GL_INVALID_ENUM);
8451 }
8452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008453 }
8454 catch(std::bad_alloc&)
8455 {
8456 return gl::error(GL_OUT_OF_MEMORY);
8457 }
8458}
8459
8460void __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)
8461{
8462 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8463 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8464 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8465 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8466
8467 try
8468 {
8469 gl::Context *context = gl::getNonLostContext();
8470
8471 if (context)
8472 {
8473 if (context->getClientVersion() < 3)
8474 {
8475 return gl::error(GL_INVALID_OPERATION);
8476 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008477
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008478 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 +00008479 {
8480 return gl::error(GL_INVALID_VALUE);
8481 }
8482
8483 if (!data)
8484 {
8485 return gl::error(GL_INVALID_VALUE);
8486 }
8487
8488 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008489 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8490 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008491 {
8492 return;
8493 }
8494
8495 switch(target)
8496 {
8497 case GL_TEXTURE_3D:
8498 {
8499 gl::Texture3D *texture = context->getTexture3D();
8500 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8501 format, imageSize, data);
8502 }
8503 break;
8504
8505 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008506 {
8507 gl::Texture2DArray *texture = context->getTexture2DArray();
8508 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8509 format, imageSize, data);
8510 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008511 break;
8512
8513 default:
8514 return gl::error(GL_INVALID_ENUM);
8515 }
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 glGenQueries(GLsizei n, GLuint* ids)
8525{
8526 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8527
8528 try
8529 {
8530 gl::Context *context = gl::getNonLostContext();
8531
8532 if (context)
8533 {
8534 if (context->getClientVersion() < 3)
8535 {
8536 return gl::error(GL_INVALID_OPERATION);
8537 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008538
Jamie Madill54133512013-06-21 09:33:07 -04008539 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008540 UNIMPLEMENTED();
8541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008542 }
8543 catch(std::bad_alloc&)
8544 {
8545 return gl::error(GL_OUT_OF_MEMORY);
8546 }
8547}
8548
8549void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8550{
8551 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8552
8553 try
8554 {
8555 gl::Context *context = gl::getNonLostContext();
8556
8557 if (context)
8558 {
8559 if (context->getClientVersion() < 3)
8560 {
8561 return gl::error(GL_INVALID_OPERATION);
8562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008563
Jamie Madill54133512013-06-21 09:33:07 -04008564 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008565 UNIMPLEMENTED();
8566 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008567 }
8568 catch(std::bad_alloc&)
8569 {
8570 return gl::error(GL_OUT_OF_MEMORY);
8571 }
8572}
8573
8574GLboolean __stdcall glIsQuery(GLuint id)
8575{
8576 EVENT("(GLuint id = %u)", id);
8577
8578 try
8579 {
8580 gl::Context *context = gl::getNonLostContext();
8581
8582 if (context)
8583 {
8584 if (context->getClientVersion() < 3)
8585 {
8586 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8587 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008588
Jamie Madill54133512013-06-21 09:33:07 -04008589 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008590 UNIMPLEMENTED();
8591 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008592 }
8593 catch(std::bad_alloc&)
8594 {
8595 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8596 }
8597
8598 return GL_FALSE;
8599}
8600
8601void __stdcall glBeginQuery(GLenum target, GLuint id)
8602{
8603 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8604
8605 try
8606 {
8607 gl::Context *context = gl::getNonLostContext();
8608
8609 if (context)
8610 {
8611 if (context->getClientVersion() < 3)
8612 {
8613 return gl::error(GL_INVALID_OPERATION);
8614 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008615
Jamie Madill54133512013-06-21 09:33:07 -04008616 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008617 UNIMPLEMENTED();
8618 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008619 }
8620 catch(std::bad_alloc&)
8621 {
8622 return gl::error(GL_OUT_OF_MEMORY);
8623 }
8624}
8625
8626void __stdcall glEndQuery(GLenum target)
8627{
8628 EVENT("(GLenum target = 0x%X)", target);
8629
8630 try
8631 {
8632 gl::Context *context = gl::getNonLostContext();
8633
8634 if (context)
8635 {
8636 if (context->getClientVersion() < 3)
8637 {
8638 return gl::error(GL_INVALID_OPERATION);
8639 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008640
Jamie Madill54133512013-06-21 09:33:07 -04008641 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008642 UNIMPLEMENTED();
8643 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008644 }
8645 catch(std::bad_alloc&)
8646 {
8647 return gl::error(GL_OUT_OF_MEMORY);
8648 }
8649}
8650
8651void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8652{
8653 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8654
8655 try
8656 {
8657 gl::Context *context = gl::getNonLostContext();
8658
8659 if (context)
8660 {
8661 if (context->getClientVersion() < 3)
8662 {
8663 return gl::error(GL_INVALID_OPERATION);
8664 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008665
Jamie Madill54133512013-06-21 09:33:07 -04008666 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008667 UNIMPLEMENTED();
8668 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008669 }
8670 catch(std::bad_alloc&)
8671 {
8672 return gl::error(GL_OUT_OF_MEMORY);
8673 }
8674}
8675
8676void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8677{
8678 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8679
8680 try
8681 {
8682 gl::Context *context = gl::getNonLostContext();
8683
8684 if (context)
8685 {
8686 if (context->getClientVersion() < 3)
8687 {
8688 return gl::error(GL_INVALID_OPERATION);
8689 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008690
Jamie Madill54133512013-06-21 09:33:07 -04008691 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008692 UNIMPLEMENTED();
8693 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008694 }
8695 catch(std::bad_alloc&)
8696 {
8697 return gl::error(GL_OUT_OF_MEMORY);
8698 }
8699}
8700
8701GLboolean __stdcall glUnmapBuffer(GLenum target)
8702{
8703 EVENT("(GLenum target = 0x%X)", target);
8704
8705 try
8706 {
8707 gl::Context *context = gl::getNonLostContext();
8708
8709 if (context)
8710 {
8711 if (context->getClientVersion() < 3)
8712 {
8713 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8714 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008715
Jamie Madill54133512013-06-21 09:33:07 -04008716 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008717 UNIMPLEMENTED();
8718 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008719 }
8720 catch(std::bad_alloc&)
8721 {
8722 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8723 }
8724
8725 return GL_FALSE;
8726}
8727
8728void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8729{
8730 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8731
8732 try
8733 {
8734 gl::Context *context = gl::getNonLostContext();
8735
8736 if (context)
8737 {
8738 if (context->getClientVersion() < 3)
8739 {
8740 return gl::error(GL_INVALID_OPERATION);
8741 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008742
Jamie Madill54133512013-06-21 09:33:07 -04008743 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008744 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008745 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008746 }
8747 catch(std::bad_alloc&)
8748 {
8749 return gl::error(GL_OUT_OF_MEMORY);
8750 }
8751}
8752
8753void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8754{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008755 try
8756 {
8757 gl::Context *context = gl::getNonLostContext();
8758
8759 if (context)
8760 {
8761 if (context->getClientVersion() < 3)
8762 {
8763 return gl::error(GL_INVALID_OPERATION);
8764 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008765
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008766 glDrawBuffersEXT(n, bufs);
8767 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008768 }
8769 catch(std::bad_alloc&)
8770 {
8771 return gl::error(GL_OUT_OF_MEMORY);
8772 }
8773}
8774
8775void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8776{
8777 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8778 location, count, transpose, value);
8779
8780 try
8781 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008782 if (count < 0)
8783 {
8784 return gl::error(GL_INVALID_VALUE);
8785 }
8786
8787 if (location == -1)
8788 {
8789 return;
8790 }
8791
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008792 gl::Context *context = gl::getNonLostContext();
8793
8794 if (context)
8795 {
8796 if (context->getClientVersion() < 3)
8797 {
8798 return gl::error(GL_INVALID_OPERATION);
8799 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008800
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008801 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8802 if (!programBinary)
8803 {
8804 return gl::error(GL_INVALID_OPERATION);
8805 }
8806
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008807 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008808 {
8809 return gl::error(GL_INVALID_OPERATION);
8810 }
8811 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008812 }
8813 catch(std::bad_alloc&)
8814 {
8815 return gl::error(GL_OUT_OF_MEMORY);
8816 }
8817}
8818
8819void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8820{
8821 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8822 location, count, transpose, value);
8823
8824 try
8825 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008826 if (count < 0)
8827 {
8828 return gl::error(GL_INVALID_VALUE);
8829 }
8830
8831 if (location == -1)
8832 {
8833 return;
8834 }
8835
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008836 gl::Context *context = gl::getNonLostContext();
8837
8838 if (context)
8839 {
8840 if (context->getClientVersion() < 3)
8841 {
8842 return gl::error(GL_INVALID_OPERATION);
8843 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008844
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008845 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8846 if (!programBinary)
8847 {
8848 return gl::error(GL_INVALID_OPERATION);
8849 }
8850
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008851 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008852 {
8853 return gl::error(GL_INVALID_OPERATION);
8854 }
8855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008856 }
8857 catch(std::bad_alloc&)
8858 {
8859 return gl::error(GL_OUT_OF_MEMORY);
8860 }
8861}
8862
8863void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8864{
8865 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8866 location, count, transpose, value);
8867
8868 try
8869 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008870 if (count < 0)
8871 {
8872 return gl::error(GL_INVALID_VALUE);
8873 }
8874
8875 if (location == -1)
8876 {
8877 return;
8878 }
8879
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008880 gl::Context *context = gl::getNonLostContext();
8881
8882 if (context)
8883 {
8884 if (context->getClientVersion() < 3)
8885 {
8886 return gl::error(GL_INVALID_OPERATION);
8887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008888
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008889 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8890 if (!programBinary)
8891 {
8892 return gl::error(GL_INVALID_OPERATION);
8893 }
8894
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008895 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008896 {
8897 return gl::error(GL_INVALID_OPERATION);
8898 }
8899 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008900 }
8901 catch(std::bad_alloc&)
8902 {
8903 return gl::error(GL_OUT_OF_MEMORY);
8904 }
8905}
8906
8907void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8908{
8909 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8910 location, count, transpose, value);
8911
8912 try
8913 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008914 if (count < 0)
8915 {
8916 return gl::error(GL_INVALID_VALUE);
8917 }
8918
8919 if (location == -1)
8920 {
8921 return;
8922 }
8923
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008924 gl::Context *context = gl::getNonLostContext();
8925
8926 if (context)
8927 {
8928 if (context->getClientVersion() < 3)
8929 {
8930 return gl::error(GL_INVALID_OPERATION);
8931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008932
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008933 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8934 if (!programBinary)
8935 {
8936 return gl::error(GL_INVALID_OPERATION);
8937 }
8938
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008939 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008940 {
8941 return gl::error(GL_INVALID_OPERATION);
8942 }
8943 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008944 }
8945 catch(std::bad_alloc&)
8946 {
8947 return gl::error(GL_OUT_OF_MEMORY);
8948 }
8949}
8950
8951void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8952{
8953 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8954 location, count, transpose, value);
8955
8956 try
8957 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008958 if (count < 0)
8959 {
8960 return gl::error(GL_INVALID_VALUE);
8961 }
8962
8963 if (location == -1)
8964 {
8965 return;
8966 }
8967
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008968 gl::Context *context = gl::getNonLostContext();
8969
8970 if (context)
8971 {
8972 if (context->getClientVersion() < 3)
8973 {
8974 return gl::error(GL_INVALID_OPERATION);
8975 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008976
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008977 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8978 if (!programBinary)
8979 {
8980 return gl::error(GL_INVALID_OPERATION);
8981 }
8982
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008983 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008984 {
8985 return gl::error(GL_INVALID_OPERATION);
8986 }
8987 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008988 }
8989 catch(std::bad_alloc&)
8990 {
8991 return gl::error(GL_OUT_OF_MEMORY);
8992 }
8993}
8994
8995void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8996{
8997 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8998 location, count, transpose, value);
8999
9000 try
9001 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009002 if (count < 0)
9003 {
9004 return gl::error(GL_INVALID_VALUE);
9005 }
9006
9007 if (location == -1)
9008 {
9009 return;
9010 }
9011
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009012 gl::Context *context = gl::getNonLostContext();
9013
9014 if (context)
9015 {
9016 if (context->getClientVersion() < 3)
9017 {
9018 return gl::error(GL_INVALID_OPERATION);
9019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009020
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009021 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9022 if (!programBinary)
9023 {
9024 return gl::error(GL_INVALID_OPERATION);
9025 }
9026
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009027 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009028 {
9029 return gl::error(GL_INVALID_OPERATION);
9030 }
9031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009032 }
9033 catch(std::bad_alloc&)
9034 {
9035 return gl::error(GL_OUT_OF_MEMORY);
9036 }
9037}
9038
9039void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9040{
9041 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9042 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9043 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9044
9045 try
9046 {
9047 gl::Context *context = gl::getNonLostContext();
9048
9049 if (context)
9050 {
9051 if (context->getClientVersion() < 3)
9052 {
9053 return gl::error(GL_INVALID_OPERATION);
9054 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009055
Geoff Lang758d5b22013-06-11 11:42:50 -04009056 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9057 dstX0, dstY0, dstX1, dstY1, mask, filter,
9058 false))
9059 {
9060 return;
9061 }
9062
9063 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9064 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009065 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009066 }
9067 catch(std::bad_alloc&)
9068 {
9069 return gl::error(GL_OUT_OF_MEMORY);
9070 }
9071}
9072
9073void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9074{
9075 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9076 target, samples, internalformat, width, height);
9077
9078 try
9079 {
9080 gl::Context *context = gl::getNonLostContext();
9081
9082 if (context)
9083 {
9084 if (context->getClientVersion() < 3)
9085 {
9086 return gl::error(GL_INVALID_OPERATION);
9087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009088
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009089 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9090 width, height, false))
9091 {
9092 return;
9093 }
9094
9095 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009096 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009097 }
9098 catch(std::bad_alloc&)
9099 {
9100 return gl::error(GL_OUT_OF_MEMORY);
9101 }
9102}
9103
9104void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9105{
9106 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9107 target, attachment, texture, level, layer);
9108
9109 try
9110 {
9111 gl::Context *context = gl::getNonLostContext();
9112
9113 if (context)
9114 {
9115 if (context->getClientVersion() < 3)
9116 {
9117 return gl::error(GL_INVALID_OPERATION);
9118 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009119
Jamie Madill54133512013-06-21 09:33:07 -04009120 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009121 UNIMPLEMENTED();
9122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009123 }
9124 catch(std::bad_alloc&)
9125 {
9126 return gl::error(GL_OUT_OF_MEMORY);
9127 }
9128}
9129
9130GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9131{
9132 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9133 target, offset, length, access);
9134
9135 try
9136 {
9137 gl::Context *context = gl::getNonLostContext();
9138
9139 if (context)
9140 {
9141 if (context->getClientVersion() < 3)
9142 {
9143 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9144 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009145
Jamie Madill54133512013-06-21 09:33:07 -04009146 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009147 UNIMPLEMENTED();
9148 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009149 }
9150 catch(std::bad_alloc&)
9151 {
9152 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9153 }
9154
9155 return NULL;
9156}
9157
9158void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9159{
9160 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9161
9162 try
9163 {
9164 gl::Context *context = gl::getNonLostContext();
9165
9166 if (context)
9167 {
9168 if (context->getClientVersion() < 3)
9169 {
9170 return gl::error(GL_INVALID_OPERATION);
9171 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009172
Jamie Madill54133512013-06-21 09:33:07 -04009173 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009174 UNIMPLEMENTED();
9175 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009176 }
9177 catch(std::bad_alloc&)
9178 {
9179 return gl::error(GL_OUT_OF_MEMORY);
9180 }
9181}
9182
9183void __stdcall glBindVertexArray(GLuint array)
9184{
9185 EVENT("(GLuint array = %u)", array);
9186
9187 try
9188 {
9189 gl::Context *context = gl::getNonLostContext();
9190
9191 if (context)
9192 {
9193 if (context->getClientVersion() < 3)
9194 {
9195 return gl::error(GL_INVALID_OPERATION);
9196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009197
Jamie Madilld1028542013-07-02 11:57:04 -04009198 gl::VertexArray *vao = context->getVertexArray(array);
9199
9200 if (!vao)
9201 {
9202 // The default VAO should always exist
9203 ASSERT(array != 0);
9204 return gl::error(GL_INVALID_OPERATION);
9205 }
9206
9207 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009208 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009209 }
9210 catch(std::bad_alloc&)
9211 {
9212 return gl::error(GL_OUT_OF_MEMORY);
9213 }
9214}
9215
9216void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9217{
9218 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9219
9220 try
9221 {
9222 gl::Context *context = gl::getNonLostContext();
9223
9224 if (context)
9225 {
9226 if (context->getClientVersion() < 3)
9227 {
9228 return gl::error(GL_INVALID_OPERATION);
9229 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009230
Jamie Madilld1028542013-07-02 11:57:04 -04009231 if (n < 0)
9232 {
9233 return gl::error(GL_INVALID_VALUE);
9234 }
9235
9236 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9237 {
9238 if (arrays[arrayIndex] != 0)
9239 {
9240 context->deleteVertexArray(arrays[arrayIndex]);
9241 }
9242 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009243 }
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
9251void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9252{
9253 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9254
9255 try
9256 {
9257 gl::Context *context = gl::getNonLostContext();
9258
9259 if (context)
9260 {
9261 if (context->getClientVersion() < 3)
9262 {
9263 return gl::error(GL_INVALID_OPERATION);
9264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009265
Jamie Madilld1028542013-07-02 11:57:04 -04009266 if (n < 0)
9267 {
9268 return gl::error(GL_INVALID_VALUE);
9269 }
9270
9271 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9272 {
9273 arrays[arrayIndex] = context->createVertexArray();
9274 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009275 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009276 }
9277 catch(std::bad_alloc&)
9278 {
9279 return gl::error(GL_OUT_OF_MEMORY);
9280 }
9281}
9282
9283GLboolean __stdcall glIsVertexArray(GLuint array)
9284{
9285 EVENT("(GLuint array = %u)", array);
9286
9287 try
9288 {
9289 gl::Context *context = gl::getNonLostContext();
9290
9291 if (context)
9292 {
9293 if (context->getClientVersion() < 3)
9294 {
9295 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9296 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009297
Jamie Madilld1028542013-07-02 11:57:04 -04009298 if (array == 0)
9299 {
9300 return GL_FALSE;
9301 }
9302
9303 gl::VertexArray *vao = context->getVertexArray(array);
9304
9305 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009306 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009307 }
9308 catch(std::bad_alloc&)
9309 {
9310 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9311 }
9312
9313 return GL_FALSE;
9314}
9315
9316void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9317{
9318 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9319 target, index, data);
9320
9321 try
9322 {
9323 gl::Context *context = gl::getNonLostContext();
9324
9325 if (context)
9326 {
9327 if (context->getClientVersion() < 3)
9328 {
9329 return gl::error(GL_INVALID_OPERATION);
9330 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009331
Jamie Madill54133512013-06-21 09:33:07 -04009332 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009333 UNIMPLEMENTED();
9334 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009335 }
9336 catch(std::bad_alloc&)
9337 {
9338 return gl::error(GL_OUT_OF_MEMORY);
9339 }
9340}
9341
9342void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9343{
9344 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9345
9346 try
9347 {
9348 gl::Context *context = gl::getNonLostContext();
9349
9350 if (context)
9351 {
9352 if (context->getClientVersion() < 3)
9353 {
9354 return gl::error(GL_INVALID_OPERATION);
9355 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009356
Jamie Madill54133512013-06-21 09:33:07 -04009357 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009358 UNIMPLEMENTED();
9359 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009360 }
9361 catch(std::bad_alloc&)
9362 {
9363 return gl::error(GL_OUT_OF_MEMORY);
9364 }
9365}
9366
9367void __stdcall glEndTransformFeedback(void)
9368{
9369 EVENT("(void)");
9370
9371 try
9372 {
9373 gl::Context *context = gl::getNonLostContext();
9374
9375 if (context)
9376 {
9377 if (context->getClientVersion() < 3)
9378 {
9379 return gl::error(GL_INVALID_OPERATION);
9380 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009381
Jamie Madill54133512013-06-21 09:33:07 -04009382 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009383 UNIMPLEMENTED();
9384 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009385 }
9386 catch(std::bad_alloc&)
9387 {
9388 return gl::error(GL_OUT_OF_MEMORY);
9389 }
9390}
9391
9392void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9393{
9394 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9395 target, index, buffer, offset, size);
9396
9397 try
9398 {
9399 gl::Context *context = gl::getNonLostContext();
9400
9401 if (context)
9402 {
9403 if (context->getClientVersion() < 3)
9404 {
9405 return gl::error(GL_INVALID_OPERATION);
9406 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009407
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009408 switch (target)
9409 {
9410 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009411 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009412 {
9413 return gl::error(GL_INVALID_VALUE);
9414 }
9415 break;
9416
9417 case GL_UNIFORM_BUFFER:
9418 if (index >= context->getMaximumCombinedUniformBufferBindings())
9419 {
9420 return gl::error(GL_INVALID_VALUE);
9421 }
9422 break;
9423
9424 default:
9425 return gl::error(GL_INVALID_ENUM);
9426 }
9427
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009428 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009429 {
9430 return gl::error(GL_INVALID_VALUE);
9431 }
9432
9433 switch (target)
9434 {
9435 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009436
9437 // size and offset must be a multiple of 4
9438 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9439 {
9440 return gl::error(GL_INVALID_VALUE);
9441 }
9442
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009443 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9444 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009445 break;
9446
9447 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009448
9449 // it is an error to bind an offset not a multiple of the alignment
9450 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9451 {
9452 return gl::error(GL_INVALID_VALUE);
9453 }
9454
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009455 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9456 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009457 break;
9458
9459 default:
9460 UNREACHABLE();
9461 }
9462 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009463 }
9464 catch(std::bad_alloc&)
9465 {
9466 return gl::error(GL_OUT_OF_MEMORY);
9467 }
9468}
9469
9470void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9471{
9472 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9473 target, index, buffer);
9474
9475 try
9476 {
9477 gl::Context *context = gl::getNonLostContext();
9478
9479 if (context)
9480 {
9481 if (context->getClientVersion() < 3)
9482 {
9483 return gl::error(GL_INVALID_OPERATION);
9484 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009485
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009486 switch (target)
9487 {
9488 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009489 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009490 {
9491 return gl::error(GL_INVALID_VALUE);
9492 }
9493 break;
9494
9495 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009496 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009497 {
9498 return gl::error(GL_INVALID_VALUE);
9499 }
9500 break;
9501
9502 default:
9503 return gl::error(GL_INVALID_ENUM);
9504 }
9505
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009506 switch (target)
9507 {
9508 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009509 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009510 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009511 break;
9512
9513 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009514 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009515 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009516 break;
9517
9518 default:
9519 UNREACHABLE();
9520 }
9521 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009522 }
9523 catch(std::bad_alloc&)
9524 {
9525 return gl::error(GL_OUT_OF_MEMORY);
9526 }
9527}
9528
9529void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9530{
9531 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9532 program, count, varyings, bufferMode);
9533
9534 try
9535 {
9536 gl::Context *context = gl::getNonLostContext();
9537
9538 if (context)
9539 {
9540 if (context->getClientVersion() < 3)
9541 {
9542 return gl::error(GL_INVALID_OPERATION);
9543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009544
Jamie Madill54133512013-06-21 09:33:07 -04009545 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009546 UNIMPLEMENTED();
9547 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009548 }
9549 catch(std::bad_alloc&)
9550 {
9551 return gl::error(GL_OUT_OF_MEMORY);
9552 }
9553}
9554
9555void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9556{
9557 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9558 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9559 program, index, bufSize, length, size, type, name);
9560
9561 try
9562 {
9563 gl::Context *context = gl::getNonLostContext();
9564
9565 if (context)
9566 {
9567 if (context->getClientVersion() < 3)
9568 {
9569 return gl::error(GL_INVALID_OPERATION);
9570 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009571
Jamie Madill54133512013-06-21 09:33:07 -04009572 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009573 UNIMPLEMENTED();
9574 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009575 }
9576 catch(std::bad_alloc&)
9577 {
9578 return gl::error(GL_OUT_OF_MEMORY);
9579 }
9580}
9581
9582void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9583{
9584 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9585 index, size, type, stride, pointer);
9586
9587 try
9588 {
9589 gl::Context *context = gl::getNonLostContext();
9590
9591 if (context)
9592 {
9593 if (context->getClientVersion() < 3)
9594 {
9595 return gl::error(GL_INVALID_OPERATION);
9596 }
9597 }
9598
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009599 if (index >= gl::MAX_VERTEX_ATTRIBS)
9600 {
9601 return gl::error(GL_INVALID_VALUE);
9602 }
9603
9604 if (size < 1 || size > 4)
9605 {
9606 return gl::error(GL_INVALID_VALUE);
9607 }
9608
9609 switch (type)
9610 {
9611 case GL_BYTE:
9612 case GL_UNSIGNED_BYTE:
9613 case GL_SHORT:
9614 case GL_UNSIGNED_SHORT:
9615 case GL_INT:
9616 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009617 case GL_INT_2_10_10_10_REV:
9618 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009619 break;
9620 default:
9621 return gl::error(GL_INVALID_ENUM);
9622 }
9623
9624 if (stride < 0)
9625 {
9626 return gl::error(GL_INVALID_VALUE);
9627 }
9628
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009629 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9630 {
9631 return gl::error(GL_INVALID_OPERATION);
9632 }
9633
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009634 if (context)
9635 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009636 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9637 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9638 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9639 // and the pointer argument is not NULL.
9640 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9641 {
9642 return gl::error(GL_INVALID_OPERATION);
9643 }
9644
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009645 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9646 stride, pointer);
9647 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009648 }
9649 catch(std::bad_alloc&)
9650 {
9651 return gl::error(GL_OUT_OF_MEMORY);
9652 }
9653}
9654
9655void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9656{
9657 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9658 index, pname, params);
9659
9660 try
9661 {
9662 gl::Context *context = gl::getNonLostContext();
9663
9664 if (context)
9665 {
9666 if (context->getClientVersion() < 3)
9667 {
9668 return gl::error(GL_INVALID_OPERATION);
9669 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009670
Jamie Madilla7d05862013-07-02 11:57:06 -04009671 if (index >= gl::MAX_VERTEX_ATTRIBS)
9672 {
9673 return gl::error(GL_INVALID_VALUE);
9674 }
9675
9676 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9677
9678 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9679 {
9680 return;
9681 }
9682
9683 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9684 {
9685 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9686 for (int i = 0; i < 4; ++i)
9687 {
9688 params[i] = currentValueData.IntValues[i];
9689 }
9690 }
9691 else
9692 {
9693 *params = attribState.querySingleParameter<GLint>(pname);
9694 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009695 }
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 glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9704{
9705 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9706 index, pname, params);
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 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009718
Jamie Madilla7d05862013-07-02 11:57:06 -04009719 if (index >= gl::MAX_VERTEX_ATTRIBS)
9720 {
9721 return gl::error(GL_INVALID_VALUE);
9722 }
9723
9724 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9725
9726 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9727 {
9728 return;
9729 }
9730
9731 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9732 {
9733 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9734 for (int i = 0; i < 4; ++i)
9735 {
9736 params[i] = currentValueData.UnsignedIntValues[i];
9737 }
9738 }
9739 else
9740 {
9741 *params = attribState.querySingleParameter<GLuint>(pname);
9742 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009744 }
9745 catch(std::bad_alloc&)
9746 {
9747 return gl::error(GL_OUT_OF_MEMORY);
9748 }
9749}
9750
9751void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9752{
9753 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9754 index, x, y, z, w);
9755
9756 try
9757 {
9758 gl::Context *context = gl::getNonLostContext();
9759
9760 if (context)
9761 {
9762 if (context->getClientVersion() < 3)
9763 {
9764 return gl::error(GL_INVALID_OPERATION);
9765 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009766
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009767 if (index >= gl::MAX_VERTEX_ATTRIBS)
9768 {
9769 return gl::error(GL_INVALID_VALUE);
9770 }
9771
9772 GLint vals[4] = { x, y, z, w };
9773 context->setVertexAttribi(index, vals);
9774 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009775 }
9776 catch(std::bad_alloc&)
9777 {
9778 return gl::error(GL_OUT_OF_MEMORY);
9779 }
9780}
9781
9782void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9783{
9784 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9785 index, x, y, z, w);
9786
9787 try
9788 {
9789 gl::Context *context = gl::getNonLostContext();
9790
9791 if (context)
9792 {
9793 if (context->getClientVersion() < 3)
9794 {
9795 return gl::error(GL_INVALID_OPERATION);
9796 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009797
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009798 if (index >= gl::MAX_VERTEX_ATTRIBS)
9799 {
9800 return gl::error(GL_INVALID_VALUE);
9801 }
9802
9803 GLuint vals[4] = { x, y, z, w };
9804 context->setVertexAttribu(index, vals);
9805 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009806 }
9807 catch(std::bad_alloc&)
9808 {
9809 return gl::error(GL_OUT_OF_MEMORY);
9810 }
9811}
9812
9813void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9814{
9815 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9816
9817 try
9818 {
9819 gl::Context *context = gl::getNonLostContext();
9820
9821 if (context)
9822 {
9823 if (context->getClientVersion() < 3)
9824 {
9825 return gl::error(GL_INVALID_OPERATION);
9826 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009827
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009828 if (index >= gl::MAX_VERTEX_ATTRIBS)
9829 {
9830 return gl::error(GL_INVALID_VALUE);
9831 }
9832
9833 context->setVertexAttribi(index, v);
9834 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009835 }
9836 catch(std::bad_alloc&)
9837 {
9838 return gl::error(GL_OUT_OF_MEMORY);
9839 }
9840}
9841
9842void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9843{
9844 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9845
9846 try
9847 {
9848 gl::Context *context = gl::getNonLostContext();
9849
9850 if (context)
9851 {
9852 if (context->getClientVersion() < 3)
9853 {
9854 return gl::error(GL_INVALID_OPERATION);
9855 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009856
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009857 if (index >= gl::MAX_VERTEX_ATTRIBS)
9858 {
9859 return gl::error(GL_INVALID_VALUE);
9860 }
9861
9862 context->setVertexAttribu(index, v);
9863 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009864 }
9865 catch(std::bad_alloc&)
9866 {
9867 return gl::error(GL_OUT_OF_MEMORY);
9868 }
9869}
9870
9871void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9872{
9873 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9874 program, location, params);
9875
9876 try
9877 {
9878 gl::Context *context = gl::getNonLostContext();
9879
9880 if (context)
9881 {
9882 if (context->getClientVersion() < 3)
9883 {
9884 return gl::error(GL_INVALID_OPERATION);
9885 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009886
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009887 if (program == 0)
9888 {
9889 return gl::error(GL_INVALID_VALUE);
9890 }
9891
9892 gl::Program *programObject = context->getProgram(program);
9893
9894 if (!programObject || !programObject->isLinked())
9895 {
9896 return gl::error(GL_INVALID_OPERATION);
9897 }
9898
9899 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9900 if (!programBinary)
9901 {
9902 return gl::error(GL_INVALID_OPERATION);
9903 }
9904
9905 if (!programBinary->getUniformuiv(location, NULL, params))
9906 {
9907 return gl::error(GL_INVALID_OPERATION);
9908 }
9909 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009910 }
9911 catch(std::bad_alloc&)
9912 {
9913 return gl::error(GL_OUT_OF_MEMORY);
9914 }
9915}
9916
9917GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9918{
9919 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9920 program, name);
9921
9922 try
9923 {
9924 gl::Context *context = gl::getNonLostContext();
9925
9926 if (context)
9927 {
9928 if (context->getClientVersion() < 3)
9929 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009930 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009932
Jamie Madilld1e78c92013-06-20 11:55:50 -04009933 if (program == 0)
9934 {
9935 return gl::error(GL_INVALID_VALUE, -1);
9936 }
9937
9938 gl::Program *programObject = context->getProgram(program);
9939
9940 if (!programObject || !programObject->isLinked())
9941 {
9942 return gl::error(GL_INVALID_OPERATION, -1);
9943 }
9944
9945 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9946 if (!programBinary)
9947 {
9948 return gl::error(GL_INVALID_OPERATION, -1);
9949 }
9950
9951 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009952 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009953 }
9954 catch(std::bad_alloc&)
9955 {
9956 return gl::error(GL_OUT_OF_MEMORY, 0);
9957 }
9958
9959 return 0;
9960}
9961
9962void __stdcall glUniform1ui(GLint location, GLuint v0)
9963{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009964 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009965}
9966
9967void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9968{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009969 const GLuint xy[] = { v0, v1 };
9970 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009971}
9972
9973void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9974{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009975 const GLuint xyz[] = { v0, v1, v2 };
9976 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009977}
9978
9979void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9980{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009981 const GLuint xyzw[] = { v0, v1, v2, v3 };
9982 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009983}
9984
9985void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9986{
9987 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9988 location, count, value);
9989
9990 try
9991 {
9992 gl::Context *context = gl::getNonLostContext();
9993
9994 if (context)
9995 {
9996 if (context->getClientVersion() < 3)
9997 {
9998 return gl::error(GL_INVALID_OPERATION);
9999 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010000
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010001 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10002 if (!programBinary)
10003 {
10004 return gl::error(GL_INVALID_OPERATION);
10005 }
10006
10007 if (!programBinary->setUniform1uiv(location, count, value))
10008 {
10009 return gl::error(GL_INVALID_OPERATION);
10010 }
10011 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010012 }
10013 catch(std::bad_alloc&)
10014 {
10015 return gl::error(GL_OUT_OF_MEMORY);
10016 }
10017}
10018
10019void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10020{
10021 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10022 location, count, value);
10023
10024 try
10025 {
10026 gl::Context *context = gl::getNonLostContext();
10027
10028 if (context)
10029 {
10030 if (context->getClientVersion() < 3)
10031 {
10032 return gl::error(GL_INVALID_OPERATION);
10033 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010034
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010035 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10036 if (!programBinary)
10037 {
10038 return gl::error(GL_INVALID_OPERATION);
10039 }
10040
10041 if (!programBinary->setUniform2uiv(location, count, value))
10042 {
10043 return gl::error(GL_INVALID_OPERATION);
10044 }
10045 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010046 }
10047 catch(std::bad_alloc&)
10048 {
10049 return gl::error(GL_OUT_OF_MEMORY);
10050 }
10051}
10052
10053void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10054{
10055 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10056 location, count, value);
10057
10058 try
10059 {
10060 gl::Context *context = gl::getNonLostContext();
10061
10062 if (context)
10063 {
10064 if (context->getClientVersion() < 3)
10065 {
10066 return gl::error(GL_INVALID_OPERATION);
10067 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010068
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010069 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10070 if (!programBinary)
10071 {
10072 return gl::error(GL_INVALID_OPERATION);
10073 }
10074
10075 if (!programBinary->setUniform3uiv(location, count, value))
10076 {
10077 return gl::error(GL_INVALID_OPERATION);
10078 }
10079 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010080 }
10081 catch(std::bad_alloc&)
10082 {
10083 return gl::error(GL_OUT_OF_MEMORY);
10084 }
10085}
10086
10087void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10088{
10089 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10090 location, count, value);
10091
10092 try
10093 {
10094 gl::Context *context = gl::getNonLostContext();
10095
10096 if (context)
10097 {
10098 if (context->getClientVersion() < 3)
10099 {
10100 return gl::error(GL_INVALID_OPERATION);
10101 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010102
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010103 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10104 if (!programBinary)
10105 {
10106 return gl::error(GL_INVALID_OPERATION);
10107 }
10108
10109 if (!programBinary->setUniform4uiv(location, count, value))
10110 {
10111 return gl::error(GL_INVALID_OPERATION);
10112 }
10113 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010114 }
10115 catch(std::bad_alloc&)
10116 {
10117 return gl::error(GL_OUT_OF_MEMORY);
10118 }
10119}
10120
10121void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10122{
10123 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10124 buffer, drawbuffer, value);
10125
10126 try
10127 {
10128 gl::Context *context = gl::getNonLostContext();
10129
10130 if (context)
10131 {
10132 if (context->getClientVersion() < 3)
10133 {
10134 return gl::error(GL_INVALID_OPERATION);
10135 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010136
Jamie Madill54133512013-06-21 09:33:07 -040010137 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010138 UNIMPLEMENTED();
10139 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010140 }
10141 catch(std::bad_alloc&)
10142 {
10143 return gl::error(GL_OUT_OF_MEMORY);
10144 }
10145}
10146
10147void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10148{
10149 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10150 buffer, drawbuffer, value);
10151
10152 try
10153 {
10154 gl::Context *context = gl::getNonLostContext();
10155
10156 if (context)
10157 {
10158 if (context->getClientVersion() < 3)
10159 {
10160 return gl::error(GL_INVALID_OPERATION);
10161 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010162
Jamie Madill54133512013-06-21 09:33:07 -040010163 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010164 UNIMPLEMENTED();
10165 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010166 }
10167 catch(std::bad_alloc&)
10168 {
10169 return gl::error(GL_OUT_OF_MEMORY);
10170 }
10171}
10172
10173void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10174{
10175 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10176 buffer, drawbuffer, value);
10177
10178 try
10179 {
10180 gl::Context *context = gl::getNonLostContext();
10181
10182 if (context)
10183 {
10184 if (context->getClientVersion() < 3)
10185 {
10186 return gl::error(GL_INVALID_OPERATION);
10187 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010188
Jamie Madill54133512013-06-21 09:33:07 -040010189 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010190 UNIMPLEMENTED();
10191 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010192 }
10193 catch(std::bad_alloc&)
10194 {
10195 return gl::error(GL_OUT_OF_MEMORY);
10196 }
10197}
10198
10199void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10200{
10201 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10202 buffer, drawbuffer, depth, stencil);
10203
10204 try
10205 {
10206 gl::Context *context = gl::getNonLostContext();
10207
10208 if (context)
10209 {
10210 if (context->getClientVersion() < 3)
10211 {
10212 return gl::error(GL_INVALID_OPERATION);
10213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010214
Jamie Madill54133512013-06-21 09:33:07 -040010215 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010216 UNIMPLEMENTED();
10217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010218 }
10219 catch(std::bad_alloc&)
10220 {
10221 return gl::error(GL_OUT_OF_MEMORY);
10222 }
10223}
10224
10225const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10226{
10227 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10228
10229 try
10230 {
10231 gl::Context *context = gl::getNonLostContext();
10232
10233 if (context)
10234 {
10235 if (context->getClientVersion() < 3)
10236 {
10237 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10238 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010239
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010240 if (name != GL_EXTENSIONS)
10241 {
10242 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10243 }
10244
10245 if (index >= context->getNumExtensions())
10246 {
10247 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10248 }
10249
10250 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10251 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010252 }
10253 catch(std::bad_alloc&)
10254 {
10255 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10256 }
10257
10258 return NULL;
10259}
10260
10261void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10262{
10263 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10264 readTarget, writeTarget, readOffset, writeOffset, size);
10265
10266 try
10267 {
10268 gl::Context *context = gl::getNonLostContext();
10269
10270 if (context)
10271 {
10272 if (context->getClientVersion() < 3)
10273 {
10274 return gl::error(GL_INVALID_OPERATION);
10275 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010276
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010277 gl::Buffer *readBuffer = NULL;
10278 switch (readTarget)
10279 {
10280 case GL_ARRAY_BUFFER:
10281 readBuffer = context->getArrayBuffer();
10282 break;
10283 case GL_COPY_READ_BUFFER:
10284 readBuffer = context->getCopyReadBuffer();
10285 break;
10286 case GL_COPY_WRITE_BUFFER:
10287 readBuffer = context->getCopyWriteBuffer();
10288 break;
10289 case GL_ELEMENT_ARRAY_BUFFER:
10290 readBuffer = context->getElementArrayBuffer();
10291 break;
10292 case GL_PIXEL_PACK_BUFFER:
10293 readBuffer = context->getPixelPackBuffer();
10294 break;
10295 case GL_PIXEL_UNPACK_BUFFER:
10296 readBuffer = context->getPixelUnpackBuffer();
10297 break;
10298 case GL_TRANSFORM_FEEDBACK_BUFFER:
10299 readBuffer = context->getGenericTransformFeedbackBuffer();
10300 break;
10301 case GL_UNIFORM_BUFFER:
10302 readBuffer = context->getGenericUniformBuffer();
10303 break;
10304 default:
10305 return gl::error(GL_INVALID_ENUM);
10306 }
10307
10308 gl::Buffer *writeBuffer = NULL;
10309 switch (writeTarget)
10310 {
10311 case GL_ARRAY_BUFFER:
10312 writeBuffer = context->getArrayBuffer();
10313 break;
10314 case GL_COPY_READ_BUFFER:
10315 writeBuffer = context->getCopyReadBuffer();
10316 break;
10317 case GL_COPY_WRITE_BUFFER:
10318 writeBuffer = context->getCopyWriteBuffer();
10319 break;
10320 case GL_ELEMENT_ARRAY_BUFFER:
10321 writeBuffer = context->getElementArrayBuffer();
10322 break;
10323 case GL_PIXEL_PACK_BUFFER:
10324 writeBuffer = context->getPixelPackBuffer();
10325 break;
10326 case GL_PIXEL_UNPACK_BUFFER:
10327 writeBuffer = context->getPixelUnpackBuffer();
10328 break;
10329 case GL_TRANSFORM_FEEDBACK_BUFFER:
10330 writeBuffer = context->getGenericTransformFeedbackBuffer();
10331 break;
10332 case GL_UNIFORM_BUFFER:
10333 writeBuffer = context->getGenericUniformBuffer();
10334 break;
10335 default:
10336 return gl::error(GL_INVALID_ENUM);
10337 }
10338
10339 if (!readBuffer || !writeBuffer)
10340 {
10341 return gl::error(GL_INVALID_OPERATION);
10342 }
10343
10344 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10345 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10346 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10347 {
10348 return gl::error(GL_INVALID_VALUE);
10349 }
10350
10351 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10352 {
10353 return gl::error(GL_INVALID_VALUE);
10354 }
10355
10356 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10357
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010358 // if size is zero, the copy is a successful no-op
10359 if (size > 0)
10360 {
10361 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10362 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010363 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010364 }
10365 catch(std::bad_alloc&)
10366 {
10367 return gl::error(GL_OUT_OF_MEMORY);
10368 }
10369}
10370
10371void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10372{
10373 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10374 program, uniformCount, uniformNames, uniformIndices);
10375
10376 try
10377 {
10378 gl::Context *context = gl::getNonLostContext();
10379
10380 if (context)
10381 {
10382 if (context->getClientVersion() < 3)
10383 {
10384 return gl::error(GL_INVALID_OPERATION);
10385 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010386
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010387 if (uniformCount < 0)
10388 {
10389 return gl::error(GL_INVALID_VALUE);
10390 }
10391
10392 gl::Program *programObject = context->getProgram(program);
10393
10394 if (!programObject)
10395 {
10396 if (context->getShader(program))
10397 {
10398 return gl::error(GL_INVALID_OPERATION);
10399 }
10400 else
10401 {
10402 return gl::error(GL_INVALID_VALUE);
10403 }
10404 }
10405
10406 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10407 if (!programObject->isLinked() || !programBinary)
10408 {
10409 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10410 {
10411 uniformIndices[uniformId] = GL_INVALID_INDEX;
10412 }
10413 }
10414 else
10415 {
10416 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10417 {
10418 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10419 }
10420 }
10421 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010422 }
10423 catch(std::bad_alloc&)
10424 {
10425 return gl::error(GL_OUT_OF_MEMORY);
10426 }
10427}
10428
10429void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10430{
10431 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10432 program, uniformCount, uniformIndices, pname, params);
10433
10434 try
10435 {
10436 gl::Context *context = gl::getNonLostContext();
10437
10438 if (context)
10439 {
10440 if (context->getClientVersion() < 3)
10441 {
10442 return gl::error(GL_INVALID_OPERATION);
10443 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010444
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010445 if (uniformCount < 0)
10446 {
10447 return gl::error(GL_INVALID_VALUE);
10448 }
10449
10450 gl::Program *programObject = context->getProgram(program);
10451
10452 if (!programObject)
10453 {
10454 if (context->getShader(program))
10455 {
10456 return gl::error(GL_INVALID_OPERATION);
10457 }
10458 else
10459 {
10460 return gl::error(GL_INVALID_VALUE);
10461 }
10462 }
10463
10464 switch (pname)
10465 {
10466 case GL_UNIFORM_TYPE:
10467 case GL_UNIFORM_SIZE:
10468 case GL_UNIFORM_NAME_LENGTH:
10469 case GL_UNIFORM_BLOCK_INDEX:
10470 case GL_UNIFORM_OFFSET:
10471 case GL_UNIFORM_ARRAY_STRIDE:
10472 case GL_UNIFORM_MATRIX_STRIDE:
10473 case GL_UNIFORM_IS_ROW_MAJOR:
10474 break;
10475 default:
10476 return gl::error(GL_INVALID_ENUM);
10477 }
10478
10479 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10480
10481 if (!programBinary && uniformCount > 0)
10482 {
10483 return gl::error(GL_INVALID_VALUE);
10484 }
10485
10486 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10487 {
10488 const GLuint index = uniformIndices[uniformId];
10489
10490 if (index >= (GLuint)programBinary->getActiveUniformCount())
10491 {
10492 return gl::error(GL_INVALID_VALUE);
10493 }
10494 }
10495
10496 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10497 {
10498 const GLuint index = uniformIndices[uniformId];
10499 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10500 }
10501 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010502 }
10503 catch(std::bad_alloc&)
10504 {
10505 return gl::error(GL_OUT_OF_MEMORY);
10506 }
10507}
10508
10509GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10510{
10511 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10512
10513 try
10514 {
10515 gl::Context *context = gl::getNonLostContext();
10516
10517 if (context)
10518 {
10519 if (context->getClientVersion() < 3)
10520 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010521 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010522 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010523
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010524 gl::Program *programObject = context->getProgram(program);
10525
10526 if (!programObject)
10527 {
10528 if (context->getShader(program))
10529 {
10530 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10531 }
10532 else
10533 {
10534 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10535 }
10536 }
10537
10538 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10539 if (!programBinary)
10540 {
10541 return GL_INVALID_INDEX;
10542 }
10543
10544 return programBinary->getUniformBlockIndex(uniformBlockName);
10545 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010546 }
10547 catch(std::bad_alloc&)
10548 {
10549 return gl::error(GL_OUT_OF_MEMORY, 0);
10550 }
10551
10552 return 0;
10553}
10554
10555void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10556{
10557 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10558 program, uniformBlockIndex, pname, params);
10559
10560 try
10561 {
10562 gl::Context *context = gl::getNonLostContext();
10563
10564 if (context)
10565 {
10566 if (context->getClientVersion() < 3)
10567 {
10568 return gl::error(GL_INVALID_OPERATION);
10569 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010570 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010571
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010572 if (!programObject)
10573 {
10574 if (context->getShader(program))
10575 {
10576 return gl::error(GL_INVALID_OPERATION);
10577 }
10578 else
10579 {
10580 return gl::error(GL_INVALID_VALUE);
10581 }
10582 }
10583
10584 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10585
10586 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10587 {
10588 return gl::error(GL_INVALID_VALUE);
10589 }
10590
10591 switch (pname)
10592 {
10593 case GL_UNIFORM_BLOCK_BINDING:
10594 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10595 break;
10596
10597 case GL_UNIFORM_BLOCK_DATA_SIZE:
10598 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10599 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10600 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10601 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10602 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10603 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10604 break;
10605
10606 default:
10607 return gl::error(GL_INVALID_ENUM);
10608 }
10609 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010610 }
10611 catch(std::bad_alloc&)
10612 {
10613 return gl::error(GL_OUT_OF_MEMORY);
10614 }
10615}
10616
10617void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10618{
10619 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10620 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10621
10622 try
10623 {
10624 gl::Context *context = gl::getNonLostContext();
10625
10626 if (context)
10627 {
10628 if (context->getClientVersion() < 3)
10629 {
10630 return gl::error(GL_INVALID_OPERATION);
10631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010632
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010633 gl::Program *programObject = context->getProgram(program);
10634
10635 if (!programObject)
10636 {
10637 if (context->getShader(program))
10638 {
10639 return gl::error(GL_INVALID_OPERATION);
10640 }
10641 else
10642 {
10643 return gl::error(GL_INVALID_VALUE);
10644 }
10645 }
10646
10647 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10648
10649 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10650 {
10651 return gl::error(GL_INVALID_VALUE);
10652 }
10653
10654 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10655 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010656 }
10657 catch(std::bad_alloc&)
10658 {
10659 return gl::error(GL_OUT_OF_MEMORY);
10660 }
10661}
10662
10663void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10664{
10665 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10666 program, uniformBlockIndex, uniformBlockBinding);
10667
10668 try
10669 {
10670 gl::Context *context = gl::getNonLostContext();
10671
10672 if (context)
10673 {
10674 if (context->getClientVersion() < 3)
10675 {
10676 return gl::error(GL_INVALID_OPERATION);
10677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010678
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010679 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10680 {
10681 return gl::error(GL_INVALID_VALUE);
10682 }
10683
10684 gl::Program *programObject = context->getProgram(program);
10685
10686 if (!programObject)
10687 {
10688 if (context->getShader(program))
10689 {
10690 return gl::error(GL_INVALID_OPERATION);
10691 }
10692 else
10693 {
10694 return gl::error(GL_INVALID_VALUE);
10695 }
10696 }
10697
10698 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10699
10700 // if never linked, there won't be any uniform blocks
10701 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10702 {
10703 return gl::error(GL_INVALID_VALUE);
10704 }
10705
10706 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10707 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010708 }
10709 catch(std::bad_alloc&)
10710 {
10711 return gl::error(GL_OUT_OF_MEMORY);
10712 }
10713}
10714
10715void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10716{
10717 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10718 mode, first, count, instanceCount);
10719
10720 try
10721 {
10722 gl::Context *context = gl::getNonLostContext();
10723
10724 if (context)
10725 {
10726 if (context->getClientVersion() < 3)
10727 {
10728 return gl::error(GL_INVALID_OPERATION);
10729 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010730
Jamie Madill54133512013-06-21 09:33:07 -040010731 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010732 UNIMPLEMENTED();
10733 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010734 }
10735 catch(std::bad_alloc&)
10736 {
10737 return gl::error(GL_OUT_OF_MEMORY);
10738 }
10739}
10740
10741void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10742{
10743 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10744 mode, count, type, indices, instanceCount);
10745
10746 try
10747 {
10748 gl::Context *context = gl::getNonLostContext();
10749
10750 if (context)
10751 {
10752 if (context->getClientVersion() < 3)
10753 {
10754 return gl::error(GL_INVALID_OPERATION);
10755 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010756
Jamie Madill54133512013-06-21 09:33:07 -040010757 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010758 UNIMPLEMENTED();
10759 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010760 }
10761 catch(std::bad_alloc&)
10762 {
10763 return gl::error(GL_OUT_OF_MEMORY);
10764 }
10765}
10766
10767GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10768{
10769 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10770
10771 try
10772 {
10773 gl::Context *context = gl::getNonLostContext();
10774
10775 if (context)
10776 {
10777 if (context->getClientVersion() < 3)
10778 {
10779 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10780 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010781
Jamie Madill54133512013-06-21 09:33:07 -040010782 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010783 UNIMPLEMENTED();
10784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010785 }
10786 catch(std::bad_alloc&)
10787 {
10788 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10789 }
10790
10791 return NULL;
10792}
10793
10794GLboolean __stdcall glIsSync(GLsync sync)
10795{
10796 EVENT("(GLsync sync = 0x%0.8p)", sync);
10797
10798 try
10799 {
10800 gl::Context *context = gl::getNonLostContext();
10801
10802 if (context)
10803 {
10804 if (context->getClientVersion() < 3)
10805 {
10806 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10807 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010808
Jamie Madill54133512013-06-21 09:33:07 -040010809 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010810 UNIMPLEMENTED();
10811 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010812 }
10813 catch(std::bad_alloc&)
10814 {
10815 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10816 }
10817
10818 return GL_FALSE;
10819}
10820
10821void __stdcall glDeleteSync(GLsync sync)
10822{
10823 EVENT("(GLsync sync = 0x%0.8p)", sync);
10824
10825 try
10826 {
10827 gl::Context *context = gl::getNonLostContext();
10828
10829 if (context)
10830 {
10831 if (context->getClientVersion() < 3)
10832 {
10833 return gl::error(GL_INVALID_OPERATION);
10834 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010835
Jamie Madill54133512013-06-21 09:33:07 -040010836 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010837 UNIMPLEMENTED();
10838 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010839 }
10840 catch(std::bad_alloc&)
10841 {
10842 return gl::error(GL_OUT_OF_MEMORY);
10843 }
10844}
10845
10846GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10847{
10848 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10849 sync, flags, timeout);
10850
10851 try
10852 {
10853 gl::Context *context = gl::getNonLostContext();
10854
10855 if (context)
10856 {
10857 if (context->getClientVersion() < 3)
10858 {
10859 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10860 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010861
Jamie Madill54133512013-06-21 09:33:07 -040010862 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010863 UNIMPLEMENTED();
10864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010865 }
10866 catch(std::bad_alloc&)
10867 {
10868 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10869 }
10870
10871 return GL_FALSE;
10872}
10873
10874void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10875{
10876 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10877 sync, flags, timeout);
10878
10879 try
10880 {
10881 gl::Context *context = gl::getNonLostContext();
10882
10883 if (context)
10884 {
10885 if (context->getClientVersion() < 3)
10886 {
10887 return gl::error(GL_INVALID_OPERATION);
10888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010889
Jamie Madill54133512013-06-21 09:33:07 -040010890 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010891 UNIMPLEMENTED();
10892 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010893 }
10894 catch(std::bad_alloc&)
10895 {
10896 return gl::error(GL_OUT_OF_MEMORY);
10897 }
10898}
10899
10900void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10901{
10902 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10903 pname, params);
10904
10905 try
10906 {
10907 gl::Context *context = gl::getNonLostContext();
10908
10909 if (context)
10910 {
10911 if (context->getClientVersion() < 3)
10912 {
10913 return gl::error(GL_INVALID_OPERATION);
10914 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010915
Jamie Madill54133512013-06-21 09:33:07 -040010916 // glGetInteger64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010917 UNIMPLEMENTED();
10918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010919 }
10920 catch(std::bad_alloc&)
10921 {
10922 return gl::error(GL_OUT_OF_MEMORY);
10923 }
10924}
10925
10926void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10927{
10928 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10929 sync, pname, bufSize, length, values);
10930
10931 try
10932 {
10933 gl::Context *context = gl::getNonLostContext();
10934
10935 if (context)
10936 {
10937 if (context->getClientVersion() < 3)
10938 {
10939 return gl::error(GL_INVALID_OPERATION);
10940 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010941
Jamie Madill54133512013-06-21 09:33:07 -040010942 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010943 UNIMPLEMENTED();
10944 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010945 }
10946 catch(std::bad_alloc&)
10947 {
10948 return gl::error(GL_OUT_OF_MEMORY);
10949 }
10950}
10951
10952void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10953{
10954 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10955 target, index, data);
10956
10957 try
10958 {
10959 gl::Context *context = gl::getNonLostContext();
10960
10961 if (context)
10962 {
10963 if (context->getClientVersion() < 3)
10964 {
10965 return gl::error(GL_INVALID_OPERATION);
10966 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010967
Jamie Madill54133512013-06-21 09:33:07 -040010968 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010969 UNIMPLEMENTED();
10970 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010971 }
10972 catch(std::bad_alloc&)
10973 {
10974 return gl::error(GL_OUT_OF_MEMORY);
10975 }
10976}
10977
10978void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10979{
10980 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10981 target, pname, params);
10982
10983 try
10984 {
10985 gl::Context *context = gl::getNonLostContext();
10986
10987 if (context)
10988 {
10989 if (context->getClientVersion() < 3)
10990 {
10991 return gl::error(GL_INVALID_OPERATION);
10992 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010993
Jamie Madill54133512013-06-21 09:33:07 -040010994 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010995 UNIMPLEMENTED();
10996 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010997 }
10998 catch(std::bad_alloc&)
10999 {
11000 return gl::error(GL_OUT_OF_MEMORY);
11001 }
11002}
11003
11004void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11005{
11006 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11007
11008 try
11009 {
11010 gl::Context *context = gl::getNonLostContext();
11011
11012 if (context)
11013 {
11014 if (context->getClientVersion() < 3)
11015 {
11016 return gl::error(GL_INVALID_OPERATION);
11017 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011018
Jamie Madill54133512013-06-21 09:33:07 -040011019 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011020 UNIMPLEMENTED();
11021 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011022 }
11023 catch(std::bad_alloc&)
11024 {
11025 return gl::error(GL_OUT_OF_MEMORY);
11026 }
11027}
11028
11029void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11030{
11031 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11032
11033 try
11034 {
11035 gl::Context *context = gl::getNonLostContext();
11036
11037 if (context)
11038 {
11039 if (context->getClientVersion() < 3)
11040 {
11041 return gl::error(GL_INVALID_OPERATION);
11042 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011043
Jamie Madill54133512013-06-21 09:33:07 -040011044 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011045 UNIMPLEMENTED();
11046 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011047 }
11048 catch(std::bad_alloc&)
11049 {
11050 return gl::error(GL_OUT_OF_MEMORY);
11051 }
11052}
11053
11054GLboolean __stdcall glIsSampler(GLuint sampler)
11055{
11056 EVENT("(GLuint sampler = %u)", sampler);
11057
11058 try
11059 {
11060 gl::Context *context = gl::getNonLostContext();
11061
11062 if (context)
11063 {
11064 if (context->getClientVersion() < 3)
11065 {
11066 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11067 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011068
Jamie Madill54133512013-06-21 09:33:07 -040011069 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011070 UNIMPLEMENTED();
11071 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011072 }
11073 catch(std::bad_alloc&)
11074 {
11075 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11076 }
11077
11078 return GL_FALSE;
11079}
11080
11081void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11082{
11083 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11084
11085 try
11086 {
11087 gl::Context *context = gl::getNonLostContext();
11088
11089 if (context)
11090 {
11091 if (context->getClientVersion() < 3)
11092 {
11093 return gl::error(GL_INVALID_OPERATION);
11094 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011095
Jamie Madill54133512013-06-21 09:33:07 -040011096 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011097 UNIMPLEMENTED();
11098 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011099 }
11100 catch(std::bad_alloc&)
11101 {
11102 return gl::error(GL_OUT_OF_MEMORY);
11103 }
11104}
11105
11106void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11107{
11108 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11109
11110 try
11111 {
11112 gl::Context *context = gl::getNonLostContext();
11113
11114 if (context)
11115 {
11116 if (context->getClientVersion() < 3)
11117 {
11118 return gl::error(GL_INVALID_OPERATION);
11119 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011120
Jamie Madill54133512013-06-21 09:33:07 -040011121 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011122 UNIMPLEMENTED();
11123 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011124 }
11125 catch(std::bad_alloc&)
11126 {
11127 return gl::error(GL_OUT_OF_MEMORY);
11128 }
11129}
11130
11131void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11132{
11133 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11134 sampler, pname, param);
11135
11136 try
11137 {
11138 gl::Context *context = gl::getNonLostContext();
11139
11140 if (context)
11141 {
11142 if (context->getClientVersion() < 3)
11143 {
11144 return gl::error(GL_INVALID_OPERATION);
11145 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011146
Jamie Madill54133512013-06-21 09:33:07 -040011147 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011148 UNIMPLEMENTED();
11149 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011150 }
11151 catch(std::bad_alloc&)
11152 {
11153 return gl::error(GL_OUT_OF_MEMORY);
11154 }
11155}
11156
11157void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11158{
11159 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11160
11161 try
11162 {
11163 gl::Context *context = gl::getNonLostContext();
11164
11165 if (context)
11166 {
11167 if (context->getClientVersion() < 3)
11168 {
11169 return gl::error(GL_INVALID_OPERATION);
11170 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011171
Jamie Madill54133512013-06-21 09:33:07 -040011172 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011173 UNIMPLEMENTED();
11174 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011175 }
11176 catch(std::bad_alloc&)
11177 {
11178 return gl::error(GL_OUT_OF_MEMORY);
11179 }
11180}
11181
11182void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11183{
11184 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11185
11186 try
11187 {
11188 gl::Context *context = gl::getNonLostContext();
11189
11190 if (context)
11191 {
11192 if (context->getClientVersion() < 3)
11193 {
11194 return gl::error(GL_INVALID_OPERATION);
11195 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011196
Jamie Madill54133512013-06-21 09:33:07 -040011197 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011198 UNIMPLEMENTED();
11199 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011200 }
11201 catch(std::bad_alloc&)
11202 {
11203 return gl::error(GL_OUT_OF_MEMORY);
11204 }
11205}
11206
11207void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11208{
11209 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11210
11211 try
11212 {
11213 gl::Context *context = gl::getNonLostContext();
11214
11215 if (context)
11216 {
11217 if (context->getClientVersion() < 3)
11218 {
11219 return gl::error(GL_INVALID_OPERATION);
11220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011221
Jamie Madill54133512013-06-21 09:33:07 -040011222 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011223 UNIMPLEMENTED();
11224 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011225 }
11226 catch(std::bad_alloc&)
11227 {
11228 return gl::error(GL_OUT_OF_MEMORY);
11229 }
11230}
11231
11232void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11233{
11234 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11235
11236 try
11237 {
11238 gl::Context *context = gl::getNonLostContext();
11239
11240 if (context)
11241 {
11242 if (context->getClientVersion() < 3)
11243 {
11244 return gl::error(GL_INVALID_OPERATION);
11245 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011246
Jamie Madill54133512013-06-21 09:33:07 -040011247 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011248 UNIMPLEMENTED();
11249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011250 }
11251 catch(std::bad_alloc&)
11252 {
11253 return gl::error(GL_OUT_OF_MEMORY);
11254 }
11255}
11256
11257void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11258{
11259 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11260
11261 try
11262 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011263 if (index >= gl::MAX_VERTEX_ATTRIBS)
11264 {
11265 return gl::error(GL_INVALID_VALUE);
11266 }
11267
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011268 gl::Context *context = gl::getNonLostContext();
11269
11270 if (context)
11271 {
11272 if (context->getClientVersion() < 3)
11273 {
11274 return gl::error(GL_INVALID_OPERATION);
11275 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011276
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011277 context->setVertexAttribDivisor(index, divisor);
11278 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011279 }
11280 catch(std::bad_alloc&)
11281 {
11282 return gl::error(GL_OUT_OF_MEMORY);
11283 }
11284}
11285
11286void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11287{
11288 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11289
11290 try
11291 {
11292 gl::Context *context = gl::getNonLostContext();
11293
11294 if (context)
11295 {
11296 if (context->getClientVersion() < 3)
11297 {
11298 return gl::error(GL_INVALID_OPERATION);
11299 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011300
Jamie Madill54133512013-06-21 09:33:07 -040011301 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011302 UNIMPLEMENTED();
11303 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011304 }
11305 catch(std::bad_alloc&)
11306 {
11307 return gl::error(GL_OUT_OF_MEMORY);
11308 }
11309}
11310
11311void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11312{
11313 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11314
11315 try
11316 {
11317 gl::Context *context = gl::getNonLostContext();
11318
11319 if (context)
11320 {
11321 if (context->getClientVersion() < 3)
11322 {
11323 return gl::error(GL_INVALID_OPERATION);
11324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011325
Jamie Madill54133512013-06-21 09:33:07 -040011326 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011327 UNIMPLEMENTED();
11328 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011329 }
11330 catch(std::bad_alloc&)
11331 {
11332 return gl::error(GL_OUT_OF_MEMORY);
11333 }
11334}
11335
11336void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11337{
11338 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11339
11340 try
11341 {
11342 gl::Context *context = gl::getNonLostContext();
11343
11344 if (context)
11345 {
11346 if (context->getClientVersion() < 3)
11347 {
11348 return gl::error(GL_INVALID_OPERATION);
11349 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011350
Jamie Madill54133512013-06-21 09:33:07 -040011351 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011352 UNIMPLEMENTED();
11353 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011354 }
11355 catch(std::bad_alloc&)
11356 {
11357 return gl::error(GL_OUT_OF_MEMORY);
11358 }
11359}
11360
11361GLboolean __stdcall glIsTransformFeedback(GLuint id)
11362{
11363 EVENT("(GLuint id = %u)", id);
11364
11365 try
11366 {
11367 gl::Context *context = gl::getNonLostContext();
11368
11369 if (context)
11370 {
11371 if (context->getClientVersion() < 3)
11372 {
11373 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11374 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011375
Jamie Madill54133512013-06-21 09:33:07 -040011376 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011377 UNIMPLEMENTED();
11378 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011379 }
11380 catch(std::bad_alloc&)
11381 {
11382 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11383 }
11384
11385 return GL_FALSE;
11386}
11387
11388void __stdcall glPauseTransformFeedback(void)
11389{
11390 EVENT("(void)");
11391
11392 try
11393 {
11394 gl::Context *context = gl::getNonLostContext();
11395
11396 if (context)
11397 {
11398 if (context->getClientVersion() < 3)
11399 {
11400 return gl::error(GL_INVALID_OPERATION);
11401 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011402
Jamie Madill54133512013-06-21 09:33:07 -040011403 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011404 UNIMPLEMENTED();
11405 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011406 }
11407 catch(std::bad_alloc&)
11408 {
11409 return gl::error(GL_OUT_OF_MEMORY);
11410 }
11411}
11412
11413void __stdcall glResumeTransformFeedback(void)
11414{
11415 EVENT("(void)");
11416
11417 try
11418 {
11419 gl::Context *context = gl::getNonLostContext();
11420
11421 if (context)
11422 {
11423 if (context->getClientVersion() < 3)
11424 {
11425 return gl::error(GL_INVALID_OPERATION);
11426 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011427
Jamie Madill54133512013-06-21 09:33:07 -040011428 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011429 UNIMPLEMENTED();
11430 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011431 }
11432 catch(std::bad_alloc&)
11433 {
11434 return gl::error(GL_OUT_OF_MEMORY);
11435 }
11436}
11437
11438void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11439{
11440 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11441 program, bufSize, length, binaryFormat, binary);
11442
11443 try
11444 {
11445 gl::Context *context = gl::getNonLostContext();
11446
11447 if (context)
11448 {
11449 if (context->getClientVersion() < 3)
11450 {
11451 return gl::error(GL_INVALID_OPERATION);
11452 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011453
Jamie Madill54133512013-06-21 09:33:07 -040011454 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011455 UNIMPLEMENTED();
11456 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011457 }
11458 catch(std::bad_alloc&)
11459 {
11460 return gl::error(GL_OUT_OF_MEMORY);
11461 }
11462}
11463
11464void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11465{
11466 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11467 program, binaryFormat, binary, length);
11468
11469 try
11470 {
11471 gl::Context *context = gl::getNonLostContext();
11472
11473 if (context)
11474 {
11475 if (context->getClientVersion() < 3)
11476 {
11477 return gl::error(GL_INVALID_OPERATION);
11478 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011479
Jamie Madill54133512013-06-21 09:33:07 -040011480 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011481 UNIMPLEMENTED();
11482 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011483 }
11484 catch(std::bad_alloc&)
11485 {
11486 return gl::error(GL_OUT_OF_MEMORY);
11487 }
11488}
11489
11490void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11491{
11492 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11493 program, pname, value);
11494
11495 try
11496 {
11497 gl::Context *context = gl::getNonLostContext();
11498
11499 if (context)
11500 {
11501 if (context->getClientVersion() < 3)
11502 {
11503 return gl::error(GL_INVALID_OPERATION);
11504 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011505
Jamie Madill54133512013-06-21 09:33:07 -040011506 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011507 UNIMPLEMENTED();
11508 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011509 }
11510 catch(std::bad_alloc&)
11511 {
11512 return gl::error(GL_OUT_OF_MEMORY);
11513 }
11514}
11515
11516void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11517{
11518 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11519 target, numAttachments, attachments);
11520
11521 try
11522 {
11523 gl::Context *context = gl::getNonLostContext();
11524
11525 if (context)
11526 {
11527 if (context->getClientVersion() < 3)
11528 {
11529 return gl::error(GL_INVALID_OPERATION);
11530 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011531
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011532 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11533 {
11534 return;
11535 }
11536
11537 int maxDimension = context->getMaximumRenderbufferDimension();
11538 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011540 }
11541 catch(std::bad_alloc&)
11542 {
11543 return gl::error(GL_OUT_OF_MEMORY);
11544 }
11545}
11546
11547void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11548{
11549 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11550 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11551 target, numAttachments, attachments, x, y, width, height);
11552
11553 try
11554 {
11555 gl::Context *context = gl::getNonLostContext();
11556
11557 if (context)
11558 {
11559 if (context->getClientVersion() < 3)
11560 {
11561 return gl::error(GL_INVALID_OPERATION);
11562 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011563
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011564 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11565 {
11566 return;
11567 }
11568
11569 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11570 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011571 }
11572 catch(std::bad_alloc&)
11573 {
11574 return gl::error(GL_OUT_OF_MEMORY);
11575 }
11576}
11577
11578void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11579{
11580 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11581 target, levels, internalformat, width, height);
11582
11583 try
11584 {
11585 gl::Context *context = gl::getNonLostContext();
11586
11587 if (context)
11588 {
11589 if (context->getClientVersion() < 3)
11590 {
11591 return gl::error(GL_INVALID_OPERATION);
11592 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011593
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011594 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11595 {
11596 return;
11597 }
11598
11599 switch (target)
11600 {
11601 case GL_TEXTURE_2D:
11602 {
11603 gl::Texture2D *texture2d = context->getTexture2D();
11604 texture2d->storage(levels, internalformat, width, height);
11605 }
11606 break;
11607
11608 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11609 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11610 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11611 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11612 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11613 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11614 {
11615 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11616 textureCube->storage(levels, internalformat, width);
11617 }
11618 break;
11619
11620 default:
11621 return gl::error(GL_INVALID_ENUM);
11622 }
11623 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011624 }
11625 catch(std::bad_alloc&)
11626 {
11627 return gl::error(GL_OUT_OF_MEMORY);
11628 }
11629}
11630
11631void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11632{
11633 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11634 "GLsizei height = %d, GLsizei depth = %d)",
11635 target, levels, internalformat, width, height, depth);
11636
11637 try
11638 {
11639 gl::Context *context = gl::getNonLostContext();
11640
11641 if (context)
11642 {
11643 if (context->getClientVersion() < 3)
11644 {
11645 return gl::error(GL_INVALID_OPERATION);
11646 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011647
11648 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11649 {
11650 return;
11651 }
11652
11653 switch (target)
11654 {
11655 case GL_TEXTURE_3D:
11656 {
11657 gl::Texture3D *texture3d = context->getTexture3D();
11658 texture3d->storage(levels, internalformat, width, height, depth);
11659 }
11660 break;
11661
11662 case GL_TEXTURE_2D_ARRAY:
11663 {
11664 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11665 texture2darray->storage(levels, internalformat, width, height, depth);
11666 }
11667 break;
11668
11669 default:
11670 return gl::error(GL_INVALID_ENUM);
11671 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011672 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011673 }
11674 catch(std::bad_alloc&)
11675 {
11676 return gl::error(GL_OUT_OF_MEMORY);
11677 }
11678}
11679
11680void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11681{
11682 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11683 "GLint* params = 0x%0.8p)",
11684 target, internalformat, pname, bufSize, params);
11685
11686 try
11687 {
11688 gl::Context *context = gl::getNonLostContext();
11689
11690 if (context)
11691 {
11692 if (context->getClientVersion() < 3)
11693 {
11694 return gl::error(GL_INVALID_OPERATION);
11695 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011696
Shannon Woods809d2502013-07-08 10:32:18 -040011697 if (!gl::IsColorRenderingSupported(internalformat, context) &&
11698 !gl::IsDepthRenderingSupported(internalformat, context) &&
11699 !gl::IsStencilRenderingSupported(internalformat, context))
11700 {
11701 return gl::error(GL_INVALID_ENUM);
11702 }
11703
11704 if (target != GL_RENDERBUFFER)
11705 {
11706 return gl::error(GL_INVALID_ENUM);
11707 }
11708
11709 if (bufSize < 0)
11710 {
11711 return gl::error(GL_INVALID_VALUE);
11712 }
11713
11714 switch (pname)
11715 {
11716 case GL_NUM_SAMPLE_COUNTS:
11717 if (bufSize != 0)
11718 *params = context->getNumSampleCounts(internalformat);
11719 break;
11720 case GL_SAMPLES:
11721 context->getSampleCounts(internalformat, bufSize, params);
11722 break;
11723 default:
11724 return gl::error(GL_INVALID_ENUM);
11725 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011727 }
11728 catch(std::bad_alloc&)
11729 {
11730 return gl::error(GL_OUT_OF_MEMORY);
11731 }
11732}
11733
11734// Extension functions
11735
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011736void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11737 GLbitfield mask, GLenum filter)
11738{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011739 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011740 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11741 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11742 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11743
11744 try
11745 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011746 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011747
11748 if (context)
11749 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011750 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11751 dstX0, dstY0, dstX1, dstY1, mask, filter,
11752 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011753 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011754 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011755 }
11756
Geoff Lang758d5b22013-06-11 11:42:50 -040011757 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11758 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011759 }
11760 }
11761 catch(std::bad_alloc&)
11762 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011763 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011764 }
11765}
11766
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011767void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11768 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011769{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011770 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011771 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011772 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011773 target, level, internalformat, width, height, depth, border, format, type, pixels);
11774
11775 try
11776 {
11777 UNIMPLEMENTED(); // FIXME
11778 }
11779 catch(std::bad_alloc&)
11780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011781 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011782 }
11783}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011784
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011785void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11786 GLenum *binaryFormat, void *binary)
11787{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011788 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 +000011789 program, bufSize, length, binaryFormat, binary);
11790
11791 try
11792 {
11793 gl::Context *context = gl::getNonLostContext();
11794
11795 if (context)
11796 {
11797 gl::Program *programObject = context->getProgram(program);
11798
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011799 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011801 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011802 }
11803
11804 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11805
11806 if (!programBinary)
11807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011808 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011809 }
11810
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011811 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011813 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011814 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011815
11816 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011817 }
11818 }
11819 catch(std::bad_alloc&)
11820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011821 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011822 }
11823}
11824
11825void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11826 const void *binary, GLint length)
11827{
11828 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11829 program, binaryFormat, binary, length);
11830
11831 try
11832 {
11833 gl::Context *context = gl::getNonLostContext();
11834
11835 if (context)
11836 {
11837 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011839 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011840 }
11841
11842 gl::Program *programObject = context->getProgram(program);
11843
11844 if (!programObject)
11845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011846 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011847 }
11848
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011849 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011850 }
11851 }
11852 catch(std::bad_alloc&)
11853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011854 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011855 }
11856}
11857
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011858void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11859{
11860 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11861
11862 try
11863 {
11864 gl::Context *context = gl::getNonLostContext();
11865
11866 if (context)
11867 {
11868 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11869 {
11870 return gl::error(GL_INVALID_VALUE);
11871 }
11872
11873 if (context->getDrawFramebufferHandle() == 0)
11874 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011875 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011876 {
11877 return gl::error(GL_INVALID_OPERATION);
11878 }
11879
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011880 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011881 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011882 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011883 }
11884 }
11885 else
11886 {
11887 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11888 {
11889 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11890 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11891 {
11892 return gl::error(GL_INVALID_OPERATION);
11893 }
11894 }
11895 }
11896
11897 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11898
11899 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11900 {
11901 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11902 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011903
11904 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11905 {
11906 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11907 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011908 }
11909 }
11910 catch (std::bad_alloc&)
11911 {
11912 return gl::error(GL_OUT_OF_MEMORY);
11913 }
11914}
11915
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011916__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11917{
11918 struct Extension
11919 {
11920 const char *name;
11921 __eglMustCastToProperFunctionPointerType address;
11922 };
11923
11924 static const Extension glExtensions[] =
11925 {
11926 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011927 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011928 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011929 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11930 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11931 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11932 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11933 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11934 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11935 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011936 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011937 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011938 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11939 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11940 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11941 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011942 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11943 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11944 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11945 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11946 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11947 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11948 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011949 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011950 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11951 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11952 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011953 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11954 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011955
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011956 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011957 {
11958 if (strcmp(procname, glExtensions[ext].name) == 0)
11959 {
11960 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11961 }
11962 }
11963
11964 return NULL;
11965}
11966
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011967// Non-public functions used by EGL
11968
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011969bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011970{
11971 EVENT("(egl::Surface* surface = 0x%0.8p)",
11972 surface);
11973
11974 try
11975 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011976 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011977
11978 if (context)
11979 {
11980 gl::Texture2D *textureObject = context->getTexture2D();
11981
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011982 if (textureObject->isImmutable())
11983 {
11984 return false;
11985 }
11986
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011987 if (textureObject)
11988 {
11989 textureObject->bindTexImage(surface);
11990 }
11991 }
11992 }
11993 catch(std::bad_alloc&)
11994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011995 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011996 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011997
11998 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011999}
12000
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012001}