blob: 6753c3b7a13c543d45cd1b925a51518d6f337bcc [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
Geoff Lang4150b352013-08-05 14:14:43 -0400737 if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000738 {
739 return gl::error(GL_INVALID_OPERATION, false);
740 }
741 }
742
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000743 // Validate sub image parameters
744 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000745 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000746 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000747 {
748 return gl::error(GL_INVALID_OPERATION, false);
749 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000750
751 if (format != GL_NONE)
752 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000753 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000754 if (internalformat != textureInternalFormat)
755 {
756 return gl::error(GL_INVALID_OPERATION, false);
757 }
758 }
759
760 if (isCompressed)
761 {
762 if ((width % 4 != 0 && width != textureLevelWidth) ||
763 (height % 4 != 0 && height != textureLevelHeight))
764 {
765 return gl::error(GL_INVALID_OPERATION, false);
766 }
767 }
768
769 if (width == 0 || height == 0 || depth == 0)
770 {
771 return false;
772 }
773
774 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
775 {
776 return gl::error(GL_INVALID_VALUE, false);
777 }
778
779 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
780 std::numeric_limits<GLsizei>::max() - yoffset < height ||
781 std::numeric_limits<GLsizei>::max() - zoffset < depth)
782 {
783 return gl::error(GL_INVALID_VALUE, false);
784 }
785
786 if (xoffset + width > textureLevelWidth ||
787 yoffset + height > textureLevelHeight ||
788 zoffset + depth > textureLevelDepth)
789 {
790 return gl::error(GL_INVALID_VALUE, false);
791 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000792 }
793
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000794 return true;
795}
796
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000797
798bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
799 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
800 GLint border)
801{
Geoff Lang0fe19492013-07-25 17:04:31 -0400802 if (!gl::IsInternalTextureTarget(target, context->getClientVersion()))
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000803 {
804 return gl::error(GL_INVALID_ENUM, false);
805 }
806
807 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
808 {
809 return gl::error(GL_INVALID_VALUE, false);
810 }
811
812 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
813 {
814 return gl::error(GL_INVALID_VALUE, false);
815 }
816
817 if (width == 0 || height == 0)
818 {
819 return false;
820 }
821
822 // Verify zero border
823 if (border != 0)
824 {
825 return gl::error(GL_INVALID_VALUE, false);
826 }
827
828 // Validate dimensions based on Context limits and validate the texture
829 if (level > context->getMaximumTextureLevel())
830 {
831 return gl::error(GL_INVALID_VALUE, false);
832 }
833
834 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
835
836 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
837 {
838 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
839 }
840
841 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
842 {
843 return gl::error(GL_INVALID_OPERATION, false);
844 }
845
846 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
847 gl::Texture *texture = NULL;
848 GLenum textureFormat = GL_RGBA;
849
850 switch (target)
851 {
852 case GL_TEXTURE_2D:
853 {
854 if (width > (context->getMaximum2DTextureDimension() >> level) ||
855 height > (context->getMaximum2DTextureDimension() >> level))
856 {
857 return gl::error(GL_INVALID_VALUE, false);
858 }
859
860 gl::Texture2D *tex2d = context->getTexture2D();
861 if (tex2d)
862 {
863 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
864 {
865 return false; // error already registered by validateSubImageParams
866 }
867 texture = tex2d;
868 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
869 }
870 }
871 break;
872
873 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
874 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
875 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
876 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
879 {
880 if (!isSubImage && width != height)
881 {
882 return gl::error(GL_INVALID_VALUE, false);
883 }
884
885 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
886 height > (context->getMaximumCubeTextureDimension() >> level))
887 {
888 return gl::error(GL_INVALID_VALUE, false);
889 }
890
891 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
892 if (texcube)
893 {
894 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
895 {
896 return false; // error already registered by validateSubImageParams
897 }
898 texture = texcube;
899 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
900 }
901 }
902 break;
903
904 default:
905 return gl::error(GL_INVALID_ENUM, false);
906 }
907
908 if (!texture)
909 {
910 return gl::error(GL_INVALID_OPERATION, false);
911 }
912
913 if (texture->isImmutable() && !isSubImage)
914 {
915 return gl::error(GL_INVALID_OPERATION, false);
916 }
917
918
919 // [OpenGL ES 2.0.24] table 3.9
920 if (isSubImage)
921 {
922 switch (textureFormat)
923 {
924 case GL_ALPHA:
925 if (colorbufferFormat != GL_ALPHA8_EXT &&
926 colorbufferFormat != GL_RGBA4 &&
927 colorbufferFormat != GL_RGB5_A1 &&
928 colorbufferFormat != GL_RGBA8_OES)
929 {
930 return gl::error(GL_INVALID_OPERATION, false);
931 }
932 break;
933 case GL_LUMINANCE:
934 case GL_RGB:
935 if (colorbufferFormat != GL_RGB565 &&
936 colorbufferFormat != GL_RGB8_OES &&
937 colorbufferFormat != GL_RGBA4 &&
938 colorbufferFormat != GL_RGB5_A1 &&
939 colorbufferFormat != GL_RGBA8_OES)
940 {
941 return gl::error(GL_INVALID_OPERATION, false);
942 }
943 break;
944 case GL_LUMINANCE_ALPHA:
945 case GL_RGBA:
946 if (colorbufferFormat != GL_RGBA4 &&
947 colorbufferFormat != GL_RGB5_A1 &&
948 colorbufferFormat != GL_RGBA8_OES)
949 {
950 return gl::error(GL_INVALID_OPERATION, false);
951 }
952 break;
953 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
954 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
956 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
957 return gl::error(GL_INVALID_OPERATION, false);
958 case GL_DEPTH_COMPONENT:
959 case GL_DEPTH_STENCIL_OES:
960 return gl::error(GL_INVALID_OPERATION, false);
961 default:
962 return gl::error(GL_INVALID_OPERATION, false);
963 }
964 }
965 else
966 {
967 switch (internalformat)
968 {
969 case GL_ALPHA:
970 if (colorbufferFormat != GL_ALPHA8_EXT &&
971 colorbufferFormat != GL_RGBA4 &&
972 colorbufferFormat != GL_RGB5_A1 &&
973 colorbufferFormat != GL_BGRA8_EXT &&
974 colorbufferFormat != GL_RGBA8_OES)
975 {
976 return gl::error(GL_INVALID_OPERATION, false);
977 }
978 break;
979 case GL_LUMINANCE:
980 case GL_RGB:
981 if (colorbufferFormat != GL_RGB565 &&
982 colorbufferFormat != GL_RGB8_OES &&
983 colorbufferFormat != GL_RGBA4 &&
984 colorbufferFormat != GL_RGB5_A1 &&
985 colorbufferFormat != GL_BGRA8_EXT &&
986 colorbufferFormat != GL_RGBA8_OES)
987 {
988 return gl::error(GL_INVALID_OPERATION, false);
989 }
990 break;
991 case GL_LUMINANCE_ALPHA:
992 case GL_RGBA:
993 if (colorbufferFormat != GL_RGBA4 &&
994 colorbufferFormat != GL_RGB5_A1 &&
995 colorbufferFormat != GL_BGRA8_EXT &&
996 colorbufferFormat != GL_RGBA8_OES)
997 {
998 return gl::error(GL_INVALID_OPERATION, false);
999 }
1000 break;
1001 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1002 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1003 if (context->supportsDXT1Textures())
1004 {
1005 return gl::error(GL_INVALID_OPERATION, false);
1006 }
1007 else
1008 {
1009 return gl::error(GL_INVALID_ENUM, false);
1010 }
1011 break;
1012 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1013 if (context->supportsDXT3Textures())
1014 {
1015 return gl::error(GL_INVALID_OPERATION, false);
1016 }
1017 else
1018 {
1019 return gl::error(GL_INVALID_ENUM, false);
1020 }
1021 break;
1022 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1023 if (context->supportsDXT5Textures())
1024 {
1025 return gl::error(GL_INVALID_OPERATION, false);
1026 }
1027 else
1028 {
1029 return gl::error(GL_INVALID_ENUM, false);
1030 }
1031 break;
1032 case GL_DEPTH_COMPONENT:
1033 case GL_DEPTH_COMPONENT16:
1034 case GL_DEPTH_COMPONENT32_OES:
1035 case GL_DEPTH_STENCIL_OES:
1036 case GL_DEPTH24_STENCIL8_OES:
1037 if (context->supportsDepthTextures())
1038 {
1039 return gl::error(GL_INVALID_OPERATION, false);
1040 }
1041 else
1042 {
1043 return gl::error(GL_INVALID_ENUM, false);
1044 }
1045 default:
1046 return gl::error(GL_INVALID_ENUM, false);
1047 }
1048 }
1049
1050 return true;
1051}
1052
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001053bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1054 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1055 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001056{
1057 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001058 {
1059 return gl::error(GL_INVALID_VALUE, false);
1060 }
1061
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001062 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1063 {
1064 return gl::error(GL_INVALID_VALUE, false);
1065 }
1066
1067 if (width == 0 || height == 0)
1068 {
1069 return false;
1070 }
1071
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001072 if (border != 0)
1073 {
1074 return gl::error(GL_INVALID_VALUE, false);
1075 }
1076
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001077 if (level > context->getMaximumTextureLevel())
1078 {
1079 return gl::error(GL_INVALID_VALUE, false);
1080 }
1081
1082 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1083
1084 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1085 {
1086 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1087 }
1088
1089 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1090 {
1091 return gl::error(GL_INVALID_OPERATION, false);
1092 }
1093
1094 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001095 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001096 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001097 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001098 bool textureCompressed = false;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001099 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001100 GLint textureLevelWidth = 0;
1101 GLint textureLevelHeight = 0;
1102 GLint textureLevelDepth = 0;
1103 switch (target)
1104 {
1105 case GL_TEXTURE_2D:
1106 {
1107 gl::Texture2D *texture2d = context->getTexture2D();
1108 if (texture2d)
1109 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001110 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001111 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001112 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001113 textureLevelWidth = texture2d->getWidth(level);
1114 textureLevelHeight = texture2d->getHeight(level);
1115 textureLevelDepth = 1;
1116 texture = texture2d;
1117 }
1118 }
1119 break;
1120
1121 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1122 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1124 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1126 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1127 {
1128 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1129 if (textureCube)
1130 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001131 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001132 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001133 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001134 textureLevelWidth = textureCube->getWidth(target, level);
1135 textureLevelHeight = textureCube->getHeight(target, level);
1136 textureLevelDepth = 1;
1137 texture = textureCube;
1138 }
1139 }
1140 break;
1141
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001142 case GL_TEXTURE_2D_ARRAY:
1143 {
1144 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1145 if (texture2dArray)
1146 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001147 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001148 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001149 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001150 textureLevelWidth = texture2dArray->getWidth(level);
1151 textureLevelHeight = texture2dArray->getHeight(level);
1152 textureLevelDepth = texture2dArray->getDepth(level);
1153 texture = texture2dArray;
1154 }
1155 }
1156 break;
1157
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001158 case GL_TEXTURE_3D:
1159 {
1160 gl::Texture3D *texture3d = context->getTexture3D();
1161 if (texture3d)
1162 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001163 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001164 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001165 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001166 textureLevelWidth = texture3d->getWidth(level);
1167 textureLevelHeight = texture3d->getHeight(level);
1168 textureLevelDepth = texture3d->getDepth(level);
1169 texture = texture3d;
1170 }
1171 }
1172 break;
1173
1174 default:
1175 return gl::error(GL_INVALID_ENUM, false);
1176 }
1177
1178 if (!texture)
1179 {
1180 return gl::error(GL_INVALID_OPERATION, false);
1181 }
1182
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001183 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001184 {
1185 return gl::error(GL_INVALID_OPERATION, false);
1186 }
1187
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001188 if (textureIsDepth)
1189 {
1190 return gl::error(GL_INVALID_OPERATION, false);
1191 }
1192
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001193 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001194 {
1195 if ((width % 4 != 0 && width != textureLevelWidth) ||
1196 (height % 4 != 0 && height != textureLevelHeight))
1197 {
1198 return gl::error(GL_INVALID_OPERATION, false);
1199 }
1200 }
1201
Geoff Langa4d13322013-06-05 14:57:51 -04001202 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001203 {
Geoff Langa4d13322013-06-05 14:57:51 -04001204 if (xoffset + width > textureLevelWidth ||
1205 yoffset + height > textureLevelHeight ||
1206 zoffset >= textureLevelDepth)
1207 {
1208 return gl::error(GL_INVALID_VALUE, false);
1209 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001210
Geoff Langa4d13322013-06-05 14:57:51 -04001211 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1212 context->getClientVersion()))
1213 {
1214 return gl::error(GL_INVALID_OPERATION, false);
1215 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001216 }
1217
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001218 return true;
1219}
1220
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001221bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1222 GLsizei width, GLsizei height)
1223{
1224 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1225 {
1226 return gl::error(GL_INVALID_ENUM, false);
1227 }
1228
1229 if (width < 1 || height < 1 || levels < 1)
1230 {
1231 return gl::error(GL_INVALID_VALUE, false);
1232 }
1233
1234 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1235 {
1236 return gl::error(GL_INVALID_VALUE, false);
1237 }
1238
1239 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1240 {
1241 return gl::error(GL_INVALID_OPERATION, false);
1242 }
1243
1244 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1245 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1246
1247 if (format == GL_NONE || type == GL_NONE)
1248 {
1249 return gl::error(GL_INVALID_ENUM, false);
1250 }
1251
1252 switch (target)
1253 {
1254 case GL_TEXTURE_2D:
1255 if (width > context->getMaximum2DTextureDimension() ||
1256 height > context->getMaximum2DTextureDimension())
1257 {
1258 return gl::error(GL_INVALID_VALUE, false);
1259 }
1260 break;
1261 case GL_TEXTURE_CUBE_MAP:
1262 if (width > context->getMaximumCubeTextureDimension() ||
1263 height > context->getMaximumCubeTextureDimension())
1264 {
1265 return gl::error(GL_INVALID_VALUE, false);
1266 }
1267 break;
1268 default:
1269 return gl::error(GL_INVALID_ENUM, false);
1270 }
1271
1272 if (levels != 1 && !context->supportsNonPower2Texture())
1273 {
1274 if (!gl::isPow2(width) || !gl::isPow2(height))
1275 {
1276 return gl::error(GL_INVALID_OPERATION, false);
1277 }
1278 }
1279
1280 switch (internalformat)
1281 {
1282 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1283 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1284 if (!context->supportsDXT1Textures())
1285 {
1286 return gl::error(GL_INVALID_ENUM, false);
1287 }
1288 break;
1289 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1290 if (!context->supportsDXT3Textures())
1291 {
1292 return gl::error(GL_INVALID_ENUM, false);
1293 }
1294 break;
1295 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1296 if (!context->supportsDXT5Textures())
1297 {
1298 return gl::error(GL_INVALID_ENUM, false);
1299 }
1300 break;
1301 case GL_RGBA32F_EXT:
1302 case GL_RGB32F_EXT:
1303 case GL_ALPHA32F_EXT:
1304 case GL_LUMINANCE32F_EXT:
1305 case GL_LUMINANCE_ALPHA32F_EXT:
1306 if (!context->supportsFloat32Textures())
1307 {
1308 return gl::error(GL_INVALID_ENUM, false);
1309 }
1310 break;
1311 case GL_RGBA16F_EXT:
1312 case GL_RGB16F_EXT:
1313 case GL_ALPHA16F_EXT:
1314 case GL_LUMINANCE16F_EXT:
1315 case GL_LUMINANCE_ALPHA16F_EXT:
1316 if (!context->supportsFloat16Textures())
1317 {
1318 return gl::error(GL_INVALID_ENUM, false);
1319 }
1320 break;
1321 case GL_DEPTH_COMPONENT16:
1322 case GL_DEPTH_COMPONENT32_OES:
1323 case GL_DEPTH24_STENCIL8_OES:
1324 if (!context->supportsDepthTextures())
1325 {
1326 return gl::error(GL_INVALID_ENUM, false);
1327 }
1328 if (target != GL_TEXTURE_2D)
1329 {
1330 return gl::error(GL_INVALID_OPERATION, false);
1331 }
1332 // ANGLE_depth_texture only supports 1-level textures
1333 if (levels != 1)
1334 {
1335 return gl::error(GL_INVALID_OPERATION, false);
1336 }
1337 break;
1338 default:
1339 break;
1340 }
1341
1342 gl::Texture *texture = NULL;
1343 switch(target)
1344 {
1345 case GL_TEXTURE_2D:
1346 texture = context->getTexture2D();
1347 break;
1348 case GL_TEXTURE_CUBE_MAP:
1349 texture = context->getTextureCubeMap();
1350 break;
1351 default:
1352 UNREACHABLE();
1353 }
1354
1355 if (!texture || texture->id() == 0)
1356 {
1357 return gl::error(GL_INVALID_OPERATION, false);
1358 }
1359
1360 if (texture->isImmutable())
1361 {
1362 return gl::error(GL_INVALID_OPERATION, false);
1363 }
1364
1365 return true;
1366}
1367
1368bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1369 GLsizei width, GLsizei height, GLsizei depth)
1370{
1371 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1372 {
1373 return gl::error(GL_INVALID_VALUE, false);
1374 }
1375
1376 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1377 {
1378 return gl::error(GL_INVALID_OPERATION, false);
1379 }
1380
1381 gl::Texture *texture = NULL;
1382 switch (target)
1383 {
1384 case GL_TEXTURE_2D:
1385 {
1386 texture = context->getTexture2D();
1387
1388 if (width > (context->getMaximum2DTextureDimension()) ||
1389 height > (context->getMaximum2DTextureDimension()))
1390 {
1391 return gl::error(GL_INVALID_VALUE, false);
1392 }
1393 }
1394 break;
1395
1396 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1397 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1399 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1401 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1402 {
1403 texture = context->getTextureCubeMap();
1404
1405 if (width != height)
1406 {
1407 return gl::error(GL_INVALID_VALUE, false);
1408 }
1409
1410 if (width > (context->getMaximumCubeTextureDimension()))
1411 {
1412 return gl::error(GL_INVALID_VALUE, false);
1413 }
1414 }
1415 break;
1416
1417 case GL_TEXTURE_3D:
1418 {
1419 texture = context->getTexture3D();
1420
1421 if (width > (context->getMaximum3DTextureDimension()) ||
1422 height > (context->getMaximum3DTextureDimension()) ||
1423 depth > (context->getMaximum3DTextureDimension()))
1424 {
1425 return gl::error(GL_INVALID_VALUE, false);
1426 }
1427 }
1428 break;
1429
1430 case GL_TEXTURE_2D_ARRAY:
1431 {
1432 texture = context->getTexture2DArray();
1433
1434 if (width > (context->getMaximum2DTextureDimension()) ||
1435 height > (context->getMaximum2DTextureDimension()) ||
1436 depth > (context->getMaximum2DArrayTextureLayers()))
1437 {
1438 return gl::error(GL_INVALID_VALUE, false);
1439 }
1440 }
1441 break;
1442
1443 default:
1444 return gl::error(GL_INVALID_ENUM, false);
1445 }
1446
1447 if (!texture || texture->id() == 0)
1448 {
1449 return gl::error(GL_INVALID_OPERATION, false);
1450 }
1451
1452 if (texture->isImmutable())
1453 {
1454 return gl::error(GL_INVALID_OPERATION, false);
1455 }
1456
1457 if (!gl::IsValidInternalFormat(internalformat, context))
1458 {
1459 return gl::error(GL_INVALID_ENUM, false);
1460 }
1461
1462 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1463 {
1464 return gl::error(GL_INVALID_ENUM, false);
1465 }
1466
1467 return true;
1468}
1469
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001470bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1471 GLenum internalformat, GLsizei width, GLsizei height,
1472 bool angleExtension)
1473{
1474 switch (target)
1475 {
1476 case GL_RENDERBUFFER:
1477 break;
1478 default:
1479 return gl::error(GL_INVALID_ENUM, false);
1480 }
1481
1482 if (width < 0 || height < 0 || samples < 0)
1483 {
1484 return gl::error(GL_INVALID_VALUE, false);
1485 }
1486
1487 if (!gl::IsValidInternalFormat(internalformat, context))
1488 {
1489 return gl::error(GL_INVALID_ENUM, false);
1490 }
1491
1492 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1493 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1494 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1495 // internal format must be sized and not an integer format if samples is greater than zero.
1496 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1497 {
1498 return gl::error(GL_INVALID_ENUM, false);
1499 }
1500
1501 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1502 {
1503 return gl::error(GL_INVALID_OPERATION, false);
1504 }
1505
1506 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1507 !gl::IsDepthRenderingSupported(internalformat, context) &&
1508 !gl::IsStencilRenderingSupported(internalformat, context))
1509 {
1510 return gl::error(GL_INVALID_ENUM, false);
1511 }
1512
1513 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1514 {
1515 return gl::error(GL_INVALID_VALUE, false);
1516 }
1517
1518 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1519 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1520 // states that samples must be less than or equal to the maximum samples for the specified
1521 // internal format.
1522 if (angleExtension)
1523 {
1524 if (samples > context->getMaxSupportedSamples())
1525 {
1526 return gl::error(GL_INVALID_VALUE, false);
1527 }
1528 }
1529 else
1530 {
1531 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1532 {
1533 return gl::error(GL_INVALID_VALUE, false);
1534 }
1535 }
1536
1537 GLuint handle = context->getRenderbufferHandle();
1538 if (handle == 0)
1539 {
1540 return gl::error(GL_INVALID_OPERATION, false);
1541 }
1542
1543 return true;
1544}
1545
Geoff Lang3ed0c482013-07-25 17:03:18 -04001546bool validateES2FramebufferTextureParameters(gl::Context *context, GLenum target, GLenum attachment,
1547 GLenum textarget, GLuint texture, GLint level)
1548{
1549 META_ASSERT(GL_DRAW_FRAMEBUFFER == GL_DRAW_FRAMEBUFFER_ANGLE && GL_READ_FRAMEBUFFER == GL_READ_FRAMEBUFFER_ANGLE);
1550
1551 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER)
1552 {
1553 return gl::error(GL_INVALID_ENUM, false);
1554 }
1555
1556 if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15)
1557 {
1558 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0);
1559 if (colorAttachment >= context->getMaximumRenderTargets())
1560 {
1561 return gl::error(GL_INVALID_VALUE, false);
1562 }
1563 }
1564 else
1565 {
1566 switch (attachment)
1567 {
1568 case GL_DEPTH_ATTACHMENT:
1569 case GL_STENCIL_ATTACHMENT:
1570 break;
1571 default:
1572 return gl::error(GL_INVALID_ENUM, false);
1573 }
1574 }
1575
1576 if (texture != 0)
1577 {
1578 gl::Texture *tex = context->getTexture(texture);
1579
1580 if (tex == NULL)
1581 {
1582 return gl::error(GL_INVALID_OPERATION, false);
1583 }
1584
1585 switch (textarget)
1586 {
1587 case GL_TEXTURE_2D:
1588 {
1589 if (tex->getTarget() != GL_TEXTURE_2D)
1590 {
1591 return gl::error(GL_INVALID_OPERATION, false);
1592 }
1593 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1594 if (tex2d->isCompressed(level))
1595 {
1596 return gl::error(GL_INVALID_OPERATION, false);
1597 }
1598 break;
1599 }
1600
1601 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1602 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1603 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1604 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1605 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1606 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1607 {
1608 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1609 {
1610 return gl::error(GL_INVALID_OPERATION, false);
1611 }
1612 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1613 if (texcube->isCompressed(textarget, level))
1614 {
1615 return gl::error(GL_INVALID_OPERATION, false);
1616 }
1617 break;
1618 }
1619
1620 default:
1621 return gl::error(GL_INVALID_ENUM, false);
1622 }
1623
1624 if (level != 0)
1625 {
1626 return gl::error(GL_INVALID_VALUE, false);
1627 }
1628 }
1629
1630 gl::Framebuffer *framebuffer = NULL;
1631 GLuint framebufferHandle = 0;
1632 if (target == GL_READ_FRAMEBUFFER)
1633 {
1634 framebuffer = context->getReadFramebuffer();
1635 framebufferHandle = context->getReadFramebufferHandle();
1636 }
1637 else
1638 {
1639 framebuffer = context->getDrawFramebuffer();
1640 framebufferHandle = context->getDrawFramebufferHandle();
1641 }
1642
1643 if (framebufferHandle == 0 || !framebuffer)
1644 {
1645 return gl::error(GL_INVALID_OPERATION, false);
1646 }
1647
1648 return true;
1649}
1650
1651bool validateES3FramebufferTextureParameters(gl::Context *context, GLenum target, GLenum attachment,
1652 GLenum textarget, GLuint texture, GLint level, GLint layer,
1653 bool layerCall)
1654{
1655 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER)
1656 {
1657 return gl::error(GL_INVALID_ENUM, false);
1658 }
1659
1660 if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15)
1661 {
1662 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0);
1663 if (colorAttachment >= context->getMaximumRenderTargets())
1664 {
1665 return gl::error(GL_INVALID_VALUE, false);
1666 }
1667 }
1668 else
1669 {
1670 switch (attachment)
1671 {
1672 case GL_DEPTH_ATTACHMENT:
1673 case GL_STENCIL_ATTACHMENT:
1674 case GL_DEPTH_STENCIL_ATTACHMENT:
1675 break;
1676 default:
1677 return gl::error(GL_INVALID_ENUM, false);
1678 }
1679 }
1680
1681 if (texture != 0)
1682 {
1683 gl::Texture *tex = context->getTexture(texture);
1684
1685 if (tex == NULL)
1686 {
1687 return gl::error(GL_INVALID_OPERATION, false);
1688 }
1689
1690 if (level < 0)
1691 {
1692 return gl::error(GL_INVALID_VALUE, false);
1693 }
1694
1695 if (layer < 0)
1696 {
1697 return gl::error(GL_INVALID_VALUE, false);
1698 }
1699
1700 if (!layerCall)
1701 {
1702 switch (textarget)
1703 {
1704 case GL_TEXTURE_2D:
1705 {
1706 if (level > gl::log2(context->getMaximum2DTextureDimension()))
1707 {
1708 return gl::error(GL_INVALID_VALUE, false);
1709 }
1710 if (tex->getTarget() != GL_TEXTURE_2D)
1711 {
1712 return gl::error(GL_INVALID_OPERATION, false);
1713 }
1714 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1715 if (tex2d->isCompressed(level))
1716 {
1717 return gl::error(GL_INVALID_OPERATION, false);
1718 }
1719 break;
1720 }
1721
1722 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1723 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1724 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1725 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1726 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1727 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1728 {
1729 if (level > gl::log2(context->getMaximumCubeTextureDimension()))
1730 {
1731 return gl::error(GL_INVALID_VALUE, false);
1732 }
1733 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1734 {
1735 return gl::error(GL_INVALID_OPERATION, false);
1736 }
1737 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1738 if (texcube->isCompressed(textarget, level))
1739 {
1740 return gl::error(GL_INVALID_OPERATION, false);
1741 }
1742 break;
1743 }
1744
1745 default:
1746 return gl::error(GL_INVALID_ENUM, false);
1747 }
1748 }
1749 else
1750 {
1751 switch (tex->getTarget())
1752 {
1753 case GL_TEXTURE_2D_ARRAY:
1754 {
1755 if (level > gl::log2(context->getMaximum2DTextureDimension()))
1756 {
1757 return gl::error(GL_INVALID_VALUE, false);
1758 }
1759
1760 if (layer >= context->getMaximum2DArrayTextureLayers())
1761 {
1762 return gl::error(GL_INVALID_VALUE, false);
1763 }
1764
1765 gl::Texture2DArray *texArray = static_cast<gl::Texture2DArray *>(tex);
1766 if (texArray->isCompressed(level))
1767 {
1768 return gl::error(GL_INVALID_OPERATION, false);
1769 }
1770
1771 break;
1772 }
1773
1774 case GL_TEXTURE_3D:
1775 {
1776 if (level > gl::log2(context->getMaximum3DTextureDimension()))
1777 {
1778 return gl::error(GL_INVALID_VALUE, false);
1779 }
1780
1781 if (layer >= context->getMaximum3DTextureDimension())
1782 {
1783 return gl::error(GL_INVALID_VALUE, false);
1784 }
1785
1786 gl::Texture3D *tex3d = static_cast<gl::Texture3D *>(tex);
1787 if (tex3d->isCompressed(level))
1788 {
1789 return gl::error(GL_INVALID_OPERATION, false);
1790 }
1791
1792 break;
1793 }
1794
1795 default:
1796 return gl::error(GL_INVALID_OPERATION, false);
1797 }
1798 }
1799 }
1800
1801 gl::Framebuffer *framebuffer = NULL;
1802 GLuint framebufferHandle = 0;
1803 if (target == GL_READ_FRAMEBUFFER)
1804 {
1805 framebuffer = context->getReadFramebuffer();
1806 framebufferHandle = context->getReadFramebufferHandle();
1807 }
1808 else
1809 {
1810 framebuffer = context->getDrawFramebuffer();
1811 framebufferHandle = context->getDrawFramebufferHandle();
1812 }
1813
1814 if (framebufferHandle == 0 || !framebuffer)
1815 {
1816 return gl::error(GL_INVALID_OPERATION, false);
1817 }
1818
1819 return true;
1820}
1821
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001822// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001823bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001824{
1825 switch (format)
1826 {
1827 case GL_RGBA:
1828 switch (type)
1829 {
1830 case GL_UNSIGNED_BYTE:
1831 break;
1832 default:
1833 return false;
1834 }
1835 break;
1836 case GL_BGRA_EXT:
1837 switch (type)
1838 {
1839 case GL_UNSIGNED_BYTE:
1840 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1841 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1842 break;
1843 default:
1844 return false;
1845 }
1846 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001847 default:
1848 return false;
1849 }
1850 return true;
1851}
1852
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001853bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1854{
1855 switch (format)
1856 {
1857 case GL_RGBA:
1858 switch (type)
1859 {
1860 case GL_UNSIGNED_BYTE:
1861 break;
1862 case GL_UNSIGNED_INT_2_10_10_10_REV:
1863 if (internalFormat != GL_RGB10_A2)
1864 {
1865 return false;
1866 }
1867 break;
1868 default:
1869 return false;
1870 }
1871 break;
1872 case GL_RGBA_INTEGER:
1873 switch (type)
1874 {
1875 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001876 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1877 {
1878 return false;
1879 }
1880 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001881 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001882 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1883 {
1884 return false;
1885 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001886 break;
1887 default:
1888 return false;
1889 }
1890 break;
1891 case GL_BGRA_EXT:
1892 switch (type)
1893 {
1894 case GL_UNSIGNED_BYTE:
1895 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1896 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1897 break;
1898 default:
1899 return false;
1900 }
1901 break;
1902 default:
1903 return false;
1904 }
1905 return true;
1906}
1907
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001908bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1909 const GLenum* attachments)
1910{
1911 bool defaultFramebuffer = false;
1912
1913 switch (target)
1914 {
1915 case GL_DRAW_FRAMEBUFFER:
1916 case GL_FRAMEBUFFER:
1917 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1918 break;
1919 case GL_READ_FRAMEBUFFER:
1920 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1921 break;
1922 default:
1923 return gl::error(GL_INVALID_ENUM, false);
1924 }
1925
1926 for (int i = 0; i < numAttachments; ++i)
1927 {
1928 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1929 {
1930 if (defaultFramebuffer)
1931 {
1932 return gl::error(GL_INVALID_ENUM, false);
1933 }
1934
1935 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1936 {
1937 return gl::error(GL_INVALID_OPERATION, false);
1938 }
1939 }
1940 else
1941 {
1942 switch (attachments[i])
1943 {
1944 case GL_DEPTH_ATTACHMENT:
1945 case GL_STENCIL_ATTACHMENT:
1946 case GL_DEPTH_STENCIL_ATTACHMENT:
1947 if (defaultFramebuffer)
1948 {
1949 return gl::error(GL_INVALID_ENUM, false);
1950 }
1951 break;
1952 case GL_COLOR:
1953 case GL_DEPTH:
1954 case GL_STENCIL:
1955 if (!defaultFramebuffer)
1956 {
1957 return gl::error(GL_INVALID_ENUM, false);
1958 }
1959 break;
1960 default:
1961 return gl::error(GL_INVALID_ENUM, false);
1962 }
1963 }
1964 }
1965
1966 return true;
1967}
1968
Geoff Lang758d5b22013-06-11 11:42:50 -04001969bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1970 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1971 GLenum filter, bool fromAngleExtension)
1972{
1973 switch (filter)
1974 {
1975 case GL_NEAREST:
1976 break;
1977 case GL_LINEAR:
1978 if (fromAngleExtension)
1979 {
1980 return gl::error(GL_INVALID_ENUM, false);
1981 }
1982 break;
1983 default:
1984 return gl::error(GL_INVALID_ENUM, false);
1985 }
1986
1987 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1988 {
1989 return gl::error(GL_INVALID_VALUE, false);
1990 }
1991
1992 if (mask == 0)
1993 {
1994 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1995 // buffers are copied.
1996 return false;
1997 }
1998
1999 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
2000 {
2001 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
2002 return gl::error(GL_INVALID_OPERATION, false);
2003 }
2004
2005 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
2006 // color buffer, leaving only nearest being unfiltered from above
2007 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
2008 {
2009 return gl::error(GL_INVALID_OPERATION, false);
2010 }
2011
2012 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
2013 {
2014 if (fromAngleExtension)
2015 {
2016 ERR("Blits with the same source and destination framebuffer are not supported by this "
2017 "implementation.");
2018 }
2019 return gl::error(GL_INVALID_OPERATION, false);
2020 }
2021
2022 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
2023 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
2024 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
2025 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
2026 {
2027 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
2028 }
2029
2030 if (drawFramebuffer->getSamples() != 0)
2031 {
2032 return gl::error(GL_INVALID_OPERATION, false);
2033 }
2034
2035 gl::Rectangle sourceClippedRect, destClippedRect;
2036 bool partialCopy;
2037 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
2038 &sourceClippedRect, &destClippedRect, &partialCopy))
2039 {
2040 return gl::error(GL_INVALID_OPERATION, false);
2041 }
2042
2043 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
2044
2045 GLuint clientVersion = context->getClientVersion();
2046
2047 if (mask & GL_COLOR_BUFFER_BIT)
2048 {
2049 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
2050 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
2051
2052 if (readColorBuffer && drawColorBuffer)
2053 {
2054 GLint readInternalFormat = readColorBuffer->getActualFormat();
2055 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
2056
2057 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
2058 {
2059 if (drawFramebuffer->isEnabledColorAttachment(i))
2060 {
2061 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
2062
2063 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
2064 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
2065 {
2066 return gl::error(GL_INVALID_OPERATION, false);
2067 }
2068
2069 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
2070 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
2071 {
2072 return gl::error(GL_INVALID_OPERATION, false);
2073 }
2074
2075 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
2076 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
2077 {
2078 return gl::error(GL_INVALID_OPERATION, false);
2079 }
2080
2081 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
2082 {
2083 return gl::error(GL_INVALID_OPERATION, false);
2084 }
2085 }
2086 }
2087
2088 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
2089 {
2090 return gl::error(GL_INVALID_OPERATION, false);
2091 }
2092
2093 if (fromAngleExtension)
2094 {
2095 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
2096 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
2097 {
2098 return gl::error(GL_INVALID_OPERATION, false);
2099 }
2100
2101 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
2102 {
2103 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
2104 {
2105 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
2106 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
2107 {
2108 return gl::error(GL_INVALID_OPERATION, false);
2109 }
2110
2111 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
2112 {
2113 return gl::error(GL_INVALID_OPERATION, false);
2114 }
2115 }
2116 }
2117
2118 if (partialCopy && readFramebuffer->getSamples() != 0)
2119 {
2120 return gl::error(GL_INVALID_OPERATION, false);
2121 }
2122 }
2123 }
2124 }
2125
2126 if (mask & GL_DEPTH_BUFFER_BIT)
2127 {
2128 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
2129 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
2130
2131 if (readDepthBuffer && drawDepthBuffer)
2132 {
2133 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
2134 {
2135 return gl::error(GL_INVALID_OPERATION, false);
2136 }
2137
2138 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
2139 {
2140 return gl::error(GL_INVALID_OPERATION, false);
2141 }
2142
2143 if (fromAngleExtension)
2144 {
2145 if (partialCopy)
2146 {
2147 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2148 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2149 }
2150
2151 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
2152 {
2153 return gl::error(GL_INVALID_OPERATION, false);
2154 }
2155 }
2156 }
2157 }
2158
2159 if (mask & GL_STENCIL_BUFFER_BIT)
2160 {
2161 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
2162 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
2163
2164 if (fromAngleExtension && partialCopy)
2165 {
2166 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2167 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2168 }
2169
2170 if (readStencilBuffer && drawStencilBuffer)
2171 {
2172 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
2173 {
2174 return gl::error(GL_INVALID_OPERATION, false);
2175 }
2176
2177 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
2178 {
2179 return gl::error(GL_INVALID_OPERATION, false);
2180 }
2181
2182 if (fromAngleExtension)
2183 {
2184 if (partialCopy)
2185 {
2186 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
2187 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
2188 }
2189
2190 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
2191 {
2192 return gl::error(GL_INVALID_OPERATION, false);
2193 }
2194 }
2195 }
2196 }
2197
2198 return true;
2199}
2200
Jamie Madillaff71502013-07-02 11:57:05 -04002201bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
2202{
2203 switch (pname)
2204 {
2205 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
2206 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
2207 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
2208 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
2209 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
2210 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2211 case GL_CURRENT_VERTEX_ATTRIB:
2212 return true;
2213
2214 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
2215 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
2216 // the same constant.
2217 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
2218 return true;
2219
Jamie Madill30855b32013-07-02 11:57:06 -04002220 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
2221 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
2222
Jamie Madillaff71502013-07-02 11:57:05 -04002223 default:
2224 return gl::error(GL_INVALID_ENUM, false);
2225 }
2226}
2227
Jamie Madill478fdb22013-07-19 16:36:59 -04002228bool validateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
2229{
2230 switch (pname)
2231 {
2232 case GL_TEXTURE_WRAP_R:
2233 case GL_TEXTURE_SWIZZLE_R:
2234 case GL_TEXTURE_SWIZZLE_G:
2235 case GL_TEXTURE_SWIZZLE_B:
2236 case GL_TEXTURE_SWIZZLE_A:
2237 case GL_TEXTURE_BASE_LEVEL:
2238 case GL_TEXTURE_MAX_LEVEL:
2239 case GL_TEXTURE_COMPARE_MODE:
2240 case GL_TEXTURE_COMPARE_FUNC:
2241 case GL_TEXTURE_MIN_LOD:
2242 case GL_TEXTURE_MAX_LOD:
2243 if (context->getClientVersion() < 3)
2244 {
2245 return gl::error(GL_INVALID_ENUM, false);
2246 }
2247 break;
2248
2249 default: break;
2250 }
2251
2252 switch (pname)
2253 {
2254 case GL_TEXTURE_WRAP_S:
2255 case GL_TEXTURE_WRAP_T:
2256 case GL_TEXTURE_WRAP_R:
2257 switch (param)
2258 {
2259 case GL_REPEAT:
2260 case GL_CLAMP_TO_EDGE:
2261 case GL_MIRRORED_REPEAT:
2262 return true;
2263 default:
2264 return gl::error(GL_INVALID_ENUM, false);
2265 }
2266
2267 case GL_TEXTURE_MIN_FILTER:
2268 switch (param)
2269 {
2270 case GL_NEAREST:
2271 case GL_LINEAR:
2272 case GL_NEAREST_MIPMAP_NEAREST:
2273 case GL_LINEAR_MIPMAP_NEAREST:
2274 case GL_NEAREST_MIPMAP_LINEAR:
2275 case GL_LINEAR_MIPMAP_LINEAR:
2276 return true;
2277 default:
2278 return gl::error(GL_INVALID_ENUM, false);
2279 }
2280 break;
2281
2282 case GL_TEXTURE_MAG_FILTER:
2283 switch (param)
2284 {
2285 case GL_NEAREST:
2286 case GL_LINEAR:
2287 return true;
2288 default:
2289 return gl::error(GL_INVALID_ENUM, false);
2290 }
2291 break;
2292
2293 case GL_TEXTURE_USAGE_ANGLE:
2294 switch (param)
2295 {
2296 case GL_NONE:
2297 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
2298 return true;
2299 default:
2300 return gl::error(GL_INVALID_ENUM, false);
2301 }
2302 break;
2303
2304 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2305 if (!context->supportsTextureFilterAnisotropy())
2306 {
2307 return gl::error(GL_INVALID_ENUM, false);
2308 }
2309
2310 // we assume the parameter passed to this validation method is truncated, not rounded
2311 if (param < 1)
2312 {
2313 return gl::error(GL_INVALID_VALUE, false);
2314 }
2315 return true;
2316
2317 case GL_TEXTURE_MIN_LOD:
2318 case GL_TEXTURE_MAX_LOD:
2319 // any value is permissible
2320 return true;
2321
2322 case GL_TEXTURE_COMPARE_MODE:
2323 switch (param)
2324 {
2325 case GL_NONE:
2326 case GL_COMPARE_REF_TO_TEXTURE:
2327 return true;
2328 default:
2329 return gl::error(GL_INVALID_ENUM, false);
2330 }
2331 break;
2332
2333 case GL_TEXTURE_COMPARE_FUNC:
2334 switch (param)
2335 {
2336 case GL_LEQUAL:
2337 case GL_GEQUAL:
2338 case GL_LESS:
2339 case GL_GREATER:
2340 case GL_EQUAL:
2341 case GL_NOTEQUAL:
2342 case GL_ALWAYS:
2343 case GL_NEVER:
2344 return true;
2345 default:
2346 return gl::error(GL_INVALID_ENUM, false);
2347 }
2348 break;
2349
2350 case GL_TEXTURE_SWIZZLE_R:
2351 case GL_TEXTURE_SWIZZLE_G:
2352 case GL_TEXTURE_SWIZZLE_B:
2353 case GL_TEXTURE_SWIZZLE_A:
2354 case GL_TEXTURE_BASE_LEVEL:
2355 case GL_TEXTURE_MAX_LEVEL:
2356 UNIMPLEMENTED();
2357 return true;
2358
2359 default:
2360 return gl::error(GL_INVALID_ENUM, false);
2361 }
2362}
2363
2364
Jamie Madillfb8a8302013-07-03 14:24:12 -04002365gl::Texture *getTargetTexture(gl::Context *context, GLenum target)
2366{
2367 if (context->getClientVersion() < 3)
2368 {
2369 if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
2370 {
2371 return NULL;
2372 }
2373 }
2374
2375 switch (target)
2376 {
2377 case GL_TEXTURE_2D: return context->getTexture2D();
2378 case GL_TEXTURE_CUBE_MAP: return context->getTextureCubeMap();
2379 case GL_TEXTURE_3D: return context->getTexture3D();
2380 case GL_TEXTURE_2D_ARRAY: return context->getTexture2DArray();
2381 default: return NULL;
2382 }
2383}
Jamie Madill478fdb22013-07-19 16:36:59 -04002384
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04002385bool validateSamplerObjectParameter(GLenum pname)
2386{
2387 switch (pname)
2388 {
2389 case GL_TEXTURE_MIN_FILTER:
2390 case GL_TEXTURE_MAG_FILTER:
2391 case GL_TEXTURE_WRAP_S:
2392 case GL_TEXTURE_WRAP_T:
2393 case GL_TEXTURE_WRAP_R:
2394 case GL_TEXTURE_MIN_LOD:
2395 case GL_TEXTURE_MAX_LOD:
2396 case GL_TEXTURE_COMPARE_MODE:
2397 case GL_TEXTURE_COMPARE_FUNC:
2398 return true;
2399
2400 default:
2401 return gl::error(GL_INVALID_ENUM, false);
2402 }
2403}
2404
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002405extern "C"
2406{
2407
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002408// OpenGL ES 2.0 functions
2409
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002410void __stdcall glActiveTexture(GLenum texture)
2411{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002412 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002413
2414 try
2415 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002416 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417
2418 if (context)
2419 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002420 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002422 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002423 }
2424
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002425 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002426 }
2427 }
2428 catch(std::bad_alloc&)
2429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002430 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002431 }
2432}
2433
2434void __stdcall glAttachShader(GLuint program, GLuint shader)
2435{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002436 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002437
2438 try
2439 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002440 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441
2442 if (context)
2443 {
2444 gl::Program *programObject = context->getProgram(program);
2445 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002446
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002447 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002448 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002449 if (context->getShader(program))
2450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002451 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002452 }
2453 else
2454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002455 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002456 }
2457 }
2458
2459 if (!shaderObject)
2460 {
2461 if (context->getProgram(shader))
2462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002463 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002464 }
2465 else
2466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002467 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002468 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 }
2470
2471 if (!programObject->attachShader(shaderObject))
2472 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002473 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002474 }
2475 }
2476 }
2477 catch(std::bad_alloc&)
2478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002479 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480 }
2481}
2482
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002483void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2484{
2485 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2486
2487 try
2488 {
2489 switch (target)
2490 {
2491 case GL_ANY_SAMPLES_PASSED_EXT:
2492 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2493 break;
2494 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002495 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002496 }
2497
2498 if (id == 0)
2499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002500 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002501 }
2502
2503 gl::Context *context = gl::getNonLostContext();
2504
2505 if (context)
2506 {
2507 context->beginQuery(target, id);
2508 }
2509 }
2510 catch(std::bad_alloc&)
2511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002512 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002513 }
2514}
2515
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002516void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002517{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002518 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002519
2520 try
2521 {
2522 if (index >= gl::MAX_VERTEX_ATTRIBS)
2523 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002524 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002525 }
2526
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002527 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528
2529 if (context)
2530 {
2531 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002532
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002533 if (!programObject)
2534 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002535 if (context->getShader(program))
2536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002537 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002538 }
2539 else
2540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002541 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002542 }
2543 }
2544
2545 if (strncmp(name, "gl_", 3) == 0)
2546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002547 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 }
2549
2550 programObject->bindAttributeLocation(index, name);
2551 }
2552 }
2553 catch(std::bad_alloc&)
2554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002555 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002556 }
2557}
2558
2559void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2560{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002561 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002562
2563 try
2564 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002565 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002566
2567 if (context)
2568 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002569 // Check ES3 specific targets
2570 switch (target)
2571 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002572 case GL_COPY_READ_BUFFER:
2573 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002574 case GL_PIXEL_PACK_BUFFER:
2575 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002576 case GL_UNIFORM_BUFFER:
2577 case GL_TRANSFORM_FEEDBACK_BUFFER:
2578 if (context->getClientVersion() < 3)
2579 {
2580 return gl::error(GL_INVALID_ENUM);
2581 }
2582 }
2583
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002584 switch (target)
2585 {
2586 case GL_ARRAY_BUFFER:
2587 context->bindArrayBuffer(buffer);
2588 return;
2589 case GL_ELEMENT_ARRAY_BUFFER:
2590 context->bindElementArrayBuffer(buffer);
2591 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002592 case GL_COPY_READ_BUFFER:
2593 context->bindCopyReadBuffer(buffer);
2594 return;
2595 case GL_COPY_WRITE_BUFFER:
2596 context->bindCopyWriteBuffer(buffer);
2597 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002598 case GL_PIXEL_PACK_BUFFER:
2599 context->bindPixelPackBuffer(buffer);
2600 return;
2601 case GL_PIXEL_UNPACK_BUFFER:
2602 context->bindPixelUnpackBuffer(buffer);
2603 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002604 case GL_UNIFORM_BUFFER:
2605 context->bindGenericUniformBuffer(buffer);
2606 return;
2607 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002608 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002609 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002610 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002611 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002612 }
2613 }
2614 }
2615 catch(std::bad_alloc&)
2616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002617 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002618 }
2619}
2620
2621void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2622{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002623 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002624
2625 try
2626 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002627 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002629 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002630 }
2631
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002632 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002633
2634 if (context)
2635 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002636 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2637 {
2638 context->bindReadFramebuffer(framebuffer);
2639 }
2640
2641 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2642 {
2643 context->bindDrawFramebuffer(framebuffer);
2644 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002645 }
2646 }
2647 catch(std::bad_alloc&)
2648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002649 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002650 }
2651}
2652
2653void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2654{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002655 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002656
2657 try
2658 {
2659 if (target != GL_RENDERBUFFER)
2660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002661 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002662 }
2663
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002664 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665
2666 if (context)
2667 {
2668 context->bindRenderbuffer(renderbuffer);
2669 }
2670 }
2671 catch(std::bad_alloc&)
2672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002673 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674 }
2675}
2676
2677void __stdcall glBindTexture(GLenum target, GLuint texture)
2678{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002679 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002680
2681 try
2682 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002683 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002684
2685 if (context)
2686 {
2687 gl::Texture *textureObject = context->getTexture(texture);
2688
2689 if (textureObject && textureObject->getTarget() != target && texture != 0)
2690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002692 }
2693
2694 switch (target)
2695 {
2696 case GL_TEXTURE_2D:
2697 context->bindTexture2D(texture);
2698 return;
2699 case GL_TEXTURE_CUBE_MAP:
2700 context->bindTextureCubeMap(texture);
2701 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002702 case GL_TEXTURE_3D:
2703 if (context->getClientVersion() < 3)
2704 {
2705 return gl::error(GL_INVALID_ENUM);
2706 }
2707 context->bindTexture3D(texture);
2708 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002709 case GL_TEXTURE_2D_ARRAY:
2710 if (context->getClientVersion() < 3)
2711 {
2712 return gl::error(GL_INVALID_ENUM);
2713 }
2714 context->bindTexture2DArray(texture);
2715 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002716 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002717 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002718 }
2719 }
2720 }
2721 catch(std::bad_alloc&)
2722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002723 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002724 }
2725}
2726
2727void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002729 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002730 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002731
2732 try
2733 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002734 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002735
2736 if (context)
2737 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002738 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002739 }
2740 }
2741 catch(std::bad_alloc&)
2742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002743 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002744 }
2745}
2746
2747void __stdcall glBlendEquation(GLenum mode)
2748{
2749 glBlendEquationSeparate(mode, mode);
2750}
2751
2752void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002754 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755
2756 try
2757 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002758 gl::Context *context = gl::getNonLostContext();
2759
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002760 switch (modeRGB)
2761 {
2762 case GL_FUNC_ADD:
2763 case GL_FUNC_SUBTRACT:
2764 case GL_FUNC_REVERSE_SUBTRACT:
2765 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002766
2767 case GL_MIN:
2768 case GL_MAX:
2769 if (context && context->getClientVersion() < 3)
2770 {
2771 return gl::error(GL_INVALID_ENUM);
2772 }
2773 break;
2774
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002775 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002776 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777 }
2778
2779 switch (modeAlpha)
2780 {
2781 case GL_FUNC_ADD:
2782 case GL_FUNC_SUBTRACT:
2783 case GL_FUNC_REVERSE_SUBTRACT:
2784 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002785
2786 case GL_MIN:
2787 case GL_MAX:
2788 if (context && context->getClientVersion() < 3)
2789 {
2790 return gl::error(GL_INVALID_ENUM);
2791 }
2792 break;
2793
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002794 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002795 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002796 }
2797
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002798 if (context)
2799 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002800 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002801 }
2802 }
2803 catch(std::bad_alloc&)
2804 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002805 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002806 }
2807}
2808
2809void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2810{
2811 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2812}
2813
2814void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2815{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002816 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 +00002817 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002818
2819 try
2820 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002821 gl::Context *context = gl::getNonLostContext();
2822
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002823 switch (srcRGB)
2824 {
2825 case GL_ZERO:
2826 case GL_ONE:
2827 case GL_SRC_COLOR:
2828 case GL_ONE_MINUS_SRC_COLOR:
2829 case GL_DST_COLOR:
2830 case GL_ONE_MINUS_DST_COLOR:
2831 case GL_SRC_ALPHA:
2832 case GL_ONE_MINUS_SRC_ALPHA:
2833 case GL_DST_ALPHA:
2834 case GL_ONE_MINUS_DST_ALPHA:
2835 case GL_CONSTANT_COLOR:
2836 case GL_ONE_MINUS_CONSTANT_COLOR:
2837 case GL_CONSTANT_ALPHA:
2838 case GL_ONE_MINUS_CONSTANT_ALPHA:
2839 case GL_SRC_ALPHA_SATURATE:
2840 break;
2841 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002842 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843 }
2844
2845 switch (dstRGB)
2846 {
2847 case GL_ZERO:
2848 case GL_ONE:
2849 case GL_SRC_COLOR:
2850 case GL_ONE_MINUS_SRC_COLOR:
2851 case GL_DST_COLOR:
2852 case GL_ONE_MINUS_DST_COLOR:
2853 case GL_SRC_ALPHA:
2854 case GL_ONE_MINUS_SRC_ALPHA:
2855 case GL_DST_ALPHA:
2856 case GL_ONE_MINUS_DST_ALPHA:
2857 case GL_CONSTANT_COLOR:
2858 case GL_ONE_MINUS_CONSTANT_COLOR:
2859 case GL_CONSTANT_ALPHA:
2860 case GL_ONE_MINUS_CONSTANT_ALPHA:
2861 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002862
2863 case GL_SRC_ALPHA_SATURATE:
2864 if (!context || context->getClientVersion() < 3)
2865 {
2866 return gl::error(GL_INVALID_ENUM);
2867 }
2868 break;
2869
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002870 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002871 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002872 }
2873
2874 switch (srcAlpha)
2875 {
2876 case GL_ZERO:
2877 case GL_ONE:
2878 case GL_SRC_COLOR:
2879 case GL_ONE_MINUS_SRC_COLOR:
2880 case GL_DST_COLOR:
2881 case GL_ONE_MINUS_DST_COLOR:
2882 case GL_SRC_ALPHA:
2883 case GL_ONE_MINUS_SRC_ALPHA:
2884 case GL_DST_ALPHA:
2885 case GL_ONE_MINUS_DST_ALPHA:
2886 case GL_CONSTANT_COLOR:
2887 case GL_ONE_MINUS_CONSTANT_COLOR:
2888 case GL_CONSTANT_ALPHA:
2889 case GL_ONE_MINUS_CONSTANT_ALPHA:
2890 case GL_SRC_ALPHA_SATURATE:
2891 break;
2892 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002893 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002894 }
2895
2896 switch (dstAlpha)
2897 {
2898 case GL_ZERO:
2899 case GL_ONE:
2900 case GL_SRC_COLOR:
2901 case GL_ONE_MINUS_SRC_COLOR:
2902 case GL_DST_COLOR:
2903 case GL_ONE_MINUS_DST_COLOR:
2904 case GL_SRC_ALPHA:
2905 case GL_ONE_MINUS_SRC_ALPHA:
2906 case GL_DST_ALPHA:
2907 case GL_ONE_MINUS_DST_ALPHA:
2908 case GL_CONSTANT_COLOR:
2909 case GL_ONE_MINUS_CONSTANT_COLOR:
2910 case GL_CONSTANT_ALPHA:
2911 case GL_ONE_MINUS_CONSTANT_ALPHA:
2912 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002913
2914 case GL_SRC_ALPHA_SATURATE:
2915 if (!context || context->getClientVersion() < 3)
2916 {
2917 return gl::error(GL_INVALID_ENUM);
2918 }
2919 break;
2920
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002921 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002922 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002923 }
2924
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002925 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2926 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2927
2928 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2929 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2930
2931 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002932 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002933 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 +00002934 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002935 }
2936
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002937 if (context)
2938 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002939 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002940 }
2941 }
2942 catch(std::bad_alloc&)
2943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002944 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002945 }
2946}
2947
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002948void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002949{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002950 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 +00002951 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002952
2953 try
2954 {
2955 if (size < 0)
2956 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002957 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002958 }
2959
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002960 gl::Context *context = gl::getNonLostContext();
2961
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002962 switch (usage)
2963 {
2964 case GL_STREAM_DRAW:
2965 case GL_STATIC_DRAW:
2966 case GL_DYNAMIC_DRAW:
2967 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002968
2969 case GL_STREAM_READ:
2970 case GL_STREAM_COPY:
2971 case GL_STATIC_READ:
2972 case GL_STATIC_COPY:
2973 case GL_DYNAMIC_READ:
2974 case GL_DYNAMIC_COPY:
2975 if (context && context->getClientVersion() < 3)
2976 {
2977 return gl::error(GL_INVALID_ENUM);
2978 }
2979 break;
2980
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002981 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002982 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002983 }
2984
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002985 if (context)
2986 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002987 // Check ES3 specific targets
2988 switch (target)
2989 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002990 case GL_COPY_READ_BUFFER:
2991 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002992 case GL_PIXEL_PACK_BUFFER:
2993 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002994 case GL_UNIFORM_BUFFER:
2995 case GL_TRANSFORM_FEEDBACK_BUFFER:
2996 if (context->getClientVersion() < 3)
2997 {
2998 return gl::error(GL_INVALID_ENUM);
2999 }
3000 }
3001
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003002 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003003
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003004 switch (target)
3005 {
3006 case GL_ARRAY_BUFFER:
3007 buffer = context->getArrayBuffer();
3008 break;
3009 case GL_ELEMENT_ARRAY_BUFFER:
3010 buffer = context->getElementArrayBuffer();
3011 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003012 case GL_COPY_READ_BUFFER:
3013 buffer = context->getCopyReadBuffer();
3014 break;
3015 case GL_COPY_WRITE_BUFFER:
3016 buffer = context->getCopyWriteBuffer();
3017 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003018 case GL_PIXEL_PACK_BUFFER:
3019 buffer = context->getPixelPackBuffer();
3020 break;
3021 case GL_PIXEL_UNPACK_BUFFER:
3022 buffer = context->getPixelUnpackBuffer();
3023 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003024 case GL_TRANSFORM_FEEDBACK_BUFFER:
3025 buffer = context->getGenericTransformFeedbackBuffer();
3026 break;
3027 case GL_UNIFORM_BUFFER:
3028 buffer = context->getGenericUniformBuffer();
3029 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003030 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003032 }
3033
3034 if (!buffer)
3035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003036 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003037 }
3038
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003039 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003040 }
3041 }
3042 catch(std::bad_alloc&)
3043 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003044 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003045 }
3046}
3047
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003048void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003049{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003050 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 +00003051 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003052
3053 try
3054 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003055 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003057 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003058 }
3059
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00003060 if (data == NULL)
3061 {
3062 return;
3063 }
3064
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003065 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003066
3067 if (context)
3068 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003069 // Check ES3 specific targets
3070 switch (target)
3071 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003072 case GL_COPY_READ_BUFFER:
3073 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003074 case GL_PIXEL_PACK_BUFFER:
3075 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003076 case GL_UNIFORM_BUFFER:
3077 case GL_TRANSFORM_FEEDBACK_BUFFER:
3078 if (context->getClientVersion() < 3)
3079 {
3080 return gl::error(GL_INVALID_ENUM);
3081 }
3082 }
3083
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003084 gl::Buffer *buffer;
3085
3086 switch (target)
3087 {
3088 case GL_ARRAY_BUFFER:
3089 buffer = context->getArrayBuffer();
3090 break;
3091 case GL_ELEMENT_ARRAY_BUFFER:
3092 buffer = context->getElementArrayBuffer();
3093 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00003094 case GL_COPY_READ_BUFFER:
3095 buffer = context->getCopyReadBuffer();
3096 break;
3097 case GL_COPY_WRITE_BUFFER:
3098 buffer = context->getCopyWriteBuffer();
3099 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00003100 case GL_PIXEL_PACK_BUFFER:
3101 buffer = context->getPixelPackBuffer();
3102 break;
3103 case GL_PIXEL_UNPACK_BUFFER:
3104 buffer = context->getPixelUnpackBuffer();
3105 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00003106 case GL_TRANSFORM_FEEDBACK_BUFFER:
3107 buffer = context->getGenericTransformFeedbackBuffer();
3108 break;
3109 case GL_UNIFORM_BUFFER:
3110 buffer = context->getGenericUniformBuffer();
3111 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003112 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003113 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003114 }
3115
3116 if (!buffer)
3117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003118 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003119 }
3120
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003121 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003122 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003123 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003124 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00003125
3126 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003127 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003128 }
3129 catch(std::bad_alloc&)
3130 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003131 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003132 }
3133}
3134
3135GLenum __stdcall glCheckFramebufferStatus(GLenum target)
3136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003137 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003138
3139 try
3140 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003141 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003143 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003144 }
3145
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003146 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003147
3148 if (context)
3149 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003150 gl::Framebuffer *framebuffer = NULL;
3151 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3152 {
3153 framebuffer = context->getReadFramebuffer();
3154 }
3155 else
3156 {
3157 framebuffer = context->getDrawFramebuffer();
3158 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003159
3160 return framebuffer->completeness();
3161 }
3162 }
3163 catch(std::bad_alloc&)
3164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003165 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003166 }
3167
3168 return 0;
3169}
3170
3171void __stdcall glClear(GLbitfield mask)
3172{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003173 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003174
3175 try
3176 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003177 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003178
3179 if (context)
3180 {
3181 context->clear(mask);
3182 }
3183 }
3184 catch(std::bad_alloc&)
3185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003186 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003187 }
3188}
3189
3190void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
3191{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003192 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003193 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003194
3195 try
3196 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003197 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003198
3199 if (context)
3200 {
3201 context->setClearColor(red, green, blue, alpha);
3202 }
3203 }
3204 catch(std::bad_alloc&)
3205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003206 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003207 }
3208}
3209
3210void __stdcall glClearDepthf(GLclampf depth)
3211{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003212 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003213
3214 try
3215 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003216 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003217
3218 if (context)
3219 {
3220 context->setClearDepth(depth);
3221 }
3222 }
3223 catch(std::bad_alloc&)
3224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003225 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003226 }
3227}
3228
3229void __stdcall glClearStencil(GLint s)
3230{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003231 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232
3233 try
3234 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003235 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003236
3237 if (context)
3238 {
3239 context->setClearStencil(s);
3240 }
3241 }
3242 catch(std::bad_alloc&)
3243 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003244 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003245 }
3246}
3247
3248void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3249{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003250 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003251 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003252
3253 try
3254 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003255 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003256
3257 if (context)
3258 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00003259 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003260 }
3261 }
3262 catch(std::bad_alloc&)
3263 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003264 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003265 }
3266}
3267
3268void __stdcall glCompileShader(GLuint shader)
3269{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003270 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003271
3272 try
3273 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003274 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003275
3276 if (context)
3277 {
3278 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003279
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003280 if (!shaderObject)
3281 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003282 if (context->getProgram(shader))
3283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003284 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003285 }
3286 else
3287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003288 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003289 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003290 }
3291
3292 shaderObject->compile();
3293 }
3294 }
3295 catch(std::bad_alloc&)
3296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003297 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003298 }
3299}
3300
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003301void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
3302 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003303{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003304 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003305 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003306 target, level, internalformat, width, height, border, imageSize, data);
3307
3308 try
3309 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003311
3312 if (context)
3313 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003314 if (context->getClientVersion() < 3 &&
3315 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3316 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3317 {
3318 return;
3319 }
3320
3321 if (context->getClientVersion() >= 3 &&
3322 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3323 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3324 {
3325 return;
3326 }
3327
3328 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003330 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003331 }
3332
3333 switch (target)
3334 {
3335 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003336 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003337 gl::Texture2D *texture = context->getTexture2D();
3338 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003339 }
3340 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003341
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003342 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3343 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3344 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3345 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3346 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3347 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003348 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003349 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3350 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003351 }
3352 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003353
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003354 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003355 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003356 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003357 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003358 }
3359 catch(std::bad_alloc&)
3360 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003361 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003362 }
3363}
3364
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003365void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3366 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003368 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003369 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003370 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003371 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3372
3373 try
3374 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003375 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003376
3377 if (context)
3378 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003379 if (context->getClientVersion() < 3 &&
3380 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3381 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3382 {
3383 return;
3384 }
3385
3386 if (context->getClientVersion() >= 3 &&
3387 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3388 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3389 {
3390 return;
3391 }
3392
3393 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003395 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003396 }
3397
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003398 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003399 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003400 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003401 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003402 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003403 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003404 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003405 break;
3406
3407 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3408 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3409 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3410 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3411 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3412 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003413 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003414 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003415 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003416 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003417 break;
3418
3419 default:
3420 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003421 }
3422 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 }
3424 catch(std::bad_alloc&)
3425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003426 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427 }
3428}
3429
3430void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3431{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003432 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003433 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003434 target, level, internalformat, x, y, width, height, border);
3435
3436 try
3437 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003438 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003439
3440 if (context)
3441 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003442 if (context->getClientVersion() < 3 &&
3443 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3444 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003445 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003446 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003447 }
3448
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003449 if (context->getClientVersion() >= 3 &&
3450 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3451 0, 0, 0, x, y, width, height, border))
3452 {
3453 return;
3454 }
3455
3456 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3457
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003458 switch (target)
3459 {
3460 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003461 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003462 gl::Texture2D *texture = context->getTexture2D();
3463 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003464 }
3465 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003466
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003467 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3468 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3469 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3470 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3471 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3472 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003473 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003474 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3475 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003476 }
3477 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003478
3479 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003480 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003481 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003482 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003483 }
3484 catch(std::bad_alloc&)
3485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003487 }
3488}
3489
3490void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003492 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003493 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494 target, level, xoffset, yoffset, x, y, width, height);
3495
3496 try
3497 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003498 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003499
3500 if (context)
3501 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003502 if (context->getClientVersion() < 3 &&
3503 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3504 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003505 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003506 return;
3507 }
3508
3509 if (context->getClientVersion() >= 3 &&
3510 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3511 xoffset, yoffset, 0, x, y, width, height, 0))
3512 {
3513 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003514 }
3515
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003516 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003517
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003518 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003519 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003520 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003521 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003522 gl::Texture2D *texture = context->getTexture2D();
3523 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003524 }
3525 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003526
3527 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3528 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3529 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3530 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3531 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003533 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003534 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3535 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003536 }
3537 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003538
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003539 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003540 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003541 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003542 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003543 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003544
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003545 catch(std::bad_alloc&)
3546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003547 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003548 }
3549}
3550
3551GLuint __stdcall glCreateProgram(void)
3552{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003553 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003554
3555 try
3556 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003557 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003558
3559 if (context)
3560 {
3561 return context->createProgram();
3562 }
3563 }
3564 catch(std::bad_alloc&)
3565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003566 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003567 }
3568
3569 return 0;
3570}
3571
3572GLuint __stdcall glCreateShader(GLenum type)
3573{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003574 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003575
3576 try
3577 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003578 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003579
3580 if (context)
3581 {
3582 switch (type)
3583 {
3584 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003585 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003586 return context->createShader(type);
3587 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003588 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589 }
3590 }
3591 }
3592 catch(std::bad_alloc&)
3593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003594 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003595 }
3596
3597 return 0;
3598}
3599
3600void __stdcall glCullFace(GLenum mode)
3601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003602 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003603
3604 try
3605 {
3606 switch (mode)
3607 {
3608 case GL_FRONT:
3609 case GL_BACK:
3610 case GL_FRONT_AND_BACK:
3611 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003612 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003613
3614 if (context)
3615 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003616 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617 }
3618 }
3619 break;
3620 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003621 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003622 }
3623 }
3624 catch(std::bad_alloc&)
3625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003626 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003627 }
3628}
3629
3630void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003632 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003633
3634 try
3635 {
3636 if (n < 0)
3637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003638 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003639 }
3640
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003641 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003642
3643 if (context)
3644 {
3645 for (int i = 0; i < n; i++)
3646 {
3647 context->deleteBuffer(buffers[i]);
3648 }
3649 }
3650 }
3651 catch(std::bad_alloc&)
3652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003653 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654 }
3655}
3656
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003657void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3658{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003659 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003660
3661 try
3662 {
3663 if (n < 0)
3664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003665 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003666 }
3667
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003668 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003669
3670 if (context)
3671 {
3672 for (int i = 0; i < n; i++)
3673 {
Jamie Madill33dc8432013-07-26 11:55:05 -04003674 context->deleteFenceNV(fences[i]);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003675 }
3676 }
3677 }
3678 catch(std::bad_alloc&)
3679 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003680 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003681 }
3682}
3683
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003684void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3685{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003686 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003687
3688 try
3689 {
3690 if (n < 0)
3691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003692 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003693 }
3694
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003695 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003696
3697 if (context)
3698 {
3699 for (int i = 0; i < n; i++)
3700 {
3701 if (framebuffers[i] != 0)
3702 {
3703 context->deleteFramebuffer(framebuffers[i]);
3704 }
3705 }
3706 }
3707 }
3708 catch(std::bad_alloc&)
3709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003710 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003711 }
3712}
3713
3714void __stdcall glDeleteProgram(GLuint program)
3715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003716 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003717
3718 try
3719 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003720 if (program == 0)
3721 {
3722 return;
3723 }
3724
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003725 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003726
3727 if (context)
3728 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003729 if (!context->getProgram(program))
3730 {
3731 if(context->getShader(program))
3732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003733 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003734 }
3735 else
3736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003737 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003738 }
3739 }
3740
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003741 context->deleteProgram(program);
3742 }
3743 }
3744 catch(std::bad_alloc&)
3745 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003746 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003747 }
3748}
3749
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003750void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3751{
3752 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3753
3754 try
3755 {
3756 if (n < 0)
3757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003758 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003759 }
3760
3761 gl::Context *context = gl::getNonLostContext();
3762
3763 if (context)
3764 {
3765 for (int i = 0; i < n; i++)
3766 {
3767 context->deleteQuery(ids[i]);
3768 }
3769 }
3770 }
3771 catch(std::bad_alloc&)
3772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003773 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003774 }
3775}
3776
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003777void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3778{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003779 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003780
3781 try
3782 {
3783 if (n < 0)
3784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003785 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003786 }
3787
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003788 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789
3790 if (context)
3791 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003792 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003793 {
3794 context->deleteRenderbuffer(renderbuffers[i]);
3795 }
3796 }
3797 }
3798 catch(std::bad_alloc&)
3799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003800 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003801 }
3802}
3803
3804void __stdcall glDeleteShader(GLuint shader)
3805{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003806 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003807
3808 try
3809 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003810 if (shader == 0)
3811 {
3812 return;
3813 }
3814
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003815 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003816
3817 if (context)
3818 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003819 if (!context->getShader(shader))
3820 {
3821 if(context->getProgram(shader))
3822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003823 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003824 }
3825 else
3826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003827 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003828 }
3829 }
3830
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003831 context->deleteShader(shader);
3832 }
3833 }
3834 catch(std::bad_alloc&)
3835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003836 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003837 }
3838}
3839
3840void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003842 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843
3844 try
3845 {
3846 if (n < 0)
3847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003849 }
3850
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003851 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003852
3853 if (context)
3854 {
3855 for (int i = 0; i < n; i++)
3856 {
3857 if (textures[i] != 0)
3858 {
3859 context->deleteTexture(textures[i]);
3860 }
3861 }
3862 }
3863 }
3864 catch(std::bad_alloc&)
3865 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003866 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003867 }
3868}
3869
3870void __stdcall glDepthFunc(GLenum func)
3871{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003872 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003873
3874 try
3875 {
3876 switch (func)
3877 {
3878 case GL_NEVER:
3879 case GL_ALWAYS:
3880 case GL_LESS:
3881 case GL_LEQUAL:
3882 case GL_EQUAL:
3883 case GL_GREATER:
3884 case GL_GEQUAL:
3885 case GL_NOTEQUAL:
3886 break;
3887 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003888 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003889 }
3890
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003891 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003892
3893 if (context)
3894 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003895 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003896 }
3897 }
3898 catch(std::bad_alloc&)
3899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003900 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003901 }
3902}
3903
3904void __stdcall glDepthMask(GLboolean flag)
3905{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003906 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003907
3908 try
3909 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003911
3912 if (context)
3913 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003914 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003915 }
3916 }
3917 catch(std::bad_alloc&)
3918 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003919 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920 }
3921}
3922
3923void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3924{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003925 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003926
3927 try
3928 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003929 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003930
3931 if (context)
3932 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003933 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003934 }
3935 }
3936 catch(std::bad_alloc&)
3937 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003938 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003939 }
3940}
3941
3942void __stdcall glDetachShader(GLuint program, GLuint shader)
3943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003944 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003945
3946 try
3947 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003948 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003949
3950 if (context)
3951 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003952
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953 gl::Program *programObject = context->getProgram(program);
3954 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003955
3956 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003958 gl::Shader *shaderByProgramHandle;
3959 shaderByProgramHandle = context->getShader(program);
3960 if (!shaderByProgramHandle)
3961 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003962 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003963 }
3964 else
3965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003966 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003967 }
3968 }
3969
3970 if (!shaderObject)
3971 {
3972 gl::Program *programByShaderHandle = context->getProgram(shader);
3973 if (!programByShaderHandle)
3974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003975 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003976 }
3977 else
3978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003979 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003980 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003981 }
3982
3983 if (!programObject->detachShader(shaderObject))
3984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003985 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003986 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003987 }
3988 }
3989 catch(std::bad_alloc&)
3990 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003991 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003992 }
3993}
3994
3995void __stdcall glDisable(GLenum cap)
3996{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003997 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003998
3999 try
4000 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004001 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004002
4003 if (context)
4004 {
4005 switch (cap)
4006 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004007 case GL_CULL_FACE: context->setCullFace(false); break;
4008 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
4009 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
4010 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
4011 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
4012 case GL_STENCIL_TEST: context->setStencilTest(false); break;
4013 case GL_DEPTH_TEST: context->setDepthTest(false); break;
4014 case GL_BLEND: context->setBlend(false); break;
4015 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00004016
4017 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
4018 case GL_RASTERIZER_DISCARD:
4019 if (context->getClientVersion() < 3)
4020 {
4021 return gl::error(GL_INVALID_ENUM);
4022 }
4023 UNIMPLEMENTED();
4024 break;
4025
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004026 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004027 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004028 }
4029 }
4030 }
4031 catch(std::bad_alloc&)
4032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004033 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004034 }
4035}
4036
4037void __stdcall glDisableVertexAttribArray(GLuint index)
4038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004039 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004040
4041 try
4042 {
4043 if (index >= gl::MAX_VERTEX_ATTRIBS)
4044 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004045 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004048 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004049
4050 if (context)
4051 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004052 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004053 }
4054 }
4055 catch(std::bad_alloc&)
4056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004058 }
4059}
4060
4061void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
4062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004063 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004064
4065 try
4066 {
4067 if (count < 0 || first < 0)
4068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004072 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004073
4074 if (context)
4075 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004076 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077 }
4078 }
4079 catch(std::bad_alloc&)
4080 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004081 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 }
4083}
4084
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004085void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
4086{
4087 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
4088
4089 try
4090 {
4091 if (count < 0 || first < 0 || primcount < 0)
4092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004093 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004094 }
4095
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004096 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004097 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004098 gl::Context *context = gl::getNonLostContext();
4099
4100 if (context)
4101 {
4102 context->drawArrays(mode, first, count, primcount);
4103 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004104 }
4105 }
4106 catch(std::bad_alloc&)
4107 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004108 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004109 }
4110}
4111
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004112void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004113{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004114 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 +00004115 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004116
4117 try
4118 {
4119 if (count < 0)
4120 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004121 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004122 }
4123
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004124 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004125
4126 if (context)
4127 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004128 switch (type)
4129 {
4130 case GL_UNSIGNED_BYTE:
4131 case GL_UNSIGNED_SHORT:
4132 break;
4133 case GL_UNSIGNED_INT:
4134 if (!context->supports32bitIndices())
4135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004136 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00004137 }
4138 break;
4139 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004140 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00004141 }
4142
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004143 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004144 }
4145 }
4146 catch(std::bad_alloc&)
4147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004148 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149 }
4150}
4151
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004152void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
4153{
4154 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
4155 mode, count, type, indices, primcount);
4156
4157 try
4158 {
4159 if (count < 0 || primcount < 0)
4160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004161 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004162 }
4163
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004164 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004165 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004166 gl::Context *context = gl::getNonLostContext();
4167
4168 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004169 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004170 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004171 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004172 case GL_UNSIGNED_BYTE:
4173 case GL_UNSIGNED_SHORT:
4174 break;
4175 case GL_UNSIGNED_INT:
4176 if (!context->supports32bitIndices())
4177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004178 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004179 }
4180 break;
4181 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004182 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004183 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00004184
4185 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004186 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004187 }
4188 }
4189 catch(std::bad_alloc&)
4190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004191 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004192 }
4193}
4194
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004195void __stdcall glEnable(GLenum cap)
4196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004197 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004198
4199 try
4200 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004201 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004202
4203 if (context)
4204 {
4205 switch (cap)
4206 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004207 case GL_CULL_FACE: context->setCullFace(true); break;
4208 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
4209 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
4210 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
4211 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
4212 case GL_STENCIL_TEST: context->setStencilTest(true); break;
4213 case GL_DEPTH_TEST: context->setDepthTest(true); break;
4214 case GL_BLEND: context->setBlend(true); break;
4215 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004216 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004217 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004218 }
4219 }
4220 }
4221 catch(std::bad_alloc&)
4222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004223 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004224 }
4225}
4226
4227void __stdcall glEnableVertexAttribArray(GLuint index)
4228{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004229 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004230
4231 try
4232 {
4233 if (index >= gl::MAX_VERTEX_ATTRIBS)
4234 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004235 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004236 }
4237
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004238 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004239
4240 if (context)
4241 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00004242 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004243 }
4244 }
4245 catch(std::bad_alloc&)
4246 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004247 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004248 }
4249}
4250
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004251void __stdcall glEndQueryEXT(GLenum target)
4252{
4253 EVENT("GLenum target = 0x%X)", target);
4254
4255 try
4256 {
4257 switch (target)
4258 {
4259 case GL_ANY_SAMPLES_PASSED_EXT:
4260 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
4261 break;
4262 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004263 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004264 }
4265
4266 gl::Context *context = gl::getNonLostContext();
4267
4268 if (context)
4269 {
4270 context->endQuery(target);
4271 }
4272 }
4273 catch(std::bad_alloc&)
4274 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004275 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004276 }
4277}
4278
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004279void __stdcall glFinishFenceNV(GLuint fence)
4280{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004281 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004282
4283 try
4284 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004285 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004286
4287 if (context)
4288 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004289 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004290
4291 if (fenceObject == NULL)
4292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004293 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004294 }
4295
Jamie Madillfb9a7402013-07-26 11:55:01 -04004296 if (fenceObject->isFence() != GL_TRUE)
4297 {
4298 return gl::error(GL_INVALID_OPERATION);
4299 }
4300
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004301 fenceObject->finishFence();
4302 }
4303 }
4304 catch(std::bad_alloc&)
4305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004306 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004307 }
4308}
4309
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004310void __stdcall glFinish(void)
4311{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004312 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004313
4314 try
4315 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004317
4318 if (context)
4319 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004320 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004321 }
4322 }
4323 catch(std::bad_alloc&)
4324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004325 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004326 }
4327}
4328
4329void __stdcall glFlush(void)
4330{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004331 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004332
4333 try
4334 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004335 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004336
4337 if (context)
4338 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004339 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004340 }
4341 }
4342 catch(std::bad_alloc&)
4343 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004344 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345 }
4346}
4347
4348void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4349{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004350 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004351 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004352
4353 try
4354 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004355 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004356 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004358 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004359 }
4360
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004361 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004362
4363 if (context)
4364 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004365 gl::Framebuffer *framebuffer = NULL;
4366 GLuint framebufferHandle = 0;
4367 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4368 {
4369 framebuffer = context->getReadFramebuffer();
4370 framebufferHandle = context->getReadFramebufferHandle();
4371 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004372 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004373 {
4374 framebuffer = context->getDrawFramebuffer();
4375 framebufferHandle = context->getDrawFramebufferHandle();
4376 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004377
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004378 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004379 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004380 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004381 }
4382
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004383 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004384 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004385 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4386
4387 if (colorAttachment >= context->getMaximumRenderTargets())
4388 {
4389 return gl::error(GL_INVALID_VALUE);
4390 }
4391
Geoff Lang309c92a2013-07-25 16:23:19 -04004392 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004393 }
4394 else
4395 {
4396 switch (attachment)
4397 {
4398 case GL_DEPTH_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004399 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004400 break;
4401 case GL_STENCIL_ATTACHMENT:
Geoff Lang309c92a2013-07-25 16:23:19 -04004402 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004403 break;
Geoff Lang7e9ee232013-08-05 10:18:42 -04004404 case GL_DEPTH_STENCIL_ATTACHMENT:
4405 if (context->getClientVersion() < 3)
4406 {
4407 return gl::error(GL_INVALID_ENUM);
4408 }
4409 framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
4410 break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004411 default:
4412 return gl::error(GL_INVALID_ENUM);
4413 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004414 }
4415 }
4416 }
4417 catch(std::bad_alloc&)
4418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004419 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004420 }
4421}
4422
4423void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4424{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004425 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004426 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004427
4428 try
4429 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004430 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004431 if (context)
4432 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004433 if (context->getClientVersion() < 3 &&
4434 !validateES2FramebufferTextureParameters(context, target, attachment, textarget, texture, level))
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 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04004438
4439 if (context->getClientVersion() >= 3 &&
4440 !validateES3FramebufferTextureParameters(context, target, attachment, textarget, texture, level, 0, false))
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004441 {
Geoff Lang3ed0c482013-07-25 17:03:18 -04004442 return;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004443 }
4444
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004445 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004446 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004447 textarget = GL_NONE;
4448 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004449
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004450 gl::Framebuffer *framebuffer = NULL;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004451 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4452 {
4453 framebuffer = context->getReadFramebuffer();
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004454 }
4455 else
4456 {
4457 framebuffer = context->getDrawFramebuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004458 }
4459
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004460 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004461 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004462 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
Geoff Lang309c92a2013-07-25 16:23:19 -04004463 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004464 }
4465 else
4466 {
4467 switch (attachment)
4468 {
Geoff Lang309c92a2013-07-25 16:23:19 -04004469 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, 0); break;
4470 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, 0); break;
4471 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004472 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004473 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004474 }
4475 }
4476 catch(std::bad_alloc&)
4477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004478 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479 }
4480}
4481
4482void __stdcall glFrontFace(GLenum mode)
4483{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004484 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004485
4486 try
4487 {
4488 switch (mode)
4489 {
4490 case GL_CW:
4491 case GL_CCW:
4492 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004494
4495 if (context)
4496 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004497 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498 }
4499 }
4500 break;
4501 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004502 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004503 }
4504 }
4505 catch(std::bad_alloc&)
4506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004507 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004508 }
4509}
4510
4511void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4512{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004513 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004514
4515 try
4516 {
4517 if (n < 0)
4518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004519 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004520 }
4521
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004522 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004523
4524 if (context)
4525 {
4526 for (int i = 0; i < n; i++)
4527 {
4528 buffers[i] = context->createBuffer();
4529 }
4530 }
4531 }
4532 catch(std::bad_alloc&)
4533 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004534 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004535 }
4536}
4537
4538void __stdcall glGenerateMipmap(GLenum target)
4539{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004540 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004541
4542 try
4543 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004544 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004545
4546 if (context)
4547 {
Geoff Langae4852a2013-06-05 15:00:34 -04004548 gl::Texture *texture = NULL;
4549 GLint internalFormat = GL_NONE;
4550 bool isCompressed = false;
4551 bool isDepth = false;
4552
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004553 switch (target)
4554 {
4555 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004556 {
4557 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004558 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004559 {
Geoff Langae4852a2013-06-05 15:00:34 -04004560 internalFormat = tex2d->getInternalFormat(0);
4561 isCompressed = tex2d->isCompressed(0);
4562 isDepth = tex2d->isDepth(0);
4563 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004564 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004565 break;
4566 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004567
4568 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004569 {
4570 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004571 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004572 {
Geoff Langae4852a2013-06-05 15:00:34 -04004573 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4574 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4575 isDepth = false;
4576 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004577 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004578 break;
4579 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004580
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004581 case GL_TEXTURE_3D:
4582 {
4583 if (context->getClientVersion() < 3)
4584 {
4585 return gl::error(GL_INVALID_ENUM);
4586 }
4587
4588 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004589 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004590 {
Geoff Langae4852a2013-06-05 15:00:34 -04004591 internalFormat = tex3D->getInternalFormat(0);
4592 isCompressed = tex3D->isCompressed(0);
4593 isDepth = tex3D->isDepth(0);
4594 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004595 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004596 break;
4597 }
4598
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004599 case GL_TEXTURE_2D_ARRAY:
4600 {
4601 if (context->getClientVersion() < 3)
4602 {
4603 return gl::error(GL_INVALID_ENUM);
4604 }
4605
4606 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004607 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004608 {
Geoff Langae4852a2013-06-05 15:00:34 -04004609 internalFormat = tex2darr->getInternalFormat(0);
4610 isCompressed = tex2darr->isCompressed(0);
4611 isDepth = tex2darr->isDepth(0);
4612 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004613 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004614 break;
4615 }
4616
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004617 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004618 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004619 }
Geoff Langae4852a2013-06-05 15:00:34 -04004620
4621 if (!texture)
4622 {
4623 return gl::error(GL_INVALID_OPERATION);
4624 }
4625
4626 // Internally, all texture formats are sized so checking if the format
4627 // is color renderable and filterable will not fail.
4628 if (isDepth || isCompressed ||
4629 !gl::IsColorRenderingSupported(internalFormat, context) ||
4630 !gl::IsTextureFilteringSupported(internalFormat, context))
4631 {
4632 return gl::error(GL_INVALID_OPERATION);
4633 }
4634
4635 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004636 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004637 }
4638 catch(std::bad_alloc&)
4639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004640 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004641 }
4642}
4643
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004644void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4645{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004646 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004647
4648 try
4649 {
4650 if (n < 0)
4651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004652 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004653 }
4654
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004655 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004656
4657 if (context)
4658 {
4659 for (int i = 0; i < n; i++)
4660 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004661 fences[i] = context->createFenceNV();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004662 }
4663 }
4664 }
4665 catch(std::bad_alloc&)
4666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004667 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004668 }
4669}
4670
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004673 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674
4675 try
4676 {
4677 if (n < 0)
4678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004679 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004680 }
4681
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004682 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004683
4684 if (context)
4685 {
4686 for (int i = 0; i < n; i++)
4687 {
4688 framebuffers[i] = context->createFramebuffer();
4689 }
4690 }
4691 }
4692 catch(std::bad_alloc&)
4693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004694 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004695 }
4696}
4697
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004698void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4699{
4700 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4701
4702 try
4703 {
4704 if (n < 0)
4705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004707 }
4708
4709 gl::Context *context = gl::getNonLostContext();
4710
4711 if (context)
4712 {
4713 for (int i = 0; i < n; i++)
4714 {
4715 ids[i] = context->createQuery();
4716 }
4717 }
4718 }
4719 catch(std::bad_alloc&)
4720 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004721 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004722 }
4723}
4724
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4726{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004727 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004728
4729 try
4730 {
4731 if (n < 0)
4732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004733 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004734 }
4735
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004736 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737
4738 if (context)
4739 {
4740 for (int i = 0; i < n; i++)
4741 {
4742 renderbuffers[i] = context->createRenderbuffer();
4743 }
4744 }
4745 }
4746 catch(std::bad_alloc&)
4747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004748 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004749 }
4750}
4751
4752void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4753{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004754 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004755
4756 try
4757 {
4758 if (n < 0)
4759 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004760 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004761 }
4762
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004763 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004764
4765 if (context)
4766 {
4767 for (int i = 0; i < n; i++)
4768 {
4769 textures[i] = context->createTexture();
4770 }
4771 }
4772 }
4773 catch(std::bad_alloc&)
4774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004775 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004776 }
4777}
4778
daniel@transgaming.com85423182010-04-22 13:35:27 +00004779void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004780{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004781 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004782 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004783 program, index, bufsize, length, size, type, name);
4784
4785 try
4786 {
4787 if (bufsize < 0)
4788 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004789 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004790 }
4791
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004792 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004793
4794 if (context)
4795 {
4796 gl::Program *programObject = context->getProgram(program);
4797
4798 if (!programObject)
4799 {
4800 if (context->getShader(program))
4801 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004802 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004803 }
4804 else
4805 {
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
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004810 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004812 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004813 }
4814
4815 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4816 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004817 }
4818 catch(std::bad_alloc&)
4819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004820 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004821 }
4822}
4823
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004824void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004825{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004826 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004827 "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 +00004828 program, index, bufsize, length, size, type, name);
4829
4830 try
4831 {
4832 if (bufsize < 0)
4833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004834 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004835 }
4836
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004837 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004838
4839 if (context)
4840 {
4841 gl::Program *programObject = context->getProgram(program);
4842
4843 if (!programObject)
4844 {
4845 if (context->getShader(program))
4846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004847 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004848 }
4849 else
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
4855 if (index >= (GLuint)programObject->getActiveUniformCount())
4856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004857 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004858 }
4859
4860 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4861 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004862 }
4863 catch(std::bad_alloc&)
4864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004865 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004866 }
4867}
4868
4869void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4870{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004871 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 +00004872 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004873
4874 try
4875 {
4876 if (maxcount < 0)
4877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004878 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004879 }
4880
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004881 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004882
4883 if (context)
4884 {
4885 gl::Program *programObject = context->getProgram(program);
4886
4887 if (!programObject)
4888 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004889 if (context->getShader(program))
4890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004891 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004892 }
4893 else
4894 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004895 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004896 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004897 }
4898
4899 return programObject->getAttachedShaders(maxcount, count, shaders);
4900 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004901 }
4902 catch(std::bad_alloc&)
4903 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004904 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004905 }
4906}
4907
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004908int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004909{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004910 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004911
4912 try
4913 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004914 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004915
4916 if (context)
4917 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004918
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004919 gl::Program *programObject = context->getProgram(program);
4920
4921 if (!programObject)
4922 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004923 if (context->getShader(program))
4924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004925 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004926 }
4927 else
4928 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004929 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004930 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004931 }
4932
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004933 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004934 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004936 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004937 }
4938
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004939 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004940 }
4941 }
4942 catch(std::bad_alloc&)
4943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004944 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004945 }
4946
4947 return -1;
4948}
4949
4950void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004952 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004953
4954 try
4955 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004956 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004957
4958 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004959 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004960 if (!(context->getBooleanv(pname, params)))
4961 {
4962 GLenum nativeType;
4963 unsigned int numParams = 0;
4964 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004965 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004966
4967 if (numParams == 0)
4968 return; // it is known that the pname is valid, but there are no parameters to return
4969
4970 if (nativeType == GL_FLOAT)
4971 {
4972 GLfloat *floatParams = NULL;
4973 floatParams = new GLfloat[numParams];
4974
4975 context->getFloatv(pname, floatParams);
4976
4977 for (unsigned int i = 0; i < numParams; ++i)
4978 {
4979 if (floatParams[i] == 0.0f)
4980 params[i] = GL_FALSE;
4981 else
4982 params[i] = GL_TRUE;
4983 }
4984
4985 delete [] floatParams;
4986 }
4987 else if (nativeType == GL_INT)
4988 {
4989 GLint *intParams = NULL;
4990 intParams = new GLint[numParams];
4991
4992 context->getIntegerv(pname, intParams);
4993
4994 for (unsigned int i = 0; i < numParams; ++i)
4995 {
4996 if (intParams[i] == 0)
4997 params[i] = GL_FALSE;
4998 else
4999 params[i] = GL_TRUE;
5000 }
5001
5002 delete [] intParams;
5003 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005004 else if (nativeType == GL_INT_64_ANGLEX)
5005 {
5006 GLint64 *int64Params = NULL;
5007 int64Params = new GLint64[numParams];
5008
5009 context->getInteger64v(pname, int64Params);
5010
5011 for (unsigned int i = 0; i < numParams; ++i)
5012 {
5013 if (int64Params[i] == 0)
5014 params[i] = GL_FALSE;
5015 else
5016 params[i] = GL_TRUE;
5017 }
5018
5019 delete [] int64Params;
5020 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005021 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005022 }
5023 }
5024 catch(std::bad_alloc&)
5025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005026 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005027 }
5028}
5029
5030void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
5031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005032 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 +00005033
5034 try
5035 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005036 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005037
5038 if (context)
5039 {
5040 gl::Buffer *buffer;
5041
5042 switch (target)
5043 {
5044 case GL_ARRAY_BUFFER:
5045 buffer = context->getArrayBuffer();
5046 break;
5047 case GL_ELEMENT_ARRAY_BUFFER:
5048 buffer = context->getElementArrayBuffer();
5049 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005050 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005051 }
5052
5053 if (!buffer)
5054 {
5055 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005056 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005057 }
5058
5059 switch (pname)
5060 {
5061 case GL_BUFFER_USAGE:
5062 *params = buffer->usage();
5063 break;
5064 case GL_BUFFER_SIZE:
5065 *params = buffer->size();
5066 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005067 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00005068 }
5069 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005070 }
5071 catch(std::bad_alloc&)
5072 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005073 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005074 }
5075}
5076
5077GLenum __stdcall glGetError(void)
5078{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005079 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005080
5081 gl::Context *context = gl::getContext();
5082
5083 if (context)
5084 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00005085 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005086 }
5087
5088 return GL_NO_ERROR;
5089}
5090
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005091void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
5092{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005093 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005094
5095 try
5096 {
5097
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005098 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005099
5100 if (context)
5101 {
Jamie Madill33dc8432013-07-26 11:55:05 -04005102 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005103
5104 if (fenceObject == NULL)
5105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005106 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005107 }
5108
Jamie Madillfb9a7402013-07-26 11:55:01 -04005109 if (fenceObject->isFence() != GL_TRUE)
5110 {
5111 return gl::error(GL_INVALID_OPERATION);
5112 }
5113
5114 switch (pname)
5115 {
5116 case GL_FENCE_STATUS_NV:
5117 case GL_FENCE_CONDITION_NV:
5118 break;
5119
5120 default: return gl::error(GL_INVALID_ENUM);
5121 }
5122
5123 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005124 }
5125 }
5126 catch(std::bad_alloc&)
5127 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005128 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005129 }
5130}
5131
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005132void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
5133{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005134 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005135
5136 try
5137 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005138 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005139
5140 if (context)
5141 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005142 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005143 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005144 GLenum nativeType;
5145 unsigned int numParams = 0;
5146 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005147 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005148
5149 if (numParams == 0)
5150 return; // it is known that the pname is valid, but that there are no parameters to return.
5151
5152 if (nativeType == GL_BOOL)
5153 {
5154 GLboolean *boolParams = NULL;
5155 boolParams = new GLboolean[numParams];
5156
5157 context->getBooleanv(pname, boolParams);
5158
5159 for (unsigned int i = 0; i < numParams; ++i)
5160 {
5161 if (boolParams[i] == GL_FALSE)
5162 params[i] = 0.0f;
5163 else
5164 params[i] = 1.0f;
5165 }
5166
5167 delete [] boolParams;
5168 }
5169 else if (nativeType == GL_INT)
5170 {
5171 GLint *intParams = NULL;
5172 intParams = new GLint[numParams];
5173
5174 context->getIntegerv(pname, intParams);
5175
5176 for (unsigned int i = 0; i < numParams; ++i)
5177 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005178 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005179 }
5180
5181 delete [] intParams;
5182 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005183 else if (nativeType == GL_INT_64_ANGLEX)
5184 {
5185 GLint64 *int64Params = NULL;
5186 int64Params = new GLint64[numParams];
5187
5188 context->getInteger64v(pname, int64Params);
5189
5190 for (unsigned int i = 0; i < numParams; ++i)
5191 {
5192 params[i] = static_cast<GLfloat>(int64Params[i]);
5193 }
5194
5195 delete [] int64Params;
5196 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005197 }
5198 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005199 }
5200 catch(std::bad_alloc&)
5201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005202 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005203 }
5204}
5205
5206void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
5207{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005208 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 +00005209 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005210
5211 try
5212 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005213 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005214
5215 if (context)
5216 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005217 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005219 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005220 }
5221
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005222 gl::Framebuffer *framebuffer = NULL;
5223 if (target == GL_READ_FRAMEBUFFER_ANGLE)
5224 {
5225 if(context->getReadFramebufferHandle() == 0)
5226 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005227 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005228 }
5229
5230 framebuffer = context->getReadFramebuffer();
5231 }
5232 else
5233 {
5234 if (context->getDrawFramebufferHandle() == 0)
5235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005236 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005237 }
5238
5239 framebuffer = context->getDrawFramebuffer();
5240 }
5241
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005242 GLenum attachmentType;
5243 GLuint attachmentHandle;
Geoff Lang309c92a2013-07-25 16:23:19 -04005244 GLuint attachmentLevel;
5245 GLuint attachmentLayer;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005246
5247 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005248 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005249 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5250
5251 if (colorAttachment >= context->getMaximumRenderTargets())
5252 {
5253 return gl::error(GL_INVALID_ENUM);
5254 }
5255
5256 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5257 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
Geoff Lang309c92a2013-07-25 16:23:19 -04005258 attachmentLevel = framebuffer->getColorbufferMipLevel(colorAttachment);
5259 attachmentLayer = framebuffer->getColorbufferLayer(colorAttachment);
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005260 }
5261 else
5262 {
5263 switch (attachment)
5264 {
5265 case GL_DEPTH_ATTACHMENT:
5266 attachmentType = framebuffer->getDepthbufferType();
5267 attachmentHandle = framebuffer->getDepthbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005268 attachmentLevel = framebuffer->getDepthbufferMipLevel();
5269 attachmentLayer = framebuffer->getDepthbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005270 break;
5271 case GL_STENCIL_ATTACHMENT:
5272 attachmentType = framebuffer->getStencilbufferType();
5273 attachmentHandle = framebuffer->getStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005274 attachmentLevel = framebuffer->getStencilbufferMipLevel();
5275 attachmentLayer = framebuffer->getStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005276 break;
Geoff Lang55ba29c2013-07-11 16:57:53 -04005277 case GL_DEPTH_STENCIL_ATTACHMENT:
5278 if (context->getClientVersion() < 3)
5279 {
5280 return gl::error(GL_INVALID_ENUM);
5281 }
5282 if (framebuffer->getDepthbufferHandle() != framebuffer->getStencilbufferHandle())
5283 {
5284 return gl::error(GL_INVALID_OPERATION);
5285 }
5286 attachmentType = framebuffer->getDepthStencilbufferType();
5287 attachmentHandle = framebuffer->getDepthStencilbufferHandle();
Geoff Lang309c92a2013-07-25 16:23:19 -04005288 attachmentLevel = framebuffer->getDepthStencilbufferMipLevel();
5289 attachmentLayer = framebuffer->getDepthStencilbufferLayer();
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005290 default: return gl::error(GL_INVALID_ENUM);
5291 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005292 }
5293
5294 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005295 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005296 {
5297 attachmentObjectType = attachmentType;
5298 }
Geoff Lang0fe19492013-07-25 17:04:31 -04005299 else if (gl::IsInternalTextureTarget(attachmentType, context->getClientVersion()))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005300 {
5301 attachmentObjectType = GL_TEXTURE;
5302 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005303 else
5304 {
5305 UNREACHABLE();
5306 return;
5307 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005308
5309 switch (pname)
5310 {
5311 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5312 *params = attachmentObjectType;
5313 break;
5314 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5315 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5316 {
5317 *params = attachmentHandle;
5318 }
5319 else
5320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005321 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005322 }
5323 break;
5324 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5325 if (attachmentObjectType == GL_TEXTURE)
5326 {
Geoff Lang309c92a2013-07-25 16:23:19 -04005327 *params = attachmentLevel;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005328 }
5329 else
5330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005331 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005332 }
5333 break;
5334 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5335 if (attachmentObjectType == GL_TEXTURE)
5336 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005337 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005338 {
5339 *params = attachmentType;
5340 }
5341 else
5342 {
5343 *params = 0;
5344 }
5345 }
5346 else
5347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005348 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005349 }
5350 break;
Geoff Lang309c92a2013-07-25 16:23:19 -04005351 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
5352 if (context->getClientVersion() < 3)
5353 {
5354 return gl::error(GL_INVALID_ENUM);
5355 }
5356 if (attachmentObjectType == GL_TEXTURE)
5357 {
5358 *params = attachmentLayer;
5359 }
5360 else
5361 {
5362 return gl::error(GL_INVALID_ENUM);
5363 }
5364 break;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005365 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005366 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005367 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005368 }
5369 }
5370 catch(std::bad_alloc&)
5371 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005372 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005373 }
5374}
5375
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005376GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5377{
5378 EVENT("()");
5379
5380 try
5381 {
5382 gl::Context *context = gl::getContext();
5383
5384 if (context)
5385 {
5386 return context->getResetStatus();
5387 }
5388
5389 return GL_NO_ERROR;
5390 }
5391 catch(std::bad_alloc&)
5392 {
5393 return GL_OUT_OF_MEMORY;
5394 }
5395}
5396
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005397void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005399 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005400
5401 try
5402 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005403 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005404
5405 if (context)
5406 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005407 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005408 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005409 GLenum nativeType;
5410 unsigned int numParams = 0;
5411 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005412 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005413
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005414 if (numParams == 0)
5415 return; // it is known that pname is valid, but there are no parameters to return
5416
5417 if (nativeType == GL_BOOL)
5418 {
5419 GLboolean *boolParams = NULL;
5420 boolParams = new GLboolean[numParams];
5421
5422 context->getBooleanv(pname, boolParams);
5423
5424 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005425 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005426 if (boolParams[i] == GL_FALSE)
5427 params[i] = 0;
5428 else
5429 params[i] = 1;
5430 }
5431
5432 delete [] boolParams;
5433 }
5434 else if (nativeType == GL_FLOAT)
5435 {
5436 GLfloat *floatParams = NULL;
5437 floatParams = new GLfloat[numParams];
5438
5439 context->getFloatv(pname, floatParams);
5440
5441 for (unsigned int i = 0; i < numParams; ++i)
5442 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005443 // 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 +00005444 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 +00005445 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005446 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005447 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005448 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005449 {
Jamie Madillaf496912013-07-19 16:36:54 -04005450 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005451 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005452 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005453
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005454 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005455 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005456 else if (nativeType == GL_INT_64_ANGLEX)
5457 {
5458 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5459 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5460 GLint64 *int64Params = NULL;
5461 int64Params = new GLint64[numParams];
5462
5463 context->getInteger64v(pname, int64Params);
5464
5465 for (unsigned int i = 0; i < numParams; ++i)
5466 {
5467 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5468 params[i] = static_cast<GLint>(clampedValue);
5469 }
5470
5471 delete [] int64Params;
5472 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005473 }
5474 }
5475 }
5476 catch(std::bad_alloc&)
5477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005478 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005479 }
5480}
5481
5482void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5483{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005484 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005485
5486 try
5487 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005488 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005489
5490 if (context)
5491 {
5492 gl::Program *programObject = context->getProgram(program);
5493
5494 if (!programObject)
5495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005496 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005497 }
5498
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005499 if (context->getClientVersion() < 3)
5500 {
5501 switch (pname)
5502 {
5503 case GL_ACTIVE_UNIFORM_BLOCKS:
5504 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5505 return gl::error(GL_INVALID_ENUM);
5506 }
5507 }
5508
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005509 switch (pname)
5510 {
5511 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005512 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005513 return;
5514 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005515 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005516 return;
5517 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005518 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005519 return;
5520 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005521 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005522 return;
5523 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005524 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005525 return;
5526 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005527 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005528 return;
5529 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005530 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005531 return;
5532 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005533 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005534 return;
5535 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005536 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005537 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005538 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005539 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005540 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005541 case GL_ACTIVE_UNIFORM_BLOCKS:
5542 *params = programObject->getActiveUniformBlockCount();
5543 return;
5544 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5545 *params = programObject->getActiveUniformBlockMaxLength();
5546 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005547 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005548 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005549 }
5550 }
5551 }
5552 catch(std::bad_alloc&)
5553 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005554 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005555 }
5556}
5557
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005558void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005559{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005560 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 +00005561 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005562
5563 try
5564 {
5565 if (bufsize < 0)
5566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005567 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005568 }
5569
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005570 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005571
5572 if (context)
5573 {
5574 gl::Program *programObject = context->getProgram(program);
5575
5576 if (!programObject)
5577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005578 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005579 }
5580
5581 programObject->getInfoLog(bufsize, length, infolog);
5582 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005583 }
5584 catch(std::bad_alloc&)
5585 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005586 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005587 }
5588}
5589
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005590void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5591{
5592 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5593
5594 try
5595 {
5596 switch (pname)
5597 {
5598 case GL_CURRENT_QUERY_EXT:
5599 break;
5600 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005601 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005602 }
5603
5604 gl::Context *context = gl::getNonLostContext();
5605
5606 if (context)
5607 {
5608 params[0] = context->getActiveQuery(target);
5609 }
5610 }
5611 catch(std::bad_alloc&)
5612 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005613 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005614 }
5615}
5616
5617void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5618{
5619 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5620
5621 try
5622 {
5623 switch (pname)
5624 {
5625 case GL_QUERY_RESULT_EXT:
5626 case GL_QUERY_RESULT_AVAILABLE_EXT:
5627 break;
5628 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005629 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005630 }
5631 gl::Context *context = gl::getNonLostContext();
5632
5633 if (context)
5634 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005635 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5636
5637 if (!queryObject)
5638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005639 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005640 }
5641
5642 if (context->getActiveQuery(queryObject->getType()) == id)
5643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005644 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005645 }
5646
5647 switch(pname)
5648 {
5649 case GL_QUERY_RESULT_EXT:
5650 params[0] = queryObject->getResult();
5651 break;
5652 case GL_QUERY_RESULT_AVAILABLE_EXT:
5653 params[0] = queryObject->isResultAvailable();
5654 break;
5655 default:
5656 ASSERT(false);
5657 }
5658 }
5659 }
5660 catch(std::bad_alloc&)
5661 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005662 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005663 }
5664}
5665
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005666void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5667{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005668 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 +00005669
5670 try
5671 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005672 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005673
5674 if (context)
5675 {
5676 if (target != GL_RENDERBUFFER)
5677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005678 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005679 }
5680
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005681 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005682 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005683 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005684 }
5685
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005686 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005687
5688 switch (pname)
5689 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005690 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5691 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5692 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5693 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5694 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5695 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5696 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5697 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5698 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005699 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005700 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005701 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005702 *params = renderbuffer->getSamples();
5703 }
5704 else
5705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005706 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005707 }
5708 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005709 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005710 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005711 }
5712 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005713 }
5714 catch(std::bad_alloc&)
5715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005717 }
5718}
5719
5720void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5721{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005722 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005723
5724 try
5725 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005726 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005727
5728 if (context)
5729 {
5730 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005731
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005732 if (!shaderObject)
5733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005734 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005735 }
5736
5737 switch (pname)
5738 {
5739 case GL_SHADER_TYPE:
5740 *params = shaderObject->getType();
5741 return;
5742 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005743 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005744 return;
5745 case GL_COMPILE_STATUS:
5746 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5747 return;
5748 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005749 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005750 return;
5751 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005752 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005753 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005754 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5755 *params = shaderObject->getTranslatedSourceLength();
5756 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005757 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005758 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005759 }
5760 }
5761 }
5762 catch(std::bad_alloc&)
5763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005764 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005765 }
5766}
5767
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005768void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005769{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005770 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 +00005771 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005772
5773 try
5774 {
5775 if (bufsize < 0)
5776 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005777 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005778 }
5779
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005780 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005781
5782 if (context)
5783 {
5784 gl::Shader *shaderObject = context->getShader(shader);
5785
5786 if (!shaderObject)
5787 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005788 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005789 }
5790
5791 shaderObject->getInfoLog(bufsize, length, infolog);
5792 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005793 }
5794 catch(std::bad_alloc&)
5795 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005796 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005797 }
5798}
5799
5800void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5801{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005802 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 +00005803 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005804
5805 try
5806 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005807 switch (shadertype)
5808 {
5809 case GL_VERTEX_SHADER:
5810 case GL_FRAGMENT_SHADER:
5811 break;
5812 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005813 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005814 }
5815
5816 switch (precisiontype)
5817 {
5818 case GL_LOW_FLOAT:
5819 case GL_MEDIUM_FLOAT:
5820 case GL_HIGH_FLOAT:
5821 // Assume IEEE 754 precision
5822 range[0] = 127;
5823 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005824 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005825 break;
5826 case GL_LOW_INT:
5827 case GL_MEDIUM_INT:
5828 case GL_HIGH_INT:
5829 // Some (most) hardware only supports single-precision floating-point numbers,
5830 // which can accurately represent integers up to +/-16777216
5831 range[0] = 24;
5832 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005833 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005834 break;
5835 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005836 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005837 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005838 }
5839 catch(std::bad_alloc&)
5840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005841 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005842 }
5843}
5844
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005845void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005846{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005847 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 +00005848 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005849
5850 try
5851 {
5852 if (bufsize < 0)
5853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005854 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005855 }
5856
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005857 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005858
5859 if (context)
5860 {
5861 gl::Shader *shaderObject = context->getShader(shader);
5862
5863 if (!shaderObject)
5864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005865 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005866 }
5867
5868 shaderObject->getSource(bufsize, length, source);
5869 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005870 }
5871 catch(std::bad_alloc&)
5872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005873 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005874 }
5875}
5876
zmo@google.coma574f782011-10-03 21:45:23 +00005877void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5878{
5879 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5880 shader, bufsize, length, source);
5881
5882 try
5883 {
5884 if (bufsize < 0)
5885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005886 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005887 }
5888
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005889 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005890
5891 if (context)
5892 {
5893 gl::Shader *shaderObject = context->getShader(shader);
5894
5895 if (!shaderObject)
5896 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005897 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005898 }
5899
5900 shaderObject->getTranslatedSource(bufsize, length, source);
5901 }
5902 }
5903 catch(std::bad_alloc&)
5904 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005905 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005906 }
5907}
5908
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005909const GLubyte* __stdcall glGetString(GLenum name)
5910{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005911 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005912
5913 try
5914 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005915 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005916
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005917 switch (name)
5918 {
5919 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005920 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005921 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005922 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005923 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005924 if (context->getClientVersion() == 2)
5925 {
5926 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5927 }
5928 else
5929 {
5930 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5931 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005932 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005933 if (context->getClientVersion() == 2)
5934 {
5935 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5936 }
5937 else
5938 {
5939 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5940 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005941 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005942 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005943 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005944 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005945 }
5946 }
5947 catch(std::bad_alloc&)
5948 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005949 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005950 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005951}
5952
5953void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5954{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005955 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 +00005956
5957 try
5958 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005959 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005960
5961 if (context)
5962 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005963 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005964
Jamie Madillfb8a8302013-07-03 14:24:12 -04005965 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005967 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005968 }
5969
5970 switch (pname)
5971 {
5972 case GL_TEXTURE_MAG_FILTER:
5973 *params = (GLfloat)texture->getMagFilter();
5974 break;
5975 case GL_TEXTURE_MIN_FILTER:
5976 *params = (GLfloat)texture->getMinFilter();
5977 break;
5978 case GL_TEXTURE_WRAP_S:
5979 *params = (GLfloat)texture->getWrapS();
5980 break;
5981 case GL_TEXTURE_WRAP_T:
5982 *params = (GLfloat)texture->getWrapT();
5983 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005984 case GL_TEXTURE_WRAP_R:
5985 if (context->getClientVersion() < 3)
5986 {
5987 return gl::error(GL_INVALID_ENUM);
5988 }
5989 *params = (GLfloat)texture->getWrapR();
5990 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005991 case GL_TEXTURE_IMMUTABLE_FORMAT:
5992 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005993 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5994 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005995 case GL_TEXTURE_IMMUTABLE_LEVELS:
5996 if (context->getClientVersion() < 3)
5997 {
5998 return gl::error(GL_INVALID_ENUM);
5999 }
6000 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
6001 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006002 case GL_TEXTURE_USAGE_ANGLE:
6003 *params = (GLfloat)texture->getUsage();
6004 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006005 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6006 if (!context->supportsTextureFilterAnisotropy())
6007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006008 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006009 }
6010 *params = (GLfloat)texture->getMaxAnisotropy();
6011 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006012 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006013 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006014 }
6015 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006016 }
6017 catch(std::bad_alloc&)
6018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006019 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006020 }
6021}
6022
6023void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
6024{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006025 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 +00006026
6027 try
6028 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006029 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006030
6031 if (context)
6032 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04006033 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006034
Jamie Madillfb8a8302013-07-03 14:24:12 -04006035 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006037 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006038 }
6039
6040 switch (pname)
6041 {
6042 case GL_TEXTURE_MAG_FILTER:
6043 *params = texture->getMagFilter();
6044 break;
6045 case GL_TEXTURE_MIN_FILTER:
6046 *params = texture->getMinFilter();
6047 break;
6048 case GL_TEXTURE_WRAP_S:
6049 *params = texture->getWrapS();
6050 break;
6051 case GL_TEXTURE_WRAP_T:
6052 *params = texture->getWrapT();
6053 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006054 case GL_TEXTURE_WRAP_R:
6055 if (context->getClientVersion() < 3)
6056 {
6057 return gl::error(GL_INVALID_ENUM);
6058 }
6059 *params = texture->getWrapR();
6060 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006061 case GL_TEXTURE_IMMUTABLE_FORMAT:
6062 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00006063 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
6064 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00006065 case GL_TEXTURE_IMMUTABLE_LEVELS:
6066 if (context->getClientVersion() < 3)
6067 {
6068 return gl::error(GL_INVALID_ENUM);
6069 }
6070 *params = texture->isImmutable() ? texture->levelCount() : 0;
6071 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006072 case GL_TEXTURE_USAGE_ANGLE:
6073 *params = texture->getUsage();
6074 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006075 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6076 if (!context->supportsTextureFilterAnisotropy())
6077 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006078 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006079 }
6080 *params = (GLint)texture->getMaxAnisotropy();
6081 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006082
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006083 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006084 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00006085 }
6086 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006087 }
6088 catch(std::bad_alloc&)
6089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006090 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006091 }
6092}
6093
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006094void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
6095{
6096 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
6097 program, location, bufSize, params);
6098
6099 try
6100 {
6101 if (bufSize < 0)
6102 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006103 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006104 }
6105
6106 gl::Context *context = gl::getNonLostContext();
6107
6108 if (context)
6109 {
6110 if (program == 0)
6111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006112 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006113 }
6114
6115 gl::Program *programObject = context->getProgram(program);
6116
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006117 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006119 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006120 }
6121
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006122 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6123 if (!programBinary)
6124 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006125 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006126 }
6127
6128 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006130 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006131 }
6132 }
6133 }
6134 catch(std::bad_alloc&)
6135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006136 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006137 }
6138}
6139
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006140void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
6141{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006142 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006143
6144 try
6145 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006146 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006147
6148 if (context)
6149 {
6150 if (program == 0)
6151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006152 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006153 }
6154
6155 gl::Program *programObject = context->getProgram(program);
6156
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006157 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006158 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006159 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006160 }
6161
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006162 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6163 if (!programBinary)
6164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006165 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006166 }
6167
6168 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006170 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006171 }
6172 }
6173 }
6174 catch(std::bad_alloc&)
6175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006176 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006177 }
6178}
6179
6180void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
6181{
6182 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
6183 program, location, bufSize, params);
6184
6185 try
6186 {
6187 if (bufSize < 0)
6188 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006189 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006190 }
6191
6192 gl::Context *context = gl::getNonLostContext();
6193
6194 if (context)
6195 {
6196 if (program == 0)
6197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006198 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006199 }
6200
6201 gl::Program *programObject = context->getProgram(program);
6202
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006203 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006205 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00006206 }
6207
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006208 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6209 if (!programBinary)
6210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006211 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006212 }
6213
6214 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006216 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006217 }
6218 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006219 }
6220 catch(std::bad_alloc&)
6221 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006222 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006223 }
6224}
6225
6226void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
6227{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006228 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006229
6230 try
6231 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006232 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006233
6234 if (context)
6235 {
6236 if (program == 0)
6237 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006238 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006239 }
6240
6241 gl::Program *programObject = context->getProgram(program);
6242
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006243 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006245 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006246 }
6247
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006248 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6249 if (!programBinary)
6250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006251 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006252 }
6253
6254 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006256 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006257 }
6258 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006259 }
6260 catch(std::bad_alloc&)
6261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006262 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006263 }
6264}
6265
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006266int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006267{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006268 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006269
6270 try
6271 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006272 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006273
6274 if (strstr(name, "gl_") == name)
6275 {
6276 return -1;
6277 }
6278
6279 if (context)
6280 {
6281 gl::Program *programObject = context->getProgram(program);
6282
6283 if (!programObject)
6284 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006285 if (context->getShader(program))
6286 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006287 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006288 }
6289 else
6290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006291 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006292 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006293 }
6294
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006295 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006296 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006297 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006298 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006299 }
6300
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006301 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006302 }
6303 }
6304 catch(std::bad_alloc&)
6305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006306 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006307 }
6308
6309 return -1;
6310}
6311
6312void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6313{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006314 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006315
6316 try
6317 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006318 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006319
daniel@transgaming.come0078962010-04-15 20:45:08 +00006320 if (context)
6321 {
6322 if (index >= gl::MAX_VERTEX_ATTRIBS)
6323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006324 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006325 }
6326
daniel@transgaming.com83921382011-01-08 05:46:00 +00006327 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006328
Jamie Madillaff71502013-07-02 11:57:05 -04006329 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006330 {
Jamie Madillaff71502013-07-02 11:57:05 -04006331 return;
6332 }
6333
6334 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6335 {
6336 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6337 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006338 {
Jamie Madillaff71502013-07-02 11:57:05 -04006339 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006340 }
Jamie Madillaff71502013-07-02 11:57:05 -04006341 }
6342 else
6343 {
6344 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006345 }
6346 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006347 }
6348 catch(std::bad_alloc&)
6349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006350 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006351 }
6352}
6353
6354void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6355{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006356 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006357
6358 try
6359 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006360 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006361
daniel@transgaming.come0078962010-04-15 20:45:08 +00006362 if (context)
6363 {
6364 if (index >= gl::MAX_VERTEX_ATTRIBS)
6365 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006366 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006367 }
6368
daniel@transgaming.com83921382011-01-08 05:46:00 +00006369 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006370
Jamie Madillaff71502013-07-02 11:57:05 -04006371 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006372 {
Jamie Madillaff71502013-07-02 11:57:05 -04006373 return;
6374 }
6375
6376 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6377 {
6378 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6379 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006380 {
Jamie Madillaff71502013-07-02 11:57:05 -04006381 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006382 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006383 }
Jamie Madillaff71502013-07-02 11:57:05 -04006384 }
6385 else
6386 {
6387 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006388 }
6389 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006390 }
6391 catch(std::bad_alloc&)
6392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006394 }
6395}
6396
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006397void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006399 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006400
6401 try
6402 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006403 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006404
daniel@transgaming.come0078962010-04-15 20:45:08 +00006405 if (context)
6406 {
6407 if (index >= gl::MAX_VERTEX_ATTRIBS)
6408 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006409 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006410 }
6411
6412 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006414 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006415 }
6416
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006417 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006418 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006419 }
6420 catch(std::bad_alloc&)
6421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006422 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006423 }
6424}
6425
6426void __stdcall glHint(GLenum target, GLenum mode)
6427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006428 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006429
6430 try
6431 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006432 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006433 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006434 case GL_FASTEST:
6435 case GL_NICEST:
6436 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006437 break;
6438 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006439 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006440 }
6441
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006442 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006443 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006444 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006445 case GL_GENERATE_MIPMAP_HINT:
6446 if (context) context->setGenerateMipmapHint(mode);
6447 break;
6448 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6449 if (context) context->setFragmentShaderDerivativeHint(mode);
6450 break;
6451 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006452 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006453 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006454 }
6455 catch(std::bad_alloc&)
6456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006457 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006458 }
6459}
6460
6461GLboolean __stdcall glIsBuffer(GLuint buffer)
6462{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006463 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006464
6465 try
6466 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006467 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006468
6469 if (context && buffer)
6470 {
6471 gl::Buffer *bufferObject = context->getBuffer(buffer);
6472
6473 if (bufferObject)
6474 {
6475 return GL_TRUE;
6476 }
6477 }
6478 }
6479 catch(std::bad_alloc&)
6480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006481 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006482 }
6483
6484 return GL_FALSE;
6485}
6486
6487GLboolean __stdcall glIsEnabled(GLenum cap)
6488{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006489 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006490
6491 try
6492 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006493 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006494
6495 if (context)
6496 {
6497 switch (cap)
6498 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006499 case GL_CULL_FACE: return context->isCullFaceEnabled();
6500 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6501 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6502 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6503 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6504 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6505 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6506 case GL_BLEND: return context->isBlendEnabled();
6507 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006508 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006509 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006510 }
6511 }
6512 }
6513 catch(std::bad_alloc&)
6514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006515 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006516 }
6517
6518 return false;
6519}
6520
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006521GLboolean __stdcall glIsFenceNV(GLuint fence)
6522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006523 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006524
6525 try
6526 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006527 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006528
6529 if (context)
6530 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006531 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006532
6533 if (fenceObject == NULL)
6534 {
6535 return GL_FALSE;
6536 }
6537
6538 return fenceObject->isFence();
6539 }
6540 }
6541 catch(std::bad_alloc&)
6542 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006543 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006544 }
6545
6546 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006547}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006548
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006549GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6550{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006551 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006552
6553 try
6554 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006555 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006556
6557 if (context && framebuffer)
6558 {
6559 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6560
6561 if (framebufferObject)
6562 {
6563 return GL_TRUE;
6564 }
6565 }
6566 }
6567 catch(std::bad_alloc&)
6568 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006569 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006570 }
6571
6572 return GL_FALSE;
6573}
6574
6575GLboolean __stdcall glIsProgram(GLuint program)
6576{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006577 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006578
6579 try
6580 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006581 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006582
6583 if (context && program)
6584 {
6585 gl::Program *programObject = context->getProgram(program);
6586
6587 if (programObject)
6588 {
6589 return GL_TRUE;
6590 }
6591 }
6592 }
6593 catch(std::bad_alloc&)
6594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006595 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006596 }
6597
6598 return GL_FALSE;
6599}
6600
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006601GLboolean __stdcall glIsQueryEXT(GLuint id)
6602{
6603 EVENT("(GLuint id = %d)", id);
6604
6605 try
6606 {
6607 if (id == 0)
6608 {
6609 return GL_FALSE;
6610 }
6611
6612 gl::Context *context = gl::getNonLostContext();
6613
6614 if (context)
6615 {
6616 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6617
6618 if (queryObject)
6619 {
6620 return GL_TRUE;
6621 }
6622 }
6623 }
6624 catch(std::bad_alloc&)
6625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006626 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006627 }
6628
6629 return GL_FALSE;
6630}
6631
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006632GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6633{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006634 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006635
6636 try
6637 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006638 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006639
6640 if (context && renderbuffer)
6641 {
6642 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6643
6644 if (renderbufferObject)
6645 {
6646 return GL_TRUE;
6647 }
6648 }
6649 }
6650 catch(std::bad_alloc&)
6651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006652 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006653 }
6654
6655 return GL_FALSE;
6656}
6657
6658GLboolean __stdcall glIsShader(GLuint shader)
6659{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006660 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006661
6662 try
6663 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006664 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006665
6666 if (context && shader)
6667 {
6668 gl::Shader *shaderObject = context->getShader(shader);
6669
6670 if (shaderObject)
6671 {
6672 return GL_TRUE;
6673 }
6674 }
6675 }
6676 catch(std::bad_alloc&)
6677 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006678 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006679 }
6680
6681 return GL_FALSE;
6682}
6683
6684GLboolean __stdcall glIsTexture(GLuint texture)
6685{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006686 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006687
6688 try
6689 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006690 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006691
6692 if (context && texture)
6693 {
6694 gl::Texture *textureObject = context->getTexture(texture);
6695
6696 if (textureObject)
6697 {
6698 return GL_TRUE;
6699 }
6700 }
6701 }
6702 catch(std::bad_alloc&)
6703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006704 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006705 }
6706
6707 return GL_FALSE;
6708}
6709
6710void __stdcall glLineWidth(GLfloat width)
6711{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006712 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006713
6714 try
6715 {
6716 if (width <= 0.0f)
6717 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006718 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006719 }
6720
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006721 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006722
6723 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006724 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006725 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006726 }
6727 }
6728 catch(std::bad_alloc&)
6729 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006730 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006731 }
6732}
6733
6734void __stdcall glLinkProgram(GLuint program)
6735{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006736 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006737
6738 try
6739 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006740 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006741
6742 if (context)
6743 {
6744 gl::Program *programObject = context->getProgram(program);
6745
6746 if (!programObject)
6747 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006748 if (context->getShader(program))
6749 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006750 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006751 }
6752 else
6753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006754 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006755 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006756 }
6757
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006758 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006759 }
6760 }
6761 catch(std::bad_alloc&)
6762 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006763 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006764 }
6765}
6766
6767void __stdcall glPixelStorei(GLenum pname, GLint param)
6768{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006769 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006770
6771 try
6772 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006773 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006774
6775 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006776 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006777 switch (pname)
6778 {
6779 case GL_UNPACK_ALIGNMENT:
6780 if (param != 1 && param != 2 && param != 4 && param != 8)
6781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006783 }
6784
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006785 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006786 break;
6787
6788 case GL_PACK_ALIGNMENT:
6789 if (param != 1 && param != 2 && param != 4 && param != 8)
6790 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006791 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006792 }
6793
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006794 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006795 break;
6796
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006797 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6798 context->setPackReverseRowOrder(param != 0);
6799 break;
6800
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006801 case GL_UNPACK_IMAGE_HEIGHT:
6802 case GL_UNPACK_SKIP_IMAGES:
6803 case GL_UNPACK_ROW_LENGTH:
6804 case GL_UNPACK_SKIP_ROWS:
6805 case GL_UNPACK_SKIP_PIXELS:
6806 case GL_PACK_ROW_LENGTH:
6807 case GL_PACK_SKIP_ROWS:
6808 case GL_PACK_SKIP_PIXELS:
6809 if (context->getClientVersion() < 3)
6810 {
6811 return gl::error(GL_INVALID_ENUM);
6812 }
6813 UNIMPLEMENTED();
6814 break;
6815
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006816 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006817 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006818 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006819 }
6820 }
6821 catch(std::bad_alloc&)
6822 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006823 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006824 }
6825}
6826
6827void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6828{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006829 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006830
6831 try
6832 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006833 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006834
6835 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006836 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006837 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006838 }
6839 }
6840 catch(std::bad_alloc&)
6841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006842 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006843 }
6844}
6845
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006846void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6847 GLenum format, GLenum type, GLsizei bufSize,
6848 GLvoid *data)
6849{
6850 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6851 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6852 x, y, width, height, format, type, bufSize, data);
6853
6854 try
6855 {
6856 if (width < 0 || height < 0 || bufSize < 0)
6857 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006858 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006859 }
6860
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006861 gl::Context *context = gl::getNonLostContext();
6862
6863 if (context)
6864 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006865 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006866 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006867
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006868 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6869 // and attempting to read back if that's the case is an error. The error will be registered
6870 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006871 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006872 return;
6873
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006874 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6875 validES3ReadFormatType(currentInternalFormat, format, type);
6876
6877 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006879 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006880 }
6881
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006882 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6883 }
6884 }
6885 catch(std::bad_alloc&)
6886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006887 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006888 }
6889}
6890
6891void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6892 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006893{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006894 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006895 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006896 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006897
6898 try
6899 {
6900 if (width < 0 || height < 0)
6901 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006902 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006903 }
6904
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006905 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006906
6907 if (context)
6908 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006909 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006910 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006911
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006912 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6913 // and attempting to read back if that's the case is an error. The error will be registered
6914 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006915 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006916 return;
6917
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006918 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6919 validES3ReadFormatType(currentInternalFormat, format, type);
6920
6921 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006923 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006924 }
6925
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006926 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006927 }
6928 }
6929 catch(std::bad_alloc&)
6930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006931 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006932 }
6933}
6934
6935void __stdcall glReleaseShaderCompiler(void)
6936{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006937 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006938
6939 try
6940 {
6941 gl::Shader::releaseCompiler();
6942 }
6943 catch(std::bad_alloc&)
6944 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006945 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006946 }
6947}
6948
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006949void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006951 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 +00006952 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006953
6954 try
6955 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006956 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006957
6958 if (context)
6959 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006960 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6961 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006962 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006963 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006964 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006965
6966 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006967 }
6968 }
6969 catch(std::bad_alloc&)
6970 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006971 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006972 }
6973}
6974
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006975void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6976{
6977 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6978}
6979
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006980void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6981{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006982 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006983
6984 try
6985 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006986 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006987
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006988 if (context)
6989 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006990 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006991 }
6992 }
6993 catch(std::bad_alloc&)
6994 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006995 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006996 }
6997}
6998
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006999void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
7000{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007001 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007002
7003 try
7004 {
7005 if (condition != GL_ALL_COMPLETED_NV)
7006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007007 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007008 }
7009
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007010 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007011
7012 if (context)
7013 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007014 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007015
7016 if (fenceObject == NULL)
7017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007018 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007019 }
7020
7021 fenceObject->setFence(condition);
7022 }
7023 }
7024 catch(std::bad_alloc&)
7025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007026 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007027 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007028}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007029
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007030void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
7031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007032 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 +00007033
7034 try
7035 {
7036 if (width < 0 || height < 0)
7037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007038 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007039 }
7040
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007041 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007042
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007043 if (context)
7044 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007045 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007046 }
7047 }
7048 catch(std::bad_alloc&)
7049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007050 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007051 }
7052}
7053
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007054void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007056 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007057 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007058 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007059
7060 try
7061 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00007062 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007063 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007064 }
7065 catch(std::bad_alloc&)
7066 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007067 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007068 }
7069}
7070
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00007071void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007072{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007073 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 +00007074 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007075
7076 try
7077 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007078 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007080 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007081 }
7082
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007083 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007084
7085 if (context)
7086 {
7087 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007088
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007089 if (!shaderObject)
7090 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007091 if (context->getProgram(shader))
7092 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007093 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007094 }
7095 else
7096 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007097 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00007098 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007099 }
7100
7101 shaderObject->setSource(count, string, length);
7102 }
7103 }
7104 catch(std::bad_alloc&)
7105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007106 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007107 }
7108}
7109
7110void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
7111{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007112 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007113}
7114
7115void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
7116{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007117 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 +00007118
7119 try
7120 {
7121 switch (face)
7122 {
7123 case GL_FRONT:
7124 case GL_BACK:
7125 case GL_FRONT_AND_BACK:
7126 break;
7127 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007128 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007129 }
7130
7131 switch (func)
7132 {
7133 case GL_NEVER:
7134 case GL_ALWAYS:
7135 case GL_LESS:
7136 case GL_LEQUAL:
7137 case GL_EQUAL:
7138 case GL_GEQUAL:
7139 case GL_GREATER:
7140 case GL_NOTEQUAL:
7141 break;
7142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007143 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007144 }
7145
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007146 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007147
7148 if (context)
7149 {
7150 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7151 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007152 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007153 }
7154
7155 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7156 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007157 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007158 }
7159 }
7160 }
7161 catch(std::bad_alloc&)
7162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007163 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007164 }
7165}
7166
7167void __stdcall glStencilMask(GLuint mask)
7168{
7169 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
7170}
7171
7172void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
7173{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007174 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007175
7176 try
7177 {
7178 switch (face)
7179 {
7180 case GL_FRONT:
7181 case GL_BACK:
7182 case GL_FRONT_AND_BACK:
7183 break;
7184 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007185 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007186 }
7187
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007188 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007189
7190 if (context)
7191 {
7192 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7193 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007194 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007195 }
7196
7197 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7198 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007199 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007200 }
7201 }
7202 }
7203 catch(std::bad_alloc&)
7204 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007205 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007206 }
7207}
7208
7209void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
7210{
7211 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
7212}
7213
7214void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
7215{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007216 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 +00007217 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007218
7219 try
7220 {
7221 switch (face)
7222 {
7223 case GL_FRONT:
7224 case GL_BACK:
7225 case GL_FRONT_AND_BACK:
7226 break;
7227 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007228 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007229 }
7230
7231 switch (fail)
7232 {
7233 case GL_ZERO:
7234 case GL_KEEP:
7235 case GL_REPLACE:
7236 case GL_INCR:
7237 case GL_DECR:
7238 case GL_INVERT:
7239 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007240 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007241 break;
7242 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007243 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007244 }
7245
7246 switch (zfail)
7247 {
7248 case GL_ZERO:
7249 case GL_KEEP:
7250 case GL_REPLACE:
7251 case GL_INCR:
7252 case GL_DECR:
7253 case GL_INVERT:
7254 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007255 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007256 break;
7257 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007258 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007259 }
7260
7261 switch (zpass)
7262 {
7263 case GL_ZERO:
7264 case GL_KEEP:
7265 case GL_REPLACE:
7266 case GL_INCR:
7267 case GL_DECR:
7268 case GL_INVERT:
7269 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007270 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007271 break;
7272 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007273 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007274 }
7275
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007276 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007277
7278 if (context)
7279 {
7280 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7281 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007282 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007283 }
7284
7285 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7286 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007287 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007288 }
7289 }
7290 }
7291 catch(std::bad_alloc&)
7292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007293 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007294 }
7295}
7296
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007297GLboolean __stdcall glTestFenceNV(GLuint fence)
7298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007299 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007300
7301 try
7302 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007303 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007304
7305 if (context)
7306 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007307 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007308
7309 if (fenceObject == NULL)
7310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007311 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007312 }
7313
Jamie Madillfb9a7402013-07-26 11:55:01 -04007314 if (fenceObject->isFence() != GL_TRUE)
7315 {
7316 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
7317 }
7318
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007319 return fenceObject->testFence();
7320 }
7321 }
7322 catch(std::bad_alloc&)
7323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007324 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007325 }
7326
7327 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007328}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007329
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007330void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7331 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007332{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007333 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 +00007334 "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 +00007335 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007336
7337 try
7338 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007339 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007340
7341 if (context)
7342 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007343 if (context->getClientVersion() < 3 &&
7344 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7345 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007346 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007347 return;
7348 }
7349
7350 if (context->getClientVersion() >= 3 &&
7351 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7352 0, 0, 0, width, height, 1, border, format, type))
7353 {
7354 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007355 }
7356
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007357 switch (target)
7358 {
7359 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007360 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007361 gl::Texture2D *texture = context->getTexture2D();
7362 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007363 }
7364 break;
7365 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007366 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007367 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007368 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007369 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007370 break;
7371 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7372 {
7373 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7374 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7375 }
7376 break;
7377 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7378 {
7379 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7380 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7381 }
7382 break;
7383 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7384 {
7385 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7386 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7387 }
7388 break;
7389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7390 {
7391 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7392 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7393 }
7394 break;
7395 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7396 {
7397 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7398 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7399 }
7400 break;
7401 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007402 }
7403 }
7404 }
7405 catch(std::bad_alloc&)
7406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007407 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007408 }
7409}
7410
7411void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7412{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007413 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7414
7415 try
7416 {
7417 gl::Context *context = gl::getNonLostContext();
7418
7419 if (context)
7420 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007421 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7422 {
7423 return;
7424 }
7425
Jamie Madillfb8a8302013-07-03 14:24:12 -04007426 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007427
Jamie Madillfb8a8302013-07-03 14:24:12 -04007428 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007429 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007430 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007431 }
7432
7433 switch (pname)
7434 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007435 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7436 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7437 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7438 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7439 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7440 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7441 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7442 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7443 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007444
Jamie Madill478fdb22013-07-19 16:36:59 -04007445 case GL_TEXTURE_SWIZZLE_R:
7446 case GL_TEXTURE_SWIZZLE_G:
7447 case GL_TEXTURE_SWIZZLE_B:
7448 case GL_TEXTURE_SWIZZLE_A:
7449 case GL_TEXTURE_BASE_LEVEL:
7450 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007451 case GL_TEXTURE_MIN_LOD:
7452 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007453 UNIMPLEMENTED();
7454 break;
7455
Jamie Madill478fdb22013-07-19 16:36:59 -04007456 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007457 }
7458 }
7459 }
7460 catch(std::bad_alloc&)
7461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007462 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007463 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007464}
7465
7466void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7467{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007468 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007469}
7470
7471void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7472{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007473 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007474
7475 try
7476 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007477 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007478
7479 if (context)
7480 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007481 if (!validateTexParamParameters(context, pname, param))
7482 {
7483 return;
7484 }
7485
Jamie Madillfb8a8302013-07-03 14:24:12 -04007486 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007487
Jamie Madillfb8a8302013-07-03 14:24:12 -04007488 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007489 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007490 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007491 }
7492
7493 switch (pname)
7494 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007495 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7496 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7497 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7498 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7499 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7500 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7501 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7502 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7503 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007504
7505 case GL_TEXTURE_SWIZZLE_R:
7506 case GL_TEXTURE_SWIZZLE_G:
7507 case GL_TEXTURE_SWIZZLE_B:
7508 case GL_TEXTURE_SWIZZLE_A:
7509 case GL_TEXTURE_BASE_LEVEL:
7510 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007511 case GL_TEXTURE_MIN_LOD:
7512 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007513 UNIMPLEMENTED();
7514 break;
7515
Jamie Madill478fdb22013-07-19 16:36:59 -04007516 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007517 }
7518 }
7519 }
7520 catch(std::bad_alloc&)
7521 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007522 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007523 }
7524}
7525
7526void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7527{
7528 glTexParameteri(target, pname, *params);
7529}
7530
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007531void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7532{
7533 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7534 target, levels, internalformat, width, height);
7535
7536 try
7537 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007538 gl::Context *context = gl::getNonLostContext();
7539
7540 if (context)
7541 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007542 if (context->getClientVersion() < 3 &&
7543 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
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
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007548 if (context->getClientVersion() >= 3 &&
7549 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007550 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007551 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007552 }
7553
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007554 switch (target)
7555 {
7556 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007557 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007558 gl::Texture2D *texture2d = context->getTexture2D();
7559 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007560 }
7561 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007562
7563 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7564 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7565 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7566 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7567 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7568 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007569 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007570 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7571 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007572 }
7573 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007574
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007575 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007576 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007577 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007578 }
7579 }
7580 catch(std::bad_alloc&)
7581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007582 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007583 }
7584}
7585
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007586void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7587 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007588{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007589 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007590 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007591 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007592 target, level, xoffset, yoffset, width, height, format, type, pixels);
7593
7594 try
7595 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007596 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007597
7598 if (context)
7599 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007600 if (context->getClientVersion() < 3 &&
7601 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7602 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007603 {
7604 return;
7605 }
7606
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007607 if (context->getClientVersion() >= 3 &&
7608 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7609 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007610 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007611 return;
7612 }
7613
7614 switch (target)
7615 {
7616 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007617 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007618 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007619 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007620 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007621 break;
7622
7623 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7627 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7628 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007629 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007630 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007631 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007632 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007633 break;
7634
7635 default:
7636 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007637 }
7638 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007639 }
7640 catch(std::bad_alloc&)
7641 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007642 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007643 }
7644}
7645
7646void __stdcall glUniform1f(GLint location, GLfloat x)
7647{
7648 glUniform1fv(location, 1, &x);
7649}
7650
7651void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7652{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007653 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007654
7655 try
7656 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007657 if (count < 0)
7658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007659 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007660 }
7661
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007662 if (location == -1)
7663 {
7664 return;
7665 }
7666
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007667 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007668
7669 if (context)
7670 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007671 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007672 if (!programBinary)
7673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007674 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007675 }
7676
7677 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007679 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007680 }
7681 }
7682 }
7683 catch(std::bad_alloc&)
7684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007685 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007686 }
7687}
7688
7689void __stdcall glUniform1i(GLint location, GLint x)
7690{
7691 glUniform1iv(location, 1, &x);
7692}
7693
7694void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7695{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007696 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007697
7698 try
7699 {
7700 if (count < 0)
7701 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007702 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007703 }
7704
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007705 if (location == -1)
7706 {
7707 return;
7708 }
7709
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007710 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007711
7712 if (context)
7713 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007714 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007715 if (!programBinary)
7716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007717 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007718 }
7719
7720 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007722 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007723 }
7724 }
7725 }
7726 catch(std::bad_alloc&)
7727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007728 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007729 }
7730}
7731
7732void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7733{
7734 GLfloat xy[2] = {x, y};
7735
7736 glUniform2fv(location, 1, (GLfloat*)&xy);
7737}
7738
7739void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7740{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007741 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007742
7743 try
7744 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007745 if (count < 0)
7746 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007747 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007748 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007749
7750 if (location == -1)
7751 {
7752 return;
7753 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007754
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007755 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007756
7757 if (context)
7758 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007759 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007760 if (!programBinary)
7761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007762 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007763 }
7764
7765 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007767 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007768 }
7769 }
7770 }
7771 catch(std::bad_alloc&)
7772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007773 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007774 }
7775}
7776
7777void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7778{
7779 GLint xy[4] = {x, y};
7780
7781 glUniform2iv(location, 1, (GLint*)&xy);
7782}
7783
7784void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7785{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007786 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007787
7788 try
7789 {
7790 if (count < 0)
7791 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007792 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007793 }
7794
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007795 if (location == -1)
7796 {
7797 return;
7798 }
7799
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007800 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007801
7802 if (context)
7803 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007804 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007805 if (!programBinary)
7806 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007807 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007808 }
7809
7810 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007812 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007813 }
7814 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007815 }
7816 catch(std::bad_alloc&)
7817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007818 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007819 }
7820}
7821
7822void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7823{
7824 GLfloat xyz[3] = {x, y, z};
7825
7826 glUniform3fv(location, 1, (GLfloat*)&xyz);
7827}
7828
7829void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7830{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007831 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007832
7833 try
7834 {
7835 if (count < 0)
7836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007837 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007838 }
7839
7840 if (location == -1)
7841 {
7842 return;
7843 }
7844
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007845 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007846
7847 if (context)
7848 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007849 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007850 if (!programBinary)
7851 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007852 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007853 }
7854
7855 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007857 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007858 }
7859 }
7860 }
7861 catch(std::bad_alloc&)
7862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007863 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007864 }
7865}
7866
7867void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7868{
7869 GLint xyz[3] = {x, y, z};
7870
7871 glUniform3iv(location, 1, (GLint*)&xyz);
7872}
7873
7874void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7875{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007876 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007877
7878 try
7879 {
7880 if (count < 0)
7881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007882 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007883 }
7884
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007885 if (location == -1)
7886 {
7887 return;
7888 }
7889
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007890 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007891
7892 if (context)
7893 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007894 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007895 if (!programBinary)
7896 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007897 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007898 }
7899
7900 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007901 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007902 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007903 }
7904 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007905 }
7906 catch(std::bad_alloc&)
7907 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007908 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007909 }
7910}
7911
7912void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7913{
7914 GLfloat xyzw[4] = {x, y, z, w};
7915
7916 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7917}
7918
7919void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7920{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007921 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007922
7923 try
7924 {
7925 if (count < 0)
7926 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007927 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007928 }
7929
7930 if (location == -1)
7931 {
7932 return;
7933 }
7934
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007935 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007936
7937 if (context)
7938 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007939 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007940 if (!programBinary)
7941 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007942 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007943 }
7944
7945 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007946 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007947 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007948 }
7949 }
7950 }
7951 catch(std::bad_alloc&)
7952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007953 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007954 }
7955}
7956
7957void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7958{
7959 GLint xyzw[4] = {x, y, z, w};
7960
7961 glUniform4iv(location, 1, (GLint*)&xyzw);
7962}
7963
7964void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7965{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007966 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007967
7968 try
7969 {
7970 if (count < 0)
7971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007972 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007973 }
7974
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007975 if (location == -1)
7976 {
7977 return;
7978 }
7979
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007980 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007981
7982 if (context)
7983 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007984 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007985 if (!programBinary)
7986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007987 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007988 }
7989
7990 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007991 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007992 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007993 }
7994 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007995 }
7996 catch(std::bad_alloc&)
7997 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007998 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007999 }
8000}
8001
8002void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8003{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008004 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008005 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008006
8007 try
8008 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008009 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008011 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008012 }
8013
8014 if (location == -1)
8015 {
8016 return;
8017 }
8018
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008019 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008020
8021 if (context)
8022 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008023 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8024 {
8025 return gl::error(GL_INVALID_VALUE);
8026 }
8027
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008028 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008029 if (!programBinary)
8030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008031 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008032 }
8033
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008034 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008036 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008037 }
8038 }
8039 }
8040 catch(std::bad_alloc&)
8041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008042 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008043 }
8044}
8045
8046void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8047{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008048 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008049 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008050
8051 try
8052 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008053 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008055 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008056 }
8057
8058 if (location == -1)
8059 {
8060 return;
8061 }
8062
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008063 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008064
8065 if (context)
8066 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008067 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8068 {
8069 return gl::error(GL_INVALID_VALUE);
8070 }
8071
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008072 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008073 if (!programBinary)
8074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008075 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008076 }
8077
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008078 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008080 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008081 }
8082 }
8083 }
8084 catch(std::bad_alloc&)
8085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008086 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008087 }
8088}
8089
8090void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8091{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008092 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008093 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008094
8095 try
8096 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008097 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008099 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008100 }
8101
8102 if (location == -1)
8103 {
8104 return;
8105 }
8106
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008107 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008108
8109 if (context)
8110 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008111 if (transpose != GL_FALSE && context->getClientVersion() < 3)
8112 {
8113 return gl::error(GL_INVALID_VALUE);
8114 }
8115
daniel@transgaming.com62a28462012-07-24 18:33:59 +00008116 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008117 if (!programBinary)
8118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008119 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00008120 }
8121
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008122 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008123 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008124 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008125 }
8126 }
8127 }
8128 catch(std::bad_alloc&)
8129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008130 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008131 }
8132}
8133
8134void __stdcall glUseProgram(GLuint program)
8135{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008136 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008137
8138 try
8139 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008140 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008141
8142 if (context)
8143 {
8144 gl::Program *programObject = context->getProgram(program);
8145
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008146 if (!programObject && program != 0)
8147 {
8148 if (context->getShader(program))
8149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008150 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008151 }
8152 else
8153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008154 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00008155 }
8156 }
8157
daniel@transgaming.com716056c2012-07-24 18:38:59 +00008158 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008160 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008161 }
8162
8163 context->useProgram(program);
8164 }
8165 }
8166 catch(std::bad_alloc&)
8167 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008168 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008169 }
8170}
8171
8172void __stdcall glValidateProgram(GLuint program)
8173{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008174 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008175
8176 try
8177 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008178 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008179
8180 if (context)
8181 {
8182 gl::Program *programObject = context->getProgram(program);
8183
8184 if (!programObject)
8185 {
8186 if (context->getShader(program))
8187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008188 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008189 }
8190 else
8191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008192 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008193 }
8194 }
8195
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00008196 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00008197 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008198 }
8199 catch(std::bad_alloc&)
8200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008201 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008202 }
8203}
8204
8205void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
8206{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008207 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008208
8209 try
8210 {
8211 if (index >= gl::MAX_VERTEX_ATTRIBS)
8212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008213 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008214 }
8215
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008216 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008217
8218 if (context)
8219 {
8220 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008221 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008222 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008223 }
8224 catch(std::bad_alloc&)
8225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008226 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008227 }
8228}
8229
8230void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
8231{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008232 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008233
8234 try
8235 {
8236 if (index >= gl::MAX_VERTEX_ATTRIBS)
8237 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008238 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008239 }
8240
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008241 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008242
8243 if (context)
8244 {
8245 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008246 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008247 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008248 }
8249 catch(std::bad_alloc&)
8250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008251 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008252 }
8253}
8254
8255void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008257 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008258
8259 try
8260 {
8261 if (index >= gl::MAX_VERTEX_ATTRIBS)
8262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008263 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008264 }
8265
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008266 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008267
8268 if (context)
8269 {
8270 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008271 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008272 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008273 }
8274 catch(std::bad_alloc&)
8275 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008276 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008277 }
8278}
8279
8280void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8281{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008282 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008283
8284 try
8285 {
8286 if (index >= gl::MAX_VERTEX_ATTRIBS)
8287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008288 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008289 }
8290
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008291 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008292
8293 if (context)
8294 {
8295 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008296 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008297 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008298 }
8299 catch(std::bad_alloc&)
8300 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008301 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008302 }
8303}
8304
8305void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8306{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008307 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 +00008308
8309 try
8310 {
8311 if (index >= gl::MAX_VERTEX_ATTRIBS)
8312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008313 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008314 }
8315
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008316 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008317
8318 if (context)
8319 {
8320 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008321 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008322 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008323 }
8324 catch(std::bad_alloc&)
8325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008326 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008327 }
8328}
8329
8330void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8331{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008332 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008333
8334 try
8335 {
8336 if (index >= gl::MAX_VERTEX_ATTRIBS)
8337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008338 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008339 }
8340
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008341 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008342
8343 if (context)
8344 {
8345 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008346 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008347 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008348 }
8349 catch(std::bad_alloc&)
8350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008351 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008352 }
8353}
8354
8355void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8356{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008357 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 +00008358
8359 try
8360 {
8361 if (index >= gl::MAX_VERTEX_ATTRIBS)
8362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008363 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008364 }
8365
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008366 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008367
8368 if (context)
8369 {
8370 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008371 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008372 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008373 }
8374 catch(std::bad_alloc&)
8375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008376 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008377 }
8378}
8379
8380void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008382 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008383
8384 try
8385 {
8386 if (index >= gl::MAX_VERTEX_ATTRIBS)
8387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008388 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008389 }
8390
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008391 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008392
8393 if (context)
8394 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008395 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008396 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008397 }
8398 catch(std::bad_alloc&)
8399 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008400 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008401 }
8402}
8403
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008404void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8405{
8406 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8407
8408 try
8409 {
8410 if (index >= gl::MAX_VERTEX_ATTRIBS)
8411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008412 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008413 }
8414
8415 gl::Context *context = gl::getNonLostContext();
8416
8417 if (context)
8418 {
8419 context->setVertexAttribDivisor(index, divisor);
8420 }
8421 }
8422 catch(std::bad_alloc&)
8423 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008424 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008425 }
8426}
8427
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008428void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008429{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008430 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008431 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008432 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008433
8434 try
8435 {
8436 if (index >= gl::MAX_VERTEX_ATTRIBS)
8437 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008438 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008439 }
8440
8441 if (size < 1 || size > 4)
8442 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008443 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008444 }
8445
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008446 gl::Context *context = gl::getNonLostContext();
8447
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008448 switch (type)
8449 {
8450 case GL_BYTE:
8451 case GL_UNSIGNED_BYTE:
8452 case GL_SHORT:
8453 case GL_UNSIGNED_SHORT:
8454 case GL_FIXED:
8455 case GL_FLOAT:
8456 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008457 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008458 case GL_INT:
8459 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008460 case GL_INT_2_10_10_10_REV:
8461 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008462 if (context && context->getClientVersion() < 3)
8463 {
8464 return gl::error(GL_INVALID_ENUM);
8465 }
8466 else
8467 {
8468 break;
8469 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008470 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008471 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008472 }
8473
8474 if (stride < 0)
8475 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008476 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008477 }
8478
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008479 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8480 {
8481 return gl::error(GL_INVALID_OPERATION);
8482 }
8483
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008484 if (context)
8485 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008486 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8487 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8488 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8489 // and the pointer argument is not NULL.
8490 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8491 {
8492 return gl::error(GL_INVALID_OPERATION);
8493 }
8494
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008495 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8496 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008497 }
8498 }
8499 catch(std::bad_alloc&)
8500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008501 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008502 }
8503}
8504
8505void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8506{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008507 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 +00008508
8509 try
8510 {
8511 if (width < 0 || height < 0)
8512 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008513 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008514 }
8515
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008516 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008517
8518 if (context)
8519 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008520 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008521 }
8522 }
8523 catch(std::bad_alloc&)
8524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008525 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008526 }
8527}
8528
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008529// OpenGL ES 3.0 functions
8530
8531void __stdcall glReadBuffer(GLenum mode)
8532{
8533 EVENT("(GLenum mode = 0x%X)", mode);
8534
8535 try
8536 {
8537 gl::Context *context = gl::getNonLostContext();
8538
8539 if (context)
8540 {
8541 if (context->getClientVersion() < 3)
8542 {
8543 return gl::error(GL_INVALID_OPERATION);
8544 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008545
Jamie Madill54133512013-06-21 09:33:07 -04008546 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008547 UNIMPLEMENTED();
8548 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008549 }
8550 catch(std::bad_alloc&)
8551 {
8552 return gl::error(GL_OUT_OF_MEMORY);
8553 }
8554}
8555
8556void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8557{
8558 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8559 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8560
8561 try
8562 {
8563 gl::Context *context = gl::getNonLostContext();
8564
8565 if (context)
8566 {
8567 if (context->getClientVersion() < 3)
8568 {
8569 return gl::error(GL_INVALID_OPERATION);
8570 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008571
Jamie Madill54133512013-06-21 09:33:07 -04008572 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008573 UNIMPLEMENTED();
8574 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008575 }
8576 catch(std::bad_alloc&)
8577 {
8578 return gl::error(GL_OUT_OF_MEMORY);
8579 }
8580}
8581
8582void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8583{
8584 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8585 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8586 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8587 target, level, internalformat, width, height, depth, border, format, type, pixels);
8588
8589 try
8590 {
8591 gl::Context *context = gl::getNonLostContext();
8592
8593 if (context)
8594 {
8595 if (context->getClientVersion() < 3)
8596 {
8597 return gl::error(GL_INVALID_OPERATION);
8598 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008599
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008600 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008601 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008602 0, 0, 0, width, height, depth, border, format, type))
8603 {
8604 return;
8605 }
8606
8607 switch(target)
8608 {
8609 case GL_TEXTURE_3D:
8610 {
8611 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008612 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008613 }
8614 break;
8615
8616 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008617 {
8618 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008619 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008620 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008621 break;
8622
8623 default:
8624 return gl::error(GL_INVALID_ENUM);
8625 }
8626 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008627 }
8628 catch(std::bad_alloc&)
8629 {
8630 return gl::error(GL_OUT_OF_MEMORY);
8631 }
8632}
8633
8634void __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)
8635{
8636 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8637 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8638 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8639 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8640
8641 try
8642 {
8643 gl::Context *context = gl::getNonLostContext();
8644
8645 if (context)
8646 {
8647 if (context->getClientVersion() < 3)
8648 {
8649 return gl::error(GL_INVALID_OPERATION);
8650 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008651
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008652 if (!pixels)
8653 {
8654 return gl::error(GL_INVALID_VALUE);
8655 }
8656
8657 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008658 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008659 xoffset, yoffset, zoffset, width, height, depth, 0,
8660 format, type))
8661 {
8662 return;
8663 }
8664
8665 switch(target)
8666 {
8667 case GL_TEXTURE_3D:
8668 {
8669 gl::Texture3D *texture = context->getTexture3D();
8670 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8671 }
8672 break;
8673
8674 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008675 {
8676 gl::Texture2DArray *texture = context->getTexture2DArray();
8677 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8678 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008679 break;
8680
8681 default:
8682 return gl::error(GL_INVALID_ENUM);
8683 }
8684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008685 }
8686 catch(std::bad_alloc&)
8687 {
8688 return gl::error(GL_OUT_OF_MEMORY);
8689 }
8690}
8691
8692void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8693{
8694 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8695 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8696 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8697
8698 try
8699 {
8700 gl::Context *context = gl::getNonLostContext();
8701
8702 if (context)
8703 {
8704 if (context->getClientVersion() < 3)
8705 {
8706 return gl::error(GL_INVALID_OPERATION);
8707 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008708
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008709 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8710 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008711 {
8712 return;
8713 }
8714
8715 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8716 gl::Texture *texture = NULL;
8717 switch (target)
8718 {
8719 case GL_TEXTURE_3D:
8720 texture = context->getTexture3D();
8721 break;
8722
8723 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008724 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008725 break;
8726
8727 default:
8728 return gl::error(GL_INVALID_ENUM);
8729 }
8730
8731 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8732 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008733 }
8734 catch(std::bad_alloc&)
8735 {
8736 return gl::error(GL_OUT_OF_MEMORY);
8737 }
8738}
8739
8740void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8741{
8742 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8743 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8744 "const GLvoid* data = 0x%0.8p)",
8745 target, level, internalformat, width, height, depth, border, imageSize, data);
8746
8747 try
8748 {
8749 gl::Context *context = gl::getNonLostContext();
8750
8751 if (context)
8752 {
8753 if (context->getClientVersion() < 3)
8754 {
8755 return gl::error(GL_INVALID_OPERATION);
8756 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008757
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008758 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 +00008759 {
8760 return gl::error(GL_INVALID_VALUE);
8761 }
8762
8763 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008764 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8765 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008766 {
8767 return;
8768 }
8769
8770 switch(target)
8771 {
8772 case GL_TEXTURE_3D:
8773 {
8774 gl::Texture3D *texture = context->getTexture3D();
8775 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8776 }
8777 break;
8778
8779 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008780 {
8781 gl::Texture2DArray *texture = context->getTexture2DArray();
8782 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8783 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008784 break;
8785
8786 default:
8787 return gl::error(GL_INVALID_ENUM);
8788 }
8789 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008790 }
8791 catch(std::bad_alloc&)
8792 {
8793 return gl::error(GL_OUT_OF_MEMORY);
8794 }
8795}
8796
8797void __stdcall glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
8798{
8799 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8800 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8801 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8802 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8803
8804 try
8805 {
8806 gl::Context *context = gl::getNonLostContext();
8807
8808 if (context)
8809 {
8810 if (context->getClientVersion() < 3)
8811 {
8812 return gl::error(GL_INVALID_OPERATION);
8813 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008814
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008815 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 +00008816 {
8817 return gl::error(GL_INVALID_VALUE);
8818 }
8819
8820 if (!data)
8821 {
8822 return gl::error(GL_INVALID_VALUE);
8823 }
8824
8825 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008826 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8827 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008828 {
8829 return;
8830 }
8831
8832 switch(target)
8833 {
8834 case GL_TEXTURE_3D:
8835 {
8836 gl::Texture3D *texture = context->getTexture3D();
8837 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8838 format, imageSize, data);
8839 }
8840 break;
8841
8842 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008843 {
8844 gl::Texture2DArray *texture = context->getTexture2DArray();
8845 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8846 format, imageSize, data);
8847 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008848 break;
8849
8850 default:
8851 return gl::error(GL_INVALID_ENUM);
8852 }
8853 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008854 }
8855 catch(std::bad_alloc&)
8856 {
8857 return gl::error(GL_OUT_OF_MEMORY);
8858 }
8859}
8860
8861void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8862{
8863 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8864
8865 try
8866 {
8867 gl::Context *context = gl::getNonLostContext();
8868
8869 if (context)
8870 {
8871 if (context->getClientVersion() < 3)
8872 {
8873 return gl::error(GL_INVALID_OPERATION);
8874 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008875
Jamie Madill3641b4b2013-07-26 12:54:59 -04008876 glGenQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008877 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008878 }
8879 catch(std::bad_alloc&)
8880 {
8881 return gl::error(GL_OUT_OF_MEMORY);
8882 }
8883}
8884
8885void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8886{
8887 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8888
8889 try
8890 {
8891 gl::Context *context = gl::getNonLostContext();
8892
8893 if (context)
8894 {
8895 if (context->getClientVersion() < 3)
8896 {
8897 return gl::error(GL_INVALID_OPERATION);
8898 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008899
Jamie Madill3641b4b2013-07-26 12:54:59 -04008900 glDeleteQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008901 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008902 }
8903 catch(std::bad_alloc&)
8904 {
8905 return gl::error(GL_OUT_OF_MEMORY);
8906 }
8907}
8908
8909GLboolean __stdcall glIsQuery(GLuint id)
8910{
8911 EVENT("(GLuint id = %u)", id);
8912
8913 try
8914 {
8915 gl::Context *context = gl::getNonLostContext();
8916
8917 if (context)
8918 {
8919 if (context->getClientVersion() < 3)
8920 {
8921 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8922 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008923
Jamie Madill3641b4b2013-07-26 12:54:59 -04008924 // TODO: XFB queries
8925 return glIsQueryEXT(id);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008926 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008927 }
8928 catch(std::bad_alloc&)
8929 {
8930 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8931 }
8932
8933 return GL_FALSE;
8934}
8935
8936void __stdcall glBeginQuery(GLenum target, GLuint id)
8937{
8938 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8939
8940 try
8941 {
8942 gl::Context *context = gl::getNonLostContext();
8943
8944 if (context)
8945 {
8946 if (context->getClientVersion() < 3)
8947 {
8948 return gl::error(GL_INVALID_OPERATION);
8949 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008950
Jamie Madill3641b4b2013-07-26 12:54:59 -04008951 switch (target)
8952 {
8953 case GL_ANY_SAMPLES_PASSED:
8954 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
8955 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
8956 break;
8957 default:
8958 return gl::error(GL_INVALID_ENUM);
8959 }
8960
8961 if (id == 0)
8962 {
8963 return gl::error(GL_INVALID_OPERATION);
8964 }
8965
8966 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8967 {
8968 // TODO: XFB queries
8969 UNIMPLEMENTED();
8970 }
8971 else
8972 {
8973 context->beginQuery(target, id);
8974 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008975 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008976 }
8977 catch(std::bad_alloc&)
8978 {
8979 return gl::error(GL_OUT_OF_MEMORY);
8980 }
8981}
8982
8983void __stdcall glEndQuery(GLenum target)
8984{
8985 EVENT("(GLenum target = 0x%X)", target);
8986
8987 try
8988 {
8989 gl::Context *context = gl::getNonLostContext();
8990
8991 if (context)
8992 {
8993 if (context->getClientVersion() < 3)
8994 {
8995 return gl::error(GL_INVALID_OPERATION);
8996 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008997
Jamie Madill3641b4b2013-07-26 12:54:59 -04008998 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8999 {
9000 // TODO: XFB queries
9001 UNIMPLEMENTED();
9002 }
9003 else
9004 {
9005 glEndQueryEXT(target);
9006 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009008 }
9009 catch(std::bad_alloc&)
9010 {
9011 return gl::error(GL_OUT_OF_MEMORY);
9012 }
9013}
9014
9015void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
9016{
9017 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
9018
9019 try
9020 {
9021 gl::Context *context = gl::getNonLostContext();
9022
9023 if (context)
9024 {
9025 if (context->getClientVersion() < 3)
9026 {
9027 return gl::error(GL_INVALID_OPERATION);
9028 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009029
Jamie Madill3641b4b2013-07-26 12:54:59 -04009030 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
9031 {
9032 // TODO: XFB queries
9033 UNIMPLEMENTED();
9034 }
9035 else
9036 {
9037 glGetQueryivEXT(target, pname, params);
9038 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009039 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009040 }
9041 catch(std::bad_alloc&)
9042 {
9043 return gl::error(GL_OUT_OF_MEMORY);
9044 }
9045}
9046
9047void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
9048{
9049 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
9050
9051 try
9052 {
9053 gl::Context *context = gl::getNonLostContext();
9054
9055 if (context)
9056 {
9057 if (context->getClientVersion() < 3)
9058 {
9059 return gl::error(GL_INVALID_OPERATION);
9060 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009061
Jamie Madill3641b4b2013-07-26 12:54:59 -04009062 // TODO: XFB queries
9063 glGetQueryObjectuivEXT(id, pname, params);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009064 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009065 }
9066 catch(std::bad_alloc&)
9067 {
9068 return gl::error(GL_OUT_OF_MEMORY);
9069 }
9070}
9071
9072GLboolean __stdcall glUnmapBuffer(GLenum target)
9073{
9074 EVENT("(GLenum target = 0x%X)", target);
9075
9076 try
9077 {
9078 gl::Context *context = gl::getNonLostContext();
9079
9080 if (context)
9081 {
9082 if (context->getClientVersion() < 3)
9083 {
9084 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9085 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009086
Jamie Madill54133512013-06-21 09:33:07 -04009087 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009088 UNIMPLEMENTED();
9089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009090 }
9091 catch(std::bad_alloc&)
9092 {
9093 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9094 }
9095
9096 return GL_FALSE;
9097}
9098
9099void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
9100{
9101 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
9102
9103 try
9104 {
9105 gl::Context *context = gl::getNonLostContext();
9106
9107 if (context)
9108 {
9109 if (context->getClientVersion() < 3)
9110 {
9111 return gl::error(GL_INVALID_OPERATION);
9112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009113
Jamie Madill54133512013-06-21 09:33:07 -04009114 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00009115 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009116 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009117 }
9118 catch(std::bad_alloc&)
9119 {
9120 return gl::error(GL_OUT_OF_MEMORY);
9121 }
9122}
9123
9124void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
9125{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009126 try
9127 {
9128 gl::Context *context = gl::getNonLostContext();
9129
9130 if (context)
9131 {
9132 if (context->getClientVersion() < 3)
9133 {
9134 return gl::error(GL_INVALID_OPERATION);
9135 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009136
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00009137 glDrawBuffersEXT(n, bufs);
9138 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009139 }
9140 catch(std::bad_alloc&)
9141 {
9142 return gl::error(GL_OUT_OF_MEMORY);
9143 }
9144}
9145
9146void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9147{
9148 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9149 location, count, transpose, value);
9150
9151 try
9152 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009153 if (count < 0)
9154 {
9155 return gl::error(GL_INVALID_VALUE);
9156 }
9157
9158 if (location == -1)
9159 {
9160 return;
9161 }
9162
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009163 gl::Context *context = gl::getNonLostContext();
9164
9165 if (context)
9166 {
9167 if (context->getClientVersion() < 3)
9168 {
9169 return gl::error(GL_INVALID_OPERATION);
9170 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009171
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009172 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9173 if (!programBinary)
9174 {
9175 return gl::error(GL_INVALID_OPERATION);
9176 }
9177
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009178 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009179 {
9180 return gl::error(GL_INVALID_OPERATION);
9181 }
9182 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009183 }
9184 catch(std::bad_alloc&)
9185 {
9186 return gl::error(GL_OUT_OF_MEMORY);
9187 }
9188}
9189
9190void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9191{
9192 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9193 location, count, transpose, value);
9194
9195 try
9196 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009197 if (count < 0)
9198 {
9199 return gl::error(GL_INVALID_VALUE);
9200 }
9201
9202 if (location == -1)
9203 {
9204 return;
9205 }
9206
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009207 gl::Context *context = gl::getNonLostContext();
9208
9209 if (context)
9210 {
9211 if (context->getClientVersion() < 3)
9212 {
9213 return gl::error(GL_INVALID_OPERATION);
9214 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009215
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009216 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9217 if (!programBinary)
9218 {
9219 return gl::error(GL_INVALID_OPERATION);
9220 }
9221
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009222 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009223 {
9224 return gl::error(GL_INVALID_OPERATION);
9225 }
9226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009227 }
9228 catch(std::bad_alloc&)
9229 {
9230 return gl::error(GL_OUT_OF_MEMORY);
9231 }
9232}
9233
9234void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9235{
9236 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9237 location, count, transpose, value);
9238
9239 try
9240 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009241 if (count < 0)
9242 {
9243 return gl::error(GL_INVALID_VALUE);
9244 }
9245
9246 if (location == -1)
9247 {
9248 return;
9249 }
9250
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009251 gl::Context *context = gl::getNonLostContext();
9252
9253 if (context)
9254 {
9255 if (context->getClientVersion() < 3)
9256 {
9257 return gl::error(GL_INVALID_OPERATION);
9258 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009259
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009260 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9261 if (!programBinary)
9262 {
9263 return gl::error(GL_INVALID_OPERATION);
9264 }
9265
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009266 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009267 {
9268 return gl::error(GL_INVALID_OPERATION);
9269 }
9270 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009271 }
9272 catch(std::bad_alloc&)
9273 {
9274 return gl::error(GL_OUT_OF_MEMORY);
9275 }
9276}
9277
9278void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9279{
9280 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9281 location, count, transpose, value);
9282
9283 try
9284 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009285 if (count < 0)
9286 {
9287 return gl::error(GL_INVALID_VALUE);
9288 }
9289
9290 if (location == -1)
9291 {
9292 return;
9293 }
9294
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009295 gl::Context *context = gl::getNonLostContext();
9296
9297 if (context)
9298 {
9299 if (context->getClientVersion() < 3)
9300 {
9301 return gl::error(GL_INVALID_OPERATION);
9302 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009303
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009304 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9305 if (!programBinary)
9306 {
9307 return gl::error(GL_INVALID_OPERATION);
9308 }
9309
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009310 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009311 {
9312 return gl::error(GL_INVALID_OPERATION);
9313 }
9314 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009315 }
9316 catch(std::bad_alloc&)
9317 {
9318 return gl::error(GL_OUT_OF_MEMORY);
9319 }
9320}
9321
9322void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9323{
9324 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9325 location, count, transpose, value);
9326
9327 try
9328 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009329 if (count < 0)
9330 {
9331 return gl::error(GL_INVALID_VALUE);
9332 }
9333
9334 if (location == -1)
9335 {
9336 return;
9337 }
9338
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009339 gl::Context *context = gl::getNonLostContext();
9340
9341 if (context)
9342 {
9343 if (context->getClientVersion() < 3)
9344 {
9345 return gl::error(GL_INVALID_OPERATION);
9346 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009347
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009348 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9349 if (!programBinary)
9350 {
9351 return gl::error(GL_INVALID_OPERATION);
9352 }
9353
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009354 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009355 {
9356 return gl::error(GL_INVALID_OPERATION);
9357 }
9358 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009359 }
9360 catch(std::bad_alloc&)
9361 {
9362 return gl::error(GL_OUT_OF_MEMORY);
9363 }
9364}
9365
9366void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9367{
9368 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9369 location, count, transpose, value);
9370
9371 try
9372 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009373 if (count < 0)
9374 {
9375 return gl::error(GL_INVALID_VALUE);
9376 }
9377
9378 if (location == -1)
9379 {
9380 return;
9381 }
9382
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009383 gl::Context *context = gl::getNonLostContext();
9384
9385 if (context)
9386 {
9387 if (context->getClientVersion() < 3)
9388 {
9389 return gl::error(GL_INVALID_OPERATION);
9390 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009391
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009392 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9393 if (!programBinary)
9394 {
9395 return gl::error(GL_INVALID_OPERATION);
9396 }
9397
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009398 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009399 {
9400 return gl::error(GL_INVALID_OPERATION);
9401 }
9402 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009403 }
9404 catch(std::bad_alloc&)
9405 {
9406 return gl::error(GL_OUT_OF_MEMORY);
9407 }
9408}
9409
9410void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9411{
9412 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9413 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9414 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9415
9416 try
9417 {
9418 gl::Context *context = gl::getNonLostContext();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009419 if (context)
9420 {
9421 if (context->getClientVersion() < 3)
9422 {
9423 return gl::error(GL_INVALID_OPERATION);
9424 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009425
Geoff Lang758d5b22013-06-11 11:42:50 -04009426 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9427 dstX0, dstY0, dstX1, dstY1, mask, filter,
9428 false))
9429 {
9430 return;
9431 }
9432
9433 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9434 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009435 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009436 }
9437 catch(std::bad_alloc&)
9438 {
9439 return gl::error(GL_OUT_OF_MEMORY);
9440 }
9441}
9442
9443void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9444{
9445 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9446 target, samples, internalformat, width, height);
9447
9448 try
9449 {
9450 gl::Context *context = gl::getNonLostContext();
9451
9452 if (context)
9453 {
9454 if (context->getClientVersion() < 3)
9455 {
9456 return gl::error(GL_INVALID_OPERATION);
9457 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009458
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009459 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9460 width, height, false))
9461 {
9462 return;
9463 }
9464
9465 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009466 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009467 }
9468 catch(std::bad_alloc&)
9469 {
9470 return gl::error(GL_OUT_OF_MEMORY);
9471 }
9472}
9473
9474void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9475{
9476 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9477 target, attachment, texture, level, layer);
9478
9479 try
9480 {
9481 gl::Context *context = gl::getNonLostContext();
9482
9483 if (context)
9484 {
9485 if (context->getClientVersion() < 3)
9486 {
9487 return gl::error(GL_INVALID_OPERATION);
9488 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009489
Geoff Lang3ed0c482013-07-25 17:03:18 -04009490 if (!validateES3FramebufferTextureParameters(context, target, attachment, GL_NONE, texture, level, layer, true))
9491 {
9492 return;
9493 }
9494
9495 gl::Framebuffer *framebuffer = NULL;
9496 if (target == GL_READ_FRAMEBUFFER)
9497 {
9498 framebuffer = context->getReadFramebuffer();
9499 }
9500 else
9501 {
9502 framebuffer = context->getDrawFramebuffer();
9503 }
9504
9505 gl::Texture *textureObject = context->getTexture(texture);
9506 GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
9507
9508 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
9509 {
9510 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
9511 framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
9512 }
9513 else
9514 {
9515 switch (attachment)
9516 {
9517 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture, level, layer); break;
9518 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture, level, layer); break;
9519 case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
9520 }
9521 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009522 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009523 }
9524 catch(std::bad_alloc&)
9525 {
9526 return gl::error(GL_OUT_OF_MEMORY);
9527 }
9528}
9529
9530GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9531{
9532 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9533 target, offset, length, access);
9534
9535 try
9536 {
9537 gl::Context *context = gl::getNonLostContext();
9538
9539 if (context)
9540 {
9541 if (context->getClientVersion() < 3)
9542 {
9543 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9544 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009545
Jamie Madill54133512013-06-21 09:33:07 -04009546 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009547 UNIMPLEMENTED();
9548 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009549 }
9550 catch(std::bad_alloc&)
9551 {
9552 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9553 }
9554
9555 return NULL;
9556}
9557
9558void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9559{
9560 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9561
9562 try
9563 {
9564 gl::Context *context = gl::getNonLostContext();
9565
9566 if (context)
9567 {
9568 if (context->getClientVersion() < 3)
9569 {
9570 return gl::error(GL_INVALID_OPERATION);
9571 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009572
Jamie Madill54133512013-06-21 09:33:07 -04009573 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009574 UNIMPLEMENTED();
9575 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009576 }
9577 catch(std::bad_alloc&)
9578 {
9579 return gl::error(GL_OUT_OF_MEMORY);
9580 }
9581}
9582
9583void __stdcall glBindVertexArray(GLuint array)
9584{
9585 EVENT("(GLuint array = %u)", array);
9586
9587 try
9588 {
9589 gl::Context *context = gl::getNonLostContext();
9590
9591 if (context)
9592 {
9593 if (context->getClientVersion() < 3)
9594 {
9595 return gl::error(GL_INVALID_OPERATION);
9596 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009597
Jamie Madilld1028542013-07-02 11:57:04 -04009598 gl::VertexArray *vao = context->getVertexArray(array);
9599
9600 if (!vao)
9601 {
9602 // The default VAO should always exist
9603 ASSERT(array != 0);
9604 return gl::error(GL_INVALID_OPERATION);
9605 }
9606
9607 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009608 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009609 }
9610 catch(std::bad_alloc&)
9611 {
9612 return gl::error(GL_OUT_OF_MEMORY);
9613 }
9614}
9615
9616void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9617{
9618 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9619
9620 try
9621 {
9622 gl::Context *context = gl::getNonLostContext();
9623
9624 if (context)
9625 {
9626 if (context->getClientVersion() < 3)
9627 {
9628 return gl::error(GL_INVALID_OPERATION);
9629 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009630
Jamie Madilld1028542013-07-02 11:57:04 -04009631 if (n < 0)
9632 {
9633 return gl::error(GL_INVALID_VALUE);
9634 }
9635
9636 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9637 {
9638 if (arrays[arrayIndex] != 0)
9639 {
9640 context->deleteVertexArray(arrays[arrayIndex]);
9641 }
9642 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009643 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009644 }
9645 catch(std::bad_alloc&)
9646 {
9647 return gl::error(GL_OUT_OF_MEMORY);
9648 }
9649}
9650
9651void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9652{
9653 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9654
9655 try
9656 {
9657 gl::Context *context = gl::getNonLostContext();
9658
9659 if (context)
9660 {
9661 if (context->getClientVersion() < 3)
9662 {
9663 return gl::error(GL_INVALID_OPERATION);
9664 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009665
Jamie Madilld1028542013-07-02 11:57:04 -04009666 if (n < 0)
9667 {
9668 return gl::error(GL_INVALID_VALUE);
9669 }
9670
9671 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9672 {
9673 arrays[arrayIndex] = context->createVertexArray();
9674 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009675 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009676 }
9677 catch(std::bad_alloc&)
9678 {
9679 return gl::error(GL_OUT_OF_MEMORY);
9680 }
9681}
9682
9683GLboolean __stdcall glIsVertexArray(GLuint array)
9684{
9685 EVENT("(GLuint array = %u)", array);
9686
9687 try
9688 {
9689 gl::Context *context = gl::getNonLostContext();
9690
9691 if (context)
9692 {
9693 if (context->getClientVersion() < 3)
9694 {
9695 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9696 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009697
Jamie Madilld1028542013-07-02 11:57:04 -04009698 if (array == 0)
9699 {
9700 return GL_FALSE;
9701 }
9702
9703 gl::VertexArray *vao = context->getVertexArray(array);
9704
9705 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009706 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009707 }
9708 catch(std::bad_alloc&)
9709 {
9710 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9711 }
9712
9713 return GL_FALSE;
9714}
9715
9716void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9717{
9718 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9719 target, index, data);
9720
9721 try
9722 {
9723 gl::Context *context = gl::getNonLostContext();
9724
9725 if (context)
9726 {
9727 if (context->getClientVersion() < 3)
9728 {
9729 return gl::error(GL_INVALID_OPERATION);
9730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009731
Jamie Madill54133512013-06-21 09:33:07 -04009732 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009733 UNIMPLEMENTED();
9734 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009735 }
9736 catch(std::bad_alloc&)
9737 {
9738 return gl::error(GL_OUT_OF_MEMORY);
9739 }
9740}
9741
9742void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9743{
9744 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9745
9746 try
9747 {
9748 gl::Context *context = gl::getNonLostContext();
9749
9750 if (context)
9751 {
9752 if (context->getClientVersion() < 3)
9753 {
9754 return gl::error(GL_INVALID_OPERATION);
9755 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009756
Jamie Madill54133512013-06-21 09:33:07 -04009757 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009758 UNIMPLEMENTED();
9759 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009760 }
9761 catch(std::bad_alloc&)
9762 {
9763 return gl::error(GL_OUT_OF_MEMORY);
9764 }
9765}
9766
9767void __stdcall glEndTransformFeedback(void)
9768{
9769 EVENT("(void)");
9770
9771 try
9772 {
9773 gl::Context *context = gl::getNonLostContext();
9774
9775 if (context)
9776 {
9777 if (context->getClientVersion() < 3)
9778 {
9779 return gl::error(GL_INVALID_OPERATION);
9780 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009781
Jamie Madill54133512013-06-21 09:33:07 -04009782 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009783 UNIMPLEMENTED();
9784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009785 }
9786 catch(std::bad_alloc&)
9787 {
9788 return gl::error(GL_OUT_OF_MEMORY);
9789 }
9790}
9791
9792void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9793{
9794 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9795 target, index, buffer, offset, size);
9796
9797 try
9798 {
9799 gl::Context *context = gl::getNonLostContext();
9800
9801 if (context)
9802 {
9803 if (context->getClientVersion() < 3)
9804 {
9805 return gl::error(GL_INVALID_OPERATION);
9806 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009807
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009808 switch (target)
9809 {
9810 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009811 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009812 {
9813 return gl::error(GL_INVALID_VALUE);
9814 }
9815 break;
9816
9817 case GL_UNIFORM_BUFFER:
9818 if (index >= context->getMaximumCombinedUniformBufferBindings())
9819 {
9820 return gl::error(GL_INVALID_VALUE);
9821 }
9822 break;
9823
9824 default:
9825 return gl::error(GL_INVALID_ENUM);
9826 }
9827
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009828 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009829 {
9830 return gl::error(GL_INVALID_VALUE);
9831 }
9832
9833 switch (target)
9834 {
9835 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009836
9837 // size and offset must be a multiple of 4
9838 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9839 {
9840 return gl::error(GL_INVALID_VALUE);
9841 }
9842
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009843 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9844 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009845 break;
9846
9847 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009848
9849 // it is an error to bind an offset not a multiple of the alignment
9850 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9851 {
9852 return gl::error(GL_INVALID_VALUE);
9853 }
9854
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009855 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9856 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009857 break;
9858
9859 default:
9860 UNREACHABLE();
9861 }
9862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009863 }
9864 catch(std::bad_alloc&)
9865 {
9866 return gl::error(GL_OUT_OF_MEMORY);
9867 }
9868}
9869
9870void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9871{
9872 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9873 target, index, buffer);
9874
9875 try
9876 {
9877 gl::Context *context = gl::getNonLostContext();
9878
9879 if (context)
9880 {
9881 if (context->getClientVersion() < 3)
9882 {
9883 return gl::error(GL_INVALID_OPERATION);
9884 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009885
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009886 switch (target)
9887 {
9888 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009889 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009890 {
9891 return gl::error(GL_INVALID_VALUE);
9892 }
9893 break;
9894
9895 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009896 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009897 {
9898 return gl::error(GL_INVALID_VALUE);
9899 }
9900 break;
9901
9902 default:
9903 return gl::error(GL_INVALID_ENUM);
9904 }
9905
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009906 switch (target)
9907 {
9908 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009909 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009910 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009911 break;
9912
9913 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009914 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009915 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009916 break;
9917
9918 default:
9919 UNREACHABLE();
9920 }
9921 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009922 }
9923 catch(std::bad_alloc&)
9924 {
9925 return gl::error(GL_OUT_OF_MEMORY);
9926 }
9927}
9928
9929void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9930{
9931 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9932 program, count, varyings, bufferMode);
9933
9934 try
9935 {
9936 gl::Context *context = gl::getNonLostContext();
9937
9938 if (context)
9939 {
9940 if (context->getClientVersion() < 3)
9941 {
9942 return gl::error(GL_INVALID_OPERATION);
9943 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009944
Jamie Madill54133512013-06-21 09:33:07 -04009945 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009946 UNIMPLEMENTED();
9947 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009948 }
9949 catch(std::bad_alloc&)
9950 {
9951 return gl::error(GL_OUT_OF_MEMORY);
9952 }
9953}
9954
9955void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9956{
9957 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9958 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9959 program, index, bufSize, length, size, type, name);
9960
9961 try
9962 {
9963 gl::Context *context = gl::getNonLostContext();
9964
9965 if (context)
9966 {
9967 if (context->getClientVersion() < 3)
9968 {
9969 return gl::error(GL_INVALID_OPERATION);
9970 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009971
Jamie Madill54133512013-06-21 09:33:07 -04009972 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009973 UNIMPLEMENTED();
9974 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009975 }
9976 catch(std::bad_alloc&)
9977 {
9978 return gl::error(GL_OUT_OF_MEMORY);
9979 }
9980}
9981
9982void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9983{
9984 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9985 index, size, type, stride, pointer);
9986
9987 try
9988 {
9989 gl::Context *context = gl::getNonLostContext();
9990
9991 if (context)
9992 {
9993 if (context->getClientVersion() < 3)
9994 {
9995 return gl::error(GL_INVALID_OPERATION);
9996 }
9997 }
9998
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009999 if (index >= gl::MAX_VERTEX_ATTRIBS)
10000 {
10001 return gl::error(GL_INVALID_VALUE);
10002 }
10003
10004 if (size < 1 || size > 4)
10005 {
10006 return gl::error(GL_INVALID_VALUE);
10007 }
10008
10009 switch (type)
10010 {
10011 case GL_BYTE:
10012 case GL_UNSIGNED_BYTE:
10013 case GL_SHORT:
10014 case GL_UNSIGNED_SHORT:
10015 case GL_INT:
10016 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +000010017 case GL_INT_2_10_10_10_REV:
10018 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010019 break;
10020 default:
10021 return gl::error(GL_INVALID_ENUM);
10022 }
10023
10024 if (stride < 0)
10025 {
10026 return gl::error(GL_INVALID_VALUE);
10027 }
10028
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +000010029 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
10030 {
10031 return gl::error(GL_INVALID_OPERATION);
10032 }
10033
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010034 if (context)
10035 {
Jamie Madilld8db8662013-07-02 11:57:04 -040010036 // [OpenGL ES 3.0.2] Section 2.8 page 24:
10037 // An INVALID_OPERATION error is generated when a non-zero vertex array object
10038 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
10039 // and the pointer argument is not NULL.
10040 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
10041 {
10042 return gl::error(GL_INVALID_OPERATION);
10043 }
10044
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010045 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
10046 stride, pointer);
10047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010048 }
10049 catch(std::bad_alloc&)
10050 {
10051 return gl::error(GL_OUT_OF_MEMORY);
10052 }
10053}
10054
10055void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
10056{
10057 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10058 index, pname, params);
10059
10060 try
10061 {
10062 gl::Context *context = gl::getNonLostContext();
10063
10064 if (context)
10065 {
10066 if (context->getClientVersion() < 3)
10067 {
10068 return gl::error(GL_INVALID_OPERATION);
10069 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010070
Jamie Madilla7d05862013-07-02 11:57:06 -040010071 if (index >= gl::MAX_VERTEX_ATTRIBS)
10072 {
10073 return gl::error(GL_INVALID_VALUE);
10074 }
10075
10076 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
10077
10078 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
10079 {
10080 return;
10081 }
10082
10083 if (pname == GL_CURRENT_VERTEX_ATTRIB)
10084 {
10085 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
10086 for (int i = 0; i < 4; ++i)
10087 {
10088 params[i] = currentValueData.IntValues[i];
10089 }
10090 }
10091 else
10092 {
10093 *params = attribState.querySingleParameter<GLint>(pname);
10094 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010095 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010096 }
10097 catch(std::bad_alloc&)
10098 {
10099 return gl::error(GL_OUT_OF_MEMORY);
10100 }
10101}
10102
10103void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
10104{
10105 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
10106 index, pname, params);
10107
10108 try
10109 {
10110 gl::Context *context = gl::getNonLostContext();
10111
10112 if (context)
10113 {
10114 if (context->getClientVersion() < 3)
10115 {
10116 return gl::error(GL_INVALID_OPERATION);
10117 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010118
Jamie Madilla7d05862013-07-02 11:57:06 -040010119 if (index >= gl::MAX_VERTEX_ATTRIBS)
10120 {
10121 return gl::error(GL_INVALID_VALUE);
10122 }
10123
10124 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
10125
10126 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
10127 {
10128 return;
10129 }
10130
10131 if (pname == GL_CURRENT_VERTEX_ATTRIB)
10132 {
10133 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
10134 for (int i = 0; i < 4; ++i)
10135 {
10136 params[i] = currentValueData.UnsignedIntValues[i];
10137 }
10138 }
10139 else
10140 {
10141 *params = attribState.querySingleParameter<GLuint>(pname);
10142 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010143 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010144 }
10145 catch(std::bad_alloc&)
10146 {
10147 return gl::error(GL_OUT_OF_MEMORY);
10148 }
10149}
10150
10151void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
10152{
10153 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
10154 index, x, y, z, w);
10155
10156 try
10157 {
10158 gl::Context *context = gl::getNonLostContext();
10159
10160 if (context)
10161 {
10162 if (context->getClientVersion() < 3)
10163 {
10164 return gl::error(GL_INVALID_OPERATION);
10165 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010166
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010167 if (index >= gl::MAX_VERTEX_ATTRIBS)
10168 {
10169 return gl::error(GL_INVALID_VALUE);
10170 }
10171
10172 GLint vals[4] = { x, y, z, w };
10173 context->setVertexAttribi(index, vals);
10174 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010175 }
10176 catch(std::bad_alloc&)
10177 {
10178 return gl::error(GL_OUT_OF_MEMORY);
10179 }
10180}
10181
10182void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
10183{
10184 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
10185 index, x, y, z, w);
10186
10187 try
10188 {
10189 gl::Context *context = gl::getNonLostContext();
10190
10191 if (context)
10192 {
10193 if (context->getClientVersion() < 3)
10194 {
10195 return gl::error(GL_INVALID_OPERATION);
10196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010197
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010198 if (index >= gl::MAX_VERTEX_ATTRIBS)
10199 {
10200 return gl::error(GL_INVALID_VALUE);
10201 }
10202
10203 GLuint vals[4] = { x, y, z, w };
10204 context->setVertexAttribu(index, vals);
10205 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010206 }
10207 catch(std::bad_alloc&)
10208 {
10209 return gl::error(GL_OUT_OF_MEMORY);
10210 }
10211}
10212
10213void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
10214{
10215 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
10216
10217 try
10218 {
10219 gl::Context *context = gl::getNonLostContext();
10220
10221 if (context)
10222 {
10223 if (context->getClientVersion() < 3)
10224 {
10225 return gl::error(GL_INVALID_OPERATION);
10226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010227
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010228 if (index >= gl::MAX_VERTEX_ATTRIBS)
10229 {
10230 return gl::error(GL_INVALID_VALUE);
10231 }
10232
10233 context->setVertexAttribi(index, v);
10234 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010235 }
10236 catch(std::bad_alloc&)
10237 {
10238 return gl::error(GL_OUT_OF_MEMORY);
10239 }
10240}
10241
10242void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
10243{
10244 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
10245
10246 try
10247 {
10248 gl::Context *context = gl::getNonLostContext();
10249
10250 if (context)
10251 {
10252 if (context->getClientVersion() < 3)
10253 {
10254 return gl::error(GL_INVALID_OPERATION);
10255 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010256
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +000010257 if (index >= gl::MAX_VERTEX_ATTRIBS)
10258 {
10259 return gl::error(GL_INVALID_VALUE);
10260 }
10261
10262 context->setVertexAttribu(index, v);
10263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010264 }
10265 catch(std::bad_alloc&)
10266 {
10267 return gl::error(GL_OUT_OF_MEMORY);
10268 }
10269}
10270
10271void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
10272{
10273 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
10274 program, location, params);
10275
10276 try
10277 {
10278 gl::Context *context = gl::getNonLostContext();
10279
10280 if (context)
10281 {
10282 if (context->getClientVersion() < 3)
10283 {
10284 return gl::error(GL_INVALID_OPERATION);
10285 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010286
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +000010287 if (program == 0)
10288 {
10289 return gl::error(GL_INVALID_VALUE);
10290 }
10291
10292 gl::Program *programObject = context->getProgram(program);
10293
10294 if (!programObject || !programObject->isLinked())
10295 {
10296 return gl::error(GL_INVALID_OPERATION);
10297 }
10298
10299 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10300 if (!programBinary)
10301 {
10302 return gl::error(GL_INVALID_OPERATION);
10303 }
10304
10305 if (!programBinary->getUniformuiv(location, NULL, params))
10306 {
10307 return gl::error(GL_INVALID_OPERATION);
10308 }
10309 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010310 }
10311 catch(std::bad_alloc&)
10312 {
10313 return gl::error(GL_OUT_OF_MEMORY);
10314 }
10315}
10316
10317GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10318{
10319 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10320 program, name);
10321
10322 try
10323 {
10324 gl::Context *context = gl::getNonLostContext();
10325
10326 if (context)
10327 {
10328 if (context->getClientVersion() < 3)
10329 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010330 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010331 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010332
Jamie Madilld1e78c92013-06-20 11:55:50 -040010333 if (program == 0)
10334 {
10335 return gl::error(GL_INVALID_VALUE, -1);
10336 }
10337
10338 gl::Program *programObject = context->getProgram(program);
10339
10340 if (!programObject || !programObject->isLinked())
10341 {
10342 return gl::error(GL_INVALID_OPERATION, -1);
10343 }
10344
10345 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10346 if (!programBinary)
10347 {
10348 return gl::error(GL_INVALID_OPERATION, -1);
10349 }
10350
10351 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010352 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010353 }
10354 catch(std::bad_alloc&)
10355 {
10356 return gl::error(GL_OUT_OF_MEMORY, 0);
10357 }
10358
10359 return 0;
10360}
10361
10362void __stdcall glUniform1ui(GLint location, GLuint v0)
10363{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010364 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010365}
10366
10367void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10368{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010369 const GLuint xy[] = { v0, v1 };
10370 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010371}
10372
10373void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10374{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010375 const GLuint xyz[] = { v0, v1, v2 };
10376 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010377}
10378
10379void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10380{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010381 const GLuint xyzw[] = { v0, v1, v2, v3 };
10382 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010383}
10384
10385void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10386{
10387 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10388 location, count, value);
10389
10390 try
10391 {
10392 gl::Context *context = gl::getNonLostContext();
10393
10394 if (context)
10395 {
10396 if (context->getClientVersion() < 3)
10397 {
10398 return gl::error(GL_INVALID_OPERATION);
10399 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010400
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010401 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10402 if (!programBinary)
10403 {
10404 return gl::error(GL_INVALID_OPERATION);
10405 }
10406
10407 if (!programBinary->setUniform1uiv(location, count, value))
10408 {
10409 return gl::error(GL_INVALID_OPERATION);
10410 }
10411 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010412 }
10413 catch(std::bad_alloc&)
10414 {
10415 return gl::error(GL_OUT_OF_MEMORY);
10416 }
10417}
10418
10419void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10420{
10421 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10422 location, count, value);
10423
10424 try
10425 {
10426 gl::Context *context = gl::getNonLostContext();
10427
10428 if (context)
10429 {
10430 if (context->getClientVersion() < 3)
10431 {
10432 return gl::error(GL_INVALID_OPERATION);
10433 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010434
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010435 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10436 if (!programBinary)
10437 {
10438 return gl::error(GL_INVALID_OPERATION);
10439 }
10440
10441 if (!programBinary->setUniform2uiv(location, count, value))
10442 {
10443 return gl::error(GL_INVALID_OPERATION);
10444 }
10445 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010446 }
10447 catch(std::bad_alloc&)
10448 {
10449 return gl::error(GL_OUT_OF_MEMORY);
10450 }
10451}
10452
10453void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10454{
10455 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10456 location, count, value);
10457
10458 try
10459 {
10460 gl::Context *context = gl::getNonLostContext();
10461
10462 if (context)
10463 {
10464 if (context->getClientVersion() < 3)
10465 {
10466 return gl::error(GL_INVALID_OPERATION);
10467 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010468
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010469 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10470 if (!programBinary)
10471 {
10472 return gl::error(GL_INVALID_OPERATION);
10473 }
10474
10475 if (!programBinary->setUniform3uiv(location, count, value))
10476 {
10477 return gl::error(GL_INVALID_OPERATION);
10478 }
10479 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010480 }
10481 catch(std::bad_alloc&)
10482 {
10483 return gl::error(GL_OUT_OF_MEMORY);
10484 }
10485}
10486
10487void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10488{
10489 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10490 location, count, value);
10491
10492 try
10493 {
10494 gl::Context *context = gl::getNonLostContext();
10495
10496 if (context)
10497 {
10498 if (context->getClientVersion() < 3)
10499 {
10500 return gl::error(GL_INVALID_OPERATION);
10501 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010502
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010503 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10504 if (!programBinary)
10505 {
10506 return gl::error(GL_INVALID_OPERATION);
10507 }
10508
10509 if (!programBinary->setUniform4uiv(location, count, value))
10510 {
10511 return gl::error(GL_INVALID_OPERATION);
10512 }
10513 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010514 }
10515 catch(std::bad_alloc&)
10516 {
10517 return gl::error(GL_OUT_OF_MEMORY);
10518 }
10519}
10520
10521void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10522{
10523 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10524 buffer, drawbuffer, value);
10525
10526 try
10527 {
10528 gl::Context *context = gl::getNonLostContext();
10529
10530 if (context)
10531 {
10532 if (context->getClientVersion() < 3)
10533 {
10534 return gl::error(GL_INVALID_OPERATION);
10535 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010536
Jamie Madill54133512013-06-21 09:33:07 -040010537 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010538 UNIMPLEMENTED();
10539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010540 }
10541 catch(std::bad_alloc&)
10542 {
10543 return gl::error(GL_OUT_OF_MEMORY);
10544 }
10545}
10546
10547void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10548{
10549 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10550 buffer, drawbuffer, value);
10551
10552 try
10553 {
10554 gl::Context *context = gl::getNonLostContext();
10555
10556 if (context)
10557 {
10558 if (context->getClientVersion() < 3)
10559 {
10560 return gl::error(GL_INVALID_OPERATION);
10561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010562
Jamie Madill54133512013-06-21 09:33:07 -040010563 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010564 UNIMPLEMENTED();
10565 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010566 }
10567 catch(std::bad_alloc&)
10568 {
10569 return gl::error(GL_OUT_OF_MEMORY);
10570 }
10571}
10572
10573void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10574{
10575 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10576 buffer, drawbuffer, value);
10577
10578 try
10579 {
10580 gl::Context *context = gl::getNonLostContext();
10581
10582 if (context)
10583 {
10584 if (context->getClientVersion() < 3)
10585 {
10586 return gl::error(GL_INVALID_OPERATION);
10587 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010588
Jamie Madill54133512013-06-21 09:33:07 -040010589 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010590 UNIMPLEMENTED();
10591 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010592 }
10593 catch(std::bad_alloc&)
10594 {
10595 return gl::error(GL_OUT_OF_MEMORY);
10596 }
10597}
10598
10599void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10600{
10601 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10602 buffer, drawbuffer, depth, stencil);
10603
10604 try
10605 {
10606 gl::Context *context = gl::getNonLostContext();
10607
10608 if (context)
10609 {
10610 if (context->getClientVersion() < 3)
10611 {
10612 return gl::error(GL_INVALID_OPERATION);
10613 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010614
Jamie Madill54133512013-06-21 09:33:07 -040010615 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010616 UNIMPLEMENTED();
10617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010618 }
10619 catch(std::bad_alloc&)
10620 {
10621 return gl::error(GL_OUT_OF_MEMORY);
10622 }
10623}
10624
10625const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10626{
10627 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10628
10629 try
10630 {
10631 gl::Context *context = gl::getNonLostContext();
10632
10633 if (context)
10634 {
10635 if (context->getClientVersion() < 3)
10636 {
10637 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10638 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010639
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010640 if (name != GL_EXTENSIONS)
10641 {
10642 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10643 }
10644
10645 if (index >= context->getNumExtensions())
10646 {
10647 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10648 }
10649
10650 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10651 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010652 }
10653 catch(std::bad_alloc&)
10654 {
10655 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10656 }
10657
10658 return NULL;
10659}
10660
10661void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10662{
10663 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10664 readTarget, writeTarget, readOffset, writeOffset, size);
10665
10666 try
10667 {
10668 gl::Context *context = gl::getNonLostContext();
10669
10670 if (context)
10671 {
10672 if (context->getClientVersion() < 3)
10673 {
10674 return gl::error(GL_INVALID_OPERATION);
10675 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010676
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010677 gl::Buffer *readBuffer = NULL;
10678 switch (readTarget)
10679 {
10680 case GL_ARRAY_BUFFER:
10681 readBuffer = context->getArrayBuffer();
10682 break;
10683 case GL_COPY_READ_BUFFER:
10684 readBuffer = context->getCopyReadBuffer();
10685 break;
10686 case GL_COPY_WRITE_BUFFER:
10687 readBuffer = context->getCopyWriteBuffer();
10688 break;
10689 case GL_ELEMENT_ARRAY_BUFFER:
10690 readBuffer = context->getElementArrayBuffer();
10691 break;
10692 case GL_PIXEL_PACK_BUFFER:
10693 readBuffer = context->getPixelPackBuffer();
10694 break;
10695 case GL_PIXEL_UNPACK_BUFFER:
10696 readBuffer = context->getPixelUnpackBuffer();
10697 break;
10698 case GL_TRANSFORM_FEEDBACK_BUFFER:
10699 readBuffer = context->getGenericTransformFeedbackBuffer();
10700 break;
10701 case GL_UNIFORM_BUFFER:
10702 readBuffer = context->getGenericUniformBuffer();
10703 break;
10704 default:
10705 return gl::error(GL_INVALID_ENUM);
10706 }
10707
10708 gl::Buffer *writeBuffer = NULL;
10709 switch (writeTarget)
10710 {
10711 case GL_ARRAY_BUFFER:
10712 writeBuffer = context->getArrayBuffer();
10713 break;
10714 case GL_COPY_READ_BUFFER:
10715 writeBuffer = context->getCopyReadBuffer();
10716 break;
10717 case GL_COPY_WRITE_BUFFER:
10718 writeBuffer = context->getCopyWriteBuffer();
10719 break;
10720 case GL_ELEMENT_ARRAY_BUFFER:
10721 writeBuffer = context->getElementArrayBuffer();
10722 break;
10723 case GL_PIXEL_PACK_BUFFER:
10724 writeBuffer = context->getPixelPackBuffer();
10725 break;
10726 case GL_PIXEL_UNPACK_BUFFER:
10727 writeBuffer = context->getPixelUnpackBuffer();
10728 break;
10729 case GL_TRANSFORM_FEEDBACK_BUFFER:
10730 writeBuffer = context->getGenericTransformFeedbackBuffer();
10731 break;
10732 case GL_UNIFORM_BUFFER:
10733 writeBuffer = context->getGenericUniformBuffer();
10734 break;
10735 default:
10736 return gl::error(GL_INVALID_ENUM);
10737 }
10738
10739 if (!readBuffer || !writeBuffer)
10740 {
10741 return gl::error(GL_INVALID_OPERATION);
10742 }
10743
10744 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10745 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10746 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10747 {
10748 return gl::error(GL_INVALID_VALUE);
10749 }
10750
10751 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10752 {
10753 return gl::error(GL_INVALID_VALUE);
10754 }
10755
10756 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10757
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010758 // if size is zero, the copy is a successful no-op
10759 if (size > 0)
10760 {
10761 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10762 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010763 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010764 }
10765 catch(std::bad_alloc&)
10766 {
10767 return gl::error(GL_OUT_OF_MEMORY);
10768 }
10769}
10770
10771void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10772{
10773 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10774 program, uniformCount, uniformNames, uniformIndices);
10775
10776 try
10777 {
10778 gl::Context *context = gl::getNonLostContext();
10779
10780 if (context)
10781 {
10782 if (context->getClientVersion() < 3)
10783 {
10784 return gl::error(GL_INVALID_OPERATION);
10785 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010786
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010787 if (uniformCount < 0)
10788 {
10789 return gl::error(GL_INVALID_VALUE);
10790 }
10791
10792 gl::Program *programObject = context->getProgram(program);
10793
10794 if (!programObject)
10795 {
10796 if (context->getShader(program))
10797 {
10798 return gl::error(GL_INVALID_OPERATION);
10799 }
10800 else
10801 {
10802 return gl::error(GL_INVALID_VALUE);
10803 }
10804 }
10805
10806 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10807 if (!programObject->isLinked() || !programBinary)
10808 {
10809 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10810 {
10811 uniformIndices[uniformId] = GL_INVALID_INDEX;
10812 }
10813 }
10814 else
10815 {
10816 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10817 {
10818 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10819 }
10820 }
10821 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010822 }
10823 catch(std::bad_alloc&)
10824 {
10825 return gl::error(GL_OUT_OF_MEMORY);
10826 }
10827}
10828
10829void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10830{
10831 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10832 program, uniformCount, uniformIndices, pname, params);
10833
10834 try
10835 {
10836 gl::Context *context = gl::getNonLostContext();
10837
10838 if (context)
10839 {
10840 if (context->getClientVersion() < 3)
10841 {
10842 return gl::error(GL_INVALID_OPERATION);
10843 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010844
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010845 if (uniformCount < 0)
10846 {
10847 return gl::error(GL_INVALID_VALUE);
10848 }
10849
10850 gl::Program *programObject = context->getProgram(program);
10851
10852 if (!programObject)
10853 {
10854 if (context->getShader(program))
10855 {
10856 return gl::error(GL_INVALID_OPERATION);
10857 }
10858 else
10859 {
10860 return gl::error(GL_INVALID_VALUE);
10861 }
10862 }
10863
10864 switch (pname)
10865 {
10866 case GL_UNIFORM_TYPE:
10867 case GL_UNIFORM_SIZE:
10868 case GL_UNIFORM_NAME_LENGTH:
10869 case GL_UNIFORM_BLOCK_INDEX:
10870 case GL_UNIFORM_OFFSET:
10871 case GL_UNIFORM_ARRAY_STRIDE:
10872 case GL_UNIFORM_MATRIX_STRIDE:
10873 case GL_UNIFORM_IS_ROW_MAJOR:
10874 break;
10875 default:
10876 return gl::error(GL_INVALID_ENUM);
10877 }
10878
10879 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10880
10881 if (!programBinary && uniformCount > 0)
10882 {
10883 return gl::error(GL_INVALID_VALUE);
10884 }
10885
10886 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10887 {
10888 const GLuint index = uniformIndices[uniformId];
10889
10890 if (index >= (GLuint)programBinary->getActiveUniformCount())
10891 {
10892 return gl::error(GL_INVALID_VALUE);
10893 }
10894 }
10895
10896 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10897 {
10898 const GLuint index = uniformIndices[uniformId];
10899 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10900 }
10901 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010902 }
10903 catch(std::bad_alloc&)
10904 {
10905 return gl::error(GL_OUT_OF_MEMORY);
10906 }
10907}
10908
10909GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10910{
10911 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10912
10913 try
10914 {
10915 gl::Context *context = gl::getNonLostContext();
10916
10917 if (context)
10918 {
10919 if (context->getClientVersion() < 3)
10920 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010921 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010922 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010923
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010924 gl::Program *programObject = context->getProgram(program);
10925
10926 if (!programObject)
10927 {
10928 if (context->getShader(program))
10929 {
10930 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10931 }
10932 else
10933 {
10934 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10935 }
10936 }
10937
10938 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10939 if (!programBinary)
10940 {
10941 return GL_INVALID_INDEX;
10942 }
10943
10944 return programBinary->getUniformBlockIndex(uniformBlockName);
10945 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010946 }
10947 catch(std::bad_alloc&)
10948 {
10949 return gl::error(GL_OUT_OF_MEMORY, 0);
10950 }
10951
10952 return 0;
10953}
10954
10955void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10956{
10957 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10958 program, uniformBlockIndex, pname, params);
10959
10960 try
10961 {
10962 gl::Context *context = gl::getNonLostContext();
10963
10964 if (context)
10965 {
10966 if (context->getClientVersion() < 3)
10967 {
10968 return gl::error(GL_INVALID_OPERATION);
10969 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010970 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010971
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010972 if (!programObject)
10973 {
10974 if (context->getShader(program))
10975 {
10976 return gl::error(GL_INVALID_OPERATION);
10977 }
10978 else
10979 {
10980 return gl::error(GL_INVALID_VALUE);
10981 }
10982 }
10983
10984 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10985
10986 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10987 {
10988 return gl::error(GL_INVALID_VALUE);
10989 }
10990
10991 switch (pname)
10992 {
10993 case GL_UNIFORM_BLOCK_BINDING:
10994 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10995 break;
10996
10997 case GL_UNIFORM_BLOCK_DATA_SIZE:
10998 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10999 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
11000 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
11001 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
11002 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
11003 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
11004 break;
11005
11006 default:
11007 return gl::error(GL_INVALID_ENUM);
11008 }
11009 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011010 }
11011 catch(std::bad_alloc&)
11012 {
11013 return gl::error(GL_OUT_OF_MEMORY);
11014 }
11015}
11016
11017void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
11018{
11019 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
11020 program, uniformBlockIndex, bufSize, length, uniformBlockName);
11021
11022 try
11023 {
11024 gl::Context *context = gl::getNonLostContext();
11025
11026 if (context)
11027 {
11028 if (context->getClientVersion() < 3)
11029 {
11030 return gl::error(GL_INVALID_OPERATION);
11031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011032
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000011033 gl::Program *programObject = context->getProgram(program);
11034
11035 if (!programObject)
11036 {
11037 if (context->getShader(program))
11038 {
11039 return gl::error(GL_INVALID_OPERATION);
11040 }
11041 else
11042 {
11043 return gl::error(GL_INVALID_VALUE);
11044 }
11045 }
11046
11047 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11048
11049 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
11050 {
11051 return gl::error(GL_INVALID_VALUE);
11052 }
11053
11054 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
11055 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011056 }
11057 catch(std::bad_alloc&)
11058 {
11059 return gl::error(GL_OUT_OF_MEMORY);
11060 }
11061}
11062
11063void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
11064{
11065 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
11066 program, uniformBlockIndex, uniformBlockBinding);
11067
11068 try
11069 {
11070 gl::Context *context = gl::getNonLostContext();
11071
11072 if (context)
11073 {
11074 if (context->getClientVersion() < 3)
11075 {
11076 return gl::error(GL_INVALID_OPERATION);
11077 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011078
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000011079 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
11080 {
11081 return gl::error(GL_INVALID_VALUE);
11082 }
11083
11084 gl::Program *programObject = context->getProgram(program);
11085
11086 if (!programObject)
11087 {
11088 if (context->getShader(program))
11089 {
11090 return gl::error(GL_INVALID_OPERATION);
11091 }
11092 else
11093 {
11094 return gl::error(GL_INVALID_VALUE);
11095 }
11096 }
11097
11098 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11099
11100 // if never linked, there won't be any uniform blocks
11101 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
11102 {
11103 return gl::error(GL_INVALID_VALUE);
11104 }
11105
11106 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
11107 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011108 }
11109 catch(std::bad_alloc&)
11110 {
11111 return gl::error(GL_OUT_OF_MEMORY);
11112 }
11113}
11114
11115void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
11116{
11117 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
11118 mode, first, count, instanceCount);
11119
11120 try
11121 {
11122 gl::Context *context = gl::getNonLostContext();
11123
11124 if (context)
11125 {
11126 if (context->getClientVersion() < 3)
11127 {
11128 return gl::error(GL_INVALID_OPERATION);
11129 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011130
Jamie Madill54133512013-06-21 09:33:07 -040011131 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011132 UNIMPLEMENTED();
11133 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011134 }
11135 catch(std::bad_alloc&)
11136 {
11137 return gl::error(GL_OUT_OF_MEMORY);
11138 }
11139}
11140
11141void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
11142{
11143 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
11144 mode, count, type, indices, instanceCount);
11145
11146 try
11147 {
11148 gl::Context *context = gl::getNonLostContext();
11149
11150 if (context)
11151 {
11152 if (context->getClientVersion() < 3)
11153 {
11154 return gl::error(GL_INVALID_OPERATION);
11155 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011156
Jamie Madill54133512013-06-21 09:33:07 -040011157 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011158 UNIMPLEMENTED();
11159 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011160 }
11161 catch(std::bad_alloc&)
11162 {
11163 return gl::error(GL_OUT_OF_MEMORY);
11164 }
11165}
11166
11167GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
11168{
11169 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
11170
11171 try
11172 {
11173 gl::Context *context = gl::getNonLostContext();
11174
11175 if (context)
11176 {
11177 if (context->getClientVersion() < 3)
11178 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011179 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011180 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011181
Jamie Madill5215e1a2013-07-26 11:55:19 -040011182 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
11183 {
11184 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
11185 }
11186
11187 if (flags != 0)
11188 {
11189 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
11190 }
11191
11192 return context->createFenceSync(condition);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011193 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011194 }
11195 catch(std::bad_alloc&)
11196 {
11197 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
11198 }
11199
11200 return NULL;
11201}
11202
11203GLboolean __stdcall glIsSync(GLsync sync)
11204{
11205 EVENT("(GLsync sync = 0x%0.8p)", sync);
11206
11207 try
11208 {
11209 gl::Context *context = gl::getNonLostContext();
11210
11211 if (context)
11212 {
11213 if (context->getClientVersion() < 3)
11214 {
11215 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11216 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011217
Jamie Madill5215e1a2013-07-26 11:55:19 -040011218 return (context->getFenceSync(sync) != NULL);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011219 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011220 }
11221 catch(std::bad_alloc&)
11222 {
11223 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11224 }
11225
11226 return GL_FALSE;
11227}
11228
11229void __stdcall glDeleteSync(GLsync sync)
11230{
11231 EVENT("(GLsync sync = 0x%0.8p)", sync);
11232
11233 try
11234 {
11235 gl::Context *context = gl::getNonLostContext();
11236
11237 if (context)
11238 {
11239 if (context->getClientVersion() < 3)
11240 {
11241 return gl::error(GL_INVALID_OPERATION);
11242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011243
Jamie Madill5215e1a2013-07-26 11:55:19 -040011244 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
11245 {
11246 return gl::error(GL_INVALID_VALUE);
11247 }
11248
11249 context->deleteFenceSync(sync);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011250 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011251 }
11252 catch(std::bad_alloc&)
11253 {
11254 return gl::error(GL_OUT_OF_MEMORY);
11255 }
11256}
11257
11258GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11259{
11260 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11261 sync, flags, timeout);
11262
11263 try
11264 {
11265 gl::Context *context = gl::getNonLostContext();
11266
11267 if (context)
11268 {
11269 if (context->getClientVersion() < 3)
11270 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011271 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011272 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011273
Jamie Madill5215e1a2013-07-26 11:55:19 -040011274 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
11275 {
11276 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11277 }
11278
11279 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11280
11281 if (!fenceSync)
11282 {
11283 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11284 }
11285
11286 return fenceSync->clientWait(flags, timeout);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011287 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011288 }
11289 catch(std::bad_alloc&)
11290 {
11291 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11292 }
11293
11294 return GL_FALSE;
11295}
11296
11297void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11298{
11299 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11300 sync, flags, timeout);
11301
11302 try
11303 {
11304 gl::Context *context = gl::getNonLostContext();
11305
11306 if (context)
11307 {
11308 if (context->getClientVersion() < 3)
11309 {
11310 return gl::error(GL_INVALID_OPERATION);
11311 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011312
Jamie Madill5215e1a2013-07-26 11:55:19 -040011313 if (flags != 0)
11314 {
11315 return gl::error(GL_INVALID_VALUE);
11316 }
11317
11318 if (timeout != GL_TIMEOUT_IGNORED)
11319 {
11320 return gl::error(GL_INVALID_VALUE);
11321 }
11322
11323 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11324
11325 if (!fenceSync)
11326 {
11327 return gl::error(GL_INVALID_VALUE);
11328 }
11329
11330 fenceSync->serverWait();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011331 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011332 }
11333 catch(std::bad_alloc&)
11334 {
11335 return gl::error(GL_OUT_OF_MEMORY);
11336 }
11337}
11338
11339void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
11340{
11341 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11342 pname, params);
11343
11344 try
11345 {
11346 gl::Context *context = gl::getNonLostContext();
11347
11348 if (context)
11349 {
11350 if (context->getClientVersion() < 3)
11351 {
11352 return gl::error(GL_INVALID_OPERATION);
11353 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011354
Jamie Madill71fbd602013-07-19 16:36:55 -040011355 if (!(context->getInteger64v(pname, params)))
11356 {
11357 GLenum nativeType;
11358 unsigned int numParams = 0;
11359 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11360 return gl::error(GL_INVALID_ENUM);
11361
11362 if (numParams == 0)
11363 return; // it is known that the pname is valid, but that there are no parameters to return.
11364
11365 if (nativeType == GL_BOOL)
11366 {
11367 GLboolean *boolParams = NULL;
11368 boolParams = new GLboolean[numParams];
11369
11370 context->getBooleanv(pname, boolParams);
11371
11372 for (unsigned int i = 0; i < numParams; ++i)
11373 {
11374 if (boolParams[i] == GL_FALSE)
11375 params[i] = 0;
11376 else
11377 params[i] = 1;
11378 }
11379
11380 delete [] boolParams;
11381 }
11382 else if (nativeType == GL_INT)
11383 {
11384 GLint *intParams = NULL;
11385 intParams = new GLint[numParams];
11386
11387 context->getIntegerv(pname, intParams);
11388
11389 for (unsigned int i = 0; i < numParams; ++i)
11390 {
11391 params[i] = static_cast<GLint64>(intParams[i]);
11392 }
11393
11394 delete [] intParams;
11395 }
11396 else if (nativeType == GL_FLOAT)
11397 {
11398 GLfloat *floatParams = NULL;
11399 floatParams = new GLfloat[numParams];
11400
11401 context->getFloatv(pname, floatParams);
11402
11403 for (unsigned int i = 0; i < numParams; ++i)
11404 {
11405 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11406 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11407 {
11408 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11409 }
11410 else
11411 {
11412 params[i] = gl::iround<GLint64>(floatParams[i]);
11413 }
11414 }
11415
11416 delete [] floatParams;
11417 }
11418 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011419 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011420 }
11421 catch(std::bad_alloc&)
11422 {
11423 return gl::error(GL_OUT_OF_MEMORY);
11424 }
11425}
11426
11427void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11428{
11429 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11430 sync, pname, bufSize, length, values);
11431
11432 try
11433 {
11434 gl::Context *context = gl::getNonLostContext();
11435
11436 if (context)
11437 {
11438 if (context->getClientVersion() < 3)
11439 {
11440 return gl::error(GL_INVALID_OPERATION);
11441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011442
Jamie Madill5215e1a2013-07-26 11:55:19 -040011443 if (bufSize < 0)
11444 {
11445 return gl::error(GL_INVALID_VALUE);
11446 }
11447
11448 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11449
11450 if (!fenceSync)
11451 {
11452 return gl::error(GL_INVALID_VALUE);
11453 }
11454
11455 switch (pname)
11456 {
11457 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
11458 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
11459 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
11460 case GL_SYNC_FLAGS: values[0] = 0; break;
11461
11462 default:
11463 return gl::error(GL_INVALID_ENUM);
11464 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011465 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011466 }
11467 catch(std::bad_alloc&)
11468 {
11469 return gl::error(GL_OUT_OF_MEMORY);
11470 }
11471}
11472
11473void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11474{
11475 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11476 target, index, data);
11477
11478 try
11479 {
11480 gl::Context *context = gl::getNonLostContext();
11481
11482 if (context)
11483 {
11484 if (context->getClientVersion() < 3)
11485 {
11486 return gl::error(GL_INVALID_OPERATION);
11487 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011488
Jamie Madill54133512013-06-21 09:33:07 -040011489 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011490 UNIMPLEMENTED();
11491 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011492 }
11493 catch(std::bad_alloc&)
11494 {
11495 return gl::error(GL_OUT_OF_MEMORY);
11496 }
11497}
11498
11499void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11500{
11501 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11502 target, pname, params);
11503
11504 try
11505 {
11506 gl::Context *context = gl::getNonLostContext();
11507
11508 if (context)
11509 {
11510 if (context->getClientVersion() < 3)
11511 {
11512 return gl::error(GL_INVALID_OPERATION);
11513 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011514
Jamie Madill54133512013-06-21 09:33:07 -040011515 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011516 UNIMPLEMENTED();
11517 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011518 }
11519 catch(std::bad_alloc&)
11520 {
11521 return gl::error(GL_OUT_OF_MEMORY);
11522 }
11523}
11524
11525void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11526{
11527 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11528
11529 try
11530 {
11531 gl::Context *context = gl::getNonLostContext();
11532
11533 if (context)
11534 {
11535 if (context->getClientVersion() < 3)
11536 {
11537 return gl::error(GL_INVALID_OPERATION);
11538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011539
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011540 if (count < 0)
11541 {
11542 return gl::error(GL_INVALID_VALUE);
11543 }
11544
11545 for (int i = 0; i < count; i++)
11546 {
11547 samplers[i] = context->createSampler();
11548 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011549 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011550 }
11551 catch(std::bad_alloc&)
11552 {
11553 return gl::error(GL_OUT_OF_MEMORY);
11554 }
11555}
11556
11557void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11558{
11559 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11560
11561 try
11562 {
11563 gl::Context *context = gl::getNonLostContext();
11564
11565 if (context)
11566 {
11567 if (context->getClientVersion() < 3)
11568 {
11569 return gl::error(GL_INVALID_OPERATION);
11570 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011571
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011572 if (count < 0)
11573 {
11574 return gl::error(GL_INVALID_VALUE);
11575 }
11576
11577 for (int i = 0; i < count; i++)
11578 {
11579 context->deleteSampler(samplers[i]);
11580 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011581 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011582 }
11583 catch(std::bad_alloc&)
11584 {
11585 return gl::error(GL_OUT_OF_MEMORY);
11586 }
11587}
11588
11589GLboolean __stdcall glIsSampler(GLuint sampler)
11590{
11591 EVENT("(GLuint sampler = %u)", sampler);
11592
11593 try
11594 {
11595 gl::Context *context = gl::getNonLostContext();
11596
11597 if (context)
11598 {
11599 if (context->getClientVersion() < 3)
11600 {
11601 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11602 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011603
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011604 return context->isSampler(sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011605 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011606 }
11607 catch(std::bad_alloc&)
11608 {
11609 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11610 }
11611
11612 return GL_FALSE;
11613}
11614
11615void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11616{
11617 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11618
11619 try
11620 {
11621 gl::Context *context = gl::getNonLostContext();
11622
11623 if (context)
11624 {
11625 if (context->getClientVersion() < 3)
11626 {
11627 return gl::error(GL_INVALID_OPERATION);
11628 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011629
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011630 if (sampler != 0 && !context->isSampler(sampler))
11631 {
11632 return gl::error(GL_INVALID_OPERATION);
11633 }
11634
11635 if (unit >= context->getMaximumCombinedTextureImageUnits())
11636 {
11637 return gl::error(GL_INVALID_VALUE);
11638 }
11639
11640 context->bindSampler(unit, sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011641 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011642 }
11643 catch(std::bad_alloc&)
11644 {
11645 return gl::error(GL_OUT_OF_MEMORY);
11646 }
11647}
11648
11649void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11650{
11651 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11652
11653 try
11654 {
11655 gl::Context *context = gl::getNonLostContext();
11656
11657 if (context)
11658 {
11659 if (context->getClientVersion() < 3)
11660 {
11661 return gl::error(GL_INVALID_OPERATION);
11662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011663
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011664 if (!validateSamplerObjectParameter(pname))
11665 {
11666 return;
11667 }
11668
11669 if (!validateTexParamParameters(context, pname, param))
11670 {
11671 return;
11672 }
11673
11674 if (!context->isSampler(sampler))
11675 {
11676 return gl::error(GL_INVALID_OPERATION);
11677 }
11678
11679 context->samplerParameteri(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011681 }
11682 catch(std::bad_alloc&)
11683 {
11684 return gl::error(GL_OUT_OF_MEMORY);
11685 }
11686}
11687
11688void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11689{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011690 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011691}
11692
11693void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11694{
11695 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11696
11697 try
11698 {
11699 gl::Context *context = gl::getNonLostContext();
11700
11701 if (context)
11702 {
11703 if (context->getClientVersion() < 3)
11704 {
11705 return gl::error(GL_INVALID_OPERATION);
11706 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011707
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011708 if (!validateSamplerObjectParameter(pname))
11709 {
11710 return;
11711 }
11712
11713 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
11714 {
11715 return;
11716 }
11717
11718 if (!context->isSampler(sampler))
11719 {
11720 return gl::error(GL_INVALID_OPERATION);
11721 }
11722
11723 context->samplerParameterf(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011724 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011725 }
11726 catch(std::bad_alloc&)
11727 {
11728 return gl::error(GL_OUT_OF_MEMORY);
11729 }
11730}
11731
11732void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11733{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011734 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011735}
11736
11737void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11738{
11739 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11740
11741 try
11742 {
11743 gl::Context *context = gl::getNonLostContext();
11744
11745 if (context)
11746 {
11747 if (context->getClientVersion() < 3)
11748 {
11749 return gl::error(GL_INVALID_OPERATION);
11750 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011751
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011752 if (!validateSamplerObjectParameter(pname))
11753 {
11754 return;
11755 }
11756
11757 if (!context->isSampler(sampler))
11758 {
11759 return gl::error(GL_INVALID_OPERATION);
11760 }
11761
11762 *params = context->getSamplerParameteri(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011763 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011764 }
11765 catch(std::bad_alloc&)
11766 {
11767 return gl::error(GL_OUT_OF_MEMORY);
11768 }
11769}
11770
11771void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11772{
11773 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11774
11775 try
11776 {
11777 gl::Context *context = gl::getNonLostContext();
11778
11779 if (context)
11780 {
11781 if (context->getClientVersion() < 3)
11782 {
11783 return gl::error(GL_INVALID_OPERATION);
11784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011785
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011786 if (!validateSamplerObjectParameter(pname))
11787 {
11788 return;
11789 }
11790
11791 if (!context->isSampler(sampler))
11792 {
11793 return gl::error(GL_INVALID_OPERATION);
11794 }
11795
11796 *params = context->getSamplerParameterf(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011797 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011798 }
11799 catch(std::bad_alloc&)
11800 {
11801 return gl::error(GL_OUT_OF_MEMORY);
11802 }
11803}
11804
11805void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11806{
11807 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11808
11809 try
11810 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011811 if (index >= gl::MAX_VERTEX_ATTRIBS)
11812 {
11813 return gl::error(GL_INVALID_VALUE);
11814 }
11815
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011816 gl::Context *context = gl::getNonLostContext();
11817
11818 if (context)
11819 {
11820 if (context->getClientVersion() < 3)
11821 {
11822 return gl::error(GL_INVALID_OPERATION);
11823 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011824
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011825 context->setVertexAttribDivisor(index, divisor);
11826 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011827 }
11828 catch(std::bad_alloc&)
11829 {
11830 return gl::error(GL_OUT_OF_MEMORY);
11831 }
11832}
11833
11834void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11835{
11836 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11837
11838 try
11839 {
11840 gl::Context *context = gl::getNonLostContext();
11841
11842 if (context)
11843 {
11844 if (context->getClientVersion() < 3)
11845 {
11846 return gl::error(GL_INVALID_OPERATION);
11847 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011848
Jamie Madill54133512013-06-21 09:33:07 -040011849 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011850 UNIMPLEMENTED();
11851 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011852 }
11853 catch(std::bad_alloc&)
11854 {
11855 return gl::error(GL_OUT_OF_MEMORY);
11856 }
11857}
11858
11859void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11860{
11861 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11862
11863 try
11864 {
11865 gl::Context *context = gl::getNonLostContext();
11866
11867 if (context)
11868 {
11869 if (context->getClientVersion() < 3)
11870 {
11871 return gl::error(GL_INVALID_OPERATION);
11872 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011873
Jamie Madill54133512013-06-21 09:33:07 -040011874 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011875 UNIMPLEMENTED();
11876 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011877 }
11878 catch(std::bad_alloc&)
11879 {
11880 return gl::error(GL_OUT_OF_MEMORY);
11881 }
11882}
11883
11884void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11885{
11886 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11887
11888 try
11889 {
11890 gl::Context *context = gl::getNonLostContext();
11891
11892 if (context)
11893 {
11894 if (context->getClientVersion() < 3)
11895 {
11896 return gl::error(GL_INVALID_OPERATION);
11897 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011898
Jamie Madill54133512013-06-21 09:33:07 -040011899 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011900 UNIMPLEMENTED();
11901 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011902 }
11903 catch(std::bad_alloc&)
11904 {
11905 return gl::error(GL_OUT_OF_MEMORY);
11906 }
11907}
11908
11909GLboolean __stdcall glIsTransformFeedback(GLuint id)
11910{
11911 EVENT("(GLuint id = %u)", id);
11912
11913 try
11914 {
11915 gl::Context *context = gl::getNonLostContext();
11916
11917 if (context)
11918 {
11919 if (context->getClientVersion() < 3)
11920 {
11921 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11922 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011923
Jamie Madill54133512013-06-21 09:33:07 -040011924 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011925 UNIMPLEMENTED();
11926 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011927 }
11928 catch(std::bad_alloc&)
11929 {
11930 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11931 }
11932
11933 return GL_FALSE;
11934}
11935
11936void __stdcall glPauseTransformFeedback(void)
11937{
11938 EVENT("(void)");
11939
11940 try
11941 {
11942 gl::Context *context = gl::getNonLostContext();
11943
11944 if (context)
11945 {
11946 if (context->getClientVersion() < 3)
11947 {
11948 return gl::error(GL_INVALID_OPERATION);
11949 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011950
Jamie Madill54133512013-06-21 09:33:07 -040011951 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011952 UNIMPLEMENTED();
11953 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011954 }
11955 catch(std::bad_alloc&)
11956 {
11957 return gl::error(GL_OUT_OF_MEMORY);
11958 }
11959}
11960
11961void __stdcall glResumeTransformFeedback(void)
11962{
11963 EVENT("(void)");
11964
11965 try
11966 {
11967 gl::Context *context = gl::getNonLostContext();
11968
11969 if (context)
11970 {
11971 if (context->getClientVersion() < 3)
11972 {
11973 return gl::error(GL_INVALID_OPERATION);
11974 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011975
Jamie Madill54133512013-06-21 09:33:07 -040011976 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011977 UNIMPLEMENTED();
11978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011979 }
11980 catch(std::bad_alloc&)
11981 {
11982 return gl::error(GL_OUT_OF_MEMORY);
11983 }
11984}
11985
11986void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11987{
11988 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11989 program, bufSize, length, binaryFormat, binary);
11990
11991 try
11992 {
11993 gl::Context *context = gl::getNonLostContext();
11994
11995 if (context)
11996 {
11997 if (context->getClientVersion() < 3)
11998 {
11999 return gl::error(GL_INVALID_OPERATION);
12000 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012001
Jamie Madill54133512013-06-21 09:33:07 -040012002 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012003 UNIMPLEMENTED();
12004 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012005 }
12006 catch(std::bad_alloc&)
12007 {
12008 return gl::error(GL_OUT_OF_MEMORY);
12009 }
12010}
12011
12012void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
12013{
12014 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
12015 program, binaryFormat, binary, length);
12016
12017 try
12018 {
12019 gl::Context *context = gl::getNonLostContext();
12020
12021 if (context)
12022 {
12023 if (context->getClientVersion() < 3)
12024 {
12025 return gl::error(GL_INVALID_OPERATION);
12026 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012027
Jamie Madill54133512013-06-21 09:33:07 -040012028 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012029 UNIMPLEMENTED();
12030 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012031 }
12032 catch(std::bad_alloc&)
12033 {
12034 return gl::error(GL_OUT_OF_MEMORY);
12035 }
12036}
12037
12038void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
12039{
12040 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
12041 program, pname, value);
12042
12043 try
12044 {
12045 gl::Context *context = gl::getNonLostContext();
12046
12047 if (context)
12048 {
12049 if (context->getClientVersion() < 3)
12050 {
12051 return gl::error(GL_INVALID_OPERATION);
12052 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012053
Jamie Madill54133512013-06-21 09:33:07 -040012054 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012055 UNIMPLEMENTED();
12056 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012057 }
12058 catch(std::bad_alloc&)
12059 {
12060 return gl::error(GL_OUT_OF_MEMORY);
12061 }
12062}
12063
12064void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
12065{
12066 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
12067 target, numAttachments, attachments);
12068
12069 try
12070 {
12071 gl::Context *context = gl::getNonLostContext();
12072
12073 if (context)
12074 {
12075 if (context->getClientVersion() < 3)
12076 {
12077 return gl::error(GL_INVALID_OPERATION);
12078 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012079
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000012080 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
12081 {
12082 return;
12083 }
12084
12085 int maxDimension = context->getMaximumRenderbufferDimension();
12086 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
12087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012088 }
12089 catch(std::bad_alloc&)
12090 {
12091 return gl::error(GL_OUT_OF_MEMORY);
12092 }
12093}
12094
12095void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
12096{
12097 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
12098 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
12099 target, numAttachments, attachments, x, y, width, height);
12100
12101 try
12102 {
12103 gl::Context *context = gl::getNonLostContext();
12104
12105 if (context)
12106 {
12107 if (context->getClientVersion() < 3)
12108 {
12109 return gl::error(GL_INVALID_OPERATION);
12110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012111
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000012112 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
12113 {
12114 return;
12115 }
12116
12117 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
12118 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012119 }
12120 catch(std::bad_alloc&)
12121 {
12122 return gl::error(GL_OUT_OF_MEMORY);
12123 }
12124}
12125
12126void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
12127{
12128 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
12129 target, levels, internalformat, width, height);
12130
12131 try
12132 {
12133 gl::Context *context = gl::getNonLostContext();
12134
12135 if (context)
12136 {
12137 if (context->getClientVersion() < 3)
12138 {
12139 return gl::error(GL_INVALID_OPERATION);
12140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012141
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000012142 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
12143 {
12144 return;
12145 }
12146
12147 switch (target)
12148 {
12149 case GL_TEXTURE_2D:
12150 {
12151 gl::Texture2D *texture2d = context->getTexture2D();
12152 texture2d->storage(levels, internalformat, width, height);
12153 }
12154 break;
12155
12156 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
12157 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
12158 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
12159 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
12160 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
12161 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
12162 {
12163 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
12164 textureCube->storage(levels, internalformat, width);
12165 }
12166 break;
12167
12168 default:
12169 return gl::error(GL_INVALID_ENUM);
12170 }
12171 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012172 }
12173 catch(std::bad_alloc&)
12174 {
12175 return gl::error(GL_OUT_OF_MEMORY);
12176 }
12177}
12178
12179void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
12180{
12181 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
12182 "GLsizei height = %d, GLsizei depth = %d)",
12183 target, levels, internalformat, width, height, depth);
12184
12185 try
12186 {
12187 gl::Context *context = gl::getNonLostContext();
12188
12189 if (context)
12190 {
12191 if (context->getClientVersion() < 3)
12192 {
12193 return gl::error(GL_INVALID_OPERATION);
12194 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000012195
12196 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
12197 {
12198 return;
12199 }
12200
12201 switch (target)
12202 {
12203 case GL_TEXTURE_3D:
12204 {
12205 gl::Texture3D *texture3d = context->getTexture3D();
12206 texture3d->storage(levels, internalformat, width, height, depth);
12207 }
12208 break;
12209
12210 case GL_TEXTURE_2D_ARRAY:
12211 {
12212 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
12213 texture2darray->storage(levels, internalformat, width, height, depth);
12214 }
12215 break;
12216
12217 default:
12218 return gl::error(GL_INVALID_ENUM);
12219 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000012220 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012221 }
12222 catch(std::bad_alloc&)
12223 {
12224 return gl::error(GL_OUT_OF_MEMORY);
12225 }
12226}
12227
12228void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
12229{
12230 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
12231 "GLint* params = 0x%0.8p)",
12232 target, internalformat, pname, bufSize, params);
12233
12234 try
12235 {
12236 gl::Context *context = gl::getNonLostContext();
12237
12238 if (context)
12239 {
12240 if (context->getClientVersion() < 3)
12241 {
12242 return gl::error(GL_INVALID_OPERATION);
12243 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012244
Shannon Woods809d2502013-07-08 10:32:18 -040012245 if (!gl::IsColorRenderingSupported(internalformat, context) &&
12246 !gl::IsDepthRenderingSupported(internalformat, context) &&
12247 !gl::IsStencilRenderingSupported(internalformat, context))
12248 {
12249 return gl::error(GL_INVALID_ENUM);
12250 }
12251
12252 if (target != GL_RENDERBUFFER)
12253 {
12254 return gl::error(GL_INVALID_ENUM);
12255 }
12256
12257 if (bufSize < 0)
12258 {
12259 return gl::error(GL_INVALID_VALUE);
12260 }
12261
12262 switch (pname)
12263 {
12264 case GL_NUM_SAMPLE_COUNTS:
12265 if (bufSize != 0)
12266 *params = context->getNumSampleCounts(internalformat);
12267 break;
12268 case GL_SAMPLES:
12269 context->getSampleCounts(internalformat, bufSize, params);
12270 break;
12271 default:
12272 return gl::error(GL_INVALID_ENUM);
12273 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012274 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012275 }
12276 catch(std::bad_alloc&)
12277 {
12278 return gl::error(GL_OUT_OF_MEMORY);
12279 }
12280}
12281
12282// Extension functions
12283
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012284void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
12285 GLbitfield mask, GLenum filter)
12286{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012287 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012288 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
12289 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
12290 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
12291
12292 try
12293 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012294 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012295
12296 if (context)
12297 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012298 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
12299 dstX0, dstY0, dstX1, dstY1, mask, filter,
12300 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012301 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012302 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012303 }
12304
Geoff Lang758d5b22013-06-11 11:42:50 -040012305 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
12306 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012307 }
12308 }
12309 catch(std::bad_alloc&)
12310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012311 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012312 }
12313}
12314
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012315void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
12316 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012317{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012318 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000012319 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012320 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012321 target, level, internalformat, width, height, depth, border, format, type, pixels);
12322
12323 try
12324 {
12325 UNIMPLEMENTED(); // FIXME
12326 }
12327 catch(std::bad_alloc&)
12328 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012329 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012330 }
12331}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012332
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012333void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
12334 GLenum *binaryFormat, void *binary)
12335{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012336 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 +000012337 program, bufSize, length, binaryFormat, binary);
12338
12339 try
12340 {
12341 gl::Context *context = gl::getNonLostContext();
12342
12343 if (context)
12344 {
12345 gl::Program *programObject = context->getProgram(program);
12346
daniel@transgaming.com716056c2012-07-24 18:38:59 +000012347 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012348 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012349 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012350 }
12351
12352 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
12353
12354 if (!programBinary)
12355 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012356 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012357 }
12358
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012359 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012360 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012361 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012362 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012363
12364 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012365 }
12366 }
12367 catch(std::bad_alloc&)
12368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012369 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012370 }
12371}
12372
12373void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
12374 const void *binary, GLint length)
12375{
12376 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
12377 program, binaryFormat, binary, length);
12378
12379 try
12380 {
12381 gl::Context *context = gl::getNonLostContext();
12382
12383 if (context)
12384 {
12385 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12386 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012387 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012388 }
12389
12390 gl::Program *programObject = context->getProgram(program);
12391
12392 if (!programObject)
12393 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012394 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012395 }
12396
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012397 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012398 }
12399 }
12400 catch(std::bad_alloc&)
12401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012402 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012403 }
12404}
12405
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012406void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12407{
12408 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12409
12410 try
12411 {
12412 gl::Context *context = gl::getNonLostContext();
12413
12414 if (context)
12415 {
12416 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12417 {
12418 return gl::error(GL_INVALID_VALUE);
12419 }
12420
12421 if (context->getDrawFramebufferHandle() == 0)
12422 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012423 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012424 {
12425 return gl::error(GL_INVALID_OPERATION);
12426 }
12427
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012428 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012429 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012430 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012431 }
12432 }
12433 else
12434 {
12435 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12436 {
12437 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12438 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12439 {
12440 return gl::error(GL_INVALID_OPERATION);
12441 }
12442 }
12443 }
12444
12445 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12446
12447 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12448 {
12449 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12450 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012451
12452 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12453 {
12454 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12455 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012456 }
12457 }
12458 catch (std::bad_alloc&)
12459 {
12460 return gl::error(GL_OUT_OF_MEMORY);
12461 }
12462}
12463
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012464__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12465{
12466 struct Extension
12467 {
12468 const char *name;
12469 __eglMustCastToProperFunctionPointerType address;
12470 };
12471
12472 static const Extension glExtensions[] =
12473 {
12474 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012475 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012476 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012477 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12478 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12479 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12480 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12481 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12482 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12483 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012484 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012485 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012486 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12487 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12488 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12489 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012490 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12491 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12492 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12493 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12494 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12495 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12496 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012497 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012498 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12499 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12500 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012501 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12502 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012503
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012504 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012505 {
12506 if (strcmp(procname, glExtensions[ext].name) == 0)
12507 {
12508 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12509 }
12510 }
12511
12512 return NULL;
12513}
12514
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012515// Non-public functions used by EGL
12516
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012517bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012518{
12519 EVENT("(egl::Surface* surface = 0x%0.8p)",
12520 surface);
12521
12522 try
12523 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012524 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012525
12526 if (context)
12527 {
12528 gl::Texture2D *textureObject = context->getTexture2D();
12529
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012530 if (textureObject->isImmutable())
12531 {
12532 return false;
12533 }
12534
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012535 if (textureObject)
12536 {
12537 textureObject->bindTexImage(surface);
12538 }
12539 }
12540 }
12541 catch(std::bad_alloc&)
12542 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012543 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012544 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012545
12546 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012547}
12548
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012549}