blob: 47d23bfc9c9f6924ff72b82dc4e1af1b419f4355 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000026bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000028 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000029 {
30 return false;
31 }
32
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000033 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000034 {
35 return true;
36 }
37
38 if (level == 0)
39 {
40 return true;
41 }
42
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000043 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000044 {
45 return true;
46 }
47
48 return false;
49}
50
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000051bool validCompressedImageSize(GLsizei width, GLsizei height)
52{
53 if (width != 1 && width != 2 && width % 4 != 0)
54 {
55 return false;
56 }
57
58 if (height != 1 && height != 2 && height % 4 != 0)
59 {
60 return false;
61 }
62
63 return true;
64}
65
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066// Verify that format/type are one of the combinations from table 3.4.
67bool checkTextureFormatType(GLenum format, GLenum type)
68{
69 // validate <format> by itself (used as secondary key below)
70 switch (format)
71 {
72 case GL_RGBA:
73 case GL_BGRA_EXT:
74 case GL_RGB:
75 case GL_ALPHA:
76 case GL_LUMINANCE:
77 case GL_LUMINANCE_ALPHA:
78 case GL_DEPTH_COMPONENT:
79 case GL_DEPTH_STENCIL_OES:
80 break;
81 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000082 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000083 }
84
85 // invalid <type> -> sets INVALID_ENUM
86 // invalid <format>+<type> combination -> sets INVALID_OPERATION
87 switch (type)
88 {
89 case GL_UNSIGNED_BYTE:
90 switch (format)
91 {
92 case GL_RGBA:
93 case GL_BGRA_EXT:
94 case GL_RGB:
95 case GL_ALPHA:
96 case GL_LUMINANCE:
97 case GL_LUMINANCE_ALPHA:
98 return true;
99 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000100 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000101 }
102
103 case GL_FLOAT:
104 case GL_HALF_FLOAT_OES:
105 switch (format)
106 {
107 case GL_RGBA:
108 case GL_RGB:
109 case GL_ALPHA:
110 case GL_LUMINANCE:
111 case GL_LUMINANCE_ALPHA:
112 return true;
113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000114 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000115 }
116
117 case GL_UNSIGNED_SHORT_4_4_4_4:
118 case GL_UNSIGNED_SHORT_5_5_5_1:
119 switch (format)
120 {
121 case GL_RGBA:
122 return true;
123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000124 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000125 }
126
127 case GL_UNSIGNED_SHORT_5_6_5:
128 switch (format)
129 {
130 case GL_RGB:
131 return true;
132 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000134 }
135
136 case GL_UNSIGNED_SHORT:
137 case GL_UNSIGNED_INT:
138 switch (format)
139 {
140 case GL_DEPTH_COMPONENT:
141 return true;
142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000143 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000144 }
145
146 case GL_UNSIGNED_INT_24_8_OES:
147 switch (format)
148 {
149 case GL_DEPTH_STENCIL_OES:
150 return true;
151 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000152 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000153 }
154
155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000156 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000157 }
158}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000160bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000161 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000162 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000163{
164 if (!texture)
165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000166 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000167 }
168
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000169 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000172 }
173
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000174 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000175 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000176 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000177 if (internalformat != texture->getInternalFormat(level))
178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000179 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000180 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000181 }
182
183 if (compressed)
184 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000185 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
186 (height % 4 != 0 && height != texture->getHeight(0)))
187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000188 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000189 }
190 }
191
192 if (xoffset + width > texture->getWidth(level) ||
193 yoffset + height > texture->getHeight(level))
194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
198 return true;
199}
200
201bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000202 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000203 gl::TextureCubeMap *texture)
204{
205 if (!texture)
206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000207 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000208 }
209
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000210 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000213 }
214
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000215 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000216 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000217 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000218 if (internalformat != texture->getInternalFormat(target, level))
219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000220 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000221 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000222 }
223
224 if (compressed)
225 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000226 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
227 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000229 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000230 }
231 }
232
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000233 if (xoffset + width > texture->getWidth(target, level) ||
234 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000236 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000237 }
238
239 return true;
240}
241
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000242bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
243 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
244 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
245{
246 if (!validImageSize(context, level, width, height, 1))
247 {
248 return gl::error(GL_INVALID_VALUE, false);
249 }
250
251 if (isCompressed && !validCompressedImageSize(width, height))
252 {
253 return gl::error(GL_INVALID_OPERATION, false);
254 }
255
256 if (level < 0 || xoffset < 0 ||
257 std::numeric_limits<GLsizei>::max() - xoffset < width ||
258 std::numeric_limits<GLsizei>::max() - yoffset < height)
259 {
260 return gl::error(GL_INVALID_VALUE, false);
261 }
262
263 if (!isSubImage && !isCompressed && internalformat != GLint(format))
264 {
265 return gl::error(GL_INVALID_OPERATION, false);
266 }
267
268 gl::Texture *texture = NULL;
269 bool textureCompressed = false;
270 GLenum textureInternalFormat = GL_NONE;
271 GLint textureLevelWidth = 0;
272 GLint textureLevelHeight = 0;
273 switch (target)
274 {
275 case GL_TEXTURE_2D:
276 {
277 if (width > (context->getMaximum2DTextureDimension() >> level) ||
278 height > (context->getMaximum2DTextureDimension() >> level))
279 {
280 return gl::error(GL_INVALID_VALUE, false);
281 }
282
283 gl::Texture2D *tex2d = context->getTexture2D();
284 if (tex2d)
285 {
286 textureCompressed = tex2d->isCompressed(level);
287 textureInternalFormat = tex2d->getInternalFormat(level);
288 textureLevelWidth = tex2d->getWidth(level);
289 textureLevelHeight = tex2d->getHeight(level);
290 texture = tex2d;
291 }
292
293 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
294 level, format, type, tex2d))
295 {
296 return false;
297 }
298
299 texture = tex2d;
300 }
301 break;
302
303 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
304 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
305 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
309 {
310 if (!isSubImage && width != height)
311 {
312 return gl::error(GL_INVALID_VALUE, false);
313 }
314
315 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
316 height > (context->getMaximumCubeTextureDimension() >> level))
317 {
318 return gl::error(GL_INVALID_VALUE, false);
319 }
320
321 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
322 if (texCube)
323 {
324 textureCompressed = texCube->isCompressed(target, level);
325 textureInternalFormat = texCube->getInternalFormat(target, level);
326 textureLevelWidth = texCube->getWidth(target, level);
327 textureLevelHeight = texCube->getHeight(target, level);
328 texture = texCube;
329 }
330
331 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
332 target, level, format, type, texCube))
333 {
334 return false;
335 }
336 }
337 break;
338
339 default:
340 return gl::error(GL_INVALID_ENUM, false);
341 }
342
343 if (!texture)
344 {
345 return gl::error(GL_INVALID_OPERATION, false);
346 }
347
348 if (!isSubImage && texture->isImmutable())
349 {
350 return gl::error(GL_INVALID_OPERATION, false);
351 }
352
353 // Verify zero border
354 if (border != 0)
355 {
356 return gl::error(GL_INVALID_VALUE, false);
357 }
358
359 // Verify texture is not requesting more mip levels than are available.
360 if (level > context->getMaximumTextureLevel())
361 {
362 return gl::error(GL_INVALID_VALUE, false);
363 }
364
365 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
366 if (isCompressed)
367 {
368 switch (actualInternalFormat)
369 {
370 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
371 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
372 if (!context->supportsDXT1Textures())
373 {
374 return gl::error(GL_INVALID_ENUM, false);
375 }
376 break;
377 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
378 if (!context->supportsDXT3Textures())
379 {
380 return gl::error(GL_INVALID_ENUM, false);
381 }
382 break;
383 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
384 if (!context->supportsDXT5Textures())
385 {
386 return gl::error(GL_INVALID_ENUM, false);
387 }
388 break;
389 default:
390 return gl::error(GL_INVALID_ENUM, false);
391 }
392 }
393 else
394 {
395 // validate <type> by itself (used as secondary key below)
396 switch (type)
397 {
398 case GL_UNSIGNED_BYTE:
399 case GL_UNSIGNED_SHORT_5_6_5:
400 case GL_UNSIGNED_SHORT_4_4_4_4:
401 case GL_UNSIGNED_SHORT_5_5_5_1:
402 case GL_UNSIGNED_SHORT:
403 case GL_UNSIGNED_INT:
404 case GL_UNSIGNED_INT_24_8_OES:
405 case GL_HALF_FLOAT_OES:
406 case GL_FLOAT:
407 break;
408 default:
409 return gl::error(GL_INVALID_ENUM, false);
410 }
411
412 // validate <format> + <type> combinations
413 // - invalid <format> -> sets INVALID_ENUM
414 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
415 switch (format)
416 {
417 case GL_ALPHA:
418 case GL_LUMINANCE:
419 case GL_LUMINANCE_ALPHA:
420 switch (type)
421 {
422 case GL_UNSIGNED_BYTE:
423 case GL_FLOAT:
424 case GL_HALF_FLOAT_OES:
425 break;
426 default:
427 return gl::error(GL_INVALID_OPERATION, false);
428 }
429 break;
430 case GL_RGB:
431 switch (type)
432 {
433 case GL_UNSIGNED_BYTE:
434 case GL_UNSIGNED_SHORT_5_6_5:
435 case GL_FLOAT:
436 case GL_HALF_FLOAT_OES:
437 break;
438 default:
439 return gl::error(GL_INVALID_OPERATION, false);
440 }
441 break;
442 case GL_RGBA:
443 switch (type)
444 {
445 case GL_UNSIGNED_BYTE:
446 case GL_UNSIGNED_SHORT_4_4_4_4:
447 case GL_UNSIGNED_SHORT_5_5_5_1:
448 case GL_FLOAT:
449 case GL_HALF_FLOAT_OES:
450 break;
451 default:
452 return gl::error(GL_INVALID_OPERATION, false);
453 }
454 break;
455 case GL_BGRA_EXT:
456 switch (type)
457 {
458 case GL_UNSIGNED_BYTE:
459 break;
460 default:
461 return gl::error(GL_INVALID_OPERATION, false);
462 }
463 break;
464 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
465 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
466 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
467 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
468 break;
469 case GL_DEPTH_COMPONENT:
470 switch (type)
471 {
472 case GL_UNSIGNED_SHORT:
473 case GL_UNSIGNED_INT:
474 break;
475 default:
476 return gl::error(GL_INVALID_OPERATION, false);
477 }
478 break;
479 case GL_DEPTH_STENCIL_OES:
480 switch (type)
481 {
482 case GL_UNSIGNED_INT_24_8_OES:
483 break;
484 default:
485 return gl::error(GL_INVALID_OPERATION, false);
486 }
487 break;
488 default:
489 return gl::error(GL_INVALID_ENUM, false);
490 }
491
492 switch (format)
493 {
494 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
495 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
496 if (context->supportsDXT1Textures())
497 {
498 return gl::error(GL_INVALID_OPERATION, false);
499 }
500 else
501 {
502 return gl::error(GL_INVALID_ENUM, false);
503 }
504 break;
505 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
506 if (context->supportsDXT3Textures())
507 {
508 return gl::error(GL_INVALID_OPERATION, false);
509 }
510 else
511 {
512 return gl::error(GL_INVALID_ENUM, false);
513 }
514 break;
515 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
516 if (context->supportsDXT5Textures())
517 {
518 return gl::error(GL_INVALID_OPERATION, false);
519 }
520 else
521 {
522 return gl::error(GL_INVALID_ENUM, false);
523 }
524 break;
525 case GL_DEPTH_COMPONENT:
526 case GL_DEPTH_STENCIL_OES:
527 if (!context->supportsDepthTextures())
528 {
529 return gl::error(GL_INVALID_VALUE, false);
530 }
531 if (target != GL_TEXTURE_2D)
532 {
533 return gl::error(GL_INVALID_OPERATION, false);
534 }
535 // OES_depth_texture supports loading depth data and multiple levels,
536 // but ANGLE_depth_texture does not
537 if (pixels != NULL || level != 0)
538 {
539 return gl::error(GL_INVALID_OPERATION, false);
540 }
541 break;
542 default:
543 break;
544 }
545
546 if (type == GL_FLOAT)
547 {
548 if (!context->supportsFloat32Textures())
549 {
550 return gl::error(GL_INVALID_ENUM, false);
551 }
552 }
553 else if (type == GL_HALF_FLOAT_OES)
554 {
555 if (!context->supportsFloat16Textures())
556 {
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559 }
560 }
561
562 return true;
563}
564
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000565bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
566 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
567 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000568{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000569 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000570 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000571 {
572 return gl::error(GL_INVALID_VALUE, false);
573 }
574
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000575 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000576 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000577 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000578 }
579
580 // Verify zero border
581 if (border != 0)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 // Validate dimensions based on Context limits and validate the texture
587 if (level > context->getMaximumTextureLevel())
588 {
589 return gl::error(GL_INVALID_VALUE, false);
590 }
591
592 gl::Texture *texture = NULL;
593 bool textureCompressed = false;
594 GLenum textureInternalFormat = GL_NONE;
595 GLint textureLevelWidth = 0;
596 GLint textureLevelHeight = 0;
597 GLint textureLevelDepth = 0;
598 switch (target)
599 {
600 case GL_TEXTURE_2D:
601 {
602 if (width > (context->getMaximum2DTextureDimension() >> level) ||
603 height > (context->getMaximum2DTextureDimension() >> level))
604 {
605 return gl::error(GL_INVALID_VALUE, false);
606 }
607
608 gl::Texture2D *texture2d = context->getTexture2D();
609 if (texture2d)
610 {
611 textureCompressed = texture2d->isCompressed(level);
612 textureInternalFormat = texture2d->getInternalFormat(level);
613 textureLevelWidth = texture2d->getWidth(level);
614 textureLevelHeight = texture2d->getHeight(level);
615 textureLevelDepth = 1;
616 texture = texture2d;
617 }
618 }
619 break;
620
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
627 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000628 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000629 {
630 return gl::error(GL_INVALID_VALUE, false);
631 }
632
633 if (width > (context->getMaximumCubeTextureDimension() >> level))
634 {
635 return gl::error(GL_INVALID_VALUE, false);
636 }
637
638 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
639 if (textureCube)
640 {
641 textureCompressed = textureCube->isCompressed(target, level);
642 textureInternalFormat = textureCube->getInternalFormat(target, level);
643 textureLevelWidth = textureCube->getWidth(target, level);
644 textureLevelHeight = textureCube->getHeight(target, level);
645 textureLevelDepth = 1;
646 texture = textureCube;
647 }
648 }
649 break;
650
651 case GL_TEXTURE_3D:
652 {
653 if (width > (context->getMaximum3DTextureDimension() >> level) ||
654 height > (context->getMaximum3DTextureDimension() >> level) ||
655 depth > (context->getMaximum3DTextureDimension() >> level))
656 {
657 return gl::error(GL_INVALID_VALUE, false);
658 }
659
660 gl::Texture3D *texture3d = context->getTexture3D();
661 if (texture3d)
662 {
663 textureCompressed = texture3d->isCompressed(level);
664 textureInternalFormat = texture3d->getInternalFormat(level);
665 textureLevelWidth = texture3d->getWidth(level);
666 textureLevelHeight = texture3d->getHeight(level);
667 textureLevelDepth = texture3d->getDepth(level);
668 texture = texture3d;
669 }
670 }
671 break;
672
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000673 case GL_TEXTURE_2D_ARRAY:
674 {
675 if (width > (context->getMaximum2DTextureDimension() >> level) ||
676 height > (context->getMaximum2DTextureDimension() >> level) ||
677 depth > (context->getMaximum2DArrayTextureLayers() >> level))
678 {
679 return gl::error(GL_INVALID_VALUE, false);
680 }
681
682 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
683 if (texture2darray)
684 {
685 textureCompressed = texture2darray->isCompressed(level);
686 textureInternalFormat = texture2darray->getInternalFormat(level);
687 textureLevelWidth = texture2darray->getWidth(level);
688 textureLevelHeight = texture2darray->getHeight(level);
689 textureLevelDepth = texture2darray->getDepth(level);
690 texture = texture2darray;
691 }
692 }
693 break;
694
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000695 default:
696 return gl::error(GL_INVALID_ENUM, false);
697 }
698
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000699 if (!texture)
700 {
701 return gl::error(GL_INVALID_OPERATION, false);
702 }
703
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000704 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000705 {
706 return gl::error(GL_INVALID_OPERATION, false);
707 }
708
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000709 // Validate texture formats
710 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
711 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000712 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000713 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000714 {
715 return gl::error(GL_INVALID_ENUM, false);
716 }
717
718 if (target == GL_TEXTURE_3D)
719 {
720 return gl::error(GL_INVALID_OPERATION, false);
721 }
722 }
723 else
724 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000725 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
726 !gl::IsValidFormat(format, context->getClientVersion()) ||
727 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000728 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000729 return gl::error(GL_INVALID_ENUM, false);
730 }
731
732 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
733 {
734 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000735 }
736
737 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
738 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000739 {
740 return gl::error(GL_INVALID_OPERATION, false);
741 }
742 }
743
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000744 // Validate sub image parameters
745 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000746 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000747 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000748 {
749 return gl::error(GL_INVALID_OPERATION, false);
750 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000751
752 if (format != GL_NONE)
753 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000754 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000755 if (internalformat != textureInternalFormat)
756 {
757 return gl::error(GL_INVALID_OPERATION, false);
758 }
759 }
760
761 if (isCompressed)
762 {
763 if ((width % 4 != 0 && width != textureLevelWidth) ||
764 (height % 4 != 0 && height != textureLevelHeight))
765 {
766 return gl::error(GL_INVALID_OPERATION, false);
767 }
768 }
769
770 if (width == 0 || height == 0 || depth == 0)
771 {
772 return false;
773 }
774
775 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
776 {
777 return gl::error(GL_INVALID_VALUE, false);
778 }
779
780 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
781 std::numeric_limits<GLsizei>::max() - yoffset < height ||
782 std::numeric_limits<GLsizei>::max() - zoffset < depth)
783 {
784 return gl::error(GL_INVALID_VALUE, false);
785 }
786
787 if (xoffset + width > textureLevelWidth ||
788 yoffset + height > textureLevelHeight ||
789 zoffset + depth > textureLevelDepth)
790 {
791 return gl::error(GL_INVALID_VALUE, false);
792 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000793 }
794
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000795 return true;
796}
797
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000798
799bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
800 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
801 GLint border)
802{
803 if (!gl::IsInternalTextureTarget(target))
804 {
805 return gl::error(GL_INVALID_ENUM, false);
806 }
807
808 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
809 {
810 return gl::error(GL_INVALID_VALUE, false);
811 }
812
813 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
814 {
815 return gl::error(GL_INVALID_VALUE, false);
816 }
817
818 if (width == 0 || height == 0)
819 {
820 return false;
821 }
822
823 // Verify zero border
824 if (border != 0)
825 {
826 return gl::error(GL_INVALID_VALUE, false);
827 }
828
829 // Validate dimensions based on Context limits and validate the texture
830 if (level > context->getMaximumTextureLevel())
831 {
832 return gl::error(GL_INVALID_VALUE, false);
833 }
834
835 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
836
837 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
838 {
839 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
840 }
841
842 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
843 {
844 return gl::error(GL_INVALID_OPERATION, false);
845 }
846
847 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
848 gl::Texture *texture = NULL;
849 GLenum textureFormat = GL_RGBA;
850
851 switch (target)
852 {
853 case GL_TEXTURE_2D:
854 {
855 if (width > (context->getMaximum2DTextureDimension() >> level) ||
856 height > (context->getMaximum2DTextureDimension() >> level))
857 {
858 return gl::error(GL_INVALID_VALUE, false);
859 }
860
861 gl::Texture2D *tex2d = context->getTexture2D();
862 if (tex2d)
863 {
864 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
865 {
866 return false; // error already registered by validateSubImageParams
867 }
868 texture = tex2d;
869 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
870 }
871 }
872 break;
873
874 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
875 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
876 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
878 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
879 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
880 {
881 if (!isSubImage && width != height)
882 {
883 return gl::error(GL_INVALID_VALUE, false);
884 }
885
886 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
887 height > (context->getMaximumCubeTextureDimension() >> level))
888 {
889 return gl::error(GL_INVALID_VALUE, false);
890 }
891
892 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
893 if (texcube)
894 {
895 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
896 {
897 return false; // error already registered by validateSubImageParams
898 }
899 texture = texcube;
900 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
901 }
902 }
903 break;
904
905 default:
906 return gl::error(GL_INVALID_ENUM, false);
907 }
908
909 if (!texture)
910 {
911 return gl::error(GL_INVALID_OPERATION, false);
912 }
913
914 if (texture->isImmutable() && !isSubImage)
915 {
916 return gl::error(GL_INVALID_OPERATION, false);
917 }
918
919
920 // [OpenGL ES 2.0.24] table 3.9
921 if (isSubImage)
922 {
923 switch (textureFormat)
924 {
925 case GL_ALPHA:
926 if (colorbufferFormat != GL_ALPHA8_EXT &&
927 colorbufferFormat != GL_RGBA4 &&
928 colorbufferFormat != GL_RGB5_A1 &&
929 colorbufferFormat != GL_RGBA8_OES)
930 {
931 return gl::error(GL_INVALID_OPERATION, false);
932 }
933 break;
934 case GL_LUMINANCE:
935 case GL_RGB:
936 if (colorbufferFormat != GL_RGB565 &&
937 colorbufferFormat != GL_RGB8_OES &&
938 colorbufferFormat != GL_RGBA4 &&
939 colorbufferFormat != GL_RGB5_A1 &&
940 colorbufferFormat != GL_RGBA8_OES)
941 {
942 return gl::error(GL_INVALID_OPERATION, false);
943 }
944 break;
945 case GL_LUMINANCE_ALPHA:
946 case GL_RGBA:
947 if (colorbufferFormat != GL_RGBA4 &&
948 colorbufferFormat != GL_RGB5_A1 &&
949 colorbufferFormat != GL_RGBA8_OES)
950 {
951 return gl::error(GL_INVALID_OPERATION, false);
952 }
953 break;
954 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
956 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
957 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
958 return gl::error(GL_INVALID_OPERATION, false);
959 case GL_DEPTH_COMPONENT:
960 case GL_DEPTH_STENCIL_OES:
961 return gl::error(GL_INVALID_OPERATION, false);
962 default:
963 return gl::error(GL_INVALID_OPERATION, false);
964 }
965 }
966 else
967 {
968 switch (internalformat)
969 {
970 case GL_ALPHA:
971 if (colorbufferFormat != GL_ALPHA8_EXT &&
972 colorbufferFormat != GL_RGBA4 &&
973 colorbufferFormat != GL_RGB5_A1 &&
974 colorbufferFormat != GL_BGRA8_EXT &&
975 colorbufferFormat != GL_RGBA8_OES)
976 {
977 return gl::error(GL_INVALID_OPERATION, false);
978 }
979 break;
980 case GL_LUMINANCE:
981 case GL_RGB:
982 if (colorbufferFormat != GL_RGB565 &&
983 colorbufferFormat != GL_RGB8_OES &&
984 colorbufferFormat != GL_RGBA4 &&
985 colorbufferFormat != GL_RGB5_A1 &&
986 colorbufferFormat != GL_BGRA8_EXT &&
987 colorbufferFormat != GL_RGBA8_OES)
988 {
989 return gl::error(GL_INVALID_OPERATION, false);
990 }
991 break;
992 case GL_LUMINANCE_ALPHA:
993 case GL_RGBA:
994 if (colorbufferFormat != GL_RGBA4 &&
995 colorbufferFormat != GL_RGB5_A1 &&
996 colorbufferFormat != GL_BGRA8_EXT &&
997 colorbufferFormat != GL_RGBA8_OES)
998 {
999 return gl::error(GL_INVALID_OPERATION, false);
1000 }
1001 break;
1002 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1003 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1004 if (context->supportsDXT1Textures())
1005 {
1006 return gl::error(GL_INVALID_OPERATION, false);
1007 }
1008 else
1009 {
1010 return gl::error(GL_INVALID_ENUM, false);
1011 }
1012 break;
1013 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1014 if (context->supportsDXT3Textures())
1015 {
1016 return gl::error(GL_INVALID_OPERATION, false);
1017 }
1018 else
1019 {
1020 return gl::error(GL_INVALID_ENUM, false);
1021 }
1022 break;
1023 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1024 if (context->supportsDXT5Textures())
1025 {
1026 return gl::error(GL_INVALID_OPERATION, false);
1027 }
1028 else
1029 {
1030 return gl::error(GL_INVALID_ENUM, false);
1031 }
1032 break;
1033 case GL_DEPTH_COMPONENT:
1034 case GL_DEPTH_COMPONENT16:
1035 case GL_DEPTH_COMPONENT32_OES:
1036 case GL_DEPTH_STENCIL_OES:
1037 case GL_DEPTH24_STENCIL8_OES:
1038 if (context->supportsDepthTextures())
1039 {
1040 return gl::error(GL_INVALID_OPERATION, false);
1041 }
1042 else
1043 {
1044 return gl::error(GL_INVALID_ENUM, false);
1045 }
1046 default:
1047 return gl::error(GL_INVALID_ENUM, false);
1048 }
1049 }
1050
1051 return true;
1052}
1053
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001054bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1055 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1056 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001057{
1058 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001059 {
1060 return gl::error(GL_INVALID_VALUE, false);
1061 }
1062
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001063 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1064 {
1065 return gl::error(GL_INVALID_VALUE, false);
1066 }
1067
1068 if (width == 0 || height == 0)
1069 {
1070 return false;
1071 }
1072
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001073 if (border != 0)
1074 {
1075 return gl::error(GL_INVALID_VALUE, false);
1076 }
1077
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001078 if (level > context->getMaximumTextureLevel())
1079 {
1080 return gl::error(GL_INVALID_VALUE, false);
1081 }
1082
1083 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1084
1085 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1086 {
1087 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1088 }
1089
1090 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1091 {
1092 return gl::error(GL_INVALID_OPERATION, false);
1093 }
1094
1095 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001096 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001097 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001098 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001099 bool textureCompressed = false;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001100 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001101 GLint textureLevelWidth = 0;
1102 GLint textureLevelHeight = 0;
1103 GLint textureLevelDepth = 0;
1104 switch (target)
1105 {
1106 case GL_TEXTURE_2D:
1107 {
1108 gl::Texture2D *texture2d = context->getTexture2D();
1109 if (texture2d)
1110 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001111 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001112 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001113 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001114 textureLevelWidth = texture2d->getWidth(level);
1115 textureLevelHeight = texture2d->getHeight(level);
1116 textureLevelDepth = 1;
1117 texture = texture2d;
1118 }
1119 }
1120 break;
1121
1122 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1124 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1126 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1127 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1128 {
1129 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1130 if (textureCube)
1131 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001132 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001133 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001134 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001135 textureLevelWidth = textureCube->getWidth(target, level);
1136 textureLevelHeight = textureCube->getHeight(target, level);
1137 textureLevelDepth = 1;
1138 texture = textureCube;
1139 }
1140 }
1141 break;
1142
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001143 case GL_TEXTURE_2D_ARRAY:
1144 {
1145 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1146 if (texture2dArray)
1147 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001148 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001149 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001150 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001151 textureLevelWidth = texture2dArray->getWidth(level);
1152 textureLevelHeight = texture2dArray->getHeight(level);
1153 textureLevelDepth = texture2dArray->getDepth(level);
1154 texture = texture2dArray;
1155 }
1156 }
1157 break;
1158
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001159 case GL_TEXTURE_3D:
1160 {
1161 gl::Texture3D *texture3d = context->getTexture3D();
1162 if (texture3d)
1163 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001164 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001165 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001166 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001167 textureLevelWidth = texture3d->getWidth(level);
1168 textureLevelHeight = texture3d->getHeight(level);
1169 textureLevelDepth = texture3d->getDepth(level);
1170 texture = texture3d;
1171 }
1172 }
1173 break;
1174
1175 default:
1176 return gl::error(GL_INVALID_ENUM, false);
1177 }
1178
1179 if (!texture)
1180 {
1181 return gl::error(GL_INVALID_OPERATION, false);
1182 }
1183
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001184 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001185 {
1186 return gl::error(GL_INVALID_OPERATION, false);
1187 }
1188
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001189 if (textureIsDepth)
1190 {
1191 return gl::error(GL_INVALID_OPERATION, false);
1192 }
1193
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001194 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001195 {
1196 if ((width % 4 != 0 && width != textureLevelWidth) ||
1197 (height % 4 != 0 && height != textureLevelHeight))
1198 {
1199 return gl::error(GL_INVALID_OPERATION, false);
1200 }
1201 }
1202
Geoff Langa4d13322013-06-05 14:57:51 -04001203 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001204 {
Geoff Langa4d13322013-06-05 14:57:51 -04001205 if (xoffset + width > textureLevelWidth ||
1206 yoffset + height > textureLevelHeight ||
1207 zoffset >= textureLevelDepth)
1208 {
1209 return gl::error(GL_INVALID_VALUE, false);
1210 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001211
Geoff Langa4d13322013-06-05 14:57:51 -04001212 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1213 context->getClientVersion()))
1214 {
1215 return gl::error(GL_INVALID_OPERATION, false);
1216 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001217 }
1218
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001219 return true;
1220}
1221
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001222bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1223 GLsizei width, GLsizei height)
1224{
1225 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1226 {
1227 return gl::error(GL_INVALID_ENUM, false);
1228 }
1229
1230 if (width < 1 || height < 1 || levels < 1)
1231 {
1232 return gl::error(GL_INVALID_VALUE, false);
1233 }
1234
1235 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1236 {
1237 return gl::error(GL_INVALID_VALUE, false);
1238 }
1239
1240 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1241 {
1242 return gl::error(GL_INVALID_OPERATION, false);
1243 }
1244
1245 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1246 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1247
1248 if (format == GL_NONE || type == GL_NONE)
1249 {
1250 return gl::error(GL_INVALID_ENUM, false);
1251 }
1252
1253 switch (target)
1254 {
1255 case GL_TEXTURE_2D:
1256 if (width > context->getMaximum2DTextureDimension() ||
1257 height > context->getMaximum2DTextureDimension())
1258 {
1259 return gl::error(GL_INVALID_VALUE, false);
1260 }
1261 break;
1262 case GL_TEXTURE_CUBE_MAP:
1263 if (width > context->getMaximumCubeTextureDimension() ||
1264 height > context->getMaximumCubeTextureDimension())
1265 {
1266 return gl::error(GL_INVALID_VALUE, false);
1267 }
1268 break;
1269 default:
1270 return gl::error(GL_INVALID_ENUM, false);
1271 }
1272
1273 if (levels != 1 && !context->supportsNonPower2Texture())
1274 {
1275 if (!gl::isPow2(width) || !gl::isPow2(height))
1276 {
1277 return gl::error(GL_INVALID_OPERATION, false);
1278 }
1279 }
1280
1281 switch (internalformat)
1282 {
1283 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1284 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1285 if (!context->supportsDXT1Textures())
1286 {
1287 return gl::error(GL_INVALID_ENUM, false);
1288 }
1289 break;
1290 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1291 if (!context->supportsDXT3Textures())
1292 {
1293 return gl::error(GL_INVALID_ENUM, false);
1294 }
1295 break;
1296 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1297 if (!context->supportsDXT5Textures())
1298 {
1299 return gl::error(GL_INVALID_ENUM, false);
1300 }
1301 break;
1302 case GL_RGBA32F_EXT:
1303 case GL_RGB32F_EXT:
1304 case GL_ALPHA32F_EXT:
1305 case GL_LUMINANCE32F_EXT:
1306 case GL_LUMINANCE_ALPHA32F_EXT:
1307 if (!context->supportsFloat32Textures())
1308 {
1309 return gl::error(GL_INVALID_ENUM, false);
1310 }
1311 break;
1312 case GL_RGBA16F_EXT:
1313 case GL_RGB16F_EXT:
1314 case GL_ALPHA16F_EXT:
1315 case GL_LUMINANCE16F_EXT:
1316 case GL_LUMINANCE_ALPHA16F_EXT:
1317 if (!context->supportsFloat16Textures())
1318 {
1319 return gl::error(GL_INVALID_ENUM, false);
1320 }
1321 break;
1322 case GL_DEPTH_COMPONENT16:
1323 case GL_DEPTH_COMPONENT32_OES:
1324 case GL_DEPTH24_STENCIL8_OES:
1325 if (!context->supportsDepthTextures())
1326 {
1327 return gl::error(GL_INVALID_ENUM, false);
1328 }
1329 if (target != GL_TEXTURE_2D)
1330 {
1331 return gl::error(GL_INVALID_OPERATION, false);
1332 }
1333 // ANGLE_depth_texture only supports 1-level textures
1334 if (levels != 1)
1335 {
1336 return gl::error(GL_INVALID_OPERATION, false);
1337 }
1338 break;
1339 default:
1340 break;
1341 }
1342
1343 gl::Texture *texture = NULL;
1344 switch(target)
1345 {
1346 case GL_TEXTURE_2D:
1347 texture = context->getTexture2D();
1348 break;
1349 case GL_TEXTURE_CUBE_MAP:
1350 texture = context->getTextureCubeMap();
1351 break;
1352 default:
1353 UNREACHABLE();
1354 }
1355
1356 if (!texture || texture->id() == 0)
1357 {
1358 return gl::error(GL_INVALID_OPERATION, false);
1359 }
1360
1361 if (texture->isImmutable())
1362 {
1363 return gl::error(GL_INVALID_OPERATION, false);
1364 }
1365
1366 return true;
1367}
1368
1369bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1370 GLsizei width, GLsizei height, GLsizei depth)
1371{
1372 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1373 {
1374 return gl::error(GL_INVALID_VALUE, false);
1375 }
1376
1377 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1378 {
1379 return gl::error(GL_INVALID_OPERATION, false);
1380 }
1381
1382 gl::Texture *texture = NULL;
1383 switch (target)
1384 {
1385 case GL_TEXTURE_2D:
1386 {
1387 texture = context->getTexture2D();
1388
1389 if (width > (context->getMaximum2DTextureDimension()) ||
1390 height > (context->getMaximum2DTextureDimension()))
1391 {
1392 return gl::error(GL_INVALID_VALUE, false);
1393 }
1394 }
1395 break;
1396
1397 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1399 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1401 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1402 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1403 {
1404 texture = context->getTextureCubeMap();
1405
1406 if (width != height)
1407 {
1408 return gl::error(GL_INVALID_VALUE, false);
1409 }
1410
1411 if (width > (context->getMaximumCubeTextureDimension()))
1412 {
1413 return gl::error(GL_INVALID_VALUE, false);
1414 }
1415 }
1416 break;
1417
1418 case GL_TEXTURE_3D:
1419 {
1420 texture = context->getTexture3D();
1421
1422 if (width > (context->getMaximum3DTextureDimension()) ||
1423 height > (context->getMaximum3DTextureDimension()) ||
1424 depth > (context->getMaximum3DTextureDimension()))
1425 {
1426 return gl::error(GL_INVALID_VALUE, false);
1427 }
1428 }
1429 break;
1430
1431 case GL_TEXTURE_2D_ARRAY:
1432 {
1433 texture = context->getTexture2DArray();
1434
1435 if (width > (context->getMaximum2DTextureDimension()) ||
1436 height > (context->getMaximum2DTextureDimension()) ||
1437 depth > (context->getMaximum2DArrayTextureLayers()))
1438 {
1439 return gl::error(GL_INVALID_VALUE, false);
1440 }
1441 }
1442 break;
1443
1444 default:
1445 return gl::error(GL_INVALID_ENUM, false);
1446 }
1447
1448 if (!texture || texture->id() == 0)
1449 {
1450 return gl::error(GL_INVALID_OPERATION, false);
1451 }
1452
1453 if (texture->isImmutable())
1454 {
1455 return gl::error(GL_INVALID_OPERATION, false);
1456 }
1457
1458 if (!gl::IsValidInternalFormat(internalformat, context))
1459 {
1460 return gl::error(GL_INVALID_ENUM, false);
1461 }
1462
1463 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1464 {
1465 return gl::error(GL_INVALID_ENUM, false);
1466 }
1467
1468 return true;
1469}
1470
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001471bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1472 GLenum internalformat, GLsizei width, GLsizei height,
1473 bool angleExtension)
1474{
1475 switch (target)
1476 {
1477 case GL_RENDERBUFFER:
1478 break;
1479 default:
1480 return gl::error(GL_INVALID_ENUM, false);
1481 }
1482
1483 if (width < 0 || height < 0 || samples < 0)
1484 {
1485 return gl::error(GL_INVALID_VALUE, false);
1486 }
1487
1488 if (!gl::IsValidInternalFormat(internalformat, context))
1489 {
1490 return gl::error(GL_INVALID_ENUM, false);
1491 }
1492
1493 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1494 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1495 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1496 // internal format must be sized and not an integer format if samples is greater than zero.
1497 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1498 {
1499 return gl::error(GL_INVALID_ENUM, false);
1500 }
1501
1502 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1503 {
1504 return gl::error(GL_INVALID_OPERATION, false);
1505 }
1506
1507 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1508 !gl::IsDepthRenderingSupported(internalformat, context) &&
1509 !gl::IsStencilRenderingSupported(internalformat, context))
1510 {
1511 return gl::error(GL_INVALID_ENUM, false);
1512 }
1513
1514 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1515 {
1516 return gl::error(GL_INVALID_VALUE, false);
1517 }
1518
1519 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1520 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1521 // states that samples must be less than or equal to the maximum samples for the specified
1522 // internal format.
1523 if (angleExtension)
1524 {
1525 if (samples > context->getMaxSupportedSamples())
1526 {
1527 return gl::error(GL_INVALID_VALUE, false);
1528 }
1529 }
1530 else
1531 {
1532 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1533 {
1534 return gl::error(GL_INVALID_VALUE, false);
1535 }
1536 }
1537
1538 GLuint handle = context->getRenderbufferHandle();
1539 if (handle == 0)
1540 {
1541 return gl::error(GL_INVALID_OPERATION, false);
1542 }
1543
1544 return true;
1545}
1546
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001547// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001548bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001549{
1550 switch (format)
1551 {
1552 case GL_RGBA:
1553 switch (type)
1554 {
1555 case GL_UNSIGNED_BYTE:
1556 break;
1557 default:
1558 return false;
1559 }
1560 break;
1561 case GL_BGRA_EXT:
1562 switch (type)
1563 {
1564 case GL_UNSIGNED_BYTE:
1565 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1566 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1567 break;
1568 default:
1569 return false;
1570 }
1571 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001572 default:
1573 return false;
1574 }
1575 return true;
1576}
1577
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001578bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1579{
1580 switch (format)
1581 {
1582 case GL_RGBA:
1583 switch (type)
1584 {
1585 case GL_UNSIGNED_BYTE:
1586 break;
1587 case GL_UNSIGNED_INT_2_10_10_10_REV:
1588 if (internalFormat != GL_RGB10_A2)
1589 {
1590 return false;
1591 }
1592 break;
1593 default:
1594 return false;
1595 }
1596 break;
1597 case GL_RGBA_INTEGER:
1598 switch (type)
1599 {
1600 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001601 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1602 {
1603 return false;
1604 }
1605 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001606 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001607 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1608 {
1609 return false;
1610 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001611 break;
1612 default:
1613 return false;
1614 }
1615 break;
1616 case GL_BGRA_EXT:
1617 switch (type)
1618 {
1619 case GL_UNSIGNED_BYTE:
1620 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1621 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1622 break;
1623 default:
1624 return false;
1625 }
1626 break;
1627 default:
1628 return false;
1629 }
1630 return true;
1631}
1632
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001633bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1634 const GLenum* attachments)
1635{
1636 bool defaultFramebuffer = false;
1637
1638 switch (target)
1639 {
1640 case GL_DRAW_FRAMEBUFFER:
1641 case GL_FRAMEBUFFER:
1642 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1643 break;
1644 case GL_READ_FRAMEBUFFER:
1645 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1646 break;
1647 default:
1648 return gl::error(GL_INVALID_ENUM, false);
1649 }
1650
1651 for (int i = 0; i < numAttachments; ++i)
1652 {
1653 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1654 {
1655 if (defaultFramebuffer)
1656 {
1657 return gl::error(GL_INVALID_ENUM, false);
1658 }
1659
1660 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1661 {
1662 return gl::error(GL_INVALID_OPERATION, false);
1663 }
1664 }
1665 else
1666 {
1667 switch (attachments[i])
1668 {
1669 case GL_DEPTH_ATTACHMENT:
1670 case GL_STENCIL_ATTACHMENT:
1671 case GL_DEPTH_STENCIL_ATTACHMENT:
1672 if (defaultFramebuffer)
1673 {
1674 return gl::error(GL_INVALID_ENUM, false);
1675 }
1676 break;
1677 case GL_COLOR:
1678 case GL_DEPTH:
1679 case GL_STENCIL:
1680 if (!defaultFramebuffer)
1681 {
1682 return gl::error(GL_INVALID_ENUM, false);
1683 }
1684 break;
1685 default:
1686 return gl::error(GL_INVALID_ENUM, false);
1687 }
1688 }
1689 }
1690
1691 return true;
1692}
1693
Geoff Lang758d5b22013-06-11 11:42:50 -04001694bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1695 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1696 GLenum filter, bool fromAngleExtension)
1697{
1698 switch (filter)
1699 {
1700 case GL_NEAREST:
1701 break;
1702 case GL_LINEAR:
1703 if (fromAngleExtension)
1704 {
1705 return gl::error(GL_INVALID_ENUM, false);
1706 }
1707 break;
1708 default:
1709 return gl::error(GL_INVALID_ENUM, false);
1710 }
1711
1712 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1713 {
1714 return gl::error(GL_INVALID_VALUE, false);
1715 }
1716
1717 if (mask == 0)
1718 {
1719 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1720 // buffers are copied.
1721 return false;
1722 }
1723
1724 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
1725 {
1726 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
1727 return gl::error(GL_INVALID_OPERATION, false);
1728 }
1729
1730 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
1731 // color buffer, leaving only nearest being unfiltered from above
1732 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
1733 {
1734 return gl::error(GL_INVALID_OPERATION, false);
1735 }
1736
1737 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
1738 {
1739 if (fromAngleExtension)
1740 {
1741 ERR("Blits with the same source and destination framebuffer are not supported by this "
1742 "implementation.");
1743 }
1744 return gl::error(GL_INVALID_OPERATION, false);
1745 }
1746
1747 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
1748 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
1749 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
1750 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1751 {
1752 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1753 }
1754
1755 if (drawFramebuffer->getSamples() != 0)
1756 {
1757 return gl::error(GL_INVALID_OPERATION, false);
1758 }
1759
1760 gl::Rectangle sourceClippedRect, destClippedRect;
1761 bool partialCopy;
1762 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
1763 &sourceClippedRect, &destClippedRect, &partialCopy))
1764 {
1765 return gl::error(GL_INVALID_OPERATION, false);
1766 }
1767
1768 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
1769
1770 GLuint clientVersion = context->getClientVersion();
1771
1772 if (mask & GL_COLOR_BUFFER_BIT)
1773 {
1774 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
1775 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
1776
1777 if (readColorBuffer && drawColorBuffer)
1778 {
1779 GLint readInternalFormat = readColorBuffer->getActualFormat();
1780 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
1781
1782 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
1783 {
1784 if (drawFramebuffer->isEnabledColorAttachment(i))
1785 {
1786 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
1787
1788 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
1789 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
1790 {
1791 return gl::error(GL_INVALID_OPERATION, false);
1792 }
1793
1794 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
1795 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1796 {
1797 return gl::error(GL_INVALID_OPERATION, false);
1798 }
1799
1800 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
1801 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1802 {
1803 return gl::error(GL_INVALID_OPERATION, false);
1804 }
1805
1806 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
1807 {
1808 return gl::error(GL_INVALID_OPERATION, false);
1809 }
1810 }
1811 }
1812
1813 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
1814 {
1815 return gl::error(GL_INVALID_OPERATION, false);
1816 }
1817
1818 if (fromAngleExtension)
1819 {
1820 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
1821 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
1822 {
1823 return gl::error(GL_INVALID_OPERATION, false);
1824 }
1825
1826 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
1827 {
1828 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
1829 {
1830 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
1831 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
1832 {
1833 return gl::error(GL_INVALID_OPERATION, false);
1834 }
1835
1836 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
1837 {
1838 return gl::error(GL_INVALID_OPERATION, false);
1839 }
1840 }
1841 }
1842
1843 if (partialCopy && readFramebuffer->getSamples() != 0)
1844 {
1845 return gl::error(GL_INVALID_OPERATION, false);
1846 }
1847 }
1848 }
1849 }
1850
1851 if (mask & GL_DEPTH_BUFFER_BIT)
1852 {
1853 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
1854 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
1855
1856 if (readDepthBuffer && drawDepthBuffer)
1857 {
1858 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
1859 {
1860 return gl::error(GL_INVALID_OPERATION, false);
1861 }
1862
1863 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
1864 {
1865 return gl::error(GL_INVALID_OPERATION, false);
1866 }
1867
1868 if (fromAngleExtension)
1869 {
1870 if (partialCopy)
1871 {
1872 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1873 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1874 }
1875
1876 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
1877 {
1878 return gl::error(GL_INVALID_OPERATION, false);
1879 }
1880 }
1881 }
1882 }
1883
1884 if (mask & GL_STENCIL_BUFFER_BIT)
1885 {
1886 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
1887 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
1888
1889 if (fromAngleExtension && partialCopy)
1890 {
1891 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1892 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1893 }
1894
1895 if (readStencilBuffer && drawStencilBuffer)
1896 {
1897 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
1898 {
1899 return gl::error(GL_INVALID_OPERATION, false);
1900 }
1901
1902 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
1903 {
1904 return gl::error(GL_INVALID_OPERATION, false);
1905 }
1906
1907 if (fromAngleExtension)
1908 {
1909 if (partialCopy)
1910 {
1911 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1912 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1913 }
1914
1915 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
1916 {
1917 return gl::error(GL_INVALID_OPERATION, false);
1918 }
1919 }
1920 }
1921 }
1922
1923 return true;
1924}
1925
Jamie Madillaff71502013-07-02 11:57:05 -04001926bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
1927{
1928 switch (pname)
1929 {
1930 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1931 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1932 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1933 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1934 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1935 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1936 case GL_CURRENT_VERTEX_ATTRIB:
1937 return true;
1938
1939 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
1940 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
1941 // the same constant.
1942 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
1943 return true;
1944
Jamie Madill30855b32013-07-02 11:57:06 -04001945 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1946 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
1947
Jamie Madillaff71502013-07-02 11:57:05 -04001948 default:
1949 return gl::error(GL_INVALID_ENUM, false);
1950 }
1951}
1952
Jamie Madill478fdb22013-07-19 16:36:59 -04001953bool validateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
1954{
1955 switch (pname)
1956 {
1957 case GL_TEXTURE_WRAP_R:
1958 case GL_TEXTURE_SWIZZLE_R:
1959 case GL_TEXTURE_SWIZZLE_G:
1960 case GL_TEXTURE_SWIZZLE_B:
1961 case GL_TEXTURE_SWIZZLE_A:
1962 case GL_TEXTURE_BASE_LEVEL:
1963 case GL_TEXTURE_MAX_LEVEL:
1964 case GL_TEXTURE_COMPARE_MODE:
1965 case GL_TEXTURE_COMPARE_FUNC:
1966 case GL_TEXTURE_MIN_LOD:
1967 case GL_TEXTURE_MAX_LOD:
1968 if (context->getClientVersion() < 3)
1969 {
1970 return gl::error(GL_INVALID_ENUM, false);
1971 }
1972 break;
1973
1974 default: break;
1975 }
1976
1977 switch (pname)
1978 {
1979 case GL_TEXTURE_WRAP_S:
1980 case GL_TEXTURE_WRAP_T:
1981 case GL_TEXTURE_WRAP_R:
1982 switch (param)
1983 {
1984 case GL_REPEAT:
1985 case GL_CLAMP_TO_EDGE:
1986 case GL_MIRRORED_REPEAT:
1987 return true;
1988 default:
1989 return gl::error(GL_INVALID_ENUM, false);
1990 }
1991
1992 case GL_TEXTURE_MIN_FILTER:
1993 switch (param)
1994 {
1995 case GL_NEAREST:
1996 case GL_LINEAR:
1997 case GL_NEAREST_MIPMAP_NEAREST:
1998 case GL_LINEAR_MIPMAP_NEAREST:
1999 case GL_NEAREST_MIPMAP_LINEAR:
2000 case GL_LINEAR_MIPMAP_LINEAR:
2001 return true;
2002 default:
2003 return gl::error(GL_INVALID_ENUM, false);
2004 }
2005 break;
2006
2007 case GL_TEXTURE_MAG_FILTER:
2008 switch (param)
2009 {
2010 case GL_NEAREST:
2011 case GL_LINEAR:
2012 return true;
2013 default:
2014 return gl::error(GL_INVALID_ENUM, false);
2015 }
2016 break;
2017
2018 case GL_TEXTURE_USAGE_ANGLE:
2019 switch (param)
2020 {
2021 case GL_NONE:
2022 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
2023 return true;
2024 default:
2025 return gl::error(GL_INVALID_ENUM, false);
2026 }
2027 break;
2028
2029 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2030 if (!context->supportsTextureFilterAnisotropy())
2031 {
2032 return gl::error(GL_INVALID_ENUM, false);
2033 }
2034
2035 // we assume the parameter passed to this validation method is truncated, not rounded
2036 if (param < 1)
2037 {
2038 return gl::error(GL_INVALID_VALUE, false);
2039 }
2040 return true;
2041
2042 case GL_TEXTURE_MIN_LOD:
2043 case GL_TEXTURE_MAX_LOD:
2044 // any value is permissible
2045 return true;
2046
2047 case GL_TEXTURE_COMPARE_MODE:
2048 switch (param)
2049 {
2050 case GL_NONE:
2051 case GL_COMPARE_REF_TO_TEXTURE:
2052 return true;
2053 default:
2054 return gl::error(GL_INVALID_ENUM, false);
2055 }
2056 break;
2057
2058 case GL_TEXTURE_COMPARE_FUNC:
2059 switch (param)
2060 {
2061 case GL_LEQUAL:
2062 case GL_GEQUAL:
2063 case GL_LESS:
2064 case GL_GREATER:
2065 case GL_EQUAL:
2066 case GL_NOTEQUAL:
2067 case GL_ALWAYS:
2068 case GL_NEVER:
2069 return true;
2070 default:
2071 return gl::error(GL_INVALID_ENUM, false);
2072 }
2073 break;
2074
2075 case GL_TEXTURE_SWIZZLE_R:
2076 case GL_TEXTURE_SWIZZLE_G:
2077 case GL_TEXTURE_SWIZZLE_B:
2078 case GL_TEXTURE_SWIZZLE_A:
2079 case GL_TEXTURE_BASE_LEVEL:
2080 case GL_TEXTURE_MAX_LEVEL:
2081 UNIMPLEMENTED();
2082 return true;
2083
2084 default:
2085 return gl::error(GL_INVALID_ENUM, false);
2086 }
2087}
2088
2089
Jamie Madillfb8a8302013-07-03 14:24:12 -04002090gl::Texture *getTargetTexture(gl::Context *context, GLenum target)
2091{
2092 if (context->getClientVersion() < 3)
2093 {
2094 if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
2095 {
2096 return NULL;
2097 }
2098 }
2099
2100 switch (target)
2101 {
2102 case GL_TEXTURE_2D: return context->getTexture2D();
2103 case GL_TEXTURE_CUBE_MAP: return context->getTextureCubeMap();
2104 case GL_TEXTURE_3D: return context->getTexture3D();
2105 case GL_TEXTURE_2D_ARRAY: return context->getTexture2DArray();
2106 default: return NULL;
2107 }
2108}
Jamie Madill478fdb22013-07-19 16:36:59 -04002109
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04002110bool validateSamplerObjectParameter(GLenum pname)
2111{
2112 switch (pname)
2113 {
2114 case GL_TEXTURE_MIN_FILTER:
2115 case GL_TEXTURE_MAG_FILTER:
2116 case GL_TEXTURE_WRAP_S:
2117 case GL_TEXTURE_WRAP_T:
2118 case GL_TEXTURE_WRAP_R:
2119 case GL_TEXTURE_MIN_LOD:
2120 case GL_TEXTURE_MAX_LOD:
2121 case GL_TEXTURE_COMPARE_MODE:
2122 case GL_TEXTURE_COMPARE_FUNC:
2123 return true;
2124
2125 default:
2126 return gl::error(GL_INVALID_ENUM, false);
2127 }
2128}
2129
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002130extern "C"
2131{
2132
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002133// OpenGL ES 2.0 functions
2134
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002135void __stdcall glActiveTexture(GLenum texture)
2136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002137 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138
2139 try
2140 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002141 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002142
2143 if (context)
2144 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002145 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002147 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002148 }
2149
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002150 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151 }
2152 }
2153 catch(std::bad_alloc&)
2154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002155 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002156 }
2157}
2158
2159void __stdcall glAttachShader(GLuint program, GLuint shader)
2160{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002161 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002162
2163 try
2164 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002165 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166
2167 if (context)
2168 {
2169 gl::Program *programObject = context->getProgram(program);
2170 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002171
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002172 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002173 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002174 if (context->getShader(program))
2175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002176 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002177 }
2178 else
2179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002180 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002181 }
2182 }
2183
2184 if (!shaderObject)
2185 {
2186 if (context->getProgram(shader))
2187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002188 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002189 }
2190 else
2191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002192 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002193 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002194 }
2195
2196 if (!programObject->attachShader(shaderObject))
2197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002198 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002199 }
2200 }
2201 }
2202 catch(std::bad_alloc&)
2203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002204 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002205 }
2206}
2207
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002208void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2209{
2210 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2211
2212 try
2213 {
2214 switch (target)
2215 {
2216 case GL_ANY_SAMPLES_PASSED_EXT:
2217 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2218 break;
2219 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002221 }
2222
2223 if (id == 0)
2224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002225 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002226 }
2227
2228 gl::Context *context = gl::getNonLostContext();
2229
2230 if (context)
2231 {
2232 context->beginQuery(target, id);
2233 }
2234 }
2235 catch(std::bad_alloc&)
2236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002237 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002238 }
2239}
2240
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002241void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002242{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002243 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002244
2245 try
2246 {
2247 if (index >= gl::MAX_VERTEX_ATTRIBS)
2248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002249 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002250 }
2251
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002252 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002253
2254 if (context)
2255 {
2256 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002257
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002258 if (!programObject)
2259 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002260 if (context->getShader(program))
2261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002262 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002263 }
2264 else
2265 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002266 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002267 }
2268 }
2269
2270 if (strncmp(name, "gl_", 3) == 0)
2271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002272 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002273 }
2274
2275 programObject->bindAttributeLocation(index, name);
2276 }
2277 }
2278 catch(std::bad_alloc&)
2279 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002280 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002281 }
2282}
2283
2284void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2285{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002286 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287
2288 try
2289 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002290 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002291
2292 if (context)
2293 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002294 // Check ES3 specific targets
2295 switch (target)
2296 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002297 case GL_COPY_READ_BUFFER:
2298 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002299 case GL_PIXEL_PACK_BUFFER:
2300 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002301 case GL_UNIFORM_BUFFER:
2302 case GL_TRANSFORM_FEEDBACK_BUFFER:
2303 if (context->getClientVersion() < 3)
2304 {
2305 return gl::error(GL_INVALID_ENUM);
2306 }
2307 }
2308
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002309 switch (target)
2310 {
2311 case GL_ARRAY_BUFFER:
2312 context->bindArrayBuffer(buffer);
2313 return;
2314 case GL_ELEMENT_ARRAY_BUFFER:
2315 context->bindElementArrayBuffer(buffer);
2316 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002317 case GL_COPY_READ_BUFFER:
2318 context->bindCopyReadBuffer(buffer);
2319 return;
2320 case GL_COPY_WRITE_BUFFER:
2321 context->bindCopyWriteBuffer(buffer);
2322 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002323 case GL_PIXEL_PACK_BUFFER:
2324 context->bindPixelPackBuffer(buffer);
2325 return;
2326 case GL_PIXEL_UNPACK_BUFFER:
2327 context->bindPixelUnpackBuffer(buffer);
2328 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002329 case GL_UNIFORM_BUFFER:
2330 context->bindGenericUniformBuffer(buffer);
2331 return;
2332 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002333 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002335 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002336 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337 }
2338 }
2339 }
2340 catch(std::bad_alloc&)
2341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002342 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002343 }
2344}
2345
2346void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2347{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002348 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349
2350 try
2351 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002352 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002354 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002355 }
2356
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002357 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002358
2359 if (context)
2360 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002361 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2362 {
2363 context->bindReadFramebuffer(framebuffer);
2364 }
2365
2366 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2367 {
2368 context->bindDrawFramebuffer(framebuffer);
2369 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002370 }
2371 }
2372 catch(std::bad_alloc&)
2373 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002374 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002375 }
2376}
2377
2378void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002380 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002381
2382 try
2383 {
2384 if (target != GL_RENDERBUFFER)
2385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002386 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002387 }
2388
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002389 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002390
2391 if (context)
2392 {
2393 context->bindRenderbuffer(renderbuffer);
2394 }
2395 }
2396 catch(std::bad_alloc&)
2397 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002398 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002399 }
2400}
2401
2402void __stdcall glBindTexture(GLenum target, GLuint texture)
2403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002404 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002405
2406 try
2407 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002408 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002409
2410 if (context)
2411 {
2412 gl::Texture *textureObject = context->getTexture(texture);
2413
2414 if (textureObject && textureObject->getTarget() != target && texture != 0)
2415 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002416 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417 }
2418
2419 switch (target)
2420 {
2421 case GL_TEXTURE_2D:
2422 context->bindTexture2D(texture);
2423 return;
2424 case GL_TEXTURE_CUBE_MAP:
2425 context->bindTextureCubeMap(texture);
2426 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002427 case GL_TEXTURE_3D:
2428 if (context->getClientVersion() < 3)
2429 {
2430 return gl::error(GL_INVALID_ENUM);
2431 }
2432 context->bindTexture3D(texture);
2433 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002434 case GL_TEXTURE_2D_ARRAY:
2435 if (context->getClientVersion() < 3)
2436 {
2437 return gl::error(GL_INVALID_ENUM);
2438 }
2439 context->bindTexture2DArray(texture);
2440 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002442 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444 }
2445 }
2446 catch(std::bad_alloc&)
2447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 }
2450}
2451
2452void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002454 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002455 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002456
2457 try
2458 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002459 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460
2461 if (context)
2462 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002463 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002464 }
2465 }
2466 catch(std::bad_alloc&)
2467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 }
2470}
2471
2472void __stdcall glBlendEquation(GLenum mode)
2473{
2474 glBlendEquationSeparate(mode, mode);
2475}
2476
2477void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002479 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480
2481 try
2482 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002483 gl::Context *context = gl::getNonLostContext();
2484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002485 switch (modeRGB)
2486 {
2487 case GL_FUNC_ADD:
2488 case GL_FUNC_SUBTRACT:
2489 case GL_FUNC_REVERSE_SUBTRACT:
2490 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002491
2492 case GL_MIN:
2493 case GL_MAX:
2494 if (context && context->getClientVersion() < 3)
2495 {
2496 return gl::error(GL_INVALID_ENUM);
2497 }
2498 break;
2499
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002501 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002502 }
2503
2504 switch (modeAlpha)
2505 {
2506 case GL_FUNC_ADD:
2507 case GL_FUNC_SUBTRACT:
2508 case GL_FUNC_REVERSE_SUBTRACT:
2509 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002510
2511 case GL_MIN:
2512 case GL_MAX:
2513 if (context && context->getClientVersion() < 3)
2514 {
2515 return gl::error(GL_INVALID_ENUM);
2516 }
2517 break;
2518
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002519 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002520 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002521 }
2522
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002523 if (context)
2524 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002525 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002526 }
2527 }
2528 catch(std::bad_alloc&)
2529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531 }
2532}
2533
2534void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2535{
2536 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2537}
2538
2539void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2540{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002541 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 +00002542 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002543
2544 try
2545 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002546 gl::Context *context = gl::getNonLostContext();
2547
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 switch (srcRGB)
2549 {
2550 case GL_ZERO:
2551 case GL_ONE:
2552 case GL_SRC_COLOR:
2553 case GL_ONE_MINUS_SRC_COLOR:
2554 case GL_DST_COLOR:
2555 case GL_ONE_MINUS_DST_COLOR:
2556 case GL_SRC_ALPHA:
2557 case GL_ONE_MINUS_SRC_ALPHA:
2558 case GL_DST_ALPHA:
2559 case GL_ONE_MINUS_DST_ALPHA:
2560 case GL_CONSTANT_COLOR:
2561 case GL_ONE_MINUS_CONSTANT_COLOR:
2562 case GL_CONSTANT_ALPHA:
2563 case GL_ONE_MINUS_CONSTANT_ALPHA:
2564 case GL_SRC_ALPHA_SATURATE:
2565 break;
2566 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002567 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002568 }
2569
2570 switch (dstRGB)
2571 {
2572 case GL_ZERO:
2573 case GL_ONE:
2574 case GL_SRC_COLOR:
2575 case GL_ONE_MINUS_SRC_COLOR:
2576 case GL_DST_COLOR:
2577 case GL_ONE_MINUS_DST_COLOR:
2578 case GL_SRC_ALPHA:
2579 case GL_ONE_MINUS_SRC_ALPHA:
2580 case GL_DST_ALPHA:
2581 case GL_ONE_MINUS_DST_ALPHA:
2582 case GL_CONSTANT_COLOR:
2583 case GL_ONE_MINUS_CONSTANT_COLOR:
2584 case GL_CONSTANT_ALPHA:
2585 case GL_ONE_MINUS_CONSTANT_ALPHA:
2586 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002587
2588 case GL_SRC_ALPHA_SATURATE:
2589 if (!context || context->getClientVersion() < 3)
2590 {
2591 return gl::error(GL_INVALID_ENUM);
2592 }
2593 break;
2594
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002595 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002596 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597 }
2598
2599 switch (srcAlpha)
2600 {
2601 case GL_ZERO:
2602 case GL_ONE:
2603 case GL_SRC_COLOR:
2604 case GL_ONE_MINUS_SRC_COLOR:
2605 case GL_DST_COLOR:
2606 case GL_ONE_MINUS_DST_COLOR:
2607 case GL_SRC_ALPHA:
2608 case GL_ONE_MINUS_SRC_ALPHA:
2609 case GL_DST_ALPHA:
2610 case GL_ONE_MINUS_DST_ALPHA:
2611 case GL_CONSTANT_COLOR:
2612 case GL_ONE_MINUS_CONSTANT_COLOR:
2613 case GL_CONSTANT_ALPHA:
2614 case GL_ONE_MINUS_CONSTANT_ALPHA:
2615 case GL_SRC_ALPHA_SATURATE:
2616 break;
2617 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002618 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619 }
2620
2621 switch (dstAlpha)
2622 {
2623 case GL_ZERO:
2624 case GL_ONE:
2625 case GL_SRC_COLOR:
2626 case GL_ONE_MINUS_SRC_COLOR:
2627 case GL_DST_COLOR:
2628 case GL_ONE_MINUS_DST_COLOR:
2629 case GL_SRC_ALPHA:
2630 case GL_ONE_MINUS_SRC_ALPHA:
2631 case GL_DST_ALPHA:
2632 case GL_ONE_MINUS_DST_ALPHA:
2633 case GL_CONSTANT_COLOR:
2634 case GL_ONE_MINUS_CONSTANT_COLOR:
2635 case GL_CONSTANT_ALPHA:
2636 case GL_ONE_MINUS_CONSTANT_ALPHA:
2637 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002638
2639 case GL_SRC_ALPHA_SATURATE:
2640 if (!context || context->getClientVersion() < 3)
2641 {
2642 return gl::error(GL_INVALID_ENUM);
2643 }
2644 break;
2645
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002646 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002647 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002648 }
2649
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002650 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2651 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2652
2653 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2654 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2655
2656 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002657 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002658 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 +00002659 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002660 }
2661
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002662 if (context)
2663 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002664 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665 }
2666 }
2667 catch(std::bad_alloc&)
2668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002669 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002670 }
2671}
2672
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002673void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002675 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 +00002676 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677
2678 try
2679 {
2680 if (size < 0)
2681 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002683 }
2684
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002685 gl::Context *context = gl::getNonLostContext();
2686
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002687 switch (usage)
2688 {
2689 case GL_STREAM_DRAW:
2690 case GL_STATIC_DRAW:
2691 case GL_DYNAMIC_DRAW:
2692 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002693
2694 case GL_STREAM_READ:
2695 case GL_STREAM_COPY:
2696 case GL_STATIC_READ:
2697 case GL_STATIC_COPY:
2698 case GL_DYNAMIC_READ:
2699 case GL_DYNAMIC_COPY:
2700 if (context && context->getClientVersion() < 3)
2701 {
2702 return gl::error(GL_INVALID_ENUM);
2703 }
2704 break;
2705
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002706 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002707 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002708 }
2709
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002710 if (context)
2711 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002712 // Check ES3 specific targets
2713 switch (target)
2714 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002715 case GL_COPY_READ_BUFFER:
2716 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002717 case GL_PIXEL_PACK_BUFFER:
2718 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002719 case GL_UNIFORM_BUFFER:
2720 case GL_TRANSFORM_FEEDBACK_BUFFER:
2721 if (context->getClientVersion() < 3)
2722 {
2723 return gl::error(GL_INVALID_ENUM);
2724 }
2725 }
2726
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002728
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002729 switch (target)
2730 {
2731 case GL_ARRAY_BUFFER:
2732 buffer = context->getArrayBuffer();
2733 break;
2734 case GL_ELEMENT_ARRAY_BUFFER:
2735 buffer = context->getElementArrayBuffer();
2736 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002737 case GL_COPY_READ_BUFFER:
2738 buffer = context->getCopyReadBuffer();
2739 break;
2740 case GL_COPY_WRITE_BUFFER:
2741 buffer = context->getCopyWriteBuffer();
2742 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002743 case GL_PIXEL_PACK_BUFFER:
2744 buffer = context->getPixelPackBuffer();
2745 break;
2746 case GL_PIXEL_UNPACK_BUFFER:
2747 buffer = context->getPixelUnpackBuffer();
2748 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002749 case GL_TRANSFORM_FEEDBACK_BUFFER:
2750 buffer = context->getGenericTransformFeedbackBuffer();
2751 break;
2752 case GL_UNIFORM_BUFFER:
2753 buffer = context->getGenericUniformBuffer();
2754 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002756 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757 }
2758
2759 if (!buffer)
2760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002761 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762 }
2763
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002764 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765 }
2766 }
2767 catch(std::bad_alloc&)
2768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002769 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002770 }
2771}
2772
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002773void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002775 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 +00002776 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777
2778 try
2779 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002780 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002783 }
2784
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002785 if (data == NULL)
2786 {
2787 return;
2788 }
2789
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002790 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002791
2792 if (context)
2793 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002794 // Check ES3 specific targets
2795 switch (target)
2796 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002797 case GL_COPY_READ_BUFFER:
2798 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002799 case GL_PIXEL_PACK_BUFFER:
2800 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002801 case GL_UNIFORM_BUFFER:
2802 case GL_TRANSFORM_FEEDBACK_BUFFER:
2803 if (context->getClientVersion() < 3)
2804 {
2805 return gl::error(GL_INVALID_ENUM);
2806 }
2807 }
2808
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002809 gl::Buffer *buffer;
2810
2811 switch (target)
2812 {
2813 case GL_ARRAY_BUFFER:
2814 buffer = context->getArrayBuffer();
2815 break;
2816 case GL_ELEMENT_ARRAY_BUFFER:
2817 buffer = context->getElementArrayBuffer();
2818 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002819 case GL_COPY_READ_BUFFER:
2820 buffer = context->getCopyReadBuffer();
2821 break;
2822 case GL_COPY_WRITE_BUFFER:
2823 buffer = context->getCopyWriteBuffer();
2824 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002825 case GL_PIXEL_PACK_BUFFER:
2826 buffer = context->getPixelPackBuffer();
2827 break;
2828 case GL_PIXEL_UNPACK_BUFFER:
2829 buffer = context->getPixelUnpackBuffer();
2830 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002831 case GL_TRANSFORM_FEEDBACK_BUFFER:
2832 buffer = context->getGenericTransformFeedbackBuffer();
2833 break;
2834 case GL_UNIFORM_BUFFER:
2835 buffer = context->getGenericUniformBuffer();
2836 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002837 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002838 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002839 }
2840
2841 if (!buffer)
2842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002843 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002844 }
2845
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002846 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002849 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002850
2851 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002852 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002853 }
2854 catch(std::bad_alloc&)
2855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002856 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002857 }
2858}
2859
2860GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2861{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002862 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002863
2864 try
2865 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002866 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002867 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002868 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002869 }
2870
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002871 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002872
2873 if (context)
2874 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002875 gl::Framebuffer *framebuffer = NULL;
2876 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2877 {
2878 framebuffer = context->getReadFramebuffer();
2879 }
2880 else
2881 {
2882 framebuffer = context->getDrawFramebuffer();
2883 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002884
2885 return framebuffer->completeness();
2886 }
2887 }
2888 catch(std::bad_alloc&)
2889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002890 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002891 }
2892
2893 return 0;
2894}
2895
2896void __stdcall glClear(GLbitfield mask)
2897{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002898 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002899
2900 try
2901 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002903
2904 if (context)
2905 {
2906 context->clear(mask);
2907 }
2908 }
2909 catch(std::bad_alloc&)
2910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002911 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002912 }
2913}
2914
2915void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002917 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002918 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002919
2920 try
2921 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002922 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002923
2924 if (context)
2925 {
2926 context->setClearColor(red, green, blue, alpha);
2927 }
2928 }
2929 catch(std::bad_alloc&)
2930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002931 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002932 }
2933}
2934
2935void __stdcall glClearDepthf(GLclampf depth)
2936{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002937 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002938
2939 try
2940 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002941 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002942
2943 if (context)
2944 {
2945 context->setClearDepth(depth);
2946 }
2947 }
2948 catch(std::bad_alloc&)
2949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002951 }
2952}
2953
2954void __stdcall glClearStencil(GLint s)
2955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002956 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002957
2958 try
2959 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002961
2962 if (context)
2963 {
2964 context->setClearStencil(s);
2965 }
2966 }
2967 catch(std::bad_alloc&)
2968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002969 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002970 }
2971}
2972
2973void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2974{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002975 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002976 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002977
2978 try
2979 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002980 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002981
2982 if (context)
2983 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002984 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002985 }
2986 }
2987 catch(std::bad_alloc&)
2988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002990 }
2991}
2992
2993void __stdcall glCompileShader(GLuint shader)
2994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002995 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002996
2997 try
2998 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002999 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003000
3001 if (context)
3002 {
3003 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003004
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003005 if (!shaderObject)
3006 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003007 if (context->getProgram(shader))
3008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003009 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003010 }
3011 else
3012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003013 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003014 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003015 }
3016
3017 shaderObject->compile();
3018 }
3019 }
3020 catch(std::bad_alloc&)
3021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003022 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003023 }
3024}
3025
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003026void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
3027 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003028{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003029 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003030 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031 target, level, internalformat, width, height, border, imageSize, data);
3032
3033 try
3034 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003035 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003036
3037 if (context)
3038 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003039 if (context->getClientVersion() < 3 &&
3040 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3041 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3042 {
3043 return;
3044 }
3045
3046 if (context->getClientVersion() >= 3 &&
3047 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3048 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3049 {
3050 return;
3051 }
3052
3053 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003055 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003056 }
3057
3058 switch (target)
3059 {
3060 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003061 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003062 gl::Texture2D *texture = context->getTexture2D();
3063 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003064 }
3065 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003066
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003067 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3068 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3069 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3070 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3071 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3072 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003073 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003074 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3075 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003076 }
3077 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003078
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003079 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003080 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003081 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003082 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003083 }
3084 catch(std::bad_alloc&)
3085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003086 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003087 }
3088}
3089
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003090void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3091 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003092{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003093 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003094 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003095 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3097
3098 try
3099 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003101
3102 if (context)
3103 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003104 if (context->getClientVersion() < 3 &&
3105 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3106 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3107 {
3108 return;
3109 }
3110
3111 if (context->getClientVersion() >= 3 &&
3112 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3113 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3114 {
3115 return;
3116 }
3117
3118 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003120 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003121 }
3122
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003123 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003124 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003125 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003126 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003127 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003128 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003129 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003130 break;
3131
3132 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3133 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3134 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3135 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3136 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3137 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003138 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003139 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003140 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003141 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003142 break;
3143
3144 default:
3145 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003146 }
3147 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148 }
3149 catch(std::bad_alloc&)
3150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003151 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003152 }
3153}
3154
3155void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003157 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003158 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003159 target, level, internalformat, x, y, width, height, border);
3160
3161 try
3162 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003163 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003164
3165 if (context)
3166 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003167 if (context->getClientVersion() < 3 &&
3168 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3169 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003170 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003171 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003172 }
3173
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003174 if (context->getClientVersion() >= 3 &&
3175 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3176 0, 0, 0, x, y, width, height, border))
3177 {
3178 return;
3179 }
3180
3181 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3182
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003183 switch (target)
3184 {
3185 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003186 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003187 gl::Texture2D *texture = context->getTexture2D();
3188 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003189 }
3190 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003191
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003192 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3193 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3194 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3195 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3196 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3197 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003198 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003199 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3200 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003201 }
3202 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003203
3204 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003205 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003206 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003207 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208 }
3209 catch(std::bad_alloc&)
3210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003211 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003212 }
3213}
3214
3215void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3216{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003217 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003218 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003219 target, level, xoffset, yoffset, x, y, width, height);
3220
3221 try
3222 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003223 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003224
3225 if (context)
3226 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003227 if (context->getClientVersion() < 3 &&
3228 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3229 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003230 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003231 return;
3232 }
3233
3234 if (context->getClientVersion() >= 3 &&
3235 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3236 xoffset, yoffset, 0, x, y, width, height, 0))
3237 {
3238 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003239 }
3240
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003241 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003242
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003243 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003244 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003245 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003246 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003247 gl::Texture2D *texture = context->getTexture2D();
3248 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003249 }
3250 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003251
3252 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3253 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3254 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3255 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3256 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3257 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003258 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003259 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3260 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003261 }
3262 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003263
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003264 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003266 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003267 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003269
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003270 catch(std::bad_alloc&)
3271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003272 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003273 }
3274}
3275
3276GLuint __stdcall glCreateProgram(void)
3277{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003278 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003279
3280 try
3281 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003282 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283
3284 if (context)
3285 {
3286 return context->createProgram();
3287 }
3288 }
3289 catch(std::bad_alloc&)
3290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003291 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292 }
3293
3294 return 0;
3295}
3296
3297GLuint __stdcall glCreateShader(GLenum type)
3298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003299 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003300
3301 try
3302 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003303 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304
3305 if (context)
3306 {
3307 switch (type)
3308 {
3309 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003310 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003311 return context->createShader(type);
3312 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003313 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003314 }
3315 }
3316 }
3317 catch(std::bad_alloc&)
3318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003319 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003320 }
3321
3322 return 0;
3323}
3324
3325void __stdcall glCullFace(GLenum mode)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 try
3330 {
3331 switch (mode)
3332 {
3333 case GL_FRONT:
3334 case GL_BACK:
3335 case GL_FRONT_AND_BACK:
3336 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003338
3339 if (context)
3340 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003341 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003342 }
3343 }
3344 break;
3345 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003346 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003347 }
3348 }
3349 catch(std::bad_alloc&)
3350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003351 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003352 }
3353}
3354
3355void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3356{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003357 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003358
3359 try
3360 {
3361 if (n < 0)
3362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003363 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364 }
3365
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003366 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367
3368 if (context)
3369 {
3370 for (int i = 0; i < n; i++)
3371 {
3372 context->deleteBuffer(buffers[i]);
3373 }
3374 }
3375 }
3376 catch(std::bad_alloc&)
3377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003378 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379 }
3380}
3381
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003382void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003384 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003385
3386 try
3387 {
3388 if (n < 0)
3389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003390 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003391 }
3392
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003393 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003394
3395 if (context)
3396 {
3397 for (int i = 0; i < n; i++)
3398 {
Jamie Madill33dc8432013-07-26 11:55:05 -04003399 context->deleteFenceNV(fences[i]);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003400 }
3401 }
3402 }
3403 catch(std::bad_alloc&)
3404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003405 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003406 }
3407}
3408
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003409void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3410{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003411 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412
3413 try
3414 {
3415 if (n < 0)
3416 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003417 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418 }
3419
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003420 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421
3422 if (context)
3423 {
3424 for (int i = 0; i < n; i++)
3425 {
3426 if (framebuffers[i] != 0)
3427 {
3428 context->deleteFramebuffer(framebuffers[i]);
3429 }
3430 }
3431 }
3432 }
3433 catch(std::bad_alloc&)
3434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003435 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436 }
3437}
3438
3439void __stdcall glDeleteProgram(GLuint program)
3440{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003441 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003442
3443 try
3444 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003445 if (program == 0)
3446 {
3447 return;
3448 }
3449
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451
3452 if (context)
3453 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003454 if (!context->getProgram(program))
3455 {
3456 if(context->getShader(program))
3457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003458 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003459 }
3460 else
3461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003462 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003463 }
3464 }
3465
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 context->deleteProgram(program);
3467 }
3468 }
3469 catch(std::bad_alloc&)
3470 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003471 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 }
3473}
3474
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003475void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3476{
3477 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3478
3479 try
3480 {
3481 if (n < 0)
3482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003483 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003484 }
3485
3486 gl::Context *context = gl::getNonLostContext();
3487
3488 if (context)
3489 {
3490 for (int i = 0; i < n; i++)
3491 {
3492 context->deleteQuery(ids[i]);
3493 }
3494 }
3495 }
3496 catch(std::bad_alloc&)
3497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003498 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003499 }
3500}
3501
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3503{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003504 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003505
3506 try
3507 {
3508 if (n < 0)
3509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003511 }
3512
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003513 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514
3515 if (context)
3516 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003517 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003518 {
3519 context->deleteRenderbuffer(renderbuffers[i]);
3520 }
3521 }
3522 }
3523 catch(std::bad_alloc&)
3524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003525 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 }
3527}
3528
3529void __stdcall glDeleteShader(GLuint shader)
3530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003531 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003532
3533 try
3534 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003535 if (shader == 0)
3536 {
3537 return;
3538 }
3539
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003540 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003541
3542 if (context)
3543 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003544 if (!context->getShader(shader))
3545 {
3546 if(context->getProgram(shader))
3547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003548 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003549 }
3550 else
3551 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003552 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003553 }
3554 }
3555
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003556 context->deleteShader(shader);
3557 }
3558 }
3559 catch(std::bad_alloc&)
3560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003561 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003562 }
3563}
3564
3565void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003567 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568
3569 try
3570 {
3571 if (n < 0)
3572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003573 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 }
3575
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577
3578 if (context)
3579 {
3580 for (int i = 0; i < n; i++)
3581 {
3582 if (textures[i] != 0)
3583 {
3584 context->deleteTexture(textures[i]);
3585 }
3586 }
3587 }
3588 }
3589 catch(std::bad_alloc&)
3590 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003591 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003592 }
3593}
3594
3595void __stdcall glDepthFunc(GLenum func)
3596{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003597 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598
3599 try
3600 {
3601 switch (func)
3602 {
3603 case GL_NEVER:
3604 case GL_ALWAYS:
3605 case GL_LESS:
3606 case GL_LEQUAL:
3607 case GL_EQUAL:
3608 case GL_GREATER:
3609 case GL_GEQUAL:
3610 case GL_NOTEQUAL:
3611 break;
3612 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003613 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614 }
3615
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003616 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617
3618 if (context)
3619 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003620 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621 }
3622 }
3623 catch(std::bad_alloc&)
3624 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003625 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003626 }
3627}
3628
3629void __stdcall glDepthMask(GLboolean flag)
3630{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003631 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003632
3633 try
3634 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003635 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636
3637 if (context)
3638 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003639 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 }
3641 }
3642 catch(std::bad_alloc&)
3643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003644 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003645 }
3646}
3647
3648void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3649{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003650 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651
3652 try
3653 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003654 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655
3656 if (context)
3657 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003658 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 }
3660 }
3661 catch(std::bad_alloc&)
3662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003663 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664 }
3665}
3666
3667void __stdcall glDetachShader(GLuint program, GLuint shader)
3668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003669 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670
3671 try
3672 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003673 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003674
3675 if (context)
3676 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003677
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003678 gl::Program *programObject = context->getProgram(program);
3679 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003680
3681 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003682 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003683 gl::Shader *shaderByProgramHandle;
3684 shaderByProgramHandle = context->getShader(program);
3685 if (!shaderByProgramHandle)
3686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003687 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003688 }
3689 else
3690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003692 }
3693 }
3694
3695 if (!shaderObject)
3696 {
3697 gl::Program *programByShaderHandle = context->getProgram(shader);
3698 if (!programByShaderHandle)
3699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003700 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003701 }
3702 else
3703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003704 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003705 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003706 }
3707
3708 if (!programObject->detachShader(shaderObject))
3709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003710 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003711 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712 }
3713 }
3714 catch(std::bad_alloc&)
3715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003717 }
3718}
3719
3720void __stdcall glDisable(GLenum cap)
3721{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003722 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723
3724 try
3725 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003726 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003727
3728 if (context)
3729 {
3730 switch (cap)
3731 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003732 case GL_CULL_FACE: context->setCullFace(false); break;
3733 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3734 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3735 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3736 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3737 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3738 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3739 case GL_BLEND: context->setBlend(false); break;
3740 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003741
3742 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3743 case GL_RASTERIZER_DISCARD:
3744 if (context->getClientVersion() < 3)
3745 {
3746 return gl::error(GL_INVALID_ENUM);
3747 }
3748 UNIMPLEMENTED();
3749 break;
3750
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003751 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003752 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003753 }
3754 }
3755 }
3756 catch(std::bad_alloc&)
3757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003758 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759 }
3760}
3761
3762void __stdcall glDisableVertexAttribArray(GLuint index)
3763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003764 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003765
3766 try
3767 {
3768 if (index >= gl::MAX_VERTEX_ATTRIBS)
3769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003770 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003771 }
3772
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003773 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003774
3775 if (context)
3776 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003777 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778 }
3779 }
3780 catch(std::bad_alloc&)
3781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003782 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003783 }
3784}
3785
3786void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3787{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003788 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789
3790 try
3791 {
3792 if (count < 0 || first < 0)
3793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003794 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003795 }
3796
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003797 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003798
3799 if (context)
3800 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003801 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003802 }
3803 }
3804 catch(std::bad_alloc&)
3805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003806 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003807 }
3808}
3809
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003810void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3811{
3812 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3813
3814 try
3815 {
3816 if (count < 0 || first < 0 || primcount < 0)
3817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003818 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003819 }
3820
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003821 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003822 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003823 gl::Context *context = gl::getNonLostContext();
3824
3825 if (context)
3826 {
3827 context->drawArrays(mode, first, count, primcount);
3828 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003829 }
3830 }
3831 catch(std::bad_alloc&)
3832 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003833 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003834 }
3835}
3836
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003837void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003839 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 +00003840 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841
3842 try
3843 {
3844 if (count < 0)
3845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003846 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003847 }
3848
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003849 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850
3851 if (context)
3852 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003853 switch (type)
3854 {
3855 case GL_UNSIGNED_BYTE:
3856 case GL_UNSIGNED_SHORT:
3857 break;
3858 case GL_UNSIGNED_INT:
3859 if (!context->supports32bitIndices())
3860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003861 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003862 }
3863 break;
3864 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003865 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003866 }
3867
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003868 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869 }
3870 }
3871 catch(std::bad_alloc&)
3872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003873 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003874 }
3875}
3876
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003877void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3878{
3879 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3880 mode, count, type, indices, primcount);
3881
3882 try
3883 {
3884 if (count < 0 || primcount < 0)
3885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003886 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003887 }
3888
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003889 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003890 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003891 gl::Context *context = gl::getNonLostContext();
3892
3893 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003894 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003895 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003896 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003897 case GL_UNSIGNED_BYTE:
3898 case GL_UNSIGNED_SHORT:
3899 break;
3900 case GL_UNSIGNED_INT:
3901 if (!context->supports32bitIndices())
3902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003904 }
3905 break;
3906 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003907 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003908 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003909
3910 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003911 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003912 }
3913 }
3914 catch(std::bad_alloc&)
3915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003916 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003917 }
3918}
3919
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920void __stdcall glEnable(GLenum cap)
3921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003922 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923
3924 try
3925 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003926 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927
3928 if (context)
3929 {
3930 switch (cap)
3931 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003932 case GL_CULL_FACE: context->setCullFace(true); break;
3933 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3934 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3935 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3936 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3937 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3938 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3939 case GL_BLEND: context->setBlend(true); break;
3940 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003941 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003942 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003943 }
3944 }
3945 }
3946 catch(std::bad_alloc&)
3947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003948 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003949 }
3950}
3951
3952void __stdcall glEnableVertexAttribArray(GLuint index)
3953{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003954 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003955
3956 try
3957 {
3958 if (index >= gl::MAX_VERTEX_ATTRIBS)
3959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003960 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003961 }
3962
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003963 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964
3965 if (context)
3966 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003967 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003968 }
3969 }
3970 catch(std::bad_alloc&)
3971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003972 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003973 }
3974}
3975
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003976void __stdcall glEndQueryEXT(GLenum target)
3977{
3978 EVENT("GLenum target = 0x%X)", target);
3979
3980 try
3981 {
3982 switch (target)
3983 {
3984 case GL_ANY_SAMPLES_PASSED_EXT:
3985 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3986 break;
3987 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003988 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003989 }
3990
3991 gl::Context *context = gl::getNonLostContext();
3992
3993 if (context)
3994 {
3995 context->endQuery(target);
3996 }
3997 }
3998 catch(std::bad_alloc&)
3999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004000 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004001 }
4002}
4003
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004004void __stdcall glFinishFenceNV(GLuint fence)
4005{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004006 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004007
4008 try
4009 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004010 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004011
4012 if (context)
4013 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004014 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004015
4016 if (fenceObject == NULL)
4017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004018 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004019 }
4020
Jamie Madillfb9a7402013-07-26 11:55:01 -04004021 if (fenceObject->isFence() != GL_TRUE)
4022 {
4023 return gl::error(GL_INVALID_OPERATION);
4024 }
4025
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004026 fenceObject->finishFence();
4027 }
4028 }
4029 catch(std::bad_alloc&)
4030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004031 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004032 }
4033}
4034
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004035void __stdcall glFinish(void)
4036{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004037 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004038
4039 try
4040 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004041 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004042
4043 if (context)
4044 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004045 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047 }
4048 catch(std::bad_alloc&)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051 }
4052}
4053
4054void __stdcall glFlush(void)
4055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004056 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004057
4058 try
4059 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004060 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004061
4062 if (context)
4063 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004064 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 }
4066 }
4067 catch(std::bad_alloc&)
4068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071}
4072
4073void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4074{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004075 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004076 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077
4078 try
4079 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004080 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004081 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004083 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004084 }
4085
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004086 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004087
4088 if (context)
4089 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004090 gl::Framebuffer *framebuffer = NULL;
4091 GLuint framebufferHandle = 0;
4092 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4093 {
4094 framebuffer = context->getReadFramebuffer();
4095 framebufferHandle = context->getReadFramebufferHandle();
4096 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004097 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004098 {
4099 framebuffer = context->getDrawFramebuffer();
4100 framebufferHandle = context->getDrawFramebufferHandle();
4101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004103 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004104 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004105 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004106 }
4107
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004108 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004109 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004110 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4111
4112 if (colorAttachment >= context->getMaximumRenderTargets())
4113 {
4114 return gl::error(GL_INVALID_VALUE);
4115 }
4116
4117 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
4118 }
4119 else
4120 {
4121 switch (attachment)
4122 {
4123 case GL_DEPTH_ATTACHMENT:
4124 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
4125 break;
4126 case GL_STENCIL_ATTACHMENT:
4127 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
4128 break;
4129 default:
4130 return gl::error(GL_INVALID_ENUM);
4131 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004132 }
4133 }
4134 }
4135 catch(std::bad_alloc&)
4136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004137 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004138 }
4139}
4140
4141void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4142{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004143 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004144 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004145
4146 try
4147 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004148 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004151 }
4152
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004153 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004154
4155 if (context)
4156 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004157 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
4158 {
4159 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4160
4161 if (colorAttachment >= context->getMaximumRenderTargets())
4162 {
4163 return gl::error(GL_INVALID_VALUE);
4164 }
4165 }
4166 else
4167 {
4168 switch (attachment)
4169 {
4170 case GL_DEPTH_ATTACHMENT:
4171 case GL_STENCIL_ATTACHMENT:
4172 break;
Geoff Lang55ba29c2013-07-11 16:57:53 -04004173 case GL_DEPTH_STENCIL_ATTACHMENT:
4174 if (context->getClientVersion() < 3)
4175 {
4176 return gl::error(GL_INVALID_ENUM);
4177 }
4178 break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004179 default:
4180 return gl::error(GL_INVALID_ENUM);
4181 }
4182 }
4183
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004184 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004185 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004186 textarget = GL_NONE;
4187 }
4188 else
4189 {
4190 gl::Texture *tex = context->getTexture(texture);
4191
4192 if (tex == NULL)
4193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004194 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004195 }
4196
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004197 switch (textarget)
4198 {
4199 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004200 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004201 if (tex->getTarget() != GL_TEXTURE_2D)
4202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004203 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004204 }
4205 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004206 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004207 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004208 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004209 }
4210 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004211 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004212
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004213 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004215 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004216 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004217 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004218 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004219 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004220 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4221 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004222 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004223 }
4224 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004225 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004226 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004227 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004228 }
4229 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004230 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004232 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004233 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004234 }
4235
4236 if (level != 0)
4237 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004238 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004239 }
4240 }
4241
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004242 gl::Framebuffer *framebuffer = NULL;
4243 GLuint framebufferHandle = 0;
4244 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4245 {
4246 framebuffer = context->getReadFramebuffer();
4247 framebufferHandle = context->getReadFramebufferHandle();
4248 }
4249 else
4250 {
4251 framebuffer = context->getDrawFramebuffer();
4252 framebufferHandle = context->getDrawFramebufferHandle();
4253 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004254
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004255 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004257 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004258 }
4259
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004260 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004261 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004262 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4263
4264 if (colorAttachment >= context->getMaximumRenderTargets())
4265 {
4266 return gl::error(GL_INVALID_VALUE);
4267 }
4268
4269 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4270 }
4271 else
4272 {
4273 switch (attachment)
4274 {
Geoff Lang55ba29c2013-07-11 16:57:53 -04004275 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4276 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4277 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture); break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004278 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004279 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004280 }
4281 }
4282 catch(std::bad_alloc&)
4283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004284 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004285 }
4286}
4287
4288void __stdcall glFrontFace(GLenum mode)
4289{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004290 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004291
4292 try
4293 {
4294 switch (mode)
4295 {
4296 case GL_CW:
4297 case GL_CCW:
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 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004303 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304 }
4305 }
4306 break;
4307 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004308 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004309 }
4310 }
4311 catch(std::bad_alloc&)
4312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004313 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004314 }
4315}
4316
4317void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004319 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004320
4321 try
4322 {
4323 if (n < 0)
4324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004325 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326 }
4327
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004328 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004329
4330 if (context)
4331 {
4332 for (int i = 0; i < n; i++)
4333 {
4334 buffers[i] = context->createBuffer();
4335 }
4336 }
4337 }
4338 catch(std::bad_alloc&)
4339 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004340 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004341 }
4342}
4343
4344void __stdcall glGenerateMipmap(GLenum target)
4345{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004346 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004347
4348 try
4349 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004350 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004351
4352 if (context)
4353 {
Geoff Langae4852a2013-06-05 15:00:34 -04004354 gl::Texture *texture = NULL;
4355 GLint internalFormat = GL_NONE;
4356 bool isCompressed = false;
4357 bool isDepth = false;
4358
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004359 switch (target)
4360 {
4361 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004362 {
4363 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004364 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004365 {
Geoff Langae4852a2013-06-05 15:00:34 -04004366 internalFormat = tex2d->getInternalFormat(0);
4367 isCompressed = tex2d->isCompressed(0);
4368 isDepth = tex2d->isDepth(0);
4369 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004370 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004371 break;
4372 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004373
4374 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004375 {
4376 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004377 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004378 {
Geoff Langae4852a2013-06-05 15:00:34 -04004379 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4380 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4381 isDepth = false;
4382 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004383 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004384 break;
4385 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004386
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004387 case GL_TEXTURE_3D:
4388 {
4389 if (context->getClientVersion() < 3)
4390 {
4391 return gl::error(GL_INVALID_ENUM);
4392 }
4393
4394 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004395 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004396 {
Geoff Langae4852a2013-06-05 15:00:34 -04004397 internalFormat = tex3D->getInternalFormat(0);
4398 isCompressed = tex3D->isCompressed(0);
4399 isDepth = tex3D->isDepth(0);
4400 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004401 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004402 break;
4403 }
4404
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004405 case GL_TEXTURE_2D_ARRAY:
4406 {
4407 if (context->getClientVersion() < 3)
4408 {
4409 return gl::error(GL_INVALID_ENUM);
4410 }
4411
4412 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004413 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004414 {
Geoff Langae4852a2013-06-05 15:00:34 -04004415 internalFormat = tex2darr->getInternalFormat(0);
4416 isCompressed = tex2darr->isCompressed(0);
4417 isDepth = tex2darr->isDepth(0);
4418 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004419 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004420 break;
4421 }
4422
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004423 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004424 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004425 }
Geoff Langae4852a2013-06-05 15:00:34 -04004426
4427 if (!texture)
4428 {
4429 return gl::error(GL_INVALID_OPERATION);
4430 }
4431
4432 // Internally, all texture formats are sized so checking if the format
4433 // is color renderable and filterable will not fail.
4434 if (isDepth || isCompressed ||
4435 !gl::IsColorRenderingSupported(internalFormat, context) ||
4436 !gl::IsTextureFilteringSupported(internalFormat, context))
4437 {
4438 return gl::error(GL_INVALID_OPERATION);
4439 }
4440
4441 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004442 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004443 }
4444 catch(std::bad_alloc&)
4445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004446 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004447 }
4448}
4449
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004450void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4451{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004452 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004453
4454 try
4455 {
4456 if (n < 0)
4457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004458 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004459 }
4460
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004461 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004462
4463 if (context)
4464 {
4465 for (int i = 0; i < n; i++)
4466 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004467 fences[i] = context->createFenceNV();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004468 }
4469 }
4470 }
4471 catch(std::bad_alloc&)
4472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004473 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004474 }
4475}
4476
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004477void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004479 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004480
4481 try
4482 {
4483 if (n < 0)
4484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004485 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004486 }
4487
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004488 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004489
4490 if (context)
4491 {
4492 for (int i = 0; i < n; i++)
4493 {
4494 framebuffers[i] = context->createFramebuffer();
4495 }
4496 }
4497 }
4498 catch(std::bad_alloc&)
4499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004500 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004501 }
4502}
4503
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004504void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4505{
4506 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4507
4508 try
4509 {
4510 if (n < 0)
4511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004513 }
4514
4515 gl::Context *context = gl::getNonLostContext();
4516
4517 if (context)
4518 {
4519 for (int i = 0; i < n; i++)
4520 {
4521 ids[i] = context->createQuery();
4522 }
4523 }
4524 }
4525 catch(std::bad_alloc&)
4526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004527 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004528 }
4529}
4530
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004531void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4532{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004533 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004534
4535 try
4536 {
4537 if (n < 0)
4538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004539 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004540 }
4541
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004542 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543
4544 if (context)
4545 {
4546 for (int i = 0; i < n; i++)
4547 {
4548 renderbuffers[i] = context->createRenderbuffer();
4549 }
4550 }
4551 }
4552 catch(std::bad_alloc&)
4553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555 }
4556}
4557
4558void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004560 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004561
4562 try
4563 {
4564 if (n < 0)
4565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004567 }
4568
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004569 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570
4571 if (context)
4572 {
4573 for (int i = 0; i < n; i++)
4574 {
4575 textures[i] = context->createTexture();
4576 }
4577 }
4578 }
4579 catch(std::bad_alloc&)
4580 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004581 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004582 }
4583}
4584
daniel@transgaming.com85423182010-04-22 13:35:27 +00004585void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004586{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004587 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004588 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004589 program, index, bufsize, length, size, type, name);
4590
4591 try
4592 {
4593 if (bufsize < 0)
4594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004595 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004596 }
4597
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004599
4600 if (context)
4601 {
4602 gl::Program *programObject = context->getProgram(program);
4603
4604 if (!programObject)
4605 {
4606 if (context->getShader(program))
4607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004608 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004609 }
4610 else
4611 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004612 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004613 }
4614 }
4615
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004616 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004618 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004619 }
4620
4621 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4622 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004623 }
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
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004630void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004632 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004633 "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 +00004634 program, index, bufsize, length, size, type, name);
4635
4636 try
4637 {
4638 if (bufsize < 0)
4639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004640 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004641 }
4642
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004643 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004644
4645 if (context)
4646 {
4647 gl::Program *programObject = context->getProgram(program);
4648
4649 if (!programObject)
4650 {
4651 if (context->getShader(program))
4652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004653 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004654 }
4655 else
4656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004657 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004658 }
4659 }
4660
4661 if (index >= (GLuint)programObject->getActiveUniformCount())
4662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004663 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004664 }
4665
4666 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4667 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004668 }
4669 catch(std::bad_alloc&)
4670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004671 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004672 }
4673}
4674
4675void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4676{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004677 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 +00004678 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004679
4680 try
4681 {
4682 if (maxcount < 0)
4683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004685 }
4686
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004687 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004688
4689 if (context)
4690 {
4691 gl::Program *programObject = context->getProgram(program);
4692
4693 if (!programObject)
4694 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004695 if (context->getShader(program))
4696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004697 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004698 }
4699 else
4700 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004701 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004702 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004703 }
4704
4705 return programObject->getAttachedShaders(maxcount, count, shaders);
4706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004707 }
4708 catch(std::bad_alloc&)
4709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004710 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004711 }
4712}
4713
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004714int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004716 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004717
4718 try
4719 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004720 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721
4722 if (context)
4723 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004724
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725 gl::Program *programObject = context->getProgram(program);
4726
4727 if (!programObject)
4728 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004729 if (context->getShader(program))
4730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004731 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004732 }
4733 else
4734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004735 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004736 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737 }
4738
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004739 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004740 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004742 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004743 }
4744
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004745 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004746 }
4747 }
4748 catch(std::bad_alloc&)
4749 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004750 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004751 }
4752
4753 return -1;
4754}
4755
4756void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4757{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004758 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004759
4760 try
4761 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004762 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004763
4764 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004765 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004766 if (!(context->getBooleanv(pname, params)))
4767 {
4768 GLenum nativeType;
4769 unsigned int numParams = 0;
4770 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004771 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004772
4773 if (numParams == 0)
4774 return; // it is known that the pname is valid, but there are no parameters to return
4775
4776 if (nativeType == GL_FLOAT)
4777 {
4778 GLfloat *floatParams = NULL;
4779 floatParams = new GLfloat[numParams];
4780
4781 context->getFloatv(pname, floatParams);
4782
4783 for (unsigned int i = 0; i < numParams; ++i)
4784 {
4785 if (floatParams[i] == 0.0f)
4786 params[i] = GL_FALSE;
4787 else
4788 params[i] = GL_TRUE;
4789 }
4790
4791 delete [] floatParams;
4792 }
4793 else if (nativeType == GL_INT)
4794 {
4795 GLint *intParams = NULL;
4796 intParams = new GLint[numParams];
4797
4798 context->getIntegerv(pname, intParams);
4799
4800 for (unsigned int i = 0; i < numParams; ++i)
4801 {
4802 if (intParams[i] == 0)
4803 params[i] = GL_FALSE;
4804 else
4805 params[i] = GL_TRUE;
4806 }
4807
4808 delete [] intParams;
4809 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004810 else if (nativeType == GL_INT_64_ANGLEX)
4811 {
4812 GLint64 *int64Params = NULL;
4813 int64Params = new GLint64[numParams];
4814
4815 context->getInteger64v(pname, int64Params);
4816
4817 for (unsigned int i = 0; i < numParams; ++i)
4818 {
4819 if (int64Params[i] == 0)
4820 params[i] = GL_FALSE;
4821 else
4822 params[i] = GL_TRUE;
4823 }
4824
4825 delete [] int64Params;
4826 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004827 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004828 }
4829 }
4830 catch(std::bad_alloc&)
4831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004832 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004833 }
4834}
4835
4836void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004838 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 +00004839
4840 try
4841 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004842 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004843
4844 if (context)
4845 {
4846 gl::Buffer *buffer;
4847
4848 switch (target)
4849 {
4850 case GL_ARRAY_BUFFER:
4851 buffer = context->getArrayBuffer();
4852 break;
4853 case GL_ELEMENT_ARRAY_BUFFER:
4854 buffer = context->getElementArrayBuffer();
4855 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004856 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004857 }
4858
4859 if (!buffer)
4860 {
4861 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004862 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004863 }
4864
4865 switch (pname)
4866 {
4867 case GL_BUFFER_USAGE:
4868 *params = buffer->usage();
4869 break;
4870 case GL_BUFFER_SIZE:
4871 *params = buffer->size();
4872 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004873 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004874 }
4875 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004876 }
4877 catch(std::bad_alloc&)
4878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004879 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004880 }
4881}
4882
4883GLenum __stdcall glGetError(void)
4884{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004885 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004886
4887 gl::Context *context = gl::getContext();
4888
4889 if (context)
4890 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004891 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004892 }
4893
4894 return GL_NO_ERROR;
4895}
4896
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004897void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004899 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004900
4901 try
4902 {
4903
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004904 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004905
4906 if (context)
4907 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004908 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004909
4910 if (fenceObject == NULL)
4911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004912 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004913 }
4914
Jamie Madillfb9a7402013-07-26 11:55:01 -04004915 if (fenceObject->isFence() != GL_TRUE)
4916 {
4917 return gl::error(GL_INVALID_OPERATION);
4918 }
4919
4920 switch (pname)
4921 {
4922 case GL_FENCE_STATUS_NV:
4923 case GL_FENCE_CONDITION_NV:
4924 break;
4925
4926 default: return gl::error(GL_INVALID_ENUM);
4927 }
4928
4929 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004930 }
4931 }
4932 catch(std::bad_alloc&)
4933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004934 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004935 }
4936}
4937
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004938void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4939{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004940 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004941
4942 try
4943 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004944 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004945
4946 if (context)
4947 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004948 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004949 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004950 GLenum nativeType;
4951 unsigned int numParams = 0;
4952 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004953 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004954
4955 if (numParams == 0)
4956 return; // it is known that the pname is valid, but that there are no parameters to return.
4957
4958 if (nativeType == GL_BOOL)
4959 {
4960 GLboolean *boolParams = NULL;
4961 boolParams = new GLboolean[numParams];
4962
4963 context->getBooleanv(pname, boolParams);
4964
4965 for (unsigned int i = 0; i < numParams; ++i)
4966 {
4967 if (boolParams[i] == GL_FALSE)
4968 params[i] = 0.0f;
4969 else
4970 params[i] = 1.0f;
4971 }
4972
4973 delete [] boolParams;
4974 }
4975 else if (nativeType == GL_INT)
4976 {
4977 GLint *intParams = NULL;
4978 intParams = new GLint[numParams];
4979
4980 context->getIntegerv(pname, intParams);
4981
4982 for (unsigned int i = 0; i < numParams; ++i)
4983 {
Jamie Madill71fbd602013-07-19 16:36:55 -04004984 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004985 }
4986
4987 delete [] intParams;
4988 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004989 else if (nativeType == GL_INT_64_ANGLEX)
4990 {
4991 GLint64 *int64Params = NULL;
4992 int64Params = new GLint64[numParams];
4993
4994 context->getInteger64v(pname, int64Params);
4995
4996 for (unsigned int i = 0; i < numParams; ++i)
4997 {
4998 params[i] = static_cast<GLfloat>(int64Params[i]);
4999 }
5000
5001 delete [] int64Params;
5002 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005003 }
5004 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005005 }
5006 catch(std::bad_alloc&)
5007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005008 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005009 }
5010}
5011
5012void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
5013{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005014 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 +00005015 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005016
5017 try
5018 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005019 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005020
5021 if (context)
5022 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005023 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005025 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005026 }
5027
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005028 gl::Framebuffer *framebuffer = NULL;
5029 if (target == GL_READ_FRAMEBUFFER_ANGLE)
5030 {
5031 if(context->getReadFramebufferHandle() == 0)
5032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005033 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005034 }
5035
5036 framebuffer = context->getReadFramebuffer();
5037 }
5038 else
5039 {
5040 if (context->getDrawFramebufferHandle() == 0)
5041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005042 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005043 }
5044
5045 framebuffer = context->getDrawFramebuffer();
5046 }
5047
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005048 GLenum attachmentType;
5049 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005050
5051 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005052 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005053 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5054
5055 if (colorAttachment >= context->getMaximumRenderTargets())
5056 {
5057 return gl::error(GL_INVALID_ENUM);
5058 }
5059
5060 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5061 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
5062 }
5063 else
5064 {
5065 switch (attachment)
5066 {
5067 case GL_DEPTH_ATTACHMENT:
5068 attachmentType = framebuffer->getDepthbufferType();
5069 attachmentHandle = framebuffer->getDepthbufferHandle();
5070 break;
5071 case GL_STENCIL_ATTACHMENT:
5072 attachmentType = framebuffer->getStencilbufferType();
5073 attachmentHandle = framebuffer->getStencilbufferHandle();
5074 break;
Geoff Lang55ba29c2013-07-11 16:57:53 -04005075 case GL_DEPTH_STENCIL_ATTACHMENT:
5076 if (context->getClientVersion() < 3)
5077 {
5078 return gl::error(GL_INVALID_ENUM);
5079 }
5080 if (framebuffer->getDepthbufferHandle() != framebuffer->getStencilbufferHandle())
5081 {
5082 return gl::error(GL_INVALID_OPERATION);
5083 }
5084 attachmentType = framebuffer->getDepthStencilbufferType();
5085 attachmentHandle = framebuffer->getDepthStencilbufferHandle();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005086 default: return gl::error(GL_INVALID_ENUM);
5087 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005088 }
5089
5090 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005091 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005092 {
5093 attachmentObjectType = attachmentType;
5094 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00005095 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005096 {
5097 attachmentObjectType = GL_TEXTURE;
5098 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005099 else
5100 {
5101 UNREACHABLE();
5102 return;
5103 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005104
5105 switch (pname)
5106 {
5107 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5108 *params = attachmentObjectType;
5109 break;
5110 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5111 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5112 {
5113 *params = attachmentHandle;
5114 }
5115 else
5116 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005117 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005118 }
5119 break;
5120 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5121 if (attachmentObjectType == GL_TEXTURE)
5122 {
5123 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
5124 }
5125 else
5126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005127 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005128 }
5129 break;
5130 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5131 if (attachmentObjectType == GL_TEXTURE)
5132 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005133 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005134 {
5135 *params = attachmentType;
5136 }
5137 else
5138 {
5139 *params = 0;
5140 }
5141 }
5142 else
5143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005144 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005145 }
5146 break;
5147 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005148 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005149 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005150 }
5151 }
5152 catch(std::bad_alloc&)
5153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005154 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005155 }
5156}
5157
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005158GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5159{
5160 EVENT("()");
5161
5162 try
5163 {
5164 gl::Context *context = gl::getContext();
5165
5166 if (context)
5167 {
5168 return context->getResetStatus();
5169 }
5170
5171 return GL_NO_ERROR;
5172 }
5173 catch(std::bad_alloc&)
5174 {
5175 return GL_OUT_OF_MEMORY;
5176 }
5177}
5178
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005179void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5180{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005181 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005182
5183 try
5184 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005185 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005186
5187 if (context)
5188 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005189 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005190 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005191 GLenum nativeType;
5192 unsigned int numParams = 0;
5193 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005194 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005195
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005196 if (numParams == 0)
5197 return; // it is known that pname is valid, but there are no parameters to return
5198
5199 if (nativeType == GL_BOOL)
5200 {
5201 GLboolean *boolParams = NULL;
5202 boolParams = new GLboolean[numParams];
5203
5204 context->getBooleanv(pname, boolParams);
5205
5206 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005207 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005208 if (boolParams[i] == GL_FALSE)
5209 params[i] = 0;
5210 else
5211 params[i] = 1;
5212 }
5213
5214 delete [] boolParams;
5215 }
5216 else if (nativeType == GL_FLOAT)
5217 {
5218 GLfloat *floatParams = NULL;
5219 floatParams = new GLfloat[numParams];
5220
5221 context->getFloatv(pname, floatParams);
5222
5223 for (unsigned int i = 0; i < numParams; ++i)
5224 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005225 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
daniel@transgaming.comc1641352010-04-26 15:33:36 +00005226 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 +00005227 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005228 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005229 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005230 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005231 {
Jamie Madillaf496912013-07-19 16:36:54 -04005232 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005233 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005234 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005235
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005236 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005237 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005238 else if (nativeType == GL_INT_64_ANGLEX)
5239 {
5240 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5241 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5242 GLint64 *int64Params = NULL;
5243 int64Params = new GLint64[numParams];
5244
5245 context->getInteger64v(pname, int64Params);
5246
5247 for (unsigned int i = 0; i < numParams; ++i)
5248 {
5249 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5250 params[i] = static_cast<GLint>(clampedValue);
5251 }
5252
5253 delete [] int64Params;
5254 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005255 }
5256 }
5257 }
5258 catch(std::bad_alloc&)
5259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005260 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 }
5262}
5263
5264void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5265{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005266 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005267
5268 try
5269 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005270 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005271
5272 if (context)
5273 {
5274 gl::Program *programObject = context->getProgram(program);
5275
5276 if (!programObject)
5277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005278 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005279 }
5280
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005281 if (context->getClientVersion() < 3)
5282 {
5283 switch (pname)
5284 {
5285 case GL_ACTIVE_UNIFORM_BLOCKS:
5286 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5287 return gl::error(GL_INVALID_ENUM);
5288 }
5289 }
5290
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005291 switch (pname)
5292 {
5293 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005294 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005295 return;
5296 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005297 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005298 return;
5299 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005300 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005301 return;
5302 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005303 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005304 return;
5305 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005306 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005307 return;
5308 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005309 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005310 return;
5311 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005312 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005313 return;
5314 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005315 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005316 return;
5317 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005318 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005319 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005320 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005321 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005322 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005323 case GL_ACTIVE_UNIFORM_BLOCKS:
5324 *params = programObject->getActiveUniformBlockCount();
5325 return;
5326 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5327 *params = programObject->getActiveUniformBlockMaxLength();
5328 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005329 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005330 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005331 }
5332 }
5333 }
5334 catch(std::bad_alloc&)
5335 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005336 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005337 }
5338}
5339
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005340void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005341{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005342 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 +00005343 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005344
5345 try
5346 {
5347 if (bufsize < 0)
5348 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005349 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005350 }
5351
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005352 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005353
5354 if (context)
5355 {
5356 gl::Program *programObject = context->getProgram(program);
5357
5358 if (!programObject)
5359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005360 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005361 }
5362
5363 programObject->getInfoLog(bufsize, length, infolog);
5364 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005365 }
5366 catch(std::bad_alloc&)
5367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005368 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005369 }
5370}
5371
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005372void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5373{
5374 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5375
5376 try
5377 {
5378 switch (pname)
5379 {
5380 case GL_CURRENT_QUERY_EXT:
5381 break;
5382 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005383 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005384 }
5385
5386 gl::Context *context = gl::getNonLostContext();
5387
5388 if (context)
5389 {
5390 params[0] = context->getActiveQuery(target);
5391 }
5392 }
5393 catch(std::bad_alloc&)
5394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005395 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005396 }
5397}
5398
5399void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5400{
5401 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5402
5403 try
5404 {
5405 switch (pname)
5406 {
5407 case GL_QUERY_RESULT_EXT:
5408 case GL_QUERY_RESULT_AVAILABLE_EXT:
5409 break;
5410 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005411 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005412 }
5413 gl::Context *context = gl::getNonLostContext();
5414
5415 if (context)
5416 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005417 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5418
5419 if (!queryObject)
5420 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005421 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005422 }
5423
5424 if (context->getActiveQuery(queryObject->getType()) == id)
5425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005426 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005427 }
5428
5429 switch(pname)
5430 {
5431 case GL_QUERY_RESULT_EXT:
5432 params[0] = queryObject->getResult();
5433 break;
5434 case GL_QUERY_RESULT_AVAILABLE_EXT:
5435 params[0] = queryObject->isResultAvailable();
5436 break;
5437 default:
5438 ASSERT(false);
5439 }
5440 }
5441 }
5442 catch(std::bad_alloc&)
5443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005444 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005445 }
5446}
5447
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005448void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005450 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 +00005451
5452 try
5453 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005454 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005455
5456 if (context)
5457 {
5458 if (target != GL_RENDERBUFFER)
5459 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005460 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005461 }
5462
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005463 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005464 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005465 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005466 }
5467
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005468 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005469
5470 switch (pname)
5471 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005472 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5473 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5474 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5475 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5476 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5477 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5478 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5479 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5480 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005481 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005482 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005483 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005484 *params = renderbuffer->getSamples();
5485 }
5486 else
5487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005488 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005489 }
5490 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005491 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005492 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005493 }
5494 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005495 }
5496 catch(std::bad_alloc&)
5497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005498 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005499 }
5500}
5501
5502void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5503{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005504 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005505
5506 try
5507 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005508 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005509
5510 if (context)
5511 {
5512 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005513
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005514 if (!shaderObject)
5515 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005516 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005517 }
5518
5519 switch (pname)
5520 {
5521 case GL_SHADER_TYPE:
5522 *params = shaderObject->getType();
5523 return;
5524 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005525 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005526 return;
5527 case GL_COMPILE_STATUS:
5528 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5529 return;
5530 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005531 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005532 return;
5533 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005534 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005535 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005536 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5537 *params = shaderObject->getTranslatedSourceLength();
5538 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005539 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005540 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005541 }
5542 }
5543 }
5544 catch(std::bad_alloc&)
5545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005546 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005547 }
5548}
5549
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005550void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005551{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005552 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 +00005553 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005554
5555 try
5556 {
5557 if (bufsize < 0)
5558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005559 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005560 }
5561
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005562 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005563
5564 if (context)
5565 {
5566 gl::Shader *shaderObject = context->getShader(shader);
5567
5568 if (!shaderObject)
5569 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005570 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005571 }
5572
5573 shaderObject->getInfoLog(bufsize, length, infolog);
5574 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005575 }
5576 catch(std::bad_alloc&)
5577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005578 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005579 }
5580}
5581
5582void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005584 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 +00005585 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005586
5587 try
5588 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005589 switch (shadertype)
5590 {
5591 case GL_VERTEX_SHADER:
5592 case GL_FRAGMENT_SHADER:
5593 break;
5594 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005595 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005596 }
5597
5598 switch (precisiontype)
5599 {
5600 case GL_LOW_FLOAT:
5601 case GL_MEDIUM_FLOAT:
5602 case GL_HIGH_FLOAT:
5603 // Assume IEEE 754 precision
5604 range[0] = 127;
5605 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005606 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005607 break;
5608 case GL_LOW_INT:
5609 case GL_MEDIUM_INT:
5610 case GL_HIGH_INT:
5611 // Some (most) hardware only supports single-precision floating-point numbers,
5612 // which can accurately represent integers up to +/-16777216
5613 range[0] = 24;
5614 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005615 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005616 break;
5617 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005618 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005619 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005620 }
5621 catch(std::bad_alloc&)
5622 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005623 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005624 }
5625}
5626
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005627void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005628{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005629 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 +00005630 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005631
5632 try
5633 {
5634 if (bufsize < 0)
5635 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005636 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005637 }
5638
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005639 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005640
5641 if (context)
5642 {
5643 gl::Shader *shaderObject = context->getShader(shader);
5644
5645 if (!shaderObject)
5646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005647 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005648 }
5649
5650 shaderObject->getSource(bufsize, length, source);
5651 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005652 }
5653 catch(std::bad_alloc&)
5654 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005655 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005656 }
5657}
5658
zmo@google.coma574f782011-10-03 21:45:23 +00005659void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5660{
5661 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5662 shader, bufsize, length, source);
5663
5664 try
5665 {
5666 if (bufsize < 0)
5667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005668 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005669 }
5670
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005671 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005672
5673 if (context)
5674 {
5675 gl::Shader *shaderObject = context->getShader(shader);
5676
5677 if (!shaderObject)
5678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005679 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005680 }
5681
5682 shaderObject->getTranslatedSource(bufsize, length, source);
5683 }
5684 }
5685 catch(std::bad_alloc&)
5686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005687 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005688 }
5689}
5690
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005691const GLubyte* __stdcall glGetString(GLenum name)
5692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005693 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005694
5695 try
5696 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005697 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005698
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005699 switch (name)
5700 {
5701 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005702 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005703 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005704 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005705 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005706 if (context->getClientVersion() == 2)
5707 {
5708 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5709 }
5710 else
5711 {
5712 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5713 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005714 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005715 if (context->getClientVersion() == 2)
5716 {
5717 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5718 }
5719 else
5720 {
5721 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5722 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005723 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005724 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005725 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005726 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005727 }
5728 }
5729 catch(std::bad_alloc&)
5730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005731 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005732 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005733}
5734
5735void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5736{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005737 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 +00005738
5739 try
5740 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005741 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005742
5743 if (context)
5744 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005745 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005746
Jamie Madillfb8a8302013-07-03 14:24:12 -04005747 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005748 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005749 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005750 }
5751
5752 switch (pname)
5753 {
5754 case GL_TEXTURE_MAG_FILTER:
5755 *params = (GLfloat)texture->getMagFilter();
5756 break;
5757 case GL_TEXTURE_MIN_FILTER:
5758 *params = (GLfloat)texture->getMinFilter();
5759 break;
5760 case GL_TEXTURE_WRAP_S:
5761 *params = (GLfloat)texture->getWrapS();
5762 break;
5763 case GL_TEXTURE_WRAP_T:
5764 *params = (GLfloat)texture->getWrapT();
5765 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005766 case GL_TEXTURE_WRAP_R:
5767 if (context->getClientVersion() < 3)
5768 {
5769 return gl::error(GL_INVALID_ENUM);
5770 }
5771 *params = (GLfloat)texture->getWrapR();
5772 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005773 case GL_TEXTURE_IMMUTABLE_FORMAT:
5774 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005775 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5776 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005777 case GL_TEXTURE_IMMUTABLE_LEVELS:
5778 if (context->getClientVersion() < 3)
5779 {
5780 return gl::error(GL_INVALID_ENUM);
5781 }
5782 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5783 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005784 case GL_TEXTURE_USAGE_ANGLE:
5785 *params = (GLfloat)texture->getUsage();
5786 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005787 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5788 if (!context->supportsTextureFilterAnisotropy())
5789 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005790 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005791 }
5792 *params = (GLfloat)texture->getMaxAnisotropy();
5793 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005794 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005795 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005796 }
5797 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005798 }
5799 catch(std::bad_alloc&)
5800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005801 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005802 }
5803}
5804
5805void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5806{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005807 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 +00005808
5809 try
5810 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005811 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005812
5813 if (context)
5814 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005815 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005816
Jamie Madillfb8a8302013-07-03 14:24:12 -04005817 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005819 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005820 }
5821
5822 switch (pname)
5823 {
5824 case GL_TEXTURE_MAG_FILTER:
5825 *params = texture->getMagFilter();
5826 break;
5827 case GL_TEXTURE_MIN_FILTER:
5828 *params = texture->getMinFilter();
5829 break;
5830 case GL_TEXTURE_WRAP_S:
5831 *params = texture->getWrapS();
5832 break;
5833 case GL_TEXTURE_WRAP_T:
5834 *params = texture->getWrapT();
5835 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005836 case GL_TEXTURE_WRAP_R:
5837 if (context->getClientVersion() < 3)
5838 {
5839 return gl::error(GL_INVALID_ENUM);
5840 }
5841 *params = texture->getWrapR();
5842 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005843 case GL_TEXTURE_IMMUTABLE_FORMAT:
5844 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005845 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5846 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005847 case GL_TEXTURE_IMMUTABLE_LEVELS:
5848 if (context->getClientVersion() < 3)
5849 {
5850 return gl::error(GL_INVALID_ENUM);
5851 }
5852 *params = texture->isImmutable() ? texture->levelCount() : 0;
5853 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005854 case GL_TEXTURE_USAGE_ANGLE:
5855 *params = texture->getUsage();
5856 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005857 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5858 if (!context->supportsTextureFilterAnisotropy())
5859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005860 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005861 }
5862 *params = (GLint)texture->getMaxAnisotropy();
5863 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005864
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005865 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005866 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005867 }
5868 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005869 }
5870 catch(std::bad_alloc&)
5871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005872 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005873 }
5874}
5875
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005876void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5877{
5878 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5879 program, location, bufSize, params);
5880
5881 try
5882 {
5883 if (bufSize < 0)
5884 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005885 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005886 }
5887
5888 gl::Context *context = gl::getNonLostContext();
5889
5890 if (context)
5891 {
5892 if (program == 0)
5893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005894 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005895 }
5896
5897 gl::Program *programObject = context->getProgram(program);
5898
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005899 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005901 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005902 }
5903
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005904 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5905 if (!programBinary)
5906 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005907 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005908 }
5909
5910 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005912 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005913 }
5914 }
5915 }
5916 catch(std::bad_alloc&)
5917 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005918 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005919 }
5920}
5921
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005922void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5923{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005924 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005925
5926 try
5927 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005928 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005929
5930 if (context)
5931 {
5932 if (program == 0)
5933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005934 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005935 }
5936
5937 gl::Program *programObject = context->getProgram(program);
5938
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005939 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005941 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005942 }
5943
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005944 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5945 if (!programBinary)
5946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005947 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005948 }
5949
5950 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005952 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005953 }
5954 }
5955 }
5956 catch(std::bad_alloc&)
5957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005958 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005959 }
5960}
5961
5962void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5963{
5964 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5965 program, location, bufSize, params);
5966
5967 try
5968 {
5969 if (bufSize < 0)
5970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005971 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005972 }
5973
5974 gl::Context *context = gl::getNonLostContext();
5975
5976 if (context)
5977 {
5978 if (program == 0)
5979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005980 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005981 }
5982
5983 gl::Program *programObject = context->getProgram(program);
5984
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005985 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005987 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005988 }
5989
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005990 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5991 if (!programBinary)
5992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005993 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005994 }
5995
5996 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005997 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005998 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005999 }
6000 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006001 }
6002 catch(std::bad_alloc&)
6003 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006004 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006005 }
6006}
6007
6008void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
6009{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006010 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006011
6012 try
6013 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006014 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006015
6016 if (context)
6017 {
6018 if (program == 0)
6019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006020 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006021 }
6022
6023 gl::Program *programObject = context->getProgram(program);
6024
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006025 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006027 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006028 }
6029
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006030 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6031 if (!programBinary)
6032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006033 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006034 }
6035
6036 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006038 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006039 }
6040 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006041 }
6042 catch(std::bad_alloc&)
6043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006044 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006045 }
6046}
6047
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006048int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006050 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006051
6052 try
6053 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006054 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006055
6056 if (strstr(name, "gl_") == name)
6057 {
6058 return -1;
6059 }
6060
6061 if (context)
6062 {
6063 gl::Program *programObject = context->getProgram(program);
6064
6065 if (!programObject)
6066 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006067 if (context->getShader(program))
6068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006069 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006070 }
6071 else
6072 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006073 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006074 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006075 }
6076
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006077 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006078 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006080 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006081 }
6082
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006083 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006084 }
6085 }
6086 catch(std::bad_alloc&)
6087 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006088 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006089 }
6090
6091 return -1;
6092}
6093
6094void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6095{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006096 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006097
6098 try
6099 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006101
daniel@transgaming.come0078962010-04-15 20:45:08 +00006102 if (context)
6103 {
6104 if (index >= gl::MAX_VERTEX_ATTRIBS)
6105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006106 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006107 }
6108
daniel@transgaming.com83921382011-01-08 05:46:00 +00006109 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006110
Jamie Madillaff71502013-07-02 11:57:05 -04006111 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006112 {
Jamie Madillaff71502013-07-02 11:57:05 -04006113 return;
6114 }
6115
6116 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6117 {
6118 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6119 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006120 {
Jamie Madillaff71502013-07-02 11:57:05 -04006121 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006122 }
Jamie Madillaff71502013-07-02 11:57:05 -04006123 }
6124 else
6125 {
6126 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006127 }
6128 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006129 }
6130 catch(std::bad_alloc&)
6131 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006132 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006133 }
6134}
6135
6136void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6137{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006138 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006139
6140 try
6141 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006142 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006143
daniel@transgaming.come0078962010-04-15 20:45:08 +00006144 if (context)
6145 {
6146 if (index >= gl::MAX_VERTEX_ATTRIBS)
6147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006148 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006149 }
6150
daniel@transgaming.com83921382011-01-08 05:46:00 +00006151 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006152
Jamie Madillaff71502013-07-02 11:57:05 -04006153 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006154 {
Jamie Madillaff71502013-07-02 11:57:05 -04006155 return;
6156 }
6157
6158 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6159 {
6160 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6161 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006162 {
Jamie Madillaff71502013-07-02 11:57:05 -04006163 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006164 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006165 }
Jamie Madillaff71502013-07-02 11:57:05 -04006166 }
6167 else
6168 {
6169 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006170 }
6171 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006172 }
6173 catch(std::bad_alloc&)
6174 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006175 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006176 }
6177}
6178
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006179void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006180{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006181 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006182
6183 try
6184 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006185 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006186
daniel@transgaming.come0078962010-04-15 20:45:08 +00006187 if (context)
6188 {
6189 if (index >= gl::MAX_VERTEX_ATTRIBS)
6190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006191 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006192 }
6193
6194 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006196 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006197 }
6198
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006199 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006200 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006201 }
6202 catch(std::bad_alloc&)
6203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006204 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006205 }
6206}
6207
6208void __stdcall glHint(GLenum target, GLenum mode)
6209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006210 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006211
6212 try
6213 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006214 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006215 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006216 case GL_FASTEST:
6217 case GL_NICEST:
6218 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006219 break;
6220 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006221 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006222 }
6223
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006224 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006225 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006226 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006227 case GL_GENERATE_MIPMAP_HINT:
6228 if (context) context->setGenerateMipmapHint(mode);
6229 break;
6230 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6231 if (context) context->setFragmentShaderDerivativeHint(mode);
6232 break;
6233 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006234 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006235 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006236 }
6237 catch(std::bad_alloc&)
6238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006239 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006240 }
6241}
6242
6243GLboolean __stdcall glIsBuffer(GLuint buffer)
6244{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006245 EVENT("(GLuint buffer = %d)", buffer);
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 && buffer)
6252 {
6253 gl::Buffer *bufferObject = context->getBuffer(buffer);
6254
6255 if (bufferObject)
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
6269GLboolean __stdcall glIsEnabled(GLenum cap)
6270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006271 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006272
6273 try
6274 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006275 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006276
6277 if (context)
6278 {
6279 switch (cap)
6280 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006281 case GL_CULL_FACE: return context->isCullFaceEnabled();
6282 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6283 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6284 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6285 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6286 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6287 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6288 case GL_BLEND: return context->isBlendEnabled();
6289 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006291 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006292 }
6293 }
6294 }
6295 catch(std::bad_alloc&)
6296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006297 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006298 }
6299
6300 return false;
6301}
6302
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006303GLboolean __stdcall glIsFenceNV(GLuint fence)
6304{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006305 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006306
6307 try
6308 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006309 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006310
6311 if (context)
6312 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006313 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006314
6315 if (fenceObject == NULL)
6316 {
6317 return GL_FALSE;
6318 }
6319
6320 return fenceObject->isFence();
6321 }
6322 }
6323 catch(std::bad_alloc&)
6324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006325 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006326 }
6327
6328 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006329}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006330
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006331GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006333 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006334
6335 try
6336 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006338
6339 if (context && framebuffer)
6340 {
6341 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6342
6343 if (framebufferObject)
6344 {
6345 return GL_TRUE;
6346 }
6347 }
6348 }
6349 catch(std::bad_alloc&)
6350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006351 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006352 }
6353
6354 return GL_FALSE;
6355}
6356
6357GLboolean __stdcall glIsProgram(GLuint program)
6358{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006359 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006360
6361 try
6362 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006364
6365 if (context && program)
6366 {
6367 gl::Program *programObject = context->getProgram(program);
6368
6369 if (programObject)
6370 {
6371 return GL_TRUE;
6372 }
6373 }
6374 }
6375 catch(std::bad_alloc&)
6376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006377 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006378 }
6379
6380 return GL_FALSE;
6381}
6382
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006383GLboolean __stdcall glIsQueryEXT(GLuint id)
6384{
6385 EVENT("(GLuint id = %d)", id);
6386
6387 try
6388 {
6389 if (id == 0)
6390 {
6391 return GL_FALSE;
6392 }
6393
6394 gl::Context *context = gl::getNonLostContext();
6395
6396 if (context)
6397 {
6398 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6399
6400 if (queryObject)
6401 {
6402 return GL_TRUE;
6403 }
6404 }
6405 }
6406 catch(std::bad_alloc&)
6407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006408 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006409 }
6410
6411 return GL_FALSE;
6412}
6413
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006414GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6415{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006416 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006417
6418 try
6419 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006420 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006421
6422 if (context && renderbuffer)
6423 {
6424 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6425
6426 if (renderbufferObject)
6427 {
6428 return GL_TRUE;
6429 }
6430 }
6431 }
6432 catch(std::bad_alloc&)
6433 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006434 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006435 }
6436
6437 return GL_FALSE;
6438}
6439
6440GLboolean __stdcall glIsShader(GLuint shader)
6441{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006442 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006443
6444 try
6445 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006446 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006447
6448 if (context && shader)
6449 {
6450 gl::Shader *shaderObject = context->getShader(shader);
6451
6452 if (shaderObject)
6453 {
6454 return GL_TRUE;
6455 }
6456 }
6457 }
6458 catch(std::bad_alloc&)
6459 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006460 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006461 }
6462
6463 return GL_FALSE;
6464}
6465
6466GLboolean __stdcall glIsTexture(GLuint texture)
6467{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006468 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006469
6470 try
6471 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006472 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006473
6474 if (context && texture)
6475 {
6476 gl::Texture *textureObject = context->getTexture(texture);
6477
6478 if (textureObject)
6479 {
6480 return GL_TRUE;
6481 }
6482 }
6483 }
6484 catch(std::bad_alloc&)
6485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006486 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006487 }
6488
6489 return GL_FALSE;
6490}
6491
6492void __stdcall glLineWidth(GLfloat width)
6493{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006494 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006495
6496 try
6497 {
6498 if (width <= 0.0f)
6499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006500 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006501 }
6502
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006503 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006504
6505 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006506 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006507 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006508 }
6509 }
6510 catch(std::bad_alloc&)
6511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006512 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006513 }
6514}
6515
6516void __stdcall glLinkProgram(GLuint program)
6517{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006518 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006519
6520 try
6521 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006522 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006523
6524 if (context)
6525 {
6526 gl::Program *programObject = context->getProgram(program);
6527
6528 if (!programObject)
6529 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006530 if (context->getShader(program))
6531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006532 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006533 }
6534 else
6535 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006536 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006537 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006538 }
6539
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006540 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006541 }
6542 }
6543 catch(std::bad_alloc&)
6544 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006545 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006546 }
6547}
6548
6549void __stdcall glPixelStorei(GLenum pname, GLint param)
6550{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006551 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006552
6553 try
6554 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006555 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006556
6557 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006558 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006559 switch (pname)
6560 {
6561 case GL_UNPACK_ALIGNMENT:
6562 if (param != 1 && param != 2 && param != 4 && param != 8)
6563 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006564 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006565 }
6566
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006567 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006568 break;
6569
6570 case GL_PACK_ALIGNMENT:
6571 if (param != 1 && param != 2 && param != 4 && param != 8)
6572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006573 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006574 }
6575
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006576 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006577 break;
6578
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006579 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6580 context->setPackReverseRowOrder(param != 0);
6581 break;
6582
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006583 case GL_UNPACK_IMAGE_HEIGHT:
6584 case GL_UNPACK_SKIP_IMAGES:
6585 case GL_UNPACK_ROW_LENGTH:
6586 case GL_UNPACK_SKIP_ROWS:
6587 case GL_UNPACK_SKIP_PIXELS:
6588 case GL_PACK_ROW_LENGTH:
6589 case GL_PACK_SKIP_ROWS:
6590 case GL_PACK_SKIP_PIXELS:
6591 if (context->getClientVersion() < 3)
6592 {
6593 return gl::error(GL_INVALID_ENUM);
6594 }
6595 UNIMPLEMENTED();
6596 break;
6597
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006598 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006599 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006600 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006601 }
6602 }
6603 catch(std::bad_alloc&)
6604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006606 }
6607}
6608
6609void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006611 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006612
6613 try
6614 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006615 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006616
6617 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006618 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006619 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006620 }
6621 }
6622 catch(std::bad_alloc&)
6623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006624 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006625 }
6626}
6627
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006628void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6629 GLenum format, GLenum type, GLsizei bufSize,
6630 GLvoid *data)
6631{
6632 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6633 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6634 x, y, width, height, format, type, bufSize, data);
6635
6636 try
6637 {
6638 if (width < 0 || height < 0 || bufSize < 0)
6639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006640 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006641 }
6642
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006643 gl::Context *context = gl::getNonLostContext();
6644
6645 if (context)
6646 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006647 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006648 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006649
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006650 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6651 // and attempting to read back if that's the case is an error. The error will be registered
6652 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006653 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006654 return;
6655
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006656 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6657 validES3ReadFormatType(currentInternalFormat, format, type);
6658
6659 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006661 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006662 }
6663
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006664 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6665 }
6666 }
6667 catch(std::bad_alloc&)
6668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006669 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006670 }
6671}
6672
6673void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6674 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006675{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006676 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006677 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006678 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006679
6680 try
6681 {
6682 if (width < 0 || height < 0)
6683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006685 }
6686
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006687 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006688
6689 if (context)
6690 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006691 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006692 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006693
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006694 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6695 // and attempting to read back if that's the case is an error. The error will be registered
6696 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006697 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006698 return;
6699
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006700 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6701 validES3ReadFormatType(currentInternalFormat, format, type);
6702
6703 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006704 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006705 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006706 }
6707
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006708 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006709 }
6710 }
6711 catch(std::bad_alloc&)
6712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006713 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006714 }
6715}
6716
6717void __stdcall glReleaseShaderCompiler(void)
6718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006719 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006720
6721 try
6722 {
6723 gl::Shader::releaseCompiler();
6724 }
6725 catch(std::bad_alloc&)
6726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006727 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006728 }
6729}
6730
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006731void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006732{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006733 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 +00006734 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006735
6736 try
6737 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006738 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006739
6740 if (context)
6741 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006742 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6743 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006744 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006745 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006746 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006747
6748 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006749 }
6750 }
6751 catch(std::bad_alloc&)
6752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006753 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006754 }
6755}
6756
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006757void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6758{
6759 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6760}
6761
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006762void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6763{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006764 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006765
6766 try
6767 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006768 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006769
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006770 if (context)
6771 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006772 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006773 }
6774 }
6775 catch(std::bad_alloc&)
6776 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006777 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006778 }
6779}
6780
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006781void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6782{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006783 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006784
6785 try
6786 {
6787 if (condition != GL_ALL_COMPLETED_NV)
6788 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006789 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006790 }
6791
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006792 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006793
6794 if (context)
6795 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006796 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006797
6798 if (fenceObject == NULL)
6799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006800 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006801 }
6802
6803 fenceObject->setFence(condition);
6804 }
6805 }
6806 catch(std::bad_alloc&)
6807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006808 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006809 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006810}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006811
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006812void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6813{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006814 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 +00006815
6816 try
6817 {
6818 if (width < 0 || height < 0)
6819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006820 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006821 }
6822
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006823 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006824
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006825 if (context)
6826 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006827 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006828 }
6829 }
6830 catch(std::bad_alloc&)
6831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006832 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006833 }
6834}
6835
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006836void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006837{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006838 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006839 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006840 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006841
6842 try
6843 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006844 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006845 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006846 }
6847 catch(std::bad_alloc&)
6848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006849 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006850 }
6851}
6852
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006853void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006854{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006855 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 +00006856 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006857
6858 try
6859 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006860 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006861 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006862 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006863 }
6864
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006865 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006866
6867 if (context)
6868 {
6869 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006870
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006871 if (!shaderObject)
6872 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006873 if (context->getProgram(shader))
6874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006875 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006876 }
6877 else
6878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006879 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006880 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006881 }
6882
6883 shaderObject->setSource(count, string, length);
6884 }
6885 }
6886 catch(std::bad_alloc&)
6887 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006888 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006889 }
6890}
6891
6892void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6893{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006894 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006895}
6896
6897void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006899 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 +00006900
6901 try
6902 {
6903 switch (face)
6904 {
6905 case GL_FRONT:
6906 case GL_BACK:
6907 case GL_FRONT_AND_BACK:
6908 break;
6909 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006910 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006911 }
6912
6913 switch (func)
6914 {
6915 case GL_NEVER:
6916 case GL_ALWAYS:
6917 case GL_LESS:
6918 case GL_LEQUAL:
6919 case GL_EQUAL:
6920 case GL_GEQUAL:
6921 case GL_GREATER:
6922 case GL_NOTEQUAL:
6923 break;
6924 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006925 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006926 }
6927
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006928 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006929
6930 if (context)
6931 {
6932 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6933 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006934 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006935 }
6936
6937 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6938 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006939 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006940 }
6941 }
6942 }
6943 catch(std::bad_alloc&)
6944 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006945 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006946 }
6947}
6948
6949void __stdcall glStencilMask(GLuint mask)
6950{
6951 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6952}
6953
6954void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006956 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006957
6958 try
6959 {
6960 switch (face)
6961 {
6962 case GL_FRONT:
6963 case GL_BACK:
6964 case GL_FRONT_AND_BACK:
6965 break;
6966 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006967 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006968 }
6969
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006970 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006971
6972 if (context)
6973 {
6974 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6975 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006976 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006977 }
6978
6979 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6980 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006981 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006982 }
6983 }
6984 }
6985 catch(std::bad_alloc&)
6986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006987 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006988 }
6989}
6990
6991void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6992{
6993 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6994}
6995
6996void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6997{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006998 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 +00006999 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007000
7001 try
7002 {
7003 switch (face)
7004 {
7005 case GL_FRONT:
7006 case GL_BACK:
7007 case GL_FRONT_AND_BACK:
7008 break;
7009 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007010 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007011 }
7012
7013 switch (fail)
7014 {
7015 case GL_ZERO:
7016 case GL_KEEP:
7017 case GL_REPLACE:
7018 case GL_INCR:
7019 case GL_DECR:
7020 case GL_INVERT:
7021 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007022 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007023 break;
7024 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007025 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007026 }
7027
7028 switch (zfail)
7029 {
7030 case GL_ZERO:
7031 case GL_KEEP:
7032 case GL_REPLACE:
7033 case GL_INCR:
7034 case GL_DECR:
7035 case GL_INVERT:
7036 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007037 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007038 break;
7039 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007040 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007041 }
7042
7043 switch (zpass)
7044 {
7045 case GL_ZERO:
7046 case GL_KEEP:
7047 case GL_REPLACE:
7048 case GL_INCR:
7049 case GL_DECR:
7050 case GL_INVERT:
7051 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007052 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007053 break;
7054 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007055 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007056 }
7057
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007058 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007059
7060 if (context)
7061 {
7062 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7063 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007064 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007065 }
7066
7067 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7068 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007069 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007070 }
7071 }
7072 }
7073 catch(std::bad_alloc&)
7074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007075 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007076 }
7077}
7078
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007079GLboolean __stdcall glTestFenceNV(GLuint fence)
7080{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007081 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007082
7083 try
7084 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007085 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007086
7087 if (context)
7088 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007089 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007090
7091 if (fenceObject == NULL)
7092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007093 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007094 }
7095
Jamie Madillfb9a7402013-07-26 11:55:01 -04007096 if (fenceObject->isFence() != GL_TRUE)
7097 {
7098 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
7099 }
7100
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007101 return fenceObject->testFence();
7102 }
7103 }
7104 catch(std::bad_alloc&)
7105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007106 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007107 }
7108
7109 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007110}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007111
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007112void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7113 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007114{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007115 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 +00007116 "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 +00007117 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007118
7119 try
7120 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007121 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007122
7123 if (context)
7124 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007125 if (context->getClientVersion() < 3 &&
7126 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7127 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007128 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007129 return;
7130 }
7131
7132 if (context->getClientVersion() >= 3 &&
7133 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7134 0, 0, 0, width, height, 1, border, format, type))
7135 {
7136 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007137 }
7138
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007139 switch (target)
7140 {
7141 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007142 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007143 gl::Texture2D *texture = context->getTexture2D();
7144 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007145 }
7146 break;
7147 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007148 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007149 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007150 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007151 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007152 break;
7153 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7154 {
7155 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7156 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7157 }
7158 break;
7159 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7160 {
7161 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7162 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7163 }
7164 break;
7165 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7166 {
7167 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7168 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7169 }
7170 break;
7171 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7172 {
7173 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7174 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7175 }
7176 break;
7177 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7178 {
7179 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7180 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7181 }
7182 break;
7183 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007184 }
7185 }
7186 }
7187 catch(std::bad_alloc&)
7188 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007189 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007190 }
7191}
7192
7193void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7194{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007195 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7196
7197 try
7198 {
7199 gl::Context *context = gl::getNonLostContext();
7200
7201 if (context)
7202 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007203 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7204 {
7205 return;
7206 }
7207
Jamie Madillfb8a8302013-07-03 14:24:12 -04007208 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007209
Jamie Madillfb8a8302013-07-03 14:24:12 -04007210 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007212 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007213 }
7214
7215 switch (pname)
7216 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007217 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7218 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7219 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7220 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7221 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7222 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7223 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7224 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7225 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007226
Jamie Madill478fdb22013-07-19 16:36:59 -04007227 case GL_TEXTURE_SWIZZLE_R:
7228 case GL_TEXTURE_SWIZZLE_G:
7229 case GL_TEXTURE_SWIZZLE_B:
7230 case GL_TEXTURE_SWIZZLE_A:
7231 case GL_TEXTURE_BASE_LEVEL:
7232 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007233 case GL_TEXTURE_MIN_LOD:
7234 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007235 UNIMPLEMENTED();
7236 break;
7237
Jamie Madill478fdb22013-07-19 16:36:59 -04007238 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007239 }
7240 }
7241 }
7242 catch(std::bad_alloc&)
7243 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007244 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007245 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007246}
7247
7248void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7249{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007250 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007251}
7252
7253void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7254{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007255 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007256
7257 try
7258 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007259 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007260
7261 if (context)
7262 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007263 if (!validateTexParamParameters(context, pname, param))
7264 {
7265 return;
7266 }
7267
Jamie Madillfb8a8302013-07-03 14:24:12 -04007268 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007269
Jamie Madillfb8a8302013-07-03 14:24:12 -04007270 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007272 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007273 }
7274
7275 switch (pname)
7276 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007277 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7278 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7279 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7280 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7281 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7282 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7283 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7284 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7285 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007286
7287 case GL_TEXTURE_SWIZZLE_R:
7288 case GL_TEXTURE_SWIZZLE_G:
7289 case GL_TEXTURE_SWIZZLE_B:
7290 case GL_TEXTURE_SWIZZLE_A:
7291 case GL_TEXTURE_BASE_LEVEL:
7292 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007293 case GL_TEXTURE_MIN_LOD:
7294 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007295 UNIMPLEMENTED();
7296 break;
7297
Jamie Madill478fdb22013-07-19 16:36:59 -04007298 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007299 }
7300 }
7301 }
7302 catch(std::bad_alloc&)
7303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007304 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007305 }
7306}
7307
7308void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7309{
7310 glTexParameteri(target, pname, *params);
7311}
7312
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007313void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7314{
7315 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7316 target, levels, internalformat, width, height);
7317
7318 try
7319 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007320 gl::Context *context = gl::getNonLostContext();
7321
7322 if (context)
7323 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007324 if (context->getClientVersion() < 3 &&
7325 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007326 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007327 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007328 }
7329
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007330 if (context->getClientVersion() >= 3 &&
7331 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007332 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007333 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007334 }
7335
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007336 switch (target)
7337 {
7338 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007339 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007340 gl::Texture2D *texture2d = context->getTexture2D();
7341 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007342 }
7343 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007344
7345 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7346 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7347 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7348 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7349 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7350 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007351 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007352 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7353 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007354 }
7355 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007356
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007357 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007358 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007359 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007360 }
7361 }
7362 catch(std::bad_alloc&)
7363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007364 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007365 }
7366}
7367
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007368void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7369 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007370{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007371 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007372 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007373 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007374 target, level, xoffset, yoffset, width, height, format, type, pixels);
7375
7376 try
7377 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007378 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007379
7380 if (context)
7381 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007382 if (context->getClientVersion() < 3 &&
7383 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7384 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007385 {
7386 return;
7387 }
7388
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007389 if (context->getClientVersion() >= 3 &&
7390 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7391 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007392 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007393 return;
7394 }
7395
7396 switch (target)
7397 {
7398 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007399 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007400 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007401 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007402 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007403 break;
7404
7405 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7406 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7407 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7408 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7409 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7410 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007411 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007412 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007413 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007414 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007415 break;
7416
7417 default:
7418 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007419 }
7420 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007421 }
7422 catch(std::bad_alloc&)
7423 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007424 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007425 }
7426}
7427
7428void __stdcall glUniform1f(GLint location, GLfloat x)
7429{
7430 glUniform1fv(location, 1, &x);
7431}
7432
7433void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7434{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007435 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007436
7437 try
7438 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007439 if (count < 0)
7440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007441 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007442 }
7443
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007444 if (location == -1)
7445 {
7446 return;
7447 }
7448
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007449 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007450
7451 if (context)
7452 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007453 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007454 if (!programBinary)
7455 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007456 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007457 }
7458
7459 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007460 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007461 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007462 }
7463 }
7464 }
7465 catch(std::bad_alloc&)
7466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007467 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007468 }
7469}
7470
7471void __stdcall glUniform1i(GLint location, GLint x)
7472{
7473 glUniform1iv(location, 1, &x);
7474}
7475
7476void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7477{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007478 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007479
7480 try
7481 {
7482 if (count < 0)
7483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007484 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007485 }
7486
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007487 if (location == -1)
7488 {
7489 return;
7490 }
7491
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007492 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007493
7494 if (context)
7495 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007496 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007497 if (!programBinary)
7498 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007499 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007500 }
7501
7502 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007503 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007504 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007505 }
7506 }
7507 }
7508 catch(std::bad_alloc&)
7509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007510 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007511 }
7512}
7513
7514void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7515{
7516 GLfloat xy[2] = {x, y};
7517
7518 glUniform2fv(location, 1, (GLfloat*)&xy);
7519}
7520
7521void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007523 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007524
7525 try
7526 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007527 if (count < 0)
7528 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007529 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007530 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007531
7532 if (location == -1)
7533 {
7534 return;
7535 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007536
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007537 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007538
7539 if (context)
7540 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007541 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007542 if (!programBinary)
7543 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007544 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007545 }
7546
7547 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007549 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007550 }
7551 }
7552 }
7553 catch(std::bad_alloc&)
7554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007555 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007556 }
7557}
7558
7559void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7560{
7561 GLint xy[4] = {x, y};
7562
7563 glUniform2iv(location, 1, (GLint*)&xy);
7564}
7565
7566void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7567{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007568 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007569
7570 try
7571 {
7572 if (count < 0)
7573 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007574 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007575 }
7576
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007577 if (location == -1)
7578 {
7579 return;
7580 }
7581
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007582 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007583
7584 if (context)
7585 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007586 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007587 if (!programBinary)
7588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007589 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007590 }
7591
7592 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007594 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007595 }
7596 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007597 }
7598 catch(std::bad_alloc&)
7599 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007600 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007601 }
7602}
7603
7604void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7605{
7606 GLfloat xyz[3] = {x, y, z};
7607
7608 glUniform3fv(location, 1, (GLfloat*)&xyz);
7609}
7610
7611void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7612{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007613 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007614
7615 try
7616 {
7617 if (count < 0)
7618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007619 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007620 }
7621
7622 if (location == -1)
7623 {
7624 return;
7625 }
7626
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007627 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007628
7629 if (context)
7630 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007631 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007632 if (!programBinary)
7633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007634 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007635 }
7636
7637 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007639 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007640 }
7641 }
7642 }
7643 catch(std::bad_alloc&)
7644 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007645 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007646 }
7647}
7648
7649void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7650{
7651 GLint xyz[3] = {x, y, z};
7652
7653 glUniform3iv(location, 1, (GLint*)&xyz);
7654}
7655
7656void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7657{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007658 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007659
7660 try
7661 {
7662 if (count < 0)
7663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007664 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007665 }
7666
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007667 if (location == -1)
7668 {
7669 return;
7670 }
7671
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007673
7674 if (context)
7675 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007676 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007677 if (!programBinary)
7678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007679 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007680 }
7681
7682 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007684 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007685 }
7686 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007687 }
7688 catch(std::bad_alloc&)
7689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007690 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007691 }
7692}
7693
7694void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7695{
7696 GLfloat xyzw[4] = {x, y, z, w};
7697
7698 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7699}
7700
7701void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7702{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007703 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007704
7705 try
7706 {
7707 if (count < 0)
7708 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007709 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007710 }
7711
7712 if (location == -1)
7713 {
7714 return;
7715 }
7716
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007717 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007718
7719 if (context)
7720 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007721 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007722 if (!programBinary)
7723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007724 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007725 }
7726
7727 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007729 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007730 }
7731 }
7732 }
7733 catch(std::bad_alloc&)
7734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007735 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007736 }
7737}
7738
7739void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7740{
7741 GLint xyzw[4] = {x, y, z, w};
7742
7743 glUniform4iv(location, 1, (GLint*)&xyzw);
7744}
7745
7746void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7747{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007748 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007749
7750 try
7751 {
7752 if (count < 0)
7753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007754 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007755 }
7756
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007757 if (location == -1)
7758 {
7759 return;
7760 }
7761
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007762 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007763
7764 if (context)
7765 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007766 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007767 if (!programBinary)
7768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007769 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007770 }
7771
7772 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007774 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007775 }
7776 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007777 }
7778 catch(std::bad_alloc&)
7779 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007780 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007781 }
7782}
7783
7784void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7785{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007786 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007787 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007788
7789 try
7790 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007791 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007793 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007794 }
7795
7796 if (location == -1)
7797 {
7798 return;
7799 }
7800
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007801 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007802
7803 if (context)
7804 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007805 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7806 {
7807 return gl::error(GL_INVALID_VALUE);
7808 }
7809
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007810 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007811 if (!programBinary)
7812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007813 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007814 }
7815
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007816 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007818 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007819 }
7820 }
7821 }
7822 catch(std::bad_alloc&)
7823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007824 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007825 }
7826}
7827
7828void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7829{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007830 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007831 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007832
7833 try
7834 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007835 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007837 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007838 }
7839
7840 if (location == -1)
7841 {
7842 return;
7843 }
7844
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007845 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007846
7847 if (context)
7848 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007849 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7850 {
7851 return gl::error(GL_INVALID_VALUE);
7852 }
7853
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007854 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007855 if (!programBinary)
7856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007857 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007858 }
7859
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007860 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007861 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007862 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007863 }
7864 }
7865 }
7866 catch(std::bad_alloc&)
7867 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007868 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007869 }
7870}
7871
7872void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7873{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007874 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007875 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007876
7877 try
7878 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007879 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007881 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007882 }
7883
7884 if (location == -1)
7885 {
7886 return;
7887 }
7888
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007889 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007890
7891 if (context)
7892 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007893 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7894 {
7895 return gl::error(GL_INVALID_VALUE);
7896 }
7897
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007898 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007899 if (!programBinary)
7900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007901 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007902 }
7903
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007904 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007906 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007907 }
7908 }
7909 }
7910 catch(std::bad_alloc&)
7911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007912 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007913 }
7914}
7915
7916void __stdcall glUseProgram(GLuint program)
7917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007918 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007919
7920 try
7921 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007922 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007923
7924 if (context)
7925 {
7926 gl::Program *programObject = context->getProgram(program);
7927
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007928 if (!programObject && program != 0)
7929 {
7930 if (context->getShader(program))
7931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007932 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007933 }
7934 else
7935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007936 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007937 }
7938 }
7939
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007940 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007941 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007942 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007943 }
7944
7945 context->useProgram(program);
7946 }
7947 }
7948 catch(std::bad_alloc&)
7949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007951 }
7952}
7953
7954void __stdcall glValidateProgram(GLuint program)
7955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007956 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007957
7958 try
7959 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007961
7962 if (context)
7963 {
7964 gl::Program *programObject = context->getProgram(program);
7965
7966 if (!programObject)
7967 {
7968 if (context->getShader(program))
7969 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007970 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007971 }
7972 else
7973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007974 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007975 }
7976 }
7977
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007978 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007979 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007980 }
7981 catch(std::bad_alloc&)
7982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007983 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007984 }
7985}
7986
7987void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7988{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007989 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007990
7991 try
7992 {
7993 if (index >= gl::MAX_VERTEX_ATTRIBS)
7994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007995 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007996 }
7997
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007998 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007999
8000 if (context)
8001 {
8002 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008003 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008004 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008005 }
8006 catch(std::bad_alloc&)
8007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008008 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008009 }
8010}
8011
8012void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
8013{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008014 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008015
8016 try
8017 {
8018 if (index >= gl::MAX_VERTEX_ATTRIBS)
8019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008020 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008021 }
8022
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008023 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008024
8025 if (context)
8026 {
8027 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008028 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008029 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008030 }
8031 catch(std::bad_alloc&)
8032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008033 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008034 }
8035}
8036
8037void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008039 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008040
8041 try
8042 {
8043 if (index >= gl::MAX_VERTEX_ATTRIBS)
8044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008045 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008046 }
8047
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008048 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008049
8050 if (context)
8051 {
8052 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008053 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008054 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008055 }
8056 catch(std::bad_alloc&)
8057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008058 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008059 }
8060}
8061
8062void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8063{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008064 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008065
8066 try
8067 {
8068 if (index >= gl::MAX_VERTEX_ATTRIBS)
8069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008070 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008071 }
8072
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008073 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008074
8075 if (context)
8076 {
8077 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008078 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008079 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008080 }
8081 catch(std::bad_alloc&)
8082 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008083 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008084 }
8085}
8086
8087void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8088{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008089 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 +00008090
8091 try
8092 {
8093 if (index >= gl::MAX_VERTEX_ATTRIBS)
8094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008095 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008096 }
8097
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008098 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008099
8100 if (context)
8101 {
8102 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008103 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008104 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008105 }
8106 catch(std::bad_alloc&)
8107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008108 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008109 }
8110}
8111
8112void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8113{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008114 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008115
8116 try
8117 {
8118 if (index >= gl::MAX_VERTEX_ATTRIBS)
8119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008120 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008121 }
8122
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008123 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008124
8125 if (context)
8126 {
8127 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008128 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008129 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008130 }
8131 catch(std::bad_alloc&)
8132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008133 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008134 }
8135}
8136
8137void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8138{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008139 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 +00008140
8141 try
8142 {
8143 if (index >= gl::MAX_VERTEX_ATTRIBS)
8144 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008145 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008146 }
8147
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008148 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008149
8150 if (context)
8151 {
8152 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008153 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008154 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008155 }
8156 catch(std::bad_alloc&)
8157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008158 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008159 }
8160}
8161
8162void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8163{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008164 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008165
8166 try
8167 {
8168 if (index >= gl::MAX_VERTEX_ATTRIBS)
8169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008170 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008171 }
8172
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008173 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008174
8175 if (context)
8176 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008177 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008178 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008179 }
8180 catch(std::bad_alloc&)
8181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008182 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008183 }
8184}
8185
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008186void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8187{
8188 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8189
8190 try
8191 {
8192 if (index >= gl::MAX_VERTEX_ATTRIBS)
8193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008194 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008195 }
8196
8197 gl::Context *context = gl::getNonLostContext();
8198
8199 if (context)
8200 {
8201 context->setVertexAttribDivisor(index, divisor);
8202 }
8203 }
8204 catch(std::bad_alloc&)
8205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008206 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008207 }
8208}
8209
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008210void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008211{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008212 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008213 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008214 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008215
8216 try
8217 {
8218 if (index >= gl::MAX_VERTEX_ATTRIBS)
8219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008220 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008221 }
8222
8223 if (size < 1 || size > 4)
8224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008225 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008226 }
8227
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008228 gl::Context *context = gl::getNonLostContext();
8229
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008230 switch (type)
8231 {
8232 case GL_BYTE:
8233 case GL_UNSIGNED_BYTE:
8234 case GL_SHORT:
8235 case GL_UNSIGNED_SHORT:
8236 case GL_FIXED:
8237 case GL_FLOAT:
8238 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008239 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008240 case GL_INT:
8241 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008242 case GL_INT_2_10_10_10_REV:
8243 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008244 if (context && context->getClientVersion() < 3)
8245 {
8246 return gl::error(GL_INVALID_ENUM);
8247 }
8248 else
8249 {
8250 break;
8251 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008252 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008253 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008254 }
8255
8256 if (stride < 0)
8257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008258 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008259 }
8260
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008261 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8262 {
8263 return gl::error(GL_INVALID_OPERATION);
8264 }
8265
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008266 if (context)
8267 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008268 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8269 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8270 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8271 // and the pointer argument is not NULL.
8272 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8273 {
8274 return gl::error(GL_INVALID_OPERATION);
8275 }
8276
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008277 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8278 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008279 }
8280 }
8281 catch(std::bad_alloc&)
8282 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008283 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008284 }
8285}
8286
8287void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8288{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008289 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 +00008290
8291 try
8292 {
8293 if (width < 0 || height < 0)
8294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008295 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008296 }
8297
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008298 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008299
8300 if (context)
8301 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008302 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008303 }
8304 }
8305 catch(std::bad_alloc&)
8306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008307 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008308 }
8309}
8310
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008311// OpenGL ES 3.0 functions
8312
8313void __stdcall glReadBuffer(GLenum mode)
8314{
8315 EVENT("(GLenum mode = 0x%X)", mode);
8316
8317 try
8318 {
8319 gl::Context *context = gl::getNonLostContext();
8320
8321 if (context)
8322 {
8323 if (context->getClientVersion() < 3)
8324 {
8325 return gl::error(GL_INVALID_OPERATION);
8326 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008327
Jamie Madill54133512013-06-21 09:33:07 -04008328 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008329 UNIMPLEMENTED();
8330 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008331 }
8332 catch(std::bad_alloc&)
8333 {
8334 return gl::error(GL_OUT_OF_MEMORY);
8335 }
8336}
8337
8338void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8339{
8340 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8341 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8342
8343 try
8344 {
8345 gl::Context *context = gl::getNonLostContext();
8346
8347 if (context)
8348 {
8349 if (context->getClientVersion() < 3)
8350 {
8351 return gl::error(GL_INVALID_OPERATION);
8352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008353
Jamie Madill54133512013-06-21 09:33:07 -04008354 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008355 UNIMPLEMENTED();
8356 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008357 }
8358 catch(std::bad_alloc&)
8359 {
8360 return gl::error(GL_OUT_OF_MEMORY);
8361 }
8362}
8363
8364void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8365{
8366 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8367 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8368 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8369 target, level, internalformat, width, height, depth, border, format, type, pixels);
8370
8371 try
8372 {
8373 gl::Context *context = gl::getNonLostContext();
8374
8375 if (context)
8376 {
8377 if (context->getClientVersion() < 3)
8378 {
8379 return gl::error(GL_INVALID_OPERATION);
8380 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008381
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008382 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008383 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008384 0, 0, 0, width, height, depth, border, format, type))
8385 {
8386 return;
8387 }
8388
8389 switch(target)
8390 {
8391 case GL_TEXTURE_3D:
8392 {
8393 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008394 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008395 }
8396 break;
8397
8398 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008399 {
8400 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008401 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008402 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008403 break;
8404
8405 default:
8406 return gl::error(GL_INVALID_ENUM);
8407 }
8408 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008409 }
8410 catch(std::bad_alloc&)
8411 {
8412 return gl::error(GL_OUT_OF_MEMORY);
8413 }
8414}
8415
8416void __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)
8417{
8418 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8419 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8420 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8421 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8422
8423 try
8424 {
8425 gl::Context *context = gl::getNonLostContext();
8426
8427 if (context)
8428 {
8429 if (context->getClientVersion() < 3)
8430 {
8431 return gl::error(GL_INVALID_OPERATION);
8432 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008433
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008434 if (!pixels)
8435 {
8436 return gl::error(GL_INVALID_VALUE);
8437 }
8438
8439 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008440 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008441 xoffset, yoffset, zoffset, width, height, depth, 0,
8442 format, type))
8443 {
8444 return;
8445 }
8446
8447 switch(target)
8448 {
8449 case GL_TEXTURE_3D:
8450 {
8451 gl::Texture3D *texture = context->getTexture3D();
8452 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8453 }
8454 break;
8455
8456 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008457 {
8458 gl::Texture2DArray *texture = context->getTexture2DArray();
8459 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8460 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008461 break;
8462
8463 default:
8464 return gl::error(GL_INVALID_ENUM);
8465 }
8466 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008467 }
8468 catch(std::bad_alloc&)
8469 {
8470 return gl::error(GL_OUT_OF_MEMORY);
8471 }
8472}
8473
8474void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8475{
8476 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8477 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8478 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8479
8480 try
8481 {
8482 gl::Context *context = gl::getNonLostContext();
8483
8484 if (context)
8485 {
8486 if (context->getClientVersion() < 3)
8487 {
8488 return gl::error(GL_INVALID_OPERATION);
8489 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008490
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008491 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8492 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008493 {
8494 return;
8495 }
8496
8497 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8498 gl::Texture *texture = NULL;
8499 switch (target)
8500 {
8501 case GL_TEXTURE_3D:
8502 texture = context->getTexture3D();
8503 break;
8504
8505 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008506 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008507 break;
8508
8509 default:
8510 return gl::error(GL_INVALID_ENUM);
8511 }
8512
8513 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8514 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008515 }
8516 catch(std::bad_alloc&)
8517 {
8518 return gl::error(GL_OUT_OF_MEMORY);
8519 }
8520}
8521
8522void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8523{
8524 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8525 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8526 "const GLvoid* data = 0x%0.8p)",
8527 target, level, internalformat, width, height, depth, border, imageSize, data);
8528
8529 try
8530 {
8531 gl::Context *context = gl::getNonLostContext();
8532
8533 if (context)
8534 {
8535 if (context->getClientVersion() < 3)
8536 {
8537 return gl::error(GL_INVALID_OPERATION);
8538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008539
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008540 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 +00008541 {
8542 return gl::error(GL_INVALID_VALUE);
8543 }
8544
8545 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008546 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8547 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008548 {
8549 return;
8550 }
8551
8552 switch(target)
8553 {
8554 case GL_TEXTURE_3D:
8555 {
8556 gl::Texture3D *texture = context->getTexture3D();
8557 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8558 }
8559 break;
8560
8561 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008562 {
8563 gl::Texture2DArray *texture = context->getTexture2DArray();
8564 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8565 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008566 break;
8567
8568 default:
8569 return gl::error(GL_INVALID_ENUM);
8570 }
8571 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008572 }
8573 catch(std::bad_alloc&)
8574 {
8575 return gl::error(GL_OUT_OF_MEMORY);
8576 }
8577}
8578
8579void __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)
8580{
8581 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8582 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8583 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8584 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8585
8586 try
8587 {
8588 gl::Context *context = gl::getNonLostContext();
8589
8590 if (context)
8591 {
8592 if (context->getClientVersion() < 3)
8593 {
8594 return gl::error(GL_INVALID_OPERATION);
8595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008596
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008597 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 +00008598 {
8599 return gl::error(GL_INVALID_VALUE);
8600 }
8601
8602 if (!data)
8603 {
8604 return gl::error(GL_INVALID_VALUE);
8605 }
8606
8607 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008608 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8609 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008610 {
8611 return;
8612 }
8613
8614 switch(target)
8615 {
8616 case GL_TEXTURE_3D:
8617 {
8618 gl::Texture3D *texture = context->getTexture3D();
8619 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8620 format, imageSize, data);
8621 }
8622 break;
8623
8624 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008625 {
8626 gl::Texture2DArray *texture = context->getTexture2DArray();
8627 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8628 format, imageSize, data);
8629 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008630 break;
8631
8632 default:
8633 return gl::error(GL_INVALID_ENUM);
8634 }
8635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008636 }
8637 catch(std::bad_alloc&)
8638 {
8639 return gl::error(GL_OUT_OF_MEMORY);
8640 }
8641}
8642
8643void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8644{
8645 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8646
8647 try
8648 {
8649 gl::Context *context = gl::getNonLostContext();
8650
8651 if (context)
8652 {
8653 if (context->getClientVersion() < 3)
8654 {
8655 return gl::error(GL_INVALID_OPERATION);
8656 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008657
Jamie Madill3641b4b2013-07-26 12:54:59 -04008658 glGenQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008659 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008660 }
8661 catch(std::bad_alloc&)
8662 {
8663 return gl::error(GL_OUT_OF_MEMORY);
8664 }
8665}
8666
8667void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8668{
8669 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8670
8671 try
8672 {
8673 gl::Context *context = gl::getNonLostContext();
8674
8675 if (context)
8676 {
8677 if (context->getClientVersion() < 3)
8678 {
8679 return gl::error(GL_INVALID_OPERATION);
8680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008681
Jamie Madill3641b4b2013-07-26 12:54:59 -04008682 glDeleteQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008683 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008684 }
8685 catch(std::bad_alloc&)
8686 {
8687 return gl::error(GL_OUT_OF_MEMORY);
8688 }
8689}
8690
8691GLboolean __stdcall glIsQuery(GLuint id)
8692{
8693 EVENT("(GLuint id = %u)", id);
8694
8695 try
8696 {
8697 gl::Context *context = gl::getNonLostContext();
8698
8699 if (context)
8700 {
8701 if (context->getClientVersion() < 3)
8702 {
8703 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8704 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008705
Jamie Madill3641b4b2013-07-26 12:54:59 -04008706 // TODO: XFB queries
8707 return glIsQueryEXT(id);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008708 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008709 }
8710 catch(std::bad_alloc&)
8711 {
8712 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8713 }
8714
8715 return GL_FALSE;
8716}
8717
8718void __stdcall glBeginQuery(GLenum target, GLuint id)
8719{
8720 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8721
8722 try
8723 {
8724 gl::Context *context = gl::getNonLostContext();
8725
8726 if (context)
8727 {
8728 if (context->getClientVersion() < 3)
8729 {
8730 return gl::error(GL_INVALID_OPERATION);
8731 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008732
Jamie Madill3641b4b2013-07-26 12:54:59 -04008733 switch (target)
8734 {
8735 case GL_ANY_SAMPLES_PASSED:
8736 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
8737 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
8738 break;
8739 default:
8740 return gl::error(GL_INVALID_ENUM);
8741 }
8742
8743 if (id == 0)
8744 {
8745 return gl::error(GL_INVALID_OPERATION);
8746 }
8747
8748 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8749 {
8750 // TODO: XFB queries
8751 UNIMPLEMENTED();
8752 }
8753 else
8754 {
8755 context->beginQuery(target, id);
8756 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008757 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008758 }
8759 catch(std::bad_alloc&)
8760 {
8761 return gl::error(GL_OUT_OF_MEMORY);
8762 }
8763}
8764
8765void __stdcall glEndQuery(GLenum target)
8766{
8767 EVENT("(GLenum target = 0x%X)", target);
8768
8769 try
8770 {
8771 gl::Context *context = gl::getNonLostContext();
8772
8773 if (context)
8774 {
8775 if (context->getClientVersion() < 3)
8776 {
8777 return gl::error(GL_INVALID_OPERATION);
8778 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008779
Jamie Madill3641b4b2013-07-26 12:54:59 -04008780 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8781 {
8782 // TODO: XFB queries
8783 UNIMPLEMENTED();
8784 }
8785 else
8786 {
8787 glEndQueryEXT(target);
8788 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008789 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008790 }
8791 catch(std::bad_alloc&)
8792 {
8793 return gl::error(GL_OUT_OF_MEMORY);
8794 }
8795}
8796
8797void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8798{
8799 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8800
8801 try
8802 {
8803 gl::Context *context = gl::getNonLostContext();
8804
8805 if (context)
8806 {
8807 if (context->getClientVersion() < 3)
8808 {
8809 return gl::error(GL_INVALID_OPERATION);
8810 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008811
Jamie Madill3641b4b2013-07-26 12:54:59 -04008812 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8813 {
8814 // TODO: XFB queries
8815 UNIMPLEMENTED();
8816 }
8817 else
8818 {
8819 glGetQueryivEXT(target, pname, params);
8820 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008821 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008822 }
8823 catch(std::bad_alloc&)
8824 {
8825 return gl::error(GL_OUT_OF_MEMORY);
8826 }
8827}
8828
8829void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8830{
8831 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8832
8833 try
8834 {
8835 gl::Context *context = gl::getNonLostContext();
8836
8837 if (context)
8838 {
8839 if (context->getClientVersion() < 3)
8840 {
8841 return gl::error(GL_INVALID_OPERATION);
8842 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008843
Jamie Madill3641b4b2013-07-26 12:54:59 -04008844 // TODO: XFB queries
8845 glGetQueryObjectuivEXT(id, pname, params);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008846 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008847 }
8848 catch(std::bad_alloc&)
8849 {
8850 return gl::error(GL_OUT_OF_MEMORY);
8851 }
8852}
8853
8854GLboolean __stdcall glUnmapBuffer(GLenum target)
8855{
8856 EVENT("(GLenum target = 0x%X)", target);
8857
8858 try
8859 {
8860 gl::Context *context = gl::getNonLostContext();
8861
8862 if (context)
8863 {
8864 if (context->getClientVersion() < 3)
8865 {
8866 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8867 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008868
Jamie Madill54133512013-06-21 09:33:07 -04008869 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008870 UNIMPLEMENTED();
8871 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008872 }
8873 catch(std::bad_alloc&)
8874 {
8875 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8876 }
8877
8878 return GL_FALSE;
8879}
8880
8881void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8882{
8883 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8884
8885 try
8886 {
8887 gl::Context *context = gl::getNonLostContext();
8888
8889 if (context)
8890 {
8891 if (context->getClientVersion() < 3)
8892 {
8893 return gl::error(GL_INVALID_OPERATION);
8894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008895
Jamie Madill54133512013-06-21 09:33:07 -04008896 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008897 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008898 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008899 }
8900 catch(std::bad_alloc&)
8901 {
8902 return gl::error(GL_OUT_OF_MEMORY);
8903 }
8904}
8905
8906void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8907{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008908 try
8909 {
8910 gl::Context *context = gl::getNonLostContext();
8911
8912 if (context)
8913 {
8914 if (context->getClientVersion() < 3)
8915 {
8916 return gl::error(GL_INVALID_OPERATION);
8917 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008918
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008919 glDrawBuffersEXT(n, bufs);
8920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008921 }
8922 catch(std::bad_alloc&)
8923 {
8924 return gl::error(GL_OUT_OF_MEMORY);
8925 }
8926}
8927
8928void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8929{
8930 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8931 location, count, transpose, value);
8932
8933 try
8934 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008935 if (count < 0)
8936 {
8937 return gl::error(GL_INVALID_VALUE);
8938 }
8939
8940 if (location == -1)
8941 {
8942 return;
8943 }
8944
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008945 gl::Context *context = gl::getNonLostContext();
8946
8947 if (context)
8948 {
8949 if (context->getClientVersion() < 3)
8950 {
8951 return gl::error(GL_INVALID_OPERATION);
8952 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008953
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008954 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8955 if (!programBinary)
8956 {
8957 return gl::error(GL_INVALID_OPERATION);
8958 }
8959
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008960 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008961 {
8962 return gl::error(GL_INVALID_OPERATION);
8963 }
8964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008965 }
8966 catch(std::bad_alloc&)
8967 {
8968 return gl::error(GL_OUT_OF_MEMORY);
8969 }
8970}
8971
8972void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8973{
8974 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8975 location, count, transpose, value);
8976
8977 try
8978 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008979 if (count < 0)
8980 {
8981 return gl::error(GL_INVALID_VALUE);
8982 }
8983
8984 if (location == -1)
8985 {
8986 return;
8987 }
8988
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008989 gl::Context *context = gl::getNonLostContext();
8990
8991 if (context)
8992 {
8993 if (context->getClientVersion() < 3)
8994 {
8995 return gl::error(GL_INVALID_OPERATION);
8996 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008997
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008998 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8999 if (!programBinary)
9000 {
9001 return gl::error(GL_INVALID_OPERATION);
9002 }
9003
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009004 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009005 {
9006 return gl::error(GL_INVALID_OPERATION);
9007 }
9008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009009 }
9010 catch(std::bad_alloc&)
9011 {
9012 return gl::error(GL_OUT_OF_MEMORY);
9013 }
9014}
9015
9016void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9017{
9018 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9019 location, count, transpose, value);
9020
9021 try
9022 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009023 if (count < 0)
9024 {
9025 return gl::error(GL_INVALID_VALUE);
9026 }
9027
9028 if (location == -1)
9029 {
9030 return;
9031 }
9032
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009033 gl::Context *context = gl::getNonLostContext();
9034
9035 if (context)
9036 {
9037 if (context->getClientVersion() < 3)
9038 {
9039 return gl::error(GL_INVALID_OPERATION);
9040 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009041
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009042 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9043 if (!programBinary)
9044 {
9045 return gl::error(GL_INVALID_OPERATION);
9046 }
9047
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009048 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009049 {
9050 return gl::error(GL_INVALID_OPERATION);
9051 }
9052 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009053 }
9054 catch(std::bad_alloc&)
9055 {
9056 return gl::error(GL_OUT_OF_MEMORY);
9057 }
9058}
9059
9060void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9061{
9062 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9063 location, count, transpose, value);
9064
9065 try
9066 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009067 if (count < 0)
9068 {
9069 return gl::error(GL_INVALID_VALUE);
9070 }
9071
9072 if (location == -1)
9073 {
9074 return;
9075 }
9076
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009077 gl::Context *context = gl::getNonLostContext();
9078
9079 if (context)
9080 {
9081 if (context->getClientVersion() < 3)
9082 {
9083 return gl::error(GL_INVALID_OPERATION);
9084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009085
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009086 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9087 if (!programBinary)
9088 {
9089 return gl::error(GL_INVALID_OPERATION);
9090 }
9091
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009092 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009093 {
9094 return gl::error(GL_INVALID_OPERATION);
9095 }
9096 }
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 glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9105{
9106 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9107 location, count, transpose, value);
9108
9109 try
9110 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009111 if (count < 0)
9112 {
9113 return gl::error(GL_INVALID_VALUE);
9114 }
9115
9116 if (location == -1)
9117 {
9118 return;
9119 }
9120
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009121 gl::Context *context = gl::getNonLostContext();
9122
9123 if (context)
9124 {
9125 if (context->getClientVersion() < 3)
9126 {
9127 return gl::error(GL_INVALID_OPERATION);
9128 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009129
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009130 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9131 if (!programBinary)
9132 {
9133 return gl::error(GL_INVALID_OPERATION);
9134 }
9135
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009136 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009137 {
9138 return gl::error(GL_INVALID_OPERATION);
9139 }
9140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009141 }
9142 catch(std::bad_alloc&)
9143 {
9144 return gl::error(GL_OUT_OF_MEMORY);
9145 }
9146}
9147
9148void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9149{
9150 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9151 location, count, transpose, value);
9152
9153 try
9154 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009155 if (count < 0)
9156 {
9157 return gl::error(GL_INVALID_VALUE);
9158 }
9159
9160 if (location == -1)
9161 {
9162 return;
9163 }
9164
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009165 gl::Context *context = gl::getNonLostContext();
9166
9167 if (context)
9168 {
9169 if (context->getClientVersion() < 3)
9170 {
9171 return gl::error(GL_INVALID_OPERATION);
9172 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009173
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009174 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9175 if (!programBinary)
9176 {
9177 return gl::error(GL_INVALID_OPERATION);
9178 }
9179
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009180 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009181 {
9182 return gl::error(GL_INVALID_OPERATION);
9183 }
9184 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009185 }
9186 catch(std::bad_alloc&)
9187 {
9188 return gl::error(GL_OUT_OF_MEMORY);
9189 }
9190}
9191
9192void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9193{
9194 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9195 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9196 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9197
9198 try
9199 {
9200 gl::Context *context = gl::getNonLostContext();
9201
9202 if (context)
9203 {
9204 if (context->getClientVersion() < 3)
9205 {
9206 return gl::error(GL_INVALID_OPERATION);
9207 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009208
Geoff Lang758d5b22013-06-11 11:42:50 -04009209 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9210 dstX0, dstY0, dstX1, dstY1, mask, filter,
9211 false))
9212 {
9213 return;
9214 }
9215
9216 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9217 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009219 }
9220 catch(std::bad_alloc&)
9221 {
9222 return gl::error(GL_OUT_OF_MEMORY);
9223 }
9224}
9225
9226void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9227{
9228 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9229 target, samples, internalformat, width, height);
9230
9231 try
9232 {
9233 gl::Context *context = gl::getNonLostContext();
9234
9235 if (context)
9236 {
9237 if (context->getClientVersion() < 3)
9238 {
9239 return gl::error(GL_INVALID_OPERATION);
9240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009241
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009242 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9243 width, height, false))
9244 {
9245 return;
9246 }
9247
9248 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009250 }
9251 catch(std::bad_alloc&)
9252 {
9253 return gl::error(GL_OUT_OF_MEMORY);
9254 }
9255}
9256
9257void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9258{
9259 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9260 target, attachment, texture, level, layer);
9261
9262 try
9263 {
9264 gl::Context *context = gl::getNonLostContext();
9265
9266 if (context)
9267 {
9268 if (context->getClientVersion() < 3)
9269 {
9270 return gl::error(GL_INVALID_OPERATION);
9271 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009272
Jamie Madill54133512013-06-21 09:33:07 -04009273 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009274 UNIMPLEMENTED();
9275 }
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
9283GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9284{
9285 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9286 target, offset, length, access);
9287
9288 try
9289 {
9290 gl::Context *context = gl::getNonLostContext();
9291
9292 if (context)
9293 {
9294 if (context->getClientVersion() < 3)
9295 {
9296 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9297 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009298
Jamie Madill54133512013-06-21 09:33:07 -04009299 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009300 UNIMPLEMENTED();
9301 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009302 }
9303 catch(std::bad_alloc&)
9304 {
9305 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9306 }
9307
9308 return NULL;
9309}
9310
9311void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9312{
9313 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9314
9315 try
9316 {
9317 gl::Context *context = gl::getNonLostContext();
9318
9319 if (context)
9320 {
9321 if (context->getClientVersion() < 3)
9322 {
9323 return gl::error(GL_INVALID_OPERATION);
9324 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009325
Jamie Madill54133512013-06-21 09:33:07 -04009326 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009327 UNIMPLEMENTED();
9328 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009329 }
9330 catch(std::bad_alloc&)
9331 {
9332 return gl::error(GL_OUT_OF_MEMORY);
9333 }
9334}
9335
9336void __stdcall glBindVertexArray(GLuint array)
9337{
9338 EVENT("(GLuint array = %u)", array);
9339
9340 try
9341 {
9342 gl::Context *context = gl::getNonLostContext();
9343
9344 if (context)
9345 {
9346 if (context->getClientVersion() < 3)
9347 {
9348 return gl::error(GL_INVALID_OPERATION);
9349 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009350
Jamie Madilld1028542013-07-02 11:57:04 -04009351 gl::VertexArray *vao = context->getVertexArray(array);
9352
9353 if (!vao)
9354 {
9355 // The default VAO should always exist
9356 ASSERT(array != 0);
9357 return gl::error(GL_INVALID_OPERATION);
9358 }
9359
9360 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009361 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009362 }
9363 catch(std::bad_alloc&)
9364 {
9365 return gl::error(GL_OUT_OF_MEMORY);
9366 }
9367}
9368
9369void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9370{
9371 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9372
9373 try
9374 {
9375 gl::Context *context = gl::getNonLostContext();
9376
9377 if (context)
9378 {
9379 if (context->getClientVersion() < 3)
9380 {
9381 return gl::error(GL_INVALID_OPERATION);
9382 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009383
Jamie Madilld1028542013-07-02 11:57:04 -04009384 if (n < 0)
9385 {
9386 return gl::error(GL_INVALID_VALUE);
9387 }
9388
9389 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9390 {
9391 if (arrays[arrayIndex] != 0)
9392 {
9393 context->deleteVertexArray(arrays[arrayIndex]);
9394 }
9395 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009396 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009397 }
9398 catch(std::bad_alloc&)
9399 {
9400 return gl::error(GL_OUT_OF_MEMORY);
9401 }
9402}
9403
9404void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9405{
9406 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9407
9408 try
9409 {
9410 gl::Context *context = gl::getNonLostContext();
9411
9412 if (context)
9413 {
9414 if (context->getClientVersion() < 3)
9415 {
9416 return gl::error(GL_INVALID_OPERATION);
9417 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009418
Jamie Madilld1028542013-07-02 11:57:04 -04009419 if (n < 0)
9420 {
9421 return gl::error(GL_INVALID_VALUE);
9422 }
9423
9424 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9425 {
9426 arrays[arrayIndex] = context->createVertexArray();
9427 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009429 }
9430 catch(std::bad_alloc&)
9431 {
9432 return gl::error(GL_OUT_OF_MEMORY);
9433 }
9434}
9435
9436GLboolean __stdcall glIsVertexArray(GLuint array)
9437{
9438 EVENT("(GLuint array = %u)", array);
9439
9440 try
9441 {
9442 gl::Context *context = gl::getNonLostContext();
9443
9444 if (context)
9445 {
9446 if (context->getClientVersion() < 3)
9447 {
9448 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9449 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009450
Jamie Madilld1028542013-07-02 11:57:04 -04009451 if (array == 0)
9452 {
9453 return GL_FALSE;
9454 }
9455
9456 gl::VertexArray *vao = context->getVertexArray(array);
9457
9458 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009459 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009460 }
9461 catch(std::bad_alloc&)
9462 {
9463 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9464 }
9465
9466 return GL_FALSE;
9467}
9468
9469void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9470{
9471 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9472 target, index, data);
9473
9474 try
9475 {
9476 gl::Context *context = gl::getNonLostContext();
9477
9478 if (context)
9479 {
9480 if (context->getClientVersion() < 3)
9481 {
9482 return gl::error(GL_INVALID_OPERATION);
9483 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009484
Jamie Madill54133512013-06-21 09:33:07 -04009485 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009486 UNIMPLEMENTED();
9487 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009488 }
9489 catch(std::bad_alloc&)
9490 {
9491 return gl::error(GL_OUT_OF_MEMORY);
9492 }
9493}
9494
9495void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9496{
9497 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9498
9499 try
9500 {
9501 gl::Context *context = gl::getNonLostContext();
9502
9503 if (context)
9504 {
9505 if (context->getClientVersion() < 3)
9506 {
9507 return gl::error(GL_INVALID_OPERATION);
9508 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009509
Jamie Madill54133512013-06-21 09:33:07 -04009510 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009511 UNIMPLEMENTED();
9512 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009513 }
9514 catch(std::bad_alloc&)
9515 {
9516 return gl::error(GL_OUT_OF_MEMORY);
9517 }
9518}
9519
9520void __stdcall glEndTransformFeedback(void)
9521{
9522 EVENT("(void)");
9523
9524 try
9525 {
9526 gl::Context *context = gl::getNonLostContext();
9527
9528 if (context)
9529 {
9530 if (context->getClientVersion() < 3)
9531 {
9532 return gl::error(GL_INVALID_OPERATION);
9533 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009534
Jamie Madill54133512013-06-21 09:33:07 -04009535 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009536 UNIMPLEMENTED();
9537 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009538 }
9539 catch(std::bad_alloc&)
9540 {
9541 return gl::error(GL_OUT_OF_MEMORY);
9542 }
9543}
9544
9545void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9546{
9547 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9548 target, index, buffer, offset, size);
9549
9550 try
9551 {
9552 gl::Context *context = gl::getNonLostContext();
9553
9554 if (context)
9555 {
9556 if (context->getClientVersion() < 3)
9557 {
9558 return gl::error(GL_INVALID_OPERATION);
9559 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009560
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009561 switch (target)
9562 {
9563 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009564 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009565 {
9566 return gl::error(GL_INVALID_VALUE);
9567 }
9568 break;
9569
9570 case GL_UNIFORM_BUFFER:
9571 if (index >= context->getMaximumCombinedUniformBufferBindings())
9572 {
9573 return gl::error(GL_INVALID_VALUE);
9574 }
9575 break;
9576
9577 default:
9578 return gl::error(GL_INVALID_ENUM);
9579 }
9580
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009581 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009582 {
9583 return gl::error(GL_INVALID_VALUE);
9584 }
9585
9586 switch (target)
9587 {
9588 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009589
9590 // size and offset must be a multiple of 4
9591 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9592 {
9593 return gl::error(GL_INVALID_VALUE);
9594 }
9595
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009596 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9597 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009598 break;
9599
9600 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009601
9602 // it is an error to bind an offset not a multiple of the alignment
9603 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9604 {
9605 return gl::error(GL_INVALID_VALUE);
9606 }
9607
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009608 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9609 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009610 break;
9611
9612 default:
9613 UNREACHABLE();
9614 }
9615 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009616 }
9617 catch(std::bad_alloc&)
9618 {
9619 return gl::error(GL_OUT_OF_MEMORY);
9620 }
9621}
9622
9623void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9624{
9625 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9626 target, index, buffer);
9627
9628 try
9629 {
9630 gl::Context *context = gl::getNonLostContext();
9631
9632 if (context)
9633 {
9634 if (context->getClientVersion() < 3)
9635 {
9636 return gl::error(GL_INVALID_OPERATION);
9637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009638
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009639 switch (target)
9640 {
9641 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009642 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009643 {
9644 return gl::error(GL_INVALID_VALUE);
9645 }
9646 break;
9647
9648 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009649 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009650 {
9651 return gl::error(GL_INVALID_VALUE);
9652 }
9653 break;
9654
9655 default:
9656 return gl::error(GL_INVALID_ENUM);
9657 }
9658
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009659 switch (target)
9660 {
9661 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009662 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009663 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009664 break;
9665
9666 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009667 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009668 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009669 break;
9670
9671 default:
9672 UNREACHABLE();
9673 }
9674 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009675 }
9676 catch(std::bad_alloc&)
9677 {
9678 return gl::error(GL_OUT_OF_MEMORY);
9679 }
9680}
9681
9682void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9683{
9684 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9685 program, count, varyings, bufferMode);
9686
9687 try
9688 {
9689 gl::Context *context = gl::getNonLostContext();
9690
9691 if (context)
9692 {
9693 if (context->getClientVersion() < 3)
9694 {
9695 return gl::error(GL_INVALID_OPERATION);
9696 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009697
Jamie Madill54133512013-06-21 09:33:07 -04009698 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009699 UNIMPLEMENTED();
9700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009701 }
9702 catch(std::bad_alloc&)
9703 {
9704 return gl::error(GL_OUT_OF_MEMORY);
9705 }
9706}
9707
9708void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9709{
9710 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9711 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9712 program, index, bufSize, length, size, type, name);
9713
9714 try
9715 {
9716 gl::Context *context = gl::getNonLostContext();
9717
9718 if (context)
9719 {
9720 if (context->getClientVersion() < 3)
9721 {
9722 return gl::error(GL_INVALID_OPERATION);
9723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009724
Jamie Madill54133512013-06-21 09:33:07 -04009725 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009726 UNIMPLEMENTED();
9727 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009728 }
9729 catch(std::bad_alloc&)
9730 {
9731 return gl::error(GL_OUT_OF_MEMORY);
9732 }
9733}
9734
9735void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9736{
9737 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9738 index, size, type, stride, pointer);
9739
9740 try
9741 {
9742 gl::Context *context = gl::getNonLostContext();
9743
9744 if (context)
9745 {
9746 if (context->getClientVersion() < 3)
9747 {
9748 return gl::error(GL_INVALID_OPERATION);
9749 }
9750 }
9751
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009752 if (index >= gl::MAX_VERTEX_ATTRIBS)
9753 {
9754 return gl::error(GL_INVALID_VALUE);
9755 }
9756
9757 if (size < 1 || size > 4)
9758 {
9759 return gl::error(GL_INVALID_VALUE);
9760 }
9761
9762 switch (type)
9763 {
9764 case GL_BYTE:
9765 case GL_UNSIGNED_BYTE:
9766 case GL_SHORT:
9767 case GL_UNSIGNED_SHORT:
9768 case GL_INT:
9769 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009770 case GL_INT_2_10_10_10_REV:
9771 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009772 break;
9773 default:
9774 return gl::error(GL_INVALID_ENUM);
9775 }
9776
9777 if (stride < 0)
9778 {
9779 return gl::error(GL_INVALID_VALUE);
9780 }
9781
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009782 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9783 {
9784 return gl::error(GL_INVALID_OPERATION);
9785 }
9786
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009787 if (context)
9788 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009789 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9790 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9791 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9792 // and the pointer argument is not NULL.
9793 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9794 {
9795 return gl::error(GL_INVALID_OPERATION);
9796 }
9797
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009798 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9799 stride, pointer);
9800 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009801 }
9802 catch(std::bad_alloc&)
9803 {
9804 return gl::error(GL_OUT_OF_MEMORY);
9805 }
9806}
9807
9808void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9809{
9810 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9811 index, pname, params);
9812
9813 try
9814 {
9815 gl::Context *context = gl::getNonLostContext();
9816
9817 if (context)
9818 {
9819 if (context->getClientVersion() < 3)
9820 {
9821 return gl::error(GL_INVALID_OPERATION);
9822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009823
Jamie Madilla7d05862013-07-02 11:57:06 -04009824 if (index >= gl::MAX_VERTEX_ATTRIBS)
9825 {
9826 return gl::error(GL_INVALID_VALUE);
9827 }
9828
9829 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9830
9831 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9832 {
9833 return;
9834 }
9835
9836 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9837 {
9838 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9839 for (int i = 0; i < 4; ++i)
9840 {
9841 params[i] = currentValueData.IntValues[i];
9842 }
9843 }
9844 else
9845 {
9846 *params = attribState.querySingleParameter<GLint>(pname);
9847 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009848 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009849 }
9850 catch(std::bad_alloc&)
9851 {
9852 return gl::error(GL_OUT_OF_MEMORY);
9853 }
9854}
9855
9856void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9857{
9858 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9859 index, pname, params);
9860
9861 try
9862 {
9863 gl::Context *context = gl::getNonLostContext();
9864
9865 if (context)
9866 {
9867 if (context->getClientVersion() < 3)
9868 {
9869 return gl::error(GL_INVALID_OPERATION);
9870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009871
Jamie Madilla7d05862013-07-02 11:57:06 -04009872 if (index >= gl::MAX_VERTEX_ATTRIBS)
9873 {
9874 return gl::error(GL_INVALID_VALUE);
9875 }
9876
9877 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9878
9879 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9880 {
9881 return;
9882 }
9883
9884 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9885 {
9886 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9887 for (int i = 0; i < 4; ++i)
9888 {
9889 params[i] = currentValueData.UnsignedIntValues[i];
9890 }
9891 }
9892 else
9893 {
9894 *params = attribState.querySingleParameter<GLuint>(pname);
9895 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009896 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009897 }
9898 catch(std::bad_alloc&)
9899 {
9900 return gl::error(GL_OUT_OF_MEMORY);
9901 }
9902}
9903
9904void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9905{
9906 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9907 index, x, y, z, w);
9908
9909 try
9910 {
9911 gl::Context *context = gl::getNonLostContext();
9912
9913 if (context)
9914 {
9915 if (context->getClientVersion() < 3)
9916 {
9917 return gl::error(GL_INVALID_OPERATION);
9918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009919
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009920 if (index >= gl::MAX_VERTEX_ATTRIBS)
9921 {
9922 return gl::error(GL_INVALID_VALUE);
9923 }
9924
9925 GLint vals[4] = { x, y, z, w };
9926 context->setVertexAttribi(index, vals);
9927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009928 }
9929 catch(std::bad_alloc&)
9930 {
9931 return gl::error(GL_OUT_OF_MEMORY);
9932 }
9933}
9934
9935void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9936{
9937 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9938 index, x, y, z, w);
9939
9940 try
9941 {
9942 gl::Context *context = gl::getNonLostContext();
9943
9944 if (context)
9945 {
9946 if (context->getClientVersion() < 3)
9947 {
9948 return gl::error(GL_INVALID_OPERATION);
9949 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009950
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009951 if (index >= gl::MAX_VERTEX_ATTRIBS)
9952 {
9953 return gl::error(GL_INVALID_VALUE);
9954 }
9955
9956 GLuint vals[4] = { x, y, z, w };
9957 context->setVertexAttribu(index, vals);
9958 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009959 }
9960 catch(std::bad_alloc&)
9961 {
9962 return gl::error(GL_OUT_OF_MEMORY);
9963 }
9964}
9965
9966void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9967{
9968 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9969
9970 try
9971 {
9972 gl::Context *context = gl::getNonLostContext();
9973
9974 if (context)
9975 {
9976 if (context->getClientVersion() < 3)
9977 {
9978 return gl::error(GL_INVALID_OPERATION);
9979 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009980
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009981 if (index >= gl::MAX_VERTEX_ATTRIBS)
9982 {
9983 return gl::error(GL_INVALID_VALUE);
9984 }
9985
9986 context->setVertexAttribi(index, v);
9987 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009988 }
9989 catch(std::bad_alloc&)
9990 {
9991 return gl::error(GL_OUT_OF_MEMORY);
9992 }
9993}
9994
9995void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9996{
9997 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9998
9999 try
10000 {
10001 gl::Context *context = gl::getNonLostContext();
10002
10003 if (context)
10004 {
10005 if (context->getClientVersion() < 3)
10006 {
10007 return gl::error(GL_INVALID_OPERATION);
10008 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010009
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010010 if (index >= gl::MAX_VERTEX_ATTRIBS)
10011 {
10012 return gl::error(GL_INVALID_VALUE);
10013 }
10014
10015 context->setVertexAttribu(index, v);
10016 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010017 }
10018 catch(std::bad_alloc&)
10019 {
10020 return gl::error(GL_OUT_OF_MEMORY);
10021 }
10022}
10023
10024void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
10025{
10026 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
10027 program, location, params);
10028
10029 try
10030 {
10031 gl::Context *context = gl::getNonLostContext();
10032
10033 if (context)
10034 {
10035 if (context->getClientVersion() < 3)
10036 {
10037 return gl::error(GL_INVALID_OPERATION);
10038 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010039
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +000010040 if (program == 0)
10041 {
10042 return gl::error(GL_INVALID_VALUE);
10043 }
10044
10045 gl::Program *programObject = context->getProgram(program);
10046
10047 if (!programObject || !programObject->isLinked())
10048 {
10049 return gl::error(GL_INVALID_OPERATION);
10050 }
10051
10052 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10053 if (!programBinary)
10054 {
10055 return gl::error(GL_INVALID_OPERATION);
10056 }
10057
10058 if (!programBinary->getUniformuiv(location, NULL, params))
10059 {
10060 return gl::error(GL_INVALID_OPERATION);
10061 }
10062 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010063 }
10064 catch(std::bad_alloc&)
10065 {
10066 return gl::error(GL_OUT_OF_MEMORY);
10067 }
10068}
10069
10070GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10071{
10072 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10073 program, name);
10074
10075 try
10076 {
10077 gl::Context *context = gl::getNonLostContext();
10078
10079 if (context)
10080 {
10081 if (context->getClientVersion() < 3)
10082 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010083 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010085
Jamie Madilld1e78c92013-06-20 11:55:50 -040010086 if (program == 0)
10087 {
10088 return gl::error(GL_INVALID_VALUE, -1);
10089 }
10090
10091 gl::Program *programObject = context->getProgram(program);
10092
10093 if (!programObject || !programObject->isLinked())
10094 {
10095 return gl::error(GL_INVALID_OPERATION, -1);
10096 }
10097
10098 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10099 if (!programBinary)
10100 {
10101 return gl::error(GL_INVALID_OPERATION, -1);
10102 }
10103
10104 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010105 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010106 }
10107 catch(std::bad_alloc&)
10108 {
10109 return gl::error(GL_OUT_OF_MEMORY, 0);
10110 }
10111
10112 return 0;
10113}
10114
10115void __stdcall glUniform1ui(GLint location, GLuint v0)
10116{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010117 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010118}
10119
10120void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10121{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010122 const GLuint xy[] = { v0, v1 };
10123 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010124}
10125
10126void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10127{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010128 const GLuint xyz[] = { v0, v1, v2 };
10129 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010130}
10131
10132void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10133{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010134 const GLuint xyzw[] = { v0, v1, v2, v3 };
10135 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010136}
10137
10138void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10139{
10140 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10141 location, count, value);
10142
10143 try
10144 {
10145 gl::Context *context = gl::getNonLostContext();
10146
10147 if (context)
10148 {
10149 if (context->getClientVersion() < 3)
10150 {
10151 return gl::error(GL_INVALID_OPERATION);
10152 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010153
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010154 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10155 if (!programBinary)
10156 {
10157 return gl::error(GL_INVALID_OPERATION);
10158 }
10159
10160 if (!programBinary->setUniform1uiv(location, count, value))
10161 {
10162 return gl::error(GL_INVALID_OPERATION);
10163 }
10164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010165 }
10166 catch(std::bad_alloc&)
10167 {
10168 return gl::error(GL_OUT_OF_MEMORY);
10169 }
10170}
10171
10172void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10173{
10174 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10175 location, count, value);
10176
10177 try
10178 {
10179 gl::Context *context = gl::getNonLostContext();
10180
10181 if (context)
10182 {
10183 if (context->getClientVersion() < 3)
10184 {
10185 return gl::error(GL_INVALID_OPERATION);
10186 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010187
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010188 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10189 if (!programBinary)
10190 {
10191 return gl::error(GL_INVALID_OPERATION);
10192 }
10193
10194 if (!programBinary->setUniform2uiv(location, count, value))
10195 {
10196 return gl::error(GL_INVALID_OPERATION);
10197 }
10198 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010199 }
10200 catch(std::bad_alloc&)
10201 {
10202 return gl::error(GL_OUT_OF_MEMORY);
10203 }
10204}
10205
10206void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10207{
10208 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10209 location, count, value);
10210
10211 try
10212 {
10213 gl::Context *context = gl::getNonLostContext();
10214
10215 if (context)
10216 {
10217 if (context->getClientVersion() < 3)
10218 {
10219 return gl::error(GL_INVALID_OPERATION);
10220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010221
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010222 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10223 if (!programBinary)
10224 {
10225 return gl::error(GL_INVALID_OPERATION);
10226 }
10227
10228 if (!programBinary->setUniform3uiv(location, count, value))
10229 {
10230 return gl::error(GL_INVALID_OPERATION);
10231 }
10232 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010233 }
10234 catch(std::bad_alloc&)
10235 {
10236 return gl::error(GL_OUT_OF_MEMORY);
10237 }
10238}
10239
10240void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10241{
10242 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10243 location, count, value);
10244
10245 try
10246 {
10247 gl::Context *context = gl::getNonLostContext();
10248
10249 if (context)
10250 {
10251 if (context->getClientVersion() < 3)
10252 {
10253 return gl::error(GL_INVALID_OPERATION);
10254 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010255
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010256 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10257 if (!programBinary)
10258 {
10259 return gl::error(GL_INVALID_OPERATION);
10260 }
10261
10262 if (!programBinary->setUniform4uiv(location, count, value))
10263 {
10264 return gl::error(GL_INVALID_OPERATION);
10265 }
10266 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010267 }
10268 catch(std::bad_alloc&)
10269 {
10270 return gl::error(GL_OUT_OF_MEMORY);
10271 }
10272}
10273
10274void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10275{
10276 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10277 buffer, drawbuffer, value);
10278
10279 try
10280 {
10281 gl::Context *context = gl::getNonLostContext();
10282
10283 if (context)
10284 {
10285 if (context->getClientVersion() < 3)
10286 {
10287 return gl::error(GL_INVALID_OPERATION);
10288 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010289
Jamie Madill54133512013-06-21 09:33:07 -040010290 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010291 UNIMPLEMENTED();
10292 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010293 }
10294 catch(std::bad_alloc&)
10295 {
10296 return gl::error(GL_OUT_OF_MEMORY);
10297 }
10298}
10299
10300void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10301{
10302 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10303 buffer, drawbuffer, value);
10304
10305 try
10306 {
10307 gl::Context *context = gl::getNonLostContext();
10308
10309 if (context)
10310 {
10311 if (context->getClientVersion() < 3)
10312 {
10313 return gl::error(GL_INVALID_OPERATION);
10314 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010315
Jamie Madill54133512013-06-21 09:33:07 -040010316 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010317 UNIMPLEMENTED();
10318 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010319 }
10320 catch(std::bad_alloc&)
10321 {
10322 return gl::error(GL_OUT_OF_MEMORY);
10323 }
10324}
10325
10326void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10327{
10328 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10329 buffer, drawbuffer, value);
10330
10331 try
10332 {
10333 gl::Context *context = gl::getNonLostContext();
10334
10335 if (context)
10336 {
10337 if (context->getClientVersion() < 3)
10338 {
10339 return gl::error(GL_INVALID_OPERATION);
10340 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010341
Jamie Madill54133512013-06-21 09:33:07 -040010342 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010343 UNIMPLEMENTED();
10344 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010345 }
10346 catch(std::bad_alloc&)
10347 {
10348 return gl::error(GL_OUT_OF_MEMORY);
10349 }
10350}
10351
10352void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10353{
10354 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10355 buffer, drawbuffer, depth, stencil);
10356
10357 try
10358 {
10359 gl::Context *context = gl::getNonLostContext();
10360
10361 if (context)
10362 {
10363 if (context->getClientVersion() < 3)
10364 {
10365 return gl::error(GL_INVALID_OPERATION);
10366 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010367
Jamie Madill54133512013-06-21 09:33:07 -040010368 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010369 UNIMPLEMENTED();
10370 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010371 }
10372 catch(std::bad_alloc&)
10373 {
10374 return gl::error(GL_OUT_OF_MEMORY);
10375 }
10376}
10377
10378const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10379{
10380 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10381
10382 try
10383 {
10384 gl::Context *context = gl::getNonLostContext();
10385
10386 if (context)
10387 {
10388 if (context->getClientVersion() < 3)
10389 {
10390 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10391 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010392
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010393 if (name != GL_EXTENSIONS)
10394 {
10395 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10396 }
10397
10398 if (index >= context->getNumExtensions())
10399 {
10400 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10401 }
10402
10403 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10404 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010405 }
10406 catch(std::bad_alloc&)
10407 {
10408 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10409 }
10410
10411 return NULL;
10412}
10413
10414void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10415{
10416 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10417 readTarget, writeTarget, readOffset, writeOffset, size);
10418
10419 try
10420 {
10421 gl::Context *context = gl::getNonLostContext();
10422
10423 if (context)
10424 {
10425 if (context->getClientVersion() < 3)
10426 {
10427 return gl::error(GL_INVALID_OPERATION);
10428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010429
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010430 gl::Buffer *readBuffer = NULL;
10431 switch (readTarget)
10432 {
10433 case GL_ARRAY_BUFFER:
10434 readBuffer = context->getArrayBuffer();
10435 break;
10436 case GL_COPY_READ_BUFFER:
10437 readBuffer = context->getCopyReadBuffer();
10438 break;
10439 case GL_COPY_WRITE_BUFFER:
10440 readBuffer = context->getCopyWriteBuffer();
10441 break;
10442 case GL_ELEMENT_ARRAY_BUFFER:
10443 readBuffer = context->getElementArrayBuffer();
10444 break;
10445 case GL_PIXEL_PACK_BUFFER:
10446 readBuffer = context->getPixelPackBuffer();
10447 break;
10448 case GL_PIXEL_UNPACK_BUFFER:
10449 readBuffer = context->getPixelUnpackBuffer();
10450 break;
10451 case GL_TRANSFORM_FEEDBACK_BUFFER:
10452 readBuffer = context->getGenericTransformFeedbackBuffer();
10453 break;
10454 case GL_UNIFORM_BUFFER:
10455 readBuffer = context->getGenericUniformBuffer();
10456 break;
10457 default:
10458 return gl::error(GL_INVALID_ENUM);
10459 }
10460
10461 gl::Buffer *writeBuffer = NULL;
10462 switch (writeTarget)
10463 {
10464 case GL_ARRAY_BUFFER:
10465 writeBuffer = context->getArrayBuffer();
10466 break;
10467 case GL_COPY_READ_BUFFER:
10468 writeBuffer = context->getCopyReadBuffer();
10469 break;
10470 case GL_COPY_WRITE_BUFFER:
10471 writeBuffer = context->getCopyWriteBuffer();
10472 break;
10473 case GL_ELEMENT_ARRAY_BUFFER:
10474 writeBuffer = context->getElementArrayBuffer();
10475 break;
10476 case GL_PIXEL_PACK_BUFFER:
10477 writeBuffer = context->getPixelPackBuffer();
10478 break;
10479 case GL_PIXEL_UNPACK_BUFFER:
10480 writeBuffer = context->getPixelUnpackBuffer();
10481 break;
10482 case GL_TRANSFORM_FEEDBACK_BUFFER:
10483 writeBuffer = context->getGenericTransformFeedbackBuffer();
10484 break;
10485 case GL_UNIFORM_BUFFER:
10486 writeBuffer = context->getGenericUniformBuffer();
10487 break;
10488 default:
10489 return gl::error(GL_INVALID_ENUM);
10490 }
10491
10492 if (!readBuffer || !writeBuffer)
10493 {
10494 return gl::error(GL_INVALID_OPERATION);
10495 }
10496
10497 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10498 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10499 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10500 {
10501 return gl::error(GL_INVALID_VALUE);
10502 }
10503
10504 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10505 {
10506 return gl::error(GL_INVALID_VALUE);
10507 }
10508
10509 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10510
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010511 // if size is zero, the copy is a successful no-op
10512 if (size > 0)
10513 {
10514 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10515 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010516 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010517 }
10518 catch(std::bad_alloc&)
10519 {
10520 return gl::error(GL_OUT_OF_MEMORY);
10521 }
10522}
10523
10524void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10525{
10526 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10527 program, uniformCount, uniformNames, uniformIndices);
10528
10529 try
10530 {
10531 gl::Context *context = gl::getNonLostContext();
10532
10533 if (context)
10534 {
10535 if (context->getClientVersion() < 3)
10536 {
10537 return gl::error(GL_INVALID_OPERATION);
10538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010539
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010540 if (uniformCount < 0)
10541 {
10542 return gl::error(GL_INVALID_VALUE);
10543 }
10544
10545 gl::Program *programObject = context->getProgram(program);
10546
10547 if (!programObject)
10548 {
10549 if (context->getShader(program))
10550 {
10551 return gl::error(GL_INVALID_OPERATION);
10552 }
10553 else
10554 {
10555 return gl::error(GL_INVALID_VALUE);
10556 }
10557 }
10558
10559 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10560 if (!programObject->isLinked() || !programBinary)
10561 {
10562 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10563 {
10564 uniformIndices[uniformId] = GL_INVALID_INDEX;
10565 }
10566 }
10567 else
10568 {
10569 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10570 {
10571 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10572 }
10573 }
10574 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010575 }
10576 catch(std::bad_alloc&)
10577 {
10578 return gl::error(GL_OUT_OF_MEMORY);
10579 }
10580}
10581
10582void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10583{
10584 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10585 program, uniformCount, uniformIndices, pname, params);
10586
10587 try
10588 {
10589 gl::Context *context = gl::getNonLostContext();
10590
10591 if (context)
10592 {
10593 if (context->getClientVersion() < 3)
10594 {
10595 return gl::error(GL_INVALID_OPERATION);
10596 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010597
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010598 if (uniformCount < 0)
10599 {
10600 return gl::error(GL_INVALID_VALUE);
10601 }
10602
10603 gl::Program *programObject = context->getProgram(program);
10604
10605 if (!programObject)
10606 {
10607 if (context->getShader(program))
10608 {
10609 return gl::error(GL_INVALID_OPERATION);
10610 }
10611 else
10612 {
10613 return gl::error(GL_INVALID_VALUE);
10614 }
10615 }
10616
10617 switch (pname)
10618 {
10619 case GL_UNIFORM_TYPE:
10620 case GL_UNIFORM_SIZE:
10621 case GL_UNIFORM_NAME_LENGTH:
10622 case GL_UNIFORM_BLOCK_INDEX:
10623 case GL_UNIFORM_OFFSET:
10624 case GL_UNIFORM_ARRAY_STRIDE:
10625 case GL_UNIFORM_MATRIX_STRIDE:
10626 case GL_UNIFORM_IS_ROW_MAJOR:
10627 break;
10628 default:
10629 return gl::error(GL_INVALID_ENUM);
10630 }
10631
10632 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10633
10634 if (!programBinary && uniformCount > 0)
10635 {
10636 return gl::error(GL_INVALID_VALUE);
10637 }
10638
10639 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10640 {
10641 const GLuint index = uniformIndices[uniformId];
10642
10643 if (index >= (GLuint)programBinary->getActiveUniformCount())
10644 {
10645 return gl::error(GL_INVALID_VALUE);
10646 }
10647 }
10648
10649 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10650 {
10651 const GLuint index = uniformIndices[uniformId];
10652 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10653 }
10654 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010655 }
10656 catch(std::bad_alloc&)
10657 {
10658 return gl::error(GL_OUT_OF_MEMORY);
10659 }
10660}
10661
10662GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10663{
10664 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10665
10666 try
10667 {
10668 gl::Context *context = gl::getNonLostContext();
10669
10670 if (context)
10671 {
10672 if (context->getClientVersion() < 3)
10673 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010674 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010675 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010676
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010677 gl::Program *programObject = context->getProgram(program);
10678
10679 if (!programObject)
10680 {
10681 if (context->getShader(program))
10682 {
10683 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10684 }
10685 else
10686 {
10687 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10688 }
10689 }
10690
10691 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10692 if (!programBinary)
10693 {
10694 return GL_INVALID_INDEX;
10695 }
10696
10697 return programBinary->getUniformBlockIndex(uniformBlockName);
10698 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010699 }
10700 catch(std::bad_alloc&)
10701 {
10702 return gl::error(GL_OUT_OF_MEMORY, 0);
10703 }
10704
10705 return 0;
10706}
10707
10708void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10709{
10710 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10711 program, uniformBlockIndex, pname, params);
10712
10713 try
10714 {
10715 gl::Context *context = gl::getNonLostContext();
10716
10717 if (context)
10718 {
10719 if (context->getClientVersion() < 3)
10720 {
10721 return gl::error(GL_INVALID_OPERATION);
10722 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010723 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010724
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010725 if (!programObject)
10726 {
10727 if (context->getShader(program))
10728 {
10729 return gl::error(GL_INVALID_OPERATION);
10730 }
10731 else
10732 {
10733 return gl::error(GL_INVALID_VALUE);
10734 }
10735 }
10736
10737 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10738
10739 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10740 {
10741 return gl::error(GL_INVALID_VALUE);
10742 }
10743
10744 switch (pname)
10745 {
10746 case GL_UNIFORM_BLOCK_BINDING:
10747 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10748 break;
10749
10750 case GL_UNIFORM_BLOCK_DATA_SIZE:
10751 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10752 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10753 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10754 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10755 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10756 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10757 break;
10758
10759 default:
10760 return gl::error(GL_INVALID_ENUM);
10761 }
10762 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010763 }
10764 catch(std::bad_alloc&)
10765 {
10766 return gl::error(GL_OUT_OF_MEMORY);
10767 }
10768}
10769
10770void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10771{
10772 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10773 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10774
10775 try
10776 {
10777 gl::Context *context = gl::getNonLostContext();
10778
10779 if (context)
10780 {
10781 if (context->getClientVersion() < 3)
10782 {
10783 return gl::error(GL_INVALID_OPERATION);
10784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010785
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010786 gl::Program *programObject = context->getProgram(program);
10787
10788 if (!programObject)
10789 {
10790 if (context->getShader(program))
10791 {
10792 return gl::error(GL_INVALID_OPERATION);
10793 }
10794 else
10795 {
10796 return gl::error(GL_INVALID_VALUE);
10797 }
10798 }
10799
10800 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10801
10802 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10803 {
10804 return gl::error(GL_INVALID_VALUE);
10805 }
10806
10807 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10808 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010809 }
10810 catch(std::bad_alloc&)
10811 {
10812 return gl::error(GL_OUT_OF_MEMORY);
10813 }
10814}
10815
10816void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10817{
10818 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10819 program, uniformBlockIndex, uniformBlockBinding);
10820
10821 try
10822 {
10823 gl::Context *context = gl::getNonLostContext();
10824
10825 if (context)
10826 {
10827 if (context->getClientVersion() < 3)
10828 {
10829 return gl::error(GL_INVALID_OPERATION);
10830 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010831
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010832 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10833 {
10834 return gl::error(GL_INVALID_VALUE);
10835 }
10836
10837 gl::Program *programObject = context->getProgram(program);
10838
10839 if (!programObject)
10840 {
10841 if (context->getShader(program))
10842 {
10843 return gl::error(GL_INVALID_OPERATION);
10844 }
10845 else
10846 {
10847 return gl::error(GL_INVALID_VALUE);
10848 }
10849 }
10850
10851 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10852
10853 // if never linked, there won't be any uniform blocks
10854 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10855 {
10856 return gl::error(GL_INVALID_VALUE);
10857 }
10858
10859 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10860 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010861 }
10862 catch(std::bad_alloc&)
10863 {
10864 return gl::error(GL_OUT_OF_MEMORY);
10865 }
10866}
10867
10868void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10869{
10870 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10871 mode, first, count, instanceCount);
10872
10873 try
10874 {
10875 gl::Context *context = gl::getNonLostContext();
10876
10877 if (context)
10878 {
10879 if (context->getClientVersion() < 3)
10880 {
10881 return gl::error(GL_INVALID_OPERATION);
10882 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010883
Jamie Madill54133512013-06-21 09:33:07 -040010884 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010885 UNIMPLEMENTED();
10886 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010887 }
10888 catch(std::bad_alloc&)
10889 {
10890 return gl::error(GL_OUT_OF_MEMORY);
10891 }
10892}
10893
10894void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10895{
10896 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10897 mode, count, type, indices, instanceCount);
10898
10899 try
10900 {
10901 gl::Context *context = gl::getNonLostContext();
10902
10903 if (context)
10904 {
10905 if (context->getClientVersion() < 3)
10906 {
10907 return gl::error(GL_INVALID_OPERATION);
10908 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010909
Jamie Madill54133512013-06-21 09:33:07 -040010910 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010911 UNIMPLEMENTED();
10912 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010913 }
10914 catch(std::bad_alloc&)
10915 {
10916 return gl::error(GL_OUT_OF_MEMORY);
10917 }
10918}
10919
10920GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10921{
10922 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10923
10924 try
10925 {
10926 gl::Context *context = gl::getNonLostContext();
10927
10928 if (context)
10929 {
10930 if (context->getClientVersion() < 3)
10931 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040010932 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010933 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010934
Jamie Madill5215e1a2013-07-26 11:55:19 -040010935 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
10936 {
10937 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
10938 }
10939
10940 if (flags != 0)
10941 {
10942 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
10943 }
10944
10945 return context->createFenceSync(condition);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010946 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010947 }
10948 catch(std::bad_alloc&)
10949 {
10950 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10951 }
10952
10953 return NULL;
10954}
10955
10956GLboolean __stdcall glIsSync(GLsync sync)
10957{
10958 EVENT("(GLsync sync = 0x%0.8p)", sync);
10959
10960 try
10961 {
10962 gl::Context *context = gl::getNonLostContext();
10963
10964 if (context)
10965 {
10966 if (context->getClientVersion() < 3)
10967 {
10968 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010970
Jamie Madill5215e1a2013-07-26 11:55:19 -040010971 return (context->getFenceSync(sync) != NULL);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010972 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010973 }
10974 catch(std::bad_alloc&)
10975 {
10976 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10977 }
10978
10979 return GL_FALSE;
10980}
10981
10982void __stdcall glDeleteSync(GLsync sync)
10983{
10984 EVENT("(GLsync sync = 0x%0.8p)", sync);
10985
10986 try
10987 {
10988 gl::Context *context = gl::getNonLostContext();
10989
10990 if (context)
10991 {
10992 if (context->getClientVersion() < 3)
10993 {
10994 return gl::error(GL_INVALID_OPERATION);
10995 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010996
Jamie Madill5215e1a2013-07-26 11:55:19 -040010997 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
10998 {
10999 return gl::error(GL_INVALID_VALUE);
11000 }
11001
11002 context->deleteFenceSync(sync);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011003 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011004 }
11005 catch(std::bad_alloc&)
11006 {
11007 return gl::error(GL_OUT_OF_MEMORY);
11008 }
11009}
11010
11011GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11012{
11013 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11014 sync, flags, timeout);
11015
11016 try
11017 {
11018 gl::Context *context = gl::getNonLostContext();
11019
11020 if (context)
11021 {
11022 if (context->getClientVersion() < 3)
11023 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011024 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011025 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011026
Jamie Madill5215e1a2013-07-26 11:55:19 -040011027 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
11028 {
11029 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11030 }
11031
11032 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11033
11034 if (!fenceSync)
11035 {
11036 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11037 }
11038
11039 return fenceSync->clientWait(flags, timeout);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011040 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011041 }
11042 catch(std::bad_alloc&)
11043 {
11044 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11045 }
11046
11047 return GL_FALSE;
11048}
11049
11050void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11051{
11052 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11053 sync, flags, timeout);
11054
11055 try
11056 {
11057 gl::Context *context = gl::getNonLostContext();
11058
11059 if (context)
11060 {
11061 if (context->getClientVersion() < 3)
11062 {
11063 return gl::error(GL_INVALID_OPERATION);
11064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011065
Jamie Madill5215e1a2013-07-26 11:55:19 -040011066 if (flags != 0)
11067 {
11068 return gl::error(GL_INVALID_VALUE);
11069 }
11070
11071 if (timeout != GL_TIMEOUT_IGNORED)
11072 {
11073 return gl::error(GL_INVALID_VALUE);
11074 }
11075
11076 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11077
11078 if (!fenceSync)
11079 {
11080 return gl::error(GL_INVALID_VALUE);
11081 }
11082
11083 fenceSync->serverWait();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011085 }
11086 catch(std::bad_alloc&)
11087 {
11088 return gl::error(GL_OUT_OF_MEMORY);
11089 }
11090}
11091
11092void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
11093{
11094 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11095 pname, params);
11096
11097 try
11098 {
11099 gl::Context *context = gl::getNonLostContext();
11100
11101 if (context)
11102 {
11103 if (context->getClientVersion() < 3)
11104 {
11105 return gl::error(GL_INVALID_OPERATION);
11106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011107
Jamie Madill71fbd602013-07-19 16:36:55 -040011108 if (!(context->getInteger64v(pname, params)))
11109 {
11110 GLenum nativeType;
11111 unsigned int numParams = 0;
11112 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11113 return gl::error(GL_INVALID_ENUM);
11114
11115 if (numParams == 0)
11116 return; // it is known that the pname is valid, but that there are no parameters to return.
11117
11118 if (nativeType == GL_BOOL)
11119 {
11120 GLboolean *boolParams = NULL;
11121 boolParams = new GLboolean[numParams];
11122
11123 context->getBooleanv(pname, boolParams);
11124
11125 for (unsigned int i = 0; i < numParams; ++i)
11126 {
11127 if (boolParams[i] == GL_FALSE)
11128 params[i] = 0;
11129 else
11130 params[i] = 1;
11131 }
11132
11133 delete [] boolParams;
11134 }
11135 else if (nativeType == GL_INT)
11136 {
11137 GLint *intParams = NULL;
11138 intParams = new GLint[numParams];
11139
11140 context->getIntegerv(pname, intParams);
11141
11142 for (unsigned int i = 0; i < numParams; ++i)
11143 {
11144 params[i] = static_cast<GLint64>(intParams[i]);
11145 }
11146
11147 delete [] intParams;
11148 }
11149 else if (nativeType == GL_FLOAT)
11150 {
11151 GLfloat *floatParams = NULL;
11152 floatParams = new GLfloat[numParams];
11153
11154 context->getFloatv(pname, floatParams);
11155
11156 for (unsigned int i = 0; i < numParams; ++i)
11157 {
11158 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11159 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11160 {
11161 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11162 }
11163 else
11164 {
11165 params[i] = gl::iround<GLint64>(floatParams[i]);
11166 }
11167 }
11168
11169 delete [] floatParams;
11170 }
11171 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011172 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011173 }
11174 catch(std::bad_alloc&)
11175 {
11176 return gl::error(GL_OUT_OF_MEMORY);
11177 }
11178}
11179
11180void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11181{
11182 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11183 sync, pname, bufSize, length, values);
11184
11185 try
11186 {
11187 gl::Context *context = gl::getNonLostContext();
11188
11189 if (context)
11190 {
11191 if (context->getClientVersion() < 3)
11192 {
11193 return gl::error(GL_INVALID_OPERATION);
11194 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011195
Jamie Madill5215e1a2013-07-26 11:55:19 -040011196 if (bufSize < 0)
11197 {
11198 return gl::error(GL_INVALID_VALUE);
11199 }
11200
11201 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11202
11203 if (!fenceSync)
11204 {
11205 return gl::error(GL_INVALID_VALUE);
11206 }
11207
11208 switch (pname)
11209 {
11210 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
11211 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
11212 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
11213 case GL_SYNC_FLAGS: values[0] = 0; break;
11214
11215 default:
11216 return gl::error(GL_INVALID_ENUM);
11217 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011219 }
11220 catch(std::bad_alloc&)
11221 {
11222 return gl::error(GL_OUT_OF_MEMORY);
11223 }
11224}
11225
11226void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11227{
11228 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11229 target, index, data);
11230
11231 try
11232 {
11233 gl::Context *context = gl::getNonLostContext();
11234
11235 if (context)
11236 {
11237 if (context->getClientVersion() < 3)
11238 {
11239 return gl::error(GL_INVALID_OPERATION);
11240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011241
Jamie Madill54133512013-06-21 09:33:07 -040011242 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011243 UNIMPLEMENTED();
11244 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011245 }
11246 catch(std::bad_alloc&)
11247 {
11248 return gl::error(GL_OUT_OF_MEMORY);
11249 }
11250}
11251
11252void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11253{
11254 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11255 target, pname, params);
11256
11257 try
11258 {
11259 gl::Context *context = gl::getNonLostContext();
11260
11261 if (context)
11262 {
11263 if (context->getClientVersion() < 3)
11264 {
11265 return gl::error(GL_INVALID_OPERATION);
11266 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011267
Jamie Madill54133512013-06-21 09:33:07 -040011268 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011269 UNIMPLEMENTED();
11270 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011271 }
11272 catch(std::bad_alloc&)
11273 {
11274 return gl::error(GL_OUT_OF_MEMORY);
11275 }
11276}
11277
11278void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11279{
11280 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11281
11282 try
11283 {
11284 gl::Context *context = gl::getNonLostContext();
11285
11286 if (context)
11287 {
11288 if (context->getClientVersion() < 3)
11289 {
11290 return gl::error(GL_INVALID_OPERATION);
11291 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011292
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011293 if (count < 0)
11294 {
11295 return gl::error(GL_INVALID_VALUE);
11296 }
11297
11298 for (int i = 0; i < count; i++)
11299 {
11300 samplers[i] = context->createSampler();
11301 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011302 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011303 }
11304 catch(std::bad_alloc&)
11305 {
11306 return gl::error(GL_OUT_OF_MEMORY);
11307 }
11308}
11309
11310void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11311{
11312 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11313
11314 try
11315 {
11316 gl::Context *context = gl::getNonLostContext();
11317
11318 if (context)
11319 {
11320 if (context->getClientVersion() < 3)
11321 {
11322 return gl::error(GL_INVALID_OPERATION);
11323 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011324
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011325 if (count < 0)
11326 {
11327 return gl::error(GL_INVALID_VALUE);
11328 }
11329
11330 for (int i = 0; i < count; i++)
11331 {
11332 context->deleteSampler(samplers[i]);
11333 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011334 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011335 }
11336 catch(std::bad_alloc&)
11337 {
11338 return gl::error(GL_OUT_OF_MEMORY);
11339 }
11340}
11341
11342GLboolean __stdcall glIsSampler(GLuint sampler)
11343{
11344 EVENT("(GLuint sampler = %u)", sampler);
11345
11346 try
11347 {
11348 gl::Context *context = gl::getNonLostContext();
11349
11350 if (context)
11351 {
11352 if (context->getClientVersion() < 3)
11353 {
11354 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11355 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011356
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011357 return context->isSampler(sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011358 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011359 }
11360 catch(std::bad_alloc&)
11361 {
11362 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11363 }
11364
11365 return GL_FALSE;
11366}
11367
11368void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11369{
11370 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11371
11372 try
11373 {
11374 gl::Context *context = gl::getNonLostContext();
11375
11376 if (context)
11377 {
11378 if (context->getClientVersion() < 3)
11379 {
11380 return gl::error(GL_INVALID_OPERATION);
11381 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011382
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011383 if (sampler != 0 && !context->isSampler(sampler))
11384 {
11385 return gl::error(GL_INVALID_OPERATION);
11386 }
11387
11388 if (unit >= context->getMaximumCombinedTextureImageUnits())
11389 {
11390 return gl::error(GL_INVALID_VALUE);
11391 }
11392
11393 context->bindSampler(unit, sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011394 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011395 }
11396 catch(std::bad_alloc&)
11397 {
11398 return gl::error(GL_OUT_OF_MEMORY);
11399 }
11400}
11401
11402void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11403{
11404 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11405
11406 try
11407 {
11408 gl::Context *context = gl::getNonLostContext();
11409
11410 if (context)
11411 {
11412 if (context->getClientVersion() < 3)
11413 {
11414 return gl::error(GL_INVALID_OPERATION);
11415 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011416
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011417 if (!validateSamplerObjectParameter(pname))
11418 {
11419 return;
11420 }
11421
11422 if (!validateTexParamParameters(context, pname, param))
11423 {
11424 return;
11425 }
11426
11427 if (!context->isSampler(sampler))
11428 {
11429 return gl::error(GL_INVALID_OPERATION);
11430 }
11431
11432 context->samplerParameteri(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011433 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011434 }
11435 catch(std::bad_alloc&)
11436 {
11437 return gl::error(GL_OUT_OF_MEMORY);
11438 }
11439}
11440
11441void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11442{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011443 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011444}
11445
11446void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11447{
11448 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11449
11450 try
11451 {
11452 gl::Context *context = gl::getNonLostContext();
11453
11454 if (context)
11455 {
11456 if (context->getClientVersion() < 3)
11457 {
11458 return gl::error(GL_INVALID_OPERATION);
11459 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011460
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011461 if (!validateSamplerObjectParameter(pname))
11462 {
11463 return;
11464 }
11465
11466 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
11467 {
11468 return;
11469 }
11470
11471 if (!context->isSampler(sampler))
11472 {
11473 return gl::error(GL_INVALID_OPERATION);
11474 }
11475
11476 context->samplerParameterf(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011477 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011478 }
11479 catch(std::bad_alloc&)
11480 {
11481 return gl::error(GL_OUT_OF_MEMORY);
11482 }
11483}
11484
11485void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11486{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011487 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011488}
11489
11490void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11491{
11492 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11493
11494 try
11495 {
11496 gl::Context *context = gl::getNonLostContext();
11497
11498 if (context)
11499 {
11500 if (context->getClientVersion() < 3)
11501 {
11502 return gl::error(GL_INVALID_OPERATION);
11503 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011504
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011505 if (!validateSamplerObjectParameter(pname))
11506 {
11507 return;
11508 }
11509
11510 if (!context->isSampler(sampler))
11511 {
11512 return gl::error(GL_INVALID_OPERATION);
11513 }
11514
11515 *params = context->getSamplerParameteri(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011516 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011517 }
11518 catch(std::bad_alloc&)
11519 {
11520 return gl::error(GL_OUT_OF_MEMORY);
11521 }
11522}
11523
11524void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11525{
11526 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11527
11528 try
11529 {
11530 gl::Context *context = gl::getNonLostContext();
11531
11532 if (context)
11533 {
11534 if (context->getClientVersion() < 3)
11535 {
11536 return gl::error(GL_INVALID_OPERATION);
11537 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011538
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011539 if (!validateSamplerObjectParameter(pname))
11540 {
11541 return;
11542 }
11543
11544 if (!context->isSampler(sampler))
11545 {
11546 return gl::error(GL_INVALID_OPERATION);
11547 }
11548
11549 *params = context->getSamplerParameterf(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011550 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011551 }
11552 catch(std::bad_alloc&)
11553 {
11554 return gl::error(GL_OUT_OF_MEMORY);
11555 }
11556}
11557
11558void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11559{
11560 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11561
11562 try
11563 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011564 if (index >= gl::MAX_VERTEX_ATTRIBS)
11565 {
11566 return gl::error(GL_INVALID_VALUE);
11567 }
11568
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011569 gl::Context *context = gl::getNonLostContext();
11570
11571 if (context)
11572 {
11573 if (context->getClientVersion() < 3)
11574 {
11575 return gl::error(GL_INVALID_OPERATION);
11576 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011577
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011578 context->setVertexAttribDivisor(index, divisor);
11579 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011580 }
11581 catch(std::bad_alloc&)
11582 {
11583 return gl::error(GL_OUT_OF_MEMORY);
11584 }
11585}
11586
11587void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11588{
11589 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11590
11591 try
11592 {
11593 gl::Context *context = gl::getNonLostContext();
11594
11595 if (context)
11596 {
11597 if (context->getClientVersion() < 3)
11598 {
11599 return gl::error(GL_INVALID_OPERATION);
11600 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011601
Jamie Madill54133512013-06-21 09:33:07 -040011602 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011603 UNIMPLEMENTED();
11604 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011605 }
11606 catch(std::bad_alloc&)
11607 {
11608 return gl::error(GL_OUT_OF_MEMORY);
11609 }
11610}
11611
11612void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11613{
11614 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11615
11616 try
11617 {
11618 gl::Context *context = gl::getNonLostContext();
11619
11620 if (context)
11621 {
11622 if (context->getClientVersion() < 3)
11623 {
11624 return gl::error(GL_INVALID_OPERATION);
11625 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011626
Jamie Madill54133512013-06-21 09:33:07 -040011627 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011628 UNIMPLEMENTED();
11629 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011630 }
11631 catch(std::bad_alloc&)
11632 {
11633 return gl::error(GL_OUT_OF_MEMORY);
11634 }
11635}
11636
11637void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11638{
11639 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11640
11641 try
11642 {
11643 gl::Context *context = gl::getNonLostContext();
11644
11645 if (context)
11646 {
11647 if (context->getClientVersion() < 3)
11648 {
11649 return gl::error(GL_INVALID_OPERATION);
11650 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011651
Jamie Madill54133512013-06-21 09:33:07 -040011652 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011653 UNIMPLEMENTED();
11654 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011655 }
11656 catch(std::bad_alloc&)
11657 {
11658 return gl::error(GL_OUT_OF_MEMORY);
11659 }
11660}
11661
11662GLboolean __stdcall glIsTransformFeedback(GLuint id)
11663{
11664 EVENT("(GLuint id = %u)", id);
11665
11666 try
11667 {
11668 gl::Context *context = gl::getNonLostContext();
11669
11670 if (context)
11671 {
11672 if (context->getClientVersion() < 3)
11673 {
11674 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11675 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011676
Jamie Madill54133512013-06-21 09:33:07 -040011677 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011678 UNIMPLEMENTED();
11679 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011680 }
11681 catch(std::bad_alloc&)
11682 {
11683 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11684 }
11685
11686 return GL_FALSE;
11687}
11688
11689void __stdcall glPauseTransformFeedback(void)
11690{
11691 EVENT("(void)");
11692
11693 try
11694 {
11695 gl::Context *context = gl::getNonLostContext();
11696
11697 if (context)
11698 {
11699 if (context->getClientVersion() < 3)
11700 {
11701 return gl::error(GL_INVALID_OPERATION);
11702 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011703
Jamie Madill54133512013-06-21 09:33:07 -040011704 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011705 UNIMPLEMENTED();
11706 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011707 }
11708 catch(std::bad_alloc&)
11709 {
11710 return gl::error(GL_OUT_OF_MEMORY);
11711 }
11712}
11713
11714void __stdcall glResumeTransformFeedback(void)
11715{
11716 EVENT("(void)");
11717
11718 try
11719 {
11720 gl::Context *context = gl::getNonLostContext();
11721
11722 if (context)
11723 {
11724 if (context->getClientVersion() < 3)
11725 {
11726 return gl::error(GL_INVALID_OPERATION);
11727 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011728
Jamie Madill54133512013-06-21 09:33:07 -040011729 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011730 UNIMPLEMENTED();
11731 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011732 }
11733 catch(std::bad_alloc&)
11734 {
11735 return gl::error(GL_OUT_OF_MEMORY);
11736 }
11737}
11738
11739void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11740{
11741 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11742 program, bufSize, length, binaryFormat, binary);
11743
11744 try
11745 {
11746 gl::Context *context = gl::getNonLostContext();
11747
11748 if (context)
11749 {
11750 if (context->getClientVersion() < 3)
11751 {
11752 return gl::error(GL_INVALID_OPERATION);
11753 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011754
Jamie Madill54133512013-06-21 09:33:07 -040011755 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011756 UNIMPLEMENTED();
11757 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011758 }
11759 catch(std::bad_alloc&)
11760 {
11761 return gl::error(GL_OUT_OF_MEMORY);
11762 }
11763}
11764
11765void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11766{
11767 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11768 program, binaryFormat, binary, length);
11769
11770 try
11771 {
11772 gl::Context *context = gl::getNonLostContext();
11773
11774 if (context)
11775 {
11776 if (context->getClientVersion() < 3)
11777 {
11778 return gl::error(GL_INVALID_OPERATION);
11779 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011780
Jamie Madill54133512013-06-21 09:33:07 -040011781 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011782 UNIMPLEMENTED();
11783 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011784 }
11785 catch(std::bad_alloc&)
11786 {
11787 return gl::error(GL_OUT_OF_MEMORY);
11788 }
11789}
11790
11791void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11792{
11793 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11794 program, pname, value);
11795
11796 try
11797 {
11798 gl::Context *context = gl::getNonLostContext();
11799
11800 if (context)
11801 {
11802 if (context->getClientVersion() < 3)
11803 {
11804 return gl::error(GL_INVALID_OPERATION);
11805 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011806
Jamie Madill54133512013-06-21 09:33:07 -040011807 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011808 UNIMPLEMENTED();
11809 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011810 }
11811 catch(std::bad_alloc&)
11812 {
11813 return gl::error(GL_OUT_OF_MEMORY);
11814 }
11815}
11816
11817void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11818{
11819 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11820 target, numAttachments, attachments);
11821
11822 try
11823 {
11824 gl::Context *context = gl::getNonLostContext();
11825
11826 if (context)
11827 {
11828 if (context->getClientVersion() < 3)
11829 {
11830 return gl::error(GL_INVALID_OPERATION);
11831 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011832
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011833 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11834 {
11835 return;
11836 }
11837
11838 int maxDimension = context->getMaximumRenderbufferDimension();
11839 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11840 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011841 }
11842 catch(std::bad_alloc&)
11843 {
11844 return gl::error(GL_OUT_OF_MEMORY);
11845 }
11846}
11847
11848void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11849{
11850 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11851 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11852 target, numAttachments, attachments, x, y, width, height);
11853
11854 try
11855 {
11856 gl::Context *context = gl::getNonLostContext();
11857
11858 if (context)
11859 {
11860 if (context->getClientVersion() < 3)
11861 {
11862 return gl::error(GL_INVALID_OPERATION);
11863 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011864
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011865 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11866 {
11867 return;
11868 }
11869
11870 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11871 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011872 }
11873 catch(std::bad_alloc&)
11874 {
11875 return gl::error(GL_OUT_OF_MEMORY);
11876 }
11877}
11878
11879void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11880{
11881 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11882 target, levels, internalformat, width, height);
11883
11884 try
11885 {
11886 gl::Context *context = gl::getNonLostContext();
11887
11888 if (context)
11889 {
11890 if (context->getClientVersion() < 3)
11891 {
11892 return gl::error(GL_INVALID_OPERATION);
11893 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011894
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011895 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11896 {
11897 return;
11898 }
11899
11900 switch (target)
11901 {
11902 case GL_TEXTURE_2D:
11903 {
11904 gl::Texture2D *texture2d = context->getTexture2D();
11905 texture2d->storage(levels, internalformat, width, height);
11906 }
11907 break;
11908
11909 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11910 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11911 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11912 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11913 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11914 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11915 {
11916 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11917 textureCube->storage(levels, internalformat, width);
11918 }
11919 break;
11920
11921 default:
11922 return gl::error(GL_INVALID_ENUM);
11923 }
11924 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011925 }
11926 catch(std::bad_alloc&)
11927 {
11928 return gl::error(GL_OUT_OF_MEMORY);
11929 }
11930}
11931
11932void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11933{
11934 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11935 "GLsizei height = %d, GLsizei depth = %d)",
11936 target, levels, internalformat, width, height, depth);
11937
11938 try
11939 {
11940 gl::Context *context = gl::getNonLostContext();
11941
11942 if (context)
11943 {
11944 if (context->getClientVersion() < 3)
11945 {
11946 return gl::error(GL_INVALID_OPERATION);
11947 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011948
11949 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11950 {
11951 return;
11952 }
11953
11954 switch (target)
11955 {
11956 case GL_TEXTURE_3D:
11957 {
11958 gl::Texture3D *texture3d = context->getTexture3D();
11959 texture3d->storage(levels, internalformat, width, height, depth);
11960 }
11961 break;
11962
11963 case GL_TEXTURE_2D_ARRAY:
11964 {
11965 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11966 texture2darray->storage(levels, internalformat, width, height, depth);
11967 }
11968 break;
11969
11970 default:
11971 return gl::error(GL_INVALID_ENUM);
11972 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011973 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011974 }
11975 catch(std::bad_alloc&)
11976 {
11977 return gl::error(GL_OUT_OF_MEMORY);
11978 }
11979}
11980
11981void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11982{
11983 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11984 "GLint* params = 0x%0.8p)",
11985 target, internalformat, pname, bufSize, params);
11986
11987 try
11988 {
11989 gl::Context *context = gl::getNonLostContext();
11990
11991 if (context)
11992 {
11993 if (context->getClientVersion() < 3)
11994 {
11995 return gl::error(GL_INVALID_OPERATION);
11996 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011997
Shannon Woods809d2502013-07-08 10:32:18 -040011998 if (!gl::IsColorRenderingSupported(internalformat, context) &&
11999 !gl::IsDepthRenderingSupported(internalformat, context) &&
12000 !gl::IsStencilRenderingSupported(internalformat, context))
12001 {
12002 return gl::error(GL_INVALID_ENUM);
12003 }
12004
12005 if (target != GL_RENDERBUFFER)
12006 {
12007 return gl::error(GL_INVALID_ENUM);
12008 }
12009
12010 if (bufSize < 0)
12011 {
12012 return gl::error(GL_INVALID_VALUE);
12013 }
12014
12015 switch (pname)
12016 {
12017 case GL_NUM_SAMPLE_COUNTS:
12018 if (bufSize != 0)
12019 *params = context->getNumSampleCounts(internalformat);
12020 break;
12021 case GL_SAMPLES:
12022 context->getSampleCounts(internalformat, bufSize, params);
12023 break;
12024 default:
12025 return gl::error(GL_INVALID_ENUM);
12026 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012027 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012028 }
12029 catch(std::bad_alloc&)
12030 {
12031 return gl::error(GL_OUT_OF_MEMORY);
12032 }
12033}
12034
12035// Extension functions
12036
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012037void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
12038 GLbitfield mask, GLenum filter)
12039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012040 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012041 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
12042 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
12043 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
12044
12045 try
12046 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012047 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012048
12049 if (context)
12050 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012051 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
12052 dstX0, dstY0, dstX1, dstY1, mask, filter,
12053 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012054 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012055 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012056 }
12057
Geoff Lang758d5b22013-06-11 11:42:50 -040012058 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
12059 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012060 }
12061 }
12062 catch(std::bad_alloc&)
12063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012064 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012065 }
12066}
12067
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012068void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
12069 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012070{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012071 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000012072 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012073 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012074 target, level, internalformat, width, height, depth, border, format, type, pixels);
12075
12076 try
12077 {
12078 UNIMPLEMENTED(); // FIXME
12079 }
12080 catch(std::bad_alloc&)
12081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012082 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012083 }
12084}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012085
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012086void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
12087 GLenum *binaryFormat, void *binary)
12088{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012089 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 +000012090 program, bufSize, length, binaryFormat, binary);
12091
12092 try
12093 {
12094 gl::Context *context = gl::getNonLostContext();
12095
12096 if (context)
12097 {
12098 gl::Program *programObject = context->getProgram(program);
12099
daniel@transgaming.com716056c2012-07-24 18:38:59 +000012100 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012102 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012103 }
12104
12105 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
12106
12107 if (!programBinary)
12108 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012109 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012110 }
12111
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012112 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012114 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012115 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012116
12117 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012118 }
12119 }
12120 catch(std::bad_alloc&)
12121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012122 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012123 }
12124}
12125
12126void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
12127 const void *binary, GLint length)
12128{
12129 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
12130 program, binaryFormat, binary, length);
12131
12132 try
12133 {
12134 gl::Context *context = gl::getNonLostContext();
12135
12136 if (context)
12137 {
12138 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012140 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012141 }
12142
12143 gl::Program *programObject = context->getProgram(program);
12144
12145 if (!programObject)
12146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012147 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012148 }
12149
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012150 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012151 }
12152 }
12153 catch(std::bad_alloc&)
12154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012155 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012156 }
12157}
12158
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012159void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12160{
12161 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12162
12163 try
12164 {
12165 gl::Context *context = gl::getNonLostContext();
12166
12167 if (context)
12168 {
12169 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12170 {
12171 return gl::error(GL_INVALID_VALUE);
12172 }
12173
12174 if (context->getDrawFramebufferHandle() == 0)
12175 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012176 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012177 {
12178 return gl::error(GL_INVALID_OPERATION);
12179 }
12180
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012181 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012182 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012183 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012184 }
12185 }
12186 else
12187 {
12188 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12189 {
12190 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12191 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12192 {
12193 return gl::error(GL_INVALID_OPERATION);
12194 }
12195 }
12196 }
12197
12198 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12199
12200 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12201 {
12202 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12203 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012204
12205 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12206 {
12207 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12208 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012209 }
12210 }
12211 catch (std::bad_alloc&)
12212 {
12213 return gl::error(GL_OUT_OF_MEMORY);
12214 }
12215}
12216
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012217__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12218{
12219 struct Extension
12220 {
12221 const char *name;
12222 __eglMustCastToProperFunctionPointerType address;
12223 };
12224
12225 static const Extension glExtensions[] =
12226 {
12227 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012228 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012229 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012230 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12231 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12232 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12233 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12234 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12235 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12236 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012237 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012238 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012239 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12240 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12241 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12242 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012243 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12244 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12245 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12246 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12247 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12248 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12249 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012250 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012251 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12252 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12253 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012254 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12255 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012256
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012257 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012258 {
12259 if (strcmp(procname, glExtensions[ext].name) == 0)
12260 {
12261 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12262 }
12263 }
12264
12265 return NULL;
12266}
12267
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012268// Non-public functions used by EGL
12269
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012270bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012271{
12272 EVENT("(egl::Surface* surface = 0x%0.8p)",
12273 surface);
12274
12275 try
12276 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012277 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012278
12279 if (context)
12280 {
12281 gl::Texture2D *textureObject = context->getTexture2D();
12282
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012283 if (textureObject->isImmutable())
12284 {
12285 return false;
12286 }
12287
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012288 if (textureObject)
12289 {
12290 textureObject->bindTexImage(surface);
12291 }
12292 }
12293 }
12294 catch(std::bad_alloc&)
12295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012296 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012297 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012298
12299 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012300}
12301
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012302}