blob: e87213185f3c9e489b4b6762fff03647bd450677 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002//
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
9
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +000010#include "common/version.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
12#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000013#include "common/utilities.h"
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +000014#include "libGLESv2/formatutils.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000016#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000020#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000022#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000023#include "libGLESv2/Context.h"
Jamie Madill57a89722013-07-02 11:57:03 -040024#include "libGLESv2/VertexArray.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000026bool validImageSize(const gl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000028 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000029 {
30 return false;
31 }
32
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000033 if (context->supportsNonPower2Texture())
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000034 {
35 return true;
36 }
37
38 if (level == 0)
39 {
40 return true;
41 }
42
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000043 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000044 {
45 return true;
46 }
47
48 return false;
49}
50
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +000051bool validCompressedImageSize(GLsizei width, GLsizei height)
52{
53 if (width != 1 && width != 2 && width % 4 != 0)
54 {
55 return false;
56 }
57
58 if (height != 1 && height != 2 && height % 4 != 0)
59 {
60 return false;
61 }
62
63 return true;
64}
65
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066// Verify that format/type are one of the combinations from table 3.4.
67bool checkTextureFormatType(GLenum format, GLenum type)
68{
69 // validate <format> by itself (used as secondary key below)
70 switch (format)
71 {
72 case GL_RGBA:
73 case GL_BGRA_EXT:
74 case GL_RGB:
75 case GL_ALPHA:
76 case GL_LUMINANCE:
77 case GL_LUMINANCE_ALPHA:
78 case GL_DEPTH_COMPONENT:
79 case GL_DEPTH_STENCIL_OES:
80 break;
81 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000082 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000083 }
84
85 // invalid <type> -> sets INVALID_ENUM
86 // invalid <format>+<type> combination -> sets INVALID_OPERATION
87 switch (type)
88 {
89 case GL_UNSIGNED_BYTE:
90 switch (format)
91 {
92 case GL_RGBA:
93 case GL_BGRA_EXT:
94 case GL_RGB:
95 case GL_ALPHA:
96 case GL_LUMINANCE:
97 case GL_LUMINANCE_ALPHA:
98 return true;
99 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000100 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000101 }
102
103 case GL_FLOAT:
104 case GL_HALF_FLOAT_OES:
105 switch (format)
106 {
107 case GL_RGBA:
108 case GL_RGB:
109 case GL_ALPHA:
110 case GL_LUMINANCE:
111 case GL_LUMINANCE_ALPHA:
112 return true;
113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000114 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000115 }
116
117 case GL_UNSIGNED_SHORT_4_4_4_4:
118 case GL_UNSIGNED_SHORT_5_5_5_1:
119 switch (format)
120 {
121 case GL_RGBA:
122 return true;
123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000124 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000125 }
126
127 case GL_UNSIGNED_SHORT_5_6_5:
128 switch (format)
129 {
130 case GL_RGB:
131 return true;
132 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000133 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000134 }
135
136 case GL_UNSIGNED_SHORT:
137 case GL_UNSIGNED_INT:
138 switch (format)
139 {
140 case GL_DEPTH_COMPONENT:
141 return true;
142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000143 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000144 }
145
146 case GL_UNSIGNED_INT_24_8_OES:
147 switch (format)
148 {
149 case GL_DEPTH_STENCIL_OES:
150 return true;
151 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000152 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000153 }
154
155 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000156 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000157 }
158}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000160bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000161 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000162 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000163{
164 if (!texture)
165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000166 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000167 }
168
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000169 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000172 }
173
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000174 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000175 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000176 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000177 if (internalformat != texture->getInternalFormat(level))
178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000179 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000180 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000181 }
182
183 if (compressed)
184 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000185 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
186 (height % 4 != 0 && height != texture->getHeight(0)))
187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000188 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000189 }
190 }
191
192 if (xoffset + width > texture->getWidth(level) ||
193 yoffset + height > texture->getHeight(level))
194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
198 return true;
199}
200
201bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000202 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000203 gl::TextureCubeMap *texture)
204{
205 if (!texture)
206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000207 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000208 }
209
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000210 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000213 }
214
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000215 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000216 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000217 GLenum internalformat = gl::GetSizedInternalFormat(format, type, 2);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000218 if (internalformat != texture->getInternalFormat(target, level))
219 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000220 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000221 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000222 }
223
224 if (compressed)
225 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000226 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
227 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000228 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000229 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000230 }
231 }
232
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000233 if (xoffset + width > texture->getWidth(target, level) ||
234 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000236 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000237 }
238
239 return true;
240}
241
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000242bool validateES2TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
243 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
244 GLint border, GLenum format, GLenum type, const GLvoid *pixels)
245{
246 if (!validImageSize(context, level, width, height, 1))
247 {
248 return gl::error(GL_INVALID_VALUE, false);
249 }
250
251 if (isCompressed && !validCompressedImageSize(width, height))
252 {
253 return gl::error(GL_INVALID_OPERATION, false);
254 }
255
256 if (level < 0 || xoffset < 0 ||
257 std::numeric_limits<GLsizei>::max() - xoffset < width ||
258 std::numeric_limits<GLsizei>::max() - yoffset < height)
259 {
260 return gl::error(GL_INVALID_VALUE, false);
261 }
262
263 if (!isSubImage && !isCompressed && internalformat != GLint(format))
264 {
265 return gl::error(GL_INVALID_OPERATION, false);
266 }
267
268 gl::Texture *texture = NULL;
269 bool textureCompressed = false;
270 GLenum textureInternalFormat = GL_NONE;
271 GLint textureLevelWidth = 0;
272 GLint textureLevelHeight = 0;
273 switch (target)
274 {
275 case GL_TEXTURE_2D:
276 {
277 if (width > (context->getMaximum2DTextureDimension() >> level) ||
278 height > (context->getMaximum2DTextureDimension() >> level))
279 {
280 return gl::error(GL_INVALID_VALUE, false);
281 }
282
283 gl::Texture2D *tex2d = context->getTexture2D();
284 if (tex2d)
285 {
286 textureCompressed = tex2d->isCompressed(level);
287 textureInternalFormat = tex2d->getInternalFormat(level);
288 textureLevelWidth = tex2d->getWidth(level);
289 textureLevelHeight = tex2d->getHeight(level);
290 texture = tex2d;
291 }
292
293 if (isSubImage && !validateSubImageParams2D(isCompressed, width, height, xoffset, yoffset,
294 level, format, type, tex2d))
295 {
296 return false;
297 }
298
299 texture = tex2d;
300 }
301 break;
302
303 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
304 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
305 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
309 {
310 if (!isSubImage && width != height)
311 {
312 return gl::error(GL_INVALID_VALUE, false);
313 }
314
315 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
316 height > (context->getMaximumCubeTextureDimension() >> level))
317 {
318 return gl::error(GL_INVALID_VALUE, false);
319 }
320
321 gl::TextureCubeMap *texCube = context->getTextureCubeMap();
322 if (texCube)
323 {
324 textureCompressed = texCube->isCompressed(target, level);
325 textureInternalFormat = texCube->getInternalFormat(target, level);
326 textureLevelWidth = texCube->getWidth(target, level);
327 textureLevelHeight = texCube->getHeight(target, level);
328 texture = texCube;
329 }
330
331 if (isSubImage && !validateSubImageParamsCube(isCompressed, width, height, xoffset, yoffset,
332 target, level, format, type, texCube))
333 {
334 return false;
335 }
336 }
337 break;
338
339 default:
340 return gl::error(GL_INVALID_ENUM, false);
341 }
342
343 if (!texture)
344 {
345 return gl::error(GL_INVALID_OPERATION, false);
346 }
347
348 if (!isSubImage && texture->isImmutable())
349 {
350 return gl::error(GL_INVALID_OPERATION, false);
351 }
352
353 // Verify zero border
354 if (border != 0)
355 {
356 return gl::error(GL_INVALID_VALUE, false);
357 }
358
359 // Verify texture is not requesting more mip levels than are available.
360 if (level > context->getMaximumTextureLevel())
361 {
362 return gl::error(GL_INVALID_VALUE, false);
363 }
364
365 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
366 if (isCompressed)
367 {
368 switch (actualInternalFormat)
369 {
370 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
371 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
372 if (!context->supportsDXT1Textures())
373 {
374 return gl::error(GL_INVALID_ENUM, false);
375 }
376 break;
377 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
378 if (!context->supportsDXT3Textures())
379 {
380 return gl::error(GL_INVALID_ENUM, false);
381 }
382 break;
383 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
384 if (!context->supportsDXT5Textures())
385 {
386 return gl::error(GL_INVALID_ENUM, false);
387 }
388 break;
389 default:
390 return gl::error(GL_INVALID_ENUM, false);
391 }
392 }
393 else
394 {
395 // validate <type> by itself (used as secondary key below)
396 switch (type)
397 {
398 case GL_UNSIGNED_BYTE:
399 case GL_UNSIGNED_SHORT_5_6_5:
400 case GL_UNSIGNED_SHORT_4_4_4_4:
401 case GL_UNSIGNED_SHORT_5_5_5_1:
402 case GL_UNSIGNED_SHORT:
403 case GL_UNSIGNED_INT:
404 case GL_UNSIGNED_INT_24_8_OES:
405 case GL_HALF_FLOAT_OES:
406 case GL_FLOAT:
407 break;
408 default:
409 return gl::error(GL_INVALID_ENUM, false);
410 }
411
412 // validate <format> + <type> combinations
413 // - invalid <format> -> sets INVALID_ENUM
414 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
415 switch (format)
416 {
417 case GL_ALPHA:
418 case GL_LUMINANCE:
419 case GL_LUMINANCE_ALPHA:
420 switch (type)
421 {
422 case GL_UNSIGNED_BYTE:
423 case GL_FLOAT:
424 case GL_HALF_FLOAT_OES:
425 break;
426 default:
427 return gl::error(GL_INVALID_OPERATION, false);
428 }
429 break;
430 case GL_RGB:
431 switch (type)
432 {
433 case GL_UNSIGNED_BYTE:
434 case GL_UNSIGNED_SHORT_5_6_5:
435 case GL_FLOAT:
436 case GL_HALF_FLOAT_OES:
437 break;
438 default:
439 return gl::error(GL_INVALID_OPERATION, false);
440 }
441 break;
442 case GL_RGBA:
443 switch (type)
444 {
445 case GL_UNSIGNED_BYTE:
446 case GL_UNSIGNED_SHORT_4_4_4_4:
447 case GL_UNSIGNED_SHORT_5_5_5_1:
448 case GL_FLOAT:
449 case GL_HALF_FLOAT_OES:
450 break;
451 default:
452 return gl::error(GL_INVALID_OPERATION, false);
453 }
454 break;
455 case GL_BGRA_EXT:
456 switch (type)
457 {
458 case GL_UNSIGNED_BYTE:
459 break;
460 default:
461 return gl::error(GL_INVALID_OPERATION, false);
462 }
463 break;
464 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
465 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
466 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
467 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
468 break;
469 case GL_DEPTH_COMPONENT:
470 switch (type)
471 {
472 case GL_UNSIGNED_SHORT:
473 case GL_UNSIGNED_INT:
474 break;
475 default:
476 return gl::error(GL_INVALID_OPERATION, false);
477 }
478 break;
479 case GL_DEPTH_STENCIL_OES:
480 switch (type)
481 {
482 case GL_UNSIGNED_INT_24_8_OES:
483 break;
484 default:
485 return gl::error(GL_INVALID_OPERATION, false);
486 }
487 break;
488 default:
489 return gl::error(GL_INVALID_ENUM, false);
490 }
491
492 switch (format)
493 {
494 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
495 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
496 if (context->supportsDXT1Textures())
497 {
498 return gl::error(GL_INVALID_OPERATION, false);
499 }
500 else
501 {
502 return gl::error(GL_INVALID_ENUM, false);
503 }
504 break;
505 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
506 if (context->supportsDXT3Textures())
507 {
508 return gl::error(GL_INVALID_OPERATION, false);
509 }
510 else
511 {
512 return gl::error(GL_INVALID_ENUM, false);
513 }
514 break;
515 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
516 if (context->supportsDXT5Textures())
517 {
518 return gl::error(GL_INVALID_OPERATION, false);
519 }
520 else
521 {
522 return gl::error(GL_INVALID_ENUM, false);
523 }
524 break;
525 case GL_DEPTH_COMPONENT:
526 case GL_DEPTH_STENCIL_OES:
527 if (!context->supportsDepthTextures())
528 {
529 return gl::error(GL_INVALID_VALUE, false);
530 }
531 if (target != GL_TEXTURE_2D)
532 {
533 return gl::error(GL_INVALID_OPERATION, false);
534 }
535 // OES_depth_texture supports loading depth data and multiple levels,
536 // but ANGLE_depth_texture does not
537 if (pixels != NULL || level != 0)
538 {
539 return gl::error(GL_INVALID_OPERATION, false);
540 }
541 break;
542 default:
543 break;
544 }
545
546 if (type == GL_FLOAT)
547 {
548 if (!context->supportsFloat32Textures())
549 {
550 return gl::error(GL_INVALID_ENUM, false);
551 }
552 }
553 else if (type == GL_HALF_FLOAT_OES)
554 {
555 if (!context->supportsFloat16Textures())
556 {
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559 }
560 }
561
562 return true;
563}
564
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +0000565bool validateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
566 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
567 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000568{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000569 // Validate image size
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000570 if (!validImageSize(context, level, width, height, depth))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000571 {
572 return gl::error(GL_INVALID_VALUE, false);
573 }
574
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000575 if (isCompressed && !validCompressedImageSize(width, height))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000576 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000577 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000578 }
579
580 // Verify zero border
581 if (border != 0)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 // Validate dimensions based on Context limits and validate the texture
587 if (level > context->getMaximumTextureLevel())
588 {
589 return gl::error(GL_INVALID_VALUE, false);
590 }
591
592 gl::Texture *texture = NULL;
593 bool textureCompressed = false;
594 GLenum textureInternalFormat = GL_NONE;
595 GLint textureLevelWidth = 0;
596 GLint textureLevelHeight = 0;
597 GLint textureLevelDepth = 0;
598 switch (target)
599 {
600 case GL_TEXTURE_2D:
601 {
602 if (width > (context->getMaximum2DTextureDimension() >> level) ||
603 height > (context->getMaximum2DTextureDimension() >> level))
604 {
605 return gl::error(GL_INVALID_VALUE, false);
606 }
607
608 gl::Texture2D *texture2d = context->getTexture2D();
609 if (texture2d)
610 {
611 textureCompressed = texture2d->isCompressed(level);
612 textureInternalFormat = texture2d->getInternalFormat(level);
613 textureLevelWidth = texture2d->getWidth(level);
614 textureLevelHeight = texture2d->getHeight(level);
615 textureLevelDepth = 1;
616 texture = texture2d;
617 }
618 }
619 break;
620
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
627 {
shannonwoods@chromium.org92852cf2013-05-30 00:14:12 +0000628 if (!isSubImage && width != height)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000629 {
630 return gl::error(GL_INVALID_VALUE, false);
631 }
632
633 if (width > (context->getMaximumCubeTextureDimension() >> level))
634 {
635 return gl::error(GL_INVALID_VALUE, false);
636 }
637
638 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
639 if (textureCube)
640 {
641 textureCompressed = textureCube->isCompressed(target, level);
642 textureInternalFormat = textureCube->getInternalFormat(target, level);
643 textureLevelWidth = textureCube->getWidth(target, level);
644 textureLevelHeight = textureCube->getHeight(target, level);
645 textureLevelDepth = 1;
646 texture = textureCube;
647 }
648 }
649 break;
650
651 case GL_TEXTURE_3D:
652 {
653 if (width > (context->getMaximum3DTextureDimension() >> level) ||
654 height > (context->getMaximum3DTextureDimension() >> level) ||
655 depth > (context->getMaximum3DTextureDimension() >> level))
656 {
657 return gl::error(GL_INVALID_VALUE, false);
658 }
659
660 gl::Texture3D *texture3d = context->getTexture3D();
661 if (texture3d)
662 {
663 textureCompressed = texture3d->isCompressed(level);
664 textureInternalFormat = texture3d->getInternalFormat(level);
665 textureLevelWidth = texture3d->getWidth(level);
666 textureLevelHeight = texture3d->getHeight(level);
667 textureLevelDepth = texture3d->getDepth(level);
668 texture = texture3d;
669 }
670 }
671 break;
672
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000673 case GL_TEXTURE_2D_ARRAY:
674 {
675 if (width > (context->getMaximum2DTextureDimension() >> level) ||
676 height > (context->getMaximum2DTextureDimension() >> level) ||
677 depth > (context->getMaximum2DArrayTextureLayers() >> level))
678 {
679 return gl::error(GL_INVALID_VALUE, false);
680 }
681
682 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
683 if (texture2darray)
684 {
685 textureCompressed = texture2darray->isCompressed(level);
686 textureInternalFormat = texture2darray->getInternalFormat(level);
687 textureLevelWidth = texture2darray->getWidth(level);
688 textureLevelHeight = texture2darray->getHeight(level);
689 textureLevelDepth = texture2darray->getDepth(level);
690 texture = texture2darray;
691 }
692 }
693 break;
694
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000695 default:
696 return gl::error(GL_INVALID_ENUM, false);
697 }
698
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000699 if (!texture)
700 {
701 return gl::error(GL_INVALID_OPERATION, false);
702 }
703
shannonwoods@chromium.orgcf2533c2013-05-30 00:14:18 +0000704 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000705 {
706 return gl::error(GL_INVALID_OPERATION, false);
707 }
708
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000709 // Validate texture formats
710 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
711 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000712 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000713 if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000714 {
715 return gl::error(GL_INVALID_ENUM, false);
716 }
717
718 if (target == GL_TEXTURE_3D)
719 {
720 return gl::error(GL_INVALID_OPERATION, false);
721 }
722 }
723 else
724 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000725 if (!gl::IsValidInternalFormat(actualInternalFormat, context) ||
726 !gl::IsValidFormat(format, context->getClientVersion()) ||
727 !gl::IsValidType(type, context->getClientVersion()))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000728 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000729 return gl::error(GL_INVALID_ENUM, false);
730 }
731
732 if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getClientVersion()))
733 {
734 return gl::error(GL_INVALID_OPERATION, false);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000735 }
736
737 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
738 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000739 {
740 return gl::error(GL_INVALID_OPERATION, false);
741 }
742 }
743
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000744 // Validate sub image parameters
745 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000746 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000747 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000748 {
749 return gl::error(GL_INVALID_OPERATION, false);
750 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000751
752 if (format != GL_NONE)
753 {
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +0000754 GLenum internalformat = gl::GetSizedInternalFormat(format, type, context->getClientVersion());
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000755 if (internalformat != textureInternalFormat)
756 {
757 return gl::error(GL_INVALID_OPERATION, false);
758 }
759 }
760
761 if (isCompressed)
762 {
763 if ((width % 4 != 0 && width != textureLevelWidth) ||
764 (height % 4 != 0 && height != textureLevelHeight))
765 {
766 return gl::error(GL_INVALID_OPERATION, false);
767 }
768 }
769
770 if (width == 0 || height == 0 || depth == 0)
771 {
772 return false;
773 }
774
775 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
776 {
777 return gl::error(GL_INVALID_VALUE, false);
778 }
779
780 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
781 std::numeric_limits<GLsizei>::max() - yoffset < height ||
782 std::numeric_limits<GLsizei>::max() - zoffset < depth)
783 {
784 return gl::error(GL_INVALID_VALUE, false);
785 }
786
787 if (xoffset + width > textureLevelWidth ||
788 yoffset + height > textureLevelHeight ||
789 zoffset + depth > textureLevelDepth)
790 {
791 return gl::error(GL_INVALID_VALUE, false);
792 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000793 }
794
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000795 return true;
796}
797
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +0000798
799bool validateES2CopyTexImageParameters(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
800 GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height,
801 GLint border)
802{
803 if (!gl::IsInternalTextureTarget(target))
804 {
805 return gl::error(GL_INVALID_ENUM, false);
806 }
807
808 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
809 {
810 return gl::error(GL_INVALID_VALUE, false);
811 }
812
813 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
814 {
815 return gl::error(GL_INVALID_VALUE, false);
816 }
817
818 if (width == 0 || height == 0)
819 {
820 return false;
821 }
822
823 // Verify zero border
824 if (border != 0)
825 {
826 return gl::error(GL_INVALID_VALUE, false);
827 }
828
829 // Validate dimensions based on Context limits and validate the texture
830 if (level > context->getMaximumTextureLevel())
831 {
832 return gl::error(GL_INVALID_VALUE, false);
833 }
834
835 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
836
837 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
838 {
839 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
840 }
841
842 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
843 {
844 return gl::error(GL_INVALID_OPERATION, false);
845 }
846
847 GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
848 gl::Texture *texture = NULL;
849 GLenum textureFormat = GL_RGBA;
850
851 switch (target)
852 {
853 case GL_TEXTURE_2D:
854 {
855 if (width > (context->getMaximum2DTextureDimension() >> level) ||
856 height > (context->getMaximum2DTextureDimension() >> level))
857 {
858 return gl::error(GL_INVALID_VALUE, false);
859 }
860
861 gl::Texture2D *tex2d = context->getTexture2D();
862 if (tex2d)
863 {
864 if (isSubImage && !validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
865 {
866 return false; // error already registered by validateSubImageParams
867 }
868 texture = tex2d;
869 textureFormat = gl::GetFormat(tex2d->getInternalFormat(level), context->getClientVersion());
870 }
871 }
872 break;
873
874 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
875 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
876 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
877 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
878 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
879 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
880 {
881 if (!isSubImage && width != height)
882 {
883 return gl::error(GL_INVALID_VALUE, false);
884 }
885
886 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
887 height > (context->getMaximumCubeTextureDimension() >> level))
888 {
889 return gl::error(GL_INVALID_VALUE, false);
890 }
891
892 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
893 if (texcube)
894 {
895 if (isSubImage && !validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
896 {
897 return false; // error already registered by validateSubImageParams
898 }
899 texture = texcube;
900 textureFormat = gl::GetFormat(texcube->getInternalFormat(target, level), context->getClientVersion());
901 }
902 }
903 break;
904
905 default:
906 return gl::error(GL_INVALID_ENUM, false);
907 }
908
909 if (!texture)
910 {
911 return gl::error(GL_INVALID_OPERATION, false);
912 }
913
914 if (texture->isImmutable() && !isSubImage)
915 {
916 return gl::error(GL_INVALID_OPERATION, false);
917 }
918
919
920 // [OpenGL ES 2.0.24] table 3.9
921 if (isSubImage)
922 {
923 switch (textureFormat)
924 {
925 case GL_ALPHA:
926 if (colorbufferFormat != GL_ALPHA8_EXT &&
927 colorbufferFormat != GL_RGBA4 &&
928 colorbufferFormat != GL_RGB5_A1 &&
929 colorbufferFormat != GL_RGBA8_OES)
930 {
931 return gl::error(GL_INVALID_OPERATION, false);
932 }
933 break;
934 case GL_LUMINANCE:
935 case GL_RGB:
936 if (colorbufferFormat != GL_RGB565 &&
937 colorbufferFormat != GL_RGB8_OES &&
938 colorbufferFormat != GL_RGBA4 &&
939 colorbufferFormat != GL_RGB5_A1 &&
940 colorbufferFormat != GL_RGBA8_OES)
941 {
942 return gl::error(GL_INVALID_OPERATION, false);
943 }
944 break;
945 case GL_LUMINANCE_ALPHA:
946 case GL_RGBA:
947 if (colorbufferFormat != GL_RGBA4 &&
948 colorbufferFormat != GL_RGB5_A1 &&
949 colorbufferFormat != GL_RGBA8_OES)
950 {
951 return gl::error(GL_INVALID_OPERATION, false);
952 }
953 break;
954 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
955 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
956 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
957 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
958 return gl::error(GL_INVALID_OPERATION, false);
959 case GL_DEPTH_COMPONENT:
960 case GL_DEPTH_STENCIL_OES:
961 return gl::error(GL_INVALID_OPERATION, false);
962 default:
963 return gl::error(GL_INVALID_OPERATION, false);
964 }
965 }
966 else
967 {
968 switch (internalformat)
969 {
970 case GL_ALPHA:
971 if (colorbufferFormat != GL_ALPHA8_EXT &&
972 colorbufferFormat != GL_RGBA4 &&
973 colorbufferFormat != GL_RGB5_A1 &&
974 colorbufferFormat != GL_BGRA8_EXT &&
975 colorbufferFormat != GL_RGBA8_OES)
976 {
977 return gl::error(GL_INVALID_OPERATION, false);
978 }
979 break;
980 case GL_LUMINANCE:
981 case GL_RGB:
982 if (colorbufferFormat != GL_RGB565 &&
983 colorbufferFormat != GL_RGB8_OES &&
984 colorbufferFormat != GL_RGBA4 &&
985 colorbufferFormat != GL_RGB5_A1 &&
986 colorbufferFormat != GL_BGRA8_EXT &&
987 colorbufferFormat != GL_RGBA8_OES)
988 {
989 return gl::error(GL_INVALID_OPERATION, false);
990 }
991 break;
992 case GL_LUMINANCE_ALPHA:
993 case GL_RGBA:
994 if (colorbufferFormat != GL_RGBA4 &&
995 colorbufferFormat != GL_RGB5_A1 &&
996 colorbufferFormat != GL_BGRA8_EXT &&
997 colorbufferFormat != GL_RGBA8_OES)
998 {
999 return gl::error(GL_INVALID_OPERATION, false);
1000 }
1001 break;
1002 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1003 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1004 if (context->supportsDXT1Textures())
1005 {
1006 return gl::error(GL_INVALID_OPERATION, false);
1007 }
1008 else
1009 {
1010 return gl::error(GL_INVALID_ENUM, false);
1011 }
1012 break;
1013 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1014 if (context->supportsDXT3Textures())
1015 {
1016 return gl::error(GL_INVALID_OPERATION, false);
1017 }
1018 else
1019 {
1020 return gl::error(GL_INVALID_ENUM, false);
1021 }
1022 break;
1023 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1024 if (context->supportsDXT5Textures())
1025 {
1026 return gl::error(GL_INVALID_OPERATION, false);
1027 }
1028 else
1029 {
1030 return gl::error(GL_INVALID_ENUM, false);
1031 }
1032 break;
1033 case GL_DEPTH_COMPONENT:
1034 case GL_DEPTH_COMPONENT16:
1035 case GL_DEPTH_COMPONENT32_OES:
1036 case GL_DEPTH_STENCIL_OES:
1037 case GL_DEPTH24_STENCIL8_OES:
1038 if (context->supportsDepthTextures())
1039 {
1040 return gl::error(GL_INVALID_OPERATION, false);
1041 }
1042 else
1043 {
1044 return gl::error(GL_INVALID_ENUM, false);
1045 }
1046 default:
1047 return gl::error(GL_INVALID_ENUM, false);
1048 }
1049 }
1050
1051 return true;
1052}
1053
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001054bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
1055 bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
1056 GLsizei width, GLsizei height, GLint border)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001057{
1058 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001059 {
1060 return gl::error(GL_INVALID_VALUE, false);
1061 }
1062
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001063 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1064 {
1065 return gl::error(GL_INVALID_VALUE, false);
1066 }
1067
1068 if (width == 0 || height == 0)
1069 {
1070 return false;
1071 }
1072
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001073 if (border != 0)
1074 {
1075 return gl::error(GL_INVALID_VALUE, false);
1076 }
1077
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001078 if (level > context->getMaximumTextureLevel())
1079 {
1080 return gl::error(GL_INVALID_VALUE, false);
1081 }
1082
1083 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
1084
1085 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1086 {
1087 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1088 }
1089
1090 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
1091 {
1092 return gl::error(GL_INVALID_OPERATION, false);
1093 }
1094
1095 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001096 GLenum colorbufferInternalFormat = source->getInternalFormat();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001097 gl::Texture *texture = NULL;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001098 GLenum textureInternalFormat = GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001099 bool textureCompressed = false;
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001100 bool textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001101 GLint textureLevelWidth = 0;
1102 GLint textureLevelHeight = 0;
1103 GLint textureLevelDepth = 0;
1104 switch (target)
1105 {
1106 case GL_TEXTURE_2D:
1107 {
1108 gl::Texture2D *texture2d = context->getTexture2D();
1109 if (texture2d)
1110 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001111 textureInternalFormat = texture2d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001112 textureCompressed = texture2d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001113 textureIsDepth = texture2d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001114 textureLevelWidth = texture2d->getWidth(level);
1115 textureLevelHeight = texture2d->getHeight(level);
1116 textureLevelDepth = 1;
1117 texture = texture2d;
1118 }
1119 }
1120 break;
1121
1122 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1123 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1124 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1125 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1126 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1127 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1128 {
1129 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1130 if (textureCube)
1131 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001132 textureInternalFormat = textureCube->getInternalFormat(target, level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001133 textureCompressed = textureCube->isCompressed(target, level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001134 textureIsDepth = false;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001135 textureLevelWidth = textureCube->getWidth(target, level);
1136 textureLevelHeight = textureCube->getHeight(target, level);
1137 textureLevelDepth = 1;
1138 texture = textureCube;
1139 }
1140 }
1141 break;
1142
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001143 case GL_TEXTURE_2D_ARRAY:
1144 {
1145 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1146 if (texture2dArray)
1147 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001148 textureInternalFormat = texture2dArray->getInternalFormat(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001149 textureCompressed = texture2dArray->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001150 textureIsDepth = texture2dArray->isDepth(level);
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00001151 textureLevelWidth = texture2dArray->getWidth(level);
1152 textureLevelHeight = texture2dArray->getHeight(level);
1153 textureLevelDepth = texture2dArray->getDepth(level);
1154 texture = texture2dArray;
1155 }
1156 }
1157 break;
1158
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001159 case GL_TEXTURE_3D:
1160 {
1161 gl::Texture3D *texture3d = context->getTexture3D();
1162 if (texture3d)
1163 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001164 textureInternalFormat = texture3d->getInternalFormat(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001165 textureCompressed = texture3d->isCompressed(level);
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001166 textureIsDepth = texture3d->isDepth(level);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001167 textureLevelWidth = texture3d->getWidth(level);
1168 textureLevelHeight = texture3d->getHeight(level);
1169 textureLevelDepth = texture3d->getDepth(level);
1170 texture = texture3d;
1171 }
1172 }
1173 break;
1174
1175 default:
1176 return gl::error(GL_INVALID_ENUM, false);
1177 }
1178
1179 if (!texture)
1180 {
1181 return gl::error(GL_INVALID_OPERATION, false);
1182 }
1183
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001184 if (texture->isImmutable() && !isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001185 {
1186 return gl::error(GL_INVALID_OPERATION, false);
1187 }
1188
Geoff Lang0e7c2fd2013-06-12 16:43:52 -04001189 if (textureIsDepth)
1190 {
1191 return gl::error(GL_INVALID_OPERATION, false);
1192 }
1193
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00001194 if (textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001195 {
1196 if ((width % 4 != 0 && width != textureLevelWidth) ||
1197 (height % 4 != 0 && height != textureLevelHeight))
1198 {
1199 return gl::error(GL_INVALID_OPERATION, false);
1200 }
1201 }
1202
Geoff Langa4d13322013-06-05 14:57:51 -04001203 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001204 {
Geoff Langa4d13322013-06-05 14:57:51 -04001205 if (xoffset + width > textureLevelWidth ||
1206 yoffset + height > textureLevelHeight ||
1207 zoffset >= textureLevelDepth)
1208 {
1209 return gl::error(GL_INVALID_VALUE, false);
1210 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001211
Geoff Langa4d13322013-06-05 14:57:51 -04001212 if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
1213 context->getClientVersion()))
1214 {
1215 return gl::error(GL_INVALID_OPERATION, false);
1216 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00001217 }
1218
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001219 return true;
1220}
1221
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00001222bool validateES2TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1223 GLsizei width, GLsizei height)
1224{
1225 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
1226 {
1227 return gl::error(GL_INVALID_ENUM, false);
1228 }
1229
1230 if (width < 1 || height < 1 || levels < 1)
1231 {
1232 return gl::error(GL_INVALID_VALUE, false);
1233 }
1234
1235 if (target == GL_TEXTURE_CUBE_MAP && width != height)
1236 {
1237 return gl::error(GL_INVALID_VALUE, false);
1238 }
1239
1240 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1241 {
1242 return gl::error(GL_INVALID_OPERATION, false);
1243 }
1244
1245 GLenum format = gl::GetFormat(internalformat, context->getClientVersion());
1246 GLenum type = gl::GetType(internalformat, context->getClientVersion());
1247
1248 if (format == GL_NONE || type == GL_NONE)
1249 {
1250 return gl::error(GL_INVALID_ENUM, false);
1251 }
1252
1253 switch (target)
1254 {
1255 case GL_TEXTURE_2D:
1256 if (width > context->getMaximum2DTextureDimension() ||
1257 height > context->getMaximum2DTextureDimension())
1258 {
1259 return gl::error(GL_INVALID_VALUE, false);
1260 }
1261 break;
1262 case GL_TEXTURE_CUBE_MAP:
1263 if (width > context->getMaximumCubeTextureDimension() ||
1264 height > context->getMaximumCubeTextureDimension())
1265 {
1266 return gl::error(GL_INVALID_VALUE, false);
1267 }
1268 break;
1269 default:
1270 return gl::error(GL_INVALID_ENUM, false);
1271 }
1272
1273 if (levels != 1 && !context->supportsNonPower2Texture())
1274 {
1275 if (!gl::isPow2(width) || !gl::isPow2(height))
1276 {
1277 return gl::error(GL_INVALID_OPERATION, false);
1278 }
1279 }
1280
1281 switch (internalformat)
1282 {
1283 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1284 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1285 if (!context->supportsDXT1Textures())
1286 {
1287 return gl::error(GL_INVALID_ENUM, false);
1288 }
1289 break;
1290 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1291 if (!context->supportsDXT3Textures())
1292 {
1293 return gl::error(GL_INVALID_ENUM, false);
1294 }
1295 break;
1296 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1297 if (!context->supportsDXT5Textures())
1298 {
1299 return gl::error(GL_INVALID_ENUM, false);
1300 }
1301 break;
1302 case GL_RGBA32F_EXT:
1303 case GL_RGB32F_EXT:
1304 case GL_ALPHA32F_EXT:
1305 case GL_LUMINANCE32F_EXT:
1306 case GL_LUMINANCE_ALPHA32F_EXT:
1307 if (!context->supportsFloat32Textures())
1308 {
1309 return gl::error(GL_INVALID_ENUM, false);
1310 }
1311 break;
1312 case GL_RGBA16F_EXT:
1313 case GL_RGB16F_EXT:
1314 case GL_ALPHA16F_EXT:
1315 case GL_LUMINANCE16F_EXT:
1316 case GL_LUMINANCE_ALPHA16F_EXT:
1317 if (!context->supportsFloat16Textures())
1318 {
1319 return gl::error(GL_INVALID_ENUM, false);
1320 }
1321 break;
1322 case GL_DEPTH_COMPONENT16:
1323 case GL_DEPTH_COMPONENT32_OES:
1324 case GL_DEPTH24_STENCIL8_OES:
1325 if (!context->supportsDepthTextures())
1326 {
1327 return gl::error(GL_INVALID_ENUM, false);
1328 }
1329 if (target != GL_TEXTURE_2D)
1330 {
1331 return gl::error(GL_INVALID_OPERATION, false);
1332 }
1333 // ANGLE_depth_texture only supports 1-level textures
1334 if (levels != 1)
1335 {
1336 return gl::error(GL_INVALID_OPERATION, false);
1337 }
1338 break;
1339 default:
1340 break;
1341 }
1342
1343 gl::Texture *texture = NULL;
1344 switch(target)
1345 {
1346 case GL_TEXTURE_2D:
1347 texture = context->getTexture2D();
1348 break;
1349 case GL_TEXTURE_CUBE_MAP:
1350 texture = context->getTextureCubeMap();
1351 break;
1352 default:
1353 UNREACHABLE();
1354 }
1355
1356 if (!texture || texture->id() == 0)
1357 {
1358 return gl::error(GL_INVALID_OPERATION, false);
1359 }
1360
1361 if (texture->isImmutable())
1362 {
1363 return gl::error(GL_INVALID_OPERATION, false);
1364 }
1365
1366 return true;
1367}
1368
1369bool validateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
1370 GLsizei width, GLsizei height, GLsizei depth)
1371{
1372 if (width < 1 || height < 1 || depth < 1 || levels < 1)
1373 {
1374 return gl::error(GL_INVALID_VALUE, false);
1375 }
1376
1377 if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
1378 {
1379 return gl::error(GL_INVALID_OPERATION, false);
1380 }
1381
1382 gl::Texture *texture = NULL;
1383 switch (target)
1384 {
1385 case GL_TEXTURE_2D:
1386 {
1387 texture = context->getTexture2D();
1388
1389 if (width > (context->getMaximum2DTextureDimension()) ||
1390 height > (context->getMaximum2DTextureDimension()))
1391 {
1392 return gl::error(GL_INVALID_VALUE, false);
1393 }
1394 }
1395 break;
1396
1397 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1398 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1399 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1400 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1401 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1402 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1403 {
1404 texture = context->getTextureCubeMap();
1405
1406 if (width != height)
1407 {
1408 return gl::error(GL_INVALID_VALUE, false);
1409 }
1410
1411 if (width > (context->getMaximumCubeTextureDimension()))
1412 {
1413 return gl::error(GL_INVALID_VALUE, false);
1414 }
1415 }
1416 break;
1417
1418 case GL_TEXTURE_3D:
1419 {
1420 texture = context->getTexture3D();
1421
1422 if (width > (context->getMaximum3DTextureDimension()) ||
1423 height > (context->getMaximum3DTextureDimension()) ||
1424 depth > (context->getMaximum3DTextureDimension()))
1425 {
1426 return gl::error(GL_INVALID_VALUE, false);
1427 }
1428 }
1429 break;
1430
1431 case GL_TEXTURE_2D_ARRAY:
1432 {
1433 texture = context->getTexture2DArray();
1434
1435 if (width > (context->getMaximum2DTextureDimension()) ||
1436 height > (context->getMaximum2DTextureDimension()) ||
1437 depth > (context->getMaximum2DArrayTextureLayers()))
1438 {
1439 return gl::error(GL_INVALID_VALUE, false);
1440 }
1441 }
1442 break;
1443
1444 default:
1445 return gl::error(GL_INVALID_ENUM, false);
1446 }
1447
1448 if (!texture || texture->id() == 0)
1449 {
1450 return gl::error(GL_INVALID_OPERATION, false);
1451 }
1452
1453 if (texture->isImmutable())
1454 {
1455 return gl::error(GL_INVALID_OPERATION, false);
1456 }
1457
1458 if (!gl::IsValidInternalFormat(internalformat, context))
1459 {
1460 return gl::error(GL_INVALID_ENUM, false);
1461 }
1462
1463 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1464 {
1465 return gl::error(GL_INVALID_ENUM, false);
1466 }
1467
1468 return true;
1469}
1470
Geoff Lang2e1dcd52013-05-29 10:34:08 -04001471bool validateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
1472 GLenum internalformat, GLsizei width, GLsizei height,
1473 bool angleExtension)
1474{
1475 switch (target)
1476 {
1477 case GL_RENDERBUFFER:
1478 break;
1479 default:
1480 return gl::error(GL_INVALID_ENUM, false);
1481 }
1482
1483 if (width < 0 || height < 0 || samples < 0)
1484 {
1485 return gl::error(GL_INVALID_VALUE, false);
1486 }
1487
1488 if (!gl::IsValidInternalFormat(internalformat, context))
1489 {
1490 return gl::error(GL_INVALID_ENUM, false);
1491 }
1492
1493 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
1494 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
1495 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
1496 // internal format must be sized and not an integer format if samples is greater than zero.
1497 if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion()))
1498 {
1499 return gl::error(GL_INVALID_ENUM, false);
1500 }
1501
1502 if (gl::IsIntegerFormat(internalformat, context->getClientVersion()) && samples > 0)
1503 {
1504 return gl::error(GL_INVALID_OPERATION, false);
1505 }
1506
1507 if (!gl::IsColorRenderingSupported(internalformat, context) &&
1508 !gl::IsDepthRenderingSupported(internalformat, context) &&
1509 !gl::IsStencilRenderingSupported(internalformat, context))
1510 {
1511 return gl::error(GL_INVALID_ENUM, false);
1512 }
1513
1514 if (std::max(width, height) > context->getMaximumRenderbufferDimension())
1515 {
1516 return gl::error(GL_INVALID_VALUE, false);
1517 }
1518
1519 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
1520 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
1521 // states that samples must be less than or equal to the maximum samples for the specified
1522 // internal format.
1523 if (angleExtension)
1524 {
1525 if (samples > context->getMaxSupportedSamples())
1526 {
1527 return gl::error(GL_INVALID_VALUE, false);
1528 }
1529 }
1530 else
1531 {
1532 if (samples > context->getMaxSupportedFormatSamples(internalformat))
1533 {
1534 return gl::error(GL_INVALID_VALUE, false);
1535 }
1536 }
1537
1538 GLuint handle = context->getRenderbufferHandle();
1539 if (handle == 0)
1540 {
1541 return gl::error(GL_INVALID_OPERATION, false);
1542 }
1543
1544 return true;
1545}
1546
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001547// check for combinations of format and type that are valid for ReadPixels
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001548bool validES2ReadFormatType(GLenum format, GLenum type)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001549{
1550 switch (format)
1551 {
1552 case GL_RGBA:
1553 switch (type)
1554 {
1555 case GL_UNSIGNED_BYTE:
1556 break;
1557 default:
1558 return false;
1559 }
1560 break;
1561 case GL_BGRA_EXT:
1562 switch (type)
1563 {
1564 case GL_UNSIGNED_BYTE:
1565 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1566 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1567 break;
1568 default:
1569 return false;
1570 }
1571 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00001572 default:
1573 return false;
1574 }
1575 return true;
1576}
1577
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001578bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
1579{
1580 switch (format)
1581 {
1582 case GL_RGBA:
1583 switch (type)
1584 {
1585 case GL_UNSIGNED_BYTE:
1586 break;
1587 case GL_UNSIGNED_INT_2_10_10_10_REV:
1588 if (internalFormat != GL_RGB10_A2)
1589 {
1590 return false;
1591 }
1592 break;
1593 default:
1594 return false;
1595 }
1596 break;
1597 case GL_RGBA_INTEGER:
1598 switch (type)
1599 {
1600 case GL_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001601 if (!gl::IsSignedIntegerFormat(internalFormat, 3))
1602 {
1603 return false;
1604 }
1605 break;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001606 case GL_UNSIGNED_INT:
Geoff Langd384a942013-06-05 15:00:10 -04001607 if (!gl::IsUnsignedIntegerFormat(internalFormat, 3))
1608 {
1609 return false;
1610 }
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00001611 break;
1612 default:
1613 return false;
1614 }
1615 break;
1616 case GL_BGRA_EXT:
1617 switch (type)
1618 {
1619 case GL_UNSIGNED_BYTE:
1620 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1621 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1622 break;
1623 default:
1624 return false;
1625 }
1626 break;
1627 default:
1628 return false;
1629 }
1630 return true;
1631}
1632
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00001633bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
1634 const GLenum* attachments)
1635{
1636 bool defaultFramebuffer = false;
1637
1638 switch (target)
1639 {
1640 case GL_DRAW_FRAMEBUFFER:
1641 case GL_FRAMEBUFFER:
1642 defaultFramebuffer = context->getDrawFramebufferHandle() == 0;
1643 break;
1644 case GL_READ_FRAMEBUFFER:
1645 defaultFramebuffer = context->getReadFramebufferHandle() == 0;
1646 break;
1647 default:
1648 return gl::error(GL_INVALID_ENUM, false);
1649 }
1650
1651 for (int i = 0; i < numAttachments; ++i)
1652 {
1653 if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
1654 {
1655 if (defaultFramebuffer)
1656 {
1657 return gl::error(GL_INVALID_ENUM, false);
1658 }
1659
1660 if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getMaximumRenderTargets())
1661 {
1662 return gl::error(GL_INVALID_OPERATION, false);
1663 }
1664 }
1665 else
1666 {
1667 switch (attachments[i])
1668 {
1669 case GL_DEPTH_ATTACHMENT:
1670 case GL_STENCIL_ATTACHMENT:
1671 case GL_DEPTH_STENCIL_ATTACHMENT:
1672 if (defaultFramebuffer)
1673 {
1674 return gl::error(GL_INVALID_ENUM, false);
1675 }
1676 break;
1677 case GL_COLOR:
1678 case GL_DEPTH:
1679 case GL_STENCIL:
1680 if (!defaultFramebuffer)
1681 {
1682 return gl::error(GL_INVALID_ENUM, false);
1683 }
1684 break;
1685 default:
1686 return gl::error(GL_INVALID_ENUM, false);
1687 }
1688 }
1689 }
1690
1691 return true;
1692}
1693
Geoff Lang758d5b22013-06-11 11:42:50 -04001694bool validateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1695 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
1696 GLenum filter, bool fromAngleExtension)
1697{
1698 switch (filter)
1699 {
1700 case GL_NEAREST:
1701 break;
1702 case GL_LINEAR:
1703 if (fromAngleExtension)
1704 {
1705 return gl::error(GL_INVALID_ENUM, false);
1706 }
1707 break;
1708 default:
1709 return gl::error(GL_INVALID_ENUM, false);
1710 }
1711
1712 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
1713 {
1714 return gl::error(GL_INVALID_VALUE, false);
1715 }
1716
1717 if (mask == 0)
1718 {
1719 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
1720 // buffers are copied.
1721 return false;
1722 }
1723
1724 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
1725 {
1726 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
1727 return gl::error(GL_INVALID_OPERATION, false);
1728 }
1729
1730 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
1731 // color buffer, leaving only nearest being unfiltered from above
1732 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
1733 {
1734 return gl::error(GL_INVALID_OPERATION, false);
1735 }
1736
1737 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
1738 {
1739 if (fromAngleExtension)
1740 {
1741 ERR("Blits with the same source and destination framebuffer are not supported by this "
1742 "implementation.");
1743 }
1744 return gl::error(GL_INVALID_OPERATION, false);
1745 }
1746
1747 gl::Framebuffer *readFramebuffer = context->getReadFramebuffer();
1748 gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer();
1749 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
1750 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1751 {
1752 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1753 }
1754
1755 if (drawFramebuffer->getSamples() != 0)
1756 {
1757 return gl::error(GL_INVALID_OPERATION, false);
1758 }
1759
1760 gl::Rectangle sourceClippedRect, destClippedRect;
1761 bool partialCopy;
1762 if (!context->clipBlitFramebufferCoordinates(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
1763 &sourceClippedRect, &destClippedRect, &partialCopy))
1764 {
1765 return gl::error(GL_INVALID_OPERATION, false);
1766 }
1767
1768 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
1769
1770 GLuint clientVersion = context->getClientVersion();
1771
1772 if (mask & GL_COLOR_BUFFER_BIT)
1773 {
1774 gl::Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer();
1775 gl::Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
1776
1777 if (readColorBuffer && drawColorBuffer)
1778 {
1779 GLint readInternalFormat = readColorBuffer->getActualFormat();
1780 GLint drawInternalFormat = drawColorBuffer->getActualFormat();
1781
1782 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
1783 {
1784 if (drawFramebuffer->isEnabledColorAttachment(i))
1785 {
1786 GLint drawbufferAttachmentFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
1787
1788 if (gl::IsNormalizedFixedPointFormat(readInternalFormat, clientVersion) &&
1789 !gl::IsNormalizedFixedPointFormat(drawbufferAttachmentFormat, clientVersion))
1790 {
1791 return gl::error(GL_INVALID_OPERATION, false);
1792 }
1793
1794 if (gl::IsUnsignedIntegerFormat(readInternalFormat, clientVersion) &&
1795 !gl::IsUnsignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1796 {
1797 return gl::error(GL_INVALID_OPERATION, false);
1798 }
1799
1800 if (gl::IsSignedIntegerFormat(readInternalFormat, clientVersion) &&
1801 !gl::IsSignedIntegerFormat(drawbufferAttachmentFormat, clientVersion))
1802 {
1803 return gl::error(GL_INVALID_OPERATION, false);
1804 }
1805
1806 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawbufferAttachmentFormat || !sameBounds))
1807 {
1808 return gl::error(GL_INVALID_OPERATION, false);
1809 }
1810 }
1811 }
1812
1813 if (gl::IsIntegerFormat(readInternalFormat, clientVersion) && filter == GL_LINEAR)
1814 {
1815 return gl::error(GL_INVALID_OPERATION, false);
1816 }
1817
1818 if (fromAngleExtension)
1819 {
1820 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
1821 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
1822 {
1823 return gl::error(GL_INVALID_OPERATION, false);
1824 }
1825
1826 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
1827 {
1828 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
1829 {
1830 if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D &&
1831 drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER)
1832 {
1833 return gl::error(GL_INVALID_OPERATION, false);
1834 }
1835
1836 if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat())
1837 {
1838 return gl::error(GL_INVALID_OPERATION, false);
1839 }
1840 }
1841 }
1842
1843 if (partialCopy && readFramebuffer->getSamples() != 0)
1844 {
1845 return gl::error(GL_INVALID_OPERATION, false);
1846 }
1847 }
1848 }
1849 }
1850
1851 if (mask & GL_DEPTH_BUFFER_BIT)
1852 {
1853 gl::Renderbuffer *readDepthBuffer = readFramebuffer->getDepthbuffer();
1854 gl::Renderbuffer *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
1855
1856 if (readDepthBuffer && drawDepthBuffer)
1857 {
1858 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
1859 {
1860 return gl::error(GL_INVALID_OPERATION, false);
1861 }
1862
1863 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
1864 {
1865 return gl::error(GL_INVALID_OPERATION, false);
1866 }
1867
1868 if (fromAngleExtension)
1869 {
1870 if (partialCopy)
1871 {
1872 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1873 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1874 }
1875
1876 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
1877 {
1878 return gl::error(GL_INVALID_OPERATION, false);
1879 }
1880 }
1881 }
1882 }
1883
1884 if (mask & GL_STENCIL_BUFFER_BIT)
1885 {
1886 gl::Renderbuffer *readStencilBuffer = readFramebuffer->getStencilbuffer();
1887 gl::Renderbuffer *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
1888
1889 if (fromAngleExtension && partialCopy)
1890 {
1891 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1892 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1893 }
1894
1895 if (readStencilBuffer && drawStencilBuffer)
1896 {
1897 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
1898 {
1899 return gl::error(GL_INVALID_OPERATION, false);
1900 }
1901
1902 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
1903 {
1904 return gl::error(GL_INVALID_OPERATION, false);
1905 }
1906
1907 if (fromAngleExtension)
1908 {
1909 if (partialCopy)
1910 {
1911 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
1912 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
1913 }
1914
1915 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
1916 {
1917 return gl::error(GL_INVALID_OPERATION, false);
1918 }
1919 }
1920 }
1921 }
1922
1923 return true;
1924}
1925
Jamie Madillaff71502013-07-02 11:57:05 -04001926bool validateGetVertexAttribParameters(GLenum pname, int clientVersion)
1927{
1928 switch (pname)
1929 {
1930 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
1931 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
1932 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
1933 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
1934 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
1935 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
1936 case GL_CURRENT_VERTEX_ATTRIB:
1937 return true;
1938
1939 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
1940 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
1941 // the same constant.
1942 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
1943 return true;
1944
Jamie Madill30855b32013-07-02 11:57:06 -04001945 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1946 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
1947
Jamie Madillaff71502013-07-02 11:57:05 -04001948 default:
1949 return gl::error(GL_INVALID_ENUM, false);
1950 }
1951}
1952
Jamie Madill478fdb22013-07-19 16:36:59 -04001953bool validateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
1954{
1955 switch (pname)
1956 {
1957 case GL_TEXTURE_WRAP_R:
1958 case GL_TEXTURE_SWIZZLE_R:
1959 case GL_TEXTURE_SWIZZLE_G:
1960 case GL_TEXTURE_SWIZZLE_B:
1961 case GL_TEXTURE_SWIZZLE_A:
1962 case GL_TEXTURE_BASE_LEVEL:
1963 case GL_TEXTURE_MAX_LEVEL:
1964 case GL_TEXTURE_COMPARE_MODE:
1965 case GL_TEXTURE_COMPARE_FUNC:
1966 case GL_TEXTURE_MIN_LOD:
1967 case GL_TEXTURE_MAX_LOD:
1968 if (context->getClientVersion() < 3)
1969 {
1970 return gl::error(GL_INVALID_ENUM, false);
1971 }
1972 break;
1973
1974 default: break;
1975 }
1976
1977 switch (pname)
1978 {
1979 case GL_TEXTURE_WRAP_S:
1980 case GL_TEXTURE_WRAP_T:
1981 case GL_TEXTURE_WRAP_R:
1982 switch (param)
1983 {
1984 case GL_REPEAT:
1985 case GL_CLAMP_TO_EDGE:
1986 case GL_MIRRORED_REPEAT:
1987 return true;
1988 default:
1989 return gl::error(GL_INVALID_ENUM, false);
1990 }
1991
1992 case GL_TEXTURE_MIN_FILTER:
1993 switch (param)
1994 {
1995 case GL_NEAREST:
1996 case GL_LINEAR:
1997 case GL_NEAREST_MIPMAP_NEAREST:
1998 case GL_LINEAR_MIPMAP_NEAREST:
1999 case GL_NEAREST_MIPMAP_LINEAR:
2000 case GL_LINEAR_MIPMAP_LINEAR:
2001 return true;
2002 default:
2003 return gl::error(GL_INVALID_ENUM, false);
2004 }
2005 break;
2006
2007 case GL_TEXTURE_MAG_FILTER:
2008 switch (param)
2009 {
2010 case GL_NEAREST:
2011 case GL_LINEAR:
2012 return true;
2013 default:
2014 return gl::error(GL_INVALID_ENUM, false);
2015 }
2016 break;
2017
2018 case GL_TEXTURE_USAGE_ANGLE:
2019 switch (param)
2020 {
2021 case GL_NONE:
2022 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
2023 return true;
2024 default:
2025 return gl::error(GL_INVALID_ENUM, false);
2026 }
2027 break;
2028
2029 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2030 if (!context->supportsTextureFilterAnisotropy())
2031 {
2032 return gl::error(GL_INVALID_ENUM, false);
2033 }
2034
2035 // we assume the parameter passed to this validation method is truncated, not rounded
2036 if (param < 1)
2037 {
2038 return gl::error(GL_INVALID_VALUE, false);
2039 }
2040 return true;
2041
2042 case GL_TEXTURE_MIN_LOD:
2043 case GL_TEXTURE_MAX_LOD:
2044 // any value is permissible
2045 return true;
2046
2047 case GL_TEXTURE_COMPARE_MODE:
2048 switch (param)
2049 {
2050 case GL_NONE:
2051 case GL_COMPARE_REF_TO_TEXTURE:
2052 return true;
2053 default:
2054 return gl::error(GL_INVALID_ENUM, false);
2055 }
2056 break;
2057
2058 case GL_TEXTURE_COMPARE_FUNC:
2059 switch (param)
2060 {
2061 case GL_LEQUAL:
2062 case GL_GEQUAL:
2063 case GL_LESS:
2064 case GL_GREATER:
2065 case GL_EQUAL:
2066 case GL_NOTEQUAL:
2067 case GL_ALWAYS:
2068 case GL_NEVER:
2069 return true;
2070 default:
2071 return gl::error(GL_INVALID_ENUM, false);
2072 }
2073 break;
2074
2075 case GL_TEXTURE_SWIZZLE_R:
2076 case GL_TEXTURE_SWIZZLE_G:
2077 case GL_TEXTURE_SWIZZLE_B:
2078 case GL_TEXTURE_SWIZZLE_A:
2079 case GL_TEXTURE_BASE_LEVEL:
2080 case GL_TEXTURE_MAX_LEVEL:
2081 UNIMPLEMENTED();
2082 return true;
2083
2084 default:
2085 return gl::error(GL_INVALID_ENUM, false);
2086 }
2087}
2088
2089
Jamie Madillfb8a8302013-07-03 14:24:12 -04002090gl::Texture *getTargetTexture(gl::Context *context, GLenum target)
2091{
2092 if (context->getClientVersion() < 3)
2093 {
2094 if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
2095 {
2096 return NULL;
2097 }
2098 }
2099
2100 switch (target)
2101 {
2102 case GL_TEXTURE_2D: return context->getTexture2D();
2103 case GL_TEXTURE_CUBE_MAP: return context->getTextureCubeMap();
2104 case GL_TEXTURE_3D: return context->getTexture3D();
2105 case GL_TEXTURE_2D_ARRAY: return context->getTexture2DArray();
2106 default: return NULL;
2107 }
2108}
Jamie Madill478fdb22013-07-19 16:36:59 -04002109
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04002110bool validateSamplerObjectParameter(GLenum pname)
2111{
2112 switch (pname)
2113 {
2114 case GL_TEXTURE_MIN_FILTER:
2115 case GL_TEXTURE_MAG_FILTER:
2116 case GL_TEXTURE_WRAP_S:
2117 case GL_TEXTURE_WRAP_T:
2118 case GL_TEXTURE_WRAP_R:
2119 case GL_TEXTURE_MIN_LOD:
2120 case GL_TEXTURE_MAX_LOD:
2121 case GL_TEXTURE_COMPARE_MODE:
2122 case GL_TEXTURE_COMPARE_FUNC:
2123 return true;
2124
2125 default:
2126 return gl::error(GL_INVALID_ENUM, false);
2127 }
2128}
2129
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002130extern "C"
2131{
2132
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002133// OpenGL ES 2.0 functions
2134
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002135void __stdcall glActiveTexture(GLenum texture)
2136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002137 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002138
2139 try
2140 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002141 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002142
2143 if (context)
2144 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002145 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
2146 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002147 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +00002148 }
2149
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002150 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151 }
2152 }
2153 catch(std::bad_alloc&)
2154 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002155 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002156 }
2157}
2158
2159void __stdcall glAttachShader(GLuint program, GLuint shader)
2160{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002161 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002162
2163 try
2164 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002165 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002166
2167 if (context)
2168 {
2169 gl::Program *programObject = context->getProgram(program);
2170 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002171
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002172 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002173 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002174 if (context->getShader(program))
2175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002176 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002177 }
2178 else
2179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002180 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002181 }
2182 }
2183
2184 if (!shaderObject)
2185 {
2186 if (context->getProgram(shader))
2187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002188 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002189 }
2190 else
2191 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002192 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +00002193 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002194 }
2195
2196 if (!programObject->attachShader(shaderObject))
2197 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002198 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002199 }
2200 }
2201 }
2202 catch(std::bad_alloc&)
2203 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002204 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002205 }
2206}
2207
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002208void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
2209{
2210 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
2211
2212 try
2213 {
2214 switch (target)
2215 {
2216 case GL_ANY_SAMPLES_PASSED_EXT:
2217 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2218 break;
2219 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002220 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002221 }
2222
2223 if (id == 0)
2224 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002225 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002226 }
2227
2228 gl::Context *context = gl::getNonLostContext();
2229
2230 if (context)
2231 {
2232 context->beginQuery(target, id);
2233 }
2234 }
2235 catch(std::bad_alloc&)
2236 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002237 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002238 }
2239}
2240
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002241void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002242{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002243 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002244
2245 try
2246 {
2247 if (index >= gl::MAX_VERTEX_ATTRIBS)
2248 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002249 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002250 }
2251
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002252 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002253
2254 if (context)
2255 {
2256 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002257
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002258 if (!programObject)
2259 {
daniel@transgaming.com98079832010-04-13 03:26:29 +00002260 if (context->getShader(program))
2261 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002262 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002263 }
2264 else
2265 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002266 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +00002267 }
2268 }
2269
2270 if (strncmp(name, "gl_", 3) == 0)
2271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002272 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002273 }
2274
2275 programObject->bindAttributeLocation(index, name);
2276 }
2277 }
2278 catch(std::bad_alloc&)
2279 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002280 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002281 }
2282}
2283
2284void __stdcall glBindBuffer(GLenum target, GLuint buffer)
2285{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002286 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287
2288 try
2289 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002290 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002291
2292 if (context)
2293 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002294 // Check ES3 specific targets
2295 switch (target)
2296 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002297 case GL_COPY_READ_BUFFER:
2298 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002299 case GL_PIXEL_PACK_BUFFER:
2300 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002301 case GL_UNIFORM_BUFFER:
2302 case GL_TRANSFORM_FEEDBACK_BUFFER:
2303 if (context->getClientVersion() < 3)
2304 {
2305 return gl::error(GL_INVALID_ENUM);
2306 }
2307 }
2308
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002309 switch (target)
2310 {
2311 case GL_ARRAY_BUFFER:
2312 context->bindArrayBuffer(buffer);
2313 return;
2314 case GL_ELEMENT_ARRAY_BUFFER:
2315 context->bindElementArrayBuffer(buffer);
2316 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002317 case GL_COPY_READ_BUFFER:
2318 context->bindCopyReadBuffer(buffer);
2319 return;
2320 case GL_COPY_WRITE_BUFFER:
2321 context->bindCopyWriteBuffer(buffer);
2322 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002323 case GL_PIXEL_PACK_BUFFER:
2324 context->bindPixelPackBuffer(buffer);
2325 return;
2326 case GL_PIXEL_UNPACK_BUFFER:
2327 context->bindPixelUnpackBuffer(buffer);
2328 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002329 case GL_UNIFORM_BUFFER:
2330 context->bindGenericUniformBuffer(buffer);
2331 return;
2332 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org7a1ebad2013-05-30 00:05:20 +00002333 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002334 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002335 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002336 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337 }
2338 }
2339 }
2340 catch(std::bad_alloc&)
2341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002342 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002343 }
2344}
2345
2346void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
2347{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002348 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349
2350 try
2351 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002352 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002354 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002355 }
2356
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002357 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002358
2359 if (context)
2360 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002361 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2362 {
2363 context->bindReadFramebuffer(framebuffer);
2364 }
2365
2366 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
2367 {
2368 context->bindDrawFramebuffer(framebuffer);
2369 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002370 }
2371 }
2372 catch(std::bad_alloc&)
2373 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002374 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002375 }
2376}
2377
2378void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2379{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002380 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002381
2382 try
2383 {
2384 if (target != GL_RENDERBUFFER)
2385 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002386 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002387 }
2388
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002389 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002390
2391 if (context)
2392 {
2393 context->bindRenderbuffer(renderbuffer);
2394 }
2395 }
2396 catch(std::bad_alloc&)
2397 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002398 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002399 }
2400}
2401
2402void __stdcall glBindTexture(GLenum target, GLuint texture)
2403{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002404 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002405
2406 try
2407 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002408 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002409
2410 if (context)
2411 {
2412 gl::Texture *textureObject = context->getTexture(texture);
2413
2414 if (textureObject && textureObject->getTarget() != target && texture != 0)
2415 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002416 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002417 }
2418
2419 switch (target)
2420 {
2421 case GL_TEXTURE_2D:
2422 context->bindTexture2D(texture);
2423 return;
2424 case GL_TEXTURE_CUBE_MAP:
2425 context->bindTextureCubeMap(texture);
2426 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00002427 case GL_TEXTURE_3D:
2428 if (context->getClientVersion() < 3)
2429 {
2430 return gl::error(GL_INVALID_ENUM);
2431 }
2432 context->bindTexture3D(texture);
2433 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00002434 case GL_TEXTURE_2D_ARRAY:
2435 if (context->getClientVersion() < 3)
2436 {
2437 return gl::error(GL_INVALID_ENUM);
2438 }
2439 context->bindTexture2DArray(texture);
2440 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002442 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002443 }
2444 }
2445 }
2446 catch(std::bad_alloc&)
2447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 }
2450}
2451
2452void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2453{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002454 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002455 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002456
2457 try
2458 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002459 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002460
2461 if (context)
2462 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002463 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002464 }
2465 }
2466 catch(std::bad_alloc&)
2467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002469 }
2470}
2471
2472void __stdcall glBlendEquation(GLenum mode)
2473{
2474 glBlendEquationSeparate(mode, mode);
2475}
2476
2477void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
2478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002479 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002480
2481 try
2482 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002483 gl::Context *context = gl::getNonLostContext();
2484
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002485 switch (modeRGB)
2486 {
2487 case GL_FUNC_ADD:
2488 case GL_FUNC_SUBTRACT:
2489 case GL_FUNC_REVERSE_SUBTRACT:
2490 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002491
2492 case GL_MIN:
2493 case GL_MAX:
2494 if (context && context->getClientVersion() < 3)
2495 {
2496 return gl::error(GL_INVALID_ENUM);
2497 }
2498 break;
2499
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002501 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002502 }
2503
2504 switch (modeAlpha)
2505 {
2506 case GL_FUNC_ADD:
2507 case GL_FUNC_SUBTRACT:
2508 case GL_FUNC_REVERSE_SUBTRACT:
2509 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00002510
2511 case GL_MIN:
2512 case GL_MAX:
2513 if (context && context->getClientVersion() < 3)
2514 {
2515 return gl::error(GL_INVALID_ENUM);
2516 }
2517 break;
2518
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002519 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002520 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002521 }
2522
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002523 if (context)
2524 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002525 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002526 }
2527 }
2528 catch(std::bad_alloc&)
2529 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002530 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002531 }
2532}
2533
2534void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
2535{
2536 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
2537}
2538
2539void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
2540{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002541 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002542 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002543
2544 try
2545 {
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002546 gl::Context *context = gl::getNonLostContext();
2547
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002548 switch (srcRGB)
2549 {
2550 case GL_ZERO:
2551 case GL_ONE:
2552 case GL_SRC_COLOR:
2553 case GL_ONE_MINUS_SRC_COLOR:
2554 case GL_DST_COLOR:
2555 case GL_ONE_MINUS_DST_COLOR:
2556 case GL_SRC_ALPHA:
2557 case GL_ONE_MINUS_SRC_ALPHA:
2558 case GL_DST_ALPHA:
2559 case GL_ONE_MINUS_DST_ALPHA:
2560 case GL_CONSTANT_COLOR:
2561 case GL_ONE_MINUS_CONSTANT_COLOR:
2562 case GL_CONSTANT_ALPHA:
2563 case GL_ONE_MINUS_CONSTANT_ALPHA:
2564 case GL_SRC_ALPHA_SATURATE:
2565 break;
2566 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002567 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002568 }
2569
2570 switch (dstRGB)
2571 {
2572 case GL_ZERO:
2573 case GL_ONE:
2574 case GL_SRC_COLOR:
2575 case GL_ONE_MINUS_SRC_COLOR:
2576 case GL_DST_COLOR:
2577 case GL_ONE_MINUS_DST_COLOR:
2578 case GL_SRC_ALPHA:
2579 case GL_ONE_MINUS_SRC_ALPHA:
2580 case GL_DST_ALPHA:
2581 case GL_ONE_MINUS_DST_ALPHA:
2582 case GL_CONSTANT_COLOR:
2583 case GL_ONE_MINUS_CONSTANT_COLOR:
2584 case GL_CONSTANT_ALPHA:
2585 case GL_ONE_MINUS_CONSTANT_ALPHA:
2586 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002587
2588 case GL_SRC_ALPHA_SATURATE:
2589 if (!context || context->getClientVersion() < 3)
2590 {
2591 return gl::error(GL_INVALID_ENUM);
2592 }
2593 break;
2594
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002595 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002596 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597 }
2598
2599 switch (srcAlpha)
2600 {
2601 case GL_ZERO:
2602 case GL_ONE:
2603 case GL_SRC_COLOR:
2604 case GL_ONE_MINUS_SRC_COLOR:
2605 case GL_DST_COLOR:
2606 case GL_ONE_MINUS_DST_COLOR:
2607 case GL_SRC_ALPHA:
2608 case GL_ONE_MINUS_SRC_ALPHA:
2609 case GL_DST_ALPHA:
2610 case GL_ONE_MINUS_DST_ALPHA:
2611 case GL_CONSTANT_COLOR:
2612 case GL_ONE_MINUS_CONSTANT_COLOR:
2613 case GL_CONSTANT_ALPHA:
2614 case GL_ONE_MINUS_CONSTANT_ALPHA:
2615 case GL_SRC_ALPHA_SATURATE:
2616 break;
2617 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002618 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002619 }
2620
2621 switch (dstAlpha)
2622 {
2623 case GL_ZERO:
2624 case GL_ONE:
2625 case GL_SRC_COLOR:
2626 case GL_ONE_MINUS_SRC_COLOR:
2627 case GL_DST_COLOR:
2628 case GL_ONE_MINUS_DST_COLOR:
2629 case GL_SRC_ALPHA:
2630 case GL_ONE_MINUS_SRC_ALPHA:
2631 case GL_DST_ALPHA:
2632 case GL_ONE_MINUS_DST_ALPHA:
2633 case GL_CONSTANT_COLOR:
2634 case GL_ONE_MINUS_CONSTANT_COLOR:
2635 case GL_CONSTANT_ALPHA:
2636 case GL_ONE_MINUS_CONSTANT_ALPHA:
2637 break;
shannonwoods@chromium.org48ae0252013-05-30 00:13:22 +00002638
2639 case GL_SRC_ALPHA_SATURATE:
2640 if (!context || context->getClientVersion() < 3)
2641 {
2642 return gl::error(GL_INVALID_ENUM);
2643 }
2644 break;
2645
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002646 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002647 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002648 }
2649
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002650 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
2651 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
2652
2653 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
2654 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
2655
2656 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002657 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00002658 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002659 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002660 }
2661
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002662 if (context)
2663 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002664 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665 }
2666 }
2667 catch(std::bad_alloc&)
2668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002669 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002670 }
2671}
2672
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002673void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002674{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002675 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002676 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002677
2678 try
2679 {
2680 if (size < 0)
2681 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002682 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002683 }
2684
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002685 gl::Context *context = gl::getNonLostContext();
2686
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002687 switch (usage)
2688 {
2689 case GL_STREAM_DRAW:
2690 case GL_STATIC_DRAW:
2691 case GL_DYNAMIC_DRAW:
2692 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00002693
2694 case GL_STREAM_READ:
2695 case GL_STREAM_COPY:
2696 case GL_STATIC_READ:
2697 case GL_STATIC_COPY:
2698 case GL_DYNAMIC_READ:
2699 case GL_DYNAMIC_COPY:
2700 if (context && context->getClientVersion() < 3)
2701 {
2702 return gl::error(GL_INVALID_ENUM);
2703 }
2704 break;
2705
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002706 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002707 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002708 }
2709
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002710 if (context)
2711 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002712 // Check ES3 specific targets
2713 switch (target)
2714 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002715 case GL_COPY_READ_BUFFER:
2716 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002717 case GL_PIXEL_PACK_BUFFER:
2718 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002719 case GL_UNIFORM_BUFFER:
2720 case GL_TRANSFORM_FEEDBACK_BUFFER:
2721 if (context->getClientVersion() < 3)
2722 {
2723 return gl::error(GL_INVALID_ENUM);
2724 }
2725 }
2726
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002727 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002728
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002729 switch (target)
2730 {
2731 case GL_ARRAY_BUFFER:
2732 buffer = context->getArrayBuffer();
2733 break;
2734 case GL_ELEMENT_ARRAY_BUFFER:
2735 buffer = context->getElementArrayBuffer();
2736 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002737 case GL_COPY_READ_BUFFER:
2738 buffer = context->getCopyReadBuffer();
2739 break;
2740 case GL_COPY_WRITE_BUFFER:
2741 buffer = context->getCopyWriteBuffer();
2742 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002743 case GL_PIXEL_PACK_BUFFER:
2744 buffer = context->getPixelPackBuffer();
2745 break;
2746 case GL_PIXEL_UNPACK_BUFFER:
2747 buffer = context->getPixelUnpackBuffer();
2748 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002749 case GL_TRANSFORM_FEEDBACK_BUFFER:
2750 buffer = context->getGenericTransformFeedbackBuffer();
2751 break;
2752 case GL_UNIFORM_BUFFER:
2753 buffer = context->getGenericUniformBuffer();
2754 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002756 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002757 }
2758
2759 if (!buffer)
2760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002761 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762 }
2763
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002764 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002765 }
2766 }
2767 catch(std::bad_alloc&)
2768 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002769 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002770 }
2771}
2772
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002773void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002775 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002776 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777
2778 try
2779 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002780 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002783 }
2784
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00002785 if (data == NULL)
2786 {
2787 return;
2788 }
2789
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002790 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002791
2792 if (context)
2793 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002794 // Check ES3 specific targets
2795 switch (target)
2796 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002797 case GL_COPY_READ_BUFFER:
2798 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002799 case GL_PIXEL_PACK_BUFFER:
2800 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002801 case GL_UNIFORM_BUFFER:
2802 case GL_TRANSFORM_FEEDBACK_BUFFER:
2803 if (context->getClientVersion() < 3)
2804 {
2805 return gl::error(GL_INVALID_ENUM);
2806 }
2807 }
2808
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002809 gl::Buffer *buffer;
2810
2811 switch (target)
2812 {
2813 case GL_ARRAY_BUFFER:
2814 buffer = context->getArrayBuffer();
2815 break;
2816 case GL_ELEMENT_ARRAY_BUFFER:
2817 buffer = context->getElementArrayBuffer();
2818 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00002819 case GL_COPY_READ_BUFFER:
2820 buffer = context->getCopyReadBuffer();
2821 break;
2822 case GL_COPY_WRITE_BUFFER:
2823 buffer = context->getCopyWriteBuffer();
2824 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00002825 case GL_PIXEL_PACK_BUFFER:
2826 buffer = context->getPixelPackBuffer();
2827 break;
2828 case GL_PIXEL_UNPACK_BUFFER:
2829 buffer = context->getPixelUnpackBuffer();
2830 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00002831 case GL_TRANSFORM_FEEDBACK_BUFFER:
2832 buffer = context->getGenericTransformFeedbackBuffer();
2833 break;
2834 case GL_UNIFORM_BUFFER:
2835 buffer = context->getGenericUniformBuffer();
2836 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002837 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002838 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002839 }
2840
2841 if (!buffer)
2842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002843 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002844 }
2845
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002846 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002847 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002848 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002849 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00002850
2851 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00002852 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002853 }
2854 catch(std::bad_alloc&)
2855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002856 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002857 }
2858}
2859
2860GLenum __stdcall glCheckFramebufferStatus(GLenum target)
2861{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002862 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002863
2864 try
2865 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002866 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002867 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002868 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002869 }
2870
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002871 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002872
2873 if (context)
2874 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002875 gl::Framebuffer *framebuffer = NULL;
2876 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2877 {
2878 framebuffer = context->getReadFramebuffer();
2879 }
2880 else
2881 {
2882 framebuffer = context->getDrawFramebuffer();
2883 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002884
2885 return framebuffer->completeness();
2886 }
2887 }
2888 catch(std::bad_alloc&)
2889 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002890 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002891 }
2892
2893 return 0;
2894}
2895
2896void __stdcall glClear(GLbitfield mask)
2897{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002898 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002899
2900 try
2901 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002902 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002903
2904 if (context)
2905 {
2906 context->clear(mask);
2907 }
2908 }
2909 catch(std::bad_alloc&)
2910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002911 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002912 }
2913}
2914
2915void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
2916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002917 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002918 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002919
2920 try
2921 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002922 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002923
2924 if (context)
2925 {
2926 context->setClearColor(red, green, blue, alpha);
2927 }
2928 }
2929 catch(std::bad_alloc&)
2930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002931 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002932 }
2933}
2934
2935void __stdcall glClearDepthf(GLclampf depth)
2936{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002937 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002938
2939 try
2940 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002941 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002942
2943 if (context)
2944 {
2945 context->setClearDepth(depth);
2946 }
2947 }
2948 catch(std::bad_alloc&)
2949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002951 }
2952}
2953
2954void __stdcall glClearStencil(GLint s)
2955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002956 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002957
2958 try
2959 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002960 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002961
2962 if (context)
2963 {
2964 context->setClearStencil(s);
2965 }
2966 }
2967 catch(std::bad_alloc&)
2968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002969 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002970 }
2971}
2972
2973void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
2974{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002975 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002976 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002977
2978 try
2979 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002980 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002981
2982 if (context)
2983 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00002984 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002985 }
2986 }
2987 catch(std::bad_alloc&)
2988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002989 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002990 }
2991}
2992
2993void __stdcall glCompileShader(GLuint shader)
2994{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002995 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002996
2997 try
2998 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002999 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003000
3001 if (context)
3002 {
3003 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003004
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003005 if (!shaderObject)
3006 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003007 if (context->getProgram(shader))
3008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003009 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003010 }
3011 else
3012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003013 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00003014 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003015 }
3016
3017 shaderObject->compile();
3018 }
3019 }
3020 catch(std::bad_alloc&)
3021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003022 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003023 }
3024}
3025
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003026void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
3027 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003028{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003029 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003030 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003031 target, level, internalformat, width, height, border, imageSize, data);
3032
3033 try
3034 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003035 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003036
3037 if (context)
3038 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003039 if (context->getClientVersion() < 3 &&
3040 !validateES2TexImageParameters(context, target, level, internalformat, true, false,
3041 0, 0, width, height, 0, GL_NONE, GL_NONE, data))
3042 {
3043 return;
3044 }
3045
3046 if (context->getClientVersion() >= 3 &&
3047 !validateES3TexImageParameters(context, target, level, internalformat, true, false,
3048 0, 0, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3049 {
3050 return;
3051 }
3052
3053 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(internalformat, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003055 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003056 }
3057
3058 switch (target)
3059 {
3060 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003061 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003062 gl::Texture2D *texture = context->getTexture2D();
3063 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003064 }
3065 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003066
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003067 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3068 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3069 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3070 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3071 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3072 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003073 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003074 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3075 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003076 }
3077 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003078
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003079 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003080 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003081 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00003082 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003083 }
3084 catch(std::bad_alloc&)
3085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003086 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003087 }
3088}
3089
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003090void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
3091 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003092{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003093 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003094 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003095 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003096 target, level, xoffset, yoffset, width, height, format, imageSize, data);
3097
3098 try
3099 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00003101
3102 if (context)
3103 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003104 if (context->getClientVersion() < 3 &&
3105 !validateES2TexImageParameters(context, target, level, GL_NONE, true, true,
3106 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
3107 {
3108 return;
3109 }
3110
3111 if (context->getClientVersion() >= 3 &&
3112 !validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
3113 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE))
3114 {
3115 return;
3116 }
3117
3118 if (imageSize < 0 || imageSize != (GLsizei)gl::GetBlockSize(format, GL_UNSIGNED_BYTE, context->getClientVersion(), width, height))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003120 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003121 }
3122
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003123 switch (target)
daniel@transgaming.com01868132010-08-24 19:21:17 +00003124 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003125 case GL_TEXTURE_2D:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003126 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003127 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003128 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003129 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003130 break;
3131
3132 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3133 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3134 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3135 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3136 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3137 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com01868132010-08-24 19:21:17 +00003138 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003139 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00003140 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003141 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003142 break;
3143
3144 default:
3145 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00003146 }
3147 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148 }
3149 catch(std::bad_alloc&)
3150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003151 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003152 }
3153}
3154
3155void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
3156{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003157 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003158 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003159 target, level, internalformat, x, y, width, height, border);
3160
3161 try
3162 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003163 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003164
3165 if (context)
3166 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003167 if (context->getClientVersion() < 3 &&
3168 !validateES2CopyTexImageParameters(context, target, level, internalformat, false,
3169 0, 0, x, y, width, height, border))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003170 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003171 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00003172 }
3173
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003174 if (context->getClientVersion() >= 3 &&
3175 !validateES3CopyTexImageParameters(context, target, level, internalformat, false,
3176 0, 0, 0, x, y, width, height, border))
3177 {
3178 return;
3179 }
3180
3181 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
3182
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003183 switch (target)
3184 {
3185 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003186 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003187 gl::Texture2D *texture = context->getTexture2D();
3188 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003189 }
3190 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003191
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003192 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3193 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3194 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3195 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3196 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3197 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003198 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003199 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3200 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003201 }
3202 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003203
3204 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003205 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003206 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003207 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208 }
3209 catch(std::bad_alloc&)
3210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003211 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003212 }
3213}
3214
3215void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
3216{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003217 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003218 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003219 target, level, xoffset, yoffset, x, y, width, height);
3220
3221 try
3222 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003223 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003224
3225 if (context)
3226 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003227 if (context->getClientVersion() < 3 &&
3228 !validateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
3229 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003230 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003231 return;
3232 }
3233
3234 if (context->getClientVersion() >= 3 &&
3235 !validateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
3236 xoffset, yoffset, 0, x, y, width, height, 0))
3237 {
3238 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00003239 }
3240
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003241 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003242
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003243 switch (target)
daniel@transgaming.combbc57792010-07-28 19:21:05 +00003244 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003245 case GL_TEXTURE_2D:
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00003246 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003247 gl::Texture2D *texture = context->getTexture2D();
3248 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003249 }
3250 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003251
3252 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3253 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3254 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3255 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3256 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3257 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003258 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003259 gl::TextureCubeMap *texture = context->getTextureCubeMap();
3260 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00003261 }
3262 break;
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003263
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003264 default:
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00003265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00003266 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003267 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00003269
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003270 catch(std::bad_alloc&)
3271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003272 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003273 }
3274}
3275
3276GLuint __stdcall glCreateProgram(void)
3277{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003278 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003279
3280 try
3281 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003282 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283
3284 if (context)
3285 {
3286 return context->createProgram();
3287 }
3288 }
3289 catch(std::bad_alloc&)
3290 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003291 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003292 }
3293
3294 return 0;
3295}
3296
3297GLuint __stdcall glCreateShader(GLenum type)
3298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003299 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003300
3301 try
3302 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003303 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304
3305 if (context)
3306 {
3307 switch (type)
3308 {
3309 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003310 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003311 return context->createShader(type);
3312 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003313 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003314 }
3315 }
3316 }
3317 catch(std::bad_alloc&)
3318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003319 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003320 }
3321
3322 return 0;
3323}
3324
3325void __stdcall glCullFace(GLenum mode)
3326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003327 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328
3329 try
3330 {
3331 switch (mode)
3332 {
3333 case GL_FRONT:
3334 case GL_BACK:
3335 case GL_FRONT_AND_BACK:
3336 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003337 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003338
3339 if (context)
3340 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003341 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003342 }
3343 }
3344 break;
3345 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003346 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003347 }
3348 }
3349 catch(std::bad_alloc&)
3350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003351 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003352 }
3353}
3354
3355void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
3356{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003357 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003358
3359 try
3360 {
3361 if (n < 0)
3362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003363 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364 }
3365
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003366 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003367
3368 if (context)
3369 {
3370 for (int i = 0; i < n; i++)
3371 {
3372 context->deleteBuffer(buffers[i]);
3373 }
3374 }
3375 }
3376 catch(std::bad_alloc&)
3377 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003378 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003379 }
3380}
3381
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003382void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
3383{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003384 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003385
3386 try
3387 {
3388 if (n < 0)
3389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003390 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003391 }
3392
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003393 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003394
3395 if (context)
3396 {
3397 for (int i = 0; i < n; i++)
3398 {
Jamie Madill33dc8432013-07-26 11:55:05 -04003399 context->deleteFenceNV(fences[i]);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003400 }
3401 }
3402 }
3403 catch(std::bad_alloc&)
3404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003405 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003406 }
3407}
3408
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003409void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
3410{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003411 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003412
3413 try
3414 {
3415 if (n < 0)
3416 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003417 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003418 }
3419
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003420 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003421
3422 if (context)
3423 {
3424 for (int i = 0; i < n; i++)
3425 {
3426 if (framebuffers[i] != 0)
3427 {
3428 context->deleteFramebuffer(framebuffers[i]);
3429 }
3430 }
3431 }
3432 }
3433 catch(std::bad_alloc&)
3434 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003435 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003436 }
3437}
3438
3439void __stdcall glDeleteProgram(GLuint program)
3440{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003441 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003442
3443 try
3444 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003445 if (program == 0)
3446 {
3447 return;
3448 }
3449
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003450 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003451
3452 if (context)
3453 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003454 if (!context->getProgram(program))
3455 {
3456 if(context->getShader(program))
3457 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003458 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003459 }
3460 else
3461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003462 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003463 }
3464 }
3465
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003466 context->deleteProgram(program);
3467 }
3468 }
3469 catch(std::bad_alloc&)
3470 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003471 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 }
3473}
3474
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003475void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
3476{
3477 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
3478
3479 try
3480 {
3481 if (n < 0)
3482 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003483 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003484 }
3485
3486 gl::Context *context = gl::getNonLostContext();
3487
3488 if (context)
3489 {
3490 for (int i = 0; i < n; i++)
3491 {
3492 context->deleteQuery(ids[i]);
3493 }
3494 }
3495 }
3496 catch(std::bad_alloc&)
3497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003498 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003499 }
3500}
3501
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
3503{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003504 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003505
3506 try
3507 {
3508 if (n < 0)
3509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003511 }
3512
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003513 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003514
3515 if (context)
3516 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00003517 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003518 {
3519 context->deleteRenderbuffer(renderbuffers[i]);
3520 }
3521 }
3522 }
3523 catch(std::bad_alloc&)
3524 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003525 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003526 }
3527}
3528
3529void __stdcall glDeleteShader(GLuint shader)
3530{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003531 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003532
3533 try
3534 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003535 if (shader == 0)
3536 {
3537 return;
3538 }
3539
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003540 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003541
3542 if (context)
3543 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003544 if (!context->getShader(shader))
3545 {
3546 if(context->getProgram(shader))
3547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003548 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003549 }
3550 else
3551 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003552 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00003553 }
3554 }
3555
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003556 context->deleteShader(shader);
3557 }
3558 }
3559 catch(std::bad_alloc&)
3560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003561 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003562 }
3563}
3564
3565void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
3566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003567 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003568
3569 try
3570 {
3571 if (n < 0)
3572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003573 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003574 }
3575
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003577
3578 if (context)
3579 {
3580 for (int i = 0; i < n; i++)
3581 {
3582 if (textures[i] != 0)
3583 {
3584 context->deleteTexture(textures[i]);
3585 }
3586 }
3587 }
3588 }
3589 catch(std::bad_alloc&)
3590 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003591 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003592 }
3593}
3594
3595void __stdcall glDepthFunc(GLenum func)
3596{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003597 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598
3599 try
3600 {
3601 switch (func)
3602 {
3603 case GL_NEVER:
3604 case GL_ALWAYS:
3605 case GL_LESS:
3606 case GL_LEQUAL:
3607 case GL_EQUAL:
3608 case GL_GREATER:
3609 case GL_GEQUAL:
3610 case GL_NOTEQUAL:
3611 break;
3612 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003613 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614 }
3615
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003616 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003617
3618 if (context)
3619 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003620 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003621 }
3622 }
3623 catch(std::bad_alloc&)
3624 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003625 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003626 }
3627}
3628
3629void __stdcall glDepthMask(GLboolean flag)
3630{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003631 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003632
3633 try
3634 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003635 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636
3637 if (context)
3638 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003639 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 }
3641 }
3642 catch(std::bad_alloc&)
3643 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003644 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003645 }
3646}
3647
3648void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
3649{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003650 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651
3652 try
3653 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003654 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003655
3656 if (context)
3657 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003658 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003659 }
3660 }
3661 catch(std::bad_alloc&)
3662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003663 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003664 }
3665}
3666
3667void __stdcall glDetachShader(GLuint program, GLuint shader)
3668{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003669 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003670
3671 try
3672 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003673 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003674
3675 if (context)
3676 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003677
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003678 gl::Program *programObject = context->getProgram(program);
3679 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003680
3681 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003682 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003683 gl::Shader *shaderByProgramHandle;
3684 shaderByProgramHandle = context->getShader(program);
3685 if (!shaderByProgramHandle)
3686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003687 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003688 }
3689 else
3690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003691 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003692 }
3693 }
3694
3695 if (!shaderObject)
3696 {
3697 gl::Program *programByShaderHandle = context->getProgram(shader);
3698 if (!programByShaderHandle)
3699 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003700 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003701 }
3702 else
3703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003704 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00003705 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003706 }
3707
3708 if (!programObject->detachShader(shaderObject))
3709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003710 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003711 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003712 }
3713 }
3714 catch(std::bad_alloc&)
3715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003717 }
3718}
3719
3720void __stdcall glDisable(GLenum cap)
3721{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003722 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723
3724 try
3725 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003726 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003727
3728 if (context)
3729 {
3730 switch (cap)
3731 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003732 case GL_CULL_FACE: context->setCullFace(false); break;
3733 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
3734 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
3735 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
3736 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
3737 case GL_STENCIL_TEST: context->setStencilTest(false); break;
3738 case GL_DEPTH_TEST: context->setDepthTest(false); break;
3739 case GL_BLEND: context->setBlend(false); break;
3740 case GL_DITHER: context->setDither(false); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00003741
3742 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
3743 case GL_RASTERIZER_DISCARD:
3744 if (context->getClientVersion() < 3)
3745 {
3746 return gl::error(GL_INVALID_ENUM);
3747 }
3748 UNIMPLEMENTED();
3749 break;
3750
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003751 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003752 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003753 }
3754 }
3755 }
3756 catch(std::bad_alloc&)
3757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003758 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003759 }
3760}
3761
3762void __stdcall glDisableVertexAttribArray(GLuint index)
3763{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003764 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003765
3766 try
3767 {
3768 if (index >= gl::MAX_VERTEX_ATTRIBS)
3769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003770 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003771 }
3772
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003773 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003774
3775 if (context)
3776 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003777 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003778 }
3779 }
3780 catch(std::bad_alloc&)
3781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003782 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003783 }
3784}
3785
3786void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
3787{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003788 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003789
3790 try
3791 {
3792 if (count < 0 || first < 0)
3793 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003794 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003795 }
3796
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003797 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003798
3799 if (context)
3800 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003801 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003802 }
3803 }
3804 catch(std::bad_alloc&)
3805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003806 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003807 }
3808}
3809
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003810void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
3811{
3812 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
3813
3814 try
3815 {
3816 if (count < 0 || first < 0 || primcount < 0)
3817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003818 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003819 }
3820
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003821 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003822 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003823 gl::Context *context = gl::getNonLostContext();
3824
3825 if (context)
3826 {
3827 context->drawArrays(mode, first, count, primcount);
3828 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003829 }
3830 }
3831 catch(std::bad_alloc&)
3832 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003833 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003834 }
3835}
3836
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003837void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003838{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003839 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003840 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003841
3842 try
3843 {
3844 if (count < 0)
3845 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003846 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003847 }
3848
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003849 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003850
3851 if (context)
3852 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003853 switch (type)
3854 {
3855 case GL_UNSIGNED_BYTE:
3856 case GL_UNSIGNED_SHORT:
3857 break;
3858 case GL_UNSIGNED_INT:
3859 if (!context->supports32bitIndices())
3860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003861 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003862 }
3863 break;
3864 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003865 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00003866 }
3867
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003868 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869 }
3870 }
3871 catch(std::bad_alloc&)
3872 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003873 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003874 }
3875}
3876
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003877void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
3878{
3879 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
3880 mode, count, type, indices, primcount);
3881
3882 try
3883 {
3884 if (count < 0 || primcount < 0)
3885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003886 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003887 }
3888
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003889 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003890 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003891 gl::Context *context = gl::getNonLostContext();
3892
3893 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003894 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003895 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003896 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003897 case GL_UNSIGNED_BYTE:
3898 case GL_UNSIGNED_SHORT:
3899 break;
3900 case GL_UNSIGNED_INT:
3901 if (!context->supports32bitIndices())
3902 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003904 }
3905 break;
3906 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003907 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003908 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00003909
3910 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003911 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003912 }
3913 }
3914 catch(std::bad_alloc&)
3915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003916 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00003917 }
3918}
3919
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920void __stdcall glEnable(GLenum cap)
3921{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003922 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923
3924 try
3925 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003926 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003927
3928 if (context)
3929 {
3930 switch (cap)
3931 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003932 case GL_CULL_FACE: context->setCullFace(true); break;
3933 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
3934 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
3935 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
3936 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
3937 case GL_STENCIL_TEST: context->setStencilTest(true); break;
3938 case GL_DEPTH_TEST: context->setDepthTest(true); break;
3939 case GL_BLEND: context->setBlend(true); break;
3940 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003941 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003942 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003943 }
3944 }
3945 }
3946 catch(std::bad_alloc&)
3947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003948 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003949 }
3950}
3951
3952void __stdcall glEnableVertexAttribArray(GLuint index)
3953{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003954 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003955
3956 try
3957 {
3958 if (index >= gl::MAX_VERTEX_ATTRIBS)
3959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003960 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003961 }
3962
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003963 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964
3965 if (context)
3966 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00003967 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003968 }
3969 }
3970 catch(std::bad_alloc&)
3971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003972 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003973 }
3974}
3975
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003976void __stdcall glEndQueryEXT(GLenum target)
3977{
3978 EVENT("GLenum target = 0x%X)", target);
3979
3980 try
3981 {
3982 switch (target)
3983 {
3984 case GL_ANY_SAMPLES_PASSED_EXT:
3985 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
3986 break;
3987 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003988 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003989 }
3990
3991 gl::Context *context = gl::getNonLostContext();
3992
3993 if (context)
3994 {
3995 context->endQuery(target);
3996 }
3997 }
3998 catch(std::bad_alloc&)
3999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004000 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004001 }
4002}
4003
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004004void __stdcall glFinishFenceNV(GLuint fence)
4005{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004006 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004007
4008 try
4009 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004010 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004011
4012 if (context)
4013 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004014 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004015
4016 if (fenceObject == NULL)
4017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004018 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004019 }
4020
Jamie Madillfb9a7402013-07-26 11:55:01 -04004021 if (fenceObject->isFence() != GL_TRUE)
4022 {
4023 return gl::error(GL_INVALID_OPERATION);
4024 }
4025
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004026 fenceObject->finishFence();
4027 }
4028 }
4029 catch(std::bad_alloc&)
4030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004031 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004032 }
4033}
4034
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004035void __stdcall glFinish(void)
4036{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004037 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004038
4039 try
4040 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004041 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004042
4043 if (context)
4044 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004045 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046 }
4047 }
4048 catch(std::bad_alloc&)
4049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004050 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051 }
4052}
4053
4054void __stdcall glFlush(void)
4055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004056 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004057
4058 try
4059 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004060 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004061
4062 if (context)
4063 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00004064 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004065 }
4066 }
4067 catch(std::bad_alloc&)
4068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004069 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004070 }
4071}
4072
4073void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
4074{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004075 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004076 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004077
4078 try
4079 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004080 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004081 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004082 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004083 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004084 }
4085
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004086 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004087
4088 if (context)
4089 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004090 gl::Framebuffer *framebuffer = NULL;
4091 GLuint framebufferHandle = 0;
4092 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4093 {
4094 framebuffer = context->getReadFramebuffer();
4095 framebufferHandle = context->getReadFramebufferHandle();
4096 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004097 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004098 {
4099 framebuffer = context->getDrawFramebuffer();
4100 framebufferHandle = context->getDrawFramebufferHandle();
4101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004102
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00004103 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004104 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004105 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004106 }
4107
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004108 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004109 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004110 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4111
4112 if (colorAttachment >= context->getMaximumRenderTargets())
4113 {
4114 return gl::error(GL_INVALID_VALUE);
4115 }
4116
4117 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
4118 }
4119 else
4120 {
4121 switch (attachment)
4122 {
4123 case GL_DEPTH_ATTACHMENT:
4124 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
4125 break;
4126 case GL_STENCIL_ATTACHMENT:
4127 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
4128 break;
4129 default:
4130 return gl::error(GL_INVALID_ENUM);
4131 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004132 }
4133 }
4134 }
4135 catch(std::bad_alloc&)
4136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004137 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004138 }
4139}
4140
4141void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
4142{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004143 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004144 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004145
4146 try
4147 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004148 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004150 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004151 }
4152
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004153 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004154
4155 if (context)
4156 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004157 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
4158 {
4159 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4160
4161 if (colorAttachment >= context->getMaximumRenderTargets())
4162 {
4163 return gl::error(GL_INVALID_VALUE);
4164 }
4165 }
4166 else
4167 {
4168 switch (attachment)
4169 {
4170 case GL_DEPTH_ATTACHMENT:
4171 case GL_STENCIL_ATTACHMENT:
4172 break;
4173 default:
4174 return gl::error(GL_INVALID_ENUM);
4175 }
4176 }
4177
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004178 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004179 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004180 textarget = GL_NONE;
4181 }
4182 else
4183 {
4184 gl::Texture *tex = context->getTexture(texture);
4185
4186 if (tex == NULL)
4187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004188 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004189 }
4190
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004191 switch (textarget)
4192 {
4193 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004194 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004195 if (tex->getTarget() != GL_TEXTURE_2D)
4196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004197 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004198 }
4199 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00004200 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004202 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004203 }
4204 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004205 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004206
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004207 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004208 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004209 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004210 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004211 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004212 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004213 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004214 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
4215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004216 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004217 }
4218 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00004219 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004221 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004222 }
4223 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004224 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00004225
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004226 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004227 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004228 }
4229
4230 if (level != 0)
4231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004233 }
4234 }
4235
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004236 gl::Framebuffer *framebuffer = NULL;
4237 GLuint framebufferHandle = 0;
4238 if (target == GL_READ_FRAMEBUFFER_ANGLE)
4239 {
4240 framebuffer = context->getReadFramebuffer();
4241 framebufferHandle = context->getReadFramebufferHandle();
4242 }
4243 else
4244 {
4245 framebuffer = context->getDrawFramebuffer();
4246 framebufferHandle = context->getDrawFramebufferHandle();
4247 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004248
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00004249 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004251 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004252 }
4253
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004254 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004255 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00004256 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
4257
4258 if (colorAttachment >= context->getMaximumRenderTargets())
4259 {
4260 return gl::error(GL_INVALID_VALUE);
4261 }
4262
4263 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
4264 }
4265 else
4266 {
4267 switch (attachment)
4268 {
4269 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
4270 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
4271 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00004272 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273 }
4274 }
4275 catch(std::bad_alloc&)
4276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004277 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004278 }
4279}
4280
4281void __stdcall glFrontFace(GLenum mode)
4282{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004283 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004284
4285 try
4286 {
4287 switch (mode)
4288 {
4289 case GL_CW:
4290 case GL_CCW:
4291 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004292 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004293
4294 if (context)
4295 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004296 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297 }
4298 }
4299 break;
4300 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004301 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004302 }
4303 }
4304 catch(std::bad_alloc&)
4305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004306 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004307 }
4308}
4309
4310void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
4311{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004312 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004313
4314 try
4315 {
4316 if (n < 0)
4317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004318 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004319 }
4320
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004321 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004322
4323 if (context)
4324 {
4325 for (int i = 0; i < n; i++)
4326 {
4327 buffers[i] = context->createBuffer();
4328 }
4329 }
4330 }
4331 catch(std::bad_alloc&)
4332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004333 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004334 }
4335}
4336
4337void __stdcall glGenerateMipmap(GLenum target)
4338{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004339 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004340
4341 try
4342 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004343 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004344
4345 if (context)
4346 {
Geoff Langae4852a2013-06-05 15:00:34 -04004347 gl::Texture *texture = NULL;
4348 GLint internalFormat = GL_NONE;
4349 bool isCompressed = false;
4350 bool isDepth = false;
4351
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004352 switch (target)
4353 {
4354 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004355 {
4356 gl::Texture2D *tex2d = context->getTexture2D();
Geoff Langae4852a2013-06-05 15:00:34 -04004357 if (tex2d)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004358 {
Geoff Langae4852a2013-06-05 15:00:34 -04004359 internalFormat = tex2d->getInternalFormat(0);
4360 isCompressed = tex2d->isCompressed(0);
4361 isDepth = tex2d->isDepth(0);
4362 texture = tex2d;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004363 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004364 break;
4365 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004366
4367 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004368 {
4369 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
Geoff Langae4852a2013-06-05 15:00:34 -04004370 if (texcube)
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004371 {
Geoff Langae4852a2013-06-05 15:00:34 -04004372 internalFormat = texcube->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4373 isCompressed = texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
4374 isDepth = false;
4375 texture = texcube;
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004376 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00004377 break;
4378 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004379
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004380 case GL_TEXTURE_3D:
4381 {
4382 if (context->getClientVersion() < 3)
4383 {
4384 return gl::error(GL_INVALID_ENUM);
4385 }
4386
4387 gl::Texture3D *tex3D = context->getTexture3D();
Geoff Langae4852a2013-06-05 15:00:34 -04004388 if (tex3D)
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004389 {
Geoff Langae4852a2013-06-05 15:00:34 -04004390 internalFormat = tex3D->getInternalFormat(0);
4391 isCompressed = tex3D->isCompressed(0);
4392 isDepth = tex3D->isDepth(0);
4393 texture = tex3D;
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004394 }
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00004395 break;
4396 }
4397
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004398 case GL_TEXTURE_2D_ARRAY:
4399 {
4400 if (context->getClientVersion() < 3)
4401 {
4402 return gl::error(GL_INVALID_ENUM);
4403 }
4404
4405 gl::Texture2DArray *tex2darr = context->getTexture2DArray();
Geoff Langae4852a2013-06-05 15:00:34 -04004406 if (tex2darr)
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004407 {
Geoff Langae4852a2013-06-05 15:00:34 -04004408 internalFormat = tex2darr->getInternalFormat(0);
4409 isCompressed = tex2darr->isCompressed(0);
4410 isDepth = tex2darr->isDepth(0);
4411 texture = tex2darr;
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004412 }
shannonwoods@chromium.org30aa1a92013-05-30 00:03:13 +00004413 break;
4414 }
4415
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004416 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004417 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004418 }
Geoff Langae4852a2013-06-05 15:00:34 -04004419
4420 if (!texture)
4421 {
4422 return gl::error(GL_INVALID_OPERATION);
4423 }
4424
4425 // Internally, all texture formats are sized so checking if the format
4426 // is color renderable and filterable will not fail.
4427 if (isDepth || isCompressed ||
4428 !gl::IsColorRenderingSupported(internalFormat, context) ||
4429 !gl::IsTextureFilteringSupported(internalFormat, context))
4430 {
4431 return gl::error(GL_INVALID_OPERATION);
4432 }
4433
4434 texture->generateMipmaps();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00004435 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004436 }
4437 catch(std::bad_alloc&)
4438 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004439 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004440 }
4441}
4442
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004443void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
4444{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004445 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004446
4447 try
4448 {
4449 if (n < 0)
4450 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004451 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004452 }
4453
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004454 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004455
4456 if (context)
4457 {
4458 for (int i = 0; i < n; i++)
4459 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004460 fences[i] = context->createFenceNV();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004461 }
4462 }
4463 }
4464 catch(std::bad_alloc&)
4465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004466 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004467 }
4468}
4469
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004470void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
4471{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004472 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004473
4474 try
4475 {
4476 if (n < 0)
4477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004478 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004479 }
4480
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004481 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004482
4483 if (context)
4484 {
4485 for (int i = 0; i < n; i++)
4486 {
4487 framebuffers[i] = context->createFramebuffer();
4488 }
4489 }
4490 }
4491 catch(std::bad_alloc&)
4492 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004493 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004494 }
4495}
4496
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004497void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
4498{
4499 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
4500
4501 try
4502 {
4503 if (n < 0)
4504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004505 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004506 }
4507
4508 gl::Context *context = gl::getNonLostContext();
4509
4510 if (context)
4511 {
4512 for (int i = 0; i < n; i++)
4513 {
4514 ids[i] = context->createQuery();
4515 }
4516 }
4517 }
4518 catch(std::bad_alloc&)
4519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004520 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004521 }
4522}
4523
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004524void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
4525{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004526 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004527
4528 try
4529 {
4530 if (n < 0)
4531 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004532 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004533 }
4534
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004535 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004536
4537 if (context)
4538 {
4539 for (int i = 0; i < n; i++)
4540 {
4541 renderbuffers[i] = context->createRenderbuffer();
4542 }
4543 }
4544 }
4545 catch(std::bad_alloc&)
4546 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004547 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004548 }
4549}
4550
4551void __stdcall glGenTextures(GLsizei n, GLuint* textures)
4552{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004553 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004554
4555 try
4556 {
4557 if (n < 0)
4558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004559 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004560 }
4561
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004562 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004563
4564 if (context)
4565 {
4566 for (int i = 0; i < n; i++)
4567 {
4568 textures[i] = context->createTexture();
4569 }
4570 }
4571 }
4572 catch(std::bad_alloc&)
4573 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004574 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004575 }
4576}
4577
daniel@transgaming.com85423182010-04-22 13:35:27 +00004578void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004579{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004580 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00004581 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004582 program, index, bufsize, length, size, type, name);
4583
4584 try
4585 {
4586 if (bufsize < 0)
4587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004588 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004589 }
4590
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004591 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00004592
4593 if (context)
4594 {
4595 gl::Program *programObject = context->getProgram(program);
4596
4597 if (!programObject)
4598 {
4599 if (context->getShader(program))
4600 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004601 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004602 }
4603 else
4604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004605 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004606 }
4607 }
4608
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004609 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00004610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004611 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00004612 }
4613
4614 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4615 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004616 }
4617 catch(std::bad_alloc&)
4618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004619 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004620 }
4621}
4622
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004623void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004624{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004625 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004626 "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 +00004627 program, index, bufsize, length, size, type, name);
4628
4629 try
4630 {
4631 if (bufsize < 0)
4632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004633 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004634 }
4635
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004637
4638 if (context)
4639 {
4640 gl::Program *programObject = context->getProgram(program);
4641
4642 if (!programObject)
4643 {
4644 if (context->getShader(program))
4645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004646 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004647 }
4648 else
4649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004650 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004651 }
4652 }
4653
4654 if (index >= (GLuint)programObject->getActiveUniformCount())
4655 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004656 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00004657 }
4658
4659 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4660 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004661 }
4662 catch(std::bad_alloc&)
4663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004664 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004665 }
4666}
4667
4668void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
4669{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004670 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 +00004671 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004672
4673 try
4674 {
4675 if (maxcount < 0)
4676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004677 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004678 }
4679
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004680 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004681
4682 if (context)
4683 {
4684 gl::Program *programObject = context->getProgram(program);
4685
4686 if (!programObject)
4687 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004688 if (context->getShader(program))
4689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004690 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004691 }
4692 else
4693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004694 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00004695 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004696 }
4697
4698 return programObject->getAttachedShaders(maxcount, count, shaders);
4699 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004700 }
4701 catch(std::bad_alloc&)
4702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004703 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004704 }
4705}
4706
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004707int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004708{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004709 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004710
4711 try
4712 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004713 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004714
4715 if (context)
4716 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004717
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004718 gl::Program *programObject = context->getProgram(program);
4719
4720 if (!programObject)
4721 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004722 if (context->getShader(program))
4723 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004724 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004725 }
4726 else
4727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004728 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00004729 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004730 }
4731
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004732 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004733 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004735 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00004736 }
4737
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004738 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004739 }
4740 }
4741 catch(std::bad_alloc&)
4742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004743 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004744 }
4745
4746 return -1;
4747}
4748
4749void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
4750{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004751 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004752
4753 try
4754 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004755 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004756
4757 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004758 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004759 if (!(context->getBooleanv(pname, params)))
4760 {
4761 GLenum nativeType;
4762 unsigned int numParams = 0;
4763 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004764 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004765
4766 if (numParams == 0)
4767 return; // it is known that the pname is valid, but there are no parameters to return
4768
4769 if (nativeType == GL_FLOAT)
4770 {
4771 GLfloat *floatParams = NULL;
4772 floatParams = new GLfloat[numParams];
4773
4774 context->getFloatv(pname, floatParams);
4775
4776 for (unsigned int i = 0; i < numParams; ++i)
4777 {
4778 if (floatParams[i] == 0.0f)
4779 params[i] = GL_FALSE;
4780 else
4781 params[i] = GL_TRUE;
4782 }
4783
4784 delete [] floatParams;
4785 }
4786 else if (nativeType == GL_INT)
4787 {
4788 GLint *intParams = NULL;
4789 intParams = new GLint[numParams];
4790
4791 context->getIntegerv(pname, intParams);
4792
4793 for (unsigned int i = 0; i < numParams; ++i)
4794 {
4795 if (intParams[i] == 0)
4796 params[i] = GL_FALSE;
4797 else
4798 params[i] = GL_TRUE;
4799 }
4800
4801 delete [] intParams;
4802 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004803 else if (nativeType == GL_INT_64_ANGLEX)
4804 {
4805 GLint64 *int64Params = NULL;
4806 int64Params = new GLint64[numParams];
4807
4808 context->getInteger64v(pname, int64Params);
4809
4810 for (unsigned int i = 0; i < numParams; ++i)
4811 {
4812 if (int64Params[i] == 0)
4813 params[i] = GL_FALSE;
4814 else
4815 params[i] = GL_TRUE;
4816 }
4817
4818 delete [] int64Params;
4819 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004820 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004821 }
4822 }
4823 catch(std::bad_alloc&)
4824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004825 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004826 }
4827}
4828
4829void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
4830{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004831 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 +00004832
4833 try
4834 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004835 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004836
4837 if (context)
4838 {
4839 gl::Buffer *buffer;
4840
4841 switch (target)
4842 {
4843 case GL_ARRAY_BUFFER:
4844 buffer = context->getArrayBuffer();
4845 break;
4846 case GL_ELEMENT_ARRAY_BUFFER:
4847 buffer = context->getElementArrayBuffer();
4848 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004849 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004850 }
4851
4852 if (!buffer)
4853 {
4854 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004855 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004856 }
4857
4858 switch (pname)
4859 {
4860 case GL_BUFFER_USAGE:
4861 *params = buffer->usage();
4862 break;
4863 case GL_BUFFER_SIZE:
4864 *params = buffer->size();
4865 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004866 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00004867 }
4868 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004869 }
4870 catch(std::bad_alloc&)
4871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004872 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004873 }
4874}
4875
4876GLenum __stdcall glGetError(void)
4877{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004878 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004879
4880 gl::Context *context = gl::getContext();
4881
4882 if (context)
4883 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00004884 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004885 }
4886
4887 return GL_NO_ERROR;
4888}
4889
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004890void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
4891{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004892 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004893
4894 try
4895 {
4896
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004897 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004898
4899 if (context)
4900 {
Jamie Madill33dc8432013-07-26 11:55:05 -04004901 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004902
4903 if (fenceObject == NULL)
4904 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004905 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004906 }
4907
Jamie Madillfb9a7402013-07-26 11:55:01 -04004908 if (fenceObject->isFence() != GL_TRUE)
4909 {
4910 return gl::error(GL_INVALID_OPERATION);
4911 }
4912
4913 switch (pname)
4914 {
4915 case GL_FENCE_STATUS_NV:
4916 case GL_FENCE_CONDITION_NV:
4917 break;
4918
4919 default: return gl::error(GL_INVALID_ENUM);
4920 }
4921
4922 params[0] = fenceObject->getFencei(pname);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004923 }
4924 }
4925 catch(std::bad_alloc&)
4926 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004927 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004928 }
4929}
4930
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004931void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
4932{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004933 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004934
4935 try
4936 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004937 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004938
4939 if (context)
4940 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004941 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004942 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004943 GLenum nativeType;
4944 unsigned int numParams = 0;
4945 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004946 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004947
4948 if (numParams == 0)
4949 return; // it is known that the pname is valid, but that there are no parameters to return.
4950
4951 if (nativeType == GL_BOOL)
4952 {
4953 GLboolean *boolParams = NULL;
4954 boolParams = new GLboolean[numParams];
4955
4956 context->getBooleanv(pname, boolParams);
4957
4958 for (unsigned int i = 0; i < numParams; ++i)
4959 {
4960 if (boolParams[i] == GL_FALSE)
4961 params[i] = 0.0f;
4962 else
4963 params[i] = 1.0f;
4964 }
4965
4966 delete [] boolParams;
4967 }
4968 else if (nativeType == GL_INT)
4969 {
4970 GLint *intParams = NULL;
4971 intParams = new GLint[numParams];
4972
4973 context->getIntegerv(pname, intParams);
4974
4975 for (unsigned int i = 0; i < numParams; ++i)
4976 {
Jamie Madill71fbd602013-07-19 16:36:55 -04004977 params[i] = static_cast<GLfloat>(intParams[i]);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00004978 }
4979
4980 delete [] intParams;
4981 }
Jamie Madill71fbd602013-07-19 16:36:55 -04004982 else if (nativeType == GL_INT_64_ANGLEX)
4983 {
4984 GLint64 *int64Params = NULL;
4985 int64Params = new GLint64[numParams];
4986
4987 context->getInteger64v(pname, int64Params);
4988
4989 for (unsigned int i = 0; i < numParams; ++i)
4990 {
4991 params[i] = static_cast<GLfloat>(int64Params[i]);
4992 }
4993
4994 delete [] int64Params;
4995 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00004996 }
4997 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004998 }
4999 catch(std::bad_alloc&)
5000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005001 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005002 }
5003}
5004
5005void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
5006{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005007 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 +00005008 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005009
5010 try
5011 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005012 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005013
5014 if (context)
5015 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005016 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005018 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005019 }
5020
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005021 gl::Framebuffer *framebuffer = NULL;
5022 if (target == GL_READ_FRAMEBUFFER_ANGLE)
5023 {
5024 if(context->getReadFramebufferHandle() == 0)
5025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005026 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005027 }
5028
5029 framebuffer = context->getReadFramebuffer();
5030 }
5031 else
5032 {
5033 if (context->getDrawFramebufferHandle() == 0)
5034 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005035 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00005036 }
5037
5038 framebuffer = context->getDrawFramebuffer();
5039 }
5040
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005041 GLenum attachmentType;
5042 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005043
5044 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005045 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00005046 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
5047
5048 if (colorAttachment >= context->getMaximumRenderTargets())
5049 {
5050 return gl::error(GL_INVALID_ENUM);
5051 }
5052
5053 attachmentType = framebuffer->getColorbufferType(colorAttachment);
5054 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
5055 }
5056 else
5057 {
5058 switch (attachment)
5059 {
5060 case GL_DEPTH_ATTACHMENT:
5061 attachmentType = framebuffer->getDepthbufferType();
5062 attachmentHandle = framebuffer->getDepthbufferHandle();
5063 break;
5064 case GL_STENCIL_ATTACHMENT:
5065 attachmentType = framebuffer->getStencilbufferType();
5066 attachmentHandle = framebuffer->getStencilbufferHandle();
5067 break;
5068 default: return gl::error(GL_INVALID_ENUM);
5069 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005070 }
5071
5072 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00005073 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005074 {
5075 attachmentObjectType = attachmentType;
5076 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00005077 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005078 {
5079 attachmentObjectType = GL_TEXTURE;
5080 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00005081 else
5082 {
5083 UNREACHABLE();
5084 return;
5085 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005086
5087 switch (pname)
5088 {
5089 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
5090 *params = attachmentObjectType;
5091 break;
5092 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
5093 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
5094 {
5095 *params = attachmentHandle;
5096 }
5097 else
5098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005099 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005100 }
5101 break;
5102 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
5103 if (attachmentObjectType == GL_TEXTURE)
5104 {
5105 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
5106 }
5107 else
5108 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005109 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005110 }
5111 break;
5112 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
5113 if (attachmentObjectType == GL_TEXTURE)
5114 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00005115 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005116 {
5117 *params = attachmentType;
5118 }
5119 else
5120 {
5121 *params = 0;
5122 }
5123 }
5124 else
5125 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005126 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005127 }
5128 break;
5129 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005130 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00005131 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005132 }
5133 }
5134 catch(std::bad_alloc&)
5135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005136 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005137 }
5138}
5139
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00005140GLenum __stdcall glGetGraphicsResetStatusEXT(void)
5141{
5142 EVENT("()");
5143
5144 try
5145 {
5146 gl::Context *context = gl::getContext();
5147
5148 if (context)
5149 {
5150 return context->getResetStatus();
5151 }
5152
5153 return GL_NO_ERROR;
5154 }
5155 catch(std::bad_alloc&)
5156 {
5157 return GL_OUT_OF_MEMORY;
5158 }
5159}
5160
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005161void __stdcall glGetIntegerv(GLenum pname, GLint* params)
5162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005163 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005164
5165 try
5166 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005167 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005168
5169 if (context)
5170 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005171 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005172 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005173 GLenum nativeType;
5174 unsigned int numParams = 0;
5175 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005176 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005177
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005178 if (numParams == 0)
5179 return; // it is known that pname is valid, but there are no parameters to return
5180
5181 if (nativeType == GL_BOOL)
5182 {
5183 GLboolean *boolParams = NULL;
5184 boolParams = new GLboolean[numParams];
5185
5186 context->getBooleanv(pname, boolParams);
5187
5188 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005189 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005190 if (boolParams[i] == GL_FALSE)
5191 params[i] = 0;
5192 else
5193 params[i] = 1;
5194 }
5195
5196 delete [] boolParams;
5197 }
5198 else if (nativeType == GL_FLOAT)
5199 {
5200 GLfloat *floatParams = NULL;
5201 floatParams = new GLfloat[numParams];
5202
5203 context->getFloatv(pname, floatParams);
5204
5205 for (unsigned int i = 0; i < numParams; ++i)
5206 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005207 // 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 +00005208 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 +00005209 {
Jamie Madill71fbd602013-07-19 16:36:55 -04005210 params[i] = static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005211 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005212 else
Jamie Madill71fbd602013-07-19 16:36:55 -04005213 {
Jamie Madillaf496912013-07-19 16:36:54 -04005214 params[i] = gl::iround<GLint>(floatParams[i]);
Jamie Madill71fbd602013-07-19 16:36:55 -04005215 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005216 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005217
daniel@transgaming.com777f2672010-04-07 03:25:16 +00005218 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005219 }
Jamie Madill71fbd602013-07-19 16:36:55 -04005220 else if (nativeType == GL_INT_64_ANGLEX)
5221 {
5222 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
5223 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
5224 GLint64 *int64Params = NULL;
5225 int64Params = new GLint64[numParams];
5226
5227 context->getInteger64v(pname, int64Params);
5228
5229 for (unsigned int i = 0; i < numParams; ++i)
5230 {
5231 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
5232 params[i] = static_cast<GLint>(clampedValue);
5233 }
5234
5235 delete [] int64Params;
5236 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005237 }
5238 }
5239 }
5240 catch(std::bad_alloc&)
5241 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005242 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005243 }
5244}
5245
5246void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
5247{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005248 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005249
5250 try
5251 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005252 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005253
5254 if (context)
5255 {
5256 gl::Program *programObject = context->getProgram(program);
5257
5258 if (!programObject)
5259 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005260 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 }
5262
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005263 if (context->getClientVersion() < 3)
5264 {
5265 switch (pname)
5266 {
5267 case GL_ACTIVE_UNIFORM_BLOCKS:
5268 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5269 return gl::error(GL_INVALID_ENUM);
5270 }
5271 }
5272
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005273 switch (pname)
5274 {
5275 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005276 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005277 return;
5278 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005279 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005280 return;
5281 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00005282 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005283 return;
5284 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005285 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005286 return;
5287 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005288 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005289 return;
5290 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005291 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005292 return;
5293 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00005294 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005295 return;
5296 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005297 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005298 return;
5299 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00005300 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005301 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005302 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00005303 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00005304 return;
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00005305 case GL_ACTIVE_UNIFORM_BLOCKS:
5306 *params = programObject->getActiveUniformBlockCount();
5307 return;
5308 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
5309 *params = programObject->getActiveUniformBlockMaxLength();
5310 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005311 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005312 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005313 }
5314 }
5315 }
5316 catch(std::bad_alloc&)
5317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005318 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005319 }
5320}
5321
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005322void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005323{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005324 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 +00005325 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005326
5327 try
5328 {
5329 if (bufsize < 0)
5330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005331 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005332 }
5333
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005334 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005335
5336 if (context)
5337 {
5338 gl::Program *programObject = context->getProgram(program);
5339
5340 if (!programObject)
5341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005342 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005343 }
5344
5345 programObject->getInfoLog(bufsize, length, infolog);
5346 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005347 }
5348 catch(std::bad_alloc&)
5349 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005350 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005351 }
5352}
5353
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005354void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
5355{
5356 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
5357
5358 try
5359 {
5360 switch (pname)
5361 {
5362 case GL_CURRENT_QUERY_EXT:
5363 break;
5364 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005365 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005366 }
5367
5368 gl::Context *context = gl::getNonLostContext();
5369
5370 if (context)
5371 {
5372 params[0] = context->getActiveQuery(target);
5373 }
5374 }
5375 catch(std::bad_alloc&)
5376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005377 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005378 }
5379}
5380
5381void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
5382{
5383 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
5384
5385 try
5386 {
5387 switch (pname)
5388 {
5389 case GL_QUERY_RESULT_EXT:
5390 case GL_QUERY_RESULT_AVAILABLE_EXT:
5391 break;
5392 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005393 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005394 }
5395 gl::Context *context = gl::getNonLostContext();
5396
5397 if (context)
5398 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005399 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5400
5401 if (!queryObject)
5402 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005403 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005404 }
5405
5406 if (context->getActiveQuery(queryObject->getType()) == id)
5407 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005408 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005409 }
5410
5411 switch(pname)
5412 {
5413 case GL_QUERY_RESULT_EXT:
5414 params[0] = queryObject->getResult();
5415 break;
5416 case GL_QUERY_RESULT_AVAILABLE_EXT:
5417 params[0] = queryObject->isResultAvailable();
5418 break;
5419 default:
5420 ASSERT(false);
5421 }
5422 }
5423 }
5424 catch(std::bad_alloc&)
5425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005426 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005427 }
5428}
5429
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005430void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
5431{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005432 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 +00005433
5434 try
5435 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005436 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005437
5438 if (context)
5439 {
5440 if (target != GL_RENDERBUFFER)
5441 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005442 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005443 }
5444
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005445 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005446 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005447 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005448 }
5449
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005450 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005451
5452 switch (pname)
5453 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005454 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
5455 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
5456 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
5457 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
5458 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
5459 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
5460 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
5461 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
5462 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005463 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005464 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005465 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00005466 *params = renderbuffer->getSamples();
5467 }
5468 else
5469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005470 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005471 }
5472 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005473 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005474 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00005475 }
5476 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005477 }
5478 catch(std::bad_alloc&)
5479 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005480 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005481 }
5482}
5483
5484void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
5485{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005486 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005487
5488 try
5489 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005490 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005491
5492 if (context)
5493 {
5494 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005495
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005496 if (!shaderObject)
5497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005498 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005499 }
5500
5501 switch (pname)
5502 {
5503 case GL_SHADER_TYPE:
5504 *params = shaderObject->getType();
5505 return;
5506 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005507 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005508 return;
5509 case GL_COMPILE_STATUS:
5510 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
5511 return;
5512 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005513 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005514 return;
5515 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005516 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005517 return;
zmo@google.coma574f782011-10-03 21:45:23 +00005518 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
5519 *params = shaderObject->getTranslatedSourceLength();
5520 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005521 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005522 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005523 }
5524 }
5525 }
5526 catch(std::bad_alloc&)
5527 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005528 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005529 }
5530}
5531
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005532void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005533{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005534 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 +00005535 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005536
5537 try
5538 {
5539 if (bufsize < 0)
5540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005541 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005542 }
5543
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005544 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005545
5546 if (context)
5547 {
5548 gl::Shader *shaderObject = context->getShader(shader);
5549
5550 if (!shaderObject)
5551 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005552 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005553 }
5554
5555 shaderObject->getInfoLog(bufsize, length, infolog);
5556 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005557 }
5558 catch(std::bad_alloc&)
5559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005560 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005561 }
5562}
5563
5564void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
5565{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005566 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 +00005567 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005568
5569 try
5570 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005571 switch (shadertype)
5572 {
5573 case GL_VERTEX_SHADER:
5574 case GL_FRAGMENT_SHADER:
5575 break;
5576 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005577 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005578 }
5579
5580 switch (precisiontype)
5581 {
5582 case GL_LOW_FLOAT:
5583 case GL_MEDIUM_FLOAT:
5584 case GL_HIGH_FLOAT:
5585 // Assume IEEE 754 precision
5586 range[0] = 127;
5587 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005588 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005589 break;
5590 case GL_LOW_INT:
5591 case GL_MEDIUM_INT:
5592 case GL_HIGH_INT:
5593 // Some (most) hardware only supports single-precision floating-point numbers,
5594 // which can accurately represent integers up to +/-16777216
5595 range[0] = 24;
5596 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00005597 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005598 break;
5599 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005600 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00005601 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005602 }
5603 catch(std::bad_alloc&)
5604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005606 }
5607}
5608
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005609void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005611 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 +00005612 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005613
5614 try
5615 {
5616 if (bufsize < 0)
5617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005618 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005619 }
5620
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005621 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005622
5623 if (context)
5624 {
5625 gl::Shader *shaderObject = context->getShader(shader);
5626
5627 if (!shaderObject)
5628 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005629 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00005630 }
5631
5632 shaderObject->getSource(bufsize, length, source);
5633 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005634 }
5635 catch(std::bad_alloc&)
5636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005637 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005638 }
5639}
5640
zmo@google.coma574f782011-10-03 21:45:23 +00005641void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
5642{
5643 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
5644 shader, bufsize, length, source);
5645
5646 try
5647 {
5648 if (bufsize < 0)
5649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005650 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00005651 }
5652
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005653 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00005654
5655 if (context)
5656 {
5657 gl::Shader *shaderObject = context->getShader(shader);
5658
5659 if (!shaderObject)
5660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005661 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00005662 }
5663
5664 shaderObject->getTranslatedSource(bufsize, length, source);
5665 }
5666 }
5667 catch(std::bad_alloc&)
5668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005669 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00005670 }
5671}
5672
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005673const GLubyte* __stdcall glGetString(GLenum name)
5674{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005675 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005676
5677 try
5678 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005679 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00005680
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005681 switch (name)
5682 {
5683 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00005684 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005685 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00005686 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005687 case GL_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005688 if (context->getClientVersion() == 2)
5689 {
5690 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
5691 }
5692 else
5693 {
5694 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " VERSION_STRING ")";
5695 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005696 case GL_SHADING_LANGUAGE_VERSION:
shannonwoods@chromium.orge2865d02013-05-30 00:06:01 +00005697 if (context->getClientVersion() == 2)
5698 {
5699 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
5700 }
5701 else
5702 {
5703 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " VERSION_STRING ")";
5704 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005705 case GL_EXTENSIONS:
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00005706 return (GLubyte*)((context != NULL) ? context->getCombinedExtensionsString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005707 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005708 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005709 }
5710 }
5711 catch(std::bad_alloc&)
5712 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005713 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005714 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005715}
5716
5717void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
5718{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005719 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 +00005720
5721 try
5722 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005723 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005724
5725 if (context)
5726 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005727 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005728
Jamie Madillfb8a8302013-07-03 14:24:12 -04005729 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005731 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005732 }
5733
5734 switch (pname)
5735 {
5736 case GL_TEXTURE_MAG_FILTER:
5737 *params = (GLfloat)texture->getMagFilter();
5738 break;
5739 case GL_TEXTURE_MIN_FILTER:
5740 *params = (GLfloat)texture->getMinFilter();
5741 break;
5742 case GL_TEXTURE_WRAP_S:
5743 *params = (GLfloat)texture->getWrapS();
5744 break;
5745 case GL_TEXTURE_WRAP_T:
5746 *params = (GLfloat)texture->getWrapT();
5747 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005748 case GL_TEXTURE_WRAP_R:
5749 if (context->getClientVersion() < 3)
5750 {
5751 return gl::error(GL_INVALID_ENUM);
5752 }
5753 *params = (GLfloat)texture->getWrapR();
5754 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005755 case GL_TEXTURE_IMMUTABLE_FORMAT:
5756 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005757 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
5758 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005759 case GL_TEXTURE_IMMUTABLE_LEVELS:
5760 if (context->getClientVersion() < 3)
5761 {
5762 return gl::error(GL_INVALID_ENUM);
5763 }
5764 *params = (GLfloat)(texture->isImmutable() ? texture->levelCount() : 0);
5765 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005766 case GL_TEXTURE_USAGE_ANGLE:
5767 *params = (GLfloat)texture->getUsage();
5768 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005769 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5770 if (!context->supportsTextureFilterAnisotropy())
5771 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005772 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005773 }
5774 *params = (GLfloat)texture->getMaxAnisotropy();
5775 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005776 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005777 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005778 }
5779 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005780 }
5781 catch(std::bad_alloc&)
5782 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005783 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005784 }
5785}
5786
5787void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
5788{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005789 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 +00005790
5791 try
5792 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005793 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005794
5795 if (context)
5796 {
Jamie Madillfb8a8302013-07-03 14:24:12 -04005797 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005798
Jamie Madillfb8a8302013-07-03 14:24:12 -04005799 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005800 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005801 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005802 }
5803
5804 switch (pname)
5805 {
5806 case GL_TEXTURE_MAG_FILTER:
5807 *params = texture->getMagFilter();
5808 break;
5809 case GL_TEXTURE_MIN_FILTER:
5810 *params = texture->getMinFilter();
5811 break;
5812 case GL_TEXTURE_WRAP_S:
5813 *params = texture->getWrapS();
5814 break;
5815 case GL_TEXTURE_WRAP_T:
5816 *params = texture->getWrapT();
5817 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00005818 case GL_TEXTURE_WRAP_R:
5819 if (context->getClientVersion() < 3)
5820 {
5821 return gl::error(GL_INVALID_ENUM);
5822 }
5823 *params = texture->getWrapR();
5824 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005825 case GL_TEXTURE_IMMUTABLE_FORMAT:
5826 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00005827 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
5828 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00005829 case GL_TEXTURE_IMMUTABLE_LEVELS:
5830 if (context->getClientVersion() < 3)
5831 {
5832 return gl::error(GL_INVALID_ENUM);
5833 }
5834 *params = texture->isImmutable() ? texture->levelCount() : 0;
5835 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00005836 case GL_TEXTURE_USAGE_ANGLE:
5837 *params = texture->getUsage();
5838 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005839 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
5840 if (!context->supportsTextureFilterAnisotropy())
5841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005842 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00005843 }
5844 *params = (GLint)texture->getMaxAnisotropy();
5845 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00005846
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005847 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005848 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00005849 }
5850 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005851 }
5852 catch(std::bad_alloc&)
5853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005854 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005855 }
5856}
5857
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005858void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
5859{
5860 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
5861 program, location, bufSize, params);
5862
5863 try
5864 {
5865 if (bufSize < 0)
5866 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005867 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005868 }
5869
5870 gl::Context *context = gl::getNonLostContext();
5871
5872 if (context)
5873 {
5874 if (program == 0)
5875 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005876 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005877 }
5878
5879 gl::Program *programObject = context->getProgram(program);
5880
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005881 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005883 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005884 }
5885
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005886 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5887 if (!programBinary)
5888 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005889 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005890 }
5891
5892 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005894 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005895 }
5896 }
5897 }
5898 catch(std::bad_alloc&)
5899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005900 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005901 }
5902}
5903
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005904void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
5905{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005906 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005907
5908 try
5909 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005911
5912 if (context)
5913 {
5914 if (program == 0)
5915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005916 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005917 }
5918
5919 gl::Program *programObject = context->getProgram(program);
5920
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005921 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005923 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005924 }
5925
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005926 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5927 if (!programBinary)
5928 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005929 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005930 }
5931
5932 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005933 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005934 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005935 }
5936 }
5937 }
5938 catch(std::bad_alloc&)
5939 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005940 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005941 }
5942}
5943
5944void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
5945{
5946 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
5947 program, location, bufSize, params);
5948
5949 try
5950 {
5951 if (bufSize < 0)
5952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005953 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005954 }
5955
5956 gl::Context *context = gl::getNonLostContext();
5957
5958 if (context)
5959 {
5960 if (program == 0)
5961 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005962 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005963 }
5964
5965 gl::Program *programObject = context->getProgram(program);
5966
daniel@transgaming.com716056c2012-07-24 18:38:59 +00005967 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005969 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00005970 }
5971
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005972 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
5973 if (!programBinary)
5974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005975 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00005976 }
5977
5978 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005979 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005980 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005981 }
5982 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005983 }
5984 catch(std::bad_alloc&)
5985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005986 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005987 }
5988}
5989
5990void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
5991{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005992 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005993
5994 try
5995 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005996 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00005997
5998 if (context)
5999 {
6000 if (program == 0)
6001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006002 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006003 }
6004
6005 gl::Program *programObject = context->getProgram(program);
6006
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006007 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006009 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006010 }
6011
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006012 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6013 if (!programBinary)
6014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006015 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006016 }
6017
6018 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006020 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00006021 }
6022 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006023 }
6024 catch(std::bad_alloc&)
6025 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006026 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006027 }
6028}
6029
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006030int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006031{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006032 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006033
6034 try
6035 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006036 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006037
6038 if (strstr(name, "gl_") == name)
6039 {
6040 return -1;
6041 }
6042
6043 if (context)
6044 {
6045 gl::Program *programObject = context->getProgram(program);
6046
6047 if (!programObject)
6048 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006049 if (context->getShader(program))
6050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006051 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006052 }
6053 else
6054 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006055 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00006056 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006057 }
6058
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006059 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00006060 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006061 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006062 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006063 }
6064
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006065 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006066 }
6067 }
6068 catch(std::bad_alloc&)
6069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006070 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006071 }
6072
6073 return -1;
6074}
6075
6076void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
6077{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006078 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006079
6080 try
6081 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006082 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006083
daniel@transgaming.come0078962010-04-15 20:45:08 +00006084 if (context)
6085 {
6086 if (index >= gl::MAX_VERTEX_ATTRIBS)
6087 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006088 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006089 }
6090
daniel@transgaming.com83921382011-01-08 05:46:00 +00006091 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006092
Jamie Madillaff71502013-07-02 11:57:05 -04006093 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006094 {
Jamie Madillaff71502013-07-02 11:57:05 -04006095 return;
6096 }
6097
6098 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6099 {
6100 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6101 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006102 {
Jamie Madillaff71502013-07-02 11:57:05 -04006103 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00006104 }
Jamie Madillaff71502013-07-02 11:57:05 -04006105 }
6106 else
6107 {
6108 *params = attribState.querySingleParameter<GLfloat>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006109 }
6110 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006111 }
6112 catch(std::bad_alloc&)
6113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006114 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006115 }
6116}
6117
6118void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
6119{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006120 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006121
6122 try
6123 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006124 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006125
daniel@transgaming.come0078962010-04-15 20:45:08 +00006126 if (context)
6127 {
6128 if (index >= gl::MAX_VERTEX_ATTRIBS)
6129 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006130 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006131 }
6132
daniel@transgaming.com83921382011-01-08 05:46:00 +00006133 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006134
Jamie Madillaff71502013-07-02 11:57:05 -04006135 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
daniel@transgaming.come0078962010-04-15 20:45:08 +00006136 {
Jamie Madillaff71502013-07-02 11:57:05 -04006137 return;
6138 }
6139
6140 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6141 {
6142 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
6143 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00006144 {
Jamie Madillaff71502013-07-02 11:57:05 -04006145 float currentValue = currentValueData.FloatValues[i];
Jamie Madillaf496912013-07-19 16:36:54 -04006146 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006147 }
Jamie Madillaff71502013-07-02 11:57:05 -04006148 }
6149 else
6150 {
6151 *params = attribState.querySingleParameter<GLint>(pname);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006152 }
6153 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006154 }
6155 catch(std::bad_alloc&)
6156 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006157 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006158 }
6159}
6160
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006161void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006163 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006164
6165 try
6166 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006167 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006168
daniel@transgaming.come0078962010-04-15 20:45:08 +00006169 if (context)
6170 {
6171 if (index >= gl::MAX_VERTEX_ATTRIBS)
6172 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006173 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006174 }
6175
6176 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
6177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006178 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00006179 }
6180
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006181 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00006182 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006183 }
6184 catch(std::bad_alloc&)
6185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006186 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006187 }
6188}
6189
6190void __stdcall glHint(GLenum target, GLenum mode)
6191{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006192 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006193
6194 try
6195 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006196 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006197 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006198 case GL_FASTEST:
6199 case GL_NICEST:
6200 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006201 break;
6202 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006203 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006204 }
6205
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006206 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006207 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006208 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006209 case GL_GENERATE_MIPMAP_HINT:
6210 if (context) context->setGenerateMipmapHint(mode);
6211 break;
6212 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6213 if (context) context->setFragmentShaderDerivativeHint(mode);
6214 break;
6215 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006216 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006217 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006218 }
6219 catch(std::bad_alloc&)
6220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006221 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006222 }
6223}
6224
6225GLboolean __stdcall glIsBuffer(GLuint buffer)
6226{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006227 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006228
6229 try
6230 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006231 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006232
6233 if (context && buffer)
6234 {
6235 gl::Buffer *bufferObject = context->getBuffer(buffer);
6236
6237 if (bufferObject)
6238 {
6239 return GL_TRUE;
6240 }
6241 }
6242 }
6243 catch(std::bad_alloc&)
6244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006245 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006246 }
6247
6248 return GL_FALSE;
6249}
6250
6251GLboolean __stdcall glIsEnabled(GLenum cap)
6252{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006253 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006254
6255 try
6256 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006257 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006258
6259 if (context)
6260 {
6261 switch (cap)
6262 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006263 case GL_CULL_FACE: return context->isCullFaceEnabled();
6264 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6265 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6266 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6267 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6268 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6269 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6270 case GL_BLEND: return context->isBlendEnabled();
6271 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006272 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006273 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006274 }
6275 }
6276 }
6277 catch(std::bad_alloc&)
6278 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006279 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006280 }
6281
6282 return false;
6283}
6284
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006285GLboolean __stdcall glIsFenceNV(GLuint fence)
6286{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006287 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006288
6289 try
6290 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006291 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006292
6293 if (context)
6294 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006295 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006296
6297 if (fenceObject == NULL)
6298 {
6299 return GL_FALSE;
6300 }
6301
6302 return fenceObject->isFence();
6303 }
6304 }
6305 catch(std::bad_alloc&)
6306 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006307 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006308 }
6309
6310 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006311}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006312
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006313GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6314{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006315 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006316
6317 try
6318 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006319 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006320
6321 if (context && framebuffer)
6322 {
6323 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6324
6325 if (framebufferObject)
6326 {
6327 return GL_TRUE;
6328 }
6329 }
6330 }
6331 catch(std::bad_alloc&)
6332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006333 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006334 }
6335
6336 return GL_FALSE;
6337}
6338
6339GLboolean __stdcall glIsProgram(GLuint program)
6340{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006341 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006342
6343 try
6344 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006345 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006346
6347 if (context && program)
6348 {
6349 gl::Program *programObject = context->getProgram(program);
6350
6351 if (programObject)
6352 {
6353 return GL_TRUE;
6354 }
6355 }
6356 }
6357 catch(std::bad_alloc&)
6358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006359 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006360 }
6361
6362 return GL_FALSE;
6363}
6364
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006365GLboolean __stdcall glIsQueryEXT(GLuint id)
6366{
6367 EVENT("(GLuint id = %d)", id);
6368
6369 try
6370 {
6371 if (id == 0)
6372 {
6373 return GL_FALSE;
6374 }
6375
6376 gl::Context *context = gl::getNonLostContext();
6377
6378 if (context)
6379 {
6380 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6381
6382 if (queryObject)
6383 {
6384 return GL_TRUE;
6385 }
6386 }
6387 }
6388 catch(std::bad_alloc&)
6389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006390 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006391 }
6392
6393 return GL_FALSE;
6394}
6395
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006396GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006398 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006399
6400 try
6401 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006402 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006403
6404 if (context && renderbuffer)
6405 {
6406 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6407
6408 if (renderbufferObject)
6409 {
6410 return GL_TRUE;
6411 }
6412 }
6413 }
6414 catch(std::bad_alloc&)
6415 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006416 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006417 }
6418
6419 return GL_FALSE;
6420}
6421
6422GLboolean __stdcall glIsShader(GLuint shader)
6423{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006424 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006425
6426 try
6427 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006428 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006429
6430 if (context && shader)
6431 {
6432 gl::Shader *shaderObject = context->getShader(shader);
6433
6434 if (shaderObject)
6435 {
6436 return GL_TRUE;
6437 }
6438 }
6439 }
6440 catch(std::bad_alloc&)
6441 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006442 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006443 }
6444
6445 return GL_FALSE;
6446}
6447
6448GLboolean __stdcall glIsTexture(GLuint texture)
6449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006450 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006451
6452 try
6453 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006454 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006455
6456 if (context && texture)
6457 {
6458 gl::Texture *textureObject = context->getTexture(texture);
6459
6460 if (textureObject)
6461 {
6462 return GL_TRUE;
6463 }
6464 }
6465 }
6466 catch(std::bad_alloc&)
6467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006468 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006469 }
6470
6471 return GL_FALSE;
6472}
6473
6474void __stdcall glLineWidth(GLfloat width)
6475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006476 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006477
6478 try
6479 {
6480 if (width <= 0.0f)
6481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006482 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006483 }
6484
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006485 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006486
6487 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006488 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006489 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006490 }
6491 }
6492 catch(std::bad_alloc&)
6493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006494 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006495 }
6496}
6497
6498void __stdcall glLinkProgram(GLuint program)
6499{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006500 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006501
6502 try
6503 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006504 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006505
6506 if (context)
6507 {
6508 gl::Program *programObject = context->getProgram(program);
6509
6510 if (!programObject)
6511 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006512 if (context->getShader(program))
6513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006515 }
6516 else
6517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006518 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006519 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006520 }
6521
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006522 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006523 }
6524 }
6525 catch(std::bad_alloc&)
6526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006527 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006528 }
6529}
6530
6531void __stdcall glPixelStorei(GLenum pname, GLint param)
6532{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006533 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006534
6535 try
6536 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006537 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006538
6539 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006540 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006541 switch (pname)
6542 {
6543 case GL_UNPACK_ALIGNMENT:
6544 if (param != 1 && param != 2 && param != 4 && param != 8)
6545 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006546 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006547 }
6548
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006549 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006550 break;
6551
6552 case GL_PACK_ALIGNMENT:
6553 if (param != 1 && param != 2 && param != 4 && param != 8)
6554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006555 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006556 }
6557
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006558 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006559 break;
6560
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006561 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6562 context->setPackReverseRowOrder(param != 0);
6563 break;
6564
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006565 case GL_UNPACK_IMAGE_HEIGHT:
6566 case GL_UNPACK_SKIP_IMAGES:
6567 case GL_UNPACK_ROW_LENGTH:
6568 case GL_UNPACK_SKIP_ROWS:
6569 case GL_UNPACK_SKIP_PIXELS:
6570 case GL_PACK_ROW_LENGTH:
6571 case GL_PACK_SKIP_ROWS:
6572 case GL_PACK_SKIP_PIXELS:
6573 if (context->getClientVersion() < 3)
6574 {
6575 return gl::error(GL_INVALID_ENUM);
6576 }
6577 UNIMPLEMENTED();
6578 break;
6579
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006580 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006581 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006582 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006583 }
6584 }
6585 catch(std::bad_alloc&)
6586 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006587 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006588 }
6589}
6590
6591void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6592{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006593 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006594
6595 try
6596 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006597 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006598
6599 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006600 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006601 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006602 }
6603 }
6604 catch(std::bad_alloc&)
6605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006606 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006607 }
6608}
6609
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006610void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6611 GLenum format, GLenum type, GLsizei bufSize,
6612 GLvoid *data)
6613{
6614 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6615 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6616 x, y, width, height, format, type, bufSize, data);
6617
6618 try
6619 {
6620 if (width < 0 || height < 0 || bufSize < 0)
6621 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006622 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006623 }
6624
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006625 gl::Context *context = gl::getNonLostContext();
6626
6627 if (context)
6628 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006629 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006630 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006631
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006632 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6633 // and attempting to read back if that's the case is an error. The error will be registered
6634 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006635 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006636 return;
6637
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006638 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6639 validES3ReadFormatType(currentInternalFormat, format, type);
6640
6641 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006642 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006643 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006644 }
6645
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006646 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6647 }
6648 }
6649 catch(std::bad_alloc&)
6650 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006651 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006652 }
6653}
6654
6655void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6656 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006657{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006658 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006659 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006660 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006661
6662 try
6663 {
6664 if (width < 0 || height < 0)
6665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006666 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006667 }
6668
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006669 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006670
6671 if (context)
6672 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006673 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006674 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006675
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006676 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6677 // and attempting to read back if that's the case is an error. The error will be registered
6678 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006679 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006680 return;
6681
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006682 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6683 validES3ReadFormatType(currentInternalFormat, format, type);
6684
6685 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006687 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006688 }
6689
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006690 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006691 }
6692 }
6693 catch(std::bad_alloc&)
6694 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006695 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006696 }
6697}
6698
6699void __stdcall glReleaseShaderCompiler(void)
6700{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006701 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006702
6703 try
6704 {
6705 gl::Shader::releaseCompiler();
6706 }
6707 catch(std::bad_alloc&)
6708 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006709 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006710 }
6711}
6712
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006713void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006714{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006715 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 +00006716 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717
6718 try
6719 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006720 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006721
6722 if (context)
6723 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006724 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6725 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006726 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006727 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006728 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006729
6730 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006731 }
6732 }
6733 catch(std::bad_alloc&)
6734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006735 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006736 }
6737}
6738
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006739void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6740{
6741 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6742}
6743
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006744void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6745{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006746 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006747
6748 try
6749 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006750 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006751
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006752 if (context)
6753 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006754 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006755 }
6756 }
6757 catch(std::bad_alloc&)
6758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006759 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006760 }
6761}
6762
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006763void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6764{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006765 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006766
6767 try
6768 {
6769 if (condition != GL_ALL_COMPLETED_NV)
6770 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006771 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006772 }
6773
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006774 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006775
6776 if (context)
6777 {
Jamie Madill33dc8432013-07-26 11:55:05 -04006778 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006779
6780 if (fenceObject == NULL)
6781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006782 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006783 }
6784
6785 fenceObject->setFence(condition);
6786 }
6787 }
6788 catch(std::bad_alloc&)
6789 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006790 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006791 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006792}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006793
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006794void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6795{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006796 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 +00006797
6798 try
6799 {
6800 if (width < 0 || height < 0)
6801 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006802 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006803 }
6804
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006805 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006806
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006807 if (context)
6808 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006809 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006810 }
6811 }
6812 catch(std::bad_alloc&)
6813 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006814 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006815 }
6816}
6817
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006818void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006819{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006820 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006821 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006822 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006823
6824 try
6825 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006826 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006827 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006828 }
6829 catch(std::bad_alloc&)
6830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006831 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006832 }
6833}
6834
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006835void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006836{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006837 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 +00006838 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006839
6840 try
6841 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006842 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006844 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006845 }
6846
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006847 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006848
6849 if (context)
6850 {
6851 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006852
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006853 if (!shaderObject)
6854 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006855 if (context->getProgram(shader))
6856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006857 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006858 }
6859 else
6860 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006861 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006862 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006863 }
6864
6865 shaderObject->setSource(count, string, length);
6866 }
6867 }
6868 catch(std::bad_alloc&)
6869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006870 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006871 }
6872}
6873
6874void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6875{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006876 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006877}
6878
6879void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6880{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006881 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 +00006882
6883 try
6884 {
6885 switch (face)
6886 {
6887 case GL_FRONT:
6888 case GL_BACK:
6889 case GL_FRONT_AND_BACK:
6890 break;
6891 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006892 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006893 }
6894
6895 switch (func)
6896 {
6897 case GL_NEVER:
6898 case GL_ALWAYS:
6899 case GL_LESS:
6900 case GL_LEQUAL:
6901 case GL_EQUAL:
6902 case GL_GEQUAL:
6903 case GL_GREATER:
6904 case GL_NOTEQUAL:
6905 break;
6906 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006907 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006908 }
6909
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006911
6912 if (context)
6913 {
6914 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6915 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006916 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006917 }
6918
6919 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6920 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006921 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006922 }
6923 }
6924 }
6925 catch(std::bad_alloc&)
6926 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006927 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006928 }
6929}
6930
6931void __stdcall glStencilMask(GLuint mask)
6932{
6933 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6934}
6935
6936void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6937{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006938 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006939
6940 try
6941 {
6942 switch (face)
6943 {
6944 case GL_FRONT:
6945 case GL_BACK:
6946 case GL_FRONT_AND_BACK:
6947 break;
6948 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006949 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006950 }
6951
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006952 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006953
6954 if (context)
6955 {
6956 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6957 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006958 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006959 }
6960
6961 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6962 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006963 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006964 }
6965 }
6966 }
6967 catch(std::bad_alloc&)
6968 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006969 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006970 }
6971}
6972
6973void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6974{
6975 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6976}
6977
6978void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6979{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006980 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 +00006981 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006982
6983 try
6984 {
6985 switch (face)
6986 {
6987 case GL_FRONT:
6988 case GL_BACK:
6989 case GL_FRONT_AND_BACK:
6990 break;
6991 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006992 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006993 }
6994
6995 switch (fail)
6996 {
6997 case GL_ZERO:
6998 case GL_KEEP:
6999 case GL_REPLACE:
7000 case GL_INCR:
7001 case GL_DECR:
7002 case GL_INVERT:
7003 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007004 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007005 break;
7006 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007007 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007008 }
7009
7010 switch (zfail)
7011 {
7012 case GL_ZERO:
7013 case GL_KEEP:
7014 case GL_REPLACE:
7015 case GL_INCR:
7016 case GL_DECR:
7017 case GL_INVERT:
7018 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007019 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007020 break;
7021 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007022 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007023 }
7024
7025 switch (zpass)
7026 {
7027 case GL_ZERO:
7028 case GL_KEEP:
7029 case GL_REPLACE:
7030 case GL_INCR:
7031 case GL_DECR:
7032 case GL_INVERT:
7033 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00007034 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007035 break;
7036 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007037 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007038 }
7039
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007040 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007041
7042 if (context)
7043 {
7044 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
7045 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007046 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007047 }
7048
7049 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
7050 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007051 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007052 }
7053 }
7054 }
7055 catch(std::bad_alloc&)
7056 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007057 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007058 }
7059}
7060
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007061GLboolean __stdcall glTestFenceNV(GLuint fence)
7062{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007063 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007064
7065 try
7066 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007067 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007068
7069 if (context)
7070 {
Jamie Madill33dc8432013-07-26 11:55:05 -04007071 gl::FenceNV *fenceObject = context->getFenceNV(fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007072
7073 if (fenceObject == NULL)
7074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007075 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007076 }
7077
Jamie Madillfb9a7402013-07-26 11:55:01 -04007078 if (fenceObject->isFence() != GL_TRUE)
7079 {
7080 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
7081 }
7082
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007083 return fenceObject->testFence();
7084 }
7085 }
7086 catch(std::bad_alloc&)
7087 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007088 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007089 }
7090
7091 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00007092}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00007093
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007094void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
7095 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007096{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007097 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 +00007098 "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 +00007099 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007100
7101 try
7102 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007103 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007104
7105 if (context)
7106 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007107 if (context->getClientVersion() < 3 &&
7108 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
7109 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007110 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007111 return;
7112 }
7113
7114 if (context->getClientVersion() >= 3 &&
7115 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
7116 0, 0, 0, width, height, 1, border, format, type))
7117 {
7118 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00007119 }
7120
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007121 switch (target)
7122 {
7123 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007124 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007125 gl::Texture2D *texture = context->getTexture2D();
7126 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007127 }
7128 break;
7129 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00007130 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007131 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00007132 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007133 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007134 break;
7135 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7136 {
7137 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7138 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7139 }
7140 break;
7141 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7142 {
7143 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7144 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7145 }
7146 break;
7147 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7148 {
7149 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7150 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7151 }
7152 break;
7153 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7154 {
7155 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7156 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7157 }
7158 break;
7159 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
7160 {
7161 gl::TextureCubeMap *texture = context->getTextureCubeMap();
7162 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
7163 }
7164 break;
7165 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007166 }
7167 }
7168 }
7169 catch(std::bad_alloc&)
7170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007171 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007172 }
7173}
7174
7175void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
7176{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007177 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
7178
7179 try
7180 {
7181 gl::Context *context = gl::getNonLostContext();
7182
7183 if (context)
7184 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007185 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
7186 {
7187 return;
7188 }
7189
Jamie Madillfb8a8302013-07-03 14:24:12 -04007190 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007191
Jamie Madillfb8a8302013-07-03 14:24:12 -04007192 if (!texture)
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007193 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007194 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007195 }
7196
7197 switch (pname)
7198 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007199 case GL_TEXTURE_WRAP_S: texture->setWrapS(gl::uiround<GLenum>(param)); break;
7200 case GL_TEXTURE_WRAP_T: texture->setWrapT(gl::uiround<GLenum>(param)); break;
7201 case GL_TEXTURE_WRAP_R: texture->setWrapR(gl::uiround<GLenum>(param)); break;
7202 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter(gl::uiround<GLenum>(param)); break;
7203 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter(gl::uiround<GLenum>(param)); break;
7204 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
7205 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy(static_cast<GLfloat>(param), context->getTextureMaxAnisotropy()); break;
7206 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode(gl::uiround<GLenum>(param)); break;
7207 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc(gl::uiround<GLenum>(param)); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007208
Jamie Madill478fdb22013-07-19 16:36:59 -04007209 case GL_TEXTURE_SWIZZLE_R:
7210 case GL_TEXTURE_SWIZZLE_G:
7211 case GL_TEXTURE_SWIZZLE_B:
7212 case GL_TEXTURE_SWIZZLE_A:
7213 case GL_TEXTURE_BASE_LEVEL:
7214 case GL_TEXTURE_MAX_LEVEL:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007215 case GL_TEXTURE_MIN_LOD:
7216 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007217 UNIMPLEMENTED();
7218 break;
7219
Jamie Madill478fdb22013-07-19 16:36:59 -04007220 default: UNREACHABLE(); break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007221 }
7222 }
7223 }
7224 catch(std::bad_alloc&)
7225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007226 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007227 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007228}
7229
7230void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7231{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007232 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007233}
7234
7235void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7236{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007237 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007238
7239 try
7240 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007241 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007242
7243 if (context)
7244 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007245 if (!validateTexParamParameters(context, pname, param))
7246 {
7247 return;
7248 }
7249
Jamie Madillfb8a8302013-07-03 14:24:12 -04007250 gl::Texture *texture = getTargetTexture(context, target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007251
Jamie Madillfb8a8302013-07-03 14:24:12 -04007252 if (!texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007253 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007254 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007255 }
7256
7257 switch (pname)
7258 {
Jamie Madill478fdb22013-07-19 16:36:59 -04007259 case GL_TEXTURE_WRAP_S: texture->setWrapS((GLenum)param); break;
7260 case GL_TEXTURE_WRAP_T: texture->setWrapT((GLenum)param); break;
7261 case GL_TEXTURE_WRAP_R: texture->setWrapR((GLenum)param); break;
7262 case GL_TEXTURE_MIN_FILTER: texture->setMinFilter((GLenum)param); break;
7263 case GL_TEXTURE_MAG_FILTER: texture->setMagFilter((GLenum)param); break;
7264 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
7265 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()); break;
7266 case GL_TEXTURE_COMPARE_MODE: texture->setCompareMode((GLenum)param); break;
7267 case GL_TEXTURE_COMPARE_FUNC: texture->setCompareFunc((GLenum)param); break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007268
7269 case GL_TEXTURE_SWIZZLE_R:
7270 case GL_TEXTURE_SWIZZLE_G:
7271 case GL_TEXTURE_SWIZZLE_B:
7272 case GL_TEXTURE_SWIZZLE_A:
7273 case GL_TEXTURE_BASE_LEVEL:
7274 case GL_TEXTURE_MAX_LEVEL:
Jamie Madill478fdb22013-07-19 16:36:59 -04007275 case GL_TEXTURE_MIN_LOD:
7276 case GL_TEXTURE_MAX_LOD:
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007277 UNIMPLEMENTED();
7278 break;
7279
Jamie Madill478fdb22013-07-19 16:36:59 -04007280 default: UNREACHABLE(); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007281 }
7282 }
7283 }
7284 catch(std::bad_alloc&)
7285 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007286 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007287 }
7288}
7289
7290void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7291{
7292 glTexParameteri(target, pname, *params);
7293}
7294
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007295void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7296{
7297 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7298 target, levels, internalformat, width, height);
7299
7300 try
7301 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007302 gl::Context *context = gl::getNonLostContext();
7303
7304 if (context)
7305 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007306 if (context->getClientVersion() < 3 &&
7307 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007308 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007309 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007310 }
7311
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007312 if (context->getClientVersion() >= 3 &&
7313 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007314 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007315 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007316 }
7317
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007318 switch (target)
7319 {
7320 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007321 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007322 gl::Texture2D *texture2d = context->getTexture2D();
7323 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007324 }
7325 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007326
7327 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7328 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7329 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7330 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7331 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7332 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007333 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007334 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7335 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007336 }
7337 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007338
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007339 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007340 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007341 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007342 }
7343 }
7344 catch(std::bad_alloc&)
7345 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007346 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007347 }
7348}
7349
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007350void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7351 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007352{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007353 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007354 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007355 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007356 target, level, xoffset, yoffset, width, height, format, type, pixels);
7357
7358 try
7359 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007360 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007361
7362 if (context)
7363 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007364 if (context->getClientVersion() < 3 &&
7365 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7366 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007367 {
7368 return;
7369 }
7370
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007371 if (context->getClientVersion() >= 3 &&
7372 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7373 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007374 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007375 return;
7376 }
7377
7378 switch (target)
7379 {
7380 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007381 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007382 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007383 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007384 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007385 break;
7386
7387 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7390 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7391 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007393 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007394 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007395 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007396 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007397 break;
7398
7399 default:
7400 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007401 }
7402 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007403 }
7404 catch(std::bad_alloc&)
7405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007406 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007407 }
7408}
7409
7410void __stdcall glUniform1f(GLint location, GLfloat x)
7411{
7412 glUniform1fv(location, 1, &x);
7413}
7414
7415void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7416{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007417 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007418
7419 try
7420 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007421 if (count < 0)
7422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007423 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007424 }
7425
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007426 if (location == -1)
7427 {
7428 return;
7429 }
7430
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007431 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007432
7433 if (context)
7434 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007435 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007436 if (!programBinary)
7437 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007438 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007439 }
7440
7441 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007442 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007443 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007444 }
7445 }
7446 }
7447 catch(std::bad_alloc&)
7448 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007449 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007450 }
7451}
7452
7453void __stdcall glUniform1i(GLint location, GLint x)
7454{
7455 glUniform1iv(location, 1, &x);
7456}
7457
7458void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007460 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007461
7462 try
7463 {
7464 if (count < 0)
7465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007466 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007467 }
7468
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007469 if (location == -1)
7470 {
7471 return;
7472 }
7473
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007475
7476 if (context)
7477 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007478 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007479 if (!programBinary)
7480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007481 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007482 }
7483
7484 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007486 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007487 }
7488 }
7489 }
7490 catch(std::bad_alloc&)
7491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007492 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007493 }
7494}
7495
7496void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7497{
7498 GLfloat xy[2] = {x, y};
7499
7500 glUniform2fv(location, 1, (GLfloat*)&xy);
7501}
7502
7503void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7504{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007505 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007506
7507 try
7508 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007509 if (count < 0)
7510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007511 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007512 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007513
7514 if (location == -1)
7515 {
7516 return;
7517 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007518
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007519 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007520
7521 if (context)
7522 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007523 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007524 if (!programBinary)
7525 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007526 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007527 }
7528
7529 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007530 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007531 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007532 }
7533 }
7534 }
7535 catch(std::bad_alloc&)
7536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007537 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007538 }
7539}
7540
7541void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7542{
7543 GLint xy[4] = {x, y};
7544
7545 glUniform2iv(location, 1, (GLint*)&xy);
7546}
7547
7548void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007550 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007551
7552 try
7553 {
7554 if (count < 0)
7555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007556 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007557 }
7558
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007559 if (location == -1)
7560 {
7561 return;
7562 }
7563
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007565
7566 if (context)
7567 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007568 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007569 if (!programBinary)
7570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007571 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007572 }
7573
7574 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007575 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007576 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007577 }
7578 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007579 }
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.com4f39fd92010-03-08 20:26:45 +00007583 }
7584}
7585
7586void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7587{
7588 GLfloat xyz[3] = {x, y, z};
7589
7590 glUniform3fv(location, 1, (GLfloat*)&xyz);
7591}
7592
7593void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7594{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007595 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007596
7597 try
7598 {
7599 if (count < 0)
7600 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007601 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007602 }
7603
7604 if (location == -1)
7605 {
7606 return;
7607 }
7608
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007609 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007610
7611 if (context)
7612 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007613 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007614 if (!programBinary)
7615 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007616 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007617 }
7618
7619 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007621 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007622 }
7623 }
7624 }
7625 catch(std::bad_alloc&)
7626 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007627 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007628 }
7629}
7630
7631void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7632{
7633 GLint xyz[3] = {x, y, z};
7634
7635 glUniform3iv(location, 1, (GLint*)&xyz);
7636}
7637
7638void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7639{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007640 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007641
7642 try
7643 {
7644 if (count < 0)
7645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007646 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007647 }
7648
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007649 if (location == -1)
7650 {
7651 return;
7652 }
7653
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007654 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007655
7656 if (context)
7657 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007658 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007659 if (!programBinary)
7660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007661 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007662 }
7663
7664 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007666 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007667 }
7668 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007669 }
7670 catch(std::bad_alloc&)
7671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007672 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007673 }
7674}
7675
7676void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7677{
7678 GLfloat xyzw[4] = {x, y, z, w};
7679
7680 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7681}
7682
7683void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007685 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007686
7687 try
7688 {
7689 if (count < 0)
7690 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007691 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007692 }
7693
7694 if (location == -1)
7695 {
7696 return;
7697 }
7698
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007699 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007700
7701 if (context)
7702 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007703 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007704 if (!programBinary)
7705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007706 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007707 }
7708
7709 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007710 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007711 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007712 }
7713 }
7714 }
7715 catch(std::bad_alloc&)
7716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007717 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007718 }
7719}
7720
7721void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7722{
7723 GLint xyzw[4] = {x, y, z, w};
7724
7725 glUniform4iv(location, 1, (GLint*)&xyzw);
7726}
7727
7728void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007730 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007731
7732 try
7733 {
7734 if (count < 0)
7735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007736 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007737 }
7738
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007739 if (location == -1)
7740 {
7741 return;
7742 }
7743
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007744 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007745
7746 if (context)
7747 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007748 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007749 if (!programBinary)
7750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007751 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007752 }
7753
7754 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007755 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007756 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007757 }
7758 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007759 }
7760 catch(std::bad_alloc&)
7761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007762 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007763 }
7764}
7765
7766void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7767{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007768 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007769 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007770
7771 try
7772 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007773 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007775 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007776 }
7777
7778 if (location == -1)
7779 {
7780 return;
7781 }
7782
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007783 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007784
7785 if (context)
7786 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007787 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7788 {
7789 return gl::error(GL_INVALID_VALUE);
7790 }
7791
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007792 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007793 if (!programBinary)
7794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007795 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007796 }
7797
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007798 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007800 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007801 }
7802 }
7803 }
7804 catch(std::bad_alloc&)
7805 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007806 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007807 }
7808}
7809
7810void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7811{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007812 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007813 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007814
7815 try
7816 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007817 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007818 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007819 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007820 }
7821
7822 if (location == -1)
7823 {
7824 return;
7825 }
7826
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007827 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007828
7829 if (context)
7830 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007831 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7832 {
7833 return gl::error(GL_INVALID_VALUE);
7834 }
7835
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007836 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007837 if (!programBinary)
7838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007839 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007840 }
7841
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007842 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007843 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007844 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007845 }
7846 }
7847 }
7848 catch(std::bad_alloc&)
7849 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007850 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007851 }
7852}
7853
7854void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7855{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007856 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007857 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007858
7859 try
7860 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007861 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007863 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007864 }
7865
7866 if (location == -1)
7867 {
7868 return;
7869 }
7870
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007871 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007872
7873 if (context)
7874 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007875 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7876 {
7877 return gl::error(GL_INVALID_VALUE);
7878 }
7879
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007880 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007881 if (!programBinary)
7882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007883 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007884 }
7885
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007886 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007887 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007888 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007889 }
7890 }
7891 }
7892 catch(std::bad_alloc&)
7893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007894 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007895 }
7896}
7897
7898void __stdcall glUseProgram(GLuint program)
7899{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007900 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007901
7902 try
7903 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007905
7906 if (context)
7907 {
7908 gl::Program *programObject = context->getProgram(program);
7909
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007910 if (!programObject && program != 0)
7911 {
7912 if (context->getShader(program))
7913 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007914 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007915 }
7916 else
7917 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007918 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007919 }
7920 }
7921
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007922 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007923 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007924 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007925 }
7926
7927 context->useProgram(program);
7928 }
7929 }
7930 catch(std::bad_alloc&)
7931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007932 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007933 }
7934}
7935
7936void __stdcall glValidateProgram(GLuint program)
7937{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007938 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007939
7940 try
7941 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007942 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007943
7944 if (context)
7945 {
7946 gl::Program *programObject = context->getProgram(program);
7947
7948 if (!programObject)
7949 {
7950 if (context->getShader(program))
7951 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007952 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007953 }
7954 else
7955 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007956 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007957 }
7958 }
7959
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007960 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007961 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007962 }
7963 catch(std::bad_alloc&)
7964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007965 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007966 }
7967}
7968
7969void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7970{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007971 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007972
7973 try
7974 {
7975 if (index >= gl::MAX_VERTEX_ATTRIBS)
7976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007977 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007978 }
7979
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007980 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007981
7982 if (context)
7983 {
7984 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007985 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007986 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007987 }
7988 catch(std::bad_alloc&)
7989 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007990 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007991 }
7992}
7993
7994void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7995{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007996 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007997
7998 try
7999 {
8000 if (index >= gl::MAX_VERTEX_ATTRIBS)
8001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008002 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008003 }
8004
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008005 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008006
8007 if (context)
8008 {
8009 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008010 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008011 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008012 }
8013 catch(std::bad_alloc&)
8014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008015 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008016 }
8017}
8018
8019void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
8020{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008021 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008022
8023 try
8024 {
8025 if (index >= gl::MAX_VERTEX_ATTRIBS)
8026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008027 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008028 }
8029
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008030 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008031
8032 if (context)
8033 {
8034 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008035 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008036 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008037 }
8038 catch(std::bad_alloc&)
8039 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008040 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008041 }
8042}
8043
8044void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
8045{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008046 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008047
8048 try
8049 {
8050 if (index >= gl::MAX_VERTEX_ATTRIBS)
8051 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008052 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008053 }
8054
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008055 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008056
8057 if (context)
8058 {
8059 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008060 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008061 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008062 }
8063 catch(std::bad_alloc&)
8064 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008065 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008066 }
8067}
8068
8069void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
8070{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008071 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 +00008072
8073 try
8074 {
8075 if (index >= gl::MAX_VERTEX_ATTRIBS)
8076 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008077 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008078 }
8079
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008080 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008081
8082 if (context)
8083 {
8084 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008085 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008086 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008087 }
8088 catch(std::bad_alloc&)
8089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008090 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008091 }
8092}
8093
8094void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8095{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008096 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008097
8098 try
8099 {
8100 if (index >= gl::MAX_VERTEX_ATTRIBS)
8101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008102 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008103 }
8104
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008106
8107 if (context)
8108 {
8109 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008110 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008111 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008112 }
8113 catch(std::bad_alloc&)
8114 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008115 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008116 }
8117}
8118
8119void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8120{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008121 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 +00008122
8123 try
8124 {
8125 if (index >= gl::MAX_VERTEX_ATTRIBS)
8126 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008127 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008128 }
8129
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008130 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008131
8132 if (context)
8133 {
8134 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008135 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008136 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008137 }
8138 catch(std::bad_alloc&)
8139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008140 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008141 }
8142}
8143
8144void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8145{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008146 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008147
8148 try
8149 {
8150 if (index >= gl::MAX_VERTEX_ATTRIBS)
8151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008152 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008153 }
8154
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008155 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008156
8157 if (context)
8158 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008159 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008160 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008161 }
8162 catch(std::bad_alloc&)
8163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008164 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008165 }
8166}
8167
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008168void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8169{
8170 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8171
8172 try
8173 {
8174 if (index >= gl::MAX_VERTEX_ATTRIBS)
8175 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008176 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008177 }
8178
8179 gl::Context *context = gl::getNonLostContext();
8180
8181 if (context)
8182 {
8183 context->setVertexAttribDivisor(index, divisor);
8184 }
8185 }
8186 catch(std::bad_alloc&)
8187 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008188 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008189 }
8190}
8191
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008192void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008193{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008194 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008195 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008196 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008197
8198 try
8199 {
8200 if (index >= gl::MAX_VERTEX_ATTRIBS)
8201 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008202 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008203 }
8204
8205 if (size < 1 || size > 4)
8206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008207 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008208 }
8209
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008210 gl::Context *context = gl::getNonLostContext();
8211
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008212 switch (type)
8213 {
8214 case GL_BYTE:
8215 case GL_UNSIGNED_BYTE:
8216 case GL_SHORT:
8217 case GL_UNSIGNED_SHORT:
8218 case GL_FIXED:
8219 case GL_FLOAT:
8220 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008221 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008222 case GL_INT:
8223 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008224 case GL_INT_2_10_10_10_REV:
8225 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008226 if (context && context->getClientVersion() < 3)
8227 {
8228 return gl::error(GL_INVALID_ENUM);
8229 }
8230 else
8231 {
8232 break;
8233 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008234 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008235 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008236 }
8237
8238 if (stride < 0)
8239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008240 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008241 }
8242
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008243 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8244 {
8245 return gl::error(GL_INVALID_OPERATION);
8246 }
8247
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008248 if (context)
8249 {
Jamie Madilld8db8662013-07-02 11:57:04 -04008250 // [OpenGL ES 3.0.2] Section 2.8 page 24:
8251 // An INVALID_OPERATION error is generated when a non-zero vertex array object
8252 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
8253 // and the pointer argument is not NULL.
8254 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
8255 {
8256 return gl::error(GL_INVALID_OPERATION);
8257 }
8258
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008259 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8260 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008261 }
8262 }
8263 catch(std::bad_alloc&)
8264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008265 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008266 }
8267}
8268
8269void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8270{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008271 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 +00008272
8273 try
8274 {
8275 if (width < 0 || height < 0)
8276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008278 }
8279
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008280 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008281
8282 if (context)
8283 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008284 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008285 }
8286 }
8287 catch(std::bad_alloc&)
8288 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008289 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008290 }
8291}
8292
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008293// OpenGL ES 3.0 functions
8294
8295void __stdcall glReadBuffer(GLenum mode)
8296{
8297 EVENT("(GLenum mode = 0x%X)", mode);
8298
8299 try
8300 {
8301 gl::Context *context = gl::getNonLostContext();
8302
8303 if (context)
8304 {
8305 if (context->getClientVersion() < 3)
8306 {
8307 return gl::error(GL_INVALID_OPERATION);
8308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008309
Jamie Madill54133512013-06-21 09:33:07 -04008310 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008311 UNIMPLEMENTED();
8312 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008313 }
8314 catch(std::bad_alloc&)
8315 {
8316 return gl::error(GL_OUT_OF_MEMORY);
8317 }
8318}
8319
8320void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8321{
8322 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8323 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8324
8325 try
8326 {
8327 gl::Context *context = gl::getNonLostContext();
8328
8329 if (context)
8330 {
8331 if (context->getClientVersion() < 3)
8332 {
8333 return gl::error(GL_INVALID_OPERATION);
8334 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008335
Jamie Madill54133512013-06-21 09:33:07 -04008336 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008337 UNIMPLEMENTED();
8338 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008339 }
8340 catch(std::bad_alloc&)
8341 {
8342 return gl::error(GL_OUT_OF_MEMORY);
8343 }
8344}
8345
8346void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8347{
8348 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8349 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8350 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8351 target, level, internalformat, width, height, depth, border, format, type, pixels);
8352
8353 try
8354 {
8355 gl::Context *context = gl::getNonLostContext();
8356
8357 if (context)
8358 {
8359 if (context->getClientVersion() < 3)
8360 {
8361 return gl::error(GL_INVALID_OPERATION);
8362 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008363
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008364 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008365 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008366 0, 0, 0, width, height, depth, border, format, type))
8367 {
8368 return;
8369 }
8370
8371 switch(target)
8372 {
8373 case GL_TEXTURE_3D:
8374 {
8375 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008376 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008377 }
8378 break;
8379
8380 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008381 {
8382 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008383 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008384 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008385 break;
8386
8387 default:
8388 return gl::error(GL_INVALID_ENUM);
8389 }
8390 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008391 }
8392 catch(std::bad_alloc&)
8393 {
8394 return gl::error(GL_OUT_OF_MEMORY);
8395 }
8396}
8397
8398void __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)
8399{
8400 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8401 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8402 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8403 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8404
8405 try
8406 {
8407 gl::Context *context = gl::getNonLostContext();
8408
8409 if (context)
8410 {
8411 if (context->getClientVersion() < 3)
8412 {
8413 return gl::error(GL_INVALID_OPERATION);
8414 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008415
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008416 if (!pixels)
8417 {
8418 return gl::error(GL_INVALID_VALUE);
8419 }
8420
8421 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008422 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008423 xoffset, yoffset, zoffset, width, height, depth, 0,
8424 format, type))
8425 {
8426 return;
8427 }
8428
8429 switch(target)
8430 {
8431 case GL_TEXTURE_3D:
8432 {
8433 gl::Texture3D *texture = context->getTexture3D();
8434 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8435 }
8436 break;
8437
8438 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008439 {
8440 gl::Texture2DArray *texture = context->getTexture2DArray();
8441 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8442 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008443 break;
8444
8445 default:
8446 return gl::error(GL_INVALID_ENUM);
8447 }
8448 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008449 }
8450 catch(std::bad_alloc&)
8451 {
8452 return gl::error(GL_OUT_OF_MEMORY);
8453 }
8454}
8455
8456void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8457{
8458 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8459 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8460 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8461
8462 try
8463 {
8464 gl::Context *context = gl::getNonLostContext();
8465
8466 if (context)
8467 {
8468 if (context->getClientVersion() < 3)
8469 {
8470 return gl::error(GL_INVALID_OPERATION);
8471 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008472
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008473 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8474 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008475 {
8476 return;
8477 }
8478
8479 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8480 gl::Texture *texture = NULL;
8481 switch (target)
8482 {
8483 case GL_TEXTURE_3D:
8484 texture = context->getTexture3D();
8485 break;
8486
8487 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008488 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008489 break;
8490
8491 default:
8492 return gl::error(GL_INVALID_ENUM);
8493 }
8494
8495 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8496 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008497 }
8498 catch(std::bad_alloc&)
8499 {
8500 return gl::error(GL_OUT_OF_MEMORY);
8501 }
8502}
8503
8504void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8505{
8506 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8507 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8508 "const GLvoid* data = 0x%0.8p)",
8509 target, level, internalformat, width, height, depth, border, imageSize, data);
8510
8511 try
8512 {
8513 gl::Context *context = gl::getNonLostContext();
8514
8515 if (context)
8516 {
8517 if (context->getClientVersion() < 3)
8518 {
8519 return gl::error(GL_INVALID_OPERATION);
8520 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008521
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008522 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 +00008523 {
8524 return gl::error(GL_INVALID_VALUE);
8525 }
8526
8527 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008528 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8529 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008530 {
8531 return;
8532 }
8533
8534 switch(target)
8535 {
8536 case GL_TEXTURE_3D:
8537 {
8538 gl::Texture3D *texture = context->getTexture3D();
8539 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8540 }
8541 break;
8542
8543 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008544 {
8545 gl::Texture2DArray *texture = context->getTexture2DArray();
8546 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8547 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008548 break;
8549
8550 default:
8551 return gl::error(GL_INVALID_ENUM);
8552 }
8553 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008554 }
8555 catch(std::bad_alloc&)
8556 {
8557 return gl::error(GL_OUT_OF_MEMORY);
8558 }
8559}
8560
8561void __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)
8562{
8563 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8564 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8565 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8566 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8567
8568 try
8569 {
8570 gl::Context *context = gl::getNonLostContext();
8571
8572 if (context)
8573 {
8574 if (context->getClientVersion() < 3)
8575 {
8576 return gl::error(GL_INVALID_OPERATION);
8577 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008578
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008579 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 +00008580 {
8581 return gl::error(GL_INVALID_VALUE);
8582 }
8583
8584 if (!data)
8585 {
8586 return gl::error(GL_INVALID_VALUE);
8587 }
8588
8589 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008590 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8591 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008592 {
8593 return;
8594 }
8595
8596 switch(target)
8597 {
8598 case GL_TEXTURE_3D:
8599 {
8600 gl::Texture3D *texture = context->getTexture3D();
8601 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8602 format, imageSize, data);
8603 }
8604 break;
8605
8606 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008607 {
8608 gl::Texture2DArray *texture = context->getTexture2DArray();
8609 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8610 format, imageSize, data);
8611 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008612 break;
8613
8614 default:
8615 return gl::error(GL_INVALID_ENUM);
8616 }
8617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008618 }
8619 catch(std::bad_alloc&)
8620 {
8621 return gl::error(GL_OUT_OF_MEMORY);
8622 }
8623}
8624
8625void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8626{
8627 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8628
8629 try
8630 {
8631 gl::Context *context = gl::getNonLostContext();
8632
8633 if (context)
8634 {
8635 if (context->getClientVersion() < 3)
8636 {
8637 return gl::error(GL_INVALID_OPERATION);
8638 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008639
Jamie Madill3641b4b2013-07-26 12:54:59 -04008640 glGenQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008641 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008642 }
8643 catch(std::bad_alloc&)
8644 {
8645 return gl::error(GL_OUT_OF_MEMORY);
8646 }
8647}
8648
8649void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8650{
8651 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8652
8653 try
8654 {
8655 gl::Context *context = gl::getNonLostContext();
8656
8657 if (context)
8658 {
8659 if (context->getClientVersion() < 3)
8660 {
8661 return gl::error(GL_INVALID_OPERATION);
8662 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008663
Jamie Madill3641b4b2013-07-26 12:54:59 -04008664 glDeleteQueriesEXT(n, ids);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008665 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008666 }
8667 catch(std::bad_alloc&)
8668 {
8669 return gl::error(GL_OUT_OF_MEMORY);
8670 }
8671}
8672
8673GLboolean __stdcall glIsQuery(GLuint id)
8674{
8675 EVENT("(GLuint id = %u)", id);
8676
8677 try
8678 {
8679 gl::Context *context = gl::getNonLostContext();
8680
8681 if (context)
8682 {
8683 if (context->getClientVersion() < 3)
8684 {
8685 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8686 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008687
Jamie Madill3641b4b2013-07-26 12:54:59 -04008688 // TODO: XFB queries
8689 return glIsQueryEXT(id);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008690 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008691 }
8692 catch(std::bad_alloc&)
8693 {
8694 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8695 }
8696
8697 return GL_FALSE;
8698}
8699
8700void __stdcall glBeginQuery(GLenum target, GLuint id)
8701{
8702 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8703
8704 try
8705 {
8706 gl::Context *context = gl::getNonLostContext();
8707
8708 if (context)
8709 {
8710 if (context->getClientVersion() < 3)
8711 {
8712 return gl::error(GL_INVALID_OPERATION);
8713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008714
Jamie Madill3641b4b2013-07-26 12:54:59 -04008715 switch (target)
8716 {
8717 case GL_ANY_SAMPLES_PASSED:
8718 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
8719 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
8720 break;
8721 default:
8722 return gl::error(GL_INVALID_ENUM);
8723 }
8724
8725 if (id == 0)
8726 {
8727 return gl::error(GL_INVALID_OPERATION);
8728 }
8729
8730 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8731 {
8732 // TODO: XFB queries
8733 UNIMPLEMENTED();
8734 }
8735 else
8736 {
8737 context->beginQuery(target, id);
8738 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008739 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008740 }
8741 catch(std::bad_alloc&)
8742 {
8743 return gl::error(GL_OUT_OF_MEMORY);
8744 }
8745}
8746
8747void __stdcall glEndQuery(GLenum target)
8748{
8749 EVENT("(GLenum target = 0x%X)", target);
8750
8751 try
8752 {
8753 gl::Context *context = gl::getNonLostContext();
8754
8755 if (context)
8756 {
8757 if (context->getClientVersion() < 3)
8758 {
8759 return gl::error(GL_INVALID_OPERATION);
8760 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008761
Jamie Madill3641b4b2013-07-26 12:54:59 -04008762 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8763 {
8764 // TODO: XFB queries
8765 UNIMPLEMENTED();
8766 }
8767 else
8768 {
8769 glEndQueryEXT(target);
8770 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008771 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008772 }
8773 catch(std::bad_alloc&)
8774 {
8775 return gl::error(GL_OUT_OF_MEMORY);
8776 }
8777}
8778
8779void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8780{
8781 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8782
8783 try
8784 {
8785 gl::Context *context = gl::getNonLostContext();
8786
8787 if (context)
8788 {
8789 if (context->getClientVersion() < 3)
8790 {
8791 return gl::error(GL_INVALID_OPERATION);
8792 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008793
Jamie Madill3641b4b2013-07-26 12:54:59 -04008794 if (target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
8795 {
8796 // TODO: XFB queries
8797 UNIMPLEMENTED();
8798 }
8799 else
8800 {
8801 glGetQueryivEXT(target, pname, params);
8802 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008803 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008804 }
8805 catch(std::bad_alloc&)
8806 {
8807 return gl::error(GL_OUT_OF_MEMORY);
8808 }
8809}
8810
8811void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8812{
8813 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8814
8815 try
8816 {
8817 gl::Context *context = gl::getNonLostContext();
8818
8819 if (context)
8820 {
8821 if (context->getClientVersion() < 3)
8822 {
8823 return gl::error(GL_INVALID_OPERATION);
8824 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008825
Jamie Madill3641b4b2013-07-26 12:54:59 -04008826 // TODO: XFB queries
8827 glGetQueryObjectuivEXT(id, pname, params);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008828 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008829 }
8830 catch(std::bad_alloc&)
8831 {
8832 return gl::error(GL_OUT_OF_MEMORY);
8833 }
8834}
8835
8836GLboolean __stdcall glUnmapBuffer(GLenum target)
8837{
8838 EVENT("(GLenum target = 0x%X)", target);
8839
8840 try
8841 {
8842 gl::Context *context = gl::getNonLostContext();
8843
8844 if (context)
8845 {
8846 if (context->getClientVersion() < 3)
8847 {
8848 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8849 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008850
Jamie Madill54133512013-06-21 09:33:07 -04008851 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008852 UNIMPLEMENTED();
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, GL_FALSE);
8858 }
8859
8860 return GL_FALSE;
8861}
8862
8863void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8864{
8865 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8866
8867 try
8868 {
8869 gl::Context *context = gl::getNonLostContext();
8870
8871 if (context)
8872 {
8873 if (context->getClientVersion() < 3)
8874 {
8875 return gl::error(GL_INVALID_OPERATION);
8876 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008877
Jamie Madill54133512013-06-21 09:33:07 -04008878 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008879 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008880 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008881 }
8882 catch(std::bad_alloc&)
8883 {
8884 return gl::error(GL_OUT_OF_MEMORY);
8885 }
8886}
8887
8888void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8889{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008890 try
8891 {
8892 gl::Context *context = gl::getNonLostContext();
8893
8894 if (context)
8895 {
8896 if (context->getClientVersion() < 3)
8897 {
8898 return gl::error(GL_INVALID_OPERATION);
8899 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008900
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008901 glDrawBuffersEXT(n, bufs);
8902 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008903 }
8904 catch(std::bad_alloc&)
8905 {
8906 return gl::error(GL_OUT_OF_MEMORY);
8907 }
8908}
8909
8910void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8911{
8912 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8913 location, count, transpose, value);
8914
8915 try
8916 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008917 if (count < 0)
8918 {
8919 return gl::error(GL_INVALID_VALUE);
8920 }
8921
8922 if (location == -1)
8923 {
8924 return;
8925 }
8926
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008927 gl::Context *context = gl::getNonLostContext();
8928
8929 if (context)
8930 {
8931 if (context->getClientVersion() < 3)
8932 {
8933 return gl::error(GL_INVALID_OPERATION);
8934 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008935
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008936 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8937 if (!programBinary)
8938 {
8939 return gl::error(GL_INVALID_OPERATION);
8940 }
8941
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008942 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008943 {
8944 return gl::error(GL_INVALID_OPERATION);
8945 }
8946 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008947 }
8948 catch(std::bad_alloc&)
8949 {
8950 return gl::error(GL_OUT_OF_MEMORY);
8951 }
8952}
8953
8954void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8955{
8956 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8957 location, count, transpose, value);
8958
8959 try
8960 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008961 if (count < 0)
8962 {
8963 return gl::error(GL_INVALID_VALUE);
8964 }
8965
8966 if (location == -1)
8967 {
8968 return;
8969 }
8970
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008971 gl::Context *context = gl::getNonLostContext();
8972
8973 if (context)
8974 {
8975 if (context->getClientVersion() < 3)
8976 {
8977 return gl::error(GL_INVALID_OPERATION);
8978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008979
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008980 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8981 if (!programBinary)
8982 {
8983 return gl::error(GL_INVALID_OPERATION);
8984 }
8985
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008986 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008987 {
8988 return gl::error(GL_INVALID_OPERATION);
8989 }
8990 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008991 }
8992 catch(std::bad_alloc&)
8993 {
8994 return gl::error(GL_OUT_OF_MEMORY);
8995 }
8996}
8997
8998void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8999{
9000 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9001 location, count, transpose, value);
9002
9003 try
9004 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009005 if (count < 0)
9006 {
9007 return gl::error(GL_INVALID_VALUE);
9008 }
9009
9010 if (location == -1)
9011 {
9012 return;
9013 }
9014
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009015 gl::Context *context = gl::getNonLostContext();
9016
9017 if (context)
9018 {
9019 if (context->getClientVersion() < 3)
9020 {
9021 return gl::error(GL_INVALID_OPERATION);
9022 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009023
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009024 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9025 if (!programBinary)
9026 {
9027 return gl::error(GL_INVALID_OPERATION);
9028 }
9029
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009030 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009031 {
9032 return gl::error(GL_INVALID_OPERATION);
9033 }
9034 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009035 }
9036 catch(std::bad_alloc&)
9037 {
9038 return gl::error(GL_OUT_OF_MEMORY);
9039 }
9040}
9041
9042void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9043{
9044 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9045 location, count, transpose, value);
9046
9047 try
9048 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009049 if (count < 0)
9050 {
9051 return gl::error(GL_INVALID_VALUE);
9052 }
9053
9054 if (location == -1)
9055 {
9056 return;
9057 }
9058
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009059 gl::Context *context = gl::getNonLostContext();
9060
9061 if (context)
9062 {
9063 if (context->getClientVersion() < 3)
9064 {
9065 return gl::error(GL_INVALID_OPERATION);
9066 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009067
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009068 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9069 if (!programBinary)
9070 {
9071 return gl::error(GL_INVALID_OPERATION);
9072 }
9073
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009074 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009075 {
9076 return gl::error(GL_INVALID_OPERATION);
9077 }
9078 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009079 }
9080 catch(std::bad_alloc&)
9081 {
9082 return gl::error(GL_OUT_OF_MEMORY);
9083 }
9084}
9085
9086void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9087{
9088 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9089 location, count, transpose, value);
9090
9091 try
9092 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009093 if (count < 0)
9094 {
9095 return gl::error(GL_INVALID_VALUE);
9096 }
9097
9098 if (location == -1)
9099 {
9100 return;
9101 }
9102
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009103 gl::Context *context = gl::getNonLostContext();
9104
9105 if (context)
9106 {
9107 if (context->getClientVersion() < 3)
9108 {
9109 return gl::error(GL_INVALID_OPERATION);
9110 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009111
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009112 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9113 if (!programBinary)
9114 {
9115 return gl::error(GL_INVALID_OPERATION);
9116 }
9117
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009118 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009119 {
9120 return gl::error(GL_INVALID_OPERATION);
9121 }
9122 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009123 }
9124 catch(std::bad_alloc&)
9125 {
9126 return gl::error(GL_OUT_OF_MEMORY);
9127 }
9128}
9129
9130void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
9131{
9132 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9133 location, count, transpose, value);
9134
9135 try
9136 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009137 if (count < 0)
9138 {
9139 return gl::error(GL_INVALID_VALUE);
9140 }
9141
9142 if (location == -1)
9143 {
9144 return;
9145 }
9146
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009147 gl::Context *context = gl::getNonLostContext();
9148
9149 if (context)
9150 {
9151 if (context->getClientVersion() < 3)
9152 {
9153 return gl::error(GL_INVALID_OPERATION);
9154 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009155
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009156 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9157 if (!programBinary)
9158 {
9159 return gl::error(GL_INVALID_OPERATION);
9160 }
9161
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009162 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009163 {
9164 return gl::error(GL_INVALID_OPERATION);
9165 }
9166 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009167 }
9168 catch(std::bad_alloc&)
9169 {
9170 return gl::error(GL_OUT_OF_MEMORY);
9171 }
9172}
9173
9174void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9175{
9176 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9177 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9178 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9179
9180 try
9181 {
9182 gl::Context *context = gl::getNonLostContext();
9183
9184 if (context)
9185 {
9186 if (context->getClientVersion() < 3)
9187 {
9188 return gl::error(GL_INVALID_OPERATION);
9189 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009190
Geoff Lang758d5b22013-06-11 11:42:50 -04009191 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9192 dstX0, dstY0, dstX1, dstY1, mask, filter,
9193 false))
9194 {
9195 return;
9196 }
9197
9198 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9199 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009200 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009201 }
9202 catch(std::bad_alloc&)
9203 {
9204 return gl::error(GL_OUT_OF_MEMORY);
9205 }
9206}
9207
9208void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9209{
9210 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9211 target, samples, internalformat, width, height);
9212
9213 try
9214 {
9215 gl::Context *context = gl::getNonLostContext();
9216
9217 if (context)
9218 {
9219 if (context->getClientVersion() < 3)
9220 {
9221 return gl::error(GL_INVALID_OPERATION);
9222 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009223
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009224 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9225 width, height, false))
9226 {
9227 return;
9228 }
9229
9230 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009231 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009232 }
9233 catch(std::bad_alloc&)
9234 {
9235 return gl::error(GL_OUT_OF_MEMORY);
9236 }
9237}
9238
9239void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9240{
9241 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9242 target, attachment, texture, level, layer);
9243
9244 try
9245 {
9246 gl::Context *context = gl::getNonLostContext();
9247
9248 if (context)
9249 {
9250 if (context->getClientVersion() < 3)
9251 {
9252 return gl::error(GL_INVALID_OPERATION);
9253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009254
Jamie Madill54133512013-06-21 09:33:07 -04009255 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009256 UNIMPLEMENTED();
9257 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009258 }
9259 catch(std::bad_alloc&)
9260 {
9261 return gl::error(GL_OUT_OF_MEMORY);
9262 }
9263}
9264
9265GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9266{
9267 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9268 target, offset, length, access);
9269
9270 try
9271 {
9272 gl::Context *context = gl::getNonLostContext();
9273
9274 if (context)
9275 {
9276 if (context->getClientVersion() < 3)
9277 {
9278 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9279 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009280
Jamie Madill54133512013-06-21 09:33:07 -04009281 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009282 UNIMPLEMENTED();
9283 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009284 }
9285 catch(std::bad_alloc&)
9286 {
9287 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9288 }
9289
9290 return NULL;
9291}
9292
9293void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9294{
9295 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9296
9297 try
9298 {
9299 gl::Context *context = gl::getNonLostContext();
9300
9301 if (context)
9302 {
9303 if (context->getClientVersion() < 3)
9304 {
9305 return gl::error(GL_INVALID_OPERATION);
9306 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009307
Jamie Madill54133512013-06-21 09:33:07 -04009308 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009309 UNIMPLEMENTED();
9310 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009311 }
9312 catch(std::bad_alloc&)
9313 {
9314 return gl::error(GL_OUT_OF_MEMORY);
9315 }
9316}
9317
9318void __stdcall glBindVertexArray(GLuint array)
9319{
9320 EVENT("(GLuint array = %u)", array);
9321
9322 try
9323 {
9324 gl::Context *context = gl::getNonLostContext();
9325
9326 if (context)
9327 {
9328 if (context->getClientVersion() < 3)
9329 {
9330 return gl::error(GL_INVALID_OPERATION);
9331 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009332
Jamie Madilld1028542013-07-02 11:57:04 -04009333 gl::VertexArray *vao = context->getVertexArray(array);
9334
9335 if (!vao)
9336 {
9337 // The default VAO should always exist
9338 ASSERT(array != 0);
9339 return gl::error(GL_INVALID_OPERATION);
9340 }
9341
9342 context->bindVertexArray(array);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009343 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009344 }
9345 catch(std::bad_alloc&)
9346 {
9347 return gl::error(GL_OUT_OF_MEMORY);
9348 }
9349}
9350
9351void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9352{
9353 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9354
9355 try
9356 {
9357 gl::Context *context = gl::getNonLostContext();
9358
9359 if (context)
9360 {
9361 if (context->getClientVersion() < 3)
9362 {
9363 return gl::error(GL_INVALID_OPERATION);
9364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009365
Jamie Madilld1028542013-07-02 11:57:04 -04009366 if (n < 0)
9367 {
9368 return gl::error(GL_INVALID_VALUE);
9369 }
9370
9371 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9372 {
9373 if (arrays[arrayIndex] != 0)
9374 {
9375 context->deleteVertexArray(arrays[arrayIndex]);
9376 }
9377 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009378 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009379 }
9380 catch(std::bad_alloc&)
9381 {
9382 return gl::error(GL_OUT_OF_MEMORY);
9383 }
9384}
9385
9386void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9387{
9388 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9389
9390 try
9391 {
9392 gl::Context *context = gl::getNonLostContext();
9393
9394 if (context)
9395 {
9396 if (context->getClientVersion() < 3)
9397 {
9398 return gl::error(GL_INVALID_OPERATION);
9399 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009400
Jamie Madilld1028542013-07-02 11:57:04 -04009401 if (n < 0)
9402 {
9403 return gl::error(GL_INVALID_VALUE);
9404 }
9405
9406 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
9407 {
9408 arrays[arrayIndex] = context->createVertexArray();
9409 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009410 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009411 }
9412 catch(std::bad_alloc&)
9413 {
9414 return gl::error(GL_OUT_OF_MEMORY);
9415 }
9416}
9417
9418GLboolean __stdcall glIsVertexArray(GLuint array)
9419{
9420 EVENT("(GLuint array = %u)", array);
9421
9422 try
9423 {
9424 gl::Context *context = gl::getNonLostContext();
9425
9426 if (context)
9427 {
9428 if (context->getClientVersion() < 3)
9429 {
9430 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9431 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009432
Jamie Madilld1028542013-07-02 11:57:04 -04009433 if (array == 0)
9434 {
9435 return GL_FALSE;
9436 }
9437
9438 gl::VertexArray *vao = context->getVertexArray(array);
9439
9440 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009441 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009442 }
9443 catch(std::bad_alloc&)
9444 {
9445 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9446 }
9447
9448 return GL_FALSE;
9449}
9450
9451void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9452{
9453 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9454 target, index, data);
9455
9456 try
9457 {
9458 gl::Context *context = gl::getNonLostContext();
9459
9460 if (context)
9461 {
9462 if (context->getClientVersion() < 3)
9463 {
9464 return gl::error(GL_INVALID_OPERATION);
9465 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009466
Jamie Madill54133512013-06-21 09:33:07 -04009467 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009468 UNIMPLEMENTED();
9469 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009470 }
9471 catch(std::bad_alloc&)
9472 {
9473 return gl::error(GL_OUT_OF_MEMORY);
9474 }
9475}
9476
9477void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9478{
9479 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9480
9481 try
9482 {
9483 gl::Context *context = gl::getNonLostContext();
9484
9485 if (context)
9486 {
9487 if (context->getClientVersion() < 3)
9488 {
9489 return gl::error(GL_INVALID_OPERATION);
9490 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009491
Jamie Madill54133512013-06-21 09:33:07 -04009492 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009493 UNIMPLEMENTED();
9494 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009495 }
9496 catch(std::bad_alloc&)
9497 {
9498 return gl::error(GL_OUT_OF_MEMORY);
9499 }
9500}
9501
9502void __stdcall glEndTransformFeedback(void)
9503{
9504 EVENT("(void)");
9505
9506 try
9507 {
9508 gl::Context *context = gl::getNonLostContext();
9509
9510 if (context)
9511 {
9512 if (context->getClientVersion() < 3)
9513 {
9514 return gl::error(GL_INVALID_OPERATION);
9515 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009516
Jamie Madill54133512013-06-21 09:33:07 -04009517 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009518 UNIMPLEMENTED();
9519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009520 }
9521 catch(std::bad_alloc&)
9522 {
9523 return gl::error(GL_OUT_OF_MEMORY);
9524 }
9525}
9526
9527void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9528{
9529 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9530 target, index, buffer, offset, size);
9531
9532 try
9533 {
9534 gl::Context *context = gl::getNonLostContext();
9535
9536 if (context)
9537 {
9538 if (context->getClientVersion() < 3)
9539 {
9540 return gl::error(GL_INVALID_OPERATION);
9541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009542
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009543 switch (target)
9544 {
9545 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009546 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009547 {
9548 return gl::error(GL_INVALID_VALUE);
9549 }
9550 break;
9551
9552 case GL_UNIFORM_BUFFER:
9553 if (index >= context->getMaximumCombinedUniformBufferBindings())
9554 {
9555 return gl::error(GL_INVALID_VALUE);
9556 }
9557 break;
9558
9559 default:
9560 return gl::error(GL_INVALID_ENUM);
9561 }
9562
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009563 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009564 {
9565 return gl::error(GL_INVALID_VALUE);
9566 }
9567
9568 switch (target)
9569 {
9570 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009571
9572 // size and offset must be a multiple of 4
9573 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9574 {
9575 return gl::error(GL_INVALID_VALUE);
9576 }
9577
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009578 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9579 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009580 break;
9581
9582 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009583
9584 // it is an error to bind an offset not a multiple of the alignment
9585 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9586 {
9587 return gl::error(GL_INVALID_VALUE);
9588 }
9589
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009590 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9591 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009592 break;
9593
9594 default:
9595 UNREACHABLE();
9596 }
9597 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009598 }
9599 catch(std::bad_alloc&)
9600 {
9601 return gl::error(GL_OUT_OF_MEMORY);
9602 }
9603}
9604
9605void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9606{
9607 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9608 target, index, buffer);
9609
9610 try
9611 {
9612 gl::Context *context = gl::getNonLostContext();
9613
9614 if (context)
9615 {
9616 if (context->getClientVersion() < 3)
9617 {
9618 return gl::error(GL_INVALID_OPERATION);
9619 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009620
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009621 switch (target)
9622 {
9623 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009624 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009625 {
9626 return gl::error(GL_INVALID_VALUE);
9627 }
9628 break;
9629
9630 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009631 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009632 {
9633 return gl::error(GL_INVALID_VALUE);
9634 }
9635 break;
9636
9637 default:
9638 return gl::error(GL_INVALID_ENUM);
9639 }
9640
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009641 switch (target)
9642 {
9643 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009644 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009645 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009646 break;
9647
9648 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009649 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009650 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009651 break;
9652
9653 default:
9654 UNREACHABLE();
9655 }
9656 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009657 }
9658 catch(std::bad_alloc&)
9659 {
9660 return gl::error(GL_OUT_OF_MEMORY);
9661 }
9662}
9663
9664void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9665{
9666 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9667 program, count, varyings, bufferMode);
9668
9669 try
9670 {
9671 gl::Context *context = gl::getNonLostContext();
9672
9673 if (context)
9674 {
9675 if (context->getClientVersion() < 3)
9676 {
9677 return gl::error(GL_INVALID_OPERATION);
9678 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009679
Jamie Madill54133512013-06-21 09:33:07 -04009680 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009681 UNIMPLEMENTED();
9682 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009683 }
9684 catch(std::bad_alloc&)
9685 {
9686 return gl::error(GL_OUT_OF_MEMORY);
9687 }
9688}
9689
9690void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9691{
9692 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9693 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9694 program, index, bufSize, length, size, type, name);
9695
9696 try
9697 {
9698 gl::Context *context = gl::getNonLostContext();
9699
9700 if (context)
9701 {
9702 if (context->getClientVersion() < 3)
9703 {
9704 return gl::error(GL_INVALID_OPERATION);
9705 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009706
Jamie Madill54133512013-06-21 09:33:07 -04009707 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009708 UNIMPLEMENTED();
9709 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009710 }
9711 catch(std::bad_alloc&)
9712 {
9713 return gl::error(GL_OUT_OF_MEMORY);
9714 }
9715}
9716
9717void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9718{
9719 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9720 index, size, type, stride, pointer);
9721
9722 try
9723 {
9724 gl::Context *context = gl::getNonLostContext();
9725
9726 if (context)
9727 {
9728 if (context->getClientVersion() < 3)
9729 {
9730 return gl::error(GL_INVALID_OPERATION);
9731 }
9732 }
9733
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009734 if (index >= gl::MAX_VERTEX_ATTRIBS)
9735 {
9736 return gl::error(GL_INVALID_VALUE);
9737 }
9738
9739 if (size < 1 || size > 4)
9740 {
9741 return gl::error(GL_INVALID_VALUE);
9742 }
9743
9744 switch (type)
9745 {
9746 case GL_BYTE:
9747 case GL_UNSIGNED_BYTE:
9748 case GL_SHORT:
9749 case GL_UNSIGNED_SHORT:
9750 case GL_INT:
9751 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009752 case GL_INT_2_10_10_10_REV:
9753 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009754 break;
9755 default:
9756 return gl::error(GL_INVALID_ENUM);
9757 }
9758
9759 if (stride < 0)
9760 {
9761 return gl::error(GL_INVALID_VALUE);
9762 }
9763
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009764 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9765 {
9766 return gl::error(GL_INVALID_OPERATION);
9767 }
9768
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009769 if (context)
9770 {
Jamie Madilld8db8662013-07-02 11:57:04 -04009771 // [OpenGL ES 3.0.2] Section 2.8 page 24:
9772 // An INVALID_OPERATION error is generated when a non-zero vertex array object
9773 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
9774 // and the pointer argument is not NULL.
9775 if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
9776 {
9777 return gl::error(GL_INVALID_OPERATION);
9778 }
9779
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009780 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9781 stride, pointer);
9782 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009783 }
9784 catch(std::bad_alloc&)
9785 {
9786 return gl::error(GL_OUT_OF_MEMORY);
9787 }
9788}
9789
9790void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9791{
9792 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9793 index, pname, params);
9794
9795 try
9796 {
9797 gl::Context *context = gl::getNonLostContext();
9798
9799 if (context)
9800 {
9801 if (context->getClientVersion() < 3)
9802 {
9803 return gl::error(GL_INVALID_OPERATION);
9804 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009805
Jamie Madilla7d05862013-07-02 11:57:06 -04009806 if (index >= gl::MAX_VERTEX_ATTRIBS)
9807 {
9808 return gl::error(GL_INVALID_VALUE);
9809 }
9810
9811 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9812
9813 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9814 {
9815 return;
9816 }
9817
9818 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9819 {
9820 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9821 for (int i = 0; i < 4; ++i)
9822 {
9823 params[i] = currentValueData.IntValues[i];
9824 }
9825 }
9826 else
9827 {
9828 *params = attribState.querySingleParameter<GLint>(pname);
9829 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009830 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009831 }
9832 catch(std::bad_alloc&)
9833 {
9834 return gl::error(GL_OUT_OF_MEMORY);
9835 }
9836}
9837
9838void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9839{
9840 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9841 index, pname, params);
9842
9843 try
9844 {
9845 gl::Context *context = gl::getNonLostContext();
9846
9847 if (context)
9848 {
9849 if (context->getClientVersion() < 3)
9850 {
9851 return gl::error(GL_INVALID_OPERATION);
9852 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009853
Jamie Madilla7d05862013-07-02 11:57:06 -04009854 if (index >= gl::MAX_VERTEX_ATTRIBS)
9855 {
9856 return gl::error(GL_INVALID_VALUE);
9857 }
9858
9859 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
9860
9861 if (!validateGetVertexAttribParameters(pname, context->getClientVersion()))
9862 {
9863 return;
9864 }
9865
9866 if (pname == GL_CURRENT_VERTEX_ATTRIB)
9867 {
9868 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
9869 for (int i = 0; i < 4; ++i)
9870 {
9871 params[i] = currentValueData.UnsignedIntValues[i];
9872 }
9873 }
9874 else
9875 {
9876 *params = attribState.querySingleParameter<GLuint>(pname);
9877 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009878 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009879 }
9880 catch(std::bad_alloc&)
9881 {
9882 return gl::error(GL_OUT_OF_MEMORY);
9883 }
9884}
9885
9886void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9887{
9888 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9889 index, x, y, z, w);
9890
9891 try
9892 {
9893 gl::Context *context = gl::getNonLostContext();
9894
9895 if (context)
9896 {
9897 if (context->getClientVersion() < 3)
9898 {
9899 return gl::error(GL_INVALID_OPERATION);
9900 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009901
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009902 if (index >= gl::MAX_VERTEX_ATTRIBS)
9903 {
9904 return gl::error(GL_INVALID_VALUE);
9905 }
9906
9907 GLint vals[4] = { x, y, z, w };
9908 context->setVertexAttribi(index, vals);
9909 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009910 }
9911 catch(std::bad_alloc&)
9912 {
9913 return gl::error(GL_OUT_OF_MEMORY);
9914 }
9915}
9916
9917void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9918{
9919 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9920 index, x, y, z, w);
9921
9922 try
9923 {
9924 gl::Context *context = gl::getNonLostContext();
9925
9926 if (context)
9927 {
9928 if (context->getClientVersion() < 3)
9929 {
9930 return gl::error(GL_INVALID_OPERATION);
9931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009932
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009933 if (index >= gl::MAX_VERTEX_ATTRIBS)
9934 {
9935 return gl::error(GL_INVALID_VALUE);
9936 }
9937
9938 GLuint vals[4] = { x, y, z, w };
9939 context->setVertexAttribu(index, vals);
9940 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009941 }
9942 catch(std::bad_alloc&)
9943 {
9944 return gl::error(GL_OUT_OF_MEMORY);
9945 }
9946}
9947
9948void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9949{
9950 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9951
9952 try
9953 {
9954 gl::Context *context = gl::getNonLostContext();
9955
9956 if (context)
9957 {
9958 if (context->getClientVersion() < 3)
9959 {
9960 return gl::error(GL_INVALID_OPERATION);
9961 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009962
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009963 if (index >= gl::MAX_VERTEX_ATTRIBS)
9964 {
9965 return gl::error(GL_INVALID_VALUE);
9966 }
9967
9968 context->setVertexAttribi(index, v);
9969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009970 }
9971 catch(std::bad_alloc&)
9972 {
9973 return gl::error(GL_OUT_OF_MEMORY);
9974 }
9975}
9976
9977void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9978{
9979 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9980
9981 try
9982 {
9983 gl::Context *context = gl::getNonLostContext();
9984
9985 if (context)
9986 {
9987 if (context->getClientVersion() < 3)
9988 {
9989 return gl::error(GL_INVALID_OPERATION);
9990 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009991
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009992 if (index >= gl::MAX_VERTEX_ATTRIBS)
9993 {
9994 return gl::error(GL_INVALID_VALUE);
9995 }
9996
9997 context->setVertexAttribu(index, v);
9998 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009999 }
10000 catch(std::bad_alloc&)
10001 {
10002 return gl::error(GL_OUT_OF_MEMORY);
10003 }
10004}
10005
10006void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
10007{
10008 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
10009 program, location, params);
10010
10011 try
10012 {
10013 gl::Context *context = gl::getNonLostContext();
10014
10015 if (context)
10016 {
10017 if (context->getClientVersion() < 3)
10018 {
10019 return gl::error(GL_INVALID_OPERATION);
10020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010021
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +000010022 if (program == 0)
10023 {
10024 return gl::error(GL_INVALID_VALUE);
10025 }
10026
10027 gl::Program *programObject = context->getProgram(program);
10028
10029 if (!programObject || !programObject->isLinked())
10030 {
10031 return gl::error(GL_INVALID_OPERATION);
10032 }
10033
10034 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10035 if (!programBinary)
10036 {
10037 return gl::error(GL_INVALID_OPERATION);
10038 }
10039
10040 if (!programBinary->getUniformuiv(location, NULL, params))
10041 {
10042 return gl::error(GL_INVALID_OPERATION);
10043 }
10044 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010045 }
10046 catch(std::bad_alloc&)
10047 {
10048 return gl::error(GL_OUT_OF_MEMORY);
10049 }
10050}
10051
10052GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
10053{
10054 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
10055 program, name);
10056
10057 try
10058 {
10059 gl::Context *context = gl::getNonLostContext();
10060
10061 if (context)
10062 {
10063 if (context->getClientVersion() < 3)
10064 {
Jamie Madilld1e78c92013-06-20 11:55:50 -040010065 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010066 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010067
Jamie Madilld1e78c92013-06-20 11:55:50 -040010068 if (program == 0)
10069 {
10070 return gl::error(GL_INVALID_VALUE, -1);
10071 }
10072
10073 gl::Program *programObject = context->getProgram(program);
10074
10075 if (!programObject || !programObject->isLinked())
10076 {
10077 return gl::error(GL_INVALID_OPERATION, -1);
10078 }
10079
10080 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10081 if (!programBinary)
10082 {
10083 return gl::error(GL_INVALID_OPERATION, -1);
10084 }
10085
10086 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010088 }
10089 catch(std::bad_alloc&)
10090 {
10091 return gl::error(GL_OUT_OF_MEMORY, 0);
10092 }
10093
10094 return 0;
10095}
10096
10097void __stdcall glUniform1ui(GLint location, GLuint v0)
10098{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010099 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010100}
10101
10102void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
10103{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010104 const GLuint xy[] = { v0, v1 };
10105 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010106}
10107
10108void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
10109{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010110 const GLuint xyz[] = { v0, v1, v2 };
10111 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010112}
10113
10114void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
10115{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +000010116 const GLuint xyzw[] = { v0, v1, v2, v3 };
10117 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010118}
10119
10120void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
10121{
10122 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10123 location, count, value);
10124
10125 try
10126 {
10127 gl::Context *context = gl::getNonLostContext();
10128
10129 if (context)
10130 {
10131 if (context->getClientVersion() < 3)
10132 {
10133 return gl::error(GL_INVALID_OPERATION);
10134 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010135
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010136 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10137 if (!programBinary)
10138 {
10139 return gl::error(GL_INVALID_OPERATION);
10140 }
10141
10142 if (!programBinary->setUniform1uiv(location, count, value))
10143 {
10144 return gl::error(GL_INVALID_OPERATION);
10145 }
10146 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010147 }
10148 catch(std::bad_alloc&)
10149 {
10150 return gl::error(GL_OUT_OF_MEMORY);
10151 }
10152}
10153
10154void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
10155{
10156 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10157 location, count, value);
10158
10159 try
10160 {
10161 gl::Context *context = gl::getNonLostContext();
10162
10163 if (context)
10164 {
10165 if (context->getClientVersion() < 3)
10166 {
10167 return gl::error(GL_INVALID_OPERATION);
10168 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010169
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010170 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10171 if (!programBinary)
10172 {
10173 return gl::error(GL_INVALID_OPERATION);
10174 }
10175
10176 if (!programBinary->setUniform2uiv(location, count, value))
10177 {
10178 return gl::error(GL_INVALID_OPERATION);
10179 }
10180 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010181 }
10182 catch(std::bad_alloc&)
10183 {
10184 return gl::error(GL_OUT_OF_MEMORY);
10185 }
10186}
10187
10188void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
10189{
10190 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
10191 location, count, value);
10192
10193 try
10194 {
10195 gl::Context *context = gl::getNonLostContext();
10196
10197 if (context)
10198 {
10199 if (context->getClientVersion() < 3)
10200 {
10201 return gl::error(GL_INVALID_OPERATION);
10202 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010203
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010204 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10205 if (!programBinary)
10206 {
10207 return gl::error(GL_INVALID_OPERATION);
10208 }
10209
10210 if (!programBinary->setUniform3uiv(location, count, value))
10211 {
10212 return gl::error(GL_INVALID_OPERATION);
10213 }
10214 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010215 }
10216 catch(std::bad_alloc&)
10217 {
10218 return gl::error(GL_OUT_OF_MEMORY);
10219 }
10220}
10221
10222void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10223{
10224 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10225 location, count, value);
10226
10227 try
10228 {
10229 gl::Context *context = gl::getNonLostContext();
10230
10231 if (context)
10232 {
10233 if (context->getClientVersion() < 3)
10234 {
10235 return gl::error(GL_INVALID_OPERATION);
10236 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010237
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010238 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10239 if (!programBinary)
10240 {
10241 return gl::error(GL_INVALID_OPERATION);
10242 }
10243
10244 if (!programBinary->setUniform4uiv(location, count, value))
10245 {
10246 return gl::error(GL_INVALID_OPERATION);
10247 }
10248 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010249 }
10250 catch(std::bad_alloc&)
10251 {
10252 return gl::error(GL_OUT_OF_MEMORY);
10253 }
10254}
10255
10256void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10257{
10258 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10259 buffer, drawbuffer, value);
10260
10261 try
10262 {
10263 gl::Context *context = gl::getNonLostContext();
10264
10265 if (context)
10266 {
10267 if (context->getClientVersion() < 3)
10268 {
10269 return gl::error(GL_INVALID_OPERATION);
10270 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010271
Jamie Madill54133512013-06-21 09:33:07 -040010272 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010273 UNIMPLEMENTED();
10274 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010275 }
10276 catch(std::bad_alloc&)
10277 {
10278 return gl::error(GL_OUT_OF_MEMORY);
10279 }
10280}
10281
10282void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10283{
10284 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10285 buffer, drawbuffer, value);
10286
10287 try
10288 {
10289 gl::Context *context = gl::getNonLostContext();
10290
10291 if (context)
10292 {
10293 if (context->getClientVersion() < 3)
10294 {
10295 return gl::error(GL_INVALID_OPERATION);
10296 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010297
Jamie Madill54133512013-06-21 09:33:07 -040010298 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010299 UNIMPLEMENTED();
10300 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010301 }
10302 catch(std::bad_alloc&)
10303 {
10304 return gl::error(GL_OUT_OF_MEMORY);
10305 }
10306}
10307
10308void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10309{
10310 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10311 buffer, drawbuffer, value);
10312
10313 try
10314 {
10315 gl::Context *context = gl::getNonLostContext();
10316
10317 if (context)
10318 {
10319 if (context->getClientVersion() < 3)
10320 {
10321 return gl::error(GL_INVALID_OPERATION);
10322 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010323
Jamie Madill54133512013-06-21 09:33:07 -040010324 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010325 UNIMPLEMENTED();
10326 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010327 }
10328 catch(std::bad_alloc&)
10329 {
10330 return gl::error(GL_OUT_OF_MEMORY);
10331 }
10332}
10333
10334void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10335{
10336 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10337 buffer, drawbuffer, depth, stencil);
10338
10339 try
10340 {
10341 gl::Context *context = gl::getNonLostContext();
10342
10343 if (context)
10344 {
10345 if (context->getClientVersion() < 3)
10346 {
10347 return gl::error(GL_INVALID_OPERATION);
10348 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010349
Jamie Madill54133512013-06-21 09:33:07 -040010350 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010351 UNIMPLEMENTED();
10352 }
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);
10357 }
10358}
10359
10360const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10361{
10362 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10363
10364 try
10365 {
10366 gl::Context *context = gl::getNonLostContext();
10367
10368 if (context)
10369 {
10370 if (context->getClientVersion() < 3)
10371 {
10372 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10373 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010374
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010375 if (name != GL_EXTENSIONS)
10376 {
10377 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10378 }
10379
10380 if (index >= context->getNumExtensions())
10381 {
10382 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10383 }
10384
10385 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10386 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010387 }
10388 catch(std::bad_alloc&)
10389 {
10390 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10391 }
10392
10393 return NULL;
10394}
10395
10396void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10397{
10398 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10399 readTarget, writeTarget, readOffset, writeOffset, size);
10400
10401 try
10402 {
10403 gl::Context *context = gl::getNonLostContext();
10404
10405 if (context)
10406 {
10407 if (context->getClientVersion() < 3)
10408 {
10409 return gl::error(GL_INVALID_OPERATION);
10410 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010411
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010412 gl::Buffer *readBuffer = NULL;
10413 switch (readTarget)
10414 {
10415 case GL_ARRAY_BUFFER:
10416 readBuffer = context->getArrayBuffer();
10417 break;
10418 case GL_COPY_READ_BUFFER:
10419 readBuffer = context->getCopyReadBuffer();
10420 break;
10421 case GL_COPY_WRITE_BUFFER:
10422 readBuffer = context->getCopyWriteBuffer();
10423 break;
10424 case GL_ELEMENT_ARRAY_BUFFER:
10425 readBuffer = context->getElementArrayBuffer();
10426 break;
10427 case GL_PIXEL_PACK_BUFFER:
10428 readBuffer = context->getPixelPackBuffer();
10429 break;
10430 case GL_PIXEL_UNPACK_BUFFER:
10431 readBuffer = context->getPixelUnpackBuffer();
10432 break;
10433 case GL_TRANSFORM_FEEDBACK_BUFFER:
10434 readBuffer = context->getGenericTransformFeedbackBuffer();
10435 break;
10436 case GL_UNIFORM_BUFFER:
10437 readBuffer = context->getGenericUniformBuffer();
10438 break;
10439 default:
10440 return gl::error(GL_INVALID_ENUM);
10441 }
10442
10443 gl::Buffer *writeBuffer = NULL;
10444 switch (writeTarget)
10445 {
10446 case GL_ARRAY_BUFFER:
10447 writeBuffer = context->getArrayBuffer();
10448 break;
10449 case GL_COPY_READ_BUFFER:
10450 writeBuffer = context->getCopyReadBuffer();
10451 break;
10452 case GL_COPY_WRITE_BUFFER:
10453 writeBuffer = context->getCopyWriteBuffer();
10454 break;
10455 case GL_ELEMENT_ARRAY_BUFFER:
10456 writeBuffer = context->getElementArrayBuffer();
10457 break;
10458 case GL_PIXEL_PACK_BUFFER:
10459 writeBuffer = context->getPixelPackBuffer();
10460 break;
10461 case GL_PIXEL_UNPACK_BUFFER:
10462 writeBuffer = context->getPixelUnpackBuffer();
10463 break;
10464 case GL_TRANSFORM_FEEDBACK_BUFFER:
10465 writeBuffer = context->getGenericTransformFeedbackBuffer();
10466 break;
10467 case GL_UNIFORM_BUFFER:
10468 writeBuffer = context->getGenericUniformBuffer();
10469 break;
10470 default:
10471 return gl::error(GL_INVALID_ENUM);
10472 }
10473
10474 if (!readBuffer || !writeBuffer)
10475 {
10476 return gl::error(GL_INVALID_OPERATION);
10477 }
10478
10479 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10480 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10481 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10482 {
10483 return gl::error(GL_INVALID_VALUE);
10484 }
10485
10486 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10487 {
10488 return gl::error(GL_INVALID_VALUE);
10489 }
10490
10491 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10492
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010493 // if size is zero, the copy is a successful no-op
10494 if (size > 0)
10495 {
10496 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10497 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010498 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010499 }
10500 catch(std::bad_alloc&)
10501 {
10502 return gl::error(GL_OUT_OF_MEMORY);
10503 }
10504}
10505
10506void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10507{
10508 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10509 program, uniformCount, uniformNames, uniformIndices);
10510
10511 try
10512 {
10513 gl::Context *context = gl::getNonLostContext();
10514
10515 if (context)
10516 {
10517 if (context->getClientVersion() < 3)
10518 {
10519 return gl::error(GL_INVALID_OPERATION);
10520 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010521
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010522 if (uniformCount < 0)
10523 {
10524 return gl::error(GL_INVALID_VALUE);
10525 }
10526
10527 gl::Program *programObject = context->getProgram(program);
10528
10529 if (!programObject)
10530 {
10531 if (context->getShader(program))
10532 {
10533 return gl::error(GL_INVALID_OPERATION);
10534 }
10535 else
10536 {
10537 return gl::error(GL_INVALID_VALUE);
10538 }
10539 }
10540
10541 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10542 if (!programObject->isLinked() || !programBinary)
10543 {
10544 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10545 {
10546 uniformIndices[uniformId] = GL_INVALID_INDEX;
10547 }
10548 }
10549 else
10550 {
10551 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10552 {
10553 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10554 }
10555 }
10556 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010557 }
10558 catch(std::bad_alloc&)
10559 {
10560 return gl::error(GL_OUT_OF_MEMORY);
10561 }
10562}
10563
10564void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10565{
10566 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10567 program, uniformCount, uniformIndices, pname, params);
10568
10569 try
10570 {
10571 gl::Context *context = gl::getNonLostContext();
10572
10573 if (context)
10574 {
10575 if (context->getClientVersion() < 3)
10576 {
10577 return gl::error(GL_INVALID_OPERATION);
10578 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010579
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010580 if (uniformCount < 0)
10581 {
10582 return gl::error(GL_INVALID_VALUE);
10583 }
10584
10585 gl::Program *programObject = context->getProgram(program);
10586
10587 if (!programObject)
10588 {
10589 if (context->getShader(program))
10590 {
10591 return gl::error(GL_INVALID_OPERATION);
10592 }
10593 else
10594 {
10595 return gl::error(GL_INVALID_VALUE);
10596 }
10597 }
10598
10599 switch (pname)
10600 {
10601 case GL_UNIFORM_TYPE:
10602 case GL_UNIFORM_SIZE:
10603 case GL_UNIFORM_NAME_LENGTH:
10604 case GL_UNIFORM_BLOCK_INDEX:
10605 case GL_UNIFORM_OFFSET:
10606 case GL_UNIFORM_ARRAY_STRIDE:
10607 case GL_UNIFORM_MATRIX_STRIDE:
10608 case GL_UNIFORM_IS_ROW_MAJOR:
10609 break;
10610 default:
10611 return gl::error(GL_INVALID_ENUM);
10612 }
10613
10614 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10615
10616 if (!programBinary && uniformCount > 0)
10617 {
10618 return gl::error(GL_INVALID_VALUE);
10619 }
10620
10621 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10622 {
10623 const GLuint index = uniformIndices[uniformId];
10624
10625 if (index >= (GLuint)programBinary->getActiveUniformCount())
10626 {
10627 return gl::error(GL_INVALID_VALUE);
10628 }
10629 }
10630
10631 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10632 {
10633 const GLuint index = uniformIndices[uniformId];
10634 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10635 }
10636 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010637 }
10638 catch(std::bad_alloc&)
10639 {
10640 return gl::error(GL_OUT_OF_MEMORY);
10641 }
10642}
10643
10644GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10645{
10646 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10647
10648 try
10649 {
10650 gl::Context *context = gl::getNonLostContext();
10651
10652 if (context)
10653 {
10654 if (context->getClientVersion() < 3)
10655 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010656 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010657 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010658
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010659 gl::Program *programObject = context->getProgram(program);
10660
10661 if (!programObject)
10662 {
10663 if (context->getShader(program))
10664 {
10665 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10666 }
10667 else
10668 {
10669 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10670 }
10671 }
10672
10673 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10674 if (!programBinary)
10675 {
10676 return GL_INVALID_INDEX;
10677 }
10678
10679 return programBinary->getUniformBlockIndex(uniformBlockName);
10680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010681 }
10682 catch(std::bad_alloc&)
10683 {
10684 return gl::error(GL_OUT_OF_MEMORY, 0);
10685 }
10686
10687 return 0;
10688}
10689
10690void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10691{
10692 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10693 program, uniformBlockIndex, pname, params);
10694
10695 try
10696 {
10697 gl::Context *context = gl::getNonLostContext();
10698
10699 if (context)
10700 {
10701 if (context->getClientVersion() < 3)
10702 {
10703 return gl::error(GL_INVALID_OPERATION);
10704 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010705 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010706
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010707 if (!programObject)
10708 {
10709 if (context->getShader(program))
10710 {
10711 return gl::error(GL_INVALID_OPERATION);
10712 }
10713 else
10714 {
10715 return gl::error(GL_INVALID_VALUE);
10716 }
10717 }
10718
10719 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10720
10721 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10722 {
10723 return gl::error(GL_INVALID_VALUE);
10724 }
10725
10726 switch (pname)
10727 {
10728 case GL_UNIFORM_BLOCK_BINDING:
10729 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10730 break;
10731
10732 case GL_UNIFORM_BLOCK_DATA_SIZE:
10733 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10734 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10735 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10736 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10737 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10738 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10739 break;
10740
10741 default:
10742 return gl::error(GL_INVALID_ENUM);
10743 }
10744 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010745 }
10746 catch(std::bad_alloc&)
10747 {
10748 return gl::error(GL_OUT_OF_MEMORY);
10749 }
10750}
10751
10752void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10753{
10754 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10755 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10756
10757 try
10758 {
10759 gl::Context *context = gl::getNonLostContext();
10760
10761 if (context)
10762 {
10763 if (context->getClientVersion() < 3)
10764 {
10765 return gl::error(GL_INVALID_OPERATION);
10766 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010767
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010768 gl::Program *programObject = context->getProgram(program);
10769
10770 if (!programObject)
10771 {
10772 if (context->getShader(program))
10773 {
10774 return gl::error(GL_INVALID_OPERATION);
10775 }
10776 else
10777 {
10778 return gl::error(GL_INVALID_VALUE);
10779 }
10780 }
10781
10782 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10783
10784 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10785 {
10786 return gl::error(GL_INVALID_VALUE);
10787 }
10788
10789 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010791 }
10792 catch(std::bad_alloc&)
10793 {
10794 return gl::error(GL_OUT_OF_MEMORY);
10795 }
10796}
10797
10798void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10799{
10800 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10801 program, uniformBlockIndex, uniformBlockBinding);
10802
10803 try
10804 {
10805 gl::Context *context = gl::getNonLostContext();
10806
10807 if (context)
10808 {
10809 if (context->getClientVersion() < 3)
10810 {
10811 return gl::error(GL_INVALID_OPERATION);
10812 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010813
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010814 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10815 {
10816 return gl::error(GL_INVALID_VALUE);
10817 }
10818
10819 gl::Program *programObject = context->getProgram(program);
10820
10821 if (!programObject)
10822 {
10823 if (context->getShader(program))
10824 {
10825 return gl::error(GL_INVALID_OPERATION);
10826 }
10827 else
10828 {
10829 return gl::error(GL_INVALID_VALUE);
10830 }
10831 }
10832
10833 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10834
10835 // if never linked, there won't be any uniform blocks
10836 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10837 {
10838 return gl::error(GL_INVALID_VALUE);
10839 }
10840
10841 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10842 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010843 }
10844 catch(std::bad_alloc&)
10845 {
10846 return gl::error(GL_OUT_OF_MEMORY);
10847 }
10848}
10849
10850void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10851{
10852 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10853 mode, first, count, instanceCount);
10854
10855 try
10856 {
10857 gl::Context *context = gl::getNonLostContext();
10858
10859 if (context)
10860 {
10861 if (context->getClientVersion() < 3)
10862 {
10863 return gl::error(GL_INVALID_OPERATION);
10864 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010865
Jamie Madill54133512013-06-21 09:33:07 -040010866 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010867 UNIMPLEMENTED();
10868 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010869 }
10870 catch(std::bad_alloc&)
10871 {
10872 return gl::error(GL_OUT_OF_MEMORY);
10873 }
10874}
10875
10876void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10877{
10878 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10879 mode, count, type, indices, instanceCount);
10880
10881 try
10882 {
10883 gl::Context *context = gl::getNonLostContext();
10884
10885 if (context)
10886 {
10887 if (context->getClientVersion() < 3)
10888 {
10889 return gl::error(GL_INVALID_OPERATION);
10890 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010891
Jamie Madill54133512013-06-21 09:33:07 -040010892 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010893 UNIMPLEMENTED();
10894 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010895 }
10896 catch(std::bad_alloc&)
10897 {
10898 return gl::error(GL_OUT_OF_MEMORY);
10899 }
10900}
10901
10902GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10903{
10904 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10905
10906 try
10907 {
10908 gl::Context *context = gl::getNonLostContext();
10909
10910 if (context)
10911 {
10912 if (context->getClientVersion() < 3)
10913 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040010914 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(0));
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010915 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010916
Jamie Madill5215e1a2013-07-26 11:55:19 -040010917 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
10918 {
10919 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLsync>(0));
10920 }
10921
10922 if (flags != 0)
10923 {
10924 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLsync>(0));
10925 }
10926
10927 return context->createFenceSync(condition);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010928 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010929 }
10930 catch(std::bad_alloc&)
10931 {
10932 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10933 }
10934
10935 return NULL;
10936}
10937
10938GLboolean __stdcall glIsSync(GLsync sync)
10939{
10940 EVENT("(GLsync sync = 0x%0.8p)", sync);
10941
10942 try
10943 {
10944 gl::Context *context = gl::getNonLostContext();
10945
10946 if (context)
10947 {
10948 if (context->getClientVersion() < 3)
10949 {
10950 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10951 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010952
Jamie Madill5215e1a2013-07-26 11:55:19 -040010953 return (context->getFenceSync(sync) != NULL);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010954 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010955 }
10956 catch(std::bad_alloc&)
10957 {
10958 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10959 }
10960
10961 return GL_FALSE;
10962}
10963
10964void __stdcall glDeleteSync(GLsync sync)
10965{
10966 EVENT("(GLsync sync = 0x%0.8p)", sync);
10967
10968 try
10969 {
10970 gl::Context *context = gl::getNonLostContext();
10971
10972 if (context)
10973 {
10974 if (context->getClientVersion() < 3)
10975 {
10976 return gl::error(GL_INVALID_OPERATION);
10977 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010978
Jamie Madill5215e1a2013-07-26 11:55:19 -040010979 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
10980 {
10981 return gl::error(GL_INVALID_VALUE);
10982 }
10983
10984 context->deleteFenceSync(sync);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010985 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010986 }
10987 catch(std::bad_alloc&)
10988 {
10989 return gl::error(GL_OUT_OF_MEMORY);
10990 }
10991}
10992
10993GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10994{
10995 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10996 sync, flags, timeout);
10997
10998 try
10999 {
11000 gl::Context *context = gl::getNonLostContext();
11001
11002 if (context)
11003 {
11004 if (context->getClientVersion() < 3)
11005 {
Jamie Madill5215e1a2013-07-26 11:55:19 -040011006 return gl::error(GL_INVALID_OPERATION, GL_WAIT_FAILED);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011008
Jamie Madill5215e1a2013-07-26 11:55:19 -040011009 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
11010 {
11011 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11012 }
11013
11014 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11015
11016 if (!fenceSync)
11017 {
11018 return gl::error(GL_INVALID_VALUE, GL_WAIT_FAILED);
11019 }
11020
11021 return fenceSync->clientWait(flags, timeout);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011022 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011023 }
11024 catch(std::bad_alloc&)
11025 {
11026 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11027 }
11028
11029 return GL_FALSE;
11030}
11031
11032void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
11033{
11034 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
11035 sync, flags, timeout);
11036
11037 try
11038 {
11039 gl::Context *context = gl::getNonLostContext();
11040
11041 if (context)
11042 {
11043 if (context->getClientVersion() < 3)
11044 {
11045 return gl::error(GL_INVALID_OPERATION);
11046 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011047
Jamie Madill5215e1a2013-07-26 11:55:19 -040011048 if (flags != 0)
11049 {
11050 return gl::error(GL_INVALID_VALUE);
11051 }
11052
11053 if (timeout != GL_TIMEOUT_IGNORED)
11054 {
11055 return gl::error(GL_INVALID_VALUE);
11056 }
11057
11058 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11059
11060 if (!fenceSync)
11061 {
11062 return gl::error(GL_INVALID_VALUE);
11063 }
11064
11065 fenceSync->serverWait();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011066 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011067 }
11068 catch(std::bad_alloc&)
11069 {
11070 return gl::error(GL_OUT_OF_MEMORY);
11071 }
11072}
11073
11074void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
11075{
11076 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11077 pname, params);
11078
11079 try
11080 {
11081 gl::Context *context = gl::getNonLostContext();
11082
11083 if (context)
11084 {
11085 if (context->getClientVersion() < 3)
11086 {
11087 return gl::error(GL_INVALID_OPERATION);
11088 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011089
Jamie Madill71fbd602013-07-19 16:36:55 -040011090 if (!(context->getInteger64v(pname, params)))
11091 {
11092 GLenum nativeType;
11093 unsigned int numParams = 0;
11094 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
11095 return gl::error(GL_INVALID_ENUM);
11096
11097 if (numParams == 0)
11098 return; // it is known that the pname is valid, but that there are no parameters to return.
11099
11100 if (nativeType == GL_BOOL)
11101 {
11102 GLboolean *boolParams = NULL;
11103 boolParams = new GLboolean[numParams];
11104
11105 context->getBooleanv(pname, boolParams);
11106
11107 for (unsigned int i = 0; i < numParams; ++i)
11108 {
11109 if (boolParams[i] == GL_FALSE)
11110 params[i] = 0;
11111 else
11112 params[i] = 1;
11113 }
11114
11115 delete [] boolParams;
11116 }
11117 else if (nativeType == GL_INT)
11118 {
11119 GLint *intParams = NULL;
11120 intParams = new GLint[numParams];
11121
11122 context->getIntegerv(pname, intParams);
11123
11124 for (unsigned int i = 0; i < numParams; ++i)
11125 {
11126 params[i] = static_cast<GLint64>(intParams[i]);
11127 }
11128
11129 delete [] intParams;
11130 }
11131 else if (nativeType == GL_FLOAT)
11132 {
11133 GLfloat *floatParams = NULL;
11134 floatParams = new GLfloat[numParams];
11135
11136 context->getFloatv(pname, floatParams);
11137
11138 for (unsigned int i = 0; i < numParams; ++i)
11139 {
11140 // RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
11141 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
11142 {
11143 params[i] = static_cast<GLint64>((static_cast<GLfloat>(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
11144 }
11145 else
11146 {
11147 params[i] = gl::iround<GLint64>(floatParams[i]);
11148 }
11149 }
11150
11151 delete [] floatParams;
11152 }
11153 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011154 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011155 }
11156 catch(std::bad_alloc&)
11157 {
11158 return gl::error(GL_OUT_OF_MEMORY);
11159 }
11160}
11161
11162void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
11163{
11164 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
11165 sync, pname, bufSize, length, values);
11166
11167 try
11168 {
11169 gl::Context *context = gl::getNonLostContext();
11170
11171 if (context)
11172 {
11173 if (context->getClientVersion() < 3)
11174 {
11175 return gl::error(GL_INVALID_OPERATION);
11176 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011177
Jamie Madill5215e1a2013-07-26 11:55:19 -040011178 if (bufSize < 0)
11179 {
11180 return gl::error(GL_INVALID_VALUE);
11181 }
11182
11183 gl::FenceSync *fenceSync = context->getFenceSync(sync);
11184
11185 if (!fenceSync)
11186 {
11187 return gl::error(GL_INVALID_VALUE);
11188 }
11189
11190 switch (pname)
11191 {
11192 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
11193 case GL_SYNC_STATUS: values[0] = static_cast<GLint>(fenceSync->getStatus()); break;
11194 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
11195 case GL_SYNC_FLAGS: values[0] = 0; break;
11196
11197 default:
11198 return gl::error(GL_INVALID_ENUM);
11199 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011200 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011201 }
11202 catch(std::bad_alloc&)
11203 {
11204 return gl::error(GL_OUT_OF_MEMORY);
11205 }
11206}
11207
11208void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
11209{
11210 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
11211 target, index, data);
11212
11213 try
11214 {
11215 gl::Context *context = gl::getNonLostContext();
11216
11217 if (context)
11218 {
11219 if (context->getClientVersion() < 3)
11220 {
11221 return gl::error(GL_INVALID_OPERATION);
11222 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011223
Jamie Madill54133512013-06-21 09:33:07 -040011224 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011225 UNIMPLEMENTED();
11226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011227 }
11228 catch(std::bad_alloc&)
11229 {
11230 return gl::error(GL_OUT_OF_MEMORY);
11231 }
11232}
11233
11234void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
11235{
11236 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
11237 target, pname, params);
11238
11239 try
11240 {
11241 gl::Context *context = gl::getNonLostContext();
11242
11243 if (context)
11244 {
11245 if (context->getClientVersion() < 3)
11246 {
11247 return gl::error(GL_INVALID_OPERATION);
11248 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011249
Jamie Madill54133512013-06-21 09:33:07 -040011250 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011251 UNIMPLEMENTED();
11252 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011253 }
11254 catch(std::bad_alloc&)
11255 {
11256 return gl::error(GL_OUT_OF_MEMORY);
11257 }
11258}
11259
11260void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
11261{
11262 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
11263
11264 try
11265 {
11266 gl::Context *context = gl::getNonLostContext();
11267
11268 if (context)
11269 {
11270 if (context->getClientVersion() < 3)
11271 {
11272 return gl::error(GL_INVALID_OPERATION);
11273 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011274
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011275 if (count < 0)
11276 {
11277 return gl::error(GL_INVALID_VALUE);
11278 }
11279
11280 for (int i = 0; i < count; i++)
11281 {
11282 samplers[i] = context->createSampler();
11283 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011284 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011285 }
11286 catch(std::bad_alloc&)
11287 {
11288 return gl::error(GL_OUT_OF_MEMORY);
11289 }
11290}
11291
11292void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
11293{
11294 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
11295
11296 try
11297 {
11298 gl::Context *context = gl::getNonLostContext();
11299
11300 if (context)
11301 {
11302 if (context->getClientVersion() < 3)
11303 {
11304 return gl::error(GL_INVALID_OPERATION);
11305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011306
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011307 if (count < 0)
11308 {
11309 return gl::error(GL_INVALID_VALUE);
11310 }
11311
11312 for (int i = 0; i < count; i++)
11313 {
11314 context->deleteSampler(samplers[i]);
11315 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011316 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011317 }
11318 catch(std::bad_alloc&)
11319 {
11320 return gl::error(GL_OUT_OF_MEMORY);
11321 }
11322}
11323
11324GLboolean __stdcall glIsSampler(GLuint sampler)
11325{
11326 EVENT("(GLuint sampler = %u)", sampler);
11327
11328 try
11329 {
11330 gl::Context *context = gl::getNonLostContext();
11331
11332 if (context)
11333 {
11334 if (context->getClientVersion() < 3)
11335 {
11336 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11337 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011338
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011339 return context->isSampler(sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011340 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011341 }
11342 catch(std::bad_alloc&)
11343 {
11344 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11345 }
11346
11347 return GL_FALSE;
11348}
11349
11350void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11351{
11352 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
11353
11354 try
11355 {
11356 gl::Context *context = gl::getNonLostContext();
11357
11358 if (context)
11359 {
11360 if (context->getClientVersion() < 3)
11361 {
11362 return gl::error(GL_INVALID_OPERATION);
11363 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011364
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011365 if (sampler != 0 && !context->isSampler(sampler))
11366 {
11367 return gl::error(GL_INVALID_OPERATION);
11368 }
11369
11370 if (unit >= context->getMaximumCombinedTextureImageUnits())
11371 {
11372 return gl::error(GL_INVALID_VALUE);
11373 }
11374
11375 context->bindSampler(unit, sampler);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011376 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011377 }
11378 catch(std::bad_alloc&)
11379 {
11380 return gl::error(GL_OUT_OF_MEMORY);
11381 }
11382}
11383
11384void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11385{
11386 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11387
11388 try
11389 {
11390 gl::Context *context = gl::getNonLostContext();
11391
11392 if (context)
11393 {
11394 if (context->getClientVersion() < 3)
11395 {
11396 return gl::error(GL_INVALID_OPERATION);
11397 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011398
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011399 if (!validateSamplerObjectParameter(pname))
11400 {
11401 return;
11402 }
11403
11404 if (!validateTexParamParameters(context, pname, param))
11405 {
11406 return;
11407 }
11408
11409 if (!context->isSampler(sampler))
11410 {
11411 return gl::error(GL_INVALID_OPERATION);
11412 }
11413
11414 context->samplerParameteri(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011415 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011416 }
11417 catch(std::bad_alloc&)
11418 {
11419 return gl::error(GL_OUT_OF_MEMORY);
11420 }
11421}
11422
11423void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11424{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011425 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011426}
11427
11428void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11429{
11430 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
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 Madillf6cc8cc2013-07-03 12:44:15 -040011443 if (!validateSamplerObjectParameter(pname))
11444 {
11445 return;
11446 }
11447
11448 if (!validateTexParamParameters(context, pname, static_cast<GLint>(param)))
11449 {
11450 return;
11451 }
11452
11453 if (!context->isSampler(sampler))
11454 {
11455 return gl::error(GL_INVALID_OPERATION);
11456 }
11457
11458 context->samplerParameterf(sampler, pname, param);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011459 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011460 }
11461 catch(std::bad_alloc&)
11462 {
11463 return gl::error(GL_OUT_OF_MEMORY);
11464 }
11465}
11466
11467void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11468{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011469 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011470}
11471
11472void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11473{
11474 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11475
11476 try
11477 {
11478 gl::Context *context = gl::getNonLostContext();
11479
11480 if (context)
11481 {
11482 if (context->getClientVersion() < 3)
11483 {
11484 return gl::error(GL_INVALID_OPERATION);
11485 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011486
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011487 if (!validateSamplerObjectParameter(pname))
11488 {
11489 return;
11490 }
11491
11492 if (!context->isSampler(sampler))
11493 {
11494 return gl::error(GL_INVALID_OPERATION);
11495 }
11496
11497 *params = context->getSamplerParameteri(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011498 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011499 }
11500 catch(std::bad_alloc&)
11501 {
11502 return gl::error(GL_OUT_OF_MEMORY);
11503 }
11504}
11505
11506void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11507{
11508 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11509
11510 try
11511 {
11512 gl::Context *context = gl::getNonLostContext();
11513
11514 if (context)
11515 {
11516 if (context->getClientVersion() < 3)
11517 {
11518 return gl::error(GL_INVALID_OPERATION);
11519 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011520
Jamie Madillf6cc8cc2013-07-03 12:44:15 -040011521 if (!validateSamplerObjectParameter(pname))
11522 {
11523 return;
11524 }
11525
11526 if (!context->isSampler(sampler))
11527 {
11528 return gl::error(GL_INVALID_OPERATION);
11529 }
11530
11531 *params = context->getSamplerParameterf(sampler, pname);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011532 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011533 }
11534 catch(std::bad_alloc&)
11535 {
11536 return gl::error(GL_OUT_OF_MEMORY);
11537 }
11538}
11539
11540void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11541{
11542 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11543
11544 try
11545 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011546 if (index >= gl::MAX_VERTEX_ATTRIBS)
11547 {
11548 return gl::error(GL_INVALID_VALUE);
11549 }
11550
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011551 gl::Context *context = gl::getNonLostContext();
11552
11553 if (context)
11554 {
11555 if (context->getClientVersion() < 3)
11556 {
11557 return gl::error(GL_INVALID_OPERATION);
11558 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011559
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011560 context->setVertexAttribDivisor(index, divisor);
11561 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011562 }
11563 catch(std::bad_alloc&)
11564 {
11565 return gl::error(GL_OUT_OF_MEMORY);
11566 }
11567}
11568
11569void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11570{
11571 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11572
11573 try
11574 {
11575 gl::Context *context = gl::getNonLostContext();
11576
11577 if (context)
11578 {
11579 if (context->getClientVersion() < 3)
11580 {
11581 return gl::error(GL_INVALID_OPERATION);
11582 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011583
Jamie Madill54133512013-06-21 09:33:07 -040011584 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011585 UNIMPLEMENTED();
11586 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011587 }
11588 catch(std::bad_alloc&)
11589 {
11590 return gl::error(GL_OUT_OF_MEMORY);
11591 }
11592}
11593
11594void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11595{
11596 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11597
11598 try
11599 {
11600 gl::Context *context = gl::getNonLostContext();
11601
11602 if (context)
11603 {
11604 if (context->getClientVersion() < 3)
11605 {
11606 return gl::error(GL_INVALID_OPERATION);
11607 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011608
Jamie Madill54133512013-06-21 09:33:07 -040011609 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011610 UNIMPLEMENTED();
11611 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011612 }
11613 catch(std::bad_alloc&)
11614 {
11615 return gl::error(GL_OUT_OF_MEMORY);
11616 }
11617}
11618
11619void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11620{
11621 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11622
11623 try
11624 {
11625 gl::Context *context = gl::getNonLostContext();
11626
11627 if (context)
11628 {
11629 if (context->getClientVersion() < 3)
11630 {
11631 return gl::error(GL_INVALID_OPERATION);
11632 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011633
Jamie Madill54133512013-06-21 09:33:07 -040011634 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011635 UNIMPLEMENTED();
11636 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011637 }
11638 catch(std::bad_alloc&)
11639 {
11640 return gl::error(GL_OUT_OF_MEMORY);
11641 }
11642}
11643
11644GLboolean __stdcall glIsTransformFeedback(GLuint id)
11645{
11646 EVENT("(GLuint id = %u)", id);
11647
11648 try
11649 {
11650 gl::Context *context = gl::getNonLostContext();
11651
11652 if (context)
11653 {
11654 if (context->getClientVersion() < 3)
11655 {
11656 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11657 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011658
Jamie Madill54133512013-06-21 09:33:07 -040011659 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011660 UNIMPLEMENTED();
11661 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011662 }
11663 catch(std::bad_alloc&)
11664 {
11665 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11666 }
11667
11668 return GL_FALSE;
11669}
11670
11671void __stdcall glPauseTransformFeedback(void)
11672{
11673 EVENT("(void)");
11674
11675 try
11676 {
11677 gl::Context *context = gl::getNonLostContext();
11678
11679 if (context)
11680 {
11681 if (context->getClientVersion() < 3)
11682 {
11683 return gl::error(GL_INVALID_OPERATION);
11684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011685
Jamie Madill54133512013-06-21 09:33:07 -040011686 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011687 UNIMPLEMENTED();
11688 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011689 }
11690 catch(std::bad_alloc&)
11691 {
11692 return gl::error(GL_OUT_OF_MEMORY);
11693 }
11694}
11695
11696void __stdcall glResumeTransformFeedback(void)
11697{
11698 EVENT("(void)");
11699
11700 try
11701 {
11702 gl::Context *context = gl::getNonLostContext();
11703
11704 if (context)
11705 {
11706 if (context->getClientVersion() < 3)
11707 {
11708 return gl::error(GL_INVALID_OPERATION);
11709 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011710
Jamie Madill54133512013-06-21 09:33:07 -040011711 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011712 UNIMPLEMENTED();
11713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011714 }
11715 catch(std::bad_alloc&)
11716 {
11717 return gl::error(GL_OUT_OF_MEMORY);
11718 }
11719}
11720
11721void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11722{
11723 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11724 program, bufSize, length, binaryFormat, binary);
11725
11726 try
11727 {
11728 gl::Context *context = gl::getNonLostContext();
11729
11730 if (context)
11731 {
11732 if (context->getClientVersion() < 3)
11733 {
11734 return gl::error(GL_INVALID_OPERATION);
11735 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011736
Jamie Madill54133512013-06-21 09:33:07 -040011737 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011738 UNIMPLEMENTED();
11739 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011740 }
11741 catch(std::bad_alloc&)
11742 {
11743 return gl::error(GL_OUT_OF_MEMORY);
11744 }
11745}
11746
11747void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11748{
11749 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11750 program, binaryFormat, binary, length);
11751
11752 try
11753 {
11754 gl::Context *context = gl::getNonLostContext();
11755
11756 if (context)
11757 {
11758 if (context->getClientVersion() < 3)
11759 {
11760 return gl::error(GL_INVALID_OPERATION);
11761 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011762
Jamie Madill54133512013-06-21 09:33:07 -040011763 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011764 UNIMPLEMENTED();
11765 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011766 }
11767 catch(std::bad_alloc&)
11768 {
11769 return gl::error(GL_OUT_OF_MEMORY);
11770 }
11771}
11772
11773void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11774{
11775 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11776 program, pname, value);
11777
11778 try
11779 {
11780 gl::Context *context = gl::getNonLostContext();
11781
11782 if (context)
11783 {
11784 if (context->getClientVersion() < 3)
11785 {
11786 return gl::error(GL_INVALID_OPERATION);
11787 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011788
Jamie Madill54133512013-06-21 09:33:07 -040011789 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011790 UNIMPLEMENTED();
11791 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011792 }
11793 catch(std::bad_alloc&)
11794 {
11795 return gl::error(GL_OUT_OF_MEMORY);
11796 }
11797}
11798
11799void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11800{
11801 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11802 target, numAttachments, attachments);
11803
11804 try
11805 {
11806 gl::Context *context = gl::getNonLostContext();
11807
11808 if (context)
11809 {
11810 if (context->getClientVersion() < 3)
11811 {
11812 return gl::error(GL_INVALID_OPERATION);
11813 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011814
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011815 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11816 {
11817 return;
11818 }
11819
11820 int maxDimension = context->getMaximumRenderbufferDimension();
11821 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11822 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011823 }
11824 catch(std::bad_alloc&)
11825 {
11826 return gl::error(GL_OUT_OF_MEMORY);
11827 }
11828}
11829
11830void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11831{
11832 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11833 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11834 target, numAttachments, attachments, x, y, width, height);
11835
11836 try
11837 {
11838 gl::Context *context = gl::getNonLostContext();
11839
11840 if (context)
11841 {
11842 if (context->getClientVersion() < 3)
11843 {
11844 return gl::error(GL_INVALID_OPERATION);
11845 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011846
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011847 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11848 {
11849 return;
11850 }
11851
11852 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11853 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011854 }
11855 catch(std::bad_alloc&)
11856 {
11857 return gl::error(GL_OUT_OF_MEMORY);
11858 }
11859}
11860
11861void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11862{
11863 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11864 target, levels, internalformat, width, height);
11865
11866 try
11867 {
11868 gl::Context *context = gl::getNonLostContext();
11869
11870 if (context)
11871 {
11872 if (context->getClientVersion() < 3)
11873 {
11874 return gl::error(GL_INVALID_OPERATION);
11875 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011876
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011877 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11878 {
11879 return;
11880 }
11881
11882 switch (target)
11883 {
11884 case GL_TEXTURE_2D:
11885 {
11886 gl::Texture2D *texture2d = context->getTexture2D();
11887 texture2d->storage(levels, internalformat, width, height);
11888 }
11889 break;
11890
11891 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11892 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11893 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11894 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11895 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11896 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11897 {
11898 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11899 textureCube->storage(levels, internalformat, width);
11900 }
11901 break;
11902
11903 default:
11904 return gl::error(GL_INVALID_ENUM);
11905 }
11906 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011907 }
11908 catch(std::bad_alloc&)
11909 {
11910 return gl::error(GL_OUT_OF_MEMORY);
11911 }
11912}
11913
11914void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11915{
11916 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11917 "GLsizei height = %d, GLsizei depth = %d)",
11918 target, levels, internalformat, width, height, depth);
11919
11920 try
11921 {
11922 gl::Context *context = gl::getNonLostContext();
11923
11924 if (context)
11925 {
11926 if (context->getClientVersion() < 3)
11927 {
11928 return gl::error(GL_INVALID_OPERATION);
11929 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011930
11931 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11932 {
11933 return;
11934 }
11935
11936 switch (target)
11937 {
11938 case GL_TEXTURE_3D:
11939 {
11940 gl::Texture3D *texture3d = context->getTexture3D();
11941 texture3d->storage(levels, internalformat, width, height, depth);
11942 }
11943 break;
11944
11945 case GL_TEXTURE_2D_ARRAY:
11946 {
11947 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11948 texture2darray->storage(levels, internalformat, width, height, depth);
11949 }
11950 break;
11951
11952 default:
11953 return gl::error(GL_INVALID_ENUM);
11954 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011955 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011956 }
11957 catch(std::bad_alloc&)
11958 {
11959 return gl::error(GL_OUT_OF_MEMORY);
11960 }
11961}
11962
11963void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11964{
11965 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11966 "GLint* params = 0x%0.8p)",
11967 target, internalformat, pname, bufSize, params);
11968
11969 try
11970 {
11971 gl::Context *context = gl::getNonLostContext();
11972
11973 if (context)
11974 {
11975 if (context->getClientVersion() < 3)
11976 {
11977 return gl::error(GL_INVALID_OPERATION);
11978 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011979
Shannon Woods809d2502013-07-08 10:32:18 -040011980 if (!gl::IsColorRenderingSupported(internalformat, context) &&
11981 !gl::IsDepthRenderingSupported(internalformat, context) &&
11982 !gl::IsStencilRenderingSupported(internalformat, context))
11983 {
11984 return gl::error(GL_INVALID_ENUM);
11985 }
11986
11987 if (target != GL_RENDERBUFFER)
11988 {
11989 return gl::error(GL_INVALID_ENUM);
11990 }
11991
11992 if (bufSize < 0)
11993 {
11994 return gl::error(GL_INVALID_VALUE);
11995 }
11996
11997 switch (pname)
11998 {
11999 case GL_NUM_SAMPLE_COUNTS:
12000 if (bufSize != 0)
12001 *params = context->getNumSampleCounts(internalformat);
12002 break;
12003 case GL_SAMPLES:
12004 context->getSampleCounts(internalformat, bufSize, params);
12005 break;
12006 default:
12007 return gl::error(GL_INVALID_ENUM);
12008 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000012009 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000012010 }
12011 catch(std::bad_alloc&)
12012 {
12013 return gl::error(GL_OUT_OF_MEMORY);
12014 }
12015}
12016
12017// Extension functions
12018
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012019void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
12020 GLbitfield mask, GLenum filter)
12021{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012022 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012023 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
12024 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
12025 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
12026
12027 try
12028 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012029 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012030
12031 if (context)
12032 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012033 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
12034 dstX0, dstY0, dstX1, dstY1, mask, filter,
12035 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012036 {
Geoff Lang758d5b22013-06-11 11:42:50 -040012037 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012038 }
12039
Geoff Lang758d5b22013-06-11 11:42:50 -040012040 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
12041 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012042 }
12043 }
12044 catch(std::bad_alloc&)
12045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012046 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000012047 }
12048}
12049
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012050void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
12051 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012052{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000012053 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000012054 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000012055 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012056 target, level, internalformat, width, height, depth, border, format, type, pixels);
12057
12058 try
12059 {
12060 UNIMPLEMENTED(); // FIXME
12061 }
12062 catch(std::bad_alloc&)
12063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012064 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012065 }
12066}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012067
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012068void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
12069 GLenum *binaryFormat, void *binary)
12070{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012071 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 +000012072 program, bufSize, length, binaryFormat, binary);
12073
12074 try
12075 {
12076 gl::Context *context = gl::getNonLostContext();
12077
12078 if (context)
12079 {
12080 gl::Program *programObject = context->getProgram(program);
12081
daniel@transgaming.com716056c2012-07-24 18:38:59 +000012082 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012083 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012084 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012085 }
12086
12087 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
12088
12089 if (!programBinary)
12090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012091 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012092 }
12093
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012094 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012095 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012096 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012097 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000012098
12099 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012100 }
12101 }
12102 catch(std::bad_alloc&)
12103 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012104 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012105 }
12106}
12107
12108void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
12109 const void *binary, GLint length)
12110{
12111 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
12112 program, binaryFormat, binary, length);
12113
12114 try
12115 {
12116 gl::Context *context = gl::getNonLostContext();
12117
12118 if (context)
12119 {
12120 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
12121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012122 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012123 }
12124
12125 gl::Program *programObject = context->getProgram(program);
12126
12127 if (!programObject)
12128 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012129 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012130 }
12131
daniel@transgaming.com95d29422012-07-24 18:36:10 +000012132 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012133 }
12134 }
12135 catch(std::bad_alloc&)
12136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012137 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012138 }
12139}
12140
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012141void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
12142{
12143 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
12144
12145 try
12146 {
12147 gl::Context *context = gl::getNonLostContext();
12148
12149 if (context)
12150 {
12151 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
12152 {
12153 return gl::error(GL_INVALID_VALUE);
12154 }
12155
12156 if (context->getDrawFramebufferHandle() == 0)
12157 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012158 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012159 {
12160 return gl::error(GL_INVALID_OPERATION);
12161 }
12162
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012163 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012164 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012165 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012166 }
12167 }
12168 else
12169 {
12170 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12171 {
12172 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
12173 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
12174 {
12175 return gl::error(GL_INVALID_OPERATION);
12176 }
12177 }
12178 }
12179
12180 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
12181
12182 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
12183 {
12184 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
12185 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000012186
12187 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
12188 {
12189 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
12190 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000012191 }
12192 }
12193 catch (std::bad_alloc&)
12194 {
12195 return gl::error(GL_OUT_OF_MEMORY);
12196 }
12197}
12198
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012199__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
12200{
12201 struct Extension
12202 {
12203 const char *name;
12204 __eglMustCastToProperFunctionPointerType address;
12205 };
12206
12207 static const Extension glExtensions[] =
12208 {
12209 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000012210 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000012211 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000012212 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
12213 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
12214 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
12215 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
12216 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
12217 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
12218 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000012219 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000012220 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000012221 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
12222 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
12223 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
12224 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000012225 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
12226 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
12227 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
12228 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
12229 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
12230 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
12231 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000012232 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000012233 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
12234 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
12235 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000012236 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
12237 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012238
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000012239 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000012240 {
12241 if (strcmp(procname, glExtensions[ext].name) == 0)
12242 {
12243 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
12244 }
12245 }
12246
12247 return NULL;
12248}
12249
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000012250// Non-public functions used by EGL
12251
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012252bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012253{
12254 EVENT("(egl::Surface* surface = 0x%0.8p)",
12255 surface);
12256
12257 try
12258 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000012259 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012260
12261 if (context)
12262 {
12263 gl::Texture2D *textureObject = context->getTexture2D();
12264
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012265 if (textureObject->isImmutable())
12266 {
12267 return false;
12268 }
12269
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012270 if (textureObject)
12271 {
12272 textureObject->bindTexImage(surface);
12273 }
12274 }
12275 }
12276 catch(std::bad_alloc&)
12277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000012278 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012279 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000012280
12281 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000012282}
12283
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012284}