blob: 458bf5b07471013fe42b58944bf19e0c588b905b [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{
Geoff Lang0fe19492013-07-25 17:04:31 -0400803 if (!gl::IsInternalTextureTarget(target, context->getClientVersion()))
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000804 {
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
Geoff Lang3ed0c482013-07-25 17:03:18 -04001547bool validateES2FramebufferTextureParameters(gl::Context *context, GLenum target, GLenum attachment,
1548 GLenum textarget, GLuint texture, GLint level)
1549{
1550 META_ASSERT(GL_DRAW_FRAMEBUFFER == GL_DRAW_FRAMEBUFFER_ANGLE && GL_READ_FRAMEBUFFER == GL_READ_FRAMEBUFFER_ANGLE);
1551
1552 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER)
1553 {
1554 return gl::error(GL_INVALID_ENUM, false);
1555 }
1556
1557 if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15)
1558 {
1559 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0);
1560 if (colorAttachment >= context->getMaximumRenderTargets())
1561 {
1562 return gl::error(GL_INVALID_VALUE, false);
1563 }
1564 }
1565 else
1566 {
1567 switch (attachment)
1568 {
1569 case GL_DEPTH_ATTACHMENT:
1570 case GL_STENCIL_ATTACHMENT:
1571 break;
1572 default:
1573 return gl::error(GL_INVALID_ENUM, false);
1574 }
1575 }
1576
1577 if (texture != 0)
1578 {
1579 gl::Texture *tex = context->getTexture(texture);
1580
1581 if (tex == NULL)
1582 {
1583 return gl::error(GL_INVALID_OPERATION, false);
1584 }
1585
1586 switch (textarget)
1587 {
1588 case GL_TEXTURE_2D:
1589 {
1590 if (tex->getTarget() != GL_TEXTURE_2D)
1591 {
1592 return gl::error(GL_INVALID_OPERATION, false);
1593 }
1594 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1595 if (tex2d->isCompressed(level))
1596 {
1597 return gl::error(GL_INVALID_OPERATION, false);
1598 }
1599 break;
1600 }
1601
1602 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1603 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1604 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1605 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1606 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1607 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1608 {
1609 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1610 {
1611 return gl::error(GL_INVALID_OPERATION, false);
1612 }
1613 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1614 if (texcube->isCompressed(textarget, level))
1615 {
1616 return gl::error(GL_INVALID_OPERATION, false);
1617 }
1618 break;
1619 }
1620
1621 default:
1622 return gl::error(GL_INVALID_ENUM, false);
1623 }
1624
1625 if (level != 0)
1626 {
1627 return gl::error(GL_INVALID_VALUE, false);
1628 }
1629 }
1630
1631 gl::Framebuffer *framebuffer = NULL;
1632 GLuint framebufferHandle = 0;
1633 if (target == GL_READ_FRAMEBUFFER)
1634 {
1635 framebuffer = context->getReadFramebuffer();
1636 framebufferHandle = context->getReadFramebufferHandle();
1637 }
1638 else
1639 {
1640 framebuffer = context->getDrawFramebuffer();
1641 framebufferHandle = context->getDrawFramebufferHandle();
1642 }
1643
1644 if (framebufferHandle == 0 || !framebuffer)
1645 {
1646 return gl::error(GL_INVALID_OPERATION, false);
1647 }
1648
1649 return true;
1650}
1651
1652bool validateES3FramebufferTextureParameters(gl::Context *context, GLenum target, GLenum attachment,
1653 GLenum textarget, GLuint texture, GLint level, GLint layer,
1654 bool layerCall)
1655{
1656 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER)
1657 {
1658 return gl::error(GL_INVALID_ENUM, false);
1659 }
1660
1661 if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15)
1662 {
1663 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0);
1664 if (colorAttachment >= context->getMaximumRenderTargets())
1665 {
1666 return gl::error(GL_INVALID_VALUE, false);
1667 }
1668 }
1669 else
1670 {
1671 switch (attachment)
1672 {
1673 case GL_DEPTH_ATTACHMENT:
1674 case GL_STENCIL_ATTACHMENT:
1675 case GL_DEPTH_STENCIL_ATTACHMENT:
1676 break;
1677 default:
1678 return gl::error(GL_INVALID_ENUM, false);
1679 }
1680 }
1681
1682 if (texture != 0)
1683 {
1684 gl::Texture *tex = context->getTexture(texture);
1685
1686 if (tex == NULL)
1687 {
1688 return gl::error(GL_INVALID_OPERATION, false);
1689 }
1690
1691 if (level < 0)
1692 {
1693 return gl::error(GL_INVALID_VALUE, false);
1694 }
1695
1696 if (layer < 0)
1697 {
1698 return gl::error(GL_INVALID_VALUE, false);
1699 }
1700
1701 if (!layerCall)
1702 {
1703 switch (textarget)
1704 {
1705 case GL_TEXTURE_2D:
1706 {
1707 if (level > gl::log2(context->getMaximum2DTextureDimension()))
1708 {
1709 return gl::error(GL_INVALID_VALUE, false);
1710 }
1711 if (tex->getTarget() != GL_TEXTURE_2D)
1712 {
1713 return gl::error(GL_INVALID_OPERATION, false);
1714 }
1715 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1716 if (tex2d->isCompressed(level))
1717 {
1718 return gl::error(GL_INVALID_OPERATION, false);
1719 }
1720 break;
1721 }
1722
1723 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1724 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1725 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1726 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1727 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1728 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1729 {
1730 if (level > gl::log2(context->getMaximumCubeTextureDimension()))
1731 {
1732 return gl::error(GL_INVALID_VALUE, false);
1733 }
1734 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1735 {
1736 return gl::error(GL_INVALID_OPERATION, false);
1737 }
1738 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1739 if (texcube->isCompressed(textarget, level))
1740 {
1741 return gl::error(GL_INVALID_OPERATION, false);
1742 }
1743 break;
1744 }
1745
1746 default:
1747 return gl::error(GL_INVALID_ENUM, false);
1748 }
1749 }
1750 else
1751 {
1752 switch (tex->getTarget())
1753 {
1754 case GL_TEXTURE_2D_ARRAY:
1755 {
1756 if (level > gl::log2(context->getMaximum2DTextureDimension()))
1757 {
1758 return gl::error(GL_INVALID_VALUE, false);
1759 }
1760
1761 if (layer >= context->getMaximum2DArrayTextureLayers())
1762 {
1763 return gl::error(GL_INVALID_VALUE, false);
1764 }
1765
1766 gl::Texture2DArray *texArray = static_cast<gl::Texture2DArray *>(tex);
1767 if (texArray->isCompressed(level))
1768 {
1769 return gl::error(GL_INVALID_OPERATION, false);
1770 }
1771
1772 break;
1773 }
1774
1775 case GL_TEXTURE_3D:
1776 {
1777 if (level > gl::log2(context->getMaximum3DTextureDimension()))
1778 {
1779 return gl::error(GL_INVALID_VALUE, false);
1780 }
1781
1782 if (layer >= context->getMaximum3DTextureDimension())
1783 {
1784 return gl::error(GL_INVALID_VALUE, false);
1785 }
1786
1787 gl::Texture3D *tex3d = static_cast<gl::Texture3D *>(tex);
1788 if (tex3d->isCompressed(level))
1789 {
1790 return gl::error(GL_INVALID_OPERATION, false);
1791 }
1792
1793 break;
1794 }
1795
1796 default:
1797 return gl::error(GL_INVALID_OPERATION, false);
1798 }
1799 }
1800 }
1801
1802 gl::Framebuffer *framebuffer = NULL;
1803 GLuint framebufferHandle = 0;
1804 if (target == GL_READ_FRAMEBUFFER)
1805 {
1806 framebuffer = context->getReadFramebuffer();
1807 framebufferHandle = context->getReadFramebufferHandle();
1808 }
1809 else
1810 {
1811 framebuffer = context->getDrawFramebuffer();
1812 framebufferHandle = context->getDrawFramebufferHandle();
1813 }
1814
1815 if (framebufferHandle == 0 || !framebuffer)
1816 {
1817 return gl::error(GL_INVALID_OPERATION, false);
1818 }
1819
1820 return true;
1821}
1822
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001823// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001824bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001825{
1826 switch (format)
1827 {
1828 case GL_RGBA:
1829 switch (type)
1830 {
1831 case GL_UNSIGNED_BYTE:
1832 break;
1833 default:
1834 return false;
1835 }
1836 break;
1837 case GL_BGRA_EXT:
1838 switch (type)
1839 {
1840 case GL_UNSIGNED_BYTE:
1841 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1842 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1843 break;
1844 default:
1845 return false;
1846 }
1847 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001848 default:
1849 return false;
1850 }
1851 return true;
1852}
1853
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001854bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1855{
1856 switch (format)
1857 {
1858 case GL_RGBA:
1859 switch (type)
1860 {
1861 case GL_UNSIGNED_BYTE:
1862 break;
1863 case GL_UNSIGNED_INT_2_10_10_10_REV:
1864 if (internalFormat != GL_RGB10_A2)
1865 {
1866 return false;
1867 }
1868 break;
1869 default:
1870 return false;
1871 }
1872 break;
1873 case GL_RGBA_INTEGER:
1874 switch (type)
1875 {
1876 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001877 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1878 {
1879 return false;
1880 }
1881 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001882 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001883 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1884 {
1885 return false;
1886 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001887 break;
1888 default:
1889 return false;
1890 }
1891 break;
1892 case GL_BGRA_EXT:
1893 switch (type)
1894 {
1895 case GL_UNSIGNED_BYTE:
1896 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1897 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1898 break;
1899 default:
1900 return false;
1901 }
1902 break;
1903 default:
1904 return false;
1905 }
1906 return true;
1907}
1908
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001909bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1910 const GLenum* attachments)
1911{
1912 bool defaultFramebuffer = false;
1913
1914 switch (target)
1915 {
1916 case GL_DRAW_FRAMEBUFFER:
1917 case GL_FRAMEBUFFER:
1918 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1919 break;
1920 case GL_READ_FRAMEBUFFER:
1921 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1922 break;
1923 default:
1924 return gl::error(GL_INVALID_ENUM, false);
1925 }
1926
1927 for (int i = 0; i < numAttachments; ++i)
1928 {
1929 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1930 {
1931 if (defaultFramebuffer)
1932 {
1933 return gl::error(GL_INVALID_ENUM, false);
1934 }
1935
1936 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1937 {
1938 return gl::error(GL_INVALID_OPERATION, false);
1939 }
1940 }
1941 else
1942 {
1943 switch (attachments[i])
1944 {
1945 case GL_DEPTH_ATTACHMENT:
1946 case GL_STENCIL_ATTACHMENT:
1947 case GL_DEPTH_STENCIL_ATTACHMENT:
1948 if (defaultFramebuffer)
1949 {
1950 return gl::error(GL_INVALID_ENUM, false);
1951 }
1952 break;
1953 case GL_COLOR:
1954 case GL_DEPTH:
1955 case GL_STENCIL:
1956 if (!defaultFramebuffer)
1957 {
1958 return gl::error(GL_INVALID_ENUM, false);
1959 }
1960 break;
1961 default:
1962 return gl::error(GL_INVALID_ENUM, false);
1963 }
1964 }
1965 }
1966
1967 return true;
1968}
1969
Geoff Lang758d5b22013-06-11 11:42:50 -04001970bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1971 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1972 GLenum filter, bool fromAngleExtension)
1973{
1974 switch (filter)
1975 {
1976 case GL_NEAREST:
1977 break;
1978 case GL_LINEAR:
1979 if (fromAngleExtension)
1980 {
1981 return gl::error(GL_INVALID_ENUM, false);
1982 }
1983 break;
1984 default:
1985 return gl::error(GL_INVALID_ENUM, false);
1986 }
1987
1988 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1989 {
1990 return gl::error(GL_INVALID_VALUE, false);
1991 }
1992
1993 if (mask == 0)
1994 {
1995 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1996 // buffers are copied.
1997 return false;
1998 }
1999
2000 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
2001 {
2002 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
2003 return gl::error(GL_INVALID_OPERATION, false);
2004 }
2005
2006 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
2007 // color buffer, leaving only nearest being unfiltered from above
2008 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
2009 {
2010 return gl::error(GL_INVALID_OPERATION, false);
2011 }
2012
2013 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
2014 {
2015 if (fromAngleExtension)
2016 {
2017 ERR("Blits with the same source and destination framebuffer are not supported by this "
2018 "implementation.");
2019 }
2020 return gl::error(GL_INVALID_OPERATION, false);
2021 }
2022
2023 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
2024 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
2025 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
2026 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
2027 {
2028 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
2029 }
2030
2031 if (drawFramebuffer->getSamples() != 0)
2032 {
2033 return gl::error(GL_INVALID_OPERATION, false);
2034 }
2035
2036 gl::Rectangle sourceClippedRect, destClippedRect;
2037 bool partialCopy;
2038 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
2039 &sourceClippedRect, &destClippedRect, &partialCopy))
2040 {
2041 return gl::error(GL_INVALID_OPERATION, false);
2042 }
2043
2044 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
2045
2046 GLuint clientVersion = context->getClientVersion();
2047
2048 if (mask & GL_COLOR_BUFFER_BIT)
2049 {
2050 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
2051 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
2052
2053 if (readColorBuffer && drawColorBuffer)
2054 {
2055 GLint readInternalFormat = readColorBuffer->getActualFormat();
2056 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
2057
2058 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
2059 {
2060 if (drawFramebuffer->isEnabledColorAttachment(i))
2061 {
2062 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
2063
2064 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
2065 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
2066 {
2067 return gl::error(GL_INVALID_OPERATION, false);
2068 }
2069
2070 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
2071 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
2072 {
2073 return gl::error(GL_INVALID_OPERATION, false);
2074 }
2075
2076 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
2077 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
2078 {
2079 return gl::error(GL_INVALID_OPERATION, false);
2080 }
2081
2082 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
2083 {
2084 return gl::error(GL_INVALID_OPERATION, false);
2085 }
2086 }
2087 }
2088
2089 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
2090 {
2091 return gl::error(GL_INVALID_OPERATION, false);
2092 }
2093
2094 if (fromAngleExtension)
2095 {
2096 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
2097 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
2098 {
2099 return gl::error(GL_INVALID_OPERATION, false);
2100 }
2101
2102 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
2103 {
2104 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
2105 {
2106 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
2107 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
2108 {
2109 return gl::error(GL_INVALID_OPERATION, false);
2110 }
2111
2112 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
2113 {
2114 return gl::error(GL_INVALID_OPERATION, false);
2115 }
2116 }
2117 }
2118
2119 if (partialCopy && readFramebuffer->getSamples() != 0)
2120 {
2121 return gl::error(GL_INVALID_OPERATION, false);
2122 }
2123 }
2124 }
2125 }
2126
2127 if (mask & GL_DEPTH_BUFFER_BIT)
2128 {
2129 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
2130 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
2131
2132 if (readDepthBuffer && drawDepthBuffer)
2133 {
2134 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
2135 {
2136 return gl::error(GL_INVALID_OPERATION, false);
2137 }
2138
2139 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
2140 {
2141 return gl::error(GL_INVALID_OPERATION, false);
2142 }
2143
2144 if (fromAngleExtension)
2145 {
2146 if (partialCopy)
2147 {
2148 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2149 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2150 }
2151
2152 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
2153 {
2154 return gl::error(GL_INVALID_OPERATION, false);
2155 }
2156 }
2157 }
2158 }
2159
2160 if (mask & GL_STENCIL_BUFFER_BIT)
2161 {
2162 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
2163 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
2164
2165 if (fromAngleExtension && partialCopy)
2166 {
2167 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2168 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2169 }
2170
2171 if (readStencilBuffer && drawStencilBuffer)
2172 {
2173 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
2174 {
2175 return gl::error(GL_INVALID_OPERATION, false);
2176 }
2177
2178 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
2179 {
2180 return gl::error(GL_INVALID_OPERATION, false);
2181 }
2182
2183 if (fromAngleExtension)
2184 {
2185 if (partialCopy)
2186 {
2187 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2188 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2189 }
2190
2191 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
2192 {
2193 return gl::error(GL_INVALID_OPERATION, false);
2194 }
2195 }
2196 }
2197 }
2198
2199 return true;
2200}
2201
Jamie Madillaff71502013-07-02 11:57:05 -04002202bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
2203{
2204 switch (pname)
2205 {
2206 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
2207 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
2208 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
2209 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
2210 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
2211 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2212 case GL_CURRENT_VERTEX_ATTRIB:
2213 return true;
2214
2215 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
2216 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
2217 // the same constant.
2218 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
2219 return true;
2220
Jamie Madill30855b32013-07-02 11:57:06 -04002221 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
2222 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
2223
Jamie Madillaff71502013-07-02 11:57:05 -04002224 default:
2225 return gl::error(GL_INVALID_ENUM, false);
2226 }
2227}
2228
Jamie Madill478fdb22013-07-19 16:36:59 -04002229bool validateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
2230{
2231 switch (pname)
2232 {
2233 case GL_TEXTURE_WRAP_R:
2234 case GL_TEXTURE_SWIZZLE_R:
2235 case GL_TEXTURE_SWIZZLE_G:
2236 case GL_TEXTURE_SWIZZLE_B:
2237 case GL_TEXTURE_SWIZZLE_A:
2238 case GL_TEXTURE_BASE_LEVEL:
2239 case GL_TEXTURE_MAX_LEVEL:
2240 case GL_TEXTURE_COMPARE_MODE:
2241 case GL_TEXTURE_COMPARE_FUNC:
2242 case GL_TEXTURE_MIN_LOD:
2243 case GL_TEXTURE_MAX_LOD:
2244 if (context->getClientVersion() < 3)
2245 {
2246 return gl::error(GL_INVALID_ENUM, false);
2247 }
2248 break;
2249
2250 default: break;
2251 }
2252
2253 switch (pname)
2254 {
2255 case GL_TEXTURE_WRAP_S:
2256 case GL_TEXTURE_WRAP_T:
2257 case GL_TEXTURE_WRAP_R:
2258 switch (param)
2259 {
2260 case GL_REPEAT:
2261 case GL_CLAMP_TO_EDGE:
2262 case GL_MIRRORED_REPEAT:
2263 return true;
2264 default:
2265 return gl::error(GL_INVALID_ENUM, false);
2266 }
2267
2268 case GL_TEXTURE_MIN_FILTER:
2269 switch (param)
2270 {
2271 case GL_NEAREST:
2272 case GL_LINEAR:
2273 case GL_NEAREST_MIPMAP_NEAREST:
2274 case GL_LINEAR_MIPMAP_NEAREST:
2275 case GL_NEAREST_MIPMAP_LINEAR:
2276 case GL_LINEAR_MIPMAP_LINEAR:
2277 return true;
2278 default:
2279 return gl::error(GL_INVALID_ENUM, false);
2280 }
2281 break;
2282
2283 case GL_TEXTURE_MAG_FILTER:
2284 switch (param)
2285 {
2286 case GL_NEAREST:
2287 case GL_LINEAR:
2288 return true;
2289 default:
2290 return gl::error(GL_INVALID_ENUM, false);
2291 }
2292 break;
2293
2294 case GL_TEXTURE_USAGE_ANGLE:
2295 switch (param)
2296 {
2297 case GL_NONE:
2298 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
2299 return true;
2300 default:
2301 return gl::error(GL_INVALID_ENUM, false);
2302 }
2303 break;
2304
2305 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2306 if (!context->supportsTextureFilterAnisotropy())
2307 {
2308 return gl::error(GL_INVALID_ENUM, false);
2309 }
2310
2311 // we assume the parameter passed to this validation method is truncated, not rounded
2312 if (param < 1)
2313 {
2314 return gl::error(GL_INVALID_VALUE, false);
2315 }
2316 return true;
2317
2318 case GL_TEXTURE_MIN_LOD:
2319 case GL_TEXTURE_MAX_LOD:
2320 // any value is permissible
2321 return true;
2322
2323 case GL_TEXTURE_COMPARE_MODE:
2324 switch (param)
2325 {
2326 case GL_NONE:
2327 case GL_COMPARE_REF_TO_TEXTURE:
2328 return true;
2329 default:
2330 return gl::error(GL_INVALID_ENUM, false);
2331 }
2332 break;
2333
2334 case GL_TEXTURE_COMPARE_FUNC:
2335 switch (param)
2336 {
2337 case GL_LEQUAL:
2338 case GL_GEQUAL:
2339 case GL_LESS:
2340 case GL_GREATER:
2341 case GL_EQUAL:
2342 case GL_NOTEQUAL:
2343 case GL_ALWAYS:
2344 case GL_NEVER:
2345 return true;
2346 default:
2347 return gl::error(GL_INVALID_ENUM, false);
2348 }
2349 break;
2350
2351 case GL_TEXTURE_SWIZZLE_R:
2352 case GL_TEXTURE_SWIZZLE_G:
2353 case GL_TEXTURE_SWIZZLE_B:
2354 case GL_TEXTURE_SWIZZLE_A:
2355 case GL_TEXTURE_BASE_LEVEL:
2356 case GL_TEXTURE_MAX_LEVEL:
2357 UNIMPLEMENTED();
2358 return true;
2359
2360 default:
2361 return gl::error(GL_INVALID_ENUM, false);
2362 }
2363}
2364
2365
Jamie Madillfb8a8302013-07-03 14:24:12 -04002366gl::Texture *getTargetTexture(gl::Context *context, GLenum target)
2367{
2368 if (context->getClientVersion() < 3)
2369 {
2370 if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
2371 {
2372 return NULL;
2373 }
2374 }
2375
2376 switch (target)
2377 {
2378 case GL_TEXTURE_2D: return context->getTexture2D();
2379 case GL_TEXTURE_CUBE_MAP: return context->getTextureCubeMap();
2380 case GL_TEXTURE_3D: return context->getTexture3D();
2381 case GL_TEXTURE_2D_ARRAY: return context->getTexture2DArray();
2382 default: return NULL;
2383 }
2384}
Jamie Madill478fdb22013-07-19 16:36:59 -04002385
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04002386bool validateSamplerObjectParameter(GLenum pname)
2387{
2388 switch (pname)
2389 {
2390 case GL_TEXTURE_MIN_FILTER:
2391 case GL_TEXTURE_MAG_FILTER:
2392 case GL_TEXTURE_WRAP_S:
2393 case GL_TEXTURE_WRAP_T:
2394 case GL_TEXTURE_WRAP_R:
2395 case GL_TEXTURE_MIN_LOD:
2396 case GL_TEXTURE_MAX_LOD:
2397 case GL_TEXTURE_COMPARE_MODE:
2398 case GL_TEXTURE_COMPARE_FUNC:
2399 return true;
2400
2401 default:
2402 return gl::error(GL_INVALID_ENUM, false);
2403 }
2404}
2405
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002406extern "C"
2407{
2408
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002409// OpenGL ES 2.0 functions
2410
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002411void __stdcall glActiveTexture(GLenum texture)
2412{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002413 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002414
2415 try
2416 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002417 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002418
2419 if (context)
2420 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002421 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002423 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002424 }
2425
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002426 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002427 }
2428 }
2429 catch(std::bad_alloc&)
2430 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002431 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002432 }
2433}
2434
2435void __stdcall glAttachShader(GLuint program, GLuint shader)
2436{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002437 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002438
2439 try
2440 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002441 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002442
2443 if (context)
2444 {
2445 gl::Program *programObject = context->getProgram(program);
2446 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002447
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002448 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002450 if (context->getShader(program))
2451 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002452 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002453 }
2454 else
2455 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002456 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002457 }
2458 }
2459
2460 if (!shaderObject)
2461 {
2462 if (context->getProgram(shader))
2463 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002464 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002465 }
2466 else
2467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002468 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002469 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002470 }
2471
2472 if (!programObject->attachShader(shaderObject))
2473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002474 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002475 }
2476 }
2477 }
2478 catch(std::bad_alloc&)
2479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002480 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002481 }
2482}
2483
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002484void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2485{
2486 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2487
2488 try
2489 {
2490 switch (target)
2491 {
2492 case GL_ANY_SAMPLES_PASSED_EXT:
2493 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2494 break;
2495 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002496 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002497 }
2498
2499 if (id == 0)
2500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002501 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002502 }
2503
2504 gl::Context *context = gl::getNonLostContext();
2505
2506 if (context)
2507 {
2508 context->beginQuery(target, id);
2509 }
2510 }
2511 catch(std::bad_alloc&)
2512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002513 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002514 }
2515}
2516
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002517void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002518{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002519 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002520
2521 try
2522 {
2523 if (index >= gl::MAX_VERTEX_ATTRIBS)
2524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002525 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002526 }
2527
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002528 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529
2530 if (context)
2531 {
2532 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002533
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002534 if (!programObject)
2535 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002536 if (context->getShader(program))
2537 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002538 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002539 }
2540 else
2541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002542 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002543 }
2544 }
2545
2546 if (strncmp(name, "gl_", 3) == 0)
2547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002548 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002549 }
2550
2551 programObject->bindAttributeLocation(index, name);
2552 }
2553 }
2554 catch(std::bad_alloc&)
2555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002556 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002557 }
2558}
2559
2560void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2561{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002562 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002563
2564 try
2565 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002566 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002567
2568 if (context)
2569 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002570 // Check ES3 specific targets
2571 switch (target)
2572 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002573 case GL_COPY_READ_BUFFER:
2574 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002575 case GL_PIXEL_PACK_BUFFER:
2576 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002577 case GL_UNIFORM_BUFFER:
2578 case GL_TRANSFORM_FEEDBACK_BUFFER:
2579 if (context->getClientVersion() < 3)
2580 {
2581 return gl::error(GL_INVALID_ENUM);
2582 }
2583 }
2584
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002585 switch (target)
2586 {
2587 case GL_ARRAY_BUFFER:
2588 context->bindArrayBuffer(buffer);
2589 return;
2590 case GL_ELEMENT_ARRAY_BUFFER:
2591 context->bindElementArrayBuffer(buffer);
2592 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002593 case GL_COPY_READ_BUFFER:
2594 context->bindCopyReadBuffer(buffer);
2595 return;
2596 case GL_COPY_WRITE_BUFFER:
2597 context->bindCopyWriteBuffer(buffer);
2598 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002599 case GL_PIXEL_PACK_BUFFER:
2600 context->bindPixelPackBuffer(buffer);
2601 return;
2602 case GL_PIXEL_UNPACK_BUFFER:
2603 context->bindPixelUnpackBuffer(buffer);
2604 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002605 case GL_UNIFORM_BUFFER:
2606 context->bindGenericUniformBuffer(buffer);
2607 return;
2608 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002609 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002610 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002611 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002612 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002613 }
2614 }
2615 }
2616 catch(std::bad_alloc&)
2617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002618 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619 }
2620}
2621
2622void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002624 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002625
2626 try
2627 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002628 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002629 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002630 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002631 }
2632
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002633 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002634
2635 if (context)
2636 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002637 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2638 {
2639 context->bindReadFramebuffer(framebuffer);
2640 }
2641
2642 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2643 {
2644 context->bindDrawFramebuffer(framebuffer);
2645 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002646 }
2647 }
2648 catch(std::bad_alloc&)
2649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002650 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002651 }
2652}
2653
2654void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002656 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002657
2658 try
2659 {
2660 if (target != GL_RENDERBUFFER)
2661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002662 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002663 }
2664
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002665 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002666
2667 if (context)
2668 {
2669 context->bindRenderbuffer(renderbuffer);
2670 }
2671 }
2672 catch(std::bad_alloc&)
2673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002674 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002675 }
2676}
2677
2678void __stdcall glBindTexture(GLenum target, GLuint texture)
2679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002680 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002681
2682 try
2683 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002684 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002685
2686 if (context)
2687 {
2688 gl::Texture *textureObject = context->getTexture(texture);
2689
2690 if (textureObject && textureObject->getTarget() != target && texture != 0)
2691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002692 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002693 }
2694
2695 switch (target)
2696 {
2697 case GL_TEXTURE_2D:
2698 context->bindTexture2D(texture);
2699 return;
2700 case GL_TEXTURE_CUBE_MAP:
2701 context->bindTextureCubeMap(texture);
2702 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002703 case GL_TEXTURE_3D:
2704 if (context->getClientVersion() < 3)
2705 {
2706 return gl::error(GL_INVALID_ENUM);
2707 }
2708 context->bindTexture3D(texture);
2709 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002710 case GL_TEXTURE_2D_ARRAY:
2711 if (context->getClientVersion() < 3)
2712 {
2713 return gl::error(GL_INVALID_ENUM);
2714 }
2715 context->bindTexture2DArray(texture);
2716 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002717 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002718 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002719 }
2720 }
2721 }
2722 catch(std::bad_alloc&)
2723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002724 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002725 }
2726}
2727
2728void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002730 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002731 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002732
2733 try
2734 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002735 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002736
2737 if (context)
2738 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002739 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002740 }
2741 }
2742 catch(std::bad_alloc&)
2743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002744 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002745 }
2746}
2747
2748void __stdcall glBlendEquation(GLenum mode)
2749{
2750 glBlendEquationSeparate(mode, mode);
2751}
2752
2753void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2754{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002755 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002756
2757 try
2758 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002759 gl::Context *context = gl::getNonLostContext();
2760
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002761 switch (modeRGB)
2762 {
2763 case GL_FUNC_ADD:
2764 case GL_FUNC_SUBTRACT:
2765 case GL_FUNC_REVERSE_SUBTRACT:
2766 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002767
2768 case GL_MIN:
2769 case GL_MAX:
2770 if (context && context->getClientVersion() < 3)
2771 {
2772 return gl::error(GL_INVALID_ENUM);
2773 }
2774 break;
2775
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002776 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002777 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002778 }
2779
2780 switch (modeAlpha)
2781 {
2782 case GL_FUNC_ADD:
2783 case GL_FUNC_SUBTRACT:
2784 case GL_FUNC_REVERSE_SUBTRACT:
2785 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002786
2787 case GL_MIN:
2788 case GL_MAX:
2789 if (context && context->getClientVersion() < 3)
2790 {
2791 return gl::error(GL_INVALID_ENUM);
2792 }
2793 break;
2794
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002795 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002796 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002797 }
2798
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002799 if (context)
2800 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002801 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002802 }
2803 }
2804 catch(std::bad_alloc&)
2805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002806 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002807 }
2808}
2809
2810void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2811{
2812 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2813}
2814
2815void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2816{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002817 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 +00002818 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002819
2820 try
2821 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002822 gl::Context *context = gl::getNonLostContext();
2823
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002824 switch (srcRGB)
2825 {
2826 case GL_ZERO:
2827 case GL_ONE:
2828 case GL_SRC_COLOR:
2829 case GL_ONE_MINUS_SRC_COLOR:
2830 case GL_DST_COLOR:
2831 case GL_ONE_MINUS_DST_COLOR:
2832 case GL_SRC_ALPHA:
2833 case GL_ONE_MINUS_SRC_ALPHA:
2834 case GL_DST_ALPHA:
2835 case GL_ONE_MINUS_DST_ALPHA:
2836 case GL_CONSTANT_COLOR:
2837 case GL_ONE_MINUS_CONSTANT_COLOR:
2838 case GL_CONSTANT_ALPHA:
2839 case GL_ONE_MINUS_CONSTANT_ALPHA:
2840 case GL_SRC_ALPHA_SATURATE:
2841 break;
2842 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002843 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002844 }
2845
2846 switch (dstRGB)
2847 {
2848 case GL_ZERO:
2849 case GL_ONE:
2850 case GL_SRC_COLOR:
2851 case GL_ONE_MINUS_SRC_COLOR:
2852 case GL_DST_COLOR:
2853 case GL_ONE_MINUS_DST_COLOR:
2854 case GL_SRC_ALPHA:
2855 case GL_ONE_MINUS_SRC_ALPHA:
2856 case GL_DST_ALPHA:
2857 case GL_ONE_MINUS_DST_ALPHA:
2858 case GL_CONSTANT_COLOR:
2859 case GL_ONE_MINUS_CONSTANT_COLOR:
2860 case GL_CONSTANT_ALPHA:
2861 case GL_ONE_MINUS_CONSTANT_ALPHA:
2862 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002863
2864 case GL_SRC_ALPHA_SATURATE:
2865 if (!context || context->getClientVersion() < 3)
2866 {
2867 return gl::error(GL_INVALID_ENUM);
2868 }
2869 break;
2870
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002871 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002872 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002873 }
2874
2875 switch (srcAlpha)
2876 {
2877 case GL_ZERO:
2878 case GL_ONE:
2879 case GL_SRC_COLOR:
2880 case GL_ONE_MINUS_SRC_COLOR:
2881 case GL_DST_COLOR:
2882 case GL_ONE_MINUS_DST_COLOR:
2883 case GL_SRC_ALPHA:
2884 case GL_ONE_MINUS_SRC_ALPHA:
2885 case GL_DST_ALPHA:
2886 case GL_ONE_MINUS_DST_ALPHA:
2887 case GL_CONSTANT_COLOR:
2888 case GL_ONE_MINUS_CONSTANT_COLOR:
2889 case GL_CONSTANT_ALPHA:
2890 case GL_ONE_MINUS_CONSTANT_ALPHA:
2891 case GL_SRC_ALPHA_SATURATE:
2892 break;
2893 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002894 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002895 }
2896
2897 switch (dstAlpha)
2898 {
2899 case GL_ZERO:
2900 case GL_ONE:
2901 case GL_SRC_COLOR:
2902 case GL_ONE_MINUS_SRC_COLOR:
2903 case GL_DST_COLOR:
2904 case GL_ONE_MINUS_DST_COLOR:
2905 case GL_SRC_ALPHA:
2906 case GL_ONE_MINUS_SRC_ALPHA:
2907 case GL_DST_ALPHA:
2908 case GL_ONE_MINUS_DST_ALPHA:
2909 case GL_CONSTANT_COLOR:
2910 case GL_ONE_MINUS_CONSTANT_COLOR:
2911 case GL_CONSTANT_ALPHA:
2912 case GL_ONE_MINUS_CONSTANT_ALPHA:
2913 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002914
2915 case GL_SRC_ALPHA_SATURATE:
2916 if (!context || context->getClientVersion() < 3)
2917 {
2918 return gl::error(GL_INVALID_ENUM);
2919 }
2920 break;
2921
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002922 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002923 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002924 }
2925
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002926 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2927 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2928
2929 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2930 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2931
2932 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002933 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002934 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 +00002935 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002936 }
2937
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002938 if (context)
2939 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002940 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002941 }
2942 }
2943 catch(std::bad_alloc&)
2944 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002945 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002946 }
2947}
2948
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002949void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002951 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 +00002952 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002953
2954 try
2955 {
2956 if (size < 0)
2957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002958 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002959 }
2960
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002961 gl::Context *context = gl::getNonLostContext();
2962
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002963 switch (usage)
2964 {
2965 case GL_STREAM_DRAW:
2966 case GL_STATIC_DRAW:
2967 case GL_DYNAMIC_DRAW:
2968 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002969
2970 case GL_STREAM_READ:
2971 case GL_STREAM_COPY:
2972 case GL_STATIC_READ:
2973 case GL_STATIC_COPY:
2974 case GL_DYNAMIC_READ:
2975 case GL_DYNAMIC_COPY:
2976 if (context && context->getClientVersion() < 3)
2977 {
2978 return gl::error(GL_INVALID_ENUM);
2979 }
2980 break;
2981
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002982 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002983 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002984 }
2985
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002986 if (context)
2987 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002988 // Check ES3 specific targets
2989 switch (target)
2990 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002991 case GL_COPY_READ_BUFFER:
2992 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002993 case GL_PIXEL_PACK_BUFFER:
2994 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002995 case GL_UNIFORM_BUFFER:
2996 case GL_TRANSFORM_FEEDBACK_BUFFER:
2997 if (context->getClientVersion() < 3)
2998 {
2999 return gl::error(GL_INVALID_ENUM);
3000 }
3001 }
3002
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003003 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003004
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003005 switch (target)
3006 {
3007 case GL_ARRAY_BUFFER:
3008 buffer = context->getArrayBuffer();
3009 break;
3010 case GL_ELEMENT_ARRAY_BUFFER:
3011 buffer = context->getElementArrayBuffer();
3012 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003013 case GL_COPY_READ_BUFFER:
3014 buffer = context->getCopyReadBuffer();
3015 break;
3016 case GL_COPY_WRITE_BUFFER:
3017 buffer = context->getCopyWriteBuffer();
3018 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003019 case GL_PIXEL_PACK_BUFFER:
3020 buffer = context->getPixelPackBuffer();
3021 break;
3022 case GL_PIXEL_UNPACK_BUFFER:
3023 buffer = context->getPixelUnpackBuffer();
3024 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003025 case GL_TRANSFORM_FEEDBACK_BUFFER:
3026 buffer = context->getGenericTransformFeedbackBuffer();
3027 break;
3028 case GL_UNIFORM_BUFFER:
3029 buffer = context->getGenericUniformBuffer();
3030 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003032 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003033 }
3034
3035 if (!buffer)
3036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003037 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003038 }
3039
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003040 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003041 }
3042 }
3043 catch(std::bad_alloc&)
3044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003045 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003046 }
3047}
3048
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003049void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003050{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003051 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 +00003052 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003053
3054 try
3055 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003056 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003058 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003059 }
3060
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00003061 if (data == NULL)
3062 {
3063 return;
3064 }
3065
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003066 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003067
3068 if (context)
3069 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003070 // Check ES3 specific targets
3071 switch (target)
3072 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003073 case GL_COPY_READ_BUFFER:
3074 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003075 case GL_PIXEL_PACK_BUFFER:
3076 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003077 case GL_UNIFORM_BUFFER:
3078 case GL_TRANSFORM_FEEDBACK_BUFFER:
3079 if (context->getClientVersion() < 3)
3080 {
3081 return gl::error(GL_INVALID_ENUM);
3082 }
3083 }
3084
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003085 gl::Buffer *buffer;
3086
3087 switch (target)
3088 {
3089 case GL_ARRAY_BUFFER:
3090 buffer = context->getArrayBuffer();
3091 break;
3092 case GL_ELEMENT_ARRAY_BUFFER:
3093 buffer = context->getElementArrayBuffer();
3094 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003095 case GL_COPY_READ_BUFFER:
3096 buffer = context->getCopyReadBuffer();
3097 break;
3098 case GL_COPY_WRITE_BUFFER:
3099 buffer = context->getCopyWriteBuffer();
3100 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003101 case GL_PIXEL_PACK_BUFFER:
3102 buffer = context->getPixelPackBuffer();
3103 break;
3104 case GL_PIXEL_UNPACK_BUFFER:
3105 buffer = context->getPixelUnpackBuffer();
3106 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003107 case GL_TRANSFORM_FEEDBACK_BUFFER:
3108 buffer = context->getGenericTransformFeedbackBuffer();
3109 break;
3110 case GL_UNIFORM_BUFFER:
3111 buffer = context->getGenericUniformBuffer();
3112 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003115 }
3116
3117 if (!buffer)
3118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003119 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003120 }
3121
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003122 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003124 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003125 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003126
3127 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003128 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003129 }
3130 catch(std::bad_alloc&)
3131 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003132 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003133 }
3134}
3135
3136GLenum __stdcall glCheckFramebufferStatus(GLenum target)
3137{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003138 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003139
3140 try
3141 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003142 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003144 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003145 }
3146
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003147 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148
3149 if (context)
3150 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003151 gl::Framebuffer *framebuffer = NULL;
3152 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3153 {
3154 framebuffer = context->getReadFramebuffer();
3155 }
3156 else
3157 {
3158 framebuffer = context->getDrawFramebuffer();
3159 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003160
3161 return framebuffer->completeness();
3162 }
3163 }
3164 catch(std::bad_alloc&)
3165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003166 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003167 }
3168
3169 return 0;
3170}
3171
3172void __stdcall glClear(GLbitfield mask)
3173{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003174 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003175
3176 try
3177 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003178 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003179
3180 if (context)
3181 {
3182 context->clear(mask);
3183 }
3184 }
3185 catch(std::bad_alloc&)
3186 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003187 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003188 }
3189}
3190
3191void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
3192{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003193 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003194 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003195
3196 try
3197 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003198 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003199
3200 if (context)
3201 {
3202 context->setClearColor(red, green, blue, alpha);
3203 }
3204 }
3205 catch(std::bad_alloc&)
3206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003207 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208 }
3209}
3210
3211void __stdcall glClearDepthf(GLclampf depth)
3212{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003213 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003214
3215 try
3216 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003217 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003218
3219 if (context)
3220 {
3221 context->setClearDepth(depth);
3222 }
3223 }
3224 catch(std::bad_alloc&)
3225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003226 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003227 }
3228}
3229
3230void __stdcall glClearStencil(GLint s)
3231{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003232 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003233
3234 try
3235 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003236 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003237
3238 if (context)
3239 {
3240 context->setClearStencil(s);
3241 }
3242 }
3243 catch(std::bad_alloc&)
3244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003245 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003246 }
3247}
3248
3249void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3250{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003251 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003252 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003253
3254 try
3255 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003256 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003257
3258 if (context)
3259 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00003260 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003261 }
3262 }
3263 catch(std::bad_alloc&)
3264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003265 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003266 }
3267}
3268
3269void __stdcall glCompileShader(GLuint shader)
3270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003271 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003272
3273 try
3274 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003275 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003276
3277 if (context)
3278 {
3279 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003280
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003281 if (!shaderObject)
3282 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003283 if (context->getProgram(shader))
3284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003285 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003286 }
3287 else
3288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003289 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003290 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003291 }
3292
3293 shaderObject->compile();
3294 }
3295 }
3296 catch(std::bad_alloc&)
3297 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003298 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003299 }
3300}
3301
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003302void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
3303 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003305 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003306 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003307 target, level, internalformat, width, height, border, imageSize, data);
3308
3309 try
3310 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003311 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003312
3313 if (context)
3314 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003315 if (context->getClientVersion() < 3 &&
3316 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3317 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3318 {
3319 return;
3320 }
3321
3322 if (context->getClientVersion() >= 3 &&
3323 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3324 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3325 {
3326 return;
3327 }
3328
3329 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003331 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003332 }
3333
3334 switch (target)
3335 {
3336 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003337 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003338 gl::Texture2D *texture = context->getTexture2D();
3339 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003340 }
3341 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003342
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003343 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3344 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3345 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3346 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3347 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3348 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003349 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003350 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3351 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003352 }
3353 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003354
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003355 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003356 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003357 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003358 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003359 }
3360 catch(std::bad_alloc&)
3361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003362 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003363 }
3364}
3365
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003366void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3367 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003369 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003370 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003371 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003372 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3373
3374 try
3375 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003376 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003377
3378 if (context)
3379 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003380 if (context->getClientVersion() < 3 &&
3381 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3382 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3383 {
3384 return;
3385 }
3386
3387 if (context->getClientVersion() >= 3 &&
3388 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3389 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3390 {
3391 return;
3392 }
3393
3394 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003396 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003397 }
3398
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003399 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003400 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003401 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003402 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003403 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003404 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003405 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003406 break;
3407
3408 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3409 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3410 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3411 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3412 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3413 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003414 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003415 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003416 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003417 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003418 break;
3419
3420 default:
3421 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003422 }
3423 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003424 }
3425 catch(std::bad_alloc&)
3426 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003427 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 }
3429}
3430
3431void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3432{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003433 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003434 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003435 target, level, internalformat, x, y, width, height, border);
3436
3437 try
3438 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003440
3441 if (context)
3442 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003443 if (context->getClientVersion() < 3 &&
3444 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3445 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003446 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003447 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003448 }
3449
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003450 if (context->getClientVersion() >= 3 &&
3451 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3452 0, 0, 0, x, y, width, height, border))
3453 {
3454 return;
3455 }
3456
3457 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3458
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003459 switch (target)
3460 {
3461 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003462 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003463 gl::Texture2D *texture = context->getTexture2D();
3464 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003465 }
3466 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003467
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003468 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3469 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3470 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3471 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3472 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3473 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003474 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003475 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3476 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003477 }
3478 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003479
3480 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003481 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003482 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003483 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003484 }
3485 catch(std::bad_alloc&)
3486 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003487 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488 }
3489}
3490
3491void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3492{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003493 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003494 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003495 target, level, xoffset, yoffset, x, y, width, height);
3496
3497 try
3498 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003499 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003500
3501 if (context)
3502 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003503 if (context->getClientVersion() < 3 &&
3504 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3505 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003506 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003507 return;
3508 }
3509
3510 if (context->getClientVersion() >= 3 &&
3511 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3512 xoffset, yoffset, 0, x, y, width, height, 0))
3513 {
3514 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003515 }
3516
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003517 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003518
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003519 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003520 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003521 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003522 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003523 gl::Texture2D *texture = context->getTexture2D();
3524 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003525 }
3526 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003527
3528 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3529 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3530 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3531 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3532 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3533 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003534 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003535 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3536 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003537 }
3538 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003539
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003540 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003541 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003542 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003543 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003544 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003545
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003546 catch(std::bad_alloc&)
3547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003548 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003549 }
3550}
3551
3552GLuint __stdcall glCreateProgram(void)
3553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003554 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003555
3556 try
3557 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003558 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559
3560 if (context)
3561 {
3562 return context->createProgram();
3563 }
3564 }
3565 catch(std::bad_alloc&)
3566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003567 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568 }
3569
3570 return 0;
3571}
3572
3573GLuint __stdcall glCreateShader(GLenum type)
3574{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003575 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003576
3577 try
3578 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003579 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580
3581 if (context)
3582 {
3583 switch (type)
3584 {
3585 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003586 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003587 return context->createShader(type);
3588 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003589 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003590 }
3591 }
3592 }
3593 catch(std::bad_alloc&)
3594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003595 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003596 }
3597
3598 return 0;
3599}
3600
3601void __stdcall glCullFace(GLenum mode)
3602{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003603 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003604
3605 try
3606 {
3607 switch (mode)
3608 {
3609 case GL_FRONT:
3610 case GL_BACK:
3611 case GL_FRONT_AND_BACK:
3612 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003613 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614
3615 if (context)
3616 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003617 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618 }
3619 }
3620 break;
3621 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003622 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003623 }
3624 }
3625 catch(std::bad_alloc&)
3626 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003627 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003628 }
3629}
3630
3631void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3632{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003633 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003634
3635 try
3636 {
3637 if (n < 0)
3638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003639 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 }
3641
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003642 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003643
3644 if (context)
3645 {
3646 for (int i = 0; i < n; i++)
3647 {
3648 context->deleteBuffer(buffers[i]);
3649 }
3650 }
3651 }
3652 catch(std::bad_alloc&)
3653 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003654 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655 }
3656}
3657
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003658void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3659{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003660 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003661
3662 try
3663 {
3664 if (n < 0)
3665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003666 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003667 }
3668
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003669 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003670
3671 if (context)
3672 {
3673 for (int i = 0; i < n; i++)
3674 {
Jamie Madill33dc8432013-07-26 11:55:05 -04003675 context->deleteFenceNV(fences[i]);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003676 }
3677 }
3678 }
3679 catch(std::bad_alloc&)
3680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003681 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003682 }
3683}
3684
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003685void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3686{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003687 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003688
3689 try
3690 {
3691 if (n < 0)
3692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003693 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003694 }
3695
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003696 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003697
3698 if (context)
3699 {
3700 for (int i = 0; i < n; i++)
3701 {
3702 if (framebuffers[i] != 0)
3703 {
3704 context->deleteFramebuffer(framebuffers[i]);
3705 }
3706 }
3707 }
3708 }
3709 catch(std::bad_alloc&)
3710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003711 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712 }
3713}
3714
3715void __stdcall glDeleteProgram(GLuint program)
3716{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003717 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003718
3719 try
3720 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003721 if (program == 0)
3722 {
3723 return;
3724 }
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 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003730 if (!context->getProgram(program))
3731 {
3732 if(context->getShader(program))
3733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003734 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003735 }
3736 else
3737 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003738 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003739 }
3740 }
3741
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003742 context->deleteProgram(program);
3743 }
3744 }
3745 catch(std::bad_alloc&)
3746 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003747 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003748 }
3749}
3750
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003751void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3752{
3753 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3754
3755 try
3756 {
3757 if (n < 0)
3758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003759 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003760 }
3761
3762 gl::Context *context = gl::getNonLostContext();
3763
3764 if (context)
3765 {
3766 for (int i = 0; i < n; i++)
3767 {
3768 context->deleteQuery(ids[i]);
3769 }
3770 }
3771 }
3772 catch(std::bad_alloc&)
3773 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003774 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003775 }
3776}
3777
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003780 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003781
3782 try
3783 {
3784 if (n < 0)
3785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003787 }
3788
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003789 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003790
3791 if (context)
3792 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003793 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003794 {
3795 context->deleteRenderbuffer(renderbuffers[i]);
3796 }
3797 }
3798 }
3799 catch(std::bad_alloc&)
3800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003801 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003802 }
3803}
3804
3805void __stdcall glDeleteShader(GLuint shader)
3806{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003807 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003808
3809 try
3810 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003811 if (shader == 0)
3812 {
3813 return;
3814 }
3815
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003816 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003817
3818 if (context)
3819 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003820 if (!context->getShader(shader))
3821 {
3822 if(context->getProgram(shader))
3823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003824 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003825 }
3826 else
3827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003828 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003829 }
3830 }
3831
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003832 context->deleteShader(shader);
3833 }
3834 }
3835 catch(std::bad_alloc&)
3836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003837 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838 }
3839}
3840
3841void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3842{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003843 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003844
3845 try
3846 {
3847 if (n < 0)
3848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003849 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850 }
3851
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003852 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003853
3854 if (context)
3855 {
3856 for (int i = 0; i < n; i++)
3857 {
3858 if (textures[i] != 0)
3859 {
3860 context->deleteTexture(textures[i]);
3861 }
3862 }
3863 }
3864 }
3865 catch(std::bad_alloc&)
3866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003867 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003868 }
3869}
3870
3871void __stdcall glDepthFunc(GLenum func)
3872{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003873 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003874
3875 try
3876 {
3877 switch (func)
3878 {
3879 case GL_NEVER:
3880 case GL_ALWAYS:
3881 case GL_LESS:
3882 case GL_LEQUAL:
3883 case GL_EQUAL:
3884 case GL_GREATER:
3885 case GL_GEQUAL:
3886 case GL_NOTEQUAL:
3887 break;
3888 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003889 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003890 }
3891
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003892 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003893
3894 if (context)
3895 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003896 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003897 }
3898 }
3899 catch(std::bad_alloc&)
3900 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003901 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902 }
3903}
3904
3905void __stdcall glDepthMask(GLboolean flag)
3906{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003907 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003908
3909 try
3910 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003911 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003912
3913 if (context)
3914 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003915 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003916 }
3917 }
3918 catch(std::bad_alloc&)
3919 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003920 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003921 }
3922}
3923
3924void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3925{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003926 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927
3928 try
3929 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003930 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003931
3932 if (context)
3933 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003934 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003935 }
3936 }
3937 catch(std::bad_alloc&)
3938 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003939 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003940 }
3941}
3942
3943void __stdcall glDetachShader(GLuint program, GLuint shader)
3944{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003945 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003946
3947 try
3948 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003949 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003950
3951 if (context)
3952 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003953
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003954 gl::Program *programObject = context->getProgram(program);
3955 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003956
3957 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003958 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003959 gl::Shader *shaderByProgramHandle;
3960 shaderByProgramHandle = context->getShader(program);
3961 if (!shaderByProgramHandle)
3962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003963 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003964 }
3965 else
3966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003967 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003968 }
3969 }
3970
3971 if (!shaderObject)
3972 {
3973 gl::Program *programByShaderHandle = context->getProgram(shader);
3974 if (!programByShaderHandle)
3975 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003976 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003977 }
3978 else
3979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003980 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003981 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003982 }
3983
3984 if (!programObject->detachShader(shaderObject))
3985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003986 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003987 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003988 }
3989 }
3990 catch(std::bad_alloc&)
3991 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003992 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003993 }
3994}
3995
3996void __stdcall glDisable(GLenum cap)
3997{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003998 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003999
4000 try
4001 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004002 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004003
4004 if (context)
4005 {
4006 switch (cap)
4007 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004008 case GL_CULL_FACE: context->setCullFace(false); break;
4009 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
4010 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
4011 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
4012 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
4013 case GL_STENCIL_TEST: context->setStencilTest(false); break;
4014 case GL_DEPTH_TEST: context->setDepthTest(false); break;
4015 case GL_BLEND: context->setBlend(false); break;
4016 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00004017
4018 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
4019 case GL_RASTERIZER_DISCARD:
4020 if (context->getClientVersion() < 3)
4021 {
4022 return gl::error(GL_INVALID_ENUM);
4023 }
4024 UNIMPLEMENTED();
4025 break;
4026
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004027 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004028 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004029 }
4030 }
4031 }
4032 catch(std::bad_alloc&)
4033 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004034 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004035 }
4036}
4037
4038void __stdcall glDisableVertexAttribArray(GLuint index)
4039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004040 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004041
4042 try
4043 {
4044 if (index >= gl::MAX_VERTEX_ATTRIBS)
4045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004046 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004047 }
4048
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004049 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004050
4051 if (context)
4052 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004053 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004054 }
4055 }
4056 catch(std::bad_alloc&)
4057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004058 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004059 }
4060}
4061
4062void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
4063{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004064 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065
4066 try
4067 {
4068 if (count < 0 || first < 0)
4069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004070 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004071 }
4072
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004073 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004074
4075 if (context)
4076 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004077 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004078 }
4079 }
4080 catch(std::bad_alloc&)
4081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004082 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004083 }
4084}
4085
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004086void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
4087{
4088 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
4089
4090 try
4091 {
4092 if (count < 0 || first < 0 || primcount < 0)
4093 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004094 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004095 }
4096
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004097 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004098 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004099 gl::Context *context = gl::getNonLostContext();
4100
4101 if (context)
4102 {
4103 context->drawArrays(mode, first, count, primcount);
4104 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004105 }
4106 }
4107 catch(std::bad_alloc&)
4108 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004109 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004110 }
4111}
4112
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004113void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004114{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004115 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 +00004116 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004117
4118 try
4119 {
4120 if (count < 0)
4121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004122 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004123 }
4124
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004125 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004126
4127 if (context)
4128 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004129 switch (type)
4130 {
4131 case GL_UNSIGNED_BYTE:
4132 case GL_UNSIGNED_SHORT:
4133 break;
4134 case GL_UNSIGNED_INT:
4135 if (!context->supports32bitIndices())
4136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00004138 }
4139 break;
4140 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004141 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00004142 }
4143
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004144 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004145 }
4146 }
4147 catch(std::bad_alloc&)
4148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004149 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004150 }
4151}
4152
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004153void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
4154{
4155 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
4156 mode, count, type, indices, primcount);
4157
4158 try
4159 {
4160 if (count < 0 || primcount < 0)
4161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004162 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004163 }
4164
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004165 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004166 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004167 gl::Context *context = gl::getNonLostContext();
4168
4169 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004170 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004171 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004172 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004173 case GL_UNSIGNED_BYTE:
4174 case GL_UNSIGNED_SHORT:
4175 break;
4176 case GL_UNSIGNED_INT:
4177 if (!context->supports32bitIndices())
4178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004179 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004180 }
4181 break;
4182 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004183 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004184 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004185
4186 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004187 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004188 }
4189 }
4190 catch(std::bad_alloc&)
4191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004192 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004193 }
4194}
4195
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004196void __stdcall glEnable(GLenum cap)
4197{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004198 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004199
4200 try
4201 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004202 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004203
4204 if (context)
4205 {
4206 switch (cap)
4207 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004208 case GL_CULL_FACE: context->setCullFace(true); break;
4209 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
4210 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
4211 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
4212 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
4213 case GL_STENCIL_TEST: context->setStencilTest(true); break;
4214 case GL_DEPTH_TEST: context->setDepthTest(true); break;
4215 case GL_BLEND: context->setBlend(true); break;
4216 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004217 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004218 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004219 }
4220 }
4221 }
4222 catch(std::bad_alloc&)
4223 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004224 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225 }
4226}
4227
4228void __stdcall glEnableVertexAttribArray(GLuint index)
4229{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004230 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004231
4232 try
4233 {
4234 if (index >= gl::MAX_VERTEX_ATTRIBS)
4235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004236 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237 }
4238
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004239 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004240
4241 if (context)
4242 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004243 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004244 }
4245 }
4246 catch(std::bad_alloc&)
4247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004248 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004249 }
4250}
4251
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004252void __stdcall glEndQueryEXT(GLenum target)
4253{
4254 EVENT("GLenum target = 0x%X)", target);
4255
4256 try
4257 {
4258 switch (target)
4259 {
4260 case GL_ANY_SAMPLES_PASSED_EXT:
4261 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
4262 break;
4263 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004264 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004265 }
4266
4267 gl::Context *context = gl::getNonLostContext();
4268
4269 if (context)
4270 {
4271 context->endQuery(target);
4272 }
4273 }
4274 catch(std::bad_alloc&)
4275 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004276 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004277 }
4278}
4279
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004280void __stdcall glFinishFenceNV(GLuint fence)
4281{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004282 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004283
4284 try
4285 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004286 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004287
4288 if (context)
4289 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004290 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004291
4292 if (fenceObject == NULL)
4293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004294 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004295 }
4296
Jamie Madillfb9a7402013-07-26 11:55:01 -04004297 if (fenceObject->isFence() != GL_TRUE)
4298 {
4299 return gl::error(GL_INVALID_OPERATION);
4300 }
4301
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004302 fenceObject->finishFence();
4303 }
4304 }
4305 catch(std::bad_alloc&)
4306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004307 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004308 }
4309}
4310
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004311void __stdcall glFinish(void)
4312{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004313 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004314
4315 try
4316 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004317 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004318
4319 if (context)
4320 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004321 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004322 }
4323 }
4324 catch(std::bad_alloc&)
4325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004326 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004327 }
4328}
4329
4330void __stdcall glFlush(void)
4331{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004332 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004333
4334 try
4335 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004337
4338 if (context)
4339 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004340 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004341 }
4342 }
4343 catch(std::bad_alloc&)
4344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004345 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004346 }
4347}
4348
4349void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4350{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004351 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004352 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004353
4354 try
4355 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004356 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004357 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004359 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004360 }
4361
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004362 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004363
4364 if (context)
4365 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004366 gl::Framebuffer *framebuffer = NULL;
4367 GLuint framebufferHandle = 0;
4368 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4369 {
4370 framebuffer = context->getReadFramebuffer();
4371 framebufferHandle = context->getReadFramebufferHandle();
4372 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004373 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004374 {
4375 framebuffer = context->getDrawFramebuffer();
4376 framebufferHandle = context->getDrawFramebufferHandle();
4377 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004379 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004380 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004381 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004382 }
4383
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004384 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004385 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004386 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4387
4388 if (colorAttachment >= context->getMaximumRenderTargets())
4389 {
4390 return gl::error(GL_INVALID_VALUE);
4391 }
4392
Geoff Lang309c92a2013-07-25 16:23:19 -04004393 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004394 }
4395 else
4396 {
4397 switch (attachment)
4398 {
4399 case GL_DEPTH_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004400 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004401 break;
4402 case GL_STENCIL_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004403 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004404 break;
4405 default:
4406 return gl::error(GL_INVALID_ENUM);
4407 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004408 }
4409 }
4410 }
4411 catch(std::bad_alloc&)
4412 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004413 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004414 }
4415}
4416
4417void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4418{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004419 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004420 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004421
4422 try
4423 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004424 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004425 if (context)
4426 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004427 if (context->getClientVersion() < 3 &&
4428 !validateES2FramebufferTextureParameters(context, target, attachment, textarget, texture, level))
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004429 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004430 return;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004431 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04004432
4433 if (context->getClientVersion() >= 3 &&
4434 !validateES3FramebufferTextureParameters(context, target, attachment, textarget, texture, level, 0, false))
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004435 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004436 return;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004437 }
4438
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004439 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004440 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004441 textarget = GL_NONE;
4442 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004443
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004444 gl::Framebuffer *framebuffer = NULL;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004445 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4446 {
4447 framebuffer = context->getReadFramebuffer();
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004448 }
4449 else
4450 {
4451 framebuffer = context->getDrawFramebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004452 }
4453
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004454 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004455 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004456 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
Geoff Lang309c92a2013-07-25 16:23:19 -04004457 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004458 }
4459 else
4460 {
4461 switch (attachment)
4462 {
Geoff Lang309c92a2013-07-25 16:23:19 -04004463 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
4464 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
4465 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004466 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004467 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468 }
4469 }
4470 catch(std::bad_alloc&)
4471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004472 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473 }
4474}
4475
4476void __stdcall glFrontFace(GLenum mode)
4477{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004478 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479
4480 try
4481 {
4482 switch (mode)
4483 {
4484 case GL_CW:
4485 case GL_CCW:
4486 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004487 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004488
4489 if (context)
4490 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004491 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004492 }
4493 }
4494 break;
4495 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004496 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004497 }
4498 }
4499 catch(std::bad_alloc&)
4500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004501 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502 }
4503}
4504
4505void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4506{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004507 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508
4509 try
4510 {
4511 if (n < 0)
4512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004513 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004514 }
4515
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004516 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004517
4518 if (context)
4519 {
4520 for (int i = 0; i < n; i++)
4521 {
4522 buffers[i] = context->createBuffer();
4523 }
4524 }
4525 }
4526 catch(std::bad_alloc&)
4527 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004528 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529 }
4530}
4531
4532void __stdcall glGenerateMipmap(GLenum target)
4533{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004534 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004535
4536 try
4537 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004538 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004539
4540 if (context)
4541 {
Geoff Langae4852a2013-06-05 15:00:34 -04004542 gl::Texture *texture = NULL;
4543 GLint internalFormat = GL_NONE;
4544 bool isCompressed = false;
4545 bool isDepth = false;
4546
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004547 switch (target)
4548 {
4549 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004550 {
4551 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004552 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004553 {
Geoff Langae4852a2013-06-05 15:00:34 -04004554 internalFormat = tex2d->getInternalFormat(0);
4555 isCompressed = tex2d->isCompressed(0);
4556 isDepth = tex2d->isDepth(0);
4557 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004558 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004559 break;
4560 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004561
4562 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004563 {
4564 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004565 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004566 {
Geoff Langae4852a2013-06-05 15:00:34 -04004567 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4568 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4569 isDepth = false;
4570 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004571 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004572 break;
4573 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004574
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004575 case GL_TEXTURE_3D:
4576 {
4577 if (context->getClientVersion() < 3)
4578 {
4579 return gl::error(GL_INVALID_ENUM);
4580 }
4581
4582 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004583 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004584 {
Geoff Langae4852a2013-06-05 15:00:34 -04004585 internalFormat = tex3D->getInternalFormat(0);
4586 isCompressed = tex3D->isCompressed(0);
4587 isDepth = tex3D->isDepth(0);
4588 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004589 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004590 break;
4591 }
4592
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004593 case GL_TEXTURE_2D_ARRAY:
4594 {
4595 if (context->getClientVersion() < 3)
4596 {
4597 return gl::error(GL_INVALID_ENUM);
4598 }
4599
4600 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004601 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004602 {
Geoff Langae4852a2013-06-05 15:00:34 -04004603 internalFormat = tex2darr->getInternalFormat(0);
4604 isCompressed = tex2darr->isCompressed(0);
4605 isDepth = tex2darr->isDepth(0);
4606 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004607 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004608 break;
4609 }
4610
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004611 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004612 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004613 }
Geoff Langae4852a2013-06-05 15:00:34 -04004614
4615 if (!texture)
4616 {
4617 return gl::error(GL_INVALID_OPERATION);
4618 }
4619
4620 // Internally, all texture formats are sized so checking if the format
4621 // is color renderable and filterable will not fail.
4622 if (isDepth || isCompressed ||
4623 !gl::IsColorRenderingSupported(internalFormat, context) ||
4624 !gl::IsTextureFilteringSupported(internalFormat, context))
4625 {
4626 return gl::error(GL_INVALID_OPERATION);
4627 }
4628
4629 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004630 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004631 }
4632 catch(std::bad_alloc&)
4633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004634 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004635 }
4636}
4637
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004638void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4639{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004640 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004641
4642 try
4643 {
4644 if (n < 0)
4645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004646 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004647 }
4648
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004649 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004650
4651 if (context)
4652 {
4653 for (int i = 0; i < n; i++)
4654 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004655 fences[i] = context->createFenceNV();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004656 }
4657 }
4658 }
4659 catch(std::bad_alloc&)
4660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004661 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004662 }
4663}
4664
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4666{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004667 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004668
4669 try
4670 {
4671 if (n < 0)
4672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004673 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674 }
4675
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004676 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004677
4678 if (context)
4679 {
4680 for (int i = 0; i < n; i++)
4681 {
4682 framebuffers[i] = context->createFramebuffer();
4683 }
4684 }
4685 }
4686 catch(std::bad_alloc&)
4687 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004688 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004689 }
4690}
4691
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004692void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4693{
4694 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4695
4696 try
4697 {
4698 if (n < 0)
4699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004700 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004701 }
4702
4703 gl::Context *context = gl::getNonLostContext();
4704
4705 if (context)
4706 {
4707 for (int i = 0; i < n; i++)
4708 {
4709 ids[i] = context->createQuery();
4710 }
4711 }
4712 }
4713 catch(std::bad_alloc&)
4714 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004715 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004716 }
4717}
4718
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004719void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4720{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004721 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004722
4723 try
4724 {
4725 if (n < 0)
4726 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004727 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004728 }
4729
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004730 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004731
4732 if (context)
4733 {
4734 for (int i = 0; i < n; i++)
4735 {
4736 renderbuffers[i] = context->createRenderbuffer();
4737 }
4738 }
4739 }
4740 catch(std::bad_alloc&)
4741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004742 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004743 }
4744}
4745
4746void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4747{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004748 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004749
4750 try
4751 {
4752 if (n < 0)
4753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004754 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004755 }
4756
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004757 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004758
4759 if (context)
4760 {
4761 for (int i = 0; i < n; i++)
4762 {
4763 textures[i] = context->createTexture();
4764 }
4765 }
4766 }
4767 catch(std::bad_alloc&)
4768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004769 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004770 }
4771}
4772
daniel@transgaming.com85423182010-04-22 13:35:27 +00004773void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004775 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004776 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004777 program, index, bufsize, length, size, type, name);
4778
4779 try
4780 {
4781 if (bufsize < 0)
4782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004783 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004784 }
4785
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004786 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004787
4788 if (context)
4789 {
4790 gl::Program *programObject = context->getProgram(program);
4791
4792 if (!programObject)
4793 {
4794 if (context->getShader(program))
4795 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004796 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004797 }
4798 else
4799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004800 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004801 }
4802 }
4803
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004804 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004806 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004807 }
4808
4809 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4810 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004811 }
4812 catch(std::bad_alloc&)
4813 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004814 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004815 }
4816}
4817
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004818void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004819{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004820 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004821 "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 +00004822 program, index, bufsize, length, size, type, name);
4823
4824 try
4825 {
4826 if (bufsize < 0)
4827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004828 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004829 }
4830
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004831 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004832
4833 if (context)
4834 {
4835 gl::Program *programObject = context->getProgram(program);
4836
4837 if (!programObject)
4838 {
4839 if (context->getShader(program))
4840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004841 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004842 }
4843 else
4844 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004845 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004846 }
4847 }
4848
4849 if (index >= (GLuint)programObject->getActiveUniformCount())
4850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004851 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004852 }
4853
4854 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4855 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004856 }
4857 catch(std::bad_alloc&)
4858 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004859 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004860 }
4861}
4862
4863void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004865 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 +00004866 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004867
4868 try
4869 {
4870 if (maxcount < 0)
4871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004872 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004873 }
4874
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004875 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004876
4877 if (context)
4878 {
4879 gl::Program *programObject = context->getProgram(program);
4880
4881 if (!programObject)
4882 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004883 if (context->getShader(program))
4884 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004885 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004886 }
4887 else
4888 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004889 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004890 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004891 }
4892
4893 return programObject->getAttachedShaders(maxcount, count, shaders);
4894 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004895 }
4896 catch(std::bad_alloc&)
4897 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004898 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004899 }
4900}
4901
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004902int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004903{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004904 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004905
4906 try
4907 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004908 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004909
4910 if (context)
4911 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004912
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004913 gl::Program *programObject = context->getProgram(program);
4914
4915 if (!programObject)
4916 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004917 if (context->getShader(program))
4918 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004919 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004920 }
4921 else
4922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004923 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004924 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004925 }
4926
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004927 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004928 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004929 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004930 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004931 }
4932
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004933 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004934 }
4935 }
4936 catch(std::bad_alloc&)
4937 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004938 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004939 }
4940
4941 return -1;
4942}
4943
4944void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4945{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004946 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004947
4948 try
4949 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004950 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004951
4952 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004953 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004954 if (!(context->getBooleanv(pname, params)))
4955 {
4956 GLenum nativeType;
4957 unsigned int numParams = 0;
4958 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004959 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004960
4961 if (numParams == 0)
4962 return; // it is known that the pname is valid, but there are no parameters to return
4963
4964 if (nativeType == GL_FLOAT)
4965 {
4966 GLfloat *floatParams = NULL;
4967 floatParams = new GLfloat[numParams];
4968
4969 context->getFloatv(pname, floatParams);
4970
4971 for (unsigned int i = 0; i < numParams; ++i)
4972 {
4973 if (floatParams[i] == 0.0f)
4974 params[i] = GL_FALSE;
4975 else
4976 params[i] = GL_TRUE;
4977 }
4978
4979 delete [] floatParams;
4980 }
4981 else if (nativeType == GL_INT)
4982 {
4983 GLint *intParams = NULL;
4984 intParams = new GLint[numParams];
4985
4986 context->getIntegerv(pname, intParams);
4987
4988 for (unsigned int i = 0; i < numParams; ++i)
4989 {
4990 if (intParams[i] == 0)
4991 params[i] = GL_FALSE;
4992 else
4993 params[i] = GL_TRUE;
4994 }
4995
4996 delete [] intParams;
4997 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004998 else if (nativeType == GL_INT_64_ANGLEX)
4999 {
5000 GLint64 *int64Params = NULL;
5001 int64Params = new GLint64[numParams];
5002
5003 context->getInteger64v(pname, int64Params);
5004
5005 for (unsigned int i = 0; i < numParams; ++i)
5006 {
5007 if (int64Params[i] == 0)
5008 params[i] = GL_FALSE;
5009 else
5010 params[i] = GL_TRUE;
5011 }
5012
5013 delete [] int64Params;
5014 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005015 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005016 }
5017 }
5018 catch(std::bad_alloc&)
5019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005020 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005021 }
5022}
5023
5024void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
5025{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005026 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 +00005027
5028 try
5029 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005030 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005031
5032 if (context)
5033 {
5034 gl::Buffer *buffer;
5035
5036 switch (target)
5037 {
5038 case GL_ARRAY_BUFFER:
5039 buffer = context->getArrayBuffer();
5040 break;
5041 case GL_ELEMENT_ARRAY_BUFFER:
5042 buffer = context->getElementArrayBuffer();
5043 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005044 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005045 }
5046
5047 if (!buffer)
5048 {
5049 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005050 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005051 }
5052
5053 switch (pname)
5054 {
5055 case GL_BUFFER_USAGE:
5056 *params = buffer->usage();
5057 break;
5058 case GL_BUFFER_SIZE:
5059 *params = buffer->size();
5060 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005061 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005062 }
5063 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005064 }
5065 catch(std::bad_alloc&)
5066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005067 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005068 }
5069}
5070
5071GLenum __stdcall glGetError(void)
5072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005073 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005074
5075 gl::Context *context = gl::getContext();
5076
5077 if (context)
5078 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00005079 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005080 }
5081
5082 return GL_NO_ERROR;
5083}
5084
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005085void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
5086{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005087 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005088
5089 try
5090 {
5091
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005092 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005093
5094 if (context)
5095 {
Jamie Madill33dc8432013-07-26 11:55:05 -04005096 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005097
5098 if (fenceObject == NULL)
5099 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005100 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005101 }
5102
Jamie Madillfb9a7402013-07-26 11:55:01 -04005103 if (fenceObject->isFence() != GL_TRUE)
5104 {
5105 return gl::error(GL_INVALID_OPERATION);
5106 }
5107
5108 switch (pname)
5109 {
5110 case GL_FENCE_STATUS_NV:
5111 case GL_FENCE_CONDITION_NV:
5112 break;
5113
5114 default: return gl::error(GL_INVALID_ENUM);
5115 }
5116
5117 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005118 }
5119 }
5120 catch(std::bad_alloc&)
5121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005122 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005123 }
5124}
5125
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005126void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
5127{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005128 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005129
5130 try
5131 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005132 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005133
5134 if (context)
5135 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005136 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005137 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005138 GLenum nativeType;
5139 unsigned int numParams = 0;
5140 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005141 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005142
5143 if (numParams == 0)
5144 return; // it is known that the pname is valid, but that there are no parameters to return.
5145
5146 if (nativeType == GL_BOOL)
5147 {
5148 GLboolean *boolParams = NULL;
5149 boolParams = new GLboolean[numParams];
5150
5151 context->getBooleanv(pname, boolParams);
5152
5153 for (unsigned int i = 0; i < numParams; ++i)
5154 {
5155 if (boolParams[i] == GL_FALSE)
5156 params[i] = 0.0f;
5157 else
5158 params[i] = 1.0f;
5159 }
5160
5161 delete [] boolParams;
5162 }
5163 else if (nativeType == GL_INT)
5164 {
5165 GLint *intParams = NULL;
5166 intParams = new GLint[numParams];
5167
5168 context->getIntegerv(pname, intParams);
5169
5170 for (unsigned int i = 0; i < numParams; ++i)
5171 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005172 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005173 }
5174
5175 delete [] intParams;
5176 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005177 else if (nativeType == GL_INT_64_ANGLEX)
5178 {
5179 GLint64 *int64Params = NULL;
5180 int64Params = new GLint64[numParams];
5181
5182 context->getInteger64v(pname, int64Params);
5183
5184 for (unsigned int i = 0; i < numParams; ++i)
5185 {
5186 params[i] = static_cast<GLfloat>(int64Params[i]);
5187 }
5188
5189 delete [] int64Params;
5190 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005191 }
5192 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005193 }
5194 catch(std::bad_alloc&)
5195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005196 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005197 }
5198}
5199
5200void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
5201{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005202 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 +00005203 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005204
5205 try
5206 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005207 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005208
5209 if (context)
5210 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005211 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005213 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005214 }
5215
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005216 gl::Framebuffer *framebuffer = NULL;
5217 if (target == GL_READ_FRAMEBUFFER_ANGLE)
5218 {
5219 if(context->getReadFramebufferHandle() == 0)
5220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005221 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005222 }
5223
5224 framebuffer = context->getReadFramebuffer();
5225 }
5226 else
5227 {
5228 if (context->getDrawFramebufferHandle() == 0)
5229 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005230 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005231 }
5232
5233 framebuffer = context->getDrawFramebuffer();
5234 }
5235
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005236 GLenum attachmentType;
5237 GLuint attachmentHandle;
Geoff Lang309c92a2013-07-25 16:23:19 -04005238 GLuint attachmentLevel;
5239 GLuint attachmentLayer;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005240
5241 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005242 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005243 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5244
5245 if (colorAttachment >= context->getMaximumRenderTargets())
5246 {
5247 return gl::error(GL_INVALID_ENUM);
5248 }
5249
5250 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5251 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
Geoff Lang309c92a2013-07-25 16:23:19 -04005252 attachmentLevel = framebuffer->getColorbufferMipLevel(colorAttachment);
5253 attachmentLayer = framebuffer->getColorbufferLayer(colorAttachment);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005254 }
5255 else
5256 {
5257 switch (attachment)
5258 {
5259 case GL_DEPTH_ATTACHMENT:
5260 attachmentType = framebuffer->getDepthbufferType();
5261 attachmentHandle = framebuffer->getDepthbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005262 attachmentLevel = framebuffer->getDepthbufferMipLevel();
5263 attachmentLayer = framebuffer->getDepthbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005264 break;
5265 case GL_STENCIL_ATTACHMENT:
5266 attachmentType = framebuffer->getStencilbufferType();
5267 attachmentHandle = framebuffer->getStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005268 attachmentLevel = framebuffer->getStencilbufferMipLevel();
5269 attachmentLayer = framebuffer->getStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005270 break;
Geoff Lang55ba29c2013-07-11 16:57:53 -04005271 case GL_DEPTH_STENCIL_ATTACHMENT:
5272 if (context->getClientVersion() < 3)
5273 {
5274 return gl::error(GL_INVALID_ENUM);
5275 }
5276 if (framebuffer->getDepthbufferHandle() != framebuffer->getStencilbufferHandle())
5277 {
5278 return gl::error(GL_INVALID_OPERATION);
5279 }
5280 attachmentType = framebuffer->getDepthStencilbufferType();
5281 attachmentHandle = framebuffer->getDepthStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005282 attachmentLevel = framebuffer->getDepthStencilbufferMipLevel();
5283 attachmentLayer = framebuffer->getDepthStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005284 default: return gl::error(GL_INVALID_ENUM);
5285 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005286 }
5287
5288 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005289 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005290 {
5291 attachmentObjectType = attachmentType;
5292 }
Geoff Lang0fe19492013-07-25 17:04:31 -04005293 else if (gl::IsInternalTextureTarget(attachmentType, context->getClientVersion()))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005294 {
5295 attachmentObjectType = GL_TEXTURE;
5296 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005297 else
5298 {
5299 UNREACHABLE();
5300 return;
5301 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005302
5303 switch (pname)
5304 {
5305 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5306 *params = attachmentObjectType;
5307 break;
5308 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5309 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5310 {
5311 *params = attachmentHandle;
5312 }
5313 else
5314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005316 }
5317 break;
5318 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5319 if (attachmentObjectType == GL_TEXTURE)
5320 {
Geoff Lang309c92a2013-07-25 16:23:19 -04005321 *params = attachmentLevel;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005322 }
5323 else
5324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005325 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005326 }
5327 break;
5328 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5329 if (attachmentObjectType == GL_TEXTURE)
5330 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005331 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005332 {
5333 *params = attachmentType;
5334 }
5335 else
5336 {
5337 *params = 0;
5338 }
5339 }
5340 else
5341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005342 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005343 }
5344 break;
Geoff Lang309c92a2013-07-25 16:23:19 -04005345 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
5346 if (context->getClientVersion() < 3)
5347 {
5348 return gl::error(GL_INVALID_ENUM);
5349 }
5350 if (attachmentObjectType == GL_TEXTURE)
5351 {
5352 *params = attachmentLayer;
5353 }
5354 else
5355 {
5356 return gl::error(GL_INVALID_ENUM);
5357 }
5358 break;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005359 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005360 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005361 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005362 }
5363 }
5364 catch(std::bad_alloc&)
5365 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005366 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005367 }
5368}
5369
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005370GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5371{
5372 EVENT("()");
5373
5374 try
5375 {
5376 gl::Context *context = gl::getContext();
5377
5378 if (context)
5379 {
5380 return context->getResetStatus();
5381 }
5382
5383 return GL_NO_ERROR;
5384 }
5385 catch(std::bad_alloc&)
5386 {
5387 return GL_OUT_OF_MEMORY;
5388 }
5389}
5390
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005391void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5392{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005393 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005394
5395 try
5396 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005398
5399 if (context)
5400 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005401 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005402 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005403 GLenum nativeType;
5404 unsigned int numParams = 0;
5405 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005406 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005407
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005408 if (numParams == 0)
5409 return; // it is known that pname is valid, but there are no parameters to return
5410
5411 if (nativeType == GL_BOOL)
5412 {
5413 GLboolean *boolParams = NULL;
5414 boolParams = new GLboolean[numParams];
5415
5416 context->getBooleanv(pname, boolParams);
5417
5418 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005419 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005420 if (boolParams[i] == GL_FALSE)
5421 params[i] = 0;
5422 else
5423 params[i] = 1;
5424 }
5425
5426 delete [] boolParams;
5427 }
5428 else if (nativeType == GL_FLOAT)
5429 {
5430 GLfloat *floatParams = NULL;
5431 floatParams = new GLfloat[numParams];
5432
5433 context->getFloatv(pname, floatParams);
5434
5435 for (unsigned int i = 0; i < numParams; ++i)
5436 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005437 // 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 +00005438 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 +00005439 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005440 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005441 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005442 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005443 {
Jamie Madillaf496912013-07-19 16:36:54 -04005444 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005445 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005446 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005447
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005448 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005449 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005450 else if (nativeType == GL_INT_64_ANGLEX)
5451 {
5452 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5453 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5454 GLint64 *int64Params = NULL;
5455 int64Params = new GLint64[numParams];
5456
5457 context->getInteger64v(pname, int64Params);
5458
5459 for (unsigned int i = 0; i < numParams; ++i)
5460 {
5461 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5462 params[i] = static_cast<GLint>(clampedValue);
5463 }
5464
5465 delete [] int64Params;
5466 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005467 }
5468 }
5469 }
5470 catch(std::bad_alloc&)
5471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005472 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005473 }
5474}
5475
5476void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5477{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005478 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005479
5480 try
5481 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005482 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005483
5484 if (context)
5485 {
5486 gl::Program *programObject = context->getProgram(program);
5487
5488 if (!programObject)
5489 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005490 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005491 }
5492
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005493 if (context->getClientVersion() < 3)
5494 {
5495 switch (pname)
5496 {
5497 case GL_ACTIVE_UNIFORM_BLOCKS:
5498 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5499 return gl::error(GL_INVALID_ENUM);
5500 }
5501 }
5502
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005503 switch (pname)
5504 {
5505 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005506 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005507 return;
5508 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005509 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005510 return;
5511 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005512 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005513 return;
5514 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005515 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005516 return;
5517 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005518 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005519 return;
5520 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005521 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005522 return;
5523 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005524 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005525 return;
5526 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005527 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005528 return;
5529 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005530 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005531 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005532 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005533 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005534 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005535 case GL_ACTIVE_UNIFORM_BLOCKS:
5536 *params = programObject->getActiveUniformBlockCount();
5537 return;
5538 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5539 *params = programObject->getActiveUniformBlockMaxLength();
5540 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005541 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005542 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005543 }
5544 }
5545 }
5546 catch(std::bad_alloc&)
5547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005548 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005549 }
5550}
5551
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005552void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005554 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 +00005555 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005556
5557 try
5558 {
5559 if (bufsize < 0)
5560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005561 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005562 }
5563
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005565
5566 if (context)
5567 {
5568 gl::Program *programObject = context->getProgram(program);
5569
5570 if (!programObject)
5571 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005572 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005573 }
5574
5575 programObject->getInfoLog(bufsize, length, infolog);
5576 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005577 }
5578 catch(std::bad_alloc&)
5579 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005580 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005581 }
5582}
5583
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005584void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5585{
5586 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5587
5588 try
5589 {
5590 switch (pname)
5591 {
5592 case GL_CURRENT_QUERY_EXT:
5593 break;
5594 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005595 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005596 }
5597
5598 gl::Context *context = gl::getNonLostContext();
5599
5600 if (context)
5601 {
5602 params[0] = context->getActiveQuery(target);
5603 }
5604 }
5605 catch(std::bad_alloc&)
5606 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005607 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005608 }
5609}
5610
5611void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5612{
5613 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5614
5615 try
5616 {
5617 switch (pname)
5618 {
5619 case GL_QUERY_RESULT_EXT:
5620 case GL_QUERY_RESULT_AVAILABLE_EXT:
5621 break;
5622 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005623 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005624 }
5625 gl::Context *context = gl::getNonLostContext();
5626
5627 if (context)
5628 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005629 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5630
5631 if (!queryObject)
5632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005633 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005634 }
5635
5636 if (context->getActiveQuery(queryObject->getType()) == id)
5637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005638 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005639 }
5640
5641 switch(pname)
5642 {
5643 case GL_QUERY_RESULT_EXT:
5644 params[0] = queryObject->getResult();
5645 break;
5646 case GL_QUERY_RESULT_AVAILABLE_EXT:
5647 params[0] = queryObject->isResultAvailable();
5648 break;
5649 default:
5650 ASSERT(false);
5651 }
5652 }
5653 }
5654 catch(std::bad_alloc&)
5655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005656 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005657 }
5658}
5659
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005660void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005662 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 +00005663
5664 try
5665 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005666 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005667
5668 if (context)
5669 {
5670 if (target != GL_RENDERBUFFER)
5671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005672 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005673 }
5674
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005675 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005677 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005678 }
5679
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005680 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005681
5682 switch (pname)
5683 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005684 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5685 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5686 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5687 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5688 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5689 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5690 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5691 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5692 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005693 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005694 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005695 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005696 *params = renderbuffer->getSamples();
5697 }
5698 else
5699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005700 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005701 }
5702 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005703 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005704 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005705 }
5706 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005707 }
5708 catch(std::bad_alloc&)
5709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005710 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005711 }
5712}
5713
5714void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005716 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005717
5718 try
5719 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005720 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005721
5722 if (context)
5723 {
5724 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005725
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005726 if (!shaderObject)
5727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005728 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005729 }
5730
5731 switch (pname)
5732 {
5733 case GL_SHADER_TYPE:
5734 *params = shaderObject->getType();
5735 return;
5736 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005737 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005738 return;
5739 case GL_COMPILE_STATUS:
5740 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5741 return;
5742 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005743 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005744 return;
5745 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005746 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005747 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005748 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5749 *params = shaderObject->getTranslatedSourceLength();
5750 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005751 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005752 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005753 }
5754 }
5755 }
5756 catch(std::bad_alloc&)
5757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005758 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005759 }
5760}
5761
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005762void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005764 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 +00005765 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005766
5767 try
5768 {
5769 if (bufsize < 0)
5770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005771 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005772 }
5773
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005774 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005775
5776 if (context)
5777 {
5778 gl::Shader *shaderObject = context->getShader(shader);
5779
5780 if (!shaderObject)
5781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005783 }
5784
5785 shaderObject->getInfoLog(bufsize, length, infolog);
5786 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005787 }
5788 catch(std::bad_alloc&)
5789 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005790 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005791 }
5792}
5793
5794void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5795{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005796 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 +00005797 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005798
5799 try
5800 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005801 switch (shadertype)
5802 {
5803 case GL_VERTEX_SHADER:
5804 case GL_FRAGMENT_SHADER:
5805 break;
5806 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005807 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005808 }
5809
5810 switch (precisiontype)
5811 {
5812 case GL_LOW_FLOAT:
5813 case GL_MEDIUM_FLOAT:
5814 case GL_HIGH_FLOAT:
5815 // Assume IEEE 754 precision
5816 range[0] = 127;
5817 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005818 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005819 break;
5820 case GL_LOW_INT:
5821 case GL_MEDIUM_INT:
5822 case GL_HIGH_INT:
5823 // Some (most) hardware only supports single-precision floating-point numbers,
5824 // which can accurately represent integers up to +/-16777216
5825 range[0] = 24;
5826 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005827 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005828 break;
5829 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005830 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005831 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005832 }
5833 catch(std::bad_alloc&)
5834 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005835 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005836 }
5837}
5838
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005839void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005840{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005841 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 +00005842 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005843
5844 try
5845 {
5846 if (bufsize < 0)
5847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005849 }
5850
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005851 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005852
5853 if (context)
5854 {
5855 gl::Shader *shaderObject = context->getShader(shader);
5856
5857 if (!shaderObject)
5858 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005859 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005860 }
5861
5862 shaderObject->getSource(bufsize, length, source);
5863 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005864 }
5865 catch(std::bad_alloc&)
5866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005867 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005868 }
5869}
5870
zmo@google.coma574f782011-10-03 21:45:23 +00005871void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5872{
5873 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5874 shader, bufsize, length, source);
5875
5876 try
5877 {
5878 if (bufsize < 0)
5879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005880 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005881 }
5882
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005883 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005884
5885 if (context)
5886 {
5887 gl::Shader *shaderObject = context->getShader(shader);
5888
5889 if (!shaderObject)
5890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005891 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005892 }
5893
5894 shaderObject->getTranslatedSource(bufsize, length, source);
5895 }
5896 }
5897 catch(std::bad_alloc&)
5898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005899 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005900 }
5901}
5902
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005903const GLubyte* __stdcall glGetString(GLenum name)
5904{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005905 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005906
5907 try
5908 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005909 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005910
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005911 switch (name)
5912 {
5913 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005914 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005915 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005916 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005917 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005918 if (context->getClientVersion() == 2)
5919 {
5920 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5921 }
5922 else
5923 {
5924 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5925 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005926 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005927 if (context->getClientVersion() == 2)
5928 {
5929 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5930 }
5931 else
5932 {
5933 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5934 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005935 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005936 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005937 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005938 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005939 }
5940 }
5941 catch(std::bad_alloc&)
5942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005943 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005944 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005945}
5946
5947void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5948{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005949 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 +00005950
5951 try
5952 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005953 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005954
5955 if (context)
5956 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005957 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005958
Jamie Madillfb8a8302013-07-03 14:24:12 -04005959 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005961 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005962 }
5963
5964 switch (pname)
5965 {
5966 case GL_TEXTURE_MAG_FILTER:
5967 *params = (GLfloat)texture->getMagFilter();
5968 break;
5969 case GL_TEXTURE_MIN_FILTER:
5970 *params = (GLfloat)texture->getMinFilter();
5971 break;
5972 case GL_TEXTURE_WRAP_S:
5973 *params = (GLfloat)texture->getWrapS();
5974 break;
5975 case GL_TEXTURE_WRAP_T:
5976 *params = (GLfloat)texture->getWrapT();
5977 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005978 case GL_TEXTURE_WRAP_R:
5979 if (context->getClientVersion() < 3)
5980 {
5981 return gl::error(GL_INVALID_ENUM);
5982 }
5983 *params = (GLfloat)texture->getWrapR();
5984 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005985 case GL_TEXTURE_IMMUTABLE_FORMAT:
5986 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005987 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5988 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005989 case GL_TEXTURE_IMMUTABLE_LEVELS:
5990 if (context->getClientVersion() < 3)
5991 {
5992 return gl::error(GL_INVALID_ENUM);
5993 }
5994 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5995 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005996 case GL_TEXTURE_USAGE_ANGLE:
5997 *params = (GLfloat)texture->getUsage();
5998 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005999 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6000 if (!context->supportsTextureFilterAnisotropy())
6001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006002 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006003 }
6004 *params = (GLfloat)texture->getMaxAnisotropy();
6005 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006006 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006007 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006008 }
6009 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006010 }
6011 catch(std::bad_alloc&)
6012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006013 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006014 }
6015}
6016
6017void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
6018{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006019 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 +00006020
6021 try
6022 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006023 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006024
6025 if (context)
6026 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04006027 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006028
Jamie Madillfb8a8302013-07-03 14:24:12 -04006029 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006032 }
6033
6034 switch (pname)
6035 {
6036 case GL_TEXTURE_MAG_FILTER:
6037 *params = texture->getMagFilter();
6038 break;
6039 case GL_TEXTURE_MIN_FILTER:
6040 *params = texture->getMinFilter();
6041 break;
6042 case GL_TEXTURE_WRAP_S:
6043 *params = texture->getWrapS();
6044 break;
6045 case GL_TEXTURE_WRAP_T:
6046 *params = texture->getWrapT();
6047 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006048 case GL_TEXTURE_WRAP_R:
6049 if (context->getClientVersion() < 3)
6050 {
6051 return gl::error(GL_INVALID_ENUM);
6052 }
6053 *params = texture->getWrapR();
6054 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006055 case GL_TEXTURE_IMMUTABLE_FORMAT:
6056 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00006057 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
6058 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006059 case GL_TEXTURE_IMMUTABLE_LEVELS:
6060 if (context->getClientVersion() < 3)
6061 {
6062 return gl::error(GL_INVALID_ENUM);
6063 }
6064 *params = texture->isImmutable() ? texture->levelCount() : 0;
6065 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006066 case GL_TEXTURE_USAGE_ANGLE:
6067 *params = texture->getUsage();
6068 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006069 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6070 if (!context->supportsTextureFilterAnisotropy())
6071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006072 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006073 }
6074 *params = (GLint)texture->getMaxAnisotropy();
6075 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006076
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006077 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006078 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006079 }
6080 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006081 }
6082 catch(std::bad_alloc&)
6083 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006084 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006085 }
6086}
6087
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006088void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
6089{
6090 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
6091 program, location, bufSize, params);
6092
6093 try
6094 {
6095 if (bufSize < 0)
6096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006097 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006098 }
6099
6100 gl::Context *context = gl::getNonLostContext();
6101
6102 if (context)
6103 {
6104 if (program == 0)
6105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006106 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006107 }
6108
6109 gl::Program *programObject = context->getProgram(program);
6110
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006111 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006113 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006114 }
6115
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006116 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6117 if (!programBinary)
6118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006119 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006120 }
6121
6122 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006124 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006125 }
6126 }
6127 }
6128 catch(std::bad_alloc&)
6129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006130 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006131 }
6132}
6133
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006134void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
6135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006136 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006137
6138 try
6139 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006140 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006141
6142 if (context)
6143 {
6144 if (program == 0)
6145 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006146 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006147 }
6148
6149 gl::Program *programObject = context->getProgram(program);
6150
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006151 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006152 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006153 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006154 }
6155
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006156 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6157 if (!programBinary)
6158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006159 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006160 }
6161
6162 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006164 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006165 }
6166 }
6167 }
6168 catch(std::bad_alloc&)
6169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006170 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006171 }
6172}
6173
6174void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
6175{
6176 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
6177 program, location, bufSize, params);
6178
6179 try
6180 {
6181 if (bufSize < 0)
6182 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006183 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006184 }
6185
6186 gl::Context *context = gl::getNonLostContext();
6187
6188 if (context)
6189 {
6190 if (program == 0)
6191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006192 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006193 }
6194
6195 gl::Program *programObject = context->getProgram(program);
6196
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006197 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006198 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006199 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006200 }
6201
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006202 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6203 if (!programBinary)
6204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006205 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006206 }
6207
6208 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006210 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006211 }
6212 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006213 }
6214 catch(std::bad_alloc&)
6215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006216 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006217 }
6218}
6219
6220void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
6221{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006222 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006223
6224 try
6225 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006226 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006227
6228 if (context)
6229 {
6230 if (program == 0)
6231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006233 }
6234
6235 gl::Program *programObject = context->getProgram(program);
6236
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006237 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006239 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006240 }
6241
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006242 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6243 if (!programBinary)
6244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006245 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006246 }
6247
6248 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006249 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006250 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006251 }
6252 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006253 }
6254 catch(std::bad_alloc&)
6255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006256 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006257 }
6258}
6259
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006260int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006262 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006263
6264 try
6265 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006266 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006267
6268 if (strstr(name, "gl_") == name)
6269 {
6270 return -1;
6271 }
6272
6273 if (context)
6274 {
6275 gl::Program *programObject = context->getProgram(program);
6276
6277 if (!programObject)
6278 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006279 if (context->getShader(program))
6280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006281 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006282 }
6283 else
6284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006285 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006286 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006287 }
6288
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006289 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006290 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006291 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006292 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006293 }
6294
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006295 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006296 }
6297 }
6298 catch(std::bad_alloc&)
6299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006300 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006301 }
6302
6303 return -1;
6304}
6305
6306void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6307{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006308 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006309
6310 try
6311 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006312 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006313
daniel@transgaming.come0078962010-04-15 20:45:08 +00006314 if (context)
6315 {
6316 if (index >= gl::MAX_VERTEX_ATTRIBS)
6317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006318 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006319 }
6320
daniel@transgaming.com83921382011-01-08 05:46:00 +00006321 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006322
Jamie Madillaff71502013-07-02 11:57:05 -04006323 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006324 {
Jamie Madillaff71502013-07-02 11:57:05 -04006325 return;
6326 }
6327
6328 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6329 {
6330 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6331 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006332 {
Jamie Madillaff71502013-07-02 11:57:05 -04006333 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006334 }
Jamie Madillaff71502013-07-02 11:57:05 -04006335 }
6336 else
6337 {
6338 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006339 }
6340 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006341 }
6342 catch(std::bad_alloc&)
6343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006344 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006345 }
6346}
6347
6348void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6349{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006350 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006351
6352 try
6353 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006354 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006355
daniel@transgaming.come0078962010-04-15 20:45:08 +00006356 if (context)
6357 {
6358 if (index >= gl::MAX_VERTEX_ATTRIBS)
6359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006360 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006361 }
6362
daniel@transgaming.com83921382011-01-08 05:46:00 +00006363 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006364
Jamie Madillaff71502013-07-02 11:57:05 -04006365 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006366 {
Jamie Madillaff71502013-07-02 11:57:05 -04006367 return;
6368 }
6369
6370 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6371 {
6372 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6373 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006374 {
Jamie Madillaff71502013-07-02 11:57:05 -04006375 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006376 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006377 }
Jamie Madillaff71502013-07-02 11:57:05 -04006378 }
6379 else
6380 {
6381 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006382 }
6383 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006384 }
6385 catch(std::bad_alloc&)
6386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006387 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006388 }
6389}
6390
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006391void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006392{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006393 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006394
6395 try
6396 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006397 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006398
daniel@transgaming.come0078962010-04-15 20:45:08 +00006399 if (context)
6400 {
6401 if (index >= gl::MAX_VERTEX_ATTRIBS)
6402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006403 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006404 }
6405
6406 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006408 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006409 }
6410
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006411 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006412 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006413 }
6414 catch(std::bad_alloc&)
6415 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006416 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006417 }
6418}
6419
6420void __stdcall glHint(GLenum target, GLenum mode)
6421{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006422 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006423
6424 try
6425 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006426 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006427 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006428 case GL_FASTEST:
6429 case GL_NICEST:
6430 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006431 break;
6432 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006433 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006434 }
6435
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006436 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006437 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006438 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006439 case GL_GENERATE_MIPMAP_HINT:
6440 if (context) context->setGenerateMipmapHint(mode);
6441 break;
6442 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6443 if (context) context->setFragmentShaderDerivativeHint(mode);
6444 break;
6445 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006446 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006447 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006448 }
6449 catch(std::bad_alloc&)
6450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006451 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006452 }
6453}
6454
6455GLboolean __stdcall glIsBuffer(GLuint buffer)
6456{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006457 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006458
6459 try
6460 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006461 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006462
6463 if (context && buffer)
6464 {
6465 gl::Buffer *bufferObject = context->getBuffer(buffer);
6466
6467 if (bufferObject)
6468 {
6469 return GL_TRUE;
6470 }
6471 }
6472 }
6473 catch(std::bad_alloc&)
6474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006475 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006476 }
6477
6478 return GL_FALSE;
6479}
6480
6481GLboolean __stdcall glIsEnabled(GLenum cap)
6482{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006483 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006484
6485 try
6486 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006487 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006488
6489 if (context)
6490 {
6491 switch (cap)
6492 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006493 case GL_CULL_FACE: return context->isCullFaceEnabled();
6494 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6495 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6496 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6497 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6498 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6499 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6500 case GL_BLEND: return context->isBlendEnabled();
6501 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006502 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006503 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006504 }
6505 }
6506 }
6507 catch(std::bad_alloc&)
6508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006509 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006510 }
6511
6512 return false;
6513}
6514
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006515GLboolean __stdcall glIsFenceNV(GLuint fence)
6516{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006517 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006518
6519 try
6520 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006521 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006522
6523 if (context)
6524 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006525 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006526
6527 if (fenceObject == NULL)
6528 {
6529 return GL_FALSE;
6530 }
6531
6532 return fenceObject->isFence();
6533 }
6534 }
6535 catch(std::bad_alloc&)
6536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006537 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006538 }
6539
6540 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006541}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006542
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006543GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006545 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006546
6547 try
6548 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006549 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006550
6551 if (context && framebuffer)
6552 {
6553 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6554
6555 if (framebufferObject)
6556 {
6557 return GL_TRUE;
6558 }
6559 }
6560 }
6561 catch(std::bad_alloc&)
6562 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006563 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006564 }
6565
6566 return GL_FALSE;
6567}
6568
6569GLboolean __stdcall glIsProgram(GLuint program)
6570{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006571 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006572
6573 try
6574 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006575 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006576
6577 if (context && program)
6578 {
6579 gl::Program *programObject = context->getProgram(program);
6580
6581 if (programObject)
6582 {
6583 return GL_TRUE;
6584 }
6585 }
6586 }
6587 catch(std::bad_alloc&)
6588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006589 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006590 }
6591
6592 return GL_FALSE;
6593}
6594
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006595GLboolean __stdcall glIsQueryEXT(GLuint id)
6596{
6597 EVENT("(GLuint id = %d)", id);
6598
6599 try
6600 {
6601 if (id == 0)
6602 {
6603 return GL_FALSE;
6604 }
6605
6606 gl::Context *context = gl::getNonLostContext();
6607
6608 if (context)
6609 {
6610 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6611
6612 if (queryObject)
6613 {
6614 return GL_TRUE;
6615 }
6616 }
6617 }
6618 catch(std::bad_alloc&)
6619 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006620 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006621 }
6622
6623 return GL_FALSE;
6624}
6625
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006626GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6627{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006628 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006629
6630 try
6631 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006632 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006633
6634 if (context && renderbuffer)
6635 {
6636 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6637
6638 if (renderbufferObject)
6639 {
6640 return GL_TRUE;
6641 }
6642 }
6643 }
6644 catch(std::bad_alloc&)
6645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006646 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006647 }
6648
6649 return GL_FALSE;
6650}
6651
6652GLboolean __stdcall glIsShader(GLuint shader)
6653{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006654 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006655
6656 try
6657 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006658 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006659
6660 if (context && shader)
6661 {
6662 gl::Shader *shaderObject = context->getShader(shader);
6663
6664 if (shaderObject)
6665 {
6666 return GL_TRUE;
6667 }
6668 }
6669 }
6670 catch(std::bad_alloc&)
6671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006672 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006673 }
6674
6675 return GL_FALSE;
6676}
6677
6678GLboolean __stdcall glIsTexture(GLuint texture)
6679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006680 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006681
6682 try
6683 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006684 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006685
6686 if (context && texture)
6687 {
6688 gl::Texture *textureObject = context->getTexture(texture);
6689
6690 if (textureObject)
6691 {
6692 return GL_TRUE;
6693 }
6694 }
6695 }
6696 catch(std::bad_alloc&)
6697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006698 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006699 }
6700
6701 return GL_FALSE;
6702}
6703
6704void __stdcall glLineWidth(GLfloat width)
6705{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006706 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006707
6708 try
6709 {
6710 if (width <= 0.0f)
6711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006712 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006713 }
6714
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006715 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006716
6717 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006718 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006719 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006720 }
6721 }
6722 catch(std::bad_alloc&)
6723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006724 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006725 }
6726}
6727
6728void __stdcall glLinkProgram(GLuint program)
6729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006730 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006731
6732 try
6733 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006734 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006735
6736 if (context)
6737 {
6738 gl::Program *programObject = context->getProgram(program);
6739
6740 if (!programObject)
6741 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006742 if (context->getShader(program))
6743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006744 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006745 }
6746 else
6747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006748 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006749 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006750 }
6751
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006752 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006753 }
6754 }
6755 catch(std::bad_alloc&)
6756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006757 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006758 }
6759}
6760
6761void __stdcall glPixelStorei(GLenum pname, GLint param)
6762{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006763 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006764
6765 try
6766 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006767 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006768
6769 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006770 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006771 switch (pname)
6772 {
6773 case GL_UNPACK_ALIGNMENT:
6774 if (param != 1 && param != 2 && param != 4 && param != 8)
6775 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006776 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006777 }
6778
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006779 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006780 break;
6781
6782 case GL_PACK_ALIGNMENT:
6783 if (param != 1 && param != 2 && param != 4 && param != 8)
6784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006785 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006786 }
6787
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006788 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006789 break;
6790
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006791 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6792 context->setPackReverseRowOrder(param != 0);
6793 break;
6794
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006795 case GL_UNPACK_IMAGE_HEIGHT:
6796 case GL_UNPACK_SKIP_IMAGES:
6797 case GL_UNPACK_ROW_LENGTH:
6798 case GL_UNPACK_SKIP_ROWS:
6799 case GL_UNPACK_SKIP_PIXELS:
6800 case GL_PACK_ROW_LENGTH:
6801 case GL_PACK_SKIP_ROWS:
6802 case GL_PACK_SKIP_PIXELS:
6803 if (context->getClientVersion() < 3)
6804 {
6805 return gl::error(GL_INVALID_ENUM);
6806 }
6807 UNIMPLEMENTED();
6808 break;
6809
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006810 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006811 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006812 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006813 }
6814 }
6815 catch(std::bad_alloc&)
6816 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006817 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006818 }
6819}
6820
6821void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6822{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006823 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006824
6825 try
6826 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006827 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006828
6829 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006830 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006831 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006832 }
6833 }
6834 catch(std::bad_alloc&)
6835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006836 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006837 }
6838}
6839
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006840void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6841 GLenum format, GLenum type, GLsizei bufSize,
6842 GLvoid *data)
6843{
6844 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6845 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6846 x, y, width, height, format, type, bufSize, data);
6847
6848 try
6849 {
6850 if (width < 0 || height < 0 || bufSize < 0)
6851 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006852 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006853 }
6854
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006855 gl::Context *context = gl::getNonLostContext();
6856
6857 if (context)
6858 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006859 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006860 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006861
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006862 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6863 // and attempting to read back if that's the case is an error. The error will be registered
6864 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006865 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006866 return;
6867
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006868 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6869 validES3ReadFormatType(currentInternalFormat, format, type);
6870
6871 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006873 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006874 }
6875
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006876 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6877 }
6878 }
6879 catch(std::bad_alloc&)
6880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006881 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006882 }
6883}
6884
6885void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6886 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006887{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006888 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006889 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006890 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006891
6892 try
6893 {
6894 if (width < 0 || height < 0)
6895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006896 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006897 }
6898
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006899 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006900
6901 if (context)
6902 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006903 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006904 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006905
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006906 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6907 // and attempting to read back if that's the case is an error. The error will be registered
6908 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006909 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006910 return;
6911
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006912 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6913 validES3ReadFormatType(currentInternalFormat, format, type);
6914
6915 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006916 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006917 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006918 }
6919
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006920 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006921 }
6922 }
6923 catch(std::bad_alloc&)
6924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006925 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006926 }
6927}
6928
6929void __stdcall glReleaseShaderCompiler(void)
6930{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006931 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006932
6933 try
6934 {
6935 gl::Shader::releaseCompiler();
6936 }
6937 catch(std::bad_alloc&)
6938 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006939 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006940 }
6941}
6942
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006943void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006944{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006945 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 +00006946 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006947
6948 try
6949 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006950 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006951
6952 if (context)
6953 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006954 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6955 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006956 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006957 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006958 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006959
6960 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006961 }
6962 }
6963 catch(std::bad_alloc&)
6964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006965 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006966 }
6967}
6968
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006969void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6970{
6971 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6972}
6973
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006974void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6975{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006976 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006977
6978 try
6979 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006980 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006981
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006982 if (context)
6983 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006984 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006985 }
6986 }
6987 catch(std::bad_alloc&)
6988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006990 }
6991}
6992
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006993void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006995 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006996
6997 try
6998 {
6999 if (condition != GL_ALL_COMPLETED_NV)
7000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007001 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007002 }
7003
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007004 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007005
7006 if (context)
7007 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007008 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007009
7010 if (fenceObject == NULL)
7011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007012 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007013 }
7014
7015 fenceObject->setFence(condition);
7016 }
7017 }
7018 catch(std::bad_alloc&)
7019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007020 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007021 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007022}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007023
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007024void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
7025{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007026 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 +00007027
7028 try
7029 {
7030 if (width < 0 || height < 0)
7031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007032 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007033 }
7034
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007035 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007036
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007037 if (context)
7038 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007039 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007040 }
7041 }
7042 catch(std::bad_alloc&)
7043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007044 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007045 }
7046}
7047
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007048void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007050 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007051 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007052 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007053
7054 try
7055 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00007056 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007057 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007058 }
7059 catch(std::bad_alloc&)
7060 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007061 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007062 }
7063}
7064
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00007065void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007066{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007067 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 +00007068 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007069
7070 try
7071 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007072 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007074 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007075 }
7076
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007077 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007078
7079 if (context)
7080 {
7081 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007082
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007083 if (!shaderObject)
7084 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007085 if (context->getProgram(shader))
7086 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007087 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007088 }
7089 else
7090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007091 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007092 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007093 }
7094
7095 shaderObject->setSource(count, string, length);
7096 }
7097 }
7098 catch(std::bad_alloc&)
7099 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007100 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007101 }
7102}
7103
7104void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
7105{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007106 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007107}
7108
7109void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
7110{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007111 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 +00007112
7113 try
7114 {
7115 switch (face)
7116 {
7117 case GL_FRONT:
7118 case GL_BACK:
7119 case GL_FRONT_AND_BACK:
7120 break;
7121 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007122 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007123 }
7124
7125 switch (func)
7126 {
7127 case GL_NEVER:
7128 case GL_ALWAYS:
7129 case GL_LESS:
7130 case GL_LEQUAL:
7131 case GL_EQUAL:
7132 case GL_GEQUAL:
7133 case GL_GREATER:
7134 case GL_NOTEQUAL:
7135 break;
7136 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138 }
7139
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007140 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007141
7142 if (context)
7143 {
7144 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7145 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007146 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007147 }
7148
7149 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7150 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007151 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007152 }
7153 }
7154 }
7155 catch(std::bad_alloc&)
7156 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007157 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007158 }
7159}
7160
7161void __stdcall glStencilMask(GLuint mask)
7162{
7163 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
7164}
7165
7166void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
7167{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007168 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007169
7170 try
7171 {
7172 switch (face)
7173 {
7174 case GL_FRONT:
7175 case GL_BACK:
7176 case GL_FRONT_AND_BACK:
7177 break;
7178 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007179 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007180 }
7181
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007182 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007183
7184 if (context)
7185 {
7186 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7187 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007188 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007189 }
7190
7191 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7192 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007193 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007194 }
7195 }
7196 }
7197 catch(std::bad_alloc&)
7198 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007199 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007200 }
7201}
7202
7203void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
7204{
7205 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
7206}
7207
7208void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
7209{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007210 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 +00007211 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007212
7213 try
7214 {
7215 switch (face)
7216 {
7217 case GL_FRONT:
7218 case GL_BACK:
7219 case GL_FRONT_AND_BACK:
7220 break;
7221 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007222 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007223 }
7224
7225 switch (fail)
7226 {
7227 case GL_ZERO:
7228 case GL_KEEP:
7229 case GL_REPLACE:
7230 case GL_INCR:
7231 case GL_DECR:
7232 case GL_INVERT:
7233 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007234 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007235 break;
7236 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007237 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007238 }
7239
7240 switch (zfail)
7241 {
7242 case GL_ZERO:
7243 case GL_KEEP:
7244 case GL_REPLACE:
7245 case GL_INCR:
7246 case GL_DECR:
7247 case GL_INVERT:
7248 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007249 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007250 break;
7251 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007252 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007253 }
7254
7255 switch (zpass)
7256 {
7257 case GL_ZERO:
7258 case GL_KEEP:
7259 case GL_REPLACE:
7260 case GL_INCR:
7261 case GL_DECR:
7262 case GL_INVERT:
7263 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007264 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007265 break;
7266 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007267 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007268 }
7269
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007270 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007271
7272 if (context)
7273 {
7274 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7275 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007276 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007277 }
7278
7279 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7280 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007281 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007282 }
7283 }
7284 }
7285 catch(std::bad_alloc&)
7286 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007287 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007288 }
7289}
7290
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007291GLboolean __stdcall glTestFenceNV(GLuint fence)
7292{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007293 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007294
7295 try
7296 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007297 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007298
7299 if (context)
7300 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007301 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007302
7303 if (fenceObject == NULL)
7304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007305 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007306 }
7307
Jamie Madillfb9a7402013-07-26 11:55:01 -04007308 if (fenceObject->isFence() != GL_TRUE)
7309 {
7310 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
7311 }
7312
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007313 return fenceObject->testFence();
7314 }
7315 }
7316 catch(std::bad_alloc&)
7317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007318 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007319 }
7320
7321 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007322}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007323
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007324void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7325 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007327 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 +00007328 "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 +00007329 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007330
7331 try
7332 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007333 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007334
7335 if (context)
7336 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007337 if (context->getClientVersion() < 3 &&
7338 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7339 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007340 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007341 return;
7342 }
7343
7344 if (context->getClientVersion() >= 3 &&
7345 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7346 0, 0, 0, width, height, 1, border, format, type))
7347 {
7348 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007349 }
7350
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007351 switch (target)
7352 {
7353 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007354 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007355 gl::Texture2D *texture = context->getTexture2D();
7356 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007357 }
7358 break;
7359 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007360 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007361 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007362 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007363 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007364 break;
7365 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7366 {
7367 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7368 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7369 }
7370 break;
7371 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7372 {
7373 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7374 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7375 }
7376 break;
7377 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7378 {
7379 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7380 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7381 }
7382 break;
7383 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7384 {
7385 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7386 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7387 }
7388 break;
7389 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7390 {
7391 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7392 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7393 }
7394 break;
7395 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007396 }
7397 }
7398 }
7399 catch(std::bad_alloc&)
7400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007401 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007402 }
7403}
7404
7405void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7406{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007407 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7408
7409 try
7410 {
7411 gl::Context *context = gl::getNonLostContext();
7412
7413 if (context)
7414 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007415 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7416 {
7417 return;
7418 }
7419
Jamie Madillfb8a8302013-07-03 14:24:12 -04007420 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007421
Jamie Madillfb8a8302013-07-03 14:24:12 -04007422 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007423 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007424 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007425 }
7426
7427 switch (pname)
7428 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007429 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7430 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7431 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7432 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7433 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7434 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7435 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7436 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7437 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007438
Jamie Madill478fdb22013-07-19 16:36:59 -04007439 case GL_TEXTURE_SWIZZLE_R:
7440 case GL_TEXTURE_SWIZZLE_G:
7441 case GL_TEXTURE_SWIZZLE_B:
7442 case GL_TEXTURE_SWIZZLE_A:
7443 case GL_TEXTURE_BASE_LEVEL:
7444 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007445 case GL_TEXTURE_MIN_LOD:
7446 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007447 UNIMPLEMENTED();
7448 break;
7449
Jamie Madill478fdb22013-07-19 16:36:59 -04007450 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007451 }
7452 }
7453 }
7454 catch(std::bad_alloc&)
7455 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007456 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007457 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007458}
7459
7460void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7461{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007462 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007463}
7464
7465void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007467 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007468
7469 try
7470 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007471 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007472
7473 if (context)
7474 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007475 if (!validateTexParamParameters(context, pname, param))
7476 {
7477 return;
7478 }
7479
Jamie Madillfb8a8302013-07-03 14:24:12 -04007480 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007481
Jamie Madillfb8a8302013-07-03 14:24:12 -04007482 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007484 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007485 }
7486
7487 switch (pname)
7488 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007489 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7490 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7491 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7492 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7493 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7494 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7495 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7496 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7497 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007498
7499 case GL_TEXTURE_SWIZZLE_R:
7500 case GL_TEXTURE_SWIZZLE_G:
7501 case GL_TEXTURE_SWIZZLE_B:
7502 case GL_TEXTURE_SWIZZLE_A:
7503 case GL_TEXTURE_BASE_LEVEL:
7504 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007505 case GL_TEXTURE_MIN_LOD:
7506 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007507 UNIMPLEMENTED();
7508 break;
7509
Jamie Madill478fdb22013-07-19 16:36:59 -04007510 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007511 }
7512 }
7513 }
7514 catch(std::bad_alloc&)
7515 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007516 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007517 }
7518}
7519
7520void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7521{
7522 glTexParameteri(target, pname, *params);
7523}
7524
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007525void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7526{
7527 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7528 target, levels, internalformat, width, height);
7529
7530 try
7531 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007532 gl::Context *context = gl::getNonLostContext();
7533
7534 if (context)
7535 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007536 if (context->getClientVersion() < 3 &&
7537 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007538 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007539 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007540 }
7541
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007542 if (context->getClientVersion() >= 3 &&
7543 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007544 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007545 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007546 }
7547
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007548 switch (target)
7549 {
7550 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007551 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007552 gl::Texture2D *texture2d = context->getTexture2D();
7553 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007554 }
7555 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007556
7557 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7558 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7559 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7560 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7561 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7562 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007563 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007564 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7565 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007566 }
7567 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007568
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007569 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007570 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007571 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007572 }
7573 }
7574 catch(std::bad_alloc&)
7575 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007576 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007577 }
7578}
7579
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007580void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7581 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007582{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007583 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007584 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007585 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007586 target, level, xoffset, yoffset, width, height, format, type, pixels);
7587
7588 try
7589 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007590 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007591
7592 if (context)
7593 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007594 if (context->getClientVersion() < 3 &&
7595 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7596 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007597 {
7598 return;
7599 }
7600
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007601 if (context->getClientVersion() >= 3 &&
7602 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7603 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007604 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007605 return;
7606 }
7607
7608 switch (target)
7609 {
7610 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007611 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007612 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007613 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007614 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007615 break;
7616
7617 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7618 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7619 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7620 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7621 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007623 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007624 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007625 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007626 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007627 break;
7628
7629 default:
7630 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007631 }
7632 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007633 }
7634 catch(std::bad_alloc&)
7635 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007636 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007637 }
7638}
7639
7640void __stdcall glUniform1f(GLint location, GLfloat x)
7641{
7642 glUniform1fv(location, 1, &x);
7643}
7644
7645void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7646{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007647 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007648
7649 try
7650 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007651 if (count < 0)
7652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007653 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007654 }
7655
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007656 if (location == -1)
7657 {
7658 return;
7659 }
7660
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007661 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007662
7663 if (context)
7664 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007665 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007666 if (!programBinary)
7667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007668 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007669 }
7670
7671 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007673 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007674 }
7675 }
7676 }
7677 catch(std::bad_alloc&)
7678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007679 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007680 }
7681}
7682
7683void __stdcall glUniform1i(GLint location, GLint x)
7684{
7685 glUniform1iv(location, 1, &x);
7686}
7687
7688void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7689{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007690 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007691
7692 try
7693 {
7694 if (count < 0)
7695 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007696 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007697 }
7698
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007699 if (location == -1)
7700 {
7701 return;
7702 }
7703
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007704 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007705
7706 if (context)
7707 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007708 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007709 if (!programBinary)
7710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007711 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007712 }
7713
7714 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007716 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007717 }
7718 }
7719 }
7720 catch(std::bad_alloc&)
7721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007722 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007723 }
7724}
7725
7726void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7727{
7728 GLfloat xy[2] = {x, y};
7729
7730 glUniform2fv(location, 1, (GLfloat*)&xy);
7731}
7732
7733void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7734{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007735 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007736
7737 try
7738 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007739 if (count < 0)
7740 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007741 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007742 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007743
7744 if (location == -1)
7745 {
7746 return;
7747 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007748
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007749 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007750
7751 if (context)
7752 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007753 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007754 if (!programBinary)
7755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007756 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007757 }
7758
7759 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007761 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007762 }
7763 }
7764 }
7765 catch(std::bad_alloc&)
7766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007767 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007768 }
7769}
7770
7771void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7772{
7773 GLint xy[4] = {x, y};
7774
7775 glUniform2iv(location, 1, (GLint*)&xy);
7776}
7777
7778void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7779{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007780 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007781
7782 try
7783 {
7784 if (count < 0)
7785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007787 }
7788
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007789 if (location == -1)
7790 {
7791 return;
7792 }
7793
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007794 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007795
7796 if (context)
7797 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007798 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007799 if (!programBinary)
7800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007801 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007802 }
7803
7804 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007806 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007807 }
7808 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007809 }
7810 catch(std::bad_alloc&)
7811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007812 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007813 }
7814}
7815
7816void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7817{
7818 GLfloat xyz[3] = {x, y, z};
7819
7820 glUniform3fv(location, 1, (GLfloat*)&xyz);
7821}
7822
7823void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7824{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007825 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007826
7827 try
7828 {
7829 if (count < 0)
7830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007831 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007832 }
7833
7834 if (location == -1)
7835 {
7836 return;
7837 }
7838
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007839 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007840
7841 if (context)
7842 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007843 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007844 if (!programBinary)
7845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007846 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007847 }
7848
7849 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007850 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007851 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007852 }
7853 }
7854 }
7855 catch(std::bad_alloc&)
7856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007857 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007858 }
7859}
7860
7861void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7862{
7863 GLint xyz[3] = {x, y, z};
7864
7865 glUniform3iv(location, 1, (GLint*)&xyz);
7866}
7867
7868void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7869{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007870 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007871
7872 try
7873 {
7874 if (count < 0)
7875 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007876 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007877 }
7878
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007879 if (location == -1)
7880 {
7881 return;
7882 }
7883
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007884 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007885
7886 if (context)
7887 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007888 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007889 if (!programBinary)
7890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007891 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007892 }
7893
7894 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007896 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007897 }
7898 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007899 }
7900 catch(std::bad_alloc&)
7901 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007902 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007903 }
7904}
7905
7906void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7907{
7908 GLfloat xyzw[4] = {x, y, z, w};
7909
7910 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7911}
7912
7913void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7914{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007915 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007916
7917 try
7918 {
7919 if (count < 0)
7920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007921 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007922 }
7923
7924 if (location == -1)
7925 {
7926 return;
7927 }
7928
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007930
7931 if (context)
7932 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007933 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007934 if (!programBinary)
7935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007936 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007937 }
7938
7939 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007941 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007942 }
7943 }
7944 }
7945 catch(std::bad_alloc&)
7946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007947 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007948 }
7949}
7950
7951void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7952{
7953 GLint xyzw[4] = {x, y, z, w};
7954
7955 glUniform4iv(location, 1, (GLint*)&xyzw);
7956}
7957
7958void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7959{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007960 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007961
7962 try
7963 {
7964 if (count < 0)
7965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007966 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007967 }
7968
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007969 if (location == -1)
7970 {
7971 return;
7972 }
7973
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007974 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007975
7976 if (context)
7977 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007978 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007979 if (!programBinary)
7980 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007981 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007982 }
7983
7984 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007986 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007987 }
7988 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007989 }
7990 catch(std::bad_alloc&)
7991 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007992 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007993 }
7994}
7995
7996void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7997{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007998 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007999 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008000
8001 try
8002 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008003 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008005 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008006 }
8007
8008 if (location == -1)
8009 {
8010 return;
8011 }
8012
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008013 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008014
8015 if (context)
8016 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008017 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8018 {
8019 return gl::error(GL_INVALID_VALUE);
8020 }
8021
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008022 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008023 if (!programBinary)
8024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008025 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008026 }
8027
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008028 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008029 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008030 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008031 }
8032 }
8033 }
8034 catch(std::bad_alloc&)
8035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008036 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008037 }
8038}
8039
8040void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8041{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008042 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008043 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008044
8045 try
8046 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008047 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008049 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008050 }
8051
8052 if (location == -1)
8053 {
8054 return;
8055 }
8056
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008057 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008058
8059 if (context)
8060 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008061 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8062 {
8063 return gl::error(GL_INVALID_VALUE);
8064 }
8065
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008066 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008067 if (!programBinary)
8068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008069 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008070 }
8071
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008072 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008074 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008075 }
8076 }
8077 }
8078 catch(std::bad_alloc&)
8079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008080 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008081 }
8082}
8083
8084void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8085{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008086 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008087 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008088
8089 try
8090 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008091 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008093 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008094 }
8095
8096 if (location == -1)
8097 {
8098 return;
8099 }
8100
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008101 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008102
8103 if (context)
8104 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008105 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8106 {
8107 return gl::error(GL_INVALID_VALUE);
8108 }
8109
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008110 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008111 if (!programBinary)
8112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008113 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008114 }
8115
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008116 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008118 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008119 }
8120 }
8121 }
8122 catch(std::bad_alloc&)
8123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008124 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008125 }
8126}
8127
8128void __stdcall glUseProgram(GLuint program)
8129{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008130 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008131
8132 try
8133 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008134 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008135
8136 if (context)
8137 {
8138 gl::Program *programObject = context->getProgram(program);
8139
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008140 if (!programObject && program != 0)
8141 {
8142 if (context->getShader(program))
8143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008144 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008145 }
8146 else
8147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008148 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008149 }
8150 }
8151
daniel@transgaming.com716056c2012-07-24 18:38:59 +00008152 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008154 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008155 }
8156
8157 context->useProgram(program);
8158 }
8159 }
8160 catch(std::bad_alloc&)
8161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008162 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008163 }
8164}
8165
8166void __stdcall glValidateProgram(GLuint program)
8167{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008168 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008169
8170 try
8171 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008172 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008173
8174 if (context)
8175 {
8176 gl::Program *programObject = context->getProgram(program);
8177
8178 if (!programObject)
8179 {
8180 if (context->getShader(program))
8181 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008182 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008183 }
8184 else
8185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008186 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008187 }
8188 }
8189
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00008190 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008191 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008192 }
8193 catch(std::bad_alloc&)
8194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008195 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008196 }
8197}
8198
8199void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
8200{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008201 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008202
8203 try
8204 {
8205 if (index >= gl::MAX_VERTEX_ATTRIBS)
8206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008207 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008208 }
8209
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008210 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008211
8212 if (context)
8213 {
8214 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008215 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008217 }
8218 catch(std::bad_alloc&)
8219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008220 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008221 }
8222}
8223
8224void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
8225{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008226 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008227
8228 try
8229 {
8230 if (index >= gl::MAX_VERTEX_ATTRIBS)
8231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008233 }
8234
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008235 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008236
8237 if (context)
8238 {
8239 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008240 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008241 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008242 }
8243 catch(std::bad_alloc&)
8244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008245 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008246 }
8247}
8248
8249void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8250{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008251 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008252
8253 try
8254 {
8255 if (index >= gl::MAX_VERTEX_ATTRIBS)
8256 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008257 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008258 }
8259
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008260 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008261
8262 if (context)
8263 {
8264 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008265 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008266 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008267 }
8268 catch(std::bad_alloc&)
8269 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008270 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008271 }
8272}
8273
8274void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8275{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008276 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008277
8278 try
8279 {
8280 if (index >= gl::MAX_VERTEX_ATTRIBS)
8281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008283 }
8284
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008285 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008286
8287 if (context)
8288 {
8289 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008290 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008291 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008292 }
8293 catch(std::bad_alloc&)
8294 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008295 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008296 }
8297}
8298
8299void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8300{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008301 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 +00008302
8303 try
8304 {
8305 if (index >= gl::MAX_VERTEX_ATTRIBS)
8306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008307 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008308 }
8309
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008311
8312 if (context)
8313 {
8314 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008315 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008316 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008317 }
8318 catch(std::bad_alloc&)
8319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008320 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008321 }
8322}
8323
8324void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8325{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008326 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008327
8328 try
8329 {
8330 if (index >= gl::MAX_VERTEX_ATTRIBS)
8331 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008332 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008333 }
8334
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008336
8337 if (context)
8338 {
8339 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008340 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008341 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008342 }
8343 catch(std::bad_alloc&)
8344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008345 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008346 }
8347}
8348
8349void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8350{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008351 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 +00008352
8353 try
8354 {
8355 if (index >= gl::MAX_VERTEX_ATTRIBS)
8356 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008357 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008358 }
8359
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008360 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008361
8362 if (context)
8363 {
8364 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008365 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008366 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008367 }
8368 catch(std::bad_alloc&)
8369 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008370 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008371 }
8372}
8373
8374void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8375{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008376 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008377
8378 try
8379 {
8380 if (index >= gl::MAX_VERTEX_ATTRIBS)
8381 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008382 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008383 }
8384
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008385 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008386
8387 if (context)
8388 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008389 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008390 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008391 }
8392 catch(std::bad_alloc&)
8393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008394 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008395 }
8396}
8397
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008398void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8399{
8400 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8401
8402 try
8403 {
8404 if (index >= gl::MAX_VERTEX_ATTRIBS)
8405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008406 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008407 }
8408
8409 gl::Context *context = gl::getNonLostContext();
8410
8411 if (context)
8412 {
8413 context->setVertexAttribDivisor(index, divisor);
8414 }
8415 }
8416 catch(std::bad_alloc&)
8417 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008418 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008419 }
8420}
8421
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008422void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008423{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008424 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008425 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008426 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008427
8428 try
8429 {
8430 if (index >= gl::MAX_VERTEX_ATTRIBS)
8431 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008432 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008433 }
8434
8435 if (size < 1 || size > 4)
8436 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008437 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008438 }
8439
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008440 gl::Context *context = gl::getNonLostContext();
8441
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008442 switch (type)
8443 {
8444 case GL_BYTE:
8445 case GL_UNSIGNED_BYTE:
8446 case GL_SHORT:
8447 case GL_UNSIGNED_SHORT:
8448 case GL_FIXED:
8449 case GL_FLOAT:
8450 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008451 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008452 case GL_INT:
8453 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008454 case GL_INT_2_10_10_10_REV:
8455 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008456 if (context && context->getClientVersion() < 3)
8457 {
8458 return gl::error(GL_INVALID_ENUM);
8459 }
8460 else
8461 {
8462 break;
8463 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008464 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008465 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008466 }
8467
8468 if (stride < 0)
8469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008470 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008471 }
8472
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008473 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8474 {
8475 return gl::error(GL_INVALID_OPERATION);
8476 }
8477
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008478 if (context)
8479 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008480 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8481 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8482 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8483 // and the pointer argument is not NULL.
8484 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8485 {
8486 return gl::error(GL_INVALID_OPERATION);
8487 }
8488
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008489 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8490 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008491 }
8492 }
8493 catch(std::bad_alloc&)
8494 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008495 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008496 }
8497}
8498
8499void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008501 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 +00008502
8503 try
8504 {
8505 if (width < 0 || height < 0)
8506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008507 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008508 }
8509
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008510 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008511
8512 if (context)
8513 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008514 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008515 }
8516 }
8517 catch(std::bad_alloc&)
8518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008519 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008520 }
8521}
8522
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008523// OpenGL ES 3.0 functions
8524
8525void __stdcall glReadBuffer(GLenum mode)
8526{
8527 EVENT("(GLenum mode = 0x%X)", mode);
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
Jamie Madill54133512013-06-21 09:33:07 -04008540 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008541 UNIMPLEMENTED();
8542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008543 }
8544 catch(std::bad_alloc&)
8545 {
8546 return gl::error(GL_OUT_OF_MEMORY);
8547 }
8548}
8549
8550void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8551{
8552 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8553 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8554
8555 try
8556 {
8557 gl::Context *context = gl::getNonLostContext();
8558
8559 if (context)
8560 {
8561 if (context->getClientVersion() < 3)
8562 {
8563 return gl::error(GL_INVALID_OPERATION);
8564 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008565
Jamie Madill54133512013-06-21 09:33:07 -04008566 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008567 UNIMPLEMENTED();
8568 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008569 }
8570 catch(std::bad_alloc&)
8571 {
8572 return gl::error(GL_OUT_OF_MEMORY);
8573 }
8574}
8575
8576void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8577{
8578 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8579 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8580 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8581 target, level, internalformat, width, height, depth, border, format, type, pixels);
8582
8583 try
8584 {
8585 gl::Context *context = gl::getNonLostContext();
8586
8587 if (context)
8588 {
8589 if (context->getClientVersion() < 3)
8590 {
8591 return gl::error(GL_INVALID_OPERATION);
8592 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008593
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008594 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008595 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008596 0, 0, 0, width, height, depth, border, format, type))
8597 {
8598 return;
8599 }
8600
8601 switch(target)
8602 {
8603 case GL_TEXTURE_3D:
8604 {
8605 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008606 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008607 }
8608 break;
8609
8610 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008611 {
8612 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008613 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008614 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008615 break;
8616
8617 default:
8618 return gl::error(GL_INVALID_ENUM);
8619 }
8620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008621 }
8622 catch(std::bad_alloc&)
8623 {
8624 return gl::error(GL_OUT_OF_MEMORY);
8625 }
8626}
8627
8628void __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)
8629{
8630 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8631 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8632 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8633 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8634
8635 try
8636 {
8637 gl::Context *context = gl::getNonLostContext();
8638
8639 if (context)
8640 {
8641 if (context->getClientVersion() < 3)
8642 {
8643 return gl::error(GL_INVALID_OPERATION);
8644 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008645
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008646 if (!pixels)
8647 {
8648 return gl::error(GL_INVALID_VALUE);
8649 }
8650
8651 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008652 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008653 xoffset, yoffset, zoffset, width, height, depth, 0,
8654 format, type))
8655 {
8656 return;
8657 }
8658
8659 switch(target)
8660 {
8661 case GL_TEXTURE_3D:
8662 {
8663 gl::Texture3D *texture = context->getTexture3D();
8664 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8665 }
8666 break;
8667
8668 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008669 {
8670 gl::Texture2DArray *texture = context->getTexture2DArray();
8671 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8672 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008673 break;
8674
8675 default:
8676 return gl::error(GL_INVALID_ENUM);
8677 }
8678 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008679 }
8680 catch(std::bad_alloc&)
8681 {
8682 return gl::error(GL_OUT_OF_MEMORY);
8683 }
8684}
8685
8686void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8687{
8688 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8689 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8690 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8691
8692 try
8693 {
8694 gl::Context *context = gl::getNonLostContext();
8695
8696 if (context)
8697 {
8698 if (context->getClientVersion() < 3)
8699 {
8700 return gl::error(GL_INVALID_OPERATION);
8701 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008702
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008703 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8704 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008705 {
8706 return;
8707 }
8708
8709 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8710 gl::Texture *texture = NULL;
8711 switch (target)
8712 {
8713 case GL_TEXTURE_3D:
8714 texture = context->getTexture3D();
8715 break;
8716
8717 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008718 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008719 break;
8720
8721 default:
8722 return gl::error(GL_INVALID_ENUM);
8723 }
8724
8725 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8726 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008727 }
8728 catch(std::bad_alloc&)
8729 {
8730 return gl::error(GL_OUT_OF_MEMORY);
8731 }
8732}
8733
8734void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8735{
8736 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8737 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8738 "const GLvoid* data = 0x%0.8p)",
8739 target, level, internalformat, width, height, depth, border, imageSize, data);
8740
8741 try
8742 {
8743 gl::Context *context = gl::getNonLostContext();
8744
8745 if (context)
8746 {
8747 if (context->getClientVersion() < 3)
8748 {
8749 return gl::error(GL_INVALID_OPERATION);
8750 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008751
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008752 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 +00008753 {
8754 return gl::error(GL_INVALID_VALUE);
8755 }
8756
8757 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008758 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8759 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008760 {
8761 return;
8762 }
8763
8764 switch(target)
8765 {
8766 case GL_TEXTURE_3D:
8767 {
8768 gl::Texture3D *texture = context->getTexture3D();
8769 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8770 }
8771 break;
8772
8773 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008774 {
8775 gl::Texture2DArray *texture = context->getTexture2DArray();
8776 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8777 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008778 break;
8779
8780 default:
8781 return gl::error(GL_INVALID_ENUM);
8782 }
8783 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008784 }
8785 catch(std::bad_alloc&)
8786 {
8787 return gl::error(GL_OUT_OF_MEMORY);
8788 }
8789}
8790
8791void __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)
8792{
8793 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8794 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8795 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8796 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8797
8798 try
8799 {
8800 gl::Context *context = gl::getNonLostContext();
8801
8802 if (context)
8803 {
8804 if (context->getClientVersion() < 3)
8805 {
8806 return gl::error(GL_INVALID_OPERATION);
8807 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008808
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008809 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 +00008810 {
8811 return gl::error(GL_INVALID_VALUE);
8812 }
8813
8814 if (!data)
8815 {
8816 return gl::error(GL_INVALID_VALUE);
8817 }
8818
8819 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008820 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8821 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008822 {
8823 return;
8824 }
8825
8826 switch(target)
8827 {
8828 case GL_TEXTURE_3D:
8829 {
8830 gl::Texture3D *texture = context->getTexture3D();
8831 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8832 format, imageSize, data);
8833 }
8834 break;
8835
8836 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008837 {
8838 gl::Texture2DArray *texture = context->getTexture2DArray();
8839 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8840 format, imageSize, data);
8841 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008842 break;
8843
8844 default:
8845 return gl::error(GL_INVALID_ENUM);
8846 }
8847 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008848 }
8849 catch(std::bad_alloc&)
8850 {
8851 return gl::error(GL_OUT_OF_MEMORY);
8852 }
8853}
8854
8855void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8856{
8857 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8858
8859 try
8860 {
8861 gl::Context *context = gl::getNonLostContext();
8862
8863 if (context)
8864 {
8865 if (context->getClientVersion() < 3)
8866 {
8867 return gl::error(GL_INVALID_OPERATION);
8868 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008869
Jamie Madill3641b4b2013-07-26 12:54:59 -04008870 glGenQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008871 }
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);
8876 }
8877}
8878
8879void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8880{
8881 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8882
8883 try
8884 {
8885 gl::Context *context = gl::getNonLostContext();
8886
8887 if (context)
8888 {
8889 if (context->getClientVersion() < 3)
8890 {
8891 return gl::error(GL_INVALID_OPERATION);
8892 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008893
Jamie Madill3641b4b2013-07-26 12:54:59 -04008894 glDeleteQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008896 }
8897 catch(std::bad_alloc&)
8898 {
8899 return gl::error(GL_OUT_OF_MEMORY);
8900 }
8901}
8902
8903GLboolean __stdcall glIsQuery(GLuint id)
8904{
8905 EVENT("(GLuint id = %u)", id);
8906
8907 try
8908 {
8909 gl::Context *context = gl::getNonLostContext();
8910
8911 if (context)
8912 {
8913 if (context->getClientVersion() < 3)
8914 {
8915 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8916 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008917
Jamie Madill3641b4b2013-07-26 12:54:59 -04008918 // TODO: XFB queries
8919 return glIsQueryEXT(id);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008920 }
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, GL_FALSE);
8925 }
8926
8927 return GL_FALSE;
8928}
8929
8930void __stdcall glBeginQuery(GLenum target, GLuint id)
8931{
8932 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8933
8934 try
8935 {
8936 gl::Context *context = gl::getNonLostContext();
8937
8938 if (context)
8939 {
8940 if (context->getClientVersion() < 3)
8941 {
8942 return gl::error(GL_INVALID_OPERATION);
8943 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008944
Jamie Madill3641b4b2013-07-26 12:54:59 -04008945 switch (target)
8946 {
8947 case GL_ANY_SAMPLES_PASSED:
8948 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
8949 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
8950 break;
8951 default:
8952 return gl::error(GL_INVALID_ENUM);
8953 }
8954
8955 if (id == 0)
8956 {
8957 return gl::error(GL_INVALID_OPERATION);
8958 }
8959
8960 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8961 {
8962 // TODO: XFB queries
8963 UNIMPLEMENTED();
8964 }
8965 else
8966 {
8967 context->beginQuery(target, id);
8968 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008970 }
8971 catch(std::bad_alloc&)
8972 {
8973 return gl::error(GL_OUT_OF_MEMORY);
8974 }
8975}
8976
8977void __stdcall glEndQuery(GLenum target)
8978{
8979 EVENT("(GLenum target = 0x%X)", target);
8980
8981 try
8982 {
8983 gl::Context *context = gl::getNonLostContext();
8984
8985 if (context)
8986 {
8987 if (context->getClientVersion() < 3)
8988 {
8989 return gl::error(GL_INVALID_OPERATION);
8990 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008991
Jamie Madill3641b4b2013-07-26 12:54:59 -04008992 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8993 {
8994 // TODO: XFB queries
8995 UNIMPLEMENTED();
8996 }
8997 else
8998 {
8999 glEndQueryEXT(target);
9000 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009001 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009002 }
9003 catch(std::bad_alloc&)
9004 {
9005 return gl::error(GL_OUT_OF_MEMORY);
9006 }
9007}
9008
9009void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
9010{
9011 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
9012
9013 try
9014 {
9015 gl::Context *context = gl::getNonLostContext();
9016
9017 if (context)
9018 {
9019 if (context->getClientVersion() < 3)
9020 {
9021 return gl::error(GL_INVALID_OPERATION);
9022 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009023
Jamie Madill3641b4b2013-07-26 12:54:59 -04009024 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
9025 {
9026 // TODO: XFB queries
9027 UNIMPLEMENTED();
9028 }
9029 else
9030 {
9031 glGetQueryivEXT(target, pname, params);
9032 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009033 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009034 }
9035 catch(std::bad_alloc&)
9036 {
9037 return gl::error(GL_OUT_OF_MEMORY);
9038 }
9039}
9040
9041void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
9042{
9043 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
9044
9045 try
9046 {
9047 gl::Context *context = gl::getNonLostContext();
9048
9049 if (context)
9050 {
9051 if (context->getClientVersion() < 3)
9052 {
9053 return gl::error(GL_INVALID_OPERATION);
9054 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009055
Jamie Madill3641b4b2013-07-26 12:54:59 -04009056 // TODO: XFB queries
9057 glGetQueryObjectuivEXT(id, pname, params);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009058 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009059 }
9060 catch(std::bad_alloc&)
9061 {
9062 return gl::error(GL_OUT_OF_MEMORY);
9063 }
9064}
9065
9066GLboolean __stdcall glUnmapBuffer(GLenum target)
9067{
9068 EVENT("(GLenum target = 0x%X)", target);
9069
9070 try
9071 {
9072 gl::Context *context = gl::getNonLostContext();
9073
9074 if (context)
9075 {
9076 if (context->getClientVersion() < 3)
9077 {
9078 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9079 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009080
Jamie Madill54133512013-06-21 09:33:07 -04009081 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009082 UNIMPLEMENTED();
9083 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009084 }
9085 catch(std::bad_alloc&)
9086 {
9087 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9088 }
9089
9090 return GL_FALSE;
9091}
9092
9093void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
9094{
9095 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
9096
9097 try
9098 {
9099 gl::Context *context = gl::getNonLostContext();
9100
9101 if (context)
9102 {
9103 if (context->getClientVersion() < 3)
9104 {
9105 return gl::error(GL_INVALID_OPERATION);
9106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009107
Jamie Madill54133512013-06-21 09:33:07 -04009108 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00009109 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009111 }
9112 catch(std::bad_alloc&)
9113 {
9114 return gl::error(GL_OUT_OF_MEMORY);
9115 }
9116}
9117
9118void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
9119{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009120 try
9121 {
9122 gl::Context *context = gl::getNonLostContext();
9123
9124 if (context)
9125 {
9126 if (context->getClientVersion() < 3)
9127 {
9128 return gl::error(GL_INVALID_OPERATION);
9129 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009130
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00009131 glDrawBuffersEXT(n, bufs);
9132 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009133 }
9134 catch(std::bad_alloc&)
9135 {
9136 return gl::error(GL_OUT_OF_MEMORY);
9137 }
9138}
9139
9140void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9141{
9142 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9143 location, count, transpose, value);
9144
9145 try
9146 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009147 if (count < 0)
9148 {
9149 return gl::error(GL_INVALID_VALUE);
9150 }
9151
9152 if (location == -1)
9153 {
9154 return;
9155 }
9156
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009157 gl::Context *context = gl::getNonLostContext();
9158
9159 if (context)
9160 {
9161 if (context->getClientVersion() < 3)
9162 {
9163 return gl::error(GL_INVALID_OPERATION);
9164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009165
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009166 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9167 if (!programBinary)
9168 {
9169 return gl::error(GL_INVALID_OPERATION);
9170 }
9171
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009172 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009173 {
9174 return gl::error(GL_INVALID_OPERATION);
9175 }
9176 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009177 }
9178 catch(std::bad_alloc&)
9179 {
9180 return gl::error(GL_OUT_OF_MEMORY);
9181 }
9182}
9183
9184void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9185{
9186 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9187 location, count, transpose, value);
9188
9189 try
9190 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009191 if (count < 0)
9192 {
9193 return gl::error(GL_INVALID_VALUE);
9194 }
9195
9196 if (location == -1)
9197 {
9198 return;
9199 }
9200
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009201 gl::Context *context = gl::getNonLostContext();
9202
9203 if (context)
9204 {
9205 if (context->getClientVersion() < 3)
9206 {
9207 return gl::error(GL_INVALID_OPERATION);
9208 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009209
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009210 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9211 if (!programBinary)
9212 {
9213 return gl::error(GL_INVALID_OPERATION);
9214 }
9215
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009216 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009217 {
9218 return gl::error(GL_INVALID_OPERATION);
9219 }
9220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009221 }
9222 catch(std::bad_alloc&)
9223 {
9224 return gl::error(GL_OUT_OF_MEMORY);
9225 }
9226}
9227
9228void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9229{
9230 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9231 location, count, transpose, value);
9232
9233 try
9234 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009235 if (count < 0)
9236 {
9237 return gl::error(GL_INVALID_VALUE);
9238 }
9239
9240 if (location == -1)
9241 {
9242 return;
9243 }
9244
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009245 gl::Context *context = gl::getNonLostContext();
9246
9247 if (context)
9248 {
9249 if (context->getClientVersion() < 3)
9250 {
9251 return gl::error(GL_INVALID_OPERATION);
9252 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009253
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009254 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9255 if (!programBinary)
9256 {
9257 return gl::error(GL_INVALID_OPERATION);
9258 }
9259
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009260 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009261 {
9262 return gl::error(GL_INVALID_OPERATION);
9263 }
9264 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009265 }
9266 catch(std::bad_alloc&)
9267 {
9268 return gl::error(GL_OUT_OF_MEMORY);
9269 }
9270}
9271
9272void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9273{
9274 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9275 location, count, transpose, value);
9276
9277 try
9278 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009279 if (count < 0)
9280 {
9281 return gl::error(GL_INVALID_VALUE);
9282 }
9283
9284 if (location == -1)
9285 {
9286 return;
9287 }
9288
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009289 gl::Context *context = gl::getNonLostContext();
9290
9291 if (context)
9292 {
9293 if (context->getClientVersion() < 3)
9294 {
9295 return gl::error(GL_INVALID_OPERATION);
9296 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009297
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009298 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9299 if (!programBinary)
9300 {
9301 return gl::error(GL_INVALID_OPERATION);
9302 }
9303
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009304 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009305 {
9306 return gl::error(GL_INVALID_OPERATION);
9307 }
9308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009309 }
9310 catch(std::bad_alloc&)
9311 {
9312 return gl::error(GL_OUT_OF_MEMORY);
9313 }
9314}
9315
9316void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9317{
9318 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9319 location, count, transpose, value);
9320
9321 try
9322 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009323 if (count < 0)
9324 {
9325 return gl::error(GL_INVALID_VALUE);
9326 }
9327
9328 if (location == -1)
9329 {
9330 return;
9331 }
9332
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009333 gl::Context *context = gl::getNonLostContext();
9334
9335 if (context)
9336 {
9337 if (context->getClientVersion() < 3)
9338 {
9339 return gl::error(GL_INVALID_OPERATION);
9340 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009341
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009342 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9343 if (!programBinary)
9344 {
9345 return gl::error(GL_INVALID_OPERATION);
9346 }
9347
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009348 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009349 {
9350 return gl::error(GL_INVALID_OPERATION);
9351 }
9352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009353 }
9354 catch(std::bad_alloc&)
9355 {
9356 return gl::error(GL_OUT_OF_MEMORY);
9357 }
9358}
9359
9360void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9361{
9362 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9363 location, count, transpose, value);
9364
9365 try
9366 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009367 if (count < 0)
9368 {
9369 return gl::error(GL_INVALID_VALUE);
9370 }
9371
9372 if (location == -1)
9373 {
9374 return;
9375 }
9376
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009377 gl::Context *context = gl::getNonLostContext();
9378
9379 if (context)
9380 {
9381 if (context->getClientVersion() < 3)
9382 {
9383 return gl::error(GL_INVALID_OPERATION);
9384 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009385
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009386 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9387 if (!programBinary)
9388 {
9389 return gl::error(GL_INVALID_OPERATION);
9390 }
9391
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009392 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009393 {
9394 return gl::error(GL_INVALID_OPERATION);
9395 }
9396 }
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 glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9405{
9406 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9407 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9408 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9409
9410 try
9411 {
9412 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009413 if (context)
9414 {
9415 if (context->getClientVersion() < 3)
9416 {
9417 return gl::error(GL_INVALID_OPERATION);
9418 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009419
Geoff Lang758d5b22013-06-11 11:42:50 -04009420 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9421 dstX0, dstY0, dstX1, dstY1, mask, filter,
9422 false))
9423 {
9424 return;
9425 }
9426
9427 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9428 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009429 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009430 }
9431 catch(std::bad_alloc&)
9432 {
9433 return gl::error(GL_OUT_OF_MEMORY);
9434 }
9435}
9436
9437void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9438{
9439 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9440 target, samples, internalformat, width, height);
9441
9442 try
9443 {
9444 gl::Context *context = gl::getNonLostContext();
9445
9446 if (context)
9447 {
9448 if (context->getClientVersion() < 3)
9449 {
9450 return gl::error(GL_INVALID_OPERATION);
9451 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009452
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009453 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9454 width, height, false))
9455 {
9456 return;
9457 }
9458
9459 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009460 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009461 }
9462 catch(std::bad_alloc&)
9463 {
9464 return gl::error(GL_OUT_OF_MEMORY);
9465 }
9466}
9467
9468void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9469{
9470 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9471 target, attachment, texture, level, layer);
9472
9473 try
9474 {
9475 gl::Context *context = gl::getNonLostContext();
9476
9477 if (context)
9478 {
9479 if (context->getClientVersion() < 3)
9480 {
9481 return gl::error(GL_INVALID_OPERATION);
9482 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009483
Geoff Lang3ed0c482013-07-25 17:03:18 -04009484 if (!validateES3FramebufferTextureParameters(context, target, attachment, GL_NONE, texture, level, layer, true))
9485 {
9486 return;
9487 }
9488
9489 gl::Framebuffer *framebuffer = NULL;
9490 if (target == GL_READ_FRAMEBUFFER)
9491 {
9492 framebuffer = context->getReadFramebuffer();
9493 }
9494 else
9495 {
9496 framebuffer = context->getDrawFramebuffer();
9497 }
9498
9499 gl::Texture *textureObject = context->getTexture(texture);
9500 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
9501
9502 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
9503 {
9504 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
9505 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
9506 }
9507 else
9508 {
9509 switch (attachment)
9510 {
9511 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
9512 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
9513 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
9514 }
9515 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009516 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009517 }
9518 catch(std::bad_alloc&)
9519 {
9520 return gl::error(GL_OUT_OF_MEMORY);
9521 }
9522}
9523
9524GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9525{
9526 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9527 target, offset, length, access);
9528
9529 try
9530 {
9531 gl::Context *context = gl::getNonLostContext();
9532
9533 if (context)
9534 {
9535 if (context->getClientVersion() < 3)
9536 {
9537 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009539
Jamie Madill54133512013-06-21 09:33:07 -04009540 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009541 UNIMPLEMENTED();
9542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009543 }
9544 catch(std::bad_alloc&)
9545 {
9546 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9547 }
9548
9549 return NULL;
9550}
9551
9552void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9553{
9554 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9555
9556 try
9557 {
9558 gl::Context *context = gl::getNonLostContext();
9559
9560 if (context)
9561 {
9562 if (context->getClientVersion() < 3)
9563 {
9564 return gl::error(GL_INVALID_OPERATION);
9565 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009566
Jamie Madill54133512013-06-21 09:33:07 -04009567 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009568 UNIMPLEMENTED();
9569 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009570 }
9571 catch(std::bad_alloc&)
9572 {
9573 return gl::error(GL_OUT_OF_MEMORY);
9574 }
9575}
9576
9577void __stdcall glBindVertexArray(GLuint array)
9578{
9579 EVENT("(GLuint array = %u)", array);
9580
9581 try
9582 {
9583 gl::Context *context = gl::getNonLostContext();
9584
9585 if (context)
9586 {
9587 if (context->getClientVersion() < 3)
9588 {
9589 return gl::error(GL_INVALID_OPERATION);
9590 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009591
Jamie Madilld1028542013-07-02 11:57:04 -04009592 gl::VertexArray *vao = context->getVertexArray(array);
9593
9594 if (!vao)
9595 {
9596 // The default VAO should always exist
9597 ASSERT(array != 0);
9598 return gl::error(GL_INVALID_OPERATION);
9599 }
9600
9601 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009602 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009603 }
9604 catch(std::bad_alloc&)
9605 {
9606 return gl::error(GL_OUT_OF_MEMORY);
9607 }
9608}
9609
9610void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9611{
9612 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9613
9614 try
9615 {
9616 gl::Context *context = gl::getNonLostContext();
9617
9618 if (context)
9619 {
9620 if (context->getClientVersion() < 3)
9621 {
9622 return gl::error(GL_INVALID_OPERATION);
9623 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009624
Jamie Madilld1028542013-07-02 11:57:04 -04009625 if (n < 0)
9626 {
9627 return gl::error(GL_INVALID_VALUE);
9628 }
9629
9630 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9631 {
9632 if (arrays[arrayIndex] != 0)
9633 {
9634 context->deleteVertexArray(arrays[arrayIndex]);
9635 }
9636 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009638 }
9639 catch(std::bad_alloc&)
9640 {
9641 return gl::error(GL_OUT_OF_MEMORY);
9642 }
9643}
9644
9645void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9646{
9647 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9648
9649 try
9650 {
9651 gl::Context *context = gl::getNonLostContext();
9652
9653 if (context)
9654 {
9655 if (context->getClientVersion() < 3)
9656 {
9657 return gl::error(GL_INVALID_OPERATION);
9658 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009659
Jamie Madilld1028542013-07-02 11:57:04 -04009660 if (n < 0)
9661 {
9662 return gl::error(GL_INVALID_VALUE);
9663 }
9664
9665 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9666 {
9667 arrays[arrayIndex] = context->createVertexArray();
9668 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009669 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009670 }
9671 catch(std::bad_alloc&)
9672 {
9673 return gl::error(GL_OUT_OF_MEMORY);
9674 }
9675}
9676
9677GLboolean __stdcall glIsVertexArray(GLuint array)
9678{
9679 EVENT("(GLuint array = %u)", array);
9680
9681 try
9682 {
9683 gl::Context *context = gl::getNonLostContext();
9684
9685 if (context)
9686 {
9687 if (context->getClientVersion() < 3)
9688 {
9689 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9690 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009691
Jamie Madilld1028542013-07-02 11:57:04 -04009692 if (array == 0)
9693 {
9694 return GL_FALSE;
9695 }
9696
9697 gl::VertexArray *vao = context->getVertexArray(array);
9698
9699 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009700 }
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, GL_FALSE);
9705 }
9706
9707 return GL_FALSE;
9708}
9709
9710void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9711{
9712 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9713 target, index, data);
9714
9715 try
9716 {
9717 gl::Context *context = gl::getNonLostContext();
9718
9719 if (context)
9720 {
9721 if (context->getClientVersion() < 3)
9722 {
9723 return gl::error(GL_INVALID_OPERATION);
9724 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009725
Jamie Madill54133512013-06-21 09:33:07 -04009726 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009727 UNIMPLEMENTED();
9728 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009729 }
9730 catch(std::bad_alloc&)
9731 {
9732 return gl::error(GL_OUT_OF_MEMORY);
9733 }
9734}
9735
9736void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9737{
9738 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
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 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009750
Jamie Madill54133512013-06-21 09:33:07 -04009751 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009752 UNIMPLEMENTED();
9753 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009754 }
9755 catch(std::bad_alloc&)
9756 {
9757 return gl::error(GL_OUT_OF_MEMORY);
9758 }
9759}
9760
9761void __stdcall glEndTransformFeedback(void)
9762{
9763 EVENT("(void)");
9764
9765 try
9766 {
9767 gl::Context *context = gl::getNonLostContext();
9768
9769 if (context)
9770 {
9771 if (context->getClientVersion() < 3)
9772 {
9773 return gl::error(GL_INVALID_OPERATION);
9774 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009775
Jamie Madill54133512013-06-21 09:33:07 -04009776 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009777 UNIMPLEMENTED();
9778 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009779 }
9780 catch(std::bad_alloc&)
9781 {
9782 return gl::error(GL_OUT_OF_MEMORY);
9783 }
9784}
9785
9786void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9787{
9788 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9789 target, index, buffer, offset, size);
9790
9791 try
9792 {
9793 gl::Context *context = gl::getNonLostContext();
9794
9795 if (context)
9796 {
9797 if (context->getClientVersion() < 3)
9798 {
9799 return gl::error(GL_INVALID_OPERATION);
9800 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009801
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009802 switch (target)
9803 {
9804 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009805 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009806 {
9807 return gl::error(GL_INVALID_VALUE);
9808 }
9809 break;
9810
9811 case GL_UNIFORM_BUFFER:
9812 if (index >= context->getMaximumCombinedUniformBufferBindings())
9813 {
9814 return gl::error(GL_INVALID_VALUE);
9815 }
9816 break;
9817
9818 default:
9819 return gl::error(GL_INVALID_ENUM);
9820 }
9821
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009822 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009823 {
9824 return gl::error(GL_INVALID_VALUE);
9825 }
9826
9827 switch (target)
9828 {
9829 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009830
9831 // size and offset must be a multiple of 4
9832 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9833 {
9834 return gl::error(GL_INVALID_VALUE);
9835 }
9836
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009837 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9838 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009839 break;
9840
9841 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009842
9843 // it is an error to bind an offset not a multiple of the alignment
9844 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9845 {
9846 return gl::error(GL_INVALID_VALUE);
9847 }
9848
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009849 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9850 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009851 break;
9852
9853 default:
9854 UNREACHABLE();
9855 }
9856 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009857 }
9858 catch(std::bad_alloc&)
9859 {
9860 return gl::error(GL_OUT_OF_MEMORY);
9861 }
9862}
9863
9864void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9865{
9866 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9867 target, index, buffer);
9868
9869 try
9870 {
9871 gl::Context *context = gl::getNonLostContext();
9872
9873 if (context)
9874 {
9875 if (context->getClientVersion() < 3)
9876 {
9877 return gl::error(GL_INVALID_OPERATION);
9878 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009879
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009880 switch (target)
9881 {
9882 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009883 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009884 {
9885 return gl::error(GL_INVALID_VALUE);
9886 }
9887 break;
9888
9889 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009890 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009891 {
9892 return gl::error(GL_INVALID_VALUE);
9893 }
9894 break;
9895
9896 default:
9897 return gl::error(GL_INVALID_ENUM);
9898 }
9899
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009900 switch (target)
9901 {
9902 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009903 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009904 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009905 break;
9906
9907 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009908 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009909 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009910 break;
9911
9912 default:
9913 UNREACHABLE();
9914 }
9915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009916 }
9917 catch(std::bad_alloc&)
9918 {
9919 return gl::error(GL_OUT_OF_MEMORY);
9920 }
9921}
9922
9923void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9924{
9925 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9926 program, count, varyings, bufferMode);
9927
9928 try
9929 {
9930 gl::Context *context = gl::getNonLostContext();
9931
9932 if (context)
9933 {
9934 if (context->getClientVersion() < 3)
9935 {
9936 return gl::error(GL_INVALID_OPERATION);
9937 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009938
Jamie Madill54133512013-06-21 09:33:07 -04009939 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009940 UNIMPLEMENTED();
9941 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009942 }
9943 catch(std::bad_alloc&)
9944 {
9945 return gl::error(GL_OUT_OF_MEMORY);
9946 }
9947}
9948
9949void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9950{
9951 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9952 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9953 program, index, bufSize, length, size, type, name);
9954
9955 try
9956 {
9957 gl::Context *context = gl::getNonLostContext();
9958
9959 if (context)
9960 {
9961 if (context->getClientVersion() < 3)
9962 {
9963 return gl::error(GL_INVALID_OPERATION);
9964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009965
Jamie Madill54133512013-06-21 09:33:07 -04009966 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009967 UNIMPLEMENTED();
9968 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009969 }
9970 catch(std::bad_alloc&)
9971 {
9972 return gl::error(GL_OUT_OF_MEMORY);
9973 }
9974}
9975
9976void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9977{
9978 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9979 index, size, type, stride, pointer);
9980
9981 try
9982 {
9983 gl::Context *context = gl::getNonLostContext();
9984
9985 if (context)
9986 {
9987 if (context->getClientVersion() < 3)
9988 {
9989 return gl::error(GL_INVALID_OPERATION);
9990 }
9991 }
9992
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009993 if (index >= gl::MAX_VERTEX_ATTRIBS)
9994 {
9995 return gl::error(GL_INVALID_VALUE);
9996 }
9997
9998 if (size < 1 || size > 4)
9999 {
10000 return gl::error(GL_INVALID_VALUE);
10001 }
10002
10003 switch (type)
10004 {
10005 case GL_BYTE:
10006 case GL_UNSIGNED_BYTE:
10007 case GL_SHORT:
10008 case GL_UNSIGNED_SHORT:
10009 case GL_INT:
10010 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +000010011 case GL_INT_2_10_10_10_REV:
10012 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010013 break;
10014 default:
10015 return gl::error(GL_INVALID_ENUM);
10016 }
10017
10018 if (stride < 0)
10019 {
10020 return gl::error(GL_INVALID_VALUE);
10021 }
10022
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +000010023 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
10024 {
10025 return gl::error(GL_INVALID_OPERATION);
10026 }
10027
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010028 if (context)
10029 {
Jamie Madilld8db8662013-07-02 11:57:04 -040010030 // [OpenGL ES 3.0.2] Section 2.8 page 24:
10031 // An INVALID_OPERATION error is generated when a non-zero vertex array object
10032 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
10033 // and the pointer argument is not NULL.
10034 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
10035 {
10036 return gl::error(GL_INVALID_OPERATION);
10037 }
10038
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010039 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
10040 stride, pointer);
10041 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010042 }
10043 catch(std::bad_alloc&)
10044 {
10045 return gl::error(GL_OUT_OF_MEMORY);
10046 }
10047}
10048
10049void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
10050{
10051 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10052 index, pname, params);
10053
10054 try
10055 {
10056 gl::Context *context = gl::getNonLostContext();
10057
10058 if (context)
10059 {
10060 if (context->getClientVersion() < 3)
10061 {
10062 return gl::error(GL_INVALID_OPERATION);
10063 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010064
Jamie Madilla7d05862013-07-02 11:57:06 -040010065 if (index >= gl::MAX_VERTEX_ATTRIBS)
10066 {
10067 return gl::error(GL_INVALID_VALUE);
10068 }
10069
10070 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
10071
10072 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
10073 {
10074 return;
10075 }
10076
10077 if (pname == GL_CURRENT_VERTEX_ATTRIB)
10078 {
10079 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
10080 for (int i = 0; i < 4; ++i)
10081 {
10082 params[i] = currentValueData.IntValues[i];
10083 }
10084 }
10085 else
10086 {
10087 *params = attribState.querySingleParameter<GLint>(pname);
10088 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010090 }
10091 catch(std::bad_alloc&)
10092 {
10093 return gl::error(GL_OUT_OF_MEMORY);
10094 }
10095}
10096
10097void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
10098{
10099 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
10100 index, pname, params);
10101
10102 try
10103 {
10104 gl::Context *context = gl::getNonLostContext();
10105
10106 if (context)
10107 {
10108 if (context->getClientVersion() < 3)
10109 {
10110 return gl::error(GL_INVALID_OPERATION);
10111 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010112
Jamie Madilla7d05862013-07-02 11:57:06 -040010113 if (index >= gl::MAX_VERTEX_ATTRIBS)
10114 {
10115 return gl::error(GL_INVALID_VALUE);
10116 }
10117
10118 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
10119
10120 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
10121 {
10122 return;
10123 }
10124
10125 if (pname == GL_CURRENT_VERTEX_ATTRIB)
10126 {
10127 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
10128 for (int i = 0; i < 4; ++i)
10129 {
10130 params[i] = currentValueData.UnsignedIntValues[i];
10131 }
10132 }
10133 else
10134 {
10135 *params = attribState.querySingleParameter<GLuint>(pname);
10136 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010137 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010138 }
10139 catch(std::bad_alloc&)
10140 {
10141 return gl::error(GL_OUT_OF_MEMORY);
10142 }
10143}
10144
10145void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
10146{
10147 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
10148 index, x, y, z, w);
10149
10150 try
10151 {
10152 gl::Context *context = gl::getNonLostContext();
10153
10154 if (context)
10155 {
10156 if (context->getClientVersion() < 3)
10157 {
10158 return gl::error(GL_INVALID_OPERATION);
10159 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010160
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010161 if (index >= gl::MAX_VERTEX_ATTRIBS)
10162 {
10163 return gl::error(GL_INVALID_VALUE);
10164 }
10165
10166 GLint vals[4] = { x, y, z, w };
10167 context->setVertexAttribi(index, vals);
10168 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010169 }
10170 catch(std::bad_alloc&)
10171 {
10172 return gl::error(GL_OUT_OF_MEMORY);
10173 }
10174}
10175
10176void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
10177{
10178 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
10179 index, x, y, z, w);
10180
10181 try
10182 {
10183 gl::Context *context = gl::getNonLostContext();
10184
10185 if (context)
10186 {
10187 if (context->getClientVersion() < 3)
10188 {
10189 return gl::error(GL_INVALID_OPERATION);
10190 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010191
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010192 if (index >= gl::MAX_VERTEX_ATTRIBS)
10193 {
10194 return gl::error(GL_INVALID_VALUE);
10195 }
10196
10197 GLuint vals[4] = { x, y, z, w };
10198 context->setVertexAttribu(index, vals);
10199 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010200 }
10201 catch(std::bad_alloc&)
10202 {
10203 return gl::error(GL_OUT_OF_MEMORY);
10204 }
10205}
10206
10207void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
10208{
10209 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
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.coma8885862013-04-13 03:37:53 +000010222 if (index >= gl::MAX_VERTEX_ATTRIBS)
10223 {
10224 return gl::error(GL_INVALID_VALUE);
10225 }
10226
10227 context->setVertexAttribi(index, v);
10228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010229 }
10230 catch(std::bad_alloc&)
10231 {
10232 return gl::error(GL_OUT_OF_MEMORY);
10233 }
10234}
10235
10236void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
10237{
10238 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
10239
10240 try
10241 {
10242 gl::Context *context = gl::getNonLostContext();
10243
10244 if (context)
10245 {
10246 if (context->getClientVersion() < 3)
10247 {
10248 return gl::error(GL_INVALID_OPERATION);
10249 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010250
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010251 if (index >= gl::MAX_VERTEX_ATTRIBS)
10252 {
10253 return gl::error(GL_INVALID_VALUE);
10254 }
10255
10256 context->setVertexAttribu(index, v);
10257 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010258 }
10259 catch(std::bad_alloc&)
10260 {
10261 return gl::error(GL_OUT_OF_MEMORY);
10262 }
10263}
10264
10265void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
10266{
10267 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
10268 program, location, params);
10269
10270 try
10271 {
10272 gl::Context *context = gl::getNonLostContext();
10273
10274 if (context)
10275 {
10276 if (context->getClientVersion() < 3)
10277 {
10278 return gl::error(GL_INVALID_OPERATION);
10279 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010280
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +000010281 if (program == 0)
10282 {
10283 return gl::error(GL_INVALID_VALUE);
10284 }
10285
10286 gl::Program *programObject = context->getProgram(program);
10287
10288 if (!programObject || !programObject->isLinked())
10289 {
10290 return gl::error(GL_INVALID_OPERATION);
10291 }
10292
10293 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10294 if (!programBinary)
10295 {
10296 return gl::error(GL_INVALID_OPERATION);
10297 }
10298
10299 if (!programBinary->getUniformuiv(location, NULL, params))
10300 {
10301 return gl::error(GL_INVALID_OPERATION);
10302 }
10303 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010304 }
10305 catch(std::bad_alloc&)
10306 {
10307 return gl::error(GL_OUT_OF_MEMORY);
10308 }
10309}
10310
10311GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10312{
10313 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10314 program, name);
10315
10316 try
10317 {
10318 gl::Context *context = gl::getNonLostContext();
10319
10320 if (context)
10321 {
10322 if (context->getClientVersion() < 3)
10323 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010324 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010326
Jamie Madilld1e78c92013-06-20 11:55:50 -040010327 if (program == 0)
10328 {
10329 return gl::error(GL_INVALID_VALUE, -1);
10330 }
10331
10332 gl::Program *programObject = context->getProgram(program);
10333
10334 if (!programObject || !programObject->isLinked())
10335 {
10336 return gl::error(GL_INVALID_OPERATION, -1);
10337 }
10338
10339 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10340 if (!programBinary)
10341 {
10342 return gl::error(GL_INVALID_OPERATION, -1);
10343 }
10344
10345 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010346 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010347 }
10348 catch(std::bad_alloc&)
10349 {
10350 return gl::error(GL_OUT_OF_MEMORY, 0);
10351 }
10352
10353 return 0;
10354}
10355
10356void __stdcall glUniform1ui(GLint location, GLuint v0)
10357{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010358 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010359}
10360
10361void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10362{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010363 const GLuint xy[] = { v0, v1 };
10364 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010365}
10366
10367void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10368{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010369 const GLuint xyz[] = { v0, v1, v2 };
10370 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010371}
10372
10373void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10374{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010375 const GLuint xyzw[] = { v0, v1, v2, v3 };
10376 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010377}
10378
10379void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10380{
10381 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10382 location, count, value);
10383
10384 try
10385 {
10386 gl::Context *context = gl::getNonLostContext();
10387
10388 if (context)
10389 {
10390 if (context->getClientVersion() < 3)
10391 {
10392 return gl::error(GL_INVALID_OPERATION);
10393 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010394
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010395 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10396 if (!programBinary)
10397 {
10398 return gl::error(GL_INVALID_OPERATION);
10399 }
10400
10401 if (!programBinary->setUniform1uiv(location, count, value))
10402 {
10403 return gl::error(GL_INVALID_OPERATION);
10404 }
10405 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010406 }
10407 catch(std::bad_alloc&)
10408 {
10409 return gl::error(GL_OUT_OF_MEMORY);
10410 }
10411}
10412
10413void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10414{
10415 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10416 location, count, value);
10417
10418 try
10419 {
10420 gl::Context *context = gl::getNonLostContext();
10421
10422 if (context)
10423 {
10424 if (context->getClientVersion() < 3)
10425 {
10426 return gl::error(GL_INVALID_OPERATION);
10427 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010428
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010429 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10430 if (!programBinary)
10431 {
10432 return gl::error(GL_INVALID_OPERATION);
10433 }
10434
10435 if (!programBinary->setUniform2uiv(location, count, value))
10436 {
10437 return gl::error(GL_INVALID_OPERATION);
10438 }
10439 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010440 }
10441 catch(std::bad_alloc&)
10442 {
10443 return gl::error(GL_OUT_OF_MEMORY);
10444 }
10445}
10446
10447void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10448{
10449 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10450 location, count, value);
10451
10452 try
10453 {
10454 gl::Context *context = gl::getNonLostContext();
10455
10456 if (context)
10457 {
10458 if (context->getClientVersion() < 3)
10459 {
10460 return gl::error(GL_INVALID_OPERATION);
10461 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010462
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010463 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10464 if (!programBinary)
10465 {
10466 return gl::error(GL_INVALID_OPERATION);
10467 }
10468
10469 if (!programBinary->setUniform3uiv(location, count, value))
10470 {
10471 return gl::error(GL_INVALID_OPERATION);
10472 }
10473 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010474 }
10475 catch(std::bad_alloc&)
10476 {
10477 return gl::error(GL_OUT_OF_MEMORY);
10478 }
10479}
10480
10481void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10482{
10483 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10484 location, count, value);
10485
10486 try
10487 {
10488 gl::Context *context = gl::getNonLostContext();
10489
10490 if (context)
10491 {
10492 if (context->getClientVersion() < 3)
10493 {
10494 return gl::error(GL_INVALID_OPERATION);
10495 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010496
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010497 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10498 if (!programBinary)
10499 {
10500 return gl::error(GL_INVALID_OPERATION);
10501 }
10502
10503 if (!programBinary->setUniform4uiv(location, count, value))
10504 {
10505 return gl::error(GL_INVALID_OPERATION);
10506 }
10507 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010508 }
10509 catch(std::bad_alloc&)
10510 {
10511 return gl::error(GL_OUT_OF_MEMORY);
10512 }
10513}
10514
10515void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10516{
10517 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10518 buffer, drawbuffer, value);
10519
10520 try
10521 {
10522 gl::Context *context = gl::getNonLostContext();
10523
10524 if (context)
10525 {
10526 if (context->getClientVersion() < 3)
10527 {
10528 return gl::error(GL_INVALID_OPERATION);
10529 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010530
Jamie Madill54133512013-06-21 09:33:07 -040010531 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010532 UNIMPLEMENTED();
10533 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010534 }
10535 catch(std::bad_alloc&)
10536 {
10537 return gl::error(GL_OUT_OF_MEMORY);
10538 }
10539}
10540
10541void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10542{
10543 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10544 buffer, drawbuffer, value);
10545
10546 try
10547 {
10548 gl::Context *context = gl::getNonLostContext();
10549
10550 if (context)
10551 {
10552 if (context->getClientVersion() < 3)
10553 {
10554 return gl::error(GL_INVALID_OPERATION);
10555 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010556
Jamie Madill54133512013-06-21 09:33:07 -040010557 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010558 UNIMPLEMENTED();
10559 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010560 }
10561 catch(std::bad_alloc&)
10562 {
10563 return gl::error(GL_OUT_OF_MEMORY);
10564 }
10565}
10566
10567void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10568{
10569 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10570 buffer, drawbuffer, value);
10571
10572 try
10573 {
10574 gl::Context *context = gl::getNonLostContext();
10575
10576 if (context)
10577 {
10578 if (context->getClientVersion() < 3)
10579 {
10580 return gl::error(GL_INVALID_OPERATION);
10581 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010582
Jamie Madill54133512013-06-21 09:33:07 -040010583 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010584 UNIMPLEMENTED();
10585 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010586 }
10587 catch(std::bad_alloc&)
10588 {
10589 return gl::error(GL_OUT_OF_MEMORY);
10590 }
10591}
10592
10593void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10594{
10595 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10596 buffer, drawbuffer, depth, stencil);
10597
10598 try
10599 {
10600 gl::Context *context = gl::getNonLostContext();
10601
10602 if (context)
10603 {
10604 if (context->getClientVersion() < 3)
10605 {
10606 return gl::error(GL_INVALID_OPERATION);
10607 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010608
Jamie Madill54133512013-06-21 09:33:07 -040010609 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010610 UNIMPLEMENTED();
10611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010612 }
10613 catch(std::bad_alloc&)
10614 {
10615 return gl::error(GL_OUT_OF_MEMORY);
10616 }
10617}
10618
10619const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10620{
10621 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10622
10623 try
10624 {
10625 gl::Context *context = gl::getNonLostContext();
10626
10627 if (context)
10628 {
10629 if (context->getClientVersion() < 3)
10630 {
10631 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10632 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010633
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010634 if (name != GL_EXTENSIONS)
10635 {
10636 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10637 }
10638
10639 if (index >= context->getNumExtensions())
10640 {
10641 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10642 }
10643
10644 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10645 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010646 }
10647 catch(std::bad_alloc&)
10648 {
10649 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10650 }
10651
10652 return NULL;
10653}
10654
10655void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10656{
10657 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10658 readTarget, writeTarget, readOffset, writeOffset, size);
10659
10660 try
10661 {
10662 gl::Context *context = gl::getNonLostContext();
10663
10664 if (context)
10665 {
10666 if (context->getClientVersion() < 3)
10667 {
10668 return gl::error(GL_INVALID_OPERATION);
10669 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010670
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010671 gl::Buffer *readBuffer = NULL;
10672 switch (readTarget)
10673 {
10674 case GL_ARRAY_BUFFER:
10675 readBuffer = context->getArrayBuffer();
10676 break;
10677 case GL_COPY_READ_BUFFER:
10678 readBuffer = context->getCopyReadBuffer();
10679 break;
10680 case GL_COPY_WRITE_BUFFER:
10681 readBuffer = context->getCopyWriteBuffer();
10682 break;
10683 case GL_ELEMENT_ARRAY_BUFFER:
10684 readBuffer = context->getElementArrayBuffer();
10685 break;
10686 case GL_PIXEL_PACK_BUFFER:
10687 readBuffer = context->getPixelPackBuffer();
10688 break;
10689 case GL_PIXEL_UNPACK_BUFFER:
10690 readBuffer = context->getPixelUnpackBuffer();
10691 break;
10692 case GL_TRANSFORM_FEEDBACK_BUFFER:
10693 readBuffer = context->getGenericTransformFeedbackBuffer();
10694 break;
10695 case GL_UNIFORM_BUFFER:
10696 readBuffer = context->getGenericUniformBuffer();
10697 break;
10698 default:
10699 return gl::error(GL_INVALID_ENUM);
10700 }
10701
10702 gl::Buffer *writeBuffer = NULL;
10703 switch (writeTarget)
10704 {
10705 case GL_ARRAY_BUFFER:
10706 writeBuffer = context->getArrayBuffer();
10707 break;
10708 case GL_COPY_READ_BUFFER:
10709 writeBuffer = context->getCopyReadBuffer();
10710 break;
10711 case GL_COPY_WRITE_BUFFER:
10712 writeBuffer = context->getCopyWriteBuffer();
10713 break;
10714 case GL_ELEMENT_ARRAY_BUFFER:
10715 writeBuffer = context->getElementArrayBuffer();
10716 break;
10717 case GL_PIXEL_PACK_BUFFER:
10718 writeBuffer = context->getPixelPackBuffer();
10719 break;
10720 case GL_PIXEL_UNPACK_BUFFER:
10721 writeBuffer = context->getPixelUnpackBuffer();
10722 break;
10723 case GL_TRANSFORM_FEEDBACK_BUFFER:
10724 writeBuffer = context->getGenericTransformFeedbackBuffer();
10725 break;
10726 case GL_UNIFORM_BUFFER:
10727 writeBuffer = context->getGenericUniformBuffer();
10728 break;
10729 default:
10730 return gl::error(GL_INVALID_ENUM);
10731 }
10732
10733 if (!readBuffer || !writeBuffer)
10734 {
10735 return gl::error(GL_INVALID_OPERATION);
10736 }
10737
10738 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10739 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10740 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10741 {
10742 return gl::error(GL_INVALID_VALUE);
10743 }
10744
10745 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10746 {
10747 return gl::error(GL_INVALID_VALUE);
10748 }
10749
10750 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10751
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010752 // if size is zero, the copy is a successful no-op
10753 if (size > 0)
10754 {
10755 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10756 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010757 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010758 }
10759 catch(std::bad_alloc&)
10760 {
10761 return gl::error(GL_OUT_OF_MEMORY);
10762 }
10763}
10764
10765void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10766{
10767 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10768 program, uniformCount, uniformNames, uniformIndices);
10769
10770 try
10771 {
10772 gl::Context *context = gl::getNonLostContext();
10773
10774 if (context)
10775 {
10776 if (context->getClientVersion() < 3)
10777 {
10778 return gl::error(GL_INVALID_OPERATION);
10779 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010780
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010781 if (uniformCount < 0)
10782 {
10783 return gl::error(GL_INVALID_VALUE);
10784 }
10785
10786 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 if (!programObject->isLinked() || !programBinary)
10802 {
10803 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10804 {
10805 uniformIndices[uniformId] = GL_INVALID_INDEX;
10806 }
10807 }
10808 else
10809 {
10810 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10811 {
10812 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10813 }
10814 }
10815 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010816 }
10817 catch(std::bad_alloc&)
10818 {
10819 return gl::error(GL_OUT_OF_MEMORY);
10820 }
10821}
10822
10823void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10824{
10825 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10826 program, uniformCount, uniformIndices, pname, params);
10827
10828 try
10829 {
10830 gl::Context *context = gl::getNonLostContext();
10831
10832 if (context)
10833 {
10834 if (context->getClientVersion() < 3)
10835 {
10836 return gl::error(GL_INVALID_OPERATION);
10837 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010838
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010839 if (uniformCount < 0)
10840 {
10841 return gl::error(GL_INVALID_VALUE);
10842 }
10843
10844 gl::Program *programObject = context->getProgram(program);
10845
10846 if (!programObject)
10847 {
10848 if (context->getShader(program))
10849 {
10850 return gl::error(GL_INVALID_OPERATION);
10851 }
10852 else
10853 {
10854 return gl::error(GL_INVALID_VALUE);
10855 }
10856 }
10857
10858 switch (pname)
10859 {
10860 case GL_UNIFORM_TYPE:
10861 case GL_UNIFORM_SIZE:
10862 case GL_UNIFORM_NAME_LENGTH:
10863 case GL_UNIFORM_BLOCK_INDEX:
10864 case GL_UNIFORM_OFFSET:
10865 case GL_UNIFORM_ARRAY_STRIDE:
10866 case GL_UNIFORM_MATRIX_STRIDE:
10867 case GL_UNIFORM_IS_ROW_MAJOR:
10868 break;
10869 default:
10870 return gl::error(GL_INVALID_ENUM);
10871 }
10872
10873 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10874
10875 if (!programBinary && uniformCount > 0)
10876 {
10877 return gl::error(GL_INVALID_VALUE);
10878 }
10879
10880 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10881 {
10882 const GLuint index = uniformIndices[uniformId];
10883
10884 if (index >= (GLuint)programBinary->getActiveUniformCount())
10885 {
10886 return gl::error(GL_INVALID_VALUE);
10887 }
10888 }
10889
10890 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10891 {
10892 const GLuint index = uniformIndices[uniformId];
10893 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10894 }
10895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010896 }
10897 catch(std::bad_alloc&)
10898 {
10899 return gl::error(GL_OUT_OF_MEMORY);
10900 }
10901}
10902
10903GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10904{
10905 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10906
10907 try
10908 {
10909 gl::Context *context = gl::getNonLostContext();
10910
10911 if (context)
10912 {
10913 if (context->getClientVersion() < 3)
10914 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010915 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010916 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010917
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010918 gl::Program *programObject = context->getProgram(program);
10919
10920 if (!programObject)
10921 {
10922 if (context->getShader(program))
10923 {
10924 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10925 }
10926 else
10927 {
10928 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10929 }
10930 }
10931
10932 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10933 if (!programBinary)
10934 {
10935 return GL_INVALID_INDEX;
10936 }
10937
10938 return programBinary->getUniformBlockIndex(uniformBlockName);
10939 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010940 }
10941 catch(std::bad_alloc&)
10942 {
10943 return gl::error(GL_OUT_OF_MEMORY, 0);
10944 }
10945
10946 return 0;
10947}
10948
10949void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10950{
10951 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10952 program, uniformBlockIndex, pname, params);
10953
10954 try
10955 {
10956 gl::Context *context = gl::getNonLostContext();
10957
10958 if (context)
10959 {
10960 if (context->getClientVersion() < 3)
10961 {
10962 return gl::error(GL_INVALID_OPERATION);
10963 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010964 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010965
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010966 if (!programObject)
10967 {
10968 if (context->getShader(program))
10969 {
10970 return gl::error(GL_INVALID_OPERATION);
10971 }
10972 else
10973 {
10974 return gl::error(GL_INVALID_VALUE);
10975 }
10976 }
10977
10978 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10979
10980 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10981 {
10982 return gl::error(GL_INVALID_VALUE);
10983 }
10984
10985 switch (pname)
10986 {
10987 case GL_UNIFORM_BLOCK_BINDING:
10988 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10989 break;
10990
10991 case GL_UNIFORM_BLOCK_DATA_SIZE:
10992 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10993 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10994 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10995 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10996 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10997 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10998 break;
10999
11000 default:
11001 return gl::error(GL_INVALID_ENUM);
11002 }
11003 }
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
11011void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
11012{
11013 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
11014 program, uniformBlockIndex, bufSize, length, uniformBlockName);
11015
11016 try
11017 {
11018 gl::Context *context = gl::getNonLostContext();
11019
11020 if (context)
11021 {
11022 if (context->getClientVersion() < 3)
11023 {
11024 return gl::error(GL_INVALID_OPERATION);
11025 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011026
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000011027 gl::Program *programObject = context->getProgram(program);
11028
11029 if (!programObject)
11030 {
11031 if (context->getShader(program))
11032 {
11033 return gl::error(GL_INVALID_OPERATION);
11034 }
11035 else
11036 {
11037 return gl::error(GL_INVALID_VALUE);
11038 }
11039 }
11040
11041 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11042
11043 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
11044 {
11045 return gl::error(GL_INVALID_VALUE);
11046 }
11047
11048 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
11049 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011050 }
11051 catch(std::bad_alloc&)
11052 {
11053 return gl::error(GL_OUT_OF_MEMORY);
11054 }
11055}
11056
11057void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
11058{
11059 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
11060 program, uniformBlockIndex, uniformBlockBinding);
11061
11062 try
11063 {
11064 gl::Context *context = gl::getNonLostContext();
11065
11066 if (context)
11067 {
11068 if (context->getClientVersion() < 3)
11069 {
11070 return gl::error(GL_INVALID_OPERATION);
11071 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011072
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000011073 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
11074 {
11075 return gl::error(GL_INVALID_VALUE);
11076 }
11077
11078 gl::Program *programObject = context->getProgram(program);
11079
11080 if (!programObject)
11081 {
11082 if (context->getShader(program))
11083 {
11084 return gl::error(GL_INVALID_OPERATION);
11085 }
11086 else
11087 {
11088 return gl::error(GL_INVALID_VALUE);
11089 }
11090 }
11091
11092 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11093
11094 // if never linked, there won't be any uniform blocks
11095 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
11096 {
11097 return gl::error(GL_INVALID_VALUE);
11098 }
11099
11100 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
11101 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011102 }
11103 catch(std::bad_alloc&)
11104 {
11105 return gl::error(GL_OUT_OF_MEMORY);
11106 }
11107}
11108
11109void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
11110{
11111 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
11112 mode, first, count, instanceCount);
11113
11114 try
11115 {
11116 gl::Context *context = gl::getNonLostContext();
11117
11118 if (context)
11119 {
11120 if (context->getClientVersion() < 3)
11121 {
11122 return gl::error(GL_INVALID_OPERATION);
11123 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011124
Jamie Madill54133512013-06-21 09:33:07 -040011125 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011126 UNIMPLEMENTED();
11127 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011128 }
11129 catch(std::bad_alloc&)
11130 {
11131 return gl::error(GL_OUT_OF_MEMORY);
11132 }
11133}
11134
11135void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
11136{
11137 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
11138 mode, count, type, indices, instanceCount);
11139
11140 try
11141 {
11142 gl::Context *context = gl::getNonLostContext();
11143
11144 if (context)
11145 {
11146 if (context->getClientVersion() < 3)
11147 {
11148 return gl::error(GL_INVALID_OPERATION);
11149 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011150
Jamie Madill54133512013-06-21 09:33:07 -040011151 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011152 UNIMPLEMENTED();
11153 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011154 }
11155 catch(std::bad_alloc&)
11156 {
11157 return gl::error(GL_OUT_OF_MEMORY);
11158 }
11159}
11160
11161GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
11162{
11163 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
11164
11165 try
11166 {
11167 gl::Context *context = gl::getNonLostContext();
11168
11169 if (context)
11170 {
11171 if (context->getClientVersion() < 3)
11172 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011173 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011174 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011175
Jamie Madill5215e1a2013-07-26 11:55:19 -040011176 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
11177 {
11178 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
11179 }
11180
11181 if (flags != 0)
11182 {
11183 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
11184 }
11185
11186 return context->createFenceSync(condition);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011187 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011188 }
11189 catch(std::bad_alloc&)
11190 {
11191 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
11192 }
11193
11194 return NULL;
11195}
11196
11197GLboolean __stdcall glIsSync(GLsync sync)
11198{
11199 EVENT("(GLsync sync = 0x%0.8p)", sync);
11200
11201 try
11202 {
11203 gl::Context *context = gl::getNonLostContext();
11204
11205 if (context)
11206 {
11207 if (context->getClientVersion() < 3)
11208 {
11209 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11210 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011211
Jamie Madill5215e1a2013-07-26 11:55:19 -040011212 return (context->getFenceSync(sync) != NULL);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011214 }
11215 catch(std::bad_alloc&)
11216 {
11217 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11218 }
11219
11220 return GL_FALSE;
11221}
11222
11223void __stdcall glDeleteSync(GLsync sync)
11224{
11225 EVENT("(GLsync sync = 0x%0.8p)", sync);
11226
11227 try
11228 {
11229 gl::Context *context = gl::getNonLostContext();
11230
11231 if (context)
11232 {
11233 if (context->getClientVersion() < 3)
11234 {
11235 return gl::error(GL_INVALID_OPERATION);
11236 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011237
Jamie Madill5215e1a2013-07-26 11:55:19 -040011238 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
11239 {
11240 return gl::error(GL_INVALID_VALUE);
11241 }
11242
11243 context->deleteFenceSync(sync);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011244 }
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
11252GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11253{
11254 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11255 sync, flags, timeout);
11256
11257 try
11258 {
11259 gl::Context *context = gl::getNonLostContext();
11260
11261 if (context)
11262 {
11263 if (context->getClientVersion() < 3)
11264 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011265 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011266 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011267
Jamie Madill5215e1a2013-07-26 11:55:19 -040011268 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
11269 {
11270 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11271 }
11272
11273 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11274
11275 if (!fenceSync)
11276 {
11277 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11278 }
11279
11280 return fenceSync->clientWait(flags, timeout);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011281 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011282 }
11283 catch(std::bad_alloc&)
11284 {
11285 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11286 }
11287
11288 return GL_FALSE;
11289}
11290
11291void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11292{
11293 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11294 sync, flags, timeout);
11295
11296 try
11297 {
11298 gl::Context *context = gl::getNonLostContext();
11299
11300 if (context)
11301 {
11302 if (context->getClientVersion() < 3)
11303 {
11304 return gl::error(GL_INVALID_OPERATION);
11305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011306
Jamie Madill5215e1a2013-07-26 11:55:19 -040011307 if (flags != 0)
11308 {
11309 return gl::error(GL_INVALID_VALUE);
11310 }
11311
11312 if (timeout != GL_TIMEOUT_IGNORED)
11313 {
11314 return gl::error(GL_INVALID_VALUE);
11315 }
11316
11317 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11318
11319 if (!fenceSync)
11320 {
11321 return gl::error(GL_INVALID_VALUE);
11322 }
11323
11324 fenceSync->serverWait();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011326 }
11327 catch(std::bad_alloc&)
11328 {
11329 return gl::error(GL_OUT_OF_MEMORY);
11330 }
11331}
11332
11333void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
11334{
11335 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11336 pname, params);
11337
11338 try
11339 {
11340 gl::Context *context = gl::getNonLostContext();
11341
11342 if (context)
11343 {
11344 if (context->getClientVersion() < 3)
11345 {
11346 return gl::error(GL_INVALID_OPERATION);
11347 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011348
Jamie Madill71fbd602013-07-19 16:36:55 -040011349 if (!(context->getInteger64v(pname, params)))
11350 {
11351 GLenum nativeType;
11352 unsigned int numParams = 0;
11353 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11354 return gl::error(GL_INVALID_ENUM);
11355
11356 if (numParams == 0)
11357 return; // it is known that the pname is valid, but that there are no parameters to return.
11358
11359 if (nativeType == GL_BOOL)
11360 {
11361 GLboolean *boolParams = NULL;
11362 boolParams = new GLboolean[numParams];
11363
11364 context->getBooleanv(pname, boolParams);
11365
11366 for (unsigned int i = 0; i < numParams; ++i)
11367 {
11368 if (boolParams[i] == GL_FALSE)
11369 params[i] = 0;
11370 else
11371 params[i] = 1;
11372 }
11373
11374 delete [] boolParams;
11375 }
11376 else if (nativeType == GL_INT)
11377 {
11378 GLint *intParams = NULL;
11379 intParams = new GLint[numParams];
11380
11381 context->getIntegerv(pname, intParams);
11382
11383 for (unsigned int i = 0; i < numParams; ++i)
11384 {
11385 params[i] = static_cast<GLint64>(intParams[i]);
11386 }
11387
11388 delete [] intParams;
11389 }
11390 else if (nativeType == GL_FLOAT)
11391 {
11392 GLfloat *floatParams = NULL;
11393 floatParams = new GLfloat[numParams];
11394
11395 context->getFloatv(pname, floatParams);
11396
11397 for (unsigned int i = 0; i < numParams; ++i)
11398 {
11399 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11400 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11401 {
11402 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11403 }
11404 else
11405 {
11406 params[i] = gl::iround<GLint64>(floatParams[i]);
11407 }
11408 }
11409
11410 delete [] floatParams;
11411 }
11412 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011413 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011414 }
11415 catch(std::bad_alloc&)
11416 {
11417 return gl::error(GL_OUT_OF_MEMORY);
11418 }
11419}
11420
11421void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11422{
11423 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11424 sync, pname, bufSize, length, values);
11425
11426 try
11427 {
11428 gl::Context *context = gl::getNonLostContext();
11429
11430 if (context)
11431 {
11432 if (context->getClientVersion() < 3)
11433 {
11434 return gl::error(GL_INVALID_OPERATION);
11435 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011436
Jamie Madill5215e1a2013-07-26 11:55:19 -040011437 if (bufSize < 0)
11438 {
11439 return gl::error(GL_INVALID_VALUE);
11440 }
11441
11442 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11443
11444 if (!fenceSync)
11445 {
11446 return gl::error(GL_INVALID_VALUE);
11447 }
11448
11449 switch (pname)
11450 {
11451 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
11452 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
11453 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
11454 case GL_SYNC_FLAGS: values[0] = 0; break;
11455
11456 default:
11457 return gl::error(GL_INVALID_ENUM);
11458 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011459 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011460 }
11461 catch(std::bad_alloc&)
11462 {
11463 return gl::error(GL_OUT_OF_MEMORY);
11464 }
11465}
11466
11467void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11468{
11469 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11470 target, index, data);
11471
11472 try
11473 {
11474 gl::Context *context = gl::getNonLostContext();
11475
11476 if (context)
11477 {
11478 if (context->getClientVersion() < 3)
11479 {
11480 return gl::error(GL_INVALID_OPERATION);
11481 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011482
Jamie Madill54133512013-06-21 09:33:07 -040011483 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011484 UNIMPLEMENTED();
11485 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011486 }
11487 catch(std::bad_alloc&)
11488 {
11489 return gl::error(GL_OUT_OF_MEMORY);
11490 }
11491}
11492
11493void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11494{
11495 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11496 target, pname, params);
11497
11498 try
11499 {
11500 gl::Context *context = gl::getNonLostContext();
11501
11502 if (context)
11503 {
11504 if (context->getClientVersion() < 3)
11505 {
11506 return gl::error(GL_INVALID_OPERATION);
11507 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011508
Jamie Madill54133512013-06-21 09:33:07 -040011509 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011510 UNIMPLEMENTED();
11511 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011512 }
11513 catch(std::bad_alloc&)
11514 {
11515 return gl::error(GL_OUT_OF_MEMORY);
11516 }
11517}
11518
11519void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11520{
11521 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11522
11523 try
11524 {
11525 gl::Context *context = gl::getNonLostContext();
11526
11527 if (context)
11528 {
11529 if (context->getClientVersion() < 3)
11530 {
11531 return gl::error(GL_INVALID_OPERATION);
11532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011533
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011534 if (count < 0)
11535 {
11536 return gl::error(GL_INVALID_VALUE);
11537 }
11538
11539 for (int i = 0; i < count; i++)
11540 {
11541 samplers[i] = context->createSampler();
11542 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011544 }
11545 catch(std::bad_alloc&)
11546 {
11547 return gl::error(GL_OUT_OF_MEMORY);
11548 }
11549}
11550
11551void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11552{
11553 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11554
11555 try
11556 {
11557 gl::Context *context = gl::getNonLostContext();
11558
11559 if (context)
11560 {
11561 if (context->getClientVersion() < 3)
11562 {
11563 return gl::error(GL_INVALID_OPERATION);
11564 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011565
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011566 if (count < 0)
11567 {
11568 return gl::error(GL_INVALID_VALUE);
11569 }
11570
11571 for (int i = 0; i < count; i++)
11572 {
11573 context->deleteSampler(samplers[i]);
11574 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011575 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011576 }
11577 catch(std::bad_alloc&)
11578 {
11579 return gl::error(GL_OUT_OF_MEMORY);
11580 }
11581}
11582
11583GLboolean __stdcall glIsSampler(GLuint sampler)
11584{
11585 EVENT("(GLuint sampler = %u)", sampler);
11586
11587 try
11588 {
11589 gl::Context *context = gl::getNonLostContext();
11590
11591 if (context)
11592 {
11593 if (context->getClientVersion() < 3)
11594 {
11595 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11596 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011597
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011598 return context->isSampler(sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011599 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011600 }
11601 catch(std::bad_alloc&)
11602 {
11603 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11604 }
11605
11606 return GL_FALSE;
11607}
11608
11609void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11610{
11611 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11612
11613 try
11614 {
11615 gl::Context *context = gl::getNonLostContext();
11616
11617 if (context)
11618 {
11619 if (context->getClientVersion() < 3)
11620 {
11621 return gl::error(GL_INVALID_OPERATION);
11622 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011623
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011624 if (sampler != 0 && !context->isSampler(sampler))
11625 {
11626 return gl::error(GL_INVALID_OPERATION);
11627 }
11628
11629 if (unit >= context->getMaximumCombinedTextureImageUnits())
11630 {
11631 return gl::error(GL_INVALID_VALUE);
11632 }
11633
11634 context->bindSampler(unit, sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011636 }
11637 catch(std::bad_alloc&)
11638 {
11639 return gl::error(GL_OUT_OF_MEMORY);
11640 }
11641}
11642
11643void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11644{
11645 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11646
11647 try
11648 {
11649 gl::Context *context = gl::getNonLostContext();
11650
11651 if (context)
11652 {
11653 if (context->getClientVersion() < 3)
11654 {
11655 return gl::error(GL_INVALID_OPERATION);
11656 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011657
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011658 if (!validateSamplerObjectParameter(pname))
11659 {
11660 return;
11661 }
11662
11663 if (!validateTexParamParameters(context, pname, param))
11664 {
11665 return;
11666 }
11667
11668 if (!context->isSampler(sampler))
11669 {
11670 return gl::error(GL_INVALID_OPERATION);
11671 }
11672
11673 context->samplerParameteri(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011674 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011675 }
11676 catch(std::bad_alloc&)
11677 {
11678 return gl::error(GL_OUT_OF_MEMORY);
11679 }
11680}
11681
11682void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11683{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011684 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011685}
11686
11687void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11688{
11689 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11690
11691 try
11692 {
11693 gl::Context *context = gl::getNonLostContext();
11694
11695 if (context)
11696 {
11697 if (context->getClientVersion() < 3)
11698 {
11699 return gl::error(GL_INVALID_OPERATION);
11700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011701
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011702 if (!validateSamplerObjectParameter(pname))
11703 {
11704 return;
11705 }
11706
11707 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
11708 {
11709 return;
11710 }
11711
11712 if (!context->isSampler(sampler))
11713 {
11714 return gl::error(GL_INVALID_OPERATION);
11715 }
11716
11717 context->samplerParameterf(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011718 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011719 }
11720 catch(std::bad_alloc&)
11721 {
11722 return gl::error(GL_OUT_OF_MEMORY);
11723 }
11724}
11725
11726void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11727{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011728 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011729}
11730
11731void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11732{
11733 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11734
11735 try
11736 {
11737 gl::Context *context = gl::getNonLostContext();
11738
11739 if (context)
11740 {
11741 if (context->getClientVersion() < 3)
11742 {
11743 return gl::error(GL_INVALID_OPERATION);
11744 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011745
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011746 if (!validateSamplerObjectParameter(pname))
11747 {
11748 return;
11749 }
11750
11751 if (!context->isSampler(sampler))
11752 {
11753 return gl::error(GL_INVALID_OPERATION);
11754 }
11755
11756 *params = context->getSamplerParameteri(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011757 }
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 glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11766{
11767 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11768
11769 try
11770 {
11771 gl::Context *context = gl::getNonLostContext();
11772
11773 if (context)
11774 {
11775 if (context->getClientVersion() < 3)
11776 {
11777 return gl::error(GL_INVALID_OPERATION);
11778 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011779
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011780 if (!validateSamplerObjectParameter(pname))
11781 {
11782 return;
11783 }
11784
11785 if (!context->isSampler(sampler))
11786 {
11787 return gl::error(GL_INVALID_OPERATION);
11788 }
11789
11790 *params = context->getSamplerParameterf(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011791 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011792 }
11793 catch(std::bad_alloc&)
11794 {
11795 return gl::error(GL_OUT_OF_MEMORY);
11796 }
11797}
11798
11799void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11800{
11801 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11802
11803 try
11804 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011805 if (index >= gl::MAX_VERTEX_ATTRIBS)
11806 {
11807 return gl::error(GL_INVALID_VALUE);
11808 }
11809
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011810 gl::Context *context = gl::getNonLostContext();
11811
11812 if (context)
11813 {
11814 if (context->getClientVersion() < 3)
11815 {
11816 return gl::error(GL_INVALID_OPERATION);
11817 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011818
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011819 context->setVertexAttribDivisor(index, divisor);
11820 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011821 }
11822 catch(std::bad_alloc&)
11823 {
11824 return gl::error(GL_OUT_OF_MEMORY);
11825 }
11826}
11827
11828void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11829{
11830 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11831
11832 try
11833 {
11834 gl::Context *context = gl::getNonLostContext();
11835
11836 if (context)
11837 {
11838 if (context->getClientVersion() < 3)
11839 {
11840 return gl::error(GL_INVALID_OPERATION);
11841 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011842
Jamie Madill54133512013-06-21 09:33:07 -040011843 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011844 UNIMPLEMENTED();
11845 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011846 }
11847 catch(std::bad_alloc&)
11848 {
11849 return gl::error(GL_OUT_OF_MEMORY);
11850 }
11851}
11852
11853void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11854{
11855 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11856
11857 try
11858 {
11859 gl::Context *context = gl::getNonLostContext();
11860
11861 if (context)
11862 {
11863 if (context->getClientVersion() < 3)
11864 {
11865 return gl::error(GL_INVALID_OPERATION);
11866 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011867
Jamie Madill54133512013-06-21 09:33:07 -040011868 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011869 UNIMPLEMENTED();
11870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011871 }
11872 catch(std::bad_alloc&)
11873 {
11874 return gl::error(GL_OUT_OF_MEMORY);
11875 }
11876}
11877
11878void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11879{
11880 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11881
11882 try
11883 {
11884 gl::Context *context = gl::getNonLostContext();
11885
11886 if (context)
11887 {
11888 if (context->getClientVersion() < 3)
11889 {
11890 return gl::error(GL_INVALID_OPERATION);
11891 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011892
Jamie Madill54133512013-06-21 09:33:07 -040011893 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011894 UNIMPLEMENTED();
11895 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011896 }
11897 catch(std::bad_alloc&)
11898 {
11899 return gl::error(GL_OUT_OF_MEMORY);
11900 }
11901}
11902
11903GLboolean __stdcall glIsTransformFeedback(GLuint id)
11904{
11905 EVENT("(GLuint id = %u)", id);
11906
11907 try
11908 {
11909 gl::Context *context = gl::getNonLostContext();
11910
11911 if (context)
11912 {
11913 if (context->getClientVersion() < 3)
11914 {
11915 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11916 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011917
Jamie Madill54133512013-06-21 09:33:07 -040011918 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011919 UNIMPLEMENTED();
11920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011921 }
11922 catch(std::bad_alloc&)
11923 {
11924 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11925 }
11926
11927 return GL_FALSE;
11928}
11929
11930void __stdcall glPauseTransformFeedback(void)
11931{
11932 EVENT("(void)");
11933
11934 try
11935 {
11936 gl::Context *context = gl::getNonLostContext();
11937
11938 if (context)
11939 {
11940 if (context->getClientVersion() < 3)
11941 {
11942 return gl::error(GL_INVALID_OPERATION);
11943 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011944
Jamie Madill54133512013-06-21 09:33:07 -040011945 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011946 UNIMPLEMENTED();
11947 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011948 }
11949 catch(std::bad_alloc&)
11950 {
11951 return gl::error(GL_OUT_OF_MEMORY);
11952 }
11953}
11954
11955void __stdcall glResumeTransformFeedback(void)
11956{
11957 EVENT("(void)");
11958
11959 try
11960 {
11961 gl::Context *context = gl::getNonLostContext();
11962
11963 if (context)
11964 {
11965 if (context->getClientVersion() < 3)
11966 {
11967 return gl::error(GL_INVALID_OPERATION);
11968 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011969
Jamie Madill54133512013-06-21 09:33:07 -040011970 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011971 UNIMPLEMENTED();
11972 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011973 }
11974 catch(std::bad_alloc&)
11975 {
11976 return gl::error(GL_OUT_OF_MEMORY);
11977 }
11978}
11979
11980void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11981{
11982 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11983 program, bufSize, length, binaryFormat, binary);
11984
11985 try
11986 {
11987 gl::Context *context = gl::getNonLostContext();
11988
11989 if (context)
11990 {
11991 if (context->getClientVersion() < 3)
11992 {
11993 return gl::error(GL_INVALID_OPERATION);
11994 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011995
Jamie Madill54133512013-06-21 09:33:07 -040011996 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011997 UNIMPLEMENTED();
11998 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011999 }
12000 catch(std::bad_alloc&)
12001 {
12002 return gl::error(GL_OUT_OF_MEMORY);
12003 }
12004}
12005
12006void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
12007{
12008 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
12009 program, binaryFormat, binary, length);
12010
12011 try
12012 {
12013 gl::Context *context = gl::getNonLostContext();
12014
12015 if (context)
12016 {
12017 if (context->getClientVersion() < 3)
12018 {
12019 return gl::error(GL_INVALID_OPERATION);
12020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012021
Jamie Madill54133512013-06-21 09:33:07 -040012022 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012023 UNIMPLEMENTED();
12024 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012025 }
12026 catch(std::bad_alloc&)
12027 {
12028 return gl::error(GL_OUT_OF_MEMORY);
12029 }
12030}
12031
12032void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
12033{
12034 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
12035 program, pname, value);
12036
12037 try
12038 {
12039 gl::Context *context = gl::getNonLostContext();
12040
12041 if (context)
12042 {
12043 if (context->getClientVersion() < 3)
12044 {
12045 return gl::error(GL_INVALID_OPERATION);
12046 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012047
Jamie Madill54133512013-06-21 09:33:07 -040012048 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012049 UNIMPLEMENTED();
12050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012051 }
12052 catch(std::bad_alloc&)
12053 {
12054 return gl::error(GL_OUT_OF_MEMORY);
12055 }
12056}
12057
12058void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
12059{
12060 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
12061 target, numAttachments, attachments);
12062
12063 try
12064 {
12065 gl::Context *context = gl::getNonLostContext();
12066
12067 if (context)
12068 {
12069 if (context->getClientVersion() < 3)
12070 {
12071 return gl::error(GL_INVALID_OPERATION);
12072 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012073
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000012074 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
12075 {
12076 return;
12077 }
12078
12079 int maxDimension = context->getMaximumRenderbufferDimension();
12080 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
12081 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012082 }
12083 catch(std::bad_alloc&)
12084 {
12085 return gl::error(GL_OUT_OF_MEMORY);
12086 }
12087}
12088
12089void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
12090{
12091 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
12092 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
12093 target, numAttachments, attachments, x, y, width, height);
12094
12095 try
12096 {
12097 gl::Context *context = gl::getNonLostContext();
12098
12099 if (context)
12100 {
12101 if (context->getClientVersion() < 3)
12102 {
12103 return gl::error(GL_INVALID_OPERATION);
12104 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012105
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000012106 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
12107 {
12108 return;
12109 }
12110
12111 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
12112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012113 }
12114 catch(std::bad_alloc&)
12115 {
12116 return gl::error(GL_OUT_OF_MEMORY);
12117 }
12118}
12119
12120void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
12121{
12122 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
12123 target, levels, internalformat, width, height);
12124
12125 try
12126 {
12127 gl::Context *context = gl::getNonLostContext();
12128
12129 if (context)
12130 {
12131 if (context->getClientVersion() < 3)
12132 {
12133 return gl::error(GL_INVALID_OPERATION);
12134 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012135
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000012136 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
12137 {
12138 return;
12139 }
12140
12141 switch (target)
12142 {
12143 case GL_TEXTURE_2D:
12144 {
12145 gl::Texture2D *texture2d = context->getTexture2D();
12146 texture2d->storage(levels, internalformat, width, height);
12147 }
12148 break;
12149
12150 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
12151 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
12152 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
12153 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
12154 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
12155 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
12156 {
12157 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
12158 textureCube->storage(levels, internalformat, width);
12159 }
12160 break;
12161
12162 default:
12163 return gl::error(GL_INVALID_ENUM);
12164 }
12165 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012166 }
12167 catch(std::bad_alloc&)
12168 {
12169 return gl::error(GL_OUT_OF_MEMORY);
12170 }
12171}
12172
12173void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
12174{
12175 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
12176 "GLsizei height = %d, GLsizei depth = %d)",
12177 target, levels, internalformat, width, height, depth);
12178
12179 try
12180 {
12181 gl::Context *context = gl::getNonLostContext();
12182
12183 if (context)
12184 {
12185 if (context->getClientVersion() < 3)
12186 {
12187 return gl::error(GL_INVALID_OPERATION);
12188 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000012189
12190 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
12191 {
12192 return;
12193 }
12194
12195 switch (target)
12196 {
12197 case GL_TEXTURE_3D:
12198 {
12199 gl::Texture3D *texture3d = context->getTexture3D();
12200 texture3d->storage(levels, internalformat, width, height, depth);
12201 }
12202 break;
12203
12204 case GL_TEXTURE_2D_ARRAY:
12205 {
12206 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
12207 texture2darray->storage(levels, internalformat, width, height, depth);
12208 }
12209 break;
12210
12211 default:
12212 return gl::error(GL_INVALID_ENUM);
12213 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000012214 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012215 }
12216 catch(std::bad_alloc&)
12217 {
12218 return gl::error(GL_OUT_OF_MEMORY);
12219 }
12220}
12221
12222void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
12223{
12224 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
12225 "GLint* params = 0x%0.8p)",
12226 target, internalformat, pname, bufSize, params);
12227
12228 try
12229 {
12230 gl::Context *context = gl::getNonLostContext();
12231
12232 if (context)
12233 {
12234 if (context->getClientVersion() < 3)
12235 {
12236 return gl::error(GL_INVALID_OPERATION);
12237 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012238
Shannon Woods809d2502013-07-08 10:32:18 -040012239 if (!gl::IsColorRenderingSupported(internalformat, context) &&
12240 !gl::IsDepthRenderingSupported(internalformat, context) &&
12241 !gl::IsStencilRenderingSupported(internalformat, context))
12242 {
12243 return gl::error(GL_INVALID_ENUM);
12244 }
12245
12246 if (target != GL_RENDERBUFFER)
12247 {
12248 return gl::error(GL_INVALID_ENUM);
12249 }
12250
12251 if (bufSize < 0)
12252 {
12253 return gl::error(GL_INVALID_VALUE);
12254 }
12255
12256 switch (pname)
12257 {
12258 case GL_NUM_SAMPLE_COUNTS:
12259 if (bufSize != 0)
12260 *params = context->getNumSampleCounts(internalformat);
12261 break;
12262 case GL_SAMPLES:
12263 context->getSampleCounts(internalformat, bufSize, params);
12264 break;
12265 default:
12266 return gl::error(GL_INVALID_ENUM);
12267 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012269 }
12270 catch(std::bad_alloc&)
12271 {
12272 return gl::error(GL_OUT_OF_MEMORY);
12273 }
12274}
12275
12276// Extension functions
12277
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012278void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
12279 GLbitfield mask, GLenum filter)
12280{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012281 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012282 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
12283 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
12284 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
12285
12286 try
12287 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012288 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012289
12290 if (context)
12291 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012292 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
12293 dstX0, dstY0, dstX1, dstY1, mask, filter,
12294 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012295 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012296 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012297 }
12298
Geoff Lang758d5b22013-06-11 11:42:50 -040012299 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
12300 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012301 }
12302 }
12303 catch(std::bad_alloc&)
12304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012305 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012306 }
12307}
12308
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012309void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
12310 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012311{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012312 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000012313 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012314 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012315 target, level, internalformat, width, height, depth, border, format, type, pixels);
12316
12317 try
12318 {
12319 UNIMPLEMENTED(); // FIXME
12320 }
12321 catch(std::bad_alloc&)
12322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012323 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012324 }
12325}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012326
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012327void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
12328 GLenum *binaryFormat, void *binary)
12329{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012330 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 +000012331 program, bufSize, length, binaryFormat, binary);
12332
12333 try
12334 {
12335 gl::Context *context = gl::getNonLostContext();
12336
12337 if (context)
12338 {
12339 gl::Program *programObject = context->getProgram(program);
12340
daniel@transgaming.com716056c2012-07-24 18:38:59 +000012341 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012342 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012343 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012344 }
12345
12346 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
12347
12348 if (!programBinary)
12349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012350 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012351 }
12352
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012353 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012354 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012355 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012356 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012357
12358 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012359 }
12360 }
12361 catch(std::bad_alloc&)
12362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012363 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012364 }
12365}
12366
12367void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
12368 const void *binary, GLint length)
12369{
12370 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
12371 program, binaryFormat, binary, length);
12372
12373 try
12374 {
12375 gl::Context *context = gl::getNonLostContext();
12376
12377 if (context)
12378 {
12379 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12380 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012381 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012382 }
12383
12384 gl::Program *programObject = context->getProgram(program);
12385
12386 if (!programObject)
12387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012388 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012389 }
12390
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012391 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012392 }
12393 }
12394 catch(std::bad_alloc&)
12395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012396 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012397 }
12398}
12399
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012400void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12401{
12402 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12403
12404 try
12405 {
12406 gl::Context *context = gl::getNonLostContext();
12407
12408 if (context)
12409 {
12410 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12411 {
12412 return gl::error(GL_INVALID_VALUE);
12413 }
12414
12415 if (context->getDrawFramebufferHandle() == 0)
12416 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012417 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012418 {
12419 return gl::error(GL_INVALID_OPERATION);
12420 }
12421
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012422 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012423 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012424 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012425 }
12426 }
12427 else
12428 {
12429 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12430 {
12431 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12432 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12433 {
12434 return gl::error(GL_INVALID_OPERATION);
12435 }
12436 }
12437 }
12438
12439 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12440
12441 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12442 {
12443 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12444 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012445
12446 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12447 {
12448 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12449 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012450 }
12451 }
12452 catch (std::bad_alloc&)
12453 {
12454 return gl::error(GL_OUT_OF_MEMORY);
12455 }
12456}
12457
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012458__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12459{
12460 struct Extension
12461 {
12462 const char *name;
12463 __eglMustCastToProperFunctionPointerType address;
12464 };
12465
12466 static const Extension glExtensions[] =
12467 {
12468 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012469 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012470 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012471 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12472 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12473 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12474 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12475 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12476 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12477 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012478 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012479 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012480 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12481 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12482 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12483 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012484 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12485 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12486 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12487 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12488 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12489 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12490 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012491 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012492 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12493 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12494 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012495 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12496 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012497
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012498 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012499 {
12500 if (strcmp(procname, glExtensions[ext].name) == 0)
12501 {
12502 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12503 }
12504 }
12505
12506 return NULL;
12507}
12508
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012509// Non-public functions used by EGL
12510
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012511bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012512{
12513 EVENT("(egl::Surface* surface = 0x%0.8p)",
12514 surface);
12515
12516 try
12517 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012518 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012519
12520 if (context)
12521 {
12522 gl::Texture2D *textureObject = context->getTexture2D();
12523
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012524 if (textureObject->isImmutable())
12525 {
12526 return false;
12527 }
12528
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012529 if (textureObject)
12530 {
12531 textureObject->bindTexImage(surface);
12532 }
12533 }
12534 }
12535 catch(std::bad_alloc&)
12536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012537 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012538 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012539
12540 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012541}
12542
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012543}